book-index-ui 0.31.0 → 0.33.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.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Fa=Object.create;var kr=Object.defineProperty;var Oa=Object.getOwnPropertyDescriptor;var Pa=Object.getOwnPropertyNames;var Da=Object.getPrototypeOf,Ha=Object.prototype.hasOwnProperty;var Ga=(t,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Pa(n))!Ha.call(t,s)&&s!==r&&kr(t,s,{get:()=>n[s],enumerable:!(o=Oa(n,s))||o.enumerable});return t};var pn=(t,n,r)=>(r=t!=null?Fa(Da(t)):{},Ga(n||!t||!t.__esModule?kr(r,"default",{value:t,enumerable:!0}):r,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const be=require("./storage-entry-le9dwVgw.cjs"),e=require("react/jsx-runtime"),h=require("react"),Ua=require("opencc-js/t2cn"),Va=require("react-markdown"),Ya=require("remark-gfm"),Ka=t=>`/book-index?id=${t}`,Vo=h.createContext(Ka);function qa({buildUrl:t,children:n}){const r=h.useMemo(()=>t,[t]);return e.jsx(Vo.Provider,{value:r,children:n})}function He(){return h.useContext(Vo)}const Yo="",Ko="";function Ci(t){const n=[];let r=!1,o=t;for(;o.length;){const s=r?Ko:Yo,l=o.indexOf(s);if(l===-1){n.push({text:o,marked:r});break}l>0&&n.push({text:o.slice(0,l),marked:r}),o=o.slice(l+1),r=!r}return n}function Ke(t,n){return{title:t,tokens:n}}const wr='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Ja=[Ke("基础(VS Code 环境下跟随 --vscode-*)",{bg:{value:"#ffffff",vscode:"--vscode-editor-background"},fg:{value:"#333333",vscode:"--vscode-foreground"},"input-bg":{value:"#ffffff",vscode:"--vscode-input-background"},"input-fg":{value:"#333333",vscode:"--vscode-input-foreground"},"input-border":{value:"#cccccc",vscode:"--vscode-input-border"},"widget-border":{value:"#e0e0e0",vscode:"--vscode-widget-border"},"link-fg":{value:"#0066cc",vscode:"--vscode-textLink-foreground"},"desc-fg":{value:"#717171",vscode:"--vscode-descriptionForeground"},primary:{value:"#0078d4",vscode:"--vscode-button-background"},"primary-fg":{value:"#ffffff",vscode:"--vscode-button-foreground"},"primary-soft":{value:"rgba(0, 120, 212, 0.15)",css:"color-mix(in srgb, var(--bim-primary) 15%, transparent)"},danger:{value:"#f44336"},warning:{value:"#ff9800"},success:{value:"#4caf50"},"sidebar-bg":{value:"#f3f3f3",vscode:"--vscode-sideBar-background"},"list-hover-bg":{value:"rgba(0, 0, 0, 0.04)",vscode:"--vscode-list-hoverBackground"},"list-active-bg":{value:"rgba(0, 120, 212, 0.1)",vscode:"--vscode-list-activeSelectionBackground"},"focus-border":{value:"#0078d4",vscode:"--vscode-focusBorder"}}),Ke("底色层次 / 文字与描边 / 链接",{"bg-subtle":{value:"#fafafa"},"widget-bg":{value:"#f8f8f8"},muted:{value:"#888888"},border:{value:"#e5e5e5"},"primary-bg":{value:"#fdf4f4"},link:{value:"#1976d2"},"tag-bg":{value:"#f0f0f0"},"accent-bg":{value:"#1976d2"},"on-color-fg":{value:"#ffffff",note:"彩色底(徽章、选中态按钮)上的文字"}}),Ke("提示与警告",{"info-fg":{value:"#0c5380"},"info-bg":{value:"#e7f3ff"},"info-border":{value:"#b3dbff"},"warn-fg":{value:"#856404"},"warn-bg":{value:"#fff3cd"},"warn-border":{value:"#ffc107"},"danger-bg":{value:"rgba(244, 67, 54, 0.08)",note:"错误提示条底色"},"danger-soft-bg":{value:"rgba(244, 67, 54, 0.03)",note:"编辑器危险区块"},"danger-soft-border":{value:"rgba(244, 67, 54, 0.13)"}}),Ke("遮罩与阴影",{backdrop:{value:"rgba(0, 0, 0, 0.5)",note:"对话框遮罩"},"overlay-bg":{value:"#00000010",note:"轻量遮罩底(图片占位等)"},"shadow-dialog":{value:"0 4px 20px rgba(0, 0, 0, 0.3)"},"shadow-dropdown":{value:"0 4px 12px rgba(0, 0, 0, 0.1)"},"shadow-tooltip":{value:"0 2px 8px rgba(0, 0, 0, 0.08)"},"shadow-fab":{value:"0 2px 8px rgba(0, 0, 0, 0.25)",note:"悬浮按钮(反馈)"},"shadow-card":{value:"0 1px 4px rgba(0, 0, 0, 0.06)",note:"展开的卡片"},"shadow-node":{value:"0 1px 3px rgba(0, 0, 0, 0.1)",note:"谱系图节点"},"shadow-node-selected":{value:"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)"}}),Ke("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),Ke("资源",{"restype-text":{value:"#2196f3"},"restype-image":{value:"#ff9800"},"restype-text-image":{value:"#9c27b0"},"restype-physical":{value:"#795548"},"missing-fg":{value:"#e67e22",note:"资源缺册提示"},"colormode-bw-bg":{value:"#f5f5f5",note:"影印件色彩模式标记(黑白 / 彩色)"},"colormode-bw-fg":{value:"#757575"},"colormode-color-bg":{value:"#fff8e1"},"colormode-color-fg":{value:"#f57f17"},"progress-active":{value:"#f59e0b",note:"资源导入进度"},"progress-done":{value:"#10b981"},"progress-todo":{value:"#9ca3af"},"check-fine-bg":{value:"#e8f5e9",note:"文字资源校对程度徽章(精校 / 粗校 / AI整理)"},"check-fine-fg":{value:"#2e7d32"},"check-rough-bg":{value:"#fff3e0"},"check-rough-fg":{value:"#e65100"},"check-ai-bg":{value:"#e3f2fd"},"check-ai-fg":{value:"#1565c0"}}),Ke("整理本(CollatedEdition)",{"highlight-bg":{value:"#fff59d",note:"搜索命中高亮底"},"highlight-fg":{value:"inherit",root:!1},"section-lei":{value:"#8e6f3e",note:"章节类型标记:类 / 书 / 序 / 结语 / 考证 / 注释"},"section-shu":{value:"#c0392b"},"section-xu":{value:"#1a5276"},"section-jieyu":{value:"#7d6608"},"section-kaozhen":{value:"#5d6d7e"},"section-zhushi":{value:"#6c5b7b"},"section-tag-fg":{value:"#e74c3c",note:"章节标记(△ 等)"},"matchstate-fg":{value:"#b78900",note:"与底本匹配状态提示"},"quality-published":{value:"#1b5e20",note:"文本质量等级(出版 / 精校 / 粗校 / OCR)"},"quality-fine":{value:"#2e7d32"},"quality-rough":{value:"#1565c0"},"quality-ocr":{value:"#e65100"}}),Ke("版本传承(VersionLineageGraph / List) / 关系方向(RelationPanel)",{"lost-fg":{value:"#c62828",note:"佚失标记"},"confidence-certain":{value:"#2e7d32",note:"关系置信度"},"confidence-consensus":{value:"#1976d2"},"confidence-probable":{value:"#ed6c02"},"confidence-disputed":{value:"#c62828"},"lineage-edge-consensus":{value:"#555555",note:"⚠️ 同为 consensus,List 徽章用 --bim-confidence-consensus(蓝),Graph 连线用这个(灰)。若要统一,覆盖成 var(--bim-confidence-consensus)"},"relation-up":{value:"#2196f3"},"relation-down":{value:"#4caf50"},"relation-flat":{value:"#ff9800"}}),Ke("编辑器视图(主要在 guji-platform 插件中可见)",{"editor-type-work":{value:"#4caf50",note:"⚠️ 与展示视图的 --bim-type-* 是两套配色(历史如此)。若要统一,覆盖成对应的 var(--bim-type-*)"},"editor-type-collection":{value:"#2196f3"},"editor-type-book":{value:"#ff9800"},"editor-type-entity":{value:"#9c27b0"},"source-url":{value:"#2196f3",note:"来源类型(SourceEditor)"},"source-bookid":{value:"#4caf50"},"mode-active-bg":{value:"#2196f3",note:"模式指示器当前态(ModeIndicator)"},"cover-accent":{value:"#8e6f3e",note:'书目卡片「封面」点缀(IndexBrowser resultVariant="card")'}}),Ke("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --bim-primary 等控件色",{"page-bg":{value:"#fbf9f3",note:"纸"},"row-hover-bg":{value:"#f5f1e5"},"selection-bg":{value:"#ecdcbc",note:"选区"},"band-bg":{value:"#f0e4cb",note:"全文入口横幅(暖沙)"},"band-bg-hover":{value:"#e6d5b4"},ink:{value:"#2a231c",note:"文字层次:墨 → 正文 → 提要 → meta → 标签 → 提示"},"body-fg":{value:"#3b3228"},"quiet-fg":{value:"#5b4f40"},"meta-fg":{value:"#7b6a54"},"label-fg":{value:"#6f6457",note:"标签 / 提示:2026-09 N3a 调深,纸底与斑马底上对比度均 ≥4.5(原 #a3937b 2.8、#b3a385 2.3)"},"hint-fg":{value:"#756a5e"},accent:{value:"#9c3a2c",note:"朱"},"accent-deep":{value:"#6f2a20",note:"链接 hover"},"rule-strong":{value:"#2a231c",note:"分隔线:强 → 常规 → 虚线 → 提要左线"},rule:{value:"#e4dbc9"},"rule-dashed":{value:"#d6c9ae"},"rule-accent-soft":{value:"#e0d3b6"},"aux-fg":{value:"#6f6457",note:"辅助字(元数据、注记、「·」分隔的浅色小字)。须在 page-bg / zebra-bg 上对比度 ≥4.5(Q5 巡检)"},"card-bg":{value:"#fffdf9",note:"提要卡:抬起的面"},"zebra-bg":{value:"#f6f2eb",note:"表格斑马纹 / 左栏分组底(不画格线,靠这一阶底色分行)"},"tint-bg":{value:"#f3eee6",note:"检索框、悬停"},"shadow-summary":{value:"0 10px 32px rgba(60, 50, 40, 0.07)",note:"提要卡投影"},"flag-bg":{value:"rgba(158, 42, 43, 0.08)",note:"唯一的状态色块「有影印」"},"theme-dot-zhusha":{value:"#9c3a2c",note:"主题切换控件的色点:朱砂(不随主题变,两套主题下都要认得出)"},"theme-dot-indigo":{value:"#2e5266",note:"主题切换控件的色点:靛青"},"theme-dot-ink":{value:"#222221",note:"主题切换控件的色点:墨"},"sect-jing":{value:"#2e5266",note:"四部分布条:經部(人物页提要卡;无别处使用)"},"sect-shi":{value:"#9a7a3b",note:"四部分布条:史部"},"sect-zi":{value:"#4f7a5c",note:"四部分布条:子部"},"sect-ji":{value:"#9fb3bc",note:"四部分布条:集部"},"table-border":{value:"color-mix(in srgb, currentColor 28%, transparent)",root:!1,note:"古籍表格(跟随当前文字色)"},"table-head-bg":{value:"color-mix(in srgb, currentColor 8%, transparent)",root:!1}}),Ke('版式(v4 外观系统,overview#291):疏朗=留白分区(默认,下列值即疏朗);界栏=框线分区(`<html data-layout="boxed">`)',{"fr-bd":{value:"0 solid transparent",note:"区块外框(border 简写)。疏朗无框;界栏 1px 实线"},"fr-bg":{value:"transparent",note:"区块底。界栏=卡面色"},"fr-hd-pad":{value:"14px 18px",note:"区块标题栏内边距。10-01 起疏朗也有淡染底的标题栏(--bim-fr-hd-bg),故疏朗 14px 18px,界栏 12px 18px"},"fr-hd-bd":{value:"0 solid transparent",note:"区块标题栏下沿线(border 简写)"},"fr-bd-pad":{value:"0",note:"区块正文内边距"},"fr-gap":{value:"56px",note:"区块之间的间距。界栏收紧到 24px(框线本身已分隔)"},"fr-side-gap":{value:"34px",note:"侧栏各块之间的间距;界栏 20px"},"fr-shadow":{value:"0 1px 0 var(--bim-rule), 0 12px 32px -18px rgba(40, 36, 31, 0.25)",note:"抬起的面(提要卡)的投影;界栏不用投影,靠框线"},"fr-tab-bd":{value:"transparent",note:"页签行下沿线颜色(疏朗不画,界栏画)"},"fr-hd-size":{value:"24px",note:"分区标题字号。界栏标题在框顶标题栏里,小一档 19px"},"fr-hd-bg":{value:"color-mix(in srgb, var(--bim-accent) 7%, var(--bim-page-bg))",note:"分区标题栏底色(淡染主色)。疏朗混进页面底,界栏 6% 混进卡面底。主色取 accent(primary 是 VS Code 按钮蓝,不随配色)"},"fr-card-bd":{value:"1px solid transparent",note:"卡片边框。疏朗不画(靠卡面底与淡投影);界栏 1px"},"fr-card-bg":{value:"var(--bim-card-bg)",note:"卡片底"},"fr-row-bd":{value:"1px solid transparent",note:"列表行线、块内小分割线。疏朗不画(靠行距);界栏 1px"},"fr-row-pad":{value:"10px 2px",note:"列表行内边距。界栏收紧 7px 2px"},"fr-chrome-bd":{value:"1px solid transparent",note:"顶栏、分区导航(吸顶锚点条)的线"},"fr-tag-bd":{value:"1px solid transparent",note:"标签、版本签、计数签、工具按钮的边框。疏朗浅底无框;界栏透明底加框"},"fr-tag-bg":{value:"var(--bim-tint-bg)",note:"标签底"},"fr-tbl-cell-bd":{value:"0 solid transparent",note:"表格格线。疏朗不画(靠斑马纹);界栏全格线"},"fr-tbl-zebra":{value:"var(--bim-tint-bg)",note:"表格斑马纹(只在疏朗下有)"},"fr-rail-bd":{value:"1px solid transparent",note:"侧栏里的块、提示块的边框"},"fr-rail-bg":{value:"var(--bim-tint-bg)",note:"侧栏块底。疏朗浅底;界栏卡面底"},"fr-spine-bd":{value:"1px solid transparent",note:"题签、书脊(竖排书名)的边框。界栏是强调色浅线"},"fr-spine-bg":{value:"var(--bim-flag-bg)",note:"题签、书脊底。疏朗浅色实底;界栏卡面底(正史原志两种版式都是强调色实底)"},"fr-plank":{value:"0 solid transparent",note:"书架架板(border 简写)。只在界栏下画 3px"},"fr-axis-bd":{value:"0 solid transparent",note:"时间轴轴线。界栏 1px"},"fr-axis-band":{value:"6px",note:"时间轴底带高度。疏朗用 6px 浅色带代替轴线;界栏 0"},"fr-tick":{value:"0",note:"时间轴刻度短线长度。界栏 5px"},"fr-band-gap":{value:"3px",note:"年代带各段之间的空隙。疏朗 3px;界栏紧贴"},"fr-band-bd":{value:"0 solid transparent",note:"年代带外框与段间分隔。界栏 1px"}}),Ke("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),Ke("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),Ke("字体(全站无衬线,2026-09-05 定)",{"font-ui":{value:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif'},"font-body":{value:"system-ui, sans-serif",css:"var(--bim-font-ui)"},"font-serif":{value:wr,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:wr,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Za=Object.assign({},...Ja.map(t=>t.tokens)),qo={};for(const[t,n]of Object.entries(Za))qo[t]=`var(--bim-${t}, ${n.value})`;function i(t){const n=qo[t];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${t}`);return n}function _t(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Xa(t,n){return _t(t).includes(n)}const si={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Qa={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};i("quality-published"),i("quality-fine"),i("quality-rough"),i("quality-ocr");const Bt=h.createContext(null),Jo={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:i("check-fine-bg"),fg:i("check-fine-fg")},粗校:{label:"粗校",bg:i("check-rough-bg"),fg:i("check-rough-fg")},AI整理:{label:"AI整理",bg:i("check-ai-bg"),fg:i("check-ai-fg")}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入叢編",collectedIn:"收入叢編",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評註",studies:"所考典籍"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"結果分類",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},searchV4:{filterTitle:"篩選",dynasty:"朝代",classification:"部類",resources:"資源",extant:"存佚",clearAllFilters:"清除全部篩選",hasImage:"有影印",hasText:"有全文",hasCollated:"有整理本",filterButton:"篩選",filterSelected:"{n} 項已選",expand:"展開",collapse:"收起",filteredCount:"篩出 {n} 條",removeFilter:"取消篩選:{name}",viewLabel:"結果視圖",viewTable:"表格",viewCard:"卡片",colTitle:"題名",colType:"類型",colAuthor:"責任者",colEra:"年代",colClass:"部類",colResource:"資源",tagImage:"影印",tagText:"全文",tagCollated:"整理本",tagLost:"佚",pageInfo:"共 {total} 條 · 每頁 {size} 條 · 第 {page} / {pages} 頁",pagerLabel:"翻頁",prevPage:"上一頁",nextPage:"下一頁",emptyFiltered:"沒有找到匹配的條目。試試更短的書名、減少篩選,或切換繁 / 簡。",limitedNote:"各類只列前幾條,點上方分類頁籤看全部。",sortLabel:"排序",sortRelevance:"相關度",sortEra:"年代",sortTitle:"書名",sortEraAsc:"由早到晚",sortEraDesc:"由晚到早",sortTitleAsc:"拼音 A→Z",sortTitleDesc:"拼音 Z→A",onlyWorksNote:"部類、存佚只適用於作品;選了它們,版本、叢編、人物不參與。"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"概覽",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄",fullText:"全文",lineage:"版本傳承",feedback:"勘誤反饋",dataSource:"數據源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"數據源與授權"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},workSubtype:{book:"書",article:"篇",poem:"詩",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},ec={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:i("check-fine-bg"),fg:i("check-fine-fg")},粗校:{label:"粗校",bg:i("check-rough-bg"),fg:i("check-rough-fg")},AI整理:{label:"AI整理",bg:i("check-ai-bg"),fg:i("check-ai-fg")}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入丛编",collectedIn:"收入丛编",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评注",studies:"所考典籍"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"结果分类",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},searchV4:{filterTitle:"筛选",dynasty:"朝代",classification:"部类",resources:"资源",extant:"存佚",clearAllFilters:"清除全部筛选",hasImage:"有影印",hasText:"有全文",hasCollated:"有整理本",filterButton:"筛选",filterSelected:"{n} 项已选",expand:"展开",collapse:"收起",filteredCount:"筛出 {n} 条",removeFilter:"取消筛选:{name}",viewLabel:"结果视图",viewTable:"表格",viewCard:"卡片",colTitle:"题名",colType:"类型",colAuthor:"责任者",colEra:"年代",colClass:"部类",colResource:"资源",tagImage:"影印",tagText:"全文",tagCollated:"整理本",tagLost:"佚",pageInfo:"共 {total} 条 · 每页 {size} 条 · 第 {page} / {pages} 页",pagerLabel:"翻页",prevPage:"上一页",nextPage:"下一页",emptyFiltered:"没有找到匹配的条目。试试更短的书名、减少筛选,或切换繁 / 简。",limitedNote:"各类只列前几条,点上方分类页签看全部。",sortLabel:"排序",sortRelevance:"相关度",sortEra:"年代",sortTitle:"书名",sortEraAsc:"由早到晚",sortEraDesc:"由晚到早",sortTitleAsc:"拼音 A→Z",sortTitleDesc:"拼音 Z→A",onlyWorksNote:"部类、存佚只适用于作品;选了它们,版本、丛编、人物不参与。"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"概览",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录",fullText:"全文",lineage:"版本传承",feedback:"勘误反馈",dataSource:"数据源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"数据源与授权"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},workSubtype:{book:"书",article:"篇",poem:"诗",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},tc=["曹霑"];function nc(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ic(t,n=tc){const r=[...new Set(n.filter(Boolean))].sort((l,a)=>a.length-l.length);if(!r.length)return t;const o=new RegExp(`(${r.map(nc).join("|")})`,"g"),s=new Set(r);return l=>{if(!l)return t(l);const a=l.split(o);return a.length===1?t(l):a.map((p,c)=>c%2===1&&s.has(p)?p:p&&t(p)).join("")}}let Dt=null;function rc(){if(Dt)return Dt;try{Dt=ic(Ua.Converter({from:"tw",to:"cn"}))}catch{Dt=t=>t}return Dt}const oc={"zh-Hant":Jo,"zh-Hans":ec},Zo="bim-locale";function sc(){try{const t=localStorage.getItem(Zo);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function lc(t){try{localStorage.setItem(Zo,t)}catch{}}const ac="zh-Hans",cc=({locale:t,onLocaleChange:n,converter:r,children:o})=>{const[s,l]=h.useState(t??ac),a=t??s;h.useEffect(()=>{if(t)return;const u=sc();u&&u!==s&&l(u)},[]);const p=h.useMemo(()=>a==="zh-Hans"?r??rc():null,[a,r]),c=h.useCallback(u=>{l(u),lc(u),n==null||n(u)},[n]),d=h.useMemo(()=>({locale:a,setLocale:c,messages:oc[a],converter:p}),[a,c,p]);return e.jsx(Bt.Provider,{value:d,children:o})};function fe(){const t=h.useContext(Bt);return(t==null?void 0:t.messages)??Jo}const dc=2e3;function F(){const t=h.useContext(Bt),n=(t==null?void 0:t.locale)??"zh-Hant",r=(t==null?void 0:t.converter)??null,o=h.useRef(new Map),s=h.useRef(n);s.current!==n&&(o.current.clear(),s.current=n);const l=h.useCallback(a=>{if(!a)return"";if(!r)return a;const p=o.current.get(a);if(p!==void 0)return p;const c=r(a);if(o.current.size>=dc){const d=o.current.keys().next().value;d!==void 0&&o.current.delete(d)}return o.current.set(a,c),c},[r]);return h.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function nt(t,n){return t.replace(/\{(\w+)\}/g,(r,o)=>String(n[o]??""))}function pc(t){if(!t)return"";try{const n=new URL(t).hostname,r={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(r[n])return r[n];const o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function uc(){return{id:"",name:"",url:"",type:"text",details:""}}const li=({items:t,onChange:n,onDownload:r,downloadStatuses:o,filterType:s})=>{const l=fe(),[a,p]=h.useState(null),c=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],d=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=f=>{if(!s)return!0;const v=_t(f);return s==="text"?v.includes("text"):s==="image"?v.includes("image")||v.includes("physical"):s==="physical"?v.includes("physical"):v.includes(s)},x=t.map((f,v)=>({item:f,originalIndex:v})).filter(({item:f})=>u(f)),m=()=>{const f=uc();s&&(f.type=s),n([...t,f]),p(t.length)},g=f=>{n(t.filter((v,$)=>$!==f)),p(null)},b=(f,v,$)=>{const w=[...t];if(w[f]={...w[f],[v]:$},v==="url"&&!w[f].id){const _=pc($);_&&(w[f].id=_)}n(w)},k=(f,v,$)=>{const _={...t[f].metadata||{}};$?_[v]=$:delete _[v],b(f,"metadata",Object.keys(_).length>0?_:void 0)},y=(f,v)=>{const $=v.trim()?v.split(/[,,、]/).map(w=>w.trim()).filter(Boolean):void 0;b(f,"structure",$)},j=(f,v,$)=>{const _=t[f].coverage||{level:1,ranges:""};v==="level"?_.level=parseInt($)||1:_.ranges=$,b(f,"coverage",_.ranges?_:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:f,originalIndex:v})=>{var $,w,_;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(a===v?null:v),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===v?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:mc(f.type??"text"),color:i("on-color-fg")},children:(()=>{var z,E;const S=_t(f);return S.length===0?f.type??"text":S.length===1?((z=c.find(T=>T.value===S[0]))==null?void 0:z.label)??S[0]:S.includes("text")&&S.includes("image")?((E=c.find(T=>T.value==="text+image"))==null?void 0:E.label)??"text+image":S.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:f.name||`${l.editor.resourcePlaceholder} ${v+1}`}),f.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:f.id}),f.url&&e.jsx("a",{href:f.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),r&&f.url&&xc(v,o==null?void 0:o[v],r,l),e.jsx("button",{onClick:S=>{S.stopPropagation(),g(v)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),a===v&&e.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:[Xa(f,"image")&&f.url&&hc(f,l),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ht,children:[e.jsx("span",{style:Gt,children:l.label.type}),e.jsx("select",{value:f.type,onChange:S=>b(v,"type",S.target.value),style:{...rt,flex:1},children:c.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]}),e.jsxs("label",{style:Ht,children:[e.jsx("span",{style:Gt,children:l.label.rootType}),e.jsx("select",{value:f.root_type||"catalog",onChange:S=>b(v,"root_type",S.target.value),style:{...rt,flex:1},children:d.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:f.id,onChange:S=>b(v,"id",S.target.value),placeholder:l.editor.idAutoExtract,style:{...rt,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:f.name,onChange:S=>b(v,"name",S.target.value),placeholder:l.editor.resourceName,style:{...rt,flex:1}})]}),e.jsx("input",{type:"text",value:f.url,onChange:S=>b(v,"url",S.target.value),placeholder:l.editor.resourceUrl,style:rt}),e.jsx("input",{type:"text",value:(($=f.structure)==null?void 0:$.join("、"))||"",onChange:S=>y(v,S.target.value),placeholder:l.editor.structurePlaceholder,style:rt}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ht,children:[e.jsx("span",{style:Gt,children:l.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((w=f.coverage)==null?void 0:w.level)??"",onChange:S=>j(v,"level",S.target.value),placeholder:"1",style:{...rt,width:"60px"}})]}),e.jsxs("label",{style:{...Ht,flex:1},children:[e.jsx("span",{style:Gt,children:l.label.coverageRange}),e.jsx("input",{type:"text",value:((_=f.coverage)==null?void 0:_.ranges)||"",onChange:S=>j(v,"ranges",S.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...rt,flex:1}})]})]}),e.jsx("textarea",{value:f.details||"",onChange:S=>b(v,"details",S.target.value),placeholder:l.editor.detailsPlaceholder,style:{...rt,minHeight:"60px",resize:"vertical"}}),e.jsxs("div",{style:{borderTop:`1px solid ${i("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"6px"},children:l.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([S,z])=>{var E;return e.jsxs("label",{style:{...Ht,gap:"4px"},children:[e.jsx("span",{style:{...Gt,minWidth:"56px"},children:z}),e.jsx("input",{type:"text",value:((E=f.metadata)==null?void 0:E[S])||"",onChange:T=>k(v,S,T.target.value),placeholder:z,style:{...rt,flex:1}})]},S)})})]})]})]})]},v)}),e.jsxs("button",{onClick:m,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:l.action.addResource})]})]})};function mc(t){switch(t){case"text":return i("restype-text");case"image":return i("restype-image");case"text+image":return i("restype-text-image");case"physical":return i("restype-physical")}}function xc(t,n,r,o){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:a=>{a.stopPropagation(),s||r(t,"")},disabled:s,style:{background:"transparent",border:"none",color:i(l?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:l?o.download.completed:s?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:l?"✓":s?"⏳":"⬇"})}function hc(t,n){const r=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:r?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:i("overlay-bg")},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:o=>{o.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:i("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:i("desc-fg")},children:n.editor.imageResourceLink})})}const rt={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Ht={display:"flex",alignItems:"center",gap:"6px"},Gt={fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap"},gc={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive","www.shuge.org":"書格","shuge.org":"書格","pan.baidu.com":"百度網盤"};function Mt(t){try{return gc[new URL(t).hostname]}catch{return}}const Sr={text:0,image:1,physical:2};function Ti(t){return t.length===0?"physical":[...t].sort((n,r)=>(Sr[n]??99)-(Sr[r]??99)).join("+")}function Ni(t){var a;const n=p=>{const c=p.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const d=p.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},r=new Map;for(let p=0;p<t.length;p++){const c=t[p];if(c.volumes&&c.volumes.length>0)continue;const d=n(c.name);if(!d)continue;const[u,x]=d,m=`${u}|${Ti(_t(c))}`;r.has(m)||r.set(m,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const g=r.get(m);g.volumes.push({volume:x,url:c.url||void 0,status:"found"}),g.indices.push(p)}const o=[],s=new Set;for(const p of r.values())if(!(p.volumes.length<2)){p.volumes.sort((c,d)=>c.volume-d.volume),p.base.volumes=p.volumes,p.base.expected_volumes=p.volumes.length,p.base.url||(p.base.url=((a=p.volumes.find(c=>c.url))==null?void 0:a.url)??""),o.push(p.base);for(const c of p.indices)s.add(c)}const l=[...o];for(let p=0;p<t.length;p++)s.has(p)||l.push(t[p]);return l}function Xo(t){if(t.url)return t.url;for(const[n,r]of Object.entries(t))if(n.endsWith("_url")&&typeof r=="string")return r}function Qo(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||Xo(n)}))}function _n(t){const n=Qo(t);if(!n)return null;const r=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,o=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:r,missing:o,expected:t.expected_volumes??r+o}}function Ii(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const r=n.match(/^(\d+)/);return r?parseInt(r[1],10):void 0}function Ei(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const o=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(o)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(o[1]))}&page=${n}`;const s=new URL(t);return s.searchParams.set("page",String(n)),s.toString()}return t}catch{return t}}function Wt(t){if(!t.url)return;const n=Ii(t.metadata);return n?Ei(t.url,n):t.url}const $r={text:i("restype-text"),image:i("restype-image"),"text+image":i("restype-text-image"),physical:i("restype-physical")};function fc(t){return t.includes("text")&&t.includes("image")?$r["text+image"]:$r[t[0]||"physical"]}const Ri=({items:t,groupByType:n=!0,resourceGroups:r,onNavigate:o,renderLink:s})=>{const l=fe(),{convert:a}=F(),p=h.useMemo(()=>Ni(t||[]),[t]),{mirrorGroups:c,ungroupedItems:d}=h.useMemo(()=>{const y=new Map,j=[];for(const f of p){const v=f.group;v?(y.has(v)||y.set(v,[]),y.get(v).push(f)):j.push(f)}for(const f of y.values())f.sort((v,$)=>{const w=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return w(v)-w($)});return{mirrorGroups:y,ungroupedItems:j}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},x=y=>u[y]?u[y]:y.split("+").map(j=>u[j]||j).join("+");if(!p||p.length===0)return e.jsx("div",{style:{padding:"16px",color:i("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((y,j)=>e.jsx(Gn,{item:y},y.id||j))});const m=(y,j)=>{const f=r==null?void 0:r[y],v=(f==null?void 0:f.label)||y,$=f==null?void 0:f.description;return e.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:a(v)}),$&&e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.5},children:a($)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((w,_)=>e.jsx(Gn,{item:w,onNavigate:o,renderLink:s},w.id||_))})]},`group-${y}`)},g=new Map;for(const y of d){const j=Ti(_t(y));g.has(j)||g.set(j,[]),g.get(j).push(y)}const b=["text","image","text+image","physical"],k=[...b.filter(y=>g.has(y)),...[...g.keys()].filter(y=>!b.includes(y)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([y,j])=>m(y,j)),k.map(y=>{const j=g.get(y),f=fc(y.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:f,whiteSpace:"nowrap",flexShrink:0},children:x(y)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((v,$)=>e.jsx(Gn,{item:v,onNavigate:o,renderLink:s},v.id||$))})]},y)})]})},bc={bw:{label:"",bg:i("colormode-bw-bg"),fg:i("colormode-bw-fg")},color:{label:"",bg:i("colormode-color-bg"),fg:i("colormode-color-fg")}},Gn=({item:t})=>{const n=fe(),{convert:r}=F(),[o,s]=h.useState(!1),l=h.useMemo(()=>(t.url?Mt(t.url):void 0)||r(t.name),[t.url,t.name,r]),a=h.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(b=>({...b,url:b.url||Xo(b)})),[t.volumes]),p=a&&a.length>0,c=p?new Set(a.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=p?new Set(a.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=t.expected_volumes??(p?c+d:0),x=t.color_mode?{...bc[t.color_mode],label:n.colorMode[t.color_mode]}:null,m=t.details&&!p?r(t.details):null,g={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",background:i("input-bg"),fontSize:"12px",color:i("fg"),lineHeight:1.4,verticalAlign:"middle"};return e.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[e.jsxs("div",{style:g,children:[e.jsx("span",{style:{fontWeight:500},children:l}),x&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),m&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:m}),p&&e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[c,"/",u,n.unit.volume,d>0&&e.jsxs("span",{style:{color:i("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const b=Ii(t.metadata);return b?Ei(t.url,b):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:i("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),p&&e.jsx("button",{onClick:()=>s(!o),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",lineHeight:1.4},children:o?"▲":"▼"})]}),p&&o&&e.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:a.map(b=>{const k=b.status==="missing";return b.url&&!k?e.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${i("widget-border")}`,color:i("link-fg"),textDecoration:"none"},children:b.volume},b.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:i(k?"missing-fg":"desc-fg"),textDecoration:k?"line-through":"none",opacity:k?.6:1},children:b.volume},b.volume)})})]})},es=({indexSource:t,syncConfig:n,variant:r="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:l,onSelectFolder:a})=>{const p=fe(),c=t==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",x=u?u.split(/[/\\]/).pop()||u:"",m={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:i("primary-soft"),color:i("primary")},g={onMouseOver:k=>k.currentTarget.style.opacity="0.8",onMouseOut:k=>k.currentTarget.style.opacity="1"},b=e.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...m,background:i(d?"warning":"success"),color:i("on-color-fg")},...g,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return r==="index-browser"?c?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:o,title:p.mode.switchToSync,style:m,...g,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:p.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...m,paddingLeft:"8px",paddingRight:"8px"},...g,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:o,title:p.mode.switchToLocal,style:m,...g,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:p.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:l,title:x||p.mode.configurePath,style:{...m,background:"transparent",padding:"6px",fontSize:"12px"},...g,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:c?p.mode.switchToGithub:p.mode.switchToLocal,style:m,...g,children:[e.jsx("span",{children:c?"📁":"🌐"}),e.jsx("span",{children:c?p.mode.localMode:p.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&e.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...m,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...g,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!c&&x&&e.jsxs("div",{style:{...m,background:i("mode-active-bg"),color:i("on-color-fg"),cursor:"default"},title:u,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},zn="bim-search-history",_r=10,zr=8;function Xt(){try{const t=localStorage.getItem(zn);return t?JSON.parse(t):[]}catch{return[]}}function yc(t){try{const n=Xt().filter(r=>r!==t);n.unshift(t),n.length>_r&&(n.length=_r),localStorage.setItem(zn,JSON.stringify(n))}catch{}}function jc(t){try{const n=Xt().filter(r=>r!==t);localStorage.setItem(zn,JSON.stringify(n))}catch{}}function vc(){try{localStorage.removeItem(zn)}catch{}}const ts=({transport:t,value:n,onChange:r,onSearch:o,onEntrySelect:s,placeholder:l})=>{const a=fe(),p=l??a.search.placeholder,c={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,u]=h.useState(!1),[x,m]=h.useState([]),[g,b]=h.useState(-1),[k,y]=h.useState(Xt),j=h.useRef(null),f=h.useRef(null),v=h.useRef(null),$=h.useRef(!1);h.useEffect(()=>{b(-1);const N=n.trim();if(!N){m(k.map(B=>({type:"history",text:B})));return}if(!t.searchAll){m([]);return}let V=!1;const W=setTimeout(()=>{t.searchAll(N,zr).then(B=>{if(V)return;const H=[...B.works,...B.books,...B.collections,...B.entities??[]];m(H.slice(0,zr).map(te=>({type:"entry",text:te.title||te.id,entry:te})))}).catch(()=>{V||m([])})},80);return()=>{V=!0,clearTimeout(W)}},[n,k,t]),h.useEffect(()=>{const N=V=>{v.current&&!v.current.contains(V.target)&&u(!1)};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[]),h.useEffect(()=>{const N=V=>{var W,B;if(V.key==="/"&&document.activeElement!==j.current){const H=(W=document.activeElement)==null?void 0:W.tagName;if(H==="INPUT"||H==="TEXTAREA"||H==="SELECT")return;V.preventDefault(),(B=j.current)==null||B.focus()}};return document.addEventListener("keydown",N),()=>document.removeEventListener("keydown",N)},[]);const w=h.useCallback(N=>{N.trim()&&(yc(N.trim()),y(Xt())),o(N),u(!1)},[o]),_=h.useCallback(N=>{N.type==="history"?(r(N.text),w(N.text)):N.entry&&(s?(s(N.entry),u(!1)):(r(N.text),w(N.text)))},[r,w,s]),S=h.useCallback(N=>{if(!d||x.length===0){N.key==="Enter"&&w(n);return}switch(N.key){case"ArrowDown":N.preventDefault(),b(V=>(V+1)%x.length);break;case"ArrowUp":N.preventDefault(),b(V=>(V-1+x.length)%x.length);break;case"Enter":N.preventDefault(),g>=0&&g<x.length?_(x[g]):w(n);break;case"Escape":N.preventDefault(),u(!1);break}},[d,x,g,n,w,_]),z=h.useCallback((N,V)=>{V.stopPropagation(),jc(N),y(Xt()),m(W=>W.filter(B=>!(B.type==="history"&&B.text===N)))},[]),E=h.useCallback(N=>{N.stopPropagation(),vc(),y([]),m([])},[]);h.useEffect(()=>{if(g>=0&&f.current){const N=f.current.children;N[g]&&N[g].scrollIntoView({block:"nearest"})}},[g]);const T=!n.trim()&&k.length>0;return e.jsxs("div",{ref:v,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:j,type:"text",placeholder:p,value:n,onChange:N=>{r(N.target.value),u(!0)},onCompositionStart:()=>{$.current=!0},onCompositionEnd:()=>{$.current=!1},onFocus:()=>{u(!0)},onKeyDown:S,style:{width:"100%",padding:"8px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),d&&x.length>0&&e.jsxs("div",{ref:f,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:i("input-bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"6px",boxShadow:i("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[T&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:i("desc-fg"),borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsx("span",{children:a.search.history}),e.jsx("button",{onClick:E,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),x.map((N,V)=>e.jsxs("div",{onClick:()=>_(N),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:i("fg"),background:V===g?i("list-active-bg"):"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:N.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N.text}),N.entry&&e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:[c[N.entry.type],N.entry.edition&&` · ${N.entry.edition}`,N.entry.author&&` · ${N.entry.author}`]}),N.type==="history"&&e.jsx("button",{onClick:W=>z(N.text,W),style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${N.type}-${N.text}-${V}`))]})]})},Ft=({type:t,size:n=9})=>e.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:n,borderRadius:1,flex:"none",background:i(`type-${t}`),verticalAlign:"middle"}}),Cn={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},ns=new Set(["work","book","entity"]);function kc(t){return rs(t)||!!t.sort}function wc(t,n){return n.sort&&ns.has(t)?n.sort:void 0}const Tn=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Nn=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Li=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],is={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function In(t){return t.dynasty.length+t.classification.length+(t.hasImage?1:0)+(t.hasText?1:0)+(t.hasCollated?1:0)+(t.loss?1:0)}function rs(t){return In(t)>0}function Sc(t){const n=[];return t.dynasty.length&&n.push("dynasty"),t.classification.length&&n.push("classification"),t.hasImage&&n.push("hasImage"),t.hasText&&n.push("hasText"),t.hasCollated&&n.push("hasCollated"),t.loss&&n.push("loss"),n}function os(t,n){const r=is[t];return Sc(n).every(o=>r.has(o))}const Ut=t=>JSON.stringify(t);function $c(t,n){if(!os(n,t))return null;const r=[];if(t.dynasty.length){const o=Array.from(new Set(t.dynasty.flatMap(s=>{var l;return((l=Tn.find(a=>a.key===s))==null?void 0:l.values)??[]})));o.length===1?r.push(`dynasty = ${Ut(o[0])}`):o.length>1&&r.push(`dynasty IN [${o.map(Ut).join(", ")}]`)}return t.classification.length&&r.push(t.classification.length===1?`classification = ${Ut(t.classification[0])}`:`classification IN [${t.classification.map(Ut).join(", ")}]`),t.hasImage&&r.push("has_image = true"),t.hasText&&r.push("has_text = true"),t.hasCollated&&r.push("has_collated = true"),t.loss&&r.push(`loss_status = ${Ut(t.loss)}`),r.join(" AND ")}const Ye={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},ss="_";function yn(t,n=new URLSearchParams){for(const r of Object.values(Ye))n.delete(r);return t.dynasty.length&&n.set(Ye.dynasty,t.dynasty.join(",")),t.classification.length&&n.set(Ye.classification,t.classification.map(r=>r||ss).join(",")),t.hasImage&&n.set(Ye.hasImage,"1"),t.hasText&&n.set(Ye.hasText,"1"),t.hasCollated&&n.set(Ye.hasCollated,"1"),t.loss&&n.set(Ye.loss,t.loss),t.sort&&n.set(Ye.sort,t.sort),n}function _c(t){const n=l=>(t.get(l)??"").split(",").map(a=>a.trim()).filter(Boolean),r=new Set(Tn.map(l=>l.key)),o=new Set(Nn.map(l=>l.value)),s=t.get(Ye.loss);return{dynasty:Array.from(new Set(n(Ye.dynasty).filter(l=>r.has(l)))),classification:Array.from(new Set(n(Ye.classification).map(l=>l===ss?"":l).filter(l=>o.has(l)))),hasImage:t.get(Ye.hasImage)==="1",hasText:t.get(Ye.hasText)==="1",hasCollated:t.get(Ye.hasCollated)==="1",loss:s==="extant"||s==="partially_extant"||s==="lost"?s:"",sort:["era:asc","era:desc","title:asc","title:desc"].find(l=>l===t.get(Ye.sort))??""}}function zc(t,n){return JSON.stringify([t.dynasty.slice().sort(),t.classification.slice().sort(),t.hasImage,t.hasText,t.hasCollated,t.loss,t.sort])===JSON.stringify([n.dynasty.slice().sort(),n.classification.slice().sort(),n.hasImage,n.hasText,n.hasCollated,n.loss,n.sort])}function Cr(t,n){return t.includes(n)?t.filter(r=>r!==n):[...t,n]}const Cc=({filters:t,onChange:n})=>{const r=fe().searchV4,{convert:o}=F(),[s,l]=h.useState(!1),a=h.useId(),p=In(t),c=d=>n({...t,...d});return e.jsxs("aside",{className:"bim-sr-aside","aria-label":o(r.filterTitle),children:[e.jsxs("button",{type:"button",className:"bim-sr-fbtn","aria-expanded":s,"aria-controls":a,onClick:()=>l(d=>!d),children:[e.jsxs("span",{children:[o(r.filterButton),p>0&&e.jsx("span",{className:"bim-sr-fn",children:o(nt(r.filterSelected,{n:p}))})]}),e.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[o(s?r.collapse:r.expand)," ",s?"▴":"▾"]})]}),e.jsxs("div",{className:"bim-sr-filters",id:a,"data-open":s?"true":"false",...s?{}:{"data-collapsed":"true"},children:[e.jsxs("section",{className:"bim-sr-fg",children:[e.jsx("h3",{children:o(r.dynasty)}),e.jsx("div",{className:"bim-sr-chips",children:Tn.map(d=>e.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":t.dynasty.includes(d.key),onClick:()=>c({dynasty:Cr(t.dynasty,d.key)}),children:o(d.key)},d.key))})]}),e.jsxs("section",{className:"bim-sr-fg",children:[e.jsx("h3",{children:o(r.classification)}),Nn.map(d=>e.jsxs("label",{className:"bim-sr-opt",children:[e.jsx("input",{type:"checkbox",checked:t.classification.includes(d.value),onChange:()=>c({classification:Cr(t.classification,d.value)})}),o(d.label)]},d.value||"_"))]}),e.jsxs("section",{className:"bim-sr-fg",children:[e.jsx("h3",{children:o(r.resources)}),e.jsxs("label",{className:"bim-sr-opt",children:[e.jsx("input",{type:"checkbox",checked:t.hasImage,onChange:d=>c({hasImage:d.target.checked})}),o(r.hasImage)]}),e.jsxs("label",{className:"bim-sr-opt",children:[e.jsx("input",{type:"checkbox",checked:t.hasText,onChange:d=>c({hasText:d.target.checked})}),o(r.hasText)]}),e.jsxs("label",{className:"bim-sr-opt",children:[e.jsx("input",{type:"checkbox",checked:t.hasCollated,onChange:d=>c({hasCollated:d.target.checked})}),o(r.hasCollated)]})]}),e.jsxs("section",{className:"bim-sr-fg",children:[e.jsx("h3",{id:`${a}-loss`,children:o(r.extant)}),e.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${a}-loss`,children:Li.map(d=>e.jsx("button",{type:"button","aria-pressed":t.loss===d.value,onClick:()=>c({loss:d.value}),children:o(d.label)},d.value||"all"))})]}),e.jsx("p",{className:"bim-sr-note",children:o(r.onlyWorksNote)}),p>0&&e.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>n({...Cn,sort:t.sort}),children:o(r.clearAllFilters)})]})]})};function ls({text:t,query:n}){const r=(n??"").trim();if(!r||!t)return e.jsx(e.Fragment,{children:t});const o=t.toLowerCase(),s=r.toLowerCase(),l=[];let a=0,p=0;for(;a<t.length;){const c=o.indexOf(s,a);if(c<0){l.push(t.slice(a));break}c>a&&l.push(t.slice(a,c)),l.push(e.jsx("mark",{className:"bim-sr-hl",children:t.slice(c,c+s.length)},p++)),a=c+s.length}return e.jsx(e.Fragment,{children:l})}const Tr=({entries:t,query:n,onEntryLinkClick:r,typeName:o})=>{const s=fe(),l=s.searchV4,{convert:a}=F(),p=He();return e.jsx("div",{className:"bim-sr-tablewrap",children:e.jsxs("table",{className:"bim-sr-table",children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"34%"}}),e.jsx("col",{style:{width:"8%"}}),e.jsx("col",{style:{width:"19%"}}),e.jsx("col",{style:{width:"13%"}}),e.jsx("col",{style:{width:"12%"}}),e.jsx("col",{style:{width:"14%"}})]}),e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:a(l.colTitle)}),e.jsx("th",{scope:"col",children:a(l.colType)}),e.jsx("th",{scope:"col",children:a(l.colAuthor)}),e.jsx("th",{scope:"col",children:a(l.colEra)}),e.jsx("th",{scope:"col",children:a(l.colClass)}),e.jsx("th",{scope:"col",style:{textAlign:"right"},children:a(l.colResource)})]})}),e.jsx("tbody",{children:t.map(c=>{const d=a(c.title||c.primary_name||c.id),u=c.measure_info?a(c.measure_info):c.juan_count?`${c.juan_count}${s.unit.juan}`:"",x=c.type==="entity"?[c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:""].filter(Boolean).join(""):c.author?`${a(c.author)}${c.role&&c.role!=="author"?` ${a(c.role)}`:""}`:"",m=c.type==="book"?c.era??c.dynasty:c.dynasty,g=m?a(m):"",b=c.classification?a(c.classification):"",k=[];c.has_image&&k.push({label:l.tagImage,cls:"bim-sr-tag--img"}),c.has_text&&k.push({label:l.tagText,cls:""}),c.has_collated&&k.push({label:l.tagCollated,cls:""}),c.loss_status==="lost"&&k.push({label:l.tagLost,cls:"bim-sr-tag--lost"});const y=[x,g,b].filter(Boolean).join(" · ");return e.jsxs("tr",{children:[e.jsxs("td",{className:"bim-sr-c-title",children:[e.jsxs("div",{className:"bim-sr-tl",children:[e.jsx("a",{href:p(c.id),onClick:j=>r(c,j),children:e.jsx(ls,{text:d,query:n?a(n):void 0})}),u&&e.jsx("span",{className:"bim-sr-measure",children:u})]}),y&&e.jsx("span",{className:"bim-sr-sub",children:y})]}),e.jsxs("td",{className:"bim-sr-c-type",children:[e.jsx(Ft,{type:c.type,size:6})," ",o(c.type)]}),e.jsx("td",{className:"bim-sr-c-who",children:x||"—"}),e.jsx("td",{className:"bim-sr-c-era",children:g||"—"}),e.jsx("td",{className:"bim-sr-c-cls",children:b||"—"}),e.jsx("td",{className:"bim-sr-c-res",children:k.map(j=>e.jsx("span",{className:`bim-sr-tag ${j.cls}`,children:a(j.label)},j.label))})]},c.id)})})]})})},Tc=`
1
+ "use strict";var Ha=Object.create;var $r=Object.defineProperty;var Ga=Object.getOwnPropertyDescriptor;var Ua=Object.getOwnPropertyNames;var Va=Object.getPrototypeOf,Ya=Object.prototype.hasOwnProperty;var Ka=(t,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Ua(n))!Ya.call(t,s)&&s!==r&&$r(t,s,{get:()=>n[s],enumerable:!(o=Ga(n,s))||o.enumerable});return t};var pn=(t,n,r)=>(r=t!=null?Ha(Va(t)):{},Ka(n||!t||!t.__esModule?$r(r,"default",{value:t,enumerable:!0}):r,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const be=require("./storage-entry-DPsx0DgD.cjs"),e=require("react/jsx-runtime"),h=require("react"),qa=require("opencc-js/t2cn"),Ja=require("react-markdown"),Za=require("remark-gfm"),Xa=t=>`/book-index?id=${t}`,qo=h.createContext(Xa);function Qa({buildUrl:t,children:n}){const r=h.useMemo(()=>t,[t]);return e.jsx(qo.Provider,{value:r,children:n})}function He(){return h.useContext(qo)}const Jo="",Zo="";function Ti(t){const n=[];let r=!1,o=t;for(;o.length;){const s=r?Zo:Jo,l=o.indexOf(s);if(l===-1){n.push({text:o,marked:r});break}l>0&&n.push({text:o.slice(0,l),marked:r}),o=o.slice(l+1),r=!r}return n}function Ke(t,n){return{title:t,tokens:n}}const _r='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',ec=[Ke("基础(VS Code 环境下跟随 --vscode-*)",{bg:{value:"#ffffff",vscode:"--vscode-editor-background"},fg:{value:"#333333",vscode:"--vscode-foreground"},"input-bg":{value:"#ffffff",vscode:"--vscode-input-background"},"input-fg":{value:"#333333",vscode:"--vscode-input-foreground"},"input-border":{value:"#cccccc",vscode:"--vscode-input-border"},"widget-border":{value:"#e0e0e0",vscode:"--vscode-widget-border"},"link-fg":{value:"#0066cc",vscode:"--vscode-textLink-foreground"},"desc-fg":{value:"#717171",vscode:"--vscode-descriptionForeground"},primary:{value:"#0078d4",vscode:"--vscode-button-background"},"primary-fg":{value:"#ffffff",vscode:"--vscode-button-foreground"},"primary-soft":{value:"rgba(0, 120, 212, 0.15)",css:"color-mix(in srgb, var(--bim-primary) 15%, transparent)"},danger:{value:"#f44336"},warning:{value:"#ff9800"},success:{value:"#4caf50"},"sidebar-bg":{value:"#f3f3f3",vscode:"--vscode-sideBar-background"},"list-hover-bg":{value:"rgba(0, 0, 0, 0.04)",vscode:"--vscode-list-hoverBackground"},"list-active-bg":{value:"rgba(0, 120, 212, 0.1)",vscode:"--vscode-list-activeSelectionBackground"},"focus-border":{value:"#0078d4",vscode:"--vscode-focusBorder"}}),Ke("底色层次 / 文字与描边 / 链接",{"bg-subtle":{value:"#fafafa"},"widget-bg":{value:"#f8f8f8"},muted:{value:"#888888"},border:{value:"#e5e5e5"},"primary-bg":{value:"#fdf4f4"},link:{value:"#1976d2"},"tag-bg":{value:"#f0f0f0"},"accent-bg":{value:"#1976d2"},"on-color-fg":{value:"#ffffff",note:"彩色底(徽章、选中态按钮)上的文字"}}),Ke("提示与警告",{"info-fg":{value:"#0c5380"},"info-bg":{value:"#e7f3ff"},"info-border":{value:"#b3dbff"},"warn-fg":{value:"#856404"},"warn-bg":{value:"#fff3cd"},"warn-border":{value:"#ffc107"},"danger-bg":{value:"rgba(244, 67, 54, 0.08)",note:"错误提示条底色"},"danger-soft-bg":{value:"rgba(244, 67, 54, 0.03)",note:"编辑器危险区块"},"danger-soft-border":{value:"rgba(244, 67, 54, 0.13)"}}),Ke("遮罩与阴影",{backdrop:{value:"rgba(0, 0, 0, 0.5)",note:"对话框遮罩"},"overlay-bg":{value:"#00000010",note:"轻量遮罩底(图片占位等)"},"shadow-dialog":{value:"0 4px 20px rgba(0, 0, 0, 0.3)"},"shadow-dropdown":{value:"0 4px 12px rgba(0, 0, 0, 0.1)"},"shadow-tooltip":{value:"0 2px 8px rgba(0, 0, 0, 0.08)"},"shadow-fab":{value:"0 2px 8px rgba(0, 0, 0, 0.25)",note:"悬浮按钮(反馈)"},"shadow-card":{value:"0 1px 4px rgba(0, 0, 0, 0.06)",note:"展开的卡片"},"shadow-node":{value:"0 1px 3px rgba(0, 0, 0, 0.1)",note:"谱系图节点"},"shadow-node-selected":{value:"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)"}}),Ke("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),Ke("资源",{"restype-text":{value:"#2196f3"},"restype-image":{value:"#ff9800"},"restype-text-image":{value:"#9c27b0"},"restype-physical":{value:"#795548"},"missing-fg":{value:"#e67e22",note:"资源缺册提示"},"colormode-bw-bg":{value:"#f5f5f5",note:"影印件色彩模式标记(黑白 / 彩色)"},"colormode-bw-fg":{value:"#757575"},"colormode-color-bg":{value:"#fff8e1"},"colormode-color-fg":{value:"#f57f17"},"progress-active":{value:"#f59e0b",note:"资源导入进度"},"progress-done":{value:"#10b981"},"progress-todo":{value:"#9ca3af"},"check-fine-bg":{value:"#e8f5e9",note:"文字资源校对程度徽章(精校 / 粗校 / AI整理)"},"check-fine-fg":{value:"#2e7d32"},"check-rough-bg":{value:"#fff3e0"},"check-rough-fg":{value:"#e65100"},"check-ai-bg":{value:"#e3f2fd"},"check-ai-fg":{value:"#1565c0"}}),Ke("整理本(CollatedEdition)",{"highlight-bg":{value:"#fff59d",note:"搜索命中高亮底"},"highlight-fg":{value:"inherit",root:!1},"section-lei":{value:"#8e6f3e",note:"章节类型标记:类 / 书 / 序 / 结语 / 考证 / 注释"},"section-shu":{value:"#c0392b"},"section-xu":{value:"#1a5276"},"section-jieyu":{value:"#7d6608"},"section-kaozhen":{value:"#5d6d7e"},"section-zhushi":{value:"#6c5b7b"},"section-tag-fg":{value:"#e74c3c",note:"章节标记(△ 等)"},"matchstate-fg":{value:"#b78900",note:"与底本匹配状态提示"},"quality-published":{value:"#1b5e20",note:"文本质量等级(出版 / 精校 / 粗校 / OCR)"},"quality-fine":{value:"#2e7d32"},"quality-rough":{value:"#1565c0"},"quality-ocr":{value:"#e65100"}}),Ke("版本传承(VersionLineageGraph / List) / 关系方向(RelationPanel)",{"lost-fg":{value:"#c62828",note:"佚失标记"},"confidence-certain":{value:"#2e7d32",note:"关系置信度"},"confidence-consensus":{value:"#1976d2"},"confidence-probable":{value:"#ed6c02"},"confidence-disputed":{value:"#c62828"},"lineage-edge-consensus":{value:"#555555",note:"⚠️ 同为 consensus,List 徽章用 --bim-confidence-consensus(蓝),Graph 连线用这个(灰)。若要统一,覆盖成 var(--bim-confidence-consensus)"},"relation-up":{value:"#2196f3"},"relation-down":{value:"#4caf50"},"relation-flat":{value:"#ff9800"}}),Ke("编辑器视图(主要在 guji-platform 插件中可见)",{"editor-type-work":{value:"#4caf50",note:"⚠️ 与展示视图的 --bim-type-* 是两套配色(历史如此)。若要统一,覆盖成对应的 var(--bim-type-*)"},"editor-type-collection":{value:"#2196f3"},"editor-type-book":{value:"#ff9800"},"editor-type-entity":{value:"#9c27b0"},"source-url":{value:"#2196f3",note:"来源类型(SourceEditor)"},"source-bookid":{value:"#4caf50"},"mode-active-bg":{value:"#2196f3",note:"模式指示器当前态(ModeIndicator)"},"cover-accent":{value:"#8e6f3e",note:'书目卡片「封面」点缀(IndexBrowser resultVariant="card")'}}),Ke("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --bim-primary 等控件色",{"page-bg":{value:"#fbf9f3",note:"纸"},"row-hover-bg":{value:"#f5f1e5"},"selection-bg":{value:"#ecdcbc",note:"选区"},"band-bg":{value:"#f0e4cb",note:"全文入口横幅(暖沙)"},"band-bg-hover":{value:"#e6d5b4"},ink:{value:"#2a231c",note:"文字层次:墨 → 正文 → 提要 → meta → 标签 → 提示"},"body-fg":{value:"#3b3228"},"quiet-fg":{value:"#5b4f40"},"meta-fg":{value:"#7b6a54"},"label-fg":{value:"#6f6457",note:"标签 / 提示:2026-09 N3a 调深,纸底与斑马底上对比度均 ≥4.5(原 #a3937b 2.8、#b3a385 2.3)"},"hint-fg":{value:"#756a5e"},accent:{value:"#9c3a2c",note:"朱"},"accent-deep":{value:"#6f2a20",note:"链接 hover"},"rule-strong":{value:"#2a231c",note:"分隔线:强 → 常规 → 虚线 → 提要左线"},rule:{value:"#e4dbc9"},"rule-dashed":{value:"#d6c9ae"},"rule-accent-soft":{value:"#e0d3b6"},"aux-fg":{value:"#6f6457",note:"辅助字(元数据、注记、「·」分隔的浅色小字)。须在 page-bg / zebra-bg 上对比度 ≥4.5(Q5 巡检)"},"card-bg":{value:"#fffdf9",note:"提要卡:抬起的面"},"zebra-bg":{value:"#f6f2eb",note:"表格斑马纹 / 左栏分组底(不画格线,靠这一阶底色分行)"},"tint-bg":{value:"#f3eee6",note:"检索框、悬停"},"shadow-summary":{value:"0 10px 32px rgba(60, 50, 40, 0.07)",note:"提要卡投影"},"flag-bg":{value:"rgba(158, 42, 43, 0.08)",note:"唯一的状态色块「有影印」"},"theme-dot-zhusha":{value:"#9c3a2c",note:"主题切换控件的色点:朱砂(不随主题变,两套主题下都要认得出)"},"theme-dot-indigo":{value:"#2e5266",note:"主题切换控件的色点:靛青"},"theme-dot-ink":{value:"#222221",note:"主题切换控件的色点:墨"},"sect-jing":{value:"#2e5266",note:"四部分布条:經部(人物页提要卡;无别处使用)"},"sect-shi":{value:"#9a7a3b",note:"四部分布条:史部"},"sect-zi":{value:"#4f7a5c",note:"四部分布条:子部"},"sect-ji":{value:"#9fb3bc",note:"四部分布条:集部"},"table-border":{value:"color-mix(in srgb, currentColor 28%, transparent)",root:!1,note:"古籍表格(跟随当前文字色)"},"table-head-bg":{value:"color-mix(in srgb, currentColor 8%, transparent)",root:!1}}),Ke('版式(v4 外观系统,overview#291):疏朗=留白分区(默认,下列值即疏朗);界栏=框线分区(`<html data-layout="boxed">`)',{"fr-bd":{value:"0 solid transparent",note:"区块外框(border 简写)。疏朗无框;界栏 1px 实线"},"fr-bg":{value:"transparent",note:"区块底。界栏=卡面色"},"fr-hd-pad":{value:"14px 18px",note:"区块标题栏内边距。10-01 起疏朗也有淡染底的标题栏(--bim-fr-hd-bg),故疏朗 14px 18px,界栏 12px 18px"},"fr-hd-bd":{value:"0 solid transparent",note:"区块标题栏下沿线(border 简写)"},"fr-bd-pad":{value:"0",note:"区块正文内边距"},"fr-gap":{value:"56px",note:"区块之间的间距。界栏收紧到 24px(框线本身已分隔)"},"fr-side-gap":{value:"34px",note:"侧栏各块之间的间距;界栏 20px"},"fr-shadow":{value:"0 1px 0 var(--bim-rule), 0 12px 32px -18px rgba(40, 36, 31, 0.25)",note:"抬起的面(提要卡)的投影;界栏不用投影,靠框线"},"fr-tab-bd":{value:"transparent",note:"页签行下沿线颜色(疏朗不画,界栏画)"},"fr-hd-size":{value:"24px",note:"分区标题字号。界栏标题在框顶标题栏里,小一档 19px"},"fr-hd-bg":{value:"color-mix(in srgb, var(--bim-accent) 7%, var(--bim-page-bg))",note:"分区标题栏底色(淡染主色)。疏朗混进页面底,界栏 6% 混进卡面底。主色取 accent(primary 是 VS Code 按钮蓝,不随配色)"},"fr-card-bd":{value:"1px solid transparent",note:"卡片边框。疏朗不画(靠卡面底与淡投影);界栏 1px"},"fr-card-bg":{value:"var(--bim-card-bg)",note:"卡片底"},"fr-row-bd":{value:"1px solid transparent",note:"列表行线、块内小分割线。疏朗不画(靠行距);界栏 1px"},"fr-row-pad":{value:"10px 2px",note:"列表行内边距。界栏收紧 7px 2px"},"fr-chrome-bd":{value:"1px solid transparent",note:"顶栏、分区导航(吸顶锚点条)的线"},"fr-tag-bd":{value:"1px solid transparent",note:"标签、版本签、计数签、工具按钮的边框。疏朗浅底无框;界栏透明底加框"},"fr-tag-bg":{value:"var(--bim-tint-bg)",note:"标签底"},"fr-tbl-cell-bd":{value:"0 solid transparent",note:"表格格线。疏朗不画(靠斑马纹);界栏全格线"},"fr-tbl-zebra":{value:"var(--bim-tint-bg)",note:"表格斑马纹(只在疏朗下有)"},"fr-rail-bd":{value:"1px solid transparent",note:"侧栏里的块、提示块的边框"},"fr-rail-bg":{value:"var(--bim-tint-bg)",note:"侧栏块底。疏朗浅底;界栏卡面底"},"fr-spine-bd":{value:"1px solid transparent",note:"题签、书脊(竖排书名)的边框。界栏是强调色浅线"},"fr-spine-bg":{value:"var(--bim-flag-bg)",note:"题签、书脊底。疏朗浅色实底;界栏卡面底(正史原志两种版式都是强调色实底)"},"fr-plank":{value:"0 solid transparent",note:"书架架板(border 简写)。只在界栏下画 3px"},"fr-axis-bd":{value:"0 solid transparent",note:"时间轴轴线。界栏 1px"},"fr-axis-band":{value:"6px",note:"时间轴底带高度。疏朗用 6px 浅色带代替轴线;界栏 0"},"fr-tick":{value:"0",note:"时间轴刻度短线长度。界栏 5px"},"fr-band-gap":{value:"3px",note:"年代带各段之间的空隙。疏朗 3px;界栏紧贴"},"fr-band-bd":{value:"0 solid transparent",note:"年代带外框与段间分隔。界栏 1px"}}),Ke("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),Ke("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),Ke("字体(全站无衬线,2026-09-05 定)",{"font-ui":{value:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif'},"font-body":{value:"system-ui, sans-serif",css:"var(--bim-font-ui)"},"font-serif":{value:_r,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:_r,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],tc=Object.assign({},...ec.map(t=>t.tokens)),Xo={};for(const[t,n]of Object.entries(tc))Xo[t]=`var(--bim-${t}, ${n.value})`;function i(t){const n=Xo[t];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${t}`);return n}function _t(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function nc(t,n){return _t(t).includes(n)}const li={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},ic={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};i("quality-published"),i("quality-fine"),i("quality-rough"),i("quality-ocr");const Bt=h.createContext(null),Qo={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:i("check-fine-bg"),fg:i("check-fine-fg")},粗校:{label:"粗校",bg:i("check-rough-bg"),fg:i("check-rough-fg")},AI整理:{label:"AI整理",bg:i("check-ai-bg"),fg:i("check-ai-fg")}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入叢編",collectedIn:"收入叢編",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評註",studies:"所考典籍"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"結果分類",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},searchV4:{filterTitle:"篩選",dynasty:"朝代",classification:"部類",resources:"資源",extant:"存佚",clearAllFilters:"清除全部篩選",hasImage:"有影印",hasText:"有文本",hasCollated:"有文本",filterButton:"篩選",filterSelected:"{n} 項已選",expand:"展開",collapse:"收起",filteredCount:"篩出 {n} 條",removeFilter:"取消篩選:{name}",viewLabel:"結果視圖",viewTable:"表格",viewCard:"卡片",colTitle:"題名",colType:"類型",colAuthor:"責任者",colEra:"年代",colClass:"部類",colResource:"資源",tagImage:"影印",tagText:"文本",tagCollated:"文本",tagLost:"佚",pageInfo:"共 {total} 條 · 每頁 {size} 條 · 第 {page} / {pages} 頁",pagerLabel:"翻頁",prevPage:"上一頁",nextPage:"下一頁",emptyFiltered:"沒有找到匹配的條目。試試更短的書名、減少篩選,或切換繁 / 簡。",limitedNote:"各類只列前幾條,點上方分類頁籤看全部。",sortLabel:"排序",sortRelevance:"相關度",sortEra:"年代",sortTitle:"書名",sortEraAsc:"由早到晚",sortEraDesc:"由晚到早",sortTitleAsc:"拼音 A→Z",sortTitleDesc:"拼音 Z→A",onlyWorksNote:"部類、存佚只適用於作品;選了它們,版本、叢編、人物不參與。"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"概覽",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"文本",catalogSuffix:"·目錄",fullText:"文本",lineage:"版本傳承",feedback:"勘誤反饋",dataSource:"數據源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"數據源與授權"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},workSubtype:{book:"書",article:"篇",poem:"詩",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},rc={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:i("check-fine-bg"),fg:i("check-fine-fg")},粗校:{label:"粗校",bg:i("check-rough-bg"),fg:i("check-rough-fg")},AI整理:{label:"AI整理",bg:i("check-ai-bg"),fg:i("check-ai-fg")}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入丛编",collectedIn:"收入丛编",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评注",studies:"所考典籍"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"结果分类",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},searchV4:{filterTitle:"筛选",dynasty:"朝代",classification:"部类",resources:"资源",extant:"存佚",clearAllFilters:"清除全部筛选",hasImage:"有影印",hasText:"有文本",hasCollated:"有文本",filterButton:"筛选",filterSelected:"{n} 项已选",expand:"展开",collapse:"收起",filteredCount:"筛出 {n} 条",removeFilter:"取消筛选:{name}",viewLabel:"结果视图",viewTable:"表格",viewCard:"卡片",colTitle:"题名",colType:"类型",colAuthor:"责任者",colEra:"年代",colClass:"部类",colResource:"资源",tagImage:"影印",tagText:"文本",tagCollated:"文本",tagLost:"佚",pageInfo:"共 {total} 条 · 每页 {size} 条 · 第 {page} / {pages} 页",pagerLabel:"翻页",prevPage:"上一页",nextPage:"下一页",emptyFiltered:"没有找到匹配的条目。试试更短的书名、减少筛选,或切换繁 / 简。",limitedNote:"各类只列前几条,点上方分类页签看全部。",sortLabel:"排序",sortRelevance:"相关度",sortEra:"年代",sortTitle:"书名",sortEraAsc:"由早到晚",sortEraDesc:"由晚到早",sortTitleAsc:"拼音 A→Z",sortTitleDesc:"拼音 Z→A",onlyWorksNote:"部类、存佚只适用于作品;选了它们,版本、丛编、人物不参与。"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"概览",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"文本",catalogSuffix:"·目录",fullText:"文本",lineage:"版本传承",feedback:"勘误反馈",dataSource:"数据源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"数据源与授权"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},workSubtype:{book:"书",article:"篇",poem:"诗",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},oc=["曹霑"];function sc(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function lc(t,n=oc){const r=[...new Set(n.filter(Boolean))].sort((l,a)=>a.length-l.length);if(!r.length)return t;const o=new RegExp(`(${r.map(sc).join("|")})`,"g"),s=new Set(r);return l=>{if(!l)return t(l);const a=l.split(o);return a.length===1?t(l):a.map((p,c)=>c%2===1&&s.has(p)?p:p&&t(p)).join("")}}let Pt=null;function ac(){if(Pt)return Pt;try{Pt=lc(qa.Converter({from:"tw",to:"cn"}))}catch{Pt=t=>t}return Pt}const cc={"zh-Hant":Qo,"zh-Hans":rc},es="bim-locale";function dc(){try{const t=localStorage.getItem(es);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function pc(t){try{localStorage.setItem(es,t)}catch{}}const uc="zh-Hans",mc=({locale:t,onLocaleChange:n,converter:r,children:o})=>{const[s,l]=h.useState(t??uc),a=t??s;h.useEffect(()=>{if(t)return;const u=dc();u&&u!==s&&l(u)},[]);const p=h.useMemo(()=>a==="zh-Hans"?r??ac():null,[a,r]),c=h.useCallback(u=>{l(u),pc(u),n==null||n(u)},[n]),d=h.useMemo(()=>({locale:a,setLocale:c,messages:cc[a],converter:p}),[a,c,p]);return e.jsx(Bt.Provider,{value:d,children:o})};function fe(){const t=h.useContext(Bt);return(t==null?void 0:t.messages)??Qo}const xc=2e3;function O(){const t=h.useContext(Bt),n=(t==null?void 0:t.locale)??"zh-Hant",r=(t==null?void 0:t.converter)??null,o=h.useRef(new Map),s=h.useRef(n);s.current!==n&&(o.current.clear(),s.current=n);const l=h.useCallback(a=>{if(!a)return"";if(!r)return a;const p=o.current.get(a);if(p!==void 0)return p;const c=r(a);if(o.current.size>=xc){const d=o.current.keys().next().value;d!==void 0&&o.current.delete(d)}return o.current.set(a,c),c},[r]);return h.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function nt(t,n){return t.replace(/\{(\w+)\}/g,(r,o)=>String(n[o]??""))}function hc(t){if(!t)return"";try{const n=new URL(t).hostname,r={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(r[n])return r[n];const o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function gc(){return{id:"",name:"",url:"",type:"text",details:""}}const ai=({items:t,onChange:n,onDownload:r,downloadStatuses:o,filterType:s})=>{const l=fe(),[a,p]=h.useState(null),c=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],d=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=f=>{if(!s)return!0;const v=_t(f);return s==="text"?v.includes("text"):s==="image"?v.includes("image")||v.includes("physical"):s==="physical"?v.includes("physical"):v.includes(s)},x=t.map((f,v)=>({item:f,originalIndex:v})).filter(({item:f})=>u(f)),m=()=>{const f=gc();s&&(f.type=s),n([...t,f]),p(t.length)},g=f=>{n(t.filter((v,$)=>$!==f)),p(null)},b=(f,v,$)=>{const w=[...t];if(w[f]={...w[f],[v]:$},v==="url"&&!w[f].id){const _=hc($);_&&(w[f].id=_)}n(w)},k=(f,v,$)=>{const _={...t[f].metadata||{}};$?_[v]=$:delete _[v],b(f,"metadata",Object.keys(_).length>0?_:void 0)},y=(f,v)=>{const $=v.trim()?v.split(/[,,、]/).map(w=>w.trim()).filter(Boolean):void 0;b(f,"structure",$)},j=(f,v,$)=>{const _=t[f].coverage||{level:1,ranges:""};v==="level"?_.level=parseInt($)||1:_.ranges=$,b(f,"coverage",_.ranges?_:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:f,originalIndex:v})=>{var $,w,_;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(a===v?null:v),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===v?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:fc(f.type??"text"),color:i("on-color-fg")},children:(()=>{var z,E;const S=_t(f);return S.length===0?f.type??"text":S.length===1?((z=c.find(T=>T.value===S[0]))==null?void 0:z.label)??S[0]:S.includes("text")&&S.includes("image")?((E=c.find(T=>T.value==="text+image"))==null?void 0:E.label)??"text+image":S.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:f.name||`${l.editor.resourcePlaceholder} ${v+1}`}),f.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:f.id}),f.url&&e.jsx("a",{href:f.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),r&&f.url&&bc(v,o==null?void 0:o[v],r,l),e.jsx("button",{onClick:S=>{S.stopPropagation(),g(v)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),a===v&&e.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:[nc(f,"image")&&f.url&&yc(f,l),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Dt,children:[e.jsx("span",{style:Ht,children:l.label.type}),e.jsx("select",{value:f.type,onChange:S=>b(v,"type",S.target.value),style:{...rt,flex:1},children:c.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]}),e.jsxs("label",{style:Dt,children:[e.jsx("span",{style:Ht,children:l.label.rootType}),e.jsx("select",{value:f.root_type||"catalog",onChange:S=>b(v,"root_type",S.target.value),style:{...rt,flex:1},children:d.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:f.id,onChange:S=>b(v,"id",S.target.value),placeholder:l.editor.idAutoExtract,style:{...rt,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:f.name,onChange:S=>b(v,"name",S.target.value),placeholder:l.editor.resourceName,style:{...rt,flex:1}})]}),e.jsx("input",{type:"text",value:f.url,onChange:S=>b(v,"url",S.target.value),placeholder:l.editor.resourceUrl,style:rt}),e.jsx("input",{type:"text",value:(($=f.structure)==null?void 0:$.join("、"))||"",onChange:S=>y(v,S.target.value),placeholder:l.editor.structurePlaceholder,style:rt}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Dt,children:[e.jsx("span",{style:Ht,children:l.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((w=f.coverage)==null?void 0:w.level)??"",onChange:S=>j(v,"level",S.target.value),placeholder:"1",style:{...rt,width:"60px"}})]}),e.jsxs("label",{style:{...Dt,flex:1},children:[e.jsx("span",{style:Ht,children:l.label.coverageRange}),e.jsx("input",{type:"text",value:((_=f.coverage)==null?void 0:_.ranges)||"",onChange:S=>j(v,"ranges",S.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...rt,flex:1}})]})]}),e.jsx("textarea",{value:f.details||"",onChange:S=>b(v,"details",S.target.value),placeholder:l.editor.detailsPlaceholder,style:{...rt,minHeight:"60px",resize:"vertical"}}),e.jsxs("div",{style:{borderTop:`1px solid ${i("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"6px"},children:l.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([S,z])=>{var E;return e.jsxs("label",{style:{...Dt,gap:"4px"},children:[e.jsx("span",{style:{...Ht,minWidth:"56px"},children:z}),e.jsx("input",{type:"text",value:((E=f.metadata)==null?void 0:E[S])||"",onChange:T=>k(v,S,T.target.value),placeholder:z,style:{...rt,flex:1}})]},S)})})]})]})]})]},v)}),e.jsxs("button",{onClick:m,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:l.action.addResource})]})]})};function fc(t){switch(t){case"text":return i("restype-text");case"image":return i("restype-image");case"text+image":return i("restype-text-image");case"physical":return i("restype-physical")}}function bc(t,n,r,o){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:a=>{a.stopPropagation(),s||r(t,"")},disabled:s,style:{background:"transparent",border:"none",color:i(l?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:l?o.download.completed:s?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:l?"✓":s?"⏳":"⬇"})}function yc(t,n){const r=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:r?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:i("overlay-bg")},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:o=>{o.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:i("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:i("desc-fg")},children:n.editor.imageResourceLink})})}const rt={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Dt={display:"flex",alignItems:"center",gap:"6px"},Ht={fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap"},jc={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive","www.shuge.org":"書格","shuge.org":"書格","pan.baidu.com":"百度網盤"};function Mt(t){try{return jc[new URL(t).hostname]}catch{return}}const zr={text:0,image:1,physical:2};function Ni(t){return t.length===0?"physical":[...t].sort((n,r)=>(zr[n]??99)-(zr[r]??99)).join("+")}function Ii(t){var a;const n=p=>{const c=p.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const d=p.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},r=new Map;for(let p=0;p<t.length;p++){const c=t[p];if(c.volumes&&c.volumes.length>0)continue;const d=n(c.name);if(!d)continue;const[u,x]=d,m=`${u}|${Ni(_t(c))}`;r.has(m)||r.set(m,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const g=r.get(m);g.volumes.push({volume:x,url:c.url||void 0,status:"found"}),g.indices.push(p)}const o=[],s=new Set;for(const p of r.values())if(!(p.volumes.length<2)){p.volumes.sort((c,d)=>c.volume-d.volume),p.base.volumes=p.volumes,p.base.expected_volumes=p.volumes.length,p.base.url||(p.base.url=((a=p.volumes.find(c=>c.url))==null?void 0:a.url)??""),o.push(p.base);for(const c of p.indices)s.add(c)}const l=[...o];for(let p=0;p<t.length;p++)s.has(p)||l.push(t[p]);return l}function ts(t){if(t.url)return t.url;for(const[n,r]of Object.entries(t))if(n.endsWith("_url")&&typeof r=="string")return r}function ns(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||ts(n)}))}function _n(t){const n=ns(t);if(!n)return null;const r=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,o=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:r,missing:o,expected:t.expected_volumes??r+o}}function Ei(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const r=n.match(/^(\d+)/);return r?parseInt(r[1],10):void 0}function Ri(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const o=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(o)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(o[1]))}&page=${n}`;const s=new URL(t);return s.searchParams.set("page",String(n)),s.toString()}return t}catch{return t}}function Wt(t){if(!t.url)return;const n=Ei(t.metadata);return n?Ri(t.url,n):t.url}const Cr={text:i("restype-text"),image:i("restype-image"),"text+image":i("restype-text-image"),physical:i("restype-physical")};function vc(t){return t.includes("text")&&t.includes("image")?Cr["text+image"]:Cr[t[0]||"physical"]}const Li=({items:t,groupByType:n=!0,resourceGroups:r,onNavigate:o,renderLink:s})=>{const l=fe(),{convert:a}=O(),p=h.useMemo(()=>Ii(t||[]),[t]),{mirrorGroups:c,ungroupedItems:d}=h.useMemo(()=>{const y=new Map,j=[];for(const f of p){const v=f.group;v?(y.has(v)||y.set(v,[]),y.get(v).push(f)):j.push(f)}for(const f of y.values())f.sort((v,$)=>{const w=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return w(v)-w($)});return{mirrorGroups:y,ungroupedItems:j}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},x=y=>u[y]?u[y]:y.split("+").map(j=>u[j]||j).join("+");if(!p||p.length===0)return e.jsx("div",{style:{padding:"16px",color:i("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((y,j)=>e.jsx(Un,{item:y},y.id||j))});const m=(y,j)=>{const f=r==null?void 0:r[y],v=(f==null?void 0:f.label)||y,$=f==null?void 0:f.description;return e.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:a(v)}),$&&e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.5},children:a($)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((w,_)=>e.jsx(Un,{item:w,onNavigate:o,renderLink:s},w.id||_))})]},`group-${y}`)},g=new Map;for(const y of d){const j=Ni(_t(y));g.has(j)||g.set(j,[]),g.get(j).push(y)}const b=["text","image","text+image","physical"],k=[...b.filter(y=>g.has(y)),...[...g.keys()].filter(y=>!b.includes(y)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([y,j])=>m(y,j)),k.map(y=>{const j=g.get(y),f=vc(y.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:f,whiteSpace:"nowrap",flexShrink:0},children:x(y)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((v,$)=>e.jsx(Un,{item:v,onNavigate:o,renderLink:s},v.id||$))})]},y)})]})},kc={bw:{label:"",bg:i("colormode-bw-bg"),fg:i("colormode-bw-fg")},color:{label:"",bg:i("colormode-color-bg"),fg:i("colormode-color-fg")}},Un=({item:t})=>{const n=fe(),{convert:r}=O(),[o,s]=h.useState(!1),l=h.useMemo(()=>(t.url?Mt(t.url):void 0)||r(t.name),[t.url,t.name,r]),a=h.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(b=>({...b,url:b.url||ts(b)})),[t.volumes]),p=a&&a.length>0,c=p?new Set(a.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=p?new Set(a.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=t.expected_volumes??(p?c+d:0),x=t.color_mode?{...kc[t.color_mode],label:n.colorMode[t.color_mode]}:null,m=t.details&&!p?r(t.details):null,g={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",background:i("input-bg"),fontSize:"12px",color:i("fg"),lineHeight:1.4,verticalAlign:"middle"};return e.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[e.jsxs("div",{style:g,children:[e.jsx("span",{style:{fontWeight:500},children:l}),x&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),m&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:m}),p&&e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[c,"/",u,n.unit.volume,d>0&&e.jsxs("span",{style:{color:i("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const b=Ei(t.metadata);return b?Ri(t.url,b):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:i("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),p&&e.jsx("button",{onClick:()=>s(!o),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",lineHeight:1.4},children:o?"▲":"▼"})]}),p&&o&&e.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:a.map(b=>{const k=b.status==="missing";return b.url&&!k?e.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${i("widget-border")}`,color:i("link-fg"),textDecoration:"none"},children:b.volume},b.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:i(k?"missing-fg":"desc-fg"),textDecoration:k?"line-through":"none",opacity:k?.6:1},children:b.volume},b.volume)})})]})},is=({indexSource:t,syncConfig:n,variant:r="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:l,onSelectFolder:a})=>{const p=fe(),c=t==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",x=u?u.split(/[/\\]/).pop()||u:"",m={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:i("primary-soft"),color:i("primary")},g={onMouseOver:k=>k.currentTarget.style.opacity="0.8",onMouseOut:k=>k.currentTarget.style.opacity="1"},b=e.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...m,background:i(d?"warning":"success"),color:i("on-color-fg")},...g,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return r==="index-browser"?c?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:o,title:p.mode.switchToSync,style:m,...g,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:p.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...m,paddingLeft:"8px",paddingRight:"8px"},...g,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:o,title:p.mode.switchToLocal,style:m,...g,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:p.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:l,title:x||p.mode.configurePath,style:{...m,background:"transparent",padding:"6px",fontSize:"12px"},...g,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:c?p.mode.switchToGithub:p.mode.switchToLocal,style:m,...g,children:[e.jsx("span",{children:c?"📁":"🌐"}),e.jsx("span",{children:c?p.mode.localMode:p.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&e.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...m,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...g,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!c&&x&&e.jsxs("div",{style:{...m,background:i("mode-active-bg"),color:i("on-color-fg"),cursor:"default"},title:u,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},zn="bim-search-history",Tr=10,Nr=8;function Zt(){try{const t=localStorage.getItem(zn);return t?JSON.parse(t):[]}catch{return[]}}function wc(t){try{const n=Zt().filter(r=>r!==t);n.unshift(t),n.length>Tr&&(n.length=Tr),localStorage.setItem(zn,JSON.stringify(n))}catch{}}function Sc(t){try{const n=Zt().filter(r=>r!==t);localStorage.setItem(zn,JSON.stringify(n))}catch{}}function $c(){try{localStorage.removeItem(zn)}catch{}}const rs=({transport:t,value:n,onChange:r,onSearch:o,onEntrySelect:s,placeholder:l})=>{const a=fe(),p=l??a.search.placeholder,c={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,u]=h.useState(!1),[x,m]=h.useState([]),[g,b]=h.useState(-1),[k,y]=h.useState(Zt),j=h.useRef(null),f=h.useRef(null),v=h.useRef(null),$=h.useRef(!1);h.useEffect(()=>{b(-1);const N=n.trim();if(!N){m(k.map(B=>({type:"history",text:B})));return}if(!t.searchAll){m([]);return}let V=!1;const W=setTimeout(()=>{t.searchAll(N,Nr).then(B=>{if(V)return;const H=[...B.works,...B.books,...B.collections,...B.entities??[]];m(H.slice(0,Nr).map(te=>({type:"entry",text:te.title||te.id,entry:te})))}).catch(()=>{V||m([])})},80);return()=>{V=!0,clearTimeout(W)}},[n,k,t]),h.useEffect(()=>{const N=V=>{v.current&&!v.current.contains(V.target)&&u(!1)};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[]),h.useEffect(()=>{const N=V=>{var W,B;if(V.key==="/"&&document.activeElement!==j.current){const H=(W=document.activeElement)==null?void 0:W.tagName;if(H==="INPUT"||H==="TEXTAREA"||H==="SELECT")return;V.preventDefault(),(B=j.current)==null||B.focus()}};return document.addEventListener("keydown",N),()=>document.removeEventListener("keydown",N)},[]);const w=h.useCallback(N=>{N.trim()&&(wc(N.trim()),y(Zt())),o(N),u(!1)},[o]),_=h.useCallback(N=>{N.type==="history"?(r(N.text),w(N.text)):N.entry&&(s?(s(N.entry),u(!1)):(r(N.text),w(N.text)))},[r,w,s]),S=h.useCallback(N=>{if(!d||x.length===0){N.key==="Enter"&&w(n);return}switch(N.key){case"ArrowDown":N.preventDefault(),b(V=>(V+1)%x.length);break;case"ArrowUp":N.preventDefault(),b(V=>(V-1+x.length)%x.length);break;case"Enter":N.preventDefault(),g>=0&&g<x.length?_(x[g]):w(n);break;case"Escape":N.preventDefault(),u(!1);break}},[d,x,g,n,w,_]),z=h.useCallback((N,V)=>{V.stopPropagation(),Sc(N),y(Zt()),m(W=>W.filter(B=>!(B.type==="history"&&B.text===N)))},[]),E=h.useCallback(N=>{N.stopPropagation(),$c(),y([]),m([])},[]);h.useEffect(()=>{if(g>=0&&f.current){const N=f.current.children;N[g]&&N[g].scrollIntoView({block:"nearest"})}},[g]);const T=!n.trim()&&k.length>0;return e.jsxs("div",{ref:v,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:j,type:"text",placeholder:p,value:n,onChange:N=>{r(N.target.value),u(!0)},onCompositionStart:()=>{$.current=!0},onCompositionEnd:()=>{$.current=!1},onFocus:()=>{u(!0)},onKeyDown:S,style:{width:"100%",padding:"8px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),d&&x.length>0&&e.jsxs("div",{ref:f,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:i("input-bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"6px",boxShadow:i("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[T&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:i("desc-fg"),borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsx("span",{children:a.search.history}),e.jsx("button",{onClick:E,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),x.map((N,V)=>e.jsxs("div",{onClick:()=>_(N),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:i("fg"),background:V===g?i("list-active-bg"):"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:N.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N.text}),N.entry&&e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:[c[N.entry.type],N.entry.edition&&` · ${N.entry.edition}`,N.entry.author&&` · ${N.entry.author}`]}),N.type==="history"&&e.jsx("button",{onClick:W=>z(N.text,W),style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${N.type}-${N.text}-${V}`))]})]})},Ot=({type:t,size:n=9})=>e.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:n,borderRadius:1,flex:"none",background:i(`type-${t}`),verticalAlign:"middle"}}),Cn={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},os=new Set(["work","book","entity"]);function _c(t){return ls(t)||!!t.sort}function zc(t,n){return n.sort&&os.has(t)?n.sort:void 0}const Tn=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Nn=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Ai=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],ss={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function In(t){return t.dynasty.length+t.classification.length+(t.hasImage?1:0)+(t.hasText?1:0)+(t.hasCollated?1:0)+(t.loss?1:0)}function ls(t){return In(t)>0}function Cc(t){const n=[];return t.dynasty.length&&n.push("dynasty"),t.classification.length&&n.push("classification"),t.hasImage&&n.push("hasImage"),t.hasText&&n.push("hasText"),t.hasCollated&&n.push("hasCollated"),t.loss&&n.push("loss"),n}function as(t,n){const r=ss[t];return Cc(n).every(o=>r.has(o))}const Gt=t=>JSON.stringify(t);function Tc(t,n){if(!as(n,t))return null;const r=[];if(t.dynasty.length){const o=Array.from(new Set(t.dynasty.flatMap(s=>{var l;return((l=Tn.find(a=>a.key===s))==null?void 0:l.values)??[]})));o.length===1?r.push(`dynasty = ${Gt(o[0])}`):o.length>1&&r.push(`dynasty IN [${o.map(Gt).join(", ")}]`)}return t.classification.length&&r.push(t.classification.length===1?`classification = ${Gt(t.classification[0])}`:`classification IN [${t.classification.map(Gt).join(", ")}]`),t.hasImage&&r.push("has_image = true"),t.hasText&&r.push("has_text = true"),t.hasCollated&&r.push("has_collated = true"),t.loss&&r.push(`loss_status = ${Gt(t.loss)}`),r.join(" AND ")}const Ye={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},cs="_";function yn(t,n=new URLSearchParams){for(const r of Object.values(Ye))n.delete(r);return t.dynasty.length&&n.set(Ye.dynasty,t.dynasty.join(",")),t.classification.length&&n.set(Ye.classification,t.classification.map(r=>r||cs).join(",")),t.hasImage&&n.set(Ye.hasImage,"1"),t.hasText&&n.set(Ye.hasText,"1"),t.hasCollated&&n.set(Ye.hasCollated,"1"),t.loss&&n.set(Ye.loss,t.loss),t.sort&&n.set(Ye.sort,t.sort),n}function Nc(t){const n=l=>(t.get(l)??"").split(",").map(a=>a.trim()).filter(Boolean),r=new Set(Tn.map(l=>l.key)),o=new Set(Nn.map(l=>l.value)),s=t.get(Ye.loss);return{dynasty:Array.from(new Set(n(Ye.dynasty).filter(l=>r.has(l)))),classification:Array.from(new Set(n(Ye.classification).map(l=>l===cs?"":l).filter(l=>o.has(l)))),hasImage:t.get(Ye.hasImage)==="1",hasText:t.get(Ye.hasText)==="1"||t.get(Ye.hasCollated)==="1",hasCollated:!1,loss:s==="extant"||s==="partially_extant"||s==="lost"?s:"",sort:["era:asc","era:desc","title:asc","title:desc"].find(l=>l===t.get(Ye.sort))??""}}function Ic(t,n){return JSON.stringify([t.dynasty.slice().sort(),t.classification.slice().sort(),t.hasImage,t.hasText,t.hasCollated,t.loss,t.sort])===JSON.stringify([n.dynasty.slice().sort(),n.classification.slice().sort(),n.hasImage,n.hasText,n.hasCollated,n.loss,n.sort])}function Ir(t,n){return t.includes(n)?t.filter(r=>r!==n):[...t,n]}const Ec=({filters:t,onChange:n})=>{const r=fe().searchV4,{convert:o}=O(),[s,l]=h.useState(!1),a=h.useId(),p=In(t),c=d=>n({...t,...d});return e.jsxs("aside",{className:"bim-sr-aside","aria-label":o(r.filterTitle),children:[e.jsxs("button",{type:"button",className:"bim-sr-fbtn","aria-expanded":s,"aria-controls":a,onClick:()=>l(d=>!d),children:[e.jsxs("span",{children:[o(r.filterButton),p>0&&e.jsx("span",{className:"bim-sr-fn",children:o(nt(r.filterSelected,{n:p}))})]}),e.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[o(s?r.collapse:r.expand)," ",s?"▴":"▾"]})]}),e.jsxs("div",{className:"bim-sr-filters",id:a,"data-open":s?"true":"false",...s?{}:{"data-collapsed":"true"},children:[e.jsxs("section",{className:"bim-sr-fg",children:[e.jsx("h3",{children:o(r.dynasty)}),e.jsx("div",{className:"bim-sr-chips",children:Tn.map(d=>e.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":t.dynasty.includes(d.key),onClick:()=>c({dynasty:Ir(t.dynasty,d.key)}),children:o(d.key)},d.key))})]}),e.jsxs("section",{className:"bim-sr-fg",children:[e.jsx("h3",{children:o(r.classification)}),Nn.map(d=>e.jsxs("label",{className:"bim-sr-opt",children:[e.jsx("input",{type:"checkbox",checked:t.classification.includes(d.value),onChange:()=>c({classification:Ir(t.classification,d.value)})}),o(d.label)]},d.value||"_"))]}),e.jsxs("section",{className:"bim-sr-fg",children:[e.jsx("h3",{children:o(r.resources)}),e.jsxs("label",{className:"bim-sr-opt",children:[e.jsx("input",{type:"checkbox",checked:t.hasImage,onChange:d=>c({hasImage:d.target.checked})}),o(r.hasImage)]}),e.jsxs("label",{className:"bim-sr-opt",children:[e.jsx("input",{type:"checkbox",checked:t.hasText,onChange:d=>c({hasText:d.target.checked})}),o(r.hasText)]})]}),e.jsxs("section",{className:"bim-sr-fg",children:[e.jsx("h3",{id:`${a}-loss`,children:o(r.extant)}),e.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${a}-loss`,children:Ai.map(d=>e.jsx("button",{type:"button","aria-pressed":t.loss===d.value,onClick:()=>c({loss:d.value}),children:o(d.label)},d.value||"all"))})]}),e.jsx("p",{className:"bim-sr-note",children:o(r.onlyWorksNote)}),p>0&&e.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>n({...Cn,sort:t.sort}),children:o(r.clearAllFilters)})]})]})};function ds({text:t,query:n}){const r=(n??"").trim();if(!r||!t)return e.jsx(e.Fragment,{children:t});const o=t.toLowerCase(),s=r.toLowerCase(),l=[];let a=0,p=0;for(;a<t.length;){const c=o.indexOf(s,a);if(c<0){l.push(t.slice(a));break}c>a&&l.push(t.slice(a,c)),l.push(e.jsx("mark",{className:"bim-sr-hl",children:t.slice(c,c+s.length)},p++)),a=c+s.length}return e.jsx(e.Fragment,{children:l})}const Er=({entries:t,query:n,onEntryLinkClick:r,typeName:o})=>{const s=fe(),l=s.searchV4,{convert:a}=O(),p=He();return e.jsx("div",{className:"bim-sr-tablewrap",children:e.jsxs("table",{className:"bim-sr-table",children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"34%"}}),e.jsx("col",{style:{width:"8%"}}),e.jsx("col",{style:{width:"19%"}}),e.jsx("col",{style:{width:"13%"}}),e.jsx("col",{style:{width:"12%"}}),e.jsx("col",{style:{width:"14%"}})]}),e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:a(l.colTitle)}),e.jsx("th",{scope:"col",children:a(l.colType)}),e.jsx("th",{scope:"col",children:a(l.colAuthor)}),e.jsx("th",{scope:"col",children:a(l.colEra)}),e.jsx("th",{scope:"col",children:a(l.colClass)}),e.jsx("th",{scope:"col",style:{textAlign:"right"},children:a(l.colResource)})]})}),e.jsx("tbody",{children:t.map(c=>{const d=a(c.title||c.primary_name||c.id),u=c.measure_info?a(c.measure_info):c.juan_count?`${c.juan_count}${s.unit.juan}`:"",x=c.type==="entity"?[c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:""].filter(Boolean).join(""):c.author?`${a(c.author)}${c.role&&c.role!=="author"?` ${a(c.role)}`:""}`:"",m=c.type==="book"?c.era??c.dynasty:c.dynasty,g=m?a(m):"",b=c.classification?a(c.classification):"",k=[];c.has_image&&k.push({label:l.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&k.push({label:l.tagText,cls:""}),c.loss_status==="lost"&&k.push({label:l.tagLost,cls:"bim-sr-tag--lost"});const y=[x,g,b].filter(Boolean).join(" · ");return e.jsxs("tr",{children:[e.jsxs("td",{className:"bim-sr-c-title",children:[e.jsxs("div",{className:"bim-sr-tl",children:[e.jsx("a",{href:p(c.id),onClick:j=>r(c,j),children:e.jsx(ds,{text:d,query:n?a(n):void 0})}),u&&e.jsx("span",{className:"bim-sr-measure",children:u})]}),y&&e.jsx("span",{className:"bim-sr-sub",children:y})]}),e.jsxs("td",{className:"bim-sr-c-type",children:[e.jsx(Ot,{type:c.type,size:6})," ",o(c.type)]}),e.jsx("td",{className:"bim-sr-c-who",children:x||"—"}),e.jsx("td",{className:"bim-sr-c-era",children:g||"—"}),e.jsx("td",{className:"bim-sr-c-cls",children:b||"—"}),e.jsx("td",{className:"bim-sr-c-res",children:k.map(j=>e.jsx("span",{className:`bim-sr-tag ${j.cls}`,children:a(j.label)},j.label))})]},c.id)})})]})})},Rc=`
2
2
  .bim-sc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 10px; }
3
3
  .bim-sc { display: flex; flex-direction: column; min-width: 0; padding: 14px 16px 12px; border: 1px solid ${i("rule")}; background: ${i("card-bg")}; color: inherit; text-decoration: none; }
4
4
  .bim-sc:hover { border-color: ${i("rule-dashed")}; box-shadow: ${i("fr-shadow")}; }
@@ -12,7 +12,7 @@
12
12
  .bim-sc-fl { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: ${i("aux-fg")}; }
13
13
  .bim-sc-tags { display: flex; gap: 4px; flex: none; }
14
14
  :root[data-layout="boxed"] .bim-sc { box-shadow: none; }
15
- `,Nr=({entries:t,query:n,onEntryLinkClick:r,typeName:o})=>{const s=fe(),l=s.searchV4,{convert:a}=F(),p=He();return e.jsxs("div",{className:"bim-sc-grid",children:[e.jsx("style",{children:Tc}),t.map(c=>{const d=a(c.title||c.primary_name||c.id),u=c.measure_info?a(c.measure_info):c.juan_count?`${c.juan_count}${s.unit.juan}`:"",m=[c.type==="entity"?c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:"":`${c.dynasty?`〔${a(c.dynasty)}〕`:""}${c.author?a(c.author):""}`,c.type==="book"&&c.edition?a(c.edition):"",u].filter(Boolean).join(" · "),g=[o(c.type),c.classification?a(c.classification):""].filter(Boolean).join(" · "),b=[];return c.has_image&&b.push({label:l.tagImage,cls:"bim-sr-tag--img"}),c.has_text&&b.push({label:l.tagText,cls:""}),c.has_collated&&b.push({label:l.tagCollated,cls:""}),c.loss_status==="lost"&&b.push({label:l.tagLost,cls:"bim-sr-tag--lost"}),e.jsxs("a",{className:"bim-sc",href:p(c.id),onClick:k=>r(c,k),children:[e.jsx("span",{className:"bim-sc-t",children:e.jsx(ls,{text:d,query:n?a(n):void 0})}),m&&e.jsx("span",{className:"bim-sc-m",children:m}),c.descriptionSnippet&&e.jsx("p",{className:"bim-sc-s",children:Ci(c.descriptionSnippet).map((k,y)=>k.marked?e.jsx("mark",{children:a(k.text)},y):e.jsx(h.Fragment,{children:a(k.text)},y))}),e.jsx("span",{className:"bim-sc-sp"}),e.jsxs("div",{className:"bim-sc-f",children:[e.jsx("span",{className:"bim-sc-fl",children:g}),e.jsx("span",{className:"bim-sc-tags",children:b.map(k=>e.jsx("span",{className:`bim-sr-tag ${k.cls}`,children:a(k.label)},k.label))})]})]},c.id)})]})};function Nc(t,n){const r=new Set([1,n,t-1,t,t+1].filter(l=>l>=1&&l<=n)),o=Array.from(r).sort((l,a)=>l-a),s=[];return o.forEach((l,a)=>{a>0&&l-o[a-1]>1&&s.push("gap"),s.push(l)}),s}function Ic(t,n,r){const o=Math.max(1,Math.ceil(n/r));return Math.min(Math.max(1,t),o)}const Ec=({page:t,pageSize:n,total:r,onPage:o})=>{const s=fe().searchV4,{convert:l}=F(),a=Math.max(1,Math.ceil(r/n));return r<=0?null:e.jsxs("nav",{className:"bim-sr-pager","aria-label":l(s.pagerLabel),children:[e.jsx("span",{className:"bim-sr-info",children:l(nt(s.pageInfo,{total:r.toLocaleString(),size:n,page:t,pages:a}))}),a>1&&e.jsxs("ul",{children:[e.jsx("li",{children:e.jsx("button",{type:"button",disabled:t<=1,onClick:()=>o(t-1),children:l(s.prevPage)})}),Nc(t,a).map((p,c)=>p==="gap"?e.jsx("li",{className:"bim-sr-gap","aria-hidden":"true",children:"…"},`g${c}`):e.jsx("li",{children:e.jsx("button",{type:"button","aria-current":p===t?"page":void 0,"aria-label":`${p}`,onClick:()=>o(p),children:p})},p)),e.jsx("li",{children:e.jsx("button",{type:"button",disabled:t>=a,onClick:()=>o(t+1),children:l(s.nextPage)})})]})]})},as="(max-width: 719px)",Rc=`${as}, (pointer: coarse)`,Lc=`
15
+ `,Rr=({entries:t,query:n,onEntryLinkClick:r,typeName:o})=>{const s=fe(),l=s.searchV4,{convert:a}=O(),p=He();return e.jsxs("div",{className:"bim-sc-grid",children:[e.jsx("style",{children:Rc}),t.map(c=>{const d=a(c.title||c.primary_name||c.id),u=c.measure_info?a(c.measure_info):c.juan_count?`${c.juan_count}${s.unit.juan}`:"",m=[c.type==="entity"?c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:"":`${c.dynasty?`〔${a(c.dynasty)}〕`:""}${c.author?a(c.author):""}`,c.type==="book"&&c.edition?a(c.edition):"",u].filter(Boolean).join(" · "),g=[o(c.type),c.classification?a(c.classification):""].filter(Boolean).join(" · "),b=[];return c.has_image&&b.push({label:l.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&b.push({label:l.tagText,cls:""}),c.loss_status==="lost"&&b.push({label:l.tagLost,cls:"bim-sr-tag--lost"}),e.jsxs("a",{className:"bim-sc",href:p(c.id),onClick:k=>r(c,k),children:[e.jsx("span",{className:"bim-sc-t",children:e.jsx(ds,{text:d,query:n?a(n):void 0})}),m&&e.jsx("span",{className:"bim-sc-m",children:m}),c.descriptionSnippet&&e.jsx("p",{className:"bim-sc-s",children:Ti(c.descriptionSnippet).map((k,y)=>k.marked?e.jsx("mark",{children:a(k.text)},y):e.jsx(h.Fragment,{children:a(k.text)},y))}),e.jsx("span",{className:"bim-sc-sp"}),e.jsxs("div",{className:"bim-sc-f",children:[e.jsx("span",{className:"bim-sc-fl",children:g}),e.jsx("span",{className:"bim-sc-tags",children:b.map(k=>e.jsx("span",{className:`bim-sr-tag ${k.cls}`,children:a(k.label)},k.label))})]})]},c.id)})]})};function Lc(t,n){const r=new Set([1,n,t-1,t,t+1].filter(l=>l>=1&&l<=n)),o=Array.from(r).sort((l,a)=>l-a),s=[];return o.forEach((l,a)=>{a>0&&l-o[a-1]>1&&s.push("gap"),s.push(l)}),s}function Ac(t,n,r){const o=Math.max(1,Math.ceil(n/r));return Math.min(Math.max(1,t),o)}const Bc=({page:t,pageSize:n,total:r,onPage:o})=>{const s=fe().searchV4,{convert:l}=O(),a=Math.max(1,Math.ceil(r/n));return r<=0?null:e.jsxs("nav",{className:"bim-sr-pager","aria-label":l(s.pagerLabel),children:[e.jsx("span",{className:"bim-sr-info",children:l(nt(s.pageInfo,{total:r.toLocaleString(),size:n,page:t,pages:a}))}),a>1&&e.jsxs("ul",{children:[e.jsx("li",{children:e.jsx("button",{type:"button",disabled:t<=1,onClick:()=>o(t-1),children:l(s.prevPage)})}),Lc(t,a).map((p,c)=>p==="gap"?e.jsx("li",{className:"bim-sr-gap","aria-hidden":"true",children:"…"},`g${c}`):e.jsx("li",{children:e.jsx("button",{type:"button","aria-current":p===t?"page":void 0,"aria-label":`${p}`,onClick:()=>o(p),children:p})},p)),e.jsx("li",{children:e.jsx("button",{type:"button",disabled:t>=a,onClick:()=>o(t+1),children:l(s.nextPage)})})]})]})},ps="(max-width: 719px)",Mc=`${ps}, (pointer: coarse)`,Wc=`
16
16
  .bim-sr-layout { display: grid; grid-template-columns: 208px minmax(0, 1fr); column-gap: 40px; align-items: start; padding: 0 20px; }
17
17
  .bim-sr-layout[data-nofilters] { grid-template-columns: minmax(0, 1fr); }
18
18
  .bim-sr-aside { position: sticky; top: calc(${i("reader-top")} + 16px); padding-top: 2px; }
@@ -81,7 +81,7 @@
81
81
  .bim-sr-pager .bim-sr-gap { color: ${i("aux-fg")}; padding: 0 2px; }
82
82
  .bim-sr-empty { padding: 60px 0; text-align: center; font-size: 14px; color: ${i("meta-fg")}; }
83
83
 
84
- @media ${as} {
84
+ @media ${ps} {
85
85
  .bim-sr-layout { grid-template-columns: minmax(0, 1fr); row-gap: 16px; padding: 0 16px; }
86
86
  .bim-sr-aside { position: static; }
87
87
  .bim-sr-fbtn {
@@ -102,7 +102,7 @@
102
102
  .bim-sr-table td.bim-sr-c-res { text-align: left; padding-bottom: 2px; }
103
103
  .bim-sr-table td.bim-sr-c-res:empty { display: none; }
104
104
  }
105
- @media ${Rc} {
105
+ @media ${Mc} {
106
106
  .bim-sr-chip { min-height: 36px; }
107
107
  .bim-sr-opt { min-height: 44px; }
108
108
  .bim-sr-seg button { min-height: 44px; }
@@ -117,29 +117,29 @@
117
117
  :root[data-layout="boxed"] .bim-sr-table th { background: ${i("fr-bg")}; }
118
118
  /* 墨:强调色≈正文色,标题链接另加下划线 */
119
119
  :root[data-theme="ink"] .bim-sr-table td.bim-sr-c-title a { text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); text-underline-offset: 3px; }
120
- `,Ai="bim-search-view",Un=50,Ir=5,Er=1e3,Rr=["work","collection","book","entity"],Ac={work:"works",collection:"collections",book:"books",entity:"entities"},Bc={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function Mc(){try{return window.localStorage.getItem(Ai)==="card"?"card":"table"}catch{return"table"}}function Wc(t){try{window.localStorage.setItem(Ai,t)}catch{}}const Vt=(t,n)=>(t==null?void 0:t[Bc[n]])??0,Vn=(t,n)=>(t==null?void 0:t[Ac[n]])??[],cs=({transport:t,query:n,filters:r,onFiltersChange:o,onEntryLinkClick:s,typeName:l})=>{const a=fe(),p=a.searchV4,{convert:c}=F(),d=!!t.supportsSearchFilters,u=h.useMemo(()=>d?r:Cn,[d,r]),[x,m]=h.useState("table");h.useEffect(()=>{m(Mc())},[]);const g=A=>{m(A),Wc(A)},[b,k]=h.useState("all"),[y,j]=h.useState(1),[f,v]=h.useState(null),[$,w]=h.useState(null),[_,S]=h.useState(!1),[z,E]=h.useState(""),T=yn(u).toString(),N=In(u)>0,V=yn({...u,sort:""}).toString(),W=h.useRef({query:n,filterOnlyKey:V,sort:u.sort});h.useEffect(()=>{const A=W.current;A.query!==n||A.filterOnlyKey!==V?(k("all"),j(1)):A.sort!==u.sort&&j(1),W.current={query:n,filterOnlyKey:V,sort:u.sort}},[n,V,u.sort]),h.useEffect(()=>{let A=!1;return S(!0),E(""),(async()=>{try{let ne;if(t.searchAll)ne=await t.searchAll(n,Ir,u);else{const de=["work","book","collection","entity"],G=await Promise.all(de.map(he=>t.search(n,he,{page:1,pageSize:Ir,filters:u})));ne={works:G[0].entries,books:G[1].entries,collections:G[2].entries,entities:G[3].entries,totalWorks:G[0].total,totalBooks:G[1].total,totalCollections:G[2].total,totalEntities:G[3].total}}A||v(ne)}catch(ne){A||(E(ne instanceof Error?ne.message:String(ne)),v(null))}finally{A||S(!1)}})(),()=>{A=!0}},[t,n,T]),h.useEffect(()=>{if(b==="all"){w(null);return}let A=!1;return S(!0),(async()=>{try{const ne=await t.search(n,b,{page:y,pageSize:Un,filters:u});A||w({entries:ne.entries,total:ne.total})}catch(ne){A||(E(ne instanceof Error?ne.message:String(ne)),w(null))}finally{A||S(!1)}})(),()=>{A=!0}},[t,n,T,b,y]),h.useEffect(()=>{if(b==="all"||!$||_)return;const A=Math.min($.total,Er),ne=Ic(y,A,Un);$.entries.length===0&&A>0&&ne!==y&&j(ne)},[b,$,_,y]);const B=h.useMemo(()=>Rr.filter(A=>Vt(f,A)>0),[f]),H=B.reduce((A,ne)=>A+Vt(f,ne),0),te=!_&&!z&&f!==null&&H===0,se=h.useCallback(A=>{k(A),j(1)},[]),J=h.useMemo(()=>{var ne;const A=[];return u.dynasty.forEach(de=>A.push({name:de,remove:()=>o({...u,dynasty:u.dynasty.filter(G=>G!==de)})})),u.classification.forEach(de=>{var G;return A.push({name:((G=Nn.find(he=>he.value===de))==null?void 0:G.label)??de,remove:()=>o({...u,classification:u.classification.filter(he=>he!==de)})})}),u.hasImage&&A.push({name:p.hasImage,remove:()=>o({...u,hasImage:!1})}),u.hasText&&A.push({name:p.hasText,remove:()=>o({...u,hasText:!1})}),u.hasCollated&&A.push({name:p.hasCollated,remove:()=>o({...u,hasCollated:!1})}),u.loss&&A.push({name:`${p.extant}:${((ne=Li.find(de=>de.value===u.loss))==null?void 0:ne.label)??""}`,remove:()=>o({...u,loss:""})}),A},[u,o,p]),D={query:n,onEntryLinkClick:s,typeName:l},L=A=>x==="table"?e.jsx(Tr,{entries:A,...D}):e.jsx(Nr,{entries:A,...D}),le=Rr.flatMap(A=>Vn(f,A));return e.jsxs("div",{className:"bim-sr-layout","data-nofilters":d?void 0:"true",children:[e.jsx("style",{children:Lc}),d&&e.jsx(Cc,{filters:u,onChange:o}),e.jsxs("div",{className:"bim-sr-main","aria-busy":_,children:[B.length>0&&e.jsxs("div",{className:"bim-sr-tabs",role:"group","aria-label":a.search.resultTabs,style:{display:"flex",flexWrap:"wrap",gap:"0 4px",borderBottom:`1px solid ${i("rule")}`},children:[e.jsxs(Lr,{on:b==="all",onClick:()=>se("all"),children:[a.search.allTab," ",e.jsx("small",{children:H.toLocaleString()})]}),B.map(A=>e.jsxs(Lr,{on:b===A,onClick:()=>se(A),children:[l(A)," ",e.jsx("small",{children:Vt(f,A).toLocaleString()})]},A))]}),e.jsxs("div",{className:"bim-sr-tools",children:[d&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":c(p.sortLabel),children:[e.jsx("button",{type:"button","aria-pressed":!u.sort,onClick:()=>o({...u,sort:""}),children:c(p.sortRelevance)}),["era","title"].map(A=>{const ne=u.sort.startsWith(`${A}:`)?u.sort.endsWith("desc")?"desc":"asc":null,de=A==="era"?p.sortEra:p.sortTitle,G=A==="era"?ne==="desc"?p.sortEraDesc:p.sortEraAsc:ne==="desc"?p.sortTitleDesc:p.sortTitleAsc;return e.jsxs("button",{type:"button","aria-pressed":ne!==null,title:c(G),onClick:()=>o({...u,sort:`${A}:${ne==="asc"?"desc":"asc"}`}),children:[c(de),ne?e.jsxs("span",{"aria-hidden":"true",children:[" ",ne==="asc"?"↑":"↓"]}):null]},A)})]}),e.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),e.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":c(p.viewLabel),children:[e.jsx("button",{type:"button","aria-pressed":x==="table",onClick:()=>g("table"),children:c(p.viewTable)}),e.jsx("button",{type:"button","aria-pressed":x==="card",onClick:()=>g("card"),children:c(p.viewCard)})]})]}),N&&e.jsxs("div",{className:"bim-sr-chips-row",children:[e.jsx("span",{className:"bim-sr-count",role:"status",children:c(nt(p.filteredCount,{n:H.toLocaleString()}))}),J.map(A=>e.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":c(nt(p.removeFilter,{name:A.name})),onClick:A.remove,children:[c(A.name),e.jsx("span",{"aria-hidden":"true",children:"×"})]},A.name))]}),z&&e.jsx("div",{className:"bim-sr-empty",role:"alert",children:z}),te&&e.jsx("div",{className:"bim-sr-empty",children:c(N?p.emptyFiltered:nt(a.search.noResultsFor,{query:n}))}),!z&&!te&&b==="all"&&f&&(x==="table"?e.jsxs(e.Fragment,{children:[e.jsx(Tr,{entries:le,...D}),e.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:c(p.limitedNote)})]}):e.jsx(e.Fragment,{children:B.map(A=>e.jsxs("section",{style:{marginTop:22},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[e.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[e.jsx(Ft,{type:A,size:8}),l(A),e.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:i("meta-fg")},children:[Vt(f,A).toLocaleString()," ",a.unit.items]})]}),Vt(f,A)>Vn(f,A).length&&e.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>se(A),children:a.action.viewAll})]}),e.jsx(Nr,{entries:Vn(f,A),...D})]},A))})),!z&&b!=="all"&&$&&$.entries.length>0&&e.jsxs(e.Fragment,{children:[L($.entries),e.jsx(Ec,{page:y,pageSize:Un,total:Math.min($.total,Er),onPage:j})]}),!z&&b!=="all"&&$&&$.entries.length===0&&!_&&e.jsxs("div",{className:"bim-sr-empty",children:[c(N?p.emptyFiltered:nt(a.search.noResultsFor,{query:n})),e.jsx("div",{children:e.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>se("all"),children:a.search.allTab})})]})]})]})};function Lr({on:t,onClick:n,children:r}){return e.jsx("button",{type:"button","aria-pressed":t,onClick:n,style:{border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:14.5,minHeight:44,padding:"8px 12px",letterSpacing:".06em",color:i(t?"ink":"meta-fg"),fontWeight:t?700:400,boxShadow:t?`inset 0 -2px 0 ${i("accent")}`:"none"},children:r})}const Et="bim-recent-ids",Ar="bim-recent-entries",Br=50;function gt(){try{const t=localStorage.getItem(Et);if(t)return JSON.parse(t);const n=localStorage.getItem(Ar);if(n){const r=JSON.parse(n).map(o=>o.id);return localStorage.setItem(Et,JSON.stringify(r)),localStorage.removeItem(Ar),r}return[]}catch{return[]}}function ai(t){try{const n=gt().filter(r=>r!==t);n.unshift(t),n.length>Br&&(n.length=Br),localStorage.setItem(Et,JSON.stringify(n))}catch{}}function ds(t){try{const n=gt().filter(r=>r!==t);localStorage.setItem(Et,JSON.stringify(n))}catch{}}function Bi(){try{localStorage.removeItem(Et)}catch{}}async function Mi(t,n){var r,o,s;try{if(t.getEntry){const a=await t.getEntry(n);if(a)return a}const l=await t.getItem(n);if(l){const a=l.authors;return{id:n,title:l.title||n,type:l.type||"work",author:(r=a==null?void 0:a[0])==null?void 0:r.name,dynasty:(o=a==null?void 0:a[0])==null?void 0:o.dynasty,role:(s=a==null?void 0:a[0])==null?void 0:s.role,edition:l.edition||void 0}}}catch{}return{id:n,title:n,type:"work",notFound:!0}}const Yn=5,Fc=50,Oc=200,Mr={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},ci=({transport:t,indexSource:n="local",syncConfig:r,onEntryClick:o,onNewEntry:s,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c,hideModeIndicator:d,resultVariant:u="compact",renderEntry:x,initialQuery:m,onQueryChange:g,headerRight:b,reserveViewportHeight:k=!1,filtersEnabled:y=!1,filters:j=Cn,onFiltersChange:f})=>{const v=fe(),$=[{type:"work",name:v.indexType.work,key:"works"},{type:"book",name:v.indexType.book,key:"books"},{type:"collection",name:v.indexType.collection,key:"collections"},{type:"entity",name:v.indexType.entity,key:"entities"}],w=["work","collection","book","entity"],[_,S]=h.useState(m??""),[z,E]=h.useState(null),[T,N]=h.useState(m??""),V=yn(j).toString(),[W,B]=h.useState(j);h.useEffect(()=>{B(j)},[V]);const H=re=>{B(re),f==null||f(re)},[te,se]=h.useState(null),[J,D]=h.useState("all"),[L,le]=h.useState(!1),[A,ne]=h.useState(null),[de,G]=h.useState(""),[he,ye]=h.useState(!(m!=null&&m.trim())),[xe,pe]=h.useState(gt),[$e,Fe]=h.useState([]),[Ae,Me]=h.useState(!1),[ve,Be]=h.useState(!1),[P,ae]=h.useState(null),[ie,_e]=h.useState(null),ke=h.useRef(void 0),Y=h.useRef(!1),I=h.useCallback(async(re,ze)=>{if(!re.trim()){ye(!0),E(null),se(null);return}if(ye(!1),y){N(re);return}le(!0),G("");try{if(t.searchAll){const C=await t.searchAll(re,ze??Yn);E(C)}else{const C=["work","book","collection","entity"],q=await Promise.all(C.map(ee=>t.search(re,ee,{page:1,pageSize:ze??Yn})));E({works:q[0].entries,books:q[1].entries,collections:q[2].entries,entities:q[3].entries,totalWorks:q[0].total,totalBooks:q[1].total,totalCollections:q[2].total,totalEntities:q[3].total})}}catch(C){G(C instanceof Error?C.message:String(C)),E(null)}finally{le(!1)}},[t,y]);h.useEffect(()=>{let re=!1;const ze=()=>{var me,Ce;const C=["work","book","collection","entity"],q=Promise.all(C.map(O=>t.loadEntries(O,{page:1,pageSize:1}).catch(()=>({total:0})))),ee=((me=t.getResourceCounts)==null?void 0:me.call(t).catch(()=>null))??Promise.resolve(null),Z=((Ce=t.getSubtypeStats)==null?void 0:Ce.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([q,ee,Z]).then(([O,M,ue])=>{re||(ae({works:O[0].total,books:O[1].total,collections:O[2].total,entities:O[3].total,hasText:M==null?void 0:M.hasText,hasImage:M==null?void 0:M.hasImage}),ue&&_e(ue))})};return t.getCounts?t.getCounts().then(C=>{var q,ee;re||(ae({works:C.works,books:C.books,collections:C.collections,entities:C.entities,hasText:(q=C.resourceCounts)==null?void 0:q.hasText,hasImage:(ee=C.resourceCounts)==null?void 0:ee.hasImage}),C.subtypeStats&&_e(C.subtypeStats))}).catch(()=>{re||ze()}):ze(),()=>{re=!0}},[t]),h.useEffect(()=>{Y.current||!(m!=null&&m.trim())||(Y.current=!0,I(m))},[m,I]);const U=h.useCallback(re=>{if(S(re),!re.trim()){g==null||g(re),ye(!0),E(null),se(null),D("all");return}ke.current&&clearTimeout(ke.current),ke.current=setTimeout(()=>{se(null),D("all"),g==null||g(re),I(re)},Oc)},[I,g]),ge=h.useCallback(re=>{ke.current&&clearTimeout(ke.current),D("all"),g==null||g(re),I(re)},[I,g]),we=h.useCallback(re=>{se(re),I(_,Fc)},[_,I]);h.useEffect(()=>{if(!xe.length){Fe([]);return}let re=!1;return Me(!0),Promise.all(xe.slice(0,10).map(ze=>Mi(t,ze))).then(ze=>{re||(Fe(ze),Me(!1))}),()=>{re=!0}},[xe,t]);const R=re=>{ne(re.id),ai(re.id),pe(gt()),o==null||o(re)},oe=(re,ze)=>{if(o&&Dc(ze)){ze.preventDefault(),R(re);return}ai(re.id),pe(gt())},K=re=>{ds(re),pe(gt())},X=()=>{Bi(),pe([])},je=re=>$.find(ze=>ze.type===re),Ie=!he&&!z&&!de,Re=z&&(z.works.length>0||z.books.length>0||z.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",style:k?{minHeight:"100svh"}:void 0,children:[e.jsx("style",{children:Hc}),e.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:i("fg")},children:v.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&e.jsx(es,{variant:"index-browser",indexSource:n,syncConfig:r,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(ts,{transport:t,value:_,onChange:U,onSearch:ge,onEntrySelect:R}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${i("primary")}`,borderRadius:"6px",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"13px"},children:v.action.newEntry})]}),he&&e.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:P&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:ie?e.jsxs(e.Fragment,{children:[(ie.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:i("fg")},children:ie.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:i("fg")},children:P.books.toLocaleString()})," 本"]}),ie.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:i("fg")},children:ie.article.toLocaleString()})," 篇"]}):null,ie.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:i("fg")},children:ie.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:i("fg")},children:P.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[v.indexType.work," ",e.jsx("strong",{style:{color:i("fg")},children:P.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.book," ",e.jsx("strong",{style:{color:i("fg")},children:P.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.collection," ",e.jsx("strong",{style:{color:i("fg")},children:P.collections.toLocaleString()}),P.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.entity," ",e.jsx("strong",{style:{color:i("fg")},children:P.entities.toLocaleString()})]})]})}),P.hasImage!=null&&P.hasText!=null&&e.jsxs("span",{children:[v.resourceType.image," ",e.jsx("strong",{style:{color:i("fg")},children:P.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.resourceType.text," ",e.jsx("strong",{style:{color:i("fg")},children:P.hasText.toLocaleString()})]})]})}),y&&!he&&e.jsx(cs,{transport:t,query:T,filters:W,onFiltersChange:H,onEntryLinkClick:oe,typeName:re=>je(re).name}),!(y&&!he)&&e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:L||Ie?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg"),minHeight:Pc,boxSizing:"border-box"},children:v.search.searching}):de?e.jsx("div",{style:{textAlign:"center",padding:"40px"},children:e.jsx("p",{style:{color:i("desc-fg")},children:de})}):he?e.jsx("div",{style:{flex:1},children:Ae?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg")},children:v.search.loading}):$e.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:v.search.recentBrowse}),e.jsx("button",{onClick:X,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:v.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:$e.slice(0,ve?10:3).map(re=>re.notFound?e.jsx(Yc,{id:re.id,onRemove:K,t:v},re.id):e.jsx(Wr,{entry:re,selected:A===re.id,onClick:oe,getConfig:je,onRemove:K},re.id))}),!ve&&$e.length>3&&e.jsx("button",{onClick:()=>Be(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:v.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:v.search.searchTitle}),e.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:v.search.searchSubtitle})]})}):Re?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[e.jsx("style",{children:Gc}),(()=>{const re=Z=>z[Mr[Z]]??0,ze=w.map(Z=>$.find(me=>me.type===Z)).filter(Z=>re(Z.key)>0);if(ze.length<2)return null;const C=ze.reduce((Z,me)=>Z+re(me.key),0),q=Z=>{if(D(Z),Z!=="all"&&te!==Z){const me=$.find(O=>O.type===Z),Ce=(z[me.key]??[]).length;re(me.key)>Ce&&we(Z)}},ee=Z=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:i(Z?"fg":"desc-fg"),fontWeight:Z?700:400,boxShadow:Z?`inset 0 -2px 0 ${i("primary")}`:"none"});return e.jsxs("div",{role:"group","aria-label":v.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsxs("button",{type:"button","aria-pressed":J==="all",style:ee(J==="all"),onClick:()=>q("all"),children:[v.search.allTab," ",e.jsx("span",{style:{fontSize:12,fontWeight:400},children:C.toLocaleString()})]}),ze.map(Z=>e.jsxs("button",{type:"button","aria-pressed":J===Z.type,style:ee(J===Z.type),onClick:()=>q(Z.type),children:[Z.name," ",e.jsx("span",{style:{fontSize:12,fontWeight:400},children:re(Z.key).toLocaleString()})]},Z.type))]})})(),$.map(({type:re,name:ze,key:C})=>{const q=z[C]??[],ee=Mr[C],Z=z[ee]??0;if(q.length===0||J!=="all"&&J!==re)return null;const Ce=J==="all"&&!(te===re)&&Z>Yn;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:[e.jsx(Ft,{type:re})," ",ze,e.jsxs("span",{style:{fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[Z," ",v.unit.items]})]}),Ce&&e.jsx("button",{className:"bim-ib-viewall",onClick:()=>we(re),style:{border:"none",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"12px"},children:v.action.viewAll})]}),e.jsx("div",{style:u==="list"?{display:"flex",flexDirection:"column",gap:0}:u==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:q.map(O=>{if(x)return e.jsx(h.Fragment,{children:x(O)},O.id);const M=u==="card"?Vc:Wr;return e.jsx(M,{entry:O,selected:A===O.id,onClick:oe,getConfig:je,query:_},O.id)})})]},re)})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:nt(v.search.noResultsFor,{query:_})}),e.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:v.search.tryOther})]})})]})},Pc=240;function Dc(t){return t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&!t.altKey}const Hc=`
120
+ `,Bi="bim-search-view",Vn=50,Lr=5,Ar=1e3,Br=["work","collection","book","entity"],Oc={work:"works",collection:"collections",book:"books",entity:"entities"},Fc={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function Pc(){try{return window.localStorage.getItem(Bi)==="card"?"card":"table"}catch{return"table"}}function Dc(t){try{window.localStorage.setItem(Bi,t)}catch{}}const Ut=(t,n)=>(t==null?void 0:t[Fc[n]])??0,Yn=(t,n)=>(t==null?void 0:t[Oc[n]])??[],us=({transport:t,query:n,filters:r,onFiltersChange:o,onEntryLinkClick:s,typeName:l})=>{const a=fe(),p=a.searchV4,{convert:c}=O(),d=!!t.supportsSearchFilters,u=h.useMemo(()=>d?r:Cn,[d,r]),[x,m]=h.useState("table");h.useEffect(()=>{m(Pc())},[]);const g=A=>{m(A),Dc(A)},[b,k]=h.useState("all"),[y,j]=h.useState(1),[f,v]=h.useState(null),[$,w]=h.useState(null),[_,S]=h.useState(!1),[z,E]=h.useState(""),T=yn(u).toString(),N=In(u)>0,V=yn({...u,sort:""}).toString(),W=h.useRef({query:n,filterOnlyKey:V,sort:u.sort});h.useEffect(()=>{const A=W.current;A.query!==n||A.filterOnlyKey!==V?(k("all"),j(1)):A.sort!==u.sort&&j(1),W.current={query:n,filterOnlyKey:V,sort:u.sort}},[n,V,u.sort]),h.useEffect(()=>{let A=!1;return S(!0),E(""),(async()=>{try{let ne;if(t.searchAll)ne=await t.searchAll(n,Lr,u);else{const de=["work","book","collection","entity"],G=await Promise.all(de.map(he=>t.search(n,he,{page:1,pageSize:Lr,filters:u})));ne={works:G[0].entries,books:G[1].entries,collections:G[2].entries,entities:G[3].entries,totalWorks:G[0].total,totalBooks:G[1].total,totalCollections:G[2].total,totalEntities:G[3].total}}A||v(ne)}catch(ne){A||(E(ne instanceof Error?ne.message:String(ne)),v(null))}finally{A||S(!1)}})(),()=>{A=!0}},[t,n,T]),h.useEffect(()=>{if(b==="all"){w(null);return}let A=!1;return S(!0),(async()=>{try{const ne=await t.search(n,b,{page:y,pageSize:Vn,filters:u});A||w({entries:ne.entries,total:ne.total})}catch(ne){A||(E(ne instanceof Error?ne.message:String(ne)),w(null))}finally{A||S(!1)}})(),()=>{A=!0}},[t,n,T,b,y]),h.useEffect(()=>{if(b==="all"||!$||_)return;const A=Math.min($.total,Ar),ne=Ac(y,A,Vn);$.entries.length===0&&A>0&&ne!==y&&j(ne)},[b,$,_,y]);const B=h.useMemo(()=>Br.filter(A=>Ut(f,A)>0),[f]),H=B.reduce((A,ne)=>A+Ut(f,ne),0),te=!_&&!z&&f!==null&&H===0,se=h.useCallback(A=>{k(A),j(1)},[]),J=h.useMemo(()=>{var ne;const A=[];return u.dynasty.forEach(de=>A.push({name:de,remove:()=>o({...u,dynasty:u.dynasty.filter(G=>G!==de)})})),u.classification.forEach(de=>{var G;return A.push({name:((G=Nn.find(he=>he.value===de))==null?void 0:G.label)??de,remove:()=>o({...u,classification:u.classification.filter(he=>he!==de)})})}),u.hasImage&&A.push({name:p.hasImage,remove:()=>o({...u,hasImage:!1})}),u.hasText&&A.push({name:p.hasText,remove:()=>o({...u,hasText:!1})}),u.hasCollated&&A.push({name:p.hasCollated,remove:()=>o({...u,hasCollated:!1})}),u.loss&&A.push({name:`${p.extant}:${((ne=Ai.find(de=>de.value===u.loss))==null?void 0:ne.label)??""}`,remove:()=>o({...u,loss:""})}),A},[u,o,p]),D={query:n,onEntryLinkClick:s,typeName:l},L=A=>x==="table"?e.jsx(Er,{entries:A,...D}):e.jsx(Rr,{entries:A,...D}),le=Br.flatMap(A=>Yn(f,A));return e.jsxs("div",{className:"bim-sr-layout","data-nofilters":d?void 0:"true",children:[e.jsx("style",{children:Wc}),d&&e.jsx(Ec,{filters:u,onChange:o}),e.jsxs("div",{className:"bim-sr-main","aria-busy":_,children:[B.length>0&&e.jsxs("div",{className:"bim-sr-tabs",role:"group","aria-label":a.search.resultTabs,style:{display:"flex",flexWrap:"wrap",gap:"0 4px",borderBottom:`1px solid ${i("rule")}`},children:[e.jsxs(Mr,{on:b==="all",onClick:()=>se("all"),children:[a.search.allTab," ",e.jsx("small",{children:H.toLocaleString()})]}),B.map(A=>e.jsxs(Mr,{on:b===A,onClick:()=>se(A),children:[l(A)," ",e.jsx("small",{children:Ut(f,A).toLocaleString()})]},A))]}),e.jsxs("div",{className:"bim-sr-tools",children:[d&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":c(p.sortLabel),children:[e.jsx("button",{type:"button","aria-pressed":!u.sort,onClick:()=>o({...u,sort:""}),children:c(p.sortRelevance)}),["era","title"].map(A=>{const ne=u.sort.startsWith(`${A}:`)?u.sort.endsWith("desc")?"desc":"asc":null,de=A==="era"?p.sortEra:p.sortTitle,G=A==="era"?ne==="desc"?p.sortEraDesc:p.sortEraAsc:ne==="desc"?p.sortTitleDesc:p.sortTitleAsc;return e.jsxs("button",{type:"button","aria-pressed":ne!==null,title:c(G),onClick:()=>o({...u,sort:`${A}:${ne==="asc"?"desc":"asc"}`}),children:[c(de),ne?e.jsxs("span",{"aria-hidden":"true",children:[" ",ne==="asc"?"↑":"↓"]}):null]},A)})]}),e.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),e.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":c(p.viewLabel),children:[e.jsx("button",{type:"button","aria-pressed":x==="table",onClick:()=>g("table"),children:c(p.viewTable)}),e.jsx("button",{type:"button","aria-pressed":x==="card",onClick:()=>g("card"),children:c(p.viewCard)})]})]}),N&&e.jsxs("div",{className:"bim-sr-chips-row",children:[e.jsx("span",{className:"bim-sr-count",role:"status",children:c(nt(p.filteredCount,{n:H.toLocaleString()}))}),J.map(A=>e.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":c(nt(p.removeFilter,{name:A.name})),onClick:A.remove,children:[c(A.name),e.jsx("span",{"aria-hidden":"true",children:"×"})]},A.name))]}),z&&e.jsx("div",{className:"bim-sr-empty",role:"alert",children:z}),te&&e.jsx("div",{className:"bim-sr-empty",children:c(N?p.emptyFiltered:nt(a.search.noResultsFor,{query:n}))}),!z&&!te&&b==="all"&&f&&(x==="table"?e.jsxs(e.Fragment,{children:[e.jsx(Er,{entries:le,...D}),e.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:c(p.limitedNote)})]}):e.jsx(e.Fragment,{children:B.map(A=>e.jsxs("section",{style:{marginTop:22},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[e.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[e.jsx(Ot,{type:A,size:8}),l(A),e.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:i("meta-fg")},children:[Ut(f,A).toLocaleString()," ",a.unit.items]})]}),Ut(f,A)>Yn(f,A).length&&e.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>se(A),children:a.action.viewAll})]}),e.jsx(Rr,{entries:Yn(f,A),...D})]},A))})),!z&&b!=="all"&&$&&$.entries.length>0&&e.jsxs(e.Fragment,{children:[L($.entries),e.jsx(Bc,{page:y,pageSize:Vn,total:Math.min($.total,Ar),onPage:j})]}),!z&&b!=="all"&&$&&$.entries.length===0&&!_&&e.jsxs("div",{className:"bim-sr-empty",children:[c(N?p.emptyFiltered:nt(a.search.noResultsFor,{query:n})),e.jsx("div",{children:e.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>se("all"),children:a.search.allTab})})]})]})]})};function Mr({on:t,onClick:n,children:r}){return e.jsx("button",{type:"button","aria-pressed":t,onClick:n,style:{border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:14.5,minHeight:44,padding:"8px 12px",letterSpacing:".06em",color:i(t?"ink":"meta-fg"),fontWeight:t?700:400,boxShadow:t?`inset 0 -2px 0 ${i("accent")}`:"none"},children:r})}const Et="bim-recent-ids",Wr="bim-recent-entries",Or=50;function gt(){try{const t=localStorage.getItem(Et);if(t)return JSON.parse(t);const n=localStorage.getItem(Wr);if(n){const r=JSON.parse(n).map(o=>o.id);return localStorage.setItem(Et,JSON.stringify(r)),localStorage.removeItem(Wr),r}return[]}catch{return[]}}function ci(t){try{const n=gt().filter(r=>r!==t);n.unshift(t),n.length>Or&&(n.length=Or),localStorage.setItem(Et,JSON.stringify(n))}catch{}}function ms(t){try{const n=gt().filter(r=>r!==t);localStorage.setItem(Et,JSON.stringify(n))}catch{}}function Mi(){try{localStorage.removeItem(Et)}catch{}}async function Wi(t,n){var r,o,s;try{if(t.getEntry){const a=await t.getEntry(n);if(a)return a}const l=await t.getItem(n);if(l){const a=l.authors;return{id:n,title:l.title||n,type:l.type||"work",author:(r=a==null?void 0:a[0])==null?void 0:r.name,dynasty:(o=a==null?void 0:a[0])==null?void 0:o.dynasty,role:(s=a==null?void 0:a[0])==null?void 0:s.role,edition:l.edition||void 0}}}catch{}return{id:n,title:n,type:"work",notFound:!0}}const Kn=5,Hc=50,Gc=200,Fr={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},di=({transport:t,indexSource:n="local",syncConfig:r,onEntryClick:o,onNewEntry:s,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c,hideModeIndicator:d,resultVariant:u="compact",renderEntry:x,initialQuery:m,onQueryChange:g,headerRight:b,reserveViewportHeight:k=!1,filtersEnabled:y=!1,filters:j=Cn,onFiltersChange:f})=>{const v=fe(),$=[{type:"work",name:v.indexType.work,key:"works"},{type:"book",name:v.indexType.book,key:"books"},{type:"collection",name:v.indexType.collection,key:"collections"},{type:"entity",name:v.indexType.entity,key:"entities"}],w=["work","collection","book","entity"],[_,S]=h.useState(m??""),[z,E]=h.useState(null),[T,N]=h.useState(m??""),V=yn(j).toString(),[W,B]=h.useState(j);h.useEffect(()=>{B(j)},[V]);const H=re=>{B(re),f==null||f(re)},[te,se]=h.useState(null),[J,D]=h.useState("all"),[L,le]=h.useState(!1),[A,ne]=h.useState(null),[de,G]=h.useState(""),[he,ye]=h.useState(!(m!=null&&m.trim())),[xe,pe]=h.useState(gt),[$e,Oe]=h.useState([]),[Ae,Me]=h.useState(!1),[ve,Be]=h.useState(!1),[P,ae]=h.useState(null),[ie,_e]=h.useState(null),ke=h.useRef(void 0),Y=h.useRef(!1),I=h.useCallback(async(re,ze)=>{if(!re.trim()){ye(!0),E(null),se(null);return}if(ye(!1),y){N(re);return}le(!0),G("");try{if(t.searchAll){const C=await t.searchAll(re,ze??Kn);E(C)}else{const C=["work","book","collection","entity"],q=await Promise.all(C.map(ee=>t.search(re,ee,{page:1,pageSize:ze??Kn})));E({works:q[0].entries,books:q[1].entries,collections:q[2].entries,entities:q[3].entries,totalWorks:q[0].total,totalBooks:q[1].total,totalCollections:q[2].total,totalEntities:q[3].total})}}catch(C){G(C instanceof Error?C.message:String(C)),E(null)}finally{le(!1)}},[t,y]);h.useEffect(()=>{let re=!1;const ze=()=>{var me,Ce;const C=["work","book","collection","entity"],q=Promise.all(C.map(F=>t.loadEntries(F,{page:1,pageSize:1}).catch(()=>({total:0})))),ee=((me=t.getResourceCounts)==null?void 0:me.call(t).catch(()=>null))??Promise.resolve(null),Z=((Ce=t.getSubtypeStats)==null?void 0:Ce.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([q,ee,Z]).then(([F,M,ue])=>{re||(ae({works:F[0].total,books:F[1].total,collections:F[2].total,entities:F[3].total,hasText:M==null?void 0:M.hasText,hasImage:M==null?void 0:M.hasImage}),ue&&_e(ue))})};return t.getCounts?t.getCounts().then(C=>{var q,ee;re||(ae({works:C.works,books:C.books,collections:C.collections,entities:C.entities,hasText:(q=C.resourceCounts)==null?void 0:q.hasText,hasImage:(ee=C.resourceCounts)==null?void 0:ee.hasImage}),C.subtypeStats&&_e(C.subtypeStats))}).catch(()=>{re||ze()}):ze(),()=>{re=!0}},[t]),h.useEffect(()=>{Y.current||!(m!=null&&m.trim())||(Y.current=!0,I(m))},[m,I]);const U=h.useCallback(re=>{if(S(re),!re.trim()){g==null||g(re),ye(!0),E(null),se(null),D("all");return}ke.current&&clearTimeout(ke.current),ke.current=setTimeout(()=>{se(null),D("all"),g==null||g(re),I(re)},Gc)},[I,g]),ge=h.useCallback(re=>{ke.current&&clearTimeout(ke.current),D("all"),g==null||g(re),I(re)},[I,g]),we=h.useCallback(re=>{se(re),I(_,Hc)},[_,I]);h.useEffect(()=>{if(!xe.length){Oe([]);return}let re=!1;return Me(!0),Promise.all(xe.slice(0,10).map(ze=>Wi(t,ze))).then(ze=>{re||(Oe(ze),Me(!1))}),()=>{re=!0}},[xe,t]);const R=re=>{ne(re.id),ci(re.id),pe(gt()),o==null||o(re)},oe=(re,ze)=>{if(o&&Vc(ze)){ze.preventDefault(),R(re);return}ci(re.id),pe(gt())},K=re=>{ms(re),pe(gt())},X=()=>{Mi(),pe([])},je=re=>$.find(ze=>ze.type===re),Ie=!he&&!z&&!de,Re=z&&(z.works.length>0||z.books.length>0||z.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",style:k?{minHeight:"100svh"}:void 0,children:[e.jsx("style",{children:Yc}),e.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:i("fg")},children:v.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&e.jsx(is,{variant:"index-browser",indexSource:n,syncConfig:r,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(rs,{transport:t,value:_,onChange:U,onSearch:ge,onEntrySelect:R}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${i("primary")}`,borderRadius:"6px",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"13px"},children:v.action.newEntry})]}),he&&e.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:P&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:ie?e.jsxs(e.Fragment,{children:[(ie.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:i("fg")},children:ie.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:i("fg")},children:P.books.toLocaleString()})," 本"]}),ie.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:i("fg")},children:ie.article.toLocaleString()})," 篇"]}):null,ie.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:i("fg")},children:ie.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:i("fg")},children:P.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[v.indexType.work," ",e.jsx("strong",{style:{color:i("fg")},children:P.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.book," ",e.jsx("strong",{style:{color:i("fg")},children:P.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.collection," ",e.jsx("strong",{style:{color:i("fg")},children:P.collections.toLocaleString()}),P.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.entity," ",e.jsx("strong",{style:{color:i("fg")},children:P.entities.toLocaleString()})]})]})}),P.hasImage!=null&&P.hasText!=null&&e.jsxs("span",{children:[v.resourceType.image," ",e.jsx("strong",{style:{color:i("fg")},children:P.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.resourceType.text," ",e.jsx("strong",{style:{color:i("fg")},children:P.hasText.toLocaleString()})]})]})}),y&&!he&&e.jsx(us,{transport:t,query:T,filters:W,onFiltersChange:H,onEntryLinkClick:oe,typeName:re=>je(re).name}),!(y&&!he)&&e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:L||Ie?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg"),minHeight:Uc,boxSizing:"border-box"},children:v.search.searching}):de?e.jsx("div",{style:{textAlign:"center",padding:"40px"},children:e.jsx("p",{style:{color:i("desc-fg")},children:de})}):he?e.jsx("div",{style:{flex:1},children:Ae?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg")},children:v.search.loading}):$e.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:v.search.recentBrowse}),e.jsx("button",{onClick:X,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:v.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:$e.slice(0,ve?10:3).map(re=>re.notFound?e.jsx(Zc,{id:re.id,onRemove:K,t:v},re.id):e.jsx(Pr,{entry:re,selected:A===re.id,onClick:oe,getConfig:je,onRemove:K},re.id))}),!ve&&$e.length>3&&e.jsx("button",{onClick:()=>Be(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:v.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:v.search.searchTitle}),e.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:v.search.searchSubtitle})]})}):Re?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[e.jsx("style",{children:Kc}),(()=>{const re=Z=>z[Fr[Z]]??0,ze=w.map(Z=>$.find(me=>me.type===Z)).filter(Z=>re(Z.key)>0);if(ze.length<2)return null;const C=ze.reduce((Z,me)=>Z+re(me.key),0),q=Z=>{if(D(Z),Z!=="all"&&te!==Z){const me=$.find(F=>F.type===Z),Ce=(z[me.key]??[]).length;re(me.key)>Ce&&we(Z)}},ee=Z=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:i(Z?"fg":"desc-fg"),fontWeight:Z?700:400,boxShadow:Z?`inset 0 -2px 0 ${i("primary")}`:"none"});return e.jsxs("div",{role:"group","aria-label":v.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsxs("button",{type:"button","aria-pressed":J==="all",style:ee(J==="all"),onClick:()=>q("all"),children:[v.search.allTab," ",e.jsx("span",{style:{fontSize:12,fontWeight:400},children:C.toLocaleString()})]}),ze.map(Z=>e.jsxs("button",{type:"button","aria-pressed":J===Z.type,style:ee(J===Z.type),onClick:()=>q(Z.type),children:[Z.name," ",e.jsx("span",{style:{fontSize:12,fontWeight:400},children:re(Z.key).toLocaleString()})]},Z.type))]})})(),$.map(({type:re,name:ze,key:C})=>{const q=z[C]??[],ee=Fr[C],Z=z[ee]??0;if(q.length===0||J!=="all"&&J!==re)return null;const Ce=J==="all"&&!(te===re)&&Z>Kn;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:[e.jsx(Ot,{type:re})," ",ze,e.jsxs("span",{style:{fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[Z," ",v.unit.items]})]}),Ce&&e.jsx("button",{className:"bim-ib-viewall",onClick:()=>we(re),style:{border:"none",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"12px"},children:v.action.viewAll})]}),e.jsx("div",{style:u==="list"?{display:"flex",flexDirection:"column",gap:0}:u==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:q.map(F=>{if(x)return e.jsx(h.Fragment,{children:x(F)},F.id);const M=u==="card"?Jc:Pr;return e.jsx(M,{entry:F,selected:A===F.id,onClick:oe,getConfig:je,query:_},F.id)})})]},re)})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:nt(v.search.noResultsFor,{query:_})}),e.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:v.search.tryOther})]})})]})},Uc=240;function Vc(t){return t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&!t.altKey}const Yc=`
121
121
  .bim-ib-stats { min-height: 25px; box-sizing: content-box; }
122
122
  @media (max-width: 719px) { .bim-ib-stats { min-height: 46px; } }
123
- `,Gc=`
123
+ `,Kc=`
124
124
  @media (max-width: 719px), (pointer: coarse) {
125
125
  .bim-ib-viewall { position: relative; }
126
126
  .bim-ib-viewall::after {
127
127
  content: ""; position: absolute; left: 50%; top: 50%;
128
128
  width: max(calc(100% + 8px), 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
129
129
  }
130
- }`,ps={color:"inherit",textDecoration:"none"},Uc=({snippet:t})=>{const{convert:n}=F();return e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.6},children:Ci(t).map((r,o)=>r.marked?e.jsx("mark",{style:{background:i("highlight-bg"),color:i("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(r.text)},o):e.jsx(h.Fragment,{children:n(r.text)},o))})},Vc=({entry:t,selected:n,onClick:r,getConfig:o,query:s})=>{const l=fe(),{convert:a}=F(),p=a(t.title||t.primary_name||t.id),c=t.measure_info?a(t.measure_info):t.juan_count!=null&&t.juan_count>0?`${t.juan_count}${l.unit.juan}`:"",d=[...t.additional_titles||[],...t.attached_texts||[]],u=s&&d.length?d.find(g=>{const b=typeof g=="string"?g:g==null?void 0:g.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,x=i("cover-accent"),m=He();return e.jsxs("a",{href:m(t.id),onClick:g=>r(t,g),className:"bim-result-card",style:{...ps,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:i("bg"),border:n?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[e.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${x} 50%, ${i("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${x} 14%, ${i("bg")}), color-mix(in srgb, ${x} 7%, ${i("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[e.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${x} 45%, transparent)`}}),e.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:x},children:Array.from(p).map((g,b)=>e.jsx("span",{children:g},b))})]}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:i("fg")},children:p}),c&&e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:c})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg")},children:[t.dynasty&&e.jsxs("span",{children:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]})]}),(t.era||t.edition)&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[t.era&&e.jsxs("span",{children:["〔",a(t.era),"〕"]}),t.edition&&e.jsx("span",{children:a(t.edition)})]}),u&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[l.search.alias,":",a(typeof u=="string"?u:u.book_title||"")]}),t.descriptionSnippet&&e.jsx(Uc,{snippet:t.descriptionSnippet}),e.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:[e.jsx(Ft,{type:t.type,size:8})," ",o(t.type).name]}),t.has_text&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.textResource}),t.has_image&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.imageResource})]})]})]})},Wr=({entry:t,selected:n,onClick:r,getConfig:o,query:s,onRemove:l})=>{const a=fe(),{convert:p}=F(),c=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&c.length?c.find(x=>{const m=typeof x=="string"?x:x==null?void 0:x.book_title;return m==null?void 0:m.toLowerCase().includes(s.toLowerCase())}):void 0,u=He();return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[e.jsxs("a",{href:u(t.id),onClick:x=>r(t,x),className:"bim-result-card",style:{...ps,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx(Ft,{type:t.type,size:12}),e.jsx("span",{style:{fontSize:"9px",color:i("desc-fg"),lineHeight:1},children:o(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg")},children:p(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{children:a.misc.textResource}),t.has_image&&e.jsx("span",{children:a.misc.imageResource})]}),(t.era||t.edition)&&e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[t.era&&e.jsxs(e.Fragment,{children:["〔",p(t.era),"〕"]}),t.edition&&p(t.edition)]}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:p(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[t.juan_count,a.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",p(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:p(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",p(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:[a.search.alias,":",p(d)]})]}),!l&&e.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&e.jsx("button",{type:"button",onClick:()=>l(t.id),title:a.search.removeFromRecent,"aria-label":a.search.removeFromRecent,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},Yc=({id:t,onRemove:n,t:r})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${i("widget-border")}`,background:i("input-bg"),opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:i("fg"),fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:r.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:r.search.removeFromRecent,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Kc(t){var n;return!t.dynasty&&!t.birth_year&&!t.death_year&&(!t.alt_names||t.alt_names.length===0)&&!((n=t.description)!=null&&n.text)}function qc({data:t}){const{convert:n}=F(),{dynasty:r,birth_year:o,death_year:s}=t,l=[];return r&&l.push(`〔${n(r)}〕`),o!==void 0&&s!==void 0?l.push(`${o}—${s}`):o!==void 0?l.push(`${o}—?`):s!==void 0&&l.push(`?—${s}`),l.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:i("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function Jc({alt_names:t}){const{convert:n}=F(),r=new Map;for(const l of t){const a=l.type||"別名";r.has(a)||r.set(a,[]),r.get(a).push(l.name)}const o=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...r.keys()].sort((l,a)=>{const p=o.indexOf(l),c=o.indexOf(a);return p===-1&&c===-1?0:p===-1?1:c===-1?-1:p-c});return e.jsx("div",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const a=r.get(l);return e.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[e.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),e.jsx("span",{children:a.map((p,c)=>e.jsxs("span",{children:[c>0&&e.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},c))})]},l)})})}function Zc({data:t}){const n=t.external_ids;if(!n)return null;const r=[];return n.cbdb_id&&r.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:i("link-fg"),border:`1px solid ${i("link-fg")}40`,borderRadius:"3px",textDecoration:"none",background:`${i("link-fg")}08`},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),r.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:r})}function Xc({works:t,transport:n,onNavigate:r,renderLink:o}){const s=fe(),{convert:l}=F(),a=He(),[p,c]=h.useState(new Map);h.useEffect(()=>{if(!n)return;let m=!1;const g=t.map(k=>k.work_id);return(async()=>{const k=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(g);let $=!0;for(let w=0;w<g.length;w++){const _=v[w];_!=null&&_.title?k.set(g[w],_.title):_!=null&&_.primary_name?k.set(g[w],_.primary_name):$=!1}if($)return k}catch{}const y=[...g],j=8,f=new Array(j).fill(0).map(async()=>{for(;y.length;){const v=y.shift();if(!v)break;if(!k.has(v))try{if(n.getEntry){const _=await n.getEntry(v);if(_!=null&&_.title){k.set(v,_.title);continue}}const $=await n.getItem(v),w=$&&($.title||$.primary_name)||v;k.set(v,w)}catch{k.set(v,v)}}});return await Promise.all(f),k})().then(k=>{m||c(k)}),()=>{m=!0}},[t,n]);const d=new Map;for(const m of t){const g=m.role||"";d.has(g)||d.set(g,[]),d.get(g).push(m)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...d.keys()].sort((m,g)=>{const b=u.indexOf(m),k=u.indexOf(g);return b===-1&&k===-1?m.localeCompare(g):b===-1?1:k===-1?-1:b-k});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:i("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:i("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),x.map(m=>{const g=d.get(m);return e.jsxs("div",{style:{marginBottom:"8px"},children:[m&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"2px"},children:[l(m)," ",e.jsxs("span",{style:{color:i("desc-fg")},children:["(",g.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:m?"16px":"0",listStyle:m?"disc":"none",fontSize:"14px",lineHeight:1.8},children:g.map((b,k)=>{const y=l(p.get(b.work_id)||b.work_id);return o?e.jsx("li",{children:o(b.work_id,y)},k):r?e.jsx("li",{children:e.jsx("a",{href:a(b.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),r(b.work_id))},style:{color:i("link-fg"),textDecoration:"underline",cursor:"pointer"},children:y})},k):e.jsx("li",{children:y},k)})})]},m)})]})}const us=({data:t,transport:n,onNavigate:r,renderLink:o,headerExtra:s,hideHeader:l})=>{var x;const a=fe(),{convert:p}=F();let c=!1;try{c=be.extractStatus(t.id)==="draft"}catch{}const d=Kc(t),u=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[!l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:i("fg")},children:[p(t.primary_name),e.jsx(qc,{data:t})]}),s]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:i("desc-fg"),marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:i("type-entity"),border:`1px solid color-mix(in srgb, ${i("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${i("type-entity")} 3%, transparent)`},children:a.indexType.entity}),u&&t.subtype!=="people"&&e.jsx("span",{children:u}),c&&e.jsx("span",{style:{padding:"1px 6px",background:i("warn-bg"),border:`1px solid ${i("warn-border")}`,borderRadius:"2px",color:i("warn-fg")},children:a.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]})]}),d&&e.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:i("widget-bg"),border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(Jc,{alt_names:t.alt_names}),e.jsx(Zc,{data:t}),((x=t.description)==null?void 0:x.text)&&e.jsx("p",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(t.description.text)}),t.works&&t.works.length>0&&e.jsx(Xc,{works:t.works,transport:n,onNavigate:r,renderLink:o})]})},Qc=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function ed(t){const n=t.search(Qc);return n<0?[t,""]:[t.slice(0,n),t.slice(n)]}const ms={p:({children:t})=>e.jsx("p",{style:{margin:"0 0 0.5em"},children:t}),ul:({children:t})=>e.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:t}),ol:({children:t})=>e.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:t}),li:({children:t})=>e.jsx("li",{style:{marginBottom:"2px"},children:t}),a:({href:t,children:n})=>{let r=t,o="",s=n;if(t&&typeof n=="string"&&(n===t||n===td(t))){const[l,a]=ed(n);a&&(r=encodeURI(l),s=l,o=a)}return e.jsxs(e.Fragment,{children:[e.jsx("a",{href:r,target:r!=null&&r.startsWith("http")?"_blank":void 0,rel:r!=null&&r.startsWith("http")?"noopener noreferrer":void 0,style:{color:i("link")},children:s}),o]})},code:({children:t})=>e.jsx("code",{style:{background:i("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:t})};function td(t){try{return decodeURI(t)}catch{return t}}const nd={...ms,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},pt=({text:t,plainStrong:n,style:r,className:o})=>{const{convert:s}=F(),l=n?nd:ms;return e.jsx("div",{className:o,style:r,children:e.jsx(Va,{remarkPlugins:[Ya],components:l,children:s(t)})})},id=["〇","一","二","三","四","五","六","七","八","九"],Fr=["","十","百","千"];function xs(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),r=n.length;let o="",s=!1;for(let l=0;l<r;l++){const a=parseInt(n[l]),p=r-1-l;a===0?s=!0:(s&&o&&(o+="〇"),s=!1,a===1&&p===1&&l===0?o+=Fr[p]:o+=id[a]+Fr[p])}return o}function hs(t){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t,border:`1px solid color-mix(in srgb, ${t} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${t} 3%, transparent)`}}const rd={book:i("type-book"),work:i("type-work"),collection:i("type-collection"),entity:i("type-entity")};function od({type:t}){const n=fe();return e.jsx("span",{style:hs(rd[t]),children:n.indexType[t]})}function sd({isDraft:t}){const n=fe(),r=i(t?"status-draft":"status-official");return e.jsx("span",{style:hs(r),children:t?n.status.draft:n.status.official})}function ld({id:t}){const n=fe(),[r,o]=h.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:i("desc-fg"),background:i("bg-subtle"),border:`1px solid ${i("widget-border")}`,borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:i("fg")},children:t}),e.jsx("span",{onClick:s,title:r?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:r?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=r?"1":"0.5",children:r?"✓":"⧉"})]})}function Qe({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("desc-fg"),letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function ot({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:t}),e.jsx("span",{style:{color:i("fg")},children:n})]})}function gs({authors:t,type:n,onNavigate:r,renderLink:o}){const{convert:s}=F();return e.jsx("span",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.6},children:t.map((l,a)=>{const p=s(l.name),c=l.entity_id?e.jsx(it,{id:l.entity_id,label:p,onNavigate:r,renderLink:o}):e.jsx("span",{style:{fontWeight:500},children:p});return e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&e.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),c,l.role&&e.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},a)})})}function it({id:t,label:n,onNavigate:r,renderLink:o}){const s=He();return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:s(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),r(t))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`,paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function ad({id:t,title:n,edition:r,type:o,isDraft:s,authors:l,volumeText:a,meta:p,headerExtra:c,onNavigate:d,renderLink:u}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:i("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,r&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:r}),a&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:a})]}),c&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(od,{type:o}),e.jsx(sd,{isDraft:s}),e.jsx(ld,{id:t})]}),((l==null?void 0:l.length)||p.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&e.jsx(gs,{authors:l,type:o,onNavigate:d,renderLink:u}),p]})]})}function fs({items:t,label:n,showMeta:r,onNavigate:o,renderLink:s}){const l=fe(),{convert:a}=F();if(!t.length)return null;const[p,c]=h.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,u)=>{const x=p===u;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:i("shadow-card")}:{}},children:[e.jsxs("div",{onClick:()=>c(x?null:u),style:{padding:"8px 12px",background:i("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:a(d.source)}),!x&&r&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:m=>m.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(it,{id:d.source_bid,label:l.action.view,onNavigate:o,renderLink:s})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${i("widget-border")}`},children:[r&&(d.title_info||d.author_info||d.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&e.jsx(ot,{label:l.label.titleInfo,children:a(d.title_info)}),d.author_info&&e.jsx(ot,{label:l.label.authorInfo,children:a(d.author_info)}),d.edition&&e.jsx(ot,{label:l.label.edition,children:a(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${i("primary")}`,background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:a(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.additional_comment)})]})]})]},u)})})]})}function cd({items:t,onNavigate:n,renderLink:r}){const o=fe();return e.jsx(fs,{items:t,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:r})}function bs({items:t,onNavigate:n,renderLink:r}){const o=fe();return e.jsx(fs,{items:t,label:o.section.emendated,onNavigate:n,renderLink:r})}function ys({label:t,items:n}){const{convert:r}=F();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((o,s)=>{const l=typeof o=="string"?o:o.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:i("fg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:r(l)},s)})})]}):null}function dd({items:t}){const n=fe();return e.jsx(ys,{label:n.section.aliases,items:t})}function pd({items:t}){const n=fe();return e.jsx(ys,{label:n.section.attachedTexts,items:t})}function ud({items:t}){const n=fe(),{convert:r}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:i("fg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:["《",r(o.book_title),"》",o.n_juan!=null&&e.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},s))})]}):null}function md({items:t}){const n=fe(),{convert:r}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:i("widget-border")}}),t.map((o,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:i("primary"),border:`1.5px solid ${i("input-bg")}`}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:i("fg")},children:r(o.name)}),o.description&&e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),marginLeft:"8px"},children:r(o.description)})]},s))]})]}):null}function xd({items:t}){const n=fe(),{convert:r}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((o,s)=>e.jsxs("div",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:i("desc-fg")},children:"·"}),r(o)]},s))})]}):null}function Or({title:t,ids:n,transport:r,onNavigate:o,renderLink:s}){const{convert:l}=F(),[a,p]=h.useState([]);return h.useEffect(()=>{if(!n.length){p([]);return}if(!r){p(n.map(d=>({id:d})));return}let c=!1;return Promise.all(n.map(d=>r.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{c||p(d)}),()=>{c=!0}},[n,r]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(Qe,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(a.length?a:n.map(c=>({id:c}))).map(c=>{const d=c.edition?`${l(c.title)||c.id}(${l(c.edition)})`:l(c.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),transition:"border-color 0.15s"},children:e.jsx(it,{id:c.id,label:d,onNavigate:o,renderLink:s})},c.id)})})]}):null}function Kn({book:t,onNavigate:n,renderLink:r}){const o=fe(),{convert:s}=F(),[l,a]=h.useState(!1),p=t.resources&&t.resources.length>0,c=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:i("input-bg")},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${i("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:e.jsx(it,{id:t.id,label:c,onNavigate:n,renderLink:r})}),p&&e.jsx("span",{onClick:()=>a(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:i("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?o.action.expand:o.action.collapse,children:"▼"})]}),p&&!l&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(Ri,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:r})})]})}function hd({ids:t,workData:n,transport:r,onNavigate:o,renderLink:s,footer:l}){const a=fe(),{convert:p}=F(),[c,d]=h.useState([]);if(h.useEffect(()=>{if(!t.length){d([]);return}if(!r){d(t.map(k=>({id:k})));return}let b=!1;return Promise.all(t.map(k=>r.getItem(k).then(y=>({id:k,title:y?y.title:void 0,edition:y?y.edition:void 0,resources:y?y.resources:void 0,resource_groups:y?y.resource_groups:void 0})).catch(()=>({id:k})))).then(k=>{b||d(k)}),()=>{b=!0}},[t,r]),!t.length)return null;const u=c.length?c:t.map(b=>({id:b})),x=new Map(u.map(b=>[b.id,b])),m=n==null?void 0:n.version_graph,g=gd(t,m);return e.jsxs(e.Fragment,{children:[e.jsxs(Qe,{children:[a.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",t.length,")"]})]}),l,g.useGrouping?e.jsxs(e.Fragment,{children:[g.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:g.coreIds.map(b=>{const k=x.get(b);return k?e.jsx(Kn,{book:k,onNavigate:o,renderLink:s},b):null})}),g.groupedIds.map(b=>e.jsxs("details",{style:{marginTop:12,border:`1px solid ${i("widget-border")}`,borderRadius:6,background:i("bg-subtle")},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:i("fg"),userSelect:"none"},children:[p(b.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:i("desc-fg"),fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:i("desc-fg"),fontWeight:400},children:p(b.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(k=>{const y=x.get(k);return y?e.jsx(Kn,{book:y,onNavigate:o,renderLink:s},k):null})})]},b.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(b=>e.jsx(Kn,{book:b,onNavigate:o,renderLink:s},b.id))})]})}function gd(t,n){var y,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const r=(y=n.collections)==null?void 0:y[n.default_collection],o=(r==null?void 0:r.groups)??[],s=(r==null?void 0:r.book_ids)??[],l=o.length>0||s.length>0,a=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const p=new Set(o),c=new Set([...s,...a]),d=f=>{if(c.has(f))return!0;const v=n.node_groups[f];return v!=null&&p.has(v)},u=[],x=new Map,m=[];for(const f of t)if(!((j=n.excluded_books)!=null&&j.includes(f)))if(d(f))u.push(f);else{const v=n.node_groups[f];v?(x.has(v)||x.set(v,[]),x.get(v).push(f)):m.push(f)}if(m.length+[...x.values()].reduce((f,v)=>f+v.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(f=>[f.id,f])),k=[...x.entries()].map(([f,v])=>{const $=b.get(f);return{id:f,label:($==null?void 0:$.label)??f,description:$==null?void 0:$.description,ids:v}});return m.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:m}),{useGrouping:!0,coreIds:u,groupedIds:k}}function fd({workData:t,onNavigate:n,renderLink:r}){var a,p,c,d;const o=fe(),{convert:s}=F(),l=!!((a=t.description)!=null&&a.text)||!!t.parent_work;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:i("input-bg"),marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?`1px solid ${i("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`},children:[e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:e.jsx(it,{id:t.id,label:s(t.title),onNavigate:n,renderLink:r})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:s(t.measure_info)}):((p=t.juan_count)==null?void 0:p.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[xs(t.juan_count.number),o.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(gs,{authors:t.authors,type:"work",onNavigate:n,renderLink:r})})]}),l&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((c=t.description)==null?void 0:c.text)&&e.jsx(pt,{text:t.description.text,style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,textAlign:"justify"}}),t.parent_work&&e.jsx("div",{style:{marginTop:(d=t.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:e.jsx(ot,{label:o.label.parentWork,children:e.jsx(it,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:r})})})]})]})}function bd({items:t,onNavigate:n,renderLink:r}){const o=fe(),{convert:s}=F();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(l=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid color-mix(in srgb, ${i("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${i("type-collection")} 3%, transparent)`},children:[e.jsx("span",{style:{fontSize:"11px",color:i("type-collection")},children:o.indexType.collection}),e.jsx(it,{id:l.id,label:s(l.title)||l.id,onNavigate:n,renderLink:r}),l.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"2px"},children:nt(o.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Wi=({data:t,id:n,transport:r,onNavigate:o,renderLink:s,headerExtra:l,relatedBooksFooter:a,className:p,style:c})=>{var V,W,B,H,te,se,J,D;const d=fe(),{convert:u}=F(),[x,m]=h.useState(null),[g,b]=h.useState(!1),[k,y]=h.useState(null),[j,f]=h.useState(null),[v,$]=h.useState([]),w=t||x;if(h.useEffect(()=>{if(t||!n||!r)return;let L=!1;return b(!0),y(null),r.getItem(n).then(le=>{L||(le?m(le):y(d.misc.notFoundEntry))}).catch(le=>{L||y(le instanceof Error?le.message:d.misc.loadFailed)}).finally(()=>{L||b(!1)}),()=>{L=!0}},[t,n,r]),h.useEffect(()=>{if(!w||!r){f(null),$([]);return}let L=!1;const le=w.type==="book"||w.type==="collection"?w.work_id:void 0;if(le?r.getItem(le).then(A=>{!L&&A&&A.type==="work"&&f(A)}).catch(()=>{}):f(null),w.type==="book"){const A=w;A.contained_in&&A.contained_in.length>0?Promise.all(A.contained_in.map(ne=>{const de=typeof ne=="string"?ne:ne.id,G=typeof ne=="string"?void 0:ne.volume_index;return r.getItem(de).then(he=>({id:de,title:he&&he.title||de,volume_index:G})).catch(()=>({id:de,title:de,volume_index:G}))})).then(ne=>{L||$(ne)}):$([])}else $([]);return()=>{L=!0}},[w,r]),g)return e.jsx("div",{className:p,style:{...c,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((L,le)=>e.jsx("div",{style:{height:le===1?"32px":"16px",width:`${L}px`,background:i("widget-border"),borderRadius:"4px",opacity:.4}},le))})});if(k)return e.jsx("div",{className:p,style:{...c,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:k});if(!w)return null;if(w.type==="entity")return e.jsx("div",{className:p,style:c,children:e.jsx(us,{data:w,transport:r,onNavigate:o,renderLink:s,headerExtra:l})});const _=w.type==="book"?w:null,S=w.type==="collection"?w:null,z=w.type==="work"?w:null;let E=!1;try{E=be.extractStatus(w.id)==="draft"}catch{}let T="";w.measure_info?T=u(w.measure_info):(V=w.juan_count)!=null&&V.number?T=xs(w.juan_count.number)+d.unit.juan:(W=w.juan_count)!=null&&W.description&&(T=u(w.juan_count.description));const N=[];return(B=w.publication_info)!=null&&B.year&&N.push(e.jsx(ot,{label:d.label.year,children:w.publication_info.year},"year")),(H=w.current_location)!=null&&H.name&&N.push(e.jsx(ot,{label:d.label.currentLocation,children:u(w.current_location.name)},"loc")),(te=w.page_count)!=null&&te.description&&N.push(e.jsx(ot,{label:d.label.pageCount,children:w.page_count.description},"page")),_!=null&&_.edition&&N.push(e.jsx(ot,{label:d.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&N.push(e.jsx(ot,{label:d.label.parentWork,children:e.jsx(it,{id:z.parent_work.id,label:u(z.parent_work.title),onNavigate:o,renderLink:s})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&N.push(e.jsx(ot,{label:d.label.parentWork,children:z.parent_works.map((L,le)=>e.jsxs("span",{children:[le>0&&"、",e.jsx(it,{id:L,onNavigate:o,renderLink:s})]},L))},"pws")),e.jsxs("div",{className:p,style:c,children:[e.jsx(ad,{id:w.id,title:u(w.title),edition:w.edition?u(w.edition):void 0,type:w.type,isDraft:E,authors:w.authors,volumeText:T,meta:N,headerExtra:l,onNavigate:o,renderLink:s}),((se=w.description)==null?void 0:se.text)&&e.jsx(pt,{text:w.description.text,style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),w.appendix&&w.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:w.appendix.map((L,le)=>e.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:i("bg-subtle"),borderRadius:4,border:`1px solid ${i("widget-border")}`},children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:i("muted")},children:u(L.title)}),e.jsx(pt,{text:L.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:i("fg")}})]},le))}),v.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:d.section.containedIn}),e.jsx(bd,{items:v,onNavigate:o,renderLink:s})]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:d.section.belongsToWork}),e.jsx(fd,{workData:j,onNavigate:o,renderLink:s})]}),w.additional_works&&w.additional_works.length>0&&e.jsx(ud,{items:w.additional_works}),w.additional_titles&&w.additional_titles.length>0&&e.jsx(dd,{items:w.additional_titles}),w.attached_texts&&w.attached_texts.length>0&&e.jsx(pd,{items:w.attached_texts}),w.indexed_by&&w.indexed_by.length>0&&e.jsx(cd,{items:w.indexed_by,onNavigate:o,renderLink:s}),w.emendated_by&&w.emendated_by.length>0&&e.jsx(bs,{items:w.emendated_by,onNavigate:o,renderLink:s}),w.resources&&w.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:d.section.resources}),e.jsx(Ri,{items:w.resources,resourceGroups:w.resource_groups,groupByType:!0,onNavigate:o,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&e.jsx(md,{items:_.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(xd,{items:S.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&e.jsx(Or,{title:d.section.relatedVersions,ids:_.related_books,transport:r,onNavigate:o,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(Or,{title:d.section.containedBooks,ids:S.books,transport:r,onNavigate:o,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(Qe,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",S.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(L=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:e.jsx(it,{id:L.id,label:u(L.title),onNavigate:o,renderLink:s})},L.id))})]}),(((J=z==null?void 0:z.books)==null?void 0:J.length)||0)+(((D=z==null?void 0:z.collections)==null?void 0:D.length)||0)>0&&e.jsx(hd,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z??void 0,transport:r,onNavigate:o,renderLink:s,footer:a}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const L=[],le=z.related_works.filter(ye=>ye.relation==="part_of"),A=z.related_works.filter(ye=>ye.relation==="has_part"),ne=z.related_works.filter(ye=>ye.relation==="has_adaptation"),de=z.related_works.filter(ye=>ye.relation==="text_carried_by"),G=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),he=z.related_works.filter(ye=>!ye.relation||!G.has(ye.relation));return le.length>0&&L.push({label:d.section.belongsToWork,items:le}),A.length>0&&L.push({label:d.section.containedWorks,items:A}),ne.length>0&&L.push({label:d.section.adaptations,items:ne}),de.length>0&&L.push({label:d.section.derivativeWorks,items:de}),he.length>0&&L.push({label:d.section.relatedWorks,items:he}),L.map(ye=>e.jsxs("div",{children:[e.jsxs(Qe,{children:[ye.label,e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",ye.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:ye.items.map(xe=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:e.jsx(it,{id:xe.id,label:u(xe.title),onNavigate:o,renderLink:s})},xe.id))})]},ye.label))})()]})};function yd({data:t}){const n=fe(),{convert:r}=F(),{stats:o}=t,s=o.processed_volumes??o.total_found_volumes,l=s!=null&&t.total_volumes>0?Math.round(s/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:r(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"6px"},children:r(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:i("desc-fg")},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:i("fg")},children:t.total_volumes})," ",n.unit.volume]}),l!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:i("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:i("fg")},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:i("fg")},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:i("missing-fg")},children:o.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:i("desc-fg")},children:[n.catalog.source," ",t.source]})]})}function jd({sections:t,activeSection:n,onSelect:r}){const o=fe();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>r(null),style:Pr(n===null),children:o.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>r(s.name),style:Pr(n===s.name),children:[s.name,s.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function Pr(t){return{padding:"4px 12px",border:t?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:t?`color-mix(in srgb, ${i("primary")} 8%, transparent)`:"transparent",color:i(t?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function vd({id:t,label:n,onNavigate:r,renderLink:o}){const s=He();return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:s(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),r(t))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:n||t})}function kd(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const r=t[0],o=t[t.length-1];return o-r+1===t.length?`${r}–${o}`:t.length<=3?t.join(", "):`${r}–${o} (${t.length}${n})`}function Dr({book:t,onNavigate:n,renderLink:r,showVolumes:o}){const s=fe(),{convert:l}=F(),a=t.book_id||t.work_id,p=o&&t.volumes.length>0?kd(t.volumes,s.unit.volume):null,c=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${i("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[o&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:i("desc-fg"),textAlign:"right"},children:p}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:i("fg")},children:[l(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(d=>l(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:i(c?"missing-fg":"desc-fg"),flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),a&&e.jsx(vd,{id:a,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:r}),!a&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const Fi=({data:t,collectionId:n,transport:r,onNavigate:o,renderLink:s,className:l,style:a})=>{const p=fe(),[c,d]=h.useState(null),[u,x]=h.useState(!1),[m,g]=h.useState(null),[b,k]=h.useState(null),[y,j]=h.useState(""),f=t||c;h.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollectionCatalog))return;let S=!1;return x(!0),g(null),r.getCollectionCatalog(n).then(z=>{S||(z?d(z):g(p.catalog.notFound))}).catch(z=>{S||g(z instanceof Error?z.message:p.catalog.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,r,p]);const v=(f==null?void 0:f.sections)&&f.sections.length>0,$=h.useMemo(()=>{if(!f)return!1;if(f.volume_index&&Object.keys(f.volume_index).length>0)return!0;const S=f.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(S).size<S.length},[f]),w=h.useMemo(()=>{if(!f)return[];let S=f.books;if(b&&(S=S.filter(z=>z.section===b)),y.trim()){const z=y.trim().toLowerCase();S=S.filter(E=>E.title.toLowerCase().includes(z)||E.sub_items&&E.sub_items.some(T=>T.toLowerCase().includes(z))||E.edition&&E.edition.toLowerCase().includes(z))}return S},[f,b,y]),_=h.useMemo(()=>{if(!$)return null;const S=[],z=new Map;for(const T of w){if(!T.volumes||T.volumes.length===0)continue;const N=T.volumes[0];z.has(N)||z.set(N,[]),z.get(N).push(T)}const E=[...z.keys()].sort((T,N)=>T-N);for(const T of E)S.push({volume:T,books:z.get(T)});return S},[w,$]);return u?e.jsx("div",{className:l,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):m?e.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:m}):f?e.jsxs("div",{className:l,style:a,children:[e.jsx(yd,{data:f}),v&&e.jsx(jd,{sections:f.sections,activeSection:b,onSelect:k}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:y,onChange:S=>j(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:i("desc-fg")},children:[w.length," ",p.unit.bu]})]}),e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[_?_.map((S,z)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:i("bg"),borderBottom:`1px solid ${i("widget-border")}`,fontSize:"12px",fontWeight:600,color:i("desc-fg"),position:"sticky",top:0,zIndex:1},children:nt(p.catalog.volume,{n:S.volume})}),S.books.map((E,T)=>e.jsx(Dr,{book:E,onNavigate:o,renderLink:s,showVolumes:E.volumes.length>1},`${S.volume}-${T}`))]},`${S.volume}-${z}`)):w.map((S,z)=>e.jsx(Dr,{book:S,onNavigate:o,renderLink:s,showVolumes:!0},z)),w.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},wd="guji_markdown";function di(t){const n=t==null?void 0:t.guji_markdown;if(typeof n!="string")return!1;const r=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!r)return!1;const o=parseInt(r[1],10),s=parseInt(r[2],10);return o>0||s>=2}const Sd=/^□\{guess=([^\s{}]+)\}/;function $d(t,n){const r=t[n+1];return r!==void 0&&!/[A-Za-z/!?>\s]/.test(r)}function js(t,n){let r=0;for(let o=n;o<t.length;o++){const s=t[o];if(s===`
131
- `)return-1;if(s==="\\"){o++;continue}if(s==="[")r++;else if(s==="]"&&(r--,r===0))return o}return-1}function _d(t){return t.replace(/\\([\\[\]<>|{}])/g,"$1")}function zd(t,n){const r=t[n];if(r==="["&&t[n+1]==="["){const o=t.indexOf("]]",n+2);return o>=0&&t.slice(n+2,o).indexOf(`
132
- `)<0?{node:{type:"qw",label:t.slice(n+2,o)},end:o+2}:null}if(r===":"&&t.startsWith(":zi[",n)){const o=js(t,n+3);return o>n+4?{node:{type:"zi",label:_d(t.slice(n+4,o))},end:o+1}:null}if(r==="□"&&t[n+1]==="{"){const o=Sd.exec(t.slice(n,n+64));if(o)return{node:{type:"qz",guess:o[1]},end:n+o[0].length}}return null}function vs(t,n,r,o){const s=[];let l="";const a=()=>{if(!l)return;const p=o?l.replace(/\\?\|/g,""):l;p&&s.push({type:"text",text:p}),l=""};for(;n<t.length;){const p=t[n];if(r!==null){if(p===r)return a(),{nodes:s,end:n};if(p===`
133
- `)return null}const c=zd(t,n);if(c){a(),s.push(c.node),n=c.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&$d(t,n)&&(d=">"),d){const u=vs(t,n+1,d,!0);if(u){a(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return r!==null?null:(a(),{nodes:s,end:n})}function ks(t){return vs(t,0,null,!1).nodes}function Cd(t){return/[<⟨□]|\[\[|:zi\[/.test(t)}function ws(t){return t.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${ws(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const Ss="guji-table-v1";function $s(t){return!!t&&t.table_notation===Ss}const Td=/^:::table(?:\{[^}]*\})?[ \t]*$/,Nd=/^:::[ \t]*$/;function _s(t){const n=[];let r="";for(let o=0;o<t.length;o++){const s=t[o];if(s===":"&&t.startsWith(":zi[",o)){const a=js(t,o+3);if(a>o+4){r+=t.slice(o,a+1),o=a;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const a=t[o+1];a!==void 0&&!/[A-Za-z/!?>\s]/.test(a)&&(l=">")}if(l){const a=t.indexOf(l,o+1);if(a>0){r+=t.slice(o,a+1),o=a;continue}}s==="|"?(n.push(r),r=""):r+=s}return n.push(r),n.map(o=>o.trim())}const Id=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function Ed(t){if(t==="^")return{cont:!0};const n=Id.exec(t),r=n[1].trim(),o=n[2]?Math.max(1,parseInt(n[2],10)):1,s=n[3]?Math.max(1,parseInt(n[3],10)):1,l=r==="_";return{cont:!1,cell:{text:l?"":r,empty:l,colspan:o,rowspan:s}}}function zs(t,n=1){const r=[],o=[],s=[];let l=[];t.forEach((p,c)=>{const d=c+n+1;let u=p.trim();if(!u)return;let x=!1;u.startsWith("!")&&(x=!0,u=u.slice(1));const m=_s(u).map(Ed),g=l.map(j=>j>0),b=l.map(j=>j>0?j-1:0),k=[];let y=0;for(const j of m){if(j.cont){g[y]||r.push(`第 ${d} 行第 ${y+1} 列:续格 ^ 上方没有跨行格`),y+=1;continue}const{cell:f}=j;for(let v=y;v<y+f.colspan;v++)if(g[v]){r.push(`第 ${d} 行第 ${v+1} 列:此处被上方跨行格占住,应写 ^`);break}if(f.rowspan>1)for(let v=y;v<y+f.colspan;v++)b[v]=f.rowspan-1;k.push(f),y+=f.colspan}for(let j=y;j<g.length;j++)g[j]&&r.push(`第 ${d} 行第 ${j+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let j=0;j<b.length;j++)b[j]===void 0&&(b[j]=0);l=b,o.push({header:x,cells:k}),s.push({width:y,line:d})});const a=s.reduce((p,c)=>Math.max(p,c.width),0);for(const p of s)p.width!==a&&r.push(`第 ${p.line} 行:占 ${p.width} 列,与总列数 ${a} 不符`);return l.some(p=>p>0)&&r.push("表尾:有跨行格超出了表的最后一行"),o.length===0&&r.push("空表"),{rows:o,columns:a,warnings:r}}function Oi(t){const n=t.split(`
130
+ }`,xs={color:"inherit",textDecoration:"none"},qc=({snippet:t})=>{const{convert:n}=O();return e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.6},children:Ti(t).map((r,o)=>r.marked?e.jsx("mark",{style:{background:i("highlight-bg"),color:i("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(r.text)},o):e.jsx(h.Fragment,{children:n(r.text)},o))})},Jc=({entry:t,selected:n,onClick:r,getConfig:o,query:s})=>{const l=fe(),{convert:a}=O(),p=a(t.title||t.primary_name||t.id),c=t.measure_info?a(t.measure_info):t.juan_count!=null&&t.juan_count>0?`${t.juan_count}${l.unit.juan}`:"",d=[...t.additional_titles||[],...t.attached_texts||[]],u=s&&d.length?d.find(g=>{const b=typeof g=="string"?g:g==null?void 0:g.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,x=i("cover-accent"),m=He();return e.jsxs("a",{href:m(t.id),onClick:g=>r(t,g),className:"bim-result-card",style:{...xs,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:i("bg"),border:n?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[e.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${x} 50%, ${i("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${x} 14%, ${i("bg")}), color-mix(in srgb, ${x} 7%, ${i("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[e.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${x} 45%, transparent)`}}),e.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:x},children:Array.from(p).map((g,b)=>e.jsx("span",{children:g},b))})]}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:i("fg")},children:p}),c&&e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:c})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg")},children:[t.dynasty&&e.jsxs("span",{children:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]})]}),(t.era||t.edition)&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[t.era&&e.jsxs("span",{children:["〔",a(t.era),"〕"]}),t.edition&&e.jsx("span",{children:a(t.edition)})]}),u&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[l.search.alias,":",a(typeof u=="string"?u:u.book_title||"")]}),t.descriptionSnippet&&e.jsx(qc,{snippet:t.descriptionSnippet}),e.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:[e.jsx(Ot,{type:t.type,size:8})," ",o(t.type).name]}),t.has_text&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.textResource}),t.has_image&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.imageResource})]})]})]})},Pr=({entry:t,selected:n,onClick:r,getConfig:o,query:s,onRemove:l})=>{const a=fe(),{convert:p}=O(),c=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&c.length?c.find(x=>{const m=typeof x=="string"?x:x==null?void 0:x.book_title;return m==null?void 0:m.toLowerCase().includes(s.toLowerCase())}):void 0,u=He();return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[e.jsxs("a",{href:u(t.id),onClick:x=>r(t,x),className:"bim-result-card",style:{...xs,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx(Ot,{type:t.type,size:12}),e.jsx("span",{style:{fontSize:"9px",color:i("desc-fg"),lineHeight:1},children:o(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg")},children:p(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{children:a.misc.textResource}),t.has_image&&e.jsx("span",{children:a.misc.imageResource})]}),(t.era||t.edition)&&e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[t.era&&e.jsxs(e.Fragment,{children:["〔",p(t.era),"〕"]}),t.edition&&p(t.edition)]}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:p(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[t.juan_count,a.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",p(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:p(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",p(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:[a.search.alias,":",p(d)]})]}),!l&&e.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&e.jsx("button",{type:"button",onClick:()=>l(t.id),title:a.search.removeFromRecent,"aria-label":a.search.removeFromRecent,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},Zc=({id:t,onRemove:n,t:r})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${i("widget-border")}`,background:i("input-bg"),opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:i("fg"),fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:r.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:r.search.removeFromRecent,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Xc(t){var n;return!t.dynasty&&!t.birth_year&&!t.death_year&&(!t.alt_names||t.alt_names.length===0)&&!((n=t.description)!=null&&n.text)}function Qc({data:t}){const{convert:n}=O(),{dynasty:r,birth_year:o,death_year:s}=t,l=[];return r&&l.push(`〔${n(r)}〕`),o!==void 0&&s!==void 0?l.push(`${o}—${s}`):o!==void 0?l.push(`${o}—?`):s!==void 0&&l.push(`?—${s}`),l.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:i("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function ed({alt_names:t}){const{convert:n}=O(),r=new Map;for(const l of t){const a=l.type||"別名";r.has(a)||r.set(a,[]),r.get(a).push(l.name)}const o=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...r.keys()].sort((l,a)=>{const p=o.indexOf(l),c=o.indexOf(a);return p===-1&&c===-1?0:p===-1?1:c===-1?-1:p-c});return e.jsx("div",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const a=r.get(l);return e.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[e.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),e.jsx("span",{children:a.map((p,c)=>e.jsxs("span",{children:[c>0&&e.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},c))})]},l)})})}function td({data:t}){const n=t.external_ids;if(!n)return null;const r=[];return n.cbdb_id&&r.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:i("link-fg"),border:`1px solid ${i("link-fg")}40`,borderRadius:"3px",textDecoration:"none",background:`${i("link-fg")}08`},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),r.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:r})}function nd({works:t,transport:n,onNavigate:r,renderLink:o}){const s=fe(),{convert:l}=O(),a=He(),[p,c]=h.useState(new Map);h.useEffect(()=>{if(!n)return;let m=!1;const g=t.map(k=>k.work_id);return(async()=>{const k=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(g);let $=!0;for(let w=0;w<g.length;w++){const _=v[w];_!=null&&_.title?k.set(g[w],_.title):_!=null&&_.primary_name?k.set(g[w],_.primary_name):$=!1}if($)return k}catch{}const y=[...g],j=8,f=new Array(j).fill(0).map(async()=>{for(;y.length;){const v=y.shift();if(!v)break;if(!k.has(v))try{if(n.getEntry){const _=await n.getEntry(v);if(_!=null&&_.title){k.set(v,_.title);continue}}const $=await n.getItem(v),w=$&&($.title||$.primary_name)||v;k.set(v,w)}catch{k.set(v,v)}}});return await Promise.all(f),k})().then(k=>{m||c(k)}),()=>{m=!0}},[t,n]);const d=new Map;for(const m of t){const g=m.role||"";d.has(g)||d.set(g,[]),d.get(g).push(m)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...d.keys()].sort((m,g)=>{const b=u.indexOf(m),k=u.indexOf(g);return b===-1&&k===-1?m.localeCompare(g):b===-1?1:k===-1?-1:b-k});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:i("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:i("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),x.map(m=>{const g=d.get(m);return e.jsxs("div",{style:{marginBottom:"8px"},children:[m&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"2px"},children:[l(m)," ",e.jsxs("span",{style:{color:i("desc-fg")},children:["(",g.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:m?"16px":"0",listStyle:m?"disc":"none",fontSize:"14px",lineHeight:1.8},children:g.map((b,k)=>{const y=l(p.get(b.work_id)||b.work_id);return o?e.jsx("li",{children:o(b.work_id,y)},k):r?e.jsx("li",{children:e.jsx("a",{href:a(b.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),r(b.work_id))},style:{color:i("link-fg"),textDecoration:"underline",cursor:"pointer"},children:y})},k):e.jsx("li",{children:y},k)})})]},m)})]})}const hs=({data:t,transport:n,onNavigate:r,renderLink:o,headerExtra:s,hideHeader:l})=>{var x;const a=fe(),{convert:p}=O();let c=!1;try{c=be.extractStatus(t.id)==="draft"}catch{}const d=Xc(t),u=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[!l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:i("fg")},children:[p(t.primary_name),e.jsx(Qc,{data:t})]}),s]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:i("desc-fg"),marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:i("type-entity"),border:`1px solid color-mix(in srgb, ${i("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${i("type-entity")} 3%, transparent)`},children:a.indexType.entity}),u&&t.subtype!=="people"&&e.jsx("span",{children:u}),c&&e.jsx("span",{style:{padding:"1px 6px",background:i("warn-bg"),border:`1px solid ${i("warn-border")}`,borderRadius:"2px",color:i("warn-fg")},children:a.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]})]}),d&&e.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:i("widget-bg"),border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(ed,{alt_names:t.alt_names}),e.jsx(td,{data:t}),((x=t.description)==null?void 0:x.text)&&e.jsx("p",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(t.description.text)}),t.works&&t.works.length>0&&e.jsx(nd,{works:t.works,transport:n,onNavigate:r,renderLink:o})]})},id=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function rd(t){const n=t.search(id);return n<0?[t,""]:[t.slice(0,n),t.slice(n)]}const gs={p:({children:t})=>e.jsx("p",{style:{margin:"0 0 0.5em"},children:t}),ul:({children:t})=>e.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:t}),ol:({children:t})=>e.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:t}),li:({children:t})=>e.jsx("li",{style:{marginBottom:"2px"},children:t}),a:({href:t,children:n})=>{let r=t,o="",s=n;if(t&&typeof n=="string"&&(n===t||n===od(t))){const[l,a]=rd(n);a&&(r=encodeURI(l),s=l,o=a)}return e.jsxs(e.Fragment,{children:[e.jsx("a",{href:r,target:r!=null&&r.startsWith("http")?"_blank":void 0,rel:r!=null&&r.startsWith("http")?"noopener noreferrer":void 0,style:{color:i("link")},children:s}),o]})},code:({children:t})=>e.jsx("code",{style:{background:i("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:t})};function od(t){try{return decodeURI(t)}catch{return t}}const sd={...gs,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},pt=({text:t,plainStrong:n,style:r,className:o})=>{const{convert:s}=O(),l=n?sd:gs;return e.jsx("div",{className:o,style:r,children:e.jsx(Ja,{remarkPlugins:[Za],components:l,children:s(t)})})},ld=["〇","一","二","三","四","五","六","七","八","九"],Dr=["","十","百","千"];function fs(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),r=n.length;let o="",s=!1;for(let l=0;l<r;l++){const a=parseInt(n[l]),p=r-1-l;a===0?s=!0:(s&&o&&(o+="〇"),s=!1,a===1&&p===1&&l===0?o+=Dr[p]:o+=ld[a]+Dr[p])}return o}function bs(t){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t,border:`1px solid color-mix(in srgb, ${t} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${t} 3%, transparent)`}}const ad={book:i("type-book"),work:i("type-work"),collection:i("type-collection"),entity:i("type-entity")};function cd({type:t}){const n=fe();return e.jsx("span",{style:bs(ad[t]),children:n.indexType[t]})}function dd({isDraft:t}){const n=fe(),r=i(t?"status-draft":"status-official");return e.jsx("span",{style:bs(r),children:t?n.status.draft:n.status.official})}function pd({id:t}){const n=fe(),[r,o]=h.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:i("desc-fg"),background:i("bg-subtle"),border:`1px solid ${i("widget-border")}`,borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:i("fg")},children:t}),e.jsx("span",{onClick:s,title:r?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:r?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=r?"1":"0.5",children:r?"✓":"⧉"})]})}function Qe({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("desc-fg"),letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function ot({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:t}),e.jsx("span",{style:{color:i("fg")},children:n})]})}function ys({authors:t,type:n,onNavigate:r,renderLink:o}){const{convert:s}=O();return e.jsx("span",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.6},children:t.map((l,a)=>{const p=s(l.name),c=l.entity_id?e.jsx(it,{id:l.entity_id,label:p,onNavigate:r,renderLink:o}):e.jsx("span",{style:{fontWeight:500},children:p});return e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&e.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),c,l.role&&e.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},a)})})}function it({id:t,label:n,onNavigate:r,renderLink:o}){const s=He();return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:s(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),r(t))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`,paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function ud({id:t,title:n,edition:r,type:o,isDraft:s,authors:l,volumeText:a,meta:p,headerExtra:c,onNavigate:d,renderLink:u}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:i("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,r&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:r}),a&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:a})]}),c&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(cd,{type:o}),e.jsx(dd,{isDraft:s}),e.jsx(pd,{id:t})]}),((l==null?void 0:l.length)||p.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&e.jsx(ys,{authors:l,type:o,onNavigate:d,renderLink:u}),p]})]})}function js({items:t,label:n,showMeta:r,onNavigate:o,renderLink:s}){const l=fe(),{convert:a}=O();if(!t.length)return null;const[p,c]=h.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,u)=>{const x=p===u;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:i("shadow-card")}:{}},children:[e.jsxs("div",{onClick:()=>c(x?null:u),style:{padding:"8px 12px",background:i("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:a(d.source)}),!x&&r&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:m=>m.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(it,{id:d.source_bid,label:l.action.view,onNavigate:o,renderLink:s})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${i("widget-border")}`},children:[r&&(d.title_info||d.author_info||d.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&e.jsx(ot,{label:l.label.titleInfo,children:a(d.title_info)}),d.author_info&&e.jsx(ot,{label:l.label.authorInfo,children:a(d.author_info)}),d.edition&&e.jsx(ot,{label:l.label.edition,children:a(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${i("primary")}`,background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:a(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.additional_comment)})]})]})]},u)})})]})}function md({items:t,onNavigate:n,renderLink:r}){const o=fe();return e.jsx(js,{items:t,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:r})}function vs({items:t,onNavigate:n,renderLink:r}){const o=fe();return e.jsx(js,{items:t,label:o.section.emendated,onNavigate:n,renderLink:r})}function ks({label:t,items:n}){const{convert:r}=O();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((o,s)=>{const l=typeof o=="string"?o:o.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:i("fg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:r(l)},s)})})]}):null}function xd({items:t}){const n=fe();return e.jsx(ks,{label:n.section.aliases,items:t})}function hd({items:t}){const n=fe();return e.jsx(ks,{label:n.section.attachedTexts,items:t})}function gd({items:t}){const n=fe(),{convert:r}=O();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:i("fg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:["《",r(o.book_title),"》",o.n_juan!=null&&e.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},s))})]}):null}function fd({items:t}){const n=fe(),{convert:r}=O();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:i("widget-border")}}),t.map((o,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:i("primary"),border:`1.5px solid ${i("input-bg")}`}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:i("fg")},children:r(o.name)}),o.description&&e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),marginLeft:"8px"},children:r(o.description)})]},s))]})]}):null}function bd({items:t}){const n=fe(),{convert:r}=O();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((o,s)=>e.jsxs("div",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:i("desc-fg")},children:"·"}),r(o)]},s))})]}):null}function Hr({title:t,ids:n,transport:r,onNavigate:o,renderLink:s}){const{convert:l}=O(),[a,p]=h.useState([]);return h.useEffect(()=>{if(!n.length){p([]);return}if(!r){p(n.map(d=>({id:d})));return}let c=!1;return Promise.all(n.map(d=>r.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{c||p(d)}),()=>{c=!0}},[n,r]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(Qe,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(a.length?a:n.map(c=>({id:c}))).map(c=>{const d=c.edition?`${l(c.title)||c.id}(${l(c.edition)})`:l(c.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),transition:"border-color 0.15s"},children:e.jsx(it,{id:c.id,label:d,onNavigate:o,renderLink:s})},c.id)})})]}):null}function qn({book:t,onNavigate:n,renderLink:r}){const o=fe(),{convert:s}=O(),[l,a]=h.useState(!1),p=t.resources&&t.resources.length>0,c=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:i("input-bg")},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${i("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:e.jsx(it,{id:t.id,label:c,onNavigate:n,renderLink:r})}),p&&e.jsx("span",{onClick:()=>a(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:i("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?o.action.expand:o.action.collapse,children:"▼"})]}),p&&!l&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(Li,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:r})})]})}function yd({ids:t,workData:n,transport:r,onNavigate:o,renderLink:s,footer:l}){const a=fe(),{convert:p}=O(),[c,d]=h.useState([]);if(h.useEffect(()=>{if(!t.length){d([]);return}if(!r){d(t.map(k=>({id:k})));return}let b=!1;return Promise.all(t.map(k=>r.getItem(k).then(y=>({id:k,title:y?y.title:void 0,edition:y?y.edition:void 0,resources:y?y.resources:void 0,resource_groups:y?y.resource_groups:void 0})).catch(()=>({id:k})))).then(k=>{b||d(k)}),()=>{b=!0}},[t,r]),!t.length)return null;const u=c.length?c:t.map(b=>({id:b})),x=new Map(u.map(b=>[b.id,b])),m=n==null?void 0:n.version_graph,g=jd(t,m);return e.jsxs(e.Fragment,{children:[e.jsxs(Qe,{children:[a.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",t.length,")"]})]}),l,g.useGrouping?e.jsxs(e.Fragment,{children:[g.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:g.coreIds.map(b=>{const k=x.get(b);return k?e.jsx(qn,{book:k,onNavigate:o,renderLink:s},b):null})}),g.groupedIds.map(b=>e.jsxs("details",{style:{marginTop:12,border:`1px solid ${i("widget-border")}`,borderRadius:6,background:i("bg-subtle")},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:i("fg"),userSelect:"none"},children:[p(b.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:i("desc-fg"),fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:i("desc-fg"),fontWeight:400},children:p(b.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(k=>{const y=x.get(k);return y?e.jsx(qn,{book:y,onNavigate:o,renderLink:s},k):null})})]},b.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(b=>e.jsx(qn,{book:b,onNavigate:o,renderLink:s},b.id))})]})}function jd(t,n){var y,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const r=(y=n.collections)==null?void 0:y[n.default_collection],o=(r==null?void 0:r.groups)??[],s=(r==null?void 0:r.book_ids)??[],l=o.length>0||s.length>0,a=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const p=new Set(o),c=new Set([...s,...a]),d=f=>{if(c.has(f))return!0;const v=n.node_groups[f];return v!=null&&p.has(v)},u=[],x=new Map,m=[];for(const f of t)if(!((j=n.excluded_books)!=null&&j.includes(f)))if(d(f))u.push(f);else{const v=n.node_groups[f];v?(x.has(v)||x.set(v,[]),x.get(v).push(f)):m.push(f)}if(m.length+[...x.values()].reduce((f,v)=>f+v.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(f=>[f.id,f])),k=[...x.entries()].map(([f,v])=>{const $=b.get(f);return{id:f,label:($==null?void 0:$.label)??f,description:$==null?void 0:$.description,ids:v}});return m.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:m}),{useGrouping:!0,coreIds:u,groupedIds:k}}function vd({workData:t,onNavigate:n,renderLink:r}){var a,p,c,d;const o=fe(),{convert:s}=O(),l=!!((a=t.description)!=null&&a.text)||!!t.parent_work;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:i("input-bg"),marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?`1px solid ${i("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`},children:[e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:e.jsx(it,{id:t.id,label:s(t.title),onNavigate:n,renderLink:r})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:s(t.measure_info)}):((p=t.juan_count)==null?void 0:p.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[fs(t.juan_count.number),o.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(ys,{authors:t.authors,type:"work",onNavigate:n,renderLink:r})})]}),l&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((c=t.description)==null?void 0:c.text)&&e.jsx(pt,{text:t.description.text,style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,textAlign:"justify"}}),t.parent_work&&e.jsx("div",{style:{marginTop:(d=t.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:e.jsx(ot,{label:o.label.parentWork,children:e.jsx(it,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:r})})})]})]})}function kd({items:t,onNavigate:n,renderLink:r}){const o=fe(),{convert:s}=O();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(l=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid color-mix(in srgb, ${i("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${i("type-collection")} 3%, transparent)`},children:[e.jsx("span",{style:{fontSize:"11px",color:i("type-collection")},children:o.indexType.collection}),e.jsx(it,{id:l.id,label:s(l.title)||l.id,onNavigate:n,renderLink:r}),l.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"2px"},children:nt(o.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Oi=({data:t,id:n,transport:r,onNavigate:o,renderLink:s,headerExtra:l,relatedBooksFooter:a,className:p,style:c})=>{var V,W,B,H,te,se,J,D;const d=fe(),{convert:u}=O(),[x,m]=h.useState(null),[g,b]=h.useState(!1),[k,y]=h.useState(null),[j,f]=h.useState(null),[v,$]=h.useState([]),w=t||x;if(h.useEffect(()=>{if(t||!n||!r)return;let L=!1;return b(!0),y(null),r.getItem(n).then(le=>{L||(le?m(le):y(d.misc.notFoundEntry))}).catch(le=>{L||y(le instanceof Error?le.message:d.misc.loadFailed)}).finally(()=>{L||b(!1)}),()=>{L=!0}},[t,n,r]),h.useEffect(()=>{if(!w||!r){f(null),$([]);return}let L=!1;const le=w.type==="book"||w.type==="collection"?w.work_id:void 0;if(le?r.getItem(le).then(A=>{!L&&A&&A.type==="work"&&f(A)}).catch(()=>{}):f(null),w.type==="book"){const A=w;A.contained_in&&A.contained_in.length>0?Promise.all(A.contained_in.map(ne=>{const de=typeof ne=="string"?ne:ne.id,G=typeof ne=="string"?void 0:ne.volume_index;return r.getItem(de).then(he=>({id:de,title:he&&he.title||de,volume_index:G})).catch(()=>({id:de,title:de,volume_index:G}))})).then(ne=>{L||$(ne)}):$([])}else $([]);return()=>{L=!0}},[w,r]),g)return e.jsx("div",{className:p,style:{...c,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((L,le)=>e.jsx("div",{style:{height:le===1?"32px":"16px",width:`${L}px`,background:i("widget-border"),borderRadius:"4px",opacity:.4}},le))})});if(k)return e.jsx("div",{className:p,style:{...c,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:k});if(!w)return null;if(w.type==="entity")return e.jsx("div",{className:p,style:c,children:e.jsx(hs,{data:w,transport:r,onNavigate:o,renderLink:s,headerExtra:l})});const _=w.type==="book"?w:null,S=w.type==="collection"?w:null,z=w.type==="work"?w:null;let E=!1;try{E=be.extractStatus(w.id)==="draft"}catch{}let T="";w.measure_info?T=u(w.measure_info):(V=w.juan_count)!=null&&V.number?T=fs(w.juan_count.number)+d.unit.juan:(W=w.juan_count)!=null&&W.description&&(T=u(w.juan_count.description));const N=[];return(B=w.publication_info)!=null&&B.year&&N.push(e.jsx(ot,{label:d.label.year,children:w.publication_info.year},"year")),(H=w.current_location)!=null&&H.name&&N.push(e.jsx(ot,{label:d.label.currentLocation,children:u(w.current_location.name)},"loc")),(te=w.page_count)!=null&&te.description&&N.push(e.jsx(ot,{label:d.label.pageCount,children:w.page_count.description},"page")),_!=null&&_.edition&&N.push(e.jsx(ot,{label:d.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&N.push(e.jsx(ot,{label:d.label.parentWork,children:e.jsx(it,{id:z.parent_work.id,label:u(z.parent_work.title),onNavigate:o,renderLink:s})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&N.push(e.jsx(ot,{label:d.label.parentWork,children:z.parent_works.map((L,le)=>e.jsxs("span",{children:[le>0&&"、",e.jsx(it,{id:L,onNavigate:o,renderLink:s})]},L))},"pws")),e.jsxs("div",{className:p,style:c,children:[e.jsx(ud,{id:w.id,title:u(w.title),edition:w.edition?u(w.edition):void 0,type:w.type,isDraft:E,authors:w.authors,volumeText:T,meta:N,headerExtra:l,onNavigate:o,renderLink:s}),((se=w.description)==null?void 0:se.text)&&e.jsx(pt,{text:w.description.text,style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),w.appendix&&w.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:w.appendix.map((L,le)=>e.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:i("bg-subtle"),borderRadius:4,border:`1px solid ${i("widget-border")}`},children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:i("muted")},children:u(L.title)}),e.jsx(pt,{text:L.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:i("fg")}})]},le))}),v.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:d.section.containedIn}),e.jsx(kd,{items:v,onNavigate:o,renderLink:s})]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:d.section.belongsToWork}),e.jsx(vd,{workData:j,onNavigate:o,renderLink:s})]}),w.additional_works&&w.additional_works.length>0&&e.jsx(gd,{items:w.additional_works}),w.additional_titles&&w.additional_titles.length>0&&e.jsx(xd,{items:w.additional_titles}),w.attached_texts&&w.attached_texts.length>0&&e.jsx(hd,{items:w.attached_texts}),w.indexed_by&&w.indexed_by.length>0&&e.jsx(md,{items:w.indexed_by,onNavigate:o,renderLink:s}),w.emendated_by&&w.emendated_by.length>0&&e.jsx(vs,{items:w.emendated_by,onNavigate:o,renderLink:s}),w.resources&&w.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Qe,{children:d.section.resources}),e.jsx(Li,{items:w.resources,resourceGroups:w.resource_groups,groupByType:!0,onNavigate:o,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&e.jsx(fd,{items:_.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(bd,{items:S.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&e.jsx(Hr,{title:d.section.relatedVersions,ids:_.related_books,transport:r,onNavigate:o,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(Hr,{title:d.section.containedBooks,ids:S.books,transport:r,onNavigate:o,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(Qe,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",S.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(L=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:e.jsx(it,{id:L.id,label:u(L.title),onNavigate:o,renderLink:s})},L.id))})]}),(((J=z==null?void 0:z.books)==null?void 0:J.length)||0)+(((D=z==null?void 0:z.collections)==null?void 0:D.length)||0)>0&&e.jsx(yd,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z??void 0,transport:r,onNavigate:o,renderLink:s,footer:a}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const L=[],le=z.related_works.filter(ye=>ye.relation==="part_of"),A=z.related_works.filter(ye=>ye.relation==="has_part"),ne=z.related_works.filter(ye=>ye.relation==="has_adaptation"),de=z.related_works.filter(ye=>ye.relation==="text_carried_by"),G=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),he=z.related_works.filter(ye=>!ye.relation||!G.has(ye.relation));return le.length>0&&L.push({label:d.section.belongsToWork,items:le}),A.length>0&&L.push({label:d.section.containedWorks,items:A}),ne.length>0&&L.push({label:d.section.adaptations,items:ne}),de.length>0&&L.push({label:d.section.derivativeWorks,items:de}),he.length>0&&L.push({label:d.section.relatedWorks,items:he}),L.map(ye=>e.jsxs("div",{children:[e.jsxs(Qe,{children:[ye.label,e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",ye.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:ye.items.map(xe=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:e.jsx(it,{id:xe.id,label:u(xe.title),onNavigate:o,renderLink:s})},xe.id))})]},ye.label))})()]})};function wd({data:t}){const n=fe(),{convert:r}=O(),{stats:o}=t,s=o.processed_volumes??o.total_found_volumes,l=s!=null&&t.total_volumes>0?Math.round(s/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:r(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"6px"},children:r(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:i("desc-fg")},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:i("fg")},children:t.total_volumes})," ",n.unit.volume]}),l!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:i("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:i("fg")},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:i("fg")},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:i("missing-fg")},children:o.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:i("desc-fg")},children:[n.catalog.source," ",t.source]})]})}function Sd({sections:t,activeSection:n,onSelect:r}){const o=fe();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>r(null),style:Gr(n===null),children:o.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>r(s.name),style:Gr(n===s.name),children:[s.name,s.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function Gr(t){return{padding:"4px 12px",border:t?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:t?`color-mix(in srgb, ${i("primary")} 8%, transparent)`:"transparent",color:i(t?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function $d({id:t,label:n,onNavigate:r,renderLink:o}){const s=He();return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:s(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),r(t))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:n||t})}function _d(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const r=t[0],o=t[t.length-1];return o-r+1===t.length?`${r}–${o}`:t.length<=3?t.join(", "):`${r}–${o} (${t.length}${n})`}function Ur({book:t,onNavigate:n,renderLink:r,showVolumes:o}){const s=fe(),{convert:l}=O(),a=t.book_id||t.work_id,p=o&&t.volumes.length>0?_d(t.volumes,s.unit.volume):null,c=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${i("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[o&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:i("desc-fg"),textAlign:"right"},children:p}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:i("fg")},children:[l(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(d=>l(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:i(c?"missing-fg":"desc-fg"),flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),a&&e.jsx($d,{id:a,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:r}),!a&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const Fi=({data:t,collectionId:n,transport:r,onNavigate:o,renderLink:s,className:l,style:a})=>{const p=fe(),[c,d]=h.useState(null),[u,x]=h.useState(!1),[m,g]=h.useState(null),[b,k]=h.useState(null),[y,j]=h.useState(""),f=t||c;h.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollectionCatalog))return;let S=!1;return x(!0),g(null),r.getCollectionCatalog(n).then(z=>{S||(z?d(z):g(p.catalog.notFound))}).catch(z=>{S||g(z instanceof Error?z.message:p.catalog.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,r,p]);const v=(f==null?void 0:f.sections)&&f.sections.length>0,$=h.useMemo(()=>{if(!f)return!1;if(f.volume_index&&Object.keys(f.volume_index).length>0)return!0;const S=f.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(S).size<S.length},[f]),w=h.useMemo(()=>{if(!f)return[];let S=f.books;if(b&&(S=S.filter(z=>z.section===b)),y.trim()){const z=y.trim().toLowerCase();S=S.filter(E=>E.title.toLowerCase().includes(z)||E.sub_items&&E.sub_items.some(T=>T.toLowerCase().includes(z))||E.edition&&E.edition.toLowerCase().includes(z))}return S},[f,b,y]),_=h.useMemo(()=>{if(!$)return null;const S=[],z=new Map;for(const T of w){if(!T.volumes||T.volumes.length===0)continue;const N=T.volumes[0];z.has(N)||z.set(N,[]),z.get(N).push(T)}const E=[...z.keys()].sort((T,N)=>T-N);for(const T of E)S.push({volume:T,books:z.get(T)});return S},[w,$]);return u?e.jsx("div",{className:l,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):m?e.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:m}):f?e.jsxs("div",{className:l,style:a,children:[e.jsx(wd,{data:f}),v&&e.jsx(Sd,{sections:f.sections,activeSection:b,onSelect:k}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:y,onChange:S=>j(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:i("desc-fg")},children:[w.length," ",p.unit.bu]})]}),e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[_?_.map((S,z)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:i("bg"),borderBottom:`1px solid ${i("widget-border")}`,fontSize:"12px",fontWeight:600,color:i("desc-fg"),position:"sticky",top:0,zIndex:1},children:nt(p.catalog.volume,{n:S.volume})}),S.books.map((E,T)=>e.jsx(Ur,{book:E,onNavigate:o,renderLink:s,showVolumes:E.volumes.length>1},`${S.volume}-${T}`))]},`${S.volume}-${z}`)):w.map((S,z)=>e.jsx(Ur,{book:S,onNavigate:o,renderLink:s,showVolumes:!0},z)),w.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},zd="guji_markdown";function pi(t){const n=t==null?void 0:t.guji_markdown;if(typeof n!="string")return!1;const r=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!r)return!1;const o=parseInt(r[1],10),s=parseInt(r[2],10);return o>0||s>=2}const Cd=/^□\{guess=([^\s{}]+)\}/;function Td(t,n){const r=t[n+1];return r!==void 0&&!/[A-Za-z/!?>\s]/.test(r)}function ws(t,n){let r=0;for(let o=n;o<t.length;o++){const s=t[o];if(s===`
131
+ `)return-1;if(s==="\\"){o++;continue}if(s==="[")r++;else if(s==="]"&&(r--,r===0))return o}return-1}function Nd(t){return t.replace(/\\([\\[\]<>|{}])/g,"$1")}function Id(t,n){const r=t[n];if(r==="["&&t[n+1]==="["){const o=t.indexOf("]]",n+2);return o>=0&&t.slice(n+2,o).indexOf(`
132
+ `)<0?{node:{type:"qw",label:t.slice(n+2,o)},end:o+2}:null}if(r===":"&&t.startsWith(":zi[",n)){const o=ws(t,n+3);return o>n+4?{node:{type:"zi",label:Nd(t.slice(n+4,o))},end:o+1}:null}if(r==="□"&&t[n+1]==="{"){const o=Cd.exec(t.slice(n,n+64));if(o)return{node:{type:"qz",guess:o[1]},end:n+o[0].length}}return null}function Ss(t,n,r,o){const s=[];let l="";const a=()=>{if(!l)return;const p=o?l.replace(/\\?\|/g,""):l;p&&s.push({type:"text",text:p}),l=""};for(;n<t.length;){const p=t[n];if(r!==null){if(p===r)return a(),{nodes:s,end:n};if(p===`
133
+ `)return null}const c=Id(t,n);if(c){a(),s.push(c.node),n=c.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&Td(t,n)&&(d=">"),d){const u=Ss(t,n+1,d,!0);if(u){a(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return r!==null?null:(a(),{nodes:s,end:n})}function $s(t){return Ss(t,0,null,!1).nodes}function Ed(t){return/[<⟨□]|\[\[|:zi\[/.test(t)}function _s(t){return t.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${_s(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const zs="guji-table-v1";function Cs(t){return!!t&&t.table_notation===zs}const Rd=/^:::table(?:\{[^}]*\})?[ \t]*$/,Ld=/^:::[ \t]*$/;function Ts(t){const n=[];let r="";for(let o=0;o<t.length;o++){const s=t[o];if(s===":"&&t.startsWith(":zi[",o)){const a=ws(t,o+3);if(a>o+4){r+=t.slice(o,a+1),o=a;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const a=t[o+1];a!==void 0&&!/[A-Za-z/!?>\s]/.test(a)&&(l=">")}if(l){const a=t.indexOf(l,o+1);if(a>0){r+=t.slice(o,a+1),o=a;continue}}s==="|"?(n.push(r),r=""):r+=s}return n.push(r),n.map(o=>o.trim())}const Ad=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function Bd(t){if(t==="^")return{cont:!0};const n=Ad.exec(t),r=n[1].trim(),o=n[2]?Math.max(1,parseInt(n[2],10)):1,s=n[3]?Math.max(1,parseInt(n[3],10)):1,l=r==="_";return{cont:!1,cell:{text:l?"":r,empty:l,colspan:o,rowspan:s}}}function Ns(t,n=1){const r=[],o=[],s=[];let l=[];t.forEach((p,c)=>{const d=c+n+1;let u=p.trim();if(!u)return;let x=!1;u.startsWith("!")&&(x=!0,u=u.slice(1));const m=Ts(u).map(Bd),g=l.map(j=>j>0),b=l.map(j=>j>0?j-1:0),k=[];let y=0;for(const j of m){if(j.cont){g[y]||r.push(`第 ${d} 行第 ${y+1} 列:续格 ^ 上方没有跨行格`),y+=1;continue}const{cell:f}=j;for(let v=y;v<y+f.colspan;v++)if(g[v]){r.push(`第 ${d} 行第 ${v+1} 列:此处被上方跨行格占住,应写 ^`);break}if(f.rowspan>1)for(let v=y;v<y+f.colspan;v++)b[v]=f.rowspan-1;k.push(f),y+=f.colspan}for(let j=y;j<g.length;j++)g[j]&&r.push(`第 ${d} 行第 ${j+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let j=0;j<b.length;j++)b[j]===void 0&&(b[j]=0);l=b,o.push({header:x,cells:k}),s.push({width:y,line:d})});const a=s.reduce((p,c)=>Math.max(p,c.width),0);for(const p of s)p.width!==a&&r.push(`第 ${p.line} 行:占 ${p.width} 列,与总列数 ${a} 不符`);return l.some(p=>p>0)&&r.push("表尾:有跨行格超出了表的最后一行"),o.length===0&&r.push("空表"),{rows:o,columns:a,warnings:r}}function Pi(t){const n=t.split(`
134
134
  `),r=[];let o=[];const s=()=>{if(o.length===0)return;const a=o.join(`
135
- `);o=[],r.push({type:"text",text:a})};let l=0;for(;l<n.length;){if(Td.test(n[l].trim())){let a=l+1;for(;a<n.length&&!Nd.test(n[a].trim());)a++;if(a<n.length){s();const p=n.slice(l+1,a);r.push({type:"table",table:zs(p,l+1),source:n.slice(l,a+1).join(`
136
- `)}),l=a+1;continue}}o.push(n[l]),l++}return s(),r.map((a,p)=>{var d,u;if(a.type!=="text")return a;let c=a.text;return((d=r[p-1])==null?void 0:d.type)==="table"&&(c=c.replace(/^\n+/,"")),((u=r[p+1])==null?void 0:u.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(a=>a.type!=="text"||a.text!=="")}const qn=t=>t?t.catch(()=>null):Promise.resolve(null);function Cs(t){const n=new Map;function r(o){var l;let s=n.get(o);return s||(s=qn((l=t.getTextManifest)==null?void 0:l.call(t,o)).then(a=>{const p=a&&Array.isArray(a.versions)&&a.versions.length>0?a:null;return p||n.delete(o),p}),n.set(o,s)),s}return{getManifest(o){return be.isSafeSegment(o)?r(o):Promise.resolve(null)},async getIndex(o,s){return!be.isSafeSegment(o)||!be.isSafeSegment(s)||!t.getTextIndex?null:qn(t.getTextIndex(o,s))},async getChapter(o,s,l,a){return!be.isSafeSegment(o)||!be.isSafeSegment(s)||!be.isSafeSegment(l)||!t.getChapter?null:qn(t.getChapter(o,s,l,a))}}}const zt=()=>{const[t,n]=h.useState(1);return h.useEffect(()=>{const r=setInterval(()=>n(o=>o>=3?1:o+1),500);return()=>clearInterval(r)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:i("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(t)})},Ts="(min-width: 1100px)",Ns="(max-width: 719px)",Is="(max-width: 859px)",Rd=`${Ns}, (pointer: coarse)`,xt=i("reader-top"),Ld="48px",Es=`
135
+ `);o=[],r.push({type:"text",text:a})};let l=0;for(;l<n.length;){if(Rd.test(n[l].trim())){let a=l+1;for(;a<n.length&&!Ld.test(n[a].trim());)a++;if(a<n.length){s();const p=n.slice(l+1,a);r.push({type:"table",table:Ns(p,l+1),source:n.slice(l,a+1).join(`
136
+ `)}),l=a+1;continue}}o.push(n[l]),l++}return s(),r.map((a,p)=>{var d,u;if(a.type!=="text")return a;let c=a.text;return((d=r[p-1])==null?void 0:d.type)==="table"&&(c=c.replace(/^\n+/,"")),((u=r[p+1])==null?void 0:u.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(a=>a.type!=="text"||a.text!=="")}const Jn=t=>t?t.catch(()=>null):Promise.resolve(null);function Is(t){const n=new Map;function r(o){var l;let s=n.get(o);return s||(s=Jn((l=t.getTextManifest)==null?void 0:l.call(t,o)).then(a=>{const p=a&&Array.isArray(a.versions)&&a.versions.length>0?a:null;return p||n.delete(o),p}),n.set(o,s)),s}return{getManifest(o){return be.isSafeSegment(o)?r(o):Promise.resolve(null)},async getIndex(o,s){return!be.isSafeSegment(o)||!be.isSafeSegment(s)||!t.getTextIndex?null:Jn(t.getTextIndex(o,s))},async getChapter(o,s,l,a){return!be.isSafeSegment(o)||!be.isSafeSegment(s)||!be.isSafeSegment(l)||!t.getChapter?null:Jn(t.getChapter(o,s,l,a))}}}const zt=()=>{const[t,n]=h.useState(1);return h.useEffect(()=>{const r=setInterval(()=>n(o=>o>=3?1:o+1),500);return()=>clearInterval(r)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:i("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(t)})},Es="(min-width: 1100px)",Rs="(max-width: 719px)",Ls="(max-width: 859px)",Md=`${Rs}, (pointer: coarse)`,xt=i("reader-top"),Wd="48px",As=`
137
137
  .bim-rd {
138
138
  position: relative;
139
139
  background: ${i("page-bg")};
140
140
  color: ${i("ink")};
141
141
  font-family: ${i("font-ui")};
142
- --bimrd-bar-h: ${Ld};
142
+ --bimrd-bar-h: ${Wd};
143
143
  }
144
144
  .bim-rd *, .bim-rd *::before, .bim-rd *::after { box-sizing: border-box; }
145
145
 
@@ -429,7 +429,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
429
429
  .bim-rd-sheet-img .bim-rd-img-fig img { max-height: 60vh; }
430
430
  .bim-rd-sheet-fs { display: flex; align-items: center; justify-content: center; gap: 24px; padding: 8px 0 12px; font-size: 15px; color: ${i("ink")}; }
431
431
  .bim-rd-sheet-fs .bim-rd-t { min-width: 56px; min-height: 44px; justify-content: center; font-size: 17px; border: 1px solid ${i("rule")}; }
432
- @media ${Is} {
432
+ @media ${Ls} {
433
433
  .bim-rd[data-bb] .bim-rd-text { padding-bottom: calc(56px + 64px + env(safe-area-inset-bottom, 0px)); }
434
434
  /* 底栏上已有的,工具条上不再重复(目录、字号) */
435
435
  .bim-rd[data-bb] .bim-rd-bb-dup { display: none !important; }
@@ -439,7 +439,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
439
439
 
440
440
  /* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
441
441
  A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
442
- @media ${Rd} {
442
+ @media ${Md} {
443
443
  .bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
444
444
  .bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
445
445
  content: ""; position: absolute; left: 50%; top: 50%;
@@ -452,7 +452,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
452
452
  }
453
453
 
454
454
  /* ── 中屏以下:目录改抽屉 ── */
455
- @media not all and ${Ts} {
455
+ @media not all and ${Es} {
456
456
  .bim-rd-toc {
457
457
  position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto;
458
458
  width: min(86vw, 320px);
@@ -466,7 +466,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
466
466
  }
467
467
 
468
468
  /* ── 窄屏:书影收起,只留正文 ── */
469
- @media ${Ns} {
469
+ @media ${Rs} {
470
470
  .bim-rd-bar { padding: 0 12px; gap: 10px; }
471
471
  .bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
472
472
  /* 工具条放不下时(版本、自然段、标出作品链接都在)在条内左右滑,不撑宽页面 */
@@ -500,12 +500,12 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
500
500
  :root[data-theme="ink"] .bim-rd-t[aria-pressed="true"], :root[data-theme="ink"] .bim-rd-t[aria-current="true"] {
501
501
  text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px;
502
502
  }
503
- `;function Pi(t,n){var r;return n?t.key===n?!0:!!((r=t.children)!=null&&r.some(o=>Pi(o,n))):!1}const Ad=()=>e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:e.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Bd({item:t,activeKey:n,onSelect:r,tabKey:o}){const s=Pi(t,n),[l,a]=h.useState(s||!!t.defaultExpanded);return h.useEffect(()=>{s&&a(!0)},[s]),h.useEffect(()=>{t.defaultExpanded&&a(!0)},[t.defaultExpanded]),e.jsxs("li",{children:[e.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":t.key,tabIndex:o===t.key?0:-1,onClick:()=>a(p=>!p),children:[e.jsx(Ad,{}),e.jsx("span",{children:t.label}),t.hint!=null&&e.jsx("span",{className:"bim-rd-hint",children:t.hint})]}),l&&e.jsx(Rs,{items:t.children,activeKey:n,onSelect:r,tabKey:o})]})}function Rs({items:t,activeKey:n,onSelect:r,tabKey:o}){return e.jsx("ul",{children:t.map(s=>s.children&&s.children.length>0?e.jsx(Bd,{item:s,activeKey:n,onSelect:r,tabKey:o},s.key):e.jsx("li",{children:e.jsxs("button",{type:"button",className:"bim-rd-ti","aria-current":s.key===n?"true":void 0,disabled:s.disabled,"data-rd-toc-key":s.key,tabIndex:o===s.key?0:-1,onClick:()=>r(s.key),children:[e.jsx("span",{children:s.label}),s.hint!=null&&e.jsx("span",{className:"bim-rd-hint",children:s.hint})]})},s.key))})}function Hr(t,n){var r;for(const o of t)if(o.key===n||Pi(o,n))return o.key;return((r=t[0])==null?void 0:r.key)??null}function Ls({items:t,activeKey:n,onSelect:r,label:o="目录"}){const s=h.useRef(null),[l,a]=h.useState(null);h.useEffect(()=>{a(null)},[n]);const p=h.useMemo(()=>l||(n??Hr(t,n)),[l,n,t]);h.useEffect(()=>{const d=s.current;if(!d)return;const u=Array.from(d.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const x=u.find(m=>m.dataset.rdTocKey===p)??u.find(m=>m.dataset.rdTocKey===Hr(t,n))??u.find(m=>!m.disabled)??u[0];for(const m of u)m.tabIndex=m===x?0:-1}),h.useEffect(()=>{const d=s.current,u=d==null?void 0:d.closest(".bim-rd-toc");if(!d||!u||!n)return;const x=Array.from(d.querySelectorAll("[data-rd-toc-key]")).find(g=>g.dataset.rdTocKey===n);if(!x)return;const m=x.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(m<u.scrollTop+80||m>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,m-u.clientHeight/3))},[n]);const c=h.useCallback(d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const x=s.current;if(!x)return;const m=Array.from(x.querySelectorAll("[data-rd-toc-key]")).filter(y=>!y.disabled),g=m.indexOf(document.activeElement);let b=g;if(d.key==="ArrowDown"?b=Math.min(m.length-1,g+1):d.key==="ArrowUp"?b=Math.max(0,g-1):d.key==="Home"?b=0:d.key==="End"&&(b=m.length-1),b<0||b===g)return;d.preventDefault();const k=m[b];for(const y of m)y.tabIndex=-1;k.tabIndex=0,k.focus(),a(k.dataset.rdTocKey??null)},[]);return e.jsx("div",{ref:s,role:"navigation","aria-label":o,onKeyDown:c,children:e.jsx(Rs,{items:t,activeKey:n,onSelect:r,tabKey:p})})}function Md({page:t}){var n;return!((n=t.boxes)!=null&&n.length)||!t.width||!t.height||t.boxFormat&&t.boxFormat!=="bim-charbox-v0"?null:e.jsx("svg",{viewBox:`0 0 ${t.width} ${t.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:t.boxes.map((r,o)=>e.jsx("rect",{x:r.x,y:r.y,width:r.w,height:r.h,fill:"none",stroke:i("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},o))})}function pi({pages:t,loading:n,page:r,onPageChange:o,renderOverlay:s}){const[l,a]=h.useState(0),p=r??l,c=m=>{o?o(m):a(m)};if(h.useEffect(()=>{r===void 0&&a(0)},[t,r]),n)return e.jsx("div",{className:"bim-rd-img-box",children:e.jsx("div",{className:"bim-rd-img-empty",children:"加载书影…"})});if(!t||t.length===0)return e.jsx("div",{className:"bim-rd-img-box",children:e.jsxs("div",{className:"bim-rd-img-empty",children:[e.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),e.jsx("b",{children:"暂无书影"}),e.jsx("span",{children:"这一卷还没有配上影像;接入后在此与正文逐页对看"})]})});const d=Math.max(0,Math.min(t.length-1,p)),u=t[d],x=u.label??`${d+1}`;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bim-rd-img-box",children:e.jsxs("figure",{className:"bim-rd-img-fig",children:[e.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${x} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),e.jsx(Md,{page:u}),s==null?void 0:s(u,d)]})}),t.length>1&&e.jsxs("div",{className:"bim-rd-img-pager",children:[e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:d===0,onClick:()=>c(d-1),children:"‹"}),e.jsx("span",{"aria-live":"polite",children:u.label??`${d+1} / ${t.length}`}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:d===t.length-1,onClick:()=>c(d+1),children:"›"})]})]})}const Di={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal",workLinks:!0},at=[15,16,17,18,20,22,24],ui=18,As="bim-reader-prefs",Wd="bim-reading-mode";function Fd(){const t={...Di};try{const n=localStorage.getItem(As),r=n?JSON.parse(n):{};typeof r.fontSize=="number"&&at.includes(r.fontSize)&&(t.fontSize=r.fontSize),(r.readingMode??localStorage.getItem(Wd))==="paragraph"&&(t.readingMode="paragraph"),r.properNames===!0&&(t.properNames=!0),r.writingMode==="vertical"&&(t.writingMode="vertical"),r.workLinks===!1&&(t.workLinks=!1)}catch{}return t}function Od(t){try{localStorage.setItem(As,JSON.stringify(t))}catch{}}function un(t,n){const r=t??ui,o=at;let s=o.indexOf(r);return s<0&&(s=o.indexOf(ui)),o[Math.max(0,Math.min(o.length-1,s+n))]}function Bs(){const[t,n]=h.useState(Di);h.useEffect(()=>{n(Fd())},[]);const r=h.useCallback(o=>{n(s=>{const l={...s,...o};return Od(l),l})},[]);return[t,r]}function mi(t){if(t.optionLabel)return t.optionLabel;const n=t.label||t.key;return!t.sourceName||n.includes(t.sourceName)?n:`${n} · ${t.sourceName}`}function Ms(t,n){if(!(!t||t.length===0))return(n!=null?t.find(r=>r.key===n):void 0)??t.find(r=>r.primary)??t[0]}function Ws(t){const n=[],r=o=>{for(const s of o)s.children&&s.children.length>0?r(s.children):n.push(s)};return r(t),n}const Gr=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),Pd=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M15 5l-7 7 7 7"})}),Dd=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M9 5l7 7-7 7"})}),Ur=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),e.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function Vr(t,n){if(!n)return;const r=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(a=>a.tabIndex>=0);if(r.length===0)return;const o=r[0],s=r[r.length-1],l=document.activeElement;t.shiftKey&&(l===o||!n.contains(l))?(t.preventDefault(),s.focus()):!t.shiftKey&&(l===s||!n.contains(l))&&(t.preventDefault(),o.focus())}function Yr(t,n){const[r,o]=h.useState(n);return h.useEffect(()=>{var a;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(t);o(s.matches);const l=()=>o(s.matches);return(a=s.addEventListener)==null||a.call(s,"change",l),()=>{var p;return(p=s.removeEventListener)==null?void 0:p.call(s,"change",l)}},[t]),r}function Hd(){const t=h.useContext(Bt);if(!t)return null;const n=t.locale==="zh-Hant";return e.jsxs("button",{type:"button",className:"bim-rd-t",title:n?"切换为简体":"切換為繁體","aria-label":n?"切换为简体":"切換為繁體",onClick:()=>t.setLocale(n?"zh-Hans":"zh-Hant"),children:[e.jsx("span",{className:n?"bim-rd-on":"bim-rd-off",children:"繁"}),e.jsx("span",{className:"bim-rd-off",children:"|"}),e.jsx("span",{className:n?"bim-rd-off":"bim-rd-on",children:"简"})]})}function Gd(t,n){if(!t)return;let r;for(const o of Array.from(t.querySelectorAll('[id^="rd-e-"]')))if(o.getBoundingClientRect().top<=n+8)r=o.id;else break;return r}function Ud(t){var l;if(typeof window>"u"||!t)return;const n=(l=window.getSelection)==null?void 0:l.call(window);if(!n||n.isCollapsed||n.rangeCount===0)return;const r=t.querySelector(".bim-rd-col"),o=a=>{const p=(a==null?void 0:a.nodeType)===1?a:a==null?void 0:a.parentElement;return!!a&&!!(r!=null&&r.contains(a))&&!(p!=null&&p.closest(".bim-rd-src, .bim-rd-pager"))};if(!o(n.anchorNode)||!o(n.focusNode))return;const s=n.toString().replace(/\s+/g," ").trim();return s?s.slice(0,500):void 0}function Fs({title:t,subtitle:n,toc:r,activeKey:o,onSelect:s,tocHeader:l,tocCaption:a,images:p,imagesLoading:c,renderImageOverlay:d,imagePanel:u="auto",prefs:x,onPrefsChange:m,paragraphToggle:g,properNameToggle:b=!0,allowVertical:k,byline:y,current:j,workLinkToggle:f,rail:v,onReportError:$,revisedAt:w,backHref:_,backLabel:S="阅读",bottomBar:z=!0,pager:E=!0,pagerUnit:T="卷",versions:N,currentVersionKey:V,onVersionChange:W,versionSource:B=!0,keepChapterOnVersionChange:H=!1,children:te,className:se,style:J}){const D=h.useId().replace(/:/g,""),L=`bim-rd-toc-${D}`,le=`bim-rd-text-${D}`,A=h.useRef(null),ne=h.useRef(null),de=h.useRef(null),G=h.useRef(null),he=Yr(Ts,!0),ye=Yr(Is,!1),xe=z&&ye,[pe,$e]=h.useState(null),Fe=h.useRef(null),Ae=h.useRef(null),Me=(O,M)=>{Ae.current=M,$e(ue=>ue===O?null:O)},ve=h.useCallback(()=>{var O;$e(null),(O=Ae.current)==null||O.focus()},[]);h.useEffect(()=>{xe||$e(null)},[xe]),h.useEffect(()=>{var O,M;pe&&((M=(O=Fe.current)==null?void 0:O.querySelector("button:not([disabled])"))==null||M.focus())},[pe]);const[Be,P]=h.useState("auto"),ae=Be==="auto"?he:Be==="open",ie=!he,_e=!!p&&p.length>0,[ke,Y]=h.useState(u);h.useEffect(()=>{Y(u)},[u]);const I=ke==="auto"?_e||!!c:ke==="open",U=h.useCallback(O=>{var M;P("auto"),O&&((M=G.current)==null||M.focus())},[]),ge=()=>P(ae?"closed":"open");h.useEffect(()=>{if(!ie||Be!=="open")return;const O=de.current,M=O==null?void 0:O.querySelector('input, [data-rd-toc-key][tabindex="0"]');M==null||M.focus()},[ie,Be]);const we=h.useCallback(O=>{s(O),ie&&U(!1);const M=ne.current,ue=A.current;if(M&&ue&&typeof window<"u"){const Te=M.getBoundingClientRect().top-ue.getBoundingClientRect().bottom;Te<0&&window.scrollBy({top:Te})}},[s,ie,U]),R=h.useMemo(()=>Ws(r),[r]),[oe,K]=h.useState(null),X=Ms(N,V!==void 0?V:oe),je=(X==null?void 0:X.key)??null,Ie=h.useMemo(()=>R.map(O=>O.key).join(`
504
- `),[R]),Re=h.useRef(null),re=O=>{O!==je&&(H||(Re.current={key:O,sig:Ie,done:!1}),V===void 0&&K(O),W==null||W(O))};h.useEffect(()=>{const O=Re.current;if(!O||O.key!==je)return;const M=R.find(Te=>!Te.disabled);if(!M)return;const ue=Ie!==O.sig;!ue&&O.done||(ue?Re.current=null:O.done=!0,M.key!==o&&we(M.key))},[je,Ie,R,o,we]);const ze=R.find(O=>O.key===o),C=()=>{var O;$==null||$({chapterKey:o,chapterLabel:typeof(ze==null?void 0:ze.label)=="string"?ze.label:void 0,anchor:Gd(ne.current,((O=A.current)==null?void 0:O.getBoundingClientRect().bottom)??0),selectedText:Ud(ne.current)})},q=R.findIndex(O=>O.key===o),ee=q>0?R.slice(0,q).reverse().find(O=>!O.disabled):void 0,Z=q>=0?R.slice(q+1).find(O=>!O.disabled):void 0,me=x.fontSize??ui,Ce={...J,...x.fontSize?{"--bimrd-fs":`${x.fontSize}px`}:null};return e.jsxs("div",{className:["bim-rd",x.writingMode==="vertical"&&k?"bim-rd-vertical":"",se].filter(Boolean).join(" "),"data-toc":Be,"data-img":I?"open":"closed","data-bb":xe?"":void 0,style:Ce,children:[e.jsx("style",{children:Es}),e.jsx("a",{className:"bim-rd-skip",href:`#${le}`,onClick:O=>{var M,ue,Te;O.preventDefault(),(M=ne.current)==null||M.focus(),(Te=(ue=ne.current)==null?void 0:ue.scrollIntoView)==null||Te.call(ue,{block:"start"})},children:"跳到正文"}),e.jsxs("div",{className:"bim-rd-bar",ref:A,children:[_&&e.jsxs("a",{className:"bim-rd-back",href:_,"aria-label":`返回${S}首页`,children:[e.jsx("span",{"aria-hidden":"true",children:"‹"}),e.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:S})]}),(t||n||y||j)&&e.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[t&&e.jsx("b",{children:t}),y&&e.jsx("span",{className:"bim-rd-by",children:y}),j&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),e.jsx("span",{className:"bim-rd-cur",children:j})]}),n&&e.jsx("span",{children:n})]}),e.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":"阅读设置",children:[N&&N.length>1&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"bim-rd-ver",title:X?mi(X):void 0,children:[e.jsx("span",{className:"bim-rd-tlabel",children:"版本"}),e.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:"版本▾"}),e.jsx("select",{"aria-label":"版本",value:je??"",onChange:O=>re(O.target.value),children:N.map(O=>e.jsx("option",{value:O.key,children:mi(O)},O.key))})]}),e.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),E&&(ee||Z)&&e.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":`翻${T}`,children:[e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":`上一${T}`,title:ee?`上一${T}:${typeof ee.label=="string"?ee.label:""}`.replace(/:$/,""):`已是第一${T}`,disabled:!ee,onClick:()=>ee&&we(ee.key),children:e.jsx(Pd,{})}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":`下一${T}`,title:Z?`下一${T}:${typeof Z.label=="string"?Z.label:""}`.replace(/:$/,""):`已是最后一${T}`,disabled:!Z,onClick:()=>Z&&we(Z.key),children:e.jsx(Dd,{})})]}),E&&(ee||Z)&&e.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),e.jsxs("button",{ref:G,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":ae,"aria-controls":L,onClick:ge,children:[e.jsx(Gr,{}),e.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),e.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":I,onClick:()=>Y(I?"closed":"open"),children:[e.jsx(Ur,{}),"书影"]}),e.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),e.jsx(Hd,{}),e.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),e.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":"缩小字号",disabled:me<=at[0],onClick:()=>m({fontSize:un(x.fontSize,-1)}),children:"A−"}),e.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":"放大字号",disabled:me>=at[at.length-1],onClick:()=>m({fontSize:un(x.fontSize,1)}),children:"A+"}),(g||b||k)&&e.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),g&&e.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":x.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>m({readingMode:x.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),f&&e.jsxs("label",{className:"bim-rd-t bim-rd-chk",children:[e.jsx("input",{type:"checkbox",checked:x.workLinks,onChange:O=>m({workLinks:O.target.checked})}),e.jsx("span",{children:"标出作品链接"})]}),b&&e.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":x.properNames,title:"书名加波浪线",onClick:()=>m({properNames:!x.properNames}),children:"专名线"}),k&&e.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":x.writingMode==="vertical",onClick:()=>m({writingMode:x.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),e.jsxs("div",{className:"bim-rd-body",children:[e.jsxs("div",{className:"bim-rd-toc",id:L,ref:de,role:ie&&ae?"dialog":void 0,"aria-modal":ie&&ae?!0:void 0,"aria-label":ie&&ae?"目录":void 0,onKeyDown:O=>{if(!(!ie||!ae)){if(O.key==="Escape"){O.stopPropagation(),U(!0);return}O.key==="Tab"&&Vr(O,de.current)}},children:[e.jsxs("div",{className:"bim-rd-toc-top",children:[e.jsxs("div",{className:"bim-rd-toc-head",children:[e.jsx("span",{children:a??"目录"}),ie&&e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>U(!0),children:"✕"})]}),l]}),e.jsx(Ls,{items:r,activeKey:o,onSelect:we})]}),e.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>U(!0)}),e.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:I&&e.jsx(pi,{pages:p??null,loading:c,renderOverlay:d})}),e.jsxs("div",{className:"bim-rd-text",id:le,ref:ne,tabIndex:-1,"data-rail":v||$?"true":void 0,children:[e.jsxs("div",{className:"bim-rd-col",children:[te,B&&X&&(X.sourceName||X.license)&&e.jsxs("p",{className:"bim-rd-src","data-version":X.key,children:[X.sourceName&&e.jsxs(e.Fragment,{children:["出处"," ",X.sourceUrl?e.jsx("a",{className:"bim-rd-link",href:X.sourceUrl,target:"_blank",rel:"noreferrer",children:X.sourceName}):X.sourceName]}),X.sourceName&&X.license&&e.jsx("span",{className:"bim-rd-dot"}),X.license&&e.jsxs(e.Fragment,{children:["授权 ",X.license]})]}),w&&e.jsxs("p",{className:"bim-rd-src bim-rd-rev",children:["最近校订 ",w]}),$&&e.jsx("p",{className:"bim-rd-src bim-rd-report-foot",children:e.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:O=>O.preventDefault(),onClick:C,children:"报告错字"})}),E&&(ee||Z)&&e.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[ee?e.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>we(ee.key),children:[e.jsxs("span",{className:"bim-rd-pgcap",children:[e.jsx("span",{"aria-hidden":"true",children:"← "}),"上一",T]}),e.jsx("span",{className:"bim-rd-pglabel",children:ee.label})]}):e.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← 已是第一",T]}),Z?e.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>we(Z.key),children:[e.jsxs("span",{className:"bim-rd-pgcap",children:["下一",T,e.jsx("span",{"aria-hidden":"true",children:" →"})]}),e.jsx("span",{className:"bim-rd-pglabel",children:Z.label})]}):e.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:["已是最后一",T," →"]})]})]}),(v||$)&&e.jsxs("aside",{className:"bim-rd-rail","aria-label":"本卷",children:[v,$&&e.jsx("div",{className:"bim-rd-rail-acts",children:e.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:O=>O.preventDefault(),onClick:C,children:"报告错字"})})]})]})]}),xe&&e.jsxs("nav",{className:"bim-rd-bb","aria-label":"阅读工具",children:[e.jsxs("button",{type:"button","aria-expanded":ae,"aria-controls":L,onClick:()=>{$e(null),ge()},children:[e.jsx(Gr,{}),e.jsx("span",{children:"卷目"})]}),e.jsxs("button",{type:"button","aria-expanded":pe==="img","aria-haspopup":"dialog",onClick:O=>Me("img",O.currentTarget),children:[e.jsx(Ur,{}),e.jsx("span",{children:"书影"})]}),e.jsxs("button",{type:"button","aria-expanded":pe==="fs","aria-haspopup":"dialog",onClick:O=>Me("fs",O.currentTarget),children:[e.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"A"}),e.jsx("span",{children:"字号"})]}),$&&e.jsxs("button",{type:"button",onMouseDown:O=>O.preventDefault(),onClick:()=>{$e(null),C()},children:[e.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),e.jsx("span",{children:"报告错字"})]})]}),xe&&pe&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:ve}),e.jsxs("div",{className:"bim-rd-sheet",ref:Fe,role:"dialog","aria-modal":"true","aria-label":pe==="img"?"书影":"字号",onKeyDown:O=>{if(O.key==="Escape"){O.stopPropagation(),ve();return}O.key==="Tab"&&Vr(O,Fe.current)},children:[e.jsxs("div",{className:"bim-rd-sheet-head",children:[e.jsx("span",{children:pe==="img"?"书影":"字号"}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"关闭",onClick:ve,children:"✕"})]}),pe==="img"?e.jsx("div",{className:"bim-rd-sheet-img",children:e.jsx(pi,{pages:p??null,loading:c,renderOverlay:d})}):e.jsxs("div",{className:"bim-rd-sheet-fs",children:[e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"缩小字号",disabled:me<=at[0],onClick:()=>m({fontSize:un(x.fontSize,-1)}),children:"A−"}),e.jsxs("output",{"aria-live":"polite",children:[me,"px"]}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大字号",disabled:me>=at[at.length-1],onClick:()=>m({fontSize:un(x.fontSize,1)}),children:"A+"})]})]})]})]})}const Os=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Vd={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Ge(t){return Vd[t]??t}const Rt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],Lt={熹平:172,建安:196,黃初:220,正始:240,廣政:938,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,開成:836,會昌:841,咸通:860,建隆:960,太平興國:976,咸平:998,天禧:1017,慶曆:1041,皇祐:1049,嘉祐:1056,治平:1064,熙寧:1068,元豐:1078,元祐:1086,紹聖:1094,崇寧:1102,大觀:1107,政和:1111,宣和:1119,建炎:1127,紹興:1131,隆興:1163,乾道:1165,淳熙:1174,紹熙:1190,慶元:1195,嘉泰:1201,開禧:1205,嘉定:1208,寶慶:1225,紹定:1228,端平:1234,嘉熙:1237,淳祐:1241,寶祐:1253,開慶:1259,景定:1260,咸淳:1265,大定:1161,明昌:1190,至元:1264,大德:1297,皇慶:1312,延祐:1314,泰定:1324,天曆:1328,至順:1330,至正:1341,洪武:1368,永樂:1403,宣德:1426,正統:1436,景泰:1450,天順:1457,成化:1465,弘治:1488,正德:1506,嘉靖:1522,隆慶:1567,萬曆:1573,泰昌:1620,天啟:1621,崇禎:1628,弘光:1645,隆武:1645,紹武:1646,永曆:1647,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,正保:1644,慶安:1648,承應:1652,明曆:1655,萬治:1658,寬文:1661,延寶:1673,天和:1681,貞享:1684,元祿:1688,寶永:1704,享保:1716,元文:1736,寬保:1741,延享:1744,寬延:1748,寶曆:1751,明和:1764,安永:1772,天明:1781,寬政:1789,享和:1801,文化:1804,文政:1818,天保:1830,弘化:1844,嘉永:1848,安政:1854,萬延:1860,文久:1861,元治:1864,慶應:1865,明治:1868,大正:1912,昭和:1926,天正:1573,文祿:1592,永祿:1558,天文:1532},Ps={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function En(t){const n=t.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const r=parseInt(n[1],10);if(r<100||r>2100)return;const o=n[2]?parseInt(n[2],10):void 0;return{from:r,to:o!=null&&o>=r&&o<=2100?o:void 0}}function Yd(t){return t>=1950?"":t>=1912?"民國":t>=1645?"清":t>=1368?"明":t>=1279?"元":t>=960?"宋":t>=907?"五代":t>=618?"唐":t>=581?"隋":t>=420?"南北朝":t>=265?"晉":t>=220?"三國":t>=-202?"漢":""}const Kd=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Kr={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Hi(t){const n=t.trim().replace(/[代朝]$/,"");for(const s of Object.keys(Kr))if(n.startsWith(s))return Kr[s];const r=Ge(n);if(vt[r]!=null)return r;const o=dt(n);if(o&&n.length<=o.length+1)return Ge(o)}function jt(t,n){if(n){const r=Ps[`${n}|${t}`];if(r!=null)return r}return Lt[t]}const qd=1911;function Jd(t){const n=Lt[t];if(n==null)return;const r=st[t];let o;for(const[s,l]of Object.entries(Lt))st[s]===r&&l>n&&(o==null||l<o)&&(o=l);return o!=null?o-1:void 0}const Zd={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function jn(t){if(!t)return;if(/^\d+$/.test(t))return parseInt(t,10);let n=0,r=0,o=!1;for(const l of t){const a=Zd[l];if(a===void 0)return;o=!0,l==="十"?r=(r||1)*10:l==="廿"||l==="卅"?(n+=a,r=0):r>=10?(n+=r+a,r=0):r=r*10+a}const s=n+r;return o&&s>0?s:void 0}function dt(t){for(const n of Os)if(t.startsWith(n))return n}const st={};{const t=(n,r)=>{for(const o of r)st[o]=n};t("東漢",["熹平","建安"]),t("三國",["黃初","正始"]),t("五代",["廣政"]),t("西晉",["太康"]),t("東晉",["永和"]),t("隋",["開皇"]),t("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),t("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),t("金",["大定","明昌"]),t("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),t("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),t("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),t("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function kt(t,n){const r=n==="北宋"||n==="南宋"?"宋":n;for(const o of Object.keys(Lt))if(t.includes(o)&&!(r&&st[o]&&st[o]!==r&&Ps[`${r}|${o}`]==null))return o}function nn(t){var a,p,c;const n={era:"",reign:"",source:"none"},r=t.dating;if(r!=null&&r.era||r!=null&&r.reign)return{era:r.era??"",reign:r.reign??"",source:r.certainty==="attested"?"catalog":"edition"};const o=(a=t.lineage)==null?void 0:a.year_text;if(o){const d=dt(o)??"";return{era:Ge(d),reign:kt(o,d)??"",source:"lineage"}}const s=(p=t.publication_info)==null?void 0:p.year;if(s){const d=En(s);if(d)return{era:Yd(d.from),reign:"",source:"publication"};const u=dt(s)??Hi(s)??((c=Rt.find(g=>g.pattern.test(s)))==null?void 0:c.era)??"",x=kt(s,u)??"",m=u||(x?st[x]??"":"");if(m||x)return{era:Ge(m),reign:x,source:"publication"}}const l=t.edition||t.title||"";if(l){const d=dt(l);if(d)return{era:Ge(d),reign:kt(l,d)??"",source:"edition"};const u=Rt.find(x=>x.pattern.test(l));if(u)return{era:Ge(u.era),reign:kt(l,u.era)??u.reign??"",source:"edition"}}return n}function Rn(t){var o,s,l,a,p,c,d,u,x;if(((o=t.dating)==null?void 0:o.year)!=null)return t.dating.year;if(typeof((s=t.lineage)==null?void 0:s.year)=="number")return t.lineage.year;const n=(l=t.publication_info)==null?void 0:l.year;if(n){const m=En(n);if(m)return m.from}const r=[(a=t.lineage)==null?void 0:a.year_text,(p=t.publication_info)==null?void 0:p.year,t.edition,t.edition?void 0:t.title].filter(Boolean);for(const m of r){const g=((c=t.publication_info)==null?void 0:c.year)||((d=t.lineage)==null?void 0:d.year_text);if(g&&m!==g&&(dt(g)||Hi(g)))break;const b=m.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??m.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const v=parseInt(b[1],10);if(v>=100&&v<=2100)return v}const k=m.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(k){const v=dt(m);if(!v||Ge(v)==="民國"){const w=jn(k[1]);if(w!=null&&w>=1&&w<=120)return qd+w}}const y=dt(m)??((u=Rt.find(v=>v.pattern.test(m)))==null?void 0:u.era),j=y?Ge(y):void 0,f=kt(m,j)??(dt(m)||(x=Rt.find(v=>v.pattern.test(m)))==null?void 0:x.reign);if(f){const v=jt(f,j);if(v==null)continue;const $=m.indexOf(f),w=$>=0?m.slice($+f.length):"",_=w.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??w.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=_?jn(_[1]):void 0;return v+(S?S-1:0)}}}function Gi(t){var a,p,c,d,u,x;const n=(a=t.dating)==null?void 0:a.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const r=(p=t.lineage)==null?void 0:p.year_range;if(r&&r.length===2)return{from:r[0],to:r[1]};const o=(c=t.lineage)==null?void 0:c.year_text;if(o){const m=o.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(m){const g=xi[Ge(m[1])],b=vt[Ge(m[2])];if(g!=null&&b!=null)return{from:Math.min(g,b)-20,to:Math.max(g,b)+40}}}const s=(d=t.publication_info)==null?void 0:d.year;if(s){const m=En(s);if((m==null?void 0:m.to)!=null)return{from:m.from,to:m.to};const g=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const b=xi[Ge(g[1])],k=vt[Ge(g[2])];if(b!=null&&k!=null)return{from:Math.min(b,k)-20,to:Math.max(b,k)+40}}}const l=[(u=t.publication_info)==null?void 0:u.year,t.edition,t.title].filter(Boolean);for(const m of l){if(!/[間间]/.test(m))continue;const g=dt(m)??Hi(m)??((x=Rt.find(y=>y.pattern.test(m)))==null?void 0:x.era),b=g?Ge(g):void 0,k=[];for(const y of Object.keys(Lt))m.includes(y)&&(b&&st[y]&&st[y]!==b||jt(y,b)!=null&&k.push(y));if(k.length===0){const y=m.match(/([一-鿿])([一-鿿])[間间]/);if(y&&b){for(const j of[y[1],y[2]])for(const f of Object.keys(Lt))if(st[f]===b&&!(f[0]!==j&&f[f.length-1]!==j)&&jt(f,b)!=null){k.push(f);break}}}if(k.length>0){const y=k.map($=>jt($,b)).filter($=>$!=null),j=Math.min(...y),f=k.reduce(($,w)=>jt($,b)>=jt(w,b)?$:w),v=Jd(f)??Jn(b??"")??Math.max(...y);return{from:j,to:v>j?v:Jn(b??st[f]??"")??j}}if(b&&vt[b]!=null)return{from:vt[b],to:Jn(b)??vt[b]}}}const vt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Xd=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Qd=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,qr=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Jr(t,n){for(const r of Os){const o=t.indexOf(r);if(o<0)continue;if(r.length===1){const c=t[o+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!kt(t.slice(o),Ge(r)))continue}const s=Ge(r);if(s===n)continue;const l=t.slice(o),a=kt(l,s)??"";let p;if(a){const c=jt(a,s);if(c!=null){const u=l.slice(l.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),x=u?jn(u[1]):void 0;p=c+(x?x-1:0)}}return{era:s,reign:a,year:p}}for(const r of Rt)if(r.pattern.test(t))return{era:Ge(r.era),reign:r.reign??""}}function ep(t){var j,f,v,$,w;const n=nn(t),r=((j=t.publication_info)==null?void 0:j.year)??"",o=r?En(r):void 0;if(!n.era&&!n.reign&&!o)return;const s=t.edition||t.title||"",l=/[間间]/.test(s),a=((f=t.lineage)==null?void 0:f.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(a),c=n.source==="publication"&&Kd.test(r),d=n.source==="publication"&&/[間间]/.test(r),u=a.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let x;l||p||c||d?x=void 0:u?x=parseInt(u[2],10):x=Rn(t);const m=x==null?Gi(t):void 0;let g;n.source==="publication"&&(c||qr.test(r))?g="uncertain":n.source==="lineage"||n.source==="publication"?g="attested":qr.test(s)||!n.reign&&x==null?g="uncertain":g="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((v=t.lineage)==null?void 0:v.year_text)??(($=t.lineage)==null?void 0:$.year)??""}」`:`出版著錄「${((w=t.publication_info)==null?void 0:w.year)??""}」`,k={era:n.era,reign:n.reign,year:x,yearRange:m,certainty:g,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const _=a.match(/[、,,]\s*([宋元明清])/);_&&_[1]!==k.era&&(k.laterRepair={era:_[1]})}if(!k.laterRepair&&Qd.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(k.laterRepair={era:_[1]})}const y=Xd.find(_=>_.re.test(s));if(y){const _=s.search(y.re),S=s.slice(_),z=Jr(S,n.era)??Jr(s,n.era);z&&(k.basedOn={era:z.era,reign:z.reign,year:z.year,relation:y.relation})}return k}const xi={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Jn(t){return xi[t]}function vn(t){const n=Rn(t);if(n!=null)return n;const r=Gi(t);if(r)return r.from;const o=nn(t).era;return o?vt[o]:void 0}const Zr=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function hi(t){const n=Zr.indexOf(t);return n===-1?Zr.length:n}function tp(t){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of t){const l=s.relation;l==="part_of"?n.belongsTo.push(s):l==="collected_in"?n.collected.push(s):l==="has_part"||l==="contains_text_of"?n.contains.push(s):l==="text_carried_by"||l==="studied_by"||l==="derived_from"||l==="followed_by"||l==="has_adaptation"?n.derivative.push(s):l==="studies"||l==="preceded_by"?n.studies.push(s):n.related.push(s)}const r=[],o=(s,l)=>{n[s].length&&r.push({key:s,labelKey:l,items:n[s]})};return o("belongsTo","belongsToWork"),o("collected","collectedIn"),o("contains","containedWorks"),o("derivative","derivativeWorks"),o("studies","studies"),o("related","relatedWorks"),r}function Ui(t,n){const r=Ni(t||[]),o=new Map,s=[];for(const d of r)d.group?(o.has(d.group)||o.set(d.group,[]),o.get(d.group).push(d)):s.push(d);for(const d of o.values())d.sort((u,x)=>{const m=g=>g.group_role==="origin"?0:g.group_role==="mirror"?1:2;return m(u)-m(x)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=_t(d),x=u.includes("text"),m=u.includes("image");x&&m?l.textImage.push(d):x?l.text.push(d):m?l.image.push(d):l.physical.push(d)}const p=["text","image","textImage","physical"].filter(d=>l[d].length>0).map(d=>({key:d,items:l[d]})),c=[...o.entries()].map(([d,u])=>{var x,m;return{key:d,label:((x=n==null?void 0:n[d])==null?void 0:x.label)||d,description:(m=n==null?void 0:n[d])==null?void 0:m.description,items:u}});return{buckets:p,mirrors:c,total:r.length}}function Ln(t){const n=[],r=t.metadata||{};r.edition&&n.push(String(r.edition)),t.source_label&&n.push(t.source_label),t.details&&n.push(t.details);const o=_n(t);return o&&o.expected>0&&n.push(o.missing>0?`${o.found} / ${o.expected} 冊 缺 ${o.missing}`:`${o.found} / ${o.expected} 冊`),r.version&&n.push(String(r.version)),n.join(" · ")}function Ds(t,n){if(Ln(t)||n.filter(o=>o.name===t.name).length<2)return"";try{const o=new URL(t.url),s=o.searchParams.get("res")||o.searchParams.get("id");if(s)return s;const l=o.pathname.split("/").filter(Boolean).pop();if(l)return decodeURIComponent(l)}catch{}return""}function Hs(t,n){var l,a;const r=t.resources||[],o=[],s=[];for(const p of r){const c=_t(p);c.includes("image")&&o.push(p),c.includes("physical")&&s.push(p)}return{id:t.id,name:t.edition||t.title||t.id,era:nn(t),year:Rn(t),sortYear:vn(t),images:o,holders:s,locationName:(l=t.current_location)==null?void 0:l.name,important:np(t.id,n),group:(a=n==null?void 0:n.node_groups)==null?void 0:a[t.id],hasImage:o.length>0}}function np(t,n){var p,c;if(!n)return!1;const r=n.default_collection;if(!r)return!1;const o=(p=n.collections)==null?void 0:p[r];if(((o==null?void 0:o.book_ids)??(r==="core"?n.core_books??[]:[])).includes(t))return!0;const l=(o==null?void 0:o.groups)??[],a=(c=n.node_groups)==null?void 0:c[t];return!!a&&l.includes(a)}function Gs(t,n,r={}){const o=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(c=>!o.has(c.id)).map(c=>Hs(c,n));let l=s;r.era&&(l=l.filter(c=>c.era.era===r.era)),r.scanOnly&&(l=l.filter(c=>c.hasImage)),r.sort==="year"?l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=c.r.sortYear,x=d.r.sortYear;return u!=null&&x!=null?u-x||c.i-d.i:u!=null?-1:x!=null?1:c.i-d.i}).map(c=>c.r):l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=x=>(x.important?0:1)*2+(x.hasImage?0:1);return u(c.r)-u(d.r)||c.i-d.i}).map(c=>c.r);const p=[...new Set(s.map(c=>c.era.era).filter(Boolean))].sort((c,d)=>hi(c)-hi(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(c=>c.era.source==="edition")}}function ip(t,n){var y,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const r=(y=n.collections)==null?void 0:y[n.default_collection],o=(r==null?void 0:r.groups)??[],s=(r==null?void 0:r.book_ids)??[],l=o.length>0||s.length>0,a=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const p=new Set(o),c=new Set([...s,...a]),d=f=>{if(c.has(f))return!0;const v=n.node_groups[f];return v!=null&&p.has(v)},u=[],x=new Map,m=[];for(const f of t)if(!((j=n.excluded_books)!=null&&j.includes(f)))if(d(f))u.push(f);else{const v=n.node_groups[f];v?(x.has(v)||x.set(v,[]),x.get(v).push(f)):m.push(f)}if(m.length+[...x.values()].reduce((f,v)=>f+v.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(f=>[f.id,f])),k=[...x.entries()].map(([f,v])=>{const $=b.get(f);return{id:f,label:($==null?void 0:$.label)??f,description:$==null?void 0:$.description,ids:v}});return m.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:m}),{useGrouping:!0,coreIds:u,groupedIds:k}}const Us=["撰","編","注","校","譯","繪","其他"],rp=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function Vi(t){if(!t||!t.trim())return"撰";const n=t.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:r,re:o}of rp)if(o.test(n))return r;return"其他"}function Yi(t){if(!t)return"";const n=t.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Vs(t){const n=new Map;for(const o of t){const s=Vi(o);n.set(s,(n.get(s)??0)+1)}const r=[{cls:"全部",label:"全部",count:t.length}];for(const o of Us){const s=n.get(o);s&&r.push({cls:o,label:o,count:s})}return r.length>2?r:[]}function Ys(t,n,r){if(n&&n.books&&n.books.length>0){const s=n.books.map(a=>({id:a.work_id||a.book_id||void 0,title:a.title,section:a.section,volumes:a.volumes||[],subItems:a.sub_items,edition:a.edition,found:a.found_volumes,expected:a.expected_volumes})),l=[...new Set(s.map(a=>a.section).filter(Boolean))];return{rows:s,source:"catalog",sections:l,totalVolumes:n.total_volumes}}return t.contained_works&&t.contained_works.length>0?{rows:t.contained_works.map(l=>({id:l.id,title:l.title,volumes:Qt(l.volume_index)})),source:"works",sections:[]}:{rows:(t.books||[]).map(s=>{var l,a;return{id:s,title:((l=r==null?void 0:r.get(s))==null?void 0:l.title)||s,edition:(a=r==null?void 0:r.get(s))==null?void 0:a.edition,volumes:[]}}),source:"books",sections:[]}}function Qt(t){if(t==null)return[];if(typeof t=="number")return[t];if(Array.isArray(t))return t.filter(n=>typeof n=="number");if(typeof t=="string"){const n=t.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[r,o]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,o-r+1)},(s,l)=>r+l)}return t.split(/[,、]/).map(r=>parseInt(r.trim())).filter(r=>!isNaN(r))}return[]}function An(t,n="冊"){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const r=[...t].sort((l,a)=>l-a),o=r[0],s=r[r.length-1];return s-o+1===r.length?`${o}–${s}`:r.length<=3?r.join(", "):`${o}–${s} (${r.length}${n})`}const op=["〇","一","二","三","四","五","六","七","八","九"],Xr=["","十","百","千"];function Ks(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),r=n.length;let o="",s=!1;for(let l=0;l<r;l++){const a=parseInt(n[l]),p=r-1-l;a===0?s=!0:(s&&o&&(o+="〇"),s=!1,a===1&&p===1&&l===0?o+=Xr[p]:o+=op[a]+Xr[p])}return o}function sp(t){return t==null?"":typeof t=="string"?t:t.title??""}function ut(t,n="卷"){var o,s;const r=t;return r.measure_info?r.measure_info:(o=r.juan_count)!=null&&o.number?Ks(r.juan_count.number)+n:(s=r.juan_count)!=null&&s.description?r.juan_count.description:""}function qs(t){var o;if(t.edition_type)return t.edition_type;if((o=t.lineage)!=null&&o.category)return t.lineage.category;const n=t.edition||t.title||"",r=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,l]of r)if(s.test(n))return l;return""}const lp=216,Qr="clamp(280px, 23vw, 360px)",ap=1440,gi="(max-width: 719px)",cp=`${gi}, (pointer: coarse)`,dp=`
505
- .bim-d-main.bim-d-main-grid { max-width: ${ap}px; padding: 16px 32px 0; }
503
+ `;function Di(t,n){var r;return n?t.key===n?!0:!!((r=t.children)!=null&&r.some(o=>Di(o,n))):!1}const Od=()=>e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:e.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Fd({item:t,activeKey:n,onSelect:r,tabKey:o}){const s=Di(t,n),[l,a]=h.useState(s||!!t.defaultExpanded);return h.useEffect(()=>{s&&a(!0)},[s]),h.useEffect(()=>{t.defaultExpanded&&a(!0)},[t.defaultExpanded]),e.jsxs("li",{children:[e.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":t.key,tabIndex:o===t.key?0:-1,onClick:()=>a(p=>!p),children:[e.jsx(Od,{}),e.jsx("span",{children:t.label}),t.hint!=null&&e.jsx("span",{className:"bim-rd-hint",children:t.hint})]}),l&&e.jsx(Bs,{items:t.children,activeKey:n,onSelect:r,tabKey:o})]})}function Bs({items:t,activeKey:n,onSelect:r,tabKey:o}){return e.jsx("ul",{children:t.map(s=>s.children&&s.children.length>0?e.jsx(Fd,{item:s,activeKey:n,onSelect:r,tabKey:o},s.key):e.jsx("li",{children:e.jsxs("button",{type:"button",className:"bim-rd-ti","aria-current":s.key===n?"true":void 0,disabled:s.disabled,"data-rd-toc-key":s.key,tabIndex:o===s.key?0:-1,onClick:()=>r(s.key),children:[e.jsx("span",{children:s.label}),s.hint!=null&&e.jsx("span",{className:"bim-rd-hint",children:s.hint})]})},s.key))})}function Vr(t,n){var r;for(const o of t)if(o.key===n||Di(o,n))return o.key;return((r=t[0])==null?void 0:r.key)??null}function Ms({items:t,activeKey:n,onSelect:r,label:o="目录"}){const s=h.useRef(null),[l,a]=h.useState(null);h.useEffect(()=>{a(null)},[n]);const p=h.useMemo(()=>l||(n??Vr(t,n)),[l,n,t]);h.useEffect(()=>{const d=s.current;if(!d)return;const u=Array.from(d.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const x=u.find(m=>m.dataset.rdTocKey===p)??u.find(m=>m.dataset.rdTocKey===Vr(t,n))??u.find(m=>!m.disabled)??u[0];for(const m of u)m.tabIndex=m===x?0:-1}),h.useEffect(()=>{const d=s.current,u=d==null?void 0:d.closest(".bim-rd-toc");if(!d||!u||!n)return;const x=Array.from(d.querySelectorAll("[data-rd-toc-key]")).find(g=>g.dataset.rdTocKey===n);if(!x)return;const m=x.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(m<u.scrollTop+80||m>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,m-u.clientHeight/3))},[n]);const c=h.useCallback(d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const x=s.current;if(!x)return;const m=Array.from(x.querySelectorAll("[data-rd-toc-key]")).filter(y=>!y.disabled),g=m.indexOf(document.activeElement);let b=g;if(d.key==="ArrowDown"?b=Math.min(m.length-1,g+1):d.key==="ArrowUp"?b=Math.max(0,g-1):d.key==="Home"?b=0:d.key==="End"&&(b=m.length-1),b<0||b===g)return;d.preventDefault();const k=m[b];for(const y of m)y.tabIndex=-1;k.tabIndex=0,k.focus(),a(k.dataset.rdTocKey??null)},[]);return e.jsx("div",{ref:s,role:"navigation","aria-label":o,onKeyDown:c,children:e.jsx(Bs,{items:t,activeKey:n,onSelect:r,tabKey:p})})}function Pd({page:t}){var n;return!((n=t.boxes)!=null&&n.length)||!t.width||!t.height||t.boxFormat&&t.boxFormat!=="bim-charbox-v0"?null:e.jsx("svg",{viewBox:`0 0 ${t.width} ${t.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:t.boxes.map((r,o)=>e.jsx("rect",{x:r.x,y:r.y,width:r.w,height:r.h,fill:"none",stroke:i("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},o))})}function ui({pages:t,loading:n,page:r,onPageChange:o,renderOverlay:s}){const[l,a]=h.useState(0),p=r??l,c=m=>{o?o(m):a(m)};if(h.useEffect(()=>{r===void 0&&a(0)},[t,r]),n)return e.jsx("div",{className:"bim-rd-img-box",children:e.jsx("div",{className:"bim-rd-img-empty",children:"加载书影…"})});if(!t||t.length===0)return e.jsx("div",{className:"bim-rd-img-box",children:e.jsxs("div",{className:"bim-rd-img-empty",children:[e.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),e.jsx("b",{children:"暂无书影"}),e.jsx("span",{children:"这一卷还没有配上影像;接入后在此与正文逐页对看"})]})});const d=Math.max(0,Math.min(t.length-1,p)),u=t[d],x=u.label??`${d+1}`;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bim-rd-img-box",children:e.jsxs("figure",{className:"bim-rd-img-fig",children:[e.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${x} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),e.jsx(Pd,{page:u}),s==null?void 0:s(u,d)]})}),t.length>1&&e.jsxs("div",{className:"bim-rd-img-pager",children:[e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:d===0,onClick:()=>c(d-1),children:"‹"}),e.jsx("span",{"aria-live":"polite",children:u.label??`${d+1} / ${t.length}`}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:d===t.length-1,onClick:()=>c(d+1),children:"›"})]})]})}const Hi={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal",workLinks:!0},at=[15,16,17,18,20,22,24],mi=18,Ws="bim-reader-prefs",Dd="bim-reading-mode";function Hd(){const t={...Hi};try{const n=localStorage.getItem(Ws),r=n?JSON.parse(n):{};typeof r.fontSize=="number"&&at.includes(r.fontSize)&&(t.fontSize=r.fontSize),(r.readingMode??localStorage.getItem(Dd))==="paragraph"&&(t.readingMode="paragraph"),r.properNames===!0&&(t.properNames=!0),r.writingMode==="vertical"&&(t.writingMode="vertical"),r.workLinks===!1&&(t.workLinks=!1)}catch{}return t}function Gd(t){try{localStorage.setItem(Ws,JSON.stringify(t))}catch{}}function un(t,n){const r=t??mi,o=at;let s=o.indexOf(r);return s<0&&(s=o.indexOf(mi)),o[Math.max(0,Math.min(o.length-1,s+n))]}function Os(){const[t,n]=h.useState(Hi);h.useEffect(()=>{n(Hd())},[]);const r=h.useCallback(o=>{n(s=>{const l={...s,...o};return Gd(l),l})},[]);return[t,r]}function xi(t){if(t.optionLabel)return t.optionLabel;const n=t.label||t.key;return!t.sourceName||n.includes(t.sourceName)?n:`${n} · ${t.sourceName}`}function Fs(t,n){if(!(!t||t.length===0))return(n!=null?t.find(r=>r.key===n):void 0)??t.find(r=>r.primary)??t[0]}function Ps(t){const n=[],r=o=>{for(const s of o)s.children&&s.children.length>0?r(s.children):n.push(s)};return r(t),n}const Yr=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),Ud=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M15 5l-7 7 7 7"})}),Vd=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M9 5l7 7-7 7"})}),Kr=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),e.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function qr(t,n){if(!n)return;const r=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(a=>a.tabIndex>=0);if(r.length===0)return;const o=r[0],s=r[r.length-1],l=document.activeElement;t.shiftKey&&(l===o||!n.contains(l))?(t.preventDefault(),s.focus()):!t.shiftKey&&(l===s||!n.contains(l))&&(t.preventDefault(),o.focus())}function Jr(t,n){const[r,o]=h.useState(n);return h.useEffect(()=>{var a;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(t);o(s.matches);const l=()=>o(s.matches);return(a=s.addEventListener)==null||a.call(s,"change",l),()=>{var p;return(p=s.removeEventListener)==null?void 0:p.call(s,"change",l)}},[t]),r}function Yd(){const t=h.useContext(Bt);if(!t)return null;const n=t.locale==="zh-Hant";return e.jsxs("button",{type:"button",className:"bim-rd-t",title:n?"切换为简体":"切換為繁體","aria-label":n?"切换为简体":"切換為繁體",onClick:()=>t.setLocale(n?"zh-Hans":"zh-Hant"),children:[e.jsx("span",{className:n?"bim-rd-on":"bim-rd-off",children:"繁"}),e.jsx("span",{className:"bim-rd-off",children:"|"}),e.jsx("span",{className:n?"bim-rd-off":"bim-rd-on",children:"简"})]})}function Kd(t,n){if(!t)return;let r;for(const o of Array.from(t.querySelectorAll('[id^="rd-e-"]')))if(o.getBoundingClientRect().top<=n+8)r=o.id;else break;return r}function qd(t){var l;if(typeof window>"u"||!t)return;const n=(l=window.getSelection)==null?void 0:l.call(window);if(!n||n.isCollapsed||n.rangeCount===0)return;const r=t.querySelector(".bim-rd-col"),o=a=>{const p=(a==null?void 0:a.nodeType)===1?a:a==null?void 0:a.parentElement;return!!a&&!!(r!=null&&r.contains(a))&&!(p!=null&&p.closest(".bim-rd-src, .bim-rd-pager"))};if(!o(n.anchorNode)||!o(n.focusNode))return;const s=n.toString().replace(/\s+/g," ").trim();return s?s.slice(0,500):void 0}function Ds({title:t,subtitle:n,toc:r,activeKey:o,onSelect:s,tocHeader:l,tocCaption:a,images:p,imagesLoading:c,renderImageOverlay:d,imagePanel:u="auto",prefs:x,onPrefsChange:m,paragraphToggle:g,properNameToggle:b=!0,allowVertical:k,byline:y,current:j,workLinkToggle:f,rail:v,onReportError:$,revisedAt:w,backHref:_,backLabel:S="阅读",bottomBar:z=!0,pager:E=!0,pagerUnit:T="卷",versions:N,currentVersionKey:V,onVersionChange:W,versionSource:B=!0,keepChapterOnVersionChange:H=!1,children:te,className:se,style:J}){const D=h.useId().replace(/:/g,""),L=`bim-rd-toc-${D}`,le=`bim-rd-text-${D}`,A=h.useRef(null),ne=h.useRef(null),de=h.useRef(null),G=h.useRef(null),he=Jr(Es,!0),ye=Jr(Ls,!1),xe=z&&ye,[pe,$e]=h.useState(null),Oe=h.useRef(null),Ae=h.useRef(null),Me=(F,M)=>{Ae.current=M,$e(ue=>ue===F?null:F)},ve=h.useCallback(()=>{var F;$e(null),(F=Ae.current)==null||F.focus()},[]);h.useEffect(()=>{xe||$e(null)},[xe]),h.useEffect(()=>{var F,M;pe&&((M=(F=Oe.current)==null?void 0:F.querySelector("button:not([disabled])"))==null||M.focus())},[pe]);const[Be,P]=h.useState("auto"),ae=Be==="auto"?he:Be==="open",ie=!he,_e=!!p&&p.length>0,[ke,Y]=h.useState(u);h.useEffect(()=>{Y(u)},[u]);const I=ke==="auto"?_e||!!c:ke==="open",U=h.useCallback(F=>{var M;P("auto"),F&&((M=G.current)==null||M.focus())},[]),ge=()=>P(ae?"closed":"open");h.useEffect(()=>{if(!ie||Be!=="open")return;const F=de.current,M=F==null?void 0:F.querySelector('input, [data-rd-toc-key][tabindex="0"]');M==null||M.focus()},[ie,Be]);const we=h.useCallback(F=>{s(F),ie&&U(!1);const M=ne.current,ue=A.current;if(M&&ue&&typeof window<"u"){const Te=M.getBoundingClientRect().top-ue.getBoundingClientRect().bottom;Te<0&&window.scrollBy({top:Te})}},[s,ie,U]),R=h.useMemo(()=>Ps(r),[r]),[oe,K]=h.useState(null),X=Fs(N,V!==void 0?V:oe),je=(X==null?void 0:X.key)??null,Ie=h.useMemo(()=>R.map(F=>F.key).join(`
504
+ `),[R]),Re=h.useRef(null),re=F=>{F!==je&&(H||(Re.current={key:F,sig:Ie,done:!1}),V===void 0&&K(F),W==null||W(F))};h.useEffect(()=>{const F=Re.current;if(!F||F.key!==je)return;const M=R.find(Te=>!Te.disabled);if(!M)return;const ue=Ie!==F.sig;!ue&&F.done||(ue?Re.current=null:F.done=!0,M.key!==o&&we(M.key))},[je,Ie,R,o,we]);const ze=R.find(F=>F.key===o),C=()=>{var F;$==null||$({chapterKey:o,chapterLabel:typeof(ze==null?void 0:ze.label)=="string"?ze.label:void 0,anchor:Kd(ne.current,((F=A.current)==null?void 0:F.getBoundingClientRect().bottom)??0),selectedText:qd(ne.current)})},q=R.findIndex(F=>F.key===o),ee=q>0?R.slice(0,q).reverse().find(F=>!F.disabled):void 0,Z=q>=0?R.slice(q+1).find(F=>!F.disabled):void 0,me=x.fontSize??mi,Ce={...J,...x.fontSize?{"--bimrd-fs":`${x.fontSize}px`}:null};return e.jsxs("div",{className:["bim-rd",x.writingMode==="vertical"&&k?"bim-rd-vertical":"",se].filter(Boolean).join(" "),"data-toc":Be,"data-img":I?"open":"closed","data-bb":xe?"":void 0,style:Ce,children:[e.jsx("style",{children:As}),e.jsx("a",{className:"bim-rd-skip",href:`#${le}`,onClick:F=>{var M,ue,Te;F.preventDefault(),(M=ne.current)==null||M.focus(),(Te=(ue=ne.current)==null?void 0:ue.scrollIntoView)==null||Te.call(ue,{block:"start"})},children:"跳到正文"}),e.jsxs("div",{className:"bim-rd-bar",ref:A,children:[_&&e.jsxs("a",{className:"bim-rd-back",href:_,"aria-label":`返回${S}首页`,children:[e.jsx("span",{"aria-hidden":"true",children:"‹"}),e.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:S})]}),(t||n||y||j)&&e.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[t&&e.jsx("b",{children:t}),y&&e.jsx("span",{className:"bim-rd-by",children:y}),j&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),e.jsx("span",{className:"bim-rd-cur",children:j})]}),n&&e.jsx("span",{children:n})]}),e.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":"阅读设置",children:[N&&N.length>1&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"bim-rd-ver",title:X?xi(X):void 0,children:[e.jsx("span",{className:"bim-rd-tlabel",children:"版本"}),e.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:"版本▾"}),e.jsx("select",{"aria-label":"版本",value:je??"",onChange:F=>re(F.target.value),children:N.map(F=>e.jsx("option",{value:F.key,children:xi(F)},F.key))})]}),e.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),E&&(ee||Z)&&e.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":`翻${T}`,children:[e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":`上一${T}`,title:ee?`上一${T}:${typeof ee.label=="string"?ee.label:""}`.replace(/:$/,""):`已是第一${T}`,disabled:!ee,onClick:()=>ee&&we(ee.key),children:e.jsx(Ud,{})}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":`下一${T}`,title:Z?`下一${T}:${typeof Z.label=="string"?Z.label:""}`.replace(/:$/,""):`已是最后一${T}`,disabled:!Z,onClick:()=>Z&&we(Z.key),children:e.jsx(Vd,{})})]}),E&&(ee||Z)&&e.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),e.jsxs("button",{ref:G,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":ae,"aria-controls":L,onClick:ge,children:[e.jsx(Yr,{}),e.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),e.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":I,onClick:()=>Y(I?"closed":"open"),children:[e.jsx(Kr,{}),"书影"]}),e.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),e.jsx(Yd,{}),e.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),e.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":"缩小字号",disabled:me<=at[0],onClick:()=>m({fontSize:un(x.fontSize,-1)}),children:"A−"}),e.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":"放大字号",disabled:me>=at[at.length-1],onClick:()=>m({fontSize:un(x.fontSize,1)}),children:"A+"}),(g||b||k)&&e.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),g&&e.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":x.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>m({readingMode:x.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),f&&e.jsxs("label",{className:"bim-rd-t bim-rd-chk",children:[e.jsx("input",{type:"checkbox",checked:x.workLinks,onChange:F=>m({workLinks:F.target.checked})}),e.jsx("span",{children:"标出作品链接"})]}),b&&e.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":x.properNames,title:"书名加波浪线",onClick:()=>m({properNames:!x.properNames}),children:"专名线"}),k&&e.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":x.writingMode==="vertical",onClick:()=>m({writingMode:x.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),e.jsxs("div",{className:"bim-rd-body",children:[e.jsxs("div",{className:"bim-rd-toc",id:L,ref:de,role:ie&&ae?"dialog":void 0,"aria-modal":ie&&ae?!0:void 0,"aria-label":ie&&ae?"目录":void 0,onKeyDown:F=>{if(!(!ie||!ae)){if(F.key==="Escape"){F.stopPropagation(),U(!0);return}F.key==="Tab"&&qr(F,de.current)}},children:[e.jsxs("div",{className:"bim-rd-toc-top",children:[e.jsxs("div",{className:"bim-rd-toc-head",children:[e.jsx("span",{children:a??"目录"}),ie&&e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>U(!0),children:"✕"})]}),l]}),e.jsx(Ms,{items:r,activeKey:o,onSelect:we})]}),e.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>U(!0)}),e.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:I&&e.jsx(ui,{pages:p??null,loading:c,renderOverlay:d})}),e.jsxs("div",{className:"bim-rd-text",id:le,ref:ne,tabIndex:-1,"data-rail":v||$?"true":void 0,children:[e.jsxs("div",{className:"bim-rd-col",children:[te,B&&X&&(X.sourceName||X.license)&&e.jsxs("p",{className:"bim-rd-src","data-version":X.key,children:[X.sourceName&&e.jsxs(e.Fragment,{children:["出处"," ",X.sourceUrl?e.jsx("a",{className:"bim-rd-link",href:X.sourceUrl,target:"_blank",rel:"noreferrer",children:X.sourceName}):X.sourceName]}),X.sourceName&&X.license&&e.jsx("span",{className:"bim-rd-dot"}),X.license&&e.jsxs(e.Fragment,{children:["授权 ",X.license]})]}),w&&e.jsxs("p",{className:"bim-rd-src bim-rd-rev",children:["最近校订 ",w]}),$&&e.jsx("p",{className:"bim-rd-src bim-rd-report-foot",children:e.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:F=>F.preventDefault(),onClick:C,children:"报告错字"})}),E&&(ee||Z)&&e.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[ee?e.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>we(ee.key),children:[e.jsxs("span",{className:"bim-rd-pgcap",children:[e.jsx("span",{"aria-hidden":"true",children:"← "}),"上一",T]}),e.jsx("span",{className:"bim-rd-pglabel",children:ee.label})]}):e.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← 已是第一",T]}),Z?e.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>we(Z.key),children:[e.jsxs("span",{className:"bim-rd-pgcap",children:["下一",T,e.jsx("span",{"aria-hidden":"true",children:" →"})]}),e.jsx("span",{className:"bim-rd-pglabel",children:Z.label})]}):e.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:["已是最后一",T," →"]})]})]}),(v||$)&&e.jsxs("aside",{className:"bim-rd-rail","aria-label":"本卷",children:[v,$&&e.jsx("div",{className:"bim-rd-rail-acts",children:e.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:F=>F.preventDefault(),onClick:C,children:"报告错字"})})]})]})]}),xe&&e.jsxs("nav",{className:"bim-rd-bb","aria-label":"阅读工具",children:[e.jsxs("button",{type:"button","aria-expanded":ae,"aria-controls":L,onClick:()=>{$e(null),ge()},children:[e.jsx(Yr,{}),e.jsx("span",{children:"卷目"})]}),e.jsxs("button",{type:"button","aria-expanded":pe==="img","aria-haspopup":"dialog",onClick:F=>Me("img",F.currentTarget),children:[e.jsx(Kr,{}),e.jsx("span",{children:"书影"})]}),e.jsxs("button",{type:"button","aria-expanded":pe==="fs","aria-haspopup":"dialog",onClick:F=>Me("fs",F.currentTarget),children:[e.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"A"}),e.jsx("span",{children:"字号"})]}),$&&e.jsxs("button",{type:"button",onMouseDown:F=>F.preventDefault(),onClick:()=>{$e(null),C()},children:[e.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),e.jsx("span",{children:"报告错字"})]})]}),xe&&pe&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:ve}),e.jsxs("div",{className:"bim-rd-sheet",ref:Oe,role:"dialog","aria-modal":"true","aria-label":pe==="img"?"书影":"字号",onKeyDown:F=>{if(F.key==="Escape"){F.stopPropagation(),ve();return}F.key==="Tab"&&qr(F,Oe.current)},children:[e.jsxs("div",{className:"bim-rd-sheet-head",children:[e.jsx("span",{children:pe==="img"?"书影":"字号"}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"关闭",onClick:ve,children:"✕"})]}),pe==="img"?e.jsx("div",{className:"bim-rd-sheet-img",children:e.jsx(ui,{pages:p??null,loading:c,renderOverlay:d})}):e.jsxs("div",{className:"bim-rd-sheet-fs",children:[e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"缩小字号",disabled:me<=at[0],onClick:()=>m({fontSize:un(x.fontSize,-1)}),children:"A−"}),e.jsxs("output",{"aria-live":"polite",children:[me,"px"]}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大字号",disabled:me>=at[at.length-1],onClick:()=>m({fontSize:un(x.fontSize,1)}),children:"A+"})]})]})]})]})}const Hs=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Jd={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Ge(t){return Jd[t]??t}const Rt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],Lt={熹平:172,建安:196,黃初:220,正始:240,廣政:938,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,開成:836,會昌:841,咸通:860,建隆:960,太平興國:976,咸平:998,天禧:1017,慶曆:1041,皇祐:1049,嘉祐:1056,治平:1064,熙寧:1068,元豐:1078,元祐:1086,紹聖:1094,崇寧:1102,大觀:1107,政和:1111,宣和:1119,建炎:1127,紹興:1131,隆興:1163,乾道:1165,淳熙:1174,紹熙:1190,慶元:1195,嘉泰:1201,開禧:1205,嘉定:1208,寶慶:1225,紹定:1228,端平:1234,嘉熙:1237,淳祐:1241,寶祐:1253,開慶:1259,景定:1260,咸淳:1265,大定:1161,明昌:1190,至元:1264,大德:1297,皇慶:1312,延祐:1314,泰定:1324,天曆:1328,至順:1330,至正:1341,洪武:1368,永樂:1403,宣德:1426,正統:1436,景泰:1450,天順:1457,成化:1465,弘治:1488,正德:1506,嘉靖:1522,隆慶:1567,萬曆:1573,泰昌:1620,天啟:1621,崇禎:1628,弘光:1645,隆武:1645,紹武:1646,永曆:1647,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,正保:1644,慶安:1648,承應:1652,明曆:1655,萬治:1658,寬文:1661,延寶:1673,天和:1681,貞享:1684,元祿:1688,寶永:1704,享保:1716,元文:1736,寬保:1741,延享:1744,寬延:1748,寶曆:1751,明和:1764,安永:1772,天明:1781,寬政:1789,享和:1801,文化:1804,文政:1818,天保:1830,弘化:1844,嘉永:1848,安政:1854,萬延:1860,文久:1861,元治:1864,慶應:1865,明治:1868,大正:1912,昭和:1926,天正:1573,文祿:1592,永祿:1558,天文:1532},Gs={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function En(t){const n=t.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const r=parseInt(n[1],10);if(r<100||r>2100)return;const o=n[2]?parseInt(n[2],10):void 0;return{from:r,to:o!=null&&o>=r&&o<=2100?o:void 0}}function Zd(t){return t>=1950?"":t>=1912?"民國":t>=1645?"清":t>=1368?"明":t>=1279?"元":t>=960?"宋":t>=907?"五代":t>=618?"唐":t>=581?"隋":t>=420?"南北朝":t>=265?"晉":t>=220?"三國":t>=-202?"漢":""}const Xd=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Zr={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Gi(t){const n=t.trim().replace(/[代朝]$/,"");for(const s of Object.keys(Zr))if(n.startsWith(s))return Zr[s];const r=Ge(n);if(vt[r]!=null)return r;const o=dt(n);if(o&&n.length<=o.length+1)return Ge(o)}function jt(t,n){if(n){const r=Gs[`${n}|${t}`];if(r!=null)return r}return Lt[t]}const Qd=1911;function ep(t){const n=Lt[t];if(n==null)return;const r=st[t];let o;for(const[s,l]of Object.entries(Lt))st[s]===r&&l>n&&(o==null||l<o)&&(o=l);return o!=null?o-1:void 0}const tp={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function jn(t){if(!t)return;if(/^\d+$/.test(t))return parseInt(t,10);let n=0,r=0,o=!1;for(const l of t){const a=tp[l];if(a===void 0)return;o=!0,l==="十"?r=(r||1)*10:l==="廿"||l==="卅"?(n+=a,r=0):r>=10?(n+=r+a,r=0):r=r*10+a}const s=n+r;return o&&s>0?s:void 0}function dt(t){for(const n of Hs)if(t.startsWith(n))return n}const st={};{const t=(n,r)=>{for(const o of r)st[o]=n};t("東漢",["熹平","建安"]),t("三國",["黃初","正始"]),t("五代",["廣政"]),t("西晉",["太康"]),t("東晉",["永和"]),t("隋",["開皇"]),t("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),t("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),t("金",["大定","明昌"]),t("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),t("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),t("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),t("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function kt(t,n){const r=n==="北宋"||n==="南宋"?"宋":n;for(const o of Object.keys(Lt))if(t.includes(o)&&!(r&&st[o]&&st[o]!==r&&Gs[`${r}|${o}`]==null))return o}function nn(t){var a,p,c;const n={era:"",reign:"",source:"none"},r=t.dating;if(r!=null&&r.era||r!=null&&r.reign)return{era:r.era??"",reign:r.reign??"",source:r.certainty==="attested"?"catalog":"edition"};const o=(a=t.lineage)==null?void 0:a.year_text;if(o){const d=dt(o)??"";return{era:Ge(d),reign:kt(o,d)??"",source:"lineage"}}const s=(p=t.publication_info)==null?void 0:p.year;if(s){const d=En(s);if(d)return{era:Zd(d.from),reign:"",source:"publication"};const u=dt(s)??Gi(s)??((c=Rt.find(g=>g.pattern.test(s)))==null?void 0:c.era)??"",x=kt(s,u)??"",m=u||(x?st[x]??"":"");if(m||x)return{era:Ge(m),reign:x,source:"publication"}}const l=t.edition||t.title||"";if(l){const d=dt(l);if(d)return{era:Ge(d),reign:kt(l,d)??"",source:"edition"};const u=Rt.find(x=>x.pattern.test(l));if(u)return{era:Ge(u.era),reign:kt(l,u.era)??u.reign??"",source:"edition"}}return n}function Rn(t){var o,s,l,a,p,c,d,u,x;if(((o=t.dating)==null?void 0:o.year)!=null)return t.dating.year;if(typeof((s=t.lineage)==null?void 0:s.year)=="number")return t.lineage.year;const n=(l=t.publication_info)==null?void 0:l.year;if(n){const m=En(n);if(m)return m.from}const r=[(a=t.lineage)==null?void 0:a.year_text,(p=t.publication_info)==null?void 0:p.year,t.edition,t.edition?void 0:t.title].filter(Boolean);for(const m of r){const g=((c=t.publication_info)==null?void 0:c.year)||((d=t.lineage)==null?void 0:d.year_text);if(g&&m!==g&&(dt(g)||Gi(g)))break;const b=m.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??m.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const v=parseInt(b[1],10);if(v>=100&&v<=2100)return v}const k=m.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(k){const v=dt(m);if(!v||Ge(v)==="民國"){const w=jn(k[1]);if(w!=null&&w>=1&&w<=120)return Qd+w}}const y=dt(m)??((u=Rt.find(v=>v.pattern.test(m)))==null?void 0:u.era),j=y?Ge(y):void 0,f=kt(m,j)??(dt(m)||(x=Rt.find(v=>v.pattern.test(m)))==null?void 0:x.reign);if(f){const v=jt(f,j);if(v==null)continue;const $=m.indexOf(f),w=$>=0?m.slice($+f.length):"",_=w.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??w.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=_?jn(_[1]):void 0;return v+(S?S-1:0)}}}function Ui(t){var a,p,c,d,u,x;const n=(a=t.dating)==null?void 0:a.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const r=(p=t.lineage)==null?void 0:p.year_range;if(r&&r.length===2)return{from:r[0],to:r[1]};const o=(c=t.lineage)==null?void 0:c.year_text;if(o){const m=o.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(m){const g=hi[Ge(m[1])],b=vt[Ge(m[2])];if(g!=null&&b!=null)return{from:Math.min(g,b)-20,to:Math.max(g,b)+40}}}const s=(d=t.publication_info)==null?void 0:d.year;if(s){const m=En(s);if((m==null?void 0:m.to)!=null)return{from:m.from,to:m.to};const g=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const b=hi[Ge(g[1])],k=vt[Ge(g[2])];if(b!=null&&k!=null)return{from:Math.min(b,k)-20,to:Math.max(b,k)+40}}}const l=[(u=t.publication_info)==null?void 0:u.year,t.edition,t.title].filter(Boolean);for(const m of l){if(!/[間间]/.test(m))continue;const g=dt(m)??Gi(m)??((x=Rt.find(y=>y.pattern.test(m)))==null?void 0:x.era),b=g?Ge(g):void 0,k=[];for(const y of Object.keys(Lt))m.includes(y)&&(b&&st[y]&&st[y]!==b||jt(y,b)!=null&&k.push(y));if(k.length===0){const y=m.match(/([一-鿿])([一-鿿])[間间]/);if(y&&b){for(const j of[y[1],y[2]])for(const f of Object.keys(Lt))if(st[f]===b&&!(f[0]!==j&&f[f.length-1]!==j)&&jt(f,b)!=null){k.push(f);break}}}if(k.length>0){const y=k.map($=>jt($,b)).filter($=>$!=null),j=Math.min(...y),f=k.reduce(($,w)=>jt($,b)>=jt(w,b)?$:w),v=ep(f)??Zn(b??"")??Math.max(...y);return{from:j,to:v>j?v:Zn(b??st[f]??"")??j}}if(b&&vt[b]!=null)return{from:vt[b],to:Zn(b)??vt[b]}}}const vt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},np=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],ip=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,Xr=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Qr(t,n){for(const r of Hs){const o=t.indexOf(r);if(o<0)continue;if(r.length===1){const c=t[o+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!kt(t.slice(o),Ge(r)))continue}const s=Ge(r);if(s===n)continue;const l=t.slice(o),a=kt(l,s)??"";let p;if(a){const c=jt(a,s);if(c!=null){const u=l.slice(l.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),x=u?jn(u[1]):void 0;p=c+(x?x-1:0)}}return{era:s,reign:a,year:p}}for(const r of Rt)if(r.pattern.test(t))return{era:Ge(r.era),reign:r.reign??""}}function rp(t){var j,f,v,$,w;const n=nn(t),r=((j=t.publication_info)==null?void 0:j.year)??"",o=r?En(r):void 0;if(!n.era&&!n.reign&&!o)return;const s=t.edition||t.title||"",l=/[間间]/.test(s),a=((f=t.lineage)==null?void 0:f.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(a),c=n.source==="publication"&&Xd.test(r),d=n.source==="publication"&&/[間间]/.test(r),u=a.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let x;l||p||c||d?x=void 0:u?x=parseInt(u[2],10):x=Rn(t);const m=x==null?Ui(t):void 0;let g;n.source==="publication"&&(c||Xr.test(r))?g="uncertain":n.source==="lineage"||n.source==="publication"?g="attested":Xr.test(s)||!n.reign&&x==null?g="uncertain":g="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((v=t.lineage)==null?void 0:v.year_text)??(($=t.lineage)==null?void 0:$.year)??""}」`:`出版著錄「${((w=t.publication_info)==null?void 0:w.year)??""}」`,k={era:n.era,reign:n.reign,year:x,yearRange:m,certainty:g,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const _=a.match(/[、,,]\s*([宋元明清])/);_&&_[1]!==k.era&&(k.laterRepair={era:_[1]})}if(!k.laterRepair&&ip.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(k.laterRepair={era:_[1]})}const y=np.find(_=>_.re.test(s));if(y){const _=s.search(y.re),S=s.slice(_),z=Qr(S,n.era)??Qr(s,n.era);z&&(k.basedOn={era:z.era,reign:z.reign,year:z.year,relation:y.relation})}return k}const hi={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Zn(t){return hi[t]}function vn(t){const n=Rn(t);if(n!=null)return n;const r=Ui(t);if(r)return r.from;const o=nn(t).era;return o?vt[o]:void 0}const eo=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function gi(t){const n=eo.indexOf(t);return n===-1?eo.length:n}function op(t){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of t){const l=s.relation;l==="part_of"?n.belongsTo.push(s):l==="collected_in"?n.collected.push(s):l==="has_part"||l==="contains_text_of"?n.contains.push(s):l==="text_carried_by"||l==="studied_by"||l==="derived_from"||l==="followed_by"||l==="has_adaptation"?n.derivative.push(s):l==="studies"||l==="preceded_by"?n.studies.push(s):n.related.push(s)}const r=[],o=(s,l)=>{n[s].length&&r.push({key:s,labelKey:l,items:n[s]})};return o("belongsTo","belongsToWork"),o("collected","collectedIn"),o("contains","containedWorks"),o("derivative","derivativeWorks"),o("studies","studies"),o("related","relatedWorks"),r}function Vi(t,n){const r=Ii(t||[]),o=new Map,s=[];for(const d of r)d.group?(o.has(d.group)||o.set(d.group,[]),o.get(d.group).push(d)):s.push(d);for(const d of o.values())d.sort((u,x)=>{const m=g=>g.group_role==="origin"?0:g.group_role==="mirror"?1:2;return m(u)-m(x)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=_t(d),x=u.includes("text"),m=u.includes("image");x&&m?l.textImage.push(d):x?l.text.push(d):m?l.image.push(d):l.physical.push(d)}const p=["text","image","textImage","physical"].filter(d=>l[d].length>0).map(d=>({key:d,items:l[d]})),c=[...o.entries()].map(([d,u])=>{var x,m;return{key:d,label:((x=n==null?void 0:n[d])==null?void 0:x.label)||d,description:(m=n==null?void 0:n[d])==null?void 0:m.description,items:u}});return{buckets:p,mirrors:c,total:r.length}}function Ln(t){const n=[],r=t.metadata||{};r.edition&&n.push(String(r.edition)),t.source_label&&n.push(t.source_label),t.details&&n.push(t.details);const o=_n(t);return o&&o.expected>0&&n.push(o.missing>0?`${o.found} / ${o.expected} 冊 缺 ${o.missing}`:`${o.found} / ${o.expected} 冊`),r.version&&n.push(String(r.version)),n.join(" · ")}function Us(t,n){if(Ln(t)||n.filter(o=>o.name===t.name).length<2)return"";try{const o=new URL(t.url),s=o.searchParams.get("res")||o.searchParams.get("id");if(s)return s;const l=o.pathname.split("/").filter(Boolean).pop();if(l)return decodeURIComponent(l)}catch{}return""}function Vs(t,n){var l,a;const r=t.resources||[],o=[],s=[];for(const p of r){const c=_t(p);c.includes("image")&&o.push(p),c.includes("physical")&&s.push(p)}return{id:t.id,name:t.edition||t.title||t.id,era:nn(t),year:Rn(t),sortYear:vn(t),images:o,holders:s,locationName:(l=t.current_location)==null?void 0:l.name,important:sp(t.id,n),group:(a=n==null?void 0:n.node_groups)==null?void 0:a[t.id],hasImage:o.length>0}}function sp(t,n){var p,c;if(!n)return!1;const r=n.default_collection;if(!r)return!1;const o=(p=n.collections)==null?void 0:p[r];if(((o==null?void 0:o.book_ids)??(r==="core"?n.core_books??[]:[])).includes(t))return!0;const l=(o==null?void 0:o.groups)??[],a=(c=n.node_groups)==null?void 0:c[t];return!!a&&l.includes(a)}function Ys(t,n,r={}){const o=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(c=>!o.has(c.id)).map(c=>Vs(c,n));let l=s;r.era&&(l=l.filter(c=>c.era.era===r.era)),r.scanOnly&&(l=l.filter(c=>c.hasImage)),r.sort==="year"?l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=c.r.sortYear,x=d.r.sortYear;return u!=null&&x!=null?u-x||c.i-d.i:u!=null?-1:x!=null?1:c.i-d.i}).map(c=>c.r):l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=x=>(x.important?0:1)*2+(x.hasImage?0:1);return u(c.r)-u(d.r)||c.i-d.i}).map(c=>c.r);const p=[...new Set(s.map(c=>c.era.era).filter(Boolean))].sort((c,d)=>gi(c)-gi(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(c=>c.era.source==="edition")}}function lp(t,n){var y,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const r=(y=n.collections)==null?void 0:y[n.default_collection],o=(r==null?void 0:r.groups)??[],s=(r==null?void 0:r.book_ids)??[],l=o.length>0||s.length>0,a=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const p=new Set(o),c=new Set([...s,...a]),d=f=>{if(c.has(f))return!0;const v=n.node_groups[f];return v!=null&&p.has(v)},u=[],x=new Map,m=[];for(const f of t)if(!((j=n.excluded_books)!=null&&j.includes(f)))if(d(f))u.push(f);else{const v=n.node_groups[f];v?(x.has(v)||x.set(v,[]),x.get(v).push(f)):m.push(f)}if(m.length+[...x.values()].reduce((f,v)=>f+v.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(f=>[f.id,f])),k=[...x.entries()].map(([f,v])=>{const $=b.get(f);return{id:f,label:($==null?void 0:$.label)??f,description:$==null?void 0:$.description,ids:v}});return m.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:m}),{useGrouping:!0,coreIds:u,groupedIds:k}}const Ks=["撰","編","注","校","譯","繪","其他"],ap=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function Yi(t){if(!t||!t.trim())return"撰";const n=t.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:r,re:o}of ap)if(o.test(n))return r;return"其他"}function Ki(t){if(!t)return"";const n=t.trim();return!n||!/[一-鿿]/.test(n)?"":n}function qs(t){const n=new Map;for(const o of t){const s=Yi(o);n.set(s,(n.get(s)??0)+1)}const r=[{cls:"全部",label:"全部",count:t.length}];for(const o of Ks){const s=n.get(o);s&&r.push({cls:o,label:o,count:s})}return r.length>2?r:[]}function Js(t,n,r){if(n&&n.books&&n.books.length>0){const s=n.books.map(a=>({id:a.work_id||a.book_id||void 0,title:a.title,section:a.section,volumes:a.volumes||[],subItems:a.sub_items,edition:a.edition,found:a.found_volumes,expected:a.expected_volumes})),l=[...new Set(s.map(a=>a.section).filter(Boolean))];return{rows:s,source:"catalog",sections:l,totalVolumes:n.total_volumes}}return t.contained_works&&t.contained_works.length>0?{rows:t.contained_works.map(l=>({id:l.id,title:l.title,volumes:Xt(l.volume_index)})),source:"works",sections:[]}:{rows:(t.books||[]).map(s=>{var l,a;return{id:s,title:((l=r==null?void 0:r.get(s))==null?void 0:l.title)||s,edition:(a=r==null?void 0:r.get(s))==null?void 0:a.edition,volumes:[]}}),source:"books",sections:[]}}function Xt(t){if(t==null)return[];if(typeof t=="number")return[t];if(Array.isArray(t))return t.filter(n=>typeof n=="number");if(typeof t=="string"){const n=t.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[r,o]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,o-r+1)},(s,l)=>r+l)}return t.split(/[,、]/).map(r=>parseInt(r.trim())).filter(r=>!isNaN(r))}return[]}function An(t,n="冊"){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const r=[...t].sort((l,a)=>l-a),o=r[0],s=r[r.length-1];return s-o+1===r.length?`${o}–${s}`:r.length<=3?r.join(", "):`${o}–${s} (${r.length}${n})`}const cp=["〇","一","二","三","四","五","六","七","八","九"],to=["","十","百","千"];function Zs(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),r=n.length;let o="",s=!1;for(let l=0;l<r;l++){const a=parseInt(n[l]),p=r-1-l;a===0?s=!0:(s&&o&&(o+="〇"),s=!1,a===1&&p===1&&l===0?o+=to[p]:o+=cp[a]+to[p])}return o}function dp(t){return t==null?"":typeof t=="string"?t:t.title??""}function ut(t,n="卷"){var o,s;const r=t;return r.measure_info?r.measure_info:(o=r.juan_count)!=null&&o.number?Zs(r.juan_count.number)+n:(s=r.juan_count)!=null&&s.description?r.juan_count.description:""}function Xs(t){var o;if(t.edition_type)return t.edition_type;if((o=t.lineage)!=null&&o.category)return t.lineage.category;const n=t.edition||t.title||"",r=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,l]of r)if(s.test(n))return l;return""}const pp=216,no="clamp(280px, 23vw, 360px)",up=1440,fi="(max-width: 719px)",mp=`${fi}, (pointer: coarse)`,xp=`
505
+ .bim-d-main.bim-d-main-grid { max-width: ${up}px; padding: 16px 32px 0; }
506
506
  .bim-d-grid {
507
507
  display: grid;
508
- grid-template-columns: ${lp}px minmax(0, 1fr) ${Qr};
508
+ grid-template-columns: ${pp}px minmax(0, 1fr) ${no};
509
509
  grid-template-rows: auto 1fr;
510
510
  grid-template-areas: "rail main card" "rail main side";
511
511
  column-gap: 32px; row-gap: 28px; align-items: start;
@@ -594,6 +594,8 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
594
594
  color: ${i("accent")};
595
595
  }
596
596
  .bim-d-more:hover { text-decoration: underline; text-underline-offset: 3px; }
597
+ /* CapMore:桌面只出桌面文案;只在手机端才有得展开的按钮桌面不出 */
598
+ .bim-d-more-n, .bim-d-more.bim-d-more-ncap { display: none; }
597
599
 
598
600
  /* 著录:朝代时间轴 + 单卡翻页 */
599
601
  .bim-d-lu { display: block; }
@@ -830,7 +832,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
830
832
  .bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
831
833
 
832
834
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
833
- @media ${cp} {
835
+ @media ${mp} {
834
836
  .bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
835
837
  .bim-d-card-foot summary, .bim-d-card-toggle, .bim-d-card details.bim-d-more-names summary,
836
838
  .bim-d-tl summary, .bim-d-chap a { min-height: 44px; }
@@ -868,7 +870,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
868
870
  /* 中等宽度:左栏折到顶部一行 */
869
871
  @media (max-width: 1100px) {
870
872
  .bim-d-grid {
871
- grid-template-columns: minmax(0, 1fr) ${Qr};
873
+ grid-template-columns: minmax(0, 1fr) ${no};
872
874
  grid-template-rows: auto auto 1fr;
873
875
  grid-template-areas: "rail rail" "main card" "main side";
874
876
  }
@@ -882,7 +884,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
882
884
  }
883
885
 
884
886
  /* 手机:左栏收起,提要卡 → 正文 → 旁栏 */
885
- @media ${gi} {
887
+ @media ${fi} {
886
888
  .bim-d-main.bim-d-main-grid { padding: 8px 16px 0; }
887
889
  .bim-d-grid {
888
890
  grid-template-columns: minmax(0, 1fr);
@@ -903,6 +905,14 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
903
905
  color: ${i("aux-fg")}; }
904
906
  .bim-d-zt td.bim-d-zt-blank { display: none; }
905
907
  .bim-d-zt td.bim-d-zt-main .bim-d-meta { padding-bottom: 2px; }
908
+ /*
909
+ * 手机端(overview#325):版本行加载完、没有卷帙小字时,那个 &nbsp; 占位行(桌面防 CLS 用)还占着 24px,
910
+ * 书名和「年代 馆藏」之间空一截;人物页著作行空的「部类」格以行内块显示,多出一段缩进。都收掉。
911
+ */
912
+ .bim-d-zt tr:not([data-loading]) td.bim-d-zt-main > .bim-d-meta[aria-hidden="true"] { display: none; }
913
+ .bim-d-zt td:not(.bim-d-zt-main):empty { display: none; }
914
+ /* 影印分组本身是一张卡(.bim-d-rg),里面的行再铺斑马底就成了卡里套卡;桌面本来就不铺(见上),手机也不铺 */
915
+ .bim-d-rg .bim-d-zt tbody tr:nth-child(odd) { background: transparent; }
906
916
  /* 手机上版本行是块:解析前先按「名 + 卷帙小字 + 一行年代馆藏」占高(实测解析后 81–87px) */
907
917
  .bim-d-zt-ver tbody tr { height: auto; }
908
918
  /* 朝代页签晚到、在手机上自成一行:解析中先占两行(页签一行 + 复选框一行,实测共 66px) */
@@ -922,6 +932,11 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
922
932
  .bim-d-pick { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; padding: 12px 14px; }
923
933
  .bim-d-pick-n { margin: 0; grid-column: 2; grid-row: 1 / span 2; }
924
934
  .bim-d-find { flex-basis: 100%; min-height: 40px; }
935
+ /* 长列表手机端首批只露 NARROW_CAP(6)条,其余等「展開其餘」(overview#325);按钮换成手机文案 */
936
+ .bim-d-zt[data-ncap] tbody tr:nth-child(n+7) { display: none; }
937
+ .bim-d-more-w { display: none; }
938
+ .bim-d-more-n { display: inline; }
939
+ .bim-d-more.bim-d-more-ncap { display: inline-flex; }
925
940
  }
926
941
 
927
942
  /*
@@ -944,7 +959,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
944
959
  :root[data-layout="boxed"] .bim-d-g-rail { border: ${i("fr-bd")}; background: ${i("fr-bg")}; padding: 14px 8px; }
945
960
  :root[data-layout="boxed"] .bim-d-filters { border-bottom: 1px solid ${i("fr-tab-bd")}; }
946
961
  :root[data-layout="boxed"] .bim-d-filters .bim-d-tab { margin-bottom: -1px; }
947
- @media ${gi} {
962
+ @media ${fi} {
948
963
  :root[data-layout="boxed"] .bim-d-card { padding: 16px; }
949
964
  :root[data-layout="boxed"] .bim-d-g-rail { border: 0; background: transparent; padding: 0; }
950
965
  }
@@ -959,7 +974,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
959
974
  :root[data-theme="ink"] :is(.bim-d-zt, .bim-d-side li, .bim-d-card-desc, .bim-d-desc, .bim-d-lf-card) a:hover {
960
975
  text-decoration-color: currentColor; text-decoration-thickness: 2px;
961
976
  }
962
- `;function rn({railTop:t,back:n,up:r,nav:o,railLinks:s,main:l,card:a,side:p}){const{convert:c}=F(),d=(o||[]).filter(Boolean);return e.jsxs("div",{className:"bim-d-grid",children:[e.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[t,n&&e.jsx("div",{style:{marginTop:t?12:0},children:n}),r,d.length>1&&e.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":c("本頁導航"),style:{marginTop:20},children:[e.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:c("本頁")}),e.jsx("ul",{className:"bim-d-rail-nav",children:d.map(u=>e.jsx("li",{children:e.jsxs("a",{href:`#${u.id}`,children:[e.jsx("span",{children:c(u.label)}),u.count!=null&&e.jsx("span",{className:"bim-d-meta",children:u.count})]})},u.id))})]}),s&&s.length>0&&e.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("更多"),children:[e.jsx("p",{className:"bim-d-rail-cap",children:c("更多")}),e.jsx("ul",{className:"bim-d-rail-nav",children:s.map(u=>e.jsx("li",{children:e.jsxs("a",{href:u.href??"#",onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),u.onClick())},children:[e.jsx("span",{children:c(u.label)}),e.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},u.key))})]})]}),e.jsx("div",{className:"bim-d-g-main",children:l}),e.jsx("div",{className:"bim-d-g-card",children:a}),e.jsx("div",{className:"bim-d-g-side",children:p})]})}function Js({caption:t,children:n}){const{convert:r}=F();return e.jsxs("div",{className:"bim-d-up bim-d-ui",children:[e.jsx("span",{className:"bim-d-up-cap",children:r(t)}),n]})}function Ve({id:t,title:n,meta:r,action:o,children:s}){const{convert:l}=F();return e.jsxs("section",{id:t,className:"bim-d-sec",children:[e.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[e.jsx("h2",{children:l(n)}),r!=null&&r!==""&&e.jsx("span",{className:"bim-d-meta",children:r}),o&&e.jsx("span",{className:"bim-d-sec-act",children:o})]}),e.jsx("div",{className:"bim-d-sec-body",children:s})]})}function Ue({items:t,className:n,style:r}){const o=t.filter(s=>s!=null&&s!==""&&s!==!1);return o.length?e.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:r,children:o.map((s,l)=>e.jsxs(h.Fragment,{children:[l>0&&e.jsx("span",{className:"bim-d-dot"}),e.jsx("span",{children:s})]},l))}):null}function Bn({items:t,value:n,onChange:r}){const{convert:o}=F();return e.jsx(e.Fragment,{children:t.map(s=>e.jsx("button",{type:"button",className:[...o(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>r(s.key),children:o(s.label)},s.key))})}function Zs({label:t,checked:n,onChange:r}){const{convert:o}=F();return e.jsxs("label",{className:"bim-d-check",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:s=>r(s.target.checked)}),o(t)]})}function Ot({label:t,onClick:n}){const{convert:r}=F();return e.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:r(t)})}function on({kind:t,title:n,subtitle:r,byline:o,meta:s,description:l,clampDescription:a,facts:p,stats:c,readAction:d,secondaryAction:u,children:x,foot:m}){const{convert:g}=F(),b=(p||[]).filter(v=>v.value!=null&&v.value!==""),k=(c||[]).filter(v=>v.value!=null&&v.value!==""&&v.value!==0),[y,j]=h.useState(!1),f=!!a&&!y;return e.jsxs("div",{className:"bim-d-card",children:[t&&e.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:g(t)}),e.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),r&&e.jsx("div",{className:"bim-d-card-sub",children:r}),o&&e.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:o}),s&&e.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),l&&e.jsx("div",{className:f?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:f?{"--detail-clamp":a}:void 0,children:l}),l&&!!a&&e.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":y,onClick:()=>j(v=>!v),children:g(y?"收起":"展開")}),k.length>0&&e.jsx("div",{className:"bim-d-stats bim-d-ui",children:k.map((v,$)=>e.jsxs("div",{children:[e.jsx("b",{children:v.value}),e.jsx("span",{children:g(v.label)})]},$))}),b.length>0&&e.jsx("dl",{className:"bim-d-ui",children:b.map((v,$)=>e.jsxs(h.Fragment,{children:[e.jsx("dt",{children:g(v.label)}),e.jsx("dd",{title:v.title,children:v.value})]},$))}),x,d,u,m&&e.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:m})]})}function Ki(t){return!!t&&[...t.replace(/\s+/g,"")].length>110}function fi({href:t,onClick:n,label:r="閱讀全文"}){const{convert:o}=F();return t?e.jsx("a",{className:"bim-d-btn",href:t,onClick:n?s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),n())}:void 0,children:o(r)}):e.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:o(r)})}function St({id:t,title:n,meta:r,items:o,metas:s,currentIndex:l,cap:a=8,moreLabel:p,foot:c,sub:d,timeline:u}){const{convert:x}=F(),[m,g]=h.useState(!1);if(!o.length)return null;const b=m?o:o.slice(0,a),k=o.length-b.length;return e.jsxs("div",{id:t,className:u?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[e.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[x(n),r!=null&&r!==""&&e.jsx("span",{className:"bim-d-meta",children:r})]}),d&&e.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:d}),e.jsx("ul",{children:b.map((y,j)=>e.jsxs("li",{className:j===l?"bim-d-side-cur":void 0,"aria-current":j===l?"page":void 0,children:[y,s!=null&&s[j]?e.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[j]}):null]},j))}),k>0&&e.jsx(Ot,{label:p?p(k):`顯示更多(${k})`,onClick:()=>g(!0)}),c&&e.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const pp={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function sn({revision:t,revisedAt:n,review:r,todo:o}){const{convert:s}=F(),l=r?pp[r.status]:void 0,a=r&&r.status!=="unreviewed"&&l?[l,r.by,r.date].filter(Boolean).join(" "):"",p=[t!=null&&t!==""?`${s("數據版本")} ${t}`:"",n??"",s(a)].filter(Boolean),c=(o||[]).filter(d=>d&&d.what);return!p.length&&!c.length?null:e.jsxs(e.Fragment,{children:[p.length>0&&e.jsx(Ue,{items:p,style:{fontSize:12}}),c.length>0&&e.jsxs("details",{children:[e.jsx("summary",{children:s(`待核 ${c.length} 項`)}),e.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:c.map((d,u)=>e.jsxs("li",{children:[s(d.what),(d.by||d.date)&&e.jsxs("span",{style:{marginLeft:6},children:["(",[d.by&&s(d.by),d.date].filter(Boolean).join(" · "),")"]})]},u))})]})]})}const gn=1e3,eo=208,up=1440,mp="(max-width: 719px)",Xs=`
977
+ `;function rn({railTop:t,back:n,up:r,nav:o,railLinks:s,main:l,card:a,side:p}){const{convert:c}=O(),d=(o||[]).filter(Boolean);return e.jsxs("div",{className:"bim-d-grid",children:[e.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[t,n&&e.jsx("div",{style:{marginTop:t?12:0},children:n}),r,d.length>1&&e.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":c("本頁導航"),style:{marginTop:20},children:[e.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:c("本頁")}),e.jsx("ul",{className:"bim-d-rail-nav",children:d.map(u=>e.jsx("li",{children:e.jsxs("a",{href:`#${u.id}`,children:[e.jsx("span",{children:c(u.label)}),u.count!=null&&e.jsx("span",{className:"bim-d-meta",children:u.count})]})},u.id))})]}),s&&s.length>0&&e.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("更多"),children:[e.jsx("p",{className:"bim-d-rail-cap",children:c("更多")}),e.jsx("ul",{className:"bim-d-rail-nav",children:s.map(u=>e.jsx("li",{children:e.jsxs("a",{href:u.href??"#",onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),u.onClick())},children:[e.jsx("span",{children:c(u.label)}),e.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},u.key))})]})]}),e.jsx("div",{className:"bim-d-g-main",children:l}),e.jsx("div",{className:"bim-d-g-card",children:a}),e.jsx("div",{className:"bim-d-g-side",children:p})]})}function Qs({caption:t,children:n}){const{convert:r}=O();return e.jsxs("div",{className:"bim-d-up bim-d-ui",children:[e.jsx("span",{className:"bim-d-up-cap",children:r(t)}),n]})}function Ve({id:t,title:n,meta:r,action:o,children:s}){const{convert:l}=O();return e.jsxs("section",{id:t,className:"bim-d-sec",children:[e.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[e.jsx("h2",{children:l(n)}),r!=null&&r!==""&&e.jsx("span",{className:"bim-d-meta",children:r}),o&&e.jsx("span",{className:"bim-d-sec-act",children:o})]}),e.jsx("div",{className:"bim-d-sec-body",children:s})]})}function Ue({items:t,className:n,style:r}){const o=t.filter(s=>s!=null&&s!==""&&s!==!1);return o.length?e.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:r,children:o.map((s,l)=>e.jsxs(h.Fragment,{children:[l>0&&e.jsx("span",{className:"bim-d-dot"}),e.jsx("span",{children:s})]},l))}):null}function Bn({items:t,value:n,onChange:r}){const{convert:o}=O();return e.jsx(e.Fragment,{children:t.map(s=>e.jsx("button",{type:"button",className:[...o(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>r(s.key),children:o(s.label)},s.key))})}function el({label:t,checked:n,onChange:r}){const{convert:o}=O();return e.jsxs("label",{className:"bim-d-check",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:s=>r(s.target.checked)}),o(t)]})}const tl=6,Mn=t=>t>tl+1;function qi({total:t,shown:n,unit:r,onClick:o}){const{convert:s}=O(),l=t-n,a=Mn(t)?t-Math.min(n,tl):l;return a<=0?null:e.jsxs("button",{type:"button",className:`bim-d-more bim-d-ui${l>0?"":" bim-d-more-ncap"}`,onClick:o,children:[l>0&&e.jsx("span",{className:"bim-d-more-w",children:s(`展開其餘 ${l} ${r}`)}),e.jsx("span",{className:"bim-d-more-n",children:s(`展開其餘 ${a} ${r}`)})]})}function Ji({label:t,onClick:n}){const{convert:r}=O();return e.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:r(t)})}function on({kind:t,title:n,subtitle:r,byline:o,meta:s,description:l,clampDescription:a,facts:p,stats:c,readAction:d,secondaryAction:u,children:x,foot:m}){const{convert:g}=O(),b=(p||[]).filter(v=>v.value!=null&&v.value!==""),k=(c||[]).filter(v=>v.value!=null&&v.value!==""&&v.value!==0),[y,j]=h.useState(!1),f=!!a&&!y;return e.jsxs("div",{className:"bim-d-card",children:[t&&e.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:g(t)}),e.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),r&&e.jsx("div",{className:"bim-d-card-sub",children:r}),o&&e.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:o}),s&&e.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),l&&e.jsx("div",{className:f?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:f?{"--detail-clamp":a}:void 0,children:l}),l&&!!a&&e.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":y,onClick:()=>j(v=>!v),children:g(y?"收起":"展開")}),k.length>0&&e.jsx("div",{className:"bim-d-stats bim-d-ui",children:k.map((v,$)=>e.jsxs("div",{children:[e.jsx("b",{children:v.value}),e.jsx("span",{children:g(v.label)})]},$))}),b.length>0&&e.jsx("dl",{className:"bim-d-ui",children:b.map((v,$)=>e.jsxs(h.Fragment,{children:[e.jsx("dt",{children:g(v.label)}),e.jsx("dd",{title:v.title,children:v.value})]},$))}),x,d,u,m&&e.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:m})]})}function Zi(t){return!!t&&[...t.replace(/\s+/g,"")].length>110}function bi({href:t,onClick:n,label:r="閱讀"}){const{convert:o}=O();return t?e.jsx("a",{className:"bim-d-btn",href:t,onClick:n?s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),n())}:void 0,children:o(r)}):e.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:o(r)})}function St({id:t,title:n,meta:r,items:o,metas:s,currentIndex:l,cap:a=8,moreLabel:p,foot:c,sub:d,timeline:u}){const{convert:x}=O(),[m,g]=h.useState(!1);if(!o.length)return null;const b=m?o:o.slice(0,a),k=o.length-b.length;return e.jsxs("div",{id:t,className:u?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[e.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[x(n),r!=null&&r!==""&&e.jsx("span",{className:"bim-d-meta",children:r})]}),d&&e.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:d}),e.jsx("ul",{children:b.map((y,j)=>e.jsxs("li",{className:j===l?"bim-d-side-cur":void 0,"aria-current":j===l?"page":void 0,children:[y,s!=null&&s[j]?e.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[j]}):null]},j))}),k>0&&e.jsx(Ji,{label:p?p(k):`顯示更多(${k})`,onClick:()=>g(!0)}),c&&e.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const hp={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function sn({revision:t,revisedAt:n,review:r,todo:o}){const{convert:s}=O(),l=r?hp[r.status]:void 0,a=r&&r.status!=="unreviewed"&&l?[l,r.by,r.date].filter(Boolean).join(" "):"",p=[t!=null&&t!==""?`${s("數據版本")} ${t}`:"",n??"",s(a)].filter(Boolean),c=(o||[]).filter(d=>d&&d.what);return!p.length&&!c.length?null:e.jsxs(e.Fragment,{children:[p.length>0&&e.jsx(Ue,{items:p,style:{fontSize:12}}),c.length>0&&e.jsxs("details",{children:[e.jsx("summary",{children:s(`待核 ${c.length} 項`)}),e.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:c.map((d,u)=>e.jsxs("li",{children:[s(d.what),(d.by||d.date)&&e.jsxs("span",{style:{marginLeft:6},children:["(",[d.by&&s(d.by),d.date].filter(Boolean).join(" · "),")"]})]},u))})]})]})}const gn=1e3,io=208,gp=1440,fp="(max-width: 719px)",nl=`
963
978
  .bim-d-page {
964
979
  background: ${i("page-bg")};
965
980
  color: ${i("ink")};
@@ -979,7 +994,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
979
994
  * PAGE_MAX_WIDTH,读者的行宽体验不变。
980
995
  */
981
996
  .bim-d-main.bim-d-main-wide {
982
- max-width: ${up}px;
997
+ max-width: ${gp}px;
983
998
  }
984
999
  .bim-d-ui { font-family: var(--bim-font-ui, system-ui, sans-serif); }
985
1000
 
@@ -1011,9 +1026,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
1011
1026
  */
1012
1027
  .bim-d-reader {
1013
1028
  display: grid;
1014
- grid-template-columns: ${eo}px minmax(0, ${gn}px);
1029
+ grid-template-columns: ${io}px minmax(0, ${gn}px);
1015
1030
  gap: 32px;
1016
- max-width: ${eo+gn+32}px;
1031
+ max-width: ${io+gn+32}px;
1017
1032
  margin: 0 auto;
1018
1033
  align-items: start;
1019
1034
  }
@@ -1036,7 +1051,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
1036
1051
  align-items: start; margin-bottom: 48px; }
1037
1052
  .bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
1038
1053
 
1039
- @media ${mp} {
1054
+ @media ${fp} {
1040
1055
  .bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
1041
1056
  .bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
1042
1057
  /* 表格:meta 列折到第二行,表头隐藏 */
@@ -1054,18 +1069,18 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
1054
1069
  padding-right: 0; padding-bottom: 12px;
1055
1070
  }
1056
1071
  }
1057
- ${dp}`;function Zt({children:t,style:n,wide:r,grid:o}){return e.jsxs("div",{className:"bim-d-page",style:n,children:[e.jsx("style",{children:Xs}),e.jsx("div",{className:o?"bim-d-main bim-d-main-grid":r?"bim-d-main bim-d-main-wide":"bim-d-main",children:t})]})}function bi({breadcrumb:t,actions:n}){return e.jsxs("div",{className:"bim-d-ui bim-d-top",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:i("aux-fg")},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:t}),n&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function qi({char:t,tone:n="accent"}){return e.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,flex:"none",fontSize:11,fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",background:i(n==="accent"?"accent":"ink"),color:i("page-bg")},children:t})}function yi({items:t}){const n=He();return e.jsx(e.Fragment,{children:t.map((r,o)=>{const s=o===t.length-1,l=o>0&&e.jsx("span",{style:{color:i("hint-fg")},children:"/"},`s${o}`),a=r.id?n(r.id):r.href,p=s||!r.onClick&&!a?e.jsx("span",{style:{color:i("ink")},children:r.label},o):e.jsx("a",{href:a??"#",onClick:r.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),r.onClick())}:void 0,style:{color:i("meta-fg")},children:r.label},o);return e.jsxs(h.Fragment,{children:[l,p]},o)})})}function Qs({title:t,subtitle:n,aside:r,secondLine:o}){return e.jsxs("header",{style:{borderBottom:`2px solid ${i("rule-strong")}`,paddingBottom:18},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[e.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:t}),n&&e.jsx("span",{style:{fontSize:15,color:i("meta-fg"),letterSpacing:".06em"},children:n})]}),r&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".06em"},children:r})]}),o&&e.jsx("div",{style:{marginTop:12,fontSize:13.5,color:i("quiet-fg")},children:o})]})}function xp({children:t,facts:n}){return!t&&n?e.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${i("rule")}`,marginBottom:40},children:n}):e.jsxs("div",{className:"bim-d-intro",children:[e.jsx("div",{style:{minWidth:0},children:t}),n]})}function hp({items:t,horizontal:n}){const{convert:r}=F();return t.length?e.jsx("div",{style:{borderLeft:`2px solid ${i("accent")}`,paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:t.map((o,s)=>e.jsxs("div",{title:o.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[e.jsx("span",{className:"bim-d-ui",style:{color:i("label-fg"),letterSpacing:".08em",flex:"none"},children:r(o.label)}),e.jsx("span",{style:{color:i("body-fg"),textAlign:n?"left":"right",minWidth:0},children:o.value})]},s))}):null}function gp({glyph:t,tone:n,title:r,count:o,actions:s,id:l}){const{convert:a}=F();return e.jsxs("div",{id:l,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(qi,{char:t,tone:n}),e.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:a(r)}),o!=null&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg")},children:o})]}),s&&e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function el({label:t,active:n,onClick:r,dashed:o}){const{convert:s}=F();return e.jsx("button",{type:"button",onClick:r,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${o&&!n?"dashed":"solid"} ${i(n?"accent":"rule")}`,background:n?i("accent"):"transparent",color:i(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(t)})}function fp({label:t,onClick:n}){const{convert:r}=F();return e.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:r(t)})}function bp({label:t,onClick:n,inline:r}){const{convert:o}=F();return e.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:r?0:12,width:r?void 0:"100%",padding:r?"4px 12px":9,background:"none",border:`1px dashed ${i("rule-dashed")}`,cursor:"pointer",fontSize:12,color:i("meta-fg"),letterSpacing:r?void 0:".08em"},children:o(t)})}function tl({children:t,href:n,onClick:r,title:o}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${i("rule")}`,fontSize:13,color:i("body-fg"),lineHeight:1.5};return n||r?e.jsx("a",{href:n??"#",title:o,onClick:r?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),r())}:void 0,style:s,children:t}):e.jsx("span",{title:o,style:s,children:t})}function yp({children:t}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t})}function jp({volumes:t,unit:n="冊",max:r=60}){const[o,s]=h.useState(!1);if(!t.length)return null;const l=o?t:t.slice(0,r);return e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[l.map(a=>e.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${i("rule")}`,color:i("meta-fg")},children:a},a)),!o&&t.length>r&&e.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${i("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:i("meta-fg")},children:["+",t.length-r]}),e.jsx("span",{style:{padding:"2px 6px",color:i("hint-fg")},children:n})]})}function vp({children:t}){return e.jsx("div",{style:{borderTop:`1px solid ${i("rule-strong")}`},children:t})}function kp({spec:t}){const{convert:n}=F();return e.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${t.leadWidth}px 1fr ${t.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${i("rule-strong")}`,fontSize:11,color:i("label-fg"),letterSpacing:".1em"},children:[e.jsx("span",{}),e.jsx("span",{children:n(t.mainLabel)}),e.jsx("span",{style:{display:"grid",gridTemplateColumns:t.columns.map(r=>r.width).join(" "),gap:12},children:t.columns.map(r=>e.jsx("span",{children:n(r.label)},r.label))})]})}function wp({no:t,main:n,meta:r,spec:o}){return e.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${o.leadWidth}px 1fr ${o.metaWidth}px`,gap:12},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:i("hint-fg"),textAlign:"right"},children:t}),e.jsx("span",{style:{minWidth:0},children:n}),e.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:o.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:r})]})}function Sp(t){return String(t+1).padStart(2,"0")}function $p(){return e.jsx("span",{style:{color:i("hint-fg")},children:"—"})}function _p({open:t,onToggle:n,main:r,action:o,children:s}){return e.jsxs("div",{style:{borderBottom:`1px solid ${i("rule")}`},children:[e.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[e.jsx("button",{type:"button",onClick:n,"aria-expanded":t,className:"bim-d-ui",style:{width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",fontSize:12,lineHeight:1,border:`1px solid ${i(t?"accent":"rule-dashed")}`,background:t?i("accent"):"transparent",color:i(t?"page-bg":"accent")},children:t?"-":"+"}),e.jsx("span",{style:{fontSize:14,minWidth:0},children:r}),o]}),t&&s&&e.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${i("rule-accent-soft")}`,marginLeft:12},children:s})]})}function nl(t){const n=[];for(let r=0;r<t.length;r++){const o=t[r];let s;if(o==="⟨")s="⟩";else if(o==="<"){const p=t[r+1];if(p===void 0||/[A-Za-z/!?>\s]/.test(p))continue;s=">"}else continue;const l=t.indexOf(s,r+1);if(l<0)continue;const a=t.slice(r+1,l);a.includes(`
1058
- `)||(n.push({start:r,end:l+1,inner:a}),r=l)}return n}function il(t,n){if(t.length<=n)return t;let r=n;for(const o of nl(t)){if(o.start>=r)break;if(o.end>r){r=o.start>0?o.start:o.end;break}}return t.slice(0,r)}const rl={fontSize:".78em",color:i("meta-fg"),lineHeight:1.55},zp={display:"inline-block",fontSize:"1em",lineHeight:1.15,padding:"0 .12em",margin:"0 .05em",border:"1px solid color-mix(in srgb, currentColor 40%, transparent)",borderRadius:2,verticalAlign:"baseline",whiteSpace:"nowrap"};function ol(t,n,r){return t.map((o,s)=>{switch(o.type){case"text":return e.jsx(h.Fragment,{children:n(o.text)},s);case"jz":return e.jsx("span",{className:"bim-jiazhu",style:r===0?rl:void 0,children:ol(o.children,n,r+1)},s);case"qw":return e.jsx("span",{className:"bim-qw guji-qw",title:o.label?`闕文:${o.label}`:"闕文",children:"□"},s);case"qz":return e.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":o.guess,children:"□"},s);case"zi":return e.jsx("span",{className:"bim-zi guji-zi",title:`組字:${o.label}`,style:zp,children:o.label},s)}})}function Ze(t,n=o=>o,r){if(!t)return"";if(r!=null&&r.gujiMarkdown)return Cd(t)?ol(ks(t),n,0):n(t);if(t.indexOf("⟨")<0&&t.indexOf("<")<0)return n(t);const o=[];let s=0,l=0;for(const a of nl(t))a.start>s&&o.push(e.jsx(h.Fragment,{children:n(t.slice(s,a.start))},l++)),o.push(e.jsx("span",{className:"bim-jiazhu",style:rl,children:n(a.inner)},l++)),s=a.end;return s<t.length&&o.push(e.jsx(h.Fragment,{children:n(t.slice(s))},l++)),o}function Cp({label:t,children:n}){return e.jsxs("div",{style:{marginBottom:10},children:[t&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:i("label-fg"),marginBottom:4},children:t}),e.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:i("quiet-fg"),textAlign:"justify"},children:n})]})}function Tp({title:t,tag:n,children:r}){const{convert:o}=F();return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${i("rule-strong")}`,marginBottom:2},children:[e.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:o(t)}),n&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:i("accent"),letterSpacing:".06em"},children:o(n)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:r})]})}function sl({name:t,note:n,href:r,extra:o}){const s=e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{fontSize:14,minWidth:0},children:t}),e.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:i("hint-fg"),flex:"none"},children:r?"↗":""}),n&&e.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:i("label-fg")},children:n})]}),l={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${i("rule")}`,color:i("body-fg"),alignItems:"baseline"};return e.jsxs(e.Fragment,{children:[r?e.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:l,children:s}):e.jsx("div",{style:l,children:s}),o]})}function Np({item:t,siblings:n,showVolumes:r=!0,fallbackNote:o}){const{convert:s}=F(),[l,a]=h.useState(!1),p=_n(t),c=r&&!!p&&p.expected>0,d=(t.url?Mt(t.url):void 0)||s(t.name),u=n?Ds(t,n):"",x=u?`${d}(${u})`:d;return e.jsx(sl,{name:x,note:Ln(t)||o,href:Wt(t),extra:c?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>a(m=>!m),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:l?"收起分冊":`展開 ${p.expected} 冊`}),l&&e.jsx(Ji,{item:t})]}):void 0})}function Ji({item:t}){return e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(t.volumes||[]).map((n,r)=>{const o=n.status==="missing";return n.url&&!o?e.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{padding:"4px 8px",borderRadius:4,background:i("zebra-bg")},children:n.volume},r):e.jsx("span",{style:{padding:"1px 5px",color:i(o?"missing-fg":"hint-fg"),textDecoration:o?"line-through":void 0},children:n.volume},r)})})}function ll({label:t,items:n}){const{convert:r}=F();return n.length?e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".08em"},children:t}),n.map((o,s)=>e.jsx(tl,{children:r(o)},s))]}):null}function Ip({rows:t}){const n=t.filter(r=>r.items.length>0);return n.length?e.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(r=>e.jsx(ll,{label:r.label,items:r.items},r.label))}):null}function ji(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function al({left:t,right:n}){return e.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:i("aux-fg")},children:[e.jsx("span",{children:t}),n&&e.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function Ep({children:t,action:n}){return e.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:i("aux-fg"),borderBottom:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[e.jsx("span",{children:t}),n]})}function De({id:t,label:n,onNavigate:r,renderLink:o,style:s,dense:l}){const a=He();return o?e.jsx(e.Fragment,{children:o(t,typeof n=="string"?n:void 0,{dense:l})}):e.jsx("a",{href:a(t),onClick:r?p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),r(t))}:void 0,style:s,children:n??t})}function Rp({href:t,children:n}){return e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:[n," ",e.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const Lp={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},Ap={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},Bp=`1px solid ${i("table-border")}`,cl={border:Bp,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},Mp={...cl,background:i("table-head-bg"),fontWeight:600};function Zi({table:t,opts:n}){return e.jsx("div",{className:"bim-guji-table-wrap",style:Lp,children:e.jsx("table",{className:"bim-guji-table",style:Ap,children:e.jsx("tbody",{children:t.rows.map((r,o)=>e.jsx("tr",{children:r.cells.map((s,l)=>{const a=r.header?"th":"td";return e.jsx(a,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:r.header?Mp:cl,children:s.empty?null:Ze(s.text,void 0,n)},l)})},o))})})})}function Wp(t,n){return t.indexOf("**")<0?Ze(t,void 0,n):t.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((o,s)=>s%2===1?e.jsx("strong",{children:Ze(o.trim().slice(2,-2),void 0,n)},s):e.jsx(h.Fragment,{children:Ze(o,void 0,n)},s))}function Fp(t,n,r=!1){const o=r?{gujiMarkdown:!0}:void 0;return n?Oi(t).map((s,l)=>s.type==="table"?e.jsx(Zi,{table:s.table,opts:o},l):e.jsx(h.Fragment,{children:Wp(s.text,o)},l)):Ze(t,void 0,o)}const Op=/^(#{1,6})\s+(.*)$/,Pp=/^\*\*([^*\n]+)\*\*\s*$/;function Xi(t){const n=t.match(Op);if(n)return{level:n[1].length,text:n[2].trim()};const r=t.trim().match(Pp);return r?{level:3,text:r[1].trim()}:null}const Qi=/^<!--.*-->$/;function dl(t){return t.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function pl(t){return t.split(`
1059
- `).map(n=>n.trim()).filter(n=>n&&!Qi.test(n))}const Dp=60;function ul(t){let n=0,r=0;for(const o of t.split(`
1060
- `)){const s=o.trim();if(!s||Qi.test(s)||Xi(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>Dp&&(r+=l)}return n>0&&r*2>=n}function Hp(t){return t.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function Mn(t){if(t=Hp(t),ul(t))return"unknown";const n=dl(t);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const r=n.map(s=>pl(s).length).filter(s=>s>0);if(r.length===0)return"unknown";const o=r.reduce((s,l)=>s+l,0)/r.length;return o<=4?"record":o>=8?"catalog":"unknown"}function Gp(t){const n=t.split(`
1072
+ ${xp}`;function Jt({children:t,style:n,wide:r,grid:o}){return e.jsxs("div",{className:"bim-d-page",style:n,children:[e.jsx("style",{children:nl}),e.jsx("div",{className:o?"bim-d-main bim-d-main-grid":r?"bim-d-main bim-d-main-wide":"bim-d-main",children:t})]})}function yi({breadcrumb:t,actions:n}){return e.jsxs("div",{className:"bim-d-ui bim-d-top",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:i("aux-fg")},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:t}),n&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function Xi({char:t,tone:n="accent"}){return e.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,flex:"none",fontSize:11,fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",background:i(n==="accent"?"accent":"ink"),color:i("page-bg")},children:t})}function ji({items:t}){const n=He();return e.jsx(e.Fragment,{children:t.map((r,o)=>{const s=o===t.length-1,l=o>0&&e.jsx("span",{style:{color:i("hint-fg")},children:"/"},`s${o}`),a=r.id?n(r.id):r.href,p=s||!r.onClick&&!a?e.jsx("span",{style:{color:i("ink")},children:r.label},o):e.jsx("a",{href:a??"#",onClick:r.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),r.onClick())}:void 0,style:{color:i("meta-fg")},children:r.label},o);return e.jsxs(h.Fragment,{children:[l,p]},o)})})}function il({title:t,subtitle:n,aside:r,secondLine:o}){return e.jsxs("header",{style:{borderBottom:`2px solid ${i("rule-strong")}`,paddingBottom:18},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[e.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:t}),n&&e.jsx("span",{style:{fontSize:15,color:i("meta-fg"),letterSpacing:".06em"},children:n})]}),r&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".06em"},children:r})]}),o&&e.jsx("div",{style:{marginTop:12,fontSize:13.5,color:i("quiet-fg")},children:o})]})}function bp({children:t,facts:n}){return!t&&n?e.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${i("rule")}`,marginBottom:40},children:n}):e.jsxs("div",{className:"bim-d-intro",children:[e.jsx("div",{style:{minWidth:0},children:t}),n]})}function yp({items:t,horizontal:n}){const{convert:r}=O();return t.length?e.jsx("div",{style:{borderLeft:`2px solid ${i("accent")}`,paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:t.map((o,s)=>e.jsxs("div",{title:o.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[e.jsx("span",{className:"bim-d-ui",style:{color:i("label-fg"),letterSpacing:".08em",flex:"none"},children:r(o.label)}),e.jsx("span",{style:{color:i("body-fg"),textAlign:n?"left":"right",minWidth:0},children:o.value})]},s))}):null}function jp({glyph:t,tone:n,title:r,count:o,actions:s,id:l}){const{convert:a}=O();return e.jsxs("div",{id:l,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(Xi,{char:t,tone:n}),e.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:a(r)}),o!=null&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg")},children:o})]}),s&&e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function rl({label:t,active:n,onClick:r,dashed:o}){const{convert:s}=O();return e.jsx("button",{type:"button",onClick:r,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${o&&!n?"dashed":"solid"} ${i(n?"accent":"rule")}`,background:n?i("accent"):"transparent",color:i(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(t)})}function vp({label:t,onClick:n}){const{convert:r}=O();return e.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:r(t)})}function kp({label:t,onClick:n,inline:r}){const{convert:o}=O();return e.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:r?0:12,width:r?void 0:"100%",padding:r?"4px 12px":9,background:"none",border:`1px dashed ${i("rule-dashed")}`,cursor:"pointer",fontSize:12,color:i("meta-fg"),letterSpacing:r?void 0:".08em"},children:o(t)})}function ol({children:t,href:n,onClick:r,title:o}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${i("rule")}`,fontSize:13,color:i("body-fg"),lineHeight:1.5};return n||r?e.jsx("a",{href:n??"#",title:o,onClick:r?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),r())}:void 0,style:s,children:t}):e.jsx("span",{title:o,style:s,children:t})}function wp({children:t}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t})}function Sp({volumes:t,unit:n="冊",max:r=60}){const[o,s]=h.useState(!1);if(!t.length)return null;const l=o?t:t.slice(0,r);return e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[l.map(a=>e.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${i("rule")}`,color:i("meta-fg")},children:a},a)),!o&&t.length>r&&e.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${i("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:i("meta-fg")},children:["+",t.length-r]}),e.jsx("span",{style:{padding:"2px 6px",color:i("hint-fg")},children:n})]})}function $p({children:t}){return e.jsx("div",{style:{borderTop:`1px solid ${i("rule-strong")}`},children:t})}function _p({spec:t}){const{convert:n}=O();return e.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${t.leadWidth}px 1fr ${t.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${i("rule-strong")}`,fontSize:11,color:i("label-fg"),letterSpacing:".1em"},children:[e.jsx("span",{}),e.jsx("span",{children:n(t.mainLabel)}),e.jsx("span",{style:{display:"grid",gridTemplateColumns:t.columns.map(r=>r.width).join(" "),gap:12},children:t.columns.map(r=>e.jsx("span",{children:n(r.label)},r.label))})]})}function zp({no:t,main:n,meta:r,spec:o}){return e.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${o.leadWidth}px 1fr ${o.metaWidth}px`,gap:12},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:i("hint-fg"),textAlign:"right"},children:t}),e.jsx("span",{style:{minWidth:0},children:n}),e.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:o.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:r})]})}function Cp(t){return String(t+1).padStart(2,"0")}function Tp(){return e.jsx("span",{style:{color:i("hint-fg")},children:"—"})}function Np({open:t,onToggle:n,main:r,action:o,children:s}){return e.jsxs("div",{style:{borderBottom:`1px solid ${i("rule")}`},children:[e.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[e.jsx("button",{type:"button",onClick:n,"aria-expanded":t,className:"bim-d-ui",style:{width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",fontSize:12,lineHeight:1,border:`1px solid ${i(t?"accent":"rule-dashed")}`,background:t?i("accent"):"transparent",color:i(t?"page-bg":"accent")},children:t?"-":"+"}),e.jsx("span",{style:{fontSize:14,minWidth:0},children:r}),o]}),t&&s&&e.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${i("rule-accent-soft")}`,marginLeft:12},children:s})]})}function sl(t){const n=[];for(let r=0;r<t.length;r++){const o=t[r];let s;if(o==="⟨")s="⟩";else if(o==="<"){const p=t[r+1];if(p===void 0||/[A-Za-z/!?>\s]/.test(p))continue;s=">"}else continue;const l=t.indexOf(s,r+1);if(l<0)continue;const a=t.slice(r+1,l);a.includes(`
1073
+ `)||(n.push({start:r,end:l+1,inner:a}),r=l)}return n}function ll(t,n){if(t.length<=n)return t;let r=n;for(const o of sl(t)){if(o.start>=r)break;if(o.end>r){r=o.start>0?o.start:o.end;break}}return t.slice(0,r)}const al={fontSize:".78em",color:i("meta-fg"),lineHeight:1.55},Ip={display:"inline-block",fontSize:"1em",lineHeight:1.15,padding:"0 .12em",margin:"0 .05em",border:"1px solid color-mix(in srgb, currentColor 40%, transparent)",borderRadius:2,verticalAlign:"baseline",whiteSpace:"nowrap"};function cl(t,n,r){return t.map((o,s)=>{switch(o.type){case"text":return e.jsx(h.Fragment,{children:n(o.text)},s);case"jz":return e.jsx("span",{className:"bim-jiazhu",style:r===0?al:void 0,children:cl(o.children,n,r+1)},s);case"qw":return e.jsx("span",{className:"bim-qw guji-qw",title:o.label?`闕文:${o.label}`:"闕文",children:"□"},s);case"qz":return e.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":o.guess,children:"□"},s);case"zi":return e.jsx("span",{className:"bim-zi guji-zi",title:`組字:${o.label}`,style:Ip,children:o.label},s)}})}function Ze(t,n=o=>o,r){if(!t)return"";if(r!=null&&r.gujiMarkdown)return Ed(t)?cl($s(t),n,0):n(t);if(t.indexOf("⟨")<0&&t.indexOf("<")<0)return n(t);const o=[];let s=0,l=0;for(const a of sl(t))a.start>s&&o.push(e.jsx(h.Fragment,{children:n(t.slice(s,a.start))},l++)),o.push(e.jsx("span",{className:"bim-jiazhu",style:al,children:n(a.inner)},l++)),s=a.end;return s<t.length&&o.push(e.jsx(h.Fragment,{children:n(t.slice(s))},l++)),o}function Ep({label:t,children:n}){return e.jsxs("div",{style:{marginBottom:10},children:[t&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:i("label-fg"),marginBottom:4},children:t}),e.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:i("quiet-fg"),textAlign:"justify"},children:n})]})}function Rp({title:t,tag:n,children:r}){const{convert:o}=O();return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${i("rule-strong")}`,marginBottom:2},children:[e.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:o(t)}),n&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:i("accent"),letterSpacing:".06em"},children:o(n)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:r})]})}function dl({name:t,note:n,href:r,extra:o}){const s=e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{fontSize:14,minWidth:0},children:t}),e.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:i("hint-fg"),flex:"none"},children:r?"↗":""}),n&&e.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:i("label-fg")},children:n})]}),l={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${i("rule")}`,color:i("body-fg"),alignItems:"baseline"};return e.jsxs(e.Fragment,{children:[r?e.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:l,children:s}):e.jsx("div",{style:l,children:s}),o]})}function Lp({item:t,siblings:n,showVolumes:r=!0,fallbackNote:o}){const{convert:s}=O(),[l,a]=h.useState(!1),p=_n(t),c=r&&!!p&&p.expected>0,d=(t.url?Mt(t.url):void 0)||s(t.name),u=n?Us(t,n):"",x=u?`${d}(${u})`:d;return e.jsx(dl,{name:x,note:Ln(t)||o,href:Wt(t),extra:c?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>a(m=>!m),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:l?"收起分冊":`展開 ${p.expected} 冊`}),l&&e.jsx(Qi,{item:t})]}):void 0})}function Qi({item:t}){return e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(t.volumes||[]).map((n,r)=>{const o=n.status==="missing";return n.url&&!o?e.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{padding:"4px 8px",borderRadius:4,background:i("zebra-bg")},children:n.volume},r):e.jsx("span",{style:{padding:"1px 5px",color:i(o?"missing-fg":"hint-fg"),textDecoration:o?"line-through":void 0},children:n.volume},r)})})}function pl({label:t,items:n}){const{convert:r}=O();return n.length?e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".08em"},children:t}),n.map((o,s)=>e.jsx(ol,{children:r(o)},s))]}):null}function Ap({rows:t}){const n=t.filter(r=>r.items.length>0);return n.length?e.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(r=>e.jsx(pl,{label:r.label,items:r.items},r.label))}):null}function vi(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ul({left:t,right:n}){return e.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:i("aux-fg")},children:[e.jsx("span",{children:t}),n&&e.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function Bp({children:t,action:n}){return e.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:i("aux-fg"),borderBottom:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[e.jsx("span",{children:t}),n]})}function De({id:t,label:n,onNavigate:r,renderLink:o,style:s,dense:l}){const a=He();return o?e.jsx(e.Fragment,{children:o(t,typeof n=="string"?n:void 0,{dense:l})}):e.jsx("a",{href:a(t),onClick:r?p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),r(t))}:void 0,style:s,children:n??t})}function Mp({href:t,children:n}){return e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:[n," ",e.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const Wp={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},Op={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},Fp=`1px solid ${i("table-border")}`,ml={border:Fp,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},Pp={...ml,background:i("table-head-bg"),fontWeight:600};function er({table:t,opts:n}){return e.jsx("div",{className:"bim-guji-table-wrap",style:Wp,children:e.jsx("table",{className:"bim-guji-table",style:Op,children:e.jsx("tbody",{children:t.rows.map((r,o)=>e.jsx("tr",{children:r.cells.map((s,l)=>{const a=r.header?"th":"td";return e.jsx(a,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:r.header?Pp:ml,children:s.empty?null:Ze(s.text,void 0,n)},l)})},o))})})})}function Dp(t,n){return t.indexOf("**")<0?Ze(t,void 0,n):t.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((o,s)=>s%2===1?e.jsx("strong",{children:Ze(o.trim().slice(2,-2),void 0,n)},s):e.jsx(h.Fragment,{children:Ze(o,void 0,n)},s))}function Hp(t,n,r=!1){const o=r?{gujiMarkdown:!0}:void 0;return n?Pi(t).map((s,l)=>s.type==="table"?e.jsx(er,{table:s.table,opts:o},l):e.jsx(h.Fragment,{children:Dp(s.text,o)},l)):Ze(t,void 0,o)}const Gp=/^(#{1,6})\s+(.*)$/,Up=/^\*\*([^*\n]+)\*\*\s*$/;function tr(t){const n=t.match(Gp);if(n)return{level:n[1].length,text:n[2].trim()};const r=t.trim().match(Up);return r?{level:3,text:r[1].trim()}:null}const nr=/^<!--.*-->$/;function xl(t){return t.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function hl(t){return t.split(`
1074
+ `).map(n=>n.trim()).filter(n=>n&&!nr.test(n))}const Vp=60;function gl(t){let n=0,r=0;for(const o of t.split(`
1075
+ `)){const s=o.trim();if(!s||nr.test(s)||tr(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>Vp&&(r+=l)}return n>0&&r*2>=n}function Yp(t){return t.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function Wn(t){if(t=Yp(t),gl(t))return"unknown";const n=xl(t);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const r=n.map(s=>hl(s).length).filter(s=>s>0);if(r.length===0)return"unknown";const o=r.reduce((s,l)=>s+l,0)/r.length;return o<=4?"record":o>=8?"catalog":"unknown"}function Kp(t){const n=t.split(`
1061
1076
  `),r=[];let o=null,s=[];const l=()=>{r.push({heading:o,body:s.join(`
1062
- `)}),s=[]};for(const a of n){const p=Xi(a);if(p){l(),o={kind:"heading",level:p.level,text:p.text};continue}s.push(a)}return l(),r}function to(t){const n=[];for(const r of t.split(`
1063
- `)){const o=Xi(r);if(o){n.push({kind:"heading",level:o.level,text:o.text});continue}const s=r.trim();!s||Qi.test(s)||n.push({kind:"body",text:r})}return n}function ml(t){if(!t)return[];const n=Mn(t);if(n==="unknown")return to(t);const r=[];for(const{heading:o,body:s}of Gp(t)){o&&r.push(o);const l=dl(s);if(l.length!==0){if(ul(s)){r.push(...to(s));continue}if(n==="record"){const a=l.join(" ");a&&r.push({kind:"body",text:a})}else for(const a of l){const p=pl(a);p.length&&r.push({kind:"body",text:p.join(" ")})}}}return r}const xl=t=>t;function hl(t,n=xl){if(t.indexOf("《")<0)return n(t);const r=[],o=/《([^《》\n]+)》/g;let s=0,l=0,a;for(;a=o.exec(t);)a.index>s&&r.push(e.jsx(h.Fragment,{children:n(t.slice(s,a.index))},l++)),r.push(e.jsxs("span",{className:"bim-rd-pn",children:[e.jsx("span",{className:"bim-rd-sr",children:"《"}),n(a[1]),e.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=a.index+a[0].length;return s===0?n(t):(s<t.length&&r.push(e.jsx(h.Fragment,{children:n(t.slice(s))},l++)),r)}function er(t,n={}){const r=n.renderText??xl,o=n.properNames?l=>hl(l,r):r,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Ze(t,o,s)}function no(t,n,r){return t.indexOf("**")<0?n(t):t.split(/(\*\*[^*]+\*\*)/g).map((s,l)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?e.jsx("strong",{children:n(s.slice(2,-2))},`${r}-${l}`):e.jsx(h.Fragment,{children:n(s)},`${r}-${l}`))}const Zn=/^(#{1,6})\s+(.*)$/,Up=/^\s*<!--.*-->\s*$/;function gl(t){return t.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
1064
- `)?"":n)}function Vp(t){return t<=1?2:t===2?3:4}function Yp(){let t=1;return n=>{const r=Vp(n),o=Math.min(r,t+1);return t=o,{Tag:`h${o}`,className:`bim-rd-hl${r}`}}}function kn(t){return t?Mn(gl(t))!=="unknown":!1}function io({text:t,mode:n,inline:r,dropTitle:o}){const s=gl(t),l=(d,u,x)=>!!o&&x<=1&&d<=2&&u.trim()===o.trim(),a=Yp();if(n==="paragraph"&&Mn(s)!=="unknown"){const d=ml(s);return e.jsx(e.Fragment,{children:d.map((u,x)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,x))return null;const{Tag:m,className:g}=a(u.level??1);return e.jsx(m,{className:g,children:r(u.text)},x)}return e.jsx("p",{children:no(u.text,r,x)},x)})})}const p=s.split(`
1065
- `);let c=0;return e.jsx(e.Fragment,{children:p.map((d,u)=>{const x=d.match(Zn);if(x){const g=c++;if(l(x[1].length,x[2],g))return null;const{Tag:b,className:k}=a(x[1].length);return e.jsx(b,{className:k,children:r(x[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Zn.test(p[u-1])&&!Zn.test(p[u-2])?e.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(Up.test(d))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:g,className:b}=a(3);return e.jsx(g,{className:b,children:r(d.trim().slice(2,-2))},u)}return e.jsx("p",{children:no(d,r,u)},u)})})}function Kp(t){const{convert:n}=F();return h.useMemo(()=>t?n(t):"",[t,n])}function tr({text:t,mode:n,tables:r=!1,gujiMarkdown:o=!1,properNames:s=!1,renderText:l,dropTitle:a}){const p=Kp(t),{convert:c}=F(),d=m=>er(m,{renderText:l,properNames:s,gujiMarkdown:o}),u=o?{gujiMarkdown:!0}:void 0,x=a?c(a):void 0;return!r||p.indexOf(":::")<0?e.jsx(io,{text:p,mode:n,inline:d,dropTitle:x}):e.jsx(e.Fragment,{children:Oi(p).map((m,g)=>m.type==="table"?e.jsx(Zi,{table:m.table,opts:u},g):e.jsx(io,{text:m.text,mode:n,inline:d,dropTitle:g===0?x:void 0},g))})}function qp(t,n){const[r,o]=h.useState(null),[s,l]=h.useState(!1),a=h.useRef(0);return h.useEffect(()=>{const p=++a.current;if(!t||!n){o(null),l(!1);return}let c;try{c=t(n)}catch{o(null),l(!1);return}if(!c||typeof c.then!="function"){o(c??null),l(!1);return}l(!0),c.then(d=>{p===a.current&&o(d??null)}).catch(()=>{p===a.current&&o(null)}).finally(()=>{p===a.current&&l(!1)})},[t,n]),{images:r,loading:s}}const ro={A:"fine",B:"rough",C:"rough",D:"ocr"};function Jp(t){return typeof t!="string"?null:t in si?t:t in ro?ro[t]:null}const Zp={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Xp={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function et(t){return typeof t!="string"?"":Zp[t]??Xp[t]??t}const Qp=["〇","一","二","三","四","五","六","七","八","九"],oo=["","十","百","千"],eu=["","萬","億"];function nr(t){if(t===0)return"〇";if(t<0)return`負${nr(-t)}`;const n=[];let r=t,o=0;for(;r>0;){const s=r%1e4;s>0?n.unshift(tu(s,o>0)+eu[o]):n.length>0&&n.unshift("〇"),r=Math.floor(r/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function tu(t,n){const r=[];let o=t;for(;o>0;)r.unshift(o%10),o=Math.floor(o/10);let s="";for(let l=0;l<r.length;l++){const a=r[l],p=r.length-1-l;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&p===1&&l===0&&!n?s+=oo[p]:s+=Qp[a]+oo[p]}return s.replace(/〇$/,"")}let en=null,mn=null;const wn=new Set;function nu(){return en?Promise.resolve():mn||(mn=import("opencc-js/t2cn").then(t=>{en=t.Converter({from:"tw",to:"cn"}),wn.forEach(n=>n())}).catch(()=>{en=t=>t,wn.forEach(t=>t())}),mn)}const iu=t=>t;function Ct(){const[,t]=h.useState(0);return h.useEffect(()=>{if(en)return;const n=()=>t(r=>r+1);return wn.add(n),nu(),()=>{wn.delete(n)}},[]),en??iu}function At(t,n){return n(t).toLowerCase()}const ru=i("highlight-bg");function ln(t,n,r){if(!n)return t;const o=At(n,r);if(!o)return t;const s=At(t,r);if(s.length!==t.length)return t;const l=[];let a=0,p=0;for(;a<t.length;){const c=s.indexOf(o,a);if(c===-1){l.push(t.slice(a));break}c>a&&l.push(t.slice(a,c)),l.push(e.jsx("mark",{style:{background:ru,padding:0,color:"inherit"},children:t.slice(c,c+o.length)},p++)),a=c+o.length}return e.jsx(e.Fragment,{children:l})}function ir(t,n,r,o){if(!n)return!0;const s=At(n,o);return(r?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(a=>typeof a=="string"&&At(a,o).includes(s))}function ou(t,n,r){return n?At(t,r).includes(At(n,r)):!0}const rr={类:i("section-lei"),书:i("section-shu"),序:i("section-xu"),结语:i("section-jieyu"),注释:i("section-zhushi")},su={考证:i("section-kaozhen")};function fl(t){var o;const n=t.files.length,r=((o=t.children)==null?void 0:o.reduce((s,l)=>s+fl(l),0))||0;return n+r}function lu(t,n){const r=[],o=a=>{var p;r.push(...a.files),(p=a.children)==null||p.forEach(o)};if(o(t),r.length===0)return;const s=r.map(a=>n[a]);if(s.every(a=>a===void 0))return;if(s.some(a=>a==="loading"))return"loading";let l=0;for(const a of s)typeof a=="number"&&(l+=a);return l}const au={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function or({enabled:t,expanded:n,onClick:r,style:o,children:s}){return t?e.jsx("button",{type:"button","aria-expanded":n,onClick:r,style:{...au,...o},children:s}):e.jsx("span",{style:o,children:s})}function cu({type:t}){const n=et(t),r=rr[n]||i("desc-fg");return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:r,border:`1px solid ${r}40`,borderRadius:"2px",background:`${r}08`,flexShrink:0},children:n})}function du({section:t,onNavigate:n,highlightQuery:r="",no:o,showUnlinked:s=!1,domId:l}){const{convert:a}=F(),p=He(),c=Ct(),d=f=>f?Ze(a(f),v=>r?ln(v,r,c):v):"",[u,x]=h.useState(!1),m=!!t.summary,g=!!t.comment,b=!!t.additional_comment,k=!!(t.content&&t.content.length>60),y=m||g||b||k;h.useEffect(()=>{r&&x(!0)},[r]);const j=!u&&k?il(t.content.replace(/\n/g," "),80)+"…":null;return e.jsxs("div",{className:"bim-rd-row",id:l,style:{borderBottom:`1px solid ${i("rule")}`,overflow:"hidden"},children:[e.jsxs("div",{onClick:()=>y&&x(!u),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:y?"pointer":"default",userSelect:"none"},children:[o!=null&&e.jsx("span",{className:"bim-rd-no",style:{flex:"none",width:28,fontSize:12,color:i("label-fg")},children:o}),e.jsxs(or,{enabled:y,expanded:u,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[y&&e.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg")},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",d(t.book_title),"》"]}):d(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[nr(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:d(t.author_info||t.author)})]}),!u&&j&&e.jsx("span",{style:{display:"block",fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:d(j)})]})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:d(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:i("section-tag-fg")},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:p(t.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),f.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品","aria-label":`查看作品:${t.book_title||t.title}`,children:"作品 →"}),s&&!t.work_id&&e.jsx("span",{style:{fontSize:"11px",color:i("label-fg"),flexShrink:0},children:"未关联"})]}),u&&y&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${i("widget-border")}`,background:i("bg")},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"8px"},children:d(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${i("primary")}`,background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:d(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(t.additional_comment)})]}),k&&!m&&!g&&!b&&e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:d(t.content)})]})]})}function pu({section:t,highlightQuery:n=""}){const{convert:r}=F(),o=Ct(),s=c=>c?Ze(r(c),d=>n?ln(d,n,o):d):"",[l,a]=h.useState(!1),p=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs(or,{enabled:p,expanded:l,onClick:()=>a(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[e.jsx(cu,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:s(t.title)}),p&&e.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&p&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${rr[et(t.type)]||i("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:i("bg")},children:e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(t.content)})})]})}const uu=100;function sr(t){return et(t.type)!=="page_header"?!1:(t.content||"").length>=uu}function mu({section:t,highlightQuery:n=""}){const{convert:r}=F(),o=Ct();if(et(t.type)==="page_header"&&!sr(t)||!t.content&&!t.title)return null;const s=r((t.content||t.title||"").replace(/\n{2,}/g,`
1066
- `)),l=Ze(s,d=>n?ln(d,n,o):d),a=et(t.type),p=rr[a]||i("desc-fg"),c=a==="序"||a==="结语"||a==="注释";return e.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:i("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${p}40`:void 0,background:c?i("bg"):void 0,borderRadius:c?"0 4px 4px 0":void 0,position:"relative"},children:[c&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:a}),l]})}function xu(t,n,r){const[o,s]=h.useState({});return h.useEffect(()=>{var d;if(!n||t.length===0)return;let l=!1;const a=t.filter(u=>{var x;return!((x=r==null?void 0:r.current)!=null&&x.has(u))}),p={};for(const u of t)(d=r==null?void 0:r.current)!=null&&d.has(u)&&(p[u]=r.current.get(u));if(Object.keys(p).length>0&&s(p),a.length===0)return;const c=async u=>{var x;try{if(n.getEntry){const y=await n.getEntry(u);if(y)return{title:y.title,author:y.author}}const m=await n.getItem(u);if(!m)return null;const g=m.title||u,b=m.authors,k=(x=b==null?void 0:b[0])==null?void 0:x.name;return{title:g,author:k}}catch{return null}};return Promise.all(a.map(async u=>{var m;const x=await c(u);return(m=r==null?void 0:r.current)==null||m.set(u,x),[u,x]})).then(u=>{l||s(x=>{const m={...x};for(const[g,b]of u)m[g]=b;return m})}),()=>{l=!0}},[t.join(","),n]),o}function hu({section:t,onNavigate:n,transport:r,workLabelCache:o,highlightQuery:s=""}){const{convert:l}=F(),a=He(),p=Ct(),c=f=>f?Ze(l(f),v=>s?ln(v,s,p):v):"",[d,u]=h.useState(!1);h.useEffect(()=>{s&&u(!0)},[s]);const x=et(t.type),m=su[x]||i("desc-fg"),g=!!t.content,b=t.work_ids||[],k=b.length>1,y=xu(k?b:[],r,o),j=g&&!d&&t.content.length>80?il(t.content,80)+"……":null;return e.jsxs("div",{style:{borderBottom:`1px solid ${i("widget-border")}`,padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>g&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:g?"pointer":"default",userSelect:"none"},children:[e.jsxs(or,{enabled:g,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[g&&e.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("span",{style:{display:"block",flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg"),lineHeight:1.6},children:t.header_line?c(t.header_line):c(t.title)}),!d&&j&&e.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:i("desc-fg"),lineHeight:1.7},children:c(j)})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&e.jsx("a",{href:a(b[0]),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),f.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),k&&e.jsxs("span",{style:{fontSize:"11px",color:i("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:m,border:`1px solid ${m}40`,borderRadius:"2px",background:`${m}08`},children:x})]})]}),k&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(f=>{const v=y[f],$=v?`${l(v.title)}${v.author?`(${l(v.author)})`:""}`:f.slice(0,8)+"…";return e.jsxs("a",{href:a(f),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),w.stopPropagation(),n(f))},style:{fontSize:"12px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:f,children:["→",$]},f)})}),d&&g&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${m}40`,borderRadius:"0 4px 4px 0",background:i("bg")},children:[e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${i("widget-border")}`,fontSize:"12px",color:i("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:c(t.comment)})]})]})}function gu({juan:t,searchQuery:n,onNavigate:r,transport:o,workLabelCache:s}){const l=Ct(),a=n.trim(),p=h.useMemo(()=>a?t.sections.filter(c=>ir(c,a,!0,l)):t.sections,[t.sections,a,l]);return e.jsxs("div",{children:[e.jsx("div",{children:p.map((c,d)=>e.jsx(hu,{section:c,onNavigate:r,transport:o,workLabelCache:s,highlightQuery:a},d))}),p.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function fu(){let t=!1;return n=>n==="类"?(t=!0,"h2"):t?"h3":"h2"}function bu({sections:t,onNavigate:n,inline:r,workLinks:o=!0}){const s=He(),{convert:l}=F(),a=fu();return e.jsx(e.Fragment,{children:t.map((p,c)=>{const d=et(p.type);if(d==="page_header"&&!sr(p))return null;if(d==="类")return e.jsxs(h.Fragment,{children:[h.createElement(a("类"),null,r(l(p.title))),p.content&&e.jsx("p",{children:r(l(p.content))})]},c);if(d==="书"||d==="诗"||d==="考证"||d==="注释"){const u=p.book_title?`《${p.book_title}》${p.n_juan!=null?nr(p.n_juan)+"卷":""}`:p.title,x=r(l(u));return e.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${c}`,children:[h.createElement(a("条目"),{className:"bim-rd-entry-h"},p.work_id&&n&&o?e.jsxs(e.Fragment,{children:[e.jsx("a",{href:s(p.work_id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),n(p.work_id))},title:"查看作品",children:x}),e.jsx("a",{className:"bim-rd-wl",href:s(p.work_id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),n(p.work_id))},"aria-label":`查看作品:${u}`,children:"作品 →"})]}):x),p.author_info&&e.jsx("p",{className:"bim-rd-sub",children:r(l(p.author_info))}),p.content&&p.content.split(/\n+/).map((m,g)=>e.jsx("p",{children:r(l(m))},g)),p.summary&&e.jsxs("p",{children:[e.jsx("span",{className:"bim-rd-lbl",children:"提要"}),r(l(p.summary))]}),p.comment&&e.jsxs("p",{children:[e.jsx("span",{className:"bim-rd-lbl",children:"按語"}),r(l(p.comment))]}),p.additional_comment&&e.jsxs("p",{children:[e.jsx("span",{className:"bim-rd-lbl",children:"附按"}),r(l(p.additional_comment))]})]},c)}return p.content?e.jsx("p",{children:r(l(p.content))},c):null})})}function bl(t){return t.some(n=>{const r=et(n.type);return r==="书"||r==="诗"||r==="考证"||r==="注释"||r==="类"||(r==="序"||r==="结语")&&!!n.content||r==="page_header"&&sr(n)})}function yu({juan:t,rawText:n,positionLabel:r,groupLabel:o,index:s,searchQuery:l,onNavigate:a,transport:p,workLabelCache:c,prefs:d,view:u,onViewChange:x}){var D;const{convert:m}=F(),g=Ct(),[b,k]=h.useState("text"),y=u??b,j=L=>{k(L),x==null||x(L)},f=l.trim(),v=(s==null?void 0:s.type)==="kaozhen",$=h.useCallback(L=>f?ln(L,f,g):L,[f,g]),w=L=>er(L,{renderText:$,properNames:d.properNames}),_=h.useMemo(()=>f?t.sections.filter(L=>ir(L,f,v,g)):t.sections,[t.sections,f,v,g]),S=(L,le)=>le.filter(A=>et(A.type)===L).length,z=S("书",t.sections),E=S("诗",t.sections),T=S("考证",t.sections);let N="";v?N=f?`${S("考证",_)} / ${T} ${m("條")}`:`${T} ${m("條")}`:E>0?N=f?`${S("诗",_)} / ${E} 首`:`${E} 首`:z>0&&(N=f?`${S("书",_)} / ${z} ${m("部書")}`:`${z} ${m("部書")}`);const V=s!=null&&s.text_quality?Jp(s.text_quality.grade):null,W=[];N&&W.push(N),v&&(s!=null&&s.target_source)&&W.push(e.jsxs(e.Fragment,{children:[m("考證對象")," ",m(s.target_source)]})),V&&W.push(e.jsx("span",{title:Qa[V],children:(D=s==null?void 0:s.text_quality)!=null&&D.source_note?e.jsxs(e.Fragment,{children:["底本 ",m(s.text_quality.source_note),e.jsx("span",{className:"bim-rd-grade",children:m(si[V])})]}):e.jsxs(e.Fragment,{children:[m("文本質量"),e.jsx("span",{className:"bim-rd-grade",children:m(si[V])})]})})),t.source_url&&W.push(e.jsx("a",{className:"bim-rd-link",href:t.source_url,target:"_blank",rel:"noopener noreferrer",children:m("原文來源")}));const B=!v&&bl(t.sections),H=!!n&&(!B||d.readingMode==="paragraph"&&kn(n)),te=!v&&(B||!!n),se=v||!te?"entries":y;let J=0;return e.jsxs(e.Fragment,{children:[e.jsxs("header",{children:[(r||o)&&e.jsxs("p",{className:"bim-rd-kicker",children:[r,r&&o&&e.jsx("span",{className:"bim-rd-dot"}),o&&m(o)]}),e.jsx("h1",{className:"bim-rd-h1",children:m(t.title)}),W.length>0&&e.jsx("p",{className:"bim-rd-meta",children:W.map((L,le)=>e.jsxs(h.Fragment,{children:[le>0&&e.jsx("span",{className:"bim-rd-dot"}),L]},le))}),te&&t.sections.length>0&&e.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":"看法",children:[e.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":se==="text",onClick:()=>j("text"),children:"正文"}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":se==="entries",onClick:()=>j("entries"),children:m("條目")})]})]}),se==="text"&&e.jsx("article",{className:"bim-rd-prose",children:H?e.jsx(tr,{text:n,mode:d.readingMode,properNames:d.properNames,renderText:$,dropTitle:t.title}):e.jsx(bu,{sections:t.sections,onNavigate:a,inline:w,workLinks:d.workLinks})}),se==="entries"&&e.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:v?e.jsx(gu,{juan:t,searchQuery:l,onNavigate:a,transport:p,workLabelCache:c}):e.jsxs(e.Fragment,{children:[_.some(L=>["书","诗","考证"].includes(et(L.type)))&&e.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[e.jsx("span",{style:{width:28},children:"序"}),e.jsx("span",{style:{flex:1},children:"书名"}),e.jsx("span",{children:"作品"})]}),_.map((L,le)=>{const A=et(L.type);return A==="书"||A==="诗"||A==="考证"?(J+=1,e.jsx(du,{domId:`rd-e-${t.sections.indexOf(L)}`,section:L,onNavigate:d.workLinks?a:void 0,highlightQuery:f,no:J,showUnlinked:d.workLinks&&!!a},le)):A==="类"?e.jsx(pu,{section:L,highlightQuery:f},le):e.jsx(mu,{section:L,highlightQuery:f},le)}),_.length===0&&e.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function ju(t){const{resetKey:n,load:r,files:o,activeFile:s,activeJuan:l,activeRawText:a,query:p,isKaozhen:c}=t,d=Ct(),u=h.useRef(new Map),[x,m]=h.useState({}),[g,b]=h.useState({}),k=h.useCallback((j,f)=>{const v=f==null?void 0:f.title;v&&b($=>$[j]===v?$:{...$,[j]:v})},[]);h.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:a}),k(s,l))},[s,l,a,k]),h.useEffect(()=>{u.current.clear(),m({}),b({})},[n]);const y=h.useCallback((j,f)=>{let v=0;if(j.juan)for(const $ of j.juan.sections)ir($,f,c,d)&&v++;return v===0&&j.rawText&&ou(j.rawText,f,d)&&(v=1),v},[c,d]);return h.useEffect(()=>{const j=p.trim();if(!j){m({});return}if(!r||o.length===0)return;let f=!1;const v={},$=[];for(const E of o){const T=u.current.get(E);T?v[E]=y(T,j):(v[E]="loading",$.push(E))}m(v);const w=8;let _=0;const S=async()=>{for(;_<$.length;){if(f)return;const E=_++,T=$[E];try{const N=await r(T),V=N.juan;if(u.current.set(T,N),k(T,V),f)return;m(W=>({...W,[T]:y(N,j)}))}catch{if(f)return;m(N=>({...N,[T]:0}))}}},z=Array.from({length:Math.min(w,$.length)},()=>S());return Promise.all(z),()=>{f=!0}},[p,n,r,o.join(","),y,d,k]),{matchStates:x,titles:g}}function vu({juan:t,view:n,onView:r,textHasEntries:o}){const{convert:s}=F(),l=t.sections.map((d,u)=>({s:d,i:u,t:et(d.type)})).filter(d=>d.t==="书"||d.t==="诗");if(l.length===0)return null;const a=l.filter(d=>!!d.s.work_id).length,p=l.every(d=>d.t==="诗")?"首":"部书",c=d=>{const u=()=>{var x,m;return(m=(x=document.getElementById(`rd-e-${d}`))==null?void 0:x.scrollIntoView)==null?void 0:m.call(x,{block:"start",behavior:"smooth"})};n==="text"&&!o&&r("entries"),n==="text"&&!o?setTimeout(u,0):u()};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bim-rd-rail-card",children:[e.jsx("div",{className:"bim-rd-rail-cap",children:"本卷"}),e.jsxs("div",{className:"bim-rd-rail-n",children:[e.jsx("b",{children:l.length}),e.jsx("span",{children:s(p)}),e.jsxs("span",{className:"bim-rd-rail-linked",children:["已关联 ",a]})]}),e.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":`已关联 ${a} / ${l.length}`,children:e.jsx("span",{style:{width:`${Math.round(a/l.length*100)}%`}})})]}),e.jsxs("nav",{"aria-label":"本卷条目",children:[e.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:s("條目")}),e.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:d,i:u})=>e.jsx("li",{children:e.jsxs("a",{href:`#rd-e-${u}`,onClick:x=>{x.preventDefault(),c(u)},children:[e.jsx("span",{className:`bim-rd-rail-dot${d.work_id?" on":""}`,"aria-hidden":"true"}),e.jsx("span",{children:s(d.book_title||d.title)})]})},u))})]})]})}const xn={padding:24,color:i("desc-fg"),fontSize:14},so=/^https?:\/\//i;function ku(t){if(!t||typeof t!="object")return null;const n=l=>typeof l=="string"&&l.trim()?l.trim():void 0,r=n(t.url),o=n(t.license_url),s={name:n(t.name),url:r&&so.test(r)?r:void 0,license:n(t.license),license_url:o&&so.test(o)?o:void 0,note:n(t.note)};return s.name||s.license||s.note?s:null}function wu(t,n){return{work_id:n.work_id??t,title:n.title,type:n.type,juan_files:n.chapters.map(r=>r.file),juan_metadata:n.juan_metadata,juan_groups:n.juan_groups,references:n.references,target_source:n.target_source,target_source_id:n.target_source_id,text_source:n.text_source,text_quality:n.text_quality}}function Su(t,n){return(n==null?void 0:n.type)==="kaozhen"?"章":n!=null&&n.juan_metadata&&Object.values(n.juan_metadata).some(r=>r.vol_label)?"冊":(t==null?void 0:t.kind)==="collated"?"卷":"章"}function yl(t,n,r,o=!1){const s=r(`${n}${t.n}`);if(!t.title)return s;const l=r(t.title);return o&&!/^[卷冊册章篇回第]/.test(t.title)?`${s} ${l}`:l}function $u(t,n,r,o,s){var d;const l=new Map(t.chapters.map(u=>[u.file,u])),a=u=>u==="loading"?"…":typeof u=="number"&&u>0?u:void 0,p=(u,x)=>{const m=l.get(u);return{key:u,label:x??(m?yl(m,r,o,s):u),hint:a(n[u]),disabled:n[u]===0}},c=(d=t.juan_groups)==null?void 0:d.filter(u=>{var x;return u.files.some(m=>l.has(m))||((x=u.children)==null?void 0:x.length)});if(c&&c.length>0){const u=(x,m)=>{var b;if(x.files.length===1&&!((b=x.children)!=null&&b.length))return p(x.files[0],o(x.label));const g=lu(x,n);return{key:`group:${m}`,label:o(x.label),hint:g==="loading"?"…":typeof g=="number"&&g>0?`${g}`:fl(x),defaultExpanded:typeof g=="number"&&g>0,children:[...x.files.filter(k=>l.has(k)).map(k=>p(k)),...(x.children??[]).map((k,y)=>u(k,`${m}.${y}`))]}};return c.map((x,m)=>u(x,`${m}`))}return t.chapters.map(u=>p(u.file))}const lr=({id:t,transport:n,versionKey:r,chapter:o,onLocationChange:s,onNavigate:l,title:a,subtitle:p,resolveImages:c,renderImageOverlay:d,imagePanel:u,allowVertical:x,onReportError:m,revisedAt:g,backHref:b,backLabel:k,className:y,style:j})=>{var Oe,Ee,mt;const{convert:f}=F(),v=h.useMemo(()=>Cs(n),[n]),[$,w]=Bs(),_=He(),S=h.useRef(s);S.current=s;const[z,E]=h.useState(null),[T,N]=h.useState("loading");h.useEffect(()=>{let Q=!1;return E(null),N("loading"),v.getManifest(t).then(Le=>{Q||(Le?(E(Le),N("ready")):N("missing"))}).catch(()=>{Q||N("missing")}),()=>{Q=!0}},[v,t]);const V=r!==void 0,W=o!==void 0,[B,H]=h.useState(null),[te,se]=h.useState(null);h.useEffect(()=>{H(null),se(null)},[t]);const J=be.pickTextVersion(z,V?r:B),D=((Oe=z==null?void 0:z.versions.find(Q=>Q.key==="default"))==null?void 0:Oe.key)??((Ee=z==null?void 0:z.versions[0])==null?void 0:Ee.key)??"default",L=(J==null?void 0:J.key)??null,le=W?o:te,A=h.useCallback((Q,Le,Xe)=>{var yt;(yt=S.current)==null||yt.call(S,{key:Q,chapter:Le,isDefault:Q===D},Xe)},[D]);h.useEffect(()=>{!z||!V||r==null||z.versions.some(Q=>Q.key===r)||A(D,null,"auto")},[z,V,r,D,A]);const ne=h.useRef(new Map);h.useEffect(()=>{ne.current.clear()},[v,t]);const de=h.useCallback(async Q=>{const Le=`${t}
1067
- ${Q}`;if(ne.current.has(Le))return ne.current.get(Le)??null;const Xe=await v.getIndex(t,Q).catch(()=>null);return Xe&&ne.current.set(Le,Xe),Xe},[v,t]),[G,he]=h.useState(null),[ye,xe]=h.useState("loading");h.useEffect(()=>{if(!L)return;let Q=!1;return he(null),xe("loading"),de(L).then(Le=>{Q||(Le&&Le.chapters.length>0?(he(Le),xe("ready")):xe("failed"))}),()=>{Q=!0}},[L,de]),h.useEffect(()=>{if(!G||!L||le!=null&&G.chapters.some(Xe=>Xe.file===le))return;const Le=G.chapters[0].file;W||se(Le),A(L,Le,"auto")},[G,L,le,W,A]);const pe=G?le!=null&&G.chapters.some(Q=>Q.file===le)?le:G.chapters[0].file:le,$e=h.useMemo(()=>G&&pe?G.chapters.find(Q=>Q.file===pe)??null:null,[G,pe]),Fe=h.useRef(0),Ae=h.useCallback(async Q=>{if(!z||Q===L||!z.versions.some(dn=>dn.key===Q))return;const Le=++Fe.current,Xe=await de(Q);if(Le!==Fe.current)return;const yt=$e??(pe?{file:pe}:null),Pt=be.matchChapterAcrossVersions(yt,Xe);V||H(Q),W||se(Pt),A(Q,Pt,"version")},[z,L,de,$e,pe,V,W,A]),Me=h.useCallback(Q=>{L&&(W||se(Q),A(L,Q,"chapter"))},[L,W,A]),[ve,Be]=h.useState(null),[P,ae]=h.useState(!1),ie=h.useRef(0);h.useEffect(()=>{if(!L||!$e)return;const Q=++ie.current;ae(!0),Be(null),v.getChapter(t,L,$e.file,{json:!!$e.has_json}).then(Le=>{Q===ie.current&&Be(Le)}).catch(()=>{Q===ie.current&&Be(null)}).finally(()=>{Q===ie.current&&ae(!1)})},[v,t,L,$e]);const _e=(J==null?void 0:J.kind)==="collated",[ke,Y]=h.useState("");h.useEffect(()=>{Y("")},[t,L]);const I=h.useMemo(()=>L&&_e?async Q=>{const Le=await v.getChapter(t,L,Q,{json:!0});return{juan:(Le==null?void 0:Le.json)??null,rawText:(Le==null?void 0:Le.md)??null}}:null,[v,t,L,_e]),U=(G==null?void 0:G.type)==="kaozhen",ge=h.useMemo(()=>(G==null?void 0:G.chapters.map(Q=>Q.file))??[],[G]),{matchStates:we}=ju({resetKey:`${t}
1068
- ${L??""}`,load:I,files:ge,activeFile:pe??null,activeJuan:(ve==null?void 0:ve.json)??null,activeRawText:(ve==null?void 0:ve.md)??null,query:ke,isKaozhen:U}),R=h.useRef(new Map);h.useEffect(()=>{R.current.clear()},[t]);const oe=qp(c,pe??null),{entryTitle:K,authors:X}=Cu(t,n,a===void 0),[je,Ie]=h.useState("text");if(h.useEffect(()=>{Ie("text")},[pe,L]),T==="loading")return e.jsx("div",{className:y,style:{...j,...xn},children:"加载中…"});if(T==="missing"||!z||!J)return e.jsx("div",{className:y,style:{...j,...xn},children:"暂无文本"});if(ye==="failed")return e.jsx("div",{className:y,style:{...j,...xn},children:"无法加载目录"});if(!G)return e.jsx("div",{className:y,style:{...j,...xn},children:"加载目录…"});const Re=Su(J,G),re=$u(G,we,Re,f,_e),ze=z.versions.map(Q=>({key:Q.key,label:be.textVersionLabel(Q),optionLabel:f(be.textVersionLabel(Q)),sourceName:Q.source_name?f(Q.source_name):void 0,license:Q.license??void 0,sourceUrl:Q.source_url??void 0,primary:Q.key===D})),C=ku((mt=G.source)==null?void 0:mt.upstream),q=a??(G.title?f(G.title):K?f(K):void 0),ee=q?e.jsx("a",{href:_(t),title:"查看条目",onClick:l?Q=>{Q.metaKey||Q.ctrlKey||(Q.preventDefault(),l(t))}:void 0,children:q}):void 0,Z=X.length>0?f(X.slice(0,2).map(Q=>`${Q.dynasty?`〔${Q.dynasty}〕`:""}${Q.name}${Q.role?` ${Q.role}`:" 撰"}`).join("、")):void 0,me=$e?yl($e,Re,f,_e):void 0,Ce=_e&&!!(ve!=null&&ve.json),O=(ve==null?void 0:ve.json)??null,M=(ve==null?void 0:ve.md)??null,ue=Ce&&!U&&bl(O.sections),Te=ue&&!(M&&$.readingMode==="paragraph"&&kn(M)),We=Ce&&ue?e.jsx(vu,{juan:O,view:je,onView:Ie,textHasEntries:Te}):void 0,Ne=$s(G)||di(G),ce=M?M.replace(/^##\s+[^\n]+\n+/,""):null,Se=p??(J.source_name?f(J.source_name):f(be.textVersionLabel(J)));return e.jsxs(Fs,{className:y,style:j,title:ee,subtitle:Se,byline:Z,current:me,pagerUnit:Re,rail:We,revisedAt:g,backHref:b,backLabel:k,onReportError:m?Q=>m({...Q,bookTitle:typeof q=="string"?q:void 0,entryId:t}):void 0,workLinkToggle:Ce&&!U&&!!l&&!!(O!=null&&O.sections.some(Q=>Q.work_id)),toc:re,tocCaption:`目录 · ${G.chapters.length} ${f(Re)}`,tocHeader:_e&&G.chapters.length>1?e.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:U?"搜索全部章节…":`搜索全部${Re}…`,"aria-label":U?"搜索全部章节":`搜索全部${Re}`,value:ke,onChange:Q=>Y(Q.target.value)}):void 0,activeKey:pe??null,onSelect:Me,images:oe.images,imagesLoading:oe.loading,renderImageOverlay:d,imagePanel:u,prefs:$,onPrefsChange:w,versions:ze.length>1?ze:void 0,currentVersionKey:ze.length>1?J.key:void 0,onVersionChange:Ae,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:kn(M),allowVertical:x,children:[P&&e.jsx(zt,{}),!P&&Ce&&O&&e.jsx(yu,{juan:O,rawText:M,positionLabel:_u($e,G,Re,f),groupLabel:zu(G,pe??null),index:wu(t,G),searchQuery:ke,onNavigate:l,transport:n,workLabelCache:R,prefs:$,view:je,onViewChange:Ie},`${L}/${pe}`),!P&&!Ce&&ce!=null&&$e&&e.jsxs(e.Fragment,{children:[e.jsxs("header",{children:[e.jsx("h1",{className:"bim-rd-h1",children:$e.title?f($e.title):me}),(J.source_name||J.license)&&e.jsxs("p",{className:"bim-rd-meta",children:[J.source_name&&e.jsxs(e.Fragment,{children:["来源 ",J.source_url?e.jsx("a",{className:"bim-rd-link",href:J.source_url,target:"_blank",rel:"noreferrer",children:f(J.source_name)}):f(J.source_name)]}),J.source_name&&J.license&&e.jsx("span",{className:"bim-rd-dot"}),J.license]}),C&&e.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:["上游 ",C.url?e.jsx("a",{className:"bim-rd-link",href:C.url,target:"_blank",rel:"noreferrer",children:f(C.name??C.url)}):f(C.name??""),C.license&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bim-rd-dot"}),C.license_url?e.jsx("a",{className:"bim-rd-link",href:C.license_url,target:"_blank",rel:"noreferrer",children:C.license}):C.license]}),C.note&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bim-rd-dot"}),f(C.note)]})]})]}),e.jsx("article",{className:"bim-rd-prose",children:e.jsx(tr,{text:ce,mode:$.readingMode,tables:Ne,gujiMarkdown:di(G),properNames:$.properNames})})]}),!P&&!Ce&&ce==null&&$e&&e.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"}),G.references&&G.references.length>0&&e.jsxs("section",{className:"bim-rd-refs",children:[e.jsx("h2",{children:f("參考文獻")}),e.jsx("ol",{children:G.references.map((Q,Le)=>e.jsxs("li",{children:[Q.url?e.jsx("a",{className:"bim-rd-link",href:Q.url,target:"_blank",rel:"noopener noreferrer",children:Q.title}):e.jsx("span",{children:Q.title}),Q.author&&e.jsxs("span",{children:[",",Q.author]}),Q.note&&e.jsxs("span",{children:["。",Q.note]})]},Le))})]})]})};function _u(t,n,r,o){var l,a;if(!t)return;const s=(a=(l=n.juan_metadata)==null?void 0:l[t.file])==null?void 0:a.vol_label;return o(s?`${s}冊`:`${r}${t.n}`)}function zu(t,n){if(!n)return;const r=o=>{var s;for(const l of o??[]){const a=r(l.children);if(a)return a;if((s=l.files)!=null&&s.includes(n))return l.label}};return r(t.juan_groups)}function Cu(t,n,r){const[o,s]=h.useState({entryTitle:void 0,authors:[]});return h.useEffect(()=>{if(s({entryTitle:void 0,authors:[]}),typeof n.getItem!="function")return;let l=!1;return Promise.resolve(n.getItem(t)).then(a=>{if(l||!a)return;const p=(a.authors??[]).filter(c=>c&&c.name);s({entryTitle:r&&typeof a.title=="string"?a.title:void 0,authors:p})}).catch(()=>{}),()=>{l=!0}},[t,n,r]),o}const Tu={bug:{label:"错误反馈",color:i("danger")},resource:{label:"资源建议",color:i("primary")},suggestion:{label:"功能建议",color:i("primary")},other:{label:"其他",color:i("desc-fg")}},Nu={label:"其他",color:i("desc-fg")},Iu={pending:{label:"待处理",color:i("warning")},in_progress:{label:"处理中",color:i("primary")},resolved:{label:"已处理",color:i("success")},wontfix:{label:"不采纳",color:i("desc-fg")},duplicate:{label:"重复",color:i("desc-fg")}},Eu={label:"待处理",color:i("warning")};function Ru(t){try{const n=new Date(t),r=o=>String(o).padStart(2,"0");return`${n.getFullYear()}-${r(n.getMonth()+1)}-${r(n.getDate())} ${r(n.getHours())}:${r(n.getMinutes())}`}catch{return t}}function Lu(t,n){if(!t)return!1;try{const r=new URL(t,n);if(r.protocol!=="http:"&&r.protocol!=="https:")return!1;const o=new URL(n);return r.hostname===o.hostname}catch{return!1}}const ar=({items:t,loading:n})=>{const r=He();return n?e.jsx(zt,{}):t.length===0?e.jsx("div",{style:Au,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const s=Tu[o.type]||Nu,l=Iu[o.status]||Eu,a=typeof window<"u"&&Lu(o.pageUrl,window.location.href);return e.jsxs("div",{style:Bu,children:[e.jsxs("div",{style:Mu,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...lo,background:s.color},children:s.label}),e.jsx("span",{style:{...lo,background:l.color},children:l.label})]}),e.jsx("span",{style:Wu,children:Ru(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:Fu,children:[o.resourceId&&e.jsx("a",{href:r(o.resourceId),style:Xn,children:o.resourceId}),o.pageUrl&&!o.resourceId&&(a?e.jsx("a",{href:o.pageUrl,style:Xn,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):e.jsx("span",{style:Xn,children:o.pageUrl}))]}),e.jsx("div",{style:Ou,children:o.content}),o.reply&&e.jsxs("div",{style:Pu,children:[e.jsx("div",{style:Du,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})})},Au={textAlign:"center",padding:"40px 0",color:i("desc-fg"),fontSize:"14px"},Bu={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"16px"},Mu={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},lo={fontSize:"12px",color:i("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Wu={fontSize:"12px",color:i("desc-fg")},Fu={fontSize:"12px",marginBottom:"6px"},Xn={color:i("primary"),textDecoration:"none",borderBottom:`1px dashed ${i("primary")}`},Ou={fontSize:"14px",lineHeight:"1.6",color:i("fg"),whiteSpace:"pre-wrap"},Pu={marginTop:"12px",padding:"10px 12px",background:i("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:i("fg")},Du={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:i("primary")},vi=({transport:t,onNavigate:n,recommendedIds:r,activeTab:o,onTabChange:s,feedbackApiUrl:l})=>{const a=fe(),[p,c]=h.useState(null),[d,u]=h.useState([]),[x,m]=h.useState("recommend"),[g,b]=h.useState([]),[k,y]=h.useState(!1),j=o??x,f=H=>{m(H),s==null||s(H)},[v,$]=h.useState(!0),[w,_]=h.useState(null),[S,z]=h.useState(null),[E,T]=h.useState(null);h.useEffect(()=>{let H=!1;if(t.getCounts)return t.getCounts().then(te=>{H||c({works:te.works,books:te.books,collections:te.collections})}).catch(()=>{}),()=>{H=!0}},[t]),h.useEffect(()=>{let H=!1;return(async()=>{if(r)return r;if(t.getRecommended)try{const se=await t.getRecommended();if(se!=null&&se.groups)return se.groups.flatMap(J=>J.items.map(D=>({...D,group:J.name})))}catch{}return[]})().then(async se=>{if(H)return;const J=se.filter(L=>L.id);if(J.length===0){$(!1);return}const D=await Promise.all(J.map(async L=>{if(L.type)return{id:L.id,title:L.title,type:L.type,author:L.author,dynasty:L.dynasty,role:L.role,edition:L.edition,has_text:L.has_text,has_image:L.has_image,has_collated:L.has_collated,subtype:L.subtype,primary_name:L.primary_name,group:L.group,fallbackDescription:L.description};try{let le=null;if(t.getEntry)le=await t.getEntry(L.id);else{const A=await t.getItem(L.id);A&&(le={id:L.id,title:A.title||L.id,type:A.type||"work"})}if(le)return{...le,group:L.group,fallbackDescription:L.description}}catch{}return{id:L.id,title:L.title,type:be.extractType(L.id),group:L.group,fallbackDescription:L.description}}));H||(u(D.filter(L=>L!==null)),$(!1))}),()=>{H=!0}},[t,r]);const N=h.useRef(!1),V=h.useRef(!1),W=h.useRef(!1);h.useEffect(()=>{if(j!=="catalog"||N.current)return;const H=t.getCatalogProgress??t.getResourceProgress;if(!H)return;N.current=!0;let te=!1;return H.call(t).then(se=>{te||_(se)}).catch(()=>{N.current=!1}),()=>{te=!0}},[t,j]),h.useEffect(()=>{if(j!=="collection"||V.current||!t.getCollectionProgress)return;V.current=!0;let H=!1;return t.getCollectionProgress().then(te=>{H||z(te)}).catch(()=>{V.current=!1}),()=>{H=!0}},[t,j]),h.useEffect(()=>{if(j!=="site"||W.current||!t.getSiteProgress)return;W.current=!0;let H=!1;return t.getSiteProgress().then(te=>{H||T(te)}).catch(()=>{W.current=!1}),()=>{H=!0}},[t,j]),h.useEffect(()=>{if(!l||j!=="feedback")return;let H=!1;return y(!0),fetch(l).then(te=>te.json()).then(te=>{!H&&te.success&&b(te.items||[])}).catch(()=>{}).finally(()=>{H||y(!1)}),()=>{H=!0}},[l,j]);const B=H=>e.jsx(Ft,{type:H,size:12});return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:i("fg")},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"16px"},children:[e.jsx(Yt,{label:a.home.recommendTab,active:j==="recommend",onClick:()=>f("recommend")}),e.jsx(Yt,{label:a.home.catalogTab,active:j==="catalog",onClick:()=>f("catalog")}),e.jsx(Yt,{label:a.home.collectionTab,active:j==="collection",onClick:()=>f("collection")}),e.jsx(Yt,{label:a.home.siteTab,active:j==="site",onClick:()=>f("site")}),l&&e.jsx(Yt,{label:a.home.feedbackTab,active:j==="feedback",onClick:()=>f("feedback")})]}),j==="recommend"&&e.jsx(Hu,{recommended:d,loading:v,onNavigate:n,getIcon:B,t:a}),j==="catalog"&&e.jsx(ao,{progress:w,t:a,onNavigate:n}),j==="collection"&&e.jsx(ao,{progress:S,t:a,onNavigate:n}),j==="site"&&e.jsx(Uu,{progress:E,t:a,totalWorks:(p==null?void 0:p.works)??0}),j==="feedback"&&l&&e.jsx(ar,{items:g,loading:k})]})})},Yt=({label:t,active:n,onClick:r})=>e.jsx("button",{onClick:r,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:i(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${i("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),Hu=({recommended:t,loading:n,onNavigate:r,getIcon:o,t:s})=>{const l=He();if(n)return e.jsx(zt,{});if(t.length===0)return null;const a=new Map;for(const p of t){const c=p.group||s.home.recommendedBrowse;a.has(c)||a.set(c,[]),a.get(c).push(p)}return e.jsx(e.Fragment,{children:Array.from(a.entries()).map(([p,c])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:p}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:l(d.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),r==null||r(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,cursor:"pointer",background:i("input-bg"),textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:o(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},ao=({progress:t,t:n,onNavigate:r})=>{if(!t)return e.jsx(zt,{});const o=[...t.resources].sort((p,c)=>p.priority-c.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},a={in_progress:i("progress-active"),done:i("progress-done"),todo:i("progress-todo")};return e.jsx("div",{children:s.map(p=>{const c=o.filter(d=>d.status===p);return c.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:a[p]}}),l[p]," (",c.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(d=>e.jsx(Gu,{item:d,t:n,statusColor:a[p],onNavigate:r},d.id))})]},p)})})},Gu=({item:t,t:n,statusColor:r,onNavigate:o})=>{const s=He(),l=t.total>0?Math.round(t.imported/t.total*100):0,a=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=t.edition?`${t.name}·${t.edition}`:t.name,c=t.collection_id||t.work_id;return c&&o?e.jsx("a",{href:s(c),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),o(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:p}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:i("widget-border"),color:i("desc-fg"),whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:a})]}),e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?nt(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:r,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:t.description})]})},Uu=({progress:t,t:n,totalWorks:r})=>{if(!t)return e.jsx(zt,{});const o=[...t.resources].sort((c,d)=>c.priority-d.priority),s=o.filter(c=>c.imported>0),l=o.filter(c=>c.imported===0),a=s.reduce((c,d)=>Math.max(c,d.imported),0),p=r>0?Math.round(a/r*100):0;return e.jsxs("div",{children:[r>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${i("primary")} 6%, transparent)`,fontSize:"13px",color:i("fg")},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:a.toLocaleString()})," / ",r.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>e.jsx(co,{item:c,t:n,totalWorks:r},c.id))})]}),l.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(c=>e.jsx(co,{item:c,t:n,totalWorks:r},c.id))})]})]})},co=({item:t,t:n,totalWorks:r})=>{const o=r>0?Math.round(t.imported/r*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${o}%)`:n.home.statusTodo})]}),t.imported>0&&r>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:i("progress-done"),transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:t.description})]})},po="(max-width: 768px)";function Vu(){const[t,n]=h.useState(()=>typeof window>"u"?!1:window.matchMedia(po).matches);return h.useEffect(()=>{const r=window.matchMedia(po),o=s=>n(s.matches);return r.addEventListener("change",o),()=>r.removeEventListener("change",o)},[]),t}const Yu=({transport:t,hideModeIndicator:n=!0,onEntryClick:r,recommendedIds:o,headerRight:s})=>{var V;const l=fe(),{convert:a}=F(),p=Vu(),[c,d]=h.useState(null),[u,x]=h.useState(null),[m,g]=h.useState(!1),[b,k]=h.useState("detail"),[y,j]=h.useState([]),[f,v]=h.useState(!1),$=h.useCallback(async W=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){j([]);return}v(!0);try{if(t.getCollectionCatalogs){const B=await t.getCollectionCatalogs(W);j(B||[])}else if(t.getCollectionCatalog){const B=await t.getCollectionCatalog(W);j(B?[{resource_id:"",data:B}]:[])}}catch{j([])}finally{v(!1)}},[t]),w=h.useCallback(async W=>{if(r){r(W);return}d(W),x(null),j([]),k("detail"),g(!0);try{const B=await t.getItem(W.id);B&&(x(B),B.type==="collection"&&$(W.id))}catch(B){console.error("加载详情失败:",B)}finally{g(!1)}},[t,r,$]),_=h.useCallback(async W=>{x(null),j([]),k("detail"),g(!0);try{const B=await t.getItem(W);B&&(x(B),d({id:W,title:B.title||W,type:B.type||"book"}),B.type==="collection"&&$(W))}catch(B){console.error("导航失败:",B)}finally{g(!1)}},[t,$]),S=typeof(u==null?void 0:u.text_count)=="number"&&u.text_count>0,z=(u==null?void 0:u.type)==="collection"&&(y.length>0||f)||(u==null?void 0:u.type)==="work"&&S,E=p&&(m||u),T=h.useCallback(()=>{d(null),x(null),j([]),k("detail")},[]),N=e.jsx(e.Fragment,{children:m?e.jsx(zt,{}):u?e.jsxs(e.Fragment,{children:[(z||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${i("widget-border")}`,padding:p?"0 12px":"0 48px",background:i("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[z&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>k("detail"),style:hn(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&f&&y.length===0&&e.jsxs("button",{onClick:()=>{},style:hn(!1),children:[l.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&y.map(W=>e.jsx("button",{onClick:()=>k(`catalog:${W.resource_id}`),style:hn(b===`catalog:${W.resource_id}`),children:W.short_name?`${a(W.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},W.resource_id)),u.type==="work"&&S&&e.jsx("button",{onClick:()=>k("collated"),style:hn(b==="collated"),children:l.detailTab.collatedEdition})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(Wi,{data:u,transport:t,onNavigate:_}):b.startsWith("catalog:")?e.jsx(Fi,{data:(V=y.find(W=>`catalog:${W.resource_id}`===b))==null?void 0:V.data,onNavigate:_}):b==="collated"?e.jsx(lr,{id:u.id,transport:t,onNavigate:_}):null})]}):e.jsx(vi,{transport:t,onNavigate:_,recommendedIds:o})});return p?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:E?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${i("widget-border")}`,background:i("input-bg"),flexShrink:0},children:e.jsxs("button",{onClick:T,style:{padding:"4px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:N})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(ci,{transport:t,onEntryClick:w,hideModeIndicator:n}),!u&&e.jsx(vi,{transport:t,onNavigate:_,recommendedIds:o})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${i("widget-border")}`,display:"flex",flexDirection:"column",background:i("input-bg"),overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(ci,{transport:t,onEntryClick:w,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:i("bg"),display:"flex",flexDirection:"column"},children:N})]})};function hn(t){return{padding:"10px 16px",border:"none",borderBottom:t?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(t?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}const Ku=({data:t,onNavigate:n,className:r,style:o})=>{var u;const s=fe(),{convert:l}=F(),[a,p]=h.useState(((u=t.divisions[0])==null?void 0:u.name)??null),[c,d]=h.useState(null);return e.jsxs("div",{className:r,style:o,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:l(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg"),display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(qu,{division:x,expanded:a===x.name,onToggle:()=>p(a===x.name?null:x.name),expandedCat:c,onCatToggle:m=>d(c===m?null:m),onNavigate:n},x.name))})]})},qu=({division:t,expanded:n,onToggle:r,expandedCat:o,onCatToggle:s,onNavigate:l})=>{const{convert:a}=F(),p=t.categories.reduce((c,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return c+(u.zhulu||0)+(u.cunmu||0)},0);return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:r,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${i("primary")} 6%, transparent)`:i("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:i("fg"),textAlign:"left"},children:[e.jsx("span",{children:a(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg")},children:[t.categories.length," 類 · ",p," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(c=>{const d=`${t.name}/${c.name}`;return e.jsx(Ju,{category:c,expanded:o===d,onToggle:()=>s(d),onNavigate:l},c.name)})})]})},Ju=({category:t,expanded:n,onToggle:r,onNavigate:o})=>{var c,d,u,x;const{convert:s}=F(),l=((c=t.books)==null?void 0:c.zhulu)||[],a=((d=t.books)==null?void 0:d.cunmu)||[],p=(((u=t.stats)==null?void 0:u.zhulu)||l.length)+(((x=t.stats)==null?void 0:x.cunmu)||a.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:r,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?i("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:i("fg"),textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[s(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||a.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&e.jsx(uo,{label:"著錄",books:l,onNavigate:o}),a.length>0&&e.jsx(uo,{label:"存目",books:a,onNavigate:o})]})]})},uo=({label:t,books:n,onNavigate:r})=>{const{convert:o}=F(),s=He(),[l,a]=h.useState(n.length<=20),p=l?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((c,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:i("fg")},children:c.work_id&&r?e.jsx("a",{href:s(c.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),r(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},children:o(c.title)}):o(c.title)}),c.volumes&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:o(c.volumes)}),c.author&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:o(c.author).slice(0,20)})]},d))}),!l&&e.jsxs("button",{onClick:()=>a(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},tt=({title:t,onSave:n,onAskAI:r,extraButtons:o,children:s})=>{const l=fe();return e.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:i("fg")},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[o,r&&e.jsx("button",{onClick:r,style:Xu,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Zu,children:l.action.save})]})]}),s]})},Zu={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Xu={padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Je=({label:t,value:n,onChange:r,placeholder:o,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:l=>r(l.target.value),placeholder:o,disabled:s,style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),$t=({value:t,onChange:n,placeholder:r})=>{const o=h.useRef(null);return h.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:o,value:t||"",onChange:s=>n(s.target.value),placeholder:r,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Sn=({children:t,color:n,style:r})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||i("primary-soft"),color:i(n?"on-color-fg":"fg"),...r},children:t});function Qu(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const fn=({value:t,onChange:n,label:r})=>{const[o,s]=h.useState(!1),l=h.useRef(null),a=Qu(t||"");return h.useEffect(()=>{o&&l.current&&l.current.focus()},[o]),!o&&a?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:mo,children:r}),e.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${i("input-border")}`,borderRadius:"2px",background:i("input-bg"),cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:i("fg")},children:a.name}),e.jsx(Sn,{children:a.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:mo,children:r}),e.jsx("input",{ref:l,type:"text",value:t||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},mo={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500};function em(t){switch(t){case"url":return i("source-url");case"bookID":return i("source-bookid");default:return i("desc-fg")}}function tm(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const jl=({items:t,onChange:n,onOpenEntityPicker:r})=>{const o=fe(),[s,l]=h.useState(null),a=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(t.length)},p=x=>{n(t.filter((m,g)=>g!==x)),s===x&&l(null)},c=(x,m,g)=>{const b=[...t];b[x]={...b[x],[m]:g},n(b)},d=(x,m)=>{const g=[...t];g[x]={...g[x],type:m,id:"",name:""},n(g),m==="bookID"&&r&&r(b=>{const k=[...t];k[x]={...k[x],id:b.id,name:b.title,type:"bookID"},n(k)})},u=x=>{r&&r(m=>{const g=[...t];g[x]={...g[x],id:m.id,name:m.title,type:"bookID"},n(g)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,m)=>e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===m?null:m),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===m?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:i("fg")},children:x.name||`${o.editor.sourcePlaceholder} ${m+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:em(x.type),color:i("on-color-fg"),borderRadius:"3px",fontWeight:500},children:tm(x.type)}),e.jsx("button",{onClick:g=>{g.stopPropagation(),p(m)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),s===m&&e.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:lt,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(m,"bookID"),style:{...xo,borderColor:i("source-bookid"),color:i("source-bookid")},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(m,"url"),style:{...xo,borderColor:i("source-url"),color:i("source-url")},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:lt,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const g=[...t];g[m]={...g[m],type:"",id:"",name:""},n(g)},style:ho,children:o.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:i("bg"),border:`1px solid ${i("source-bookid")}`,borderRadius:"6px"},children:[e.jsx("span",{style:{color:i("source-bookid"),fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:x.name}),e.jsx("code",{style:{fontSize:"11px",background:i("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>u(m),style:{background:"transparent",border:`1px solid ${i("widget-border")}`,color:i("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:o.action.reselect})]}):e.jsxs("button",{onClick:()=>u(m),style:{width:"100%",padding:"14px",border:`2px dashed ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:o.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:lt,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const g=[...t];g[m]={...g[m],type:"",id:"",name:""},n(g)},style:ho,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:g=>c(m,"name",g.target.value),placeholder:o.editor.sourceNamePlaceholder,style:Tt})]}),e.jsxs("div",{children:[e.jsx("label",{style:lt,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:g=>c(m,"id",g.target.value),placeholder:"https://...",style:Tt})]})]}),x.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:`1px dashed ${i("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...lt,opacity:.7},children:o.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:lt,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:g=>c(m,"details",g.target.value),placeholder:o.editor.detailsPlaceholder,style:Tt})]}),e.jsxs("div",{children:[e.jsx("label",{style:lt,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:g=>c(m,"position",g.target.value),placeholder:"如: 卷三, p.52",style:Tt})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:lt,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:g=>c(m,"version",g.target.value),placeholder:"如: v1.0, 2024-01",style:Tt})]}),e.jsxs("div",{children:[e.jsx("label",{style:lt,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:g=>c(m,"processor_version",g.target.value),placeholder:"如: v0.1",style:Tt})]})]})]})]})})]},m)),e.jsxs("button",{onClick:a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addSource})]})]})},lt={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},Tt={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},xo={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:i("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},ho={background:"transparent",border:"none",color:i("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function vl(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(r=>({id:r.id||"",name:r.name||"",type:r.type||"",details:r.details||"",position:r.position||"",version:r.version||"",processor_version:r.processor_version||""}))}catch{}return[]}function kl(t){return!t||t.length===0?"":JSON.stringify(t)}const wl=({entityType:t,entityId:n,entityTitle:r,parentWork:o,parentCollection:s,belongsToWork:l,belongsToCollection:a,childWorks:p,childCollections:c,containedBooks:d,siblingBooks:u,onLinkEntity:x,onUnlinkEntity:m,onViewEntity:g,onCreateAndLink:b,onSaveRelations:k})=>{const y=fe();return e.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:y.section.relations})]}),k&&e.jsx("button",{onClick:k,style:nm,children:y.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Kt,{direction:"up",title:y.relation.belongsToWork,entity:l,onView:g,onUnlink:()=>m("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:r}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),e.jsx(Kt,{direction:"up",title:y.relation.containedInCollection,entity:a,onView:g,onUnlink:()=>m("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:r}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),l&&u&&u.length>0&&e.jsx(Nt,{direction:"horizontal",title:`${y.relation.siblingVersions} (${u.length})`,entities:u,onView:g,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:y.relation.addVersionForWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(Kt,{direction:"up",title:y.relation.parentWork,entity:o,onView:g,onUnlink:()=>m("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),p&&p.length>0&&e.jsx(Nt,{direction:"down",title:`${y.relation.childWorks} (${p.length})`,entities:p,onView:g,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:y.action.addSubWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),c&&c.length>0&&e.jsx(Nt,{direction:"down",title:`${y.relation.collectionImpl} (${c.length})`,entities:c,onView:g,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:y.action.addCollectionImpl,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),e.jsx(Nt,{direction:"down",title:`${y.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:g,onAdd:()=>b("childBook","book",{workId:n}),addLabel:y.action.addVersion,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(Kt,{direction:"up",title:y.relation.correspondingWork,entity:l,onView:g,onUnlink:()=>m("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:r}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),e.jsx(Kt,{direction:"up",title:y.relation.parentCollection,entity:s,onView:g,onUnlink:()=>m("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),e.jsx(Nt,{direction:"down",title:`${y.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:g,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:y.action.addSubCollection,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),e.jsx(Nt,{direction:"down",title:`${y.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:g,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:y.action.addBook,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]})]})]})},Kt=({direction:t,title:n,entity:r,onView:o,onUnlink:s,onLink:l,onCreate:a,linkLabel:p,createLabel:c,notLinkedLabel:d,viewLabel:u,unlinkLabel:x})=>{const m=i(t==="up"?"relation-up":t==="down"?"relation-down":"relation-flat"),g=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[e.jsxs("div",{style:{fontSize:"12px",color:m,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:g}),e.jsx("span",{children:n})]}),r?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:i("bg"),borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Sl(r.type)}),e.jsx("span",{style:{fontWeight:500},children:r.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:r.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(go,{onClick:()=>o(r),title:u,children:"👁️"}),e.jsx(go,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(ki,{onClick:l,children:p}),e.jsx(ki,{onClick:a,primary:!0,children:c})]})]})},Nt=({direction:t,title:n,entities:r,onView:o,onAdd:s,addLabel:l,noneLabel:a,expandMoreLabel:p})=>{const[c,d]=h.useState(!1),u=i(t==="up"?"relation-up":t==="down"?"relation-down":"relation-flat"),x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",m=c?r:r.slice(0,5);return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[e.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),r.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[m.map(g=>e.jsxs("div",{onClick:()=>o(g),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:i("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:Sl(g.type)}),e.jsx("span",{children:g.title})]},g.id)),r.length>5&&!c&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:i("link-fg"),cursor:"pointer"},children:[p," (",r.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:a}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(ki,{onClick:s,primary:!0,children:["+ ",l]})})]})},go=({onClick:t,title:n,danger:r,children:o})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:r?i("danger"):"inherit",opacity:.7},children:o}),ki=({onClick:t,primary:n,children:r})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${i("widget-border")}`,borderRadius:"4px",background:n?i("primary"):"transparent",color:n?i("primary-fg"):"inherit",cursor:"pointer"},children:r});function Sl(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const nm={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},$l=({isOpen:t,entityType:n,title:r,onSelect:o,onCancel:s,onCreate:l,searchResults:a,onSearch:p,isLoading:c,excludeId:d})=>{const[u,x]=h.useState(""),m=d?a.filter(y=>y.id!==d):a;h.useEffect(()=>{t&&(x(""),p(""))},[t]);const g=y=>{x(y),p(y)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",k=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:im,children:e.jsxs("div",{style:rm,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:r}),e.jsx("button",{onClick:s,style:om,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:u,onChange:y=>g(y.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:sm})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?e.jsx("div",{style:Qn,children:"搜索中..."}):m.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:m.map(y=>e.jsxs("div",{onClick:()=>o(y),style:lm,children:[e.jsx("span",{style:{fontSize:"16px"},children:k}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[y.title,y.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:y.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[y.id,y.author&&` · ${y.author}`,y.dynasty&&` · ${y.dynasty}`]})]})]},y.id))}):u?e.jsxs("div",{style:Qn,children:["未找到匹配的",b]}):e.jsxs("div",{style:Qn,children:["输入关键词搜索",b]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:l,style:am,children:["创建新",b,"并关联"]})]})]})})},im={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},rm={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},om={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},sm={width:"100%",padding:"10px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},lm={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:i("primary-soft")},Qn={padding:"20px",textAlign:"center",color:i("desc-fg")},am={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},fo={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},cm={work:"📜",book:"📖",collection:"📚",entity:"👤"},_l=({isOpen:t,entityType:n,relationField:r,inheritData:o,onConfirm:s,onCancel:l})=>{const[a,p]=h.useState(""),c=h.useRef(null);h.useEffect(()=>{t&&(p((o==null?void 0:o.title)||""),setTimeout(()=>{var m,g;(m=c.current)==null||m.focus(),(g=c.current)==null||g.select()},100))},[t,o==null?void 0:o.title]);const d=m=>{m.key==="Enter"&&a.trim()?u():m.key==="Escape"&&l()},u=()=>{a.trim()&&s(a.trim(),{...o,title:a.trim()})};if(!t)return null;const x=()=>{switch(r){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${fo[n]}`}};return e.jsx("div",{style:dm,onClick:m=>{m.target===m.currentTarget&&l()},children:e.jsxs("div",{style:pm,onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:cm[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:i("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:i("danger"),marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:c,type:"text",value:a,onChange:m=>p(m.target.value),onKeyDown:d,placeholder:`请输入${fo[n]}名称...`,style:um})]}),((o==null?void 0:o.author)||(o==null?void 0:o.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),background:i("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(o==null?void 0:o.author)&&e.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:l,style:mm,children:"取消"}),e.jsx("button",{onClick:u,disabled:!a.trim(),style:{...xm,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},dm={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},pm={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:i("shadow-dialog")},um={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box"},mm={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},xm={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg")};function hm(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function zl(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function gm(t){switch(t){case"work":return i("editor-type-work");case"collection":return i("editor-type-collection");case"book":return i("editor-type-book");default:return i("desc-fg")}}const Cl=({isOpen:t,title:n,filterType:r="all",recentEntities:o=[],excludeId:s,showCreateButton:l=!1,createButtonText:a,onSelect:p,onCancel:c,onCreate:d,onSearch:u})=>{const[x,m]=h.useState(""),[g,b]=h.useState([]),[k,y]=h.useState(!1),[j,f]=h.useState("recent");h.useEffect(()=>{t&&(m(""),b([]),f(o.length>0?"recent":"search"))},[t,o.length]),h.useEffect(()=>{if(!x.trim()){b([]);return}const z=setTimeout(async()=>{y(!0);try{b(await u(x,r))}catch{b([])}finally{y(!1)}},300);return()=>clearTimeout(z)},[x,r,u]);const v=h.useCallback(z=>{m(z.target.value),z.target.value.trim()&&f("search")},[]),$=h.useCallback(z=>s?z.filter(E=>E.id!==s):z,[s]);if(!t)return null;const w=n||(r==="all"?"选择实体":`选择${zl(r)}`),_=$(o),S=$(g);return e.jsx("div",{style:bm,children:e.jsxs("div",{style:ym,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:w}),e.jsx("button",{onClick:c,style:jm,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:vm}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),k&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),_.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsxs(bo,{active:j==="recent",onClick:()=>f("recent"),children:["最近使用 (",_.length,")"]}),e.jsxs(bo,{active:j==="search",onClick:()=>f("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&_.length>0?e.jsx(yo,{entities:_,onSelect:p}):x.trim()?k?e.jsx(ei,{message:"搜索中..."}):S.length>0?e.jsx(yo,{entities:S,onSelect:p}):e.jsx(ei,{message:"未找到匹配的结果"}):e.jsx(ei,{message:"输入关键词开始搜索"})}),l&&d&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:d,style:km,children:a||"创建新实体"})]})]})})},bo=({active:t,onClick:n,children:r})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(t?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:r}),yo=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(r=>e.jsx(fm,{entity:r,onClick:()=>n(r)},r.id))}),fm=({entity:t,onClick:n})=>{const[r,o]=h.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i("primary-soft"),transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:hm(t.type)}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[t.title,t.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:t.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[e.jsx("code",{style:{fontSize:"10px",background:i("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:t.id}),t.author&&e.jsx("span",{children:t.author}),t.dynasty&&e.jsx("span",{children:t.dynasty})]})]}),e.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:gm(t.type),color:i("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:zl(t.type)})]})},ei=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:t}),bm={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ym={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},jm={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},vm={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},km={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},wm={work:i("editor-type-work"),collection:i("editor-type-collection"),book:i("editor-type-book"),entity:i("editor-type-entity")},Sm={work:"📜",collection:"📚",book:"📖",entity:"👤"},Tl=({data:t,onChange:n,onSave:r,transport:o,onNavigate:s,showDelete:l,onDelete:a,onAskAI:p,renderSectionActions:c,onDownloadResource:d,downloadStatuses:u,relations:x,onRelationsChange:m})=>{var ke;const g=fe(),[b,k]=h.useState(!1),[y,j]=h.useState("work"),[f,v]=h.useState(""),[$,w]=h.useState(""),[_,S]=h.useState([]),[z,E]=h.useState(!1),[T,N]=h.useState(!1),[V,W]=h.useState("work"),[B,H]=h.useState(""),[te,se]=h.useState(),[J,D]=h.useState(!1),[L,le]=h.useState(null),[A,ne]=h.useState([]);h.useRef(null);const de=t.type,G=de==="work",he=de==="collection",ye=de==="book",xe=h.useCallback((Y,I)=>{n({...t,[Y]:I})},[t,n]),pe=h.useCallback((Y,I)=>{v(Y),j(I),w(g.editor.selectToLink+g.indexType[I]),S([]),k(!0)},[g]),$e=h.useCallback(Y=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,Y)},[o,t.id]),Fe=h.useCallback(Y=>{s==null||s(Y.id,Y.type)},[s]),Ae=h.useCallback((Y,I,U)=>{const ge={...U,author:(U==null?void 0:U.author)||t.author,dynasty:U==null?void 0:U.dynasty};W(I),H(Y),se(ge),N(!0)},[t.author]),Me=h.useCallback((Y,I)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,B,{type:V,title:Y,inheritData:I}),N(!1)},[o,t.id,B,V]),ve=h.useCallback(Y=>{if(!Y.trim()){S([]);return}E(!0),o!=null&&o.searchEntities&&o.searchEntities(Y,y).then(I=>{S(I),E(!1)}).catch(()=>{S([]),E(!1)})},[o,y]),Be=h.useCallback(Y=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,f,Y.id),k(!1)},[o,t.id,f]),P=h.useCallback(()=>{r()},[r]),ae=h.useCallback(Y=>{le(()=>Y),D(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(ne).catch(()=>{})},[o]),ie=h.useCallback((Y,I)=>o!=null&&o.searchEntities?o.searchEntities(Y,I==="all"?void 0:I):Promise.resolve([]),[o]),_e=h.useCallback(Y=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(Y),ne(I=>[Y,...I.filter(U=>U.id!==Y.id)].slice(0,10)),L==null||L(Y),D(!1),le(null)},[o,L]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${i("widget-border")}`,paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Sm[de]}),e.jsx("span",{children:t.title||g.editor.untitled}),e.jsx(Sn,{children:t.id}),e.jsx(Sn,{color:wm[de],children:g.indexType[de]})]})}),e.jsx(tt,{title:g.section.basicInfo,onSave:r,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(fn,{label:G?g.editor.workTitle:he?g.editor.collectionTitle:g.editor.bookTitle,value:t.title,onChange:Y=>xe("title",Y)}),ye&&e.jsx(fn,{label:g.editor.belongsToWork,value:t.workName||"",onChange:Y=>xe("workName",Y)}),e.jsx(Je,{label:g.editor.authorLabel,value:t.author||"",onChange:Y=>xe("author",Y)}),e.jsx(Je,{label:g.editor.publicationYearLabel,value:t.publicationYear||"",onChange:Y=>xe("publicationYear",Y)}),(ye||he)&&e.jsx(fn,{label:g.editor.containedIn,value:t.collection||"",onChange:Y=>xe("collection",Y)}),(ye||he)&&e.jsx(Je,{label:g.editor.holderLabel,value:t.holder||"",onChange:Y=>xe("holder",Y)}),(ye||he)&&e.jsx(Je,{label:ye?g.editor.pageLabel:g.editor.volumeLabel,value:t.pages||"",onChange:Y=>xe("pages",Y)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(Je,{label:g.editor.firstImageLabel,value:t.firstImage||"",onChange:Y=>xe("firstImage",Y)})})]})}),e.jsx(tt,{title:g.section.description,onSave:r,onAskAI:p?()=>p("介绍"):void 0,children:e.jsx($t,{value:t.description||"",onChange:Y=>xe("description",Y),placeholder:g.editor.descriptionPlaceholder})}),(((ke=t.additional_works)==null?void 0:ke.length)||0)>0&&e.jsx(tt,{title:g.section.additionalWorks,onSave:r,children:e.jsx($m,{items:t.additional_works||[],onChange:Y=>xe("additional_works",Y)})}),e.jsx(tt,{title:g.section.indexedBy,onSave:r,onAskAI:p?()=>p("收录于"):void 0,children:e.jsx(_m,{items:t.indexed_by||[],onChange:Y=>xe("indexed_by",Y)})}),e.jsx(tt,{title:g.section.emendatedBy,onSave:r,onAskAI:p?()=>p("考证"):void 0,children:e.jsx(zm,{items:t.emendated_by||[],onChange:Y=>xe("emendated_by",Y)})}),e.jsx(tt,{title:g.section.textResources,onSave:r,onAskAI:p?()=>p("资源"):void 0,children:e.jsx(li,{items:t.resources||[],onChange:Y=>xe("resources",Y),onDownload:d,downloadStatuses:u,filterType:"text"})}),e.jsx(tt,{title:g.section.imageResources,onSave:r,children:e.jsx(li,{items:t.resources||[],onChange:Y=>xe("resources",Y),onDownload:d,downloadStatuses:u,filterType:"image"})}),e.jsx(tt,{title:g.section.sources,onSave:r,onAskAI:p?()=>p("资料来源"):void 0,children:e.jsx(jl,{items:vl(t.sources||""),onChange:Y=>xe("sources",kl(Y)),onOpenEntityPicker:ae})}),(ye||he)&&e.jsx(tt,{title:g.section.provenance,onSave:r,onAskAI:p?()=>p("收藏历史"):void 0,children:e.jsx($t,{value:t.provenance||"",onChange:Y=>xe("provenance",Y),placeholder:g.editor.provenancePlaceholder})}),ye&&e.jsx(tt,{title:g.section.otherEditions,onSave:r,onAskAI:p?()=>p("其他版本"):void 0,children:e.jsx($t,{value:t.otherEditions||"",onChange:Y=>xe("otherEditions",Y),placeholder:g.editor.otherEditionsPlaceholder})}),e.jsx(wl,{entityType:de,entityId:t.id,entityTitle:t.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:pe,onUnlinkEntity:$e,onViewEntity:Fe,onCreateAndLink:Ae,onSaveRelations:P}),l&&a&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${i("danger-soft-border")}`,background:i("danger-soft-bg"),borderRadius:"4px"},children:[e.jsx("div",{style:{color:i("danger"),fontWeight:600,marginBottom:"8px"},children:g.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"12px"},children:g.editor.dangerZoneDesc}),e.jsx("button",{onClick:a,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("danger")}`,borderRadius:"4px",background:"transparent",color:i("danger"),cursor:"pointer"},children:g.editor.deleteEntity})]}),e.jsx($l,{isOpen:b,entityType:y,title:$,onSelect:Be,onCancel:()=>k(!1),onCreate:()=>{k(!1),Ae(f,y)},searchResults:_,onSearch:ve,isLoading:z,excludeId:t.id}),e.jsx(_l,{isOpen:T,entityType:V,relationField:B,inheritData:te,onConfirm:Me,onCancel:()=>N(!1)}),e.jsx(Cl,{isOpen:J,title:g.action.selectBookOrWork,filterType:"all",recentEntities:A,excludeId:t.id,onSelect:_e,onCancel:()=>{D(!1),le(null)},onSearch:ie})]})};function $m({items:t,onChange:n}){const r=fe(),o=(a,p,c)=>{const d=t.map((u,x)=>x===a?{...u,[p]:c}:u);n(d)},s=a=>n(t.filter((p,c)=>c!==a)),l=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((a,p)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(Je,{label:r.editor.bookNameLabel,value:a.book_title,onChange:c=>o(p,"book_title",c)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(Je,{label:r.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:c=>o(p,"n_juan",c&&parseInt(c,10)||void 0)})}),e.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("muted"),marginTop:"18px"},children:"✕"})]},p)),e.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:r.action.addAdditionalWork})]})}function Nl({items:t,onChange:n,showMeta:r,addLabel:o}){const s=fe(),[l,a]=h.useState(null),p=(u,x,m)=>{const g=t.map((b,k)=>k===u?{...b,[x]:m||void 0}:b);n(g)},c=u=>{n(t.filter((x,m)=>m!==u)),l===u&&a(null)},d=()=>{n([...t,{source:""}]),a(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((u,x)=>{const m=l===x;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:m?`color-mix(in srgb, ${i("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>a(m?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.2s",transform:m?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:u.source_bid}),e.jsx("button",{onClick:g=>{g.stopPropagation(),c(x)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${i("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:i("muted")},children:"✕"})]}),!m&&r&&(u.title_info||u.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:i("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),m&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(Je,{label:s.label.sourceName,value:u.source,onChange:g=>p(x,"source",g)}),e.jsx(Je,{label:s.label.sourceBid,value:u.source_bid||"",onChange:g=>p(x,"source_bid",g)})]}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(Je,{label:s.label.titleInfo,value:u.title_info||"",onChange:g=>p(x,"title_info",g)}),e.jsx(Je,{label:s.label.authorInfo,value:u.author_info||"",onChange:g=>p(x,"author_info",g)})]}),e.jsx(Je,{label:s.label.edition,value:u.edition||"",onChange:g=>p(x,"edition",g)})]}),e.jsx($t,{value:u.summary||"",onChange:g=>p(x,"summary",g),placeholder:s.editor.summaryPlaceholder}),e.jsx($t,{value:u.comment||"",onChange:g=>p(x,"comment",g),placeholder:s.editor.commentPlaceholder}),e.jsx($t,{value:u.additional_comment||"",onChange:g=>p(x,"additional_comment",g),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:o})]})}function _m({items:t,onChange:n}){const r=fe();return e.jsx(Nl,{items:t,onChange:n,showMeta:!0,addLabel:r.action.addIndexedBy})}function zm({items:t,onChange:n}){const r=fe();return e.jsx(Nl,{items:t,onChange:n,addLabel:r.action.addEmendatedBy})}function Il(t){var p,c,d,u,x,m,g;const n=((c=(p=t.authors)==null?void 0:p[0])==null?void 0:c.name)||"",r=((d=t.publication_info)==null?void 0:d.year)||"",o=((u=t.current_location)==null?void 0:u.name)||"",s=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((m=t.page_count)==null?void 0:m.description)||"",l=typeof t.description=="object"&&t.description!==null&&t.description.text||"",a={id:t.id,title:t.title,type:t.type,author:n,publicationYear:r,holder:o,pages:s,description:l,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const b=t;if(Array.isArray(b.related_works)){const k=b.related_works.find(y=>y.relation==="part_of");k&&(a.parentWorkId=k.id,a.parentWorkName=k.title)}}if(t.type==="book"){const b=t;a.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(a.collectionId=(g=b.contained_in[0])==null?void 0:g.id)}return a}function Cm(t){const n={id:t.id,title:t.title,type:t.type,description:t.description?{text:t.description}:void 0,authors:t.author?[{name:t.author}]:void 0,publication_info:t.publicationYear?{year:t.publicationYear}:void 0,current_location:t.holder?{name:t.holder}:void 0,page_count:t.pages?{number:parseInt(t.pages)||0,description:t.pages}:void 0,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};return t.type==="work"&&t.parentWorkId&&(n.related_works=[{id:t.parentWorkId,title:t.parentWorkName||"",relation:"part_of"}]),t.type==="book"&&(n.work_id=t.workId,t.collectionId&&(n.contained_in=[{id:t.collectionId}])),n}const Tm=t=>{const{data:n,id:r,transport:o,mode:s="view",onModeChange:l,onChange:a,onSave:p,onDelete:c,onNavigate:d,renderLink:u,onAskAI:x,renderSectionActions:m,onDownloadResource:g,downloadStatuses:b,relations:k,onRelationsChange:y,headerExtra:j,className:f,style:v}=t;fe();const[$,w]=h.useState(s),_=l?s:$;h.useEffect(()=>{s!==$&&w(s)},[s]);const S=h.useCallback(()=>{const B=_==="view"?"edit":"view";l?l(B):w(B)},[_,l]),[z,E]=h.useState(null);h.useEffect(()=>{r&&o&&o.getItem(r).then(B=>{B&&E(B)})},[r,o]);const T=n||z,N=h.useMemo(()=>T?Il(T):null,[T]),V=l||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:_==="edit"?i("accent-bg"):"transparent",color:i(_==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?"切换到编辑模式":"切换到查看模式",children:_==="view"?"✏️ 编辑":"👁 查看"}):null,W=e.jsxs(e.Fragment,{children:[V,j]});return!T&&!N?e.jsx(zt,{}):_==="view"?e.jsx(Wi,{data:T,transport:o,onNavigate:d?B=>d(B):void 0,renderLink:u,headerExtra:W,className:f,style:v}):N?e.jsxs("div",{className:f,style:v,children:[W&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:W}),e.jsx(Tl,{data:N,onChange:a||(()=>{}),onSave:p||(()=>{}),transport:o,onNavigate:d,showDelete:!!c,onDelete:c,onAskAI:x,renderSectionActions:m,onDownloadResource:g,downloadStatuses:b,relations:k,onRelationsChange:y})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:i("muted")},children:"无数据"})},jo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],El=({isOpen:t,onClose:n,onSubmit:r,feedbackListUrl:o})=>{const[s,l]=h.useState(null),[a,p]=h.useState(""),[c,d]=h.useState(""),[u,x]=h.useState("idle"),[m,g]=h.useState(""),b=h.useRef(null);h.useEffect(()=>{t&&(l(null),p(""),d(""),x("idle"),g(""))},[t]),h.useEffect(()=>{s&&setTimeout(()=>{var f;return(f=b.current)==null?void 0:f.focus()},100)},[s]),h.useEffect(()=>{if(u==="success"){const f=setTimeout(n,2e3);return()=>clearTimeout(f)}},[u,n]),h.useEffect(()=>{if(!t)return;const f=v=>{v.key==="Escape"&&n()};return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[t,n]);const k=async()=>{if(!(!s||!a.trim())){x("submitting"),g("");try{await r({type:s,content:a.trim(),...c.trim()?{contact:c.trim()}:{}}),x("success")}catch(f){x("error"),g(f instanceof Error?f.message:"提交失败,请稍后重试")}}};if(!t)return null;const y=s&&a.trim()&&u!=="submitting",j=jo.find(f=>f.value===s);return e.jsx("div",{style:Nm,onClick:f=>{f.target===f.currentTarget&&n()},children:e.jsxs("div",{style:Im,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{style:Em,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Rm,"aria-label":"关闭",children:"✕"})]}),u==="success"?e.jsxs("div",{style:Wm,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),o&&e.jsx("a",{href:o,style:{fontSize:"13px",color:i("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:jo.map(f=>e.jsxs("button",{onClick:()=>l(f.value),style:{...Lm,...s===f.value?Am:{}},children:[e.jsx("span",{children:f.icon})," ",f.label]},f.value))}),e.jsx("textarea",{ref:b,value:a,onChange:f=>p(f.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...Bm,opacity:s?1:.6}}),e.jsx("input",{type:"text",value:c,onChange:f=>d(f.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:Om}),e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[a.length," / 2000"]}),u==="error"&&e.jsx("div",{style:Fm,children:m}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:k,disabled:!y,style:{...Mm,opacity:y?1:.6,cursor:y?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},Nm={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Im={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:i("shadow-dialog")},Em={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Rm={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:i("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Lm={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Am={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Bm={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Mm={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},Wm={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:i("success")},Fm={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Om={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},wi="--bim-feedback-fab-offset",Si=48,Pm=16,Dm=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:r,hidden:o=!1,zIndex:s})=>{const[l,a]=h.useState(!1),p=n.bottom??24;return h.useEffect(()=>{if(o||typeof document>"u")return;const c=document.documentElement;return c.style.setProperty(wi,`calc(${p+Si+Pm}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(wi)}},[o,p]),e.jsxs(e.Fragment,{children:[!o&&e.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>a(!0),style:{...Hm,zIndex:s??i("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),e.jsx(El,{isOpen:l,onClose:()=>a(!1),onSubmit:t,feedbackListUrl:r})]})},Hm={position:"fixed",width:`${Si}px`,height:`${Si}px`,borderRadius:"50%",border:"none",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:i("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},vo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Rl=({onSubmit:t})=>{const[n,r]=h.useState("bug"),[o,s]=h.useState(""),[l,a]=h.useState(""),[p,c]=h.useState("idle"),[d,u]=h.useState(""),x=h.useRef(null);h.useEffect(()=>{n&&setTimeout(()=>{var k;return(k=x.current)==null?void 0:k.focus()},100)},[n]);const m=async()=>{if(!(!n||!o.trim())){c("submitting"),u("");try{await t({type:n,content:o.trim(),...l.trim()?{contact:l.trim()}:{}}),c("success"),s(""),a(""),r("bug")}catch(k){c("error"),u(k instanceof Error?k.message:"提交失败,请稍后重试")}}},g=n&&o.trim()&&p!=="submitting",b=vo.find(k=>k.value===n);return p==="success"?e.jsx("div",{style:ko,children:e.jsxs("div",{style:Km,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>c("idle"),style:qm,children:"继续提交"})]})}):e.jsxs("div",{style:ko,children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:vo.map(k=>e.jsxs("button",{onClick:()=>r(k.value),style:{...Gm,...n===k.value?Um:{}},children:[e.jsx("span",{children:k.icon})," ",k.label]},k.value))}),e.jsx("textarea",{ref:x,value:o,onChange:k=>s(k.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...Vm}}),e.jsx("input",{type:"text",value:l,onChange:k=>a(k.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:Zm}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[o.length," / 2000"]}),e.jsx("button",{onClick:m,disabled:!g,style:{...Ym,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&e.jsx("div",{style:Jm,children:d})]})},ko={padding:"16px",border:`1px solid ${i("widget-border")}`,borderRadius:"8px",background:i("input-bg")},Gm={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Um={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Vm={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Ym={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},Km={display:"flex",alignItems:"center",gap:"12px",color:i("success"),fontSize:"14px"},qm={background:"none",border:"none",color:i("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Jm={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginTop:"8px"},Zm={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function wo(t){return typeof t=="function"?t():t??"/api/feedback"}const Ll=({resourceId:t,apiUrl:n})=>{const[r,o]=h.useState([]),[s,l]=h.useState(!0),a=h.useCallback(async()=>{const c=wo(n);l(!0);try{const u=await(await fetch(`${c}?resourceId=${encodeURIComponent(t)}`)).json();u.success&&o(u.items)}catch{}finally{l(!1)}},[t,n]);h.useEffect(()=>{a()},[a]);const p=async c=>{const d=wo(n),u=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...c,pageUrl:typeof window<"u"?window.location.href:"",resourceId:t})});if(!u.ok){const x=await u.json().catch(()=>null);throw new Error((x==null?void 0:x.error)||"提交失败")}setTimeout(()=>a(),500)};return e.jsxs("div",{children:[e.jsx(ar,{items:r,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(Rl,{onSubmit:p})})]})},So={part_of:"所屬",has_part:"包含",contains_text_of:"收錄",collected_in:"叢編",text_carried_by:"載錄",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"後繼",derived_from:"衍生",has_adaptation:"改編",related:"相關"};function $o(t){return t?So[t]??t:So.related}const Xm={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function Qm(t){return Xm[t]??t}const ex={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function tx(t){return ex[t]??""}function cr({authors:t,onNavigate:n,renderLink:r}){const{convert:o}=F(),s=(t||[]).filter(l=>l&&l.name);return s.length?e.jsx(e.Fragment,{children:s.map((l,a)=>{const p=Yi(l.role);return e.jsxs(h.Fragment,{children:[a>0&&" ",l.dynasty&&e.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",o(l.dynasty),"〕"]}),l.entity_id?e.jsx(De,{id:l.entity_id,label:o(l.name),onNavigate:n,renderLink:r,dense:!0}):o(l.name),p&&e.jsx("span",{style:{marginLeft:4},children:o(p)})]},a)})}):null}function Al(t,n){var p,c;const r=Ui(t,n),o=r.mirrors.map(d=>({key:d.key,label:d.label,description:d.description,rows:d.items.filter(u=>u.group_role!=="mirror"),mirrors:d.items.filter(u=>u.group_role==="mirror")})),s=r.buckets.filter(d=>d.key==="image"||d.key==="textImage").flatMap(d=>d.items);s.length&&o.push({key:"_images",label:o.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=r.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&o.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((c=r.buckets.find(d=>d.key==="text"))==null?void 0:c.items)??[],groups:o}}function Bl(t,n){const r=(t.url?Mt(t.url):void 0)||t.name,o=Ds(t,n);return o?`${r}(${o})`:r}function dr({item:t,siblings:n,listedVolumeCounts:r}){const{convert:o}=F(),[s,l]=h.useState(!1),a=_n(t),p=!!a&&a.expected>0&&!(r!=null&&r.has(a.expected)),c=o(Bl(t,n)),d=Wt(t),u=Ln(t)||t.details;return e.jsxs("tr",{children:[e.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var m,g;const x=(m=t.metadata)!=null&&m.fragment||t.color_mode?e.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((g=t.metadata)==null?void 0:g.fragment)&&e.jsx("span",{className:"bim-d-tag",children:o("殘片")}),t.color_mode&&e.jsx("span",{className:"bim-d-tag",children:o(t.color_mode==="color"?"彩色":"黑白")})]}):null;return d?e.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[c," ",e.jsx("span",{"aria-hidden":"true",children:"↗"}),x]}):e.jsxs("span",{className:"bim-d-zt-name",children:[c,x]})})(),u&&e.jsx("span",{className:"bim-d-meta",children:o(u)}),p&&s&&e.jsx("div",{style:{padding:"0 12px 10px"},children:e.jsx(Ji,{item:t})})]}),e.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&e.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(x=>!x),children:o(s?"收起分冊":`展開 ${a.expected} 冊`)})})]})}function Ml({groups:t,listedVolumeCounts:n}){const{convert:r}=F();return e.jsx(e.Fragment,{children:t.map(o=>e.jsxs("div",{className:"bim-d-rg",children:[o.label&&e.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:r(o.label)}),o.description&&e.jsx("p",{className:"bim-d-rg-d",children:r(o.description)}),o.rows.length>0&&e.jsx("table",{className:"bim-d-zt",children:e.jsx("tbody",{children:o.rows.map((s,l)=>e.jsx(dr,{item:s,siblings:o.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),o.mirrors.length>0&&e.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[o.rows.length>0&&e.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:r("鏡像")}),o.mirrors.map((s,l)=>{const a=Wt(s),p=r(Bl(s,o.mirrors));return a?e.jsxs("a",{href:a,target:"_blank",rel:"noopener noreferrer",title:s.details?r(s.details):void 0,children:[p," ",e.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):e.jsx("span",{style:{marginRight:14},children:p},l)})]})]},o.key))})}const tn=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function $i(t){var r;if(!t)return;const n=t.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(r=tn.find(o=>n.startsWith(o.key[0])))==null?void 0:r.key}const _o=12,nx=60,Wl=({data:t,transport:n,onNavigate:r,renderLink:o,readAction:s,railTop:l,back:a,railLinks:p})=>{var Me,ve,Be;const c=fe(),{convert:d}=F(),u=h.useMemo(()=>[...t.books||[],...t.collections||[]],[t.books,t.collections]),[x,m]=h.useState(new Map),[g,b]=h.useState(!1),[k,y]=h.useState(""),[j,f]=h.useState(!1),v=u.length<=nx,$=v||g||!!k||j,w=h.useMemo(()=>$?u:u.slice(0,_o),[u,$]);h.useEffect(()=>{if(!n||w.length===0)return;const P=w.filter(ie=>!x.has(ie));if(P.length===0)return;let ae=!1;return Promise.all(P.map(ie=>n.getItem(ie).then(_e=>{const ke=_e??{};return[ie,{id:ie,title:ke.title,edition:ke.edition,resources:ke.resources,publication_info:ke.publication_info,current_location:ke.current_location,lineage:ke.lineage,measure_info:ke.measure_info}]}).catch(()=>[ie,{id:ie}]))).then(ie=>{ae||m(_e=>{const ke=new Map(_e);for(const[Y,I]of ie)ke.set(Y,I);return ke})}),()=>{ae=!0}},[n,w,x]);const _=h.useMemo(()=>u.map(P=>x.get(P)??{id:P}),[u,x]),S=u.length>0&&u.every(P=>x.has(P)),z=!!n&&w.some(P=>!x.has(P)),E=v||$,T=h.useMemo(()=>Gs(_,t.version_graph,{era:k,scanOnly:j,sort:E?"year":"default"}),[_,t.version_graph,k,j,E]),N=g?T.rows:T.rows.slice(0,_o),V=T.allRows.filter(P=>P.hasImage).length,W=t.related_works||[],B=W.filter(P=>P.relation==="collected_in"),H=h.useMemo(()=>{const P=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],ae=ie=>{const _e=P.indexOf(ie??"");return _e<0?P.length:_e};return W.filter(ie=>ie.relation!=="collected_in").map((ie,_e)=>({r:ie,i:_e})).sort((ie,_e)=>ae(ie.r.relation)-ae(_e.r.relation)||ie.i-_e.i).map(ie=>ie.r)},[W]),te=h.useMemo(()=>{const P=Ui(t.resources,t.resource_groups);return[...P.mirrors.flatMap(ae=>ae.items.map(ie=>({r:ie,kind:d(ae.label)}))),...P.buckets.flatMap(ae=>ae.items.map(ie=>({r:ie,kind:d(tx(ae.key))})))]},[t.resources,t.resource_groups,d]),se=t.indexed_by||[],J=t.emendated_by||[],D=h.useMemo(()=>{var ge,we,R;const P=[],ae=(we=(ge=t.authors)==null?void 0:ge[0])==null?void 0:we.dynasty;ae&&P.push({label:"成書",value:d(ae)});const ie=ut(t,c.unit.juan);if(ie){const oe=(R=t.juan_count)==null?void 0:R.description;P.push({label:"卷帙",value:e.jsxs(e.Fragment,{children:[d(ie),oe&&oe!==ie?e.jsxs("span",{className:"bim-d-meta",children:["(",d(oe),")"]}):null]})})}t.loss_status&&P.push({label:"存佚",value:d(Qm(t.loss_status))});const _e=T.allRows.filter(oe=>oe.sortYear!=null),ke=_e.length>0?_e.reduce((oe,K)=>oe.sortYear<=K.sortYear?oe:K):null;ke!=null&&ke.era.era?P.push({label:"最早存世",value:d([ke.era.era,ke.era.reign].filter(Boolean).join(" ")),title:ke.era.source==="edition"?d("據版本題名推斷"):void 0}):z&&P.push({label:"最早存世",value:e.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),J.length&&P.push({label:"考證",value:`${J.length} ${d("條")}`});const Y=zo(t.additional_titles);Y.length&&P.push({label:"又名",value:Y.map(d).join("、")});const I=zo(t.attached_texts);I.length&&P.push({label:"附載",value:I.map(d).join("、")});const U=(t.additional_works||[]).map(oe=>d(oe.book_title)+(oe.n_juan!=null?` ${oe.n_juan}${d(c.unit.juan)}`:""));return U.length&&P.push({label:"附錄",value:U.join("、")}),P},[t,d,c,z,T.allRows,J.length]),le=[{value:t._edition_count??u.length,label:"版本"},{value:S?V:0,label:"有影印"},{value:se.length,label:"家著錄"}],A=t.classification,ne=A?[A.l1,A.l2,A.l3,A.l4].filter(Boolean).map(P=>d(P)):[],de=t.subtype?d(c.workSubtype[t.subtype]??t.subtype):"",G=e.jsx(on,{title:d(t.title),byline:e.jsx(cr,{authors:t.authors,onNavigate:r,renderLink:o}),meta:e.jsx(Ue,{items:[...ne,A!=null&&A.source?d(`據《${A.source.split("/")[0]}》`):"",de]}),description:(Me=t.description)!=null&&Me.text?e.jsxs(e.Fragment,{children:[e.jsx(pt,{text:t.description.text,style:{fontSize:15,lineHeight:1.85}}),(ve=t.description.sources)!=null&&ve.length?e.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:t.description.sources.map(P=>d(sp(P))).filter(Boolean).join(" · ")}):null]}):void 0,stats:le,facts:D,readAction:s,foot:e.jsx(sn,{revision:t.revision,revisedAt:t.revised_at,review:t.review,todo:t.todo}),children:(Be=t.appendix)==null?void 0:Be.map((P,ae)=>e.jsxs("details",{style:{marginTop:12},children:[e.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(P.title)}),e.jsx(pt,{text:P.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},ae))}),he=T.eras.length>=2?[{key:"",label:c.catalog.all},...T.eras.map(P=>({key:P,label:`${P} ${T.allRows.filter(ae=>ae.era.era===P).length}`}))]:[],ye=[];u.length&&ye.push({id:"versions",label:"版本",count:u.length}),se.length&&ye.push({id:"catalogs",label:"著錄",count:se.length}),B.length&&ye.push({id:"collected",label:"收入叢編",count:B.length}),H.length&&ye.push({id:"related",label:"相關書目",count:H.length}),te.length&&ye.push({id:"resources",label:"在線資源",count:te.length});const xe=u.length===0&&se.length===0,pe=e.jsxs(e.Fragment,{children:[u.length>0&&e.jsxs(Ve,{id:"versions",title:"版本",meta:e.jsx(Ue,{items:[d(`共 ${u.length} 種`),S&&V?d(`${V} 種有影印`):"",T.rows.length!==T.allRows.length?d(`當前 ${T.rows.length} 種`):""]}),children:[e.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&he.length===0&&u.length>1?"":void 0,children:[he.length>0&&e.jsx(Bn,{items:he,value:k,onChange:P=>{y(P),b(!1)}}),e.jsx("span",{className:"bim-d-spacer"}),e.jsx(Zs,{label:"只看有影印",checked:j,onChange:P=>{f(P),b(!1)}}),e.jsx("span",{className:"bim-d-meta",children:d(E?"按年代排列":"按著錄順序")})]}),e.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[e.jsx("thead",{className:"bim-d-ui",children:e.jsxs("tr",{children:[e.jsx("th",{children:d("版本")}),e.jsx("th",{children:d("年代")}),e.jsx("th",{children:d("館藏")}),e.jsx("th",{children:e.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:d("影印")})})]})}),e.jsx("tbody",{children:N.map(P=>{var ae;return e.jsx(ix,{row:P,measure:(ae=x.get(P.id))==null?void 0:ae.measure_info,loaded:x.has(P.id),onNavigate:r,renderLink:o},`${P.id}:${x.has(P.id)?"r":"p"}`)})})]}),N.length===0&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(k||j?"當前篩選下沒有版本":"暫無版本著錄")}),T.rows.length>N.length&&e.jsx(Ot,{label:`展開其餘 ${T.rows.length-N.length} 種版本`,onClick:()=>b(!0)}),T.hasInferredEra&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:d("部分年代據版本題名推斷,非著錄原文")})]}),se.length>0&&e.jsx(rx,{items:se,transport:n,onNavigate:r,renderLink:o}),xe&&e.jsx(Ve,{title:"版本",children:e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),$e=(P,ae)=>e.jsx(De,{id:P,label:d(ae),onNavigate:r,renderLink:o,dense:!0}),Fe=h.useMemo(()=>{const P=new Map;for(const ae of H){const ie=$o(ae.relation);P.set(ie,(P.get(ie)??0)+1)}return P.size>1?[...P.entries()].sort((ae,ie)=>ie[1]-ae[1]).slice(0,4).map(([ae,ie])=>`${d(ae)} ${ie}`).join(" · "):void 0},[H,d]),Ae=e.jsxs(e.Fragment,{children:[e.jsx(St,{id:"collected",title:"收入叢編",items:B.map(P=>$e(P.id,P.title))}),e.jsx(St,{id:"related",title:"相關書目",meta:d(`${H.length} 部`),sub:Fe,items:H.map(P=>e.jsxs(e.Fragment,{children:[$e(P.id,P.title),e.jsx("span",{className:"bim-d-meta",title:P.note?d(P.note):void 0,children:d($o(P.relation))})]}))}),e.jsx(St,{id:"resources",title:"在線資源",cap:6,items:te.map(({r:P,kind:ae})=>{const ie=d((P.url?Mt(P.url):void 0)||P.name),_e=Wt(P);return e.jsxs(e.Fragment,{children:[_e?e.jsxs("a",{href:_e,target:"_blank",rel:"noopener noreferrer",children:[ie," ",e.jsx("span",{"aria-hidden":"true",children:"↗"})]}):e.jsx("span",{children:ie}),ae&&e.jsx("span",{className:"bim-d-meta bim-d-kind",children:ae})]})})})]});return e.jsx(rn,{railTop:l,back:a,nav:ye,railLinks:p,main:pe,card:G,side:Ae})};function zo(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Co(t,n){return n((t.url?Mt(t.url):void 0)||t.name)}function ix({row:t,measure:n,loaded:r,onNavigate:o,renderLink:s}){const{convert:l}=F(),a=[t.era.era,t.era.reign].filter(Boolean).join(" "),p=t.era.source==="edition",c=t.holders[0],d=c?Co(c,l):t.locationName?l(t.locationName):"",u=t.images[0],x=u?Wt(u):void 0,m=t.images.map(g=>Co(g,l)).join("、");return e.jsxs("tr",{"data-loading":r?void 0:"",children:[e.jsxs("td",{className:"bim-d-zt-main",children:[e.jsx(De,{id:t.id,label:l(t.name),onNavigate:o,renderLink:s,dense:!0}),n?e.jsx("span",{className:"bim-d-meta",children:l(n)}):e.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${a?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:a?l(a):r?e.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),e.jsxs("td",{className:`bim-d-zt-sub${d?"":" bim-d-zt-blank"}`,children:[d||(r?e.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),t.holders.length>1&&e.jsxs("span",{className:"bim-d-meta",children:[" +",t.holders.length-1]})]}),e.jsx("td",{className:t.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:t.hasImage&&(x?e.jsx("a",{className:"bim-d-flag",href:x,target:"_blank",rel:"noopener noreferrer",title:m,children:l("有影印")}):e.jsx("span",{className:"bim-d-flag",title:m,children:l("有影印")}))})]})}function rx({items:t,transport:n,onNavigate:r,renderLink:o}){const s=fe(),{convert:l}=F(),[a,p]=h.useState(0),c=Math.min(a,t.length-1),d=t[c],[u,x]=h.useState(new Map);return h.useEffect(()=>{if(!n)return;const m=[...new Set(t.map(b=>b.source_bid).filter(b=>!!b))];if(m.length===0)return;let g=!1;return Promise.all(m.map(b=>n.getItem(b).then(k=>{var y,j;return[b,((j=(y=k==null?void 0:k.authors)==null?void 0:y[0])==null?void 0:j.dynasty)??""]}).catch(()=>[b,""]))).then(b=>{g||x(new Map(b.filter(([,k])=>k)))}),()=>{g=!0}},[n,t]),e.jsx(Ve,{id:"catalogs",title:"著錄",meta:e.jsx(Ue,{items:[l(`歷代書目 ${t.length} 家`),l("按著錄順序")]}),children:e.jsxs("div",{className:"bim-d-lu",children:[e.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":l("著錄書目"),children:t.map((m,g)=>e.jsx("li",{role:"presentation",children:e.jsxs("button",{type:"button",role:"tab","aria-selected":g===c,"aria-label":l(m.source),onClick:()=>p(g),children:[e.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(m.source_bid??"")?l(u.get(m.source_bid??"")):" "}),e.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),e.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...l(m.source)].slice(0,9).map((b,k)=>e.jsx("span",{children:b},k))})]})},g))}),e.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&e.jsx("div",{className:"bim-d-lu-title",children:l(d.title_info)}),e.jsx(Ue,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?e.jsx(De,{id:d.source_bid,label:l(d.source),onNavigate:r,renderLink:o,dense:!0}):l(d.source),d.section?l(d.section):"",d.author_info?`${l(s.label.authorInfo)} ${l(d.author_info)}`:"",d.edition?`${l(s.label.edition)} ${l(d.edition)}`:"",d.page??""]}),d.summary&&e.jsx("p",{className:"bim-d-quote",children:Ze(l(d.summary))}),d.comment&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.comment)}),e.jsx("p",{className:"bim-d-quote",children:Ze(l(d.comment))})]}),d.additional_comment&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.additionalComment)}),e.jsx("p",{className:"bim-d-quote",children:Ze(l(d.additional_comment))})]}),!d.summary&&!d.comment&&!d.additional_comment&&!d.title_info&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:l("僅著錄書名,無提要。")}),t.length>1&&e.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?e.jsx("button",{type:"button","aria-label":l(`上一家:${t[c-1].source}`),onClick:()=>p(c-1),children:e.jsxs("span",{"aria-hidden":"true",children:["← ",l(t[c-1].source)]})}):e.jsx("span",{"aria-hidden":"true"}),e.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",t.length]}),c<t.length-1?e.jsx("button",{type:"button","aria-label":l(`下一家:${t[c+1].source}`),onClick:()=>p(c+1),children:e.jsxs("span",{"aria-hidden":"true",children:[l(t[c+1].source)," →"]})}):e.jsx("span",{"aria-hidden":"true"})]})]})]})})}function ox(t){var n;return{id:t.id,kind:"hypothetical",label:t.label,year:t.year??((n=t.year_range)==null?void 0:n[0]),year_range:t.year_range,year_uncertain:t.year_uncertain,group:t.group,note:t.note,description:t.description}}function sx(t,n){if(!t.lineage)return null;const r=t.lineage;return{id:t.id,kind:"book",label:t.title,year:r.year,year_text:r.year_text,year_uncertain:r.year_uncertain,category:r.category,status:r.status,extant_juan:r.extant_juan,group:n[t.id],note:r.note}}function To(t,n,r){return{id:`derive:${n.ref}->${t}:${r}`,source:n.ref,target:t,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function lx(t,n,r){const[o,s]=[t,n.book_id].sort();return{id:`sibling:${o}-${s}:${r}`,source:o,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function ax(t,n){var d;if(n==="all")return null;const r=(d=t.collections)==null?void 0:d[n],o=Array.isArray(r==null?void 0:r.groups)&&r.groups.length>0,s=Array.isArray(r==null?void 0:r.book_ids)&&r.book_ids.length>0,l=o||s||!!(r!=null&&r.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(t.core_books)&&t.core_books.length>0)return{books:new Set(t.core_books),hypos:t.core_hypotheticals?new Set(t.core_hypotheticals):null};if(!r||!l)return null;const a=o?new Set(r.groups):null,p=new Set(r.book_ids??[]);if(a&&t.node_groups)for(const[u,x]of Object.entries(t.node_groups))a.has(x)&&p.add(u);let c=null;if(r.hypothetical_ids&&(c=new Set(r.hypothetical_ids)),a){c||(c=new Set);for(const u of t.hypothetical_nodes??[])u.group&&a.has(u.group)&&c.add(u.id)}return{books:p,hypos:c}}function bn(t,n,r){const o=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!o||!o.enabled)return s;const l=new Set(o.excluded_books??[]),a=o.node_groups??{},p=ax(o,r??o.default_collection??"all"),c=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,x=new Set,m=new Set;if(c){const $=new Map(n.map(T=>[T.id,T])),w=new Map((o.hypothetical_nodes??[]).map(T=>[T.id,T])),_=T=>{const N=$.get(T);if(N&&N.lineage)return(N.lineage.derived_from??[]).map(W=>W.ref);const V=w.get(T);return V?(V.derived_from??[]).map(W=>W.ref):[]},S=T=>w.has(T)?!u||u.has(T):!d||d.has(T),z=new Set,E=T=>{if(!z.has(T)){z.add(T);for(const N of _(T))l.has(N)||(S(N)||(w.has(N)?m.add(N):$.has(N)&&x.add(N)),E(N))}};for(const T of n)d&&d.has(T.id)&&!l.has(T.id)&&E(T.id);for(const T of o.hypothetical_nodes??[])u&&u.has(T.id)&&E(T.id)}const g=n.filter($=>!l.has($.id)).filter($=>!d||d.has($.id)||x.has($.id)).map($=>{const w=sx($,a);return w&&x.has($.id)&&(w.bridge=!0),w}).filter($=>$!==null),b=(o.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||m.has($.id)).map($=>{const w=ox($);return m.has($.id)&&(w.bridge=!0),w}),k=[...g,...b],y=new Set(k.map($=>$.id)),j=new Set,f=[],v=$=>{j.has($.id)||!y.has($.source)||!y.has($.target)||(j.add($.id),f.push($))};for(const $ of n)l.has($.id)||!$.lineage||d&&!d.has($.id)&&!x.has($.id)||(($.lineage.derived_from??[]).forEach((w,_)=>{v(To($.id,w,_))}),($.lineage.related_to??[]).forEach((w,_)=>{v(lx($.id,w,_))}));for(const $ of o.hypothetical_nodes??[])u&&!u.has($.id)&&!m.has($.id)||($.derived_from??[]).forEach((w,_)=>{v(To($.id,w,_))});return{nodes:k,edges:f,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(l)}}function Fl(t,n,r){const o=(t??(n!=null?String(n):"")).trim();return o?!r||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(o)?o:`约 ${o}`:""}function cx(t,n){const r=[],o=t.version_graph;if(!o)return r;const s=new Set(n.map(c=>c.id)),l=new Set((o.hypothetical_nodes??[]).map(c=>c.id)),a=new Set([...s,...l]),p=(c,d)=>{a.has(d.ref)||r.push(`${c}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&r.push(`${c}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&r.push(`${c}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const d=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>p(d,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||r.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of o.hypothetical_nodes??[]){const d=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>p(d,u))}return r}const Ol=({graph:t,renderLink:n,className:r,style:o})=>{const{convert:s}=F();if(!t.nodes.length)return e.jsx("div",{style:{...wx,...o},className:r,children:"暂无版本图数据"});const l=new Map,a=new Map;for(const m of t.edges)if(m.kind==="derive"){const g=l.get(m.target)??[];g.push(m),l.set(m.target,g)}else for(const g of[m.source,m.target]){const b=a.get(g)??[];b.push(m),a.set(g,b)}const p=new Map(t.nodes.map(m=>[m.id,m])),c=new Map,d=[];for(const m of t.nodes)if(m.group){const g=c.get(m.group)??[];g.push(m),c.set(m.group,g)}else d.push(m);const u=(m,g)=>(m.year??9999)-(g.year??9999);c.forEach(m=>m.sort(u)),d.sort(u);const x=t.groups.filter(m=>c.has(m.id));return e.jsxs("div",{className:r,style:{...px,...o},children:[t.title&&e.jsx("div",{style:ux,children:s(t.title)}),t.description&&e.jsx("div",{style:mx,children:s(t.description)}),x.map(m=>e.jsx(No,{label:m.label,color:m.color,nodes:c.get(m.id),incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n},m.id)),d.length>0&&e.jsx(No,{label:"其他",nodes:d,incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n})]})},No=({label:t,color:n,nodes:r,incomingMap:o,siblingMap:s,nodeMap:l,renderLink:a})=>{const{convert:p}=F();return e.jsxs("div",{style:xx,children:[e.jsx("div",{style:{...hx,borderLeftColor:n??i("widget-border")},children:p(t)}),r.map(c=>e.jsx(dx,{node:c,incoming:o.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:a},c.id))]})},dx=({node:t,incoming:n,siblings:r,nodeMap:o,renderLink:s})=>{const l=t.kind==="hypothetical",a=t.bridge,{convert:p}=F();return e.jsxs("div",{style:{...gx,borderStyle:l||a?"dashed":"solid",opacity:a?.55:t.status==="lost"?.7:1,background:a?i("bg-subtle"):void 0},title:a?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:fx,children:[e.jsx("span",{style:bx,children:l||!s?p(t.label):s(t.id,p(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:yx,children:Fl(p(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:jx,children:[t.category&&e.jsx(qt,{children:p(t.category)}),t.status==="lost"&&e.jsx(qt,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(qt,{tone:"warn",children:"残本"}),l&&e.jsx(qt,{tone:"info",children:"假想祖本"}),a&&e.jsx(qt,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:vx,children:["现存:",p(t.extant_juan)]}),t.note&&e.jsx("div",{style:kx,children:p(t.note)}),n.length>0&&e.jsxs("div",{style:Eo,children:[e.jsx("div",{style:Ro,children:"来源:"}),n.map(c=>{const d=o.get(c.source);return e.jsxs("div",{style:Lo(c.confidence),children:[e.jsx("span",{style:Ao,children:p(c.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,p(d.label)):p((d==null?void 0:d.label)??c.source)}),c.confidence!=="consensus"&&c.confidence!=="certain"&&e.jsx(Io,{level:c.confidence}),c.evidence&&e.jsxs("span",{style:Bo,children:["· ",p(c.evidence)]})]},c.id)})]}),r.length>0&&e.jsxs("div",{style:Eo,children:[e.jsx("div",{style:Ro,children:"关联:"}),r.map(c=>{const d=c.source===t.id?c.target:c.source,u=o.get(d);return e.jsxs("div",{style:Lo(c.confidence),children:[e.jsx("span",{style:Ao,children:p(c.relation)}),e.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,p(u.label)):p((u==null?void 0:u.label)??d)}),e.jsx(Io,{level:c.confidence}),c.evidence&&e.jsxs("span",{style:Bo,children:["· ",p(c.evidence)]})]},c.id)})]})]})},qt=({children:t,tone:n="default"})=>{const o={default:{bg:i("tag-bg"),fg:i("fg")},warn:{bg:i("warn-bg"),fg:i("warn-fg")},info:{bg:i("info-bg"),fg:i("info-fg")}}[n];return e.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:o.bg,color:o.fg,marginRight:"4px"},children:t})},Io=({level:t})=>{const r={certain:{label:"确定",color:i("confidence-certain")},consensus:{label:"共识",color:i("confidence-consensus")},probable:{label:"推测",color:i("confidence-probable")},disputed:{label:"有争议",color:i("confidence-disputed")}}[t];return r?e.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${r.color}`,color:r.color,borderRadius:"8px",marginLeft:"4px"},children:r.label}):null},px={fontSize:"14px",color:i("fg")},ux={fontSize:"16px",fontWeight:600,marginBottom:"8px"},mx={fontSize:"13px",color:i("muted"),marginBottom:"16px",lineHeight:1.6},xx={marginBottom:"16px"},hx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:i("fg")},gx={border:`1px solid ${i("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:i("bg")},fx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},bx={fontSize:"15px",fontWeight:600},yx={fontSize:"12px",color:i("muted")},jx={marginBottom:"6px"},vx={fontSize:"12px",color:i("muted"),margin:"2px 0"},kx={fontSize:"12px",color:i("muted"),fontStyle:"italic",margin:"4px 0"},Eo={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${i("widget-border")}`},Ro={fontSize:"11px",color:i("muted"),marginBottom:"2px"},Lo=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Ao={display:"inline-block",padding:"0 6px",fontSize:"11px",background:i("tag-bg"),color:i("fg"),borderRadius:"3px",marginRight:"6px"},Bo={fontSize:"11px",color:i("muted")},wx={padding:"20px",textAlign:"center",color:i("muted"),fontSize:"13px"},Pl=({selectedNodeId:t,...n})=>{const[r,o]=h.useState("loading"),[s,l]=h.useState(null);return h.useEffect(()=>{let a=!1;return Sx().then(p=>{a||(p?(l(p),o("ready")):o("missing"))}),()=>{a=!0}},[]),r==="loading"?e.jsx("div",{style:Mo,children:"加载图组件中…"}):r==="missing"||!s?e.jsxs("div",{style:Mo,children:[e.jsxs("div",{children:["图组件未安装。请安装 ",e.jsx("code",{children:"@xyflow/react"})," 与 ",e.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),e.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",e.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):e.jsx($x,{modules:s,selectedNodeId:t,...n})};async function Sx(){try{const[t,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let r=!1;try{await import("@xyflow/react/dist/style.css"),r=!0}catch{r=!1}return{ReactFlow:t.ReactFlow,Background:t.Background,Controls:t.Controls,Handle:t.Handle,Position:t.Position,BaseEdge:t.BaseEdge,EdgeLabelRenderer:t.EdgeLabelRenderer,getSmoothStepPath:t.getSmoothStepPath,dagre:n,cssLoaded:r}}catch{return null}}const $x=({graph:t,renderLink:n,height:r=600,className:o,style:s,selectedNodeId:l,modules:a})=>{const{ReactFlow:p,Background:c,Controls:d,Handle:u,Position:x,BaseEdge:m,EdgeLabelRenderer:g,getSmoothStepPath:b,dagre:k}=a,y=h.useMemo(()=>({lineage:_=>{var te,se,J,D;const S=((te=_.data)==null?void 0:te.stepPosition)??.85,[z,E,T]=b({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:S,borderRadius:5}),N=!!((se=_.data)!=null&&se.isSibling),V=N?E:_.targetX-18,W=N?T:_.targetY-12,B=(J=_.data)==null?void 0:J.labelStyle,H=(D=_.data)==null?void 0:D.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(m,{id:_.id,path:z,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&e.jsx(g,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${V}px,${W}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:i("bg"),border:`0.5px solid ${i("widget-border")}`,...H,...B},children:_.label})})]})}}),[m,g,b]),j=h.useMemo(()=>({version:_=>{const S=_.data,z=S.kind==="hypothetical",E=S.status==="lost",T=S.isSelected,N=S.bridge,V=S.borderColor??i("muted"),W=N||z?"dashed":"solid",B=N?.5:E?.6:1;return e.jsxs("div",{style:{background:i(N?"bg-subtle":"bg"),border:`2px ${W} ${T?i("primary"):V}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:B,boxShadow:T?i("shadow-node-selected"):z||N?"none":i("shadow-node")},title:N?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(u,{type:"target",position:x.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&e.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&e.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.2},children:Fl(S.yearText,void 0,S.uncertain)}),E&&e.jsx("div",{style:{fontSize:9,color:i("lost-fg"),marginTop:1},children:"已佚"}),e.jsx(u,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[u,x]),{convert:f}=F(),{rfNodes:v,rfEdges:$}=h.useMemo(()=>_x(t,k,n,l,f),[t,k,n,l,f]);return e.jsx("div",{style:{width:"100%",height:r,...s},className:o,children:e.jsxs(p,{nodes:v,edges:$,nodeTypes:j,edgeTypes:y,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(c,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function _x(t,n,r,o,s=l=>l??""){const p=t.layout==="LR"||!t.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:p?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(j=>[j.id,j.color??i("muted")]));for(const j of t.nodes)c.setNode(j.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of t.edges)j.kind==="derive"&&(u.has(j.relation)||c.setEdge(j.source,j.target));n.layout(c);const x=t.nodes.map(j=>{const f=c.node(j.id),v=o?j.id===o:void 0,$={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??Cx(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:r,isSelected:v,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:f.x-160/2,y:f.y-90/2},data:$,draggable:!1,selected:v}}),m=.78,g=.06,b=new Map;for(const j of t.edges)j.kind==="derive"&&(b.has(j.source)||b.set(j.source,[]),b.get(j.source).push(j));const k=new Map;for(const[j,f]of b){if(f.length<=1)continue;const v=[...f].sort((w,_)=>{var E,T;const S=((E=c.node(w.target))==null?void 0:E.y)??0,z=((T=c.node(_.target))==null?void 0:T.y)??0;return S-z}),$=v.length;v.forEach((w,_)=>{const S=(_-($-1)/2)*g;k.set(w.id,m+S)})}const y=t.edges.map(j=>zx(j,k.get(j.id),s));return{rfNodes:x,rfEdges:y}}function zx(t,n,r=o=>o??""){const o=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",l=Tx(t.confidence),a={type:"arrowclosed",color:l,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:r(t.relation),data:{labelStyle:{color:i("fg")},isSibling:s,stepPosition:n},style:{stroke:l,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":o?"6 4":void 0,opacity:o?.75:1},animated:!1,markerEnd:a,markerStart:s?a:void 0,zIndex:1e3}}function Cx(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function Tx(t){switch(t){case"certain":return i("confidence-certain");case"consensus":return i("lineage-edge-consensus");case"probable":return i("confidence-probable");case"disputed":return i("confidence-disputed");default:return i("muted")}}const Mo={padding:"40px 20px",textAlign:"center",color:i("muted"),fontSize:"13px",border:`1px dashed ${i("widget-border")}`,borderRadius:8,background:i("bg")},pr=({graph:t,defaultMode:n="list",renderLink:r,graphHeight:o=600,selectedNodeId:s,onModeChange:l,collection:a,onCollectionChange:p,collectionsAvailable:c,collectionCounts:d,className:u,style:x})=>{var f;const[m,g]=h.useState(n),b=v=>{g(v),l==null||l(v)},k=(()=>{if(!c)return[];const v=Object.entries(c);return v.length===0||c.all?v:[...v,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),y=!!(p&&k.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:i("muted"),textAlign:"center"},children:"暂无版本传承数据"});const j=a?(f=c==null?void 0:c[a])==null?void 0:f.description:void 0;return e.jsxs("div",{className:u,style:x,children:[e.jsxs("div",{style:Nx,children:[e.jsx("button",{onClick:()=>b("list"),style:ti(m==="list"),children:"列表"}),e.jsx("button",{onClick:()=>b("graph"),style:ti(m==="graph"),children:"关系图"}),y&&e.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:i("muted"),marginRight:4},children:"集合:"}),k.map(([v,$])=>{const w=d==null?void 0:d[v];return e.jsxs("button",{onClick:()=>p==null?void 0:p(v),style:ti(a===v),title:$.description,children:[$.label,w!=null?` ${w}`:""]},v)})]})]}),y&&j&&e.jsx("div",{style:{fontSize:12,color:i("muted"),marginBottom:8,padding:"4px 8px",background:i("bg-subtle"),borderRadius:4},children:j}),m==="list"?e.jsx(Ol,{graph:t,renderLink:r}):e.jsx(Pl,{graph:t,renderLink:r,height:o,selectedNodeId:s})]})},Nx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},ti=t=>({padding:"4px 12px",fontSize:12,border:`1px solid ${i("widget-border")}`,borderRadius:4,background:t?i("primary"):"transparent",color:i(t?"primary-fg":"fg"),cursor:"pointer"}),Wo=40,Fo=2,Ix=9,Oo={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function ni(t){if(!t)return["",""];const n=t.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",t]}const Dl=({data:t,transport:n,onNavigate:r,renderLink:o,readAction:s,fullText:l,fullTextPending:a,chapterLink:p,railTop:c,back:d,railLinks:u})=>{var ge,we,R,oe,K,X,je,Ie,Re,re,ze;const x=fe(),{convert:m}=F(),[g,b]=h.useState(null),[k,y]=h.useState(new Map),[j,f]=h.useState([]),[v,$]=h.useState(new Map),[w,_]=h.useState(!1),[S,z]=h.useState("flow"),[E,T]=h.useState(null);h.useEffect(()=>{if(!n||!t.work_id){b(null);return}let C=!1;return n.getItem(t.work_id).then(q=>{!C&&q&&q.type==="work"&&b(q)}).catch(()=>{}),()=>{C=!0}},[n,t.work_id]),h.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!t.work_id){T(null);return}let C=!1;return n.getLineageGraph(t.work_id).then(q=>{C||T(q&&q.nodes.length>1?q:null)}).catch(()=>{C||T(null)}),()=>{C=!0}},[n,t.work_id]),h.useEffect(()=>{const C=t.contained_in||[];if(!n||C.length===0){y(new Map);return}let q=!1;return Promise.all(C.map(ee=>{const Z=typeof ee=="string"?ee:ee.id;return n.getItem(Z).then(me=>[Z,me]).catch(()=>[Z,null])})).then(ee=>{if(q)return;const Z=new Map;for(const[me,Ce]of ee)Ce&&Z.set(me,Ce);y(Z)}),()=>{q=!0}},[n,t.contained_in]);const N=h.useMemo(()=>{const C=new Set([...(g==null?void 0:g.books)||[],...t.related_books||[]]);return C.add(t.id),[...C]},[g==null?void 0:g.books,t.related_books,t.id]),V=N.length-1;h.useEffect(()=>{if(!n||V<=0){f([]);return}const C=N.length<=Wo,q=C?N:N.slice(0,8);let ee=!1;return Promise.all(q.map(Z=>Z===t.id?Promise.resolve({id:Z,title:t.title,edition:t.edition,year:vn(t)}):n.getItem(Z).then(me=>{const Ce=me??{};return{id:Z,title:Ce.title,edition:Ce.edition,year:me?vn(Ce):void 0}}).catch(()=>({id:Z})))).then(Z=>{if(ee)return;const me=Z.filter(Ce=>Ce.id===t.id||Ce.title||Ce.edition);C&&me.sort((Ce,O)=>(Ce.year??1/0)-(O.year??1/0)),f(me)}),()=>{ee=!0}},[n,N,V,t]);const W=t.lineage,B=h.useMemo(()=>[...((W==null?void 0:W.derived_from)||[]).filter(C=>C.ref_type==="book").map(C=>C.ref),...((W==null?void 0:W.related_to)||[]).map(C=>C.book_id)].filter(Boolean),[W]);h.useEffect(()=>{if(!n||B.length===0){$(new Map);return}let C=!1;return Promise.all(B.map(q=>n.getItem(q).then(ee=>[q,{id:q,title:ee==null?void 0:ee.title,edition:ee==null?void 0:ee.edition}]).catch(()=>[q,{id:q}]))).then(q=>{C||$(new Map(q))}),()=>{C=!0}},[n,B]);const H=h.useMemo(()=>Al(t.resources,t.resource_groups),[t.resources,t.resource_groups]),te=H.groups.reduce((C,q)=>C+q.rows.length+q.mirrors.length,0),se=H.groups.length>0&&H.groups.every(C=>C.key==="_physical"),J=nn(t),D=qs(t),L=ut(t,x.unit.juan),le=new Set((t.contained_in||[]).map(C=>typeof C=="string"?0:Qt(C.volume_index).length).filter(C=>C>0)),A=C=>{var Z;const q=(Z=t.base_edition)==null?void 0:Z.find(me=>me.book_id===C&&me.name);if(q!=null&&q.name)return q.name;const ee=v.get(C);return(ee==null?void 0:ee.edition)||(ee==null?void 0:ee.title)||""},ne=h.useMemo(()=>{var ue,Te,We,Ne,ce;const C=[];D&&C.push({label:"版本類型",value:m(D),title:t.edition_type||(ue=t.lineage)!=null&&ue.category?void 0:m("據版本題名推斷")}),(Te=t.publication_info)!=null&&Te.details?C.push({label:"刊印",value:m(t.publication_info.details)}):(J.era||J.reign)&&C.push({label:"刊寫年代",value:m([J.era,J.reign].filter(Boolean).join(" ")),title:J.source==="edition"?m("據版本題名推斷"):void 0}),L&&C.push({label:"卷帙",value:m(L)});const q=(t.contained_in||[]).flatMap(Se=>typeof Se=="string"?[]:Qt(Se.volume_index));q.length&&C.push({label:"冊次",value:m(`第 ${An(q,x.unit.volume)} ${x.unit.volume}(${q.length} ${x.unit.volume})`)});const ee=(((We=t.lineage)==null?void 0:We.derived_from)||[]).find(Se=>Se.relation==="底本"&&Se.ref_type==="book");ee&&A(ee.ref)&&C.push({label:"底本",value:e.jsx(De,{id:ee.ref,label:m(A(ee.ref)),onNavigate:r,renderLink:o,dense:!0})});const Z=(t.base_edition||[]).filter(Se=>Se&&Se.name);for(const Se of["底本","配補","參校"]){if(Se==="底本"&&ee&&A(ee.ref))continue;const Oe=Z.filter(Ee=>Ee.role===Se);Oe.length&&C.push({label:Se,value:Oe.map((Ee,mt)=>e.jsxs(h.Fragment,{children:[mt>0&&"、",Ee.book_id?e.jsx(De,{id:Ee.book_id,label:m(Ee.name),onNavigate:r,renderLink:o,dense:!0}):m(Ee.name)]},mt))})}const me=(t.provenance||[]).filter(Se=>Se&&Se.institution),Ce=(t.resources||[]).filter(Se=>(Se.types||(Se.type?[Se.type]:[])).includes("physical"));if(me.length){C.push({label:"存藏",value:me.slice(0,2).map(Ee=>m(Ee.institution)).join("、")+(me.length>2?m(` 等 ${me.length} 處`):"")});const Se=me.filter(Ee=>Ee.call_number).slice(0,2).map(Ee=>`${m(Ee.institution)} ${Ee.call_number}`);Se.length&&C.push({label:"索書號",value:Se.join(";")+(me.filter(Ee=>Ee.call_number).length>2?"…":"")});const Oe=me.flatMap(Ee=>Ee.seals||[]).filter(Boolean);Oe.length&&C.push({label:"藏印",value:m(Oe.join("、"))})}else Ce.length?C.push({label:"存藏",value:Ce.slice(0,2).map(Se=>m(Se.name)).join("、")+(Ce.length>2?m(` 等 ${Ce.length} 處`):"")}):(Ne=t.current_location)!=null&&Ne.name&&C.push({label:"存藏",value:m(t.current_location.name)});const O=t.physical_description;if(O){const Se=[["行款",O.leaf_style],["裝幀",O.binding],["尺寸",O.dimensions],["品相",O.condition]];for(const[Oe,Ee]of Se)Ee&&Ee.trim()&&C.push({label:Oe,value:m(Ee)})}(ce=t.page_count)!=null&&ce.description&&C.push({label:x.label.pageCount,value:m(t.page_count.description)});const M=[...ji(t.additional_titles),...ji(t.attached_texts)];return M.length&&C.push({label:"又名",value:M.map(m).join("、")}),C},[t,m,x,J,D,L,v,r,o]),de=m(t.title),G=t.edition?m(t.edition):void 0,he=((ge=t.lineage)==null?void 0:ge.year_text)||"",ye=e.jsx(on,{kind:"版本",title:de,subtitle:G,byline:e.jsx(cr,{authors:t.authors??(g==null?void 0:g.authors),onNavigate:r,renderLink:o}),meta:(()=>{const C=[D?m(D):"",J.era?m([J.era,J.reign].filter(Boolean).join("")):"",L?m(L):""].filter(Boolean);return C.length?e.jsx("span",{className:"bim-d-tags",children:C.map((q,ee)=>e.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ee,2)}`,children:q},ee))}):null})(),description:(we=t.description)!=null&&we.text?e.jsx(pt,{text:t.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Ki((R=t.description)==null?void 0:R.text)?6:void 0,facts:ne,readAction:s,secondaryAction:s&&te>0&&!se?e.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:m("看原書影印")}):void 0,foot:e.jsx(sn,{revision:t.revision,revisedAt:t.revised_at,review:t.review,todo:t.todo})}),xe=t.contained_in||[],pe=(l==null?void 0:l.chapters)||[],$e=pe[0]&&ni(pe[0].title)[0].slice(-1)||"章",Fe=!!((oe=W==null?void 0:W.derived_from)!=null&&oe.length||(K=W==null?void 0:W.related_to)!=null&&K.length||(X=t.appendix)!=null&&X.length),Ae=[];(pe.length||H.text.length||a)&&Ae.push({id:"fulltext",label:"全文",count:pe.length?m(`${pe.length} ${$e}`):void 0}),H.groups.length&&Ae.push({id:"images",label:se?"館藏":"影印",count:te}),Fe&&Ae.push({id:"lineage",label:"版本源流"}),xe.length&&Ae.push({id:"collections",label:"收入叢編",count:xe.length}),(je=t.location_history)!=null&&je.length&&Ae.push({id:"provenance",label:"流轉歷史"});const Me=C=>(p==null?void 0:p(C))??null,ve=pe[0],Be=ve?Me(ve.file):null,P=w?pe:pe.slice(0,Ix),ae=(C,q,ee)=>C?e.jsx("a",{className:ee,href:C.href??"#",onClick:C.onClick?Z=>{Z.metaKey||Z.ctrlKey||(Z.preventDefault(),C.onClick())}:void 0,children:q}):e.jsx("span",{className:ee,children:q}),ie=e.jsxs(e.Fragment,{children:[(pe.length>0||H.text.length>0||a)&&e.jsxs(Ve,{id:"fulltext",title:"全文",meta:pe.length>0?e.jsx(Ue,{items:[m(`${pe.length} ${$e}`),(Ie=l==null?void 0:l.source)!=null&&Ie.name?m(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[a&&!ve&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[e.jsx("span",{className:"bim-d-ft-h",children:" "}),e.jsx("span",{className:"bim-d-meta",children:" "})]}),e.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),ve&&e.jsxs("div",{className:"bim-d-ft",children:[e.jsx("h3",{className:"bim-d-ft-h",children:m(`從${ni(ve.title)[0]||"第一章"}讀起`)}),e.jsx("span",{className:"bim-d-meta",children:m((ve.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),ae(Be,e.jsxs(e.Fragment,{children:[m("進入閱讀頁")," ",e.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),pe.length>1&&e.jsx("ul",{className:"bim-d-chap",children:P.map(C=>{const[q,ee]=ni(C.title);return e.jsx("li",{children:ae(Me(C.file),e.jsxs(e.Fragment,{children:[q&&e.jsx("b",{children:m(q)}),m(ee||C.file)]}))},C.file)})}),pe.length>P.length&&e.jsx(Ot,{label:`展開其餘 ${pe.length-P.length} ${$e}`,onClick:()=>_(!0)}),H.text.length>0&&e.jsxs(e.Fragment,{children:[(pe.length>0||a)&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:m("站外全文")}),e.jsx("table",{className:"bim-d-zt",children:e.jsx("tbody",{children:H.text.map((C,q)=>e.jsx(dr,{item:C,siblings:H.text,listedVolumeCounts:le},`${C.id||C.url||C.name}-${q}`))})})]})]}),H.groups.length>0&&e.jsx(Ve,{id:"images",title:se?"館藏":"影印",meta:e.jsx(Ue,{items:[H.groups.length>1?m(`${H.groups.length} 組`):"",m(`${te} 處`)]}),children:e.jsx(Ml,{groups:H.groups,listedVolumeCounts:le})}),Fe&&e.jsx(Ve,{id:"lineage",title:"版本源流",meta:(Re=W==null?void 0:W.derived_from)!=null&&Re.length?m("據版本傳承著錄"):void 0,action:E?e.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":m("源流視圖"),children:[e.jsx("button",{type:"button","aria-pressed":S==="flow",onClick:()=>z("flow"),children:m("卡片")}),e.jsx("button",{type:"button","aria-pressed":S==="graph",onClick:()=>z("graph"),children:m("關係圖")})]}):void 0,children:S==="graph"&&E?e.jsx(pr,{graph:E,defaultMode:"graph",selectedNodeId:t.id,graphHeight:480,renderLink:(C,q)=>e.jsx(De,{id:C,label:m(q),onNavigate:r,renderLink:o,dense:!0})}):e.jsx(Rx,{data:t,heading:G||de,yearText:he,refName:A,onNavigate:r,renderLink:o})}),xe.length>0&&e.jsx(Ve,{id:"collections",title:"收入叢編",children:e.jsx("table",{className:"bim-d-zt",children:e.jsx("tbody",{children:xe.map((C,q)=>{var O,M;const ee=typeof C=="string"?C:C.id,Z=typeof C=="string"?[]:Qt(C.volume_index),me=k.get(ee),Ce=(me==null?void 0:me._member_count)||((O=me==null?void 0:me.books)==null?void 0:O.length)||((M=me==null?void 0:me.contained_works)==null?void 0:M.length)||0;return e.jsxs("tr",{children:[e.jsxs("td",{className:"bim-d-zt-main",children:[e.jsx(De,{id:ee,label:me?m(me.title):ee,onNavigate:r,renderLink:o,dense:!0}),Z.length>0&&e.jsx(Ex,{volumes:Z,unit:x.unit.volume})]}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Ce?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Ce>0&&m(`全 ${Ce} ${x.unit.bu}`)})]},`${ee}-${q}`)})})})}),(re=t.location_history)!=null&&re.length?e.jsx(Ve,{id:"provenance",title:"流轉歷史",children:e.jsx("ul",{className:"bim-d-tl",children:t.location_history.map((C,q)=>e.jsxs("li",{children:[e.jsx("span",{className:"bim-d-tl-t",children:m(C.name)}),([C.start_date,C.end_date].filter(Boolean).join("—")||C.description)&&e.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:e.jsx(Ue,{items:[[C.start_date,C.end_date].filter(Boolean).join("—"),C.description?m(C.description):""]})})]},q))})}):null,Ae.length===0&&e.jsx(Ve,{title:"影印與全文",children:e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:m("尚未著錄該版本的影印、全文與收藏信息。")})})]}),_e=j.findIndex(C=>C.id===t.id),ke=N.length<=Wo,Y=ke&&_e>=0?j.slice(Math.max(0,_e-Fo),_e+Fo+1):j.filter(C=>C.id!==t.id),I=e.jsxs(e.Fragment,{children:[g&&e.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[e.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:m(x.section.belongsToWork)}),e.jsx("div",{style:{fontSize:17,fontWeight:500},children:e.jsx(De,{id:g.id,label:m(g.title),onNavigate:r,renderLink:o})}),e.jsx(Ue,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(g.authors||[]).slice(0,2).map(C=>`${C.dynasty?`〔${m(C.dynasty)}〕`:""}${m(C.name)}`),m(ut(g,x.unit.juan)),g._edition_count?m(`${g._edition_count} 種版本`):""]}),((ze=g.description)==null?void 0:ze.text)&&e.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:m(g.description.text.replace(/[#*_>`[\]]/g,""))})]}),V>0&&Y.length>0&&e.jsxs("div",{children:[e.jsx(St,{id:"siblings",timeline:!0,title:ke?"同作品版本":x.relation.siblingVersions,meta:m(ke?"按年代":`${V} 種`),cap:Y.length,items:Y.map(C=>C.id===t.id?e.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:m(C.edition||C.title||C.id)}):e.jsx(De,{id:C.id,label:m(C.edition||C.title||C.id),onNavigate:r,renderLink:o,dense:!0})),metas:Y.map(C=>[C.year!=null?C.year<0?`前${-C.year}`:String(C.year):"",C.id===t.id?m("本頁"):""].filter(Boolean).join(" ")),currentIndex:Y.findIndex(C=>C.id===t.id)}),g&&e.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:e.jsx(De,{id:g.id,label:m(`在作品頁看全部 ${N.length} 種 →`),onNavigate:r,renderLink:o,dense:!0})})]})]}),U=t.work_id?e.jsx(Js,{caption:x.section.belongsToWork,children:e.jsx(De,{id:t.work_id,label:g?m(g.title):" ",onNavigate:r,renderLink:o,dense:!0})}):void 0;return e.jsx(rn,{railTop:c,back:d,up:U,nav:Ae,railLinks:u,main:ie,card:ye,side:I})};function Ex({volumes:t,unit:n}){const{convert:r}=F();return e.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[r(`第 ${An(t,n)} ${n}`),t.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bim-d-dot"}),r(`${t.length} ${n}`)]})]})}function Rx({data:t,heading:n,yearText:r,refName:o,onNavigate:s,renderLink:l}){var y;const{convert:a}=F(),p=t.lineage,c=(p==null?void 0:p.derived_from)||[],d=c.filter(j=>j.ref_type!=="book"),u=c.filter(j=>j.ref_type==="book"&&j.relation==="底本"),x=c.filter(j=>j.ref_type==="book"&&j.relation!=="底本"),m=(p==null?void 0:p.related_to)||[],g=c.length>0||m.length>0,b=j=>j&&Oo[j]?a(`(${Oo[j]})`):"",k=(j,f)=>e.jsx(De,{id:j,label:a(f||j),onNavigate:s,renderLink:l,dense:!0});return e.jsxs("div",{className:"bim-d-lf",children:[g&&e.jsxs("ol",{className:"bim-d-lf-list",children:[d.map((j,f)=>e.jsx("li",{className:"bim-d-lf-node",children:e.jsxs("div",{className:"bim-d-lf-dash",children:[e.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(j.relation||"祖本")}),e.jsx("span",{className:"bim-d-lf-name",children:a("擬構祖本")}),j.evidence&&e.jsxs("span",{className:"bim-d-meta",children:[a(j.evidence),b(j.confidence)]})]})},`a-${f}`)),u.map((j,f)=>e.jsx("li",{className:"bim-d-lf-node",children:e.jsxs("div",{className:"bim-d-lf-card",children:[e.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(j.relation)}),e.jsx("span",{className:"bim-d-lf-name",children:k(j.ref,o(j.ref))}),j.evidence&&e.jsxs("p",{className:"bim-d-lf-ev",children:[a(j.evidence),b(j.confidence)]})]})},`b-${f}`)),e.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[e.jsxs("div",{className:"bim-d-lf-here",children:[e.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a("本版")}),e.jsx("span",{className:"bim-d-lf-name",children:n}),r&&e.jsx("span",{className:"bim-d-lf-yr",children:a(r)})]}),x.length>0&&e.jsx("div",{className:"bim-d-lf-side",children:x.map((j,f)=>e.jsxs("div",{className:"bim-d-lf-dash",children:[e.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(j.relation)}),e.jsx("span",{className:"bim-d-lf-name",children:k(j.ref,o(j.ref))}),j.evidence&&e.jsxs("p",{className:"bim-d-lf-ev",children:[a(j.evidence),b(j.confidence)]})]},f))})]}),m.length>0&&e.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[e.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:a("翻刻 · 衍生")}),e.jsx("span",{className:"bim-d-lf-chips",children:m.map((j,f)=>e.jsxs("span",{className:"bim-d-lf-chip",title:j.evidence?a(j.evidence):void 0,children:[k(j.book_id,o(j.book_id)),e.jsx("span",{className:"bim-d-meta",children:a(j.relation)})]},f))})]})]}),(y=t.appendix)==null?void 0:y.map((j,f)=>e.jsxs("details",{className:"bim-d-lf-app",children:[e.jsxs("summary",{className:"bim-d-ui",children:[e.jsx("span",{className:"bim-d-meta",children:a("附記")})," ",a(j.title)]}),e.jsx(pt,{text:j.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${f}`)),(p==null?void 0:p.note)&&e.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:a(p.note)})]})}const Jt=16,Lx=200,Ax=16,Hl=({data:t,catalog:n,transport:r,onNavigate:o,renderLink:s,catalogAction:l,railTop:a,back:p,railLinks:c})=>{var _e,ke,Y,I,U,ge,we;const d=fe(),{convert:u}=F(),[x,m]=h.useState(""),[g,b]=h.useState(!1),[k,y]=h.useState(null),[j,f]=h.useState(""),[v,$]=h.useState(!1),w=h.useMemo(()=>Ys(t,n),[t,n]),[_,S]=h.useState(new Map),z=!!r&&w.rows.length>0&&w.rows.length<=Lx,E=z&&(w.rows.length<=Jt||v),T=E&&w.rows.every(R=>!R.id||_.has(R.id)),N=R=>{var oe;return $i(R?(oe=_.get(R))==null?void 0:oe.l1:void 0)},V=h.useMemo(()=>{const R=x.trim(),oe=R?u(R):"";return w.rows.filter(K=>{var je,Ie;if(j&&$i(K.id?(je=_.get(K.id))==null?void 0:je.l1:void 0)!==j)return!1;if(!oe)return!0;const X=K.id&&((Ie=_.get(K.id))==null?void 0:Ie.title)||K.title;return u(X).includes(oe)||(K.subItems||[]).some(Re=>u(Re).includes(oe))})},[w.rows,x,j,_,u]),W=g?V:V.slice(0,Jt),B=h.useMemo(()=>(E?w.rows:W).filter(R=>R.id&&!_.has(R.id)).map(R=>R.id),[E,w.rows,W,_]);h.useEffect(()=>{if(!r||B.length===0)return;let R=!1;const oe=B.slice(0,Ax);return Promise.all(oe.map(K=>r.getItem(K).then(X=>{var Re,re;const je=X??{},Ie={title:je.title,edition:je.edition,authors:je.authors,measure:X?ut(X,d.unit.juan):void 0,versionCount:je._edition_count??((Re=je.books)==null?void 0:Re.length),l1:((re=je.classification)==null?void 0:re.l1)||void 0};return[K,Ie]}).catch(()=>[K,{}]))).then(K=>{R||S(X=>{const je=new Map(X);for(const[Ie,Re]of K)je.set(Ie,Re);return je})}),()=>{R=!0}},[r,B,d.unit.juan]);const H=(t.contained_in||[])[0];h.useEffect(()=>{if(!H){y(null);return}if(y({id:H}),!r)return;let R=!1;return r.getItem(H).then(oe=>{R||y({id:H,title:oe==null?void 0:oe.title})}).catch(()=>{}),()=>{R=!0}},[r,H]);const te=h.useMemo(()=>Al(t.resources,t.resource_groups),[t.resources,t.resource_groups]),se=te.text.length+te.groups.reduce((R,oe)=>R+oe.rows.length+oe.mirrors.length,0),J=t.contained_works||[],D=new Set(w.rows.map(R=>R.id).filter(Boolean)),L=J.length>0&&!J.every(R=>D.has(R.id)),le=(()=>{const R=w.rows.map(oe=>oe.edition).filter(Boolean);return R.length>1&&new Set(R).size===1})(),A=w.rows.some(R=>R.volumes.length>0||R.expected!=null),ne=t._member_count||((_e=t.books)==null?void 0:_e.length)||J.length,de=ut(t,d.unit.juan),G=t.count,he=R=>typeof R=="number"&&Number.isFinite(R)?R:null,ye=he(G==null?void 0:G.juan)??he((ke=t.juan_count)==null?void 0:ke.number),xe=he(G==null?void 0:G.ce)??(w.totalVolumes||null),pe=[{value:w.rows.length,label:"子目"},{value:ye??0,label:d.unit.juan},{value:xe??0,label:d.unit.volume}],$e=h.useMemo(()=>{var K,X;const R=[];if((K=t.publication_info)!=null&&K.details&&R.push({label:"刊印",value:u(t.publication_info.details)}),ne&&ne!==w.rows.length){const je=t._member_type==="Book"?"所收版本":t._member_type==="Work"?"所收作品":"成員";R.push({label:u(je),value:`${ne} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")})}const oe=[he(G==null?void 0:G.zhong)!=null?`${G.zhong} 種`:"",he(G==null?void 0:G.han)!=null?`${G.han} 函`:""].filter(Boolean);return oe.length&&R.push({label:"應收",value:u(oe.join(" "))}),ye==null&&de&&R.push({label:"卷帙",value:u(de),title:(X=t.juan_count)!=null&&X.description?u(t.juan_count.description):void 0}),R},[t,ne,w.rows.length,ye,de,G,u,d]),Fe=h.useMemo(()=>{if(!T)return[];const R=new Map;for(const K of w.rows){const X=N(K.id);X&&R.set(X,(R.get(X)??0)+1)}const oe=tn.filter(K=>(R.get(K.key)??0)>0);return oe.length<2?[]:[{key:"",label:`${d.catalog.all} ${w.rows.length}`},...oe.map(K=>({key:K.key,label:`${K.label} ${R.get(K.key)}`}))]},[T,w.rows,_,d]),Ae=h.useMemo(()=>{if(!T||!w.rows.some(X=>X.volumes.length>0))return null;const R=[],oe=w.rows.filter(X=>X.volumes.length>0).map(X=>({k:N(X.id)??"",from:Math.min(...X.volumes),to:Math.max(...X.volumes)})).sort((X,je)=>X.from-je.from);for(const X of oe){const je=X.to-X.from+1,Ie=R[R.length-1];Ie&&Ie.key===X.k?(Ie.to=Math.max(Ie.to,X.to),Ie.n+=je):R.push({key:X.k,from:X.from,to:X.to,n:je})}const K=oe.reduce((X,je)=>Math.max(X,je.to),0);return R.length>1&&R.some(X=>X.key)?{segs:R,last:K}:null},[T,w.rows,_]),Me=(Y=t.description)==null?void 0:Y.text,ve=e.jsx(on,{kind:"叢編",title:u(t.title),byline:e.jsx(cr,{authors:t.authors,onNavigate:o,renderLink:s}),meta:e.jsx(Ue,{items:[t.subtype==="work_collection"?u("作品集"):"",(I=t.publication_info)!=null&&I.year?u(t.publication_info.year):""]}),description:Me||(U=t.history)!=null&&U.length?e.jsxs(e.Fragment,{children:[Me&&e.jsx(pt,{text:Me,style:{fontSize:15,lineHeight:1.85}}),(ge=t.history)!=null&&ge.length?e.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:t.history.map((R,oe)=>e.jsx("li",{children:u(R)},oe))}):null]}):void 0,clampDescription:Ki(Me)||(((we=t.history)==null?void 0:we.length)??0)>2?6:void 0,stats:pe,facts:$e,foot:e.jsx(sn,{revision:t.revision,revisedAt:t.revised_at,review:t.review,todo:t.todo}),children:Ae&&e.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[e.jsx("div",{className:"bim-d-dist-head",children:e.jsx("span",{children:u("全帙冊次分佈")})}),e.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":u("全帙冊次分佈"),children:Ae.segs.map((R,oe)=>{const K=tn.find(X=>X.key===R.key);return e.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!K,title:K?u(`${K.label} 第 ${R.from}–${R.to} 冊`):void 0,"aria-label":u(K?`只看${K.label}`:"未分類"),"aria-pressed":!!K&&j===R.key,style:{flexGrow:R.n,background:i(K?K.token:"rule")},onClick:()=>{K&&(f(j===R.key?"":R.key),b(!1))}},oe)})}),e.jsxs("div",{className:"bim-d-life-lab",children:[e.jsx("span",{children:u(`第 1 ${d.unit.volume}`)}),e.jsx("span",{children:u("點色段篩選部類")}),e.jsx("span",{children:u(`第 ${Ae.last} ${d.unit.volume}`)})]})]})}),Be=[];w.rows.length&&Be.push({id:"titles",label:"子目",count:w.rows.length}),se&&Be.push({id:"resources",label:"影印與全文",count:se}),L&&Be.push({id:"works",label:d.section.containedWorks,count:J.length});const P=e.jsxs(e.Fragment,{children:[w.rows.length>0&&e.jsxs(Ve,{id:"titles",title:"子目",meta:e.jsx(Ue,{items:[u(`${w.rows.length} ${d.unit.items}`),w.totalVolumes?u(`全帙 ${w.totalVolumes} ${d.unit.volume}`):"",V.length!==w.rows.length?u(`當前 ${V.length} ${d.unit.items}`):""]}),action:l,children:[(w.rows.length>Jt||Fe.length>0)&&e.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[Fe.length>0&&e.jsx(Bn,{items:Fe,value:j,onChange:R=>{f(R),b(!1)}}),z&&w.rows.length>Jt&&!T&&e.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:v,onClick:()=>$(!0),title:u(`將載入全部 ${w.rows.length} ${d.unit.items}`),children:u(v?"正在按部類分組…":"按部類分組")}),e.jsx("span",{className:"bim-d-spacer"}),w.rows.length>Jt&&e.jsx("input",{type:"search",className:"bim-d-find",value:x,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:R=>{m(R.target.value),b(!1)}})]}),e.jsxs("table",{className:"bim-d-zt",children:[e.jsx("thead",{className:"bim-d-ui",children:e.jsxs("tr",{children:[A&&e.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),e.jsx("th",{children:u("書名")}),e.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),e.jsx("tbody",{children:W.map((R,oe)=>{var ze;const K=R.id?_.get(R.id):void 0,X=K!=null&&K.title&&R.title===R.id?K.title:R.title,je=((K==null?void 0:K.authors)||[]).find(C=>C&&C.name),Ie=[je?`${je.dynasty?`〔${u(je.dynasty)}〕`:""}${u(je.name)}${je.role?` ${u(je.role)}`:""}`:"",K!=null&&K.measure?u(K.measure):"",(ze=R.subItems)!=null&&ze.length?R.subItems.map(C=>u(C)).join("、"):"",(K!=null&&K.edition||R.edition)&&!le?u((K==null?void 0:K.edition)||R.edition||""):""].filter(Boolean),Re=tn.find(C=>C.key===N(R.id)),re=R.volumes.length>0?u(`第 ${An(R.volumes,d.unit.volume)} ${d.unit.volume}`):R.expected!=null?u(`${R.found??0}/${R.expected} ${d.unit.volume}`):"";return e.jsxs("tr",{children:[A&&e.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${re?"":" bim-d-zt-blank"}`,children:[Re&&e.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:i(Re.token)}}),re||e.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),e.jsxs("td",{className:"bim-d-zt-main",children:[R.id?e.jsx(De,{id:R.id,label:u(X),onNavigate:o,renderLink:s,dense:!0}):e.jsx("span",{className:"bim-d-zt-name",children:u(X)}),Ie.length>0?e.jsx(Ue,{items:Ie}):R.id&&!K&&r?e.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${K!=null&&K.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:K!=null&&K.versionCount?u(`${K.versionCount} 種`):""})]},`${R.id??R.title}-${oe}`)})})]}),W.length===0&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),V.length>W.length&&e.jsx(Ot,{label:`展開其餘 ${V.length-W.length} ${d.unit.items}`,onClick:()=>b(!0)})]}),se>0&&e.jsxs(Ve,{id:"resources",title:"影印與全文",meta:u(`${se} 處`),children:[te.text.length>0&&e.jsxs("div",{className:"bim-d-rg",children:[te.groups.length>0&&e.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("全文")}),e.jsx("table",{className:"bim-d-zt",children:e.jsx("tbody",{children:te.text.map((R,oe)=>e.jsx(dr,{item:R,siblings:te.text},`${R.id||R.url||R.name}-${oe}`))})})]}),e.jsx(Ml,{groups:te.groups})]}),w.rows.length===0&&se===0&&e.jsx(Ve,{title:"子目",children:e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),ae=L?e.jsx(St,{id:"works",title:d.section.containedWorks,meta:u(`${J.length} 種`),cap:12,items:J.map(R=>e.jsx(De,{id:R.id,label:u(R.title),onNavigate:o,renderLink:s,dense:!0}))}):null,ie=k?e.jsx(Js,{caption:"上級叢編",children:e.jsx(De,{id:k.id,label:u(k.title||k.id),onNavigate:o,renderLink:s,dense:!0})}):void 0;return e.jsx(rn,{railTop:a,back:p,up:ie,nav:Be,railLinks:c,main:P,card:ve,side:ae})},Bx=16,ii=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Po(t){if(!t)return ii.length;const n=ii.indexOf(t);return n===-1?ii.length:n}const Mx={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function ht(t){return t==null?"":t<0?`前${-t}`:String(t)}const Wx={秦:[-221,-207],西漢:[-202,8],西汉:[-202,8],東漢:[25,220],东汉:[25,220],漢:[-202,220],汉:[-202,220],三國:[220,280],三国:[220,280],西晉:[265,316],西晋:[265,316],東晉:[317,420],东晋:[317,420],隋:[581,618],唐:[618,907],五代:[907,960],北宋:[960,1127],南宋:[1127,1279],宋:[960,1279],遼:[916,1125],辽:[916,1125],金:[1115,1234],元:[1271,1368],明:[1368,1644],清:[1636,1912]},Gl=({data:t,transport:n,onNavigate:r,renderLink:o,railTop:s,back:l,railLinks:a})=>{var ae,ie,_e,ke,Y;const p=fe(),{convert:c}=F(),[d,u]=h.useState("全部"),[x,m]=h.useState(!1),[g,b]=h.useState("default"),[k,y]=h.useState(new Map),j=h.useMemo(()=>(t.works||[]).map(I=>{const U=k.get(I.work_id);return{id:I.work_id,title:(U==null?void 0:U.title)??I.title??I.work_id,role:I.role||"",cls:Vi(I.role),versionCount:U==null?void 0:U.versionCount,section:U==null?void 0:U.cls,l1:U==null?void 0:U.l1,measure:U==null?void 0:U.measure,hasImage:U==null?void 0:U.hasImage,loaded:!!(U!=null&&U.loaded)}}),[t.works,k]),f=h.useMemo(()=>Vs((t.works||[]).map(I=>I.role)),[t.works]),v=h.useMemo(()=>{const I=d==="全部"?j:j.filter(U=>U.cls===d);return g==="versions"?[...I].sort((U,ge)=>(ge.versionCount??-1)-(U.versionCount??-1)):I},[j,d,g]),$=x?v:v.slice(0,Bx),w=h.useMemo(()=>$.filter(I=>!k.has(I.id)).map(I=>I.id),[$,k]);h.useEffect(()=>{if(!n||w.length===0)return;let I=!1;return Promise.all(w.map(U=>n.getItem(U).then(ge=>{var K,X,je,Ie,Re;const we=ge??{},R=we._edition_count??(((K=we.books)==null?void 0:K.length)??0)+(((X=we.collections)==null?void 0:X.length)??0),oe=[(je=we.classification)==null?void 0:je.l1,(Ie=we.classification)==null?void 0:Ie.l2].filter(Boolean).join(" ");return[U,{id:U,title:we.title,versionCount:R,loaded:!0,cls:oe||void 0,l1:((Re=we.classification)==null?void 0:Re.l1)||void 0,measure:ge&&ut(ge,p.unit.juan)||void 0,hasImage:!!(we.has_image??we._has_image)}]}).catch(()=>[U,{id:U,loaded:!0}]))).then(U=>{I||y(ge=>{const we=new Map(ge);for(const[R,oe]of U)we.set(R,oe);return we})}),()=>{I=!0}},[n,w,p.unit.juan]);const _=h.useMemo(()=>{const I=new Map;for(const U of t.alt_names||[]){const ge=U.type||p.section.aliases;I.has(ge)||I.set(ge,[]),I.get(ge).push(U.name)}return[...I.entries()].sort((U,ge)=>Po(U[0])-Po(ge[0])).map(([U,ge])=>({label:U,names:ge}))},[t.alt_names,p]),S=t.birth_year??((ae=t.dates)==null?void 0:ae.birth)??void 0,z=t.death_year??((ie=t.dates)==null?void 0:ie.death)??void 0,E=(_e=t.dates)==null?void 0:_e.floruit,T=S!=null||z!=null?`${ht(S)||"?"}—${ht(z)||"?"}`:Array.isArray(E)&&E.length===2&&E.every(I=>Number.isFinite(I))?`活躍於 ${ht(E[0])}—${ht(E[1])}`:"",N=new Set(["本名","字","號","号"]),V=_.filter(I=>N.has(I.label)),W=_.filter(I=>!N.has(I.label)),B=W.reduce((I,U)=>I+U.names.length,0),H=h.useMemo(()=>{const I=[];for(const ge of V)I.push({label:ge.label,value:ge.names.map(we=>c(we)).join("、")});const U=(t.works||[]).length;return U&&I.push({label:"著作",value:`${U} ${c("種")}`}),I},[t.works,V,c]),te=I=>{var U;return(U=_.find(ge=>I.includes(ge.label)))==null?void 0:U.names[0]},se=te(["字"]),J=te(["號","号"]),D=[se?`字${se}`:"",J?`號${J}`:""].filter(Boolean).join(","),L=t.native_place,le=t.dynasty?Wx[t.dynasty]:void 0,A=(()=>{if(!le||S==null||z==null||z<S)return null;const[I,U]=le,ge=Math.max(S,I),we=Math.min(z,U);if(we<=ge)return null;const R=U-I;return e.jsxs("div",{className:"bim-d-life bim-d-ui",children:[e.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":c(`${ht(S)}—${ht(z)},一生 ${z-S+1} 年`),children:e.jsx("i",{style:{left:`${(ge-I)/R*100}%`,width:`${(we-ge)/R*100}%`}})}),e.jsxs("div",{className:"bim-d-life-lab",children:[e.jsx("span",{children:c(`${ht(I)} ${t.dynasty}`)}),e.jsx("span",{children:c(`一生 ${z-S+1} 年`)}),e.jsx("span",{children:ht(U)})]})]})})(),ne=h.useMemo(()=>{if(!n||j.length===0||j.some(ge=>!ge.loaded))return null;const I=new Map;for(const ge of j){const we=$i(ge.l1);we&&I.set(we,(I.get(we)??0)+1)}const U=tn.map(ge=>({...ge,n:I.get(ge.key)??0})).filter(ge=>ge.n>0);return U.length?U:null},[j,n]),de=e.jsxs(on,{kind:Mx[t.subtype]??"人物",title:c(t.primary_name||t.title),subtitle:D?c(D):void 0,meta:e.jsxs(e.Fragment,{children:[e.jsx(Ue,{items:[t.dynasty?c(t.dynasty):"",T?c(T):"",L?c(`${L}人`):""]}),A]}),description:(ke=t.description)!=null&&ke.text?e.jsx(pt,{text:t.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Ki((Y=t.description)==null?void 0:Y.text)?6:void 0,facts:H,foot:e.jsx(sn,{revision:t.revision,revisedAt:t.revised_at,review:t.review,todo:t.todo}),children:[B>0&&e.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[e.jsx("summary",{children:c(`更多別名(${B})`)}),e.jsx("dl",{children:W.map(I=>e.jsxs(h.Fragment,{children:[e.jsx("dt",{children:c(I.label)}),e.jsx("dd",{children:I.names.map(U=>c(U)).join("、")})]},I.label))})]}),ne&&e.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[e.jsx("div",{className:"bim-d-dist-head",children:e.jsx("span",{children:c("著作分佈")})}),e.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:ne.map(I=>e.jsx("i",{style:{flexGrow:I.n,background:i(I.token)}},I.key))}),e.jsx("div",{className:"bim-d-dist-key",children:ne.map(I=>e.jsxs("span",{children:[e.jsx("i",{style:{background:i(I.token)}}),c(I.label)," ",I.n]},I.key))})]})]}),G=h.useMemo(()=>j.filter(I=>I.loaded&&(I.versionCount??0)>0).sort((I,U)=>(U.versionCount??0)-(I.versionCount??0)).slice(0,3),[j]),he=!!n&&j.length>=3&&$.some(I=>!I.loaded),ye=d==="全部"&&(he||G.length>=2),xe=t.external_ids||{},pe=[];xe.cbdb_id!=null&&pe.push({label:"CBDB",id:String(xe.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${xe.cbdb_id}`,note:xe.cbdb_match==="auto"?"自動匹配":void 0});const $e=xe.wikidata_id;$e&&pe.push({label:"Wikidata",id:$e,href:`https://www.wikidata.org/wiki/${$e}`});const Fe=xe.viaf_id;Fe&&pe.push({label:"VIAF",id:Fe,href:`https://viaf.org/viaf/${Fe}`});const Ae=f.map(I=>({key:I.cls,label:`${I.label} ${I.count}`})),Me=[...ye&&!he?[{id:"featured",label:"著作舉要",count:G.length}]:[],...j.length?[{id:"works",label:"全部著作",count:j.length}]:[],...pe.length?[{id:"external",label:"站外資料",count:pe.length}]:[]],ve=ye?e.jsxs(Ve,{id:"featured",title:"著作舉要",children:[e.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:c("存世版本最多的三部")}),e.jsxs("div",{className:"bim-d-picks","aria-busy":he||void 0,children:[he&&[0,1,2].map(I=>e.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[e.jsx("span",{className:"bim-d-pick-t",children:" "}),e.jsx("span",{className:"bim-d-meta",children:" "}),e.jsx("div",{className:"bim-d-pick-n",children:" "})]},I)),!he&&G.map(I=>e.jsxs("div",{className:"bim-d-pick",children:[e.jsx("span",{className:"bim-d-pick-t",children:e.jsx(De,{id:I.id,label:c(I.title),onNavigate:r,renderLink:o,dense:!0})}),e.jsx(Ue,{items:[I.section?c(I.section):"",I.measure?c(I.measure):""]}),e.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[e.jsx("span",{className:"bim-d-pick-num",children:I.versionCount}),e.jsx("span",{children:c("種版本")}),I.hasImage&&e.jsx("span",{className:"bim-d-flag",children:c("有影印")})]})]},I.id))]})]}):null,Be=j.length===0?e.jsx(Ve,{title:"著作",children:e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該人物的關聯作品。")})}):e.jsxs(e.Fragment,{children:[ve,e.jsxs(Ve,{id:"works",title:"著作",meta:e.jsx(Ue,{items:[c(`共 ${j.length} 種`),v.length!==j.length?c(`當前 ${v.length} 種`):""]}),children:[e.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[Ae.length>1&&e.jsx(Bn,{items:Ae,value:d,onChange:I=>{u(I),m(!1)}}),e.jsx("span",{className:"bim-d-spacer"}),e.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":g==="versions",onClick:()=>{g==="default"&&m(!0),b(I=>I==="default"?"versions":"default")},children:c(g==="default"?"按版本數排列":"按著錄順序")})]}),e.jsxs("table",{className:"bim-d-zt",children:[e.jsx("thead",{className:"bim-d-ui",children:e.jsxs("tr",{children:[e.jsx("th",{children:c("作品")}),e.jsx("th",{children:c("部類")}),e.jsx("th",{children:c("職任")}),e.jsx("th",{children:c("存世版本")}),e.jsx("th",{"aria-label":c("影印")})]})}),e.jsx("tbody",{children:$.map(I=>e.jsxs("tr",{children:[e.jsxs("td",{className:"bim-d-zt-main",children:[e.jsx(De,{id:I.id,label:c(I.title),onNavigate:r,renderLink:o,dense:!0}),I.measure?e.jsx(Ue,{items:[c(I.measure)]}):!I.loaded&&n?e.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.section||I.loaded?"":" bim-d-zt-blank"}`,children:I.section?c(I.section):null}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.role?"":" bim-d-zt-blank"}`,children:I.role?c(I.role):e.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.loaded?"":" bim-d-zt-blank"}`,children:I.loaded?I.versionCount?c(`${I.versionCount} 種`):e.jsx("span",{className:"bim-d-zt-empty",children:c("未著錄")}):""}),e.jsx("td",{className:I.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:I.hasImage&&e.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("有影印")})})]},I.id))})]}),$.length===0&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("該職任下的著作尚未著錄。")}),v.length>$.length&&e.jsx(Ot,{label:`展開其餘 ${v.length-$.length} 種著作`,onClick:()=>m(!0)})]})]}),P=pe.length>0?e.jsx(St,{id:"external",title:"站外資料",items:pe.map(I=>e.jsxs("a",{href:I.href,target:"_blank",rel:"noopener noreferrer",children:[I.label," ",e.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:pe.map(I=>I.id),foot:xe.cbdb_id!=null&&xe.cbdb_match==="auto"?c("CBDB 為自動匹配,未經人工核對"):void 0}):null;return e.jsx(rn,{railTop:s,back:l,nav:Me,railLinks:a,main:Be,card:de,side:P})},ur="(max-width: 719px)",Fx=`${ur}, (pointer: coarse)`,Ul=`
1077
+ `)}),s=[]};for(const a of n){const p=tr(a);if(p){l(),o={kind:"heading",level:p.level,text:p.text};continue}s.push(a)}return l(),r}function ro(t){const n=[];for(const r of t.split(`
1078
+ `)){const o=tr(r);if(o){n.push({kind:"heading",level:o.level,text:o.text});continue}const s=r.trim();!s||nr.test(s)||n.push({kind:"body",text:r})}return n}function fl(t){if(!t)return[];const n=Wn(t);if(n==="unknown")return ro(t);const r=[];for(const{heading:o,body:s}of Kp(t)){o&&r.push(o);const l=xl(s);if(l.length!==0){if(gl(s)){r.push(...ro(s));continue}if(n==="record"){const a=l.join(" ");a&&r.push({kind:"body",text:a})}else for(const a of l){const p=hl(a);p.length&&r.push({kind:"body",text:p.join(" ")})}}}return r}const bl=t=>t;function yl(t,n=bl){if(t.indexOf("《")<0)return n(t);const r=[],o=/《([^《》\n]+)》/g;let s=0,l=0,a;for(;a=o.exec(t);)a.index>s&&r.push(e.jsx(h.Fragment,{children:n(t.slice(s,a.index))},l++)),r.push(e.jsxs("span",{className:"bim-rd-pn",children:[e.jsx("span",{className:"bim-rd-sr",children:"《"}),n(a[1]),e.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=a.index+a[0].length;return s===0?n(t):(s<t.length&&r.push(e.jsx(h.Fragment,{children:n(t.slice(s))},l++)),r)}function ir(t,n={}){const r=n.renderText??bl,o=n.properNames?l=>yl(l,r):r,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Ze(t,o,s)}function oo(t,n,r){return t.indexOf("**")<0?n(t):t.split(/(\*\*[^*]+\*\*)/g).map((s,l)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?e.jsx("strong",{children:n(s.slice(2,-2))},`${r}-${l}`):e.jsx(h.Fragment,{children:n(s)},`${r}-${l}`))}const Xn=/^(#{1,6})\s+(.*)$/,qp=/^\s*<!--.*-->\s*$/;function jl(t){return t.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
1079
+ `)?"":n)}function Jp(t){return t<=1?2:t===2?3:4}function Zp(){let t=1;return n=>{const r=Jp(n),o=Math.min(r,t+1);return t=o,{Tag:`h${o}`,className:`bim-rd-hl${r}`}}}function kn(t){return t?Wn(jl(t))!=="unknown":!1}function so({text:t,mode:n,inline:r,dropTitle:o}){const s=jl(t),l=(d,u,x)=>!!o&&x<=1&&d<=2&&u.trim()===o.trim(),a=Zp();if(n==="paragraph"&&Wn(s)!=="unknown"){const d=fl(s);return e.jsx(e.Fragment,{children:d.map((u,x)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,x))return null;const{Tag:m,className:g}=a(u.level??1);return e.jsx(m,{className:g,children:r(u.text)},x)}return e.jsx("p",{children:oo(u.text,r,x)},x)})})}const p=s.split(`
1080
+ `);let c=0;return e.jsx(e.Fragment,{children:p.map((d,u)=>{const x=d.match(Xn);if(x){const g=c++;if(l(x[1].length,x[2],g))return null;const{Tag:b,className:k}=a(x[1].length);return e.jsx(b,{className:k,children:r(x[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Xn.test(p[u-1])&&!Xn.test(p[u-2])?e.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(qp.test(d))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:g,className:b}=a(3);return e.jsx(g,{className:b,children:r(d.trim().slice(2,-2))},u)}return e.jsx("p",{children:oo(d,r,u)},u)})})}function Xp(t){const{convert:n}=O();return h.useMemo(()=>t?n(t):"",[t,n])}function rr({text:t,mode:n,tables:r=!1,gujiMarkdown:o=!1,properNames:s=!1,renderText:l,dropTitle:a}){const p=Xp(t),{convert:c}=O(),d=m=>ir(m,{renderText:l,properNames:s,gujiMarkdown:o}),u=o?{gujiMarkdown:!0}:void 0,x=a?c(a):void 0;return!r||p.indexOf(":::")<0?e.jsx(so,{text:p,mode:n,inline:d,dropTitle:x}):e.jsx(e.Fragment,{children:Pi(p).map((m,g)=>m.type==="table"?e.jsx(er,{table:m.table,opts:u},g):e.jsx(so,{text:m.text,mode:n,inline:d,dropTitle:g===0?x:void 0},g))})}function Qp(t,n){const[r,o]=h.useState(null),[s,l]=h.useState(!1),a=h.useRef(0);return h.useEffect(()=>{const p=++a.current;if(!t||!n){o(null),l(!1);return}let c;try{c=t(n)}catch{o(null),l(!1);return}if(!c||typeof c.then!="function"){o(c??null),l(!1);return}l(!0),c.then(d=>{p===a.current&&o(d??null)}).catch(()=>{p===a.current&&o(null)}).finally(()=>{p===a.current&&l(!1)})},[t,n]),{images:r,loading:s}}const lo={A:"fine",B:"rough",C:"rough",D:"ocr"};function eu(t){return typeof t!="string"?null:t in li?t:t in lo?lo[t]:null}const tu={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},nu={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function et(t){return typeof t!="string"?"":tu[t]??nu[t]??t}const iu=["〇","一","二","三","四","五","六","七","八","九"],ao=["","十","百","千"],ru=["","萬","億"];function or(t){if(t===0)return"〇";if(t<0)return`負${or(-t)}`;const n=[];let r=t,o=0;for(;r>0;){const s=r%1e4;s>0?n.unshift(ou(s,o>0)+ru[o]):n.length>0&&n.unshift("〇"),r=Math.floor(r/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function ou(t,n){const r=[];let o=t;for(;o>0;)r.unshift(o%10),o=Math.floor(o/10);let s="";for(let l=0;l<r.length;l++){const a=r[l],p=r.length-1-l;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&p===1&&l===0&&!n?s+=ao[p]:s+=iu[a]+ao[p]}return s.replace(/〇$/,"")}let Qt=null,mn=null;const wn=new Set;function su(){return Qt?Promise.resolve():mn||(mn=import("opencc-js/t2cn").then(t=>{Qt=t.Converter({from:"tw",to:"cn"}),wn.forEach(n=>n())}).catch(()=>{Qt=t=>t,wn.forEach(t=>t())}),mn)}const lu=t=>t;function Ct(){const[,t]=h.useState(0);return h.useEffect(()=>{if(Qt)return;const n=()=>t(r=>r+1);return wn.add(n),su(),()=>{wn.delete(n)}},[]),Qt??lu}function At(t,n){return n(t).toLowerCase()}const au=i("highlight-bg");function ln(t,n,r){if(!n)return t;const o=At(n,r);if(!o)return t;const s=At(t,r);if(s.length!==t.length)return t;const l=[];let a=0,p=0;for(;a<t.length;){const c=s.indexOf(o,a);if(c===-1){l.push(t.slice(a));break}c>a&&l.push(t.slice(a,c)),l.push(e.jsx("mark",{style:{background:au,padding:0,color:"inherit"},children:t.slice(c,c+o.length)},p++)),a=c+o.length}return e.jsx(e.Fragment,{children:l})}function sr(t,n,r,o){if(!n)return!0;const s=At(n,o);return(r?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(a=>typeof a=="string"&&At(a,o).includes(s))}function cu(t,n,r){return n?At(t,r).includes(At(n,r)):!0}const lr={类:i("section-lei"),书:i("section-shu"),序:i("section-xu"),结语:i("section-jieyu"),注释:i("section-zhushi")},du={考证:i("section-kaozhen")};function vl(t){var o;const n=t.files.length,r=((o=t.children)==null?void 0:o.reduce((s,l)=>s+vl(l),0))||0;return n+r}function pu(t,n){const r=[],o=a=>{var p;r.push(...a.files),(p=a.children)==null||p.forEach(o)};if(o(t),r.length===0)return;const s=r.map(a=>n[a]);if(s.every(a=>a===void 0))return;if(s.some(a=>a==="loading"))return"loading";let l=0;for(const a of s)typeof a=="number"&&(l+=a);return l}const uu={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function ar({enabled:t,expanded:n,onClick:r,style:o,children:s}){return t?e.jsx("button",{type:"button","aria-expanded":n,onClick:r,style:{...uu,...o},children:s}):e.jsx("span",{style:o,children:s})}function mu({type:t}){const n=et(t),r=lr[n]||i("desc-fg");return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:r,border:`1px solid ${r}40`,borderRadius:"2px",background:`${r}08`,flexShrink:0},children:n})}function xu({section:t,onNavigate:n,highlightQuery:r="",no:o,showUnlinked:s=!1,domId:l}){const{convert:a}=O(),p=He(),c=Ct(),d=f=>f?Ze(a(f),v=>r?ln(v,r,c):v):"",[u,x]=h.useState(!1),m=!!t.summary,g=!!t.comment,b=!!t.additional_comment,k=!!(t.content&&t.content.length>60),y=m||g||b||k;h.useEffect(()=>{r&&x(!0)},[r]);const j=!u&&k?ll(t.content.replace(/\n/g," "),80)+"…":null;return e.jsxs("div",{className:"bim-rd-row",id:l,style:{borderBottom:`1px solid ${i("rule")}`,overflow:"hidden"},children:[e.jsxs("div",{onClick:()=>y&&x(!u),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:y?"pointer":"default",userSelect:"none"},children:[o!=null&&e.jsx("span",{className:"bim-rd-no",style:{flex:"none",width:28,fontSize:12,color:i("label-fg")},children:o}),e.jsxs(ar,{enabled:y,expanded:u,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[y&&e.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg")},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",d(t.book_title),"》"]}):d(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[or(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:d(t.author_info||t.author)})]}),!u&&j&&e.jsx("span",{style:{display:"block",fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:d(j)})]})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:d(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:i("section-tag-fg")},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:p(t.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),f.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品","aria-label":`查看作品:${t.book_title||t.title}`,children:"作品 →"}),s&&!t.work_id&&e.jsx("span",{style:{fontSize:"11px",color:i("label-fg"),flexShrink:0},children:"未关联"})]}),u&&y&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${i("widget-border")}`,background:i("bg")},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"8px"},children:d(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${i("primary")}`,background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:d(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(t.additional_comment)})]}),k&&!m&&!g&&!b&&e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:d(t.content)})]})]})}function hu({section:t,highlightQuery:n=""}){const{convert:r}=O(),o=Ct(),s=c=>c?Ze(r(c),d=>n?ln(d,n,o):d):"",[l,a]=h.useState(!1),p=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs(ar,{enabled:p,expanded:l,onClick:()=>a(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[e.jsx(mu,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:s(t.title)}),p&&e.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&p&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${lr[et(t.type)]||i("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:i("bg")},children:e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(t.content)})})]})}const gu=100;function cr(t){return et(t.type)!=="page_header"?!1:(t.content||"").length>=gu}function fu({section:t,highlightQuery:n=""}){const{convert:r}=O(),o=Ct();if(et(t.type)==="page_header"&&!cr(t)||!t.content&&!t.title)return null;const s=r((t.content||t.title||"").replace(/\n{2,}/g,`
1081
+ `)),l=Ze(s,d=>n?ln(d,n,o):d),a=et(t.type),p=lr[a]||i("desc-fg"),c=a==="序"||a==="结语"||a==="注释";return e.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:i("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${p}40`:void 0,background:c?i("bg"):void 0,borderRadius:c?"0 4px 4px 0":void 0,position:"relative"},children:[c&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:a}),l]})}function bu(t,n,r){const[o,s]=h.useState({});return h.useEffect(()=>{var d;if(!n||t.length===0)return;let l=!1;const a=t.filter(u=>{var x;return!((x=r==null?void 0:r.current)!=null&&x.has(u))}),p={};for(const u of t)(d=r==null?void 0:r.current)!=null&&d.has(u)&&(p[u]=r.current.get(u));if(Object.keys(p).length>0&&s(p),a.length===0)return;const c=async u=>{var x;try{if(n.getEntry){const y=await n.getEntry(u);if(y)return{title:y.title,author:y.author}}const m=await n.getItem(u);if(!m)return null;const g=m.title||u,b=m.authors,k=(x=b==null?void 0:b[0])==null?void 0:x.name;return{title:g,author:k}}catch{return null}};return Promise.all(a.map(async u=>{var m;const x=await c(u);return(m=r==null?void 0:r.current)==null||m.set(u,x),[u,x]})).then(u=>{l||s(x=>{const m={...x};for(const[g,b]of u)m[g]=b;return m})}),()=>{l=!0}},[t.join(","),n]),o}function yu({section:t,onNavigate:n,transport:r,workLabelCache:o,highlightQuery:s=""}){const{convert:l}=O(),a=He(),p=Ct(),c=f=>f?Ze(l(f),v=>s?ln(v,s,p):v):"",[d,u]=h.useState(!1);h.useEffect(()=>{s&&u(!0)},[s]);const x=et(t.type),m=du[x]||i("desc-fg"),g=!!t.content,b=t.work_ids||[],k=b.length>1,y=bu(k?b:[],r,o),j=g&&!d&&t.content.length>80?ll(t.content,80)+"……":null;return e.jsxs("div",{style:{borderBottom:`1px solid ${i("widget-border")}`,padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>g&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:g?"pointer":"default",userSelect:"none"},children:[e.jsxs(ar,{enabled:g,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[g&&e.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("span",{style:{display:"block",flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg"),lineHeight:1.6},children:t.header_line?c(t.header_line):c(t.title)}),!d&&j&&e.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:i("desc-fg"),lineHeight:1.7},children:c(j)})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&e.jsx("a",{href:a(b[0]),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),f.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),k&&e.jsxs("span",{style:{fontSize:"11px",color:i("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:m,border:`1px solid ${m}40`,borderRadius:"2px",background:`${m}08`},children:x})]})]}),k&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(f=>{const v=y[f],$=v?`${l(v.title)}${v.author?`(${l(v.author)})`:""}`:f.slice(0,8)+"…";return e.jsxs("a",{href:a(f),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),w.stopPropagation(),n(f))},style:{fontSize:"12px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:f,children:["→",$]},f)})}),d&&g&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${m}40`,borderRadius:"0 4px 4px 0",background:i("bg")},children:[e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${i("widget-border")}`,fontSize:"12px",color:i("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:c(t.comment)})]})]})}function ju({juan:t,searchQuery:n,onNavigate:r,transport:o,workLabelCache:s}){const l=Ct(),a=n.trim(),p=h.useMemo(()=>a?t.sections.filter(c=>sr(c,a,!0,l)):t.sections,[t.sections,a,l]);return e.jsxs("div",{children:[e.jsx("div",{children:p.map((c,d)=>e.jsx(yu,{section:c,onNavigate:r,transport:o,workLabelCache:s,highlightQuery:a},d))}),p.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function vu(){let t=!1;return n=>n==="类"?(t=!0,"h2"):t?"h3":"h2"}function ku({sections:t,onNavigate:n,inline:r,workLinks:o=!0}){const s=He(),{convert:l}=O(),a=vu();return e.jsx(e.Fragment,{children:t.map((p,c)=>{const d=et(p.type);if(d==="page_header"&&!cr(p))return null;if(d==="类")return e.jsxs(h.Fragment,{children:[h.createElement(a("类"),null,r(l(p.title))),p.content&&e.jsx("p",{children:r(l(p.content))})]},c);if(d==="书"||d==="诗"||d==="考证"||d==="注释"){const u=p.book_title?`《${p.book_title}》${p.n_juan!=null?or(p.n_juan)+"卷":""}`:p.title,x=r(l(u));return e.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${c}`,children:[h.createElement(a("条目"),{className:"bim-rd-entry-h"},p.work_id&&n&&o?e.jsxs(e.Fragment,{children:[e.jsx("a",{href:s(p.work_id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),n(p.work_id))},title:"查看作品",children:x}),e.jsx("a",{className:"bim-rd-wl",href:s(p.work_id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),n(p.work_id))},"aria-label":`查看作品:${u}`,children:"作品 →"})]}):x),p.author_info&&e.jsx("p",{className:"bim-rd-sub",children:r(l(p.author_info))}),p.content&&p.content.split(/\n+/).map((m,g)=>e.jsx("p",{children:r(l(m))},g)),p.summary&&e.jsxs("p",{children:[e.jsx("span",{className:"bim-rd-lbl",children:"提要"}),r(l(p.summary))]}),p.comment&&e.jsxs("p",{children:[e.jsx("span",{className:"bim-rd-lbl",children:"按語"}),r(l(p.comment))]}),p.additional_comment&&e.jsxs("p",{children:[e.jsx("span",{className:"bim-rd-lbl",children:"附按"}),r(l(p.additional_comment))]})]},c)}return p.content?e.jsx("p",{children:r(l(p.content))},c):null})})}function kl(t){return t.some(n=>{const r=et(n.type);return r==="书"||r==="诗"||r==="考证"||r==="注释"||r==="类"||(r==="序"||r==="结语")&&!!n.content||r==="page_header"&&cr(n)})}function wu({juan:t,rawText:n,positionLabel:r,groupLabel:o,index:s,searchQuery:l,onNavigate:a,transport:p,workLabelCache:c,prefs:d,view:u,onViewChange:x}){var D;const{convert:m}=O(),g=Ct(),[b,k]=h.useState("text"),y=u??b,j=L=>{k(L),x==null||x(L)},f=l.trim(),v=(s==null?void 0:s.type)==="kaozhen",$=h.useCallback(L=>f?ln(L,f,g):L,[f,g]),w=L=>ir(L,{renderText:$,properNames:d.properNames}),_=h.useMemo(()=>f?t.sections.filter(L=>sr(L,f,v,g)):t.sections,[t.sections,f,v,g]),S=(L,le)=>le.filter(A=>et(A.type)===L).length,z=S("书",t.sections),E=S("诗",t.sections),T=S("考证",t.sections);let N="";v?N=f?`${S("考证",_)} / ${T} ${m("條")}`:`${T} ${m("條")}`:E>0?N=f?`${S("诗",_)} / ${E} 首`:`${E} 首`:z>0&&(N=f?`${S("书",_)} / ${z} ${m("部書")}`:`${z} ${m("部書")}`);const V=s!=null&&s.text_quality?eu(s.text_quality.grade):null,W=[];N&&W.push(N),v&&(s!=null&&s.target_source)&&W.push(e.jsxs(e.Fragment,{children:[m("考證對象")," ",m(s.target_source)]})),V&&W.push(e.jsx("span",{title:ic[V],children:(D=s==null?void 0:s.text_quality)!=null&&D.source_note?e.jsxs(e.Fragment,{children:["底本 ",m(s.text_quality.source_note),e.jsx("span",{className:"bim-rd-grade",children:m(li[V])})]}):e.jsxs(e.Fragment,{children:[m("文本質量"),e.jsx("span",{className:"bim-rd-grade",children:m(li[V])})]})})),t.source_url&&W.push(e.jsx("a",{className:"bim-rd-link",href:t.source_url,target:"_blank",rel:"noopener noreferrer",children:m("原文來源")}));const B=!v&&kl(t.sections),H=!!n&&(!B||d.readingMode==="paragraph"&&kn(n)),te=!v&&(B||!!n),se=v||!te?"entries":y;let J=0;return e.jsxs(e.Fragment,{children:[e.jsxs("header",{children:[(r||o)&&e.jsxs("p",{className:"bim-rd-kicker",children:[r,r&&o&&e.jsx("span",{className:"bim-rd-dot"}),o&&m(o)]}),e.jsx("h1",{className:"bim-rd-h1",children:m(t.title)}),W.length>0&&e.jsx("p",{className:"bim-rd-meta",children:W.map((L,le)=>e.jsxs(h.Fragment,{children:[le>0&&e.jsx("span",{className:"bim-rd-dot"}),L]},le))}),te&&t.sections.length>0&&e.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":"看法",children:[e.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":se==="text",onClick:()=>j("text"),children:"正文"}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":se==="entries",onClick:()=>j("entries"),children:m("條目")})]})]}),se==="text"&&e.jsx("article",{className:"bim-rd-prose",children:H?e.jsx(rr,{text:n,mode:d.readingMode,properNames:d.properNames,renderText:$,dropTitle:t.title}):e.jsx(ku,{sections:t.sections,onNavigate:a,inline:w,workLinks:d.workLinks})}),se==="entries"&&e.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:v?e.jsx(ju,{juan:t,searchQuery:l,onNavigate:a,transport:p,workLabelCache:c}):e.jsxs(e.Fragment,{children:[_.some(L=>["书","诗","考证"].includes(et(L.type)))&&e.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[e.jsx("span",{style:{width:28},children:"序"}),e.jsx("span",{style:{flex:1},children:"书名"}),e.jsx("span",{children:"作品"})]}),_.map((L,le)=>{const A=et(L.type);return A==="书"||A==="诗"||A==="考证"?(J+=1,e.jsx(xu,{domId:`rd-e-${t.sections.indexOf(L)}`,section:L,onNavigate:d.workLinks?a:void 0,highlightQuery:f,no:J,showUnlinked:d.workLinks&&!!a},le)):A==="类"?e.jsx(hu,{section:L,highlightQuery:f},le):e.jsx(fu,{section:L,highlightQuery:f},le)}),_.length===0&&e.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function Su(t){const{resetKey:n,load:r,files:o,activeFile:s,activeJuan:l,activeRawText:a,query:p,isKaozhen:c}=t,d=Ct(),u=h.useRef(new Map),[x,m]=h.useState({}),[g,b]=h.useState({}),k=h.useCallback((j,f)=>{const v=f==null?void 0:f.title;v&&b($=>$[j]===v?$:{...$,[j]:v})},[]);h.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:a}),k(s,l))},[s,l,a,k]),h.useEffect(()=>{u.current.clear(),m({}),b({})},[n]);const y=h.useCallback((j,f)=>{let v=0;if(j.juan)for(const $ of j.juan.sections)sr($,f,c,d)&&v++;return v===0&&j.rawText&&cu(j.rawText,f,d)&&(v=1),v},[c,d]);return h.useEffect(()=>{const j=p.trim();if(!j){m({});return}if(!r||o.length===0)return;let f=!1;const v={},$=[];for(const E of o){const T=u.current.get(E);T?v[E]=y(T,j):(v[E]="loading",$.push(E))}m(v);const w=8;let _=0;const S=async()=>{for(;_<$.length;){if(f)return;const E=_++,T=$[E];try{const N=await r(T),V=N.juan;if(u.current.set(T,N),k(T,V),f)return;m(W=>({...W,[T]:y(N,j)}))}catch{if(f)return;m(N=>({...N,[T]:0}))}}},z=Array.from({length:Math.min(w,$.length)},()=>S());return Promise.all(z),()=>{f=!0}},[p,n,r,o.join(","),y,d,k]),{matchStates:x,titles:g}}function $u({juan:t,view:n,onView:r,textHasEntries:o}){const{convert:s}=O(),l=t.sections.map((d,u)=>({s:d,i:u,t:et(d.type)})).filter(d=>d.t==="书"||d.t==="诗");if(l.length===0)return null;const a=l.filter(d=>!!d.s.work_id).length,p=l.every(d=>d.t==="诗")?"首":"部书",c=d=>{const u=()=>{var x,m;return(m=(x=document.getElementById(`rd-e-${d}`))==null?void 0:x.scrollIntoView)==null?void 0:m.call(x,{block:"start",behavior:"smooth"})};n==="text"&&!o&&r("entries"),n==="text"&&!o?setTimeout(u,0):u()};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bim-rd-rail-card",children:[e.jsx("div",{className:"bim-rd-rail-cap",children:"本卷"}),e.jsxs("div",{className:"bim-rd-rail-n",children:[e.jsx("b",{children:l.length}),e.jsx("span",{children:s(p)}),e.jsxs("span",{className:"bim-rd-rail-linked",children:["已关联 ",a]})]}),e.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":`已关联 ${a} / ${l.length}`,children:e.jsx("span",{style:{width:`${Math.round(a/l.length*100)}%`}})})]}),e.jsxs("nav",{"aria-label":"本卷条目",children:[e.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:s("條目")}),e.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:d,i:u})=>e.jsx("li",{children:e.jsxs("a",{href:`#rd-e-${u}`,onClick:x=>{x.preventDefault(),c(u)},children:[e.jsx("span",{className:`bim-rd-rail-dot${d.work_id?" on":""}`,"aria-hidden":"true"}),e.jsx("span",{children:s(d.book_title||d.title)})]})},u))})]})]})}const xn={padding:24,color:i("desc-fg"),fontSize:14},co=/^https?:\/\//i;function _u(t){if(!t||typeof t!="object")return null;const n=l=>typeof l=="string"&&l.trim()?l.trim():void 0,r=n(t.url),o=n(t.license_url),s={name:n(t.name),url:r&&co.test(r)?r:void 0,license:n(t.license),license_url:o&&co.test(o)?o:void 0,note:n(t.note)};return s.name||s.license||s.note?s:null}function zu(t,n){return{work_id:n.work_id??t,title:n.title,type:n.type,juan_files:n.chapters.map(r=>r.file),juan_metadata:n.juan_metadata,juan_groups:n.juan_groups,references:n.references,target_source:n.target_source,target_source_id:n.target_source_id,text_source:n.text_source,text_quality:n.text_quality}}function Cu(t,n){return(n==null?void 0:n.type)==="kaozhen"?"章":n!=null&&n.juan_metadata&&Object.values(n.juan_metadata).some(r=>r.vol_label)?"冊":(t==null?void 0:t.kind)==="collated"?"卷":"章"}function wl(t,n,r,o=!1){const s=r(`${n}${t.n}`);if(!t.title)return s;const l=r(t.title);return o&&!/^[卷冊册章篇回第]/.test(t.title)?`${s} ${l}`:l}function Tu(t,n,r,o,s){var d;const l=new Map(t.chapters.map(u=>[u.file,u])),a=u=>u==="loading"?"…":typeof u=="number"&&u>0?u:void 0,p=(u,x)=>{const m=l.get(u);return{key:u,label:x??(m?wl(m,r,o,s):u),hint:a(n[u]),disabled:n[u]===0}},c=(d=t.juan_groups)==null?void 0:d.filter(u=>{var x;return u.files.some(m=>l.has(m))||((x=u.children)==null?void 0:x.length)});if(c&&c.length>0){const u=(x,m)=>{var b;if(x.files.length===1&&!((b=x.children)!=null&&b.length))return p(x.files[0],o(x.label));const g=pu(x,n);return{key:`group:${m}`,label:o(x.label),hint:g==="loading"?"…":typeof g=="number"&&g>0?`${g}`:vl(x),defaultExpanded:typeof g=="number"&&g>0,children:[...x.files.filter(k=>l.has(k)).map(k=>p(k)),...(x.children??[]).map((k,y)=>u(k,`${m}.${y}`))]}};return c.map((x,m)=>u(x,`${m}`))}return t.chapters.map(u=>p(u.file))}const dr=({id:t,transport:n,versionKey:r,chapter:o,onLocationChange:s,onNavigate:l,title:a,subtitle:p,resolveImages:c,renderImageOverlay:d,imagePanel:u,allowVertical:x,onReportError:m,revisedAt:g,backHref:b,backLabel:k,className:y,style:j})=>{var Fe,Ee,mt;const{convert:f}=O(),v=h.useMemo(()=>Is(n),[n]),[$,w]=Os(),_=He(),S=h.useRef(s);S.current=s;const[z,E]=h.useState(null),[T,N]=h.useState("loading");h.useEffect(()=>{let Q=!1;return E(null),N("loading"),v.getManifest(t).then(Le=>{Q||(Le?(E(Le),N("ready")):N("missing"))}).catch(()=>{Q||N("missing")}),()=>{Q=!0}},[v,t]);const V=r!==void 0,W=o!==void 0,[B,H]=h.useState(null),[te,se]=h.useState(null);h.useEffect(()=>{H(null),se(null)},[t]);const J=be.pickTextVersion(z,V?r:B),D=((Fe=z==null?void 0:z.versions.find(Q=>Q.key==="default"))==null?void 0:Fe.key)??((Ee=z==null?void 0:z.versions[0])==null?void 0:Ee.key)??"default",L=(J==null?void 0:J.key)??null,le=W?o:te,A=h.useCallback((Q,Le,Xe)=>{var yt;(yt=S.current)==null||yt.call(S,{key:Q,chapter:Le,isDefault:Q===D},Xe)},[D]);h.useEffect(()=>{!z||!V||r==null||z.versions.some(Q=>Q.key===r)||A(D,null,"auto")},[z,V,r,D,A]);const ne=h.useRef(new Map);h.useEffect(()=>{ne.current.clear()},[v,t]);const de=h.useCallback(async Q=>{const Le=`${t}
1082
+ ${Q}`;if(ne.current.has(Le))return ne.current.get(Le)??null;const Xe=await v.getIndex(t,Q).catch(()=>null);return Xe&&ne.current.set(Le,Xe),Xe},[v,t]),[G,he]=h.useState(null),[ye,xe]=h.useState("loading");h.useEffect(()=>{if(!L)return;let Q=!1;return he(null),xe("loading"),de(L).then(Le=>{Q||(Le&&Le.chapters.length>0?(he(Le),xe("ready")):xe("failed"))}),()=>{Q=!0}},[L,de]),h.useEffect(()=>{if(!G||!L||le!=null&&G.chapters.some(Xe=>Xe.file===le))return;const Le=G.chapters[0].file;W||se(Le),A(L,Le,"auto")},[G,L,le,W,A]);const pe=G?le!=null&&G.chapters.some(Q=>Q.file===le)?le:G.chapters[0].file:le,$e=h.useMemo(()=>G&&pe?G.chapters.find(Q=>Q.file===pe)??null:null,[G,pe]),Oe=h.useRef(0),Ae=h.useCallback(async Q=>{if(!z||Q===L||!z.versions.some(dn=>dn.key===Q))return;const Le=++Oe.current,Xe=await de(Q);if(Le!==Oe.current)return;const yt=$e??(pe?{file:pe}:null),Ft=be.matchChapterAcrossVersions(yt,Xe);V||H(Q),W||se(Ft),A(Q,Ft,"version")},[z,L,de,$e,pe,V,W,A]),Me=h.useCallback(Q=>{L&&(W||se(Q),A(L,Q,"chapter"))},[L,W,A]),[ve,Be]=h.useState(null),[P,ae]=h.useState(!1),ie=h.useRef(0);h.useEffect(()=>{if(!L||!$e)return;const Q=++ie.current;ae(!0),Be(null),v.getChapter(t,L,$e.file,{json:!!$e.has_json}).then(Le=>{Q===ie.current&&Be(Le)}).catch(()=>{Q===ie.current&&Be(null)}).finally(()=>{Q===ie.current&&ae(!1)})},[v,t,L,$e]);const _e=(J==null?void 0:J.kind)==="collated",[ke,Y]=h.useState("");h.useEffect(()=>{Y("")},[t,L]);const I=h.useMemo(()=>L&&_e?async Q=>{const Le=await v.getChapter(t,L,Q,{json:!0});return{juan:(Le==null?void 0:Le.json)??null,rawText:(Le==null?void 0:Le.md)??null}}:null,[v,t,L,_e]),U=(G==null?void 0:G.type)==="kaozhen",ge=h.useMemo(()=>(G==null?void 0:G.chapters.map(Q=>Q.file))??[],[G]),{matchStates:we}=Su({resetKey:`${t}
1083
+ ${L??""}`,load:I,files:ge,activeFile:pe??null,activeJuan:(ve==null?void 0:ve.json)??null,activeRawText:(ve==null?void 0:ve.md)??null,query:ke,isKaozhen:U}),R=h.useRef(new Map);h.useEffect(()=>{R.current.clear()},[t]);const oe=Qp(c,pe??null),{entryTitle:K,authors:X}=Eu(t,n,a===void 0),[je,Ie]=h.useState("text");if(h.useEffect(()=>{Ie("text")},[pe,L]),T==="loading")return e.jsx("div",{className:y,style:{...j,...xn},children:"加载中…"});if(T==="missing"||!z||!J)return e.jsx("div",{className:y,style:{...j,...xn},children:"暂无文本"});if(ye==="failed")return e.jsx("div",{className:y,style:{...j,...xn},children:"无法加载目录"});if(!G)return e.jsx("div",{className:y,style:{...j,...xn},children:"加载目录…"});const Re=Cu(J,G),re=Tu(G,we,Re,f,_e),ze=z.versions.map(Q=>({key:Q.key,label:be.textVersionLabel(Q),optionLabel:f(be.textVersionLabel(Q)),sourceName:Q.source_name?f(Q.source_name):void 0,license:Q.license??void 0,sourceUrl:Q.source_url??void 0,primary:Q.key===D})),C=_u((mt=G.source)==null?void 0:mt.upstream),q=(typeof a=="string"?f(a):a)??(G.title?f(G.title):K?f(K):void 0),ee=q?e.jsx("a",{href:_(t),title:"查看条目",onClick:l?Q=>{Q.metaKey||Q.ctrlKey||(Q.preventDefault(),l(t))}:void 0,children:q}):void 0,Z=X.length>0?f(X.slice(0,2).map(Q=>`${Q.dynasty?`〔${Q.dynasty}〕`:""}${Q.name}${Q.role?` ${Q.role}`:" 撰"}`).join("、")):void 0,me=$e?wl($e,Re,f,_e):void 0,Ce=_e&&!!(ve!=null&&ve.json),F=(ve==null?void 0:ve.json)??null,M=(ve==null?void 0:ve.md)??null,ue=Ce&&!U&&kl(F.sections),Te=ue&&!(M&&$.readingMode==="paragraph"&&kn(M)),We=Ce&&ue?e.jsx($u,{juan:F,view:je,onView:Ie,textHasEntries:Te}):void 0,Ne=Cs(G)||pi(G),ce=M?M.replace(/^##\s+[^\n]+\n+/,""):null,Se=(typeof p=="string"?f(p):p)??(J.source_name?f(J.source_name):f(be.textVersionLabel(J)));return e.jsxs(Ds,{className:y,style:j,title:ee,subtitle:Se,byline:Z,current:me,pagerUnit:Re,rail:We,revisedAt:g,backHref:b,backLabel:k,onReportError:m?Q=>m({...Q,bookTitle:typeof q=="string"?q:void 0,entryId:t}):void 0,workLinkToggle:Ce&&!U&&!!l&&!!(F!=null&&F.sections.some(Q=>Q.work_id)),toc:re,tocCaption:`目录 · ${G.chapters.length} ${f(Re)}`,tocHeader:_e&&G.chapters.length>1?e.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:U?"搜索全部章节…":`搜索全部${Re}…`,"aria-label":U?"搜索全部章节":`搜索全部${Re}`,value:ke,onChange:Q=>Y(Q.target.value)}):void 0,activeKey:pe??null,onSelect:Me,images:oe.images,imagesLoading:oe.loading,renderImageOverlay:d,imagePanel:u,prefs:$,onPrefsChange:w,versions:ze.length>1?ze:void 0,currentVersionKey:ze.length>1?J.key:void 0,onVersionChange:Ae,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:kn(M),allowVertical:x,children:[P&&e.jsx(zt,{}),!P&&Ce&&F&&e.jsx(wu,{juan:F,rawText:M,positionLabel:Nu($e,G,Re,f),groupLabel:Iu(G,pe??null),index:zu(t,G),searchQuery:ke,onNavigate:l,transport:n,workLabelCache:R,prefs:$,view:je,onViewChange:Ie},`${L}/${pe}`),!P&&!Ce&&ce!=null&&$e&&e.jsxs(e.Fragment,{children:[e.jsxs("header",{children:[e.jsx("h1",{className:"bim-rd-h1",children:$e.title?f($e.title):me}),(J.source_name||J.license)&&e.jsxs("p",{className:"bim-rd-meta",children:[J.source_name&&e.jsxs(e.Fragment,{children:["来源 ",J.source_url?e.jsx("a",{className:"bim-rd-link",href:J.source_url,target:"_blank",rel:"noreferrer",children:f(J.source_name)}):f(J.source_name)]}),J.source_name&&J.license&&e.jsx("span",{className:"bim-rd-dot"}),J.license]}),C&&e.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:["上游 ",C.url?e.jsx("a",{className:"bim-rd-link",href:C.url,target:"_blank",rel:"noreferrer",children:f(C.name??C.url)}):f(C.name??""),C.license&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bim-rd-dot"}),C.license_url?e.jsx("a",{className:"bim-rd-link",href:C.license_url,target:"_blank",rel:"noreferrer",children:C.license}):C.license]}),C.note&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bim-rd-dot"}),f(C.note)]})]})]}),e.jsx("article",{className:"bim-rd-prose",children:e.jsx(rr,{text:ce,mode:$.readingMode,tables:Ne,gujiMarkdown:pi(G),properNames:$.properNames})})]}),!P&&!Ce&&ce==null&&$e&&e.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"}),G.references&&G.references.length>0&&e.jsxs("section",{className:"bim-rd-refs",children:[e.jsx("h2",{children:f("參考文獻")}),e.jsx("ol",{children:G.references.map((Q,Le)=>e.jsxs("li",{children:[Q.url?e.jsx("a",{className:"bim-rd-link",href:Q.url,target:"_blank",rel:"noopener noreferrer",children:Q.title}):e.jsx("span",{children:Q.title}),Q.author&&e.jsxs("span",{children:[",",Q.author]}),Q.note&&e.jsxs("span",{children:["。",Q.note]})]},Le))})]})]})};function Nu(t,n,r,o){var l,a;if(!t)return;const s=(a=(l=n.juan_metadata)==null?void 0:l[t.file])==null?void 0:a.vol_label;return o(s?`${s}冊`:`${r}${t.n}`)}function Iu(t,n){if(!n)return;const r=o=>{var s;for(const l of o??[]){const a=r(l.children);if(a)return a;if((s=l.files)!=null&&s.includes(n))return l.label}};return r(t.juan_groups)}function Eu(t,n,r){const[o,s]=h.useState({entryTitle:void 0,authors:[]});return h.useEffect(()=>{if(s({entryTitle:void 0,authors:[]}),typeof n.getItem!="function")return;let l=!1;return Promise.resolve(n.getItem(t)).then(a=>{if(l||!a)return;const p=(a.authors??[]).filter(c=>c&&c.name);s({entryTitle:r&&typeof a.title=="string"?a.title:void 0,authors:p})}).catch(()=>{}),()=>{l=!0}},[t,n,r]),o}const Ru={bug:{label:"错误反馈",color:i("danger")},resource:{label:"资源建议",color:i("primary")},suggestion:{label:"功能建议",color:i("primary")},other:{label:"其他",color:i("desc-fg")}},Lu={label:"其他",color:i("desc-fg")},Au={pending:{label:"待处理",color:i("warning")},in_progress:{label:"处理中",color:i("primary")},resolved:{label:"已处理",color:i("success")},wontfix:{label:"不采纳",color:i("desc-fg")},duplicate:{label:"重复",color:i("desc-fg")}},Bu={label:"待处理",color:i("warning")};function Mu(t){try{const n=new Date(t),r=o=>String(o).padStart(2,"0");return`${n.getFullYear()}-${r(n.getMonth()+1)}-${r(n.getDate())} ${r(n.getHours())}:${r(n.getMinutes())}`}catch{return t}}function Wu(t,n){if(!t)return!1;try{const r=new URL(t,n);if(r.protocol!=="http:"&&r.protocol!=="https:")return!1;const o=new URL(n);return r.hostname===o.hostname}catch{return!1}}const pr=({items:t,loading:n})=>{const r=He();return n?e.jsx(zt,{}):t.length===0?e.jsx("div",{style:Ou,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const s=Ru[o.type]||Lu,l=Au[o.status]||Bu,a=typeof window<"u"&&Wu(o.pageUrl,window.location.href);return e.jsxs("div",{style:Fu,children:[e.jsxs("div",{style:Pu,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...po,background:s.color},children:s.label}),e.jsx("span",{style:{...po,background:l.color},children:l.label})]}),e.jsx("span",{style:Du,children:Mu(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:Hu,children:[o.resourceId&&e.jsx("a",{href:r(o.resourceId),style:Qn,children:o.resourceId}),o.pageUrl&&!o.resourceId&&(a?e.jsx("a",{href:o.pageUrl,style:Qn,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):e.jsx("span",{style:Qn,children:o.pageUrl}))]}),e.jsx("div",{style:Gu,children:o.content}),o.reply&&e.jsxs("div",{style:Uu,children:[e.jsx("div",{style:Vu,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})})},Ou={textAlign:"center",padding:"40px 0",color:i("desc-fg"),fontSize:"14px"},Fu={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"16px"},Pu={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},po={fontSize:"12px",color:i("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Du={fontSize:"12px",color:i("desc-fg")},Hu={fontSize:"12px",marginBottom:"6px"},Qn={color:i("primary"),textDecoration:"none",borderBottom:`1px dashed ${i("primary")}`},Gu={fontSize:"14px",lineHeight:"1.6",color:i("fg"),whiteSpace:"pre-wrap"},Uu={marginTop:"12px",padding:"10px 12px",background:i("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:i("fg")},Vu={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:i("primary")},ki=({transport:t,onNavigate:n,recommendedIds:r,activeTab:o,onTabChange:s,feedbackApiUrl:l})=>{const a=fe(),[p,c]=h.useState(null),[d,u]=h.useState([]),[x,m]=h.useState("recommend"),[g,b]=h.useState([]),[k,y]=h.useState(!1),j=o??x,f=H=>{m(H),s==null||s(H)},[v,$]=h.useState(!0),[w,_]=h.useState(null),[S,z]=h.useState(null),[E,T]=h.useState(null);h.useEffect(()=>{let H=!1;if(t.getCounts)return t.getCounts().then(te=>{H||c({works:te.works,books:te.books,collections:te.collections})}).catch(()=>{}),()=>{H=!0}},[t]),h.useEffect(()=>{let H=!1;return(async()=>{if(r)return r;if(t.getRecommended)try{const se=await t.getRecommended();if(se!=null&&se.groups)return se.groups.flatMap(J=>J.items.map(D=>({...D,group:J.name})))}catch{}return[]})().then(async se=>{if(H)return;const J=se.filter(L=>L.id);if(J.length===0){$(!1);return}const D=await Promise.all(J.map(async L=>{if(L.type)return{id:L.id,title:L.title,type:L.type,author:L.author,dynasty:L.dynasty,role:L.role,edition:L.edition,has_text:L.has_text,has_image:L.has_image,has_collated:L.has_collated,subtype:L.subtype,primary_name:L.primary_name,group:L.group,fallbackDescription:L.description};try{let le=null;if(t.getEntry)le=await t.getEntry(L.id);else{const A=await t.getItem(L.id);A&&(le={id:L.id,title:A.title||L.id,type:A.type||"work"})}if(le)return{...le,group:L.group,fallbackDescription:L.description}}catch{}return{id:L.id,title:L.title,type:be.extractType(L.id),group:L.group,fallbackDescription:L.description}}));H||(u(D.filter(L=>L!==null)),$(!1))}),()=>{H=!0}},[t,r]);const N=h.useRef(!1),V=h.useRef(!1),W=h.useRef(!1);h.useEffect(()=>{if(j!=="catalog"||N.current)return;const H=t.getCatalogProgress??t.getResourceProgress;if(!H)return;N.current=!0;let te=!1;return H.call(t).then(se=>{te||_(se)}).catch(()=>{N.current=!1}),()=>{te=!0}},[t,j]),h.useEffect(()=>{if(j!=="collection"||V.current||!t.getCollectionProgress)return;V.current=!0;let H=!1;return t.getCollectionProgress().then(te=>{H||z(te)}).catch(()=>{V.current=!1}),()=>{H=!0}},[t,j]),h.useEffect(()=>{if(j!=="site"||W.current||!t.getSiteProgress)return;W.current=!0;let H=!1;return t.getSiteProgress().then(te=>{H||T(te)}).catch(()=>{W.current=!1}),()=>{H=!0}},[t,j]),h.useEffect(()=>{if(!l||j!=="feedback")return;let H=!1;return y(!0),fetch(l).then(te=>te.json()).then(te=>{!H&&te.success&&b(te.items||[])}).catch(()=>{}).finally(()=>{H||y(!1)}),()=>{H=!0}},[l,j]);const B=H=>e.jsx(Ot,{type:H,size:12});return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:i("fg")},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"16px"},children:[e.jsx(Vt,{label:a.home.recommendTab,active:j==="recommend",onClick:()=>f("recommend")}),e.jsx(Vt,{label:a.home.catalogTab,active:j==="catalog",onClick:()=>f("catalog")}),e.jsx(Vt,{label:a.home.collectionTab,active:j==="collection",onClick:()=>f("collection")}),e.jsx(Vt,{label:a.home.siteTab,active:j==="site",onClick:()=>f("site")}),l&&e.jsx(Vt,{label:a.home.feedbackTab,active:j==="feedback",onClick:()=>f("feedback")})]}),j==="recommend"&&e.jsx(Yu,{recommended:d,loading:v,onNavigate:n,getIcon:B,t:a}),j==="catalog"&&e.jsx(uo,{progress:w,t:a,onNavigate:n}),j==="collection"&&e.jsx(uo,{progress:S,t:a,onNavigate:n}),j==="site"&&e.jsx(qu,{progress:E,t:a,totalWorks:(p==null?void 0:p.works)??0}),j==="feedback"&&l&&e.jsx(pr,{items:g,loading:k})]})})},Vt=({label:t,active:n,onClick:r})=>e.jsx("button",{onClick:r,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:i(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${i("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),Yu=({recommended:t,loading:n,onNavigate:r,getIcon:o,t:s})=>{const l=He();if(n)return e.jsx(zt,{});if(t.length===0)return null;const a=new Map;for(const p of t){const c=p.group||s.home.recommendedBrowse;a.has(c)||a.set(c,[]),a.get(c).push(p)}return e.jsx(e.Fragment,{children:Array.from(a.entries()).map(([p,c])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:p}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:l(d.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),r==null||r(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,cursor:"pointer",background:i("input-bg"),textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:o(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},uo=({progress:t,t:n,onNavigate:r})=>{if(!t)return e.jsx(zt,{});const o=[...t.resources].sort((p,c)=>p.priority-c.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},a={in_progress:i("progress-active"),done:i("progress-done"),todo:i("progress-todo")};return e.jsx("div",{children:s.map(p=>{const c=o.filter(d=>d.status===p);return c.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:a[p]}}),l[p]," (",c.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(d=>e.jsx(Ku,{item:d,t:n,statusColor:a[p],onNavigate:r},d.id))})]},p)})})},Ku=({item:t,t:n,statusColor:r,onNavigate:o})=>{const s=He(),l=t.total>0?Math.round(t.imported/t.total*100):0,a=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=t.edition?`${t.name}·${t.edition}`:t.name,c=t.collection_id||t.work_id;return c&&o?e.jsx("a",{href:s(c),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),o(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:p}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:i("widget-border"),color:i("desc-fg"),whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:a})]}),e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?nt(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:r,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:t.description})]})},qu=({progress:t,t:n,totalWorks:r})=>{if(!t)return e.jsx(zt,{});const o=[...t.resources].sort((c,d)=>c.priority-d.priority),s=o.filter(c=>c.imported>0),l=o.filter(c=>c.imported===0),a=s.reduce((c,d)=>Math.max(c,d.imported),0),p=r>0?Math.round(a/r*100):0;return e.jsxs("div",{children:[r>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${i("primary")} 6%, transparent)`,fontSize:"13px",color:i("fg")},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:a.toLocaleString()})," / ",r.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>e.jsx(mo,{item:c,t:n,totalWorks:r},c.id))})]}),l.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(c=>e.jsx(mo,{item:c,t:n,totalWorks:r},c.id))})]})]})},mo=({item:t,t:n,totalWorks:r})=>{const o=r>0?Math.round(t.imported/r*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${o}%)`:n.home.statusTodo})]}),t.imported>0&&r>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:i("progress-done"),transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:t.description})]})},xo="(max-width: 768px)";function Ju(){const[t,n]=h.useState(()=>typeof window>"u"?!1:window.matchMedia(xo).matches);return h.useEffect(()=>{const r=window.matchMedia(xo),o=s=>n(s.matches);return r.addEventListener("change",o),()=>r.removeEventListener("change",o)},[]),t}const Zu=({transport:t,hideModeIndicator:n=!0,onEntryClick:r,recommendedIds:o,headerRight:s})=>{var V;const l=fe(),{convert:a}=O(),p=Ju(),[c,d]=h.useState(null),[u,x]=h.useState(null),[m,g]=h.useState(!1),[b,k]=h.useState("detail"),[y,j]=h.useState([]),[f,v]=h.useState(!1),$=h.useCallback(async W=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){j([]);return}v(!0);try{if(t.getCollectionCatalogs){const B=await t.getCollectionCatalogs(W);j(B||[])}else if(t.getCollectionCatalog){const B=await t.getCollectionCatalog(W);j(B?[{resource_id:"",data:B}]:[])}}catch{j([])}finally{v(!1)}},[t]),w=h.useCallback(async W=>{if(r){r(W);return}d(W),x(null),j([]),k("detail"),g(!0);try{const B=await t.getItem(W.id);B&&(x(B),B.type==="collection"&&$(W.id))}catch(B){console.error("加载详情失败:",B)}finally{g(!1)}},[t,r,$]),_=h.useCallback(async W=>{x(null),j([]),k("detail"),g(!0);try{const B=await t.getItem(W);B&&(x(B),d({id:W,title:B.title||W,type:B.type||"book"}),B.type==="collection"&&$(W))}catch(B){console.error("导航失败:",B)}finally{g(!1)}},[t,$]),S=typeof(u==null?void 0:u.text_count)=="number"&&u.text_count>0,z=(u==null?void 0:u.type)==="collection"&&(y.length>0||f)||(u==null?void 0:u.type)==="work"&&S,E=p&&(m||u),T=h.useCallback(()=>{d(null),x(null),j([]),k("detail")},[]),N=e.jsx(e.Fragment,{children:m?e.jsx(zt,{}):u?e.jsxs(e.Fragment,{children:[(z||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${i("widget-border")}`,padding:p?"0 12px":"0 48px",background:i("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[z&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>k("detail"),style:hn(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&f&&y.length===0&&e.jsxs("button",{onClick:()=>{},style:hn(!1),children:[l.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&y.map(W=>e.jsx("button",{onClick:()=>k(`catalog:${W.resource_id}`),style:hn(b===`catalog:${W.resource_id}`),children:W.short_name?`${a(W.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},W.resource_id)),u.type==="work"&&S&&e.jsx("button",{onClick:()=>k("collated"),style:hn(b==="collated"),children:l.detailTab.collatedEdition})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(Oi,{data:u,transport:t,onNavigate:_}):b.startsWith("catalog:")?e.jsx(Fi,{data:(V=y.find(W=>`catalog:${W.resource_id}`===b))==null?void 0:V.data,onNavigate:_}):b==="collated"?e.jsx(dr,{id:u.id,transport:t,onNavigate:_}):null})]}):e.jsx(ki,{transport:t,onNavigate:_,recommendedIds:o})});return p?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:E?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${i("widget-border")}`,background:i("input-bg"),flexShrink:0},children:e.jsxs("button",{onClick:T,style:{padding:"4px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:N})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(di,{transport:t,onEntryClick:w,hideModeIndicator:n}),!u&&e.jsx(ki,{transport:t,onNavigate:_,recommendedIds:o})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${i("widget-border")}`,display:"flex",flexDirection:"column",background:i("input-bg"),overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(di,{transport:t,onEntryClick:w,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:i("bg"),display:"flex",flexDirection:"column"},children:N})]})};function hn(t){return{padding:"10px 16px",border:"none",borderBottom:t?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(t?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}const Xu=({data:t,onNavigate:n,className:r,style:o})=>{var u;const s=fe(),{convert:l}=O(),[a,p]=h.useState(((u=t.divisions[0])==null?void 0:u.name)??null),[c,d]=h.useState(null);return e.jsxs("div",{className:r,style:o,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:l(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg"),display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(Qu,{division:x,expanded:a===x.name,onToggle:()=>p(a===x.name?null:x.name),expandedCat:c,onCatToggle:m=>d(c===m?null:m),onNavigate:n},x.name))})]})},Qu=({division:t,expanded:n,onToggle:r,expandedCat:o,onCatToggle:s,onNavigate:l})=>{const{convert:a}=O(),p=t.categories.reduce((c,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return c+(u.zhulu||0)+(u.cunmu||0)},0);return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:r,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${i("primary")} 6%, transparent)`:i("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:i("fg"),textAlign:"left"},children:[e.jsx("span",{children:a(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg")},children:[t.categories.length," 類 · ",p," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(c=>{const d=`${t.name}/${c.name}`;return e.jsx(em,{category:c,expanded:o===d,onToggle:()=>s(d),onNavigate:l},c.name)})})]})},em=({category:t,expanded:n,onToggle:r,onNavigate:o})=>{var c,d,u,x;const{convert:s}=O(),l=((c=t.books)==null?void 0:c.zhulu)||[],a=((d=t.books)==null?void 0:d.cunmu)||[],p=(((u=t.stats)==null?void 0:u.zhulu)||l.length)+(((x=t.stats)==null?void 0:x.cunmu)||a.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:r,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?i("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:i("fg"),textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[s(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||a.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&e.jsx(ho,{label:"著錄",books:l,onNavigate:o}),a.length>0&&e.jsx(ho,{label:"存目",books:a,onNavigate:o})]})]})},ho=({label:t,books:n,onNavigate:r})=>{const{convert:o}=O(),s=He(),[l,a]=h.useState(n.length<=20),p=l?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((c,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:i("fg")},children:c.work_id&&r?e.jsx("a",{href:s(c.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),r(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},children:o(c.title)}):o(c.title)}),c.volumes&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:o(c.volumes)}),c.author&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:o(c.author).slice(0,20)})]},d))}),!l&&e.jsxs("button",{onClick:()=>a(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},tt=({title:t,onSave:n,onAskAI:r,extraButtons:o,children:s})=>{const l=fe();return e.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:i("fg")},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[o,r&&e.jsx("button",{onClick:r,style:nm,children:"AI"}),n&&e.jsx("button",{onClick:n,style:tm,children:l.action.save})]})]}),s]})},tm={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},nm={padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Je=({label:t,value:n,onChange:r,placeholder:o,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:l=>r(l.target.value),placeholder:o,disabled:s,style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),$t=({value:t,onChange:n,placeholder:r})=>{const o=h.useRef(null);return h.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:o,value:t||"",onChange:s=>n(s.target.value),placeholder:r,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Sn=({children:t,color:n,style:r})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||i("primary-soft"),color:i(n?"on-color-fg":"fg"),...r},children:t});function im(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const fn=({value:t,onChange:n,label:r})=>{const[o,s]=h.useState(!1),l=h.useRef(null),a=im(t||"");return h.useEffect(()=>{o&&l.current&&l.current.focus()},[o]),!o&&a?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:go,children:r}),e.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${i("input-border")}`,borderRadius:"2px",background:i("input-bg"),cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:i("fg")},children:a.name}),e.jsx(Sn,{children:a.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:go,children:r}),e.jsx("input",{ref:l,type:"text",value:t||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},go={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500};function rm(t){switch(t){case"url":return i("source-url");case"bookID":return i("source-bookid");default:return i("desc-fg")}}function om(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Sl=({items:t,onChange:n,onOpenEntityPicker:r})=>{const o=fe(),[s,l]=h.useState(null),a=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(t.length)},p=x=>{n(t.filter((m,g)=>g!==x)),s===x&&l(null)},c=(x,m,g)=>{const b=[...t];b[x]={...b[x],[m]:g},n(b)},d=(x,m)=>{const g=[...t];g[x]={...g[x],type:m,id:"",name:""},n(g),m==="bookID"&&r&&r(b=>{const k=[...t];k[x]={...k[x],id:b.id,name:b.title,type:"bookID"},n(k)})},u=x=>{r&&r(m=>{const g=[...t];g[x]={...g[x],id:m.id,name:m.title,type:"bookID"},n(g)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,m)=>e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===m?null:m),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===m?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:i("fg")},children:x.name||`${o.editor.sourcePlaceholder} ${m+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:rm(x.type),color:i("on-color-fg"),borderRadius:"3px",fontWeight:500},children:om(x.type)}),e.jsx("button",{onClick:g=>{g.stopPropagation(),p(m)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),s===m&&e.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:lt,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(m,"bookID"),style:{...fo,borderColor:i("source-bookid"),color:i("source-bookid")},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(m,"url"),style:{...fo,borderColor:i("source-url"),color:i("source-url")},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:lt,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const g=[...t];g[m]={...g[m],type:"",id:"",name:""},n(g)},style:bo,children:o.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:i("bg"),border:`1px solid ${i("source-bookid")}`,borderRadius:"6px"},children:[e.jsx("span",{style:{color:i("source-bookid"),fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:x.name}),e.jsx("code",{style:{fontSize:"11px",background:i("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>u(m),style:{background:"transparent",border:`1px solid ${i("widget-border")}`,color:i("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:o.action.reselect})]}):e.jsxs("button",{onClick:()=>u(m),style:{width:"100%",padding:"14px",border:`2px dashed ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:o.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:lt,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const g=[...t];g[m]={...g[m],type:"",id:"",name:""},n(g)},style:bo,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:g=>c(m,"name",g.target.value),placeholder:o.editor.sourceNamePlaceholder,style:Tt})]}),e.jsxs("div",{children:[e.jsx("label",{style:lt,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:g=>c(m,"id",g.target.value),placeholder:"https://...",style:Tt})]})]}),x.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:`1px dashed ${i("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...lt,opacity:.7},children:o.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:lt,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:g=>c(m,"details",g.target.value),placeholder:o.editor.detailsPlaceholder,style:Tt})]}),e.jsxs("div",{children:[e.jsx("label",{style:lt,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:g=>c(m,"position",g.target.value),placeholder:"如: 卷三, p.52",style:Tt})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:lt,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:g=>c(m,"version",g.target.value),placeholder:"如: v1.0, 2024-01",style:Tt})]}),e.jsxs("div",{children:[e.jsx("label",{style:lt,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:g=>c(m,"processor_version",g.target.value),placeholder:"如: v0.1",style:Tt})]})]})]})]})})]},m)),e.jsxs("button",{onClick:a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addSource})]})]})},lt={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},Tt={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},fo={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:i("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},bo={background:"transparent",border:"none",color:i("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function $l(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(r=>({id:r.id||"",name:r.name||"",type:r.type||"",details:r.details||"",position:r.position||"",version:r.version||"",processor_version:r.processor_version||""}))}catch{}return[]}function _l(t){return!t||t.length===0?"":JSON.stringify(t)}const zl=({entityType:t,entityId:n,entityTitle:r,parentWork:o,parentCollection:s,belongsToWork:l,belongsToCollection:a,childWorks:p,childCollections:c,containedBooks:d,siblingBooks:u,onLinkEntity:x,onUnlinkEntity:m,onViewEntity:g,onCreateAndLink:b,onSaveRelations:k})=>{const y=fe();return e.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:y.section.relations})]}),k&&e.jsx("button",{onClick:k,style:sm,children:y.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Yt,{direction:"up",title:y.relation.belongsToWork,entity:l,onView:g,onUnlink:()=>m("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:r}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),e.jsx(Yt,{direction:"up",title:y.relation.containedInCollection,entity:a,onView:g,onUnlink:()=>m("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:r}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),l&&u&&u.length>0&&e.jsx(Nt,{direction:"horizontal",title:`${y.relation.siblingVersions} (${u.length})`,entities:u,onView:g,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:y.relation.addVersionForWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(Yt,{direction:"up",title:y.relation.parentWork,entity:o,onView:g,onUnlink:()=>m("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),p&&p.length>0&&e.jsx(Nt,{direction:"down",title:`${y.relation.childWorks} (${p.length})`,entities:p,onView:g,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:y.action.addSubWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),c&&c.length>0&&e.jsx(Nt,{direction:"down",title:`${y.relation.collectionImpl} (${c.length})`,entities:c,onView:g,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:y.action.addCollectionImpl,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),e.jsx(Nt,{direction:"down",title:`${y.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:g,onAdd:()=>b("childBook","book",{workId:n}),addLabel:y.action.addVersion,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(Yt,{direction:"up",title:y.relation.correspondingWork,entity:l,onView:g,onUnlink:()=>m("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:r}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),e.jsx(Yt,{direction:"up",title:y.relation.parentCollection,entity:s,onView:g,onUnlink:()=>m("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),e.jsx(Nt,{direction:"down",title:`${y.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:g,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:y.action.addSubCollection,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),e.jsx(Nt,{direction:"down",title:`${y.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:g,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:y.action.addBook,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]})]})]})},Yt=({direction:t,title:n,entity:r,onView:o,onUnlink:s,onLink:l,onCreate:a,linkLabel:p,createLabel:c,notLinkedLabel:d,viewLabel:u,unlinkLabel:x})=>{const m=i(t==="up"?"relation-up":t==="down"?"relation-down":"relation-flat"),g=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[e.jsxs("div",{style:{fontSize:"12px",color:m,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:g}),e.jsx("span",{children:n})]}),r?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:i("bg"),borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Cl(r.type)}),e.jsx("span",{style:{fontWeight:500},children:r.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:r.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(yo,{onClick:()=>o(r),title:u,children:"👁️"}),e.jsx(yo,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(wi,{onClick:l,children:p}),e.jsx(wi,{onClick:a,primary:!0,children:c})]})]})},Nt=({direction:t,title:n,entities:r,onView:o,onAdd:s,addLabel:l,noneLabel:a,expandMoreLabel:p})=>{const[c,d]=h.useState(!1),u=i(t==="up"?"relation-up":t==="down"?"relation-down":"relation-flat"),x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",m=c?r:r.slice(0,5);return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[e.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),r.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[m.map(g=>e.jsxs("div",{onClick:()=>o(g),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:i("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:Cl(g.type)}),e.jsx("span",{children:g.title})]},g.id)),r.length>5&&!c&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:i("link-fg"),cursor:"pointer"},children:[p," (",r.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:a}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(wi,{onClick:s,primary:!0,children:["+ ",l]})})]})},yo=({onClick:t,title:n,danger:r,children:o})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:r?i("danger"):"inherit",opacity:.7},children:o}),wi=({onClick:t,primary:n,children:r})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${i("widget-border")}`,borderRadius:"4px",background:n?i("primary"):"transparent",color:n?i("primary-fg"):"inherit",cursor:"pointer"},children:r});function Cl(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const sm={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Tl=({isOpen:t,entityType:n,title:r,onSelect:o,onCancel:s,onCreate:l,searchResults:a,onSearch:p,isLoading:c,excludeId:d})=>{const[u,x]=h.useState(""),m=d?a.filter(y=>y.id!==d):a;h.useEffect(()=>{t&&(x(""),p(""))},[t]);const g=y=>{x(y),p(y)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",k=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:lm,children:e.jsxs("div",{style:am,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:r}),e.jsx("button",{onClick:s,style:cm,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:u,onChange:y=>g(y.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:dm})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?e.jsx("div",{style:ei,children:"搜索中..."}):m.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:m.map(y=>e.jsxs("div",{onClick:()=>o(y),style:pm,children:[e.jsx("span",{style:{fontSize:"16px"},children:k}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[y.title,y.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:y.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[y.id,y.author&&` · ${y.author}`,y.dynasty&&` · ${y.dynasty}`]})]})]},y.id))}):u?e.jsxs("div",{style:ei,children:["未找到匹配的",b]}):e.jsxs("div",{style:ei,children:["输入关键词搜索",b]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:l,style:um,children:["创建新",b,"并关联"]})]})]})})},lm={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},am={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},cm={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},dm={width:"100%",padding:"10px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},pm={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:i("primary-soft")},ei={padding:"20px",textAlign:"center",color:i("desc-fg")},um={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},jo={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},mm={work:"📜",book:"📖",collection:"📚",entity:"👤"},Nl=({isOpen:t,entityType:n,relationField:r,inheritData:o,onConfirm:s,onCancel:l})=>{const[a,p]=h.useState(""),c=h.useRef(null);h.useEffect(()=>{t&&(p((o==null?void 0:o.title)||""),setTimeout(()=>{var m,g;(m=c.current)==null||m.focus(),(g=c.current)==null||g.select()},100))},[t,o==null?void 0:o.title]);const d=m=>{m.key==="Enter"&&a.trim()?u():m.key==="Escape"&&l()},u=()=>{a.trim()&&s(a.trim(),{...o,title:a.trim()})};if(!t)return null;const x=()=>{switch(r){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${jo[n]}`}};return e.jsx("div",{style:xm,onClick:m=>{m.target===m.currentTarget&&l()},children:e.jsxs("div",{style:hm,onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:mm[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:i("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:i("danger"),marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:c,type:"text",value:a,onChange:m=>p(m.target.value),onKeyDown:d,placeholder:`请输入${jo[n]}名称...`,style:gm})]}),((o==null?void 0:o.author)||(o==null?void 0:o.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),background:i("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(o==null?void 0:o.author)&&e.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:l,style:fm,children:"取消"}),e.jsx("button",{onClick:u,disabled:!a.trim(),style:{...bm,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},xm={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},hm={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:i("shadow-dialog")},gm={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box"},fm={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},bm={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg")};function ym(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Il(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function jm(t){switch(t){case"work":return i("editor-type-work");case"collection":return i("editor-type-collection");case"book":return i("editor-type-book");default:return i("desc-fg")}}const El=({isOpen:t,title:n,filterType:r="all",recentEntities:o=[],excludeId:s,showCreateButton:l=!1,createButtonText:a,onSelect:p,onCancel:c,onCreate:d,onSearch:u})=>{const[x,m]=h.useState(""),[g,b]=h.useState([]),[k,y]=h.useState(!1),[j,f]=h.useState("recent");h.useEffect(()=>{t&&(m(""),b([]),f(o.length>0?"recent":"search"))},[t,o.length]),h.useEffect(()=>{if(!x.trim()){b([]);return}const z=setTimeout(async()=>{y(!0);try{b(await u(x,r))}catch{b([])}finally{y(!1)}},300);return()=>clearTimeout(z)},[x,r,u]);const v=h.useCallback(z=>{m(z.target.value),z.target.value.trim()&&f("search")},[]),$=h.useCallback(z=>s?z.filter(E=>E.id!==s):z,[s]);if(!t)return null;const w=n||(r==="all"?"选择实体":`选择${Il(r)}`),_=$(o),S=$(g);return e.jsx("div",{style:km,children:e.jsxs("div",{style:wm,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:w}),e.jsx("button",{onClick:c,style:Sm,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:$m}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),k&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),_.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsxs(vo,{active:j==="recent",onClick:()=>f("recent"),children:["最近使用 (",_.length,")"]}),e.jsxs(vo,{active:j==="search",onClick:()=>f("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&_.length>0?e.jsx(ko,{entities:_,onSelect:p}):x.trim()?k?e.jsx(ti,{message:"搜索中..."}):S.length>0?e.jsx(ko,{entities:S,onSelect:p}):e.jsx(ti,{message:"未找到匹配的结果"}):e.jsx(ti,{message:"输入关键词开始搜索"})}),l&&d&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:d,style:_m,children:a||"创建新实体"})]})]})})},vo=({active:t,onClick:n,children:r})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(t?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:r}),ko=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(r=>e.jsx(vm,{entity:r,onClick:()=>n(r)},r.id))}),vm=({entity:t,onClick:n})=>{const[r,o]=h.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i("primary-soft"),transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:ym(t.type)}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[t.title,t.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:t.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[e.jsx("code",{style:{fontSize:"10px",background:i("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:t.id}),t.author&&e.jsx("span",{children:t.author}),t.dynasty&&e.jsx("span",{children:t.dynasty})]})]}),e.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:jm(t.type),color:i("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Il(t.type)})]})},ti=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:t}),km={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},wm={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},Sm={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},$m={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},_m={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},zm={work:i("editor-type-work"),collection:i("editor-type-collection"),book:i("editor-type-book"),entity:i("editor-type-entity")},Cm={work:"📜",collection:"📚",book:"📖",entity:"👤"},Rl=({data:t,onChange:n,onSave:r,transport:o,onNavigate:s,showDelete:l,onDelete:a,onAskAI:p,renderSectionActions:c,onDownloadResource:d,downloadStatuses:u,relations:x,onRelationsChange:m})=>{var ke;const g=fe(),[b,k]=h.useState(!1),[y,j]=h.useState("work"),[f,v]=h.useState(""),[$,w]=h.useState(""),[_,S]=h.useState([]),[z,E]=h.useState(!1),[T,N]=h.useState(!1),[V,W]=h.useState("work"),[B,H]=h.useState(""),[te,se]=h.useState(),[J,D]=h.useState(!1),[L,le]=h.useState(null),[A,ne]=h.useState([]);h.useRef(null);const de=t.type,G=de==="work",he=de==="collection",ye=de==="book",xe=h.useCallback((Y,I)=>{n({...t,[Y]:I})},[t,n]),pe=h.useCallback((Y,I)=>{v(Y),j(I),w(g.editor.selectToLink+g.indexType[I]),S([]),k(!0)},[g]),$e=h.useCallback(Y=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,Y)},[o,t.id]),Oe=h.useCallback(Y=>{s==null||s(Y.id,Y.type)},[s]),Ae=h.useCallback((Y,I,U)=>{const ge={...U,author:(U==null?void 0:U.author)||t.author,dynasty:U==null?void 0:U.dynasty};W(I),H(Y),se(ge),N(!0)},[t.author]),Me=h.useCallback((Y,I)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,B,{type:V,title:Y,inheritData:I}),N(!1)},[o,t.id,B,V]),ve=h.useCallback(Y=>{if(!Y.trim()){S([]);return}E(!0),o!=null&&o.searchEntities&&o.searchEntities(Y,y).then(I=>{S(I),E(!1)}).catch(()=>{S([]),E(!1)})},[o,y]),Be=h.useCallback(Y=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,f,Y.id),k(!1)},[o,t.id,f]),P=h.useCallback(()=>{r()},[r]),ae=h.useCallback(Y=>{le(()=>Y),D(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(ne).catch(()=>{})},[o]),ie=h.useCallback((Y,I)=>o!=null&&o.searchEntities?o.searchEntities(Y,I==="all"?void 0:I):Promise.resolve([]),[o]),_e=h.useCallback(Y=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(Y),ne(I=>[Y,...I.filter(U=>U.id!==Y.id)].slice(0,10)),L==null||L(Y),D(!1),le(null)},[o,L]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${i("widget-border")}`,paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Cm[de]}),e.jsx("span",{children:t.title||g.editor.untitled}),e.jsx(Sn,{children:t.id}),e.jsx(Sn,{color:zm[de],children:g.indexType[de]})]})}),e.jsx(tt,{title:g.section.basicInfo,onSave:r,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(fn,{label:G?g.editor.workTitle:he?g.editor.collectionTitle:g.editor.bookTitle,value:t.title,onChange:Y=>xe("title",Y)}),ye&&e.jsx(fn,{label:g.editor.belongsToWork,value:t.workName||"",onChange:Y=>xe("workName",Y)}),e.jsx(Je,{label:g.editor.authorLabel,value:t.author||"",onChange:Y=>xe("author",Y)}),e.jsx(Je,{label:g.editor.publicationYearLabel,value:t.publicationYear||"",onChange:Y=>xe("publicationYear",Y)}),(ye||he)&&e.jsx(fn,{label:g.editor.containedIn,value:t.collection||"",onChange:Y=>xe("collection",Y)}),(ye||he)&&e.jsx(Je,{label:g.editor.holderLabel,value:t.holder||"",onChange:Y=>xe("holder",Y)}),(ye||he)&&e.jsx(Je,{label:ye?g.editor.pageLabel:g.editor.volumeLabel,value:t.pages||"",onChange:Y=>xe("pages",Y)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(Je,{label:g.editor.firstImageLabel,value:t.firstImage||"",onChange:Y=>xe("firstImage",Y)})})]})}),e.jsx(tt,{title:g.section.description,onSave:r,onAskAI:p?()=>p("介绍"):void 0,children:e.jsx($t,{value:t.description||"",onChange:Y=>xe("description",Y),placeholder:g.editor.descriptionPlaceholder})}),(((ke=t.additional_works)==null?void 0:ke.length)||0)>0&&e.jsx(tt,{title:g.section.additionalWorks,onSave:r,children:e.jsx(Tm,{items:t.additional_works||[],onChange:Y=>xe("additional_works",Y)})}),e.jsx(tt,{title:g.section.indexedBy,onSave:r,onAskAI:p?()=>p("收录于"):void 0,children:e.jsx(Nm,{items:t.indexed_by||[],onChange:Y=>xe("indexed_by",Y)})}),e.jsx(tt,{title:g.section.emendatedBy,onSave:r,onAskAI:p?()=>p("考证"):void 0,children:e.jsx(Im,{items:t.emendated_by||[],onChange:Y=>xe("emendated_by",Y)})}),e.jsx(tt,{title:g.section.textResources,onSave:r,onAskAI:p?()=>p("资源"):void 0,children:e.jsx(ai,{items:t.resources||[],onChange:Y=>xe("resources",Y),onDownload:d,downloadStatuses:u,filterType:"text"})}),e.jsx(tt,{title:g.section.imageResources,onSave:r,children:e.jsx(ai,{items:t.resources||[],onChange:Y=>xe("resources",Y),onDownload:d,downloadStatuses:u,filterType:"image"})}),e.jsx(tt,{title:g.section.sources,onSave:r,onAskAI:p?()=>p("资料来源"):void 0,children:e.jsx(Sl,{items:$l(t.sources||""),onChange:Y=>xe("sources",_l(Y)),onOpenEntityPicker:ae})}),(ye||he)&&e.jsx(tt,{title:g.section.provenance,onSave:r,onAskAI:p?()=>p("收藏历史"):void 0,children:e.jsx($t,{value:t.provenance||"",onChange:Y=>xe("provenance",Y),placeholder:g.editor.provenancePlaceholder})}),ye&&e.jsx(tt,{title:g.section.otherEditions,onSave:r,onAskAI:p?()=>p("其他版本"):void 0,children:e.jsx($t,{value:t.otherEditions||"",onChange:Y=>xe("otherEditions",Y),placeholder:g.editor.otherEditionsPlaceholder})}),e.jsx(zl,{entityType:de,entityId:t.id,entityTitle:t.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:pe,onUnlinkEntity:$e,onViewEntity:Oe,onCreateAndLink:Ae,onSaveRelations:P}),l&&a&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${i("danger-soft-border")}`,background:i("danger-soft-bg"),borderRadius:"4px"},children:[e.jsx("div",{style:{color:i("danger"),fontWeight:600,marginBottom:"8px"},children:g.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"12px"},children:g.editor.dangerZoneDesc}),e.jsx("button",{onClick:a,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("danger")}`,borderRadius:"4px",background:"transparent",color:i("danger"),cursor:"pointer"},children:g.editor.deleteEntity})]}),e.jsx(Tl,{isOpen:b,entityType:y,title:$,onSelect:Be,onCancel:()=>k(!1),onCreate:()=>{k(!1),Ae(f,y)},searchResults:_,onSearch:ve,isLoading:z,excludeId:t.id}),e.jsx(Nl,{isOpen:T,entityType:V,relationField:B,inheritData:te,onConfirm:Me,onCancel:()=>N(!1)}),e.jsx(El,{isOpen:J,title:g.action.selectBookOrWork,filterType:"all",recentEntities:A,excludeId:t.id,onSelect:_e,onCancel:()=>{D(!1),le(null)},onSearch:ie})]})};function Tm({items:t,onChange:n}){const r=fe(),o=(a,p,c)=>{const d=t.map((u,x)=>x===a?{...u,[p]:c}:u);n(d)},s=a=>n(t.filter((p,c)=>c!==a)),l=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((a,p)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(Je,{label:r.editor.bookNameLabel,value:a.book_title,onChange:c=>o(p,"book_title",c)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(Je,{label:r.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:c=>o(p,"n_juan",c&&parseInt(c,10)||void 0)})}),e.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("muted"),marginTop:"18px"},children:"✕"})]},p)),e.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:r.action.addAdditionalWork})]})}function Ll({items:t,onChange:n,showMeta:r,addLabel:o}){const s=fe(),[l,a]=h.useState(null),p=(u,x,m)=>{const g=t.map((b,k)=>k===u?{...b,[x]:m||void 0}:b);n(g)},c=u=>{n(t.filter((x,m)=>m!==u)),l===u&&a(null)},d=()=>{n([...t,{source:""}]),a(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((u,x)=>{const m=l===x;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:m?`color-mix(in srgb, ${i("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>a(m?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.2s",transform:m?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:u.source_bid}),e.jsx("button",{onClick:g=>{g.stopPropagation(),c(x)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${i("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:i("muted")},children:"✕"})]}),!m&&r&&(u.title_info||u.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:i("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),m&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(Je,{label:s.label.sourceName,value:u.source,onChange:g=>p(x,"source",g)}),e.jsx(Je,{label:s.label.sourceBid,value:u.source_bid||"",onChange:g=>p(x,"source_bid",g)})]}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(Je,{label:s.label.titleInfo,value:u.title_info||"",onChange:g=>p(x,"title_info",g)}),e.jsx(Je,{label:s.label.authorInfo,value:u.author_info||"",onChange:g=>p(x,"author_info",g)})]}),e.jsx(Je,{label:s.label.edition,value:u.edition||"",onChange:g=>p(x,"edition",g)})]}),e.jsx($t,{value:u.summary||"",onChange:g=>p(x,"summary",g),placeholder:s.editor.summaryPlaceholder}),e.jsx($t,{value:u.comment||"",onChange:g=>p(x,"comment",g),placeholder:s.editor.commentPlaceholder}),e.jsx($t,{value:u.additional_comment||"",onChange:g=>p(x,"additional_comment",g),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:o})]})}function Nm({items:t,onChange:n}){const r=fe();return e.jsx(Ll,{items:t,onChange:n,showMeta:!0,addLabel:r.action.addIndexedBy})}function Im({items:t,onChange:n}){const r=fe();return e.jsx(Ll,{items:t,onChange:n,addLabel:r.action.addEmendatedBy})}function Al(t){var p,c,d,u,x,m,g;const n=((c=(p=t.authors)==null?void 0:p[0])==null?void 0:c.name)||"",r=((d=t.publication_info)==null?void 0:d.year)||"",o=((u=t.current_location)==null?void 0:u.name)||"",s=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((m=t.page_count)==null?void 0:m.description)||"",l=typeof t.description=="object"&&t.description!==null&&t.description.text||"",a={id:t.id,title:t.title,type:t.type,author:n,publicationYear:r,holder:o,pages:s,description:l,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const b=t;if(Array.isArray(b.related_works)){const k=b.related_works.find(y=>y.relation==="part_of");k&&(a.parentWorkId=k.id,a.parentWorkName=k.title)}}if(t.type==="book"){const b=t;a.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(a.collectionId=(g=b.contained_in[0])==null?void 0:g.id)}return a}function Em(t){const n={id:t.id,title:t.title,type:t.type,description:t.description?{text:t.description}:void 0,authors:t.author?[{name:t.author}]:void 0,publication_info:t.publicationYear?{year:t.publicationYear}:void 0,current_location:t.holder?{name:t.holder}:void 0,page_count:t.pages?{number:parseInt(t.pages)||0,description:t.pages}:void 0,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};return t.type==="work"&&t.parentWorkId&&(n.related_works=[{id:t.parentWorkId,title:t.parentWorkName||"",relation:"part_of"}]),t.type==="book"&&(n.work_id=t.workId,t.collectionId&&(n.contained_in=[{id:t.collectionId}])),n}const Rm=t=>{const{data:n,id:r,transport:o,mode:s="view",onModeChange:l,onChange:a,onSave:p,onDelete:c,onNavigate:d,renderLink:u,onAskAI:x,renderSectionActions:m,onDownloadResource:g,downloadStatuses:b,relations:k,onRelationsChange:y,headerExtra:j,className:f,style:v}=t;fe();const[$,w]=h.useState(s),_=l?s:$;h.useEffect(()=>{s!==$&&w(s)},[s]);const S=h.useCallback(()=>{const B=_==="view"?"edit":"view";l?l(B):w(B)},[_,l]),[z,E]=h.useState(null);h.useEffect(()=>{r&&o&&o.getItem(r).then(B=>{B&&E(B)})},[r,o]);const T=n||z,N=h.useMemo(()=>T?Al(T):null,[T]),V=l||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:_==="edit"?i("accent-bg"):"transparent",color:i(_==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?"切换到编辑模式":"切换到查看模式",children:_==="view"?"✏️ 编辑":"👁 查看"}):null,W=e.jsxs(e.Fragment,{children:[V,j]});return!T&&!N?e.jsx(zt,{}):_==="view"?e.jsx(Oi,{data:T,transport:o,onNavigate:d?B=>d(B):void 0,renderLink:u,headerExtra:W,className:f,style:v}):N?e.jsxs("div",{className:f,style:v,children:[W&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:W}),e.jsx(Rl,{data:N,onChange:a||(()=>{}),onSave:p||(()=>{}),transport:o,onNavigate:d,showDelete:!!c,onDelete:c,onAskAI:x,renderSectionActions:m,onDownloadResource:g,downloadStatuses:b,relations:k,onRelationsChange:y})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:i("muted")},children:"无数据"})},wo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Bl=({isOpen:t,onClose:n,onSubmit:r,feedbackListUrl:o})=>{const[s,l]=h.useState(null),[a,p]=h.useState(""),[c,d]=h.useState(""),[u,x]=h.useState("idle"),[m,g]=h.useState(""),b=h.useRef(null);h.useEffect(()=>{t&&(l(null),p(""),d(""),x("idle"),g(""))},[t]),h.useEffect(()=>{s&&setTimeout(()=>{var f;return(f=b.current)==null?void 0:f.focus()},100)},[s]),h.useEffect(()=>{if(u==="success"){const f=setTimeout(n,2e3);return()=>clearTimeout(f)}},[u,n]),h.useEffect(()=>{if(!t)return;const f=v=>{v.key==="Escape"&&n()};return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[t,n]);const k=async()=>{if(!(!s||!a.trim())){x("submitting"),g("");try{await r({type:s,content:a.trim(),...c.trim()?{contact:c.trim()}:{}}),x("success")}catch(f){x("error"),g(f instanceof Error?f.message:"提交失败,请稍后重试")}}};if(!t)return null;const y=s&&a.trim()&&u!=="submitting",j=wo.find(f=>f.value===s);return e.jsx("div",{style:Lm,onClick:f=>{f.target===f.currentTarget&&n()},children:e.jsxs("div",{style:Am,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{style:Bm,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Mm,"aria-label":"关闭",children:"✕"})]}),u==="success"?e.jsxs("div",{style:Dm,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),o&&e.jsx("a",{href:o,style:{fontSize:"13px",color:i("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:wo.map(f=>e.jsxs("button",{onClick:()=>l(f.value),style:{...Wm,...s===f.value?Om:{}},children:[e.jsx("span",{children:f.icon})," ",f.label]},f.value))}),e.jsx("textarea",{ref:b,value:a,onChange:f=>p(f.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...Fm,opacity:s?1:.6}}),e.jsx("input",{type:"text",value:c,onChange:f=>d(f.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:Gm}),e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[a.length," / 2000"]}),u==="error"&&e.jsx("div",{style:Hm,children:m}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:k,disabled:!y,style:{...Pm,opacity:y?1:.6,cursor:y?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},Lm={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Am={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:i("shadow-dialog")},Bm={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Mm={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:i("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Wm={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Om={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Fm={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Pm={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},Dm={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:i("success")},Hm={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Gm={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},Si="--bim-feedback-fab-offset",$i=48,Um=16,Vm=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:r,hidden:o=!1,zIndex:s})=>{const[l,a]=h.useState(!1),p=n.bottom??24;return h.useEffect(()=>{if(o||typeof document>"u")return;const c=document.documentElement;return c.style.setProperty(Si,`calc(${p+$i+Um}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(Si)}},[o,p]),e.jsxs(e.Fragment,{children:[!o&&e.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>a(!0),style:{...Ym,zIndex:s??i("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),e.jsx(Bl,{isOpen:l,onClose:()=>a(!1),onSubmit:t,feedbackListUrl:r})]})},Ym={position:"fixed",width:`${$i}px`,height:`${$i}px`,borderRadius:"50%",border:"none",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:i("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},So=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ml=({onSubmit:t})=>{const[n,r]=h.useState("bug"),[o,s]=h.useState(""),[l,a]=h.useState(""),[p,c]=h.useState("idle"),[d,u]=h.useState(""),x=h.useRef(null);h.useEffect(()=>{n&&setTimeout(()=>{var k;return(k=x.current)==null?void 0:k.focus()},100)},[n]);const m=async()=>{if(!(!n||!o.trim())){c("submitting"),u("");try{await t({type:n,content:o.trim(),...l.trim()?{contact:l.trim()}:{}}),c("success"),s(""),a(""),r("bug")}catch(k){c("error"),u(k instanceof Error?k.message:"提交失败,请稍后重试")}}},g=n&&o.trim()&&p!=="submitting",b=So.find(k=>k.value===n);return p==="success"?e.jsx("div",{style:$o,children:e.jsxs("div",{style:Xm,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>c("idle"),style:Qm,children:"继续提交"})]})}):e.jsxs("div",{style:$o,children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:So.map(k=>e.jsxs("button",{onClick:()=>r(k.value),style:{...Km,...n===k.value?qm:{}},children:[e.jsx("span",{children:k.icon})," ",k.label]},k.value))}),e.jsx("textarea",{ref:x,value:o,onChange:k=>s(k.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...Jm}}),e.jsx("input",{type:"text",value:l,onChange:k=>a(k.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:tx}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[o.length," / 2000"]}),e.jsx("button",{onClick:m,disabled:!g,style:{...Zm,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&e.jsx("div",{style:ex,children:d})]})},$o={padding:"16px",border:`1px solid ${i("widget-border")}`,borderRadius:"8px",background:i("input-bg")},Km={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},qm={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Jm={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Zm={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},Xm={display:"flex",alignItems:"center",gap:"12px",color:i("success"),fontSize:"14px"},Qm={background:"none",border:"none",color:i("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ex={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginTop:"8px"},tx={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function _o(t){return typeof t=="function"?t():t??"/api/feedback"}const Wl=({resourceId:t,apiUrl:n})=>{const[r,o]=h.useState([]),[s,l]=h.useState(!0),a=h.useCallback(async()=>{const c=_o(n);l(!0);try{const u=await(await fetch(`${c}?resourceId=${encodeURIComponent(t)}`)).json();u.success&&o(u.items)}catch{}finally{l(!1)}},[t,n]);h.useEffect(()=>{a()},[a]);const p=async c=>{const d=_o(n),u=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...c,pageUrl:typeof window<"u"?window.location.href:"",resourceId:t})});if(!u.ok){const x=await u.json().catch(()=>null);throw new Error((x==null?void 0:x.error)||"提交失败")}setTimeout(()=>a(),500)};return e.jsxs("div",{children:[e.jsx(pr,{items:r,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(Ml,{onSubmit:p})})]})},zo={part_of:"所屬",has_part:"包含",contains_text_of:"收錄",collected_in:"叢編",text_carried_by:"載錄",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"後繼",derived_from:"衍生",has_adaptation:"改編",related:"相關"};function Co(t){return t?zo[t]??t:zo.related}const nx={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function ix(t){return nx[t]??t}const rx={text:"文本",image:"影印",textImage:"圖文",physical:"館藏"};function ox(t){return rx[t]??""}function ur({authors:t,onNavigate:n,renderLink:r}){const{convert:o}=O(),s=(t||[]).filter(l=>l&&l.name);return s.length?e.jsx(e.Fragment,{children:s.map((l,a)=>{const p=Ki(l.role);return e.jsxs(h.Fragment,{children:[a>0&&" ",l.dynasty&&e.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",o(l.dynasty),"〕"]}),l.entity_id?e.jsx(De,{id:l.entity_id,label:o(l.name),onNavigate:n,renderLink:r,dense:!0}):o(l.name),p&&e.jsx("span",{style:{marginLeft:4},children:o(p)})]},a)})}):null}function Ol(t,n){var p,c;const r=Vi(t,n),o=r.mirrors.map(d=>({key:d.key,label:d.label,description:d.description,rows:d.items.filter(u=>u.group_role!=="mirror"),mirrors:d.items.filter(u=>u.group_role==="mirror")})),s=r.buckets.filter(d=>d.key==="image"||d.key==="textImage").flatMap(d=>d.items);s.length&&o.push({key:"_images",label:o.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=r.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&o.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((c=r.buckets.find(d=>d.key==="text"))==null?void 0:c.items)??[],groups:o}}function Fl(t,n){const r=(t.url?Mt(t.url):void 0)||t.name,o=Us(t,n);return o?`${r}(${o})`:r}function mr({item:t,siblings:n,listedVolumeCounts:r}){const{convert:o}=O(),[s,l]=h.useState(!1),a=_n(t),p=!!a&&a.expected>0&&!(r!=null&&r.has(a.expected)),c=o(Fl(t,n)),d=Wt(t),u=Ln(t)||t.details;return e.jsxs("tr",{children:[e.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var m,g;const x=(m=t.metadata)!=null&&m.fragment||t.color_mode?e.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((g=t.metadata)==null?void 0:g.fragment)&&e.jsx("span",{className:"bim-d-tag",children:o("殘片")}),t.color_mode&&e.jsx("span",{className:"bim-d-tag",children:o(t.color_mode==="color"?"彩色":"黑白")})]}):null;return d?e.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[c," ",e.jsx("span",{"aria-hidden":"true",children:"↗"}),x]}):e.jsxs("span",{className:"bim-d-zt-name",children:[c,x]})})(),u&&e.jsx("span",{className:"bim-d-meta",children:o(u)}),p&&s&&e.jsx("div",{style:{padding:"0 12px 10px"},children:e.jsx(Qi,{item:t})})]}),e.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&e.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(x=>!x),children:o(s?"收起分冊":`展開 ${a.expected} 冊`)})})]})}function Pl({groups:t,listedVolumeCounts:n}){const{convert:r}=O();return e.jsx(e.Fragment,{children:t.map(o=>e.jsxs("div",{className:"bim-d-rg",children:[o.label&&e.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:r(o.label)}),o.description&&e.jsx("p",{className:"bim-d-rg-d",children:r(o.description)}),o.rows.length>0&&e.jsx("table",{className:"bim-d-zt",children:e.jsx("tbody",{children:o.rows.map((s,l)=>e.jsx(mr,{item:s,siblings:o.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),o.mirrors.length>0&&e.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[o.rows.length>0&&e.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:r("鏡像")}),o.mirrors.map((s,l)=>{const a=Wt(s),p=r(Fl(s,o.mirrors));return a?e.jsxs("a",{href:a,target:"_blank",rel:"noopener noreferrer",title:s.details?r(s.details):void 0,children:[p," ",e.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):e.jsx("span",{style:{marginRight:14},children:p},l)})]})]},o.key))})}const en=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function _i(t){var r;if(!t)return;const n=t.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(r=en.find(o=>n.startsWith(o.key[0])))==null?void 0:r.key}const To=12,sx=60,Dl=({data:t,transport:n,onNavigate:r,renderLink:o,readAction:s,railTop:l,back:a,railLinks:p})=>{var Me,ve,Be;const c=fe(),{convert:d}=O(),u=h.useMemo(()=>[...t.books||[],...t.collections||[]],[t.books,t.collections]),[x,m]=h.useState(new Map),[g,b]=h.useState(!1),[k,y]=h.useState(""),[j,f]=h.useState(!1),v=u.length<=sx,$=v||g||!!k||j,w=h.useMemo(()=>$?u:u.slice(0,To),[u,$]);h.useEffect(()=>{if(!n||w.length===0)return;const P=w.filter(ie=>!x.has(ie));if(P.length===0)return;let ae=!1;return Promise.all(P.map(ie=>n.getItem(ie).then(_e=>{const ke=_e??{};return[ie,{id:ie,title:ke.title,edition:ke.edition,resources:ke.resources,publication_info:ke.publication_info,current_location:ke.current_location,lineage:ke.lineage,measure_info:ke.measure_info}]}).catch(()=>[ie,{id:ie}]))).then(ie=>{ae||m(_e=>{const ke=new Map(_e);for(const[Y,I]of ie)ke.set(Y,I);return ke})}),()=>{ae=!0}},[n,w,x]);const _=h.useMemo(()=>u.map(P=>x.get(P)??{id:P}),[u,x]),S=u.length>0&&u.every(P=>x.has(P)),z=!!n&&w.some(P=>!x.has(P)),E=v||$,T=h.useMemo(()=>Ys(_,t.version_graph,{era:k,scanOnly:j,sort:E?"year":"default"}),[_,t.version_graph,k,j,E]),N=g?T.rows:T.rows.slice(0,To),V=T.allRows.filter(P=>P.hasImage).length,W=t.related_works||[],B=W.filter(P=>P.relation==="collected_in"),H=h.useMemo(()=>{const P=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],ae=ie=>{const _e=P.indexOf(ie??"");return _e<0?P.length:_e};return W.filter(ie=>ie.relation!=="collected_in").map((ie,_e)=>({r:ie,i:_e})).sort((ie,_e)=>ae(ie.r.relation)-ae(_e.r.relation)||ie.i-_e.i).map(ie=>ie.r)},[W]),te=h.useMemo(()=>{const P=Vi(t.resources,t.resource_groups);return[...P.mirrors.flatMap(ae=>ae.items.map(ie=>({r:ie,kind:d(ae.label)}))),...P.buckets.flatMap(ae=>ae.items.map(ie=>({r:ie,kind:d(ox(ae.key))})))]},[t.resources,t.resource_groups,d]),se=t.indexed_by||[],J=t.emendated_by||[],D=h.useMemo(()=>{var ge,we,R;const P=[],ae=(we=(ge=t.authors)==null?void 0:ge[0])==null?void 0:we.dynasty;ae&&P.push({label:"成書",value:d(ae)});const ie=ut(t,c.unit.juan);if(ie){const oe=(R=t.juan_count)==null?void 0:R.description;P.push({label:"卷帙",value:e.jsxs(e.Fragment,{children:[d(ie),oe&&oe!==ie?e.jsxs("span",{className:"bim-d-meta",children:["(",d(oe),")"]}):null]})})}t.loss_status&&P.push({label:"存佚",value:d(ix(t.loss_status))});const _e=T.allRows.filter(oe=>oe.sortYear!=null),ke=_e.length>0?_e.reduce((oe,K)=>oe.sortYear<=K.sortYear?oe:K):null;ke!=null&&ke.era.era?P.push({label:"最早存世",value:d([ke.era.era,ke.era.reign].filter(Boolean).join(" ")),title:ke.era.source==="edition"?d("據版本題名推斷"):void 0}):z&&P.push({label:"最早存世",value:e.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),J.length&&P.push({label:"考證",value:`${J.length} ${d("條")}`});const Y=No(t.additional_titles);Y.length&&P.push({label:"又名",value:Y.map(d).join("、")});const I=No(t.attached_texts);I.length&&P.push({label:"附載",value:I.map(d).join("、")});const U=(t.additional_works||[]).map(oe=>d(oe.book_title)+(oe.n_juan!=null?` ${oe.n_juan}${d(c.unit.juan)}`:""));return U.length&&P.push({label:"附錄",value:U.join("、")}),P},[t,d,c,z,T.allRows,J.length]),le=[{value:t._edition_count??u.length,label:"版本"},{value:S?V:0,label:"有影印"},{value:se.length,label:"家著錄"}],A=t.classification,ne=A?[A.l1,A.l2,A.l3,A.l4].filter(Boolean).map(P=>d(P)):[],de=t.subtype?d(c.workSubtype[t.subtype]??t.subtype):"",G=e.jsx(on,{title:d(t.title),byline:e.jsx(ur,{authors:t.authors,onNavigate:r,renderLink:o}),meta:e.jsx(Ue,{items:[...ne,A!=null&&A.source?d(`據《${A.source.split("/")[0]}》`):"",de]}),description:(Me=t.description)!=null&&Me.text?e.jsxs(e.Fragment,{children:[e.jsx(pt,{text:t.description.text,style:{fontSize:15,lineHeight:1.85}}),(ve=t.description.sources)!=null&&ve.length?e.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:t.description.sources.map(P=>d(dp(P))).filter(Boolean).join(" · ")}):null]}):void 0,stats:le,facts:D,readAction:s,foot:e.jsx(sn,{revision:t.revision,revisedAt:t.revised_at,review:t.review,todo:t.todo}),children:(Be=t.appendix)==null?void 0:Be.map((P,ae)=>e.jsxs("details",{style:{marginTop:12},children:[e.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(P.title)}),e.jsx(pt,{text:P.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},ae))}),he=T.eras.length>=2?[{key:"",label:c.catalog.all},...T.eras.map(P=>({key:P,label:`${P} ${T.allRows.filter(ae=>ae.era.era===P).length}`}))]:[],ye=[];u.length&&ye.push({id:"versions",label:"版本",count:u.length}),se.length&&ye.push({id:"catalogs",label:"著錄",count:se.length}),B.length&&ye.push({id:"collected",label:"收入叢編",count:B.length}),H.length&&ye.push({id:"related",label:"相關書目",count:H.length}),te.length&&ye.push({id:"resources",label:"在線資源",count:te.length});const xe=u.length===0&&se.length===0,pe=e.jsxs(e.Fragment,{children:[u.length>0&&e.jsxs(Ve,{id:"versions",title:"版本",meta:e.jsx(Ue,{items:[d(`共 ${u.length} 種`),S&&V?d(`${V} 種有影印`):"",T.rows.length!==T.allRows.length?d(`當前 ${T.rows.length} 種`):""]}),children:[e.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&he.length===0&&u.length>1?"":void 0,children:[he.length>0&&e.jsx(Bn,{items:he,value:k,onChange:P=>{y(P),b(!1)}}),e.jsx("span",{className:"bim-d-spacer"}),e.jsx(el,{label:"只看有影印",checked:j,onChange:P=>{f(P),b(!1)}}),e.jsx("span",{className:"bim-d-meta",children:d(E?"按年代排列":"按著錄順序")})]}),e.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!g&&Mn(T.rows.length)?"":void 0,children:[e.jsx("thead",{className:"bim-d-ui",children:e.jsxs("tr",{children:[e.jsx("th",{children:d("版本")}),e.jsx("th",{children:d("年代")}),e.jsx("th",{children:d("館藏")}),e.jsx("th",{children:e.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:d("影印")})})]})}),e.jsx("tbody",{children:N.map(P=>{var ae;return e.jsx(lx,{row:P,measure:(ae=x.get(P.id))==null?void 0:ae.measure_info,loaded:x.has(P.id),onNavigate:r,renderLink:o},`${P.id}:${x.has(P.id)?"r":"p"}`)})})]}),N.length===0&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(k||j?"當前篩選下沒有版本":"暫無版本著錄")}),!g&&e.jsx(qi,{total:T.rows.length,shown:N.length,unit:"種版本",onClick:()=>b(!0)}),T.hasInferredEra&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:d("部分年代據版本題名推斷,非著錄原文")})]}),se.length>0&&e.jsx(ax,{items:se,transport:n,onNavigate:r,renderLink:o}),xe&&e.jsx(Ve,{title:"版本",children:e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),$e=(P,ae)=>e.jsx(De,{id:P,label:d(ae),onNavigate:r,renderLink:o,dense:!0}),Oe=h.useMemo(()=>{const P=new Map;for(const ae of H){const ie=Co(ae.relation);P.set(ie,(P.get(ie)??0)+1)}return P.size>1?[...P.entries()].sort((ae,ie)=>ie[1]-ae[1]).slice(0,4).map(([ae,ie])=>`${d(ae)} ${ie}`).join(" · "):void 0},[H,d]),Ae=e.jsxs(e.Fragment,{children:[e.jsx(St,{id:"collected",title:"收入叢編",items:B.map(P=>$e(P.id,P.title))}),e.jsx(St,{id:"related",title:"相關書目",meta:d(`${H.length} 部`),sub:Oe,items:H.map(P=>e.jsxs(e.Fragment,{children:[$e(P.id,P.title),e.jsx("span",{className:"bim-d-meta",title:P.note?d(P.note):void 0,children:d(Co(P.relation))})]}))}),e.jsx(St,{id:"resources",title:"在線資源",cap:6,items:te.map(({r:P,kind:ae})=>{const ie=d((P.url?Mt(P.url):void 0)||P.name),_e=Wt(P);return e.jsxs(e.Fragment,{children:[_e?e.jsxs("a",{href:_e,target:"_blank",rel:"noopener noreferrer",children:[ie," ",e.jsx("span",{"aria-hidden":"true",children:"↗"})]}):e.jsx("span",{children:ie}),ae&&e.jsx("span",{className:"bim-d-meta bim-d-kind",children:ae})]})})})]});return e.jsx(rn,{railTop:l,back:a,nav:ye,railLinks:p,main:pe,card:G,side:Ae})};function No(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Io(t,n){return n((t.url?Mt(t.url):void 0)||t.name)}function lx({row:t,measure:n,loaded:r,onNavigate:o,renderLink:s}){const{convert:l}=O(),a=[t.era.era,t.era.reign].filter(Boolean).join(" "),p=t.era.source==="edition",c=t.holders[0],d=c?Io(c,l):t.locationName?l(t.locationName):"",u=t.images[0],x=u?Wt(u):void 0,m=t.images.map(g=>Io(g,l)).join("、");return e.jsxs("tr",{"data-loading":r?void 0:"",children:[e.jsxs("td",{className:"bim-d-zt-main",children:[e.jsx(De,{id:t.id,label:l(t.name),onNavigate:o,renderLink:s,dense:!0}),n?e.jsx("span",{className:"bim-d-meta",children:l(n)}):e.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${a?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:a?l(a):r?e.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),e.jsxs("td",{className:`bim-d-zt-sub${d?"":" bim-d-zt-blank"}`,children:[d||(r?e.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),t.holders.length>1&&e.jsxs("span",{className:"bim-d-meta",children:[" +",t.holders.length-1]})]}),e.jsx("td",{className:t.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:t.hasImage&&(x?e.jsx("a",{className:"bim-d-flag",href:x,target:"_blank",rel:"noopener noreferrer",title:m,children:l("有影印")}):e.jsx("span",{className:"bim-d-flag",title:m,children:l("有影印")}))})]})}function ax({items:t,transport:n,onNavigate:r,renderLink:o}){const s=fe(),{convert:l}=O(),[a,p]=h.useState(0),c=Math.min(a,t.length-1),d=t[c],[u,x]=h.useState(new Map);return h.useEffect(()=>{if(!n)return;const m=[...new Set(t.map(b=>b.source_bid).filter(b=>!!b))];if(m.length===0)return;let g=!1;return Promise.all(m.map(b=>n.getItem(b).then(k=>{var y,j;return[b,((j=(y=k==null?void 0:k.authors)==null?void 0:y[0])==null?void 0:j.dynasty)??""]}).catch(()=>[b,""]))).then(b=>{g||x(new Map(b.filter(([,k])=>k)))}),()=>{g=!0}},[n,t]),e.jsx(Ve,{id:"catalogs",title:"著錄",meta:e.jsx(Ue,{items:[l(`歷代書目 ${t.length} 家`),l("按著錄順序")]}),children:e.jsxs("div",{className:"bim-d-lu",children:[e.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":l("著錄書目"),children:t.map((m,g)=>e.jsx("li",{role:"presentation",children:e.jsxs("button",{type:"button",role:"tab","aria-selected":g===c,"aria-label":l(m.source),onClick:()=>p(g),children:[e.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(m.source_bid??"")?l(u.get(m.source_bid??"")):" "}),e.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),e.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...l(m.source)].slice(0,9).map((b,k)=>e.jsx("span",{children:b},k))})]})},g))}),e.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&e.jsx("div",{className:"bim-d-lu-title",children:l(d.title_info)}),e.jsx(Ue,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?e.jsx(De,{id:d.source_bid,label:l(d.source),onNavigate:r,renderLink:o,dense:!0}):l(d.source),d.section?l(d.section):"",d.author_info?`${l(s.label.authorInfo)} ${l(d.author_info)}`:"",d.edition?`${l(s.label.edition)} ${l(d.edition)}`:"",d.page??""]}),d.summary&&e.jsx("p",{className:"bim-d-quote",children:Ze(l(d.summary))}),d.comment&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.comment)}),e.jsx("p",{className:"bim-d-quote",children:Ze(l(d.comment))})]}),d.additional_comment&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.additionalComment)}),e.jsx("p",{className:"bim-d-quote",children:Ze(l(d.additional_comment))})]}),!d.summary&&!d.comment&&!d.additional_comment&&!d.title_info&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:l("僅著錄書名,無提要。")}),t.length>1&&e.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?e.jsx("button",{type:"button","aria-label":l(`上一家:${t[c-1].source}`),onClick:()=>p(c-1),children:e.jsxs("span",{"aria-hidden":"true",children:["← ",l(t[c-1].source)]})}):e.jsx("span",{"aria-hidden":"true"}),e.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",t.length]}),c<t.length-1?e.jsx("button",{type:"button","aria-label":l(`下一家:${t[c+1].source}`),onClick:()=>p(c+1),children:e.jsxs("span",{"aria-hidden":"true",children:[l(t[c+1].source)," →"]})}):e.jsx("span",{"aria-hidden":"true"})]})]})]})})}function cx(t){var n;return{id:t.id,kind:"hypothetical",label:t.label,year:t.year??((n=t.year_range)==null?void 0:n[0]),year_range:t.year_range,year_uncertain:t.year_uncertain,group:t.group,note:t.note,description:t.description}}function dx(t,n){if(!t.lineage)return null;const r=t.lineage;return{id:t.id,kind:"book",label:t.title,year:r.year,year_text:r.year_text,year_uncertain:r.year_uncertain,category:r.category,status:r.status,extant_juan:r.extant_juan,group:n[t.id],note:r.note}}function Eo(t,n,r){return{id:`derive:${n.ref}->${t}:${r}`,source:n.ref,target:t,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function px(t,n,r){const[o,s]=[t,n.book_id].sort();return{id:`sibling:${o}-${s}:${r}`,source:o,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function ux(t,n){var d;if(n==="all")return null;const r=(d=t.collections)==null?void 0:d[n],o=Array.isArray(r==null?void 0:r.groups)&&r.groups.length>0,s=Array.isArray(r==null?void 0:r.book_ids)&&r.book_ids.length>0,l=o||s||!!(r!=null&&r.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(t.core_books)&&t.core_books.length>0)return{books:new Set(t.core_books),hypos:t.core_hypotheticals?new Set(t.core_hypotheticals):null};if(!r||!l)return null;const a=o?new Set(r.groups):null,p=new Set(r.book_ids??[]);if(a&&t.node_groups)for(const[u,x]of Object.entries(t.node_groups))a.has(x)&&p.add(u);let c=null;if(r.hypothetical_ids&&(c=new Set(r.hypothetical_ids)),a){c||(c=new Set);for(const u of t.hypothetical_nodes??[])u.group&&a.has(u.group)&&c.add(u.id)}return{books:p,hypos:c}}function bn(t,n,r){const o=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!o||!o.enabled)return s;const l=new Set(o.excluded_books??[]),a=o.node_groups??{},p=ux(o,r??o.default_collection??"all"),c=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,x=new Set,m=new Set;if(c){const $=new Map(n.map(T=>[T.id,T])),w=new Map((o.hypothetical_nodes??[]).map(T=>[T.id,T])),_=T=>{const N=$.get(T);if(N&&N.lineage)return(N.lineage.derived_from??[]).map(W=>W.ref);const V=w.get(T);return V?(V.derived_from??[]).map(W=>W.ref):[]},S=T=>w.has(T)?!u||u.has(T):!d||d.has(T),z=new Set,E=T=>{if(!z.has(T)){z.add(T);for(const N of _(T))l.has(N)||(S(N)||(w.has(N)?m.add(N):$.has(N)&&x.add(N)),E(N))}};for(const T of n)d&&d.has(T.id)&&!l.has(T.id)&&E(T.id);for(const T of o.hypothetical_nodes??[])u&&u.has(T.id)&&E(T.id)}const g=n.filter($=>!l.has($.id)).filter($=>!d||d.has($.id)||x.has($.id)).map($=>{const w=dx($,a);return w&&x.has($.id)&&(w.bridge=!0),w}).filter($=>$!==null),b=(o.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||m.has($.id)).map($=>{const w=cx($);return m.has($.id)&&(w.bridge=!0),w}),k=[...g,...b],y=new Set(k.map($=>$.id)),j=new Set,f=[],v=$=>{j.has($.id)||!y.has($.source)||!y.has($.target)||(j.add($.id),f.push($))};for(const $ of n)l.has($.id)||!$.lineage||d&&!d.has($.id)&&!x.has($.id)||(($.lineage.derived_from??[]).forEach((w,_)=>{v(Eo($.id,w,_))}),($.lineage.related_to??[]).forEach((w,_)=>{v(px($.id,w,_))}));for(const $ of o.hypothetical_nodes??[])u&&!u.has($.id)&&!m.has($.id)||($.derived_from??[]).forEach((w,_)=>{v(Eo($.id,w,_))});return{nodes:k,edges:f,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(l)}}function Hl(t,n,r){const o=(t??(n!=null?String(n):"")).trim();return o?!r||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(o)?o:`约 ${o}`:""}function mx(t,n){const r=[],o=t.version_graph;if(!o)return r;const s=new Set(n.map(c=>c.id)),l=new Set((o.hypothetical_nodes??[]).map(c=>c.id)),a=new Set([...s,...l]),p=(c,d)=>{a.has(d.ref)||r.push(`${c}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&r.push(`${c}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&r.push(`${c}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const d=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>p(d,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||r.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of o.hypothetical_nodes??[]){const d=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>p(d,u))}return r}const Gl=({graph:t,renderLink:n,className:r,style:o})=>{const{convert:s}=O();if(!t.nodes.length)return e.jsx("div",{style:{...zx,...o},className:r,children:"暂无版本图数据"});const l=new Map,a=new Map;for(const m of t.edges)if(m.kind==="derive"){const g=l.get(m.target)??[];g.push(m),l.set(m.target,g)}else for(const g of[m.source,m.target]){const b=a.get(g)??[];b.push(m),a.set(g,b)}const p=new Map(t.nodes.map(m=>[m.id,m])),c=new Map,d=[];for(const m of t.nodes)if(m.group){const g=c.get(m.group)??[];g.push(m),c.set(m.group,g)}else d.push(m);const u=(m,g)=>(m.year??9999)-(g.year??9999);c.forEach(m=>m.sort(u)),d.sort(u);const x=t.groups.filter(m=>c.has(m.id));return e.jsxs("div",{className:r,style:{...hx,...o},children:[t.title&&e.jsx("div",{style:gx,children:s(t.title)}),t.description&&e.jsx("div",{style:fx,children:s(t.description)}),x.map(m=>e.jsx(Ro,{label:m.label,color:m.color,nodes:c.get(m.id),incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n},m.id)),d.length>0&&e.jsx(Ro,{label:"其他",nodes:d,incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n})]})},Ro=({label:t,color:n,nodes:r,incomingMap:o,siblingMap:s,nodeMap:l,renderLink:a})=>{const{convert:p}=O();return e.jsxs("div",{style:bx,children:[e.jsx("div",{style:{...yx,borderLeftColor:n??i("widget-border")},children:p(t)}),r.map(c=>e.jsx(xx,{node:c,incoming:o.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:a},c.id))]})},xx=({node:t,incoming:n,siblings:r,nodeMap:o,renderLink:s})=>{const l=t.kind==="hypothetical",a=t.bridge,{convert:p}=O();return e.jsxs("div",{style:{...jx,borderStyle:l||a?"dashed":"solid",opacity:a?.55:t.status==="lost"?.7:1,background:a?i("bg-subtle"):void 0},title:a?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:vx,children:[e.jsx("span",{style:kx,children:l||!s?p(t.label):s(t.id,p(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:wx,children:Hl(p(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:Sx,children:[t.category&&e.jsx(Kt,{children:p(t.category)}),t.status==="lost"&&e.jsx(Kt,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(Kt,{tone:"warn",children:"残本"}),l&&e.jsx(Kt,{tone:"info",children:"假想祖本"}),a&&e.jsx(Kt,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:$x,children:["现存:",p(t.extant_juan)]}),t.note&&e.jsx("div",{style:_x,children:p(t.note)}),n.length>0&&e.jsxs("div",{style:Ao,children:[e.jsx("div",{style:Bo,children:"来源:"}),n.map(c=>{const d=o.get(c.source);return e.jsxs("div",{style:Mo(c.confidence),children:[e.jsx("span",{style:Wo,children:p(c.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,p(d.label)):p((d==null?void 0:d.label)??c.source)}),c.confidence!=="consensus"&&c.confidence!=="certain"&&e.jsx(Lo,{level:c.confidence}),c.evidence&&e.jsxs("span",{style:Oo,children:["· ",p(c.evidence)]})]},c.id)})]}),r.length>0&&e.jsxs("div",{style:Ao,children:[e.jsx("div",{style:Bo,children:"关联:"}),r.map(c=>{const d=c.source===t.id?c.target:c.source,u=o.get(d);return e.jsxs("div",{style:Mo(c.confidence),children:[e.jsx("span",{style:Wo,children:p(c.relation)}),e.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,p(u.label)):p((u==null?void 0:u.label)??d)}),e.jsx(Lo,{level:c.confidence}),c.evidence&&e.jsxs("span",{style:Oo,children:["· ",p(c.evidence)]})]},c.id)})]})]})},Kt=({children:t,tone:n="default"})=>{const o={default:{bg:i("tag-bg"),fg:i("fg")},warn:{bg:i("warn-bg"),fg:i("warn-fg")},info:{bg:i("info-bg"),fg:i("info-fg")}}[n];return e.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:o.bg,color:o.fg,marginRight:"4px"},children:t})},Lo=({level:t})=>{const r={certain:{label:"确定",color:i("confidence-certain")},consensus:{label:"共识",color:i("confidence-consensus")},probable:{label:"推测",color:i("confidence-probable")},disputed:{label:"有争议",color:i("confidence-disputed")}}[t];return r?e.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${r.color}`,color:r.color,borderRadius:"8px",marginLeft:"4px"},children:r.label}):null},hx={fontSize:"14px",color:i("fg")},gx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},fx={fontSize:"13px",color:i("muted"),marginBottom:"16px",lineHeight:1.6},bx={marginBottom:"16px"},yx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:i("fg")},jx={border:`1px solid ${i("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:i("bg")},vx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},kx={fontSize:"15px",fontWeight:600},wx={fontSize:"12px",color:i("muted")},Sx={marginBottom:"6px"},$x={fontSize:"12px",color:i("muted"),margin:"2px 0"},_x={fontSize:"12px",color:i("muted"),fontStyle:"italic",margin:"4px 0"},Ao={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${i("widget-border")}`},Bo={fontSize:"11px",color:i("muted"),marginBottom:"2px"},Mo=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Wo={display:"inline-block",padding:"0 6px",fontSize:"11px",background:i("tag-bg"),color:i("fg"),borderRadius:"3px",marginRight:"6px"},Oo={fontSize:"11px",color:i("muted")},zx={padding:"20px",textAlign:"center",color:i("muted"),fontSize:"13px"},Ul=({selectedNodeId:t,...n})=>{const[r,o]=h.useState("loading"),[s,l]=h.useState(null);return h.useEffect(()=>{let a=!1;return Cx().then(p=>{a||(p?(l(p),o("ready")):o("missing"))}),()=>{a=!0}},[]),r==="loading"?e.jsx("div",{style:Fo,children:"加载图组件中…"}):r==="missing"||!s?e.jsxs("div",{style:Fo,children:[e.jsxs("div",{children:["图组件未安装。请安装 ",e.jsx("code",{children:"@xyflow/react"})," 与 ",e.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),e.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",e.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):e.jsx(Tx,{modules:s,selectedNodeId:t,...n})};async function Cx(){try{const[t,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let r=!1;try{await import("@xyflow/react/dist/style.css"),r=!0}catch{r=!1}return{ReactFlow:t.ReactFlow,Background:t.Background,Controls:t.Controls,Handle:t.Handle,Position:t.Position,BaseEdge:t.BaseEdge,EdgeLabelRenderer:t.EdgeLabelRenderer,getSmoothStepPath:t.getSmoothStepPath,dagre:n,cssLoaded:r}}catch{return null}}const Tx=({graph:t,renderLink:n,height:r=600,className:o,style:s,selectedNodeId:l,modules:a})=>{const{ReactFlow:p,Background:c,Controls:d,Handle:u,Position:x,BaseEdge:m,EdgeLabelRenderer:g,getSmoothStepPath:b,dagre:k}=a,y=h.useMemo(()=>({lineage:_=>{var te,se,J,D;const S=((te=_.data)==null?void 0:te.stepPosition)??.85,[z,E,T]=b({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:S,borderRadius:5}),N=!!((se=_.data)!=null&&se.isSibling),V=N?E:_.targetX-18,W=N?T:_.targetY-12,B=(J=_.data)==null?void 0:J.labelStyle,H=(D=_.data)==null?void 0:D.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(m,{id:_.id,path:z,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&e.jsx(g,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${V}px,${W}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:i("bg"),border:`0.5px solid ${i("widget-border")}`,...H,...B},children:_.label})})]})}}),[m,g,b]),j=h.useMemo(()=>({version:_=>{const S=_.data,z=S.kind==="hypothetical",E=S.status==="lost",T=S.isSelected,N=S.bridge,V=S.borderColor??i("muted"),W=N||z?"dashed":"solid",B=N?.5:E?.6:1;return e.jsxs("div",{style:{background:i(N?"bg-subtle":"bg"),border:`2px ${W} ${T?i("primary"):V}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:B,boxShadow:T?i("shadow-node-selected"):z||N?"none":i("shadow-node")},title:N?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(u,{type:"target",position:x.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&e.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&e.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.2},children:Hl(S.yearText,void 0,S.uncertain)}),E&&e.jsx("div",{style:{fontSize:9,color:i("lost-fg"),marginTop:1},children:"已佚"}),e.jsx(u,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[u,x]),{convert:f}=O(),{rfNodes:v,rfEdges:$}=h.useMemo(()=>Nx(t,k,n,l,f),[t,k,n,l,f]);return e.jsx("div",{style:{width:"100%",height:r,...s},className:o,children:e.jsxs(p,{nodes:v,edges:$,nodeTypes:j,edgeTypes:y,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(c,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function Nx(t,n,r,o,s=l=>l??""){const p=t.layout==="LR"||!t.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:p?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(j=>[j.id,j.color??i("muted")]));for(const j of t.nodes)c.setNode(j.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of t.edges)j.kind==="derive"&&(u.has(j.relation)||c.setEdge(j.source,j.target));n.layout(c);const x=t.nodes.map(j=>{const f=c.node(j.id),v=o?j.id===o:void 0,$={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??Ex(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:r,isSelected:v,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:f.x-160/2,y:f.y-90/2},data:$,draggable:!1,selected:v}}),m=.78,g=.06,b=new Map;for(const j of t.edges)j.kind==="derive"&&(b.has(j.source)||b.set(j.source,[]),b.get(j.source).push(j));const k=new Map;for(const[j,f]of b){if(f.length<=1)continue;const v=[...f].sort((w,_)=>{var E,T;const S=((E=c.node(w.target))==null?void 0:E.y)??0,z=((T=c.node(_.target))==null?void 0:T.y)??0;return S-z}),$=v.length;v.forEach((w,_)=>{const S=(_-($-1)/2)*g;k.set(w.id,m+S)})}const y=t.edges.map(j=>Ix(j,k.get(j.id),s));return{rfNodes:x,rfEdges:y}}function Ix(t,n,r=o=>o??""){const o=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",l=Rx(t.confidence),a={type:"arrowclosed",color:l,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:r(t.relation),data:{labelStyle:{color:i("fg")},isSibling:s,stepPosition:n},style:{stroke:l,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":o?"6 4":void 0,opacity:o?.75:1},animated:!1,markerEnd:a,markerStart:s?a:void 0,zIndex:1e3}}function Ex(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function Rx(t){switch(t){case"certain":return i("confidence-certain");case"consensus":return i("lineage-edge-consensus");case"probable":return i("confidence-probable");case"disputed":return i("confidence-disputed");default:return i("muted")}}const Fo={padding:"40px 20px",textAlign:"center",color:i("muted"),fontSize:"13px",border:`1px dashed ${i("widget-border")}`,borderRadius:8,background:i("bg")},xr=({graph:t,defaultMode:n="list",renderLink:r,graphHeight:o=600,selectedNodeId:s,onModeChange:l,collection:a,onCollectionChange:p,collectionsAvailable:c,collectionCounts:d,className:u,style:x})=>{var f;const[m,g]=h.useState(n),b=v=>{g(v),l==null||l(v)},k=(()=>{if(!c)return[];const v=Object.entries(c);return v.length===0||c.all?v:[...v,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),y=!!(p&&k.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:i("muted"),textAlign:"center"},children:"暂无版本传承数据"});const j=a?(f=c==null?void 0:c[a])==null?void 0:f.description:void 0;return e.jsxs("div",{className:u,style:x,children:[e.jsxs("div",{style:Lx,children:[e.jsx("button",{onClick:()=>b("list"),style:ni(m==="list"),children:"列表"}),e.jsx("button",{onClick:()=>b("graph"),style:ni(m==="graph"),children:"关系图"}),y&&e.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:i("muted"),marginRight:4},children:"集合:"}),k.map(([v,$])=>{const w=d==null?void 0:d[v];return e.jsxs("button",{onClick:()=>p==null?void 0:p(v),style:ni(a===v),title:$.description,children:[$.label,w!=null?` ${w}`:""]},v)})]})]}),y&&j&&e.jsx("div",{style:{fontSize:12,color:i("muted"),marginBottom:8,padding:"4px 8px",background:i("bg-subtle"),borderRadius:4},children:j}),m==="list"?e.jsx(Gl,{graph:t,renderLink:r}):e.jsx(Ul,{graph:t,renderLink:r,height:o,selectedNodeId:s})]})},Lx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},ni=t=>({padding:"4px 12px",fontSize:12,border:`1px solid ${i("widget-border")}`,borderRadius:4,background:t?i("primary"):"transparent",color:i(t?"primary-fg":"fg"),cursor:"pointer"}),Po=40,Do=2,Ax=9,Ho={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function ii(t){if(!t)return["",""];const n=t.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",t]}const Vl=({data:t,transport:n,onNavigate:r,renderLink:o,readAction:s,fullText:l,fullTextPending:a,chapterLink:p,railTop:c,back:d,railLinks:u})=>{var ge,we,R,oe,K,X,je,Ie,Re,re,ze;const x=fe(),{convert:m}=O(),[g,b]=h.useState(null),[k,y]=h.useState(new Map),[j,f]=h.useState([]),[v,$]=h.useState(new Map),[w,_]=h.useState(!1),[S,z]=h.useState("flow"),[E,T]=h.useState(null);h.useEffect(()=>{if(!n||!t.work_id){b(null);return}let C=!1;return n.getItem(t.work_id).then(q=>{!C&&q&&q.type==="work"&&b(q)}).catch(()=>{}),()=>{C=!0}},[n,t.work_id]),h.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!t.work_id){T(null);return}let C=!1;return n.getLineageGraph(t.work_id).then(q=>{C||T(q&&q.nodes.length>1?q:null)}).catch(()=>{C||T(null)}),()=>{C=!0}},[n,t.work_id]),h.useEffect(()=>{const C=t.contained_in||[];if(!n||C.length===0){y(new Map);return}let q=!1;return Promise.all(C.map(ee=>{const Z=typeof ee=="string"?ee:ee.id;return n.getItem(Z).then(me=>[Z,me]).catch(()=>[Z,null])})).then(ee=>{if(q)return;const Z=new Map;for(const[me,Ce]of ee)Ce&&Z.set(me,Ce);y(Z)}),()=>{q=!0}},[n,t.contained_in]);const N=h.useMemo(()=>{const C=new Set([...(g==null?void 0:g.books)||[],...t.related_books||[]]);return C.add(t.id),[...C]},[g==null?void 0:g.books,t.related_books,t.id]),V=N.length-1;h.useEffect(()=>{if(!n||V<=0){f([]);return}const C=N.length<=Po,q=C?N:N.slice(0,8);let ee=!1;return Promise.all(q.map(Z=>Z===t.id?Promise.resolve({id:Z,title:t.title,edition:t.edition,year:vn(t)}):n.getItem(Z).then(me=>{const Ce=me??{};return{id:Z,title:Ce.title,edition:Ce.edition,year:me?vn(Ce):void 0}}).catch(()=>({id:Z})))).then(Z=>{if(ee)return;const me=Z.filter(Ce=>Ce.id===t.id||Ce.title||Ce.edition);C&&me.sort((Ce,F)=>(Ce.year??1/0)-(F.year??1/0)),f(me)}),()=>{ee=!0}},[n,N,V,t]);const W=t.lineage,B=h.useMemo(()=>[...((W==null?void 0:W.derived_from)||[]).filter(C=>C.ref_type==="book").map(C=>C.ref),...((W==null?void 0:W.related_to)||[]).map(C=>C.book_id)].filter(Boolean),[W]);h.useEffect(()=>{if(!n||B.length===0){$(new Map);return}let C=!1;return Promise.all(B.map(q=>n.getItem(q).then(ee=>[q,{id:q,title:ee==null?void 0:ee.title,edition:ee==null?void 0:ee.edition}]).catch(()=>[q,{id:q}]))).then(q=>{C||$(new Map(q))}),()=>{C=!0}},[n,B]);const H=h.useMemo(()=>Ol(t.resources,t.resource_groups),[t.resources,t.resource_groups]),te=H.groups.reduce((C,q)=>C+q.rows.length+q.mirrors.length,0),se=H.groups.length>0&&H.groups.every(C=>C.key==="_physical"),J=nn(t),D=Xs(t),L=ut(t,x.unit.juan),le=new Set((t.contained_in||[]).map(C=>typeof C=="string"?0:Xt(C.volume_index).length).filter(C=>C>0)),A=C=>{var Z;const q=(Z=t.base_edition)==null?void 0:Z.find(me=>me.book_id===C&&me.name);if(q!=null&&q.name)return q.name;const ee=v.get(C);return(ee==null?void 0:ee.edition)||(ee==null?void 0:ee.title)||""},ne=h.useMemo(()=>{var ue,Te,We,Ne,ce;const C=[];D&&C.push({label:"版本類型",value:m(D),title:t.edition_type||(ue=t.lineage)!=null&&ue.category?void 0:m("據版本題名推斷")}),(Te=t.publication_info)!=null&&Te.details?C.push({label:"刊印",value:m(t.publication_info.details)}):(J.era||J.reign)&&C.push({label:"刊寫年代",value:m([J.era,J.reign].filter(Boolean).join(" ")),title:J.source==="edition"?m("據版本題名推斷"):void 0}),L&&C.push({label:"卷帙",value:m(L)});const q=(t.contained_in||[]).flatMap(Se=>typeof Se=="string"?[]:Xt(Se.volume_index));q.length&&C.push({label:"冊次",value:m(`第 ${An(q,x.unit.volume)} ${x.unit.volume}(${q.length} ${x.unit.volume})`)});const ee=(((We=t.lineage)==null?void 0:We.derived_from)||[]).find(Se=>Se.relation==="底本"&&Se.ref_type==="book");ee&&A(ee.ref)&&C.push({label:"底本",value:e.jsx(De,{id:ee.ref,label:m(A(ee.ref)),onNavigate:r,renderLink:o,dense:!0})});const Z=(t.base_edition||[]).filter(Se=>Se&&Se.name);for(const Se of["底本","配補","參校"]){if(Se==="底本"&&ee&&A(ee.ref))continue;const Fe=Z.filter(Ee=>Ee.role===Se);Fe.length&&C.push({label:Se,value:Fe.map((Ee,mt)=>e.jsxs(h.Fragment,{children:[mt>0&&"、",Ee.book_id?e.jsx(De,{id:Ee.book_id,label:m(Ee.name),onNavigate:r,renderLink:o,dense:!0}):m(Ee.name)]},mt))})}const me=(t.provenance||[]).filter(Se=>Se&&Se.institution),Ce=(t.resources||[]).filter(Se=>(Se.types||(Se.type?[Se.type]:[])).includes("physical"));if(me.length){C.push({label:"存藏",value:me.slice(0,2).map(Ee=>m(Ee.institution)).join("、")+(me.length>2?m(` 等 ${me.length} 處`):"")});const Se=me.filter(Ee=>Ee.call_number).slice(0,2).map(Ee=>`${m(Ee.institution)} ${Ee.call_number}`);Se.length&&C.push({label:"索書號",value:Se.join(";")+(me.filter(Ee=>Ee.call_number).length>2?"…":"")});const Fe=me.flatMap(Ee=>Ee.seals||[]).filter(Boolean);Fe.length&&C.push({label:"藏印",value:m(Fe.join("、"))})}else Ce.length?C.push({label:"存藏",value:Ce.slice(0,2).map(Se=>m(Se.name)).join("、")+(Ce.length>2?m(` 等 ${Ce.length} 處`):"")}):(Ne=t.current_location)!=null&&Ne.name&&C.push({label:"存藏",value:m(t.current_location.name)});const F=t.physical_description;if(F){const Se=[["行款",F.leaf_style],["裝幀",F.binding],["尺寸",F.dimensions],["品相",F.condition]];for(const[Fe,Ee]of Se)Ee&&Ee.trim()&&C.push({label:Fe,value:m(Ee)})}(ce=t.page_count)!=null&&ce.description&&C.push({label:x.label.pageCount,value:m(t.page_count.description)});const M=[...vi(t.additional_titles),...vi(t.attached_texts)];return M.length&&C.push({label:"又名",value:M.map(m).join("、")}),C},[t,m,x,J,D,L,v,r,o]),de=m(t.title),G=t.edition?m(t.edition):void 0,he=((ge=t.lineage)==null?void 0:ge.year_text)||"",ye=e.jsx(on,{kind:"版本",title:de,subtitle:G,byline:e.jsx(ur,{authors:t.authors??(g==null?void 0:g.authors),onNavigate:r,renderLink:o}),meta:(()=>{const C=[D?m(D):"",J.era?m([J.era,J.reign].filter(Boolean).join("")):"",L?m(L):""].filter(Boolean);return C.length?e.jsx("span",{className:"bim-d-tags",children:C.map((q,ee)=>e.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ee,2)}`,children:q},ee))}):null})(),description:(we=t.description)!=null&&we.text?e.jsx(pt,{text:t.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Zi((R=t.description)==null?void 0:R.text)?6:void 0,facts:ne,readAction:s,secondaryAction:s&&te>0&&!se?e.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:m("看原書影印")}):void 0,foot:e.jsx(sn,{revision:t.revision,revisedAt:t.revised_at,review:t.review,todo:t.todo})}),xe=t.contained_in||[],pe=(l==null?void 0:l.chapters)||[],$e=pe[0]&&ii(pe[0].title)[0].slice(-1)||"章",Oe=!!((oe=W==null?void 0:W.derived_from)!=null&&oe.length||(K=W==null?void 0:W.related_to)!=null&&K.length||(X=t.appendix)!=null&&X.length),Ae=[];(pe.length||H.text.length||a)&&Ae.push({id:"fulltext",label:"文本",count:pe.length?m(`${pe.length} ${$e}`):void 0}),H.groups.length&&Ae.push({id:"images",label:se?"館藏":"影印",count:te}),Oe&&Ae.push({id:"lineage",label:"版本源流"}),xe.length&&Ae.push({id:"collections",label:"收入叢編",count:xe.length}),(je=t.location_history)!=null&&je.length&&Ae.push({id:"provenance",label:"流轉歷史"});const Me=C=>(p==null?void 0:p(C))??null,ve=pe[0],Be=ve?Me(ve.file):null,P=w?pe:pe.slice(0,Ax),ae=(C,q,ee)=>C?e.jsx("a",{className:ee,href:C.href??"#",onClick:C.onClick?Z=>{Z.metaKey||Z.ctrlKey||(Z.preventDefault(),C.onClick())}:void 0,children:q}):e.jsx("span",{className:ee,children:q}),ie=e.jsxs(e.Fragment,{children:[(pe.length>0||H.text.length>0||a)&&e.jsxs(Ve,{id:"fulltext",title:"文本",meta:pe.length>0?e.jsx(Ue,{items:[m(`${pe.length} ${$e}`),(Ie=l==null?void 0:l.source)!=null&&Ie.name?m(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[a&&!ve&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[e.jsx("span",{className:"bim-d-ft-h",children:" "}),e.jsx("span",{className:"bim-d-meta",children:" "})]}),e.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),ve&&e.jsxs("div",{className:"bim-d-ft",children:[e.jsx("h3",{className:"bim-d-ft-h",children:m(`從${ii(ve.title)[0]||"第一章"}讀起`)}),e.jsx("span",{className:"bim-d-meta",children:m((ve.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),ae(Be,e.jsxs(e.Fragment,{children:[m("進入閱讀頁")," ",e.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),pe.length>1&&e.jsx("ul",{className:"bim-d-chap",children:P.map(C=>{const[q,ee]=ii(C.title);return e.jsx("li",{children:ae(Me(C.file),e.jsxs(e.Fragment,{children:[q&&e.jsx("b",{children:m(q)}),m(ee||C.file)]}))},C.file)})}),pe.length>P.length&&e.jsx(Ji,{label:`展開其餘 ${pe.length-P.length} ${$e}`,onClick:()=>_(!0)}),H.text.length>0&&e.jsxs(e.Fragment,{children:[(pe.length>0||a)&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:m("站外文本")}),e.jsx("table",{className:"bim-d-zt",children:e.jsx("tbody",{children:H.text.map((C,q)=>e.jsx(mr,{item:C,siblings:H.text,listedVolumeCounts:le},`${C.id||C.url||C.name}-${q}`))})})]})]}),H.groups.length>0&&e.jsx(Ve,{id:"images",title:se?"館藏":"影印",meta:e.jsx(Ue,{items:[H.groups.length>1?m(`${H.groups.length} 組`):"",m(`${te} 處`)]}),children:e.jsx(Pl,{groups:H.groups,listedVolumeCounts:le})}),Oe&&e.jsx(Ve,{id:"lineage",title:"版本源流",meta:(Re=W==null?void 0:W.derived_from)!=null&&Re.length?m("據版本傳承著錄"):void 0,action:E?e.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":m("源流視圖"),children:[e.jsx("button",{type:"button","aria-pressed":S==="flow",onClick:()=>z("flow"),children:m("卡片")}),e.jsx("button",{type:"button","aria-pressed":S==="graph",onClick:()=>z("graph"),children:m("關係圖")})]}):void 0,children:S==="graph"&&E?e.jsx(xr,{graph:E,defaultMode:"graph",selectedNodeId:t.id,graphHeight:480,renderLink:(C,q)=>e.jsx(De,{id:C,label:m(q),onNavigate:r,renderLink:o,dense:!0})}):e.jsx(Mx,{data:t,heading:G||de,yearText:he,refName:A,onNavigate:r,renderLink:o})}),xe.length>0&&e.jsx(Ve,{id:"collections",title:"收入叢編",children:e.jsx("table",{className:"bim-d-zt",children:e.jsx("tbody",{children:xe.map((C,q)=>{var F,M;const ee=typeof C=="string"?C:C.id,Z=typeof C=="string"?[]:Xt(C.volume_index),me=k.get(ee),Ce=(me==null?void 0:me._member_count)||((F=me==null?void 0:me.books)==null?void 0:F.length)||((M=me==null?void 0:me.contained_works)==null?void 0:M.length)||0;return e.jsxs("tr",{children:[e.jsxs("td",{className:"bim-d-zt-main",children:[e.jsx(De,{id:ee,label:me?m(me.title):ee,onNavigate:r,renderLink:o,dense:!0}),Z.length>0&&e.jsx(Bx,{volumes:Z,unit:x.unit.volume})]}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Ce?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Ce>0&&m(`全 ${Ce} ${x.unit.bu}`)})]},`${ee}-${q}`)})})})}),(re=t.location_history)!=null&&re.length?e.jsx(Ve,{id:"provenance",title:"流轉歷史",children:e.jsx("ul",{className:"bim-d-tl",children:t.location_history.map((C,q)=>e.jsxs("li",{children:[e.jsx("span",{className:"bim-d-tl-t",children:m(C.name)}),([C.start_date,C.end_date].filter(Boolean).join("—")||C.description)&&e.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:e.jsx(Ue,{items:[[C.start_date,C.end_date].filter(Boolean).join("—"),C.description?m(C.description):""]})})]},q))})}):null,Ae.length===0&&e.jsx(Ve,{title:"影印與文本",children:e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:m("尚未著錄該版本的影印、文本與收藏信息。")})})]}),_e=j.findIndex(C=>C.id===t.id),ke=N.length<=Po,Y=ke&&_e>=0?j.slice(Math.max(0,_e-Do),_e+Do+1):j.filter(C=>C.id!==t.id),I=e.jsxs(e.Fragment,{children:[g&&e.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[e.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:m(x.section.belongsToWork)}),e.jsx("div",{style:{fontSize:17,fontWeight:500},children:e.jsx(De,{id:g.id,label:m(g.title),onNavigate:r,renderLink:o})}),e.jsx(Ue,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(g.authors||[]).slice(0,2).map(C=>`${C.dynasty?`〔${m(C.dynasty)}〕`:""}${m(C.name)}`),m(ut(g,x.unit.juan)),g._edition_count?m(`${g._edition_count} 種版本`):""]}),((ze=g.description)==null?void 0:ze.text)&&e.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:m(g.description.text.replace(/[#*_>`[\]]/g,""))})]}),V>0&&Y.length>0&&e.jsxs("div",{children:[e.jsx(St,{id:"siblings",timeline:!0,title:ke?"同作品版本":x.relation.siblingVersions,meta:m(ke?"按年代":`${V} 種`),cap:Y.length,items:Y.map(C=>C.id===t.id?e.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:m(C.edition||C.title||C.id)}):e.jsx(De,{id:C.id,label:m(C.edition||C.title||C.id),onNavigate:r,renderLink:o,dense:!0})),metas:Y.map(C=>[C.year!=null?C.year<0?`前${-C.year}`:String(C.year):"",C.id===t.id?m("本頁"):""].filter(Boolean).join(" ")),currentIndex:Y.findIndex(C=>C.id===t.id)}),g&&e.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:e.jsx(De,{id:g.id,label:m(`在作品頁看全部 ${N.length} 種 →`),onNavigate:r,renderLink:o,dense:!0})})]})]}),U=t.work_id?e.jsx(Qs,{caption:x.section.belongsToWork,children:e.jsx(De,{id:t.work_id,label:g?m(g.title):" ",onNavigate:r,renderLink:o,dense:!0})}):void 0;return e.jsx(rn,{railTop:c,back:d,up:U,nav:Ae,railLinks:u,main:ie,card:ye,side:I})};function Bx({volumes:t,unit:n}){const{convert:r}=O();return e.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[r(`第 ${An(t,n)} ${n}`),t.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bim-d-dot"}),r(`${t.length} ${n}`)]})]})}function Mx({data:t,heading:n,yearText:r,refName:o,onNavigate:s,renderLink:l}){var y;const{convert:a}=O(),p=t.lineage,c=(p==null?void 0:p.derived_from)||[],d=c.filter(j=>j.ref_type!=="book"),u=c.filter(j=>j.ref_type==="book"&&j.relation==="底本"),x=c.filter(j=>j.ref_type==="book"&&j.relation!=="底本"),m=(p==null?void 0:p.related_to)||[],g=c.length>0||m.length>0,b=j=>j&&Ho[j]?a(`(${Ho[j]})`):"",k=(j,f)=>e.jsx(De,{id:j,label:a(f||j),onNavigate:s,renderLink:l,dense:!0});return e.jsxs("div",{className:"bim-d-lf",children:[g&&e.jsxs("ol",{className:"bim-d-lf-list",children:[d.map((j,f)=>e.jsx("li",{className:"bim-d-lf-node",children:e.jsxs("div",{className:"bim-d-lf-dash",children:[e.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(j.relation||"祖本")}),e.jsx("span",{className:"bim-d-lf-name",children:a("擬構祖本")}),j.evidence&&e.jsxs("span",{className:"bim-d-meta",children:[a(j.evidence),b(j.confidence)]})]})},`a-${f}`)),u.map((j,f)=>e.jsx("li",{className:"bim-d-lf-node",children:e.jsxs("div",{className:"bim-d-lf-card",children:[e.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(j.relation)}),e.jsx("span",{className:"bim-d-lf-name",children:k(j.ref,o(j.ref))}),j.evidence&&e.jsxs("p",{className:"bim-d-lf-ev",children:[a(j.evidence),b(j.confidence)]})]})},`b-${f}`)),e.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[e.jsxs("div",{className:"bim-d-lf-here",children:[e.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a("本版")}),e.jsx("span",{className:"bim-d-lf-name",children:n}),r&&e.jsx("span",{className:"bim-d-lf-yr",children:a(r)})]}),x.length>0&&e.jsx("div",{className:"bim-d-lf-side",children:x.map((j,f)=>e.jsxs("div",{className:"bim-d-lf-dash",children:[e.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(j.relation)}),e.jsx("span",{className:"bim-d-lf-name",children:k(j.ref,o(j.ref))}),j.evidence&&e.jsxs("p",{className:"bim-d-lf-ev",children:[a(j.evidence),b(j.confidence)]})]},f))})]}),m.length>0&&e.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[e.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:a("翻刻 · 衍生")}),e.jsx("span",{className:"bim-d-lf-chips",children:m.map((j,f)=>e.jsxs("span",{className:"bim-d-lf-chip",title:j.evidence?a(j.evidence):void 0,children:[k(j.book_id,o(j.book_id)),e.jsx("span",{className:"bim-d-meta",children:a(j.relation)})]},f))})]})]}),(y=t.appendix)==null?void 0:y.map((j,f)=>e.jsxs("details",{className:"bim-d-lf-app",children:[e.jsxs("summary",{className:"bim-d-ui",children:[e.jsx("span",{className:"bim-d-meta",children:a("附記")})," ",a(j.title)]}),e.jsx(pt,{text:j.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${f}`)),(p==null?void 0:p.note)&&e.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:a(p.note)})]})}const qt=16,Wx=200,Ox=16,Yl=({data:t,catalog:n,transport:r,onNavigate:o,renderLink:s,catalogAction:l,railTop:a,back:p,railLinks:c})=>{var _e,ke,Y,I,U,ge,we;const d=fe(),{convert:u}=O(),[x,m]=h.useState(""),[g,b]=h.useState(!1),[k,y]=h.useState(null),[j,f]=h.useState(""),[v,$]=h.useState(!1),w=h.useMemo(()=>Js(t,n),[t,n]),[_,S]=h.useState(new Map),z=!!r&&w.rows.length>0&&w.rows.length<=Wx,E=z&&(w.rows.length<=qt||v),T=E&&w.rows.every(R=>!R.id||_.has(R.id)),N=R=>{var oe;return _i(R?(oe=_.get(R))==null?void 0:oe.l1:void 0)},V=h.useMemo(()=>{const R=x.trim(),oe=R?u(R):"";return w.rows.filter(K=>{var je,Ie;if(j&&_i(K.id?(je=_.get(K.id))==null?void 0:je.l1:void 0)!==j)return!1;if(!oe)return!0;const X=K.id&&((Ie=_.get(K.id))==null?void 0:Ie.title)||K.title;return u(X).includes(oe)||(K.subItems||[]).some(Re=>u(Re).includes(oe))})},[w.rows,x,j,_,u]),W=g?V:V.slice(0,qt),B=h.useMemo(()=>(E?w.rows:W).filter(R=>R.id&&!_.has(R.id)).map(R=>R.id),[E,w.rows,W,_]);h.useEffect(()=>{if(!r||B.length===0)return;let R=!1;const oe=B.slice(0,Ox);return Promise.all(oe.map(K=>r.getItem(K).then(X=>{var Re,re;const je=X??{},Ie={title:je.title,edition:je.edition,authors:je.authors,measure:X?ut(X,d.unit.juan):void 0,versionCount:je._edition_count??((Re=je.books)==null?void 0:Re.length),l1:((re=je.classification)==null?void 0:re.l1)||void 0};return[K,Ie]}).catch(()=>[K,{}]))).then(K=>{R||S(X=>{const je=new Map(X);for(const[Ie,Re]of K)je.set(Ie,Re);return je})}),()=>{R=!0}},[r,B,d.unit.juan]);const H=(t.contained_in||[])[0];h.useEffect(()=>{if(!H){y(null);return}if(y({id:H}),!r)return;let R=!1;return r.getItem(H).then(oe=>{R||y({id:H,title:oe==null?void 0:oe.title})}).catch(()=>{}),()=>{R=!0}},[r,H]);const te=h.useMemo(()=>Ol(t.resources,t.resource_groups),[t.resources,t.resource_groups]),se=te.text.length+te.groups.reduce((R,oe)=>R+oe.rows.length+oe.mirrors.length,0),J=t.contained_works||[],D=new Set(w.rows.map(R=>R.id).filter(Boolean)),L=J.length>0&&!J.every(R=>D.has(R.id)),le=(()=>{const R=w.rows.map(oe=>oe.edition).filter(Boolean);return R.length>1&&new Set(R).size===1})(),A=w.rows.some(R=>R.volumes.length>0||R.expected!=null),ne=t._member_count||((_e=t.books)==null?void 0:_e.length)||J.length,de=ut(t,d.unit.juan),G=t.count,he=R=>typeof R=="number"&&Number.isFinite(R)?R:null,ye=he(G==null?void 0:G.juan)??he((ke=t.juan_count)==null?void 0:ke.number),xe=he(G==null?void 0:G.ce)??(w.totalVolumes||null),pe=[{value:w.rows.length,label:"子目"},{value:ye??0,label:d.unit.juan},{value:xe??0,label:d.unit.volume}],$e=h.useMemo(()=>{var K,X;const R=[];if((K=t.publication_info)!=null&&K.details&&R.push({label:"刊印",value:u(t.publication_info.details)}),ne&&ne!==w.rows.length){const je=t._member_type==="Book"?"所收版本":t._member_type==="Work"?"所收作品":"成員";R.push({label:u(je),value:`${ne} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")})}const oe=[he(G==null?void 0:G.zhong)!=null?`${G.zhong} 種`:"",he(G==null?void 0:G.han)!=null?`${G.han} 函`:""].filter(Boolean);return oe.length&&R.push({label:"應收",value:u(oe.join(" "))}),ye==null&&de&&R.push({label:"卷帙",value:u(de),title:(X=t.juan_count)!=null&&X.description?u(t.juan_count.description):void 0}),R},[t,ne,w.rows.length,ye,de,G,u,d]),Oe=h.useMemo(()=>{if(!T)return[];const R=new Map;for(const K of w.rows){const X=N(K.id);X&&R.set(X,(R.get(X)??0)+1)}const oe=en.filter(K=>(R.get(K.key)??0)>0);return oe.length<2?[]:[{key:"",label:`${d.catalog.all} ${w.rows.length}`},...oe.map(K=>({key:K.key,label:`${K.label} ${R.get(K.key)}`}))]},[T,w.rows,_,d]),Ae=h.useMemo(()=>{if(!T||!w.rows.some(X=>X.volumes.length>0))return null;const R=[],oe=w.rows.filter(X=>X.volumes.length>0).map(X=>({k:N(X.id)??"",from:Math.min(...X.volumes),to:Math.max(...X.volumes)})).sort((X,je)=>X.from-je.from);for(const X of oe){const je=X.to-X.from+1,Ie=R[R.length-1];Ie&&Ie.key===X.k?(Ie.to=Math.max(Ie.to,X.to),Ie.n+=je):R.push({key:X.k,from:X.from,to:X.to,n:je})}const K=oe.reduce((X,je)=>Math.max(X,je.to),0);return R.length>1&&R.some(X=>X.key)?{segs:R,last:K}:null},[T,w.rows,_]),Me=(Y=t.description)==null?void 0:Y.text,ve=e.jsx(on,{kind:"叢編",title:u(t.title),byline:e.jsx(ur,{authors:t.authors,onNavigate:o,renderLink:s}),meta:e.jsx(Ue,{items:[t.subtype==="work_collection"?u("作品集"):"",(I=t.publication_info)!=null&&I.year?u(t.publication_info.year):""]}),description:Me||(U=t.history)!=null&&U.length?e.jsxs(e.Fragment,{children:[Me&&e.jsx(pt,{text:Me,style:{fontSize:15,lineHeight:1.85}}),(ge=t.history)!=null&&ge.length?e.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:t.history.map((R,oe)=>e.jsx("li",{children:u(R)},oe))}):null]}):void 0,clampDescription:Zi(Me)||(((we=t.history)==null?void 0:we.length)??0)>2?6:void 0,stats:pe,facts:$e,foot:e.jsx(sn,{revision:t.revision,revisedAt:t.revised_at,review:t.review,todo:t.todo}),children:Ae&&e.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[e.jsx("div",{className:"bim-d-dist-head",children:e.jsx("span",{children:u("全帙冊次分佈")})}),e.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":u("全帙冊次分佈"),children:Ae.segs.map((R,oe)=>{const K=en.find(X=>X.key===R.key);return e.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!K,title:K?u(`${K.label} 第 ${R.from}–${R.to} 冊`):void 0,"aria-label":u(K?`只看${K.label}`:"未分類"),"aria-pressed":!!K&&j===R.key,style:{flexGrow:R.n,background:i(K?K.token:"rule")},onClick:()=>{K&&(f(j===R.key?"":R.key),b(!1))}},oe)})}),e.jsxs("div",{className:"bim-d-life-lab",children:[e.jsx("span",{children:u(`第 1 ${d.unit.volume}`)}),e.jsx("span",{children:u("點色段篩選部類")}),e.jsx("span",{children:u(`第 ${Ae.last} ${d.unit.volume}`)})]})]})}),Be=[];w.rows.length&&Be.push({id:"titles",label:"子目",count:w.rows.length}),se&&Be.push({id:"resources",label:"影印與文本",count:se}),L&&Be.push({id:"works",label:d.section.containedWorks,count:J.length});const P=e.jsxs(e.Fragment,{children:[w.rows.length>0&&e.jsxs(Ve,{id:"titles",title:"子目",meta:e.jsx(Ue,{items:[u(`${w.rows.length} ${d.unit.items}`),w.totalVolumes?u(`全帙 ${w.totalVolumes} ${d.unit.volume}`):"",V.length!==w.rows.length?u(`當前 ${V.length} ${d.unit.items}`):""]}),action:l,children:[(w.rows.length>qt||Oe.length>0)&&e.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[Oe.length>0&&e.jsx(Bn,{items:Oe,value:j,onChange:R=>{f(R),b(!1)}}),z&&w.rows.length>qt&&!T&&e.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:v,onClick:()=>$(!0),title:u(`將載入全部 ${w.rows.length} ${d.unit.items}`),children:u(v?"正在按部類分組…":"按部類分組")}),e.jsx("span",{className:"bim-d-spacer"}),w.rows.length>qt&&e.jsx("input",{type:"search",className:"bim-d-find",value:x,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:R=>{m(R.target.value),b(!1)}})]}),e.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&Mn(V.length)?"":void 0,children:[e.jsx("thead",{className:"bim-d-ui",children:e.jsxs("tr",{children:[A&&e.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),e.jsx("th",{children:u("書名")}),e.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),e.jsx("tbody",{children:W.map((R,oe)=>{var ze;const K=R.id?_.get(R.id):void 0,X=K!=null&&K.title&&R.title===R.id?K.title:R.title,je=((K==null?void 0:K.authors)||[]).find(C=>C&&C.name),Ie=[je?`${je.dynasty?`〔${u(je.dynasty)}〕`:""}${u(je.name)}${je.role?` ${u(je.role)}`:""}`:"",K!=null&&K.measure?u(K.measure):"",(ze=R.subItems)!=null&&ze.length?R.subItems.map(C=>u(C)).join("、"):"",(K!=null&&K.edition||R.edition)&&!le?u((K==null?void 0:K.edition)||R.edition||""):""].filter(Boolean),Re=en.find(C=>C.key===N(R.id)),re=R.volumes.length>0?u(`第 ${An(R.volumes,d.unit.volume)} ${d.unit.volume}`):R.expected!=null?u(`${R.found??0}/${R.expected} ${d.unit.volume}`):"";return e.jsxs("tr",{children:[A&&e.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${re?"":" bim-d-zt-blank"}`,children:[Re&&e.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:i(Re.token)}}),re||e.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),e.jsxs("td",{className:"bim-d-zt-main",children:[R.id?e.jsx(De,{id:R.id,label:u(X),onNavigate:o,renderLink:s,dense:!0}):e.jsx("span",{className:"bim-d-zt-name",children:u(X)}),Ie.length>0?e.jsx(Ue,{items:Ie}):R.id&&!K&&r?e.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${K!=null&&K.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:K!=null&&K.versionCount?u(`${K.versionCount} 種`):""})]},`${R.id??R.title}-${oe}`)})})]}),W.length===0&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),!g&&e.jsx(qi,{total:V.length,shown:W.length,unit:d.unit.items,onClick:()=>b(!0)})]}),se>0&&e.jsxs(Ve,{id:"resources",title:"影印與文本",meta:u(`${se} 處`),children:[te.text.length>0&&e.jsxs("div",{className:"bim-d-rg",children:[te.groups.length>0&&e.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("文本")}),e.jsx("table",{className:"bim-d-zt",children:e.jsx("tbody",{children:te.text.map((R,oe)=>e.jsx(mr,{item:R,siblings:te.text},`${R.id||R.url||R.name}-${oe}`))})})]}),e.jsx(Pl,{groups:te.groups})]}),w.rows.length===0&&se===0&&e.jsx(Ve,{title:"子目",children:e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),ae=L?e.jsx(St,{id:"works",title:d.section.containedWorks,meta:u(`${J.length} 種`),cap:12,items:J.map(R=>e.jsx(De,{id:R.id,label:u(R.title),onNavigate:o,renderLink:s,dense:!0}))}):null,ie=k?e.jsx(Qs,{caption:"上級叢編",children:e.jsx(De,{id:k.id,label:u(k.title||k.id),onNavigate:o,renderLink:s,dense:!0})}):void 0;return e.jsx(rn,{railTop:a,back:p,up:ie,nav:Be,railLinks:c,main:P,card:ve,side:ae})},Fx=16,ri=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Go(t){if(!t)return ri.length;const n=ri.indexOf(t);return n===-1?ri.length:n}const Px={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function ht(t){return t==null?"":t<0?`前${-t}`:String(t)}const Dx={秦:[-221,-207],西漢:[-202,8],西汉:[-202,8],東漢:[25,220],东汉:[25,220],漢:[-202,220],汉:[-202,220],三國:[220,280],三国:[220,280],西晉:[265,316],西晋:[265,316],東晉:[317,420],东晋:[317,420],隋:[581,618],唐:[618,907],五代:[907,960],北宋:[960,1127],南宋:[1127,1279],宋:[960,1279],遼:[916,1125],辽:[916,1125],金:[1115,1234],元:[1271,1368],明:[1368,1644],清:[1636,1912]},Kl=({data:t,transport:n,onNavigate:r,renderLink:o,railTop:s,back:l,railLinks:a})=>{var ae,ie,_e,ke,Y;const p=fe(),{convert:c}=O(),[d,u]=h.useState("全部"),[x,m]=h.useState(!1),[g,b]=h.useState("default"),[k,y]=h.useState(new Map),j=h.useMemo(()=>(t.works||[]).map(I=>{const U=k.get(I.work_id);return{id:I.work_id,title:(U==null?void 0:U.title)??I.title??I.work_id,role:I.role||"",cls:Yi(I.role),versionCount:U==null?void 0:U.versionCount,section:U==null?void 0:U.cls,l1:U==null?void 0:U.l1,measure:U==null?void 0:U.measure,hasImage:U==null?void 0:U.hasImage,loaded:!!(U!=null&&U.loaded)}}),[t.works,k]),f=h.useMemo(()=>qs((t.works||[]).map(I=>I.role)),[t.works]),v=h.useMemo(()=>{const I=d==="全部"?j:j.filter(U=>U.cls===d);return g==="versions"?[...I].sort((U,ge)=>(ge.versionCount??-1)-(U.versionCount??-1)):I},[j,d,g]),$=x?v:v.slice(0,Fx),w=h.useMemo(()=>$.filter(I=>!k.has(I.id)).map(I=>I.id),[$,k]);h.useEffect(()=>{if(!n||w.length===0)return;let I=!1;return Promise.all(w.map(U=>n.getItem(U).then(ge=>{var K,X,je,Ie,Re;const we=ge??{},R=we._edition_count??(((K=we.books)==null?void 0:K.length)??0)+(((X=we.collections)==null?void 0:X.length)??0),oe=[(je=we.classification)==null?void 0:je.l1,(Ie=we.classification)==null?void 0:Ie.l2].filter(Boolean).join(" ");return[U,{id:U,title:we.title,versionCount:R,loaded:!0,cls:oe||void 0,l1:((Re=we.classification)==null?void 0:Re.l1)||void 0,measure:ge&&ut(ge,p.unit.juan)||void 0,hasImage:!!(we.has_image??we._has_image)}]}).catch(()=>[U,{id:U,loaded:!0}]))).then(U=>{I||y(ge=>{const we=new Map(ge);for(const[R,oe]of U)we.set(R,oe);return we})}),()=>{I=!0}},[n,w,p.unit.juan]);const _=h.useMemo(()=>{const I=new Map;for(const U of t.alt_names||[]){const ge=U.type||p.section.aliases;I.has(ge)||I.set(ge,[]),I.get(ge).push(U.name)}return[...I.entries()].sort((U,ge)=>Go(U[0])-Go(ge[0])).map(([U,ge])=>({label:U,names:ge}))},[t.alt_names,p]),S=t.birth_year??((ae=t.dates)==null?void 0:ae.birth)??void 0,z=t.death_year??((ie=t.dates)==null?void 0:ie.death)??void 0,E=(_e=t.dates)==null?void 0:_e.floruit,T=S!=null||z!=null?`${ht(S)||"?"}—${ht(z)||"?"}`:Array.isArray(E)&&E.length===2&&E.every(I=>Number.isFinite(I))?`活躍於 ${ht(E[0])}—${ht(E[1])}`:"",N=new Set(["本名","字","號","号"]),V=_.filter(I=>N.has(I.label)),W=_.filter(I=>!N.has(I.label)),B=W.reduce((I,U)=>I+U.names.length,0),H=h.useMemo(()=>{const I=[];for(const ge of V)I.push({label:ge.label,value:ge.names.map(we=>c(we)).join("、")});const U=(t.works||[]).length;return U&&I.push({label:"著作",value:`${U} ${c("種")}`}),I},[t.works,V,c]),te=I=>{var U;return(U=_.find(ge=>I.includes(ge.label)))==null?void 0:U.names[0]},se=te(["字"]),J=te(["號","号"]),D=[se?`字${se}`:"",J?`號${J}`:""].filter(Boolean).join(","),L=t.native_place,le=t.dynasty?Dx[t.dynasty]:void 0,A=(()=>{if(!le||S==null||z==null||z<S)return null;const[I,U]=le,ge=Math.max(S,I),we=Math.min(z,U);if(we<=ge)return null;const R=U-I;return e.jsxs("div",{className:"bim-d-life bim-d-ui",children:[e.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":c(`${ht(S)}—${ht(z)},一生 ${z-S+1} 年`),children:e.jsx("i",{style:{left:`${(ge-I)/R*100}%`,width:`${(we-ge)/R*100}%`}})}),e.jsxs("div",{className:"bim-d-life-lab",children:[e.jsx("span",{children:c(`${ht(I)} ${t.dynasty}`)}),e.jsx("span",{children:c(`一生 ${z-S+1} 年`)}),e.jsx("span",{children:ht(U)})]})]})})(),ne=h.useMemo(()=>{if(!n||j.length===0||j.some(ge=>!ge.loaded))return null;const I=new Map;for(const ge of j){const we=_i(ge.l1);we&&I.set(we,(I.get(we)??0)+1)}const U=en.map(ge=>({...ge,n:I.get(ge.key)??0})).filter(ge=>ge.n>0);return U.length?U:null},[j,n]),de=e.jsxs(on,{kind:Px[t.subtype]??"人物",title:c(t.primary_name||t.title),subtitle:D?c(D):void 0,meta:e.jsxs(e.Fragment,{children:[e.jsx(Ue,{items:[t.dynasty?c(t.dynasty):"",T?c(T):"",L?c(`${L}人`):""]}),A]}),description:(ke=t.description)!=null&&ke.text?e.jsx(pt,{text:t.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Zi((Y=t.description)==null?void 0:Y.text)?6:void 0,facts:H,foot:e.jsx(sn,{revision:t.revision,revisedAt:t.revised_at,review:t.review,todo:t.todo}),children:[B>0&&e.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[e.jsx("summary",{children:c(`更多別名(${B})`)}),e.jsx("dl",{children:W.map(I=>e.jsxs(h.Fragment,{children:[e.jsx("dt",{children:c(I.label)}),e.jsx("dd",{children:I.names.map(U=>c(U)).join("、")})]},I.label))})]}),ne&&e.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[e.jsx("div",{className:"bim-d-dist-head",children:e.jsx("span",{children:c("著作分佈")})}),e.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:ne.map(I=>e.jsx("i",{style:{flexGrow:I.n,background:i(I.token)}},I.key))}),e.jsx("div",{className:"bim-d-dist-key",children:ne.map(I=>e.jsxs("span",{children:[e.jsx("i",{style:{background:i(I.token)}}),c(I.label)," ",I.n]},I.key))})]})]}),G=h.useMemo(()=>j.filter(I=>I.loaded&&(I.versionCount??0)>0).sort((I,U)=>(U.versionCount??0)-(I.versionCount??0)).slice(0,3),[j]),he=!!n&&j.length>=3&&$.some(I=>!I.loaded),ye=d==="全部"&&(he||G.length>=2),xe=t.external_ids||{},pe=[];xe.cbdb_id!=null&&pe.push({label:"CBDB",id:String(xe.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${xe.cbdb_id}`,note:xe.cbdb_match==="auto"?"自動匹配":void 0});const $e=xe.wikidata_id;$e&&pe.push({label:"Wikidata",id:$e,href:`https://www.wikidata.org/wiki/${$e}`});const Oe=xe.viaf_id;Oe&&pe.push({label:"VIAF",id:Oe,href:`https://viaf.org/viaf/${Oe}`});const Ae=f.map(I=>({key:I.cls,label:`${I.label} ${I.count}`})),Me=[...ye&&!he?[{id:"featured",label:"著作舉要",count:G.length}]:[],...j.length?[{id:"works",label:"全部著作",count:j.length}]:[],...pe.length?[{id:"external",label:"站外資料",count:pe.length}]:[]],ve=ye?e.jsxs(Ve,{id:"featured",title:"著作舉要",children:[e.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:c("存世版本最多的三部")}),e.jsxs("div",{className:"bim-d-picks","aria-busy":he||void 0,children:[he&&[0,1,2].map(I=>e.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[e.jsx("span",{className:"bim-d-pick-t",children:" "}),e.jsx("span",{className:"bim-d-meta",children:" "}),e.jsx("div",{className:"bim-d-pick-n",children:" "})]},I)),!he&&G.map(I=>e.jsxs("div",{className:"bim-d-pick",children:[e.jsx("span",{className:"bim-d-pick-t",children:e.jsx(De,{id:I.id,label:c(I.title),onNavigate:r,renderLink:o,dense:!0})}),e.jsx(Ue,{items:[I.section?c(I.section):"",I.measure?c(I.measure):""]}),e.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[e.jsx("span",{className:"bim-d-pick-num",children:I.versionCount}),e.jsx("span",{children:c("種版本")}),I.hasImage&&e.jsx("span",{className:"bim-d-flag",children:c("有影印")})]})]},I.id))]})]}):null,Be=j.length===0?e.jsx(Ve,{title:"著作",children:e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該人物的關聯作品。")})}):e.jsxs(e.Fragment,{children:[ve,e.jsxs(Ve,{id:"works",title:"著作",meta:e.jsx(Ue,{items:[c(`共 ${j.length} 種`),v.length!==j.length?c(`當前 ${v.length} 種`):""]}),children:[e.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[Ae.length>1&&e.jsx(Bn,{items:Ae,value:d,onChange:I=>{u(I),m(!1)}}),e.jsx("span",{className:"bim-d-spacer"}),e.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":g==="versions",onClick:()=>{g==="default"&&m(!0),b(I=>I==="default"?"versions":"default")},children:c(g==="default"?"按版本數排列":"按著錄順序")})]}),e.jsxs("table",{className:"bim-d-zt","data-ncap":!x&&Mn(v.length)?"":void 0,children:[e.jsx("thead",{className:"bim-d-ui",children:e.jsxs("tr",{children:[e.jsx("th",{children:c("作品")}),e.jsx("th",{children:c("部類")}),e.jsx("th",{children:c("職任")}),e.jsx("th",{children:c("存世版本")}),e.jsx("th",{"aria-label":c("影印")})]})}),e.jsx("tbody",{children:$.map(I=>e.jsxs("tr",{children:[e.jsxs("td",{className:"bim-d-zt-main",children:[e.jsx(De,{id:I.id,label:c(I.title),onNavigate:r,renderLink:o,dense:!0}),I.measure?e.jsx(Ue,{items:[c(I.measure)]}):!I.loaded&&n?e.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.section||I.loaded?"":" bim-d-zt-blank"}`,children:I.section?c(I.section):null}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.role?"":" bim-d-zt-blank"}`,children:I.role?c(I.role):e.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.loaded?"":" bim-d-zt-blank"}`,children:I.loaded?I.versionCount?c(`${I.versionCount} 種`):e.jsx("span",{className:"bim-d-zt-empty",children:c("未著錄")}):""}),e.jsx("td",{className:I.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:I.hasImage&&e.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("有影印")})})]},I.id))})]}),$.length===0&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("該職任下的著作尚未著錄。")}),!x&&e.jsx(qi,{total:v.length,shown:$.length,unit:"種著作",onClick:()=>m(!0)})]})]}),P=pe.length>0?e.jsx(St,{id:"external",title:"站外資料",items:pe.map(I=>e.jsxs("a",{href:I.href,target:"_blank",rel:"noopener noreferrer",children:[I.label," ",e.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:pe.map(I=>I.id),foot:xe.cbdb_id!=null&&xe.cbdb_match==="auto"?c("CBDB 為自動匹配,未經人工核對"):void 0}):null;return e.jsx(rn,{railTop:s,back:l,nav:Me,railLinks:a,main:Be,card:de,side:P})},hr="(max-width: 719px)",Hx=`${hr}, (pointer: coarse)`,ql=`
1069
1084
  .bim-ct {
1070
1085
  display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
1071
1086
  max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
@@ -1173,7 +1188,7 @@ ${L??""}`,load:I,files:ge,activeFile:pe??null,activeJuan:(ve==null?void 0:ve.jso
1173
1188
  .bim-ct-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1174
1189
  }
1175
1190
 
1176
- @media ${ur} {
1191
+ @media ${hr} {
1177
1192
  .bim-ct { display: block; padding: 12px 16px 40px; }
1178
1193
  .bim-ct-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
1179
1194
  .bim-ct-lrow > a { grid-template-columns: minmax(0, 1fr); }
@@ -1198,7 +1213,7 @@ ${L??""}`,load:I,files:ge,activeFile:pe??null,activeJuan:(ve==null?void 0:ve.jso
1198
1213
  }
1199
1214
 
1200
1215
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
1201
- @media ${Fx} {
1216
+ @media ${Hx} {
1202
1217
  .bim-ct-row { min-height: 44px; }
1203
1218
  .bim-ct-tw { width: 44px; }
1204
1219
  .bim-ct-pg { min-width: 44px; height: 44px; }
@@ -1224,7 +1239,7 @@ ${L??""}`,load:I,files:ge,activeFile:pe??null,activeJuan:(ve==null?void 0:ve.jso
1224
1239
  /* 窄屏分类抽屉:界栏下按钮和面板都有框 */
1225
1240
  :root[data-layout="boxed"] .bim-ct-drawer-btn { border: ${i("fr-bd")}; background: ${i("fr-bg")}; }
1226
1241
  :root[data-layout="boxed"] .bim-ct-drawer { border: ${i("fr-bd")}; }
1227
- `,wt="未分類",ct="all",mr=20;function an(t){if(!t)return[];const n=[];for(const r of[t.l1,t.l2,t.l3,t.l4]){const o=(r??"").trim();if(!o)break;n.push(o)}return n}function Ox(t){const n=an(t);return n.length?n.join("/"):wt}function Px(t){const n=an(t);return n.length?n.map((r,o)=>n.slice(0,o+1).join("/")):[wt]}function Dx(t,n=[]){const r=new Map;n.forEach((p,c)=>{const d=[p.cata_l1,p.cata_l2,p.cata_l3,p.cata_l4].filter(u=>!!u);d.forEach((u,x)=>{const m=d.slice(0,x+1).join("/");r.has(m)||r.set(m,c)})});const o=new Map;let s=0;for(const p of t){const c=an(p.classification);if(!c.length){s++;continue}let d=o;c.forEach((u,x)=>{const m=c.slice(0,x+1).join("/");let g=d.get(u);g||(g={id:m,label:u,count:0,children:new Map},d.set(u,g)),g.count++,d=g.children})}const l=p=>[...p.values()].sort((c,d)=>{const u=c.label===wt?1:0,x=d.label===wt?1:0;if(u!==x)return u-x;const m=r.get(c.id)??1/0,g=r.get(d.id)??1/0;return m!==g?m-g:c.label.localeCompare(d.label,"zh")}).map(c=>{const d={id:c.id,label:c.label,count:c.count};return c.children.size&&(d.children=l(c.children)),d}),a=l(o);return s>0&&a.push({id:wt,label:wt,count:s}),a}function It(t,n){if(!n)return[];for(const r of t){if(r.id===n)return[r];if(r.children){const o=It(r.children,n);if(o.length)return[r,...o]}}return[]}function xr(t){return t.reduce((n,r)=>n+r.count,0)}function Hx(t){return(t??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function Gx(t){var p;const n={id:t.id,title:t.title||t.id},r=t.juan_count,o=typeof r=="number"?r:r==null?void 0:r.number;typeof o=="number"&&o>0?n.juan=o:t.measure_info&&(n.juan=t.measure_info);const s=(t.authors??[]).filter(c=>c==null?void 0:c.name).map(c=>{const d=c.dynasty||(t.authors.length===1?t.dynasty:void 0);return d?{name:c.name,dynasty:d}:{name:c.name}});s.length&&(n.authors=s);const l=Hx(typeof t.description=="string"?t.description:(p=t.description)==null?void 0:p.text);l&&(n.summary=l);const a=an(t.classification);return a.length&&(n.classification=a),n}function Ux(t,n){const r=t.summary?0:1,o=n.summary?0:1;return r!==o?r-o:t.title.localeCompare(n.title,"zh")}function Vx(t,n=mr){return Math.max(1,Math.ceil(t/n))}function Vl(t,n,r=2){if(n<=1)return[1];const o=new Set([1,n]);for(let a=t-r;a<=t+r;a++)a>=1&&a<=n&&o.add(a);const s=[...o].sort((a,p)=>a-p),l=[];return s.forEach((a,p)=>{if(p>0){const c=a-s[p-1];c===2?l.push(a-1):c>2&&l.push(null)}l.push(a)}),l}const Yx=()=>e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:e.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Kx(t,n,r){const o=[];r&&o.push({id:ct,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,a)=>{var p;for(const c of l){const d=(p=c.children)!=null&&p.length?c.children:null;o.push({id:c.id,parentId:a,hasChildren:!!d,firstChildId:d?d[0].id:null}),d&&n.has(c.id)&&s(d,c.id)}};return s(t,null),o}function Yl({tree:t,selectedId:n,onSelect:r,allLabel:o="全部",label:s="分類"}){const{convert:l}=F(),a=h.useRef(null),p=n&&n!==ct?n:null,c=o!==null,[d,u]=h.useState(()=>{const w=new Set;for(const _ of It(t,p))w.add(_.id);return w});h.useEffect(()=>{const w=It(t,p);w.length&&u(_=>{if(w.every(z=>_.has(z.id)))return _;const S=new Set(_);for(const z of w)S.add(z.id);return S})},[t,p]);const x=h.useMemo(()=>Kx(t,d,c),[t,d,c]),[m,g]=h.useState(null);h.useEffect(()=>{g(null)},[n]);const b=p??(c?ct:null),k=h.useMemo(()=>{var S;const w=new Set(x.map(z=>z.id));if(m&&w.has(m))return m;if(b&&w.has(b))return b;const _=It(t,p).map(z=>z.id).filter(z=>w.has(z));return _.length?_[_.length-1]:((S=x[0])==null?void 0:S.id)??null},[x,m,b,t,p]),y=h.useCallback((w,_)=>{u(S=>{const z=S.has(w),E=_??!z;if(E===z)return S;const T=new Set(S);return E?T.add(w):T.delete(w),T})},[]),j=h.useCallback(w=>{g(w),requestAnimationFrame(()=>{var S;const _=Array.from(((S=a.current)==null?void 0:S.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===w);_==null||_.focus()})},[]),f=h.useCallback((w,_)=>{_&&y(w,!0),r(w)},[r,y]),v=h.useCallback(w=>{const _=w.target.closest("[data-ct-id]");if(!_)return;const S=_.dataset.ctId,z=x.findIndex(N=>N.id===S);if(z<0)return;const E=x[z];let T=null;switch(w.key){case"ArrowDown":T=x[Math.min(x.length-1,z+1)].id;break;case"ArrowUp":T=x[Math.max(0,z-1)].id;break;case"Home":T=x[0].id;break;case"End":T=x[x.length-1].id;break;case"ArrowRight":if(!E.hasChildren)break;d.has(S)?T=E.firstChildId:y(S,!0);break;case"ArrowLeft":E.hasChildren&&d.has(S)?y(S,!1):T=E.parentId;break;case"Enter":case" ":w.preventDefault(),f(S,E.hasChildren);return;default:return}w.preventDefault(),T&&T!==S&&j(T)},[x,d,y,j,f]),$=(w,_)=>w.map((S,z)=>{var W;const E=(W=S.children)!=null&&W.length?S.children:null,T=!!E&&d.has(S.id),N=S.id===p,V=_===1&&w.length>1&&z===w.length-1;return e.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":E?T:void 0,"aria-selected":N,tabIndex:k===S.id?0:-1,"data-ct-id":S.id,className:V?"bim-ct-last":void 0,children:[e.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{g(S.id),f(S.id,!!E)},children:[e.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:E?B=>{B.stopPropagation(),g(S.id),y(S.id)}:void 0,children:E?e.jsx(Yx,{}):null}),e.jsx("span",{className:"bim-ct-lb",children:l(S.label)}),e.jsx("span",{className:"bim-ct-n",children:S.count.toLocaleString("en-US")})]}),T&&e.jsx("ul",{role:"group",children:$(E,_+1)})]},S.id)});return e.jsxs("ul",{ref:a,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:v,children:[c&&e.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:k===ct?0:-1,"data-ct-id":ct,children:e.jsxs("div",{className:"bim-ct-row",onClick:()=>{g(ct),r(ct)},children:[e.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),e.jsx("span",{className:"bim-ct-lb",children:l(o)}),e.jsx("span",{className:"bim-ct-n",children:xr(t).toLocaleString("en-US")})]})}),$(t,1)]})}const Kl=t=>`/item/${encodeURIComponent(t)}`;function qx(t){return t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&!t.altKey}function ql(t){return t==null||t===""?null:typeof t=="number"?`${t}卷`:t}function Jl({work:t,href:n}){var a,p;const{convert:r}=F(),o=ql(t.juan),s=((a=t.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=t.classification)==null?void 0:p.filter(Boolean))??[];return e.jsx("li",{className:"bim-ct-card",children:e.jsxs("a",{href:n,children:[e.jsxs("div",{className:"bim-ct-ch",children:[e.jsx("h2",{className:"bim-ct-ct",children:r(t.title)}),o&&e.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),s.length>0&&e.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>e.jsxs(h.Fragment,{children:[d>0&&"、",c.dynasty&&e.jsxs("span",{className:"bim-ct-dy",children:["〔",r(c.dynasty),"〕"]}),r(c.name)]},d))}),t.summary&&e.jsx("p",{className:"bim-ct-sum",children:r(t.summary)}),l.length>0&&e.jsx("span",{className:"bim-ct-cls",children:l.map(c=>r(c)).join(" · ")})]})})}function Zl({work:t,href:n}){var a,p;const{convert:r}=F(),o=ql(t.juan),s=((a=t.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=t.classification)==null?void 0:p.filter(Boolean))??[];return e.jsx("li",{className:"bim-ct-lrow",children:e.jsxs("a",{href:n,children:[e.jsxs("span",{className:"bim-ct-lt",children:[r(t.title),o&&e.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),e.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>e.jsxs(h.Fragment,{children:[d>0&&"、",c.dynasty&&e.jsxs("span",{className:"bim-ct-dy",children:["〔",r(c.dynasty),"〕"]}),r(c.name)]},d))}),e.jsx("span",{className:"bim-ct-cls",children:l.map(c=>r(c)).join(" · ")})]})})}function Xl({page:t,pageCount:n,onPage:r,pageHref:o,label:s="分頁"}){const{convert:l}=F();if(n<=1)return null;const a=c=>d=>{r&&(o&&!qx(d)||(d.preventDefault(),r(c)))},p=(c,d,u)=>{if(u.disabled)return e.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const x={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return o?e.jsx("a",{...x,href:o(c),onClick:a(c),children:d}):e.jsx("button",{type:"button",...x,onClick:u.current?void 0:a(c),children:d})};return e.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(t-1,l("上一頁"),{disabled:t<=1}),e.jsx("ol",{children:Vl(t,n).map((c,d)=>e.jsx("li",{style:{display:"contents"},children:c===null?e.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(c,c,{current:c===t,aria:l(`第 ${c} 頁`)})},c??`gap${d}`))}),e.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[t," / ",n]}),p(t+1,l("下一頁"),{disabled:t>=n})]})}function Ql({works:t,workLink:n=Kl,emptyText:r="此類暫無作品",view:o="card",...s}){const{convert:l}=F();return e.jsxs("div",{className:"bim-ct-works",children:[t.length===0?e.jsx("p",{className:"bim-ct-empty",children:typeof r=="string"?l(r):r}):o==="list"?e.jsx("ul",{className:"bim-ct-list",children:t.map(a=>e.jsx(Zl,{work:a,href:n(a.id)},a.id))}):e.jsx("ul",{className:"bim-ct-grid",children:t.map(a=>e.jsx(Jl,{work:a,href:n(a.id)},a.id))}),e.jsx(Xl,{...s})]})}const Jx=()=>e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:e.jsx("path",{d:"M2.5 4.5 6 8l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Zx({tree:t,selectedId:n,page:r,pageCount:o,works:s,onSelect:l,onPage:a,searchSlot:p,workLink:c,pageHref:d,allLabel:u="全部",allTitle:x="全部典籍",pageSize:m=mr,className:g,view:b,onViewChange:k}){const{convert:y}=F(),f=`bim-ct-drawer-${h.useId().replace(/:/g,"")}`,[v,$]=h.useState(!1),[w,_]=h.useState("card"),S=b??w,z=B=>{_(B),k==null||k(B)},E=It(t,n&&n!==ct?n:null),T=E.length?E[E.length-1]:null,N=T?T.label:x,V=T?T.count:xr(t),W=h.useCallback(B=>{$(!1),l(B)},[l]);return e.jsxs("div",{className:g?`bim-ct ${g}`:"bim-ct","data-drawer":v?"open":"closed",children:[e.jsx("style",{children:Ul}),e.jsxs("aside",{className:"bim-ct-side","aria-label":y("分類導航"),children:[e.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":v,"aria-controls":f,onClick:()=>$(B=>!B),children:[e.jsxs("span",{children:[y("分類"),":",y(E.length?E.map(B=>B.label).join(" › "):u??x)]}),e.jsx(Jx,{})]}),e.jsxs("div",{className:"bim-ct-drawer",id:f,children:[e.jsx("h2",{className:"bim-ct-side-h",children:y("分類")}),e.jsx(Yl,{tree:t,selectedId:n,onSelect:W,allLabel:u})]})]}),e.jsxs("div",{className:"bim-ct-main",children:[e.jsxs("header",{className:"bim-ct-head",children:[e.jsx("h1",{className:"bim-ct-title",children:y(N)}),E.length>1&&e.jsx("span",{className:"bim-ct-crumb",children:y(E.slice(0,-1).map(B=>B.label).join(" › "))}),e.jsxs("span",{className:"bim-ct-stat",children:[y(`共 ${V.toLocaleString("en-US")} 種 · 每頁 ${m} 條`),o>1&&y(` · 第 ${r} / ${o} 頁`)]}),e.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":y("呈現方式"),children:[e.jsx("button",{type:"button","aria-pressed":S==="card",onClick:()=>z("card"),children:y("卡片")}),e.jsx("button",{type:"button","aria-pressed":S==="list",onClick:()=>z("list"),children:y("列表")})]})]}),p&&e.jsx("div",{className:"bim-ct-search",children:p}),e.jsx(Ql,{works:s,view:S,workLink:c,page:r,pageCount:o,onPage:a,pageHref:d})]})]})}const cn="(max-width: 719px)",Xx="(max-width: 1079px)",Qx=`${cn}, (pointer: coarse)`,eh=[8,18,30,42,88],hr=`
1242
+ `,wt="未分類",ct="all",gr=20;function an(t){if(!t)return[];const n=[];for(const r of[t.l1,t.l2,t.l3,t.l4]){const o=(r??"").trim();if(!o)break;n.push(o)}return n}function Gx(t){const n=an(t);return n.length?n.join("/"):wt}function Ux(t){const n=an(t);return n.length?n.map((r,o)=>n.slice(0,o+1).join("/")):[wt]}function Vx(t,n=[]){const r=new Map;n.forEach((p,c)=>{const d=[p.cata_l1,p.cata_l2,p.cata_l3,p.cata_l4].filter(u=>!!u);d.forEach((u,x)=>{const m=d.slice(0,x+1).join("/");r.has(m)||r.set(m,c)})});const o=new Map;let s=0;for(const p of t){const c=an(p.classification);if(!c.length){s++;continue}let d=o;c.forEach((u,x)=>{const m=c.slice(0,x+1).join("/");let g=d.get(u);g||(g={id:m,label:u,count:0,children:new Map},d.set(u,g)),g.count++,d=g.children})}const l=p=>[...p.values()].sort((c,d)=>{const u=c.label===wt?1:0,x=d.label===wt?1:0;if(u!==x)return u-x;const m=r.get(c.id)??1/0,g=r.get(d.id)??1/0;return m!==g?m-g:c.label.localeCompare(d.label,"zh")}).map(c=>{const d={id:c.id,label:c.label,count:c.count};return c.children.size&&(d.children=l(c.children)),d}),a=l(o);return s>0&&a.push({id:wt,label:wt,count:s}),a}function It(t,n){if(!n)return[];for(const r of t){if(r.id===n)return[r];if(r.children){const o=It(r.children,n);if(o.length)return[r,...o]}}return[]}function fr(t){return t.reduce((n,r)=>n+r.count,0)}function Yx(t){return(t??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function Kx(t){var p;const n={id:t.id,title:t.title||t.id},r=t.juan_count,o=typeof r=="number"?r:r==null?void 0:r.number;typeof o=="number"&&o>0?n.juan=o:t.measure_info&&(n.juan=t.measure_info);const s=(t.authors??[]).filter(c=>c==null?void 0:c.name).map(c=>{const d=c.dynasty||(t.authors.length===1?t.dynasty:void 0);return d?{name:c.name,dynasty:d}:{name:c.name}});s.length&&(n.authors=s);const l=Yx(typeof t.description=="string"?t.description:(p=t.description)==null?void 0:p.text);l&&(n.summary=l);const a=an(t.classification);return a.length&&(n.classification=a),n}function qx(t,n){const r=t.summary?0:1,o=n.summary?0:1;return r!==o?r-o:t.title.localeCompare(n.title,"zh")}function Jx(t,n=gr){return Math.max(1,Math.ceil(t/n))}function Jl(t,n,r=2){if(n<=1)return[1];const o=new Set([1,n]);for(let a=t-r;a<=t+r;a++)a>=1&&a<=n&&o.add(a);const s=[...o].sort((a,p)=>a-p),l=[];return s.forEach((a,p)=>{if(p>0){const c=a-s[p-1];c===2?l.push(a-1):c>2&&l.push(null)}l.push(a)}),l}const Zx=()=>e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:e.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Xx(t,n,r){const o=[];r&&o.push({id:ct,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,a)=>{var p;for(const c of l){const d=(p=c.children)!=null&&p.length?c.children:null;o.push({id:c.id,parentId:a,hasChildren:!!d,firstChildId:d?d[0].id:null}),d&&n.has(c.id)&&s(d,c.id)}};return s(t,null),o}function Zl({tree:t,selectedId:n,onSelect:r,allLabel:o="全部",label:s="分類"}){const{convert:l}=O(),a=h.useRef(null),p=n&&n!==ct?n:null,c=o!==null,[d,u]=h.useState(()=>{const w=new Set;for(const _ of It(t,p))w.add(_.id);return w});h.useEffect(()=>{const w=It(t,p);w.length&&u(_=>{if(w.every(z=>_.has(z.id)))return _;const S=new Set(_);for(const z of w)S.add(z.id);return S})},[t,p]);const x=h.useMemo(()=>Xx(t,d,c),[t,d,c]),[m,g]=h.useState(null);h.useEffect(()=>{g(null)},[n]);const b=p??(c?ct:null),k=h.useMemo(()=>{var S;const w=new Set(x.map(z=>z.id));if(m&&w.has(m))return m;if(b&&w.has(b))return b;const _=It(t,p).map(z=>z.id).filter(z=>w.has(z));return _.length?_[_.length-1]:((S=x[0])==null?void 0:S.id)??null},[x,m,b,t,p]),y=h.useCallback((w,_)=>{u(S=>{const z=S.has(w),E=_??!z;if(E===z)return S;const T=new Set(S);return E?T.add(w):T.delete(w),T})},[]),j=h.useCallback(w=>{g(w),requestAnimationFrame(()=>{var S;const _=Array.from(((S=a.current)==null?void 0:S.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===w);_==null||_.focus()})},[]),f=h.useCallback((w,_)=>{_&&y(w,!0),r(w)},[r,y]),v=h.useCallback(w=>{const _=w.target.closest("[data-ct-id]");if(!_)return;const S=_.dataset.ctId,z=x.findIndex(N=>N.id===S);if(z<0)return;const E=x[z];let T=null;switch(w.key){case"ArrowDown":T=x[Math.min(x.length-1,z+1)].id;break;case"ArrowUp":T=x[Math.max(0,z-1)].id;break;case"Home":T=x[0].id;break;case"End":T=x[x.length-1].id;break;case"ArrowRight":if(!E.hasChildren)break;d.has(S)?T=E.firstChildId:y(S,!0);break;case"ArrowLeft":E.hasChildren&&d.has(S)?y(S,!1):T=E.parentId;break;case"Enter":case" ":w.preventDefault(),f(S,E.hasChildren);return;default:return}w.preventDefault(),T&&T!==S&&j(T)},[x,d,y,j,f]),$=(w,_)=>w.map((S,z)=>{var W;const E=(W=S.children)!=null&&W.length?S.children:null,T=!!E&&d.has(S.id),N=S.id===p,V=_===1&&w.length>1&&z===w.length-1;return e.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":E?T:void 0,"aria-selected":N,tabIndex:k===S.id?0:-1,"data-ct-id":S.id,className:V?"bim-ct-last":void 0,children:[e.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{g(S.id),f(S.id,!!E)},children:[e.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:E?B=>{B.stopPropagation(),g(S.id),y(S.id)}:void 0,children:E?e.jsx(Zx,{}):null}),e.jsx("span",{className:"bim-ct-lb",children:l(S.label)}),e.jsx("span",{className:"bim-ct-n",children:S.count.toLocaleString("en-US")})]}),T&&e.jsx("ul",{role:"group",children:$(E,_+1)})]},S.id)});return e.jsxs("ul",{ref:a,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:v,children:[c&&e.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:k===ct?0:-1,"data-ct-id":ct,children:e.jsxs("div",{className:"bim-ct-row",onClick:()=>{g(ct),r(ct)},children:[e.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),e.jsx("span",{className:"bim-ct-lb",children:l(o)}),e.jsx("span",{className:"bim-ct-n",children:fr(t).toLocaleString("en-US")})]})}),$(t,1)]})}const Xl=t=>`/item/${encodeURIComponent(t)}`;function Qx(t){return t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&!t.altKey}function Ql(t){return t==null||t===""?null:typeof t=="number"?`${t}卷`:t}function ea({work:t,href:n}){var a,p;const{convert:r}=O(),o=Ql(t.juan),s=((a=t.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=t.classification)==null?void 0:p.filter(Boolean))??[];return e.jsx("li",{className:"bim-ct-card",children:e.jsxs("a",{href:n,children:[e.jsxs("div",{className:"bim-ct-ch",children:[e.jsx("h2",{className:"bim-ct-ct",children:r(t.title)}),o&&e.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),s.length>0&&e.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>e.jsxs(h.Fragment,{children:[d>0&&"、",c.dynasty&&e.jsxs("span",{className:"bim-ct-dy",children:["〔",r(c.dynasty),"〕"]}),r(c.name)]},d))}),t.summary&&e.jsx("p",{className:"bim-ct-sum",children:r(t.summary)}),l.length>0&&e.jsx("span",{className:"bim-ct-cls",children:l.map(c=>r(c)).join(" · ")})]})})}function ta({work:t,href:n}){var a,p;const{convert:r}=O(),o=Ql(t.juan),s=((a=t.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=t.classification)==null?void 0:p.filter(Boolean))??[];return e.jsx("li",{className:"bim-ct-lrow",children:e.jsxs("a",{href:n,children:[e.jsxs("span",{className:"bim-ct-lt",children:[r(t.title),o&&e.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),e.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>e.jsxs(h.Fragment,{children:[d>0&&"、",c.dynasty&&e.jsxs("span",{className:"bim-ct-dy",children:["〔",r(c.dynasty),"〕"]}),r(c.name)]},d))}),e.jsx("span",{className:"bim-ct-cls",children:l.map(c=>r(c)).join(" · ")})]})})}function na({page:t,pageCount:n,onPage:r,pageHref:o,label:s="分頁"}){const{convert:l}=O();if(n<=1)return null;const a=c=>d=>{r&&(o&&!Qx(d)||(d.preventDefault(),r(c)))},p=(c,d,u)=>{if(u.disabled)return e.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const x={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return o?e.jsx("a",{...x,href:o(c),onClick:a(c),children:d}):e.jsx("button",{type:"button",...x,onClick:u.current?void 0:a(c),children:d})};return e.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(t-1,l("上一頁"),{disabled:t<=1}),e.jsx("ol",{children:Jl(t,n).map((c,d)=>e.jsx("li",{style:{display:"contents"},children:c===null?e.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(c,c,{current:c===t,aria:l(`第 ${c} 頁`)})},c??`gap${d}`))}),e.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[t," / ",n]}),p(t+1,l("下一頁"),{disabled:t>=n})]})}function ia({works:t,workLink:n=Xl,emptyText:r="此類暫無作品",view:o="card",...s}){const{convert:l}=O();return e.jsxs("div",{className:"bim-ct-works",children:[t.length===0?e.jsx("p",{className:"bim-ct-empty",children:typeof r=="string"?l(r):r}):o==="list"?e.jsx("ul",{className:"bim-ct-list",children:t.map(a=>e.jsx(ta,{work:a,href:n(a.id)},a.id))}):e.jsx("ul",{className:"bim-ct-grid",children:t.map(a=>e.jsx(ea,{work:a,href:n(a.id)},a.id))}),e.jsx(na,{...s})]})}const eh=()=>e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:e.jsx("path",{d:"M2.5 4.5 6 8l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function th({tree:t,selectedId:n,page:r,pageCount:o,works:s,onSelect:l,onPage:a,searchSlot:p,workLink:c,pageHref:d,allLabel:u="全部",allTitle:x="全部典籍",pageSize:m=gr,className:g,view:b,onViewChange:k}){const{convert:y}=O(),f=`bim-ct-drawer-${h.useId().replace(/:/g,"")}`,[v,$]=h.useState(!1),[w,_]=h.useState("card"),S=b??w,z=B=>{_(B),k==null||k(B)},E=It(t,n&&n!==ct?n:null),T=E.length?E[E.length-1]:null,N=T?T.label:x,V=T?T.count:fr(t),W=h.useCallback(B=>{$(!1),l(B)},[l]);return e.jsxs("div",{className:g?`bim-ct ${g}`:"bim-ct","data-drawer":v?"open":"closed",children:[e.jsx("style",{children:ql}),e.jsxs("aside",{className:"bim-ct-side","aria-label":y("分類導航"),children:[e.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":v,"aria-controls":f,onClick:()=>$(B=>!B),children:[e.jsxs("span",{children:[y("分類"),":",y(E.length?E.map(B=>B.label).join(" › "):u??x)]}),e.jsx(eh,{})]}),e.jsxs("div",{className:"bim-ct-drawer",id:f,children:[e.jsx("h2",{className:"bim-ct-side-h",children:y("分類")}),e.jsx(Zl,{tree:t,selectedId:n,onSelect:W,allLabel:u})]})]}),e.jsxs("div",{className:"bim-ct-main",children:[e.jsxs("header",{className:"bim-ct-head",children:[e.jsx("h1",{className:"bim-ct-title",children:y(N)}),E.length>1&&e.jsx("span",{className:"bim-ct-crumb",children:y(E.slice(0,-1).map(B=>B.label).join(" › "))}),e.jsxs("span",{className:"bim-ct-stat",children:[y(`共 ${V.toLocaleString("en-US")} 種 · 每頁 ${m} 條`),o>1&&y(` · 第 ${r} / ${o} 頁`)]}),e.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":y("呈現方式"),children:[e.jsx("button",{type:"button","aria-pressed":S==="card",onClick:()=>z("card"),children:y("卡片")}),e.jsx("button",{type:"button","aria-pressed":S==="list",onClick:()=>z("list"),children:y("列表")})]})]}),p&&e.jsx("div",{className:"bim-ct-search",children:p}),e.jsx(ia,{works:s,view:S,workLink:c,page:r,pageCount:o,onPage:a,pageHref:d})]})]})}const cn="(max-width: 719px)",nh="(max-width: 1079px)",ih=`${cn}, (pointer: coarse)`,rh=[8,18,30,42,88],br=`
1228
1243
  .bim-rh { color: ${i("ink")}; font-family: ${i("font-ui")}; font-size: 14px; line-height: 1.6; }
1229
1244
  .bim-rh *, .bim-rh *::before, .bim-rh *::after { box-sizing: border-box; }
1230
1245
  .bim-rh a { color: ${i("accent")}; text-decoration: none; }
@@ -1372,7 +1387,7 @@ ${L??""}`,load:I,files:ge,activeFile:pe??null,activeJuan:(ve==null?void 0:ve.jso
1372
1387
  flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; padding: 0 8px; overflow: hidden;
1373
1388
  color: ${i("ink")} !important; font-size: 13px;
1374
1389
  }
1375
- ${eh.map((t,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb, ${i("accent")} ${t}%, ${i("card-bg")}); }`).join(`
1390
+ ${rh.map((t,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb, ${i("accent")} ${t}%, ${i("card-bg")}); }`).join(`
1376
1391
  `)}
1377
1392
  .bim-rh-band a[data-k="4"] { color: ${i("page-bg")} !important; }
1378
1393
  .bim-rh-band a:hover { outline: 2px solid ${i("ink")}; outline-offset: -2px; }
@@ -1400,7 +1415,7 @@ ${eh.map((t,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1400
1415
  }
1401
1416
 
1402
1417
  /* ── 中屏 ── */
1403
- @media ${Xx} {
1418
+ @media ${nh} {
1404
1419
  .bim-rh-picks, .bim-rh-works, .bim-rh-groups, .bim-rh-bu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1405
1420
  .bim-rh-authors { grid-template-columns: repeat(3, minmax(0, 1fr)); }
1406
1421
  }
@@ -1420,8 +1435,10 @@ ${eh.map((t,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1420
1435
  .bim-rh-works, .bim-rh-groups { grid-template-columns: minmax(0, 1fr); }
1421
1436
  .bim-rh-groups { gap: 24px; }
1422
1437
  .bim-rh-shelf-box + .bim-rh-groups { margin-top: 24px; }
1423
- /* 长分组只露前 6 条,「全部」按钮展开 */
1424
- .bim-rh-grp:not([data-open]) .bim-rh-rows li:nth-child(n+7) { display: none; }
1438
+ /* 长分组只露前 4 条,「全部」按钮展开(overview#325:原先 6 条,专题七组铺开约 2000px) */
1439
+ .bim-rh-grp[data-cap]:not([data-open]) .bim-rh-rows li:nth-child(n+5) { display: none; }
1440
+ /* 年代带在手机上已改成写全名的格子,「窄段悬停看全名」不适用 */
1441
+ .bim-rh-hover-hint { display: none; }
1425
1442
  .bim-rh-expand { display: inline-flex; }
1426
1443
  .bim-rh-bu { gap: 22px 16px; }
1427
1444
  .bim-rh-bu-h b { font-size: 21px; }
@@ -1435,14 +1452,24 @@ ${eh.map((t,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1435
1452
  .bim-rh-band a[data-narrow] .bim-rh-pl-s { display: none; }
1436
1453
  }
1437
1454
 
1455
+ /* 没有悬停的设备(触屏)也不说「悬停」 */
1456
+ @media (hover: none) {
1457
+ .bim-rh-hover-hint { display: none; }
1458
+ }
1459
+
1438
1460
  /* 触屏或窄屏:点击目标放大到 44px */
1439
- @media ${Qx} {
1461
+ @media ${ih} {
1440
1462
  .bim-rh-rows a, .bim-rh-bu-l a, .bim-rh-au li a, .bim-rh-chip, .bim-rh-secnav a, .bim-rh-expand { min-height: 44px; display: flex; align-items: center; }
1441
1463
  .bim-rh-chip { display: inline-flex; }
1442
1464
  }
1443
1465
 
1466
+ /* 「全部 N 部」展开键只在窄屏有用(宽屏分组本就全显示);上面触屏块的 display: flex 不能让它在平板宽屏上冒出来 */
1467
+ @media (min-width: 720px) {
1468
+ .bim-rh-expand { display: none; }
1469
+ }
1470
+
1444
1471
  @media (prefers-reduced-motion: reduce) { .bim-rh * { scroll-behavior: auto !important; transition: none !important; } }
1445
- `,ea={xianqin:"先秦",qinhan:"秦漢",weijin:"魏晉南北朝",suitang:"隋唐五代",song:"宋",liaojinyuan:"遼金元",ming:"明",qing:"清",modern:"近現代"},ta={read:t=>`/read/${encodeURIComponent(t)}`,node:t=>`/read?node=${encodeURIComponent(t)}`,period:t=>`/read?period=${encodeURIComponent(t)}`,work:t=>`/item/${encodeURIComponent(t)}`};function ft(t){return{...ta,...t??{}}}function gr(t){var r;const n=(r=t.authors)==null?void 0:r.find(o=>o==null?void 0:o.name);return n?n.dynasty?`${n.dynasty} ${n.name}`:n.name:""}function Wn(t){return(t.authors??[]).filter(r=>r==null?void 0:r.name).map(r=>r.dynasty?`〔${r.dynasty}〕${r.name}`:r.name).join(" ")}function na(t){var o;const n=[],r=new Map;for(const s of t){const l=((o=s.period_of)==null?void 0:o.trim())||"其他";let a=r.get(l);a||(a={label:l,items:[]},r.set(l,a),n.push(a)),a.items.push(s)}return n}function ia(t){return Math.max(150,Array.from(t).length*18+44)}function ra(t,n){if(n<=0||t<=0)return 0;const r=t/n;return r<.15?0:r<.35?1:r<.6?2:r<.85?3:4}const oa=.04;function Pe(t){return t.toLocaleString("en-US")}function sa({text:t}){return e.jsx(e.Fragment,{children:Array.from(t).map((n,r)=>e.jsx("span",{children:n},r))})}function qe({id:t,title:n,sub:r,more:o,children:s}){const{convert:l}=F(),a=`${t}-h`;return e.jsxs("section",{className:"bim-rh-sec",id:t,"aria-labelledby":a,children:[e.jsxs("div",{className:"bim-rh-hd",children:[e.jsx("h2",{id:a,children:l(n)}),r&&e.jsx("span",{className:"bim-rh-sub",children:r}),o]}),e.jsx("div",{className:"bim-rh-bd",children:s})]})}function la({counts:t}){const{convert:n}=F();return e.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[e.jsxs("span",{children:[e.jsx("b",{children:Pe(t.readable)}),n("部可讀")]}),t.pieces>0&&e.jsxs("span",{children:[e.jsx("b",{children:Pe(t.pieces)}),n("篇單篇詩文")]})]})}function aa({picks:t,links:n}){const{convert:r}=F(),o=ft(n);return t.length?e.jsx("ul",{className:"bim-rh-picks",children:t.map(s=>{const l=Wn(s),a=[s.type_label,s.edition].filter(Boolean).join(" · ");return e.jsx("li",{children:e.jsxs("a",{className:"bim-rh-pk",href:o.read(s.id),children:[e.jsx("span",{className:"bim-rh-slip","aria-hidden":"true",children:e.jsx(sa,{text:r(s.slip||s.title)})}),e.jsxs("span",{className:"bim-rh-pk-body",children:[a&&e.jsx("span",{className:"bim-rh-badge",children:r(a)}),e.jsx("h3",{children:r(s.title)}),l&&e.jsx("span",{className:"bim-rh-by",children:r(l)}),s.blurb&&e.jsx("p",{children:r(s.blurb)}),e.jsx("span",{className:"bim-rh-go","aria-hidden":"true",children:r("開始閱讀 →")})]})]})},s.id)})}):null}function ca(t){return t&&t>1?`${t}本`:null}function fr({topic:t,links:n,hint:r,legendCount:o="脊下「2本」=站內有幾個本子",showTitle:s=!0,legendExtra:l}){const{convert:a}=F(),p=ft(n);if(!t.items.length)return null;const c=na(t.items),d=u=>{const x=u.records?Pe(u.records):ca(u.text_count),m=gr(u),g=[u.title,u.orig?"正史原志":"",m?`${m} 撰`:"",u.records?`著錄 ${x} 條`:x?`站內 ${x}`:""].filter(Boolean).join(",");return e.jsx("li",{children:e.jsxs("a",{className:"bim-rh-spine",href:p.read(u.id),"data-orig":u.orig?"":void 0,"aria-label":a(g),title:a(g),style:{height:ia(u.title)},children:[e.jsx(sa,{text:a(u.title)}),x&&e.jsx("span",{className:"bim-rh-n bim-rh-num","data-records":u.records?"":void 0,children:a(x)})]})},u.id)};return e.jsxs("div",{className:"bim-rh-shelf-box",children:[s&&e.jsxs("h3",{className:"bim-rh-gt",children:[a(t.label),e.jsx("small",{children:a(r??"按所志朝代排列,一脊一部")})]}),e.jsx("div",{className:"bim-rh-shelf-wrap",tabIndex:0,role:"region","aria-label":a(`${t.label}書架,可橫向滾動`),children:e.jsx("ul",{className:"bim-rh-shelf",children:c.map(u=>e.jsxs("li",{className:"bim-rh-era",children:[e.jsx("ul",{className:"bim-rh-spines","aria-label":a(u.label),children:u.items.map(d)}),e.jsx("span",{"aria-hidden":"true",children:a(u.label)})]},u.label))})}),e.jsxs("p",{className:"bim-rh-legend",children:[e.jsxs("span",{children:[e.jsx("i",{"data-orig":"","aria-hidden":"true"}),a("正史原志")]}),e.jsxs("span",{children:[e.jsx("i",{"aria-hidden":"true"}),a("後人補撰、續補")]}),o&&e.jsx("span",{children:a(o)}),l==null?void 0:l.map(u=>e.jsx("span",{children:a(u)},u))]})]})}function da({topic:t,links:n}){const{convert:r}=F(),o=ft(n),[s,l]=h.useState(!1);if(!t.items.length)return null;const a=`bim-rh-g-${t.key}`;return e.jsxs("div",{className:"bim-rh-grp","data-open":s?"":void 0,children:[e.jsxs("h3",{className:"bim-rh-gt",id:a,children:[r(t.label),e.jsx("small",{className:"bim-rh-num",children:r(`${Pe(t.items.length)} 部`)})]}),e.jsx("ul",{className:"bim-rh-rows","aria-labelledby":a,children:t.items.map(p=>{const c=ca(p.text_count),d=gr(p);return e.jsx("li",{children:e.jsxs("a",{href:o.read(p.id),children:[e.jsx("span",{className:"bim-rh-t",children:r(p.title)}),c&&e.jsx("em",{className:"bim-rh-cnt bim-rh-num",children:r(c)}),d&&e.jsx("small",{children:r(d)})]})},p.id)})}),t.items.length>6&&e.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":s,onClick:()=>l(p=>!p),children:r(s?"收起":`全部 ${t.items.length} 部`)})]})}function pa({topics:t,links:n}){const r=t.filter(s=>s.shelf&&s.items.length),o=t.filter(s=>!s.shelf&&s.items.length);return!r.length&&!o.length?null:e.jsxs(e.Fragment,{children:[r.map(s=>e.jsx(fr,{topic:s,links:n},s.key)),o.length>0&&e.jsx("div",{className:"bim-rh-groups",children:o.map(s=>e.jsx(da,{topic:s,links:n},s.key))})]})}function ua({famous:t,links:n}){const{convert:r}=F(),o=ft(n);return t.length?e.jsx("ul",{className:"bim-rh-works",children:t.map(s=>e.jsx("li",{children:e.jsxs("article",{className:"bim-rh-wk",children:[e.jsxs("div",{className:"bim-rh-wk-h",children:[e.jsx("h3",{children:r(s.title)}),s.authors&&e.jsx("span",{className:"bim-rh-by",children:r(s.authors)}),e.jsx("span",{className:"bim-rh-c bim-rh-num",children:r(`${s.text_count} 個本子`)})]}),s.systems.map((l,a)=>e.jsxs("div",{className:"bim-rh-lin",role:"group","aria-label":l.label?r(l.label):void 0,children:[l.label&&e.jsx("small",{"aria-hidden":"true",children:r(l.label)}),l.items.map(p=>e.jsx("a",{className:"bim-rh-chip",href:o.read(p.id),title:r([p.title,p.edition].filter(Boolean).join(" · ")),children:r(p.short)},p.id))]},a)),s.work_id&&e.jsx("div",{className:"bim-rh-wk-f",children:e.jsx("a",{href:o.work(s.work_id),children:r(`作品頁:${s.title}的源流與全部版本 →`)})})]})},s.work_id??s.title))}):null}function br({bu:t,unclassified:n,links:r,unclassifiedNote:o="書目分類還沒補齊,其中多數是單篇詩文,已單列在下方。"}){const{convert:s}=F(),l=ft(r);return!t.length&&!n?null:e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"bim-rh-bu",children:t.map(a=>{var c;const p=((c=a.top[0])==null?void 0:c.count)||1;return e.jsxs("li",{className:"bim-rh-bu-c",children:[e.jsxs("a",{className:"bim-rh-bu-h",href:l.node(a.id),children:[e.jsx("b",{children:s(a.label)}),e.jsx("span",{className:"bim-rh-num",children:s(`${Pe(a.count)} 部`)})]}),a.top.length>0&&e.jsx("ul",{className:"bim-rh-bu-l","aria-label":s(`${a.label}子類`),children:a.top.map(d=>e.jsx("li",{children:e.jsxs("a",{href:l.node(d.id),children:[e.jsx("span",{children:s(d.label)}),e.jsx("small",{className:"bim-rh-num",children:Pe(d.count)}),e.jsx("span",{className:"bim-rh-bar","aria-hidden":"true",style:{"--bimrh-w":`${Math.round(d.count/p*100)}%`}})]})},d.id))}),a.children_total>a.top.length&&e.jsx("a",{className:"bim-rh-bu-more",href:l.node(a.id),children:s(`${a.label}全部 ${a.children_total} 類 →`)})]},a.id)})}),!!n&&e.jsxs("p",{className:"bim-rh-uncl bim-rh-num",children:[e.jsx("b",{children:s("未分類")}),e.jsx("span",{children:s(`${Pe(n)} 部`)}),e.jsx("span",{children:s(o)}),e.jsx("a",{href:l.node("unclassified"),children:s("查看未分類 →")})]})]})}function ma({periods:t,unknown:n,links:r}){const{convert:o}=F(),s=ft(r),l=t.filter(c=>c.count>0);if(!l.length)return null;const a=l.reduce((c,d)=>c+d.count,0),p=Math.max(...l.map(c=>c.count));return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"bim-rh-band",children:l.map(c=>{const d=o(c.label||ea[c.key]||c.key),u=c.count/a,x=`${d},${Pe(c.count)} ${o("部")}`;return e.jsx("li",{style:{flex:`0 0 ${(u*100).toFixed(3)}%`},children:e.jsxs("a",{href:s.period(c.key),"data-k":ra(c.count,p),"data-narrow":u<oa?"":void 0,"aria-label":x,title:x,children:[e.jsx("span",{className:"bim-rh-pl",children:d}),e.jsx("span",{className:"bim-rh-pl-s","aria-hidden":"true",children:Array.from(d)[0]}),e.jsx("small",{className:"bim-rh-num",children:Pe(c.count)})]})},c.key)})}),e.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!n&&e.jsx("span",{children:o(`另有 ${Pe(n)} 部作者無朝代,在「四部」和搜索裏能找到`)}),e.jsx("span",{children:o("窄段懸停看全名")})]})]})}function xa({authors:t,links:n}){const{convert:r}=F(),o=ft(n);return t.length?e.jsx("ul",{className:"bim-rh-authors",children:t.map(s=>e.jsxs("li",{className:"bim-rh-au",children:[e.jsxs("h3",{className:"bim-rh-au-h",children:[r(s.name),s.dynasty&&e.jsx("span",{children:r(s.dynasty)}),e.jsx("small",{className:"bim-rh-num",children:r(`${Pe(s.count)} 篇`)})]}),e.jsx("ul",{children:s.items.map(l=>e.jsx("li",{children:e.jsx("a",{href:o.read(l.id),children:r(l.title)})},l.id))}),o.author&&e.jsx("a",{className:"bim-rh-more",href:o.author(s.name),children:r(`${s.name}全部 ${s.count} 篇 →`)})]},s.name))}):null}const ha={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function th({sections:t,links:n,head:r,piecesMoreHref:o,className:s}){const{convert:l}=F(),a=t,p=ha,c=a.topics.filter(x=>!x.shelf),d={picks:a.picks.length>0,topics:c.some(x=>x.items.length>0),famous:a.famous.length>0,sibu:a.bu.length>0||a.unclassified>0,period:a.periods.some(x=>x.count>0),pieces:a.pieces.authors.length>0},u=[["picks","推薦閱讀"],["topics","專題"],["famous","名著與版本"],["sibu","四部"],["period","按年代"],["pieces","單篇詩文"]].filter(([x])=>d[x]);return e.jsxs("div",{className:s?`bim-rh ${s}`:"bim-rh",children:[e.jsx("style",{children:hr}),e.jsxs("div",{className:"bim-rh-head",children:[r,e.jsx(la,{counts:a.counts})]}),u.length>1&&e.jsx("nav",{className:"bim-rh-secnav","aria-label":l("閱讀首頁分區"),children:e.jsx("ul",{children:u.map(([x,m])=>e.jsx("li",{children:e.jsx("a",{href:`#${p[x]}`,children:l(m)})},x))})}),e.jsxs("div",{className:"bim-rh-main",children:[d.picks&&e.jsx(qe,{id:p.picks,title:"推薦閱讀",sub:l("編輯挑選,定期輪換"),children:e.jsx(aa,{picks:a.picks,links:n})}),d.topics&&e.jsx(qe,{id:p.topics,title:"專題",sub:l("按作品類型歸組;小說見下方「名著與版本」"),children:e.jsx(pa,{topics:c,links:n})}),d.famous&&e.jsx(qe,{id:p.famous,title:"名著與版本",sub:l("一部作品一張卡,卡上列出站內能讀的各個本子"),children:e.jsx(ua,{famous:a.famous,links:n})}),d.sibu&&e.jsx(qe,{id:p.sibu,title:"四部",sub:l("按古籍總目的分類樹,只計站內可讀的作品"),children:e.jsx(br,{bu:a.bu,unclassified:a.unclassified,links:n})}),d.period&&e.jsx(qe,{id:p.period,title:"按年代",sub:l("按作者朝代歸段,寬度與部數成比例"),children:e.jsx(ma,{periods:a.periods,unknown:a.period_unknown,links:n})}),d.pieces&&e.jsx(qe,{id:p.pieces,title:"單篇詩文",sub:l("單篇的詩、文、賦、表,按作者歸組"),more:o?e.jsx("a",{className:"bim-rh-more",href:o,children:l("按作者瀏覽全部 →")}):void 0,children:e.jsx(xa,{authors:a.pieces.authors,links:n})})]})]})}const nh="(max-width: 1079px)",ih=`${cn}, (pointer: coarse)`,ga=`
1472
+ `,ra={xianqin:"先秦",qinhan:"秦漢",weijin:"魏晉南北朝",suitang:"隋唐五代",song:"宋",liaojinyuan:"遼金元",ming:"明",qing:"清",modern:"近現代"},oa={read:t=>`/read/${encodeURIComponent(t)}`,node:t=>`/read?node=${encodeURIComponent(t)}`,period:t=>`/read?period=${encodeURIComponent(t)}`,work:t=>`/item/${encodeURIComponent(t)}`};function ft(t){return{...oa,...t??{}}}function yr(t){var r;const n=(r=t.authors)==null?void 0:r.find(o=>o==null?void 0:o.name);return n?n.dynasty?`${n.dynasty} ${n.name}`:n.name:""}function On(t){return(t.authors??[]).filter(r=>r==null?void 0:r.name).map(r=>r.dynasty?`〔${r.dynasty}〕${r.name}`:r.name).join(" ")}function sa(t){var o;const n=[],r=new Map;for(const s of t){const l=((o=s.period_of)==null?void 0:o.trim())||"其他";let a=r.get(l);a||(a={label:l,items:[]},r.set(l,a),n.push(a)),a.items.push(s)}return n}function la(t){return Math.max(150,Array.from(t).length*18+44)}function aa(t,n){if(n<=0||t<=0)return 0;const r=t/n;return r<.15?0:r<.35?1:r<.6?2:r<.85?3:4}const ca=.04;function Pe(t){return t.toLocaleString("en-US")}function da({text:t}){return e.jsx(e.Fragment,{children:Array.from(t).map((n,r)=>e.jsx("span",{children:n},r))})}function qe({id:t,title:n,sub:r,more:o,children:s}){const{convert:l}=O(),a=`${t}-h`;return e.jsxs("section",{className:"bim-rh-sec",id:t,"aria-labelledby":a,children:[e.jsxs("div",{className:"bim-rh-hd",children:[e.jsx("h2",{id:a,children:l(n)}),r&&e.jsx("span",{className:"bim-rh-sub",children:r}),o]}),e.jsx("div",{className:"bim-rh-bd",children:s})]})}function pa({counts:t}){const{convert:n}=O();return e.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[e.jsxs("span",{children:[e.jsx("b",{children:Pe(t.readable)}),n("部可讀")]}),t.pieces>0&&e.jsxs("span",{children:[e.jsx("b",{children:Pe(t.pieces)}),n("篇單篇詩文")]})]})}function ua({picks:t,links:n}){const{convert:r}=O(),o=ft(n);return t.length?e.jsx("ul",{className:"bim-rh-picks",children:t.map(s=>{const l=On(s),a=[s.type_label,s.edition].filter(Boolean).join(" · ");return e.jsx("li",{children:e.jsxs("a",{className:"bim-rh-pk",href:o.read(s.id),children:[e.jsx("span",{className:"bim-rh-slip","aria-hidden":"true",children:e.jsx(da,{text:r(s.slip||s.title)})}),e.jsxs("span",{className:"bim-rh-pk-body",children:[a&&e.jsx("span",{className:"bim-rh-badge",children:r(a)}),e.jsx("h3",{children:r(s.title)}),l&&e.jsx("span",{className:"bim-rh-by",children:r(l)}),s.blurb&&e.jsx("p",{children:r(s.blurb)}),e.jsx("span",{className:"bim-rh-go","aria-hidden":"true",children:r("開始閱讀 →")})]})]})},s.id)})}):null}function ma(t){return t&&t>1?`${t}本`:null}function jr({topic:t,links:n,hint:r,legendCount:o="脊下「2本」=站內有幾個本子",showTitle:s=!0,legendExtra:l}){const{convert:a}=O(),p=ft(n);if(!t.items.length)return null;const c=sa(t.items),d=u=>{const x=u.records?Pe(u.records):ma(u.text_count),m=yr(u),g=[u.title,u.orig?"正史原志":"",m?`${m} 撰`:"",u.records?`著錄 ${x} 條`:x?`站內 ${x}`:""].filter(Boolean).join(",");return e.jsx("li",{children:e.jsxs("a",{className:"bim-rh-spine",href:p.read(u.id),"data-orig":u.orig?"":void 0,"aria-label":a(g),title:a(g),style:{height:la(u.title)},children:[e.jsx(da,{text:a(u.title)}),x&&e.jsx("span",{className:"bim-rh-n bim-rh-num","data-records":u.records?"":void 0,children:a(x)})]})},u.id)};return e.jsxs("div",{className:"bim-rh-shelf-box",children:[s&&e.jsxs("h3",{className:"bim-rh-gt",children:[a(t.label),e.jsx("small",{children:a(r??"按所志朝代排列,一脊一部")})]}),e.jsx("div",{className:"bim-rh-shelf-wrap",tabIndex:0,role:"region","aria-label":a(`${t.label}書架,可橫向滾動`),children:e.jsx("ul",{className:"bim-rh-shelf",children:c.map(u=>e.jsxs("li",{className:"bim-rh-era",children:[e.jsx("ul",{className:"bim-rh-spines","aria-label":a(u.label),children:u.items.map(d)}),e.jsx("span",{"aria-hidden":"true",children:a(u.label)})]},u.label))})}),e.jsxs("p",{className:"bim-rh-legend",children:[e.jsxs("span",{children:[e.jsx("i",{"data-orig":"","aria-hidden":"true"}),a("正史原志")]}),e.jsxs("span",{children:[e.jsx("i",{"aria-hidden":"true"}),a("後人補撰、續補")]}),o&&e.jsx("span",{children:a(o)}),l==null?void 0:l.map(u=>e.jsx("span",{children:a(u)},u))]})]})}const oh=4,tn=t=>t>oh+1;function xa({topic:t,links:n}){const{convert:r}=O(),o=ft(n),[s,l]=h.useState(!1);if(!t.items.length)return null;const a=`bim-rh-g-${t.key}`;return e.jsxs("div",{className:"bim-rh-grp","data-cap":tn(t.items.length)?"":void 0,"data-open":s?"":void 0,children:[e.jsxs("h3",{className:"bim-rh-gt",id:a,children:[r(t.label),e.jsx("small",{className:"bim-rh-num",children:r(`${Pe(t.items.length)} 部`)})]}),e.jsx("ul",{className:"bim-rh-rows","aria-labelledby":a,children:t.items.map(p=>{const c=ma(p.text_count),d=yr(p);return e.jsx("li",{children:e.jsxs("a",{href:o.read(p.id),children:[e.jsx("span",{className:"bim-rh-t",children:r(p.title)}),c&&e.jsx("em",{className:"bim-rh-cnt bim-rh-num",children:r(c)}),d&&e.jsx("small",{children:r(d)})]})},p.id)})}),tn(t.items.length)&&e.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":s,onClick:()=>l(p=>!p),children:r(s?"收起":`全部 ${t.items.length} 部`)})]})}function ha({topics:t,links:n}){const r=t.filter(s=>s.shelf&&s.items.length),o=t.filter(s=>!s.shelf&&s.items.length);return!r.length&&!o.length?null:e.jsxs(e.Fragment,{children:[r.map(s=>e.jsx(jr,{topic:s,links:n},s.key)),o.length>0&&e.jsx("div",{className:"bim-rh-groups",children:o.map(s=>e.jsx(xa,{topic:s,links:n},s.key))})]})}function ga({famous:t,links:n}){const{convert:r}=O(),o=ft(n);return t.length?e.jsx("ul",{className:"bim-rh-works",children:t.map(s=>e.jsx("li",{children:e.jsxs("article",{className:"bim-rh-wk",children:[e.jsxs("div",{className:"bim-rh-wk-h",children:[e.jsx("h3",{children:r(s.title)}),s.authors&&e.jsx("span",{className:"bim-rh-by",children:r(s.authors)}),e.jsx("span",{className:"bim-rh-c bim-rh-num",children:r(`${s.text_count} 個本子`)})]}),s.systems.map((l,a)=>e.jsxs("div",{className:"bim-rh-lin",role:"group","aria-label":l.label?r(l.label):void 0,children:[l.label&&e.jsx("small",{"aria-hidden":"true",children:r(l.label)}),l.items.map(p=>e.jsx("a",{className:"bim-rh-chip",href:o.read(p.id),title:r([p.title,p.edition].filter(Boolean).join(" · ")),children:r(p.short)},p.id))]},a)),s.work_id&&e.jsx("div",{className:"bim-rh-wk-f",children:e.jsx("a",{href:o.work(s.work_id),children:r(`作品頁:${s.title}的源流與全部版本 →`)})})]})},s.work_id??s.title))}):null}function vr({bu:t,unclassified:n,links:r,unclassifiedNote:o="書目分類還沒補齊,其中多數是單篇詩文,已單列在下方。"}){const{convert:s}=O(),l=ft(r);return!t.length&&!n?null:e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"bim-rh-bu",children:t.map(a=>{var c;const p=((c=a.top[0])==null?void 0:c.count)||1;return e.jsxs("li",{className:"bim-rh-bu-c",children:[e.jsxs("a",{className:"bim-rh-bu-h",href:l.node(a.id),children:[e.jsx("b",{children:s(a.label)}),e.jsx("span",{className:"bim-rh-num",children:s(`${Pe(a.count)} 部`)})]}),a.top.length>0&&e.jsx("ul",{className:"bim-rh-bu-l","aria-label":s(`${a.label}子類`),children:a.top.map(d=>e.jsx("li",{children:e.jsxs("a",{href:l.node(d.id),children:[e.jsx("span",{children:s(d.label)}),e.jsx("small",{className:"bim-rh-num",children:Pe(d.count)}),e.jsx("span",{className:"bim-rh-bar","aria-hidden":"true",style:{"--bimrh-w":`${Math.round(d.count/p*100)}%`}})]})},d.id))}),a.children_total>a.top.length&&e.jsx("a",{className:"bim-rh-bu-more",href:l.node(a.id),children:s(`${a.label}全部 ${a.children_total} 類 →`)})]},a.id)})}),!!n&&e.jsxs("p",{className:"bim-rh-uncl bim-rh-num",children:[e.jsx("b",{children:s("未分類")}),e.jsx("span",{children:s(`${Pe(n)} 部`)}),e.jsx("span",{children:s(o)}),e.jsx("a",{href:l.node("unclassified"),children:s("查看未分類 →")})]})]})}function fa({periods:t,unknown:n,links:r}){const{convert:o}=O(),s=ft(r),l=t.filter(c=>c.count>0);if(!l.length)return null;const a=l.reduce((c,d)=>c+d.count,0),p=Math.max(...l.map(c=>c.count));return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"bim-rh-band",children:l.map(c=>{const d=o(c.label||ra[c.key]||c.key),u=c.count/a,x=`${d},${Pe(c.count)} ${o("部")}`;return e.jsx("li",{style:{flex:`0 0 ${(u*100).toFixed(3)}%`},children:e.jsxs("a",{href:s.period(c.key),"data-k":aa(c.count,p),"data-narrow":u<ca?"":void 0,"aria-label":x,title:x,children:[e.jsx("span",{className:"bim-rh-pl",children:d}),e.jsx("span",{className:"bim-rh-pl-s","aria-hidden":"true",children:Array.from(d)[0]}),e.jsx("small",{className:"bim-rh-num",children:Pe(c.count)})]})},c.key)})}),e.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!n&&e.jsx("span",{children:o(`另有 ${Pe(n)} 部作者無朝代,在「四部」和搜索裏能找到`)}),e.jsx("span",{className:"bim-rh-hover-hint",children:o("窄段懸停看全名")})]})]})}function ba({authors:t,links:n}){const{convert:r}=O(),o=ft(n);return t.length?e.jsx("ul",{className:"bim-rh-authors",children:t.map(s=>e.jsxs("li",{className:"bim-rh-au",children:[e.jsxs("h3",{className:"bim-rh-au-h",children:[r(s.name),s.dynasty&&e.jsx("span",{children:r(s.dynasty)}),e.jsx("small",{className:"bim-rh-num",children:r(`${Pe(s.count)} 篇`)})]}),e.jsx("ul",{children:s.items.map(l=>e.jsx("li",{children:e.jsx("a",{href:o.read(l.id),children:r(l.title)})},l.id))}),o.author&&e.jsx("a",{className:"bim-rh-more",href:o.author(s.name),children:r(`${s.name}全部 ${s.count} 篇 →`)})]},s.name))}):null}const ya={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function sh({sections:t,links:n,head:r,piecesMoreHref:o,className:s}){const{convert:l}=O(),a=t,p=ya,c=a.topics.filter(x=>!x.shelf),d={picks:a.picks.length>0,topics:c.some(x=>x.items.length>0),famous:a.famous.length>0,sibu:a.bu.length>0||a.unclassified>0,period:a.periods.some(x=>x.count>0),pieces:a.pieces.authors.length>0},u=[["picks","推薦閱讀"],["topics","專題"],["famous","名著與版本"],["sibu","四部"],["period","按年代"],["pieces","單篇詩文"]].filter(([x])=>d[x]);return e.jsxs("div",{className:s?`bim-rh ${s}`:"bim-rh",children:[e.jsx("style",{children:br}),e.jsxs("div",{className:"bim-rh-head",children:[r,e.jsx(pa,{counts:a.counts})]}),u.length>1&&e.jsx("nav",{className:"bim-rh-secnav","aria-label":l("閱讀首頁分區"),children:e.jsx("ul",{children:u.map(([x,m])=>e.jsx("li",{children:e.jsx("a",{href:`#${p[x]}`,children:l(m)})},x))})}),e.jsxs("div",{className:"bim-rh-main",children:[d.picks&&e.jsx(qe,{id:p.picks,title:"推薦閱讀",sub:l("編輯挑選,定期輪換"),children:e.jsx(ua,{picks:a.picks,links:n})}),d.topics&&e.jsx(qe,{id:p.topics,title:"專題",sub:l("按作品類型歸組;小說見下方「名著與版本」"),children:e.jsx(ha,{topics:c,links:n})}),d.famous&&e.jsx(qe,{id:p.famous,title:"名著與版本",sub:l("一部作品一張卡,卡上列出站內能讀的各個本子"),children:e.jsx(ga,{famous:a.famous,links:n})}),d.sibu&&e.jsx(qe,{id:p.sibu,title:"四部",sub:l("按古籍總目的分類樹,只計站內可讀的作品"),children:e.jsx(vr,{bu:a.bu,unclassified:a.unclassified,links:n})}),d.period&&e.jsx(qe,{id:p.period,title:"按年代",sub:l("按作者朝代歸段,寬度與部數成比例"),children:e.jsx(fa,{periods:a.periods,unknown:a.period_unknown,links:n})}),d.pieces&&e.jsx(qe,{id:p.pieces,title:"單篇詩文",sub:l("單篇的詩、文、賦、表,按作者歸組"),more:o?e.jsx("a",{className:"bim-rh-more",href:o,children:l("按作者瀏覽全部 →")}):void 0,children:e.jsx(ba,{authors:a.pieces.authors,links:n})})]})]})}const lh="(max-width: 1079px)",ah=`${cn}, (pointer: coarse)`,ja=`
1446
1473
  /* ── 页首:检索(宿主插槽)+类型签|最近浏览 ── */
1447
1474
  .bim-mh-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 16px 48px; align-items: start; padding-top: 8px; }
1448
1475
  .bim-mh-q { min-width: 0; }
@@ -1582,7 +1609,7 @@ ${eh.map((t,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1582
1609
  .bim-mh-cc0 { display: inline-block; margin-right: 8px; padding: 1px 7px; font-size: 11.5px; letter-spacing: 0.08em; background: ${i("check-fine-bg")}; color: ${i("check-fine-fg")}; }
1583
1610
 
1584
1611
  /* ── 中屏 ── */
1585
- @media ${nh} {
1612
+ @media ${lh} {
1586
1613
  .bim-mh-head, .bim-mh-zhi { grid-template-columns: minmax(0, 1fr); }
1587
1614
  .bim-mh-cg { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1588
1615
  .bim-mh-lin { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@@ -1602,10 +1629,15 @@ ${eh.map((t,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1602
1629
  .bim-mh-tl-list small { margin-left: 0; }
1603
1630
  .bim-mh-cov li { grid-template-columns: minmax(0, 1fr) auto; }
1604
1631
  .bim-mh-cov .bim-mh-bar { grid-column: 1 / -1; grid-row: 2; }
1632
+ /*
1633
+ * 书目著录进度表(overview#325):五列平分 343px,书目列只剩两个字宽,「钦定/四库/全书/总目」一行两字。
1634
+ * 手机端藏掉「著录条目」「已对上作品」两列数字(进度条+百分比已经表达),书目列让出来
1635
+ */
1636
+ .bim-mh-tbl tr > :nth-child(2), .bim-mh-tbl tr > :nth-child(3) { display: none; }
1605
1637
  }
1606
1638
 
1607
- @media ${ih} {
1639
+ @media ${ah} {
1608
1640
  .bim-mh-recent li a, .bim-mh-types a, .bim-mh-tl-list a { min-height: 44px; align-items: center; }
1609
1641
  .bim-mh-recent-h button { min-height: 44px; }
1610
1642
  }
1611
- `,fa={item:t=>`/item/${encodeURIComponent(t)}`,node:t=>`/catalog?node=${encodeURIComponent(t)}`};function bt(t){return{...fa,...t??{}}}function yr(t,n){return!n||n<=0?0:Math.max(0,Math.min(100,Math.round(t/n*100)))}function ba(t){const n=t.filter(d=>Number.isFinite(d.birth_year)||Number.isFinite(d.death_year)),r=t.filter(d=>!n.includes(d));if(!n.length)return{min:0,max:0,placed:[],missing:r};const o=d=>{const u=Number.isFinite(d.birth_year)?d.birth_year:d.death_year-50,x=Number.isFinite(d.death_year)?d.death_year:d.birth_year+50;return[Math.min(u,x),Math.max(u,x)]},s=n.map(o),l=Math.min(...s.map(d=>d[0])),a=Math.max(...s.map(d=>d[1])),p=Math.max(1,a-l),c=n.map((d,u)=>({p:d,from:s[u][0],to:s[u][1]})).sort((d,u)=>d.from-u.from).map(d=>({...d,left:(d.from-l)/p*100,width:Math.max(.8,(d.to-d.from)/p*100)}));return{min:l,max:a,placed:c,missing:r}}function $n(t){return t<0?`前${-t}`:String(t)}function rh(t){return{read:t.item,work:t.item,node:t.node}}const oh={work:"作",book:"版",collection:"叢",entity:"人"},sh={work:"作品",book:"版本",collection:"叢編",entity:"人物"};function ya({counts:t,links:n}){const{convert:r}=F(),o=n==null?void 0:n.type;if(!o)return null;const s=[["all","全部",null],["work","作品",t.works],["book","版本",t.books],["collection","叢編",t.collections],["entity","人物",t.entities]];return e.jsx("ul",{className:"bim-mh-types bim-rh-num","aria-label":r("按類型檢索"),children:s.map(([l,a,p])=>e.jsx("li",{children:e.jsxs("a",{href:o(l),children:[e.jsx("b",{children:r(a)}),p!=null&&p>0&&e.jsx("small",{children:Pe(p)})]})},l))})}function ja(t,n=5){const[r,o]=h.useState(null);h.useEffect(()=>{let l=!1;const a=gt().slice(0,n);if(!a.length||!t){o([]);return}return Promise.all(a.map(p=>Mi(t,p))).then(p=>{l||o(p.filter(c=>!c.notFound))}),()=>{l=!0}},[t,n]);const s=h.useCallback(()=>{Bi(),o([])},[]);return{entries:r,clear:s}}function lh(t){return t.type==="book"?t.edition||t.era||"版本":t.type==="entity"?t.dynasty||"人物":t.type==="collection"?"叢編":t.dynasty||"作品"}function va({entries:t,onClear:n,links:r}){const{convert:o}=F(),s=bt(r);return e.jsxs("aside",{className:"bim-mh-recent","aria-labelledby":"bim-mh-recent-h",children:[e.jsxs("div",{className:"bim-mh-recent-h",children:[e.jsx("h2",{id:"bim-mh-recent-h",children:o("最近瀏覽")}),t&&t.length>0&&n&&e.jsx("button",{type:"button",onClick:n,children:o("清除")})]}),t&&t.length>0&&e.jsx("ol",{children:t.map(l=>e.jsx("li",{children:e.jsxs("a",{href:s.item(l.id),"aria-label":o(`${sh[l.type]??""} ${l.title}`),children:[e.jsx("i",{className:"bim-mh-ty","aria-hidden":"true",children:o(oh[l.type]??"")}),e.jsx("span",{children:o(l.title)}),e.jsx("small",{"aria-hidden":"true",children:o(lh(l))})]})},l.id))}),t&&t.length===0&&e.jsx("p",{className:"bim-mh-recent-empty",children:o("還沒有瀏覽記錄。打開任一條目後會出現在這裏。")})]})}const ka={done:"已完成",in_progress:"進行中",todo:"計劃中"};function wa({rows:t,links:n}){const{convert:r}=F(),o=bt(n);return t.length?e.jsx("div",{className:"bim-mh-tbl-wrap",tabIndex:0,role:"region","aria-label":r("書目著錄進度"),children:e.jsxs("table",{className:"bim-mh-tbl",children:[e.jsxs("caption",{children:[r("書目著錄進度"),e.jsx("small",{children:r("每條著錄對到作品條目")})]}),e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:r("書目")}),e.jsx("th",{scope:"col",className:"bim-mh-r",children:r("著錄條目")}),e.jsx("th",{scope:"col",className:"bim-mh-r",children:r("已對上作品")}),e.jsx("th",{scope:"col",children:r("進度")}),e.jsx("th",{scope:"col",children:r("狀態")})]})}),e.jsx("tbody",{children:t.map(s=>{const l=yr(s.imported,s.total),a=s.work_id??s.collection_id,p=r(s.edition?`${s.name}·${s.edition}`:s.name);return e.jsxs("tr",{children:[e.jsx("th",{scope:"row",children:a?e.jsx("a",{href:o.item(a),children:p}):p}),e.jsx("td",{className:"bim-mh-r",children:Pe(s.total)}),e.jsx("td",{className:"bim-mh-r",children:Pe(s.imported)}),e.jsx("td",{children:e.jsxs("span",{className:"bim-mh-meter",children:[e.jsx("i",{"aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),e.jsxs("small",{children:[l,"%"]})]})}),e.jsx("td",{children:s.status&&e.jsx("span",{className:"bim-mh-st","data-st":s.status,children:r(ka[s.status]??s.status)})})]},s.id||s.name)})})]})}):null}function Sa({items:t,links:n,label:r}){const{convert:o}=F();return e.jsx("ul",{className:"bim-rh-rows","aria-label":r?o(r):void 0,children:t.map(s=>e.jsx("li",{children:e.jsxs("a",{href:n.item(s.id),children:[e.jsx("span",{className:"bim-rh-t",children:o(s.title)}),s.sub&&e.jsx("small",{children:o(s.sub)})]})},s.id))})}function $a({works:t,links:n}){const{convert:r}=F();return t.length?e.jsxs("div",{children:[e.jsxs("h3",{className:"bim-rh-gt",children:[r("同類書目與考證"),e.jsx("small",{children:r("不在書架上的")})]}),e.jsx(Sa,{items:t.map(o=>({id:o.id,title:o.title,sub:Wn(o)||void 0})),links:bt(n)})]}):null}const _a="siku_qige";function za({groups:t,links:n}){const{convert:r}=F(),o=bt(n);if(!t.length)return null;const s=t.find(p=>p.key===_a),l=t.filter(p=>p!==s),a=p=>{var c;return((c=p.match(/(文[^\s·・閣阁]+)[閣阁]/))==null?void 0:c[1])??p};return e.jsxs(e.Fragment,{children:[s&&e.jsxs(e.Fragment,{children:[e.jsxs("h3",{className:"bim-rh-gt",children:[r(s.label),e.jsx("small",{children:r(s.items.map(p=>a(p.title)).join("、"))})]}),e.jsx("ul",{className:"bim-mh-ge","aria-label":r(s.label),children:s.items.map(p=>e.jsx("li",{children:e.jsxs("a",{href:o.item(p.id),"aria-label":r(p.title),title:r(p.title),children:[e.jsx("span",{"aria-hidden":"true",children:r(a(p.title))}),a(p.title)!==p.title&&e.jsx("small",{"aria-hidden":"true",children:r("閣")})]})},p.id))})]}),l.length>0&&e.jsx("div",{className:"bim-mh-cg",style:s?void 0:{marginTop:0},children:l.map(p=>e.jsxs("div",{children:[e.jsxs("h3",{className:"bim-rh-gt",children:[r(p.label),e.jsx("small",{className:"bim-rh-num",children:r(`${p.items.length} 種`)})]}),e.jsx(Sa,{items:p.items,links:o,label:p.label})]},p.key))})]})}const Do=34,Ho=13;function Go(t){return t.birth_year==null&&t.death_year==null?"":`${t.birth_year!=null?$n(t.birth_year):"?"}–${t.death_year!=null?$n(t.death_year):"?"}`}function ah(t,n){const r=n-t,o=r>1200?300:r>400?100:50,s=[];for(let l=Math.ceil(t/o)*o;l<=n;l+=o)s.push(l);return s}function Ca({people:t,links:n}){const{convert:r}=F(),o=bt(n);if(!t.length)return null;const{min:s,max:l,placed:a,missing:p}=ba(t),c=[],d=a.map(x=>{const m=x.left>70,g=m?Math.min(x.left,x.left+x.width-Ho):x.left;let b=0;for(;c[b]!=null&&c[b]>g;)b++;return c[b]=m?x.left+x.width:x.left+Math.max(x.width,Ho),{...x,lane:b,end:m}}),u=Math.max(1,l-s);return e.jsxs(e.Fragment,{children:[d.length>0&&e.jsxs("div",{className:"bim-mh-tl",children:[e.jsx("ul",{className:"bim-mh-tl-rows",style:{height:c.length*Do+10},children:d.map(x=>e.jsxs("li",{className:"bim-mh-tl-bar","data-end":x.end?"":void 0,style:{left:`${x.left}%`,top:x.lane*Do+4,width:`${Math.max(x.width,.5)}%`},children:[e.jsx("i",{"aria-hidden":"true",style:{width:"100%"}}),e.jsxs("a",{href:o.item(x.p.id),children:[r(x.p.name),e.jsx("small",{className:"bim-rh-num",children:Go(x.p)})]})]},x.p.id))}),e.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:ah(s,l).map(x=>e.jsx("span",{style:{left:`${(x-s)/u*100}%`},children:r($n(x))},x))})]}),e.jsx("ul",{className:"bim-mh-tl-list","data-only":d.length?void 0:"",children:(d.length?t:p).map(x=>e.jsx("li",{children:e.jsxs("a",{href:o.item(x.id),children:[e.jsx("span",{children:r(x.name)}),e.jsx("small",{className:"bim-rh-num",children:r([x.dynasty,Go(x)].filter(Boolean).join(" "))})]})},x.id))}),p.length>0&&d.length>0&&e.jsx("p",{className:"bim-mh-tl-foot",children:r(`生卒年未錄、未上軸:${p.map(x=>x.name).join("、")}`)})]})}const ch=e.jsxs("svg",{width:"54",height:"34",viewBox:"0 0 54 34",fill:"none",stroke:"currentColor",strokeWidth:"1.4","aria-hidden":"true",children:[e.jsx("circle",{cx:"27",cy:"5",r:"3.5"}),e.jsx("circle",{cx:"10",cy:"29",r:"3.5"}),e.jsx("circle",{cx:"27",cy:"29",r:"3.5"}),e.jsx("circle",{cx:"44",cy:"29",r:"3.5"}),e.jsx("path",{d:"M27 8.5v17M27 15H10v10.5M27 15h17v10.5"})]});function Ta({works:t,links:n}){const{convert:r}=F(),o=bt(n);return t.length?e.jsx("ul",{className:"bim-mh-lin",children:t.map(s=>{const l=Wn(s);return e.jsx("li",{children:e.jsxs("a",{href:o.item(s.id),children:[ch,e.jsx("b",{children:r(s.title)}),l&&e.jsx("small",{children:r(l)}),e.jsx("span",{children:r("看版本譜系 →")})]})},s.id)})}):null}function Na({sites:t}){const{convert:n}=F(),r=t.filter(l=>l.status!=="todo"&&l.total>0),o=t.filter(l=>!r.includes(l));if(!t.length)return null;const s=l=>l.status==="done"?"已對接":l.status==="in_progress"?"進行中":ka[l.status]??l.status;return e.jsxs(e.Fragment,{children:[r.length>0&&e.jsx("ul",{className:"bim-mh-cov",children:r.map(l=>{const a=yr(l.imported,l.total);return e.jsxs("li",{children:[l.url?e.jsx("a",{href:l.url,rel:"noopener noreferrer",target:"_blank",children:n(l.name)}):e.jsx("span",{children:n(l.name)}),e.jsx("span",{className:"bim-mh-bar","aria-hidden":"true",style:{"--bimmh-w":`${a}%`}}),e.jsxs("small",{children:[`${Pe(l.imported)} / ${Pe(l.total)} ${a}% `,l.status&&e.jsx("span",{className:"bim-mh-st","data-st":l.status,children:n(s(l))})]})]},l.id||l.name)})}),o.length>0&&e.jsx("p",{className:"bim-mh-todo",children:n(`計劃接入:${o.map(l=>l.name).join("、")}`)})]})}const Uo=[{key:"extant",label:"存",note:"今有傳本"},{key:"partially_extant",label:"殘",note:"部分存世"},{key:"lost",label:"佚",note:"僅見著錄"},{key:"unknown",label:"未詳",note:"尚未判定"}];function Ia({stats:t,links:n,version:r,repoUrl:o,downloadHref:s}){const{convert:l}=F(),a=[[t.works,"作品"],[t.books,"版本"],[t.collections,"叢編"],[t.entities,"人物"],[t.has_image,"有影印"],[t.has_text,"有文本"],[t.article,"單篇文"],[t.poem,"單篇詩"]].filter(([d])=>d>0),p=n==null?void 0:n.loss,c=Uo.some(d=>{var u;return(((u=t.loss)==null?void 0:u[d.key])??0)>0});return e.jsxs("div",{className:"bim-mh-data",children:[a.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"bim-rh-gt",children:l("數據規模")}),e.jsx("ul",{className:"bim-mh-nums",children:a.map(([d,u])=>e.jsxs("li",{children:[e.jsx("b",{className:"bim-rh-num",children:Pe(d)}),e.jsx("span",{children:l(u)})]},u))})]}),p&&e.jsxs("div",{children:[e.jsx("h3",{className:"bim-rh-gt",children:l("按存佚檢索")}),e.jsx("ul",{className:"bim-mh-loss",children:Uo.map(d=>{var x;const u=((x=t.loss)==null?void 0:x[d.key])??0;return e.jsx("li",{children:e.jsxs("a",{href:p(d.key),children:[l(d.label),e.jsx("small",{className:"bim-rh-num",children:l(c&&u>0?`${Pe(u)} 部 · ${d.note}`:d.note)})]})},d.key)})})]}),e.jsxs("div",{className:"bim-mh-lic",children:[e.jsxs("p",{children:[e.jsx("span",{className:"bim-mh-cc0",children:"CC0"}),l("古籍元數據以 CC0 公有領域發布,可自由複製、改編、再發布。")]}),e.jsxs("p",{children:[l("數據倉庫:"),o?e.jsx("a",{href:o,children:e.jsx("code",{children:"book-index"})}):e.jsx("code",{children:"book-index"}),l("(GitHub,CC0)")]}),r&&e.jsxs("p",{children:[l("當前數據版本:"),e.jsx("code",{children:r})]}),s&&e.jsx("p",{children:e.jsx("a",{href:s,children:l("引用方式與數據下載 →")})})]})]})}const Ea={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function dh({sections:t,links:n,head:r,transport:o,catalogHref:s,collectionsHref:l,entitiesHref:a,version:p,repoUrl:c,downloadHref:d,className:u}){var _,S,z;const{convert:x}=F(),m=t,g=bt(n),b=rh(g),k=Ea,y=ja(o),j={zhi:!!((_=m.shelf)!=null&&_.items.length)||m.catalog_progress.length>0||m.related_catalogs.length>0,sibu:m.bu.length>0||m.unclassified>0,cong:m.collection_groups.length>0,people:m.bibliographers.length>0,lineage:m.lineage.length>0,sites:m.sites.length>0,data:!0},f=[["zhi","歷代史志"],["sibu","四部"],["cong","叢編"],["people","人物"],["lineage","版本譜系"],["sites","在線資源"],["data","數據與授權"]].filter(([E])=>j[E]),v=(E,T)=>E?e.jsx("a",{className:"bim-rh-more",href:E,children:x(T)}):void 0,$=(S=m.sites.find(E=>E.total>0))==null?void 0:S.total,w=$!=null&&m.sites.every(E=>E.total===0||E.total===$);return e.jsxs("div",{className:u?`bim-rh bim-mh ${u}`:"bim-rh bim-mh",children:[e.jsx("style",{children:hr+ga}),e.jsxs("div",{className:"bim-mh-head",children:[e.jsxs("div",{className:"bim-mh-q",children:[r,e.jsx(ya,{counts:m.counts,links:n})]}),o&&e.jsx(va,{entries:y.entries,onClear:y.clear,links:n})]}),f.length>1&&e.jsx("nav",{className:"bim-rh-secnav","aria-label":x("元數據首頁分區"),children:e.jsx("ul",{children:f.map(([E,T])=>e.jsx("li",{children:e.jsx("a",{href:`#${k[E]}`,children:x(T)})},E))})}),e.jsxs("div",{className:"bim-rh-main",children:[j.zhi&&e.jsxs(qe,{id:k.zhi,title:"歷代史志",sub:x("正史藝文志、經籍志與後人補志,按所志朝代排列;每部志的著錄逐條對到作品"),children:[m.shelf&&m.shelf.items.length>0&&e.jsx(fr,{topic:{key:"shelf",label:m.shelf.label,shelf:!0,items:m.shelf.items},links:b,showTitle:!1,legendCount:m.shelf.items.some(E=>E.records)?"脊下數字=著錄條目":null,legendExtra:["點書脊進作品頁"]}),(m.catalog_progress.length>0||m.related_catalogs.length>0)&&e.jsxs("div",{className:"bim-mh-zhi",style:(z=m.shelf)!=null&&z.items.length?void 0:{marginTop:0},children:[e.jsx(wa,{rows:m.catalog_progress,links:n}),e.jsx($a,{works:m.related_catalogs,links:n})]})]}),j.sibu&&e.jsx(qe,{id:k.sibu,title:"四部",sub:x("全部作品按經史子集分類;與「目錄」頁同一棵分類樹"),more:v(s,"進入目錄 →"),children:e.jsx(br,{bu:m.bu,unclassified:m.unclassified,links:b,unclassifiedNote:"多為只見於史志著錄、尚未歸類的書"})}),j.cong&&e.jsx(qe,{id:k.cong,title:"叢編",sub:x("大型叢書、影印彙編、出土文獻與館藏,逐種列到版本"),more:v(l,`全部 ${Pe(m.counts.collections)} 種 →`),children:e.jsx(za,{groups:m.collection_groups,links:n})}),j.people&&e.jsx(qe,{id:k.people,title:"人物",sub:x("歷代目錄學家,按生卒年排在一條時間軸上"),more:v(a,`全部 ${Pe(m.counts.entities)} 人 →`),children:e.jsx(Ca,{people:m.bibliographers,links:n})}),j.lineage&&e.jsx(qe,{id:k.lineage,title:"版本譜系",sub:x("版本多的作品,看各本的源流與異同"),children:e.jsx(Ta,{works:m.lineage,links:n})}),j.sites&&e.jsx(qe,{id:k.sites,title:"在線資源",sub:x(w?`外部數字圖書館與本站條目的對接,以 ${Pe($)} 種為分母`:"外部數字圖書館與本站條目的對接"),children:e.jsx(Na,{sites:m.sites})}),e.jsx(qe,{id:k.data,title:"數據與授權",sub:x("規模、存佚、許可與版本"),children:e.jsx(Ia,{stats:m.stats,links:n,version:p,repoUrl:c,downloadHref:d})})]})]})}const _i=({style:t})=>{const n=h.useContext(Bt);if(!n)return null;const{locale:r,setLocale:o}=n,s=r==="zh-Hant",l=()=>o(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:l,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:`1px solid ${i("border")}`,borderRadius:"4px",background:i("bg"),color:i("fg"),cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:s?i("primary"):void 0,fontWeight:s?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:s?void 0:i("primary"),fontWeight:s?400:700},children:"简"})]})},zi=({href:t,label:n="在 GitHub 查看本条目源文件",size:r=16,className:o,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:o,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:r+8,height:r+8,borderRadius:4,color:i("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:l=>{l.currentTarget.style.color=i("fg")},onMouseLeave:l=>{l.currentTarget.style.color=i("desc-fg")},children:e.jsx("svg",{width:r,height:r,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})});function ri(t){const n=t.text_count;return typeof n=="number"&&n>0}function oi(t,n){return{id:t,title:n.title??n.primary_name??t,type:n.type??"book"}}function ph(t,n){if(!n)return!1;const r=n.id;return r===void 0||r===t}const uh=({id:t,transport:n,initialDetail:r,initialEntry:o,activeTab:s,onTabChange:l,activeJuan:a,onJuanChange:p,lineageMode:c="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:x,initialPage:m=1,selectedLineageNodeId:g,onNavigate:b,onBack:k,backLabel:y,renderLink:j,enrichDetail:f,getSourceLink:v,readLink:$,railTop:w,extraTabs:_=[],showFeedbackTab:S=!0,feedbackApiUrl:z,height:E,footerExtra:T,hideHeaderControls:N=!1,className:V,style:W})=>{const B=fe(),{convert:H}=F(),[te]=h.useState(()=>{if(!ph(t,r))return null;const M={...r},ue=o??oi(t,M);return f&&f(ue,M),{id:t,entry:ue,detail:M}}),[se,J]=h.useState((te==null?void 0:te.entry)??null),[D,L]=h.useState((te==null?void 0:te.detail)??null),[le,A]=h.useState(!te),[ne,de]=h.useState(!1),[G,he]=h.useState([]),[ye,xe]=h.useState(!1),[pe,$e]=h.useState(null),[Fe,Ae]=h.useState(null),[Me,ve]=h.useState(null),[Be,P]=h.useState(!1),ae=h.useRef(null),[ie,_e]=h.useState(null),ke=a!==void 0?a:ie,Y=h.useCallback(M=>{p?p(M):_e(M)},[p]),I=h.useCallback(async M=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){he([]);return}xe(!0);try{if(n.getCollectionCatalogs)he(await n.getCollectionCatalogs(M)||[]);else if(n.getCollectionCatalog){const ue=await n.getCollectionCatalog(M);he(ue?[{resource_id:"",data:ue}]:[])}}catch{he([])}finally{xe(!1)}},[n]),U=h.useCallback(async M=>{var ue,Te;if(!n.getTextManifest||!n.getTextIndex){$e(null),Ae(M);return}try{const We=be.pickTextVersion(await n.getTextManifest(M)),Ne=We?await n.getTextIndex(M,We.key):null;$e(Ne&&Ne.chapters.length>0?{chapters:Ne.chapters.map(ce=>({n:ce.n,title:ce.title,file:ce.file})),source:{name:((ue=Ne.source)==null?void 0:ue.name)??(We==null?void 0:We.source_name),license:((Te=Ne.source)==null?void 0:Te.license)??(We==null?void 0:We.license)??void 0}}:null)}catch{$e(null)}finally{Ae(M)}},[n]),ge=h.useCallback(async(M,ue)=>{P(!0);try{if(n.getLineageGraph){const Oe=await n.getLineageGraph(M);Oe&&ve(Oe)}const Te=ue.version_graph;if(!Te||!Te.enabled){Me||ve(null),ae.current=null;return}const We=ue.books??[],Ne=[];for(const Oe of We)try{const Ee=await n.getItem(Oe);Ee&&Ne.push(Ee)}catch{}ae.current={work:ue,books:Ne};const ce=u??Te.default_collection??(Te.core_books&&Te.core_books.length>0?"core":"all"),Se=ce==="core"&&Array.isArray(Te.core_books)&&Te.core_books.length>0?"core":ce??"all";ve(bn(ue,Ne,Se))}catch{ve(null),ae.current=null}finally{P(!1)}},[n]),we=h.useRef({initialDetail:r,initialEntry:o});we.current={initialDetail:r,initialEntry:o},h.useEffect(()=>{let M=!1;const ue=ce=>{ce.type==="collection"?I(t):ce.type==="work"?(ce.version_graph||n.getLineageGraph)&&ge(t,ce):ce.type==="book"&&ri(ce)&&U(t)},Te=we.current;let We=null;if(te&&te.id===t)We=te;else if(Te.initialDetail&&Te.initialDetail.id===t){const ce={...Te.initialDetail},Se=Te.initialEntry??oi(t,ce);f&&f(Se,ce),We={entry:Se,detail:ce}}return We?(de(!1),he(ce=>ce.length?[]:ce),$e(null),ve(null),ae.current=null,J(We.entry),L(We.detail),A(!1),ue(We.detail),()=>{M=!0}):((async()=>{A(!0),de(!1),J(null),L(null),he([]),$e(null),ve(null),ae.current=null;try{const ce=await n.getItem(t);if(M)return;if(!ce){de(!0);return}const Se=ce;let Oe=null;if(n.getEntry&&(Oe=await n.getEntry(t),M))return;Oe||(Oe=oi(t,Se)),f&&f(Oe,Se),J(Oe),L(Se),ue(Se)}catch{M||de(!0)}finally{M||A(!1)}})(),()=>{M=!0})},[t,n,te,f,I,ge,U]),h.useEffect(()=>{const M=ae.current;!M||!u||ve(bn(M.work,M.books,u))},[u]);const R=[];if(D){if(R.push({key:"basic",label:B.detailTab.basicInfo}),D.type==="collection"){ye&&G.length===0&&R.push({key:"catalog:loading",label:`${B.detailTab.catalog}…`});for(const M of G)R.push({key:`catalog:${M.resource_id}`,label:M.short_name?`${H(M.short_name)}${B.detailTab.catalogSuffix}`:B.detailTab.collectionCatalog})}(s==="collated"||s==="fulltext")&&R.push({key:s,label:B.detailTab.fullText}),D.type==="work"&&(Me||Be)&&R.push({key:"lineage",label:Be?`${B.detailTab.lineage}…`:B.detailTab.lineage});for(const M of _)(M.position??"before-feedback")==="before-feedback"&&M.shouldShow(D)&&R.push({key:M.key,label:M.label});S&&s==="feedback"&&R.push({key:"feedback",label:B.detailTab.feedback});for(const M of _)M.position==="after-feedback"&&M.shouldShow(D)&&R.push({key:M.key,label:M.label})}h.useEffect(()=>{if(s!=="emendated"||!D)return;l("basic");const M=setTimeout(()=>{var ue;(ue=document.getElementById("studies"))==null||ue.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(M)},[s,D,l]);const oe=se&&D&&v?v({activeTab:s,activeJuan:ke,entry:se,detail:D}):null,K=h.useMemo(()=>{var Ne;if(!D)return null;const ue=(D.authors??[]).map(ce=>{const Se=Yi(ce.role);return`${ce.dynasty?`〔${H(ce.dynasty)}〕`:""}${H(ce.name)}${Se?` ${H(Se)}`:""}`}).join(" · ");let Te=!1;try{Te=be.extractStatus(D.id)==="draft"}catch{}if(D.type==="book"){const ce=D;return{title:H(ce.title),subtitle:ce.edition?H(ce.edition):ue||void 0,aside:[Te?B.status.draft:"",ue&&ce.edition?ue:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(D.type==="collection"){const ce=D;return{title:H(ce.title),subtitle:H(ut(ce,B.unit.juan))||void 0,aside:[(Ne=ce.publication_info)==null?void 0:Ne.year,Te?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:ue||void 0}}if(D.type==="entity"){const ce=D,Se=Ee=>Ee==null?"":Ee<0?`前${-Ee}`:String(Ee),Oe=ce.birth_year!=null||ce.death_year!=null?`${Se(ce.birth_year)||"?"}—${Se(ce.death_year)||"?"}`:"";return{title:H(ce.primary_name||ce.title),subtitle:[ce.dynasty?`〔${H(ce.dynasty)}〕`:"",Oe].filter(Boolean).join(" ")||void 0,aside:Te?B.status.draft:void 0,secondLine:void 0}}const We=H(ut(D,B.unit.juan));return{title:H(D.title),subtitle:[We,ue].filter(Boolean).join(" · ")||void 0,aside:[xh(B,D.subtype),Te?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[D,H,B]),X=D&&ri(D)?"text":null,je=()=>{Y(null),l("fulltext")};let Ie=null;if(D&&$){const M=$({detail:D,kind:X});M&&(Ie=e.jsx(fi,{href:M}))}else X&&(Ie=e.jsx(fi,{onClick:je}));const Re=M=>{if(!D)return null;const ue=M.replace(/\.[^.]+$/,"");if($){const Te=$({detail:D,kind:X,juan:ue});return Te?{href:Te}:null}return{onClick:()=>{Y(ue),l("fulltext")}}},re=new Set(_.map(M=>M.key)),ze=R.filter(M=>M.key.startsWith("catalog:")&&M.key!=="catalog:loading"||re.has(M.key)).map(M=>({key:M.key,label:M.label,onClick:()=>l(M.key)})),C=()=>{var M;return D?D.type==="work"?e.jsx(Wl,{data:D,transport:n,onNavigate:b,renderLink:j,readAction:Ie,railTop:w,railLinks:ze}):D.type==="book"?e.jsx(Dl,{data:D,transport:n,onNavigate:b,renderLink:j,readAction:Ie,fullText:pe,fullTextPending:ri(D)&&!!n.getTextManifest&&Fe!==D.id,chapterLink:Re,railTop:w,railLinks:ze}):D.type==="collection"?e.jsx(Hl,{data:D,catalog:(M=G[0])==null?void 0:M.data,transport:n,onNavigate:b,renderLink:j,readAction:Ie,railTop:w,railLinks:ze,catalogAction:G.length>0?e.jsxs("a",{href:"#catalog",onClick:ue=>{ue.preventDefault(),l(`catalog:${G[0].resource_id}`)},children:[H(B.detailTab.collectionCatalog)," →"]}):null}):e.jsx(Gl,{data:D,transport:n,onNavigate:b,renderLink:j,railTop:w,railLinks:ze}):null},q=()=>{var ue,Te,We;if(!se||!D)return null;if(s==="basic"||s==="emendated")return C();if(typeof s=="string"&&s.startsWith("catalog:")){const Ne=(ue=G.find(ce=>`catalog:${ce.resource_id}`===s))==null?void 0:ue.data;return e.jsx(Fi,{data:Ne,onNavigate:b,renderLink:j})}if(s==="collated"||s==="fulltext")return e.jsx(lr,{id:t,transport:n,chapter:ke,onLocationChange:Ne=>Y(Ne.chapter),onNavigate:b});if(s==="lineage"){if(!Me)return e.jsx("div",{style:{color:i("label-fg"),padding:"24px 0"},children:Be?"加載中…":"暫無版本圖數據"});const Ne=D.type==="work"?D:null;return e.jsx(pr,{graph:Me,renderLink:j,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:d,selectedNodeId:g,collection:u??((Te=Ne==null?void 0:Ne.version_graph)==null?void 0:Te.default_collection),onCollectionChange:x,collectionsAvailable:(We=Ne==null?void 0:Ne.version_graph)==null?void 0:We.collections,collectionCounts:(()=>{var Ee,mt,Q,Le,Xe,yt,Pt;if(!Ne)return;const ce={},Se=((Ee=ae.current)==null?void 0:Ee.books)??[];ce.all=(((mt=Ne.books)==null?void 0:mt.length)??0)-(((Le=(Q=Ne.version_graph)==null?void 0:Q.excluded_books)==null?void 0:Le.length)??0);const Oe=(Xe=Ne.version_graph)==null?void 0:Xe.collections;if(Oe)for(const dn of Object.keys(Oe))ce[dn]=bn(Ne,Se,dn).nodes.filter(vr=>vr.kind==="book"&&!vr.bridge).length;return ce.core==null&&((Pt=(yt=Ne.version_graph)==null?void 0:yt.core_books)!=null&&Pt.length)&&(ce.core=Ne.version_graph.core_books.length),ce})()})}if(s==="feedback"&&S)return e.jsx(Ll,{resourceId:t,apiUrl:z});const M=_.find(Ne=>Ne.key===s);return M?M.render({detail:D,entry:se,transport:n,onNavigate:b}):null};if(le)return e.jsx(Zt,{style:{minHeight:E,...W},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((M,ue)=>e.jsx("div",{style:{height:ue===1?40:16,width:M,opacity:.35,background:i("rule")}},ue))})});if(ne||!D||!se||!K)return e.jsx(Zt,{style:{minHeight:E,...W},children:e.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:i("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const ee=s==="basic"||s==="emendated",Z=[{label:y??B.detailTab.backToIndex,onClick:k}];if(D.type==="book"&&D.work_id){const M=D.work_id;Z.push({label:B.indexType.work,id:M,onClick:()=>b==null?void 0:b(M)})}Z.push({label:B.indexType[D.type]});const me=s==="collated"||s==="fulltext",Ce=typeof T=="string"?B.status[T.trim()]??T:T,O=e.jsx(al,{left:e.jsxs(e.Fragment,{children:[Ce,Ce?" · ":"",e.jsx(mh,{id:D.id,label:B.label.id,copied:B.action.copied,copyLabel:B.action.copy})]}),right:e.jsxs(e.Fragment,{children:[S&&!ee&&e.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:B.detailTab.submitVersion}),oe&&e.jsx("a",{href:oe.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:i("meta-fg")},children:B.detailTab.dataLicense})]})});return ee?e.jsx("div",{className:V,children:e.jsxs(Zt,{grid:!0,style:{minHeight:E,...W},children:[e.jsx(bi,{breadcrumb:e.jsx(yi,{items:Z}),actions:e.jsxs(e.Fragment,{children:[!N&&e.jsx(_i,{style:{border:"none",background:"transparent"}}),!N&&oe&&e.jsx(zi,{...oe})]})}),C(),O]})}):e.jsx("div",{className:V,children:e.jsxs(Zt,{wide:me,style:{minHeight:E,...W},children:[e.jsx(bi,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(qi,{char:"籍"}),e.jsx(yi,{items:Z})]}),actions:e.jsxs(e.Fragment,{children:[!N&&e.jsx(_i,{}),S&&e.jsx("button",{type:"button",onClick:()=>l("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:B.detailTab.feedback}),!N&&oe&&e.jsx(zi,{...oe})]})}),e.jsx(Qs,{...K,aside:me?e.jsxs("button",{type:"button",onClick:()=>l("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("accent"),borderBottom:`1px solid ${i("rule")}`},children:[H("作品信息")," →"]}):K.aside}),!me&&R.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:R.map(M=>e.jsx(el,{label:M.label,active:M.key===s||ee&&M.key==="basic",onClick:()=>l(M.key)},M.key))}),e.jsx("div",{style:{marginTop:!me&&R.length>1?8:0},children:q()}),O]})})};function mh({id:t,label:n,copied:r,copyLabel:o}){const[s,l]=h.useState(!1);return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[e.jsxs("span",{children:[n," ",t]}),e.jsx("button",{type:"button",onClick:()=>{var a;(a=navigator.clipboard)==null||a.writeText(t).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?r:o,"aria-label":s?r:o,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:i("aux-fg")},children:s?"✓":"⧉"})]})}function xh(t,n){return n?t.workSubtype[n]??n:""}const Ra=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],Fn="zhusha",On="bim-theme";function La(t){return t==="zhusha"||t==="indigo"||t==="ink"}function Pn(t){return La(t)?t:Fn}function hh(){try{return Pn(window.localStorage.getItem(On))}catch{return Fn}}function Aa(t){try{window.localStorage.setItem(On,t)}catch{}}function Ba(t){const n=Pn(t);return document.documentElement.setAttribute("data-theme",n),n}function Ma(){return Pn(document.documentElement.getAttribute("data-theme"))}const gh=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],jr="airy",Dn="bim-layout";function Wa(t){return t==="airy"||t==="boxed"}function Hn(t){return Wa(t)?t:jr}function fh(){try{return Hn(window.localStorage.getItem(Dn))}catch{return jr}}function bh(t){try{window.localStorage.setItem(Dn,t)}catch{}}function yh(t){const n=Hn(t);return document.documentElement.setAttribute("data-layout",n),n}function jh(){return Hn(document.documentElement.getAttribute("data-layout"))}const vh=`try{var t=localStorage.getItem(${JSON.stringify(On)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(Dn)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,kh={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},wh=({onChange:t,style:n})=>{const{convert:r}=F(),[o,s]=h.useState(Fn);h.useEffect(()=>{s(Ma())},[]);const l=a=>{s(Ba(a)),Aa(a),t==null||t(a)};return e.jsx("div",{role:"radiogroup","aria-label":r("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:Ra.map(a=>{const p=o===a.name;return e.jsx("button",{type:"button",role:"radio","aria-checked":p,"aria-label":r(a.label),title:r(a.label),onClick:()=>l(a.name),style:{width:28,height:44,padding:0,border:0,background:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:"50%",boxSizing:"border-box",background:i(kh[a.name]),boxShadow:p?`0 0 0 2px ${i("page-bg")}, 0 0 0 3.5px ${i("aux-fg")}`:"none"}})},a.name)})})};exports.BidLink=be.BidLink;exports.BookIndexError=be.BookIndexError;exports.BookIndexManager=be.BookIndexManager;exports.BookIndexStorage=be.BookIndexStorage;exports.BundleStorage=be.BundleStorage;exports.ConfigError=be.ConfigError;exports.GithubStorage=be.GithubStorage;exports.IdGenerationError=be.IdGenerationError;exports.IdGenerator=be.IdGenerator;exports.LocalStorage=be.LocalStorage;exports.MigrationError=be.MigrationError;exports.StorageError=be.StorageError;exports.base36Decode=be.base36Decode;exports.base36Encode=be.base36Encode;exports.base58Decode=be.base58Decode;exports.buildId=be.buildId;exports.buildPromotionMap=be.buildPromotionMap;exports.cleanName=be.cleanName;exports.decodeId=be.decodeId;exports.decodeIdString=be.decodeIdString;exports.encodeId=be.encodeId;exports.extractIdFromUrl=be.extractIdFromUrl;exports.extractStatus=be.extractStatus;exports.extractType=be.extractType;exports.isChapterSegment=be.isChapterSegment;exports.isTextKey=be.isTextKey;exports.matchChapterAcrossVersions=be.matchChapterAcrossVersions;exports.normalizeCatalog=be.normalizeCatalog;exports.parseId=be.parseId;exports.pickTextVersion=be.pickTextVersion;exports.shardOf=be.shardOf;exports.smartDecode=be.smartDecode;exports.textVersionLabel=be.textVersionLabel;exports.validateResource=be.validateResource;exports.Badge=Sn;exports.BidUrlProvider=qa;exports.BookDetailLayout=uh;exports.BookPage=Dl;exports.Breadcrumb=yi;exports.CATALOG_ALL_ID=ct;exports.CATALOG_CSS=Ul;exports.CATALOG_NARROW_QUERY=ur;exports.CATALOG_PAGE_SIZE=mr;exports.CATALOG_UNCLASSIFIED_ID=wt;exports.CLASSIFICATIONS=Nn;exports.CardFoot=sn;exports.CatalogPage=Zx;exports.CatalogPager=Xl;exports.CatalogTree=Yl;exports.CheckFilter=Zs;exports.Chip=tl;exports.ChipWall=yp;exports.CollectionCatalog=Fi;exports.CollectionPage=Hl;exports.CreateEntityDialog=_l;exports.DEFAULT_LAYOUT=jr;exports.DEFAULT_META_HOME_LINKS=fa;exports.DEFAULT_READER_PREFS=Di;exports.DEFAULT_READ_HOME_LINKS=ta;exports.DEFAULT_THEME=Fn;exports.DETAIL_CSS=Xs;exports.DYNASTY_GROUPS=Tn;exports.Dash=$p;exports.DataTable=vp;exports.DetailFooter=al;exports.DetailGrid=rn;exports.DetailHeader=Qs;exports.EMPTY_FILTERS=Cn;exports.EmendatedBySection=bs;exports.EmptyNote=Ep;exports.EntityDetail=us;exports.EntityPage=Gl;exports.EntityPickerDialog=Cl;exports.EntitySelector=$l;exports.ExpandRow=_p;exports.ExtLink=Rp;exports.FEEDBACK_FAB_OFFSET_VAR=wi;exports.FILTER_SUPPORT=is;exports.FONT_SIZE_STEPS=at;exports.FactList=hp;exports.FeedbackButton=Dm;exports.FeedbackDialog=El;exports.FeedbackForm=Rl;exports.FeedbackList=ar;exports.FeedbackTab=Ll;exports.FilterChip=el;exports.FormInput=Je;exports.FormTextArea=$t;exports.GUJI_MARKDOWN_FIELD=wd;exports.GUJI_TABLE_NOTATION=Ss;exports.GlyphBadge=qi;exports.GujiTable=Zi;exports.HomePage=vi;exports.ImagePanel=pi;exports.IndexApp=Yu;exports.IndexBrowser=ci;exports.IndexDetail=Wi;exports.IndexEditor=Tl;exports.IndexView=Tm;exports.IntroGrid=xp;exports.LAYOUTS=gh;exports.LAYOUT_STORAGE_KEY=Dn;exports.LOSS_OPTIONS=Li;exports.LocaleContext=Bt;exports.LocaleProvider=cc;exports.LocaleToggle=_i;exports.META_HOME_CSS=ga;exports.META_HOME_SECTION_IDS=Ea;exports.MetaCatalogTable=wa;exports.MetaCollectionGroups=za;exports.MetaDataLicense=Ia;exports.MetaHomeView=dh;exports.MetaLine=Ue;exports.MetaLineageCards=Ta;exports.MetaOnlineSites=Na;exports.MetaPeopleTimeline=Ca;exports.MetaRecentPanel=va;exports.MetaRelatedCatalogs=$a;exports.MetaTypeChips=ya;exports.ModeIndicator=es;exports.MoreButton=bp;exports.MoreLink=Ot;exports.PAGE_MAX_WIDTH=gn;exports.PERIOD_NARROW_SHARE=oa;exports.PageFrame=Zt;exports.Quote=Cp;exports.READER_CSS=Es;exports.READ_HOME_CSS=hr;exports.READ_HOME_NARROW_QUERY=cn;exports.READ_HOME_SECTION_IDS=ha;exports.READ_PERIOD_LABELS=ea;exports.RECENT_IDS_STORAGE_KEY=Et;exports.ROLE_CLASS_ORDER=Us;exports.ReadButton=fi;exports.ReadFamousWorks=ua;exports.ReadHomeView=th;exports.ReadPeriodBand=ma;exports.ReadPicks=aa;exports.ReadPieces=xa;exports.ReadSection=qe;exports.ReadShelf=fr;exports.ReadSibu=br;exports.ReadStats=la;exports.ReadTopicGroup=da;exports.ReadTopics=pa;exports.ReaderMdText=tr;exports.ReaderShell=Fs;exports.ReaderToc=Ls;exports.RelationPanel=wl;exports.RepoSourceLink=zi;exports.ResourceEditor=li;exports.ResourceGroup=Tp;exports.ResourceLine=Np;exports.ResourceList=Ri;exports.ResourceRow=sl;exports.SEARCH_VIEW_STORAGE_KEY=Ai;exports.SEVEN_PAVILIONS_KEY=_a;exports.SNIPPET_MARK_END=Ko;exports.SNIPPET_MARK_START=Yo;exports.SORTABLE_TYPES=ns;exports.SearchInput=ts;exports.SearchResults=cs;exports.Sec=Ve;exports.Section=tt;exports.SectionHead=gp;exports.SideList=St;exports.SmartBidInput=fn;exports.SourceEditor=jl;exports.SummaryCard=on;exports.THEMES=Ra;exports.THEME_INIT_SCRIPT=vh;exports.THEME_STORAGE_KEY=On;exports.TabFilter=Bn;exports.TableHead=kp;exports.TableRow=wp;exports.TagRow=ll;exports.TagRows=Ip;exports.TextButton=fp;exports.TextReader=lr;exports.ThemeToggle=wh;exports.TopStrip=bi;exports.VersionLineageGraph=Pl;exports.VersionLineageList=Ol;exports.VersionLineageView=pr;exports.VolumeChips=jp;exports.VolumeLinks=Ji;exports.WorkCard=Jl;exports.WorkCardGrid=Ql;exports.WorkCatalog=Ku;exports.WorkPage=Wl;exports.WorkRow=Zl;exports.applyLayout=yh;exports.applyTheme=Ba;exports.authorsLine=Wn;exports.bucketResources=Ui;exports.buildCatalogTree=Dx;exports.buildCollectionTable=Ys;exports.buildLineageGraph=bn;exports.buildMeiliFilter=$c;exports.buildPageUrl=Ei;exports.buildParagraphBlocks=ml;exports.buildVersionRow=Hs;exports.buildVersionTable=Gs;exports.canParagraphize=kn;exports.catalogNodeIdOf=Ox;exports.catalogNodeIdsOf=Px;exports.catalogPageCount=Vx;exports.catalogTotal=xr;exports.classificationPath=an;exports.clearAllRecentIds=Bi;exports.compareCatalogCards=Ux;exports.computeVersionPartition=ip;exports.countActiveFilters=In;exports.createTextApi=Cs;exports.currentLayout=jh;exports.currentTheme=Ma;exports.defaultWorkLink=Kl;exports.deriveDating=ep;exports.deriveEditionType=qs;exports.deriveEra=nn;exports.deriveYear=Rn;exports.deriveYearRange=Gi;exports.detailToEditor=Il;exports.detectGenre=Mn;exports.displayAuthorRole=Yi;exports.editorToDetail=Cm;exports.eraRank=hi;exports.filtersFromParams=_c;exports.filtersToParams=yn;exports.findCatalogPath=It;exports.firstAuthorText=gr;exports.flattenTitles=ji;exports.flattenToc=Ws;exports.fmtCount=Pe;exports.formatTemplate=nt;exports.formatVolumeRange=An;exports.getDisplayNameFromUrl=Mt;exports.getStartPage=Ii;exports.getTypeGroupKey=Ti;exports.groupRelatedWorks=tp;exports.gujiInlineToPlain=ws;exports.hasActiveFilters=rs;exports.hasGujiMarkdownV02=di;exports.hasGujiTableNotation=$s;exports.hasSearchOptions=kc;exports.isLayoutName=Wa;exports.isThemeName=La;exports.loadRecentIds=gt;exports.measureText=ut;exports.mergeVolumeResources=Ni;exports.normalizeEra=Ge;exports.normalizeLayout=Hn;exports.normalizeRole=Vi;exports.normalizeTheme=Pn;exports.normalizeVolumeIndex=Qt;exports.normalizeVolumes=Qo;exports.numberToChinese=Ks;exports.paginationItems=Vl;exports.parseChineseNumber=jn;exports.parseGujiInline=ks;exports.parseGujiTable=zs;exports.parseSourceString=vl;exports.pct=yr;exports.periodLevel=ra;exports.pickReaderVersion=Ms;exports.readStoredLayout=fh;exports.readStoredTheme=hh;exports.readerVersionOptionLabel=mi;exports.removeRecentId=ds;exports.renderFullTextBody=Fp;exports.renderProperNames=hl;exports.renderReaderInline=er;exports.resolveRecentEntry=Mi;exports.resourceHref=Wt;exports.resourceNote=Ln;exports.roleFacets=Vs;exports.rowNo=Sp;exports.sameFilters=zc;exports.saveRecentId=ai;exports.shelfColumns=na;exports.sortFor=wc;exports.sortYear=vn;exports.spineHeight=ia;exports.splitFullTextTables=Oi;exports.splitHighlightSnippet=Ci;exports.splitTableRow=_s;exports.storeLayout=bh;exports.storeTheme=Aa;exports.stringifySources=kl;exports.timelineLayout=ba;exports.toCatalogWorkCard=Gx;exports.typeSupportsFilters=os;exports.useBidUrl=He;exports.useConvert=F;exports.useReaderPrefs=Bs;exports.useRecentEntries=ja;exports.useT=fe;exports.validateLineageGraph=cx;exports.volumeStats=_n;exports.withDefaultLinks=ft;exports.withMetaLinks=bt;exports.yearText=$n;
1643
+ `,va={item:t=>`/item/${encodeURIComponent(t)}`,node:t=>`/catalog?node=${encodeURIComponent(t)}`};function bt(t){return{...va,...t??{}}}function kr(t,n){return!n||n<=0?0:Math.max(0,Math.min(100,Math.round(t/n*100)))}function ka(t){const n=t.filter(d=>Number.isFinite(d.birth_year)||Number.isFinite(d.death_year)),r=t.filter(d=>!n.includes(d));if(!n.length)return{min:0,max:0,placed:[],missing:r};const o=d=>{const u=Number.isFinite(d.birth_year)?d.birth_year:d.death_year-50,x=Number.isFinite(d.death_year)?d.death_year:d.birth_year+50;return[Math.min(u,x),Math.max(u,x)]},s=n.map(o),l=Math.min(...s.map(d=>d[0])),a=Math.max(...s.map(d=>d[1])),p=Math.max(1,a-l),c=n.map((d,u)=>({p:d,from:s[u][0],to:s[u][1]})).sort((d,u)=>d.from-u.from).map(d=>({...d,left:(d.from-l)/p*100,width:Math.max(.8,(d.to-d.from)/p*100)}));return{min:l,max:a,placed:c,missing:r}}function $n(t){return t<0?`前${-t}`:String(t)}function ch(t){return{read:t.item,work:t.item,node:t.node}}const dh={work:"作",book:"版",collection:"叢",entity:"人"},ph={work:"作品",book:"版本",collection:"叢編",entity:"人物"};function wa({counts:t,links:n}){const{convert:r}=O(),o=n==null?void 0:n.type;if(!o)return null;const s=[["all","全部",null],["work","作品",t.works],["book","版本",t.books],["collection","叢編",t.collections],["entity","人物",t.entities]];return e.jsx("ul",{className:"bim-mh-types bim-rh-num","aria-label":r("按類型檢索"),children:s.map(([l,a,p])=>e.jsx("li",{children:e.jsxs("a",{href:o(l),children:[e.jsx("b",{children:r(a)}),p!=null&&p>0&&e.jsx("small",{children:Pe(p)})]})},l))})}function Sa(t,n=5){const[r,o]=h.useState(null);h.useEffect(()=>{let l=!1;const a=gt().slice(0,n);if(!a.length||!t){o([]);return}return Promise.all(a.map(p=>Wi(t,p))).then(p=>{l||o(p.filter(c=>!c.notFound))}),()=>{l=!0}},[t,n]);const s=h.useCallback(()=>{Mi(),o([])},[]);return{entries:r,clear:s}}function uh(t){return t.type==="book"?t.edition||t.era||"版本":t.type==="entity"?t.dynasty||"人物":t.type==="collection"?"叢編":t.dynasty||"作品"}function $a({entries:t,onClear:n,links:r}){const{convert:o}=O(),s=bt(r);return e.jsxs("aside",{className:"bim-mh-recent","aria-labelledby":"bim-mh-recent-h",children:[e.jsxs("div",{className:"bim-mh-recent-h",children:[e.jsx("h2",{id:"bim-mh-recent-h",children:o("最近瀏覽")}),t&&t.length>0&&n&&e.jsx("button",{type:"button",onClick:n,children:o("清除")})]}),t&&t.length>0&&e.jsx("ol",{children:t.map(l=>e.jsx("li",{children:e.jsxs("a",{href:s.item(l.id),"aria-label":o(`${ph[l.type]??""} ${l.title}`),children:[e.jsx("i",{className:"bim-mh-ty","aria-hidden":"true",children:o(dh[l.type]??"")}),e.jsx("span",{children:o(l.title)}),e.jsx("small",{"aria-hidden":"true",children:o(uh(l))})]})},l.id))}),t&&t.length===0&&e.jsx("p",{className:"bim-mh-recent-empty",children:o("還沒有瀏覽記錄。打開任一條目後會出現在這裏。")})]})}const _a={done:"已完成",in_progress:"進行中",todo:"計劃中"};function za({rows:t,links:n}){const{convert:r}=O(),o=bt(n);return t.length?e.jsx("div",{className:"bim-mh-tbl-wrap",tabIndex:0,role:"region","aria-label":r("書目著錄進度"),children:e.jsxs("table",{className:"bim-mh-tbl",children:[e.jsxs("caption",{children:[r("書目著錄進度"),e.jsx("small",{children:r("每條著錄對到作品條目")})]}),e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:r("書目")}),e.jsx("th",{scope:"col",className:"bim-mh-r",children:r("著錄條目")}),e.jsx("th",{scope:"col",className:"bim-mh-r",children:r("已對上作品")}),e.jsx("th",{scope:"col",children:r("進度")}),e.jsx("th",{scope:"col",children:r("狀態")})]})}),e.jsx("tbody",{children:t.map(s=>{const l=kr(s.imported,s.total),a=s.work_id??s.collection_id,p=r(s.edition?`${s.name}·${s.edition}`:s.name);return e.jsxs("tr",{children:[e.jsx("th",{scope:"row",children:a?e.jsx("a",{href:o.item(a),children:p}):p}),e.jsx("td",{className:"bim-mh-r",children:Pe(s.total)}),e.jsx("td",{className:"bim-mh-r",children:Pe(s.imported)}),e.jsx("td",{children:e.jsxs("span",{className:"bim-mh-meter",children:[e.jsx("i",{"aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),e.jsxs("small",{children:[l,"%"]})]})}),e.jsx("td",{children:s.status&&e.jsx("span",{className:"bim-mh-st","data-st":s.status,children:r(_a[s.status]??s.status)})})]},s.id||s.name)})})]})}):null}function Ca({items:t,links:n,label:r}){const{convert:o}=O();return e.jsx("ul",{className:"bim-rh-rows","aria-label":r?o(r):void 0,children:t.map(s=>e.jsx("li",{children:e.jsxs("a",{href:n.item(s.id),children:[e.jsx("span",{className:"bim-rh-t",children:o(s.title)}),s.sub&&e.jsx("small",{children:o(s.sub)})]})},s.id))})}function Ta({works:t,links:n}){const{convert:r}=O(),[o,s]=h.useState(!1);if(!t.length)return null;const l=tn(t.length);return e.jsxs("div",{className:"bim-rh-grp","data-cap":l?"":void 0,"data-open":o?"":void 0,children:[e.jsxs("h3",{className:"bim-rh-gt",children:[r("同類書目與考證"),e.jsx("small",{children:r("不在書架上的")})]}),e.jsx(Ca,{items:t.map(a=>({id:a.id,title:a.title,sub:On(a)||void 0})),links:bt(n)}),l&&e.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":o,onClick:()=>s(a=>!a),children:r(o?"收起":`全部 ${t.length} 部`)})]})}const Na="siku_qige";function mh({group:t,links:n}){const{convert:r}=O(),[o,s]=h.useState(!1);return e.jsxs("div",{className:"bim-rh-grp","data-cap":tn(t.items.length)?"":void 0,"data-open":o?"":void 0,children:[e.jsxs("h3",{className:"bim-rh-gt",children:[r(t.label),e.jsx("small",{className:"bim-rh-num",children:r(`${t.items.length} 種`)})]}),e.jsx(Ca,{items:t.items,links:n,label:t.label}),tn(t.items.length)&&e.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":o,onClick:()=>s(l=>!l),children:r(o?"收起":`全部 ${t.items.length} 種`)})]})}function Ia({groups:t,links:n}){const{convert:r}=O(),o=bt(n);if(!t.length)return null;const s=t.find(p=>p.key===Na),l=t.filter(p=>p!==s),a=p=>{var c;return((c=p.match(/(文[^\s·・閣阁]+)[閣阁]/))==null?void 0:c[1])??p};return e.jsxs(e.Fragment,{children:[s&&e.jsxs(e.Fragment,{children:[e.jsxs("h3",{className:"bim-rh-gt",children:[r(s.label),e.jsx("small",{children:r(s.items.map(p=>a(p.title)).join("、"))})]}),e.jsx("ul",{className:"bim-mh-ge","aria-label":r(s.label),children:s.items.map(p=>e.jsx("li",{children:e.jsxs("a",{href:o.item(p.id),"aria-label":r(p.title),title:r(p.title),children:[e.jsx("span",{"aria-hidden":"true",children:r(a(p.title))}),a(p.title)!==p.title&&e.jsx("small",{"aria-hidden":"true",children:r("閣")})]})},p.id))})]}),l.length>0&&e.jsx("div",{className:"bim-mh-cg",style:s?void 0:{marginTop:0},children:l.map(p=>e.jsx(mh,{group:p,links:o},p.key))})]})}const Uo=34,Vo=13;function Yo(t){return t.birth_year==null&&t.death_year==null?"":`${t.birth_year!=null?$n(t.birth_year):"?"}–${t.death_year!=null?$n(t.death_year):"?"}`}function xh(t,n){const r=n-t,o=r>1200?300:r>400?100:50,s=[];for(let l=Math.ceil(t/o)*o;l<=n;l+=o)s.push(l);return s}function Ea({people:t,links:n}){const{convert:r}=O(),o=bt(n);if(!t.length)return null;const{min:s,max:l,placed:a,missing:p}=ka(t),c=[],d=a.map(x=>{const m=x.left>70,g=m?Math.min(x.left,x.left+x.width-Vo):x.left;let b=0;for(;c[b]!=null&&c[b]>g;)b++;return c[b]=m?x.left+x.width:x.left+Math.max(x.width,Vo),{...x,lane:b,end:m}}),u=Math.max(1,l-s);return e.jsxs(e.Fragment,{children:[d.length>0&&e.jsxs("div",{className:"bim-mh-tl",children:[e.jsx("ul",{className:"bim-mh-tl-rows",style:{height:c.length*Uo+10},children:d.map(x=>e.jsxs("li",{className:"bim-mh-tl-bar","data-end":x.end?"":void 0,style:{left:`${x.left}%`,top:x.lane*Uo+4,width:`${Math.max(x.width,.5)}%`},children:[e.jsx("i",{"aria-hidden":"true",style:{width:"100%"}}),e.jsxs("a",{href:o.item(x.p.id),children:[r(x.p.name),e.jsx("small",{className:"bim-rh-num",children:Yo(x.p)})]})]},x.p.id))}),e.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:xh(s,l).map(x=>e.jsx("span",{style:{left:`${(x-s)/u*100}%`},children:r($n(x))},x))})]}),e.jsx("ul",{className:"bim-mh-tl-list","data-only":d.length?void 0:"",children:(d.length?t:p).map(x=>e.jsx("li",{children:e.jsxs("a",{href:o.item(x.id),children:[e.jsx("span",{children:r(x.name)}),e.jsx("small",{className:"bim-rh-num",children:r([x.dynasty,Yo(x)].filter(Boolean).join(" "))})]})},x.id))}),p.length>0&&d.length>0&&e.jsx("p",{className:"bim-mh-tl-foot",children:r(`生卒年未錄、未上軸:${p.map(x=>x.name).join("、")}`)})]})}const hh=e.jsxs("svg",{width:"54",height:"34",viewBox:"0 0 54 34",fill:"none",stroke:"currentColor",strokeWidth:"1.4","aria-hidden":"true",children:[e.jsx("circle",{cx:"27",cy:"5",r:"3.5"}),e.jsx("circle",{cx:"10",cy:"29",r:"3.5"}),e.jsx("circle",{cx:"27",cy:"29",r:"3.5"}),e.jsx("circle",{cx:"44",cy:"29",r:"3.5"}),e.jsx("path",{d:"M27 8.5v17M27 15H10v10.5M27 15h17v10.5"})]});function Ra({works:t,links:n}){const{convert:r}=O(),o=bt(n);return t.length?e.jsx("ul",{className:"bim-mh-lin",children:t.map(s=>{const l=On(s);return e.jsx("li",{children:e.jsxs("a",{href:o.item(s.id),children:[hh,e.jsx("b",{children:r(s.title)}),l&&e.jsx("small",{children:r(l)}),e.jsx("span",{children:r("看版本譜系 →")})]})},s.id)})}):null}function La({sites:t}){const{convert:n}=O(),r=t.filter(l=>l.status!=="todo"&&l.total>0),o=t.filter(l=>!r.includes(l));if(!t.length)return null;const s=l=>l.status==="done"?"已對接":l.status==="in_progress"?"進行中":_a[l.status]??l.status;return e.jsxs(e.Fragment,{children:[r.length>0&&e.jsx("ul",{className:"bim-mh-cov",children:r.map(l=>{const a=kr(l.imported,l.total);return e.jsxs("li",{children:[l.url?e.jsx("a",{href:l.url,rel:"noopener noreferrer",target:"_blank",children:n(l.name)}):e.jsx("span",{children:n(l.name)}),e.jsx("span",{className:"bim-mh-bar","aria-hidden":"true",style:{"--bimmh-w":`${a}%`}}),e.jsxs("small",{children:[`${Pe(l.imported)} / ${Pe(l.total)} ${a}% `,l.status&&e.jsx("span",{className:"bim-mh-st","data-st":l.status,children:n(s(l))})]})]},l.id||l.name)})}),o.length>0&&e.jsx("p",{className:"bim-mh-todo",children:n(`計劃接入:${o.map(l=>l.name).join("、")}`)})]})}const Ko=[{key:"extant",label:"存",note:"今有傳本"},{key:"partially_extant",label:"殘",note:"部分存世"},{key:"lost",label:"佚",note:"僅見著錄"},{key:"unknown",label:"未詳",note:"尚未判定"}];function Aa({stats:t,links:n,version:r,repoUrl:o,downloadHref:s}){const{convert:l}=O(),a=[[t.works,"作品"],[t.books,"版本"],[t.collections,"叢編"],[t.entities,"人物"],[t.has_image,"有影印"],[t.has_text,"有文本"],[t.article,"單篇文"],[t.poem,"單篇詩"]].filter(([d])=>d>0),p=n==null?void 0:n.loss,c=Ko.some(d=>{var u;return(((u=t.loss)==null?void 0:u[d.key])??0)>0});return e.jsxs("div",{className:"bim-mh-data",children:[a.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"bim-rh-gt",children:l("數據規模")}),e.jsx("ul",{className:"bim-mh-nums",children:a.map(([d,u])=>e.jsxs("li",{children:[e.jsx("b",{className:"bim-rh-num",children:Pe(d)}),e.jsx("span",{children:l(u)})]},u))})]}),p&&e.jsxs("div",{children:[e.jsx("h3",{className:"bim-rh-gt",children:l("按存佚檢索")}),e.jsx("ul",{className:"bim-mh-loss",children:Ko.map(d=>{var x;const u=((x=t.loss)==null?void 0:x[d.key])??0;return e.jsx("li",{children:e.jsxs("a",{href:p(d.key),children:[l(d.label),e.jsx("small",{className:"bim-rh-num",children:l(c&&u>0?`${Pe(u)} 部 · ${d.note}`:d.note)})]})},d.key)})})]}),e.jsxs("div",{className:"bim-mh-lic",children:[e.jsxs("p",{children:[e.jsx("span",{className:"bim-mh-cc0",children:"CC0"}),l("古籍元數據以 CC0 公有領域發布,可自由複製、改編、再發布。")]}),e.jsxs("p",{children:[l("數據倉庫:"),o?e.jsx("a",{href:o,children:e.jsx("code",{children:"book-index"})}):e.jsx("code",{children:"book-index"}),l("(GitHub,CC0)")]}),r&&e.jsxs("p",{children:[l("當前數據版本:"),e.jsx("code",{children:r})]}),s&&e.jsx("p",{children:e.jsx("a",{href:s,children:l("引用方式與數據下載 →")})})]})]})}const Ba={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function gh({sections:t,links:n,head:r,transport:o,catalogHref:s,collectionsHref:l,entitiesHref:a,version:p,repoUrl:c,downloadHref:d,className:u}){var _,S,z;const{convert:x}=O(),m=t,g=bt(n),b=ch(g),k=Ba,y=Sa(o),j={zhi:!!((_=m.shelf)!=null&&_.items.length)||m.catalog_progress.length>0||m.related_catalogs.length>0,sibu:m.bu.length>0||m.unclassified>0,cong:m.collection_groups.length>0,people:m.bibliographers.length>0,lineage:m.lineage.length>0,sites:m.sites.length>0,data:!0},f=[["zhi","歷代史志"],["sibu","四部"],["cong","叢編"],["people","人物"],["lineage","版本譜系"],["sites","在線資源"],["data","數據與授權"]].filter(([E])=>j[E]),v=(E,T)=>E?e.jsx("a",{className:"bim-rh-more",href:E,children:x(T)}):void 0,$=(S=m.sites.find(E=>E.total>0))==null?void 0:S.total,w=$!=null&&m.sites.every(E=>E.total===0||E.total===$);return e.jsxs("div",{className:u?`bim-rh bim-mh ${u}`:"bim-rh bim-mh",children:[e.jsx("style",{children:br+ja}),e.jsxs("div",{className:"bim-mh-head",children:[e.jsxs("div",{className:"bim-mh-q",children:[r,e.jsx(wa,{counts:m.counts,links:n})]}),o&&e.jsx($a,{entries:y.entries,onClear:y.clear,links:n})]}),f.length>1&&e.jsx("nav",{className:"bim-rh-secnav","aria-label":x("元數據首頁分區"),children:e.jsx("ul",{children:f.map(([E,T])=>e.jsx("li",{children:e.jsx("a",{href:`#${k[E]}`,children:x(T)})},E))})}),e.jsxs("div",{className:"bim-rh-main",children:[j.zhi&&e.jsxs(qe,{id:k.zhi,title:"歷代史志",sub:x("正史藝文志、經籍志與後人補志,按所志朝代排列;每部志的著錄逐條對到作品"),children:[m.shelf&&m.shelf.items.length>0&&e.jsx(jr,{topic:{key:"shelf",label:m.shelf.label,shelf:!0,items:m.shelf.items},links:b,showTitle:!1,legendCount:m.shelf.items.some(E=>E.records)?"脊下數字=著錄條目":null,legendExtra:["點書脊進作品頁"]}),(m.catalog_progress.length>0||m.related_catalogs.length>0)&&e.jsxs("div",{className:"bim-mh-zhi",style:(z=m.shelf)!=null&&z.items.length?void 0:{marginTop:0},children:[e.jsx(za,{rows:m.catalog_progress,links:n}),e.jsx(Ta,{works:m.related_catalogs,links:n})]})]}),j.sibu&&e.jsx(qe,{id:k.sibu,title:"四部",sub:x("全部作品按經史子集分類;與「目錄」頁同一棵分類樹"),more:v(s,"進入目錄 →"),children:e.jsx(vr,{bu:m.bu,unclassified:m.unclassified,links:b,unclassifiedNote:"多為只見於史志著錄、尚未歸類的書"})}),j.cong&&e.jsx(qe,{id:k.cong,title:"叢編",sub:x("大型叢書、影印彙編、出土文獻與館藏,逐種列到版本"),more:v(l,`全部 ${Pe(m.counts.collections)} 種 →`),children:e.jsx(Ia,{groups:m.collection_groups,links:n})}),j.people&&e.jsx(qe,{id:k.people,title:"人物",sub:x("歷代目錄學家,按生卒年排在一條時間軸上"),more:v(a,`全部 ${Pe(m.counts.entities)} 人 →`),children:e.jsx(Ea,{people:m.bibliographers,links:n})}),j.lineage&&e.jsx(qe,{id:k.lineage,title:"版本譜系",sub:x("版本多的作品,看各本的源流與異同"),children:e.jsx(Ra,{works:m.lineage,links:n})}),j.sites&&e.jsx(qe,{id:k.sites,title:"在線資源",sub:x(w?`外部數字圖書館與本站條目的對接,以 ${Pe($)} 種為分母`:"外部數字圖書館與本站條目的對接"),children:e.jsx(La,{sites:m.sites})}),e.jsx(qe,{id:k.data,title:"數據與授權",sub:x("規模、存佚、許可與版本"),children:e.jsx(Aa,{stats:m.stats,links:n,version:p,repoUrl:c,downloadHref:d})})]})]})}const zi=({style:t})=>{const n=h.useContext(Bt);if(!n)return null;const{locale:r,setLocale:o}=n,s=r==="zh-Hant",l=()=>o(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:l,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:`1px solid ${i("border")}`,borderRadius:"4px",background:i("bg"),color:i("fg"),cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:s?i("primary"):void 0,fontWeight:s?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:s?void 0:i("primary"),fontWeight:s?400:700},children:"简"})]})},Ci=({href:t,label:n="在 GitHub 查看本条目源文件",size:r=16,className:o,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:o,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:r+8,height:r+8,borderRadius:4,color:i("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:l=>{l.currentTarget.style.color=i("fg")},onMouseLeave:l=>{l.currentTarget.style.color=i("desc-fg")},children:e.jsx("svg",{width:r,height:r,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})});function oi(t){const n=t.text_count;return typeof n=="number"&&n>0}function si(t,n){return{id:t,title:n.title??n.primary_name??t,type:n.type??"book"}}function fh(t,n){if(!n)return!1;const r=n.id;return r===void 0||r===t}const bh=({id:t,transport:n,initialDetail:r,initialEntry:o,activeTab:s,onTabChange:l,activeJuan:a,onJuanChange:p,lineageMode:c="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:x,initialPage:m=1,selectedLineageNodeId:g,onNavigate:b,onBack:k,backLabel:y,renderLink:j,enrichDetail:f,getSourceLink:v,readLink:$,railTop:w,extraTabs:_=[],showFeedbackTab:S=!0,feedbackApiUrl:z,height:E,footerExtra:T,hideHeaderControls:N=!1,className:V,style:W})=>{const B=fe(),{convert:H}=O(),[te]=h.useState(()=>{if(!fh(t,r))return null;const M={...r},ue=o??si(t,M);return f&&f(ue,M),{id:t,entry:ue,detail:M}}),[se,J]=h.useState((te==null?void 0:te.entry)??null),[D,L]=h.useState((te==null?void 0:te.detail)??null),[le,A]=h.useState(!te),[ne,de]=h.useState(!1),[G,he]=h.useState([]),[ye,xe]=h.useState(!1),[pe,$e]=h.useState(null),[Oe,Ae]=h.useState(null),[Me,ve]=h.useState(null),[Be,P]=h.useState(!1),ae=h.useRef(null),[ie,_e]=h.useState(null),ke=a!==void 0?a:ie,Y=h.useCallback(M=>{p?p(M):_e(M)},[p]),I=h.useCallback(async M=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){he([]);return}xe(!0);try{if(n.getCollectionCatalogs)he(await n.getCollectionCatalogs(M)||[]);else if(n.getCollectionCatalog){const ue=await n.getCollectionCatalog(M);he(ue?[{resource_id:"",data:ue}]:[])}}catch{he([])}finally{xe(!1)}},[n]),U=h.useCallback(async M=>{var ue,Te;if(!n.getTextManifest||!n.getTextIndex){$e(null),Ae(M);return}try{const We=be.pickTextVersion(await n.getTextManifest(M)),Ne=We?await n.getTextIndex(M,We.key):null;$e(Ne&&Ne.chapters.length>0?{chapters:Ne.chapters.map(ce=>({n:ce.n,title:ce.title,file:ce.file})),source:{name:((ue=Ne.source)==null?void 0:ue.name)??(We==null?void 0:We.source_name),license:((Te=Ne.source)==null?void 0:Te.license)??(We==null?void 0:We.license)??void 0}}:null)}catch{$e(null)}finally{Ae(M)}},[n]),ge=h.useCallback(async(M,ue)=>{P(!0);try{if(n.getLineageGraph){const Fe=await n.getLineageGraph(M);Fe&&ve(Fe)}const Te=ue.version_graph;if(!Te||!Te.enabled){Me||ve(null),ae.current=null;return}const We=ue.books??[],Ne=[];for(const Fe of We)try{const Ee=await n.getItem(Fe);Ee&&Ne.push(Ee)}catch{}ae.current={work:ue,books:Ne};const ce=u??Te.default_collection??(Te.core_books&&Te.core_books.length>0?"core":"all"),Se=ce==="core"&&Array.isArray(Te.core_books)&&Te.core_books.length>0?"core":ce??"all";ve(bn(ue,Ne,Se))}catch{ve(null),ae.current=null}finally{P(!1)}},[n]),we=h.useRef({initialDetail:r,initialEntry:o});we.current={initialDetail:r,initialEntry:o},h.useEffect(()=>{let M=!1;const ue=ce=>{ce.type==="collection"?I(t):ce.type==="work"?(ce.version_graph||n.getLineageGraph)&&ge(t,ce):ce.type==="book"&&oi(ce)&&U(t)},Te=we.current;let We=null;if(te&&te.id===t)We=te;else if(Te.initialDetail&&Te.initialDetail.id===t){const ce={...Te.initialDetail},Se=Te.initialEntry??si(t,ce);f&&f(Se,ce),We={entry:Se,detail:ce}}return We?(de(!1),he(ce=>ce.length?[]:ce),$e(null),ve(null),ae.current=null,J(We.entry),L(We.detail),A(!1),ue(We.detail),()=>{M=!0}):((async()=>{A(!0),de(!1),J(null),L(null),he([]),$e(null),ve(null),ae.current=null;try{const ce=await n.getItem(t);if(M)return;if(!ce){de(!0);return}const Se=ce;let Fe=null;if(n.getEntry&&(Fe=await n.getEntry(t),M))return;Fe||(Fe=si(t,Se)),f&&f(Fe,Se),J(Fe),L(Se),ue(Se)}catch{M||de(!0)}finally{M||A(!1)}})(),()=>{M=!0})},[t,n,te,f,I,ge,U]),h.useEffect(()=>{const M=ae.current;!M||!u||ve(bn(M.work,M.books,u))},[u]);const R=[];if(D){if(R.push({key:"basic",label:B.detailTab.basicInfo}),D.type==="collection"){ye&&G.length===0&&R.push({key:"catalog:loading",label:`${B.detailTab.catalog}…`});for(const M of G)R.push({key:`catalog:${M.resource_id}`,label:M.short_name?`${H(M.short_name)}${B.detailTab.catalogSuffix}`:B.detailTab.collectionCatalog})}(s==="collated"||s==="fulltext")&&R.push({key:s,label:B.detailTab.fullText}),D.type==="work"&&(Me||Be)&&R.push({key:"lineage",label:Be?`${B.detailTab.lineage}…`:B.detailTab.lineage});for(const M of _)(M.position??"before-feedback")==="before-feedback"&&M.shouldShow(D)&&R.push({key:M.key,label:M.label});S&&s==="feedback"&&R.push({key:"feedback",label:B.detailTab.feedback});for(const M of _)M.position==="after-feedback"&&M.shouldShow(D)&&R.push({key:M.key,label:M.label})}h.useEffect(()=>{if(s!=="emendated"||!D)return;l("basic");const M=setTimeout(()=>{var ue;(ue=document.getElementById("studies"))==null||ue.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(M)},[s,D,l]);const oe=se&&D&&v?v({activeTab:s,activeJuan:ke,entry:se,detail:D}):null,K=h.useMemo(()=>{var Ne;if(!D)return null;const ue=(D.authors??[]).map(ce=>{const Se=Ki(ce.role);return`${ce.dynasty?`〔${H(ce.dynasty)}〕`:""}${H(ce.name)}${Se?` ${H(Se)}`:""}`}).join(" · ");let Te=!1;try{Te=be.extractStatus(D.id)==="draft"}catch{}if(D.type==="book"){const ce=D;return{title:H(ce.title),subtitle:ce.edition?H(ce.edition):ue||void 0,aside:[Te?B.status.draft:"",ue&&ce.edition?ue:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(D.type==="collection"){const ce=D;return{title:H(ce.title),subtitle:H(ut(ce,B.unit.juan))||void 0,aside:[(Ne=ce.publication_info)==null?void 0:Ne.year,Te?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:ue||void 0}}if(D.type==="entity"){const ce=D,Se=Ee=>Ee==null?"":Ee<0?`前${-Ee}`:String(Ee),Fe=ce.birth_year!=null||ce.death_year!=null?`${Se(ce.birth_year)||"?"}—${Se(ce.death_year)||"?"}`:"";return{title:H(ce.primary_name||ce.title),subtitle:[ce.dynasty?`〔${H(ce.dynasty)}〕`:"",Fe].filter(Boolean).join(" ")||void 0,aside:Te?B.status.draft:void 0,secondLine:void 0}}const We=H(ut(D,B.unit.juan));return{title:H(D.title),subtitle:[We,ue].filter(Boolean).join(" · ")||void 0,aside:[jh(B,D.subtype),Te?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[D,H,B]),X=D&&oi(D)?"text":null,je=()=>{Y(null),l("fulltext")};let Ie=null;if(D&&$){const M=$({detail:D,kind:X});M&&(Ie=e.jsx(bi,{href:M}))}else X&&(Ie=e.jsx(bi,{onClick:je}));const Re=M=>{if(!D)return null;const ue=M.replace(/\.[^.]+$/,"");if($){const Te=$({detail:D,kind:X,juan:ue});return Te?{href:Te}:null}return{onClick:()=>{Y(ue),l("fulltext")}}},re=new Set(_.map(M=>M.key)),ze=R.filter(M=>M.key.startsWith("catalog:")&&M.key!=="catalog:loading"||re.has(M.key)).map(M=>({key:M.key,label:M.label,onClick:()=>l(M.key)})),C=()=>{var M;return D?D.type==="work"?e.jsx(Dl,{data:D,transport:n,onNavigate:b,renderLink:j,readAction:Ie,railTop:w,railLinks:ze}):D.type==="book"?e.jsx(Vl,{data:D,transport:n,onNavigate:b,renderLink:j,readAction:Ie,fullText:pe,fullTextPending:oi(D)&&!!n.getTextManifest&&Oe!==D.id,chapterLink:Re,railTop:w,railLinks:ze}):D.type==="collection"?e.jsx(Yl,{data:D,catalog:(M=G[0])==null?void 0:M.data,transport:n,onNavigate:b,renderLink:j,readAction:Ie,railTop:w,railLinks:ze,catalogAction:G.length>0?e.jsxs("a",{href:"#catalog",onClick:ue=>{ue.preventDefault(),l(`catalog:${G[0].resource_id}`)},children:[H(B.detailTab.collectionCatalog)," →"]}):null}):e.jsx(Kl,{data:D,transport:n,onNavigate:b,renderLink:j,railTop:w,railLinks:ze}):null},q=()=>{var ue,Te,We;if(!se||!D)return null;if(s==="basic"||s==="emendated")return C();if(typeof s=="string"&&s.startsWith("catalog:")){const Ne=(ue=G.find(ce=>`catalog:${ce.resource_id}`===s))==null?void 0:ue.data;return e.jsx(Fi,{data:Ne,onNavigate:b,renderLink:j})}if(s==="collated"||s==="fulltext")return e.jsx(dr,{id:t,transport:n,chapter:ke,onLocationChange:Ne=>Y(Ne.chapter),onNavigate:b});if(s==="lineage"){if(!Me)return e.jsx("div",{style:{color:i("label-fg"),padding:"24px 0"},children:Be?"加載中…":"暫無版本圖數據"});const Ne=D.type==="work"?D:null;return e.jsx(xr,{graph:Me,renderLink:j,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:d,selectedNodeId:g,collection:u??((Te=Ne==null?void 0:Ne.version_graph)==null?void 0:Te.default_collection),onCollectionChange:x,collectionsAvailable:(We=Ne==null?void 0:Ne.version_graph)==null?void 0:We.collections,collectionCounts:(()=>{var Ee,mt,Q,Le,Xe,yt,Ft;if(!Ne)return;const ce={},Se=((Ee=ae.current)==null?void 0:Ee.books)??[];ce.all=(((mt=Ne.books)==null?void 0:mt.length)??0)-(((Le=(Q=Ne.version_graph)==null?void 0:Q.excluded_books)==null?void 0:Le.length)??0);const Fe=(Xe=Ne.version_graph)==null?void 0:Xe.collections;if(Fe)for(const dn of Object.keys(Fe))ce[dn]=bn(Ne,Se,dn).nodes.filter(Sr=>Sr.kind==="book"&&!Sr.bridge).length;return ce.core==null&&((Ft=(yt=Ne.version_graph)==null?void 0:yt.core_books)!=null&&Ft.length)&&(ce.core=Ne.version_graph.core_books.length),ce})()})}if(s==="feedback"&&S)return e.jsx(Wl,{resourceId:t,apiUrl:z});const M=_.find(Ne=>Ne.key===s);return M?M.render({detail:D,entry:se,transport:n,onNavigate:b}):null};if(le)return e.jsx(Jt,{style:{minHeight:E,...W},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((M,ue)=>e.jsx("div",{style:{height:ue===1?40:16,width:M,opacity:.35,background:i("rule")}},ue))})});if(ne||!D||!se||!K)return e.jsx(Jt,{style:{minHeight:E,...W},children:e.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:i("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const ee=s==="basic"||s==="emendated",Z=[{label:y??B.detailTab.backToIndex,onClick:k}];if(D.type==="book"&&D.work_id){const M=D.work_id;Z.push({label:B.indexType.work,id:M,onClick:()=>b==null?void 0:b(M)})}Z.push({label:B.indexType[D.type]});const me=s==="collated"||s==="fulltext",Ce=typeof T=="string"?B.status[T.trim()]??T:T,F=e.jsx(ul,{left:e.jsxs(e.Fragment,{children:[Ce,Ce?" · ":"",e.jsx(yh,{id:D.id,label:B.label.id,copied:B.action.copied,copyLabel:B.action.copy})]}),right:e.jsxs(e.Fragment,{children:[S&&!ee&&e.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:B.detailTab.submitVersion}),oe&&e.jsx("a",{href:oe.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:i("meta-fg")},children:B.detailTab.dataLicense})]})});return ee?e.jsx("div",{className:V,children:e.jsxs(Jt,{grid:!0,style:{minHeight:E,...W},children:[e.jsx(yi,{breadcrumb:e.jsx(ji,{items:Z}),actions:e.jsxs(e.Fragment,{children:[!N&&e.jsx(zi,{style:{border:"none",background:"transparent"}}),!N&&oe&&e.jsx(Ci,{...oe})]})}),C(),F]})}):e.jsx("div",{className:V,children:e.jsxs(Jt,{wide:me,style:{minHeight:E,...W},children:[e.jsx(yi,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(Xi,{char:"籍"}),e.jsx(ji,{items:Z})]}),actions:e.jsxs(e.Fragment,{children:[!N&&e.jsx(zi,{}),S&&e.jsx("button",{type:"button",onClick:()=>l("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:B.detailTab.feedback}),!N&&oe&&e.jsx(Ci,{...oe})]})}),e.jsx(il,{...K,aside:me?e.jsxs("button",{type:"button",onClick:()=>l("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("accent"),borderBottom:`1px solid ${i("rule")}`},children:[H("作品信息")," →"]}):K.aside}),!me&&R.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:R.map(M=>e.jsx(rl,{label:M.label,active:M.key===s||ee&&M.key==="basic",onClick:()=>l(M.key)},M.key))}),e.jsx("div",{style:{marginTop:!me&&R.length>1?8:0},children:q()}),F]})})};function yh({id:t,label:n,copied:r,copyLabel:o}){const[s,l]=h.useState(!1);return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[e.jsxs("span",{children:[n," ",t]}),e.jsx("button",{type:"button",onClick:()=>{var a;(a=navigator.clipboard)==null||a.writeText(t).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?r:o,"aria-label":s?r:o,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:i("aux-fg")},children:s?"✓":"⧉"})]})}function jh(t,n){return n?t.workSubtype[n]??n:""}const Ma=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],Fn="zhusha",Pn="bim-theme";function Wa(t){return t==="zhusha"||t==="indigo"||t==="ink"}function Dn(t){return Wa(t)?t:Fn}function vh(){try{return Dn(window.localStorage.getItem(Pn))}catch{return Fn}}function Oa(t){try{window.localStorage.setItem(Pn,t)}catch{}}function Fa(t){const n=Dn(t);return document.documentElement.setAttribute("data-theme",n),n}function Pa(){return Dn(document.documentElement.getAttribute("data-theme"))}const kh=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],wr="airy",Hn="bim-layout";function Da(t){return t==="airy"||t==="boxed"}function Gn(t){return Da(t)?t:wr}function wh(){try{return Gn(window.localStorage.getItem(Hn))}catch{return wr}}function Sh(t){try{window.localStorage.setItem(Hn,t)}catch{}}function $h(t){const n=Gn(t);return document.documentElement.setAttribute("data-layout",n),n}function _h(){return Gn(document.documentElement.getAttribute("data-layout"))}const zh=`try{var t=localStorage.getItem(${JSON.stringify(Pn)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(Hn)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,Ch={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},Th=({onChange:t,style:n})=>{const{convert:r}=O(),[o,s]=h.useState(Fn);h.useEffect(()=>{s(Pa())},[]);const l=a=>{s(Fa(a)),Oa(a),t==null||t(a)};return e.jsx("div",{role:"radiogroup","aria-label":r("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:Ma.map(a=>{const p=o===a.name;return e.jsx("button",{type:"button",role:"radio","aria-checked":p,"aria-label":r(a.label),title:r(a.label),onClick:()=>l(a.name),style:{width:28,height:44,padding:0,border:0,background:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:"50%",boxSizing:"border-box",background:i(Ch[a.name]),boxShadow:p?`0 0 0 2px ${i("page-bg")}, 0 0 0 3.5px ${i("aux-fg")}`:"none"}})},a.name)})})};exports.BidLink=be.BidLink;exports.BookIndexError=be.BookIndexError;exports.BookIndexManager=be.BookIndexManager;exports.BookIndexStorage=be.BookIndexStorage;exports.BundleStorage=be.BundleStorage;exports.ConfigError=be.ConfigError;exports.GithubStorage=be.GithubStorage;exports.IdGenerationError=be.IdGenerationError;exports.IdGenerator=be.IdGenerator;exports.LocalStorage=be.LocalStorage;exports.MigrationError=be.MigrationError;exports.StorageError=be.StorageError;exports.base36Decode=be.base36Decode;exports.base36Encode=be.base36Encode;exports.base58Decode=be.base58Decode;exports.buildId=be.buildId;exports.buildPromotionMap=be.buildPromotionMap;exports.cleanName=be.cleanName;exports.decodeId=be.decodeId;exports.decodeIdString=be.decodeIdString;exports.encodeId=be.encodeId;exports.extractIdFromUrl=be.extractIdFromUrl;exports.extractStatus=be.extractStatus;exports.extractType=be.extractType;exports.isChapterSegment=be.isChapterSegment;exports.isTextKey=be.isTextKey;exports.matchChapterAcrossVersions=be.matchChapterAcrossVersions;exports.normalizeCatalog=be.normalizeCatalog;exports.parseId=be.parseId;exports.pickTextVersion=be.pickTextVersion;exports.shardOf=be.shardOf;exports.smartDecode=be.smartDecode;exports.textVersionLabel=be.textVersionLabel;exports.validateResource=be.validateResource;exports.Badge=Sn;exports.BidUrlProvider=Qa;exports.BookDetailLayout=bh;exports.BookPage=Vl;exports.Breadcrumb=ji;exports.CATALOG_ALL_ID=ct;exports.CATALOG_CSS=ql;exports.CATALOG_NARROW_QUERY=hr;exports.CATALOG_PAGE_SIZE=gr;exports.CATALOG_UNCLASSIFIED_ID=wt;exports.CLASSIFICATIONS=Nn;exports.CardFoot=sn;exports.CatalogPage=th;exports.CatalogPager=na;exports.CatalogTree=Zl;exports.CheckFilter=el;exports.Chip=ol;exports.ChipWall=wp;exports.CollectionCatalog=Fi;exports.CollectionPage=Yl;exports.CreateEntityDialog=Nl;exports.DEFAULT_LAYOUT=wr;exports.DEFAULT_META_HOME_LINKS=va;exports.DEFAULT_READER_PREFS=Hi;exports.DEFAULT_READ_HOME_LINKS=oa;exports.DEFAULT_THEME=Fn;exports.DETAIL_CSS=nl;exports.DYNASTY_GROUPS=Tn;exports.Dash=Tp;exports.DataTable=$p;exports.DetailFooter=ul;exports.DetailGrid=rn;exports.DetailHeader=il;exports.EMPTY_FILTERS=Cn;exports.EmendatedBySection=vs;exports.EmptyNote=Bp;exports.EntityDetail=hs;exports.EntityPage=Kl;exports.EntityPickerDialog=El;exports.EntitySelector=Tl;exports.ExpandRow=Np;exports.ExtLink=Mp;exports.FEEDBACK_FAB_OFFSET_VAR=Si;exports.FILTER_SUPPORT=ss;exports.FONT_SIZE_STEPS=at;exports.FactList=yp;exports.FeedbackButton=Vm;exports.FeedbackDialog=Bl;exports.FeedbackForm=Ml;exports.FeedbackList=pr;exports.FeedbackTab=Wl;exports.FilterChip=rl;exports.FormInput=Je;exports.FormTextArea=$t;exports.GUJI_MARKDOWN_FIELD=zd;exports.GUJI_TABLE_NOTATION=zs;exports.GlyphBadge=Xi;exports.GujiTable=er;exports.HomePage=ki;exports.ImagePanel=ui;exports.IndexApp=Zu;exports.IndexBrowser=di;exports.IndexDetail=Oi;exports.IndexEditor=Rl;exports.IndexView=Rm;exports.IntroGrid=bp;exports.LAYOUTS=kh;exports.LAYOUT_STORAGE_KEY=Hn;exports.LOSS_OPTIONS=Ai;exports.LocaleContext=Bt;exports.LocaleProvider=mc;exports.LocaleToggle=zi;exports.META_HOME_CSS=ja;exports.META_HOME_SECTION_IDS=Ba;exports.MetaCatalogTable=za;exports.MetaCollectionGroups=Ia;exports.MetaDataLicense=Aa;exports.MetaHomeView=gh;exports.MetaLine=Ue;exports.MetaLineageCards=Ra;exports.MetaOnlineSites=La;exports.MetaPeopleTimeline=Ea;exports.MetaRecentPanel=$a;exports.MetaRelatedCatalogs=Ta;exports.MetaTypeChips=wa;exports.ModeIndicator=is;exports.MoreButton=kp;exports.MoreLink=Ji;exports.PAGE_MAX_WIDTH=gn;exports.PERIOD_NARROW_SHARE=ca;exports.PageFrame=Jt;exports.Quote=Ep;exports.READER_CSS=As;exports.READ_HOME_CSS=br;exports.READ_HOME_NARROW_QUERY=cn;exports.READ_HOME_SECTION_IDS=ya;exports.READ_PERIOD_LABELS=ra;exports.RECENT_IDS_STORAGE_KEY=Et;exports.ROLE_CLASS_ORDER=Ks;exports.ReadButton=bi;exports.ReadFamousWorks=ga;exports.ReadHomeView=sh;exports.ReadPeriodBand=fa;exports.ReadPicks=ua;exports.ReadPieces=ba;exports.ReadSection=qe;exports.ReadShelf=jr;exports.ReadSibu=vr;exports.ReadStats=pa;exports.ReadTopicGroup=xa;exports.ReadTopics=ha;exports.ReaderMdText=rr;exports.ReaderShell=Ds;exports.ReaderToc=Ms;exports.RelationPanel=zl;exports.RepoSourceLink=Ci;exports.ResourceEditor=ai;exports.ResourceGroup=Rp;exports.ResourceLine=Lp;exports.ResourceList=Li;exports.ResourceRow=dl;exports.SEARCH_VIEW_STORAGE_KEY=Bi;exports.SEVEN_PAVILIONS_KEY=Na;exports.SNIPPET_MARK_END=Zo;exports.SNIPPET_MARK_START=Jo;exports.SORTABLE_TYPES=os;exports.SearchInput=rs;exports.SearchResults=us;exports.Sec=Ve;exports.Section=tt;exports.SectionHead=jp;exports.SideList=St;exports.SmartBidInput=fn;exports.SourceEditor=Sl;exports.SummaryCard=on;exports.THEMES=Ma;exports.THEME_INIT_SCRIPT=zh;exports.THEME_STORAGE_KEY=Pn;exports.TabFilter=Bn;exports.TableHead=_p;exports.TableRow=zp;exports.TagRow=pl;exports.TagRows=Ap;exports.TextButton=vp;exports.TextReader=dr;exports.ThemeToggle=Th;exports.TopStrip=yi;exports.VersionLineageGraph=Ul;exports.VersionLineageList=Gl;exports.VersionLineageView=xr;exports.VolumeChips=Sp;exports.VolumeLinks=Qi;exports.WorkCard=ea;exports.WorkCardGrid=ia;exports.WorkCatalog=Xu;exports.WorkPage=Dl;exports.WorkRow=ta;exports.applyLayout=$h;exports.applyTheme=Fa;exports.authorsLine=On;exports.bucketResources=Vi;exports.buildCatalogTree=Vx;exports.buildCollectionTable=Js;exports.buildLineageGraph=bn;exports.buildMeiliFilter=Tc;exports.buildPageUrl=Ri;exports.buildParagraphBlocks=fl;exports.buildVersionRow=Vs;exports.buildVersionTable=Ys;exports.canParagraphize=kn;exports.catalogNodeIdOf=Gx;exports.catalogNodeIdsOf=Ux;exports.catalogPageCount=Jx;exports.catalogTotal=fr;exports.classificationPath=an;exports.clearAllRecentIds=Mi;exports.compareCatalogCards=qx;exports.computeVersionPartition=lp;exports.countActiveFilters=In;exports.createTextApi=Is;exports.currentLayout=_h;exports.currentTheme=Pa;exports.defaultWorkLink=Xl;exports.deriveDating=rp;exports.deriveEditionType=Xs;exports.deriveEra=nn;exports.deriveYear=Rn;exports.deriveYearRange=Ui;exports.detailToEditor=Al;exports.detectGenre=Wn;exports.displayAuthorRole=Ki;exports.editorToDetail=Em;exports.eraRank=gi;exports.filtersFromParams=Nc;exports.filtersToParams=yn;exports.findCatalogPath=It;exports.firstAuthorText=yr;exports.flattenTitles=vi;exports.flattenToc=Ps;exports.fmtCount=Pe;exports.formatTemplate=nt;exports.formatVolumeRange=An;exports.getDisplayNameFromUrl=Mt;exports.getStartPage=Ei;exports.getTypeGroupKey=Ni;exports.groupRelatedWorks=op;exports.gujiInlineToPlain=_s;exports.hasActiveFilters=ls;exports.hasGujiMarkdownV02=pi;exports.hasGujiTableNotation=Cs;exports.hasSearchOptions=_c;exports.isLayoutName=Da;exports.isThemeName=Wa;exports.loadRecentIds=gt;exports.measureText=ut;exports.mergeVolumeResources=Ii;exports.normalizeEra=Ge;exports.normalizeLayout=Gn;exports.normalizeRole=Yi;exports.normalizeTheme=Dn;exports.normalizeVolumeIndex=Xt;exports.normalizeVolumes=ns;exports.numberToChinese=Zs;exports.paginationItems=Jl;exports.parseChineseNumber=jn;exports.parseGujiInline=$s;exports.parseGujiTable=Ns;exports.parseSourceString=$l;exports.pct=kr;exports.periodLevel=aa;exports.pickReaderVersion=Fs;exports.readStoredLayout=wh;exports.readStoredTheme=vh;exports.readerVersionOptionLabel=xi;exports.removeRecentId=ms;exports.renderFullTextBody=Hp;exports.renderProperNames=yl;exports.renderReaderInline=ir;exports.resolveRecentEntry=Wi;exports.resourceHref=Wt;exports.resourceNote=Ln;exports.roleFacets=qs;exports.rowNo=Cp;exports.sameFilters=Ic;exports.saveRecentId=ci;exports.shelfColumns=sa;exports.sortFor=zc;exports.sortYear=vn;exports.spineHeight=la;exports.splitFullTextTables=Pi;exports.splitHighlightSnippet=Ti;exports.splitTableRow=Ts;exports.storeLayout=Sh;exports.storeTheme=Oa;exports.stringifySources=_l;exports.timelineLayout=ka;exports.toCatalogWorkCard=Kx;exports.typeSupportsFilters=as;exports.useBidUrl=He;exports.useConvert=O;exports.useReaderPrefs=Os;exports.useRecentEntries=Sa;exports.useT=fe;exports.validateLineageGraph=mx;exports.volumeStats=_n;exports.withDefaultLinks=ft;exports.withMetaLinks=bt;exports.yearText=$n;