book-index-ui 0.22.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +24 -18
- package/dist/index.js +2658 -2641
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var kl=Object.create;var ro=Object.defineProperty;var Sl=Object.getOwnPropertyDescriptor;var wl=Object.getOwnPropertyNames;var _l=Object.getPrototypeOf,$l=Object.prototype.hasOwnProperty;var zl=(e,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of wl(n))!$l.call(e,s)&&s!==i&&ro(e,s,{get:()=>n[s],enumerable:!(r=Sl(n,s))||r.enumerable});return e};var ln=(e,n,i)=>(i=e!=null?kl(_l(e)):{},zl(n||!e||!e.__esModule?ro(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ke=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),f=require("react"),Cl=require("opencc-js/t2cn"),Il=require("react-markdown"),Tl=require("remark-gfm"),El=e=>`/book-index?id=${e}`,hr=f.createContext(El);function Rl({buildUrl:e,children:n}){const i=f.useMemo(()=>e,[e]);return t.jsx(hr.Provider,{value:i,children:n})}function Fe(){return f.useContext(hr)}const br="",yr="";function jr(e){const n=[];let i=!1,r=e;for(;r.length;){const s=i?yr:br,l=r.indexOf(s);if(l===-1){n.push({text:r,marked:i});break}l>0&&n.push({text:r.slice(0,l),marked:i}),r=r.slice(l+1),i=!i}return n}function He(e,n){return{title:e,tokens:n}}const so='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Nl=[He("基础(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"}}),He("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),He("提示与警告",{"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)"}}),He("遮罩与阴影",{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)"}}),He("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),He("资源",{"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"}}),He("整理本(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"}}),He("版本传承(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"}}),He("编辑器视图(主要在 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")'}}),He("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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:"主题切换控件的色点:靛蓝"},"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}}),He("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),He("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),He("字体(全站无衬线,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:so,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:so,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Ll=Object.assign({},...Nl.map(e=>e.tokens)),vr={};for(const[e,n]of Object.entries(Ll))vr[e]=`var(--bim-${e}, ${n.value})`;function o(e){const n=vr[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function yt(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function Bl(e,n){return yt(e).includes(n)}const Hn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Al={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};o("quality-published"),o("quality-fine"),o("quality-rough"),o("quality-ocr");const Rt=f.createContext(null),kr={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:o("check-fine-bg"),fg:o("check-fine-fg")},粗校:{label:"粗校",bg:o("check-rough-bg"),fg:o("check-rough-fg")},AI整理:{label:"AI整理",bg:o("check-ai-bg"),fg:o("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:"別名"},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:"圖片資源"}},Wl={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:o("check-fine-bg"),fg:o("check-fine-fg")},粗校:{label:"粗校",bg:o("check-rough-bg"),fg:o("check-rough-fg")},AI整理:{label:"AI整理",bg:o("check-ai-bg"),fg:o("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:"别名"},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:"图片资源"}},Ml=["曹霑"];function Fl(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Pl(e,n=Ml){const i=[...new Set(n.filter(Boolean))].sort((l,a)=>a.length-l.length);if(!i.length)return e;const r=new RegExp(`(${i.map(Fl).join("|")})`,"g"),s=new Set(i);return l=>{if(!l)return e(l);const a=l.split(r);return a.length===1?e(l):a.map((p,c)=>c%2===1&&s.has(p)?p:p&&e(p)).join("")}}let At=null;function Ol(){if(At)return At;try{At=Pl(Cl.Converter({from:"tw",to:"cn"}))}catch{At=e=>e}return At}const Dl={"zh-Hant":kr,"zh-Hans":Wl},Sr="bim-locale";function Hl(){try{const e=localStorage.getItem(Sr);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Gl(e){try{localStorage.setItem(Sr,e)}catch{}}const Ul="zh-Hans",Vl=({locale:e,onLocaleChange:n,converter:i,children:r})=>{const[s,l]=f.useState(e??Ul),a=e??s;f.useEffect(()=>{if(e)return;const u=Hl();u&&u!==s&&l(u)},[]);const p=f.useMemo(()=>a==="zh-Hans"?i??Ol():null,[a,i]),c=f.useCallback(u=>{l(u),Gl(u),n==null||n(u)},[n]),d=f.useMemo(()=>({locale:a,setLocale:c,messages:Dl[a],converter:p}),[a,c,p]);return t.jsx(Rt.Provider,{value:d,children:r})};function de(){const e=f.useContext(Rt);return(e==null?void 0:e.messages)??kr}const Yl=2e3;function V(){const e=f.useContext(Rt),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const l=f.useCallback(a=>{if(!a)return"";if(!i)return a;const p=r.current.get(a);if(p!==void 0)return p;const c=i(a);if(r.current.size>=Yl){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(a,c),c},[i]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Kt(e,n){return e.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function Kl(e){if(!e)return"";try{const n=new URL(e).hostname,i={"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(i[n])return i[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function ql(){return{id:"",name:"",url:"",type:"text",details:""}}const Gn=({items:e,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const l=de(),[a,p]=f.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=j=>{if(!s)return!0;const v=yt(j);return s==="text"?v.includes("text"):s==="image"?v.includes("image")||v.includes("physical"):s==="physical"?v.includes("physical"):v.includes(s)},g=e.map((j,v)=>({item:j,originalIndex:v})).filter(({item:j})=>u(j)),x=()=>{const j=ql();s&&(j.type=s),n([...e,j]),p(e.length)},m=j=>{n(e.filter((v,_)=>_!==j)),p(null)},b=(j,v,_)=>{const S=[...e];if(S[j]={...S[j],[v]:_},v==="url"&&!S[j].id){const $=Kl(_);$&&(S[j].id=$)}n(S)},k=(j,v,_)=>{const $={...e[j].metadata||{}};_?$[v]=_:delete $[v],b(j,"metadata",Object.keys($).length>0?$:void 0)},h=(j,v)=>{const _=v.trim()?v.split(/[,,、]/).map(S=>S.trim()).filter(Boolean):void 0;b(j,"structure",_)},y=(j,v,_)=>{const $=e[j].coverage||{level:1,ranges:""};v==="level"?$.level=parseInt(_)||1:$.ranges=_,b(j,"coverage",$.ranges?$:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[g.map(({item:j,originalIndex:v})=>{var _,S,$;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(a===v?null:v),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===v?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Jl(j.type??"text"),color:o("on-color-fg")},children:(()=>{var C,N;const w=yt(j);return w.length===0?j.type??"text":w.length===1?((C=c.find(E=>E.value===w[0]))==null?void 0:C.label)??w[0]:w.includes("text")&&w.includes("image")?((N=c.find(E=>E.value==="text+image"))==null?void 0:N.label)??"text+image":w.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:j.name||`${l.editor.resourcePlaceholder} ${v+1}`}),j.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:j.id}),j.url&&t.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",onClick:w=>w.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&j.url&&Zl(v,r==null?void 0:r[v],i,l),t.jsx("button",{onClick:w=>{w.stopPropagation(),m(v)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),a===v&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:[Bl(j,"image")&&j.url&&Xl(j,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.type}),t.jsx("select",{value:j.type,onChange:w=>b(v,"type",w.target.value),style:{...Qe,flex:1},children:c.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]}),t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.rootType}),t.jsx("select",{value:j.root_type||"catalog",onChange:w=>b(v,"root_type",w.target.value),style:{...Qe,flex:1},children:d.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:j.id,onChange:w=>b(v,"id",w.target.value),placeholder:l.editor.idAutoExtract,style:{...Qe,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:j.name,onChange:w=>b(v,"name",w.target.value),placeholder:l.editor.resourceName,style:{...Qe,flex:1}})]}),t.jsx("input",{type:"text",value:j.url,onChange:w=>b(v,"url",w.target.value),placeholder:l.editor.resourceUrl,style:Qe}),t.jsx("input",{type:"text",value:((_=j.structure)==null?void 0:_.join("、"))||"",onChange:w=>h(v,w.target.value),placeholder:l.editor.structurePlaceholder,style:Qe}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((S=j.coverage)==null?void 0:S.level)??"",onChange:w=>y(v,"level",w.target.value),placeholder:"1",style:{...Qe,width:"60px"}})]}),t.jsxs("label",{style:{...Wt,flex:1},children:[t.jsx("span",{style:Mt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:(($=j.coverage)==null?void 0:$.ranges)||"",onChange:w=>y(v,"ranges",w.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...Qe,flex:1}})]})]}),t.jsx("textarea",{value:j.details||"",onChange:w=>b(v,"details",w.target.value),placeholder:l.editor.detailsPlaceholder,style:{...Qe,minHeight:"60px",resize:"vertical"}}),t.jsxs("div",{style:{borderTop:`1px solid ${o("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"6px"},children:l.label.metadata}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([w,C])=>{var N;return t.jsxs("label",{style:{...Wt,gap:"4px"},children:[t.jsx("span",{style:{...Mt,minWidth:"56px"},children:C}),t.jsx("input",{type:"text",value:((N=j.metadata)==null?void 0:N[w])||"",onChange:E=>k(v,w,E.target.value),placeholder:C,style:{...Qe,flex:1}})]},w)})})]})]})]})]},v)}),t.jsxs("button",{onClick:x,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:l.action.addResource})]})]})};function Jl(e){switch(e){case"text":return o("restype-text");case"image":return o("restype-image");case"text+image":return o("restype-text-image");case"physical":return o("restype-physical")}}function Zl(e,n,i,r){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:a=>{a.stopPropagation(),s||i(e,"")},disabled:s,style:{background:"transparent",border:"none",color:o(l?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:l?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":s?"⏳":"⬇"})}function Xl(e,n){const i=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(e.url)||e.url.includes("iiif")||e.url.includes("image");return t.jsx("div",{style:{marginBottom:"12px"},children:i?t.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:o("overlay-bg")},children:t.jsx("img",{src:e.url,alt:e.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):t.jsx("div",{style:{padding:"12px",background:o("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:o("desc-fg")},children:n.editor.imageResourceLink})})}const Qe={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Wt={display:"flex",alignItems:"center",gap:"6px"},Mt={fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap"},Ql={"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 Nt(e){try{return Ql[new URL(e).hostname]}catch{return}}const lo={text:0,image:1,physical:2};function ci(e){return e.length===0?"physical":[...e].sort((n,i)=>(lo[n]??99)-(lo[i]??99)).join("+")}function di(e){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},i=new Map;for(let p=0;p<e.length;p++){const c=e[p];if(c.volumes&&c.volumes.length>0)continue;const d=n(c.name);if(!d)continue;const[u,g]=d,x=`${u}|${ci(yt(c))}`;i.has(x)||i.set(x,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const m=i.get(x);m.volumes.push({volume:g,url:c.url||void 0,status:"found"}),m.indices.push(p)}const r=[],s=new Set;for(const p of i.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)??""),r.push(p.base);for(const c of p.indices)s.add(c)}const l=[...r];for(let p=0;p<e.length;p++)s.has(p)||l.push(e[p]);return l}function wr(e){if(e.url)return e.url;for(const[n,i]of Object.entries(e))if(n.endsWith("_url")&&typeof i=="string")return i}function _r(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||wr(n)}))}function hn(e){const n=_r(e);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,r=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:r,expected:e.expected_volumes??i+r}}function pi(e){if(!e)return;const n=e.file_page_range||e.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function ui(e,n){try{if(new URL(e).hostname.includes("wikimedia.org")){const r=e.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const s=new URL(e);return s.searchParams.set("page",String(n)),s.toString()}return e}catch{return e}}function Lt(e){if(!e.url)return;const n=pi(e.metadata);return n?ui(e.url,n):e.url}const ao={text:o("restype-text"),image:o("restype-image"),"text+image":o("restype-text-image"),physical:o("restype-physical")};function ea(e){return e.includes("text")&&e.includes("image")?ao["text+image"]:ao[e[0]||"physical"]}const xi=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const l=de(),{convert:a}=V(),p=f.useMemo(()=>di(e||[]),[e]),{mirrorGroups:c,ungroupedItems:d}=f.useMemo(()=>{const h=new Map,y=[];for(const j of p){const v=j.group;v?(h.has(v)||h.set(v,[]),h.get(v).push(j)):y.push(j)}for(const j of h.values())j.sort((v,_)=>{const S=$=>$.group_role==="origin"?0:$.group_role==="mirror"?1:2;return S(v)-S(_)});return{mirrorGroups:h,ungroupedItems:y}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},g=h=>u[h]?u[h]:h.split("+").map(y=>u[y]||y).join("+");if(!p||p.length===0)return t.jsx("div",{style:{padding:"16px",color:o("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((h,y)=>t.jsx(Tn,{item:h},h.id||y))});const x=(h,y)=>{const j=i==null?void 0:i[h],v=(j==null?void 0:j.label)||h,_=j==null?void 0:j.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:a(v)}),_&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.5},children:a(_)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:y.map((S,$)=>t.jsx(Tn,{item:S,onNavigate:r,renderLink:s},S.id||$))})]},`group-${h}`)},m=new Map;for(const h of d){const y=ci(yt(h));m.has(y)||m.set(y,[]),m.get(y).push(h)}const b=["text","image","text+image","physical"],k=[...b.filter(h=>m.has(h)),...[...m.keys()].filter(h=>!b.includes(h)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([h,y])=>x(h,y)),k.map(h=>{const y=m.get(h),j=ea(h.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:j,whiteSpace:"nowrap",flexShrink:0},children:g(h)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:y.map((v,_)=>t.jsx(Tn,{item:v,onNavigate:r,renderLink:s},v.id||_))})]},h)})]})},ta={bw:{label:"",bg:o("colormode-bw-bg"),fg:o("colormode-bw-fg")},color:{label:"",bg:o("colormode-color-bg"),fg:o("colormode-color-fg")}},Tn=({item:e})=>{const n=de(),{convert:i}=V(),[r,s]=f.useState(!1),l=f.useMemo(()=>(e.url?Nt(e.url):void 0)||i(e.name),[e.url,e.name,i]),a=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(b=>({...b,url:b.url||wr(b)})),[e.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=e.expected_volumes??(p?c+d:0),g=e.color_mode?{...ta[e.color_mode],label:n.colorMode[e.color_mode]}:null,x=e.details&&!p?i(e.details):null,m={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",background:o("input-bg"),fontSize:"12px",color:o("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:m,children:[t.jsx("span",{style:{fontWeight:500},children:l}),g&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:g.bg,color:g.fg},children:g.label}),x&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:x}),p&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[c,"/",u,n.unit.volume,d>0&&t.jsxs("span",{style:{color:o("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),e.url&&t.jsx("a",{href:(()=>{const b=pi(e.metadata);return b?ui(e.url,b):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:o("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),p&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),p&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${o("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?t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${o("widget-border")}`,color:o("link-fg"),textDecoration:"none"},children:b.volume},b.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:o(k?"missing-fg":"desc-fg"),textDecoration:k?"line-through":"none",opacity:k?.6:1},children:b.volume},b.volume)})})]})},$r=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:a})=>{const p=de(),c=e==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",g=u?u.split(/[/\\]/).pop()||u:"",x={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:o("primary-soft"),color:o("primary")},m={onMouseOver:k=>k.currentTarget.style.opacity="0.8",onMouseOut:k=>k.currentTarget.style.opacity="1"},b=t.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...x,background:o(d?"warning":"success"),color:o("on-color-fg")},...m,children:[t.jsx("span",{children:d?"📝":"📚"}),t.jsx("span",{children:d?"draft":"official"})]});return i==="index-browser"?c?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,t.jsxs("div",{onClick:r,title:p.mode.switchToSync,style:x,...m,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:p.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px"},...m,children:[t.jsx("span",{children:"📂"}),g&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:g})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:p.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:g||p.mode.configurePath,style:{...x,background:"transparent",padding:"6px",fontSize:"12px"},...m,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:c?p.mode.switchToGithub:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:c?"📁":"🌐"}),t.jsx("span",{children:c?p.mode.localMode:p.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&t.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...m,children:[t.jsx("span",{children:"📂"}),g&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:g})]}),!c&&g&&t.jsxs("div",{style:{...x,background:o("mode-active-bg"),color:o("on-color-fg"),cursor:"default"},title:u,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:g})]})]})},bn="bim-search-history",co=10,po=8;function Ht(){try{const e=localStorage.getItem(bn);return e?JSON.parse(e):[]}catch{return[]}}function na(e){try{const n=Ht().filter(i=>i!==e);n.unshift(e),n.length>co&&(n.length=co),localStorage.setItem(bn,JSON.stringify(n))}catch{}}function ia(e){try{const n=Ht().filter(i=>i!==e);localStorage.setItem(bn,JSON.stringify(n))}catch{}}function oa(){try{localStorage.removeItem(bn)}catch{}}const zr=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:l})=>{const a=de(),p=l??a.search.placeholder,c={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,u]=f.useState(!1),[g,x]=f.useState([]),[m,b]=f.useState(-1),[k,h]=f.useState(Ht),y=f.useRef(null),j=f.useRef(null),v=f.useRef(null),_=f.useRef(!1);f.useEffect(()=>{b(-1);const I=n.trim();if(!I){x(k.map(M=>({type:"history",text:M})));return}if(!e.searchAll){x([]);return}let O=!1;const A=setTimeout(()=>{e.searchAll(I,po).then(M=>{if(O)return;const F=[...M.works,...M.books,...M.collections,...M.entities??[]];x(F.slice(0,po).map(Y=>({type:"entry",text:Y.title||Y.id,entry:Y})))}).catch(()=>{O||x([])})},80);return()=>{O=!0,clearTimeout(A)}},[n,k,e]),f.useEffect(()=>{const I=O=>{v.current&&!v.current.contains(O.target)&&u(!1)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[]),f.useEffect(()=>{const I=O=>{var A,M;if(O.key==="/"&&document.activeElement!==y.current){const F=(A=document.activeElement)==null?void 0:A.tagName;if(F==="INPUT"||F==="TEXTAREA"||F==="SELECT")return;O.preventDefault(),(M=y.current)==null||M.focus()}};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[]);const S=f.useCallback(I=>{I.trim()&&(na(I.trim()),h(Ht())),r(I),u(!1)},[r]),$=f.useCallback(I=>{I.type==="history"?(i(I.text),S(I.text)):I.entry&&(s?(s(I.entry),u(!1)):(i(I.text),S(I.text)))},[i,S,s]),w=f.useCallback(I=>{if(!d||g.length===0){I.key==="Enter"&&S(n);return}switch(I.key){case"ArrowDown":I.preventDefault(),b(O=>(O+1)%g.length);break;case"ArrowUp":I.preventDefault(),b(O=>(O-1+g.length)%g.length);break;case"Enter":I.preventDefault(),m>=0&&m<g.length?$(g[m]):S(n);break;case"Escape":I.preventDefault(),u(!1);break}},[d,g,m,n,S,$]),C=f.useCallback((I,O)=>{O.stopPropagation(),ia(I),h(Ht()),x(A=>A.filter(M=>!(M.type==="history"&&M.text===I)))},[]),N=f.useCallback(I=>{I.stopPropagation(),oa(),h([]),x([])},[]);f.useEffect(()=>{if(m>=0&&j.current){const I=j.current.children;I[m]&&I[m].scrollIntoView({block:"nearest"})}},[m]);const E=!n.trim()&&k.length>0;return t.jsxs("div",{ref:v,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:y,type:"text",placeholder:p,value:n,onChange:I=>{i(I.target.value),u(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{u(!0)},onKeyDown:w,style:{width:"100%",padding:"8px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),d&&g.length>0&&t.jsxs("div",{ref:j,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:o("input-bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"6px",boxShadow:o("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[E&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:o("desc-fg"),borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("span",{children:a.search.history}),t.jsx("button",{onClick:N,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),g.map((I,O)=>t.jsxs("div",{onClick:()=>$(I),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:o("fg"),background:O===m?o("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:I.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:I.text}),I.entry&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:[c[I.entry.type],I.entry.edition&&` · ${I.entry.edition}`,I.entry.author&&` · ${I.entry.author}`]}),I.type==="history"&&t.jsx("button",{onClick:A=>C(I.text,A),style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${I.type}-${I.text}-${O}`))]})]})},yn=({type:e,size:n=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:n,borderRadius:1,flex:"none",background:o(`type-${e}`),verticalAlign:"middle"}}),Ct="bim-recent-ids",uo="bim-recent-entries",xo=50,En=5,ra=50,sa=200;function _t(){try{const e=localStorage.getItem(Ct);if(e)return JSON.parse(e);const n=localStorage.getItem(uo);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Ct,JSON.stringify(i)),localStorage.removeItem(uo),i}return[]}catch{return[]}}function fo(e){try{const n=_t().filter(i=>i!==e);n.unshift(e),n.length>xo&&(n.length=xo),localStorage.setItem(Ct,JSON.stringify(n))}catch{}}function la(e){try{const n=_t().filter(i=>i!==e);localStorage.setItem(Ct,JSON.stringify(n))}catch{}}function aa(){try{localStorage.removeItem(Ct)}catch{}}const go={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Un=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c,hideModeIndicator:d,resultVariant:u="compact",renderEntry:g,initialQuery:x,onQueryChange:m,headerRight:b,reserveViewportHeight:k=!1})=>{const h=de(),y=[{type:"work",name:h.indexType.work,key:"works"},{type:"book",name:h.indexType.book,key:"books"},{type:"collection",name:h.indexType.collection,key:"collections"},{type:"entity",name:h.indexType.entity,key:"entities"}],j=["work","collection","book","entity"],[v,_]=f.useState(x??""),[S,$]=f.useState(null),[w,C]=f.useState(null),[N,E]=f.useState("all"),[I,O]=f.useState(!1),[A,M]=f.useState(null),[F,Y]=f.useState(""),[K,R]=f.useState(!(x!=null&&x.trim())),[oe,H]=f.useState(_t),[re,ee]=f.useState([]),[Q,J]=f.useState(!1),[ce,me]=f.useState(!1),[te,ie]=f.useState(null),[pe,ge]=f.useState(null),Ce=f.useRef(void 0),ve=f.useRef(!1),we=f.useCallback(async(L,B)=>{if(!L.trim()){R(!0),$(null),C(null);return}R(!1),O(!0),Y("");try{if(e.searchAll){const G=await e.searchAll(L,B??En);$(G)}else{const G=["work","book","collection","entity"],Z=await Promise.all(G.map(ue=>e.search(L,ue,{page:1,pageSize:B??En})));$({works:Z[0].entries,books:Z[1].entries,collections:Z[2].entries,entities:Z[3].entries,totalWorks:Z[0].total,totalBooks:Z[1].total,totalCollections:Z[2].total,totalEntities:Z[3].total})}}catch(G){Y(G instanceof Error?G.message:String(G)),$(null)}finally{O(!1)}},[e]);f.useEffect(()=>{let L=!1;const B=()=>{var be,Ne;const G=["work","book","collection","entity"],Z=Promise.all(G.map(je=>e.loadEntries(je,{page:1,pageSize:1}).catch(()=>({total:0})))),ue=((be=e.getResourceCounts)==null?void 0:be.call(e).catch(()=>null))??Promise.resolve(null),le=((Ne=e.getSubtypeStats)==null?void 0:Ne.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([Z,ue,le]).then(([je,Pe,at])=>{L||(ie({works:je[0].total,books:je[1].total,collections:je[2].total,entities:je[3].total,hasText:Pe==null?void 0:Pe.hasText,hasImage:Pe==null?void 0:Pe.hasImage}),at&&ge(at))})};return e.getCounts?e.getCounts().then(G=>{var Z,ue;L||(ie({works:G.works,books:G.books,collections:G.collections,entities:G.entities,hasText:(Z=G.resourceCounts)==null?void 0:Z.hasText,hasImage:(ue=G.resourceCounts)==null?void 0:ue.hasImage}),G.subtypeStats&&ge(G.subtypeStats))}).catch(()=>{L||B()}):B(),()=>{L=!0}},[e]),f.useEffect(()=>{ve.current||!(x!=null&&x.trim())||(ve.current=!0,we(x))},[x,we]);const Ee=f.useCallback(L=>{if(_(L),!L.trim()){m==null||m(L),R(!0),$(null),C(null),E("all");return}Ce.current&&clearTimeout(Ce.current),Ce.current=setTimeout(()=>{C(null),E("all"),m==null||m(L),we(L)},sa)},[we,m]),Re=f.useCallback(L=>{Ce.current&&clearTimeout(Ce.current),E("all"),m==null||m(L),we(L)},[we,m]),D=f.useCallback(L=>{C(L),we(v,ra)},[v,we]);f.useEffect(()=>{if(!oe.length){ee([]);return}let L=!1;return J(!0),Promise.all(oe.slice(0,10).map(async B=>{var G,Z,ue;try{if(e.getEntry){const be=await e.getEntry(B);if(be)return be}const le=await e.getItem(B);if(le){const be=le.authors;return{id:B,title:le.title||B,type:le.type||"work",author:(G=be==null?void 0:be[0])==null?void 0:G.name,dynasty:(Z=be==null?void 0:be[0])==null?void 0:Z.dynasty,role:(ue=be==null?void 0:be[0])==null?void 0:ue.role,edition:le.edition||void 0}}}catch{}return{id:B,title:B,type:"work",notFound:!0}})).then(B=>{L||(ee(B),J(!1))}),()=>{L=!0}},[oe,e]);const se=L=>{M(L.id),fo(L.id),H(_t()),r==null||r(L)},ne=(L,B)=>{if(r&&da(B)){B.preventDefault(),se(L);return}fo(L.id),H(_t())},he=L=>{la(L),H(_t())},q=()=>{aa(),H([])},P=L=>y.find(B=>B.type===L),T=!K&&!S&&!F,z=S&&(S.works.length>0||S.books.length>0||S.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",style:k?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:pa}),t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("h1",{style:{margin:0,fontSize:"18px",color:o("fg")},children:h.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&t.jsx($r,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(zr,{transport:e,value:v,onChange:Ee,onSearch:Re,onEntrySelect:se}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${o("primary")}`,borderRadius:"6px",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"13px"},children:h.action.newEntry})]}),K&&t.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:te&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:pe?t.jsxs(t.Fragment,{children:[(pe.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:o("fg")},children:pe.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:o("fg")},children:te.books.toLocaleString()})," 本"]}),pe.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:o("fg")},children:pe.article.toLocaleString()})," 篇"]}):null,pe.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:o("fg")},children:pe.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:o("fg")},children:te.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[h.indexType.work," ",t.jsx("strong",{style:{color:o("fg")},children:te.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.book," ",t.jsx("strong",{style:{color:o("fg")},children:te.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.collection," ",t.jsx("strong",{style:{color:o("fg")},children:te.collections.toLocaleString()}),te.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.entity," ",t.jsx("strong",{style:{color:o("fg")},children:te.entities.toLocaleString()})]})]})}),te.hasImage!=null&&te.hasText!=null&&t.jsxs("span",{children:[h.resourceType.image," ",t.jsx("strong",{style:{color:o("fg")},children:te.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.resourceType.text," ",t.jsx("strong",{style:{color:o("fg")},children:te.hasText.toLocaleString()})]})]})}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:I||T?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg"),minHeight:ca,boxSizing:"border-box"},children:h.search.searching}):F?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:o("desc-fg")},children:F})}):K?t.jsx("div",{style:{flex:1},children:Q?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:h.search.loading}):re.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:h.search.recentBrowse}),t.jsx("button",{onClick:q,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:h.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:re.slice(0,ce?10:3).map(L=>L.notFound?t.jsx(ga,{id:L.id,onRemove:he,t:h},L.id):t.jsx(mo,{entry:L,selected:A===L.id,onClick:ne,getConfig:P,onRemove:he},L.id))}),!ce&&re.length>3&&t.jsx("button",{onClick:()=>me(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:h.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:h.search.searchTitle}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:h.search.searchSubtitle})]})}):z?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:ua}),(()=>{const L=le=>S[go[le]]??0,B=j.map(le=>y.find(be=>be.type===le)).filter(le=>L(le.key)>0);if(B.length<2)return null;const G=B.reduce((le,be)=>le+L(be.key),0),Z=le=>{if(E(le),le!=="all"&&w!==le){const be=y.find(je=>je.type===le),Ne=(S[be.key]??[]).length;L(be.key)>Ne&&D(le)}},ue=le=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:o(le?"fg":"desc-fg"),fontWeight:le?700:400,boxShadow:le?`inset 0 -2px 0 ${o("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":h.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":N==="all",style:ue(N==="all"),onClick:()=>Z("all"),children:[h.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:G.toLocaleString()})]}),B.map(le=>t.jsxs("button",{type:"button","aria-pressed":N===le.type,style:ue(N===le.type),onClick:()=>Z(le.type),children:[le.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:L(le.key).toLocaleString()})]},le.type))]})})(),y.map(({type:L,name:B,key:G})=>{const Z=S[G]??[],ue=go[G],le=S[ue]??0;if(Z.length===0||N!=="all"&&N!==L)return null;const Ne=N==="all"&&!(w===L)&&le>En;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${o("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:[t.jsx(yn,{type:L})," ",B,t.jsxs("span",{style:{fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[le," ",h.unit.items]})]}),Ne&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>D(L),style:{border:"none",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"12px"},children:h.action.viewAll})]}),t.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:Z.map(je=>{if(g)return t.jsx(f.Fragment,{children:g(je)},je.id);const Pe=u==="card"?fa:mo;return t.jsx(Pe,{entry:je,selected:A===je.id,onClick:ne,getConfig:P,query:v},je.id)})})]},L)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:Kt(h.search.noResultsFor,{query:v})}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:h.search.tryOther})]})})]})},ca=240;function da(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const pa=`
|
|
1
|
+
"use strict";var kl=Object.create;var ro=Object.defineProperty;var Sl=Object.getOwnPropertyDescriptor;var wl=Object.getOwnPropertyNames;var _l=Object.getPrototypeOf,$l=Object.prototype.hasOwnProperty;var zl=(e,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of wl(n))!$l.call(e,s)&&s!==i&&ro(e,s,{get:()=>n[s],enumerable:!(r=Sl(n,s))||r.enumerable});return e};var an=(e,n,i)=>(i=e!=null?kl(_l(e)):{},zl(n||!e||!e.__esModule?ro(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const we=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),f=require("react"),Cl=require("opencc-js/t2cn"),Il=require("react-markdown"),Tl=require("remark-gfm"),El=e=>`/book-index?id=${e}`,hr=f.createContext(El);function Rl({buildUrl:e,children:n}){const i=f.useMemo(()=>e,[e]);return t.jsx(hr.Provider,{value:i,children:n})}function Pe(){return f.useContext(hr)}const br="",yr="";function jr(e){const n=[];let i=!1,r=e;for(;r.length;){const s=i?yr:br,l=r.indexOf(s);if(l===-1){n.push({text:r,marked:i});break}l>0&&n.push({text:r.slice(0,l),marked:i}),r=r.slice(l+1),i=!i}return n}function He(e,n){return{title:e,tokens:n}}const so='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Nl=[He("基础(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"}}),He("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),He("提示与警告",{"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)"}}),He("遮罩与阴影",{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)"}}),He("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),He("资源",{"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"}}),He("整理本(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"}}),He("版本传承(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"}}),He("编辑器视图(主要在 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")'}}),He("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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:"主题切换控件的色点:靛蓝"},"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}}),He("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),He("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),He("字体(全站无衬线,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:so,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:so,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Ll=Object.assign({},...Nl.map(e=>e.tokens)),vr={};for(const[e,n]of Object.entries(Ll))vr[e]=`var(--bim-${e}, ${n.value})`;function o(e){const n=vr[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function yt(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function Bl(e,n){return yt(e).includes(n)}const Hn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Al={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};o("quality-published"),o("quality-fine"),o("quality-rough"),o("quality-ocr");const Rt=f.createContext(null),kr={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:o("check-fine-bg"),fg:o("check-fine-fg")},粗校:{label:"粗校",bg:o("check-rough-bg"),fg:o("check-rough-fg")},AI整理:{label:"AI整理",bg:o("check-ai-bg"),fg:o("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:"別名"},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:"圖片資源"}},Wl={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:o("check-fine-bg"),fg:o("check-fine-fg")},粗校:{label:"粗校",bg:o("check-rough-bg"),fg:o("check-rough-fg")},AI整理:{label:"AI整理",bg:o("check-ai-bg"),fg:o("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:"别名"},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:"图片资源"}},Ml=["曹霑"];function Fl(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Pl(e,n=Ml){const i=[...new Set(n.filter(Boolean))].sort((l,a)=>a.length-l.length);if(!i.length)return e;const r=new RegExp(`(${i.map(Fl).join("|")})`,"g"),s=new Set(i);return l=>{if(!l)return e(l);const a=l.split(r);return a.length===1?e(l):a.map((p,c)=>c%2===1&&s.has(p)?p:p&&e(p)).join("")}}let At=null;function Ol(){if(At)return At;try{At=Pl(Cl.Converter({from:"tw",to:"cn"}))}catch{At=e=>e}return At}const Dl={"zh-Hant":kr,"zh-Hans":Wl},Sr="bim-locale";function Hl(){try{const e=localStorage.getItem(Sr);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Gl(e){try{localStorage.setItem(Sr,e)}catch{}}const Ul="zh-Hans",Vl=({locale:e,onLocaleChange:n,converter:i,children:r})=>{const[s,l]=f.useState(e??Ul),a=e??s;f.useEffect(()=>{if(e)return;const u=Hl();u&&u!==s&&l(u)},[]);const p=f.useMemo(()=>a==="zh-Hans"?i??Ol():null,[a,i]),c=f.useCallback(u=>{l(u),Gl(u),n==null||n(u)},[n]),d=f.useMemo(()=>({locale:a,setLocale:c,messages:Dl[a],converter:p}),[a,c,p]);return t.jsx(Rt.Provider,{value:d,children:r})};function ue(){const e=f.useContext(Rt);return(e==null?void 0:e.messages)??kr}const Yl=2e3;function q(){const e=f.useContext(Rt),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const l=f.useCallback(a=>{if(!a)return"";if(!i)return a;const p=r.current.get(a);if(p!==void 0)return p;const c=i(a);if(r.current.size>=Yl){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(a,c),c},[i]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Kt(e,n){return e.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function ql(e){if(!e)return"";try{const n=new URL(e).hostname,i={"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(i[n])return i[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function Kl(){return{id:"",name:"",url:"",type:"text",details:""}}const Gn=({items:e,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const l=ue(),[a,p]=f.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=j=>{if(!s)return!0;const k=yt(j);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},g=e.map((j,k)=>({item:j,originalIndex:k})).filter(({item:j})=>u(j)),x=()=>{const j=Kl();s&&(j.type=s),n([...e,j]),p(e.length)},m=j=>{n(e.filter((k,$)=>$!==j)),p(null)},b=(j,k,$)=>{const v=[...e];if(v[j]={...v[j],[k]:$},k==="url"&&!v[j].id){const _=ql($);_&&(v[j].id=_)}n(v)},S=(j,k,$)=>{const _={...e[j].metadata||{}};$?_[k]=$:delete _[k],b(j,"metadata",Object.keys(_).length>0?_:void 0)},h=(j,k)=>{const $=k.trim()?k.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;b(j,"structure",$)},y=(j,k,$)=>{const _=e[j].coverage||{level:1,ranges:""};k==="level"?_.level=parseInt($)||1:_.ranges=$,b(j,"coverage",_.ranges?_:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[g.map(({item:j,originalIndex:k})=>{var $,v,_;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(a===k?null:k),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===k?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Jl(j.type??"text"),color:o("on-color-fg")},children:(()=>{var z,N;const w=yt(j);return w.length===0?j.type??"text":w.length===1?((z=c.find(T=>T.value===w[0]))==null?void 0:z.label)??w[0]:w.includes("text")&&w.includes("image")?((N=c.find(T=>T.value==="text+image"))==null?void 0:N.label)??"text+image":w.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:j.name||`${l.editor.resourcePlaceholder} ${k+1}`}),j.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:j.id}),j.url&&t.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",onClick:w=>w.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&j.url&&Zl(k,r==null?void 0:r[k],i,l),t.jsx("button",{onClick:w=>{w.stopPropagation(),m(k)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),a===k&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:[Bl(j,"image")&&j.url&&Xl(j,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.type}),t.jsx("select",{value:j.type,onChange:w=>b(k,"type",w.target.value),style:{...et,flex:1},children:c.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]}),t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.rootType}),t.jsx("select",{value:j.root_type||"catalog",onChange:w=>b(k,"root_type",w.target.value),style:{...et,flex:1},children:d.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:j.id,onChange:w=>b(k,"id",w.target.value),placeholder:l.editor.idAutoExtract,style:{...et,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:j.name,onChange:w=>b(k,"name",w.target.value),placeholder:l.editor.resourceName,style:{...et,flex:1}})]}),t.jsx("input",{type:"text",value:j.url,onChange:w=>b(k,"url",w.target.value),placeholder:l.editor.resourceUrl,style:et}),t.jsx("input",{type:"text",value:(($=j.structure)==null?void 0:$.join("、"))||"",onChange:w=>h(k,w.target.value),placeholder:l.editor.structurePlaceholder,style:et}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((v=j.coverage)==null?void 0:v.level)??"",onChange:w=>y(k,"level",w.target.value),placeholder:"1",style:{...et,width:"60px"}})]}),t.jsxs("label",{style:{...Wt,flex:1},children:[t.jsx("span",{style:Mt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:((_=j.coverage)==null?void 0:_.ranges)||"",onChange:w=>y(k,"ranges",w.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...et,flex:1}})]})]}),t.jsx("textarea",{value:j.details||"",onChange:w=>b(k,"details",w.target.value),placeholder:l.editor.detailsPlaceholder,style:{...et,minHeight:"60px",resize:"vertical"}}),t.jsxs("div",{style:{borderTop:`1px solid ${o("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"6px"},children:l.label.metadata}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([w,z])=>{var N;return t.jsxs("label",{style:{...Wt,gap:"4px"},children:[t.jsx("span",{style:{...Mt,minWidth:"56px"},children:z}),t.jsx("input",{type:"text",value:((N=j.metadata)==null?void 0:N[w])||"",onChange:T=>S(k,w,T.target.value),placeholder:z,style:{...et,flex:1}})]},w)})})]})]})]})]},k)}),t.jsxs("button",{onClick:x,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:l.action.addResource})]})]})};function Jl(e){switch(e){case"text":return o("restype-text");case"image":return o("restype-image");case"text+image":return o("restype-text-image");case"physical":return o("restype-physical")}}function Zl(e,n,i,r){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:a=>{a.stopPropagation(),s||i(e,"")},disabled:s,style:{background:"transparent",border:"none",color:o(l?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:l?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":s?"⏳":"⬇"})}function Xl(e,n){const i=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(e.url)||e.url.includes("iiif")||e.url.includes("image");return t.jsx("div",{style:{marginBottom:"12px"},children:i?t.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:o("overlay-bg")},children:t.jsx("img",{src:e.url,alt:e.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):t.jsx("div",{style:{padding:"12px",background:o("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:o("desc-fg")},children:n.editor.imageResourceLink})})}const et={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Wt={display:"flex",alignItems:"center",gap:"6px"},Mt={fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap"},Ql={"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 Nt(e){try{return Ql[new URL(e).hostname]}catch{return}}const lo={text:0,image:1,physical:2};function ci(e){return e.length===0?"physical":[...e].sort((n,i)=>(lo[n]??99)-(lo[i]??99)).join("+")}function di(e){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},i=new Map;for(let p=0;p<e.length;p++){const c=e[p];if(c.volumes&&c.volumes.length>0)continue;const d=n(c.name);if(!d)continue;const[u,g]=d,x=`${u}|${ci(yt(c))}`;i.has(x)||i.set(x,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const m=i.get(x);m.volumes.push({volume:g,url:c.url||void 0,status:"found"}),m.indices.push(p)}const r=[],s=new Set;for(const p of i.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)??""),r.push(p.base);for(const c of p.indices)s.add(c)}const l=[...r];for(let p=0;p<e.length;p++)s.has(p)||l.push(e[p]);return l}function wr(e){if(e.url)return e.url;for(const[n,i]of Object.entries(e))if(n.endsWith("_url")&&typeof i=="string")return i}function _r(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||wr(n)}))}function bn(e){const n=_r(e);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,r=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:r,expected:e.expected_volumes??i+r}}function pi(e){if(!e)return;const n=e.file_page_range||e.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function ui(e,n){try{if(new URL(e).hostname.includes("wikimedia.org")){const r=e.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const s=new URL(e);return s.searchParams.set("page",String(n)),s.toString()}return e}catch{return e}}function Lt(e){if(!e.url)return;const n=pi(e.metadata);return n?ui(e.url,n):e.url}const ao={text:o("restype-text"),image:o("restype-image"),"text+image":o("restype-text-image"),physical:o("restype-physical")};function ea(e){return e.includes("text")&&e.includes("image")?ao["text+image"]:ao[e[0]||"physical"]}const xi=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const l=ue(),{convert:a}=q(),p=f.useMemo(()=>di(e||[]),[e]),{mirrorGroups:c,ungroupedItems:d}=f.useMemo(()=>{const h=new Map,y=[];for(const j of p){const k=j.group;k?(h.has(k)||h.set(k,[]),h.get(k).push(j)):y.push(j)}for(const j of h.values())j.sort((k,$)=>{const v=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return v(k)-v($)});return{mirrorGroups:h,ungroupedItems:y}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},g=h=>u[h]?u[h]:h.split("+").map(y=>u[y]||y).join("+");if(!p||p.length===0)return t.jsx("div",{style:{padding:"16px",color:o("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((h,y)=>t.jsx(En,{item:h},h.id||y))});const x=(h,y)=>{const j=i==null?void 0:i[h],k=(j==null?void 0:j.label)||h,$=j==null?void 0:j.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:a(k)}),$&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.5},children:a($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:y.map((v,_)=>t.jsx(En,{item:v,onNavigate:r,renderLink:s},v.id||_))})]},`group-${h}`)},m=new Map;for(const h of d){const y=ci(yt(h));m.has(y)||m.set(y,[]),m.get(y).push(h)}const b=["text","image","text+image","physical"],S=[...b.filter(h=>m.has(h)),...[...m.keys()].filter(h=>!b.includes(h)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([h,y])=>x(h,y)),S.map(h=>{const y=m.get(h),j=ea(h.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:j,whiteSpace:"nowrap",flexShrink:0},children:g(h)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:y.map((k,$)=>t.jsx(En,{item:k,onNavigate:r,renderLink:s},k.id||$))})]},h)})]})},ta={bw:{label:"",bg:o("colormode-bw-bg"),fg:o("colormode-bw-fg")},color:{label:"",bg:o("colormode-color-bg"),fg:o("colormode-color-fg")}},En=({item:e})=>{const n=ue(),{convert:i}=q(),[r,s]=f.useState(!1),l=f.useMemo(()=>(e.url?Nt(e.url):void 0)||i(e.name),[e.url,e.name,i]),a=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(b=>({...b,url:b.url||wr(b)})),[e.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=e.expected_volumes??(p?c+d:0),g=e.color_mode?{...ta[e.color_mode],label:n.colorMode[e.color_mode]}:null,x=e.details&&!p?i(e.details):null,m={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",background:o("input-bg"),fontSize:"12px",color:o("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:m,children:[t.jsx("span",{style:{fontWeight:500},children:l}),g&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:g.bg,color:g.fg},children:g.label}),x&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:x}),p&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[c,"/",u,n.unit.volume,d>0&&t.jsxs("span",{style:{color:o("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),e.url&&t.jsx("a",{href:(()=>{const b=pi(e.metadata);return b?ui(e.url,b):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:o("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),p&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),p&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:a.map(b=>{const S=b.status==="missing";return b.url&&!S?t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${o("widget-border")}`,color:o("link-fg"),textDecoration:"none"},children:b.volume},b.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:o(S?"missing-fg":"desc-fg"),textDecoration:S?"line-through":"none",opacity:S?.6:1},children:b.volume},b.volume)})})]})},$r=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:a})=>{const p=ue(),c=e==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",g=u?u.split(/[/\\]/).pop()||u:"",x={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:o("primary-soft"),color:o("primary")},m={onMouseOver:S=>S.currentTarget.style.opacity="0.8",onMouseOut:S=>S.currentTarget.style.opacity="1"},b=t.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...x,background:o(d?"warning":"success"),color:o("on-color-fg")},...m,children:[t.jsx("span",{children:d?"📝":"📚"}),t.jsx("span",{children:d?"draft":"official"})]});return i==="index-browser"?c?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,t.jsxs("div",{onClick:r,title:p.mode.switchToSync,style:x,...m,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:p.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px"},...m,children:[t.jsx("span",{children:"📂"}),g&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:g})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:p.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:g||p.mode.configurePath,style:{...x,background:"transparent",padding:"6px",fontSize:"12px"},...m,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:c?p.mode.switchToGithub:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:c?"📁":"🌐"}),t.jsx("span",{children:c?p.mode.localMode:p.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&t.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...m,children:[t.jsx("span",{children:"📂"}),g&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:g})]}),!c&&g&&t.jsxs("div",{style:{...x,background:o("mode-active-bg"),color:o("on-color-fg"),cursor:"default"},title:u,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:g})]})]})},yn="bim-search-history",co=10,po=8;function Gt(){try{const e=localStorage.getItem(yn);return e?JSON.parse(e):[]}catch{return[]}}function na(e){try{const n=Gt().filter(i=>i!==e);n.unshift(e),n.length>co&&(n.length=co),localStorage.setItem(yn,JSON.stringify(n))}catch{}}function ia(e){try{const n=Gt().filter(i=>i!==e);localStorage.setItem(yn,JSON.stringify(n))}catch{}}function oa(){try{localStorage.removeItem(yn)}catch{}}const zr=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:l})=>{const a=ue(),p=l??a.search.placeholder,c={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,u]=f.useState(!1),[g,x]=f.useState([]),[m,b]=f.useState(-1),[S,h]=f.useState(Gt),y=f.useRef(null),j=f.useRef(null),k=f.useRef(null),$=f.useRef(!1);f.useEffect(()=>{b(-1);const C=n.trim();if(!C){x(S.map(A=>({type:"history",text:A})));return}if(!e.searchAll){x([]);return}let P=!1;const B=setTimeout(()=>{e.searchAll(C,po).then(A=>{if(P)return;const W=[...A.works,...A.books,...A.collections,...A.entities??[]];x(W.slice(0,po).map(V=>({type:"entry",text:V.title||V.id,entry:V})))}).catch(()=>{P||x([])})},80);return()=>{P=!0,clearTimeout(B)}},[n,S,e]),f.useEffect(()=>{const C=P=>{k.current&&!k.current.contains(P.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=P=>{var B,A;if(P.key==="/"&&document.activeElement!==y.current){const W=(B=document.activeElement)==null?void 0:B.tagName;if(W==="INPUT"||W==="TEXTAREA"||W==="SELECT")return;P.preventDefault(),(A=y.current)==null||A.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const v=f.useCallback(C=>{C.trim()&&(na(C.trim()),h(Gt())),r(C),u(!1)},[r]),_=f.useCallback(C=>{C.type==="history"?(i(C.text),v(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(i(C.text),v(C.text)))},[i,v,s]),w=f.useCallback(C=>{if(!d||g.length===0){C.key==="Enter"&&v(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(P=>(P+1)%g.length);break;case"ArrowUp":C.preventDefault(),b(P=>(P-1+g.length)%g.length);break;case"Enter":C.preventDefault(),m>=0&&m<g.length?_(g[m]):v(n);break;case"Escape":C.preventDefault(),u(!1);break}},[d,g,m,n,v,_]),z=f.useCallback((C,P)=>{P.stopPropagation(),ia(C),h(Gt()),x(B=>B.filter(A=>!(A.type==="history"&&A.text===C)))},[]),N=f.useCallback(C=>{C.stopPropagation(),oa(),h([]),x([])},[]);f.useEffect(()=>{if(m>=0&&j.current){const C=j.current.children;C[m]&&C[m].scrollIntoView({block:"nearest"})}},[m]);const T=!n.trim()&&S.length>0;return t.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:y,type:"text",placeholder:p,value:n,onChange:C=>{i(C.target.value),u(!0)},onCompositionStart:()=>{$.current=!0},onCompositionEnd:()=>{$.current=!1},onFocus:()=>{u(!0)},onKeyDown:w,style:{width:"100%",padding:"8px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),d&&g.length>0&&t.jsxs("div",{ref:j,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:o("input-bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"6px",boxShadow:o("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[T&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:o("desc-fg"),borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("span",{children:a.search.history}),t.jsx("button",{onClick:N,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),g.map((C,P)=>t.jsxs("div",{onClick:()=>_(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:o("fg"),background:P===m?o("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:[c[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&t.jsx("button",{onClick:B=>z(C.text,B),style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${C.type}-${C.text}-${P}`))]})]})},jn=({type:e,size:n=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:n,borderRadius:1,flex:"none",background:o(`type-${e}`),verticalAlign:"middle"}}),Ct="bim-recent-ids",uo="bim-recent-entries",xo=50,Rn=5,ra=50,sa=200;function _t(){try{const e=localStorage.getItem(Ct);if(e)return JSON.parse(e);const n=localStorage.getItem(uo);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Ct,JSON.stringify(i)),localStorage.removeItem(uo),i}return[]}catch{return[]}}function fo(e){try{const n=_t().filter(i=>i!==e);n.unshift(e),n.length>xo&&(n.length=xo),localStorage.setItem(Ct,JSON.stringify(n))}catch{}}function la(e){try{const n=_t().filter(i=>i!==e);localStorage.setItem(Ct,JSON.stringify(n))}catch{}}function aa(){try{localStorage.removeItem(Ct)}catch{}}const go={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Un=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c,hideModeIndicator:d,resultVariant:u="compact",renderEntry:g,initialQuery:x,onQueryChange:m,headerRight:b,reserveViewportHeight:S=!1})=>{const h=ue(),y=[{type:"work",name:h.indexType.work,key:"works"},{type:"book",name:h.indexType.book,key:"books"},{type:"collection",name:h.indexType.collection,key:"collections"},{type:"entity",name:h.indexType.entity,key:"entities"}],j=["work","collection","book","entity"],[k,$]=f.useState(x??""),[v,_]=f.useState(null),[w,z]=f.useState(null),[N,T]=f.useState("all"),[C,P]=f.useState(!1),[B,A]=f.useState(null),[W,V]=f.useState(""),[K,E]=f.useState(!(x!=null&&x.trim())),[le,G]=f.useState(_t),[ae,pe]=f.useState([]),[ee,X]=f.useState(!1),[ie,me]=f.useState(!1),[te,se]=f.useState(null),[fe,be]=f.useState(null),ze=f.useRef(void 0),ve=f.useRef(!1),ke=f.useCallback(async(M,ne)=>{if(!M.trim()){E(!0),_(null),z(null);return}E(!1),P(!0),V("");try{if(e.searchAll){const R=await e.searchAll(M,ne??Rn);_(R)}else{const R=["work","book","collection","entity"],J=await Promise.all(R.map(H=>e.search(M,H,{page:1,pageSize:ne??Rn})));_({works:J[0].entries,books:J[1].entries,collections:J[2].entries,entities:J[3].entries,totalWorks:J[0].total,totalBooks:J[1].total,totalCollections:J[2].total,totalEntities:J[3].total})}}catch(R){V(R instanceof Error?R.message:String(R)),_(null)}finally{P(!1)}},[e]);f.useEffect(()=>{let M=!1;const ne=()=>{var re,Se;const R=["work","book","collection","entity"],J=Promise.all(R.map(ye=>e.loadEntries(ye,{page:1,pageSize:1}).catch(()=>({total:0})))),H=((re=e.getResourceCounts)==null?void 0:re.call(e).catch(()=>null))??Promise.resolve(null),U=((Se=e.getSubtypeStats)==null?void 0:Se.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([J,H,U]).then(([ye,Le,Ye])=>{M||(se({works:ye[0].total,books:ye[1].total,collections:ye[2].total,entities:ye[3].total,hasText:Le==null?void 0:Le.hasText,hasImage:Le==null?void 0:Le.hasImage}),Ye&&be(Ye))})};return e.getCounts?e.getCounts().then(R=>{var J,H;M||(se({works:R.works,books:R.books,collections:R.collections,entities:R.entities,hasText:(J=R.resourceCounts)==null?void 0:J.hasText,hasImage:(H=R.resourceCounts)==null?void 0:H.hasImage}),R.subtypeStats&&be(R.subtypeStats))}).catch(()=>{M||ne()}):ne(),()=>{M=!0}},[e]),f.useEffect(()=>{ve.current||!(x!=null&&x.trim())||(ve.current=!0,ke(x))},[x,ke]);const Ne=f.useCallback(M=>{if($(M),!M.trim()){m==null||m(M),E(!0),_(null),z(null),T("all");return}ze.current&&clearTimeout(ze.current),ze.current=setTimeout(()=>{z(null),T("all"),m==null||m(M),ke(M)},sa)},[ke,m]),Ee=f.useCallback(M=>{ze.current&&clearTimeout(ze.current),T("all"),m==null||m(M),ke(M)},[ke,m]),O=f.useCallback(M=>{z(M),ke(k,ra)},[k,ke]);f.useEffect(()=>{if(!le.length){pe([]);return}let M=!1;return X(!0),Promise.all(le.slice(0,10).map(async ne=>{var R,J,H;try{if(e.getEntry){const re=await e.getEntry(ne);if(re)return re}const U=await e.getItem(ne);if(U){const re=U.authors;return{id:ne,title:U.title||ne,type:U.type||"work",author:(R=re==null?void 0:re[0])==null?void 0:R.name,dynasty:(J=re==null?void 0:re[0])==null?void 0:J.dynasty,role:(H=re==null?void 0:re[0])==null?void 0:H.role,edition:U.edition||void 0}}}catch{}return{id:ne,title:ne,type:"work",notFound:!0}})).then(ne=>{M||(pe(ne),X(!1))}),()=>{M=!0}},[le,e]);const ce=M=>{A(M.id),fo(M.id),G(_t()),r==null||r(M)},oe=(M,ne)=>{if(r&&da(ne)){ne.preventDefault(),ce(M);return}fo(M.id),G(_t())},he=M=>{la(M),G(_t())},Z=()=>{aa(),G([])},F=M=>y.find(ne=>ne.type===M),I=!K&&!v&&!W,D=v&&(v.works.length>0||v.books.length>0||v.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",style:S?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:pa}),t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("h1",{style:{margin:0,fontSize:"18px",color:o("fg")},children:h.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&t.jsx($r,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(zr,{transport:e,value:k,onChange:Ne,onSearch:Ee,onEntrySelect:ce}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${o("primary")}`,borderRadius:"6px",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"13px"},children:h.action.newEntry})]}),K&&t.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:te&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:fe?t.jsxs(t.Fragment,{children:[(fe.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:o("fg")},children:fe.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:o("fg")},children:te.books.toLocaleString()})," 本"]}),fe.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:o("fg")},children:fe.article.toLocaleString()})," 篇"]}):null,fe.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:o("fg")},children:fe.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:o("fg")},children:te.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[h.indexType.work," ",t.jsx("strong",{style:{color:o("fg")},children:te.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.book," ",t.jsx("strong",{style:{color:o("fg")},children:te.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.collection," ",t.jsx("strong",{style:{color:o("fg")},children:te.collections.toLocaleString()}),te.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.entity," ",t.jsx("strong",{style:{color:o("fg")},children:te.entities.toLocaleString()})]})]})}),te.hasImage!=null&&te.hasText!=null&&t.jsxs("span",{children:[h.resourceType.image," ",t.jsx("strong",{style:{color:o("fg")},children:te.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.resourceType.text," ",t.jsx("strong",{style:{color:o("fg")},children:te.hasText.toLocaleString()})]})]})}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:C||I?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg"),minHeight:ca,boxSizing:"border-box"},children:h.search.searching}):W?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:o("desc-fg")},children:W})}):K?t.jsx("div",{style:{flex:1},children:ee?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:h.search.loading}):ae.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:h.search.recentBrowse}),t.jsx("button",{onClick:Z,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:h.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:ae.slice(0,ie?10:3).map(M=>M.notFound?t.jsx(ga,{id:M.id,onRemove:he,t:h},M.id):t.jsx(mo,{entry:M,selected:B===M.id,onClick:oe,getConfig:F,onRemove:he},M.id))}),!ie&&ae.length>3&&t.jsx("button",{onClick:()=>me(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:h.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:h.search.searchTitle}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:h.search.searchSubtitle})]})}):D?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:ua}),(()=>{const M=U=>v[go[U]]??0,ne=j.map(U=>y.find(re=>re.type===U)).filter(U=>M(U.key)>0);if(ne.length<2)return null;const R=ne.reduce((U,re)=>U+M(re.key),0),J=U=>{if(T(U),U!=="all"&&w!==U){const re=y.find(ye=>ye.type===U),Se=(v[re.key]??[]).length;M(re.key)>Se&&O(U)}},H=U=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:o(U?"fg":"desc-fg"),fontWeight:U?700:400,boxShadow:U?`inset 0 -2px 0 ${o("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":h.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":N==="all",style:H(N==="all"),onClick:()=>J("all"),children:[h.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:R.toLocaleString()})]}),ne.map(U=>t.jsxs("button",{type:"button","aria-pressed":N===U.type,style:H(N===U.type),onClick:()=>J(U.type),children:[U.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:M(U.key).toLocaleString()})]},U.type))]})})(),y.map(({type:M,name:ne,key:R})=>{const J=v[R]??[],H=go[R],U=v[H]??0;if(J.length===0||N!=="all"&&N!==M)return null;const Se=N==="all"&&!(w===M)&&U>Rn;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${o("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:[t.jsx(jn,{type:M})," ",ne,t.jsxs("span",{style:{fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[U," ",h.unit.items]})]}),Se&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>O(M),style:{border:"none",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"12px"},children:h.action.viewAll})]}),t.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:J.map(ye=>{if(g)return t.jsx(f.Fragment,{children:g(ye)},ye.id);const Le=u==="card"?fa:mo;return t.jsx(Le,{entry:ye,selected:B===ye.id,onClick:oe,getConfig:F,query:k},ye.id)})})]},M)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:Kt(h.search.noResultsFor,{query:k})}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:h.search.tryOther})]})})]})},ca=240;function da(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const pa=`
|
|
2
2
|
.bim-ib-stats { min-height: 25px; box-sizing: content-box; }
|
|
3
3
|
@media (max-width: 719px) { .bim-ib-stats { min-height: 46px; } }
|
|
4
4
|
`,ua=`
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
content: ""; position: absolute; left: 50%; top: 50%;
|
|
9
9
|
width: max(calc(100% + 8px), 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
|
|
10
10
|
}
|
|
11
|
-
}`,Cr={color:"inherit",textDecoration:"none"},xa=({snippet:e})=>{const{convert:n}=V();return t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.6},children:jr(e).map((i,r)=>i.marked?t.jsx("mark",{style:{background:o("highlight-bg"),color:o("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(i.text)},r):t.jsx(f.Fragment,{children:n(i.text)},r))})},fa=({entry:e,selected:n,onClick:i,getConfig:r,query:s})=>{const l=de(),{convert:a}=V(),p=a(e.title||e.primary_name||e.id),c=e.measure_info?a(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",d=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&d.length?d.find(m=>{const b=typeof m=="string"?m:m==null?void 0:m.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,g=o("cover-accent"),x=Fe();return t.jsxs("a",{href:x(e.id),onClick:m=>i(e,m),className:"bim-result-card",style:{...Cr,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:o("bg"),border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[t.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${g} 50%, ${o("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${g} 14%, ${o("bg")}), color-mix(in srgb, ${g} 7%, ${o("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[t.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${g} 45%, transparent)`}}),t.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:g},children:Array.from(p).map((m,b)=>t.jsx("span",{children:m},b))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:o("fg")},children:p}),c&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",a(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:a(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",a(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",a(e.era),"〕"]}),e.edition&&t.jsx("span",{children:a(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[l.search.alias,":",a(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(xa,{snippet:e.descriptionSnippet}),t.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[t.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:[t.jsx(yn,{type:e.type,size:8})," ",r(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:l.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:l.misc.imageResource})]})]})]})},mo=({entry:e,selected:n,onClick:i,getConfig:r,query:s,onRemove:l})=>{const a=de(),{convert:p}=V(),c=[...e.additional_titles||[],...e.attached_texts||[]],d=s&&c.length?c.find(g=>{const x=typeof g=="string"?g:g==null?void 0:g.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,u=Fe();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("a",{href:u(e.id),onClick:g=>i(e,g),className:"bim-result-card",style:{...Cr,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx(yn,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:o("desc-fg"),lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:p(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{children:a.misc.textResource}),e.has_image&&t.jsx("span",{children:a.misc.imageResource})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",p(e.era),"〕"]}),e.edition&&p(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:p(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.juan_count,a.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",p(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:p(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",p(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),d&&t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:[a.search.alias,":",p(d)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:a.search.removeFromRecent,"aria-label":a.search.removeFromRecent,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},ga=({id:e,onRemove:n,t:i})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${o("widget-border")}`,background:o("input-bg"),opacity:.6},children:[t.jsx("span",{style:{fontSize:"16px"},children:"❓"}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:"13px",color:o("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:i.search.itemNotFound})]}),t.jsx("button",{onClick:()=>n(e),title:i.search.removeFromRecent,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function ma(e){var n;return!e.dynasty&&!e.birth_year&&!e.death_year&&(!e.alt_names||e.alt_names.length===0)&&!((n=e.description)!=null&&n.text)}function ha({data:e}){const{convert:n}=V(),{dynasty:i,birth_year:r,death_year:s}=e,l=[];return i&&l.push(`〔${n(i)}〕`),r!==void 0&&s!==void 0?l.push(`${r}—${s}`):r!==void 0?l.push(`${r}—?`):s!==void 0&&l.push(`?—${s}`),l.length===0?null:t.jsx("span",{style:{fontSize:"14px",color:o("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function ba({alt_names:e}){const{convert:n}=V(),i=new Map;for(const l of e){const a=l.type||"別名";i.has(a)||i.set(a,[]),i.get(a).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((l,a)=>{const p=r.indexOf(l),c=r.indexOf(a);return p===-1&&c===-1?0:p===-1?1:c===-1?-1:p-c});return t.jsx("div",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const a=i.get(l);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:o("desc-fg"),fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),t.jsx("span",{children:a.map((p,c)=>t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},c))})]},l)})})}function ya({data:e}){const n=e.external_ids;if(!n)return null;const i=[];return n.cbdb_id&&i.push(t.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:o("link-fg"),border:`1px solid ${o("link-fg")}40`,borderRadius:"3px",textDecoration:"none",background:`${o("link-fg")}08`},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),i.length===0?null:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:i})}function ja({works:e,transport:n,onNavigate:i,renderLink:r}){const s=de(),{convert:l}=V(),a=Fe(),[p,c]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let x=!1;const m=e.map(k=>k.work_id);return(async()=>{const k=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(m);let _=!0;for(let S=0;S<m.length;S++){const $=v[S];$!=null&&$.title?k.set(m[S],$.title):$!=null&&$.primary_name?k.set(m[S],$.primary_name):_=!1}if(_)return k}catch{}const h=[...m],y=8,j=new Array(y).fill(0).map(async()=>{for(;h.length;){const v=h.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),S=_&&(_.title||_.primary_name)||v;k.set(v,S)}catch{k.set(v,v)}}});return await Promise.all(j),k})().then(k=>{x||c(k)}),()=>{x=!0}},[e,n]);const d=new Map;for(const x of e){const m=x.role||"";d.has(m)||d.set(m,[]),d.get(m).push(x)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],g=[...d.keys()].sort((x,m)=>{const b=u.indexOf(x),k=u.indexOf(m);return b===-1&&k===-1?x.localeCompare(m):b===-1?1:k===-1?-1:b-k});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:o("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:o("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),g.map(x=>{const m=d.get(x);return t.jsxs("div",{style:{marginBottom:"8px"},children:[x&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"2px"},children:[l(x)," ",t.jsxs("span",{style:{color:o("desc-fg")},children:["(",m.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:x?"16px":"0",listStyle:x?"disc":"none",fontSize:"14px",lineHeight:1.8},children:m.map((b,k)=>{const h=l(p.get(b.work_id)||b.work_id);return r?t.jsx("li",{children:r(b.work_id,h)},k):i?t.jsx("li",{children:t.jsx("a",{href:a(b.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),i(b.work_id))},style:{color:o("link-fg"),textDecoration:"underline",cursor:"pointer"},children:h})},k):t.jsx("li",{children:h},k)})})]},x)})]})}const Ir=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:l})=>{var g;const a=de(),{convert:p}=V();let c=!1;try{c=ke.extractStatus(e.id)==="draft"}catch{}const d=ma(e),u=e.subtype==="people"?"人物":e.subtype==="place"?"地名":e.subtype==="dynasty"?"朝代":e.subtype==="anonymous"?"佚名":e.subtype==="collective"?"集体":e.subtype;return t.jsxs("div",{children:[!l&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:o("fg")},children:[p(e.primary_name),t.jsx(ha,{data:e})]}),s]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o("type-entity"),border:`1px solid color-mix(in srgb, ${o("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${o("type-entity")} 3%, transparent)`},children:a.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),c&&t.jsx("span",{style:{padding:"1px 6px",background:o("warn-bg"),border:`1px solid ${o("warn-border")}`,borderRadius:"2px",color:o("warn-fg")},children:a.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),d&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:o("widget-bg"),border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(ba,{alt_names:e.alt_names}),t.jsx(ya,{data:e}),((g=e.description)==null?void 0:g.text)&&t.jsx("p",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(e.description.text)}),e.works&&e.works.length>0&&t.jsx(ja,{works:e.works,transport:n,onNavigate:i,renderLink:r})]})},va=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function ka(e){const n=e.search(va);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const Tr={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>{let i=e,r="",s=n;if(e&&typeof n=="string"&&(n===e||n===Sa(e))){const[l,a]=ka(n);a&&(i=encodeURI(l),s=l,r=a)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:i,target:i!=null&&i.startsWith("http")?"_blank":void 0,rel:i!=null&&i.startsWith("http")?"noopener noreferrer":void 0,style:{color:o("link")},children:s}),r]})},code:({children:e})=>t.jsx("code",{style:{background:o("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function Sa(e){try{return decodeURI(e)}catch{return e}}const wa={...Tr,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},st=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:s}=V(),l=n?wa:Tr;return t.jsx("div",{className:r,style:i,children:t.jsx(Il,{remarkPlugins:[Tl],components:l,children:s(e)})})},_a=["〇","一","二","三","四","五","六","七","八","九"],ho=["","十","百","千"];function Er(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const a=parseInt(n[l]),p=i-1-l;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&p===1&&l===0?r+=ho[p]:r+=_a[a]+ho[p])}return r}function Rr(e){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:e,border:`1px solid color-mix(in srgb, ${e} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${e} 3%, transparent)`}}const $a={book:o("type-book"),work:o("type-work"),collection:o("type-collection"),entity:o("type-entity")};function za({type:e}){const n=de();return t.jsx("span",{style:Rr($a[e]),children:n.indexType[e]})}function Ca({isDraft:e}){const n=de(),i=o(e?"status-draft":"status-official");return t.jsx("span",{style:Rr(i),children:e?n.status.draft:n.status.official})}function Ia({id:e}){const n=de(),[i,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:o("desc-fg"),background:o("bg-subtle"),border:`1px solid ${o("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:o("fg")},children:e}),t.jsx("span",{onClick:s,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function Ve({children:e,extra:n}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("desc-fg"),letterSpacing:"1px"},children:e}),t.jsx("span",{style:{flex:1}}),n]})}function et({label:e,children:n}){return t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[t.jsx("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:e}),t.jsx("span",{style:{color:o("fg")},children:n})]})}function Nr({authors:e,type:n,onNavigate:i,renderLink:r}){const{convert:s}=V();return t.jsx("span",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.6},children:e.map((l,a)=>{const p=s(l.name),c=l.entity_id?t.jsx(Ke,{id:l.entity_id,label:p,onNavigate:i,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:p});return t.jsxs("span",{children:[a>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),c,l.role&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},a)})})}function Ke({id:e,label:n,onNavigate:i,renderLink:r}){const s=Fe();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i(e))},style:{color:o("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`,paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{children:n||e})}function Ta({id:e,title:n,edition:i,type:r,isDraft:s,authors:l,volumeText:a,meta:p,headerExtra:c,onNavigate:d,renderLink:u}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:o("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:i}),a&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:a})]}),c&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(za,{type:r}),t.jsx(Ca,{isDraft:s}),t.jsx(Ia,{id:e})]}),((l==null?void 0:l.length)||p.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(Nr,{authors:l,type:r,onNavigate:d,renderLink:u}),p]})]})}function Lr({items:e,label:n,showMeta:i,onNavigate:r,renderLink:s}){const l=de(),{convert:a}=V();if(!e.length)return null;const[p,c]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((d,u)=>{const g=p===u;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...g?{boxShadow:o("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>c(g?null:u),style:{padding:"8px 12px",background:o("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.15s",transform:g?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:a(d.source)}),!g&&i&&d.title_info&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a(d.title_info)}),d.source_bid&&t.jsx("span",{onClick:x=>x.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Ke,{id:d.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),g&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${o("widget-border")}`},children:[i&&(d.title_info||d.author_info||d.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&t.jsx(et,{label:l.label.titleInfo,children:a(d.title_info)}),d.author_info&&t.jsx(et,{label:l.label.authorInfo,children:a(d.author_info)}),d.edition&&t.jsx(et,{label:l.label.edition,children:a(d.edition)})]}),d.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:a(d.summary)})]}),d.comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.comment)})]}),d.additional_comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.additional_comment)})]})]})]},u)})})]})}function Ea({items:e,onNavigate:n,renderLink:i}){const r=de();return t.jsx(Lr,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Br({items:e,onNavigate:n,renderLink:i}){const r=de();return t.jsx(Lr,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function Ar({label:e,items:n}){const{convert:i}=V();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const l=typeof r=="string"?r:r.book_title;return t.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:o("fg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:i(l)},s)})})]}):null}function Ra({items:e}){const n=de();return t.jsx(Ar,{label:n.section.aliases,items:e})}function Na({items:e}){const n=de();return t.jsx(Ar,{label:n.section.attachedTexts,items:e})}function La({items:e}){const n=de(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.appendix}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:e.map((r,s)=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:o("fg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:["《",i(r.book_title),"》",r.n_juan!=null&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function Ba({items:e}){const n=de(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.locationHistory}),t.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[t.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:o("widget-border")}}),e.map((r,s)=>t.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[t.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:o("primary"),border:`1.5px solid ${o("input-bg")}`}}),t.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:o("fg")},children:i(r.name)}),r.description&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),marginLeft:"8px"},children:i(r.description)})]},s))]})]}):null}function Aa({items:e}){const n=de(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.historyOverview}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map((r,s)=>t.jsxs("div",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[t.jsx("span",{style:{position:"absolute",left:0,top:0,color:o("desc-fg")},children:"·"}),i(r)]},s))})]}):null}function bo({title:e,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:l}=V(),[a,p]=f.useState([]);return f.useEffect(()=>{if(!n.length){p([]);return}if(!i){p(n.map(d=>({id:d})));return}let c=!1;return Promise.all(n.map(d=>i.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,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(Ve,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",n.length,")"]})]}),t.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 t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),transition:"border-color 0.15s"},children:t.jsx(Ke,{id:c.id,label:d,onNavigate:r,renderLink:s})},c.id)})})]}):null}function Rn({book:e,onNavigate:n,renderLink:i}){const r=de(),{convert:s}=V(),[l,a]=f.useState(!1),p=e.resources&&e.resources.length>0,c=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:o("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(Ke,{id:e.id,label:c,onNavigate:n,renderLink:i})}),p&&t.jsx("span",{onClick:()=>a(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:o("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),p&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(xi,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Wa({ids:e,workData:n,transport:i,onNavigate:r,renderLink:s,footer:l}){const a=de(),{convert:p}=V(),[c,d]=f.useState([]);if(f.useEffect(()=>{if(!e.length){d([]);return}if(!i){d(e.map(k=>({id:k})));return}let b=!1;return Promise.all(e.map(k=>i.getItem(k).then(h=>({id:k,title:h?h.title:void 0,edition:h?h.edition:void 0,resources:h?h.resources:void 0,resource_groups:h?h.resource_groups:void 0})).catch(()=>({id:k})))).then(k=>{b||d(k)}),()=>{b=!0}},[e,i]),!e.length)return null;const u=c.length?c:e.map(b=>({id:b})),g=new Map(u.map(b=>[b.id,b])),x=n==null?void 0:n.version_graph,m=Ma(e,x);return t.jsxs(t.Fragment,{children:[t.jsxs(Ve,{children:[a.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,m.useGrouping?t.jsxs(t.Fragment,{children:[m.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:m.coreIds.map(b=>{const k=g.get(b);return k?t.jsx(Rn,{book:k,onNavigate:r,renderLink:s},b):null})}),m.groupedIds.map(b=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${o("widget-border")}`,borderRadius:6,background:o("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:o("fg"),userSelect:"none"},children:[p(b.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:o("desc-fg"),fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:o("desc-fg"),fontWeight:400},children:p(b.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(k=>{const h=g.get(k);return h?t.jsx(Rn,{book:h,onNavigate:r,renderLink:s},k):null})})]},b.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(b=>t.jsx(Rn,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Ma(e,n){var h,y;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.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:e,groupedIds:[]};const p=new Set(r),c=new Set([...s,...a]),d=j=>{if(c.has(j))return!0;const v=n.node_groups[j];return v!=null&&p.has(v)},u=[],g=new Map,x=[];for(const j of e)if(!((y=n.excluded_books)!=null&&y.includes(j)))if(d(j))u.push(j);else{const v=n.node_groups[j];v?(g.has(v)||g.set(v,[]),g.get(v).push(j)):x.push(j)}if(x.length+[...g.values()].reduce((j,v)=>j+v.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(j=>[j.id,j])),k=[...g.entries()].map(([j,v])=>{const _=b.get(j);return{id:j,label:(_==null?void 0:_.label)??j,description:_==null?void 0:_.description,ids:v}});return x.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:k}}function Fa({workData:e,onNavigate:n,renderLink:i}){var a,p,c,d;const r=de(),{convert:s}=V(),l=!!((a=e.description)!=null&&a.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:o("input-bg"),marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`},children:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:t.jsx(Ke,{id:e.id,label:s(e.title),onNavigate:n,renderLink:i})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:s(e.measure_info)}):((p=e.juan_count)==null?void 0:p.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[Er(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(Nr,{authors:e.authors,type:"work",onNavigate:n,renderLink:i})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((c=e.description)==null?void 0:c.text)&&t.jsx(st,{text:e.description.text,style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(d=e.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:t.jsx(et,{label:r.label.parentWork,children:t.jsx(Ke,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Pa({items:e,onNavigate:n,renderLink:i}){const r=de(),{convert:s}=V();return e.length?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(l=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid color-mix(in srgb, ${o("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${o("type-collection")} 3%, transparent)`},children:[t.jsx("span",{style:{fontSize:"11px",color:o("type-collection")},children:r.indexType.collection}),t.jsx(Ke,{id:l.id,label:s(l.title)||l.id,onNavigate:n,renderLink:i}),l.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"2px"},children:Kt(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const fi=({data:e,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:a,className:p,style:c})=>{var O,A,M,F,Y,K,R,oe;const d=de(),{convert:u}=V(),[g,x]=f.useState(null),[m,b]=f.useState(!1),[k,h]=f.useState(null),[y,j]=f.useState(null),[v,_]=f.useState([]),S=e||g;if(f.useEffect(()=>{if(e||!n||!i)return;let H=!1;return b(!0),h(null),i.getItem(n).then(re=>{H||(re?x(re):h(d.misc.notFoundEntry))}).catch(re=>{H||h(re instanceof Error?re.message:d.misc.loadFailed)}).finally(()=>{H||b(!1)}),()=>{H=!0}},[e,n,i]),f.useEffect(()=>{if(!S||!i){j(null),_([]);return}let H=!1;const re=S.type==="book"||S.type==="collection"?S.work_id:void 0;if(re?i.getItem(re).then(ee=>{!H&&ee&&ee.type==="work"&&j(ee)}).catch(()=>{}):j(null),S.type==="book"){const ee=S;ee.contained_in&&ee.contained_in.length>0?Promise.all(ee.contained_in.map(Q=>{const J=typeof Q=="string"?Q:Q.id,ce=typeof Q=="string"?void 0:Q.volume_index;return i.getItem(J).then(me=>({id:J,title:me&&me.title||J,volume_index:ce})).catch(()=>({id:J,title:J,volume_index:ce}))})).then(Q=>{H||_(Q)}):_([])}else _([]);return()=>{H=!0}},[S,i]),m)return t.jsx("div",{className:p,style:{...c,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((H,re)=>t.jsx("div",{style:{height:re===1?"32px":"16px",width:`${H}px`,background:o("widget-border"),borderRadius:"4px",opacity:.4}},re))})});if(k)return t.jsx("div",{className:p,style:{...c,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:k});if(!S)return null;if(S.type==="entity")return t.jsx("div",{className:p,style:c,children:t.jsx(Ir,{data:S,transport:i,onNavigate:r,renderLink:s,headerExtra:l})});const $=S.type==="book"?S:null,w=S.type==="collection"?S:null,C=S.type==="work"?S:null;let N=!1;try{N=ke.extractStatus(S.id)==="draft"}catch{}let E="";S.measure_info?E=u(S.measure_info):(O=S.juan_count)!=null&&O.number?E=Er(S.juan_count.number)+d.unit.juan:(A=S.juan_count)!=null&&A.description&&(E=u(S.juan_count.description));const I=[];return(M=S.publication_info)!=null&&M.year&&I.push(t.jsx(et,{label:d.label.year,children:S.publication_info.year},"year")),(F=S.current_location)!=null&&F.name&&I.push(t.jsx(et,{label:d.label.currentLocation,children:u(S.current_location.name)},"loc")),(Y=S.page_count)!=null&&Y.description&&I.push(t.jsx(et,{label:d.label.pageCount,children:S.page_count.description},"page")),$!=null&&$.edition&&I.push(t.jsx(et,{label:d.label.edition,children:u($.edition)},"ver")),C!=null&&C.parent_work&&I.push(t.jsx(et,{label:d.label.parentWork,children:t.jsx(Ke,{id:C.parent_work.id,label:u(C.parent_work.title),onNavigate:r,renderLink:s})},"pw")),C!=null&&C.parent_works&&C.parent_works.length>0&&!C.parent_work&&I.push(t.jsx(et,{label:d.label.parentWork,children:C.parent_works.map((H,re)=>t.jsxs("span",{children:[re>0&&"、",t.jsx(Ke,{id:H,onNavigate:r,renderLink:s})]},H))},"pws")),t.jsxs("div",{className:p,style:c,children:[t.jsx(Ta,{id:S.id,title:u(S.title),edition:S.edition?u(S.edition):void 0,type:S.type,isDraft:N,authors:S.authors,volumeText:E,meta:I,headerExtra:l,onNavigate:r,renderLink:s}),((K=S.description)==null?void 0:K.text)&&t.jsx(st,{text:S.description.text,style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),S.appendix&&S.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:S.appendix.map((H,re)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:o("bg-subtle"),borderRadius:4,border:`1px solid ${o("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:o("muted")},children:u(H.title)}),t.jsx(st,{text:H.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:o("fg")}})]},re))}),v.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:d.section.containedIn}),t.jsx(Pa,{items:v,onNavigate:r,renderLink:s})]}),y&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:d.section.belongsToWork}),t.jsx(Fa,{workData:y,onNavigate:r,renderLink:s})]}),S.additional_works&&S.additional_works.length>0&&t.jsx(La,{items:S.additional_works}),S.additional_titles&&S.additional_titles.length>0&&t.jsx(Ra,{items:S.additional_titles}),S.attached_texts&&S.attached_texts.length>0&&t.jsx(Na,{items:S.attached_texts}),S.indexed_by&&S.indexed_by.length>0&&t.jsx(Ea,{items:S.indexed_by,onNavigate:r,renderLink:s}),S.emendated_by&&S.emendated_by.length>0&&t.jsx(Br,{items:S.emendated_by,onNavigate:r,renderLink:s}),S.resources&&S.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:d.section.resources}),t.jsx(xi,{items:S.resources,resourceGroups:S.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),($==null?void 0:$.location_history)&&$.location_history.length>0&&t.jsx(Ba,{items:$.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&t.jsx(Aa,{items:w.history}),($==null?void 0:$.related_books)&&$.related_books.length>0&&t.jsx(bo,{title:d.section.relatedVersions,ids:$.related_books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.books)&&w.books.length>0&&t.jsx(bo,{title:d.section.containedBooks,ids:w.books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.contained_works)&&w.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(Ve,{children:[d.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",w.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.contained_works.map(H=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:t.jsx(Ke,{id:H.id,label:u(H.title),onNavigate:r,renderLink:s})},H.id))})]}),(((R=C==null?void 0:C.books)==null?void 0:R.length)||0)+(((oe=C==null?void 0:C.collections)==null?void 0:oe.length)||0)>0&&t.jsx(Wa,{ids:[...(C==null?void 0:C.books)||[],...(C==null?void 0:C.collections)||[]],workData:C??void 0,transport:i,onNavigate:r,renderLink:s,footer:a}),(C==null?void 0:C.related_works)&&C.related_works.length>0&&(()=>{const H=[],re=C.related_works.filter(te=>te.relation==="part_of"),ee=C.related_works.filter(te=>te.relation==="has_part"),Q=C.related_works.filter(te=>te.relation==="has_adaptation"),J=C.related_works.filter(te=>te.relation==="text_carried_by"),ce=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),me=C.related_works.filter(te=>!te.relation||!ce.has(te.relation));return re.length>0&&H.push({label:d.section.belongsToWork,items:re}),ee.length>0&&H.push({label:d.section.containedWorks,items:ee}),Q.length>0&&H.push({label:d.section.adaptations,items:Q}),J.length>0&&H.push({label:d.section.derivativeWorks,items:J}),me.length>0&&H.push({label:d.section.relatedWorks,items:me}),H.map(te=>t.jsxs("div",{children:[t.jsxs(Ve,{children:[te.label,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",te.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:te.items.map(ie=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:t.jsx(Ke,{id:ie.id,label:u(ie.title),onNavigate:r,renderLink:s})},ie.id))})]},te.label))})()]})};function Oa({data:e}){const n=de(),{convert:i}=V(),{stats:r}=e,s=r.processed_volumes??r.total_found_volumes,l=s!=null&&e.total_volumes>0?Math.round(s/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:i(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"6px"},children:i(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:o("desc-fg")},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:o("fg")},children:e.total_volumes})," ",n.unit.volume]}),l!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:o("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:o("fg")},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&t.jsxs("span",{children:[n.catalog.matched," ",t.jsx("strong",{style:{color:o("fg")},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&t.jsxs("span",{children:[n.catalog.unmatched," ",t.jsx("strong",{style:{color:o("missing-fg")},children:r.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:o("desc-fg")},children:[n.catalog.source," ",e.source]})]})}function Da({sections:e,activeSection:n,onSelect:i}){const r=de();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:yo(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:yo(n===s.name),children:[s.name,s.volume_range&&t.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function yo(e){return{padding:"4px 12px",border:e?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${o("primary")} 8%, transparent)`:"transparent",color:o(e?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Ha({id:e,label:n,onNavigate:i,renderLink:r}){const s=Fe();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i(e))},style:{color:o("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:n||e})}function Ga(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=e[0],r=e[e.length-1];return r-i+1===e.length?`${i}–${r}`:e.length<=3?e.join(", "):`${i}–${r} (${e.length}${n})`}function jo({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const s=de(),{convert:l}=V(),a=e.book_id||e.work_id,p=r&&e.volumes.length>0?Ga(e.volumes,s.unit.volume):null,c=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${o("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:o("desc-fg"),textAlign:"right"},children:p}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:o("fg")},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(d=>l(d)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:o(c?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),a&&t.jsx(Ha,{id:a,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!a&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const gi=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:l,style:a})=>{const p=de(),[c,d]=f.useState(null),[u,g]=f.useState(!1),[x,m]=f.useState(null),[b,k]=f.useState(null),[h,y]=f.useState(""),j=e||c;f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let w=!1;return g(!0),m(null),i.getCollectionCatalog(n).then(C=>{w||(C?d(C):m(p.catalog.notFound))}).catch(C=>{w||m(C instanceof Error?C.message:p.catalog.loadFailed)}).finally(()=>{w||g(!1)}),()=>{w=!0}},[e,n,i,p]);const v=(j==null?void 0:j.sections)&&j.sections.length>0,_=f.useMemo(()=>{if(!j)return!1;if(j.volume_index&&Object.keys(j.volume_index).length>0)return!0;const w=j.books.map(N=>N.volumes[0]).filter(N=>N!=null);return new Set(w).size<w.length},[j]),S=f.useMemo(()=>{if(!j)return[];let w=j.books;if(b&&(w=w.filter(C=>C.section===b)),h.trim()){const C=h.trim().toLowerCase();w=w.filter(N=>N.title.toLowerCase().includes(C)||N.sub_items&&N.sub_items.some(E=>E.toLowerCase().includes(C))||N.edition&&N.edition.toLowerCase().includes(C))}return w},[j,b,h]),$=f.useMemo(()=>{if(!_)return null;const w=[],C=new Map;for(const E of S){if(!E.volumes||E.volumes.length===0)continue;const I=E.volumes[0];C.has(I)||C.set(I,[]),C.get(I).push(E)}const N=[...C.keys()].sort((E,I)=>E-I);for(const E of N)w.push({volume:E,books:C.get(E)});return w},[S,_]);return u?t.jsx("div",{className:l,style:{...a,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):x?t.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:x}):j?t.jsxs("div",{className:l,style:a,children:[t.jsx(Oa,{data:j}),v&&t.jsx(Da,{sections:j.sections,activeSection:b,onSelect:k}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:h,onChange:w=>y(w.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:o("desc-fg")},children:[S.length," ",p.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[$?$.map((w,C)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:o("bg"),borderBottom:`1px solid ${o("widget-border")}`,fontSize:"12px",fontWeight:600,color:o("desc-fg"),position:"sticky",top:0,zIndex:1},children:Kt(p.catalog.volume,{n:w.volume})}),w.books.map((N,E)=>t.jsx(jo,{book:N,onNavigate:r,renderLink:s,showVolumes:N.volumes.length>1},`${w.volume}-${E}`))]},`${w.volume}-${C}`)):S.map((w,C)=>t.jsx(jo,{book:w,onNavigate:r,renderLink:s,showVolumes:!0},C)),S.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},jt=()=>{const[e,n]=f.useState(1);return f.useEffect(()=>{const i=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(i)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:o("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(e)})},Wr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Ua={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Ae(e){return Ua[e]??e}const It=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],Tt={熹平: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},Mr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function jn(e){const n=e.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const i=parseInt(n[1],10);if(i<100||i>2100)return;const r=n[2]?parseInt(n[2],10):void 0;return{from:i,to:r!=null&&r>=i&&r<=2100?r:void 0}}function Va(e){return e>=1950?"":e>=1912?"民國":e>=1645?"清":e>=1368?"明":e>=1279?"元":e>=960?"宋":e>=907?"五代":e>=618?"唐":e>=581?"隋":e>=420?"南北朝":e>=265?"晉":e>=220?"三國":e>=-202?"漢":""}const Ya=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,vo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function mi(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(vo))if(n.startsWith(s))return vo[s];const i=Ae(n);if(gt[i]!=null)return i;const r=rt(n);if(r&&n.length<=r.length+1)return Ae(r)}function ft(e,n){if(n){const i=Mr[`${n}|${e}`];if(i!=null)return i}return Tt[e]}const Ka=1911;function qa(e){const n=Tt[e];if(n==null)return;const i=tt[e];let r;for(const[s,l]of Object.entries(Tt))tt[s]===i&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const Ja={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function xn(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,i=0,r=!1;for(const l of e){const a=Ja[l];if(a===void 0)return;r=!0,l==="十"?i=(i||1)*10:l==="廿"||l==="卅"?(n+=a,i=0):i>=10?(n+=i+a,i=0):i=i*10+a}const s=n+i;return r&&s>0?s:void 0}function rt(e){for(const n of Wr)if(e.startsWith(n))return n}const tt={};{const e=(n,i)=>{for(const r of i)tt[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function mt(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(Tt))if(e.includes(r)&&!(i&&tt[r]&&tt[r]!==i&&Mr[`${i}|${r}`]==null))return r}function qt(e){var a,p,c;const n={era:"",reign:"",source:"none"},i=e.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const r=(a=e.lineage)==null?void 0:a.year_text;if(r){const d=rt(r)??"";return{era:Ae(d),reign:mt(r,d)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const d=jn(s);if(d)return{era:Va(d.from),reign:"",source:"publication"};const u=rt(s)??mi(s)??((c=It.find(m=>m.pattern.test(s)))==null?void 0:c.era)??"",g=mt(s,u)??"",x=u||(g?tt[g]??"":"");if(x||g)return{era:Ae(x),reign:g,source:"publication"}}const l=e.edition||e.title||"";if(l){const d=rt(l);if(d)return{era:Ae(d),reign:mt(l,d)??"",source:"edition"};const u=It.find(g=>g.pattern.test(l));if(u)return{era:Ae(u.era),reign:mt(l,u.era)??u.reign??"",source:"edition"}}return n}function vn(e){var r,s,l,a,p,c,d,u,g;if(((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;if(typeof((s=e.lineage)==null?void 0:s.year)=="number")return e.lineage.year;const n=(l=e.publication_info)==null?void 0:l.year;if(n){const x=jn(n);if(x)return x.from}const i=[(a=e.lineage)==null?void 0:a.year_text,(p=e.publication_info)==null?void 0:p.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const x of i){const m=((c=e.publication_info)==null?void 0:c.year)||((d=e.lineage)==null?void 0:d.year_text);if(m&&x!==m&&(rt(m)||mi(m)))break;const b=x.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??x.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=x.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(k){const v=rt(x);if(!v||Ae(v)==="民國"){const S=xn(k[1]);if(S!=null&&S>=1&&S<=120)return Ka+S}}const h=rt(x)??((u=It.find(v=>v.pattern.test(x)))==null?void 0:u.era),y=h?Ae(h):void 0,j=mt(x,y)??(rt(x)||(g=It.find(v=>v.pattern.test(x)))==null?void 0:g.reign);if(j){const v=ft(j,y);if(v==null)continue;const _=x.indexOf(j),S=_>=0?x.slice(_+j.length):"",$=S.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??S.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),w=$?xn($[1]):void 0;return v+(w?w-1:0)}}}function hi(e){var a,p,c,d,u,g;const n=(a=e.dating)==null?void 0:a.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(p=e.lineage)==null?void 0:p.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const x=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(x){const m=Vn[Ae(x[1])],b=gt[Ae(x[2])];if(m!=null&&b!=null)return{from:Math.min(m,b)-20,to:Math.max(m,b)+40}}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const x=jn(s);if((x==null?void 0:x.to)!=null)return{from:x.from,to:x.to};const m=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(m){const b=Vn[Ae(m[1])],k=gt[Ae(m[2])];if(b!=null&&k!=null)return{from:Math.min(b,k)-20,to:Math.max(b,k)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const x of l){if(!/[間间]/.test(x))continue;const m=rt(x)??mi(x)??((g=It.find(h=>h.pattern.test(x)))==null?void 0:g.era),b=m?Ae(m):void 0,k=[];for(const h of Object.keys(Tt))x.includes(h)&&(b&&tt[h]&&tt[h]!==b||ft(h,b)!=null&&k.push(h));if(k.length===0){const h=x.match(/([一-鿿])([一-鿿])[間间]/);if(h&&b){for(const y of[h[1],h[2]])for(const j of Object.keys(Tt))if(tt[j]===b&&!(j[0]!==y&&j[j.length-1]!==y)&&ft(j,b)!=null){k.push(j);break}}}if(k.length>0){const h=k.map(_=>ft(_,b)).filter(_=>_!=null),y=Math.min(...h),j=k.reduce((_,S)=>ft(_,b)>=ft(S,b)?_:S),v=qa(j)??Nn(b??"")??Math.max(...h);return{from:y,to:v>y?v:Nn(b??tt[j]??"")??y}}if(b&>[b]!=null)return{from:gt[b],to:Nn(b)??gt[b]}}}const gt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Za=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Xa=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,ko=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function So(e,n){for(const i of Wr){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!mt(e.slice(r),Ae(i)))continue}const s=Ae(i);if(s===n)continue;const l=e.slice(r),a=mt(l,s)??"";let p;if(a){const c=ft(a,s);if(c!=null){const u=l.slice(l.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),g=u?xn(u[1]):void 0;p=c+(g?g-1:0)}}return{era:s,reign:a,year:p}}for(const i of It)if(i.pattern.test(e))return{era:Ae(i.era),reign:i.reign??""}}function Qa(e){var y,j,v,_,S;const n=qt(e),i=((y=e.publication_info)==null?void 0:y.year)??"",r=i?jn(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),a=((j=e.lineage)==null?void 0:j.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(a),c=n.source==="publication"&&Ya.test(i),d=n.source==="publication"&&/[間间]/.test(i),u=a.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let g;l||p||c||d?g=void 0:u?g=parseInt(u[2],10):g=vn(e);const x=g==null?hi(e):void 0;let m;n.source==="publication"&&(c||ko.test(i))?m="uncertain":n.source==="lineage"||n.source==="publication"?m="attested":ko.test(s)||!n.reign&&g==null?m="uncertain":m="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((v=e.lineage)==null?void 0:v.year_text)??((_=e.lineage)==null?void 0:_.year)??""}」`:`出版著錄「${((S=e.publication_info)==null?void 0:S.year)??""}」`,k={era:n.era,reign:n.reign,year:g,yearRange:x,certainty:m,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const $=a.match(/[、,,]\s*([宋元明清])/);$&&$[1]!==k.era&&(k.laterRepair={era:$[1]})}if(!k.laterRepair&&Xa.test(s)){const $=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);$&&$[1]!==n.era&&(k.laterRepair={era:$[1]})}const h=Za.find($=>$.re.test(s));if(h){const $=s.search(h.re),w=s.slice($),C=So(w,n.era)??So(s,n.era);C&&(k.basedOn={era:C.era,reign:C.reign,year:C.year,relation:h.relation})}return k}const Vn={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Nn(e){return Vn[e]}function fn(e){const n=vn(e);if(n!=null)return n;const i=hi(e);if(i)return i.from;const r=qt(e).era;return r?gt[r]:void 0}const wo=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Yn(e){const n=wo.indexOf(e);return n===-1?wo.length:n}function ec(e){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of e){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 i=[],r=(s,l)=>{n[s].length&&i.push({key:s,labelKey:l,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),i}function bi(e,n){const i=di(e||[]),r=new Map,s=[];for(const d of i)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((u,g)=>{const x=m=>m.group_role==="origin"?0:m.group_role==="mirror"?1:2;return x(u)-x(g)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=yt(d),g=u.includes("text"),x=u.includes("image");g&&x?l.textImage.push(d):g?l.text.push(d):x?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=[...r.entries()].map(([d,u])=>{var g,x;return{key:d,label:((g=n==null?void 0:n[d])==null?void 0:g.label)||d,description:(x=n==null?void 0:n[d])==null?void 0:x.description,items:u}});return{buckets:p,mirrors:c,total:i.length}}function kn(e){const n=[],i=e.metadata||{};i.edition&&n.push(String(i.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const r=hn(e);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),i.version&&n.push(String(i.version)),n.join(" · ")}function Fr(e,n){if(kn(e)||n.filter(r=>r.name===e.name).length<2)return"";try{const r=new URL(e.url),s=r.searchParams.get("res")||r.searchParams.get("id");if(s)return s;const l=r.pathname.split("/").filter(Boolean).pop();if(l)return decodeURIComponent(l)}catch{}return""}function Pr(e,n){var l,a;const i=e.resources||[],r=[],s=[];for(const p of i){const c=yt(p);c.includes("image")&&r.push(p),c.includes("physical")&&s.push(p)}return{id:e.id,name:e.edition||e.title||e.id,era:qt(e),year:vn(e),sortYear:fn(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:tc(e.id,n),group:(a=n==null?void 0:n.node_groups)==null?void 0:a[e.id],hasImage:r.length>0}}function tc(e,n){var p,c;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(p=n.collections)==null?void 0:p[i];if(((r==null?void 0:r.book_ids)??(i==="core"?n.core_books??[]:[])).includes(e))return!0;const l=(r==null?void 0:r.groups)??[],a=(c=n.node_groups)==null?void 0:c[e];return!!a&&l.includes(a)}function Or(e,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!r.has(c.id)).map(c=>Pr(c,n));let l=s;i.era&&(l=l.filter(c=>c.era.era===i.era)),i.scanOnly&&(l=l.filter(c=>c.hasImage)),i.sort==="year"?l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=c.r.sortYear,g=d.r.sortYear;return u!=null&&g!=null?u-g||c.i-d.i:u!=null?-1:g!=null?1:c.i-d.i}).map(c=>c.r):l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=g=>(g.important?0:1)*2+(g.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)=>Yn(c)-Yn(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(c=>c.era.source==="edition")}}function nc(e,n){var h,y;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.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:e,groupedIds:[]};const p=new Set(r),c=new Set([...s,...a]),d=j=>{if(c.has(j))return!0;const v=n.node_groups[j];return v!=null&&p.has(v)},u=[],g=new Map,x=[];for(const j of e)if(!((y=n.excluded_books)!=null&&y.includes(j)))if(d(j))u.push(j);else{const v=n.node_groups[j];v?(g.has(v)||g.set(v,[]),g.get(v).push(j)):x.push(j)}if(x.length+[...g.values()].reduce((j,v)=>j+v.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(j=>[j.id,j])),k=[...g.entries()].map(([j,v])=>{const _=b.get(j);return{id:j,label:(_==null?void 0:_.label)??j,description:_==null?void 0:_.description,ids:v}});return x.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:k}}const Dr=["撰","編","注","校","譯","繪","其他"],ic=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function yi(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of ic)if(r.test(n))return i;return"其他"}function ji(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Hr(e){const n=new Map;for(const r of e){const s=yi(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:e.length}];for(const r of Dr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function Gr(e,n,i){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 e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(l=>({id:l.id,title:l.title,volumes:Gt(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,a;return{id:s,title:((l=i==null?void 0:i.get(s))==null?void 0:l.title)||s,edition:(a=i==null?void 0:i.get(s))==null?void 0:a.edition,volumes:[]}}),source:"books",sections:[]}}function Gt(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(n=>typeof n=="number");if(typeof e=="string"){const n=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[i,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-i+1)},(s,l)=>i+l)}return e.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function Sn(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((l,a)=>l-a),r=i[0],s=i[i.length-1];return s-r+1===i.length?`${r}–${s}`:i.length<=3?i.join(", "):`${r}–${s} (${i.length}${n})`}const oc=["〇","一","二","三","四","五","六","七","八","九"],_o=["","十","百","千"];function Ur(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const a=parseInt(n[l]),p=i-1-l;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&p===1&&l===0?r+=_o[p]:r+=oc[a]+_o[p])}return r}function rc(e){return e==null?"":typeof e=="string"?e:e.title??""}function lt(e,n="卷"){var r,s;const i=e;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?Ur(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Vr(e){var r;if(e.edition_type)return e.edition_type;if((r=e.lineage)!=null&&r.category)return e.lineage.category;const n=e.edition||e.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,l]of i)if(s.test(n))return l;return""}const sc="guji_markdown";function Kn(e){const n=e==null?void 0:e.guji_markdown;if(typeof n!="string")return!1;const i=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!i)return!1;const r=parseInt(i[1],10),s=parseInt(i[2],10);return r>0||s>=2}const lc=/^□\{guess=([^\s{}]+)\}/;function ac(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function Yr(e,n){let i=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
|
|
11
|
+
}`,Cr={color:"inherit",textDecoration:"none"},xa=({snippet:e})=>{const{convert:n}=q();return t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.6},children:jr(e).map((i,r)=>i.marked?t.jsx("mark",{style:{background:o("highlight-bg"),color:o("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(i.text)},r):t.jsx(f.Fragment,{children:n(i.text)},r))})},fa=({entry:e,selected:n,onClick:i,getConfig:r,query:s})=>{const l=ue(),{convert:a}=q(),p=a(e.title||e.primary_name||e.id),c=e.measure_info?a(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",d=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&d.length?d.find(m=>{const b=typeof m=="string"?m:m==null?void 0:m.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,g=o("cover-accent"),x=Pe();return t.jsxs("a",{href:x(e.id),onClick:m=>i(e,m),className:"bim-result-card",style:{...Cr,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:o("bg"),border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[t.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${g} 50%, ${o("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${g} 14%, ${o("bg")}), color-mix(in srgb, ${g} 7%, ${o("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[t.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${g} 45%, transparent)`}}),t.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:g},children:Array.from(p).map((m,b)=>t.jsx("span",{children:m},b))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:o("fg")},children:p}),c&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",a(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:a(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",a(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",a(e.era),"〕"]}),e.edition&&t.jsx("span",{children:a(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[l.search.alias,":",a(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(xa,{snippet:e.descriptionSnippet}),t.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[t.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:[t.jsx(jn,{type:e.type,size:8})," ",r(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:l.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:l.misc.imageResource})]})]})]})},mo=({entry:e,selected:n,onClick:i,getConfig:r,query:s,onRemove:l})=>{const a=ue(),{convert:p}=q(),c=[...e.additional_titles||[],...e.attached_texts||[]],d=s&&c.length?c.find(g=>{const x=typeof g=="string"?g:g==null?void 0:g.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,u=Pe();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("a",{href:u(e.id),onClick:g=>i(e,g),className:"bim-result-card",style:{...Cr,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx(jn,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:o("desc-fg"),lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:p(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{children:a.misc.textResource}),e.has_image&&t.jsx("span",{children:a.misc.imageResource})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",p(e.era),"〕"]}),e.edition&&p(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:p(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.juan_count,a.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",p(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:p(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",p(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),d&&t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:[a.search.alias,":",p(d)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:a.search.removeFromRecent,"aria-label":a.search.removeFromRecent,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},ga=({id:e,onRemove:n,t:i})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${o("widget-border")}`,background:o("input-bg"),opacity:.6},children:[t.jsx("span",{style:{fontSize:"16px"},children:"❓"}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:"13px",color:o("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:i.search.itemNotFound})]}),t.jsx("button",{onClick:()=>n(e),title:i.search.removeFromRecent,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function ma(e){var n;return!e.dynasty&&!e.birth_year&&!e.death_year&&(!e.alt_names||e.alt_names.length===0)&&!((n=e.description)!=null&&n.text)}function ha({data:e}){const{convert:n}=q(),{dynasty:i,birth_year:r,death_year:s}=e,l=[];return i&&l.push(`〔${n(i)}〕`),r!==void 0&&s!==void 0?l.push(`${r}—${s}`):r!==void 0?l.push(`${r}—?`):s!==void 0&&l.push(`?—${s}`),l.length===0?null:t.jsx("span",{style:{fontSize:"14px",color:o("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function ba({alt_names:e}){const{convert:n}=q(),i=new Map;for(const l of e){const a=l.type||"別名";i.has(a)||i.set(a,[]),i.get(a).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((l,a)=>{const p=r.indexOf(l),c=r.indexOf(a);return p===-1&&c===-1?0:p===-1?1:c===-1?-1:p-c});return t.jsx("div",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const a=i.get(l);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:o("desc-fg"),fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),t.jsx("span",{children:a.map((p,c)=>t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},c))})]},l)})})}function ya({data:e}){const n=e.external_ids;if(!n)return null;const i=[];return n.cbdb_id&&i.push(t.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:o("link-fg"),border:`1px solid ${o("link-fg")}40`,borderRadius:"3px",textDecoration:"none",background:`${o("link-fg")}08`},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),i.length===0?null:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:i})}function ja({works:e,transport:n,onNavigate:i,renderLink:r}){const s=ue(),{convert:l}=q(),a=Pe(),[p,c]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let x=!1;const m=e.map(S=>S.work_id);return(async()=>{const S=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(m);let $=!0;for(let v=0;v<m.length;v++){const _=k[v];_!=null&&_.title?S.set(m[v],_.title):_!=null&&_.primary_name?S.set(m[v],_.primary_name):$=!1}if($)return S}catch{}const h=[...m],y=8,j=new Array(y).fill(0).map(async()=>{for(;h.length;){const k=h.shift();if(!k)break;if(!S.has(k))try{if(n.getEntry){const _=await n.getEntry(k);if(_!=null&&_.title){S.set(k,_.title);continue}}const $=await n.getItem(k),v=$&&($.title||$.primary_name)||k;S.set(k,v)}catch{S.set(k,k)}}});return await Promise.all(j),S})().then(S=>{x||c(S)}),()=>{x=!0}},[e,n]);const d=new Map;for(const x of e){const m=x.role||"";d.has(m)||d.set(m,[]),d.get(m).push(x)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],g=[...d.keys()].sort((x,m)=>{const b=u.indexOf(x),S=u.indexOf(m);return b===-1&&S===-1?x.localeCompare(m):b===-1?1:S===-1?-1:b-S});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:o("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:o("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),g.map(x=>{const m=d.get(x);return t.jsxs("div",{style:{marginBottom:"8px"},children:[x&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"2px"},children:[l(x)," ",t.jsxs("span",{style:{color:o("desc-fg")},children:["(",m.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:x?"16px":"0",listStyle:x?"disc":"none",fontSize:"14px",lineHeight:1.8},children:m.map((b,S)=>{const h=l(p.get(b.work_id)||b.work_id);return r?t.jsx("li",{children:r(b.work_id,h)},S):i?t.jsx("li",{children:t.jsx("a",{href:a(b.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),i(b.work_id))},style:{color:o("link-fg"),textDecoration:"underline",cursor:"pointer"},children:h})},S):t.jsx("li",{children:h},S)})})]},x)})]})}const Ir=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:l})=>{var g;const a=ue(),{convert:p}=q();let c=!1;try{c=we.extractStatus(e.id)==="draft"}catch{}const d=ma(e),u=e.subtype==="people"?"人物":e.subtype==="place"?"地名":e.subtype==="dynasty"?"朝代":e.subtype==="anonymous"?"佚名":e.subtype==="collective"?"集体":e.subtype;return t.jsxs("div",{children:[!l&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:o("fg")},children:[p(e.primary_name),t.jsx(ha,{data:e})]}),s]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o("type-entity"),border:`1px solid color-mix(in srgb, ${o("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${o("type-entity")} 3%, transparent)`},children:a.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),c&&t.jsx("span",{style:{padding:"1px 6px",background:o("warn-bg"),border:`1px solid ${o("warn-border")}`,borderRadius:"2px",color:o("warn-fg")},children:a.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),d&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:o("widget-bg"),border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(ba,{alt_names:e.alt_names}),t.jsx(ya,{data:e}),((g=e.description)==null?void 0:g.text)&&t.jsx("p",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(e.description.text)}),e.works&&e.works.length>0&&t.jsx(ja,{works:e.works,transport:n,onNavigate:i,renderLink:r})]})},va=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function ka(e){const n=e.search(va);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const Tr={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>{let i=e,r="",s=n;if(e&&typeof n=="string"&&(n===e||n===Sa(e))){const[l,a]=ka(n);a&&(i=encodeURI(l),s=l,r=a)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:i,target:i!=null&&i.startsWith("http")?"_blank":void 0,rel:i!=null&&i.startsWith("http")?"noopener noreferrer":void 0,style:{color:o("link")},children:s}),r]})},code:({children:e})=>t.jsx("code",{style:{background:o("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function Sa(e){try{return decodeURI(e)}catch{return e}}const wa={...Tr,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},lt=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:s}=q(),l=n?wa:Tr;return t.jsx("div",{className:r,style:i,children:t.jsx(Il,{remarkPlugins:[Tl],components:l,children:s(e)})})},_a=["〇","一","二","三","四","五","六","七","八","九"],ho=["","十","百","千"];function Er(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const a=parseInt(n[l]),p=i-1-l;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&p===1&&l===0?r+=ho[p]:r+=_a[a]+ho[p])}return r}function Rr(e){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:e,border:`1px solid color-mix(in srgb, ${e} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${e} 3%, transparent)`}}const $a={book:o("type-book"),work:o("type-work"),collection:o("type-collection"),entity:o("type-entity")};function za({type:e}){const n=ue();return t.jsx("span",{style:Rr($a[e]),children:n.indexType[e]})}function Ca({isDraft:e}){const n=ue(),i=o(e?"status-draft":"status-official");return t.jsx("span",{style:Rr(i),children:e?n.status.draft:n.status.official})}function Ia({id:e}){const n=ue(),[i,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:o("desc-fg"),background:o("bg-subtle"),border:`1px solid ${o("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:o("fg")},children:e}),t.jsx("span",{onClick:s,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function Ve({children:e,extra:n}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("desc-fg"),letterSpacing:"1px"},children:e}),t.jsx("span",{style:{flex:1}}),n]})}function tt({label:e,children:n}){return t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[t.jsx("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:e}),t.jsx("span",{style:{color:o("fg")},children:n})]})}function Nr({authors:e,type:n,onNavigate:i,renderLink:r}){const{convert:s}=q();return t.jsx("span",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.6},children:e.map((l,a)=>{const p=s(l.name),c=l.entity_id?t.jsx(Ke,{id:l.entity_id,label:p,onNavigate:i,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:p});return t.jsxs("span",{children:[a>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),c,l.role&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},a)})})}function Ke({id:e,label:n,onNavigate:i,renderLink:r}){const s=Pe();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i(e))},style:{color:o("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`,paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{children:n||e})}function Ta({id:e,title:n,edition:i,type:r,isDraft:s,authors:l,volumeText:a,meta:p,headerExtra:c,onNavigate:d,renderLink:u}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:o("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:i}),a&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:a})]}),c&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(za,{type:r}),t.jsx(Ca,{isDraft:s}),t.jsx(Ia,{id:e})]}),((l==null?void 0:l.length)||p.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(Nr,{authors:l,type:r,onNavigate:d,renderLink:u}),p]})]})}function Lr({items:e,label:n,showMeta:i,onNavigate:r,renderLink:s}){const l=ue(),{convert:a}=q();if(!e.length)return null;const[p,c]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((d,u)=>{const g=p===u;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...g?{boxShadow:o("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>c(g?null:u),style:{padding:"8px 12px",background:o("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.15s",transform:g?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:a(d.source)}),!g&&i&&d.title_info&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a(d.title_info)}),d.source_bid&&t.jsx("span",{onClick:x=>x.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Ke,{id:d.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),g&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${o("widget-border")}`},children:[i&&(d.title_info||d.author_info||d.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&t.jsx(tt,{label:l.label.titleInfo,children:a(d.title_info)}),d.author_info&&t.jsx(tt,{label:l.label.authorInfo,children:a(d.author_info)}),d.edition&&t.jsx(tt,{label:l.label.edition,children:a(d.edition)})]}),d.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:a(d.summary)})]}),d.comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.comment)})]}),d.additional_comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.additional_comment)})]})]})]},u)})})]})}function Ea({items:e,onNavigate:n,renderLink:i}){const r=ue();return t.jsx(Lr,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Br({items:e,onNavigate:n,renderLink:i}){const r=ue();return t.jsx(Lr,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function Ar({label:e,items:n}){const{convert:i}=q();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const l=typeof r=="string"?r:r.book_title;return t.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:o("fg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:i(l)},s)})})]}):null}function Ra({items:e}){const n=ue();return t.jsx(Ar,{label:n.section.aliases,items:e})}function Na({items:e}){const n=ue();return t.jsx(Ar,{label:n.section.attachedTexts,items:e})}function La({items:e}){const n=ue(),{convert:i}=q();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.appendix}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:e.map((r,s)=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:o("fg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:["《",i(r.book_title),"》",r.n_juan!=null&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function Ba({items:e}){const n=ue(),{convert:i}=q();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.locationHistory}),t.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[t.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:o("widget-border")}}),e.map((r,s)=>t.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[t.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:o("primary"),border:`1.5px solid ${o("input-bg")}`}}),t.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:o("fg")},children:i(r.name)}),r.description&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),marginLeft:"8px"},children:i(r.description)})]},s))]})]}):null}function Aa({items:e}){const n=ue(),{convert:i}=q();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.historyOverview}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map((r,s)=>t.jsxs("div",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[t.jsx("span",{style:{position:"absolute",left:0,top:0,color:o("desc-fg")},children:"·"}),i(r)]},s))})]}):null}function bo({title:e,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:l}=q(),[a,p]=f.useState([]);return f.useEffect(()=>{if(!n.length){p([]);return}if(!i){p(n.map(d=>({id:d})));return}let c=!1;return Promise.all(n.map(d=>i.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,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(Ve,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",n.length,")"]})]}),t.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 t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),transition:"border-color 0.15s"},children:t.jsx(Ke,{id:c.id,label:d,onNavigate:r,renderLink:s})},c.id)})})]}):null}function Nn({book:e,onNavigate:n,renderLink:i}){const r=ue(),{convert:s}=q(),[l,a]=f.useState(!1),p=e.resources&&e.resources.length>0,c=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:o("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(Ke,{id:e.id,label:c,onNavigate:n,renderLink:i})}),p&&t.jsx("span",{onClick:()=>a(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:o("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),p&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(xi,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Wa({ids:e,workData:n,transport:i,onNavigate:r,renderLink:s,footer:l}){const a=ue(),{convert:p}=q(),[c,d]=f.useState([]);if(f.useEffect(()=>{if(!e.length){d([]);return}if(!i){d(e.map(S=>({id:S})));return}let b=!1;return Promise.all(e.map(S=>i.getItem(S).then(h=>({id:S,title:h?h.title:void 0,edition:h?h.edition:void 0,resources:h?h.resources:void 0,resource_groups:h?h.resource_groups:void 0})).catch(()=>({id:S})))).then(S=>{b||d(S)}),()=>{b=!0}},[e,i]),!e.length)return null;const u=c.length?c:e.map(b=>({id:b})),g=new Map(u.map(b=>[b.id,b])),x=n==null?void 0:n.version_graph,m=Ma(e,x);return t.jsxs(t.Fragment,{children:[t.jsxs(Ve,{children:[a.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,m.useGrouping?t.jsxs(t.Fragment,{children:[m.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:m.coreIds.map(b=>{const S=g.get(b);return S?t.jsx(Nn,{book:S,onNavigate:r,renderLink:s},b):null})}),m.groupedIds.map(b=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${o("widget-border")}`,borderRadius:6,background:o("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:o("fg"),userSelect:"none"},children:[p(b.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:o("desc-fg"),fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:o("desc-fg"),fontWeight:400},children:p(b.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(S=>{const h=g.get(S);return h?t.jsx(Nn,{book:h,onNavigate:r,renderLink:s},S):null})})]},b.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(b=>t.jsx(Nn,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Ma(e,n){var h,y;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.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:e,groupedIds:[]};const p=new Set(r),c=new Set([...s,...a]),d=j=>{if(c.has(j))return!0;const k=n.node_groups[j];return k!=null&&p.has(k)},u=[],g=new Map,x=[];for(const j of e)if(!((y=n.excluded_books)!=null&&y.includes(j)))if(d(j))u.push(j);else{const k=n.node_groups[j];k?(g.has(k)||g.set(k,[]),g.get(k).push(j)):x.push(j)}if(x.length+[...g.values()].reduce((j,k)=>j+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(j=>[j.id,j])),S=[...g.entries()].map(([j,k])=>{const $=b.get(j);return{id:j,label:($==null?void 0:$.label)??j,description:$==null?void 0:$.description,ids:k}});return x.length>0&&S.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:S}}function Fa({workData:e,onNavigate:n,renderLink:i}){var a,p,c,d;const r=ue(),{convert:s}=q(),l=!!((a=e.description)!=null&&a.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:o("input-bg"),marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`},children:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:t.jsx(Ke,{id:e.id,label:s(e.title),onNavigate:n,renderLink:i})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:s(e.measure_info)}):((p=e.juan_count)==null?void 0:p.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[Er(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(Nr,{authors:e.authors,type:"work",onNavigate:n,renderLink:i})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((c=e.description)==null?void 0:c.text)&&t.jsx(lt,{text:e.description.text,style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(d=e.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:t.jsx(tt,{label:r.label.parentWork,children:t.jsx(Ke,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Pa({items:e,onNavigate:n,renderLink:i}){const r=ue(),{convert:s}=q();return e.length?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(l=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid color-mix(in srgb, ${o("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${o("type-collection")} 3%, transparent)`},children:[t.jsx("span",{style:{fontSize:"11px",color:o("type-collection")},children:r.indexType.collection}),t.jsx(Ke,{id:l.id,label:s(l.title)||l.id,onNavigate:n,renderLink:i}),l.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"2px"},children:Kt(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const fi=({data:e,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:a,className:p,style:c})=>{var P,B,A,W,V,K,E,le;const d=ue(),{convert:u}=q(),[g,x]=f.useState(null),[m,b]=f.useState(!1),[S,h]=f.useState(null),[y,j]=f.useState(null),[k,$]=f.useState([]),v=e||g;if(f.useEffect(()=>{if(e||!n||!i)return;let G=!1;return b(!0),h(null),i.getItem(n).then(ae=>{G||(ae?x(ae):h(d.misc.notFoundEntry))}).catch(ae=>{G||h(ae instanceof Error?ae.message:d.misc.loadFailed)}).finally(()=>{G||b(!1)}),()=>{G=!0}},[e,n,i]),f.useEffect(()=>{if(!v||!i){j(null),$([]);return}let G=!1;const ae=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(ae?i.getItem(ae).then(pe=>{!G&&pe&&pe.type==="work"&&j(pe)}).catch(()=>{}):j(null),v.type==="book"){const pe=v;pe.contained_in&&pe.contained_in.length>0?Promise.all(pe.contained_in.map(ee=>{const X=typeof ee=="string"?ee:ee.id,ie=typeof ee=="string"?void 0:ee.volume_index;return i.getItem(X).then(me=>({id:X,title:me&&me.title||X,volume_index:ie})).catch(()=>({id:X,title:X,volume_index:ie}))})).then(ee=>{G||$(ee)}):$([])}else $([]);return()=>{G=!0}},[v,i]),m)return t.jsx("div",{className:p,style:{...c,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((G,ae)=>t.jsx("div",{style:{height:ae===1?"32px":"16px",width:`${G}px`,background:o("widget-border"),borderRadius:"4px",opacity:.4}},ae))})});if(S)return t.jsx("div",{className:p,style:{...c,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:S});if(!v)return null;if(v.type==="entity")return t.jsx("div",{className:p,style:c,children:t.jsx(Ir,{data:v,transport:i,onNavigate:r,renderLink:s,headerExtra:l})});const _=v.type==="book"?v:null,w=v.type==="collection"?v:null,z=v.type==="work"?v:null;let N=!1;try{N=we.extractStatus(v.id)==="draft"}catch{}let T="";v.measure_info?T=u(v.measure_info):(P=v.juan_count)!=null&&P.number?T=Er(v.juan_count.number)+d.unit.juan:(B=v.juan_count)!=null&&B.description&&(T=u(v.juan_count.description));const C=[];return(A=v.publication_info)!=null&&A.year&&C.push(t.jsx(tt,{label:d.label.year,children:v.publication_info.year},"year")),(W=v.current_location)!=null&&W.name&&C.push(t.jsx(tt,{label:d.label.currentLocation,children:u(v.current_location.name)},"loc")),(V=v.page_count)!=null&&V.description&&C.push(t.jsx(tt,{label:d.label.pageCount,children:v.page_count.description},"page")),_!=null&&_.edition&&C.push(t.jsx(tt,{label:d.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&C.push(t.jsx(tt,{label:d.label.parentWork,children:t.jsx(Ke,{id:z.parent_work.id,label:u(z.parent_work.title),onNavigate:r,renderLink:s})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&C.push(t.jsx(tt,{label:d.label.parentWork,children:z.parent_works.map((G,ae)=>t.jsxs("span",{children:[ae>0&&"、",t.jsx(Ke,{id:G,onNavigate:r,renderLink:s})]},G))},"pws")),t.jsxs("div",{className:p,style:c,children:[t.jsx(Ta,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:N,authors:v.authors,volumeText:T,meta:C,headerExtra:l,onNavigate:r,renderLink:s}),((K=v.description)==null?void 0:K.text)&&t.jsx(lt,{text:v.description.text,style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((G,ae)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:o("bg-subtle"),borderRadius:4,border:`1px solid ${o("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:o("muted")},children:u(G.title)}),t.jsx(lt,{text:G.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:o("fg")}})]},ae))}),k.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:d.section.containedIn}),t.jsx(Pa,{items:k,onNavigate:r,renderLink:s})]}),y&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:d.section.belongsToWork}),t.jsx(Fa,{workData:y,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&t.jsx(La,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&t.jsx(Ra,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&t.jsx(Na,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&t.jsx(Ea,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&t.jsx(Br,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:d.section.resources}),t.jsx(xi,{items:v.resources,resourceGroups:v.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&t.jsx(Ba,{items:_.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&t.jsx(Aa,{items:w.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&t.jsx(bo,{title:d.section.relatedVersions,ids:_.related_books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.books)&&w.books.length>0&&t.jsx(bo,{title:d.section.containedBooks,ids:w.books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.contained_works)&&w.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(Ve,{children:[d.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",w.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.contained_works.map(G=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:t.jsx(Ke,{id:G.id,label:u(G.title),onNavigate:r,renderLink:s})},G.id))})]}),(((E=z==null?void 0:z.books)==null?void 0:E.length)||0)+(((le=z==null?void 0:z.collections)==null?void 0:le.length)||0)>0&&t.jsx(Wa,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z??void 0,transport:i,onNavigate:r,renderLink:s,footer:a}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const G=[],ae=z.related_works.filter(te=>te.relation==="part_of"),pe=z.related_works.filter(te=>te.relation==="has_part"),ee=z.related_works.filter(te=>te.relation==="has_adaptation"),X=z.related_works.filter(te=>te.relation==="text_carried_by"),ie=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),me=z.related_works.filter(te=>!te.relation||!ie.has(te.relation));return ae.length>0&&G.push({label:d.section.belongsToWork,items:ae}),pe.length>0&&G.push({label:d.section.containedWorks,items:pe}),ee.length>0&&G.push({label:d.section.adaptations,items:ee}),X.length>0&&G.push({label:d.section.derivativeWorks,items:X}),me.length>0&&G.push({label:d.section.relatedWorks,items:me}),G.map(te=>t.jsxs("div",{children:[t.jsxs(Ve,{children:[te.label,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",te.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:te.items.map(se=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:t.jsx(Ke,{id:se.id,label:u(se.title),onNavigate:r,renderLink:s})},se.id))})]},te.label))})()]})};function Oa({data:e}){const n=ue(),{convert:i}=q(),{stats:r}=e,s=r.processed_volumes??r.total_found_volumes,l=s!=null&&e.total_volumes>0?Math.round(s/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:i(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"6px"},children:i(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:o("desc-fg")},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:o("fg")},children:e.total_volumes})," ",n.unit.volume]}),l!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:o("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:o("fg")},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&t.jsxs("span",{children:[n.catalog.matched," ",t.jsx("strong",{style:{color:o("fg")},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&t.jsxs("span",{children:[n.catalog.unmatched," ",t.jsx("strong",{style:{color:o("missing-fg")},children:r.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:o("desc-fg")},children:[n.catalog.source," ",e.source]})]})}function Da({sections:e,activeSection:n,onSelect:i}){const r=ue();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:yo(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:yo(n===s.name),children:[s.name,s.volume_range&&t.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function yo(e){return{padding:"4px 12px",border:e?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${o("primary")} 8%, transparent)`:"transparent",color:o(e?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Ha({id:e,label:n,onNavigate:i,renderLink:r}){const s=Pe();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i(e))},style:{color:o("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:n||e})}function Ga(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=e[0],r=e[e.length-1];return r-i+1===e.length?`${i}–${r}`:e.length<=3?e.join(", "):`${i}–${r} (${e.length}${n})`}function jo({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const s=ue(),{convert:l}=q(),a=e.book_id||e.work_id,p=r&&e.volumes.length>0?Ga(e.volumes,s.unit.volume):null,c=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${o("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:o("desc-fg"),textAlign:"right"},children:p}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:o("fg")},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(d=>l(d)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:o(c?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),a&&t.jsx(Ha,{id:a,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!a&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const gi=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:l,style:a})=>{const p=ue(),[c,d]=f.useState(null),[u,g]=f.useState(!1),[x,m]=f.useState(null),[b,S]=f.useState(null),[h,y]=f.useState(""),j=e||c;f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let w=!1;return g(!0),m(null),i.getCollectionCatalog(n).then(z=>{w||(z?d(z):m(p.catalog.notFound))}).catch(z=>{w||m(z instanceof Error?z.message:p.catalog.loadFailed)}).finally(()=>{w||g(!1)}),()=>{w=!0}},[e,n,i,p]);const k=(j==null?void 0:j.sections)&&j.sections.length>0,$=f.useMemo(()=>{if(!j)return!1;if(j.volume_index&&Object.keys(j.volume_index).length>0)return!0;const w=j.books.map(N=>N.volumes[0]).filter(N=>N!=null);return new Set(w).size<w.length},[j]),v=f.useMemo(()=>{if(!j)return[];let w=j.books;if(b&&(w=w.filter(z=>z.section===b)),h.trim()){const z=h.trim().toLowerCase();w=w.filter(N=>N.title.toLowerCase().includes(z)||N.sub_items&&N.sub_items.some(T=>T.toLowerCase().includes(z))||N.edition&&N.edition.toLowerCase().includes(z))}return w},[j,b,h]),_=f.useMemo(()=>{if(!$)return null;const w=[],z=new Map;for(const T of v){if(!T.volumes||T.volumes.length===0)continue;const C=T.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(T)}const N=[...z.keys()].sort((T,C)=>T-C);for(const T of N)w.push({volume:T,books:z.get(T)});return w},[v,$]);return u?t.jsx("div",{className:l,style:{...a,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):x?t.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:x}):j?t.jsxs("div",{className:l,style:a,children:[t.jsx(Oa,{data:j}),k&&t.jsx(Da,{sections:j.sections,activeSection:b,onSelect:S}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:h,onChange:w=>y(w.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:o("desc-fg")},children:[v.length," ",p.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[_?_.map((w,z)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:o("bg"),borderBottom:`1px solid ${o("widget-border")}`,fontSize:"12px",fontWeight:600,color:o("desc-fg"),position:"sticky",top:0,zIndex:1},children:Kt(p.catalog.volume,{n:w.volume})}),w.books.map((N,T)=>t.jsx(jo,{book:N,onNavigate:r,renderLink:s,showVolumes:N.volumes.length>1},`${w.volume}-${T}`))]},`${w.volume}-${z}`)):v.map((w,z)=>t.jsx(jo,{book:w,onNavigate:r,renderLink:s,showVolumes:!0},z)),v.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},jt=()=>{const[e,n]=f.useState(1);return f.useEffect(()=>{const i=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(i)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:o("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(e)})},Wr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Ua={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function We(e){return Ua[e]??e}const It=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],Tt={熹平: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},Mr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function vn(e){const n=e.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const i=parseInt(n[1],10);if(i<100||i>2100)return;const r=n[2]?parseInt(n[2],10):void 0;return{from:i,to:r!=null&&r>=i&&r<=2100?r:void 0}}function Va(e){return e>=1950?"":e>=1912?"民國":e>=1645?"清":e>=1368?"明":e>=1279?"元":e>=960?"宋":e>=907?"五代":e>=618?"唐":e>=581?"隋":e>=420?"南北朝":e>=265?"晉":e>=220?"三國":e>=-202?"漢":""}const Ya=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,vo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function mi(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(vo))if(n.startsWith(s))return vo[s];const i=We(n);if(gt[i]!=null)return i;const r=st(n);if(r&&n.length<=r.length+1)return We(r)}function ft(e,n){if(n){const i=Mr[`${n}|${e}`];if(i!=null)return i}return Tt[e]}const qa=1911;function Ka(e){const n=Tt[e];if(n==null)return;const i=nt[e];let r;for(const[s,l]of Object.entries(Tt))nt[s]===i&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const Ja={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function fn(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,i=0,r=!1;for(const l of e){const a=Ja[l];if(a===void 0)return;r=!0,l==="十"?i=(i||1)*10:l==="廿"||l==="卅"?(n+=a,i=0):i>=10?(n+=i+a,i=0):i=i*10+a}const s=n+i;return r&&s>0?s:void 0}function st(e){for(const n of Wr)if(e.startsWith(n))return n}const nt={};{const e=(n,i)=>{for(const r of i)nt[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function mt(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(Tt))if(e.includes(r)&&!(i&&nt[r]&&nt[r]!==i&&Mr[`${i}|${r}`]==null))return r}function Jt(e){var a,p,c;const n={era:"",reign:"",source:"none"},i=e.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const r=(a=e.lineage)==null?void 0:a.year_text;if(r){const d=st(r)??"";return{era:We(d),reign:mt(r,d)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const d=vn(s);if(d)return{era:Va(d.from),reign:"",source:"publication"};const u=st(s)??mi(s)??((c=It.find(m=>m.pattern.test(s)))==null?void 0:c.era)??"",g=mt(s,u)??"",x=u||(g?nt[g]??"":"");if(x||g)return{era:We(x),reign:g,source:"publication"}}const l=e.edition||e.title||"";if(l){const d=st(l);if(d)return{era:We(d),reign:mt(l,d)??"",source:"edition"};const u=It.find(g=>g.pattern.test(l));if(u)return{era:We(u.era),reign:mt(l,u.era)??u.reign??"",source:"edition"}}return n}function kn(e){var r,s,l,a,p,c,d,u,g;if(((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;if(typeof((s=e.lineage)==null?void 0:s.year)=="number")return e.lineage.year;const n=(l=e.publication_info)==null?void 0:l.year;if(n){const x=vn(n);if(x)return x.from}const i=[(a=e.lineage)==null?void 0:a.year_text,(p=e.publication_info)==null?void 0:p.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const x of i){const m=((c=e.publication_info)==null?void 0:c.year)||((d=e.lineage)==null?void 0:d.year_text);if(m&&x!==m&&(st(m)||mi(m)))break;const b=x.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??x.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const k=parseInt(b[1],10);if(k>=100&&k<=2100)return k}const S=x.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(S){const k=st(x);if(!k||We(k)==="民國"){const v=fn(S[1]);if(v!=null&&v>=1&&v<=120)return qa+v}}const h=st(x)??((u=It.find(k=>k.pattern.test(x)))==null?void 0:u.era),y=h?We(h):void 0,j=mt(x,y)??(st(x)||(g=It.find(k=>k.pattern.test(x)))==null?void 0:g.reign);if(j){const k=ft(j,y);if(k==null)continue;const $=x.indexOf(j),v=$>=0?x.slice($+j.length):"",_=v.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??v.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),w=_?fn(_[1]):void 0;return k+(w?w-1:0)}}}function hi(e){var a,p,c,d,u,g;const n=(a=e.dating)==null?void 0:a.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(p=e.lineage)==null?void 0:p.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const x=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(x){const m=Vn[We(x[1])],b=gt[We(x[2])];if(m!=null&&b!=null)return{from:Math.min(m,b)-20,to:Math.max(m,b)+40}}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const x=vn(s);if((x==null?void 0:x.to)!=null)return{from:x.from,to:x.to};const m=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(m){const b=Vn[We(m[1])],S=gt[We(m[2])];if(b!=null&&S!=null)return{from:Math.min(b,S)-20,to:Math.max(b,S)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const x of l){if(!/[間间]/.test(x))continue;const m=st(x)??mi(x)??((g=It.find(h=>h.pattern.test(x)))==null?void 0:g.era),b=m?We(m):void 0,S=[];for(const h of Object.keys(Tt))x.includes(h)&&(b&&nt[h]&&nt[h]!==b||ft(h,b)!=null&&S.push(h));if(S.length===0){const h=x.match(/([一-鿿])([一-鿿])[間间]/);if(h&&b){for(const y of[h[1],h[2]])for(const j of Object.keys(Tt))if(nt[j]===b&&!(j[0]!==y&&j[j.length-1]!==y)&&ft(j,b)!=null){S.push(j);break}}}if(S.length>0){const h=S.map($=>ft($,b)).filter($=>$!=null),y=Math.min(...h),j=S.reduce(($,v)=>ft($,b)>=ft(v,b)?$:v),k=Ka(j)??Ln(b??"")??Math.max(...h);return{from:y,to:k>y?k:Ln(b??nt[j]??"")??y}}if(b&>[b]!=null)return{from:gt[b],to:Ln(b)??gt[b]}}}const gt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Za=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Xa=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,ko=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function So(e,n){for(const i of Wr){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!mt(e.slice(r),We(i)))continue}const s=We(i);if(s===n)continue;const l=e.slice(r),a=mt(l,s)??"";let p;if(a){const c=ft(a,s);if(c!=null){const u=l.slice(l.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),g=u?fn(u[1]):void 0;p=c+(g?g-1:0)}}return{era:s,reign:a,year:p}}for(const i of It)if(i.pattern.test(e))return{era:We(i.era),reign:i.reign??""}}function Qa(e){var y,j,k,$,v;const n=Jt(e),i=((y=e.publication_info)==null?void 0:y.year)??"",r=i?vn(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),a=((j=e.lineage)==null?void 0:j.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(a),c=n.source==="publication"&&Ya.test(i),d=n.source==="publication"&&/[間间]/.test(i),u=a.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let g;l||p||c||d?g=void 0:u?g=parseInt(u[2],10):g=kn(e);const x=g==null?hi(e):void 0;let m;n.source==="publication"&&(c||ko.test(i))?m="uncertain":n.source==="lineage"||n.source==="publication"?m="attested":ko.test(s)||!n.reign&&g==null?m="uncertain":m="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((k=e.lineage)==null?void 0:k.year_text)??(($=e.lineage)==null?void 0:$.year)??""}」`:`出版著錄「${((v=e.publication_info)==null?void 0:v.year)??""}」`,S={era:n.era,reign:n.reign,year:g,yearRange:x,certainty:m,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const _=a.match(/[、,,]\s*([宋元明清])/);_&&_[1]!==S.era&&(S.laterRepair={era:_[1]})}if(!S.laterRepair&&Xa.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(S.laterRepair={era:_[1]})}const h=Za.find(_=>_.re.test(s));if(h){const _=s.search(h.re),w=s.slice(_),z=So(w,n.era)??So(s,n.era);z&&(S.basedOn={era:z.era,reign:z.reign,year:z.year,relation:h.relation})}return S}const Vn={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Ln(e){return Vn[e]}function gn(e){const n=kn(e);if(n!=null)return n;const i=hi(e);if(i)return i.from;const r=Jt(e).era;return r?gt[r]:void 0}const wo=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Yn(e){const n=wo.indexOf(e);return n===-1?wo.length:n}function ec(e){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of e){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 i=[],r=(s,l)=>{n[s].length&&i.push({key:s,labelKey:l,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),i}function bi(e,n){const i=di(e||[]),r=new Map,s=[];for(const d of i)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((u,g)=>{const x=m=>m.group_role==="origin"?0:m.group_role==="mirror"?1:2;return x(u)-x(g)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=yt(d),g=u.includes("text"),x=u.includes("image");g&&x?l.textImage.push(d):g?l.text.push(d):x?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=[...r.entries()].map(([d,u])=>{var g,x;return{key:d,label:((g=n==null?void 0:n[d])==null?void 0:g.label)||d,description:(x=n==null?void 0:n[d])==null?void 0:x.description,items:u}});return{buckets:p,mirrors:c,total:i.length}}function Sn(e){const n=[],i=e.metadata||{};i.edition&&n.push(String(i.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const r=bn(e);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),i.version&&n.push(String(i.version)),n.join(" · ")}function Fr(e,n){if(Sn(e)||n.filter(r=>r.name===e.name).length<2)return"";try{const r=new URL(e.url),s=r.searchParams.get("res")||r.searchParams.get("id");if(s)return s;const l=r.pathname.split("/").filter(Boolean).pop();if(l)return decodeURIComponent(l)}catch{}return""}function Pr(e,n){var l,a;const i=e.resources||[],r=[],s=[];for(const p of i){const c=yt(p);c.includes("image")&&r.push(p),c.includes("physical")&&s.push(p)}return{id:e.id,name:e.edition||e.title||e.id,era:Jt(e),year:kn(e),sortYear:gn(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:tc(e.id,n),group:(a=n==null?void 0:n.node_groups)==null?void 0:a[e.id],hasImage:r.length>0}}function tc(e,n){var p,c;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(p=n.collections)==null?void 0:p[i];if(((r==null?void 0:r.book_ids)??(i==="core"?n.core_books??[]:[])).includes(e))return!0;const l=(r==null?void 0:r.groups)??[],a=(c=n.node_groups)==null?void 0:c[e];return!!a&&l.includes(a)}function Or(e,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!r.has(c.id)).map(c=>Pr(c,n));let l=s;i.era&&(l=l.filter(c=>c.era.era===i.era)),i.scanOnly&&(l=l.filter(c=>c.hasImage)),i.sort==="year"?l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=c.r.sortYear,g=d.r.sortYear;return u!=null&&g!=null?u-g||c.i-d.i:u!=null?-1:g!=null?1:c.i-d.i}).map(c=>c.r):l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=g=>(g.important?0:1)*2+(g.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)=>Yn(c)-Yn(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(c=>c.era.source==="edition")}}function nc(e,n){var h,y;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.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:e,groupedIds:[]};const p=new Set(r),c=new Set([...s,...a]),d=j=>{if(c.has(j))return!0;const k=n.node_groups[j];return k!=null&&p.has(k)},u=[],g=new Map,x=[];for(const j of e)if(!((y=n.excluded_books)!=null&&y.includes(j)))if(d(j))u.push(j);else{const k=n.node_groups[j];k?(g.has(k)||g.set(k,[]),g.get(k).push(j)):x.push(j)}if(x.length+[...g.values()].reduce((j,k)=>j+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(j=>[j.id,j])),S=[...g.entries()].map(([j,k])=>{const $=b.get(j);return{id:j,label:($==null?void 0:$.label)??j,description:$==null?void 0:$.description,ids:k}});return x.length>0&&S.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:S}}const Dr=["撰","編","注","校","譯","繪","其他"],ic=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function yi(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of ic)if(r.test(n))return i;return"其他"}function ji(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Hr(e){const n=new Map;for(const r of e){const s=yi(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:e.length}];for(const r of Dr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function Gr(e,n,i){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 e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(l=>({id:l.id,title:l.title,volumes:Ut(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,a;return{id:s,title:((l=i==null?void 0:i.get(s))==null?void 0:l.title)||s,edition:(a=i==null?void 0:i.get(s))==null?void 0:a.edition,volumes:[]}}),source:"books",sections:[]}}function Ut(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(n=>typeof n=="number");if(typeof e=="string"){const n=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[i,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-i+1)},(s,l)=>i+l)}return e.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function wn(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((l,a)=>l-a),r=i[0],s=i[i.length-1];return s-r+1===i.length?`${r}–${s}`:i.length<=3?i.join(", "):`${r}–${s} (${i.length}${n})`}const oc=["〇","一","二","三","四","五","六","七","八","九"],_o=["","十","百","千"];function Ur(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const a=parseInt(n[l]),p=i-1-l;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&p===1&&l===0?r+=_o[p]:r+=oc[a]+_o[p])}return r}function rc(e){return e==null?"":typeof e=="string"?e:e.title??""}function at(e,n="卷"){var r,s;const i=e;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?Ur(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Vr(e){var r;if(e.edition_type)return e.edition_type;if((r=e.lineage)!=null&&r.category)return e.lineage.category;const n=e.edition||e.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,l]of i)if(s.test(n))return l;return""}const sc="guji_markdown";function qn(e){const n=e==null?void 0:e.guji_markdown;if(typeof n!="string")return!1;const i=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!i)return!1;const r=parseInt(i[1],10),s=parseInt(i[2],10);return r>0||s>=2}const lc=/^□\{guess=([^\s{}]+)\}/;function ac(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function Yr(e,n){let i=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
|
|
12
12
|
`)return-1;if(s==="\\"){r++;continue}if(s==="[")i++;else if(s==="]"&&(i--,i===0))return r}return-1}function cc(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function dc(e,n){const i=e[n];if(i==="["&&e[n+1]==="["){const r=e.indexOf("]]",n+2);return r>=0&&e.slice(n+2,r).indexOf(`
|
|
13
|
-
`)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const r=Yr(e,n+3);return r>n+4?{node:{type:"zi",label:cc(e.slice(n+4,r))},end:r+1}:null}if(i==="□"&&e[n+1]==="{"){const r=lc.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function
|
|
14
|
-
`)return null}const c=dc(e,n);if(c){a(),s.push(c.node),n=c.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&ac(e,n)&&(d=">"),d){const u=
|
|
13
|
+
`)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const r=Yr(e,n+3);return r>n+4?{node:{type:"zi",label:cc(e.slice(n+4,r))},end:r+1}:null}if(i==="□"&&e[n+1]==="{"){const r=lc.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function qr(e,n,i,r){const s=[];let l="";const a=()=>{if(!l)return;const p=r?l.replace(/\\?\|/g,""):l;p&&s.push({type:"text",text:p}),l=""};for(;n<e.length;){const p=e[n];if(i!==null){if(p===i)return a(),{nodes:s,end:n};if(p===`
|
|
14
|
+
`)return null}const c=dc(e,n);if(c){a(),s.push(c.node),n=c.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&ac(e,n)&&(d=">"),d){const u=qr(e,n+1,d,!0);if(u){a(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return i!==null?null:(a(),{nodes:s,end:n})}function Kr(e){return qr(e,0,null,!1).nodes}function pc(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function Jr(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Jr(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const uc=216,$o="clamp(280px, 23vw, 360px)",xc=1440,Zr="(max-width: 719px)",fc=`${Zr}, (pointer: coarse)`,gc=`
|
|
15
15
|
.bim-d-main.bim-d-main-grid { max-width: ${xc}px; padding: 16px 32px 0; }
|
|
16
16
|
.bim-d-grid {
|
|
17
17
|
display: grid;
|
|
@@ -58,6 +58,12 @@
|
|
|
58
58
|
}
|
|
59
59
|
.bim-d-tab:hover { color: ${o("ink")}; }
|
|
60
60
|
.bim-d-tab[aria-pressed="true"] { color: ${o("accent")}; font-weight: 700; box-shadow: inset 0 -2px 0 ${o("accent")}; }
|
|
61
|
+
.bim-d-groupbtn {
|
|
62
|
+
background: none; border: 1px dashed ${o("rule-strong")}; border-radius: 3px; padding: 2px 8px; cursor: pointer;
|
|
63
|
+
font: inherit; color: ${o("quiet-fg")};
|
|
64
|
+
}
|
|
65
|
+
.bim-d-groupbtn:hover:not(:disabled) { color: ${o("accent")}; border-color: ${o("accent")}; }
|
|
66
|
+
.bim-d-groupbtn:disabled { cursor: progress; }
|
|
61
67
|
.bim-d-filters .bim-d-spacer { flex: 1; }
|
|
62
68
|
.bim-d-check { display: inline-flex; align-items: center; gap: 6px; color: ${o("quiet-fg")}; cursor: pointer; }
|
|
63
69
|
.bim-d-check input { accent-color: ${o("accent")}; margin: 0; width: 15px; height: 15px; }
|
|
@@ -427,7 +433,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
|
|
|
427
433
|
.bim-d-pick-n { margin: 0; grid-column: 2; grid-row: 1 / span 2; }
|
|
428
434
|
.bim-d-find { flex-basis: 100%; min-height: 40px; }
|
|
429
435
|
}
|
|
430
|
-
`;function
|
|
436
|
+
`;function Zt({railTop:e,back:n,up:i,nav:r,railLinks:s,main:l,card:a,side:p}){const{convert:c}=q(),d=(r||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,n&&t.jsx("div",{style:{marginTop:e?12:0},children:n}),i,d.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":c("本頁導航"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:c("本頁")}),t.jsx("ul",{className:"bim-d-rail-nav",children:d.map(u=>t.jsx("li",{children:t.jsxs("a",{href:`#${u.id}`,children:[t.jsx("span",{children:c(u.label)}),u.count!=null&&t.jsx("span",{className:"bim-d-meta",children:u.count})]})},u.id))})]}),s&&s.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("更多"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:c("更多")}),t.jsx("ul",{className:"bim-d-rail-nav",children:s.map(u=>t.jsx("li",{children:t.jsxs("a",{href:u.href??"#",onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),u.onClick())},children:[t.jsx("span",{children:c(u.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},u.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:l}),t.jsx("div",{className:"bim-d-g-card",children:a}),t.jsx("div",{className:"bim-d-g-side",children:p})]})}function Xr({caption:e,children:n}){const{convert:i}=q();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:i(e)}),n]})}function Fe({id:e,title:n,meta:i,action:r,children:s}){const{convert:l}=q();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:l(n)}),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i}),r&&t.jsx("span",{className:"bim-d-sec-act",children:r})]}),s]})}function Me({items:e,className:n,style:i}){const r=e.filter(s=>s!=null&&s!==""&&s!==!1);return r.length?t.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:i,children:r.map((s,l)=>t.jsxs(f.Fragment,{children:[l>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},l))}):null}function _n({items:e,value:n,onChange:i}){const{convert:r}=q();return t.jsx(t.Fragment,{children:e.map(s=>t.jsx("button",{type:"button",className:[...r(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>i(s.key),children:r(s.label)},s.key))})}function Qr({label:e,checked:n,onChange:i}){const{convert:r}=q();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:s=>i(s.target.checked)}),r(e)]})}function Bt({label:e,onClick:n}){const{convert:i}=q();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:i(e)})}function Xt({kind:e,title:n,subtitle:i,byline:r,meta:s,description:l,clampDescription:a,facts:p,stats:c,readAction:d,secondaryAction:u,children:g,foot:x}){const{convert:m}=q(),b=(p||[]).filter(k=>k.value!=null&&k.value!==""),S=(c||[]).filter(k=>k.value!=null&&k.value!==""&&k.value!==0),[h,y]=f.useState(!1),j=!!a&&!h;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:m(e)}),t.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),i&&t.jsx("div",{className:"bim-d-card-sub",children:i}),r&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:r}),s&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),l&&t.jsx("div",{className:j?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:j?{"--detail-clamp":a}:void 0,children:l}),l&&!!a&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":h,onClick:()=>y(k=>!k),children:m(h?"收起":"展開")}),S.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:S.map((k,$)=>t.jsxs("div",{children:[t.jsx("b",{children:k.value}),t.jsx("span",{children:m(k.label)})]},$))}),b.length>0&&t.jsx("dl",{className:"bim-d-ui",children:b.map((k,$)=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:m(k.label)}),t.jsx("dd",{title:k.title,children:k.value})]},$))}),g,d,u,x&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:x})]})}function vi(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function Kn({href:e,onClick:n,label:i="閱讀全文"}){const{convert:r}=q();return e?t.jsx("a",{className:"bim-d-btn",href:e,onClick:n?s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),n())}:void 0,children:r(i)}):t.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:r(i)})}function ht({id:e,title:n,meta:i,items:r,metas:s,currentIndex:l,cap:a=8,moreLabel:p,foot:c,sub:d,timeline:u}){const{convert:g}=q(),[x,m]=f.useState(!1);if(!r.length)return null;const b=x?r:r.slice(0,a),S=r.length-b.length;return t.jsxs("div",{id:e,className:u?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[g(n),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i})]}),d&&t.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:d}),t.jsx("ul",{children:b.map((h,y)=>t.jsxs("li",{className:y===l?"bim-d-side-cur":void 0,"aria-current":y===l?"page":void 0,children:[h,s!=null&&s[y]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[y]}):null]},y))}),S>0&&t.jsx(Bt,{label:p?p(S):`顯示更多(${S})`,onClick:()=>m(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const mc={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function Qt({revision:e,revisedAt:n,review:i,todo:r}){const{convert:s}=q(),l=i?mc[i.status]:void 0,a=i&&i.status!=="unreviewed"&&l?[l,i.by,i.date].filter(Boolean).join(" "):"",p=[e!=null&&e!==""?`${s("數據版本")} ${e}`:"",n??"",s(a)].filter(Boolean),c=(r||[]).filter(d=>d&&d.what);return!p.length&&!c.length?null:t.jsxs(t.Fragment,{children:[p.length>0&&t.jsx(Me,{items:p,style:{fontSize:12}}),c.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s(`待核 ${c.length} 項`)}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:c.map((d,u)=>t.jsxs("li",{children:[s(d.what),(d.by||d.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[d.by&&s(d.by),d.date].filter(Boolean).join(" · "),")"]})]},u))})]})]})}const pn=1e3,zo=208,hc=1440,bc="(max-width: 719px)",es=`
|
|
431
437
|
.bim-d-page {
|
|
432
438
|
background: ${o("page-bg")};
|
|
433
439
|
color: ${o("ink")};
|
|
@@ -436,7 +442,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
|
|
|
436
442
|
padding-bottom: 64px;
|
|
437
443
|
}
|
|
438
444
|
.bim-d-main {
|
|
439
|
-
max-width: ${
|
|
445
|
+
max-width: ${pn}px;
|
|
440
446
|
margin: 0 auto;
|
|
441
447
|
padding: 24px clamp(16px, 4vw, 28px) 0;
|
|
442
448
|
}
|
|
@@ -479,9 +485,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
|
|
|
479
485
|
*/
|
|
480
486
|
.bim-d-reader {
|
|
481
487
|
display: grid;
|
|
482
|
-
grid-template-columns: ${zo}px minmax(0, ${
|
|
488
|
+
grid-template-columns: ${zo}px minmax(0, ${pn}px);
|
|
483
489
|
gap: 32px;
|
|
484
|
-
max-width: ${zo+
|
|
490
|
+
max-width: ${zo+pn+32}px;
|
|
485
491
|
margin: 0 auto;
|
|
486
492
|
align-items: start;
|
|
487
493
|
}
|
|
@@ -522,8 +528,8 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
|
|
|
522
528
|
padding-right: 0; padding-bottom: 12px;
|
|
523
529
|
}
|
|
524
530
|
}
|
|
525
|
-
${gc}`;function
|
|
526
|
-
`)||(n.push({start:i,end:l+1,inner:a}),i=l)}return n}function rs(e,n){if(e.length<=n)return e;let i=n;for(const r of os(e)){if(r.start>=i)break;if(r.end>i){i=r.start>0?r.start:r.end;break}}return e.slice(0,i)}const ss={fontSize:".78em",color:o("meta-fg"),lineHeight:1.55},Rc={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 ls(e,n,i){return e.map((r,s)=>{switch(r.type){case"text":return t.jsx(f.Fragment,{children:n(r.text)},s);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:i===0?ss:void 0,children:ls(r.children,n,i+1)},s);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:r.label?`闕文:${r.label}`:"闕文",children:"□"},s);case"qz":return t.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":r.guess,children:"□"},s);case"zi":return t.jsx("span",{className:"bim-zi guji-zi",title:`組字:${r.label}`,style:Rc,children:r.label},s)}})}function Ue(e,n=r=>r,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return pc(e)?ls(
|
|
531
|
+
${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:es}),t.jsx("div",{className:r?"bim-d-main bim-d-main-grid":i?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function Jn({breadcrumb:e,actions:n}){return t.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:o("aux-fg")},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:e}),n&&t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function ki({char:e,tone:n="accent"}){return t.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:o(n==="accent"?"accent":"ink"),color:o("page-bg")},children:e})}function Zn({items:e}){const n=Pe();return t.jsx(t.Fragment,{children:e.map((i,r)=>{const s=r===e.length-1,l=r>0&&t.jsx("span",{style:{color:o("hint-fg")},children:"/"},`s${r}`),a=i.id?n(i.id):i.href,p=s||!i.onClick&&!a?t.jsx("span",{style:{color:o("ink")},children:i.label},r):t.jsx("a",{href:a??"#",onClick:i.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i.onClick())}:void 0,style:{color:o("meta-fg")},children:i.label},r);return t.jsxs(f.Fragment,{children:[l,p]},r)})})}function ts({title:e,subtitle:n,aside:i,secondLine:r}){return t.jsxs("header",{style:{borderBottom:`2px solid ${o("rule-strong")}`,paddingBottom:18},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[t.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:e}),n&&t.jsx("span",{style:{fontSize:15,color:o("meta-fg"),letterSpacing:".06em"},children:n})]}),i&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg"),letterSpacing:".06em"},children:i})]}),r&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:o("quiet-fg")},children:r})]})}function yc({children:e,facts:n}){return!e&&n?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${o("rule")}`,marginBottom:40},children:n}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),n]})}function jc({items:e,horizontal:n}){const{convert:i}=q();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${o("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:e.map((r,s)=>t.jsxs("div",{title:r.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[t.jsx("span",{className:"bim-d-ui",style:{color:o("label-fg"),letterSpacing:".08em",flex:"none"},children:i(r.label)}),t.jsx("span",{style:{color:o("body-fg"),textAlign:n?"left":"right",minWidth:0},children:r.value})]},s))}):null}function vc({glyph:e,tone:n,title:i,count:r,actions:s,id:l}){const{convert:a}=q();return t.jsxs("div",{id:l,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(ki,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:a(i)}),r!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg")},children:r})]}),s&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function ns({label:e,active:n,onClick:i,dashed:r}){const{convert:s}=q();return t.jsx("button",{type:"button",onClick:i,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!n?"dashed":"solid"} ${o(n?"accent":"rule")}`,background:n?o("accent"):"transparent",color:o(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(e)})}function kc({label:e,onClick:n}){const{convert:i}=q();return t.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:o("meta-fg"),borderBottom:`1px solid ${o("rule")}`},children:i(e)})}function Sc({label:e,onClick:n,inline:i}){const{convert:r}=q();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:i?0:12,width:i?void 0:"100%",padding:i?"4px 12px":9,background:"none",border:`1px dashed ${o("rule-dashed")}`,cursor:"pointer",fontSize:12,color:o("meta-fg"),letterSpacing:i?void 0:".08em"},children:r(e)})}function is({children:e,href:n,onClick:i,title:r}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${o("rule")}`,fontSize:13,color:o("body-fg"),lineHeight:1.5};return n||i?t.jsx("a",{href:n??"#",title:r,onClick:i?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i())}:void 0,style:s,children:e}):t.jsx("span",{title:r,style:s,children:e})}function wc({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function _c({volumes:e,unit:n="冊",max:i=60}){const[r,s]=f.useState(!1);if(!e.length)return null;const l=r?e:e.slice(0,i);return t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[l.map(a=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${o("rule")}`,color:o("meta-fg")},children:a},a)),!r&&e.length>i&&t.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${o("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:o("meta-fg")},children:["+",e.length-i]}),t.jsx("span",{style:{padding:"2px 6px",color:o("hint-fg")},children:n})]})}function $c({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${o("rule-strong")}`},children:e})}function zc({spec:e}){const{convert:n}=q();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${o("rule-strong")}`,fontSize:11,color:o("label-fg"),letterSpacing:".1em"},children:[t.jsx("span",{}),t.jsx("span",{children:n(e.mainLabel)}),t.jsx("span",{style:{display:"grid",gridTemplateColumns:e.columns.map(i=>i.width).join(" "),gap:12},children:e.columns.map(i=>t.jsx("span",{children:n(i.label)},i.label))})]})}function Cc({no:e,main:n,meta:i,spec:r}){return t.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${r.leadWidth}px 1fr ${r.metaWidth}px`,gap:12},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:o("hint-fg"),textAlign:"right"},children:e}),t.jsx("span",{style:{minWidth:0},children:n}),t.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:r.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:i})]})}function Ic(e){return String(e+1).padStart(2,"0")}function Tc(){return t.jsx("span",{style:{color:o("hint-fg")},children:"—"})}function Ec({open:e,onToggle:n,main:i,action:r,children:s}){return t.jsxs("div",{style:{borderBottom:`1px solid ${o("rule")}`},children:[t.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[t.jsx("button",{type:"button",onClick:n,"aria-expanded":e,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 ${o(e?"accent":"rule-dashed")}`,background:e?o("accent"):"transparent",color:o(e?"page-bg":"accent")},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:i}),r]}),e&&s&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${o("rule-accent-soft")}`,marginLeft:12},children:s})]})}function os(e){const n=[];for(let i=0;i<e.length;i++){const r=e[i];let s;if(r==="⟨")s="⟩";else if(r==="<"){const p=e[i+1];if(p===void 0||/[A-Za-z/!?>\s]/.test(p))continue;s=">"}else continue;const l=e.indexOf(s,i+1);if(l<0)continue;const a=e.slice(i+1,l);a.includes(`
|
|
532
|
+
`)||(n.push({start:i,end:l+1,inner:a}),i=l)}return n}function rs(e,n){if(e.length<=n)return e;let i=n;for(const r of os(e)){if(r.start>=i)break;if(r.end>i){i=r.start>0?r.start:r.end;break}}return e.slice(0,i)}const ss={fontSize:".78em",color:o("meta-fg"),lineHeight:1.55},Rc={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 ls(e,n,i){return e.map((r,s)=>{switch(r.type){case"text":return t.jsx(f.Fragment,{children:n(r.text)},s);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:i===0?ss:void 0,children:ls(r.children,n,i+1)},s);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:r.label?`闕文:${r.label}`:"闕文",children:"□"},s);case"qz":return t.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":r.guess,children:"□"},s);case"zi":return t.jsx("span",{className:"bim-zi guji-zi",title:`組字:${r.label}`,style:Rc,children:r.label},s)}})}function Ue(e,n=r=>r,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return pc(e)?ls(Kr(e),n,0):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let s=0,l=0;for(const a of os(e))a.start>s&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s,a.start))},l++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:ss,children:n(a.inner)},l++)),s=a.end;return s<e.length&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),r}function Nc({label:e,children:n}){return t.jsxs("div",{style:{marginBottom:10},children:[e&&t.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:o("label-fg"),marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:o("quiet-fg"),textAlign:"justify"},children:n})]})}function Lc({title:e,tag:n,children:i}){const{convert:r}=q();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${o("rule-strong")}`,marginBottom:2},children:[t.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:r(e)}),n&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:o("accent"),letterSpacing:".06em"},children:r(n)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function as({name:e,note:n,href:i,extra:r}){const s=t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{fontSize:14,minWidth:0},children:e}),t.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:o("hint-fg"),flex:"none"},children:i?"↗":""}),n&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:o("label-fg")},children:n})]}),l={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${o("rule")}`,color:o("body-fg"),alignItems:"baseline"};return t.jsxs(t.Fragment,{children:[i?t.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:l,children:s}):t.jsx("div",{style:l,children:s}),r]})}function Bc({item:e,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=q(),[l,a]=f.useState(!1),p=bn(e),c=i&&!!p&&p.expected>0,d=(e.url?Nt(e.url):void 0)||s(e.name),u=n?Fr(e,n):"",g=u?`${d}(${u})`:d;return t.jsx(as,{name:g,note:Sn(e)||r,href:Lt(e),extra:c?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>a(x=>!x),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:o("meta-fg"),borderBottom:`1px solid ${o("rule")}`},children:l?"收起分冊":`展開 ${p.expected} 冊`}),l&&t.jsx(Si,{item:e})]}):void 0})}function Si({item:e}){return t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(e.volumes||[]).map((n,i)=>{const r=n.status==="missing";return n.url&&!r?t.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{padding:"4px 8px",borderRadius:4,background:o("zebra-bg")},children:n.volume},i):t.jsx("span",{style:{padding:"1px 5px",color:o(r?"missing-fg":"hint-fg"),textDecoration:r?"line-through":void 0},children:n.volume},i)})})}function cs({label:e,items:n}){const{convert:i}=q();return n.length?t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg"),letterSpacing:".08em"},children:e}),n.map((r,s)=>t.jsx(is,{children:i(r)},s))]}):null}function Ac({rows:e}){const n=e.filter(i=>i.items.length>0);return n.length?t.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(i=>t.jsx(cs,{label:i.label,items:i.items},i.label))}):null}function Xn(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ds({left:e,right:n}){return t.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${o("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:o("aux-fg")},children:[t.jsx("span",{children:e}),n&&t.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function Wc({children:e,action:n}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:o("aux-fg"),borderBottom:`1px solid ${o("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),n]})}function Be({id:e,label:n,onNavigate:i,renderLink:r,style:s,dense:l}){const a=Pe();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:l})}):t.jsx("a",{href:a(e),onClick:i?p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(e))}:void 0,style:s,children:n??e})}function Mc({href:e,children:n}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[n," ",t.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const ps="(min-width: 1100px)",us="(max-width: 719px)",Fc=`${us}, (pointer: coarse)`,pt=o("reader-top"),Pc="48px",xs=`
|
|
527
533
|
.bim-rd {
|
|
528
534
|
position: relative;
|
|
529
535
|
background: ${o("page-bg")};
|
|
@@ -773,19 +779,19 @@ ${gc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
|
|
|
773
779
|
.bim-rd-h1 { font-size: 20px; letter-spacing: 0.06em; }
|
|
774
780
|
.bim-rd-prose { margin-top: 20px; }
|
|
775
781
|
}
|
|
776
|
-
`;function wi(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(r=>wi(r,n))):!1}const Oc=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Dc({item:e,activeKey:n,onSelect:i,tabKey:r}){const s=wi(e,n),[l,a]=f.useState(s||!!e.defaultExpanded);return f.useEffect(()=>{s&&a(!0)},[s]),f.useEffect(()=>{e.defaultExpanded&&a(!0)},[e.defaultExpanded]),t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>a(p=>!p),children:[t.jsx(Oc,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(fs,{items:e.children,activeKey:n,onSelect:i,tabKey:r})]})}function fs({items:e,activeKey:n,onSelect:i,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Dc,{item:s,activeKey:n,onSelect:i,tabKey:r},s.key):t.jsx("li",{children:t.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:r===s.key?0:-1,onClick:()=>i(s.key),children:[t.jsx("span",{children:s.label}),s.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:s.hint})]})},s.key))})}function Co(e,n){var i;for(const r of e)if(r.key===n||wi(r,n))return r.key;return((i=e[0])==null?void 0:i.key)??null}function gs({items:e,activeKey:n,onSelect:i,label:r="目录"}){const s=f.useRef(null),[l,a]=f.useState(null);f.useEffect(()=>{a(null)},[n]);const p=f.useMemo(()=>l||(n??Co(e,n)),[l,n,e]);f.useEffect(()=>{const d=s.current;if(!d)return;const u=Array.from(d.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const g=u.find(x=>x.dataset.rdTocKey===p)??u.find(x=>x.dataset.rdTocKey===Co(e,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===g?0:-1}),f.useEffect(()=>{const d=s.current,u=d==null?void 0:d.closest(".bim-rd-toc");if(!d||!u||!n)return;const g=Array.from(d.querySelectorAll("[data-rd-toc-key]")).find(m=>m.dataset.rdTocKey===n);if(!g)return;const x=g.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(x<u.scrollTop+80||x>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,x-u.clientHeight/3))},[n]);const c=f.useCallback(d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const g=s.current;if(!g)return;const x=Array.from(g.querySelectorAll("[data-rd-toc-key]")).filter(h=>!h.disabled),m=x.indexOf(document.activeElement);let b=m;if(d.key==="ArrowDown"?b=Math.min(x.length-1,m+1):d.key==="ArrowUp"?b=Math.max(0,m-1):d.key==="Home"?b=0:d.key==="End"&&(b=x.length-1),b<0||b===m)return;d.preventDefault();const
|
|
777
|
-
`),[te]),
|
|
782
|
+
`;function wi(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(r=>wi(r,n))):!1}const Oc=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Dc({item:e,activeKey:n,onSelect:i,tabKey:r}){const s=wi(e,n),[l,a]=f.useState(s||!!e.defaultExpanded);return f.useEffect(()=>{s&&a(!0)},[s]),f.useEffect(()=>{e.defaultExpanded&&a(!0)},[e.defaultExpanded]),t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>a(p=>!p),children:[t.jsx(Oc,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(fs,{items:e.children,activeKey:n,onSelect:i,tabKey:r})]})}function fs({items:e,activeKey:n,onSelect:i,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Dc,{item:s,activeKey:n,onSelect:i,tabKey:r},s.key):t.jsx("li",{children:t.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:r===s.key?0:-1,onClick:()=>i(s.key),children:[t.jsx("span",{children:s.label}),s.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:s.hint})]})},s.key))})}function Co(e,n){var i;for(const r of e)if(r.key===n||wi(r,n))return r.key;return((i=e[0])==null?void 0:i.key)??null}function gs({items:e,activeKey:n,onSelect:i,label:r="目录"}){const s=f.useRef(null),[l,a]=f.useState(null);f.useEffect(()=>{a(null)},[n]);const p=f.useMemo(()=>l||(n??Co(e,n)),[l,n,e]);f.useEffect(()=>{const d=s.current;if(!d)return;const u=Array.from(d.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const g=u.find(x=>x.dataset.rdTocKey===p)??u.find(x=>x.dataset.rdTocKey===Co(e,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===g?0:-1}),f.useEffect(()=>{const d=s.current,u=d==null?void 0:d.closest(".bim-rd-toc");if(!d||!u||!n)return;const g=Array.from(d.querySelectorAll("[data-rd-toc-key]")).find(m=>m.dataset.rdTocKey===n);if(!g)return;const x=g.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(x<u.scrollTop+80||x>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,x-u.clientHeight/3))},[n]);const c=f.useCallback(d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const g=s.current;if(!g)return;const x=Array.from(g.querySelectorAll("[data-rd-toc-key]")).filter(h=>!h.disabled),m=x.indexOf(document.activeElement);let b=m;if(d.key==="ArrowDown"?b=Math.min(x.length-1,m+1):d.key==="ArrowUp"?b=Math.max(0,m-1):d.key==="Home"?b=0:d.key==="End"&&(b=x.length-1),b<0||b===m)return;d.preventDefault();const S=x[b];for(const h of x)h.tabIndex=-1;S.tabIndex=0,S.focus(),a(S.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:c,children:t.jsx(fs,{items:e,activeKey:n,onSelect:i,tabKey:p})})}function Hc({page:e}){var n;return!((n=e.boxes)!=null&&n.length)||!e.width||!e.height||e.boxFormat&&e.boxFormat!=="bim-charbox-v0"?null:t.jsx("svg",{viewBox:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:e.boxes.map((i,r)=>t.jsx("rect",{x:i.x,y:i.y,width:i.w,height:i.h,fill:"none",stroke:o("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},r))})}function ms({pages:e,loading:n,page:i,onPageChange:r,renderOverlay:s}){const[l,a]=f.useState(0),p=i??l,c=x=>{r?r(x):a(x)};if(f.useEffect(()=>{i===void 0&&a(0)},[e,i]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:"加载书影…"})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:"暂无书影"}),t.jsx("span",{children:"这一卷还没有配上影像;接入后在此与正文逐页对看"})]})});const d=Math.max(0,Math.min(e.length-1,p)),u=e[d],g=u.label??`${d+1}`;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${g} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(Hc,{page:u}),s==null?void 0:s(u,d)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:d===0,onClick:()=>c(d-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${d+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:d===e.length-1,onClick:()=>c(d+1),children:"›"})]})]})}const _i={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal"},$t=[15,16,17,18,20,22,24],Qn=18,hs="bim-reader-prefs",Gc="bim-reading-mode";function Uc(){const e={..._i};try{const n=localStorage.getItem(hs),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&$t.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(Gc))==="paragraph"&&(e.readingMode="paragraph"),i.properNames===!0&&(e.properNames=!0),i.writingMode==="vertical"&&(e.writingMode="vertical")}catch{}return e}function Vc(e){try{localStorage.setItem(hs,JSON.stringify(e))}catch{}}function Io(e,n){const i=e??Qn,r=$t;let s=r.indexOf(i);return s<0&&(s=r.indexOf(Qn)),r[Math.max(0,Math.min(r.length-1,s+n))]}function $i(){const[e,n]=f.useState(_i);f.useEffect(()=>{n(Uc())},[]);const i=f.useCallback(r=>{n(s=>{const l={...s,...r};return Vc(l),l})},[]);return[e,i]}function bs(e){return e.map(n=>({key:n.key,label:n.version_label||n.key,sourceName:n.source_name,license:n.license,sourceUrl:n.source_url,primary:n.primary}))}function ei(e){const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function ys(e,n){if(!(!e||e.length===0))return(n!=null?e.find(i=>i.key===n):void 0)??e.find(i=>i.primary)??e[0]}function js(e){const n=[],i=r=>{for(const s of r)s.children&&s.children.length>0?i(s.children):n.push(s)};return i(e),n}const Yc=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),qc=()=>t.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:[t.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),t.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function Kc(e,n){if(!n)return;const i=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(a=>a.tabIndex>=0);if(i.length===0)return;const r=i[0],s=i[i.length-1],l=document.activeElement;e.shiftKey&&(l===r||!n.contains(l))?(e.preventDefault(),s.focus()):!e.shiftKey&&(l===s||!n.contains(l))&&(e.preventDefault(),r.focus())}function Jc(e,n){const[i,r]=f.useState(n);return f.useEffect(()=>{var a;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(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)}},[e]),i}function Zc(){const e=f.useContext(Rt);if(!e)return null;const n=e.locale==="zh-Hant";return t.jsxs("button",{type:"button",className:"bim-rd-t",title:n?"切换为简体":"切換為繁體","aria-label":n?"切换为简体":"切換為繁體",onClick:()=>e.setLocale(n?"zh-Hans":"zh-Hant"),children:[t.jsx("span",{className:n?"bim-rd-on":"bim-rd-off",children:"繁"}),t.jsx("span",{className:"bim-rd-off",children:"|"}),t.jsx("span",{className:n?"bim-rd-off":"bim-rd-on",children:"简"})]})}function zi({title:e,subtitle:n,toc:i,activeKey:r,onSelect:s,tocHeader:l,tocCaption:a,images:p,imagesLoading:c,renderImageOverlay:d,imagePanel:u="auto",prefs:g,onPrefsChange:x,paragraphToggle:m,properNameToggle:b=!0,allowVertical:S,pager:h=!0,versions:y,currentVersionKey:j,onVersionChange:k,versionSource:$=!0,children:v,className:_,style:w}){const z=f.useId().replace(/:/g,""),N=`bim-rd-toc-${z}`,T=`bim-rd-text-${z}`,C=f.useRef(null),P=f.useRef(null),B=f.useRef(null),A=f.useRef(null),W=Jc(ps,!0),[V,K]=f.useState("auto"),E=V==="auto"?W:V==="open",le=!W,G=!!p&&p.length>0,[ae,pe]=f.useState(u);f.useEffect(()=>{pe(u)},[u]);const ee=ae==="auto"?G||!!c:ae==="open",X=f.useCallback(Z=>{var F;K("auto"),Z&&((F=A.current)==null||F.focus())},[]),ie=()=>K(E?"closed":"open");f.useEffect(()=>{if(!le||V!=="open")return;const Z=B.current,F=Z==null?void 0:Z.querySelector('input, [data-rd-toc-key][tabindex="0"]');F==null||F.focus()},[le,V]);const me=f.useCallback(Z=>{s(Z),le&&X(!1);const F=P.current,I=C.current;if(F&&I&&typeof window<"u"){const D=F.getBoundingClientRect().top-I.getBoundingClientRect().bottom;D<0&&window.scrollBy({top:D})}},[s,le,X]),te=f.useMemo(()=>js(i),[i]),[se,fe]=f.useState(null),be=ys(y,j!==void 0?j:se),ze=(be==null?void 0:be.key)??null,ve=f.useMemo(()=>te.map(Z=>Z.key).join(`
|
|
783
|
+
`),[te]),ke=f.useRef(null),Ne=Z=>{Z!==ze&&(ke.current={key:Z,sig:ve,done:!1},j===void 0&&fe(Z),k==null||k(Z))};f.useEffect(()=>{const Z=ke.current;if(!Z||Z.key!==ze)return;const F=te.find(D=>!D.disabled);if(!F)return;const I=ve!==Z.sig;!I&&Z.done||(I?ke.current=null:Z.done=!0,F.key!==r&&me(F.key))},[ze,ve,te,r,me]);const Ee=te.findIndex(Z=>Z.key===r),O=Ee>0?te.slice(0,Ee).reverse().find(Z=>!Z.disabled):void 0,ce=Ee>=0?te.slice(Ee+1).find(Z=>!Z.disabled):void 0,oe=g.fontSize??Qn,he={...w,...g.fontSize?{"--bimrd-fs":`${g.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",g.writingMode==="vertical"&&S?"bim-rd-vertical":"",_].filter(Boolean).join(" "),"data-toc":V,"data-img":ee?"open":"closed",style:he,children:[t.jsx("style",{children:xs}),t.jsx("a",{className:"bim-rd-skip",href:`#${T}`,onClick:Z=>{var F,I,D;Z.preventDefault(),(F=P.current)==null||F.focus(),(D=(I=P.current)==null?void 0:I.scrollIntoView)==null||D.call(I,{block:"start"})},children:"跳到正文"}),t.jsxs("div",{className:"bim-rd-bar",ref:C,children:[(e||n)&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),n&&t.jsx("span",{children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":"阅读设置",children:[y&&y.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:be?ei(be):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:"版本"}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:"版本▾"}),t.jsx("select",{"aria-label":"版本",value:ze??"",onChange:Z=>Ne(Z.target.value),children:y.map(Z=>t.jsx("option",{value:Z.key,children:ei(Z)},Z.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),t.jsxs("button",{ref:A,type:"button",className:"bim-rd-t","aria-expanded":E,"aria-controls":N,onClick:ie,children:[t.jsx(Yc,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":ee,onClick:()=>pe(ee?"closed":"open"),children:[t.jsx(qc,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Zc,{}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"缩小字号",disabled:oe<=$t[0],onClick:()=>x({fontSize:Io(g.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"放大字号",disabled:oe>=$t[$t.length-1],onClick:()=>x({fontSize:Io(g.fontSize,1)}),children:"A+"}),(m||b||S)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),m&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":g.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>x({readingMode:g.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),b&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":g.properNames,title:"书名加波浪线",onClick:()=>x({properNames:!g.properNames}),children:"专名线"}),S&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":g.writingMode==="vertical",onClick:()=>x({writingMode:g.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:N,ref:B,role:le&&E?"dialog":void 0,"aria-modal":le&&E?!0:void 0,"aria-label":le&&E?"目录":void 0,onKeyDown:Z=>{if(!(!le||!E)){if(Z.key==="Escape"){Z.stopPropagation(),X(!0);return}Z.key==="Tab"&&Kc(Z,B.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:a??"目录"}),le&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>X(!0),children:"✕"})]}),l]}),t.jsx(gs,{items:i,activeKey:r,onSelect:me})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>X(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:ee&&t.jsx(ms,{pages:p??null,loading:c,renderOverlay:d})}),t.jsx("div",{className:"bim-rd-text",id:T,ref:P,tabIndex:-1,children:t.jsxs("div",{className:"bim-rd-col",children:[v,$&&be&&(be.sourceName||be.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":be.key,children:[be.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",be.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:be.sourceUrl,target:"_blank",rel:"noreferrer",children:be.sourceName}):be.sourceName]}),be.sourceName&&be.license&&t.jsx("span",{className:"bim-rd-dot"}),be.license&&t.jsxs(t.Fragment,{children:["授权 ",be.license]})]}),h&&(O||ce)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[t.jsx("span",{children:O&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>me(O.key),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-pglabel",children:O.label})]})}),t.jsx("span",{children:ce&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>me(ce.key),children:[t.jsx("span",{className:"bim-rd-pglabel",children:ce.label}),t.jsx("span",{"aria-hidden":"true",children:"›"})]})})]})]})})]})]})}const vs="guji-table-v1";function ks(e){return!!e&&e.table_notation===vs}const Xc=/^:::table(?:\{[^}]*\})?[ \t]*$/,Qc=/^:::[ \t]*$/;function Ss(e){const n=[];let i="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const a=Yr(e,r+3);if(a>r+4){i+=e.slice(r,a+1),r=a;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const a=e[r+1];a!==void 0&&!/[A-Za-z/!?>\s]/.test(a)&&(l=">")}if(l){const a=e.indexOf(l,r+1);if(a>0){i+=e.slice(r,a+1),r=a;continue}}s==="|"?(n.push(i),i=""):i+=s}return n.push(i),n.map(r=>r.trim())}const ed=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function td(e){if(e==="^")return{cont:!0};const n=ed.exec(e),i=n[1].trim(),r=n[2]?Math.max(1,parseInt(n[2],10)):1,s=n[3]?Math.max(1,parseInt(n[3],10)):1,l=i==="_";return{cont:!1,cell:{text:l?"":i,empty:l,colspan:r,rowspan:s}}}function ws(e,n=1){const i=[],r=[],s=[];let l=[];e.forEach((p,c)=>{const d=c+n+1;let u=p.trim();if(!u)return;let g=!1;u.startsWith("!")&&(g=!0,u=u.slice(1));const x=Ss(u).map(td),m=l.map(y=>y>0),b=l.map(y=>y>0?y-1:0),S=[];let h=0;for(const y of x){if(y.cont){m[h]||i.push(`第 ${d} 行第 ${h+1} 列:续格 ^ 上方没有跨行格`),h+=1;continue}const{cell:j}=y;for(let k=h;k<h+j.colspan;k++)if(m[k]){i.push(`第 ${d} 行第 ${k+1} 列:此处被上方跨行格占住,应写 ^`);break}if(j.rowspan>1)for(let k=h;k<h+j.colspan;k++)b[k]=j.rowspan-1;S.push(j),h+=j.colspan}for(let y=h;y<m.length;y++)m[y]&&i.push(`第 ${d} 行第 ${y+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let y=0;y<b.length;y++)b[y]===void 0&&(b[y]=0);l=b,r.push({header:g,cells:S}),s.push({width:h,line:d})});const a=s.reduce((p,c)=>Math.max(p,c.width),0);for(const p of s)p.width!==a&&i.push(`第 ${p.line} 行:占 ${p.width} 列,与总列数 ${a} 不符`);return l.some(p=>p>0)&&i.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&i.push("空表"),{rows:r,columns:a,warnings:i}}function Ci(e){const n=e.split(`
|
|
778
784
|
`),i=[];let r=[];const s=()=>{if(r.length===0)return;const a=r.join(`
|
|
779
785
|
`);r=[],i.push({type:"text",text:a})};let l=0;for(;l<n.length;){if(Xc.test(n[l].trim())){let a=l+1;for(;a<n.length&&!Qc.test(n[a].trim());)a++;if(a<n.length){s();const p=n.slice(l+1,a);i.push({type:"table",table:ws(p,l+1),source:n.slice(l,a+1).join(`
|
|
780
786
|
`)}),l=a+1;continue}}r.push(n[l]),l++}return s(),i.map((a,p)=>{var d,u;if(a.type!=="text")return a;let c=a.text;return((d=i[p-1])==null?void 0:d.type)==="table"&&(c=c.replace(/^\n+/,"")),((u=i[p+1])==null?void 0:u.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(a=>a.type!=="text"||a.text!=="")}const nd={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},id={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},od=`1px solid ${o("table-border")}`,_s={border:od,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},rd={..._s,background:o("table-head-bg"),fontWeight:600};function Ii({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:nd,children:t.jsx("table",{className:"bim-guji-table",style:id,children:t.jsx("tbody",{children:e.rows.map((i,r)=>t.jsx("tr",{children:i.cells.map((s,l)=>{const a=i.header?"th":"td";return t.jsx(a,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:i.header?rd:_s,children:s.empty?null:Ue(s.text,void 0,n)},l)})},r))})})})}function sd(e,n){return e.indexOf("**")<0?Ue(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:Ue(r.trim().slice(2,-2),void 0,n)},s):t.jsx(f.Fragment,{children:Ue(r,void 0,n)},s))}function ld(e,n,i=!1){const r=i?{gujiMarkdown:!0}:void 0;return n?Ci(e).map((s,l)=>s.type==="table"?t.jsx(Ii,{table:s.table,opts:r},l):t.jsx(f.Fragment,{children:sd(s.text,r)},l)):Ue(e,void 0,r)}const ad=/^(#{1,6})\s+(.*)$/,cd=/^\*\*([^*\n]+)\*\*\s*$/;function Ti(e){const n=e.match(ad);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(cd);return i?{level:3,text:i[1].trim()}:null}const Ei=/^<!--.*-->$/;function $s(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function zs(e){return e.split(`
|
|
781
787
|
`).map(n=>n.trim()).filter(n=>n&&!Ei.test(n))}const dd=60;function Cs(e){let n=0,i=0;for(const r of e.split(`
|
|
782
|
-
`)){const s=r.trim();if(!s||Ei.test(s)||Ti(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>dd&&(i+=l)}return n>0&&i*2>=n}function pd(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function
|
|
788
|
+
`)){const s=r.trim();if(!s||Ei.test(s)||Ti(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>dd&&(i+=l)}return n>0&&i*2>=n}function pd(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function $n(e){if(e=pd(e),Cs(e))return"unknown";const n=$s(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>zs(s).length).filter(s=>s>0);if(i.length===0)return"unknown";const r=i.reduce((s,l)=>s+l,0)/i.length;return r<=4?"record":r>=8?"catalog":"unknown"}function ud(e){const n=e.split(`
|
|
783
789
|
`),i=[];let r=null,s=[];const l=()=>{i.push({heading:r,body:s.join(`
|
|
784
790
|
`)}),s=[]};for(const a of n){const p=Ti(a);if(p){l(),r={kind:"heading",level:p.level,text:p.text};continue}s.push(a)}return l(),i}function To(e){const n=[];for(const i of e.split(`
|
|
785
|
-
`)){const r=Ti(i);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=i.trim();!s||Ei.test(s)||n.push({kind:"body",text:i})}return n}function Is(e){if(!e)return[];const n
|
|
786
|
-
`)?"":n)}function fd(e){return e<=1?2:e===2?3:4}function gd(){let e=1;return n=>{const i=fd(n),r=Math.min(i,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${i}`}}}function
|
|
787
|
-
`);let c=0;return t.jsx(t.Fragment,{children:p.map((d,u)=>{const g=d.match(Ln);if(g){const m=c++;if(l(g[1].length,g[2],m))return null;const{Tag:b,className:k}=a(g[1].length);return t.jsx(b,{className:k,children:i(g[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Ln.test(p[u-1])&&!Ln.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(xd.test(d))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:m,className:b}=a(3);return t.jsx(m,{className:b,children:i(d.trim().slice(2,-2))},u)}return t.jsx("p",{children:Eo(d,i,u)},u)})})}function md(e){const{convert:n}=V();return f.useMemo(()=>e?n(e):"",[e,n])}function Ni({text:e,mode:n,tables:i=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:a}){const p=md(e),{convert:c}=V(),d=x=>Ri(x,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,g=a?c(a):void 0;return!i||p.indexOf(":::")<0?t.jsx(Ro,{text:p,mode:n,inline:d,dropTitle:g}):t.jsx(t.Fragment,{children:Ci(p).map((x,m)=>x.type==="table"?t.jsx(Ii,{table:x.table,opts:u},m):t.jsx(Ro,{text:x.text,mode:n,inline:d,dropTitle:m===0?g:void 0},m))})}function Ns(e,n){const[i,r]=f.useState(null),[s,l]=f.useState(!1),a=f.useRef(0);return f.useEffect(()=>{const p=++a.current;if(!e||!n){r(null),l(!1);return}let c;try{c=e(n)}catch{r(null),l(!1);return}if(!c||typeof c.then!="function"){r(c??null),l(!1);return}l(!0),c.then(d=>{p===a.current&&r(d??null)}).catch(()=>{p===a.current&&r(null)}).finally(()=>{p===a.current&&l(!1)})},[e,n]),{images:i,loading:s}}const No={A:"fine",B:"rough",C:"rough",D:"ocr"};function hd(e){return typeof e!="string"?null:e in Hn?e:e in No?No[e]:null}const bd={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},yd={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function nt(e){return typeof e!="string"?"":bd[e]??yd[e]??e}const jd=["〇","一","二","三","四","五","六","七","八","九"],Lo=["","十","百","千"],vd=["","萬","億"];function Li(e){if(e===0)return"〇";if(e<0)return`負${Li(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(kd(s,r>0)+vd[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function kd(e,n){const i=[];let r=e;for(;r>0;)i.unshift(r%10),r=Math.floor(r/10);let s="";for(let l=0;l<i.length;l++){const a=i[l],p=i.length-1-l;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&p===1&&l===0&&!n?s+=Lo[p]:s+=jd[a]+Lo[p]}return s.replace(/〇$/,"")}let Ut=null,an=null;const gn=new Set;function Sd(){return Ut?Promise.resolve():an||(an=import("opencc-js/t2cn").then(e=>{Ut=e.Converter({from:"tw",to:"cn"}),gn.forEach(n=>n())}).catch(()=>{Ut=e=>e,gn.forEach(e=>e())}),an)}const wd=e=>e;function vt(){const[,e]=f.useState(0);return f.useEffect(()=>{if(Ut)return;const n=()=>e(i=>i+1);return gn.add(n),Sd(),()=>{gn.delete(n)}},[]),Ut??wd}function Et(e,n){return n(e).toLowerCase()}const _d=o("highlight-bg");function Qt(e,n,i){if(!n)return e;const r=Et(n,i);if(!r)return e;const s=Et(e,i);if(s.length!==e.length)return e;const l=[];let a=0,p=0;for(;a<e.length;){const c=s.indexOf(r,a);if(c===-1){l.push(e.slice(a));break}c>a&&l.push(e.slice(a,c)),l.push(t.jsx("mark",{style:{background:_d,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},p++)),a=c+r.length}return t.jsx(t.Fragment,{children:l})}function Bi(e,n,i,r){if(!n)return!0;const s=Et(n,r);return(i?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(a=>typeof a=="string"&&Et(a,r).includes(s))}function $d(e,n,i){return n?Et(e,i).includes(Et(n,i)):!0}const Ai={类:o("section-lei"),书:o("section-shu"),序:o("section-xu"),结语:o("section-jieyu"),注释:o("section-zhushi")},zd={考证:o("section-kaozhen")};function Cd(e){const n=e.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Ls(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((s,l)=>s+Ls(l),0))||0;return n+i}function Id(e,n){const i=[],r=a=>{var p;i.push(...a.files),(p=a.children)==null||p.forEach(r)};if(r(e),i.length===0)return;const s=i.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 Td={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Wi({enabled:e,expanded:n,onClick:i,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...Td,...r},children:s}):t.jsx("span",{style:r,children:s})}function Ed({type:e}){const n=nt(e),i=Ai[n]||o("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:i,border:`1px solid ${i}40`,borderRadius:"2px",background:`${i}08`,flexShrink:0},children:n})}function Rd({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=V(),s=Fe(),l=vt(),a=k=>k?Ue(r(k),h=>i?Qt(h,i,l):h):"",[p,c]=f.useState(!1),d=!!e.summary,u=!!e.comment,g=!!e.additional_comment,x=!!(e.content&&e.content.length>60),m=d||u||g||x;f.useEffect(()=>{i&&c(!0)},[i]);const b=!p&&x?rs(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[t.jsxs("div",{onClick:()=>m&&c(!p),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:m?"pointer":"default",userSelect:"none",background:o("input-bg")},children:[t.jsxs(Wi,{enabled:m,expanded:p,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",a(e.book_title),"》"]}):a(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[Li(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:a(e.author_info||e.author)})]}),!p&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:a(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:a(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:o("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:s(e.work_id),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),p&&m&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${o("widget-border")}`,background:o("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"8px"},children:a(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:a(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(e.additional_comment)})]}),x&&!d&&!u&&!g&&t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)})]})]})}function Nd({section:e,highlightQuery:n=""}){const{convert:i}=V(),r=vt(),s=c=>c?Ue(i(c),d=>n?Qt(d,n,r):d):"",[l,a]=f.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(Wi,{enabled:p,expanded:l,onClick:()=>a(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(Ed,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:s(e.title)}),p&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&p&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${Ai[nt(e.type)]||o("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:o("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(e.content)})})]})}const Ld=100;function Mi(e){return nt(e.type)!=="page_header"?!1:(e.content||"").length>=Ld}function Bd({section:e,highlightQuery:n=""}){const{convert:i}=V(),r=vt();if(nt(e.type)==="page_header"&&!Mi(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
788
|
-
`)),l=Ue(s,d=>n?Qt(d,n,r):d),a=nt(e.type),p=Ai[a]||o("desc-fg"),c=a==="序"||a==="结语"||a==="注释";return t.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:o("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${p}40`:void 0,background:c?o("bg"):void 0,borderRadius:c?"0 4px 4px 0":void 0,position:"relative"},children:[c&&t.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 Ad(e,n,i){const[r,s]=f.useState({});return f.useEffect(()=>{var d;if(!n||e.length===0)return;let l=!1;const a=e.filter(u=>{var g;return!((g=i==null?void 0:i.current)!=null&&g.has(u))}),p={};for(const u of e)(d=i==null?void 0:i.current)!=null&&d.has(u)&&(p[u]=i.current.get(u));if(Object.keys(p).length>0&&s(p),a.length===0)return;const c=async u=>{var g;try{if(n.getEntry){const h=await n.getEntry(u);if(h)return{title:h.title,author:h.author}}const x=await n.getItem(u);if(!x)return null;const m=x.title||u,b=x.authors,k=(g=b==null?void 0:b[0])==null?void 0:g.name;return{title:m,author:k}}catch{return null}};return Promise.all(a.map(async u=>{var x;const g=await c(u);return(x=i==null?void 0:i.current)==null||x.set(u,g),[u,g]})).then(u=>{l||s(g=>{const x={...g};for(const[m,b]of u)x[m]=b;return x})}),()=>{l=!0}},[e.join(","),n]),r}function Wd({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=V(),a=Fe(),p=vt(),c=j=>j?Ue(l(j),v=>s?Qt(v,s,p):v):"",[d,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const g=nt(e.type),x=zd[g]||o("desc-fg"),m=!!e.content,b=e.work_ids||[],k=b.length>1,h=Ad(k?b:[],i,r),y=m&&!d&&e.content.length>80?rs(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${o("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>m&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:m?"pointer":"default",userSelect:"none"},children:[t.jsxs(Wi,{enabled:m,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg"),lineHeight:1.6},children:e.header_line?c(e.header_line):c(e.title)}),!d&&y&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:c(y)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:a(b[0]),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),k&&t.jsxs("span",{style:{fontSize:"11px",color:o("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:g})]})]}),k&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(j=>{const v=h[j],_=v?`${l(v.title)}${v.author?`(${l(v.author)})`:""}`:j.slice(0,8)+"…";return t.jsxs("a",{href:a(j),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(j))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:j,children:["→",_]},j)})}),d&&m&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:o("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${o("widget-border")}`,fontSize:"12px",color:o("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:c(e.comment)})]})]})}function Md({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=vt(),a=n.trim(),p=f.useMemo(()=>a?e.sections.filter(c=>Bi(c,a,!0,l)):e.sections,[e.sections,a,l]);return t.jsxs("div",{children:[t.jsx("div",{children:p.map((c,d)=>t.jsx(Wd,{section:c,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:a},d))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Fd(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Pd({sections:e,onNavigate:n,inline:i}){const r=Fe(),{convert:s}=V(),l=Fd();return t.jsx(t.Fragment,{children:e.map((a,p)=>{const c=nt(a.type);if(c==="page_header"&&!Mi(a))return null;if(c==="类")return t.jsxs(f.Fragment,{children:[f.createElement(l("类"),null,i(s(a.title))),a.content&&t.jsx("p",{children:i(s(a.content))})]},p);if(c==="书"||c==="诗"||c==="考证"||c==="注释"){const d=a.book_title?`《${a.book_title}》${a.n_juan!=null?Li(a.n_juan)+"卷":""}`:a.title,u=i(s(d));return t.jsxs("section",{className:"bim-rd-entry",children:[f.createElement(l("条目"),{className:"bim-rd-entry-h"},a.work_id&&n?t.jsx("a",{href:r(a.work_id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),n(a.work_id))},title:"查看作品",children:u}):u),a.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(a.author_info))}),a.content&&a.content.split(/\n+/).map((g,x)=>t.jsx("p",{children:i(s(g))},x)),a.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(a.summary))]}),a.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(a.comment))]}),a.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(a.additional_comment))]})]},p)}return a.content?t.jsx("p",{children:i(s(a.content))},p):null})})}function Od(e){return e.some(n=>{const i=nt(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&Mi(n)})}function Dd({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:a,workLabelCache:p,prefs:c}){var A;const{convert:d}=V(),u=vt(),[g,x]=f.useState("text"),m=s.trim(),b=(r==null?void 0:r.type)==="kaozhen",k=f.useCallback(M=>m?Qt(M,m,u):M,[m,u]),h=M=>Ri(M,{renderText:k,properNames:c.properNames}),y=f.useMemo(()=>m?e.sections.filter(M=>Bi(M,m,b,u)):e.sections,[e.sections,m,b,u]),j=(M,F)=>F.filter(Y=>nt(Y.type)===M).length,v=j("书",e.sections),_=j("诗",e.sections),S=j("考证",e.sections);let $="";b?$=m?`${j("考证",y)} / ${S} ${d("條")}`:`${S} ${d("條")}`:_>0?$=m?`${j("诗",y)} / ${_} 首`:`${_} 首`:v>0&&($=m?`${j("书",y)} / ${v} ${d("部書")}`:`${v} ${d("部書")}`);const w=r!=null&&r.text_quality?hd(r.text_quality.grade):null,C=[];i&&C.push(i),$&&C.push($),b&&(r!=null&&r.target_source)&&C.push(t.jsxs(t.Fragment,{children:[d("考證對象")," ",d(r.target_source)]})),w&&C.push(t.jsx("span",{title:Al[w],children:(A=r==null?void 0:r.text_quality)!=null&&A.source_note?t.jsxs(t.Fragment,{children:["底本 ",d(r.text_quality.source_note),"(",d(Hn[w]),")"]}):t.jsxs(t.Fragment,{children:[d("文本質量")," ",d(Hn[w])]})})),e.source_url&&C.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:d("原文來源")}));const N=!b&&Od(e.sections),E=!!n&&(!N||c.readingMode==="paragraph"&&$n(n)),I=!b&&(N||!!n),O=b||!I?"entries":g;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:d(e.title)}),C.length>0&&t.jsx("p",{className:"bim-rd-meta",children:C.map((M,F)=>t.jsxs(f.Fragment,{children:[F>0&&t.jsx("span",{className:"bim-rd-dot"}),M]},F))}),I&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":"看法",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":O==="text",onClick:()=>x("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":O==="entries",onClick:()=>x("entries"),children:d("條目")})]})]}),O==="text"&&t.jsx("article",{className:"bim-rd-prose",children:E?t.jsx(Ni,{text:n,mode:c.readingMode,properNames:c.properNames,renderText:k,dropTitle:e.title}):t.jsx(Pd,{sections:e.sections,onNavigate:l,inline:h})}),O==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:b?t.jsx(Md,{juan:e,searchQuery:s,onNavigate:l,transport:a,workLabelCache:p}):t.jsxs(t.Fragment,{children:[y.map((M,F)=>{const Y=nt(M.type);return Y==="书"||Y==="诗"||Y==="考证"?t.jsx(Rd,{section:M,onNavigate:l,highlightQuery:m},F):Y==="类"?t.jsx(Nd,{section:M,highlightQuery:m},F):t.jsx(Bd,{section:M,highlightQuery:m},F)}),y.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function Bs(e){return e.juan_files&&e.juan_files.length>0?e.juan_files:e.files&&e.files.length>0?e.files.map(n=>n.filename):[]}function Hd(e){const n=Bs(e);return n.length>0?n[0]:null}function Gd(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:a,query:p,isKaozhen:c}=e,d=vt(),u=f.useRef(new Map),[g,x]=f.useState({}),[m,b]=f.useState({}),k=f.useCallback((y,j)=>{const v=j==null?void 0:j.title;v&&b(_=>_[y]===v?_:{..._,[y]:v})},[]);f.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:a}),k(s,l))},[s,l,a,k]),f.useEffect(()=>{u.current.clear(),x({}),b({})},[n]);const h=f.useCallback((y,j)=>{let v=0;if(y.juan)for(const _ of y.juan.sections)Bi(_,j,c,d)&&v++;return v===0&&y.rawText&&$d(y.rawText,j,d)&&(v=1),v},[c,d]);return f.useEffect(()=>{const y=p.trim();if(!y){x({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let j=!1;const v={},_=[];for(const N of r){const E=u.current.get(N);E?v[N]=h(E,y):(v[N]="loading",_.push(N))}x(v);const S=8;let $=0;const w=async()=>{var N;for(;$<_.length;){if(j)return;const E=$++,I=_[E];try{const[O,A]=await Promise.all([i.getCollatedJuan(n,I),((N=i.getCollatedJuanText)==null?void 0:N.call(i,n,I))??Promise.resolve(null)]),M={juan:O,rawText:A};if(u.current.set(I,M),k(I,O),j)return;x(F=>({...F,[I]:h(M,y)}))}catch{if(j)return;x(O=>({...O,[I]:0}))}}},C=Array.from({length:Math.min(S,_.length)},()=>w());return Promise.all(C),()=>{j=!0}},[p,n,i,r.join(","),h,d,k]),{matchStates:g,titles:m}}const Fi=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:a,style:p,title:c,subtitle:d,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m})=>{const[b,k]=f.useState(null),[h,y]=f.useState(!1),[j,v]=f.useState(null),[_,S]=f.useState(null),[$,w]=f.useState(null),[C,N]=f.useState(!1),[E,I]=f.useState(null),[O,A]=f.useState(""),M=f.useRef(new Map),F=f.useRef(0),Y=s??_,K=f.useCallback(J=>{S(J),l==null||l(J)},[l]),R=e||b;f.useEffect(()=>{e&&(y(!1),v(null))},[e]),f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let J=!1;return y(!0),v(null),i.getCollatedEditionIndex(n).then(ce=>{J||(ce?k(ce):v("未找到整理本数据"))}).catch(ce=>{J||v(ce instanceof Error?ce.message:"加载失败")}).finally(()=>{J||y(!1)}),()=>{J=!0}},[e,n,i]),f.useEffect(()=>{if(R&&!Y){const J=Hd(R);J&&K(J)}},[R,Y,K]);const oe=n||(R==null?void 0:R.work_id),H=f.useCallback(async J=>{var me;if(!oe||!(i!=null&&i.getCollatedJuan))return;const ce=++F.current;N(!0),w(null),I(null);try{const[te,ie]=await Promise.all([i.getCollatedJuan(oe,J),((me=i.getCollatedJuanText)==null?void 0:me.call(i,oe,J))??Promise.resolve(null)]);if(ce!==F.current)return;w(te),I(ie)}catch{if(ce!==F.current)return;w(null),I(null)}finally{ce===F.current&&N(!1)}},[oe,i]);f.useEffect(()=>{Y&&H(Y)},[Y,H]);const re=J=>{K(J)};if(h)return t.jsx("div",{className:a,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(j)return t.jsx("div",{className:a,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:j});if(!R)return null;const ee=R.type==="kaozhen",Q=Bs(R);return t.jsx(Vd,{className:a,style:p,index:R,allFiles:Q,isKaozhen:ee,effectiveWorkId:oe,transport:i,activeFile:Y,handleSelectFile:re,juanData:$,juanRawText:E,juanLoading:C,searchQuery:O,setSearchQuery:A,onNavigate:r,workLabelCacheRef:M,reader:{title:c,subtitle:d,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m}})};function As(e,n,i,r){var d,u,g,x;const s=(u=(d=n.juan_metadata)==null?void 0:d[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:Cd(e)),p=((x=(g=n.files)==null?void 0:g.find(m=>m.filename===e))==null?void 0:x.title)??i[e];if(!p)return{position:l,label:l};const c=r(p);return{position:l,label:l===p||l===c?c:`${l} ${c}`}}function Ud(e,n,i,r,s){const l=c=>c==="loading"?"…":typeof c=="number"&&c>0?c:void 0,a=(c,d)=>({key:c,label:d??As(c,e,r,s).label,hint:l(i[c]),disabled:i[c]===0}),p=(c,d)=>{var g;if(c.files.length===1&&!((g=c.children)!=null&&g.length))return a(c.files[0],s(c.label));const u=Id(c,i);return{key:`group:${d}`,label:s(c.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:Ls(c),defaultExpanded:typeof u=="number"&&u>0,children:[...c.files.map(x=>a(x)),...(c.children??[]).map((x,m)=>p(x,`${d}.${m}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((c,d)=>p(c,`${d}`)):n.map(c=>a(c))}const Vd=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:a,activeFile:p,handleSelectFile:c,juanData:d,juanRawText:u,juanLoading:g,searchQuery:x,setSearchQuery:m,onNavigate:b,workLabelCacheRef:k,reader:h})=>{const{convert:y}=V(),[j,v]=$i(),{matchStates:_,titles:S}=Gd({workId:l,transport:a,files:r,activeFile:p,activeJuan:d,activeRawText:u,query:x,isKaozhen:s}),$=Ns(h.resolveImages,p),w=f.useMemo(()=>Ud(i,r,_,S,y),[i,r,_,S,y]),C=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:I=>m(I.target.value)}),N=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(I=>I.vol_label)?"冊":"卷",E=p?As(p,i,S,y).position:void 0;return t.jsxs(zi,{className:e,style:n,title:h.title??(i.title?y(i.title):void 0),subtitle:h.subtitle??y(s?"考證":"整理本"),toc:w,tocCaption:`目录 · ${r.length} ${y(N)}`,tocHeader:C,activeKey:p,onSelect:c,images:$.images,imagesLoading:$.loading,renderImageOverlay:h.renderImageOverlay,imagePanel:h.imagePanel,prefs:j,onPrefsChange:v,paragraphToggle:!s&&$n(u),allowVertical:h.allowVertical,children:[g?t.jsx(jt,{}):d?t.jsx(Dd,{juan:d,rawText:u,positionLabel:E,index:i,searchQuery:x,onNavigate:b,transport:a,workLabelCache:k,prefs:j},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,i.references&&i.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:y("參考文獻")}),t.jsx("ol",{children:i.references.map((I,O)=>t.jsxs("li",{children:[I.url?t.jsx("a",{className:"bim-rd-link",href:I.url,target:"_blank",rel:"noopener noreferrer",children:I.title}):t.jsx("span",{children:I.title}),I.author&&t.jsxs("span",{children:[",",I.author]}),I.note&&t.jsxs("span",{children:["。",I.note]})]},O))})]})]})},Yd={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},Kd={label:"其他",color:o("desc-fg")},qd={pending:{label:"待处理",color:o("warning")},in_progress:{label:"处理中",color:o("primary")},resolved:{label:"已处理",color:o("success")},wontfix:{label:"不采纳",color:o("desc-fg")},duplicate:{label:"重复",color:o("desc-fg")}},Jd={label:"待处理",color:o("warning")};function Zd(e){try{const n=new Date(e),i=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return e}}function Xd(e,n){if(!e)return!1;try{const i=new URL(e,n);if(i.protocol!=="http:"&&i.protocol!=="https:")return!1;const r=new URL(n);return i.hostname===r.hostname}catch{return!1}}const Pi=({items:e,loading:n})=>{const i=Fe();return n?t.jsx(jt,{}):e.length===0?t.jsx("div",{style:Qd,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Yd[r.type]||Kd,l=qd[r.status]||Jd,a=typeof window<"u"&&Xd(r.pageUrl,window.location.href);return t.jsxs("div",{style:ep,children:[t.jsxs("div",{style:tp,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Bo,background:s.color},children:s.label}),t.jsx("span",{style:{...Bo,background:l.color},children:l.label})]}),t.jsx("span",{style:np,children:Zd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:ip,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:Bn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(a?t.jsx("a",{href:r.pageUrl,style:Bn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Bn,children:r.pageUrl}))]}),t.jsx("div",{style:op,children:r.content}),r.reply&&t.jsxs("div",{style:rp,children:[t.jsx("div",{style:sp,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Qd={textAlign:"center",padding:"40px 0",color:o("desc-fg"),fontSize:"14px"},ep={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"16px"},tp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Bo={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},np={fontSize:"12px",color:o("desc-fg")},ip={fontSize:"12px",marginBottom:"6px"},Bn={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},op={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},rp={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},sp={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},ti=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const a=de(),[p,c]=f.useState(null),[d,u]=f.useState([]),[g,x]=f.useState("recommend"),[m,b]=f.useState([]),[k,h]=f.useState(!1),y=r??g,j=F=>{x(F),s==null||s(F)},[v,_]=f.useState(!0),[S,$]=f.useState(null),[w,C]=f.useState(null),[N,E]=f.useState(null);f.useEffect(()=>{let F=!1;if(e.getCounts)return e.getCounts().then(Y=>{F||c({works:Y.works,books:Y.books,collections:Y.collections})}).catch(()=>{}),()=>{F=!0}},[e]),f.useEffect(()=>{let F=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const K=await e.getRecommended();if(K!=null&&K.groups)return K.groups.flatMap(R=>R.items.map(oe=>({...oe,group:R.name})))}catch{}return[]})().then(async K=>{if(F)return;const R=K.filter(H=>H.id);if(R.length===0){_(!1);return}const oe=await Promise.all(R.map(async H=>{if(H.type)return{id:H.id,title:H.title,type:H.type,author:H.author,dynasty:H.dynasty,role:H.role,edition:H.edition,has_text:H.has_text,has_image:H.has_image,has_collated:H.has_collated,subtype:H.subtype,primary_name:H.primary_name,group:H.group,fallbackDescription:H.description};try{let re=null;if(e.getEntry)re=await e.getEntry(H.id);else{const ee=await e.getItem(H.id);ee&&(re={id:H.id,title:ee.title||H.id,type:ee.type||"work"})}if(re)return{...re,group:H.group,fallbackDescription:H.description}}catch{}return{id:H.id,title:H.title,type:ke.extractType(H.id),group:H.group,fallbackDescription:H.description}}));F||(u(oe.filter(H=>H!==null)),_(!1))}),()=>{F=!0}},[e,i]);const I=f.useRef(!1),O=f.useRef(!1),A=f.useRef(!1);f.useEffect(()=>{if(y!=="catalog"||I.current)return;const F=e.getCatalogProgress??e.getResourceProgress;if(!F)return;I.current=!0;let Y=!1;return F.call(e).then(K=>{Y||$(K)}).catch(()=>{I.current=!1}),()=>{Y=!0}},[e,y]),f.useEffect(()=>{if(y!=="collection"||O.current||!e.getCollectionProgress)return;O.current=!0;let F=!1;return e.getCollectionProgress().then(Y=>{F||C(Y)}).catch(()=>{O.current=!1}),()=>{F=!0}},[e,y]),f.useEffect(()=>{if(y!=="site"||A.current||!e.getSiteProgress)return;A.current=!0;let F=!1;return e.getSiteProgress().then(Y=>{F||E(Y)}).catch(()=>{A.current=!1}),()=>{F=!0}},[e,y]),f.useEffect(()=>{if(!l||y!=="feedback")return;let F=!1;return h(!0),fetch(l).then(Y=>Y.json()).then(Y=>{!F&&Y.success&&b(Y.items||[])}).catch(()=>{}).finally(()=>{F||h(!1)}),()=>{F=!0}},[l,y]);const M=F=>t.jsx(yn,{type:F,size:12});return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:o("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${o("widget-border")}`,marginBottom:"16px"},children:[t.jsx(Ft,{label:a.home.recommendTab,active:y==="recommend",onClick:()=>j("recommend")}),t.jsx(Ft,{label:a.home.catalogTab,active:y==="catalog",onClick:()=>j("catalog")}),t.jsx(Ft,{label:a.home.collectionTab,active:y==="collection",onClick:()=>j("collection")}),t.jsx(Ft,{label:a.home.siteTab,active:y==="site",onClick:()=>j("site")}),l&&t.jsx(Ft,{label:a.home.feedbackTab,active:y==="feedback",onClick:()=>j("feedback")})]}),y==="recommend"&&t.jsx(lp,{recommended:d,loading:v,onNavigate:n,getIcon:M,t:a}),y==="catalog"&&t.jsx(Ao,{progress:S,t:a,onNavigate:n}),y==="collection"&&t.jsx(Ao,{progress:w,t:a,onNavigate:n}),y==="site"&&t.jsx(cp,{progress:N,t:a,totalWorks:(p==null?void 0:p.works)??0}),y==="feedback"&&l&&t.jsx(Pi,{items:m,loading:k})]})})},Ft=({label:e,active:n,onClick:i})=>t.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:o(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${o("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),lp=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=Fe();if(n)return t.jsx(jt,{});if(e.length===0)return null;const a=new Map;for(const p of e){const c=p.group||s.home.recommendedBrowse;a.has(c)||a.set(c,[]),a.get(c).push(p)}return t.jsx(t.Fragment,{children:Array.from(a.entries()).map(([p,c])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:p}),t.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 t.jsxs("a",{href:l(d.id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),i==null||i(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,cursor:"pointer",background:o("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},Ao=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(jt,{});const r=[...e.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:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(p=>{const c=r.filter(d=>d.status===p);return c.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:a[p]}}),l[p]," (",c.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(d=>t.jsx(ap,{item:d,t:n,statusColor:a[p],onNavigate:i},d.id))})]},p)})})},ap=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=Fe(),l=e.total>0?Math.round(e.imported/e.total*100):0,a=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=e.edition?`${e.name}·${e.edition}`:e.name,c=e.collection_id||e.work_id;return c&&r?t.jsx("a",{href:s(c),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:p}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:o("widget-border"),color:o("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:a})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Kt(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},cp=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(jt,{});const r=[...e.resources].sort((c,d)=>c.priority-d.priority),s=r.filter(c=>c.imported>0),l=r.filter(c=>c.imported===0),a=s.reduce((c,d)=>Math.max(c,d.imported),0),p=i>0?Math.round(a/i*100):0;return t.jsxs("div",{children:[i>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${o("primary")} 6%, transparent)`,fontSize:"13px",color:o("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:a.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>t.jsx(Wo,{item:c,t:n,totalWorks:i},c.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(c=>t.jsx(Wo,{item:c,t:n,totalWorks:i},c.id))})]})]})},Wo=({item:e,t:n,totalWorks:i})=>{const r=i>0?Math.round(e.imported/i*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:t.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&i>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:o("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},Mo="(max-width: 768px)";function dp(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Mo).matches);return f.useEffect(()=>{const i=window.matchMedia(Mo),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),e}const pp=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var Y;const l=de(),{convert:a}=V(),p=dp(),[c,d]=f.useState(null),[u,g]=f.useState(null),[x,m]=f.useState(!1),[b,k]=f.useState("detail"),[h,y]=f.useState([]),[j,v]=f.useState(!1),[_,S]=f.useState(null),[$,w]=f.useState(!1),C=f.useCallback(async K=>{if(!e.getCollatedEditionIndex){S(null);return}w(!0);try{const R=await e.getCollatedEditionIndex(K);S(R)}catch{S(null)}finally{w(!1)}},[e]),N=f.useCallback(async K=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){y([]);return}v(!0);try{if(e.getCollectionCatalogs){const R=await e.getCollectionCatalogs(K);y(R||[])}else if(e.getCollectionCatalog){const R=await e.getCollectionCatalog(K);y(R?[{resource_id:"",data:R}]:[])}}catch{y([])}finally{v(!1)}},[e]),E=f.useCallback(async K=>{if(i){i(K);return}d(K),g(null),y([]),S(null),k("detail"),m(!0);try{const R=await e.getItem(K.id);R&&(g(R),R.type==="collection"?N(K.id):R.type==="work"&&R.has_collated&&C(K.id))}catch(R){console.error("加载详情失败:",R)}finally{m(!1)}},[e,i,N,C]),I=f.useCallback(async K=>{g(null),y([]),S(null),k("detail"),m(!0);try{const R=await e.getItem(K);R&&(g(R),d({id:K,title:R.title||K,type:R.type||"book"}),R.type==="collection"?N(K):R.type==="work"&&R.has_collated&&C(K))}catch(R){console.error("导航失败:",R)}finally{m(!1)}},[e,N,C]),O=(u==null?void 0:u.type)==="collection"&&(h.length>0||j)||(u==null?void 0:u.type)==="work"&&(_||$),A=p&&(x||u),M=f.useCallback(()=>{d(null),g(null),y([]),S(null),k("detail")},[]),F=t.jsx(t.Fragment,{children:x?t.jsx(jt,{}):u?t.jsxs(t.Fragment,{children:[(O||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${o("widget-border")}`,padding:p?"0 12px":"0 48px",background:o("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[O&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>k("detail"),style:cn(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&j&&h.length===0&&t.jsxs("button",{onClick:()=>{},style:cn(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&h.map(K=>t.jsx("button",{onClick:()=>k(`catalog:${K.resource_id}`),style:cn(b===`catalog:${K.resource_id}`),children:K.short_name?`${a(K.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},K.resource_id)),u.type==="work"&&(_||$)&&t.jsxs("button",{onClick:()=>k("collated"),style:cn(b==="collated"),children:[l.detailTab.collatedEdition,$&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?t.jsx(fi,{data:u,transport:e,onNavigate:I}):b.startsWith("catalog:")?t.jsx(gi,{data:(Y=h.find(K=>`catalog:${K.resource_id}`===b))==null?void 0:Y.data,onNavigate:I}):b==="collated"?t.jsx(Fi,{index:_||void 0,workId:u.id,transport:e,onNavigate:I}):null})]}):t.jsx(ti,{transport:e,onNavigate:I,recommendedIds:r})});return p?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:A?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${o("widget-border")}`,background:o("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:M,style:{padding:"4px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:F})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Un,{transport:e,onEntryClick:E,hideModeIndicator:n}),!u&&t.jsx(ti,{transport:e,onNavigate:I,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${o("widget-border")}`,display:"flex",flexDirection:"column",background:o("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(Un,{transport:e,onEntryClick:E,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:F})]})};function cn(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function ut(e){return e.replace(/\.md$/,"")}function Fo(e){let n="";if(e.source_url)try{const r=new URL(e.source_url).pathname.split("/").filter(Boolean).pop()??"";n=decodeURIComponent(r).replace(/_/g," ")}catch{}return[e.source_name,n||e.version_label].filter(Boolean).join(" · ")||e.key}const Po={padding:24,color:o("desc-fg")},ni=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:a,onVersionChange:p,title:c,subtitle:d,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m,className:b,style:k})=>{const[h,y]=f.useState(e??null),[j,v]=f.useState(!1),[_,S]=f.useState(null),$=r!==void 0?r:_,w=f.useCallback(Q=>{s?s(Q):S(Q)},[s]),[C,N]=f.useState(null),[E,I]=f.useState(!1);f.useEffect(()=>{e&&y(e)},[e]),f.useEffect(()=>{if(e)return;y(null),v(!1);const Q=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!Q){v(!0);return}let J=!1;return Promise.resolve().then(Q).then(ce=>{J||(ce?y(ce):v(!0))}).catch(()=>{J||v(!0)}),()=>{J=!0}},[n,i,e,l]),f.useEffect(()=>{if(!h||h.chapters.length===0)return;const Q=ut(h.chapters[0].file);if(!$){w(Q);return}const J=ut($);h.chapters.some(me=>ut(me.file)===J)||w(Q)},[h,$,w]);const O=f.useMemo(()=>{if(!h||!$)return null;const Q=ut($);return h.chapters.find(J=>ut(J.file)===Q)??null},[h,$]);f.useEffect(()=>{if(!n||!O)return;const Q=l!==void 0?i.getWorkFullTextChapter?ce=>i.getWorkFullTextChapter(n,l,ce):null:i.getBookFullTextChapter?ce=>i.getBookFullTextChapter(n,ce):null;if(!Q)return;let J=!1;return I(!0),N(null),Promise.resolve(O.file).then(Q).then(ce=>{J||N(ce)}).catch(()=>{J||N(null)}).finally(()=>{J||I(!1)}),()=>{J=!0}},[n,O,i,l]);const A=Ns(u,O?ut(O.file):null),[M,F]=$i(),{convert:Y}=V(),K=!!(a&&a.length>1&&p),R=f.useMemo(()=>K?bs(a).map((Q,J)=>({...Q,label:Fo(a[J])})):void 0,[K,a]),oe=K?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:Q=>p(Q.target.value),children:a.map(Q=>t.jsx("option",{value:Q.key,children:Fo(Q)},Q.key))})]}):null;if(!h)return t.jsxs("div",{style:Po,children:[oe&&t.jsx("div",{style:{marginBottom:12},children:oe}),j?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:Po,children:[oe&&t.jsx("div",{style:{marginBottom:12},children:oe}),"全文目录为空"]});const H=h.chapters.map(Q=>({key:ut(Q.file),label:Y(Q.title)})),re=ks(h)||Kn(h),ee=C?C.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(zi,{title:c??Y(h.version_label),subtitle:d??"全文",toc:H,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:$?ut($):null,onSelect:w,images:A.images,imagesLoading:A.loading,renderImageOverlay:g,imagePanel:x,prefs:M,onPrefsChange:F,versions:R,currentVersionKey:R?l??null:void 0,onVersionChange:R?p:void 0,versionSource:!1,paragraphToggle:$n(ee),allowVertical:m,className:b,style:k,children:[O&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:Y(O.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:h.source.url,target:"_blank",rel:"noreferrer",children:Y(h.source.name)}),h.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),h.source.license]})]})]}),E&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!E&&ee!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Ni,{text:ee,mode:M.readingMode,tables:re,gujiMarkdown:Kn(h),properNames:M.properNames})}),!E&&!C&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},up=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=de(),{convert:l}=V(),[a,p]=f.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[c,d]=f.useState(null);return t.jsxs("div",{className:i,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:l(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[s.catalog.totalVolumes," ",t.jsx("strong",{children:e.total_volumes})," ",s.unit.juan]}),e.stats.zhulu!=null&&t.jsxs("span",{children:["著錄 ",t.jsx("strong",{children:e.stats.zhulu})," ",s.unit.bu]}),e.stats.cunmu!=null&&t.jsxs("span",{children:["存目 ",t.jsx("strong",{children:e.stats.cunmu})," ",s.unit.bu]}),e.stats.categories!=null&&t.jsxs("span",{children:[e.stats.categories," 類"]})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(g=>t.jsx(xp,{division:g,expanded:a===g.name,onToggle:()=>p(a===g.name?null:g.name),expandedCat:c,onCatToggle:x=>d(c===x?null:x),onNavigate:n},g.name))})]})},xp=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:a}=V(),p=e.categories.reduce((c,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return c+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${o("primary")} 6%, transparent)`:o("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:o("fg"),textAlign:"left"},children:[t.jsx("span",{children:a(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg")},children:[e.categories.length," 類 · ",p," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(c=>{const d=`${e.name}/${c.name}`;return t.jsx(fp,{category:c,expanded:r===d,onToggle:()=>s(d),onNavigate:l},c.name)})})]})},fp=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var c,d,u,g;const{convert:s}=V(),l=((c=e.books)==null?void 0:c.zhulu)||[],a=((d=e.books)==null?void 0:d.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((g=e.stats)==null?void 0:g.cunmu)||a.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?o("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:o("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||a.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Oo,{label:"著錄",books:l,onNavigate:r}),a.length>0&&t.jsx(Oo,{label:"存目",books:a,onNavigate:r})]})]})},Oo=({label:e,books:n,onNavigate:i})=>{const{convert:r}=V(),s=Fe(),[l,a]=f.useState(n.length<=20),p=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((c,d)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:o("fg")},children:c.work_id&&i?t.jsx("a",{href:s(c.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},children:r(c.title)}):r(c.title)}),c.volumes&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(c.volumes)}),c.author&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(c.author).slice(0,20)})]},d))}),!l&&t.jsxs("button",{onClick:()=>a(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},Ye=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=de();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:o("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&t.jsx("button",{onClick:i,style:mp,children:"AI"}),n&&t.jsx("button",{onClick:n,style:gp,children:l.action.save})]})]}),s]})},gp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},mp={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Ge=({label:e,value:n,onChange:i,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:l=>i(l.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),bt=({value:e,onChange:n,placeholder:i})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},mn=({children:e,color:n,style:i})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||o("primary-soft"),color:o(n?"on-color-fg":"fg"),...i},children:e});function hp(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const pn=({value:e,onChange:n,label:i})=>{const[r,s]=f.useState(!1),l=f.useRef(null),a=hp(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&a?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Do,children:i}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${o("input-border")}`,borderRadius:"2px",background:o("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:o("fg")},children:a.name}),t.jsx(mn,{children:a.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Do,children:i}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Do={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function bp(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function yp(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ws=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=de(),[s,l]=f.useState(null),a=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},p=g=>{n(e.filter((x,m)=>m!==g)),s===g&&l(null)},c=(g,x,m)=>{const b=[...e];b[g]={...b[g],[x]:m},n(b)},d=(g,x)=>{const m=[...e];m[g]={...m[g],type:x,id:"",name:""},n(m),x==="bookID"&&i&&i(b=>{const k=[...e];k[g]={...k[g],id:b.id,name:b.title,type:"bookID"},n(k)})},u=g=>{i&&i(x=>{const m=[...e];m[g]={...m[g],id:x.id,name:x.title,type:"bookID"},n(m)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((g,x)=>t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===x?null:x),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===x?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:o("fg")},children:g.name||`${r.editor.sourcePlaceholder} ${x+1}`}),g.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:bp(g.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:yp(g.type)}),t.jsx("button",{onClick:m=>{m.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===x&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!g.type&&t.jsxs("div",{children:[t.jsx("label",{style:it,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>d(x,"bookID"),style:{...Ho,borderColor:o("source-bookid"),color:o("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>d(x,"url"),style:{...Ho,borderColor:o("source-url"),color:o("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),g.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:it,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Go,children:r.action.changeType})]}),g.id&&g.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:o("bg"),border:`1px solid ${o("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:o("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:g.name}),t.jsx("code",{style:{fontSize:"11px",background:o("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:g.id})]}),t.jsx("button",{onClick:()=>u(x),style:{background:"transparent",border:`1px solid ${o("widget-border")}`,color:o("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(x),style:{width:"100%",padding:"14px",border:`2px dashed ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),g.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:it,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Go,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:g.name,onChange:m=>c(x,"name",m.target.value),placeholder:r.editor.sourceNamePlaceholder,style:St})]}),t.jsxs("div",{children:[t.jsx("label",{style:it,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:g.id,onChange:m=>c(x,"id",m.target.value),placeholder:"https://...",style:St})]})]}),g.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${o("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...it,opacity:.7},children:r.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:it,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:g.details,onChange:m=>c(x,"details",m.target.value),placeholder:r.editor.detailsPlaceholder,style:St})]}),t.jsxs("div",{children:[t.jsx("label",{style:it,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:g.position,onChange:m=>c(x,"position",m.target.value),placeholder:"如: 卷三, p.52",style:St})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:it,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:g.version,onChange:m=>c(x,"version",m.target.value),placeholder:"如: v1.0, 2024-01",style:St})]}),t.jsxs("div",{children:[t.jsx("label",{style:it,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:g.processor_version,onChange:m=>c(x,"processor_version",m.target.value),placeholder:"如: v0.1",style:St})]})]})]})]})})]},x)),t.jsxs("button",{onClick:a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},it={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},St={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Ho={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:o("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},Go={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Ms(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(i=>({id:i.id||"",name:i.name||"",type:i.type||"",details:i.details||"",position:i.position||"",version:i.version||"",processor_version:i.processor_version||""}))}catch{}return[]}function Fs(e){return!e||e.length===0?"":JSON.stringify(e)}const Ps=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:a,childWorks:p,childCollections:c,containedBooks:d,siblingBooks:u,onLinkEntity:g,onUnlinkEntity:x,onViewEntity:m,onCreateAndLink:b,onSaveRelations:k})=>{const h=de();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:h.section.relations})]}),k&&t.jsx("button",{onClick:k,style:jp,children:h.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.belongsToWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>g("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Pt,{direction:"up",title:h.relation.containedInCollection,entity:a,onView:m,onUnlink:()=>x("collectionId"),onLink:()=>g("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),l&&u&&u.length>0&&t.jsx(wt,{direction:"horizontal",title:`${h.relation.siblingVersions} (${u.length})`,entities:u,onView:m,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.parentWork,entity:r,onView:m,onUnlink:()=>x("parentWorkId"),onLink:()=>g("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),p&&p.length>0&&t.jsx(wt,{direction:"down",title:`${h.relation.childWorks} (${p.length})`,entities:p,onView:m,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),c&&c.length>0&&t.jsx(wt,{direction:"down",title:`${h.relation.collectionImpl} (${c.length})`,entities:c,onView:m,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(wt,{direction:"down",title:`${h.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>b("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.correspondingWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>g("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Pt,{direction:"up",title:h.relation.parentCollection,entity:s,onView:m,onUnlink:()=>x("parentCollectionId"),onLink:()=>g("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(wt,{direction:"down",title:`${h.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:m,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(wt,{direction:"down",title:`${h.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},Pt=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:a,linkLabel:p,createLabel:c,notLinkedLabel:d,viewLabel:u,unlinkLabel:g})=>{const x=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:o("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Os(i.type)}),t.jsx("span",{style:{fontWeight:500},children:i.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(Uo,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(Uo,{onClick:s,title:g,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(ii,{onClick:l,children:p}),t.jsx(ii,{onClick:a,primary:!0,children:c})]})]})},wt=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:a,expandMoreLabel:p})=>{const[c,d]=f.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),g=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=c?i:i.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:g}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[x.map(m=>t.jsxs("div",{onClick:()=>r(m),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:o("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:Os(m.type)}),t.jsx("span",{children:m.title})]},m.id)),i.length>5&&!c&&t.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:o("link-fg"),cursor:"pointer"},children:[p," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:a}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(ii,{onClick:s,primary:!0,children:["+ ",l]})})]})},Uo=({onClick:e,title:n,danger:i,children:r})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?o("danger"):"inherit",opacity:.7},children:r}),ii=({onClick:e,primary:n,children:i})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${o("widget-border")}`,borderRadius:"4px",background:n?o("primary"):"transparent",color:n?o("primary-fg"):"inherit",cursor:"pointer"},children:i});function Os(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const jp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Ds=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:a,onSearch:p,isLoading:c,excludeId:d})=>{const[u,g]=f.useState(""),x=d?a.filter(h=>h.id!==d):a;f.useEffect(()=>{e&&(g(""),p(""))},[e]);const m=h=>{g(h),p(h)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",k=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:vp,children:t.jsxs("div",{style:kp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),t.jsx("button",{onClick:s,style:Sp,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:h=>m(h.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:wp})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:An,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(h=>t.jsxs("div",{onClick:()=>r(h),style:_p,children:[t.jsx("span",{style:{fontSize:"16px"},children:k}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):u?t.jsxs("div",{style:An,children:["未找到匹配的",b]}):t.jsxs("div",{style:An,children:["输入关键词搜索",b]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:l,style:$p,children:["创建新",b,"并关联"]})]})]})})},vp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},kp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},Sp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},wp={width:"100%",padding:"10px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},_p={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:o("primary-soft")},An={padding:"20px",textAlign:"center",color:o("desc-fg")},$p={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Vo={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},zp={work:"📜",book:"📖",collection:"📚",entity:"👤"},Hs=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[a,p]=f.useState(""),c=f.useRef(null);f.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,m;(x=c.current)==null||x.focus(),(m=c.current)==null||m.select()},100))},[e,r==null?void 0:r.title]);const d=x=>{x.key==="Enter"&&a.trim()?u():x.key==="Escape"&&l()},u=()=>{a.trim()&&s(a.trim(),{...r,title:a.trim()})};if(!e)return null;const g=()=>{switch(i){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`创建新${Vo[n]}`}};return t.jsx("div",{style:Cp,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:Ip,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:zp[n]}),t.jsx("span",{children:g()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:o("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:o("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:c,type:"text",value:a,onChange:x=>p(x.target.value),onKeyDown:d,placeholder:`请输入${Vo[n]}名称...`,style:Tp})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),background:o("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&t.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:l,style:Ep,children:"取消"}),t.jsx("button",{onClick:u,disabled:!a.trim(),style:{...Rp,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Cp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ip={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:o("shadow-dialog")},Tp={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box"},Ep={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Rp={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function Np(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Gs(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Lp(e){switch(e){case"work":return o("editor-type-work");case"collection":return o("editor-type-collection");case"book":return o("editor-type-book");default:return o("desc-fg")}}const Us=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:a,onSelect:p,onCancel:c,onCreate:d,onSearch:u})=>{const[g,x]=f.useState(""),[m,b]=f.useState([]),[k,h]=f.useState(!1),[y,j]=f.useState("recent");f.useEffect(()=>{e&&(x(""),b([]),j(r.length>0?"recent":"search"))},[e,r.length]),f.useEffect(()=>{if(!g.trim()){b([]);return}const C=setTimeout(async()=>{h(!0);try{b(await u(g,i))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(C)},[g,i,u]);const v=f.useCallback(C=>{x(C.target.value),C.target.value.trim()&&j("search")},[]),_=f.useCallback(C=>s?C.filter(N=>N.id!==s):C,[s]);if(!e)return null;const S=n||(i==="all"?"选择实体":`选择${Gs(i)}`),$=_(r),w=_(m);return t.jsx("div",{style:Ap,children:t.jsxs("div",{style:Wp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:S}),t.jsx("button",{onClick:c,style:Mp,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:g,onChange:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Fp}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),k&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),$.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs(Yo,{active:y==="recent",onClick:()=>j("recent"),children:["最近使用 (",$.length,")"]}),t.jsxs(Yo,{active:y==="search",onClick:()=>j("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:y==="recent"&&$.length>0?t.jsx(Ko,{entities:$,onSelect:p}):g.trim()?k?t.jsx(Wn,{message:"搜索中..."}):w.length>0?t.jsx(Ko,{entities:w,onSelect:p}):t.jsx(Wn,{message:"未找到匹配的结果"}):t.jsx(Wn,{message:"输入关键词开始搜索"})}),l&&d&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:d,style:Pp,children:a||"创建新实体"})]})]})})},Yo=({active:e,onClick:n,children:i})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:i}),Ko=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(Bp,{entity:i,onClick:()=>n(i)},i.id))}),Bp=({entity:e,onClick:n})=>{const[i,r]=f.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Np(e.type)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:e.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[t.jsx("code",{style:{fontSize:"10px",background:o("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&t.jsx("span",{children:e.author}),e.dynasty&&t.jsx("span",{children:e.dynasty})]})]}),t.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Lp(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Gs(e.type)})]})},Wn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),Ap={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Wp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},Mp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Fp={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},Pp={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Op={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},Dp={work:"📜",collection:"📚",book:"📖",entity:"👤"},Vs=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:a,onAskAI:p,renderSectionActions:c,onDownloadResource:d,downloadStatuses:u,relations:g,onRelationsChange:x})=>{var q;const m=de(),[b,k]=f.useState(!1),[h,y]=f.useState("work"),[j,v]=f.useState(""),[_,S]=f.useState(""),[$,w]=f.useState([]),[C,N]=f.useState(!1),[E,I]=f.useState(!1),[O,A]=f.useState("work"),[M,F]=f.useState(""),[Y,K]=f.useState(),[R,oe]=f.useState(!1),[H,re]=f.useState(null),[ee,Q]=f.useState([]);f.useRef(null);const J=e.type,ce=J==="work",me=J==="collection",te=J==="book",ie=f.useCallback((P,T)=>{n({...e,[P]:T})},[e,n]),pe=f.useCallback((P,T)=>{v(P),y(T),S(m.editor.selectToLink+m.indexType[T]),w([]),k(!0)},[m]),ge=f.useCallback(P=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,P)},[r,e.id]),Ce=f.useCallback(P=>{s==null||s(P.id,P.type)},[s]),ve=f.useCallback((P,T,z)=>{const L={...z,author:(z==null?void 0:z.author)||e.author,dynasty:z==null?void 0:z.dynasty};A(T),F(P),K(L),I(!0)},[e.author]),we=f.useCallback((P,T)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,M,{type:O,title:P,inheritData:T}),I(!1)},[r,e.id,M,O]),Ee=f.useCallback(P=>{if(!P.trim()){w([]);return}N(!0),r!=null&&r.searchEntities&&r.searchEntities(P,h).then(T=>{w(T),N(!1)}).catch(()=>{w([]),N(!1)})},[r,h]),Re=f.useCallback(P=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,j,P.id),k(!1)},[r,e.id,j]),D=f.useCallback(()=>{i()},[i]),se=f.useCallback(P=>{re(()=>P),oe(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Q).catch(()=>{})},[r]),ne=f.useCallback((P,T)=>r!=null&&r.searchEntities?r.searchEntities(P,T==="all"?void 0:T):Promise.resolve([]),[r]),he=f.useCallback(P=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(P),Q(T=>[P,...T.filter(z=>z.id!==P.id)].slice(0,10)),H==null||H(P),oe(!1),re(null)},[r,H]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${o("widget-border")}`,paddingBottom:"16px"},children:t.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Dp[J]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(mn,{children:e.id}),t.jsx(mn,{color:Op[J],children:m.indexType[J]})]})}),t.jsx(Ye,{title:m.section.basicInfo,onSave:i,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(pn,{label:ce?m.editor.workTitle:me?m.editor.collectionTitle:m.editor.bookTitle,value:e.title,onChange:P=>ie("title",P)}),te&&t.jsx(pn,{label:m.editor.belongsToWork,value:e.workName||"",onChange:P=>ie("workName",P)}),t.jsx(Ge,{label:m.editor.authorLabel,value:e.author||"",onChange:P=>ie("author",P)}),t.jsx(Ge,{label:m.editor.publicationYearLabel,value:e.publicationYear||"",onChange:P=>ie("publicationYear",P)}),(te||me)&&t.jsx(pn,{label:m.editor.containedIn,value:e.collection||"",onChange:P=>ie("collection",P)}),(te||me)&&t.jsx(Ge,{label:m.editor.holderLabel,value:e.holder||"",onChange:P=>ie("holder",P)}),(te||me)&&t.jsx(Ge,{label:te?m.editor.pageLabel:m.editor.volumeLabel,value:e.pages||"",onChange:P=>ie("pages",P)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(Ge,{label:m.editor.firstImageLabel,value:e.firstImage||"",onChange:P=>ie("firstImage",P)})})]})}),t.jsx(Ye,{title:m.section.description,onSave:i,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(bt,{value:e.description||"",onChange:P=>ie("description",P),placeholder:m.editor.descriptionPlaceholder})}),(((q=e.additional_works)==null?void 0:q.length)||0)>0&&t.jsx(Ye,{title:m.section.additionalWorks,onSave:i,children:t.jsx(Hp,{items:e.additional_works||[],onChange:P=>ie("additional_works",P)})}),t.jsx(Ye,{title:m.section.indexedBy,onSave:i,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Gp,{items:e.indexed_by||[],onChange:P=>ie("indexed_by",P)})}),t.jsx(Ye,{title:m.section.emendatedBy,onSave:i,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Up,{items:e.emendated_by||[],onChange:P=>ie("emendated_by",P)})}),t.jsx(Ye,{title:m.section.textResources,onSave:i,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(Gn,{items:e.resources||[],onChange:P=>ie("resources",P),onDownload:d,downloadStatuses:u,filterType:"text"})}),t.jsx(Ye,{title:m.section.imageResources,onSave:i,children:t.jsx(Gn,{items:e.resources||[],onChange:P=>ie("resources",P),onDownload:d,downloadStatuses:u,filterType:"image"})}),t.jsx(Ye,{title:m.section.sources,onSave:i,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(Ws,{items:Ms(e.sources||""),onChange:P=>ie("sources",Fs(P)),onOpenEntityPicker:se})}),(te||me)&&t.jsx(Ye,{title:m.section.provenance,onSave:i,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(bt,{value:e.provenance||"",onChange:P=>ie("provenance",P),placeholder:m.editor.provenancePlaceholder})}),te&&t.jsx(Ye,{title:m.section.otherEditions,onSave:i,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(bt,{value:e.otherEditions||"",onChange:P=>ie("otherEditions",P),placeholder:m.editor.otherEditionsPlaceholder})}),t.jsx(Ps,{entityType:J,entityId:e.id,entityTitle:e.title,parentWork:g==null?void 0:g.parentWork,parentCollection:g==null?void 0:g.parentCollection,belongsToWork:g==null?void 0:g.belongsToWork,belongsToCollection:g==null?void 0:g.belongsToCollection,childWorks:g==null?void 0:g.childWorks,childCollections:g==null?void 0:g.childCollections,containedBooks:g==null?void 0:g.containedBooks,siblingBooks:g==null?void 0:g.siblingBooks,onLinkEntity:pe,onUnlinkEntity:ge,onViewEntity:Ce,onCreateAndLink:ve,onSaveRelations:D}),l&&a&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${o("danger-soft-border")}`,background:o("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:o("danger"),fontWeight:600,marginBottom:"8px"},children:m.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"12px"},children:m.editor.dangerZoneDesc}),t.jsx("button",{onClick:a,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("danger")}`,borderRadius:"4px",background:"transparent",color:o("danger"),cursor:"pointer"},children:m.editor.deleteEntity})]}),t.jsx(Ds,{isOpen:b,entityType:h,title:_,onSelect:Re,onCancel:()=>k(!1),onCreate:()=>{k(!1),ve(j,h)},searchResults:$,onSearch:Ee,isLoading:C,excludeId:e.id}),t.jsx(Hs,{isOpen:E,entityType:O,relationField:M,inheritData:Y,onConfirm:we,onCancel:()=>I(!1)}),t.jsx(Us,{isOpen:R,title:m.action.selectBookOrWork,filterType:"all",recentEntities:ee,excludeId:e.id,onSelect:he,onCancel:()=>{oe(!1),re(null)},onSearch:ne})]})};function Hp({items:e,onChange:n}){const i=de(),r=(a,p,c)=>{const d=e.map((u,g)=>g===a?{...u,[p]:c}:u);n(d)},s=a=>n(e.filter((p,c)=>c!==a)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((a,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(Ge,{label:i.editor.bookNameLabel,value:a.book_title,onChange:c=>r(p,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(Ge,{label:i.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:c=>r(p,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Ys({items:e,onChange:n,showMeta:i,addLabel:r}){const s=de(),[l,a]=f.useState(null),p=(u,g,x)=>{const m=e.map((b,k)=>k===u?{...b,[g]:x||void 0}:b);n(m)},c=u=>{n(e.filter((g,x)=>x!==u)),l===u&&a(null)},d=()=>{n([...e,{source:""}]),a(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,g)=>{const x=l===g;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:x?`color-mix(in srgb, ${o("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>a(x?null:g),children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.2s",transform:x?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:m=>{m.stopPropagation(),c(g)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${o("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:o("muted")},children:"✕"})]}),!x&&i&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:o("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),x&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ge,{label:s.label.sourceName,value:u.source,onChange:m=>p(g,"source",m)}),t.jsx(Ge,{label:s.label.sourceBid,value:u.source_bid||"",onChange:m=>p(g,"source_bid",m)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ge,{label:s.label.titleInfo,value:u.title_info||"",onChange:m=>p(g,"title_info",m)}),t.jsx(Ge,{label:s.label.authorInfo,value:u.author_info||"",onChange:m=>p(g,"author_info",m)})]}),t.jsx(Ge,{label:s.label.edition,value:u.edition||"",onChange:m=>p(g,"edition",m)})]}),t.jsx(bt,{value:u.summary||"",onChange:m=>p(g,"summary",m),placeholder:s.editor.summaryPlaceholder}),t.jsx(bt,{value:u.comment||"",onChange:m=>p(g,"comment",m),placeholder:s.editor.commentPlaceholder}),t.jsx(bt,{value:u.additional_comment||"",onChange:m=>p(g,"additional_comment",m),placeholder:s.editor.additionalCommentPlaceholder})]})]},g)}),t.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Gp({items:e,onChange:n}){const i=de();return t.jsx(Ys,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Up({items:e,onChange:n}){const i=de();return t.jsx(Ys,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function Ks(e){var p,c,d,u,g,x,m;const n=((c=(p=e.authors)==null?void 0:p[0])==null?void 0:c.name)||"",i=((d=e.publication_info)==null?void 0:d.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(g=e.page_count)!=null&&g.number?String(e.page_count.number):((x=e.page_count)==null?void 0:x.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",a={id:e.id,title:e.title,type:e.type,author:n,publicationYear:i,holder:r,pages:s,description:l,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const b=e;if(Array.isArray(b.related_works)){const k=b.related_works.find(h=>h.relation==="part_of");k&&(a.parentWorkId=k.id,a.parentWorkName=k.title)}}if(e.type==="book"){const b=e;a.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(a.collectionId=(m=b.contained_in[0])==null?void 0:m.id)}return a}function Vp(e){const n={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.publicationYear?{year:e.publicationYear}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(n.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(n.work_id=e.workId,e.collectionId&&(n.contained_in=[{id:e.collectionId}])),n}const Yp=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:a,onSave:p,onDelete:c,onNavigate:d,renderLink:u,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:k,onRelationsChange:h,headerExtra:y,className:j,style:v}=e;de();const[_,S]=f.useState(s),$=l?s:_;f.useEffect(()=>{s!==_&&S(s)},[s]);const w=f.useCallback(()=>{const M=$==="view"?"edit":"view";l?l(M):S(M)},[$,l]),[C,N]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(M=>{M&&N(M)})},[i,r]);const E=n||C,I=f.useMemo(()=>E?Ks(E):null,[E]),O=l||!n?t.jsx("button",{onClick:w,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:$==="edit"?o("accent-bg"):"transparent",color:o($==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:$==="view"?"切换到编辑模式":"切换到查看模式",children:$==="view"?"✏️ 编辑":"👁 查看"}):null,A=t.jsxs(t.Fragment,{children:[O,y]});return!E&&!I?t.jsx(jt,{}):$==="view"?t.jsx(fi,{data:E,transport:r,onNavigate:d?M=>d(M):void 0,renderLink:u,headerExtra:A,className:j,style:v}):I?t.jsxs("div",{className:j,style:v,children:[A&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:A}),t.jsx(Vs,{data:I,onChange:a||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:d,showDelete:!!c,onDelete:c,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:k,onRelationsChange:h})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},qo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],qs=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,l]=f.useState(null),[a,p]=f.useState(""),[c,d]=f.useState(""),[u,g]=f.useState("idle"),[x,m]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{e&&(l(null),p(""),d(""),g("idle"),m(""))},[e]),f.useEffect(()=>{s&&setTimeout(()=>{var j;return(j=b.current)==null?void 0:j.focus()},100)},[s]),f.useEffect(()=>{if(u==="success"){const j=setTimeout(n,2e3);return()=>clearTimeout(j)}},[u,n]),f.useEffect(()=>{if(!e)return;const j=v=>{v.key==="Escape"&&n()};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[e,n]);const k=async()=>{if(!(!s||!a.trim())){g("submitting"),m("");try{await i({type:s,content:a.trim(),...c.trim()?{contact:c.trim()}:{}}),g("success")}catch(j){g("error"),m(j instanceof Error?j.message:"提交失败,请稍后重试")}}};if(!e)return null;const h=s&&a.trim()&&u!=="submitting",y=qo.find(j=>j.value===s);return t.jsx("div",{style:Kp,onClick:j=>{j.target===j.currentTarget&&n()},children:t.jsxs("div",{style:qp,onClick:j=>j.stopPropagation(),children:[t.jsxs("div",{style:Jp,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:Zp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:nu,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:o("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:qo.map(j=>t.jsxs("button",{onClick:()=>l(j.value),style:{...Xp,...s===j.value?Qp:{}},children:[t.jsx("span",{children:j.icon})," ",j.label]},j.value))}),t.jsx("textarea",{ref:b,value:a,onChange:j=>p(j.target.value),placeholder:(y==null?void 0:y.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...eu,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:c,onChange:j=>d(j.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:ou}),t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[a.length," / 2000"]}),u==="error"&&t.jsx("div",{style:iu,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:k,disabled:!h,style:{...tu,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},Kp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},qp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},Jp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Zp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:o("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Xp={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Qp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},eu={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},tu={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},nu={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},iu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginBottom:"12px"},ou={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},oi="--bim-feedback-fab-offset",ri=48,ru=16,su=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,a]=f.useState(!1),p=n.bottom??24;return f.useEffect(()=>{if(r||typeof document>"u")return;const c=document.documentElement;return c.style.setProperty(oi,`calc(${p+ri+ru}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(oi)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>a(!0),style:{...lu,zIndex:s??o("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.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:t.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"})})}),t.jsx(qs,{isOpen:l,onClose:()=>a(!1),onSubmit:e,feedbackListUrl:i})]})},lu={position:"fixed",width:`${ri}px`,height:`${ri}px`,borderRadius:"50%",border:"none",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:o("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},Jo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Js=({onSubmit:e})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[l,a]=f.useState(""),[p,c]=f.useState("idle"),[d,u]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var k;return(k=g.current)==null?void 0:k.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){c("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),c("success"),s(""),a(""),i("bug")}catch(k){c("error"),u(k instanceof Error?k.message:"提交失败,请稍后重试")}}},m=n&&r.trim()&&p!=="submitting",b=Jo.find(k=>k.value===n);return p==="success"?t.jsx("div",{style:Zo,children:t.jsxs("div",{style:uu,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>c("idle"),style:xu,children:"继续提交"})]})}):t.jsxs("div",{style:Zo,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Jo.map(k=>t.jsxs("button",{onClick:()=>i(k.value),style:{...au,...n===k.value?cu:{}},children:[t.jsx("span",{children:k.icon})," ",k.label]},k.value))}),t.jsx("textarea",{ref:g,value:r,onChange:k=>s(k.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...du}}),t.jsx("input",{type:"text",value:l,onChange:k=>a(k.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:gu}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:x,disabled:!m,style:{...pu,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:fu,children:d})]})},Zo={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},au={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},cu={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},du={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},pu={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},uu={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},xu={background:"none",border:"none",color:o("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},fu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginTop:"8px"},gu={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function Xo(e){return typeof e=="function"?e():e??"/api/feedback"}const Zs=({resourceId:e,apiUrl:n})=>{const[i,r]=f.useState([]),[s,l]=f.useState(!0),a=f.useCallback(async()=>{const c=Xo(n);l(!0);try{const u=await(await fetch(`${c}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);f.useEffect(()=>{a()},[a]);const p=async c=>{const d=Xo(n),u=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...c,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const g=await u.json().catch(()=>null);throw new Error((g==null?void 0:g.error)||"提交失败")}setTimeout(()=>a(),500)};return t.jsxs("div",{children:[t.jsx(Pi,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Js,{onSubmit:p})})]})},Qo={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 er(e){return e?Qo[e]??e:Qo.related}const mu={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function hu(e){return mu[e]??e}const bu={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function yu(e){return bu[e]??""}function Oi({authors:e,onNavigate:n,renderLink:i}){const{convert:r}=V(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,a)=>{const p=ji(l.role);return t.jsxs(f.Fragment,{children:[a>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Le,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:i,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},a)})}):null}function Xs(e,n){var p,c;const i=bi(e,n),r=i.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=i.buckets.filter(d=>d.key==="image"||d.key==="textImage").flatMap(d=>d.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=i.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((c=i.buckets.find(d=>d.key==="text"))==null?void 0:c.items)??[],groups:r}}function Qs(e,n){const i=(e.url?Nt(e.url):void 0)||e.name,r=Fr(e,n);return r?`${i}(${r})`:i}function Di({item:e,siblings:n,listedVolumeCounts:i}){const{convert:r}=V(),[s,l]=f.useState(!1),a=hn(e),p=!!a&&a.expected>0&&!(i!=null&&i.has(a.expected)),c=r(Qs(e,n)),d=Lt(e),u=kn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var x,m;const g=(x=e.metadata)!=null&&x.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((m=e.metadata)==null?void 0:m.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("殘片")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:r(e.color_mode==="color"?"彩色":"黑白")})]}):null;return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[c," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),g]}):t.jsxs("span",{className:"bim-d-zt-name",children:[c,g]})})(),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(Si,{item:e})})]}),t.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(g=>!g),children:r(s?"收起分冊":`展開 ${a.expected} 冊`)})})]})}function el({groups:e,listedVolumeCounts:n}){const{convert:i}=V();return t.jsx(t.Fragment,{children:e.map(r=>t.jsxs("div",{className:"bim-d-rg",children:[r.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:i(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:i(r.description)}),r.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:r.rows.map((s,l)=>t.jsx(Di,{item:s,siblings:r.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),r.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[r.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:i("鏡像")}),r.mirrors.map((s,l)=>{const a=Lt(s),p=i(Qs(s,r.mirrors));return a?t.jsxs("a",{href:a,target:"_blank",rel:"noopener noreferrer",title:s.details?i(s.details):void 0,children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:p},l)})]})]},r.key))})}const Vt=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function si(e){var i;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(i=Vt.find(r=>n.startsWith(r.key[0])))==null?void 0:i.key}const tr=12,ju=60,tl=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:a,railLinks:p})=>{var we,Ee,Re;const c=de(),{convert:d}=V(),u=f.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[g,x]=f.useState(new Map),[m,b]=f.useState(!1),[k,h]=f.useState(""),[y,j]=f.useState(!1),v=u.length<=ju,_=v||m||!!k||y,S=f.useMemo(()=>_?u:u.slice(0,tr),[u,_]);f.useEffect(()=>{if(!n||S.length===0)return;const D=S.filter(ne=>!g.has(ne));if(D.length===0)return;let se=!1;return Promise.all(D.map(ne=>n.getItem(ne).then(he=>{const q=he??{};return[ne,{id:ne,title:q.title,edition:q.edition,resources:q.resources,publication_info:q.publication_info,current_location:q.current_location,lineage:q.lineage,measure_info:q.measure_info}]}).catch(()=>[ne,{id:ne}]))).then(ne=>{se||x(he=>{const q=new Map(he);for(const[P,T]of ne)q.set(P,T);return q})}),()=>{se=!0}},[n,S,g]);const $=f.useMemo(()=>u.map(D=>g.get(D)??{id:D}),[u,g]),w=u.length>0&&u.every(D=>g.has(D)),C=!!n&&S.some(D=>!g.has(D)),N=v||_,E=f.useMemo(()=>Or($,e.version_graph,{era:k,scanOnly:y,sort:N?"year":"default"}),[$,e.version_graph,k,y,N]),I=m?E.rows:E.rows.slice(0,tr),O=E.allRows.filter(D=>D.hasImage).length,A=e.related_works||[],M=A.filter(D=>D.relation==="collected_in"),F=f.useMemo(()=>{const D=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],se=ne=>{const he=D.indexOf(ne??"");return he<0?D.length:he};return A.filter(ne=>ne.relation!=="collected_in").map((ne,he)=>({r:ne,i:he})).sort((ne,he)=>se(ne.r.relation)-se(he.r.relation)||ne.i-he.i).map(ne=>ne.r)},[A]),Y=f.useMemo(()=>{const D=bi(e.resources,e.resource_groups);return[...D.mirrors.flatMap(se=>se.items.map(ne=>({r:ne,kind:d(se.label)}))),...D.buckets.flatMap(se=>se.items.map(ne=>({r:ne,kind:d(yu(se.key))})))]},[e.resources,e.resource_groups,d]),K=e.indexed_by||[],R=e.emendated_by||[],oe=f.useMemo(()=>{var L,B,G;const D=[],se=(B=(L=e.authors)==null?void 0:L[0])==null?void 0:B.dynasty;se&&D.push({label:"成書",value:d(se)});const ne=lt(e,c.unit.juan);if(ne){const Z=(G=e.juan_count)==null?void 0:G.description;D.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[d(ne),Z&&Z!==ne?t.jsxs("span",{className:"bim-d-meta",children:["(",d(Z),")"]}):null]})})}e.loss_status&&D.push({label:"存佚",value:d(hu(e.loss_status))});const he=E.allRows.filter(Z=>Z.sortYear!=null),q=he.length>0?he.reduce((Z,ue)=>Z.sortYear<=ue.sortYear?Z:ue):null;q!=null&&q.era.era?D.push({label:"最早存世",value:d([q.era.era,q.era.reign].filter(Boolean).join(" ")),title:q.era.source==="edition"?d("據版本題名推斷"):void 0}):C&&D.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),R.length&&D.push({label:"考證",value:`${R.length} ${d("條")}`});const P=nr(e.additional_titles);P.length&&D.push({label:"又名",value:P.map(d).join("、")});const T=nr(e.attached_texts);T.length&&D.push({label:"附載",value:T.map(d).join("、")});const z=(e.additional_works||[]).map(Z=>d(Z.book_title)+(Z.n_juan!=null?` ${Z.n_juan}${d(c.unit.juan)}`:""));return z.length&&D.push({label:"附錄",value:z.join("、")}),D},[e,d,c,C,E.allRows,R.length]),re=[{value:e._edition_count??u.length,label:"版本"},{value:w?O:0,label:"有影印"},{value:K.length,label:"家著錄"}],ee=e.classification,Q=ee?[ee.l1,ee.l2,ee.l3,ee.l4].filter(Boolean).map(D=>d(D)):[],J=e.subtype?d(c.workSubtype[e.subtype]??e.subtype):"",ce=t.jsx(Zt,{title:d(e.title),byline:t.jsx(Oi,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(We,{items:[...Q,ee!=null&&ee.source?d(`據《${ee.source.split("/")[0]}》`):"",J]}),description:(we=e.description)!=null&&we.text?t.jsxs(t.Fragment,{children:[t.jsx(st,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Ee=e.description.sources)!=null&&Ee.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(D=>d(rc(D))).filter(Boolean).join(" · ")}):null]}):void 0,stats:re,facts:oe,readAction:s,foot:t.jsx(Xt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Re=e.appendix)==null?void 0:Re.map((D,se)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(D.title)}),t.jsx(st,{text:D.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},se))}),me=E.eras.length>=2?[{key:"",label:c.catalog.all},...E.eras.map(D=>({key:D,label:`${D} ${E.allRows.filter(se=>se.era.era===D).length}`}))]:[],te=[];u.length&&te.push({id:"versions",label:"版本",count:u.length}),K.length&&te.push({id:"catalogs",label:"著錄",count:K.length}),M.length&&te.push({id:"collected",label:"收入叢編",count:M.length}),F.length&&te.push({id:"related",label:"相關書目",count:F.length}),Y.length&&te.push({id:"resources",label:"在線資源",count:Y.length});const ie=u.length===0&&K.length===0,pe=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Me,{id:"versions",title:"版本",meta:t.jsx(We,{items:[d(`共 ${u.length} 種`),w&&O?d(`${O} 種有影印`):"",E.rows.length!==E.allRows.length?d(`當前 ${E.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":C&&me.length===0&&u.length>1?"":void 0,children:[me.length>0&&t.jsx(wn,{items:me,value:k,onChange:D=>{h(D),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Qr,{label:"只看有影印",checked:y,onChange:D=>{j(D),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:d(N?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("版本")}),t.jsx("th",{children:d("年代")}),t.jsx("th",{children:d("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:d("影印")})})]})}),t.jsx("tbody",{children:I.map(D=>{var se;return t.jsx(vu,{row:D,measure:(se=g.get(D.id))==null?void 0:se.measure_info,loaded:g.has(D.id),onNavigate:i,renderLink:r},`${D.id}:${g.has(D.id)?"r":"p"}`)})})]}),I.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(k||y?"當前篩選下沒有版本":"暫無版本著錄")}),E.rows.length>I.length&&t.jsx(Bt,{label:`展開其餘 ${E.rows.length-I.length} 種版本`,onClick:()=>b(!0)}),E.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:d("部分年代據版本題名推斷,非著錄原文")})]}),K.length>0&&t.jsx(ku,{items:K,transport:n,onNavigate:i,renderLink:r}),ie&&t.jsx(Me,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),ge=(D,se)=>t.jsx(Le,{id:D,label:d(se),onNavigate:i,renderLink:r,dense:!0}),Ce=f.useMemo(()=>{const D=new Map;for(const se of F){const ne=er(se.relation);D.set(ne,(D.get(ne)??0)+1)}return D.size>1?[...D.entries()].sort((se,ne)=>ne[1]-se[1]).slice(0,4).map(([se,ne])=>`${d(se)} ${ne}`).join(" · "):void 0},[F,d]),ve=t.jsxs(t.Fragment,{children:[t.jsx(ht,{id:"collected",title:"收入叢編",items:M.map(D=>ge(D.id,D.title))}),t.jsx(ht,{id:"related",title:"相關書目",meta:d(`${F.length} 部`),sub:Ce,items:F.map(D=>t.jsxs(t.Fragment,{children:[ge(D.id,D.title),t.jsx("span",{className:"bim-d-meta",title:D.note?d(D.note):void 0,children:d(er(D.relation))})]}))}),t.jsx(ht,{id:"resources",title:"在線資源",cap:6,items:Y.map(({r:D,kind:se})=>{const ne=d((D.url?Nt(D.url):void 0)||D.name),he=Lt(D);return t.jsxs(t.Fragment,{children:[he?t.jsxs("a",{href:he,target:"_blank",rel:"noopener noreferrer",children:[ne," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:ne}),se&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:se})]})})})]});return t.jsx(Jt,{railTop:l,back:a,nav:te,railLinks:p,main:pe,card:ce,side:ve})};function nr(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ir(e,n){return n((e.url?Nt(e.url):void 0)||e.name)}function vu({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=V(),a=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",c=e.holders[0],d=c?ir(c,l):e.locationName?l(e.locationName):"",u=e.images[0],g=u?Lt(u):void 0,x=e.images.map(m=>ir(m,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Le,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.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):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${d?"":" bim-d-zt-blank"}`,children:[d||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(g?t.jsx("a",{className:"bim-d-flag",href:g,target:"_blank",rel:"noopener noreferrer",title:x,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:x,children:l("有影印")}))})]})}function ku({items:e,transport:n,onNavigate:i,renderLink:r}){const s=de(),{convert:l}=V(),[a,p]=f.useState(0),c=Math.min(a,e.length-1),d=e[c],[u,g]=f.useState(new Map);return f.useEffect(()=>{if(!n)return;const x=[...new Set(e.map(b=>b.source_bid).filter(b=>!!b))];if(x.length===0)return;let m=!1;return Promise.all(x.map(b=>n.getItem(b).then(k=>{var h,y;return[b,((y=(h=k==null?void 0:k.authors)==null?void 0:h[0])==null?void 0:y.dynasty)??""]}).catch(()=>[b,""]))).then(b=>{m||g(new Map(b.filter(([,k])=>k)))}),()=>{m=!0}},[n,e]),t.jsx(Me,{id:"catalogs",title:"著錄",meta:t.jsx(We,{items:[l(`歷代書目 ${e.length} 家`),l("按著錄順序")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":l("著錄書目"),children:e.map((x,m)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":m===c,"aria-label":l(x.source),onClick:()=>p(m),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(x.source_bid??"")?l(u.get(x.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...l(x.source)].slice(0,9).map((b,k)=>t.jsx("span",{children:b},k))})]})},m))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:l(d.title_info)}),t.jsx(We,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?t.jsx(Le,{id:d.source_bid,label:l(d.source),onNavigate:i,renderLink:r,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&&t.jsx("p",{className:"bim-d-quote",children:Ue(l(d.summary))}),d.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:Ue(l(d.comment))})]}),d.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:Ue(l(d.additional_comment))})]}),!d.summary&&!d.comment&&!d.additional_comment&&!d.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:l("僅著錄書名,無提要。")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?t.jsx("button",{type:"button","aria-label":l(`上一家:${e[c-1].source}`),onClick:()=>p(c-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",l(e[c-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",e.length]}),c<e.length-1?t.jsx("button",{type:"button","aria-label":l(`下一家:${e[c+1].source}`),onClick:()=>p(c+1),children:t.jsxs("span",{"aria-hidden":"true",children:[l(e[c+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function Su(e){var n;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((n=e.year_range)==null?void 0:n[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function wu(e,n){if(!e.lineage)return null;const i=e.lineage;return{id:e.id,kind:"book",label:e.title,year:i.year,year_text:i.year_text,year_uncertain:i.year_uncertain,category:i.category,status:i.status,extant_juan:i.extant_juan,group:n[e.id],note:i.note}}function or(e,n,i){return{id:`derive:${n.ref}->${e}:${i}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function _u(e,n,i){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${i}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function $u(e,n){var d;if(n==="all")return null;const i=(d=e.collections)==null?void 0:d[n],r=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,l=r||s||!!(i!=null&&i.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!i||!l)return null;const a=r?new Set(i.groups):null,p=new Set(i.book_ids??[]);if(a&&e.node_groups)for(const[u,g]of Object.entries(e.node_groups))a.has(g)&&p.add(u);let c=null;if(i.hypothetical_ids&&(c=new Set(i.hypothetical_ids)),a){c||(c=new Set);for(const u of e.hypothetical_nodes??[])u.group&&a.has(u.group)&&c.add(u.id)}return{books:p,hypos:c}}function un(e,n,i){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const l=new Set(r.excluded_books??[]),a=r.node_groups??{},p=$u(r,i??r.default_collection??"all"),c=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,g=new Set,x=new Set;if(c){const _=new Map(n.map(E=>[E.id,E])),S=new Map((r.hypothetical_nodes??[]).map(E=>[E.id,E])),$=E=>{const I=_.get(E);if(I&&I.lineage)return(I.lineage.derived_from??[]).map(A=>A.ref);const O=S.get(E);return O?(O.derived_from??[]).map(A=>A.ref):[]},w=E=>S.has(E)?!u||u.has(E):!d||d.has(E),C=new Set,N=E=>{if(!C.has(E)){C.add(E);for(const I of $(E))l.has(I)||(w(I)||(S.has(I)?x.add(I):_.has(I)&&g.add(I)),N(I))}};for(const E of n)d&&d.has(E.id)&&!l.has(E.id)&&N(E.id);for(const E of r.hypothetical_nodes??[])u&&u.has(E.id)&&N(E.id)}const m=n.filter(_=>!l.has(_.id)).filter(_=>!d||d.has(_.id)||g.has(_.id)).map(_=>{const S=wu(_,a);return S&&g.has(_.id)&&(S.bridge=!0),S}).filter(_=>_!==null),b=(r.hypothetical_nodes??[]).filter(_=>!u||u.has(_.id)||x.has(_.id)).map(_=>{const S=Su(_);return x.has(_.id)&&(S.bridge=!0),S}),k=[...m,...b],h=new Set(k.map(_=>_.id)),y=new Set,j=[],v=_=>{y.has(_.id)||!h.has(_.source)||!h.has(_.target)||(y.add(_.id),j.push(_))};for(const _ of n)l.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!g.has(_.id)||((_.lineage.derived_from??[]).forEach((S,$)=>{v(or(_.id,S,$))}),(_.lineage.related_to??[]).forEach((S,$)=>{v(_u(_.id,S,$))}));for(const _ of r.hypothetical_nodes??[])u&&!u.has(_.id)&&!x.has(_.id)||(_.derived_from??[]).forEach((S,$)=>{v(or(_.id,S,$))});return{nodes:k,edges:j,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function nl(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function zu(e,n){const i=[],r=e.version_graph;if(!r)return i;const s=new Set(n.map(c=>c.id)),l=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),a=new Set([...s,...l]),p=(c,d)=>{a.has(d.ref)||i.push(`${c}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${c}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&i.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)||i.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const d=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>p(d,u))}return i}const il=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:s}=V();if(!e.nodes.length)return t.jsx("div",{style:{...Ou,...r},className:i,children:"暂无版本图数据"});const l=new Map,a=new Map;for(const x of e.edges)if(x.kind==="derive"){const m=l.get(x.target)??[];m.push(x),l.set(x.target,m)}else for(const m of[x.source,x.target]){const b=a.get(m)??[];b.push(x),a.set(m,b)}const p=new Map(e.nodes.map(x=>[x.id,x])),c=new Map,d=[];for(const x of e.nodes)if(x.group){const m=c.get(x.group)??[];m.push(x),c.set(x.group,m)}else d.push(x);const u=(x,m)=>(x.year??9999)-(m.year??9999);c.forEach(x=>x.sort(u)),d.sort(u);const g=e.groups.filter(x=>c.has(x.id));return t.jsxs("div",{className:i,style:{...Iu,...r},children:[e.title&&t.jsx("div",{style:Tu,children:s(e.title)}),e.description&&t.jsx("div",{style:Eu,children:s(e.description)}),g.map(x=>t.jsx(rr,{label:x.label,color:x.color,nodes:c.get(x.id),incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n},x.id)),d.length>0&&t.jsx(rr,{label:"其他",nodes:d,incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n})]})},rr=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:a})=>{const{convert:p}=V();return t.jsxs("div",{style:Ru,children:[t.jsx("div",{style:{...Nu,borderLeftColor:n??o("widget-border")},children:p(e)}),i.map(c=>t.jsx(Cu,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:a},c.id))]})},Cu=({node:e,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",a=e.bridge,{convert:p}=V();return t.jsxs("div",{style:{...Lu,borderStyle:l||a?"dashed":"solid",opacity:a?.55:e.status==="lost"?.7:1,background:a?o("bg-subtle"):void 0},title:a?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:Bu,children:[t.jsx("span",{style:Au,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Wu,children:nl(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Mu,children:[e.category&&t.jsx(Ot,{children:p(e.category)}),e.status==="lost"&&t.jsx(Ot,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(Ot,{tone:"warn",children:"残本"}),l&&t.jsx(Ot,{tone:"info",children:"假想祖本"}),a&&t.jsx(Ot,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Fu,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:Pu,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:lr,children:[t.jsx("div",{style:ar,children:"来源:"}),n.map(c=>{const d=r.get(c.source);return t.jsxs("div",{style:cr(c.confidence),children:[t.jsx("span",{style:dr,children:p(c.relation)}),t.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"&&t.jsx(sr,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:pr,children:["· ",p(c.evidence)]})]},c.id)})]}),i.length>0&&t.jsxs("div",{style:lr,children:[t.jsx("div",{style:ar,children:"关联:"}),i.map(c=>{const d=c.source===e.id?c.target:c.source,u=r.get(d);return t.jsxs("div",{style:cr(c.confidence),children:[t.jsx("span",{style:dr,children:p(c.relation)}),t.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)}),t.jsx(sr,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:pr,children:["· ",p(c.evidence)]})]},c.id)})]})]})},Ot=({children:e,tone:n="default"})=>{const r={default:{bg:o("tag-bg"),fg:o("fg")},warn:{bg:o("warn-bg"),fg:o("warn-fg")},info:{bg:o("info-bg"),fg:o("info-fg")}}[n];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},sr=({level:e})=>{const i={certain:{label:"确定",color:o("confidence-certain")},consensus:{label:"共识",color:o("confidence-consensus")},probable:{label:"推测",color:o("confidence-probable")},disputed:{label:"有争议",color:o("confidence-disputed")}}[e];return i?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${i.color}`,color:i.color,borderRadius:"8px",marginLeft:"4px"},children:i.label}):null},Iu={fontSize:"14px",color:o("fg")},Tu={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Eu={fontSize:"13px",color:o("muted"),marginBottom:"16px",lineHeight:1.6},Ru={marginBottom:"16px"},Nu={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:o("fg")},Lu={border:`1px solid ${o("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:o("bg")},Bu={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Au={fontSize:"15px",fontWeight:600},Wu={fontSize:"12px",color:o("muted")},Mu={marginBottom:"6px"},Fu={fontSize:"12px",color:o("muted"),margin:"2px 0"},Pu={fontSize:"12px",color:o("muted"),fontStyle:"italic",margin:"4px 0"},lr={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${o("widget-border")}`},ar={fontSize:"11px",color:o("muted"),marginBottom:"2px"},cr=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),dr={display:"inline-block",padding:"0 6px",fontSize:"11px",background:o("tag-bg"),color:o("fg"),borderRadius:"3px",marginRight:"6px"},pr={fontSize:"11px",color:o("muted")},Ou={padding:"20px",textAlign:"center",color:o("muted"),fontSize:"13px"},ol=({selectedNodeId:e,...n})=>{const[i,r]=f.useState("loading"),[s,l]=f.useState(null);return f.useEffect(()=>{let a=!1;return Du().then(p=>{a||(p?(l(p),r("ready")):r("missing"))}),()=>{a=!0}},[]),i==="loading"?t.jsx("div",{style:ur,children:"加载图组件中…"}):i==="missing"||!s?t.jsxs("div",{style:ur,children:[t.jsxs("div",{children:["图组件未安装。请安装 ",t.jsx("code",{children:"@xyflow/react"})," 与 ",t.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),t.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",t.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):t.jsx(Hu,{modules:s,selectedNodeId:e,...n})};async function Du(){try{const[e,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let i=!1;try{await import("@xyflow/react/dist/style.css"),i=!0}catch{i=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:n,cssLoaded:i}}catch{return null}}const Hu=({graph:e,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:l,modules:a})=>{const{ReactFlow:p,Background:c,Controls:d,Handle:u,Position:g,BaseEdge:x,EdgeLabelRenderer:m,getSmoothStepPath:b,dagre:k}=a,h=f.useMemo(()=>({lineage:$=>{var Y,K,R,oe;const w=((Y=$.data)==null?void 0:Y.stepPosition)??.85,[C,N,E]=b({sourceX:$.sourceX,sourceY:$.sourceY,sourcePosition:$.sourcePosition,targetX:$.targetX,targetY:$.targetY,targetPosition:$.targetPosition,stepPosition:w,borderRadius:5}),I=!!((K=$.data)!=null&&K.isSibling),O=I?N:$.targetX-18,A=I?E:$.targetY-12,M=(R=$.data)==null?void 0:R.labelStyle,F=(oe=$.data)==null?void 0:oe.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(x,{id:$.id,path:C,style:$.style,markerStart:$.markerStart,markerEnd:$.markerEnd}),$.label&&t.jsx(m,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${O}px,${A}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:o("bg"),border:`0.5px solid ${o("widget-border")}`,...F,...M},children:$.label})})]})}}),[x,m,b]),y=f.useMemo(()=>({version:$=>{const w=$.data,C=w.kind==="hypothetical",N=w.status==="lost",E=w.isSelected,I=w.bridge,O=w.borderColor??o("muted"),A=I||C?"dashed":"solid",M=I?.5:N?.6:1;return t.jsxs("div",{style:{background:o(I?"bg-subtle":"bg"),border:`2px ${A} ${E?o("primary"):O}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:M,boxShadow:E?o("shadow-node-selected"):C||I?"none":o("shadow-node")},title:I?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:g.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:C||!w.renderLink?w.label:w.renderLink(w.bookId,w.label)}),w.description&&t.jsx("div",{style:{fontSize:10,color:o("aux-fg"),lineHeight:1.25,marginTop:1},children:w.description}),w.yearText&&t.jsx("div",{style:{fontSize:10,color:o("aux-fg"),lineHeight:1.2},children:nl(w.yearText,void 0,w.uncertain)}),N&&t.jsx("div",{style:{fontSize:9,color:o("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:g.Right,style:{visibility:"hidden"}})]})}}),[u,g]),{convert:j}=V(),{rfNodes:v,rfEdges:_}=f.useMemo(()=>Gu(e,k,n,l,j),[e,k,n,l,j]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:t.jsxs(p,{nodes:v,edges:_,nodeTypes:y,edgeTypes:h,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(d,{showInteractive:!1})]})})};function Gu(e,n,i,r,s=l=>l??""){const p=e.layout==="LR"||!e.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(e.groups.map(y=>[y.id,y.color??o("muted")]));for(const y of e.nodes)c.setNode(y.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const y of e.edges)y.kind==="derive"&&(u.has(y.relation)||c.setEdge(y.source,y.target));n.layout(c);const g=e.nodes.map(y=>{const j=c.node(y.id),v=r?y.id===r:void 0,_={kind:y.kind,label:s(y.label),bookId:y.kind==="book"?y.id:void 0,yearText:s(y.year_text??Vu(y)),uncertain:y.year_uncertain,category:y.category,status:y.status,borderColor:y.group?d.get(y.group):void 0,renderLink:i,isSelected:v,description:s(y.description),bridge:y.bridge};return{id:y.id,type:"version",position:{x:j.x-160/2,y:j.y-90/2},data:_,draggable:!1,selected:v}}),x=.78,m=.06,b=new Map;for(const y of e.edges)y.kind==="derive"&&(b.has(y.source)||b.set(y.source,[]),b.get(y.source).push(y));const k=new Map;for(const[y,j]of b){if(j.length<=1)continue;const v=[...j].sort((S,$)=>{var N,E;const w=((N=c.node(S.target))==null?void 0:N.y)??0,C=((E=c.node($.target))==null?void 0:E.y)??0;return w-C}),_=v.length;v.forEach((S,$)=>{const w=($-(_-1)/2)*m;k.set(S.id,x+w)})}const h=e.edges.map(y=>Uu(y,k.get(y.id),s));return{rfNodes:g,rfEdges:h}}function Uu(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Yu(e.confidence),a={type:"arrowclosed",color:l,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:i(e.relation),data:{labelStyle:{color:o("fg")},isSibling:s,stepPosition:n},style:{stroke:l,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:a,markerStart:s?a:void 0,zIndex:1e3}}function Vu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Yu(e){switch(e){case"certain":return o("confidence-certain");case"consensus":return o("lineage-edge-consensus");case"probable":return o("confidence-probable");case"disputed":return o("confidence-disputed");default:return o("muted")}}const ur={padding:"40px 20px",textAlign:"center",color:o("muted"),fontSize:"13px",border:`1px dashed ${o("widget-border")}`,borderRadius:8,background:o("bg")},Hi=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:a,onCollectionChange:p,collectionsAvailable:c,collectionCounts:d,className:u,style:g})=>{var j;const[x,m]=f.useState(n),b=v=>{m(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:"显示该作品所有版本(含桥接节点)"}]]})(),h=!!(p&&k.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:o("muted"),textAlign:"center"},children:"暂无版本传承数据"});const y=a?(j=c==null?void 0:c[a])==null?void 0:j.description:void 0;return t.jsxs("div",{className:u,style:g,children:[t.jsxs("div",{style:Ku,children:[t.jsx("button",{onClick:()=>b("list"),style:Mn(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:Mn(x==="graph"),children:"关系图"}),h&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:o("muted"),marginRight:4},children:"集合:"}),k.map(([v,_])=>{const S=d==null?void 0:d[v];return t.jsxs("button",{onClick:()=>p==null?void 0:p(v),style:Mn(a===v),title:_.description,children:[_.label,S!=null?` ${S}`:""]},v)})]})]}),h&&y&&t.jsx("div",{style:{fontSize:12,color:o("muted"),marginBottom:8,padding:"4px 8px",background:o("bg-subtle"),borderRadius:4},children:y}),x==="list"?t.jsx(il,{graph:e,renderLink:i}):t.jsx(ol,{graph:e,renderLink:i,height:r,selectedNodeId:s})]})},Ku={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Mn=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${o("widget-border")}`,borderRadius:4,background:e?o("primary"):"transparent",color:o(e?"primary-fg":"fg"),cursor:"pointer"}),xr=40,fr=2,qu=9,gr={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function Fn(e){if(!e)return["",""];const n=e.split(/[ ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const rl=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,fullText:l,fullTextPending:a,chapterLink:p,railTop:c,back:d,railLinks:u})=>{var L,B,G,Z,ue,le,be,Ne,je,Pe,at;const g=de(),{convert:x}=V(),[m,b]=f.useState(null),[k,h]=f.useState(new Map),[y,j]=f.useState([]),[v,_]=f.useState(new Map),[S,$]=f.useState(!1),[w,C]=f.useState("flow"),[N,E]=f.useState(null);f.useEffect(()=>{if(!n||!e.work_id){b(null);return}let W=!1;return n.getItem(e.work_id).then(ae=>{!W&&ae&&ae.type==="work"&&b(ae)}).catch(()=>{}),()=>{W=!0}},[n,e.work_id]),f.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){E(null);return}let W=!1;return n.getLineageGraph(e.work_id).then(ae=>{W||E(ae&&ae.nodes.length>1?ae:null)}).catch(()=>{W||E(null)}),()=>{W=!0}},[n,e.work_id]),f.useEffect(()=>{const W=e.contained_in||[];if(!n||W.length===0){h(new Map);return}let ae=!1;return Promise.all(W.map(fe=>{const _e=typeof fe=="string"?fe:fe.id;return n.getItem(_e).then(xe=>[_e,xe]).catch(()=>[_e,null])})).then(fe=>{if(ae)return;const _e=new Map;for(const[xe,$e]of fe)$e&&_e.set(xe,$e);h(_e)}),()=>{ae=!0}},[n,e.contained_in]);const I=f.useMemo(()=>{const W=new Set([...(m==null?void 0:m.books)||[],...e.related_books||[]]);return W.add(e.id),[...W]},[m==null?void 0:m.books,e.related_books,e.id]),O=I.length-1;f.useEffect(()=>{if(!n||O<=0){j([]);return}const W=I.length<=xr,ae=W?I:I.slice(0,8);let fe=!1;return Promise.all(ae.map(_e=>_e===e.id?Promise.resolve({id:_e,title:e.title,edition:e.edition,year:fn(e)}):n.getItem(_e).then(xe=>{const $e=xe??{};return{id:_e,title:$e.title,edition:$e.edition,year:xe?fn($e):void 0}}).catch(()=>({id:_e})))).then(_e=>{if(fe)return;const xe=_e.filter($e=>$e.id===e.id||$e.title||$e.edition);W&&xe.sort(($e,Oe)=>($e.year??1/0)-(Oe.year??1/0)),j(xe)}),()=>{fe=!0}},[n,I,O,e]);const A=e.lineage,M=f.useMemo(()=>[...((A==null?void 0:A.derived_from)||[]).filter(W=>W.ref_type==="book").map(W=>W.ref),...((A==null?void 0:A.related_to)||[]).map(W=>W.book_id)].filter(Boolean),[A]);f.useEffect(()=>{if(!n||M.length===0){_(new Map);return}let W=!1;return Promise.all(M.map(ae=>n.getItem(ae).then(fe=>[ae,{id:ae,title:fe==null?void 0:fe.title,edition:fe==null?void 0:fe.edition}]).catch(()=>[ae,{id:ae}]))).then(ae=>{W||_(new Map(ae))}),()=>{W=!0}},[n,M]);const F=f.useMemo(()=>Xs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),Y=F.groups.reduce((W,ae)=>W+ae.rows.length+ae.mirrors.length,0),K=F.groups.length>0&&F.groups.every(W=>W.key==="_physical"),R=qt(e),oe=Vr(e),H=lt(e,g.unit.juan),re=new Set((e.contained_in||[]).map(W=>typeof W=="string"?0:Gt(W.volume_index).length).filter(W=>W>0)),ee=W=>{var _e;const ae=(_e=e.base_edition)==null?void 0:_e.find(xe=>xe.book_id===W&&xe.name);if(ae!=null&&ae.name)return ae.name;const fe=v.get(W);return(fe==null?void 0:fe.edition)||(fe==null?void 0:fe.title)||""},Q=f.useMemo(()=>{var ct,tn,dt,nn,on;const W=[];oe&&W.push({label:"版本類型",value:x(oe),title:e.edition_type||(ct=e.lineage)!=null&&ct.category?void 0:x("據版本題名推斷")}),(tn=e.publication_info)!=null&&tn.details?W.push({label:"刊印",value:x(e.publication_info.details)}):(R.era||R.reign)&&W.push({label:"刊寫年代",value:x([R.era,R.reign].filter(Boolean).join(" ")),title:R.source==="edition"?x("據版本題名推斷"):void 0}),H&&W.push({label:"卷帙",value:x(H)});const ae=(e.contained_in||[]).flatMap(Se=>typeof Se=="string"?[]:Gt(Se.volume_index));ae.length&&W.push({label:"冊次",value:x(`第 ${Sn(ae,g.unit.volume)} ${g.unit.volume}(${ae.length} ${g.unit.volume})`)});const fe=(((dt=e.lineage)==null?void 0:dt.derived_from)||[]).find(Se=>Se.relation==="底本"&&Se.ref_type==="book");fe&&ee(fe.ref)&&W.push({label:"底本",value:t.jsx(Le,{id:fe.ref,label:x(ee(fe.ref)),onNavigate:i,renderLink:r,dense:!0})});const _e=(e.base_edition||[]).filter(Se=>Se&&Se.name);for(const Se of["底本","配補","參校"]){if(Se==="底本"&&fe&&ee(fe.ref))continue;const Je=_e.filter(Te=>Te.role===Se);Je.length&&W.push({label:Se,value:Je.map((Te,kt)=>t.jsxs(f.Fragment,{children:[kt>0&&"、",Te.book_id?t.jsx(Le,{id:Te.book_id,label:x(Te.name),onNavigate:i,renderLink:r,dense:!0}):x(Te.name)]},kt))})}const xe=(e.provenance||[]).filter(Se=>Se&&Se.institution),$e=(e.resources||[]).filter(Se=>(Se.types||(Se.type?[Se.type]:[])).includes("physical"));if(xe.length){W.push({label:"存藏",value:xe.slice(0,2).map(Te=>x(Te.institution)).join("、")+(xe.length>2?x(` 等 ${xe.length} 處`):"")});const Se=xe.filter(Te=>Te.call_number).slice(0,2).map(Te=>`${x(Te.institution)} ${Te.call_number}`);Se.length&&W.push({label:"索書號",value:Se.join(";")+(xe.filter(Te=>Te.call_number).length>2?"…":"")});const Je=xe.flatMap(Te=>Te.seals||[]).filter(Boolean);Je.length&&W.push({label:"藏印",value:x(Je.join("、"))})}else $e.length?W.push({label:"存藏",value:$e.slice(0,2).map(Se=>x(Se.name)).join("、")+($e.length>2?x(` 等 ${$e.length} 處`):"")}):(nn=e.current_location)!=null&&nn.name&&W.push({label:"存藏",value:x(e.current_location.name)});const Oe=e.physical_description;if(Oe){const Se=[["行款",Oe.leaf_style],["裝幀",Oe.binding],["尺寸",Oe.dimensions],["品相",Oe.condition]];for(const[Je,Te]of Se)Te&&Te.trim()&&W.push({label:Je,value:x(Te)})}(on=e.page_count)!=null&&on.description&&W.push({label:g.label.pageCount,value:x(e.page_count.description)});const qe=[...Xn(e.additional_titles),...Xn(e.attached_texts)];return qe.length&&W.push({label:"又名",value:qe.map(x).join("、")}),W},[e,x,g,R,oe,H,v,i,r]),J=x(e.title),ce=e.edition?x(e.edition):void 0,me=((L=e.lineage)==null?void 0:L.year_text)||"",te=t.jsx(Zt,{kind:"版本",title:J,subtitle:ce,byline:t.jsx(Oi,{authors:e.authors??(m==null?void 0:m.authors),onNavigate:i,renderLink:r}),meta:(()=>{const W=[oe?x(oe):"",R.era?x([R.era,R.reign].filter(Boolean).join("")):"",H?x(H):""].filter(Boolean);return W.length?t.jsx("span",{className:"bim-d-tags",children:W.map((ae,fe)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(fe,2)}`,children:ae},fe))}):null})(),description:(B=e.description)!=null&&B.text?t.jsx(st,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:vi((G=e.description)==null?void 0:G.text)?6:void 0,facts:Q,readAction:s,secondaryAction:s&&Y>0&&!K?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(Xt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),ie=e.contained_in||[],pe=(l==null?void 0:l.chapters)||[],ge=pe[0]&&Fn(pe[0].title)[0].slice(-1)||"章",Ce=!!((Z=A==null?void 0:A.derived_from)!=null&&Z.length||(ue=A==null?void 0:A.related_to)!=null&&ue.length||(le=e.appendix)!=null&&le.length),ve=[];(pe.length||F.text.length||a)&&ve.push({id:"fulltext",label:"全文",count:pe.length?x(`${pe.length} ${ge}`):void 0}),F.groups.length&&ve.push({id:"images",label:K?"館藏":"影印",count:Y}),Ce&&ve.push({id:"lineage",label:"版本源流"}),ie.length&&ve.push({id:"collections",label:"收入叢編",count:ie.length}),(be=e.location_history)!=null&&be.length&&ve.push({id:"provenance",label:"流轉歷史"});const we=W=>(p==null?void 0:p(W))??null,Ee=pe[0],Re=Ee?we(Ee.file):null,D=S?pe:pe.slice(0,qu),se=(W,ae,fe)=>W?t.jsx("a",{className:fe,href:W.href??"#",onClick:W.onClick?_e=>{_e.metaKey||_e.ctrlKey||(_e.preventDefault(),W.onClick())}:void 0,children:ae}):t.jsx("span",{className:fe,children:ae}),ne=t.jsxs(t.Fragment,{children:[(pe.length>0||F.text.length>0||a)&&t.jsxs(Me,{id:"fulltext",title:"全文",meta:pe.length>0?t.jsx(We,{items:[x(`${pe.length} ${ge}`),(Ne=l==null?void 0:l.source)!=null&&Ne.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[a&&!Ee&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),Ee&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${Fn(Ee.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((Ee.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),se(Re,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),pe.length>1&&t.jsx("ul",{className:"bim-d-chap",children:D.map(W=>{const[ae,fe]=Fn(W.title);return t.jsx("li",{children:se(we(W.file),t.jsxs(t.Fragment,{children:[ae&&t.jsx("b",{children:x(ae)}),x(fe||W.file)]}))},W.file)})}),pe.length>D.length&&t.jsx(Bt,{label:`展開其餘 ${pe.length-D.length} ${ge}`,onClick:()=>$(!0)}),F.text.length>0&&t.jsxs(t.Fragment,{children:[(pe.length>0||a)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:F.text.map((W,ae)=>t.jsx(Di,{item:W,siblings:F.text,listedVolumeCounts:re},`${W.id||W.url||W.name}-${ae}`))})})]})]}),F.groups.length>0&&t.jsx(Me,{id:"images",title:K?"館藏":"影印",meta:t.jsx(We,{items:[F.groups.length>1?x(`${F.groups.length} 組`):"",x(`${Y} 處`)]}),children:t.jsx(el,{groups:F.groups,listedVolumeCounts:re})}),Ce&&t.jsx(Me,{id:"lineage",title:"版本源流",meta:(je=A==null?void 0:A.derived_from)!=null&&je.length?x("據版本傳承著錄"):void 0,action:N?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":x("源流視圖"),children:[t.jsx("button",{type:"button","aria-pressed":w==="flow",onClick:()=>C("flow"),children:x("卡片")}),t.jsx("button",{type:"button","aria-pressed":w==="graph",onClick:()=>C("graph"),children:x("關係圖")})]}):void 0,children:w==="graph"&&N?t.jsx(Hi,{graph:N,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(W,ae)=>t.jsx(Le,{id:W,label:x(ae),onNavigate:i,renderLink:r,dense:!0})}):t.jsx(Zu,{data:e,heading:ce||J,yearText:me,refName:ee,onNavigate:i,renderLink:r})}),ie.length>0&&t.jsx(Me,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:ie.map((W,ae)=>{var Oe,qe;const fe=typeof W=="string"?W:W.id,_e=typeof W=="string"?[]:Gt(W.volume_index),xe=k.get(fe),$e=(xe==null?void 0:xe._member_count)||((Oe=xe==null?void 0:xe.books)==null?void 0:Oe.length)||((qe=xe==null?void 0:xe.contained_works)==null?void 0:qe.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Le,{id:fe,label:xe?x(xe.title):fe,onNavigate:i,renderLink:r,dense:!0}),_e.length>0&&t.jsx(Ju,{volumes:_e,unit:g.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${$e?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:$e>0&&x(`全 ${$e} ${g.unit.bu}`)})]},`${fe}-${ae}`)})})})}),(Pe=e.location_history)!=null&&Pe.length?t.jsx(Me,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((W,ae)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(W.name)}),([W.start_date,W.end_date].filter(Boolean).join("—")||W.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(We,{items:[[W.start_date,W.end_date].filter(Boolean).join("—"),W.description?x(W.description):""]})})]},ae))})}):null,ve.length===0&&t.jsx(Me,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),he=y.findIndex(W=>W.id===e.id),q=I.length<=xr,P=q&&he>=0?y.slice(Math.max(0,he-fr),he+fr+1):y.filter(W=>W.id!==e.id),T=t.jsxs(t.Fragment,{children:[m&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:x(g.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Le,{id:m.id,label:x(m.title),onNavigate:i,renderLink:r})}),t.jsx(We,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(m.authors||[]).slice(0,2).map(W=>`${W.dynasty?`〔${x(W.dynasty)}〕`:""}${x(W.name)}`),x(lt(m,g.unit.juan)),m._edition_count?x(`${m._edition_count} 種版本`):""]}),((at=m.description)==null?void 0:at.text)&&t.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:x(m.description.text.replace(/[#*_>`[\]]/g,""))})]}),O>0&&P.length>0&&t.jsxs("div",{children:[t.jsx(ht,{id:"siblings",timeline:!0,title:q?"同作品版本":g.relation.siblingVersions,meta:x(q?"按年代":`${O} 種`),cap:P.length,items:P.map(W=>W.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(W.edition||W.title||W.id)}):t.jsx(Le,{id:W.id,label:x(W.edition||W.title||W.id),onNavigate:i,renderLink:r,dense:!0})),metas:P.map(W=>[W.year!=null?W.year<0?`前${-W.year}`:String(W.year):"",W.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:P.findIndex(W=>W.id===e.id)}),m&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Le,{id:m.id,label:x(`在作品頁看全部 ${I.length} 種 →`),onNavigate:i,renderLink:r,dense:!0})})]})]}),z=e.work_id?t.jsx(Xr,{caption:g.section.belongsToWork,children:t.jsx(Le,{id:e.work_id,label:m?x(m.title):" ",onNavigate:i,renderLink:r,dense:!0})}):void 0;return t.jsx(Jt,{railTop:c,back:d,up:z,nav:ve,railLinks:u,main:ne,card:te,side:T})};function Ju({volumes:e,unit:n}){const{convert:i}=V();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${Sn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}function Zu({data:e,heading:n,yearText:i,refName:r,onNavigate:s,renderLink:l}){var h;const{convert:a}=V(),p=e.lineage,c=(p==null?void 0:p.derived_from)||[],d=c.filter(y=>y.ref_type!=="book"),u=c.filter(y=>y.ref_type==="book"&&y.relation==="底本"),g=c.filter(y=>y.ref_type==="book"&&y.relation!=="底本"),x=(p==null?void 0:p.related_to)||[],m=c.length>0||x.length>0,b=y=>y&&gr[y]?a(`(${gr[y]})`):"",k=(y,j)=>t.jsx(Le,{id:y,label:a(j||y),onNavigate:s,renderLink:l,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[m&&t.jsxs("ol",{className:"bim-d-lf-list",children:[d.map((y,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(y.relation||"祖本")}),t.jsx("span",{className:"bim-d-lf-name",children:a("擬構祖本")}),y.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[a(y.evidence),b(y.confidence)]})]})},`a-${j}`)),u.map((y,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(y.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:k(y.ref,r(y.ref))}),y.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[a(y.evidence),b(y.confidence)]})]})},`b-${j}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a("本版")}),t.jsx("span",{className:"bim-d-lf-name",children:n}),i&&t.jsx("span",{className:"bim-d-lf-yr",children:a(i)})]}),g.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:g.map((y,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(y.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:k(y.ref,r(y.ref))}),y.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[a(y.evidence),b(y.confidence)]})]},j))})]}),x.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:a("翻刻 · 衍生")}),t.jsx("span",{className:"bim-d-lf-chips",children:x.map((y,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:y.evidence?a(y.evidence):void 0,children:[k(y.book_id,r(y.book_id)),t.jsx("span",{className:"bim-d-meta",children:a(y.relation)})]},j))})]})]}),(h=e.appendix)==null?void 0:h.map((y,j)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:a("附記")})," ",a(y.title)]}),t.jsx(st,{text:y.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${j}`)),(p==null?void 0:p.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:a(p.note)})]})}const Pn=16,Xu=200,Qu=16,sl=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,railTop:a,back:p,railLinks:c})=>{var D,se,ne,he,q,P,T;const d=de(),{convert:u}=V(),[g,x]=f.useState(""),[m,b]=f.useState(!1),[k,h]=f.useState(null),[y,j]=f.useState(""),v=f.useMemo(()=>Gr(e,n),[e,n]),[_,S]=f.useState(new Map),$=!!i&&v.rows.length>0&&v.rows.length<=Xu,w=$&&v.rows.every(z=>!z.id||_.has(z.id)),C=z=>{var L;return si(z?(L=_.get(z))==null?void 0:L.l1:void 0)},N=f.useMemo(()=>{const z=g.trim(),L=z?u(z):"";return v.rows.filter(B=>{var Z,ue;if(y&&si(B.id?(Z=_.get(B.id))==null?void 0:Z.l1:void 0)!==y)return!1;if(!L)return!0;const G=B.id&&((ue=_.get(B.id))==null?void 0:ue.title)||B.title;return u(G).includes(L)||(B.subItems||[]).some(le=>u(le).includes(L))})},[v.rows,g,y,_,u]),E=m?N:N.slice(0,Pn),I=f.useMemo(()=>($?v.rows:E).filter(z=>z.id&&!_.has(z.id)).map(z=>z.id),[$,v.rows,E,_]);f.useEffect(()=>{if(!i||I.length===0)return;let z=!1;const L=I.slice(0,Qu);return Promise.all(L.map(B=>i.getItem(B).then(G=>{var le,be;const Z=G??{},ue={title:Z.title,edition:Z.edition,authors:Z.authors,measure:G?lt(G,d.unit.juan):void 0,versionCount:Z._edition_count??((le=Z.books)==null?void 0:le.length),l1:((be=Z.classification)==null?void 0:be.l1)||void 0};return[B,ue]}).catch(()=>[B,{}]))).then(B=>{z||S(G=>{const Z=new Map(G);for(const[ue,le]of B)Z.set(ue,le);return Z})}),()=>{z=!0}},[i,I,d.unit.juan]);const O=(e.contained_in||[])[0];f.useEffect(()=>{if(!O){h(null);return}if(h({id:O}),!i)return;let z=!1;return i.getItem(O).then(L=>{z||h({id:O,title:L==null?void 0:L.title})}).catch(()=>{}),()=>{z=!0}},[i,O]);const A=f.useMemo(()=>Xs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),M=A.text.length+A.groups.reduce((z,L)=>z+L.rows.length+L.mirrors.length,0),F=e.contained_works||[],Y=new Set(v.rows.map(z=>z.id).filter(Boolean)),K=F.length>0&&!F.every(z=>Y.has(z.id)),R=(()=>{const z=v.rows.map(L=>L.edition).filter(Boolean);return z.length>1&&new Set(z).size===1})(),oe=v.rows.some(z=>z.volumes.length>0||z.expected!=null),H=e._member_count||((D=e.books)==null?void 0:D.length)||F.length,re=lt(e,d.unit.juan),ee=e.count,Q=z=>typeof z=="number"&&Number.isFinite(z)?z:null,J=Q(ee==null?void 0:ee.juan)??Q((se=e.juan_count)==null?void 0:se.number),ce=Q(ee==null?void 0:ee.ce)??(v.totalVolumes||null),me=[{value:v.rows.length,label:"子目"},{value:J??0,label:d.unit.juan},{value:ce??0,label:d.unit.volume}],te=f.useMemo(()=>{var B,G;const z=[];if((B=e.publication_info)!=null&&B.details&&z.push({label:"刊印",value:u(e.publication_info.details)}),H&&H!==v.rows.length){const Z=e._member_type==="Book"?"所收版本":e._member_type==="Work"?"所收作品":"成員";z.push({label:u(Z),value:`${H} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")})}const L=[Q(ee==null?void 0:ee.zhong)!=null?`${ee.zhong} 種`:"",Q(ee==null?void 0:ee.han)!=null?`${ee.han} 函`:""].filter(Boolean);return L.length&&z.push({label:"應收",value:u(L.join(" "))}),J==null&&re&&z.push({label:"卷帙",value:u(re),title:(G=e.juan_count)!=null&&G.description?u(e.juan_count.description):void 0}),z},[e,H,v.rows.length,J,re,ee,u,d]),ie=f.useMemo(()=>{if(!w)return[];const z=new Map;for(const B of v.rows){const G=C(B.id);G&&z.set(G,(z.get(G)??0)+1)}const L=Vt.filter(B=>(z.get(B.key)??0)>0);return L.length<2?[]:[{key:"",label:`${d.catalog.all} ${v.rows.length}`},...L.map(B=>({key:B.key,label:`${B.label} ${z.get(B.key)}`}))]},[w,v.rows,_,d]),pe=f.useMemo(()=>{if(!w||!v.rows.some(G=>G.volumes.length>0))return null;const z=[],L=v.rows.filter(G=>G.volumes.length>0).map(G=>({k:C(G.id)??"",from:Math.min(...G.volumes),to:Math.max(...G.volumes)})).sort((G,Z)=>G.from-Z.from);for(const G of L){const Z=G.to-G.from+1,ue=z[z.length-1];ue&&ue.key===G.k?(ue.to=Math.max(ue.to,G.to),ue.n+=Z):z.push({key:G.k,from:G.from,to:G.to,n:Z})}const B=L.reduce((G,Z)=>Math.max(G,Z.to),0);return z.length>1&&z.some(G=>G.key)?{segs:z,last:B}:null},[w,v.rows,_]),ge=(ne=e.description)==null?void 0:ne.text,Ce=t.jsx(Zt,{kind:"叢編",title:u(e.title),byline:t.jsx(Oi,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(We,{items:[e.subtype==="work_collection"?u("作品集"):"",(he=e.publication_info)!=null&&he.year?u(e.publication_info.year):""]}),description:ge||(q=e.history)!=null&&q.length?t.jsxs(t.Fragment,{children:[ge&&t.jsx(st,{text:ge,style:{fontSize:15,lineHeight:1.85}}),(P=e.history)!=null&&P.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((z,L)=>t.jsx("li",{children:u(z)},L))}):null]}):void 0,clampDescription:vi(ge)||(((T=e.history)==null?void 0:T.length)??0)>2?6:void 0,stats:me,facts:te,foot:t.jsx(Xt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:pe&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:u("全帙冊次分佈")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":u("全帙冊次分佈"),children:pe.segs.map((z,L)=>{const B=Vt.find(G=>G.key===z.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!B,title:B?u(`${B.label} 第 ${z.from}–${z.to} 冊`):void 0,"aria-label":u(B?`只看${B.label}`:"未分類"),"aria-pressed":!!B&&y===z.key,style:{flexGrow:z.n,background:o(B?B.token:"rule")},onClick:()=>{B&&(j(y===z.key?"":z.key),b(!1))}},L)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:u(`第 1 ${d.unit.volume}`)}),t.jsx("span",{children:u("點色段篩選部類")}),t.jsx("span",{children:u(`第 ${pe.last} ${d.unit.volume}`)})]})]})}),ve=[];v.rows.length&&ve.push({id:"titles",label:"子目",count:v.rows.length}),M&&ve.push({id:"resources",label:"影印與全文",count:M}),K&&ve.push({id:"works",label:d.section.containedWorks,count:F.length});const we=t.jsxs(t.Fragment,{children:[v.rows.length>0&&t.jsxs(Me,{id:"titles",title:"子目",meta:t.jsx(We,{items:[u(`${v.rows.length} ${d.unit.items}`),v.totalVolumes?u(`全帙 ${v.totalVolumes} ${d.unit.volume}`):"",N.length!==v.rows.length?u(`當前 ${N.length} ${d.unit.items}`):""]}),action:l,children:[(v.rows.length>Pn||ie.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ie.length>0&&t.jsx(wn,{items:ie,value:y,onChange:z=>{j(z),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),v.rows.length>Pn&&t.jsx("input",{type:"search",className:"bim-d-find",value:g,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:z=>{x(z.target.value),b(!1)}})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[oe&&t.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),t.jsx("th",{children:u("書名")}),t.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),t.jsx("tbody",{children:E.map((z,L)=>{var Ne;const B=z.id?_.get(z.id):void 0,G=B!=null&&B.title&&z.title===z.id?B.title:z.title,Z=((B==null?void 0:B.authors)||[]).find(je=>je&&je.name),ue=[Z?`${Z.dynasty?`〔${u(Z.dynasty)}〕`:""}${u(Z.name)}${Z.role?` ${u(Z.role)}`:""}`:"",B!=null&&B.measure?u(B.measure):"",(Ne=z.subItems)!=null&&Ne.length?z.subItems.map(je=>u(je)).join("、"):"",(B!=null&&B.edition||z.edition)&&!R?u((B==null?void 0:B.edition)||z.edition||""):""].filter(Boolean),le=Vt.find(je=>je.key===C(z.id)),be=z.volumes.length>0?u(`第 ${Sn(z.volumes,d.unit.volume)} ${d.unit.volume}`):z.expected!=null?u(`${z.found??0}/${z.expected} ${d.unit.volume}`):"";return t.jsxs("tr",{children:[oe&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${be?"":" bim-d-zt-blank"}`,children:[le&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:o(le.token)}}),be||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[z.id?t.jsx(Le,{id:z.id,label:u(G),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(G)}),ue.length>0?t.jsx(We,{items:ue}):z.id&&!B&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${B!=null&&B.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:B!=null&&B.versionCount?u(`${B.versionCount} 種`):""})]},`${z.id??z.title}-${L}`)})})]}),E.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),N.length>E.length&&t.jsx(Bt,{label:`展開其餘 ${N.length-E.length} ${d.unit.items}`,onClick:()=>b(!0)})]}),M>0&&t.jsxs(Me,{id:"resources",title:"影印與全文",meta:u(`${M} 處`),children:[A.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[A.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:A.text.map((z,L)=>t.jsx(Di,{item:z,siblings:A.text},`${z.id||z.url||z.name}-${L}`))})})]}),t.jsx(el,{groups:A.groups})]}),v.rows.length===0&&M===0&&t.jsx(Me,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),Ee=K?t.jsx(ht,{id:"works",title:d.section.containedWorks,meta:u(`${F.length} 種`),cap:12,items:F.map(z=>t.jsx(Le,{id:z.id,label:u(z.title),onNavigate:r,renderLink:s,dense:!0}))}):null,Re=k?t.jsx(Xr,{caption:"上級叢編",children:t.jsx(Le,{id:k.id,label:u(k.title||k.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(Jt,{railTop:a,back:p,up:Re,nav:ve,railLinks:c,main:we,card:Ce,side:Ee})},ex=16,On=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function mr(e){if(!e)return On.length;const n=On.indexOf(e);return n===-1?On.length:n}const tx={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function xt(e){return e==null?"":e<0?`前${-e}`:String(e)}const nx={秦:[-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]},ll=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:a})=>{var se,ne,he,q,P;const p=de(),{convert:c}=V(),[d,u]=f.useState("全部"),[g,x]=f.useState(!1),[m,b]=f.useState("default"),[k,h]=f.useState(new Map),y=f.useMemo(()=>(e.works||[]).map(T=>{const z=k.get(T.work_id);return{id:T.work_id,title:(z==null?void 0:z.title)??T.title??T.work_id,role:T.role||"",cls:yi(T.role),versionCount:z==null?void 0:z.versionCount,section:z==null?void 0:z.cls,l1:z==null?void 0:z.l1,measure:z==null?void 0:z.measure,hasImage:z==null?void 0:z.hasImage,loaded:!!(z!=null&&z.loaded)}}),[e.works,k]),j=f.useMemo(()=>Hr((e.works||[]).map(T=>T.role)),[e.works]),v=f.useMemo(()=>{const T=d==="全部"?y:y.filter(z=>z.cls===d);return m==="versions"?[...T].sort((z,L)=>(L.versionCount??-1)-(z.versionCount??-1)):T},[y,d,m]),_=g?v:v.slice(0,ex),S=f.useMemo(()=>_.filter(T=>!k.has(T.id)).map(T=>T.id),[_,k]);f.useEffect(()=>{if(!n||S.length===0)return;let T=!1;return Promise.all(S.map(z=>n.getItem(z).then(L=>{var ue,le,be,Ne,je;const B=L??{},G=B._edition_count??(((ue=B.books)==null?void 0:ue.length)??0)+(((le=B.collections)==null?void 0:le.length)??0),Z=[(be=B.classification)==null?void 0:be.l1,(Ne=B.classification)==null?void 0:Ne.l2].filter(Boolean).join(" ");return[z,{id:z,title:B.title,versionCount:G,loaded:!0,cls:Z||void 0,l1:((je=B.classification)==null?void 0:je.l1)||void 0,measure:L&<(L,p.unit.juan)||void 0,hasImage:!!(B.has_image??B._has_image)}]}).catch(()=>[z,{id:z,loaded:!0}]))).then(z=>{T||h(L=>{const B=new Map(L);for(const[G,Z]of z)B.set(G,Z);return B})}),()=>{T=!0}},[n,S,p.unit.juan]);const $=f.useMemo(()=>{const T=new Map;for(const z of e.alt_names||[]){const L=z.type||p.section.aliases;T.has(L)||T.set(L,[]),T.get(L).push(z.name)}return[...T.entries()].sort((z,L)=>mr(z[0])-mr(L[0])).map(([z,L])=>({label:z,names:L}))},[e.alt_names,p]),w=e.birth_year??((se=e.dates)==null?void 0:se.birth)??void 0,C=e.death_year??((ne=e.dates)==null?void 0:ne.death)??void 0,N=(he=e.dates)==null?void 0:he.floruit,E=w!=null||C!=null?`${xt(w)||"?"}—${xt(C)||"?"}`:Array.isArray(N)&&N.length===2&&N.every(T=>Number.isFinite(T))?`活躍於 ${xt(N[0])}—${xt(N[1])}`:"",I=new Set(["本名","字","號","号"]),O=$.filter(T=>I.has(T.label)),A=$.filter(T=>!I.has(T.label)),M=A.reduce((T,z)=>T+z.names.length,0),F=f.useMemo(()=>{const T=[];for(const L of O)T.push({label:L.label,value:L.names.map(B=>c(B)).join("、")});const z=(e.works||[]).length;return z&&T.push({label:"著作",value:`${z} ${c("種")}`}),T},[e.works,O,c]),Y=T=>{var z;return(z=$.find(L=>T.includes(L.label)))==null?void 0:z.names[0]},K=Y(["字"]),R=Y(["號","号"]),oe=[K?`字${K}`:"",R?`號${R}`:""].filter(Boolean).join(","),H=e.native_place,re=e.dynasty?nx[e.dynasty]:void 0,ee=(()=>{if(!re||w==null||C==null||C<w)return null;const[T,z]=re,L=Math.max(w,T),B=Math.min(C,z);if(B<=L)return null;const G=z-T;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":c(`${xt(w)}—${xt(C)},一生 ${C-w+1} 年`),children:t.jsx("i",{style:{left:`${(L-T)/G*100}%`,width:`${(B-L)/G*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:c(`${xt(T)} ${e.dynasty}`)}),t.jsx("span",{children:c(`一生 ${C-w+1} 年`)}),t.jsx("span",{children:xt(z)})]})]})})(),Q=f.useMemo(()=>{if(!n||y.length===0||y.some(L=>!L.loaded))return null;const T=new Map;for(const L of y){const B=si(L.l1);B&&T.set(B,(T.get(B)??0)+1)}const z=Vt.map(L=>({...L,n:T.get(L.key)??0})).filter(L=>L.n>0);return z.length?z:null},[y,n]),J=t.jsxs(Zt,{kind:tx[e.subtype]??"人物",title:c(e.primary_name||e.title),subtitle:oe?c(oe):void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(We,{items:[e.dynasty?c(e.dynasty):"",E?c(E):"",H?c(`${H}人`):""]}),ee]}),description:(q=e.description)!=null&&q.text?t.jsx(st,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:vi((P=e.description)==null?void 0:P.text)?6:void 0,facts:F,foot:t.jsx(Xt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[M>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c(`更多別名(${M})`)}),t.jsx("dl",{children:A.map(T=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:c(T.label)}),t.jsx("dd",{children:T.names.map(z=>c(z)).join("、")})]},T.label))})]}),Q&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:c("著作分佈")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:Q.map(T=>t.jsx("i",{style:{flexGrow:T.n,background:o(T.token)}},T.key))}),t.jsx("div",{className:"bim-d-dist-key",children:Q.map(T=>t.jsxs("span",{children:[t.jsx("i",{style:{background:o(T.token)}}),c(T.label)," ",T.n]},T.key))})]})]}),ce=f.useMemo(()=>y.filter(T=>T.loaded&&(T.versionCount??0)>0).sort((T,z)=>(z.versionCount??0)-(T.versionCount??0)).slice(0,3),[y]),me=!!n&&y.length>=3&&_.some(T=>!T.loaded),te=d==="全部"&&(me||ce.length>=2),ie=e.external_ids||{},pe=[];ie.cbdb_id!=null&&pe.push({label:"CBDB",id:String(ie.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${ie.cbdb_id}`,note:ie.cbdb_match==="auto"?"自動匹配":void 0});const ge=ie.wikidata_id;ge&&pe.push({label:"Wikidata",id:ge,href:`https://www.wikidata.org/wiki/${ge}`});const Ce=ie.viaf_id;Ce&&pe.push({label:"VIAF",id:Ce,href:`https://viaf.org/viaf/${Ce}`});const ve=j.map(T=>({key:T.cls,label:`${T.label} ${T.count}`})),we=[...te&&!me?[{id:"featured",label:"著作舉要",count:ce.length}]:[],...y.length?[{id:"works",label:"全部著作",count:y.length}]:[],...pe.length?[{id:"external",label:"站外資料",count:pe.length}]:[]],Ee=te?t.jsxs(Me,{id:"featured",title:"著作舉要",children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:c("存世版本最多的三部")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":me||void 0,children:[me&&[0,1,2].map(T=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},T)),!me&&ce.map(T=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Le,{id:T.id,label:c(T.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx(We,{items:[T.section?c(T.section):"",T.measure?c(T.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:T.versionCount}),t.jsx("span",{children:c("種版本")}),T.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("有影印")})]})]},T.id))]})]}):null,Re=y.length===0?t.jsx(Me,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該人物的關聯作品。")})}):t.jsxs(t.Fragment,{children:[Ee,t.jsxs(Me,{id:"works",title:"著作",meta:t.jsx(We,{items:[c(`共 ${y.length} 種`),v.length!==y.length?c(`當前 ${v.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ve.length>1&&t.jsx(wn,{items:ve,value:d,onChange:T=>{u(T),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":m==="versions",onClick:()=>{m==="default"&&x(!0),b(T=>T==="default"?"versions":"default")},children:c(m==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("作品")}),t.jsx("th",{children:c("部類")}),t.jsx("th",{children:c("職任")}),t.jsx("th",{children:c("存世版本")}),t.jsx("th",{"aria-label":c("影印")})]})}),t.jsx("tbody",{children:_.map(T=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Le,{id:T.id,label:c(T.title),onNavigate:i,renderLink:r,dense:!0}),T.measure?t.jsx(We,{items:[c(T.measure)]}):!T.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${T.section||T.loaded?"":" bim-d-zt-blank"}`,children:T.section?c(T.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${T.role?"":" bim-d-zt-blank"}`,children:T.role?c(T.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${T.loaded?"":" bim-d-zt-blank"}`,children:T.loaded?T.versionCount?c(`${T.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:c("未著錄")}):""}),t.jsx("td",{className:T.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:T.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("有影印")})})]},T.id))})]}),_.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("該職任下的著作尚未著錄。")}),v.length>_.length&&t.jsx(Bt,{label:`展開其餘 ${v.length-_.length} 種著作`,onClick:()=>x(!0)})]})]}),D=pe.length>0?t.jsx(ht,{id:"external",title:"站外資料",items:pe.map(T=>t.jsxs("a",{href:T.href,target:"_blank",rel:"noopener noreferrer",children:[T.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:pe.map(T=>T.id),foot:ie.cbdb_id!=null&&ie.cbdb_match==="auto"?c("CBDB 為自動匹配,未經人工核對"):void 0}):null;return t.jsx(Jt,{railTop:s,back:l,nav:we,railLinks:a,main:Re,card:J,side:D})},Gi="(max-width: 719px)",ix=`${Gi}, (pointer: coarse)`,al=`
|
|
791
|
+
`)){const r=Ti(i);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=i.trim();!s||Ei.test(s)||n.push({kind:"body",text:i})}return n}function Is(e){if(!e)return[];const n=$n(e);if(n==="unknown")return To(e);const i=[];for(const{heading:r,body:s}of ud(e)){r&&i.push(r);const l=$s(s);if(l.length!==0){if(Cs(s)){i.push(...To(s));continue}if(n==="record"){const a=l.join(" ");a&&i.push({kind:"body",text:a})}else for(const a of l){const p=zs(a);p.length&&i.push({kind:"body",text:p.join(" ")})}}}return i}const Ts=e=>e;function Es(e,n=Ts){if(e.indexOf("《")<0)return n(e);const i=[],r=/《([^《》\n]+)》/g;let s=0,l=0,a;for(;a=r.exec(e);)a.index>s&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s,a.index))},l++)),i.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(a[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=a.index+a[0].length;return s===0?n(e):(s<e.length&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),i)}function Ri(e,n={}){const i=n.renderText??Ts,r=n.properNames?l=>Es(l,i):i,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Ue(e,r,s)}function Eo(e,n,i){return e.indexOf("**")<0?n(e):e.split(/(\*\*[^*]+\*\*)/g).map((s,l)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?t.jsx("strong",{children:n(s.slice(2,-2))},`${i}-${l}`):t.jsx(f.Fragment,{children:n(s)},`${i}-${l}`))}const Bn=/^(#{1,6})\s+(.*)$/,xd=/^\s*<!--.*-->\s*$/;function Rs(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
|
|
792
|
+
`)?"":n)}function fd(e){return e<=1?2:e===2?3:4}function gd(){let e=1;return n=>{const i=fd(n),r=Math.min(i,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${i}`}}}function zn(e){return e?$n(Rs(e))!=="unknown":!1}function Ro({text:e,mode:n,inline:i,dropTitle:r}){const s=Rs(e),l=(d,u,g)=>!!r&&g<=1&&d<=2&&u.trim()===r.trim(),a=gd();if(n==="paragraph"&&$n(s)!=="unknown"){const d=Is(s);return t.jsx(t.Fragment,{children:d.map((u,g)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,g))return null;const{Tag:x,className:m}=a(u.level??1);return t.jsx(x,{className:m,children:i(u.text)},g)}return t.jsx("p",{children:Eo(u.text,i,g)},g)})})}const p=s.split(`
|
|
793
|
+
`);let c=0;return t.jsx(t.Fragment,{children:p.map((d,u)=>{const g=d.match(Bn);if(g){const m=c++;if(l(g[1].length,g[2],m))return null;const{Tag:b,className:S}=a(g[1].length);return t.jsx(b,{className:S,children:i(g[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Bn.test(p[u-1])&&!Bn.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(xd.test(d))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:m,className:b}=a(3);return t.jsx(m,{className:b,children:i(d.trim().slice(2,-2))},u)}return t.jsx("p",{children:Eo(d,i,u)},u)})})}function md(e){const{convert:n}=q();return f.useMemo(()=>e?n(e):"",[e,n])}function Ni({text:e,mode:n,tables:i=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:a}){const p=md(e),{convert:c}=q(),d=x=>Ri(x,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,g=a?c(a):void 0;return!i||p.indexOf(":::")<0?t.jsx(Ro,{text:p,mode:n,inline:d,dropTitle:g}):t.jsx(t.Fragment,{children:Ci(p).map((x,m)=>x.type==="table"?t.jsx(Ii,{table:x.table,opts:u},m):t.jsx(Ro,{text:x.text,mode:n,inline:d,dropTitle:m===0?g:void 0},m))})}function Ns(e,n){const[i,r]=f.useState(null),[s,l]=f.useState(!1),a=f.useRef(0);return f.useEffect(()=>{const p=++a.current;if(!e||!n){r(null),l(!1);return}let c;try{c=e(n)}catch{r(null),l(!1);return}if(!c||typeof c.then!="function"){r(c??null),l(!1);return}l(!0),c.then(d=>{p===a.current&&r(d??null)}).catch(()=>{p===a.current&&r(null)}).finally(()=>{p===a.current&&l(!1)})},[e,n]),{images:i,loading:s}}const No={A:"fine",B:"rough",C:"rough",D:"ocr"};function hd(e){return typeof e!="string"?null:e in Hn?e:e in No?No[e]:null}const bd={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},yd={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function it(e){return typeof e!="string"?"":bd[e]??yd[e]??e}const jd=["〇","一","二","三","四","五","六","七","八","九"],Lo=["","十","百","千"],vd=["","萬","億"];function Li(e){if(e===0)return"〇";if(e<0)return`負${Li(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(kd(s,r>0)+vd[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function kd(e,n){const i=[];let r=e;for(;r>0;)i.unshift(r%10),r=Math.floor(r/10);let s="";for(let l=0;l<i.length;l++){const a=i[l],p=i.length-1-l;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&p===1&&l===0&&!n?s+=Lo[p]:s+=jd[a]+Lo[p]}return s.replace(/〇$/,"")}let Vt=null,cn=null;const mn=new Set;function Sd(){return Vt?Promise.resolve():cn||(cn=import("opencc-js/t2cn").then(e=>{Vt=e.Converter({from:"tw",to:"cn"}),mn.forEach(n=>n())}).catch(()=>{Vt=e=>e,mn.forEach(e=>e())}),cn)}const wd=e=>e;function vt(){const[,e]=f.useState(0);return f.useEffect(()=>{if(Vt)return;const n=()=>e(i=>i+1);return mn.add(n),Sd(),()=>{mn.delete(n)}},[]),Vt??wd}function Et(e,n){return n(e).toLowerCase()}const _d=o("highlight-bg");function en(e,n,i){if(!n)return e;const r=Et(n,i);if(!r)return e;const s=Et(e,i);if(s.length!==e.length)return e;const l=[];let a=0,p=0;for(;a<e.length;){const c=s.indexOf(r,a);if(c===-1){l.push(e.slice(a));break}c>a&&l.push(e.slice(a,c)),l.push(t.jsx("mark",{style:{background:_d,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},p++)),a=c+r.length}return t.jsx(t.Fragment,{children:l})}function Bi(e,n,i,r){if(!n)return!0;const s=Et(n,r);return(i?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(a=>typeof a=="string"&&Et(a,r).includes(s))}function $d(e,n,i){return n?Et(e,i).includes(Et(n,i)):!0}const Ai={类:o("section-lei"),书:o("section-shu"),序:o("section-xu"),结语:o("section-jieyu"),注释:o("section-zhushi")},zd={考证:o("section-kaozhen")};function Cd(e){const n=e.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Ls(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((s,l)=>s+Ls(l),0))||0;return n+i}function Id(e,n){const i=[],r=a=>{var p;i.push(...a.files),(p=a.children)==null||p.forEach(r)};if(r(e),i.length===0)return;const s=i.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 Td={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Wi({enabled:e,expanded:n,onClick:i,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...Td,...r},children:s}):t.jsx("span",{style:r,children:s})}function Ed({type:e}){const n=it(e),i=Ai[n]||o("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:i,border:`1px solid ${i}40`,borderRadius:"2px",background:`${i}08`,flexShrink:0},children:n})}function Rd({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=q(),s=Pe(),l=vt(),a=S=>S?Ue(r(S),h=>i?en(h,i,l):h):"",[p,c]=f.useState(!1),d=!!e.summary,u=!!e.comment,g=!!e.additional_comment,x=!!(e.content&&e.content.length>60),m=d||u||g||x;f.useEffect(()=>{i&&c(!0)},[i]);const b=!p&&x?rs(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[t.jsxs("div",{onClick:()=>m&&c(!p),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:m?"pointer":"default",userSelect:"none",background:o("input-bg")},children:[t.jsxs(Wi,{enabled:m,expanded:p,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",a(e.book_title),"》"]}):a(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[Li(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:a(e.author_info||e.author)})]}),!p&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:a(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:a(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:o("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:s(e.work_id),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),p&&m&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${o("widget-border")}`,background:o("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"8px"},children:a(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:a(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(e.additional_comment)})]}),x&&!d&&!u&&!g&&t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)})]})]})}function Nd({section:e,highlightQuery:n=""}){const{convert:i}=q(),r=vt(),s=c=>c?Ue(i(c),d=>n?en(d,n,r):d):"",[l,a]=f.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(Wi,{enabled:p,expanded:l,onClick:()=>a(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(Ed,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:s(e.title)}),p&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&p&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${Ai[it(e.type)]||o("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:o("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(e.content)})})]})}const Ld=100;function Mi(e){return it(e.type)!=="page_header"?!1:(e.content||"").length>=Ld}function Bd({section:e,highlightQuery:n=""}){const{convert:i}=q(),r=vt();if(it(e.type)==="page_header"&&!Mi(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
794
|
+
`)),l=Ue(s,d=>n?en(d,n,r):d),a=it(e.type),p=Ai[a]||o("desc-fg"),c=a==="序"||a==="结语"||a==="注释";return t.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:o("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${p}40`:void 0,background:c?o("bg"):void 0,borderRadius:c?"0 4px 4px 0":void 0,position:"relative"},children:[c&&t.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 Ad(e,n,i){const[r,s]=f.useState({});return f.useEffect(()=>{var d;if(!n||e.length===0)return;let l=!1;const a=e.filter(u=>{var g;return!((g=i==null?void 0:i.current)!=null&&g.has(u))}),p={};for(const u of e)(d=i==null?void 0:i.current)!=null&&d.has(u)&&(p[u]=i.current.get(u));if(Object.keys(p).length>0&&s(p),a.length===0)return;const c=async u=>{var g;try{if(n.getEntry){const h=await n.getEntry(u);if(h)return{title:h.title,author:h.author}}const x=await n.getItem(u);if(!x)return null;const m=x.title||u,b=x.authors,S=(g=b==null?void 0:b[0])==null?void 0:g.name;return{title:m,author:S}}catch{return null}};return Promise.all(a.map(async u=>{var x;const g=await c(u);return(x=i==null?void 0:i.current)==null||x.set(u,g),[u,g]})).then(u=>{l||s(g=>{const x={...g};for(const[m,b]of u)x[m]=b;return x})}),()=>{l=!0}},[e.join(","),n]),r}function Wd({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=q(),a=Pe(),p=vt(),c=j=>j?Ue(l(j),k=>s?en(k,s,p):k):"",[d,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const g=it(e.type),x=zd[g]||o("desc-fg"),m=!!e.content,b=e.work_ids||[],S=b.length>1,h=Ad(S?b:[],i,r),y=m&&!d&&e.content.length>80?rs(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${o("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>m&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:m?"pointer":"default",userSelect:"none"},children:[t.jsxs(Wi,{enabled:m,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg"),lineHeight:1.6},children:e.header_line?c(e.header_line):c(e.title)}),!d&&y&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:c(y)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:a(b[0]),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),S&&t.jsxs("span",{style:{fontSize:"11px",color:o("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:g})]})]}),S&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(j=>{const k=h[j],$=k?`${l(k.title)}${k.author?`(${l(k.author)})`:""}`:j.slice(0,8)+"…";return t.jsxs("a",{href:a(j),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(j))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:j,children:["→",$]},j)})}),d&&m&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:o("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${o("widget-border")}`,fontSize:"12px",color:o("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:c(e.comment)})]})]})}function Md({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=vt(),a=n.trim(),p=f.useMemo(()=>a?e.sections.filter(c=>Bi(c,a,!0,l)):e.sections,[e.sections,a,l]);return t.jsxs("div",{children:[t.jsx("div",{children:p.map((c,d)=>t.jsx(Wd,{section:c,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:a},d))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Fd(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Pd({sections:e,onNavigate:n,inline:i}){const r=Pe(),{convert:s}=q(),l=Fd();return t.jsx(t.Fragment,{children:e.map((a,p)=>{const c=it(a.type);if(c==="page_header"&&!Mi(a))return null;if(c==="类")return t.jsxs(f.Fragment,{children:[f.createElement(l("类"),null,i(s(a.title))),a.content&&t.jsx("p",{children:i(s(a.content))})]},p);if(c==="书"||c==="诗"||c==="考证"||c==="注释"){const d=a.book_title?`《${a.book_title}》${a.n_juan!=null?Li(a.n_juan)+"卷":""}`:a.title,u=i(s(d));return t.jsxs("section",{className:"bim-rd-entry",children:[f.createElement(l("条目"),{className:"bim-rd-entry-h"},a.work_id&&n?t.jsx("a",{href:r(a.work_id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),n(a.work_id))},title:"查看作品",children:u}):u),a.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(a.author_info))}),a.content&&a.content.split(/\n+/).map((g,x)=>t.jsx("p",{children:i(s(g))},x)),a.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(a.summary))]}),a.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(a.comment))]}),a.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(a.additional_comment))]})]},p)}return a.content?t.jsx("p",{children:i(s(a.content))},p):null})})}function Od(e){return e.some(n=>{const i=it(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&Mi(n)})}function Dd({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:a,workLabelCache:p,prefs:c}){var B;const{convert:d}=q(),u=vt(),[g,x]=f.useState("text"),m=s.trim(),b=(r==null?void 0:r.type)==="kaozhen",S=f.useCallback(A=>m?en(A,m,u):A,[m,u]),h=A=>Ri(A,{renderText:S,properNames:c.properNames}),y=f.useMemo(()=>m?e.sections.filter(A=>Bi(A,m,b,u)):e.sections,[e.sections,m,b,u]),j=(A,W)=>W.filter(V=>it(V.type)===A).length,k=j("书",e.sections),$=j("诗",e.sections),v=j("考证",e.sections);let _="";b?_=m?`${j("考证",y)} / ${v} ${d("條")}`:`${v} ${d("條")}`:$>0?_=m?`${j("诗",y)} / ${$} 首`:`${$} 首`:k>0&&(_=m?`${j("书",y)} / ${k} ${d("部書")}`:`${k} ${d("部書")}`);const w=r!=null&&r.text_quality?hd(r.text_quality.grade):null,z=[];i&&z.push(i),_&&z.push(_),b&&(r!=null&&r.target_source)&&z.push(t.jsxs(t.Fragment,{children:[d("考證對象")," ",d(r.target_source)]})),w&&z.push(t.jsx("span",{title:Al[w],children:(B=r==null?void 0:r.text_quality)!=null&&B.source_note?t.jsxs(t.Fragment,{children:["底本 ",d(r.text_quality.source_note),"(",d(Hn[w]),")"]}):t.jsxs(t.Fragment,{children:[d("文本質量")," ",d(Hn[w])]})})),e.source_url&&z.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:d("原文來源")}));const N=!b&&Od(e.sections),T=!!n&&(!N||c.readingMode==="paragraph"&&zn(n)),C=!b&&(N||!!n),P=b||!C?"entries":g;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:d(e.title)}),z.length>0&&t.jsx("p",{className:"bim-rd-meta",children:z.map((A,W)=>t.jsxs(f.Fragment,{children:[W>0&&t.jsx("span",{className:"bim-rd-dot"}),A]},W))}),C&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":"看法",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":P==="text",onClick:()=>x("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":P==="entries",onClick:()=>x("entries"),children:d("條目")})]})]}),P==="text"&&t.jsx("article",{className:"bim-rd-prose",children:T?t.jsx(Ni,{text:n,mode:c.readingMode,properNames:c.properNames,renderText:S,dropTitle:e.title}):t.jsx(Pd,{sections:e.sections,onNavigate:l,inline:h})}),P==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:b?t.jsx(Md,{juan:e,searchQuery:s,onNavigate:l,transport:a,workLabelCache:p}):t.jsxs(t.Fragment,{children:[y.map((A,W)=>{const V=it(A.type);return V==="书"||V==="诗"||V==="考证"?t.jsx(Rd,{section:A,onNavigate:l,highlightQuery:m},W):V==="类"?t.jsx(Nd,{section:A,highlightQuery:m},W):t.jsx(Bd,{section:A,highlightQuery:m},W)}),y.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function Bs(e){return e.juan_files&&e.juan_files.length>0?e.juan_files:e.files&&e.files.length>0?e.files.map(n=>n.filename):[]}function Hd(e){const n=Bs(e);return n.length>0?n[0]:null}function Gd(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:a,query:p,isKaozhen:c}=e,d=vt(),u=f.useRef(new Map),[g,x]=f.useState({}),[m,b]=f.useState({}),S=f.useCallback((y,j)=>{const k=j==null?void 0:j.title;k&&b($=>$[y]===k?$:{...$,[y]:k})},[]);f.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:a}),S(s,l))},[s,l,a,S]),f.useEffect(()=>{u.current.clear(),x({}),b({})},[n]);const h=f.useCallback((y,j)=>{let k=0;if(y.juan)for(const $ of y.juan.sections)Bi($,j,c,d)&&k++;return k===0&&y.rawText&&$d(y.rawText,j,d)&&(k=1),k},[c,d]);return f.useEffect(()=>{const y=p.trim();if(!y){x({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let j=!1;const k={},$=[];for(const N of r){const T=u.current.get(N);T?k[N]=h(T,y):(k[N]="loading",$.push(N))}x(k);const v=8;let _=0;const w=async()=>{var N;for(;_<$.length;){if(j)return;const T=_++,C=$[T];try{const[P,B]=await Promise.all([i.getCollatedJuan(n,C),((N=i.getCollatedJuanText)==null?void 0:N.call(i,n,C))??Promise.resolve(null)]),A={juan:P,rawText:B};if(u.current.set(C,A),S(C,P),j)return;x(W=>({...W,[C]:h(A,y)}))}catch{if(j)return;x(P=>({...P,[C]:0}))}}},z=Array.from({length:Math.min(v,$.length)},()=>w());return Promise.all(z),()=>{j=!0}},[p,n,i,r.join(","),h,d,S]),{matchStates:g,titles:m}}const Fi=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:a,style:p,title:c,subtitle:d,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m})=>{const[b,S]=f.useState(null),[h,y]=f.useState(!1),[j,k]=f.useState(null),[$,v]=f.useState(null),[_,w]=f.useState(null),[z,N]=f.useState(!1),[T,C]=f.useState(null),[P,B]=f.useState(""),A=f.useRef(new Map),W=f.useRef(0),V=s??$,K=f.useCallback(X=>{v(X),l==null||l(X)},[l]),E=e||b;f.useEffect(()=>{e&&(y(!1),k(null))},[e]),f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let X=!1;return y(!0),k(null),i.getCollatedEditionIndex(n).then(ie=>{X||(ie?S(ie):k("未找到整理本数据"))}).catch(ie=>{X||k(ie instanceof Error?ie.message:"加载失败")}).finally(()=>{X||y(!1)}),()=>{X=!0}},[e,n,i]),f.useEffect(()=>{if(E&&!V){const X=Hd(E);X&&K(X)}},[E,V,K]);const le=n||(E==null?void 0:E.work_id),G=f.useCallback(async X=>{var me;if(!le||!(i!=null&&i.getCollatedJuan))return;const ie=++W.current;N(!0),w(null),C(null);try{const[te,se]=await Promise.all([i.getCollatedJuan(le,X),((me=i.getCollatedJuanText)==null?void 0:me.call(i,le,X))??Promise.resolve(null)]);if(ie!==W.current)return;w(te),C(se)}catch{if(ie!==W.current)return;w(null),C(null)}finally{ie===W.current&&N(!1)}},[le,i]);f.useEffect(()=>{V&&G(V)},[V,G]);const ae=X=>{K(X)};if(h)return t.jsx("div",{className:a,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(j)return t.jsx("div",{className:a,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:j});if(!E)return null;const pe=E.type==="kaozhen",ee=Bs(E);return t.jsx(Vd,{className:a,style:p,index:E,allFiles:ee,isKaozhen:pe,effectiveWorkId:le,transport:i,activeFile:V,handleSelectFile:ae,juanData:_,juanRawText:T,juanLoading:z,searchQuery:P,setSearchQuery:B,onNavigate:r,workLabelCacheRef:A,reader:{title:c,subtitle:d,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m}})};function As(e,n,i,r){var d,u,g,x;const s=(u=(d=n.juan_metadata)==null?void 0:d[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:Cd(e)),p=((x=(g=n.files)==null?void 0:g.find(m=>m.filename===e))==null?void 0:x.title)??i[e];if(!p)return{position:l,label:l};const c=r(p);return{position:l,label:l===p||l===c?c:`${l} ${c}`}}function Ud(e,n,i,r,s){const l=c=>c==="loading"?"…":typeof c=="number"&&c>0?c:void 0,a=(c,d)=>({key:c,label:d??As(c,e,r,s).label,hint:l(i[c]),disabled:i[c]===0}),p=(c,d)=>{var g;if(c.files.length===1&&!((g=c.children)!=null&&g.length))return a(c.files[0],s(c.label));const u=Id(c,i);return{key:`group:${d}`,label:s(c.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:Ls(c),defaultExpanded:typeof u=="number"&&u>0,children:[...c.files.map(x=>a(x)),...(c.children??[]).map((x,m)=>p(x,`${d}.${m}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((c,d)=>p(c,`${d}`)):n.map(c=>a(c))}const Vd=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:a,activeFile:p,handleSelectFile:c,juanData:d,juanRawText:u,juanLoading:g,searchQuery:x,setSearchQuery:m,onNavigate:b,workLabelCacheRef:S,reader:h})=>{const{convert:y}=q(),[j,k]=$i(),{matchStates:$,titles:v}=Gd({workId:l,transport:a,files:r,activeFile:p,activeJuan:d,activeRawText:u,query:x,isKaozhen:s}),_=Ns(h.resolveImages,p),w=f.useMemo(()=>Ud(i,r,$,v,y),[i,r,$,v,y]),z=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:C=>m(C.target.value)}),N=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(C=>C.vol_label)?"冊":"卷",T=p?As(p,i,v,y).position:void 0;return t.jsxs(zi,{className:e,style:n,title:h.title??(i.title?y(i.title):void 0),subtitle:h.subtitle??y(s?"考證":"整理本"),toc:w,tocCaption:`目录 · ${r.length} ${y(N)}`,tocHeader:z,activeKey:p,onSelect:c,images:_.images,imagesLoading:_.loading,renderImageOverlay:h.renderImageOverlay,imagePanel:h.imagePanel,prefs:j,onPrefsChange:k,paragraphToggle:!s&&zn(u),allowVertical:h.allowVertical,children:[g?t.jsx(jt,{}):d?t.jsx(Dd,{juan:d,rawText:u,positionLabel:T,index:i,searchQuery:x,onNavigate:b,transport:a,workLabelCache:S,prefs:j},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,i.references&&i.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:y("參考文獻")}),t.jsx("ol",{children:i.references.map((C,P)=>t.jsxs("li",{children:[C.url?t.jsx("a",{className:"bim-rd-link",href:C.url,target:"_blank",rel:"noopener noreferrer",children:C.title}):t.jsx("span",{children:C.title}),C.author&&t.jsxs("span",{children:[",",C.author]}),C.note&&t.jsxs("span",{children:["。",C.note]})]},P))})]})]})},Yd={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},qd={label:"其他",color:o("desc-fg")},Kd={pending:{label:"待处理",color:o("warning")},in_progress:{label:"处理中",color:o("primary")},resolved:{label:"已处理",color:o("success")},wontfix:{label:"不采纳",color:o("desc-fg")},duplicate:{label:"重复",color:o("desc-fg")}},Jd={label:"待处理",color:o("warning")};function Zd(e){try{const n=new Date(e),i=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return e}}function Xd(e,n){if(!e)return!1;try{const i=new URL(e,n);if(i.protocol!=="http:"&&i.protocol!=="https:")return!1;const r=new URL(n);return i.hostname===r.hostname}catch{return!1}}const Pi=({items:e,loading:n})=>{const i=Pe();return n?t.jsx(jt,{}):e.length===0?t.jsx("div",{style:Qd,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Yd[r.type]||qd,l=Kd[r.status]||Jd,a=typeof window<"u"&&Xd(r.pageUrl,window.location.href);return t.jsxs("div",{style:ep,children:[t.jsxs("div",{style:tp,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Bo,background:s.color},children:s.label}),t.jsx("span",{style:{...Bo,background:l.color},children:l.label})]}),t.jsx("span",{style:np,children:Zd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:ip,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:An,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(a?t.jsx("a",{href:r.pageUrl,style:An,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:An,children:r.pageUrl}))]}),t.jsx("div",{style:op,children:r.content}),r.reply&&t.jsxs("div",{style:rp,children:[t.jsx("div",{style:sp,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Qd={textAlign:"center",padding:"40px 0",color:o("desc-fg"),fontSize:"14px"},ep={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"16px"},tp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Bo={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},np={fontSize:"12px",color:o("desc-fg")},ip={fontSize:"12px",marginBottom:"6px"},An={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},op={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},rp={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},sp={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},ti=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const a=ue(),[p,c]=f.useState(null),[d,u]=f.useState([]),[g,x]=f.useState("recommend"),[m,b]=f.useState([]),[S,h]=f.useState(!1),y=r??g,j=W=>{x(W),s==null||s(W)},[k,$]=f.useState(!0),[v,_]=f.useState(null),[w,z]=f.useState(null),[N,T]=f.useState(null);f.useEffect(()=>{let W=!1;if(e.getCounts)return e.getCounts().then(V=>{W||c({works:V.works,books:V.books,collections:V.collections})}).catch(()=>{}),()=>{W=!0}},[e]),f.useEffect(()=>{let W=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const K=await e.getRecommended();if(K!=null&&K.groups)return K.groups.flatMap(E=>E.items.map(le=>({...le,group:E.name})))}catch{}return[]})().then(async K=>{if(W)return;const E=K.filter(G=>G.id);if(E.length===0){$(!1);return}const le=await Promise.all(E.map(async G=>{if(G.type)return{id:G.id,title:G.title,type:G.type,author:G.author,dynasty:G.dynasty,role:G.role,edition:G.edition,has_text:G.has_text,has_image:G.has_image,has_collated:G.has_collated,subtype:G.subtype,primary_name:G.primary_name,group:G.group,fallbackDescription:G.description};try{let ae=null;if(e.getEntry)ae=await e.getEntry(G.id);else{const pe=await e.getItem(G.id);pe&&(ae={id:G.id,title:pe.title||G.id,type:pe.type||"work"})}if(ae)return{...ae,group:G.group,fallbackDescription:G.description}}catch{}return{id:G.id,title:G.title,type:we.extractType(G.id),group:G.group,fallbackDescription:G.description}}));W||(u(le.filter(G=>G!==null)),$(!1))}),()=>{W=!0}},[e,i]);const C=f.useRef(!1),P=f.useRef(!1),B=f.useRef(!1);f.useEffect(()=>{if(y!=="catalog"||C.current)return;const W=e.getCatalogProgress??e.getResourceProgress;if(!W)return;C.current=!0;let V=!1;return W.call(e).then(K=>{V||_(K)}).catch(()=>{C.current=!1}),()=>{V=!0}},[e,y]),f.useEffect(()=>{if(y!=="collection"||P.current||!e.getCollectionProgress)return;P.current=!0;let W=!1;return e.getCollectionProgress().then(V=>{W||z(V)}).catch(()=>{P.current=!1}),()=>{W=!0}},[e,y]),f.useEffect(()=>{if(y!=="site"||B.current||!e.getSiteProgress)return;B.current=!0;let W=!1;return e.getSiteProgress().then(V=>{W||T(V)}).catch(()=>{B.current=!1}),()=>{W=!0}},[e,y]),f.useEffect(()=>{if(!l||y!=="feedback")return;let W=!1;return h(!0),fetch(l).then(V=>V.json()).then(V=>{!W&&V.success&&b(V.items||[])}).catch(()=>{}).finally(()=>{W||h(!1)}),()=>{W=!0}},[l,y]);const A=W=>t.jsx(jn,{type:W,size:12});return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:o("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${o("widget-border")}`,marginBottom:"16px"},children:[t.jsx(Ft,{label:a.home.recommendTab,active:y==="recommend",onClick:()=>j("recommend")}),t.jsx(Ft,{label:a.home.catalogTab,active:y==="catalog",onClick:()=>j("catalog")}),t.jsx(Ft,{label:a.home.collectionTab,active:y==="collection",onClick:()=>j("collection")}),t.jsx(Ft,{label:a.home.siteTab,active:y==="site",onClick:()=>j("site")}),l&&t.jsx(Ft,{label:a.home.feedbackTab,active:y==="feedback",onClick:()=>j("feedback")})]}),y==="recommend"&&t.jsx(lp,{recommended:d,loading:k,onNavigate:n,getIcon:A,t:a}),y==="catalog"&&t.jsx(Ao,{progress:v,t:a,onNavigate:n}),y==="collection"&&t.jsx(Ao,{progress:w,t:a,onNavigate:n}),y==="site"&&t.jsx(cp,{progress:N,t:a,totalWorks:(p==null?void 0:p.works)??0}),y==="feedback"&&l&&t.jsx(Pi,{items:m,loading:S})]})})},Ft=({label:e,active:n,onClick:i})=>t.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:o(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${o("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),lp=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=Pe();if(n)return t.jsx(jt,{});if(e.length===0)return null;const a=new Map;for(const p of e){const c=p.group||s.home.recommendedBrowse;a.has(c)||a.set(c,[]),a.get(c).push(p)}return t.jsx(t.Fragment,{children:Array.from(a.entries()).map(([p,c])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:p}),t.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 t.jsxs("a",{href:l(d.id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),i==null||i(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,cursor:"pointer",background:o("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},Ao=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(jt,{});const r=[...e.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:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(p=>{const c=r.filter(d=>d.status===p);return c.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:a[p]}}),l[p]," (",c.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(d=>t.jsx(ap,{item:d,t:n,statusColor:a[p],onNavigate:i},d.id))})]},p)})})},ap=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=Pe(),l=e.total>0?Math.round(e.imported/e.total*100):0,a=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=e.edition?`${e.name}·${e.edition}`:e.name,c=e.collection_id||e.work_id;return c&&r?t.jsx("a",{href:s(c),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:p}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:o("widget-border"),color:o("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:a})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Kt(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},cp=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(jt,{});const r=[...e.resources].sort((c,d)=>c.priority-d.priority),s=r.filter(c=>c.imported>0),l=r.filter(c=>c.imported===0),a=s.reduce((c,d)=>Math.max(c,d.imported),0),p=i>0?Math.round(a/i*100):0;return t.jsxs("div",{children:[i>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${o("primary")} 6%, transparent)`,fontSize:"13px",color:o("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:a.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>t.jsx(Wo,{item:c,t:n,totalWorks:i},c.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(c=>t.jsx(Wo,{item:c,t:n,totalWorks:i},c.id))})]})]})},Wo=({item:e,t:n,totalWorks:i})=>{const r=i>0?Math.round(e.imported/i*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:t.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&i>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:o("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},Mo="(max-width: 768px)";function dp(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Mo).matches);return f.useEffect(()=>{const i=window.matchMedia(Mo),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),e}const pp=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var V;const l=ue(),{convert:a}=q(),p=dp(),[c,d]=f.useState(null),[u,g]=f.useState(null),[x,m]=f.useState(!1),[b,S]=f.useState("detail"),[h,y]=f.useState([]),[j,k]=f.useState(!1),[$,v]=f.useState(null),[_,w]=f.useState(!1),z=f.useCallback(async K=>{if(!e.getCollatedEditionIndex){v(null);return}w(!0);try{const E=await e.getCollatedEditionIndex(K);v(E)}catch{v(null)}finally{w(!1)}},[e]),N=f.useCallback(async K=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){y([]);return}k(!0);try{if(e.getCollectionCatalogs){const E=await e.getCollectionCatalogs(K);y(E||[])}else if(e.getCollectionCatalog){const E=await e.getCollectionCatalog(K);y(E?[{resource_id:"",data:E}]:[])}}catch{y([])}finally{k(!1)}},[e]),T=f.useCallback(async K=>{if(i){i(K);return}d(K),g(null),y([]),v(null),S("detail"),m(!0);try{const E=await e.getItem(K.id);E&&(g(E),E.type==="collection"?N(K.id):E.type==="work"&&E.has_collated&&z(K.id))}catch(E){console.error("加载详情失败:",E)}finally{m(!1)}},[e,i,N,z]),C=f.useCallback(async K=>{g(null),y([]),v(null),S("detail"),m(!0);try{const E=await e.getItem(K);E&&(g(E),d({id:K,title:E.title||K,type:E.type||"book"}),E.type==="collection"?N(K):E.type==="work"&&E.has_collated&&z(K))}catch(E){console.error("导航失败:",E)}finally{m(!1)}},[e,N,z]),P=(u==null?void 0:u.type)==="collection"&&(h.length>0||j)||(u==null?void 0:u.type)==="work"&&($||_),B=p&&(x||u),A=f.useCallback(()=>{d(null),g(null),y([]),v(null),S("detail")},[]),W=t.jsx(t.Fragment,{children:x?t.jsx(jt,{}):u?t.jsxs(t.Fragment,{children:[(P||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${o("widget-border")}`,padding:p?"0 12px":"0 48px",background:o("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[P&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>S("detail"),style:dn(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&j&&h.length===0&&t.jsxs("button",{onClick:()=>{},style:dn(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&h.map(K=>t.jsx("button",{onClick:()=>S(`catalog:${K.resource_id}`),style:dn(b===`catalog:${K.resource_id}`),children:K.short_name?`${a(K.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},K.resource_id)),u.type==="work"&&($||_)&&t.jsxs("button",{onClick:()=>S("collated"),style:dn(b==="collated"),children:[l.detailTab.collatedEdition,_&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?t.jsx(fi,{data:u,transport:e,onNavigate:C}):b.startsWith("catalog:")?t.jsx(gi,{data:(V=h.find(K=>`catalog:${K.resource_id}`===b))==null?void 0:V.data,onNavigate:C}):b==="collated"?t.jsx(Fi,{index:$||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(ti,{transport:e,onNavigate:C,recommendedIds:r})});return p?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:B?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${o("widget-border")}`,background:o("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:A,style:{padding:"4px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:W})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Un,{transport:e,onEntryClick:T,hideModeIndicator:n}),!u&&t.jsx(ti,{transport:e,onNavigate:C,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${o("widget-border")}`,display:"flex",flexDirection:"column",background:o("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(Un,{transport:e,onEntryClick:T,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:W})]})};function dn(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function ut(e){return e.replace(/\.md$/,"")}function Fo(e){let n="";if(e.source_url)try{const r=new URL(e.source_url).pathname.split("/").filter(Boolean).pop()??"";n=decodeURIComponent(r).replace(/_/g," ")}catch{}return[e.source_name,n||e.version_label].filter(Boolean).join(" · ")||e.key}const Po={padding:24,color:o("desc-fg")},ni=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:a,onVersionChange:p,title:c,subtitle:d,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m,className:b,style:S})=>{const[h,y]=f.useState(e??null),[j,k]=f.useState(!1),[$,v]=f.useState(null),_=r!==void 0?r:$,w=f.useCallback(ee=>{s?s(ee):v(ee)},[s]),[z,N]=f.useState(null),[T,C]=f.useState(!1);f.useEffect(()=>{e&&y(e)},[e]),f.useEffect(()=>{if(e)return;y(null),k(!1);const ee=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!ee){k(!0);return}let X=!1;return Promise.resolve().then(ee).then(ie=>{X||(ie?y(ie):k(!0))}).catch(()=>{X||k(!0)}),()=>{X=!0}},[n,i,e,l]),f.useEffect(()=>{if(!h||h.chapters.length===0)return;const ee=ut(h.chapters[0].file);if(!_){w(ee);return}const X=ut(_);h.chapters.some(me=>ut(me.file)===X)||w(ee)},[h,_,w]);const P=f.useMemo(()=>{if(!h||!_)return null;const ee=ut(_);return h.chapters.find(X=>ut(X.file)===ee)??null},[h,_]);f.useEffect(()=>{if(!n||!P)return;const ee=l!==void 0?i.getWorkFullTextChapter?ie=>i.getWorkFullTextChapter(n,l,ie):null:i.getBookFullTextChapter?ie=>i.getBookFullTextChapter(n,ie):null;if(!ee)return;let X=!1;return C(!0),N(null),Promise.resolve(P.file).then(ee).then(ie=>{X||N(ie)}).catch(()=>{X||N(null)}).finally(()=>{X||C(!1)}),()=>{X=!0}},[n,P,i,l]);const B=Ns(u,P?ut(P.file):null),[A,W]=$i(),{convert:V}=q(),K=!!(a&&a.length>1&&p),E=f.useMemo(()=>K?bs(a).map((ee,X)=>({...ee,label:Fo(a[X])})):void 0,[K,a]),le=K?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:ee=>p(ee.target.value),children:a.map(ee=>t.jsx("option",{value:ee.key,children:Fo(ee)},ee.key))})]}):null;if(!h)return t.jsxs("div",{style:Po,children:[le&&t.jsx("div",{style:{marginBottom:12},children:le}),j?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:Po,children:[le&&t.jsx("div",{style:{marginBottom:12},children:le}),"全文目录为空"]});const G=h.chapters.map(ee=>({key:ut(ee.file),label:V(ee.title)})),ae=ks(h)||qn(h),pe=z?z.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(zi,{title:c??V(h.version_label),subtitle:d??"全文",toc:G,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:_?ut(_):null,onSelect:w,images:B.images,imagesLoading:B.loading,renderImageOverlay:g,imagePanel:x,prefs:A,onPrefsChange:W,versions:E,currentVersionKey:E?l??null:void 0,onVersionChange:E?p:void 0,versionSource:!1,paragraphToggle:zn(pe),allowVertical:m,className:b,style:S,children:[P&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:V(P.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:h.source.url,target:"_blank",rel:"noreferrer",children:V(h.source.name)}),h.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),h.source.license]})]})]}),T&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!T&&pe!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Ni,{text:pe,mode:A.readingMode,tables:ae,gujiMarkdown:qn(h),properNames:A.properNames})}),!T&&!z&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},up=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=ue(),{convert:l}=q(),[a,p]=f.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[c,d]=f.useState(null);return t.jsxs("div",{className:i,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:l(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[s.catalog.totalVolumes," ",t.jsx("strong",{children:e.total_volumes})," ",s.unit.juan]}),e.stats.zhulu!=null&&t.jsxs("span",{children:["著錄 ",t.jsx("strong",{children:e.stats.zhulu})," ",s.unit.bu]}),e.stats.cunmu!=null&&t.jsxs("span",{children:["存目 ",t.jsx("strong",{children:e.stats.cunmu})," ",s.unit.bu]}),e.stats.categories!=null&&t.jsxs("span",{children:[e.stats.categories," 類"]})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(g=>t.jsx(xp,{division:g,expanded:a===g.name,onToggle:()=>p(a===g.name?null:g.name),expandedCat:c,onCatToggle:x=>d(c===x?null:x),onNavigate:n},g.name))})]})},xp=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:a}=q(),p=e.categories.reduce((c,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return c+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${o("primary")} 6%, transparent)`:o("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:o("fg"),textAlign:"left"},children:[t.jsx("span",{children:a(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg")},children:[e.categories.length," 類 · ",p," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(c=>{const d=`${e.name}/${c.name}`;return t.jsx(fp,{category:c,expanded:r===d,onToggle:()=>s(d),onNavigate:l},c.name)})})]})},fp=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var c,d,u,g;const{convert:s}=q(),l=((c=e.books)==null?void 0:c.zhulu)||[],a=((d=e.books)==null?void 0:d.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((g=e.stats)==null?void 0:g.cunmu)||a.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?o("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:o("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||a.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Oo,{label:"著錄",books:l,onNavigate:r}),a.length>0&&t.jsx(Oo,{label:"存目",books:a,onNavigate:r})]})]})},Oo=({label:e,books:n,onNavigate:i})=>{const{convert:r}=q(),s=Pe(),[l,a]=f.useState(n.length<=20),p=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((c,d)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:o("fg")},children:c.work_id&&i?t.jsx("a",{href:s(c.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},children:r(c.title)}):r(c.title)}),c.volumes&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(c.volumes)}),c.author&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(c.author).slice(0,20)})]},d))}),!l&&t.jsxs("button",{onClick:()=>a(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},qe=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=ue();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:o("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&t.jsx("button",{onClick:i,style:mp,children:"AI"}),n&&t.jsx("button",{onClick:n,style:gp,children:l.action.save})]})]}),s]})},gp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},mp={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Ge=({label:e,value:n,onChange:i,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:l=>i(l.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),bt=({value:e,onChange:n,placeholder:i})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},hn=({children:e,color:n,style:i})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||o("primary-soft"),color:o(n?"on-color-fg":"fg"),...i},children:e});function hp(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const un=({value:e,onChange:n,label:i})=>{const[r,s]=f.useState(!1),l=f.useRef(null),a=hp(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&a?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Do,children:i}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${o("input-border")}`,borderRadius:"2px",background:o("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:o("fg")},children:a.name}),t.jsx(hn,{children:a.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Do,children:i}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Do={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function bp(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function yp(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ws=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=ue(),[s,l]=f.useState(null),a=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},p=g=>{n(e.filter((x,m)=>m!==g)),s===g&&l(null)},c=(g,x,m)=>{const b=[...e];b[g]={...b[g],[x]:m},n(b)},d=(g,x)=>{const m=[...e];m[g]={...m[g],type:x,id:"",name:""},n(m),x==="bookID"&&i&&i(b=>{const S=[...e];S[g]={...S[g],id:b.id,name:b.title,type:"bookID"},n(S)})},u=g=>{i&&i(x=>{const m=[...e];m[g]={...m[g],id:x.id,name:x.title,type:"bookID"},n(m)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((g,x)=>t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===x?null:x),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===x?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:o("fg")},children:g.name||`${r.editor.sourcePlaceholder} ${x+1}`}),g.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:bp(g.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:yp(g.type)}),t.jsx("button",{onClick:m=>{m.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===x&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!g.type&&t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>d(x,"bookID"),style:{...Ho,borderColor:o("source-bookid"),color:o("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>d(x,"url"),style:{...Ho,borderColor:o("source-url"),color:o("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),g.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:ot,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Go,children:r.action.changeType})]}),g.id&&g.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:o("bg"),border:`1px solid ${o("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:o("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:g.name}),t.jsx("code",{style:{fontSize:"11px",background:o("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:g.id})]}),t.jsx("button",{onClick:()=>u(x),style:{background:"transparent",border:`1px solid ${o("widget-border")}`,color:o("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(x),style:{width:"100%",padding:"14px",border:`2px dashed ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),g.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:ot,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Go,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:g.name,onChange:m=>c(x,"name",m.target.value),placeholder:r.editor.sourceNamePlaceholder,style:St})]}),t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:g.id,onChange:m=>c(x,"id",m.target.value),placeholder:"https://...",style:St})]})]}),g.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${o("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...ot,opacity:.7},children:r.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:g.details,onChange:m=>c(x,"details",m.target.value),placeholder:r.editor.detailsPlaceholder,style:St})]}),t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:g.position,onChange:m=>c(x,"position",m.target.value),placeholder:"如: 卷三, p.52",style:St})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:g.version,onChange:m=>c(x,"version",m.target.value),placeholder:"如: v1.0, 2024-01",style:St})]}),t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:g.processor_version,onChange:m=>c(x,"processor_version",m.target.value),placeholder:"如: v0.1",style:St})]})]})]})]})})]},x)),t.jsxs("button",{onClick:a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},ot={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},St={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Ho={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:o("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},Go={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Ms(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(i=>({id:i.id||"",name:i.name||"",type:i.type||"",details:i.details||"",position:i.position||"",version:i.version||"",processor_version:i.processor_version||""}))}catch{}return[]}function Fs(e){return!e||e.length===0?"":JSON.stringify(e)}const Ps=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:a,childWorks:p,childCollections:c,containedBooks:d,siblingBooks:u,onLinkEntity:g,onUnlinkEntity:x,onViewEntity:m,onCreateAndLink:b,onSaveRelations:S})=>{const h=ue();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:h.section.relations})]}),S&&t.jsx("button",{onClick:S,style:jp,children:h.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.belongsToWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>g("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Pt,{direction:"up",title:h.relation.containedInCollection,entity:a,onView:m,onUnlink:()=>x("collectionId"),onLink:()=>g("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),l&&u&&u.length>0&&t.jsx(wt,{direction:"horizontal",title:`${h.relation.siblingVersions} (${u.length})`,entities:u,onView:m,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.parentWork,entity:r,onView:m,onUnlink:()=>x("parentWorkId"),onLink:()=>g("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),p&&p.length>0&&t.jsx(wt,{direction:"down",title:`${h.relation.childWorks} (${p.length})`,entities:p,onView:m,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),c&&c.length>0&&t.jsx(wt,{direction:"down",title:`${h.relation.collectionImpl} (${c.length})`,entities:c,onView:m,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(wt,{direction:"down",title:`${h.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>b("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.correspondingWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>g("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Pt,{direction:"up",title:h.relation.parentCollection,entity:s,onView:m,onUnlink:()=>x("parentCollectionId"),onLink:()=>g("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(wt,{direction:"down",title:`${h.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:m,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(wt,{direction:"down",title:`${h.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},Pt=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:a,linkLabel:p,createLabel:c,notLinkedLabel:d,viewLabel:u,unlinkLabel:g})=>{const x=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:o("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Os(i.type)}),t.jsx("span",{style:{fontWeight:500},children:i.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(Uo,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(Uo,{onClick:s,title:g,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(ii,{onClick:l,children:p}),t.jsx(ii,{onClick:a,primary:!0,children:c})]})]})},wt=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:a,expandMoreLabel:p})=>{const[c,d]=f.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),g=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=c?i:i.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:g}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[x.map(m=>t.jsxs("div",{onClick:()=>r(m),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:o("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:Os(m.type)}),t.jsx("span",{children:m.title})]},m.id)),i.length>5&&!c&&t.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:o("link-fg"),cursor:"pointer"},children:[p," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:a}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(ii,{onClick:s,primary:!0,children:["+ ",l]})})]})},Uo=({onClick:e,title:n,danger:i,children:r})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?o("danger"):"inherit",opacity:.7},children:r}),ii=({onClick:e,primary:n,children:i})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${o("widget-border")}`,borderRadius:"4px",background:n?o("primary"):"transparent",color:n?o("primary-fg"):"inherit",cursor:"pointer"},children:i});function Os(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const jp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Ds=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:a,onSearch:p,isLoading:c,excludeId:d})=>{const[u,g]=f.useState(""),x=d?a.filter(h=>h.id!==d):a;f.useEffect(()=>{e&&(g(""),p(""))},[e]);const m=h=>{g(h),p(h)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",S=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:vp,children:t.jsxs("div",{style:kp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),t.jsx("button",{onClick:s,style:Sp,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:h=>m(h.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:wp})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:Wn,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(h=>t.jsxs("div",{onClick:()=>r(h),style:_p,children:[t.jsx("span",{style:{fontSize:"16px"},children:S}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):u?t.jsxs("div",{style:Wn,children:["未找到匹配的",b]}):t.jsxs("div",{style:Wn,children:["输入关键词搜索",b]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:l,style:$p,children:["创建新",b,"并关联"]})]})]})})},vp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},kp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},Sp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},wp={width:"100%",padding:"10px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},_p={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:o("primary-soft")},Wn={padding:"20px",textAlign:"center",color:o("desc-fg")},$p={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Vo={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},zp={work:"📜",book:"📖",collection:"📚",entity:"👤"},Hs=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[a,p]=f.useState(""),c=f.useRef(null);f.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,m;(x=c.current)==null||x.focus(),(m=c.current)==null||m.select()},100))},[e,r==null?void 0:r.title]);const d=x=>{x.key==="Enter"&&a.trim()?u():x.key==="Escape"&&l()},u=()=>{a.trim()&&s(a.trim(),{...r,title:a.trim()})};if(!e)return null;const g=()=>{switch(i){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`创建新${Vo[n]}`}};return t.jsx("div",{style:Cp,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:Ip,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:zp[n]}),t.jsx("span",{children:g()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:o("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:o("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:c,type:"text",value:a,onChange:x=>p(x.target.value),onKeyDown:d,placeholder:`请输入${Vo[n]}名称...`,style:Tp})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),background:o("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&t.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:l,style:Ep,children:"取消"}),t.jsx("button",{onClick:u,disabled:!a.trim(),style:{...Rp,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Cp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ip={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:o("shadow-dialog")},Tp={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box"},Ep={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Rp={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function Np(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Gs(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Lp(e){switch(e){case"work":return o("editor-type-work");case"collection":return o("editor-type-collection");case"book":return o("editor-type-book");default:return o("desc-fg")}}const Us=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:a,onSelect:p,onCancel:c,onCreate:d,onSearch:u})=>{const[g,x]=f.useState(""),[m,b]=f.useState([]),[S,h]=f.useState(!1),[y,j]=f.useState("recent");f.useEffect(()=>{e&&(x(""),b([]),j(r.length>0?"recent":"search"))},[e,r.length]),f.useEffect(()=>{if(!g.trim()){b([]);return}const z=setTimeout(async()=>{h(!0);try{b(await u(g,i))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(z)},[g,i,u]);const k=f.useCallback(z=>{x(z.target.value),z.target.value.trim()&&j("search")},[]),$=f.useCallback(z=>s?z.filter(N=>N.id!==s):z,[s]);if(!e)return null;const v=n||(i==="all"?"选择实体":`选择${Gs(i)}`),_=$(r),w=$(m);return t.jsx("div",{style:Ap,children:t.jsxs("div",{style:Wp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:v}),t.jsx("button",{onClick:c,style:Mp,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:g,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Fp}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),S&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),_.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs(Yo,{active:y==="recent",onClick:()=>j("recent"),children:["最近使用 (",_.length,")"]}),t.jsxs(Yo,{active:y==="search",onClick:()=>j("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:y==="recent"&&_.length>0?t.jsx(qo,{entities:_,onSelect:p}):g.trim()?S?t.jsx(Mn,{message:"搜索中..."}):w.length>0?t.jsx(qo,{entities:w,onSelect:p}):t.jsx(Mn,{message:"未找到匹配的结果"}):t.jsx(Mn,{message:"输入关键词开始搜索"})}),l&&d&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:d,style:Pp,children:a||"创建新实体"})]})]})})},Yo=({active:e,onClick:n,children:i})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:i}),qo=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(Bp,{entity:i,onClick:()=>n(i)},i.id))}),Bp=({entity:e,onClick:n})=>{const[i,r]=f.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Np(e.type)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:e.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[t.jsx("code",{style:{fontSize:"10px",background:o("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&t.jsx("span",{children:e.author}),e.dynasty&&t.jsx("span",{children:e.dynasty})]})]}),t.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Lp(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Gs(e.type)})]})},Mn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),Ap={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Wp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},Mp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Fp={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},Pp={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Op={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},Dp={work:"📜",collection:"📚",book:"📖",entity:"👤"},Vs=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:a,onAskAI:p,renderSectionActions:c,onDownloadResource:d,downloadStatuses:u,relations:g,onRelationsChange:x})=>{var Z;const m=ue(),[b,S]=f.useState(!1),[h,y]=f.useState("work"),[j,k]=f.useState(""),[$,v]=f.useState(""),[_,w]=f.useState([]),[z,N]=f.useState(!1),[T,C]=f.useState(!1),[P,B]=f.useState("work"),[A,W]=f.useState(""),[V,K]=f.useState(),[E,le]=f.useState(!1),[G,ae]=f.useState(null),[pe,ee]=f.useState([]);f.useRef(null);const X=e.type,ie=X==="work",me=X==="collection",te=X==="book",se=f.useCallback((F,I)=>{n({...e,[F]:I})},[e,n]),fe=f.useCallback((F,I)=>{k(F),y(I),v(m.editor.selectToLink+m.indexType[I]),w([]),S(!0)},[m]),be=f.useCallback(F=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,F)},[r,e.id]),ze=f.useCallback(F=>{s==null||s(F.id,F.type)},[s]),ve=f.useCallback((F,I,D)=>{const M={...D,author:(D==null?void 0:D.author)||e.author,dynasty:D==null?void 0:D.dynasty};B(I),W(F),K(M),C(!0)},[e.author]),ke=f.useCallback((F,I)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,A,{type:P,title:F,inheritData:I}),C(!1)},[r,e.id,A,P]),Ne=f.useCallback(F=>{if(!F.trim()){w([]);return}N(!0),r!=null&&r.searchEntities&&r.searchEntities(F,h).then(I=>{w(I),N(!1)}).catch(()=>{w([]),N(!1)})},[r,h]),Ee=f.useCallback(F=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,j,F.id),S(!1)},[r,e.id,j]),O=f.useCallback(()=>{i()},[i]),ce=f.useCallback(F=>{ae(()=>F),le(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(ee).catch(()=>{})},[r]),oe=f.useCallback((F,I)=>r!=null&&r.searchEntities?r.searchEntities(F,I==="all"?void 0:I):Promise.resolve([]),[r]),he=f.useCallback(F=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(F),ee(I=>[F,...I.filter(D=>D.id!==F.id)].slice(0,10)),G==null||G(F),le(!1),ae(null)},[r,G]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${o("widget-border")}`,paddingBottom:"16px"},children:t.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Dp[X]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(hn,{children:e.id}),t.jsx(hn,{color:Op[X],children:m.indexType[X]})]})}),t.jsx(qe,{title:m.section.basicInfo,onSave:i,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(un,{label:ie?m.editor.workTitle:me?m.editor.collectionTitle:m.editor.bookTitle,value:e.title,onChange:F=>se("title",F)}),te&&t.jsx(un,{label:m.editor.belongsToWork,value:e.workName||"",onChange:F=>se("workName",F)}),t.jsx(Ge,{label:m.editor.authorLabel,value:e.author||"",onChange:F=>se("author",F)}),t.jsx(Ge,{label:m.editor.publicationYearLabel,value:e.publicationYear||"",onChange:F=>se("publicationYear",F)}),(te||me)&&t.jsx(un,{label:m.editor.containedIn,value:e.collection||"",onChange:F=>se("collection",F)}),(te||me)&&t.jsx(Ge,{label:m.editor.holderLabel,value:e.holder||"",onChange:F=>se("holder",F)}),(te||me)&&t.jsx(Ge,{label:te?m.editor.pageLabel:m.editor.volumeLabel,value:e.pages||"",onChange:F=>se("pages",F)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(Ge,{label:m.editor.firstImageLabel,value:e.firstImage||"",onChange:F=>se("firstImage",F)})})]})}),t.jsx(qe,{title:m.section.description,onSave:i,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(bt,{value:e.description||"",onChange:F=>se("description",F),placeholder:m.editor.descriptionPlaceholder})}),(((Z=e.additional_works)==null?void 0:Z.length)||0)>0&&t.jsx(qe,{title:m.section.additionalWorks,onSave:i,children:t.jsx(Hp,{items:e.additional_works||[],onChange:F=>se("additional_works",F)})}),t.jsx(qe,{title:m.section.indexedBy,onSave:i,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Gp,{items:e.indexed_by||[],onChange:F=>se("indexed_by",F)})}),t.jsx(qe,{title:m.section.emendatedBy,onSave:i,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Up,{items:e.emendated_by||[],onChange:F=>se("emendated_by",F)})}),t.jsx(qe,{title:m.section.textResources,onSave:i,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(Gn,{items:e.resources||[],onChange:F=>se("resources",F),onDownload:d,downloadStatuses:u,filterType:"text"})}),t.jsx(qe,{title:m.section.imageResources,onSave:i,children:t.jsx(Gn,{items:e.resources||[],onChange:F=>se("resources",F),onDownload:d,downloadStatuses:u,filterType:"image"})}),t.jsx(qe,{title:m.section.sources,onSave:i,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(Ws,{items:Ms(e.sources||""),onChange:F=>se("sources",Fs(F)),onOpenEntityPicker:ce})}),(te||me)&&t.jsx(qe,{title:m.section.provenance,onSave:i,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(bt,{value:e.provenance||"",onChange:F=>se("provenance",F),placeholder:m.editor.provenancePlaceholder})}),te&&t.jsx(qe,{title:m.section.otherEditions,onSave:i,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(bt,{value:e.otherEditions||"",onChange:F=>se("otherEditions",F),placeholder:m.editor.otherEditionsPlaceholder})}),t.jsx(Ps,{entityType:X,entityId:e.id,entityTitle:e.title,parentWork:g==null?void 0:g.parentWork,parentCollection:g==null?void 0:g.parentCollection,belongsToWork:g==null?void 0:g.belongsToWork,belongsToCollection:g==null?void 0:g.belongsToCollection,childWorks:g==null?void 0:g.childWorks,childCollections:g==null?void 0:g.childCollections,containedBooks:g==null?void 0:g.containedBooks,siblingBooks:g==null?void 0:g.siblingBooks,onLinkEntity:fe,onUnlinkEntity:be,onViewEntity:ze,onCreateAndLink:ve,onSaveRelations:O}),l&&a&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${o("danger-soft-border")}`,background:o("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:o("danger"),fontWeight:600,marginBottom:"8px"},children:m.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"12px"},children:m.editor.dangerZoneDesc}),t.jsx("button",{onClick:a,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("danger")}`,borderRadius:"4px",background:"transparent",color:o("danger"),cursor:"pointer"},children:m.editor.deleteEntity})]}),t.jsx(Ds,{isOpen:b,entityType:h,title:$,onSelect:Ee,onCancel:()=>S(!1),onCreate:()=>{S(!1),ve(j,h)},searchResults:_,onSearch:Ne,isLoading:z,excludeId:e.id}),t.jsx(Hs,{isOpen:T,entityType:P,relationField:A,inheritData:V,onConfirm:ke,onCancel:()=>C(!1)}),t.jsx(Us,{isOpen:E,title:m.action.selectBookOrWork,filterType:"all",recentEntities:pe,excludeId:e.id,onSelect:he,onCancel:()=>{le(!1),ae(null)},onSearch:oe})]})};function Hp({items:e,onChange:n}){const i=ue(),r=(a,p,c)=>{const d=e.map((u,g)=>g===a?{...u,[p]:c}:u);n(d)},s=a=>n(e.filter((p,c)=>c!==a)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((a,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(Ge,{label:i.editor.bookNameLabel,value:a.book_title,onChange:c=>r(p,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(Ge,{label:i.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:c=>r(p,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Ys({items:e,onChange:n,showMeta:i,addLabel:r}){const s=ue(),[l,a]=f.useState(null),p=(u,g,x)=>{const m=e.map((b,S)=>S===u?{...b,[g]:x||void 0}:b);n(m)},c=u=>{n(e.filter((g,x)=>x!==u)),l===u&&a(null)},d=()=>{n([...e,{source:""}]),a(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,g)=>{const x=l===g;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:x?`color-mix(in srgb, ${o("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>a(x?null:g),children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.2s",transform:x?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:m=>{m.stopPropagation(),c(g)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${o("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:o("muted")},children:"✕"})]}),!x&&i&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:o("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),x&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ge,{label:s.label.sourceName,value:u.source,onChange:m=>p(g,"source",m)}),t.jsx(Ge,{label:s.label.sourceBid,value:u.source_bid||"",onChange:m=>p(g,"source_bid",m)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ge,{label:s.label.titleInfo,value:u.title_info||"",onChange:m=>p(g,"title_info",m)}),t.jsx(Ge,{label:s.label.authorInfo,value:u.author_info||"",onChange:m=>p(g,"author_info",m)})]}),t.jsx(Ge,{label:s.label.edition,value:u.edition||"",onChange:m=>p(g,"edition",m)})]}),t.jsx(bt,{value:u.summary||"",onChange:m=>p(g,"summary",m),placeholder:s.editor.summaryPlaceholder}),t.jsx(bt,{value:u.comment||"",onChange:m=>p(g,"comment",m),placeholder:s.editor.commentPlaceholder}),t.jsx(bt,{value:u.additional_comment||"",onChange:m=>p(g,"additional_comment",m),placeholder:s.editor.additionalCommentPlaceholder})]})]},g)}),t.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Gp({items:e,onChange:n}){const i=ue();return t.jsx(Ys,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Up({items:e,onChange:n}){const i=ue();return t.jsx(Ys,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function qs(e){var p,c,d,u,g,x,m;const n=((c=(p=e.authors)==null?void 0:p[0])==null?void 0:c.name)||"",i=((d=e.publication_info)==null?void 0:d.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(g=e.page_count)!=null&&g.number?String(e.page_count.number):((x=e.page_count)==null?void 0:x.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",a={id:e.id,title:e.title,type:e.type,author:n,publicationYear:i,holder:r,pages:s,description:l,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const b=e;if(Array.isArray(b.related_works)){const S=b.related_works.find(h=>h.relation==="part_of");S&&(a.parentWorkId=S.id,a.parentWorkName=S.title)}}if(e.type==="book"){const b=e;a.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(a.collectionId=(m=b.contained_in[0])==null?void 0:m.id)}return a}function Vp(e){const n={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.publicationYear?{year:e.publicationYear}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(n.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(n.work_id=e.workId,e.collectionId&&(n.contained_in=[{id:e.collectionId}])),n}const Yp=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:a,onSave:p,onDelete:c,onNavigate:d,renderLink:u,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:S,onRelationsChange:h,headerExtra:y,className:j,style:k}=e;ue();const[$,v]=f.useState(s),_=l?s:$;f.useEffect(()=>{s!==$&&v(s)},[s]);const w=f.useCallback(()=>{const A=_==="view"?"edit":"view";l?l(A):v(A)},[_,l]),[z,N]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(A=>{A&&N(A)})},[i,r]);const T=n||z,C=f.useMemo(()=>T?qs(T):null,[T]),P=l||!n?t.jsx("button",{onClick:w,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:_==="edit"?o("accent-bg"):"transparent",color:o(_==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?"切换到编辑模式":"切换到查看模式",children:_==="view"?"✏️ 编辑":"👁 查看"}):null,B=t.jsxs(t.Fragment,{children:[P,y]});return!T&&!C?t.jsx(jt,{}):_==="view"?t.jsx(fi,{data:T,transport:r,onNavigate:d?A=>d(A):void 0,renderLink:u,headerExtra:B,className:j,style:k}):C?t.jsxs("div",{className:j,style:k,children:[B&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:B}),t.jsx(Vs,{data:C,onChange:a||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:d,showDelete:!!c,onDelete:c,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:S,onRelationsChange:h})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},Ko=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ks=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,l]=f.useState(null),[a,p]=f.useState(""),[c,d]=f.useState(""),[u,g]=f.useState("idle"),[x,m]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{e&&(l(null),p(""),d(""),g("idle"),m(""))},[e]),f.useEffect(()=>{s&&setTimeout(()=>{var j;return(j=b.current)==null?void 0:j.focus()},100)},[s]),f.useEffect(()=>{if(u==="success"){const j=setTimeout(n,2e3);return()=>clearTimeout(j)}},[u,n]),f.useEffect(()=>{if(!e)return;const j=k=>{k.key==="Escape"&&n()};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[e,n]);const S=async()=>{if(!(!s||!a.trim())){g("submitting"),m("");try{await i({type:s,content:a.trim(),...c.trim()?{contact:c.trim()}:{}}),g("success")}catch(j){g("error"),m(j instanceof Error?j.message:"提交失败,请稍后重试")}}};if(!e)return null;const h=s&&a.trim()&&u!=="submitting",y=Ko.find(j=>j.value===s);return t.jsx("div",{style:qp,onClick:j=>{j.target===j.currentTarget&&n()},children:t.jsxs("div",{style:Kp,onClick:j=>j.stopPropagation(),children:[t.jsxs("div",{style:Jp,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:Zp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:nu,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:o("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Ko.map(j=>t.jsxs("button",{onClick:()=>l(j.value),style:{...Xp,...s===j.value?Qp:{}},children:[t.jsx("span",{children:j.icon})," ",j.label]},j.value))}),t.jsx("textarea",{ref:b,value:a,onChange:j=>p(j.target.value),placeholder:(y==null?void 0:y.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...eu,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:c,onChange:j=>d(j.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:ou}),t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[a.length," / 2000"]}),u==="error"&&t.jsx("div",{style:iu,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:S,disabled:!h,style:{...tu,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},qp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Kp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},Jp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Zp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:o("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Xp={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Qp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},eu={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},tu={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},nu={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},iu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginBottom:"12px"},ou={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},oi="--bim-feedback-fab-offset",ri=48,ru=16,su=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,a]=f.useState(!1),p=n.bottom??24;return f.useEffect(()=>{if(r||typeof document>"u")return;const c=document.documentElement;return c.style.setProperty(oi,`calc(${p+ri+ru}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(oi)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>a(!0),style:{...lu,zIndex:s??o("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.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:t.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"})})}),t.jsx(Ks,{isOpen:l,onClose:()=>a(!1),onSubmit:e,feedbackListUrl:i})]})},lu={position:"fixed",width:`${ri}px`,height:`${ri}px`,borderRadius:"50%",border:"none",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:o("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},Jo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Js=({onSubmit:e})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[l,a]=f.useState(""),[p,c]=f.useState("idle"),[d,u]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var S;return(S=g.current)==null?void 0:S.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){c("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),c("success"),s(""),a(""),i("bug")}catch(S){c("error"),u(S instanceof Error?S.message:"提交失败,请稍后重试")}}},m=n&&r.trim()&&p!=="submitting",b=Jo.find(S=>S.value===n);return p==="success"?t.jsx("div",{style:Zo,children:t.jsxs("div",{style:uu,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>c("idle"),style:xu,children:"继续提交"})]})}):t.jsxs("div",{style:Zo,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Jo.map(S=>t.jsxs("button",{onClick:()=>i(S.value),style:{...au,...n===S.value?cu:{}},children:[t.jsx("span",{children:S.icon})," ",S.label]},S.value))}),t.jsx("textarea",{ref:g,value:r,onChange:S=>s(S.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...du}}),t.jsx("input",{type:"text",value:l,onChange:S=>a(S.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:gu}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:x,disabled:!m,style:{...pu,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:fu,children:d})]})},Zo={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},au={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},cu={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},du={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},pu={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},uu={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},xu={background:"none",border:"none",color:o("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},fu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginTop:"8px"},gu={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function Xo(e){return typeof e=="function"?e():e??"/api/feedback"}const Zs=({resourceId:e,apiUrl:n})=>{const[i,r]=f.useState([]),[s,l]=f.useState(!0),a=f.useCallback(async()=>{const c=Xo(n);l(!0);try{const u=await(await fetch(`${c}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);f.useEffect(()=>{a()},[a]);const p=async c=>{const d=Xo(n),u=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...c,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const g=await u.json().catch(()=>null);throw new Error((g==null?void 0:g.error)||"提交失败")}setTimeout(()=>a(),500)};return t.jsxs("div",{children:[t.jsx(Pi,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Js,{onSubmit:p})})]})},Qo={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 er(e){return e?Qo[e]??e:Qo.related}const mu={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function hu(e){return mu[e]??e}const bu={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function yu(e){return bu[e]??""}function Oi({authors:e,onNavigate:n,renderLink:i}){const{convert:r}=q(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,a)=>{const p=ji(l.role);return t.jsxs(f.Fragment,{children:[a>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Be,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:i,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},a)})}):null}function Xs(e,n){var p,c;const i=bi(e,n),r=i.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=i.buckets.filter(d=>d.key==="image"||d.key==="textImage").flatMap(d=>d.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=i.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((c=i.buckets.find(d=>d.key==="text"))==null?void 0:c.items)??[],groups:r}}function Qs(e,n){const i=(e.url?Nt(e.url):void 0)||e.name,r=Fr(e,n);return r?`${i}(${r})`:i}function Di({item:e,siblings:n,listedVolumeCounts:i}){const{convert:r}=q(),[s,l]=f.useState(!1),a=bn(e),p=!!a&&a.expected>0&&!(i!=null&&i.has(a.expected)),c=r(Qs(e,n)),d=Lt(e),u=Sn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var x,m;const g=(x=e.metadata)!=null&&x.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((m=e.metadata)==null?void 0:m.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("殘片")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:r(e.color_mode==="color"?"彩色":"黑白")})]}):null;return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[c," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),g]}):t.jsxs("span",{className:"bim-d-zt-name",children:[c,g]})})(),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(Si,{item:e})})]}),t.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(g=>!g),children:r(s?"收起分冊":`展開 ${a.expected} 冊`)})})]})}function el({groups:e,listedVolumeCounts:n}){const{convert:i}=q();return t.jsx(t.Fragment,{children:e.map(r=>t.jsxs("div",{className:"bim-d-rg",children:[r.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:i(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:i(r.description)}),r.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:r.rows.map((s,l)=>t.jsx(Di,{item:s,siblings:r.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),r.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[r.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:i("鏡像")}),r.mirrors.map((s,l)=>{const a=Lt(s),p=i(Qs(s,r.mirrors));return a?t.jsxs("a",{href:a,target:"_blank",rel:"noopener noreferrer",title:s.details?i(s.details):void 0,children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:p},l)})]})]},r.key))})}const Yt=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function si(e){var i;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(i=Yt.find(r=>n.startsWith(r.key[0])))==null?void 0:i.key}const tr=12,ju=60,tl=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:a,railLinks:p})=>{var ke,Ne,Ee;const c=ue(),{convert:d}=q(),u=f.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[g,x]=f.useState(new Map),[m,b]=f.useState(!1),[S,h]=f.useState(""),[y,j]=f.useState(!1),k=u.length<=ju,$=k||m||!!S||y,v=f.useMemo(()=>$?u:u.slice(0,tr),[u,$]);f.useEffect(()=>{if(!n||v.length===0)return;const O=v.filter(oe=>!g.has(oe));if(O.length===0)return;let ce=!1;return Promise.all(O.map(oe=>n.getItem(oe).then(he=>{const Z=he??{};return[oe,{id:oe,title:Z.title,edition:Z.edition,resources:Z.resources,publication_info:Z.publication_info,current_location:Z.current_location,lineage:Z.lineage,measure_info:Z.measure_info}]}).catch(()=>[oe,{id:oe}]))).then(oe=>{ce||x(he=>{const Z=new Map(he);for(const[F,I]of oe)Z.set(F,I);return Z})}),()=>{ce=!0}},[n,v,g]);const _=f.useMemo(()=>u.map(O=>g.get(O)??{id:O}),[u,g]),w=u.length>0&&u.every(O=>g.has(O)),z=!!n&&v.some(O=>!g.has(O)),N=k||$,T=f.useMemo(()=>Or(_,e.version_graph,{era:S,scanOnly:y,sort:N?"year":"default"}),[_,e.version_graph,S,y,N]),C=m?T.rows:T.rows.slice(0,tr),P=T.allRows.filter(O=>O.hasImage).length,B=e.related_works||[],A=B.filter(O=>O.relation==="collected_in"),W=f.useMemo(()=>{const O=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],ce=oe=>{const he=O.indexOf(oe??"");return he<0?O.length:he};return B.filter(oe=>oe.relation!=="collected_in").map((oe,he)=>({r:oe,i:he})).sort((oe,he)=>ce(oe.r.relation)-ce(he.r.relation)||oe.i-he.i).map(oe=>oe.r)},[B]),V=f.useMemo(()=>{const O=bi(e.resources,e.resource_groups);return[...O.mirrors.flatMap(ce=>ce.items.map(oe=>({r:oe,kind:d(ce.label)}))),...O.buckets.flatMap(ce=>ce.items.map(oe=>({r:oe,kind:d(yu(ce.key))})))]},[e.resources,e.resource_groups,d]),K=e.indexed_by||[],E=e.emendated_by||[],le=f.useMemo(()=>{var M,ne,R;const O=[],ce=(ne=(M=e.authors)==null?void 0:M[0])==null?void 0:ne.dynasty;ce&&O.push({label:"成書",value:d(ce)});const oe=at(e,c.unit.juan);if(oe){const J=(R=e.juan_count)==null?void 0:R.description;O.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[d(oe),J&&J!==oe?t.jsxs("span",{className:"bim-d-meta",children:["(",d(J),")"]}):null]})})}e.loss_status&&O.push({label:"存佚",value:d(hu(e.loss_status))});const he=T.allRows.filter(J=>J.sortYear!=null),Z=he.length>0?he.reduce((J,H)=>J.sortYear<=H.sortYear?J:H):null;Z!=null&&Z.era.era?O.push({label:"最早存世",value:d([Z.era.era,Z.era.reign].filter(Boolean).join(" ")),title:Z.era.source==="edition"?d("據版本題名推斷"):void 0}):z&&O.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),E.length&&O.push({label:"考證",value:`${E.length} ${d("條")}`});const F=nr(e.additional_titles);F.length&&O.push({label:"又名",value:F.map(d).join("、")});const I=nr(e.attached_texts);I.length&&O.push({label:"附載",value:I.map(d).join("、")});const D=(e.additional_works||[]).map(J=>d(J.book_title)+(J.n_juan!=null?` ${J.n_juan}${d(c.unit.juan)}`:""));return D.length&&O.push({label:"附錄",value:D.join("、")}),O},[e,d,c,z,T.allRows,E.length]),ae=[{value:e._edition_count??u.length,label:"版本"},{value:w?P:0,label:"有影印"},{value:K.length,label:"家著錄"}],pe=e.classification,ee=pe?[pe.l1,pe.l2,pe.l3,pe.l4].filter(Boolean).map(O=>d(O)):[],X=e.subtype?d(c.workSubtype[e.subtype]??e.subtype):"",ie=t.jsx(Xt,{title:d(e.title),byline:t.jsx(Oi,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(Me,{items:[...ee,pe!=null&&pe.source?d(`據《${pe.source.split("/")[0]}》`):"",X]}),description:(ke=e.description)!=null&&ke.text?t.jsxs(t.Fragment,{children:[t.jsx(lt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Ne=e.description.sources)!=null&&Ne.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(O=>d(rc(O))).filter(Boolean).join(" · ")}):null]}):void 0,stats:ae,facts:le,readAction:s,foot:t.jsx(Qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Ee=e.appendix)==null?void 0:Ee.map((O,ce)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(O.title)}),t.jsx(lt,{text:O.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},ce))}),me=T.eras.length>=2?[{key:"",label:c.catalog.all},...T.eras.map(O=>({key:O,label:`${O} ${T.allRows.filter(ce=>ce.era.era===O).length}`}))]:[],te=[];u.length&&te.push({id:"versions",label:"版本",count:u.length}),K.length&&te.push({id:"catalogs",label:"著錄",count:K.length}),A.length&&te.push({id:"collected",label:"收入叢編",count:A.length}),W.length&&te.push({id:"related",label:"相關書目",count:W.length}),V.length&&te.push({id:"resources",label:"在線資源",count:V.length});const se=u.length===0&&K.length===0,fe=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Fe,{id:"versions",title:"版本",meta:t.jsx(Me,{items:[d(`共 ${u.length} 種`),w&&P?d(`${P} 種有影印`):"",T.rows.length!==T.allRows.length?d(`當前 ${T.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&me.length===0&&u.length>1?"":void 0,children:[me.length>0&&t.jsx(_n,{items:me,value:S,onChange:O=>{h(O),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Qr,{label:"只看有影印",checked:y,onChange:O=>{j(O),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:d(N?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("版本")}),t.jsx("th",{children:d("年代")}),t.jsx("th",{children:d("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:d("影印")})})]})}),t.jsx("tbody",{children:C.map(O=>{var ce;return t.jsx(vu,{row:O,measure:(ce=g.get(O.id))==null?void 0:ce.measure_info,loaded:g.has(O.id),onNavigate:i,renderLink:r},`${O.id}:${g.has(O.id)?"r":"p"}`)})})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(S||y?"當前篩選下沒有版本":"暫無版本著錄")}),T.rows.length>C.length&&t.jsx(Bt,{label:`展開其餘 ${T.rows.length-C.length} 種版本`,onClick:()=>b(!0)}),T.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:d("部分年代據版本題名推斷,非著錄原文")})]}),K.length>0&&t.jsx(ku,{items:K,transport:n,onNavigate:i,renderLink:r}),se&&t.jsx(Fe,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),be=(O,ce)=>t.jsx(Be,{id:O,label:d(ce),onNavigate:i,renderLink:r,dense:!0}),ze=f.useMemo(()=>{const O=new Map;for(const ce of W){const oe=er(ce.relation);O.set(oe,(O.get(oe)??0)+1)}return O.size>1?[...O.entries()].sort((ce,oe)=>oe[1]-ce[1]).slice(0,4).map(([ce,oe])=>`${d(ce)} ${oe}`).join(" · "):void 0},[W,d]),ve=t.jsxs(t.Fragment,{children:[t.jsx(ht,{id:"collected",title:"收入叢編",items:A.map(O=>be(O.id,O.title))}),t.jsx(ht,{id:"related",title:"相關書目",meta:d(`${W.length} 部`),sub:ze,items:W.map(O=>t.jsxs(t.Fragment,{children:[be(O.id,O.title),t.jsx("span",{className:"bim-d-meta",title:O.note?d(O.note):void 0,children:d(er(O.relation))})]}))}),t.jsx(ht,{id:"resources",title:"在線資源",cap:6,items:V.map(({r:O,kind:ce})=>{const oe=d((O.url?Nt(O.url):void 0)||O.name),he=Lt(O);return t.jsxs(t.Fragment,{children:[he?t.jsxs("a",{href:he,target:"_blank",rel:"noopener noreferrer",children:[oe," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:oe}),ce&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:ce})]})})})]});return t.jsx(Zt,{railTop:l,back:a,nav:te,railLinks:p,main:fe,card:ie,side:ve})};function nr(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ir(e,n){return n((e.url?Nt(e.url):void 0)||e.name)}function vu({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=q(),a=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",c=e.holders[0],d=c?ir(c,l):e.locationName?l(e.locationName):"",u=e.images[0],g=u?Lt(u):void 0,x=e.images.map(m=>ir(m,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Be,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.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):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${d?"":" bim-d-zt-blank"}`,children:[d||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(g?t.jsx("a",{className:"bim-d-flag",href:g,target:"_blank",rel:"noopener noreferrer",title:x,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:x,children:l("有影印")}))})]})}function ku({items:e,transport:n,onNavigate:i,renderLink:r}){const s=ue(),{convert:l}=q(),[a,p]=f.useState(0),c=Math.min(a,e.length-1),d=e[c],[u,g]=f.useState(new Map);return f.useEffect(()=>{if(!n)return;const x=[...new Set(e.map(b=>b.source_bid).filter(b=>!!b))];if(x.length===0)return;let m=!1;return Promise.all(x.map(b=>n.getItem(b).then(S=>{var h,y;return[b,((y=(h=S==null?void 0:S.authors)==null?void 0:h[0])==null?void 0:y.dynasty)??""]}).catch(()=>[b,""]))).then(b=>{m||g(new Map(b.filter(([,S])=>S)))}),()=>{m=!0}},[n,e]),t.jsx(Fe,{id:"catalogs",title:"著錄",meta:t.jsx(Me,{items:[l(`歷代書目 ${e.length} 家`),l("按著錄順序")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":l("著錄書目"),children:e.map((x,m)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":m===c,"aria-label":l(x.source),onClick:()=>p(m),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(x.source_bid??"")?l(u.get(x.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...l(x.source)].slice(0,9).map((b,S)=>t.jsx("span",{children:b},S))})]})},m))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:l(d.title_info)}),t.jsx(Me,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?t.jsx(Be,{id:d.source_bid,label:l(d.source),onNavigate:i,renderLink:r,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&&t.jsx("p",{className:"bim-d-quote",children:Ue(l(d.summary))}),d.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:Ue(l(d.comment))})]}),d.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:Ue(l(d.additional_comment))})]}),!d.summary&&!d.comment&&!d.additional_comment&&!d.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:l("僅著錄書名,無提要。")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?t.jsx("button",{type:"button","aria-label":l(`上一家:${e[c-1].source}`),onClick:()=>p(c-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",l(e[c-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",e.length]}),c<e.length-1?t.jsx("button",{type:"button","aria-label":l(`下一家:${e[c+1].source}`),onClick:()=>p(c+1),children:t.jsxs("span",{"aria-hidden":"true",children:[l(e[c+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function Su(e){var n;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((n=e.year_range)==null?void 0:n[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function wu(e,n){if(!e.lineage)return null;const i=e.lineage;return{id:e.id,kind:"book",label:e.title,year:i.year,year_text:i.year_text,year_uncertain:i.year_uncertain,category:i.category,status:i.status,extant_juan:i.extant_juan,group:n[e.id],note:i.note}}function or(e,n,i){return{id:`derive:${n.ref}->${e}:${i}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function _u(e,n,i){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${i}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function $u(e,n){var d;if(n==="all")return null;const i=(d=e.collections)==null?void 0:d[n],r=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,l=r||s||!!(i!=null&&i.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!i||!l)return null;const a=r?new Set(i.groups):null,p=new Set(i.book_ids??[]);if(a&&e.node_groups)for(const[u,g]of Object.entries(e.node_groups))a.has(g)&&p.add(u);let c=null;if(i.hypothetical_ids&&(c=new Set(i.hypothetical_ids)),a){c||(c=new Set);for(const u of e.hypothetical_nodes??[])u.group&&a.has(u.group)&&c.add(u.id)}return{books:p,hypos:c}}function xn(e,n,i){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const l=new Set(r.excluded_books??[]),a=r.node_groups??{},p=$u(r,i??r.default_collection??"all"),c=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,g=new Set,x=new Set;if(c){const $=new Map(n.map(T=>[T.id,T])),v=new Map((r.hypothetical_nodes??[]).map(T=>[T.id,T])),_=T=>{const C=$.get(T);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(B=>B.ref);const P=v.get(T);return P?(P.derived_from??[]).map(B=>B.ref):[]},w=T=>v.has(T)?!u||u.has(T):!d||d.has(T),z=new Set,N=T=>{if(!z.has(T)){z.add(T);for(const C of _(T))l.has(C)||(w(C)||(v.has(C)?x.add(C):$.has(C)&&g.add(C)),N(C))}};for(const T of n)d&&d.has(T.id)&&!l.has(T.id)&&N(T.id);for(const T of r.hypothetical_nodes??[])u&&u.has(T.id)&&N(T.id)}const m=n.filter($=>!l.has($.id)).filter($=>!d||d.has($.id)||g.has($.id)).map($=>{const v=wu($,a);return v&&g.has($.id)&&(v.bridge=!0),v}).filter($=>$!==null),b=(r.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||x.has($.id)).map($=>{const v=Su($);return x.has($.id)&&(v.bridge=!0),v}),S=[...m,...b],h=new Set(S.map($=>$.id)),y=new Set,j=[],k=$=>{y.has($.id)||!h.has($.source)||!h.has($.target)||(y.add($.id),j.push($))};for(const $ of n)l.has($.id)||!$.lineage||d&&!d.has($.id)&&!g.has($.id)||(($.lineage.derived_from??[]).forEach((v,_)=>{k(or($.id,v,_))}),($.lineage.related_to??[]).forEach((v,_)=>{k(_u($.id,v,_))}));for(const $ of r.hypothetical_nodes??[])u&&!u.has($.id)&&!x.has($.id)||($.derived_from??[]).forEach((v,_)=>{k(or($.id,v,_))});return{nodes:S,edges:j,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function nl(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function zu(e,n){const i=[],r=e.version_graph;if(!r)return i;const s=new Set(n.map(c=>c.id)),l=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),a=new Set([...s,...l]),p=(c,d)=>{a.has(d.ref)||i.push(`${c}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${c}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&i.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)||i.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const d=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>p(d,u))}return i}const il=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:s}=q();if(!e.nodes.length)return t.jsx("div",{style:{...Ou,...r},className:i,children:"暂无版本图数据"});const l=new Map,a=new Map;for(const x of e.edges)if(x.kind==="derive"){const m=l.get(x.target)??[];m.push(x),l.set(x.target,m)}else for(const m of[x.source,x.target]){const b=a.get(m)??[];b.push(x),a.set(m,b)}const p=new Map(e.nodes.map(x=>[x.id,x])),c=new Map,d=[];for(const x of e.nodes)if(x.group){const m=c.get(x.group)??[];m.push(x),c.set(x.group,m)}else d.push(x);const u=(x,m)=>(x.year??9999)-(m.year??9999);c.forEach(x=>x.sort(u)),d.sort(u);const g=e.groups.filter(x=>c.has(x.id));return t.jsxs("div",{className:i,style:{...Iu,...r},children:[e.title&&t.jsx("div",{style:Tu,children:s(e.title)}),e.description&&t.jsx("div",{style:Eu,children:s(e.description)}),g.map(x=>t.jsx(rr,{label:x.label,color:x.color,nodes:c.get(x.id),incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n},x.id)),d.length>0&&t.jsx(rr,{label:"其他",nodes:d,incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n})]})},rr=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:a})=>{const{convert:p}=q();return t.jsxs("div",{style:Ru,children:[t.jsx("div",{style:{...Nu,borderLeftColor:n??o("widget-border")},children:p(e)}),i.map(c=>t.jsx(Cu,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:a},c.id))]})},Cu=({node:e,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",a=e.bridge,{convert:p}=q();return t.jsxs("div",{style:{...Lu,borderStyle:l||a?"dashed":"solid",opacity:a?.55:e.status==="lost"?.7:1,background:a?o("bg-subtle"):void 0},title:a?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:Bu,children:[t.jsx("span",{style:Au,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Wu,children:nl(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Mu,children:[e.category&&t.jsx(Ot,{children:p(e.category)}),e.status==="lost"&&t.jsx(Ot,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(Ot,{tone:"warn",children:"残本"}),l&&t.jsx(Ot,{tone:"info",children:"假想祖本"}),a&&t.jsx(Ot,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Fu,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:Pu,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:lr,children:[t.jsx("div",{style:ar,children:"来源:"}),n.map(c=>{const d=r.get(c.source);return t.jsxs("div",{style:cr(c.confidence),children:[t.jsx("span",{style:dr,children:p(c.relation)}),t.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"&&t.jsx(sr,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:pr,children:["· ",p(c.evidence)]})]},c.id)})]}),i.length>0&&t.jsxs("div",{style:lr,children:[t.jsx("div",{style:ar,children:"关联:"}),i.map(c=>{const d=c.source===e.id?c.target:c.source,u=r.get(d);return t.jsxs("div",{style:cr(c.confidence),children:[t.jsx("span",{style:dr,children:p(c.relation)}),t.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)}),t.jsx(sr,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:pr,children:["· ",p(c.evidence)]})]},c.id)})]})]})},Ot=({children:e,tone:n="default"})=>{const r={default:{bg:o("tag-bg"),fg:o("fg")},warn:{bg:o("warn-bg"),fg:o("warn-fg")},info:{bg:o("info-bg"),fg:o("info-fg")}}[n];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},sr=({level:e})=>{const i={certain:{label:"确定",color:o("confidence-certain")},consensus:{label:"共识",color:o("confidence-consensus")},probable:{label:"推测",color:o("confidence-probable")},disputed:{label:"有争议",color:o("confidence-disputed")}}[e];return i?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${i.color}`,color:i.color,borderRadius:"8px",marginLeft:"4px"},children:i.label}):null},Iu={fontSize:"14px",color:o("fg")},Tu={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Eu={fontSize:"13px",color:o("muted"),marginBottom:"16px",lineHeight:1.6},Ru={marginBottom:"16px"},Nu={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:o("fg")},Lu={border:`1px solid ${o("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:o("bg")},Bu={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Au={fontSize:"15px",fontWeight:600},Wu={fontSize:"12px",color:o("muted")},Mu={marginBottom:"6px"},Fu={fontSize:"12px",color:o("muted"),margin:"2px 0"},Pu={fontSize:"12px",color:o("muted"),fontStyle:"italic",margin:"4px 0"},lr={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${o("widget-border")}`},ar={fontSize:"11px",color:o("muted"),marginBottom:"2px"},cr=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),dr={display:"inline-block",padding:"0 6px",fontSize:"11px",background:o("tag-bg"),color:o("fg"),borderRadius:"3px",marginRight:"6px"},pr={fontSize:"11px",color:o("muted")},Ou={padding:"20px",textAlign:"center",color:o("muted"),fontSize:"13px"},ol=({selectedNodeId:e,...n})=>{const[i,r]=f.useState("loading"),[s,l]=f.useState(null);return f.useEffect(()=>{let a=!1;return Du().then(p=>{a||(p?(l(p),r("ready")):r("missing"))}),()=>{a=!0}},[]),i==="loading"?t.jsx("div",{style:ur,children:"加载图组件中…"}):i==="missing"||!s?t.jsxs("div",{style:ur,children:[t.jsxs("div",{children:["图组件未安装。请安装 ",t.jsx("code",{children:"@xyflow/react"})," 与 ",t.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),t.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",t.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):t.jsx(Hu,{modules:s,selectedNodeId:e,...n})};async function Du(){try{const[e,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let i=!1;try{await import("@xyflow/react/dist/style.css"),i=!0}catch{i=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:n,cssLoaded:i}}catch{return null}}const Hu=({graph:e,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:l,modules:a})=>{const{ReactFlow:p,Background:c,Controls:d,Handle:u,Position:g,BaseEdge:x,EdgeLabelRenderer:m,getSmoothStepPath:b,dagre:S}=a,h=f.useMemo(()=>({lineage:_=>{var V,K,E,le;const w=((V=_.data)==null?void 0:V.stepPosition)??.85,[z,N,T]=b({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:w,borderRadius:5}),C=!!((K=_.data)!=null&&K.isSibling),P=C?N:_.targetX-18,B=C?T:_.targetY-12,A=(E=_.data)==null?void 0:E.labelStyle,W=(le=_.data)==null?void 0:le.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(x,{id:_.id,path:z,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&t.jsx(m,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${P}px,${B}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:o("bg"),border:`0.5px solid ${o("widget-border")}`,...W,...A},children:_.label})})]})}}),[x,m,b]),y=f.useMemo(()=>({version:_=>{const w=_.data,z=w.kind==="hypothetical",N=w.status==="lost",T=w.isSelected,C=w.bridge,P=w.borderColor??o("muted"),B=C||z?"dashed":"solid",A=C?.5:N?.6:1;return t.jsxs("div",{style:{background:o(C?"bg-subtle":"bg"),border:`2px ${B} ${T?o("primary"):P}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:A,boxShadow:T?o("shadow-node-selected"):z||C?"none":o("shadow-node")},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:g.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!w.renderLink?w.label:w.renderLink(w.bookId,w.label)}),w.description&&t.jsx("div",{style:{fontSize:10,color:o("aux-fg"),lineHeight:1.25,marginTop:1},children:w.description}),w.yearText&&t.jsx("div",{style:{fontSize:10,color:o("aux-fg"),lineHeight:1.2},children:nl(w.yearText,void 0,w.uncertain)}),N&&t.jsx("div",{style:{fontSize:9,color:o("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:g.Right,style:{visibility:"hidden"}})]})}}),[u,g]),{convert:j}=q(),{rfNodes:k,rfEdges:$}=f.useMemo(()=>Gu(e,S,n,l,j),[e,S,n,l,j]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:t.jsxs(p,{nodes:k,edges:$,nodeTypes:y,edgeTypes:h,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(d,{showInteractive:!1})]})})};function Gu(e,n,i,r,s=l=>l??""){const p=e.layout==="LR"||!e.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(e.groups.map(y=>[y.id,y.color??o("muted")]));for(const y of e.nodes)c.setNode(y.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const y of e.edges)y.kind==="derive"&&(u.has(y.relation)||c.setEdge(y.source,y.target));n.layout(c);const g=e.nodes.map(y=>{const j=c.node(y.id),k=r?y.id===r:void 0,$={kind:y.kind,label:s(y.label),bookId:y.kind==="book"?y.id:void 0,yearText:s(y.year_text??Vu(y)),uncertain:y.year_uncertain,category:y.category,status:y.status,borderColor:y.group?d.get(y.group):void 0,renderLink:i,isSelected:k,description:s(y.description),bridge:y.bridge};return{id:y.id,type:"version",position:{x:j.x-160/2,y:j.y-90/2},data:$,draggable:!1,selected:k}}),x=.78,m=.06,b=new Map;for(const y of e.edges)y.kind==="derive"&&(b.has(y.source)||b.set(y.source,[]),b.get(y.source).push(y));const S=new Map;for(const[y,j]of b){if(j.length<=1)continue;const k=[...j].sort((v,_)=>{var N,T;const w=((N=c.node(v.target))==null?void 0:N.y)??0,z=((T=c.node(_.target))==null?void 0:T.y)??0;return w-z}),$=k.length;k.forEach((v,_)=>{const w=(_-($-1)/2)*m;S.set(v.id,x+w)})}const h=e.edges.map(y=>Uu(y,S.get(y.id),s));return{rfNodes:g,rfEdges:h}}function Uu(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Yu(e.confidence),a={type:"arrowclosed",color:l,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:i(e.relation),data:{labelStyle:{color:o("fg")},isSibling:s,stepPosition:n},style:{stroke:l,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:a,markerStart:s?a:void 0,zIndex:1e3}}function Vu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Yu(e){switch(e){case"certain":return o("confidence-certain");case"consensus":return o("lineage-edge-consensus");case"probable":return o("confidence-probable");case"disputed":return o("confidence-disputed");default:return o("muted")}}const ur={padding:"40px 20px",textAlign:"center",color:o("muted"),fontSize:"13px",border:`1px dashed ${o("widget-border")}`,borderRadius:8,background:o("bg")},Hi=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:a,onCollectionChange:p,collectionsAvailable:c,collectionCounts:d,className:u,style:g})=>{var j;const[x,m]=f.useState(n),b=k=>{m(k),l==null||l(k)},S=(()=>{if(!c)return[];const k=Object.entries(c);return k.length===0||c.all?k:[...k,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),h=!!(p&&S.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:o("muted"),textAlign:"center"},children:"暂无版本传承数据"});const y=a?(j=c==null?void 0:c[a])==null?void 0:j.description:void 0;return t.jsxs("div",{className:u,style:g,children:[t.jsxs("div",{style:qu,children:[t.jsx("button",{onClick:()=>b("list"),style:Fn(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:Fn(x==="graph"),children:"关系图"}),h&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:o("muted"),marginRight:4},children:"集合:"}),S.map(([k,$])=>{const v=d==null?void 0:d[k];return t.jsxs("button",{onClick:()=>p==null?void 0:p(k),style:Fn(a===k),title:$.description,children:[$.label,v!=null?` ${v}`:""]},k)})]})]}),h&&y&&t.jsx("div",{style:{fontSize:12,color:o("muted"),marginBottom:8,padding:"4px 8px",background:o("bg-subtle"),borderRadius:4},children:y}),x==="list"?t.jsx(il,{graph:e,renderLink:i}):t.jsx(ol,{graph:e,renderLink:i,height:r,selectedNodeId:s})]})},qu={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Fn=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${o("widget-border")}`,borderRadius:4,background:e?o("primary"):"transparent",color:o(e?"primary-fg":"fg"),cursor:"pointer"}),xr=40,fr=2,Ku=9,gr={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function Pn(e){if(!e)return["",""];const n=e.split(/[ ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const rl=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,fullText:l,fullTextPending:a,chapterLink:p,railTop:c,back:d,railLinks:u})=>{var M,ne,R,J,H,U,re,Se,ye,Le,Ye;const g=ue(),{convert:x}=q(),[m,b]=f.useState(null),[S,h]=f.useState(new Map),[y,j]=f.useState([]),[k,$]=f.useState(new Map),[v,_]=f.useState(!1),[w,z]=f.useState("flow"),[N,T]=f.useState(null);f.useEffect(()=>{if(!n||!e.work_id){b(null);return}let L=!1;return n.getItem(e.work_id).then(de=>{!L&&de&&de.type==="work"&&b(de)}).catch(()=>{}),()=>{L=!0}},[n,e.work_id]),f.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){T(null);return}let L=!1;return n.getLineageGraph(e.work_id).then(de=>{L||T(de&&de.nodes.length>1?de:null)}).catch(()=>{L||T(null)}),()=>{L=!0}},[n,e.work_id]),f.useEffect(()=>{const L=e.contained_in||[];if(!n||L.length===0){h(new Map);return}let de=!1;return Promise.all(L.map(ge=>{const $e=typeof ge=="string"?ge:ge.id;return n.getItem($e).then(xe=>[$e,xe]).catch(()=>[$e,null])})).then(ge=>{if(de)return;const $e=new Map;for(const[xe,Ce]of ge)Ce&&$e.set(xe,Ce);h($e)}),()=>{de=!0}},[n,e.contained_in]);const C=f.useMemo(()=>{const L=new Set([...(m==null?void 0:m.books)||[],...e.related_books||[]]);return L.add(e.id),[...L]},[m==null?void 0:m.books,e.related_books,e.id]),P=C.length-1;f.useEffect(()=>{if(!n||P<=0){j([]);return}const L=C.length<=xr,de=L?C:C.slice(0,8);let ge=!1;return Promise.all(de.map($e=>$e===e.id?Promise.resolve({id:$e,title:e.title,edition:e.edition,year:gn(e)}):n.getItem($e).then(xe=>{const Ce=xe??{};return{id:$e,title:Ce.title,edition:Ce.edition,year:xe?gn(Ce):void 0}}).catch(()=>({id:$e})))).then($e=>{if(ge)return;const xe=$e.filter(Ce=>Ce.id===e.id||Ce.title||Ce.edition);L&&xe.sort((Ce,Oe)=>(Ce.year??1/0)-(Oe.year??1/0)),j(xe)}),()=>{ge=!0}},[n,C,P,e]);const B=e.lineage,A=f.useMemo(()=>[...((B==null?void 0:B.derived_from)||[]).filter(L=>L.ref_type==="book").map(L=>L.ref),...((B==null?void 0:B.related_to)||[]).map(L=>L.book_id)].filter(Boolean),[B]);f.useEffect(()=>{if(!n||A.length===0){$(new Map);return}let L=!1;return Promise.all(A.map(de=>n.getItem(de).then(ge=>[de,{id:de,title:ge==null?void 0:ge.title,edition:ge==null?void 0:ge.edition}]).catch(()=>[de,{id:de}]))).then(de=>{L||$(new Map(de))}),()=>{L=!0}},[n,A]);const W=f.useMemo(()=>Xs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),V=W.groups.reduce((L,de)=>L+de.rows.length+de.mirrors.length,0),K=W.groups.length>0&&W.groups.every(L=>L.key==="_physical"),E=Jt(e),le=Vr(e),G=at(e,g.unit.juan),ae=new Set((e.contained_in||[]).map(L=>typeof L=="string"?0:Ut(L.volume_index).length).filter(L=>L>0)),pe=L=>{var $e;const de=($e=e.base_edition)==null?void 0:$e.find(xe=>xe.book_id===L&&xe.name);if(de!=null&&de.name)return de.name;const ge=k.get(L);return(ge==null?void 0:ge.edition)||(ge==null?void 0:ge.title)||""},ee=f.useMemo(()=>{var ct,nn,dt,on,rn;const L=[];le&&L.push({label:"版本類型",value:x(le),title:e.edition_type||(ct=e.lineage)!=null&&ct.category?void 0:x("據版本題名推斷")}),(nn=e.publication_info)!=null&&nn.details?L.push({label:"刊印",value:x(e.publication_info.details)}):(E.era||E.reign)&&L.push({label:"刊寫年代",value:x([E.era,E.reign].filter(Boolean).join(" ")),title:E.source==="edition"?x("據版本題名推斷"):void 0}),G&&L.push({label:"卷帙",value:x(G)});const de=(e.contained_in||[]).flatMap(_e=>typeof _e=="string"?[]:Ut(_e.volume_index));de.length&&L.push({label:"冊次",value:x(`第 ${wn(de,g.unit.volume)} ${g.unit.volume}(${de.length} ${g.unit.volume})`)});const ge=(((dt=e.lineage)==null?void 0:dt.derived_from)||[]).find(_e=>_e.relation==="底本"&&_e.ref_type==="book");ge&&pe(ge.ref)&&L.push({label:"底本",value:t.jsx(Be,{id:ge.ref,label:x(pe(ge.ref)),onNavigate:i,renderLink:r,dense:!0})});const $e=(e.base_edition||[]).filter(_e=>_e&&_e.name);for(const _e of["底本","配補","參校"]){if(_e==="底本"&&ge&&pe(ge.ref))continue;const Ze=$e.filter(Re=>Re.role===_e);Ze.length&&L.push({label:_e,value:Ze.map((Re,kt)=>t.jsxs(f.Fragment,{children:[kt>0&&"、",Re.book_id?t.jsx(Be,{id:Re.book_id,label:x(Re.name),onNavigate:i,renderLink:r,dense:!0}):x(Re.name)]},kt))})}const xe=(e.provenance||[]).filter(_e=>_e&&_e.institution),Ce=(e.resources||[]).filter(_e=>(_e.types||(_e.type?[_e.type]:[])).includes("physical"));if(xe.length){L.push({label:"存藏",value:xe.slice(0,2).map(Re=>x(Re.institution)).join("、")+(xe.length>2?x(` 等 ${xe.length} 處`):"")});const _e=xe.filter(Re=>Re.call_number).slice(0,2).map(Re=>`${x(Re.institution)} ${Re.call_number}`);_e.length&&L.push({label:"索書號",value:_e.join(";")+(xe.filter(Re=>Re.call_number).length>2?"…":"")});const Ze=xe.flatMap(Re=>Re.seals||[]).filter(Boolean);Ze.length&&L.push({label:"藏印",value:x(Ze.join("、"))})}else Ce.length?L.push({label:"存藏",value:Ce.slice(0,2).map(_e=>x(_e.name)).join("、")+(Ce.length>2?x(` 等 ${Ce.length} 處`):"")}):(on=e.current_location)!=null&&on.name&&L.push({label:"存藏",value:x(e.current_location.name)});const Oe=e.physical_description;if(Oe){const _e=[["行款",Oe.leaf_style],["裝幀",Oe.binding],["尺寸",Oe.dimensions],["品相",Oe.condition]];for(const[Ze,Re]of _e)Re&&Re.trim()&&L.push({label:Ze,value:x(Re)})}(rn=e.page_count)!=null&&rn.description&&L.push({label:g.label.pageCount,value:x(e.page_count.description)});const Je=[...Xn(e.additional_titles),...Xn(e.attached_texts)];return Je.length&&L.push({label:"又名",value:Je.map(x).join("、")}),L},[e,x,g,E,le,G,k,i,r]),X=x(e.title),ie=e.edition?x(e.edition):void 0,me=((M=e.lineage)==null?void 0:M.year_text)||"",te=t.jsx(Xt,{kind:"版本",title:X,subtitle:ie,byline:t.jsx(Oi,{authors:e.authors??(m==null?void 0:m.authors),onNavigate:i,renderLink:r}),meta:(()=>{const L=[le?x(le):"",E.era?x([E.era,E.reign].filter(Boolean).join("")):"",G?x(G):""].filter(Boolean);return L.length?t.jsx("span",{className:"bim-d-tags",children:L.map((de,ge)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ge,2)}`,children:de},ge))}):null})(),description:(ne=e.description)!=null&&ne.text?t.jsx(lt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:vi((R=e.description)==null?void 0:R.text)?6:void 0,facts:ee,readAction:s,secondaryAction:s&&V>0&&!K?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(Qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),se=e.contained_in||[],fe=(l==null?void 0:l.chapters)||[],be=fe[0]&&Pn(fe[0].title)[0].slice(-1)||"章",ze=!!((J=B==null?void 0:B.derived_from)!=null&&J.length||(H=B==null?void 0:B.related_to)!=null&&H.length||(U=e.appendix)!=null&&U.length),ve=[];(fe.length||W.text.length||a)&&ve.push({id:"fulltext",label:"全文",count:fe.length?x(`${fe.length} ${be}`):void 0}),W.groups.length&&ve.push({id:"images",label:K?"館藏":"影印",count:V}),ze&&ve.push({id:"lineage",label:"版本源流"}),se.length&&ve.push({id:"collections",label:"收入叢編",count:se.length}),(re=e.location_history)!=null&&re.length&&ve.push({id:"provenance",label:"流轉歷史"});const ke=L=>(p==null?void 0:p(L))??null,Ne=fe[0],Ee=Ne?ke(Ne.file):null,O=v?fe:fe.slice(0,Ku),ce=(L,de,ge)=>L?t.jsx("a",{className:ge,href:L.href??"#",onClick:L.onClick?$e=>{$e.metaKey||$e.ctrlKey||($e.preventDefault(),L.onClick())}:void 0,children:de}):t.jsx("span",{className:ge,children:de}),oe=t.jsxs(t.Fragment,{children:[(fe.length>0||W.text.length>0||a)&&t.jsxs(Fe,{id:"fulltext",title:"全文",meta:fe.length>0?t.jsx(Me,{items:[x(`${fe.length} ${be}`),(Se=l==null?void 0:l.source)!=null&&Se.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[a&&!Ne&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),Ne&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${Pn(Ne.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((Ne.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),ce(Ee,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),fe.length>1&&t.jsx("ul",{className:"bim-d-chap",children:O.map(L=>{const[de,ge]=Pn(L.title);return t.jsx("li",{children:ce(ke(L.file),t.jsxs(t.Fragment,{children:[de&&t.jsx("b",{children:x(de)}),x(ge||L.file)]}))},L.file)})}),fe.length>O.length&&t.jsx(Bt,{label:`展開其餘 ${fe.length-O.length} ${be}`,onClick:()=>_(!0)}),W.text.length>0&&t.jsxs(t.Fragment,{children:[(fe.length>0||a)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:W.text.map((L,de)=>t.jsx(Di,{item:L,siblings:W.text,listedVolumeCounts:ae},`${L.id||L.url||L.name}-${de}`))})})]})]}),W.groups.length>0&&t.jsx(Fe,{id:"images",title:K?"館藏":"影印",meta:t.jsx(Me,{items:[W.groups.length>1?x(`${W.groups.length} 組`):"",x(`${V} 處`)]}),children:t.jsx(el,{groups:W.groups,listedVolumeCounts:ae})}),ze&&t.jsx(Fe,{id:"lineage",title:"版本源流",meta:(ye=B==null?void 0:B.derived_from)!=null&&ye.length?x("據版本傳承著錄"):void 0,action:N?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":x("源流視圖"),children:[t.jsx("button",{type:"button","aria-pressed":w==="flow",onClick:()=>z("flow"),children:x("卡片")}),t.jsx("button",{type:"button","aria-pressed":w==="graph",onClick:()=>z("graph"),children:x("關係圖")})]}):void 0,children:w==="graph"&&N?t.jsx(Hi,{graph:N,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(L,de)=>t.jsx(Be,{id:L,label:x(de),onNavigate:i,renderLink:r,dense:!0})}):t.jsx(Zu,{data:e,heading:ie||X,yearText:me,refName:pe,onNavigate:i,renderLink:r})}),se.length>0&&t.jsx(Fe,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:se.map((L,de)=>{var Oe,Je;const ge=typeof L=="string"?L:L.id,$e=typeof L=="string"?[]:Ut(L.volume_index),xe=S.get(ge),Ce=(xe==null?void 0:xe._member_count)||((Oe=xe==null?void 0:xe.books)==null?void 0:Oe.length)||((Je=xe==null?void 0:xe.contained_works)==null?void 0:Je.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Be,{id:ge,label:xe?x(xe.title):ge,onNavigate:i,renderLink:r,dense:!0}),$e.length>0&&t.jsx(Ju,{volumes:$e,unit:g.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Ce?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Ce>0&&x(`全 ${Ce} ${g.unit.bu}`)})]},`${ge}-${de}`)})})})}),(Le=e.location_history)!=null&&Le.length?t.jsx(Fe,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((L,de)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(L.name)}),([L.start_date,L.end_date].filter(Boolean).join("—")||L.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(Me,{items:[[L.start_date,L.end_date].filter(Boolean).join("—"),L.description?x(L.description):""]})})]},de))})}):null,ve.length===0&&t.jsx(Fe,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),he=y.findIndex(L=>L.id===e.id),Z=C.length<=xr,F=Z&&he>=0?y.slice(Math.max(0,he-fr),he+fr+1):y.filter(L=>L.id!==e.id),I=t.jsxs(t.Fragment,{children:[m&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:x(g.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Be,{id:m.id,label:x(m.title),onNavigate:i,renderLink:r})}),t.jsx(Me,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(m.authors||[]).slice(0,2).map(L=>`${L.dynasty?`〔${x(L.dynasty)}〕`:""}${x(L.name)}`),x(at(m,g.unit.juan)),m._edition_count?x(`${m._edition_count} 種版本`):""]}),((Ye=m.description)==null?void 0:Ye.text)&&t.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:x(m.description.text.replace(/[#*_>`[\]]/g,""))})]}),P>0&&F.length>0&&t.jsxs("div",{children:[t.jsx(ht,{id:"siblings",timeline:!0,title:Z?"同作品版本":g.relation.siblingVersions,meta:x(Z?"按年代":`${P} 種`),cap:F.length,items:F.map(L=>L.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(L.edition||L.title||L.id)}):t.jsx(Be,{id:L.id,label:x(L.edition||L.title||L.id),onNavigate:i,renderLink:r,dense:!0})),metas:F.map(L=>[L.year!=null?L.year<0?`前${-L.year}`:String(L.year):"",L.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:F.findIndex(L=>L.id===e.id)}),m&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Be,{id:m.id,label:x(`在作品頁看全部 ${C.length} 種 →`),onNavigate:i,renderLink:r,dense:!0})})]})]}),D=e.work_id?t.jsx(Xr,{caption:g.section.belongsToWork,children:t.jsx(Be,{id:e.work_id,label:m?x(m.title):" ",onNavigate:i,renderLink:r,dense:!0})}):void 0;return t.jsx(Zt,{railTop:c,back:d,up:D,nav:ve,railLinks:u,main:oe,card:te,side:I})};function Ju({volumes:e,unit:n}){const{convert:i}=q();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${wn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}function Zu({data:e,heading:n,yearText:i,refName:r,onNavigate:s,renderLink:l}){var h;const{convert:a}=q(),p=e.lineage,c=(p==null?void 0:p.derived_from)||[],d=c.filter(y=>y.ref_type!=="book"),u=c.filter(y=>y.ref_type==="book"&&y.relation==="底本"),g=c.filter(y=>y.ref_type==="book"&&y.relation!=="底本"),x=(p==null?void 0:p.related_to)||[],m=c.length>0||x.length>0,b=y=>y&&gr[y]?a(`(${gr[y]})`):"",S=(y,j)=>t.jsx(Be,{id:y,label:a(j||y),onNavigate:s,renderLink:l,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[m&&t.jsxs("ol",{className:"bim-d-lf-list",children:[d.map((y,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(y.relation||"祖本")}),t.jsx("span",{className:"bim-d-lf-name",children:a("擬構祖本")}),y.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[a(y.evidence),b(y.confidence)]})]})},`a-${j}`)),u.map((y,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(y.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:S(y.ref,r(y.ref))}),y.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[a(y.evidence),b(y.confidence)]})]})},`b-${j}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a("本版")}),t.jsx("span",{className:"bim-d-lf-name",children:n}),i&&t.jsx("span",{className:"bim-d-lf-yr",children:a(i)})]}),g.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:g.map((y,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(y.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:S(y.ref,r(y.ref))}),y.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[a(y.evidence),b(y.confidence)]})]},j))})]}),x.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:a("翻刻 · 衍生")}),t.jsx("span",{className:"bim-d-lf-chips",children:x.map((y,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:y.evidence?a(y.evidence):void 0,children:[S(y.book_id,r(y.book_id)),t.jsx("span",{className:"bim-d-meta",children:a(y.relation)})]},j))})]})]}),(h=e.appendix)==null?void 0:h.map((y,j)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:a("附記")})," ",a(y.title)]}),t.jsx(lt,{text:y.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${j}`)),(p==null?void 0:p.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:a(p.note)})]})}const Dt=16,Xu=200,Qu=16,sl=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,railTop:a,back:p,railLinks:c})=>{var he,Z,F,I,D,M,ne;const d=ue(),{convert:u}=q(),[g,x]=f.useState(""),[m,b]=f.useState(!1),[S,h]=f.useState(null),[y,j]=f.useState(""),[k,$]=f.useState(!1),v=f.useMemo(()=>Gr(e,n),[e,n]),[_,w]=f.useState(new Map),z=!!i&&v.rows.length>0&&v.rows.length<=Xu,N=z&&(v.rows.length<=Dt||k),T=N&&v.rows.every(R=>!R.id||_.has(R.id)),C=R=>{var J;return si(R?(J=_.get(R))==null?void 0:J.l1:void 0)},P=f.useMemo(()=>{const R=g.trim(),J=R?u(R):"";return v.rows.filter(H=>{var re,Se;if(y&&si(H.id?(re=_.get(H.id))==null?void 0:re.l1:void 0)!==y)return!1;if(!J)return!0;const U=H.id&&((Se=_.get(H.id))==null?void 0:Se.title)||H.title;return u(U).includes(J)||(H.subItems||[]).some(ye=>u(ye).includes(J))})},[v.rows,g,y,_,u]),B=m?P:P.slice(0,Dt),A=f.useMemo(()=>(N?v.rows:B).filter(R=>R.id&&!_.has(R.id)).map(R=>R.id),[N,v.rows,B,_]);f.useEffect(()=>{if(!i||A.length===0)return;let R=!1;const J=A.slice(0,Qu);return Promise.all(J.map(H=>i.getItem(H).then(U=>{var ye,Le;const re=U??{},Se={title:re.title,edition:re.edition,authors:re.authors,measure:U?at(U,d.unit.juan):void 0,versionCount:re._edition_count??((ye=re.books)==null?void 0:ye.length),l1:((Le=re.classification)==null?void 0:Le.l1)||void 0};return[H,Se]}).catch(()=>[H,{}]))).then(H=>{R||w(U=>{const re=new Map(U);for(const[Se,ye]of H)re.set(Se,ye);return re})}),()=>{R=!0}},[i,A,d.unit.juan]);const W=(e.contained_in||[])[0];f.useEffect(()=>{if(!W){h(null);return}if(h({id:W}),!i)return;let R=!1;return i.getItem(W).then(J=>{R||h({id:W,title:J==null?void 0:J.title})}).catch(()=>{}),()=>{R=!0}},[i,W]);const V=f.useMemo(()=>Xs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),K=V.text.length+V.groups.reduce((R,J)=>R+J.rows.length+J.mirrors.length,0),E=e.contained_works||[],le=new Set(v.rows.map(R=>R.id).filter(Boolean)),G=E.length>0&&!E.every(R=>le.has(R.id)),ae=(()=>{const R=v.rows.map(J=>J.edition).filter(Boolean);return R.length>1&&new Set(R).size===1})(),pe=v.rows.some(R=>R.volumes.length>0||R.expected!=null),ee=e._member_count||((he=e.books)==null?void 0:he.length)||E.length,X=at(e,d.unit.juan),ie=e.count,me=R=>typeof R=="number"&&Number.isFinite(R)?R:null,te=me(ie==null?void 0:ie.juan)??me((Z=e.juan_count)==null?void 0:Z.number),se=me(ie==null?void 0:ie.ce)??(v.totalVolumes||null),fe=[{value:v.rows.length,label:"子目"},{value:te??0,label:d.unit.juan},{value:se??0,label:d.unit.volume}],be=f.useMemo(()=>{var H,U;const R=[];if((H=e.publication_info)!=null&&H.details&&R.push({label:"刊印",value:u(e.publication_info.details)}),ee&&ee!==v.rows.length){const re=e._member_type==="Book"?"所收版本":e._member_type==="Work"?"所收作品":"成員";R.push({label:u(re),value:`${ee} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")})}const J=[me(ie==null?void 0:ie.zhong)!=null?`${ie.zhong} 種`:"",me(ie==null?void 0:ie.han)!=null?`${ie.han} 函`:""].filter(Boolean);return J.length&&R.push({label:"應收",value:u(J.join(" "))}),te==null&&X&&R.push({label:"卷帙",value:u(X),title:(U=e.juan_count)!=null&&U.description?u(e.juan_count.description):void 0}),R},[e,ee,v.rows.length,te,X,ie,u,d]),ze=f.useMemo(()=>{if(!T)return[];const R=new Map;for(const H of v.rows){const U=C(H.id);U&&R.set(U,(R.get(U)??0)+1)}const J=Yt.filter(H=>(R.get(H.key)??0)>0);return J.length<2?[]:[{key:"",label:`${d.catalog.all} ${v.rows.length}`},...J.map(H=>({key:H.key,label:`${H.label} ${R.get(H.key)}`}))]},[T,v.rows,_,d]),ve=f.useMemo(()=>{if(!T||!v.rows.some(U=>U.volumes.length>0))return null;const R=[],J=v.rows.filter(U=>U.volumes.length>0).map(U=>({k:C(U.id)??"",from:Math.min(...U.volumes),to:Math.max(...U.volumes)})).sort((U,re)=>U.from-re.from);for(const U of J){const re=U.to-U.from+1,Se=R[R.length-1];Se&&Se.key===U.k?(Se.to=Math.max(Se.to,U.to),Se.n+=re):R.push({key:U.k,from:U.from,to:U.to,n:re})}const H=J.reduce((U,re)=>Math.max(U,re.to),0);return R.length>1&&R.some(U=>U.key)?{segs:R,last:H}:null},[T,v.rows,_]),ke=(F=e.description)==null?void 0:F.text,Ne=t.jsx(Xt,{kind:"叢編",title:u(e.title),byline:t.jsx(Oi,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Me,{items:[e.subtype==="work_collection"?u("作品集"):"",(I=e.publication_info)!=null&&I.year?u(e.publication_info.year):""]}),description:ke||(D=e.history)!=null&&D.length?t.jsxs(t.Fragment,{children:[ke&&t.jsx(lt,{text:ke,style:{fontSize:15,lineHeight:1.85}}),(M=e.history)!=null&&M.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((R,J)=>t.jsx("li",{children:u(R)},J))}):null]}):void 0,clampDescription:vi(ke)||(((ne=e.history)==null?void 0:ne.length)??0)>2?6:void 0,stats:fe,facts:be,foot:t.jsx(Qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ve&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:u("全帙冊次分佈")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":u("全帙冊次分佈"),children:ve.segs.map((R,J)=>{const H=Yt.find(U=>U.key===R.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!H,title:H?u(`${H.label} 第 ${R.from}–${R.to} 冊`):void 0,"aria-label":u(H?`只看${H.label}`:"未分類"),"aria-pressed":!!H&&y===R.key,style:{flexGrow:R.n,background:o(H?H.token:"rule")},onClick:()=>{H&&(j(y===R.key?"":R.key),b(!1))}},J)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:u(`第 1 ${d.unit.volume}`)}),t.jsx("span",{children:u("點色段篩選部類")}),t.jsx("span",{children:u(`第 ${ve.last} ${d.unit.volume}`)})]})]})}),Ee=[];v.rows.length&&Ee.push({id:"titles",label:"子目",count:v.rows.length}),K&&Ee.push({id:"resources",label:"影印與全文",count:K}),G&&Ee.push({id:"works",label:d.section.containedWorks,count:E.length});const O=t.jsxs(t.Fragment,{children:[v.rows.length>0&&t.jsxs(Fe,{id:"titles",title:"子目",meta:t.jsx(Me,{items:[u(`${v.rows.length} ${d.unit.items}`),v.totalVolumes?u(`全帙 ${v.totalVolumes} ${d.unit.volume}`):"",P.length!==v.rows.length?u(`當前 ${P.length} ${d.unit.items}`):""]}),action:l,children:[(v.rows.length>Dt||ze.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ze.length>0&&t.jsx(_n,{items:ze,value:y,onChange:R=>{j(R),b(!1)}}),z&&v.rows.length>Dt&&!T&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:k,onClick:()=>$(!0),title:u(`將載入全部 ${v.rows.length} ${d.unit.items}`),children:u(k?"正在按部類分組…":"按部類分組")}),t.jsx("span",{className:"bim-d-spacer"}),v.rows.length>Dt&&t.jsx("input",{type:"search",className:"bim-d-find",value:g,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:R=>{x(R.target.value),b(!1)}})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[pe&&t.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),t.jsx("th",{children:u("書名")}),t.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),t.jsx("tbody",{children:B.map((R,J)=>{var Ye;const H=R.id?_.get(R.id):void 0,U=H!=null&&H.title&&R.title===R.id?H.title:R.title,re=((H==null?void 0:H.authors)||[]).find(L=>L&&L.name),Se=[re?`${re.dynasty?`〔${u(re.dynasty)}〕`:""}${u(re.name)}${re.role?` ${u(re.role)}`:""}`:"",H!=null&&H.measure?u(H.measure):"",(Ye=R.subItems)!=null&&Ye.length?R.subItems.map(L=>u(L)).join("、"):"",(H!=null&&H.edition||R.edition)&&!ae?u((H==null?void 0:H.edition)||R.edition||""):""].filter(Boolean),ye=Yt.find(L=>L.key===C(R.id)),Le=R.volumes.length>0?u(`第 ${wn(R.volumes,d.unit.volume)} ${d.unit.volume}`):R.expected!=null?u(`${R.found??0}/${R.expected} ${d.unit.volume}`):"";return t.jsxs("tr",{children:[pe&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Le?"":" bim-d-zt-blank"}`,children:[ye&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:o(ye.token)}}),Le||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[R.id?t.jsx(Be,{id:R.id,label:u(U),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(U)}),Se.length>0?t.jsx(Me,{items:Se}):R.id&&!H&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${H!=null&&H.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:H!=null&&H.versionCount?u(`${H.versionCount} 種`):""})]},`${R.id??R.title}-${J}`)})})]}),B.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),P.length>B.length&&t.jsx(Bt,{label:`展開其餘 ${P.length-B.length} ${d.unit.items}`,onClick:()=>b(!0)})]}),K>0&&t.jsxs(Fe,{id:"resources",title:"影印與全文",meta:u(`${K} 處`),children:[V.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[V.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:V.text.map((R,J)=>t.jsx(Di,{item:R,siblings:V.text},`${R.id||R.url||R.name}-${J}`))})})]}),t.jsx(el,{groups:V.groups})]}),v.rows.length===0&&K===0&&t.jsx(Fe,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),ce=G?t.jsx(ht,{id:"works",title:d.section.containedWorks,meta:u(`${E.length} 種`),cap:12,items:E.map(R=>t.jsx(Be,{id:R.id,label:u(R.title),onNavigate:r,renderLink:s,dense:!0}))}):null,oe=S?t.jsx(Xr,{caption:"上級叢編",children:t.jsx(Be,{id:S.id,label:u(S.title||S.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(Zt,{railTop:a,back:p,up:oe,nav:Ee,railLinks:c,main:O,card:Ne,side:ce})},ex=16,On=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function mr(e){if(!e)return On.length;const n=On.indexOf(e);return n===-1?On.length:n}const tx={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function xt(e){return e==null?"":e<0?`前${-e}`:String(e)}const nx={秦:[-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]},ll=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:a})=>{var ce,oe,he,Z,F;const p=ue(),{convert:c}=q(),[d,u]=f.useState("全部"),[g,x]=f.useState(!1),[m,b]=f.useState("default"),[S,h]=f.useState(new Map),y=f.useMemo(()=>(e.works||[]).map(I=>{const D=S.get(I.work_id);return{id:I.work_id,title:(D==null?void 0:D.title)??I.title??I.work_id,role:I.role||"",cls:yi(I.role),versionCount:D==null?void 0:D.versionCount,section:D==null?void 0:D.cls,l1:D==null?void 0:D.l1,measure:D==null?void 0:D.measure,hasImage:D==null?void 0:D.hasImage,loaded:!!(D!=null&&D.loaded)}}),[e.works,S]),j=f.useMemo(()=>Hr((e.works||[]).map(I=>I.role)),[e.works]),k=f.useMemo(()=>{const I=d==="全部"?y:y.filter(D=>D.cls===d);return m==="versions"?[...I].sort((D,M)=>(M.versionCount??-1)-(D.versionCount??-1)):I},[y,d,m]),$=g?k:k.slice(0,ex),v=f.useMemo(()=>$.filter(I=>!S.has(I.id)).map(I=>I.id),[$,S]);f.useEffect(()=>{if(!n||v.length===0)return;let I=!1;return Promise.all(v.map(D=>n.getItem(D).then(M=>{var H,U,re,Se,ye;const ne=M??{},R=ne._edition_count??(((H=ne.books)==null?void 0:H.length)??0)+(((U=ne.collections)==null?void 0:U.length)??0),J=[(re=ne.classification)==null?void 0:re.l1,(Se=ne.classification)==null?void 0:Se.l2].filter(Boolean).join(" ");return[D,{id:D,title:ne.title,versionCount:R,loaded:!0,cls:J||void 0,l1:((ye=ne.classification)==null?void 0:ye.l1)||void 0,measure:M&&at(M,p.unit.juan)||void 0,hasImage:!!(ne.has_image??ne._has_image)}]}).catch(()=>[D,{id:D,loaded:!0}]))).then(D=>{I||h(M=>{const ne=new Map(M);for(const[R,J]of D)ne.set(R,J);return ne})}),()=>{I=!0}},[n,v,p.unit.juan]);const _=f.useMemo(()=>{const I=new Map;for(const D of e.alt_names||[]){const M=D.type||p.section.aliases;I.has(M)||I.set(M,[]),I.get(M).push(D.name)}return[...I.entries()].sort((D,M)=>mr(D[0])-mr(M[0])).map(([D,M])=>({label:D,names:M}))},[e.alt_names,p]),w=e.birth_year??((ce=e.dates)==null?void 0:ce.birth)??void 0,z=e.death_year??((oe=e.dates)==null?void 0:oe.death)??void 0,N=(he=e.dates)==null?void 0:he.floruit,T=w!=null||z!=null?`${xt(w)||"?"}—${xt(z)||"?"}`:Array.isArray(N)&&N.length===2&&N.every(I=>Number.isFinite(I))?`活躍於 ${xt(N[0])}—${xt(N[1])}`:"",C=new Set(["本名","字","號","号"]),P=_.filter(I=>C.has(I.label)),B=_.filter(I=>!C.has(I.label)),A=B.reduce((I,D)=>I+D.names.length,0),W=f.useMemo(()=>{const I=[];for(const M of P)I.push({label:M.label,value:M.names.map(ne=>c(ne)).join("、")});const D=(e.works||[]).length;return D&&I.push({label:"著作",value:`${D} ${c("種")}`}),I},[e.works,P,c]),V=I=>{var D;return(D=_.find(M=>I.includes(M.label)))==null?void 0:D.names[0]},K=V(["字"]),E=V(["號","号"]),le=[K?`字${K}`:"",E?`號${E}`:""].filter(Boolean).join(","),G=e.native_place,ae=e.dynasty?nx[e.dynasty]:void 0,pe=(()=>{if(!ae||w==null||z==null||z<w)return null;const[I,D]=ae,M=Math.max(w,I),ne=Math.min(z,D);if(ne<=M)return null;const R=D-I;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":c(`${xt(w)}—${xt(z)},一生 ${z-w+1} 年`),children:t.jsx("i",{style:{left:`${(M-I)/R*100}%`,width:`${(ne-M)/R*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:c(`${xt(I)} ${e.dynasty}`)}),t.jsx("span",{children:c(`一生 ${z-w+1} 年`)}),t.jsx("span",{children:xt(D)})]})]})})(),ee=f.useMemo(()=>{if(!n||y.length===0||y.some(M=>!M.loaded))return null;const I=new Map;for(const M of y){const ne=si(M.l1);ne&&I.set(ne,(I.get(ne)??0)+1)}const D=Yt.map(M=>({...M,n:I.get(M.key)??0})).filter(M=>M.n>0);return D.length?D:null},[y,n]),X=t.jsxs(Xt,{kind:tx[e.subtype]??"人物",title:c(e.primary_name||e.title),subtitle:le?c(le):void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(Me,{items:[e.dynasty?c(e.dynasty):"",T?c(T):"",G?c(`${G}人`):""]}),pe]}),description:(Z=e.description)!=null&&Z.text?t.jsx(lt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:vi((F=e.description)==null?void 0:F.text)?6:void 0,facts:W,foot:t.jsx(Qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[A>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c(`更多別名(${A})`)}),t.jsx("dl",{children:B.map(I=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:c(I.label)}),t.jsx("dd",{children:I.names.map(D=>c(D)).join("、")})]},I.label))})]}),ee&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:c("著作分佈")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:ee.map(I=>t.jsx("i",{style:{flexGrow:I.n,background:o(I.token)}},I.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ee.map(I=>t.jsxs("span",{children:[t.jsx("i",{style:{background:o(I.token)}}),c(I.label)," ",I.n]},I.key))})]})]}),ie=f.useMemo(()=>y.filter(I=>I.loaded&&(I.versionCount??0)>0).sort((I,D)=>(D.versionCount??0)-(I.versionCount??0)).slice(0,3),[y]),me=!!n&&y.length>=3&&$.some(I=>!I.loaded),te=d==="全部"&&(me||ie.length>=2),se=e.external_ids||{},fe=[];se.cbdb_id!=null&&fe.push({label:"CBDB",id:String(se.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${se.cbdb_id}`,note:se.cbdb_match==="auto"?"自動匹配":void 0});const be=se.wikidata_id;be&&fe.push({label:"Wikidata",id:be,href:`https://www.wikidata.org/wiki/${be}`});const ze=se.viaf_id;ze&&fe.push({label:"VIAF",id:ze,href:`https://viaf.org/viaf/${ze}`});const ve=j.map(I=>({key:I.cls,label:`${I.label} ${I.count}`})),ke=[...te&&!me?[{id:"featured",label:"著作舉要",count:ie.length}]:[],...y.length?[{id:"works",label:"全部著作",count:y.length}]:[],...fe.length?[{id:"external",label:"站外資料",count:fe.length}]:[]],Ne=te?t.jsxs(Fe,{id:"featured",title:"著作舉要",children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:c("存世版本最多的三部")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":me||void 0,children:[me&&[0,1,2].map(I=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},I)),!me&&ie.map(I=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Be,{id:I.id,label:c(I.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx(Me,{items:[I.section?c(I.section):"",I.measure?c(I.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:I.versionCount}),t.jsx("span",{children:c("種版本")}),I.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("有影印")})]})]},I.id))]})]}):null,Ee=y.length===0?t.jsx(Fe,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該人物的關聯作品。")})}):t.jsxs(t.Fragment,{children:[Ne,t.jsxs(Fe,{id:"works",title:"著作",meta:t.jsx(Me,{items:[c(`共 ${y.length} 種`),k.length!==y.length?c(`當前 ${k.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ve.length>1&&t.jsx(_n,{items:ve,value:d,onChange:I=>{u(I),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":m==="versions",onClick:()=>{m==="default"&&x(!0),b(I=>I==="default"?"versions":"default")},children:c(m==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("作品")}),t.jsx("th",{children:c("部類")}),t.jsx("th",{children:c("職任")}),t.jsx("th",{children:c("存世版本")}),t.jsx("th",{"aria-label":c("影印")})]})}),t.jsx("tbody",{children:$.map(I=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Be,{id:I.id,label:c(I.title),onNavigate:i,renderLink:r,dense:!0}),I.measure?t.jsx(Me,{items:[c(I.measure)]}):!I.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.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}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.role?"":" bim-d-zt-blank"}`,children:I.role?c(I.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.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} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:c("未著錄")}):""}),t.jsx("td",{className:I.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:I.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("有影印")})})]},I.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("該職任下的著作尚未著錄。")}),k.length>$.length&&t.jsx(Bt,{label:`展開其餘 ${k.length-$.length} 種著作`,onClick:()=>x(!0)})]})]}),O=fe.length>0?t.jsx(ht,{id:"external",title:"站外資料",items:fe.map(I=>t.jsxs("a",{href:I.href,target:"_blank",rel:"noopener noreferrer",children:[I.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:fe.map(I=>I.id),foot:se.cbdb_id!=null&&se.cbdb_match==="auto"?c("CBDB 為自動匹配,未經人工核對"):void 0}):null;return t.jsx(Zt,{railTop:s,back:l,nav:ke,railLinks:a,main:Ee,card:X,side:O})},Gi="(max-width: 719px)",ix=`${Gi}, (pointer: coarse)`,al=`
|
|
789
795
|
.bim-ct {
|
|
790
796
|
display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
|
|
791
797
|
max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
|
|
@@ -923,4 +929,4 @@ ${gc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
|
|
|
923
929
|
.bim-ct-tw { width: 44px; }
|
|
924
930
|
.bim-ct-pg { min-width: 44px; height: 44px; }
|
|
925
931
|
}
|
|
926
|
-
`,Yt="未分類",ot="all",Ui=20;function en(e){if(!e)return[];const n=[];for(const i of[e.l1,e.l2,e.l3,e.l4]){const r=(i??"").trim();if(!r)break;n.push(r)}return n}function ox(e){const n=en(e);return n.length?n.join("/"):Yt}function rx(e){const n=en(e);return n.length?n.map((i,r)=>n.slice(0,r+1).join("/")):[Yt]}function sx(e,n=[]){const i=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,g)=>{const x=d.slice(0,g+1).join("/");i.has(x)||i.set(x,c)})});const r=new Map;let s=0;for(const p of e){const c=en(p.classification);if(!c.length){s++;continue}let d=r;c.forEach((u,g)=>{const x=c.slice(0,g+1).join("/");let m=d.get(u);m||(m={id:x,label:u,count:0,children:new Map},d.set(u,m)),m.count++,d=m.children})}const l=p=>[...p.values()].sort((c,d)=>{const u=i.get(c.id)??1/0,g=i.get(d.id)??1/0;return u!==g?u-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(r);return s>0&&a.push({id:Yt,label:Yt,count:s}),a}function zt(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const r=zt(i.children,n);if(r.length)return[i,...r]}}return[]}function Vi(e){return e.reduce((n,i)=>n+i.count,0)}function lx(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function ax(e){var p;const n={id:e.id,title:e.title||e.id},i=e.juan_count,r=typeof i=="number"?i:i==null?void 0:i.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(c=>c==null?void 0:c.name).map(c=>{const d=c.dynasty||(e.authors.length===1?e.dynasty:void 0);return d?{name:c.name,dynasty:d}:{name:c.name}});s.length&&(n.authors=s);const l=lx(typeof e.description=="string"?e.description:(p=e.description)==null?void 0:p.text);l&&(n.summary=l);const a=en(e.classification);return a.length&&(n.classification=a),n}function cx(e,n){const i=e.summary?0:1,r=n.summary?0:1;return i!==r?i-r:e.title.localeCompare(n.title,"zh")}function dx(e,n=Ui){return Math.max(1,Math.ceil(e/n))}function cl(e,n,i=2){if(n<=1)return[1];const r=new Set([1,n]);for(let a=e-i;a<=e+i;a++)a>=1&&a<=n&&r.add(a);const s=[...r].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 px=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function ux(e,n,i){const r=[];i&&r.push({id:ot,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;r.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(e,null),r}function dl({tree:e,selectedId:n,onSelect:i,allLabel:r="全部",label:s="分類"}){const{convert:l}=V(),a=f.useRef(null),p=n&&n!==ot?n:null,c=r!==null,[d,u]=f.useState(()=>{const S=new Set;for(const $ of zt(e,p))S.add($.id);return S});f.useEffect(()=>{const S=zt(e,p);S.length&&u($=>{if(S.every(C=>$.has(C.id)))return $;const w=new Set($);for(const C of S)w.add(C.id);return w})},[e,p]);const g=f.useMemo(()=>ux(e,d,c),[e,d,c]),[x,m]=f.useState(null);f.useEffect(()=>{m(null)},[n]);const b=p??(c?ot:null),k=f.useMemo(()=>{var w;const S=new Set(g.map(C=>C.id));if(x&&S.has(x))return x;if(b&&S.has(b))return b;const $=zt(e,p).map(C=>C.id).filter(C=>S.has(C));return $.length?$[$.length-1]:((w=g[0])==null?void 0:w.id)??null},[g,x,b,e,p]),h=f.useCallback((S,$)=>{u(w=>{const C=w.has(S),N=$??!C;if(N===C)return w;const E=new Set(w);return N?E.add(S):E.delete(S),E})},[]),y=f.useCallback(S=>{m(S),requestAnimationFrame(()=>{var w;const $=Array.from(((w=a.current)==null?void 0:w.querySelectorAll("[data-ct-id]"))??[]).find(C=>C.dataset.ctId===S);$==null||$.focus()})},[]),j=f.useCallback((S,$)=>{$&&h(S,!0),i(S)},[i,h]),v=f.useCallback(S=>{const $=S.target.closest("[data-ct-id]");if(!$)return;const w=$.dataset.ctId,C=g.findIndex(I=>I.id===w);if(C<0)return;const N=g[C];let E=null;switch(S.key){case"ArrowDown":E=g[Math.min(g.length-1,C+1)].id;break;case"ArrowUp":E=g[Math.max(0,C-1)].id;break;case"Home":E=g[0].id;break;case"End":E=g[g.length-1].id;break;case"ArrowRight":if(!N.hasChildren)break;d.has(w)?E=N.firstChildId:h(w,!0);break;case"ArrowLeft":N.hasChildren&&d.has(w)?h(w,!1):E=N.parentId;break;case"Enter":case" ":S.preventDefault(),j(w,N.hasChildren);return;default:return}S.preventDefault(),E&&E!==w&&y(E)},[g,d,h,y,j]),_=(S,$)=>S.map((w,C)=>{var A;const N=(A=w.children)!=null&&A.length?w.children:null,E=!!N&&d.has(w.id),I=w.id===p,O=$===1&&S.length>1&&C===S.length-1;return t.jsxs("li",{role:"treeitem","aria-level":$,"aria-expanded":N?E:void 0,"aria-selected":I,tabIndex:k===w.id?0:-1,"data-ct-id":w.id,className:O?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":$-1},onClick:()=>{m(w.id),j(w.id,!!N)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:N?M=>{M.stopPropagation(),m(w.id),h(w.id)}:void 0,children:N?t.jsx(px,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(w.label)}),t.jsx("span",{className:"bim-ct-n",children:w.count.toLocaleString("en-US")})]}),E&&t.jsx("ul",{role:"group",children:_(N,$+1)})]},w.id)});return t.jsxs("ul",{ref:a,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:v,children:[c&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:k===ot?0:-1,"data-ct-id":ot,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{m(ot),i(ot)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),t.jsx("span",{className:"bim-ct-lb",children:l(r)}),t.jsx("span",{className:"bim-ct-n",children:Vi(e).toLocaleString("en-US")})]})}),_(e,1)]})}const pl=e=>`/item/${encodeURIComponent(e)}`;function xx(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function ul(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function xl({work:e,href:n}){var a,p;const{convert:i}=V(),r=ul(e.juan),s=((a=e.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:n,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:i(e.title)}),r&&t.jsx("span",{className:"bim-ct-juan",children:i(r)})]}),s.length>0&&t.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>t.jsxs(f.Fragment,{children:[d>0&&"、",c.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(c.dynasty),"〕"]}),i(c.name)]},d))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:i(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(c=>i(c)).join(" · ")})]})})}function fl({work:e,href:n}){var a,p;const{convert:i}=V(),r=ul(e.juan),s=((a=e.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-lrow",children:t.jsxs("a",{href:n,children:[t.jsxs("span",{className:"bim-ct-lt",children:[i(e.title),r&&t.jsx("span",{className:"bim-ct-juan",children:i(r)})]}),t.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>t.jsxs(f.Fragment,{children:[d>0&&"、",c.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(c.dynasty),"〕"]}),i(c.name)]},d))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(c=>i(c)).join(" · ")})]})})}function gl({page:e,pageCount:n,onPage:i,pageHref:r,label:s="分頁"}){const{convert:l}=V();if(n<=1)return null;const a=c=>d=>{i&&(r&&!xx(d)||(d.preventDefault(),i(c)))},p=(c,d,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const g={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...g,href:r(c),onClick:a(c),children:d}):t.jsx("button",{type:"button",...g,onClick:u.current?void 0:a(c),children:d})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:cl(e,n).map((c,d)=>t.jsx("li",{style:{display:"contents"},children:c===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(c,c,{current:c===e,aria:l(`第 ${c} 頁`)})},c??`gap${d}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),p(e+1,l("下一頁"),{disabled:e>=n})]})}function ml({works:e,workLink:n=pl,emptyText:i="此類暫無作品",view:r="card",...s}){const{convert:l}=V();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:typeof i=="string"?l(i):i}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(a=>t.jsx(fl,{work:a,href:n(a.id)},a.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(a=>t.jsx(xl,{work:a,href:n(a.id)},a.id))}),t.jsx(gl,{...s})]})}const fx=()=>t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:t.jsx("path",{d:"M2.5 4.5 6 8l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function gx({tree:e,selectedId:n,page:i,pageCount:r,works:s,onSelect:l,onPage:a,searchSlot:p,workLink:c,pageHref:d,allLabel:u="全部",allTitle:g="全部典籍",pageSize:x=Ui,className:m,view:b,onViewChange:k}){const{convert:h}=V(),j=`bim-ct-drawer-${f.useId().replace(/:/g,"")}`,[v,_]=f.useState(!1),[S,$]=f.useState("card"),w=b??S,C=M=>{$(M),k==null||k(M)},N=zt(e,n&&n!==ot?n:null),E=N.length?N[N.length-1]:null,I=E?E.label:g,O=E?E.count:Vi(e),A=f.useCallback(M=>{_(!1),l(M)},[l]);return t.jsxs("div",{className:m?`bim-ct ${m}`:"bim-ct","data-drawer":v?"open":"closed",children:[t.jsx("style",{children:al}),t.jsxs("aside",{className:"bim-ct-side","aria-label":h("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":v,"aria-controls":j,onClick:()=>_(M=>!M),children:[t.jsxs("span",{children:[h("分類"),":",h(N.length?N.map(M=>M.label).join(" › "):u??g)]}),t.jsx(fx,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:j,children:[t.jsx("h2",{className:"bim-ct-side-h",children:h("分類")}),t.jsx(dl,{tree:e,selectedId:n,onSelect:A,allLabel:u})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:h(I)}),N.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:h(N.slice(0,-1).map(M=>M.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[h(`共 ${O.toLocaleString("en-US")} 種 · 每頁 ${x} 條`),r>1&&h(` · 第 ${i} / ${r} 頁`)]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":h("呈現方式"),children:[t.jsx("button",{type:"button","aria-pressed":w==="card",onClick:()=>C("card"),children:h("卡片")}),t.jsx("button",{type:"button","aria-pressed":w==="list",onClick:()=>C("list"),children:h("列表")})]})]}),p&&t.jsx("div",{className:"bim-ct-search",children:p}),t.jsx(ml,{works:s,view:w,workLink:c,page:i,pageCount:r,onPage:a,pageHref:d})]})]})}const li=({style:e})=>{const n=f.useContext(Rt);if(!n)return null;const{locale:i,setLocale:r}=n,s=i==="zh-Hant",l=()=>r(s?"zh-Hans":"zh-Hant");return t.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 ${o("border")}`,borderRadius:"4px",background:o("bg"),color:o("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:s?o("primary"):void 0,fontWeight:s?700:400},children:"繁"}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:s?void 0:o("primary"),fontWeight:s?400:700},children:"简"})]})},ai=({href:e,label:n="在 GitHub 查看本条目源文件",size:i=16,className:r,style:s})=>t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:o("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:l=>{l.currentTarget.style.color=o("fg")},onMouseLeave:l=>{l.currentTarget.style.color=o("desc-fg")},children:t.jsx("svg",{width:i,height:i,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:t.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 Dn(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function mx(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const hx=({id:e,transport:n,initialDetail:i,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:a,onJuanChange:p,lineageMode:c="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:g,initialPage:x=1,selectedLineageNodeId:m,onNavigate:b,onBack:k,backLabel:h,renderLink:y,enrichDetail:j,getSourceLink:v,readLink:_,railTop:S,extraTabs:$=[],showFeedbackTab:w=!0,feedbackApiUrl:C,height:N,footerExtra:E,className:I,style:O})=>{var qi;const A=de(),{convert:M}=V(),[F]=f.useState(()=>{if(!mx(e,i))return null;const U={...i},ye=r??Dn(e,U);return j&&j(ye,U),{id:e,entry:ye,detail:U}}),[Y,K]=f.useState((F==null?void 0:F.entry)??null),[R,oe]=f.useState((F==null?void 0:F.detail)??null),[H,re]=f.useState(!F),[ee,Q]=f.useState(!1),[J,ce]=f.useState([]),[me,te]=f.useState(!1),[ie,pe]=f.useState(null),[ge,Ce]=f.useState(!1),[ve,we]=f.useState(null),[Ee,Re]=f.useState(!1),[D,se]=f.useState(null),[ne,he]=f.useState([]),[q,P]=f.useState(!1),[T,z]=f.useState(null),[L,B]=f.useState(null),[G,Z]=f.useState(!1),ue=f.useRef(null),[le,be]=f.useState(null),Ne=a!==void 0?a:le,je=f.useCallback(U=>{p?p(U):be(U)},[p]),Pe=f.useCallback(async U=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){ce([]);return}te(!0);try{if(n.getCollectionCatalogs)ce(await n.getCollectionCatalogs(U)||[]);else if(n.getCollectionCatalog){const ye=await n.getCollectionCatalog(U);ce(ye?[{resource_id:"",data:ye}]:[])}}catch{ce([])}finally{te(!1)}},[n]),at=f.useCallback(async U=>{if(!n.getCollatedEditionIndex){pe(null);return}Ce(!0);try{pe(await n.getCollatedEditionIndex(U))}catch{pe(null)}finally{Ce(!1)}},[n]),W=f.useCallback(async U=>{if(!n.getBookFullTextIndex){we(null);return}Re(!0);try{we(await n.getBookFullTextIndex(U))}catch{we(null)}finally{Re(!1),se(U)}},[n]),ae=f.useCallback(async U=>{var ye;if(!n.getWorkFullTextList){he([]);return}P(!0);try{const ze=(await n.getWorkFullTextList(U)??[]).filter(Be=>Be.owner_type!=="Book");he(ze),z(((ye=ze.find(Be=>Be.primary)??ze[0])==null?void 0:ye.key)??null)}catch{he([])}finally{P(!1)}},[n]),fe=f.useCallback(async(U,ye)=>{Z(!0);try{if(n.getLineageGraph){const De=await n.getLineageGraph(U);De&&B(De)}const ze=ye.version_graph;if(!ze||!ze.enabled){L||B(null),ue.current=null;return}const Be=ye.books??[],Ze=[];for(const De of Be)try{const Xe=await n.getItem(De);Xe&&Ze.push(Xe)}catch{}ue.current={work:ye,books:Ze};const X=u??ze.default_collection??(ze.core_books&&ze.core_books.length>0?"core":"all"),Ie=X==="core"&&Array.isArray(ze.core_books)&&ze.core_books.length>0?"core":X??"all";B(un(ye,Ze,Ie))}catch{B(null),ue.current=null}finally{Z(!1)}},[n]),_e=f.useRef({initialDetail:i,initialEntry:r});_e.current={initialDetail:i,initialEntry:r},f.useEffect(()=>{let U=!1;const ye=X=>{X.type==="collection"?Pe(e):X.type==="work"?(X.has_collated&&at(e),(X.version_graph||n.getLineageGraph)&&fe(e,X),n.getWorkFullTextList&&ae(e)):X.type==="book"&&X.has_full_text&&n.getBookFullTextIndex&&W(e)},ze=_e.current;let Be=null;if(F&&F.id===e)Be=F;else if(ze.initialDetail&&ze.initialDetail.id===e){const X={...ze.initialDetail},Ie=ze.initialEntry??Dn(e,X);j&&j(Ie,X),Be={entry:Ie,detail:X}}return Be?(Q(!1),ce(X=>X.length?[]:X),pe(null),we(null),he(X=>X.length?[]:X),z(null),B(null),ue.current=null,K(Be.entry),oe(Be.detail),re(!1),ye(Be.detail),()=>{U=!0}):((async()=>{re(!0),Q(!1),K(null),oe(null),ce([]),pe(null),we(null),he([]),z(null),B(null),ue.current=null;try{const X=await n.getItem(e);if(U)return;if(!X){Q(!0);return}const Ie=X;let De=null;if(n.getEntry&&(De=await n.getEntry(e),U))return;De||(De=Dn(e,Ie)),j&&j(De,Ie),K(De),oe(Ie),ye(Ie)}catch{U||Q(!0)}finally{U||re(!1)}})(),()=>{U=!0})},[e,n,F,j,Pe,at,fe,W,ae]),f.useEffect(()=>{const U=ue.current;!U||!u||B(un(U.work,U.books,u))},[u]);const xe=[];if(R){if(xe.push({key:"basic",label:A.detailTab.basicInfo}),R.type==="collection"){me&&J.length===0&&xe.push({key:"catalog:loading",label:`${A.detailTab.catalog}…`});for(const U of J)xe.push({key:`catalog:${U.resource_id}`,label:U.short_name?`${M(U.short_name)}${A.detailTab.catalogSuffix}`:A.detailTab.collectionCatalog})}R.type==="work"&&(ie||ge)&&s==="collated"&&xe.push({key:"collated",label:ge?`${A.detailTab.collatedEdition}…`:A.detailTab.collatedEdition}),R.type==="book"&&(ve||Ee)&&s==="fulltext"&&xe.push({key:"fulltext",label:Ee?`${A.detailTab.fullText}…`:A.detailTab.fullText}),R.type==="work"&&(ne.length>0||q)&&s==="fulltext"&&xe.push({key:"fulltext",label:q?`${A.detailTab.fullText}…`:A.detailTab.fullText}),R.type==="work"&&(L||G)&&xe.push({key:"lineage",label:G?`${A.detailTab.lineage}…`:A.detailTab.lineage});for(const U of $)(U.position??"before-feedback")==="before-feedback"&&U.shouldShow(R)&&xe.push({key:U.key,label:U.label});w&&s==="feedback"&&xe.push({key:"feedback",label:A.detailTab.feedback});for(const U of $)U.position==="after-feedback"&&U.shouldShow(R)&&xe.push({key:U.key,label:U.label})}f.useEffect(()=>{if(s!=="emendated"||!R)return;l("basic");const U=setTimeout(()=>{var ye;(ye=document.getElementById("studies"))==null||ye.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(U)},[s,R,l]);const $e=Y&&R&&v?v({activeTab:s,activeJuan:Ne,entry:Y,detail:R}):null,Oe=f.useMemo(()=>{var Ze;if(!R)return null;const ye=(R.authors??[]).map(X=>{const Ie=ji(X.role);return`${X.dynasty?`〔${M(X.dynasty)}〕`:""}${M(X.name)}${Ie?` ${M(Ie)}`:""}`}).join(" · ");let ze=!1;try{ze=ke.extractStatus(R.id)==="draft"}catch{}if(R.type==="book"){const X=R;return{title:M(X.title),subtitle:X.edition?M(X.edition):ye||void 0,aside:[ze?A.status.draft:"",ye&&X.edition?ye:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(R.type==="collection"){const X=R;return{title:M(X.title),subtitle:M(lt(X,A.unit.juan))||void 0,aside:[(Ze=X.publication_info)==null?void 0:Ze.year,ze?A.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:ye||void 0}}if(R.type==="entity"){const X=R,Ie=Xe=>Xe==null?"":Xe<0?`前${-Xe}`:String(Xe),De=X.birth_year!=null||X.death_year!=null?`${Ie(X.birth_year)||"?"}—${Ie(X.death_year)||"?"}`:"";return{title:M(X.primary_name||X.title),subtitle:[X.dynasty?`〔${M(X.dynasty)}〕`:"",De].filter(Boolean).join(" ")||void 0,aside:ze?A.status.draft:void 0,secondLine:void 0}}const Be=M(lt(R,A.unit.juan));return{title:M(R.title),subtitle:[Be,ye].filter(Boolean).join(" · ")||void 0,aside:[yx(A,R.subtype),ze?A.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[R,M,A]),qe=R?R.type==="work"?(((qi=ie==null?void 0:ie.juan_files)==null?void 0:qi.length)??0)>0?"collated":ne.length>0?"fulltext":null:R.type==="book"&&(((ve==null?void 0:ve.chapters.length)??0)>0||R.has_full_text&&n.getBookFullTextIndex&&D!==R.id)?"fulltext":null:null,ct=ne.find(U=>U.primary)??ne[0],tn=()=>{var U;qe==="collated"&&((U=ie==null?void 0:ie.juan_files)!=null&&U.length)?(je(ie.juan_files[0]),l("collated")):qe==="fulltext"&&((R==null?void 0:R.type)==="work"&&ct&&z(ct.key),je(null),l("fulltext"))};let dt=null;if(R&&_){const U=_({detail:R,kind:qe,fullTextKey:R.type==="work"?ct==null?void 0:ct.key:void 0});U&&(dt=t.jsx(qn,{href:U}))}else qe&&(dt=t.jsx(qn,{onClick:tn}));const nn=U=>{if(!R)return null;const ye=U.replace(/\.[^.]+$/,"");if(_){const ze=_({detail:R,kind:"fulltext",juan:ye});return ze?{href:ze}:null}return{onClick:()=>{je(ye),l("fulltext")}}},on=new Set($.map(U=>U.key)),Se=xe.filter(U=>U.key.startsWith("catalog:")&&U.key!=="catalog:loading"||on.has(U.key)).map(U=>({key:U.key,label:U.label,onClick:()=>l(U.key)})),Je=()=>{var U;return R?R.type==="work"?t.jsx(tl,{data:R,transport:n,onNavigate:b,renderLink:y,readAction:dt,railTop:S,railLinks:Se}):R.type==="book"?t.jsx(rl,{data:R,transport:n,onNavigate:b,renderLink:y,readAction:dt,fullText:ve,fullTextPending:!!R.has_full_text&&!!n.getBookFullTextIndex&&D!==R.id,chapterLink:nn,railTop:S,railLinks:Se}):R.type==="collection"?t.jsx(sl,{data:R,catalog:(U=J[0])==null?void 0:U.data,transport:n,onNavigate:b,renderLink:y,readAction:dt,railTop:S,railLinks:Se,catalogAction:J.length>0?t.jsxs("a",{href:"#catalog",onClick:ye=>{ye.preventDefault(),l(`catalog:${J[0].resource_id}`)},children:[M(A.detailTab.collectionCatalog)," →"]}):null}):t.jsx(ll,{data:R,transport:n,onNavigate:b,renderLink:y,railTop:S,railLinks:Se}):null},Te=()=>{var ye,ze,Be,Ze;if(!Y||!R)return null;if(s==="basic"||s==="emendated")return Je();if(typeof s=="string"&&s.startsWith("catalog:")){const X=(ye=J.find(Ie=>`catalog:${Ie.resource_id}`===s))==null?void 0:ye.data;return t.jsx(gi,{data:X,onNavigate:b,renderLink:y})}if(s==="collated")return t.jsx(Fi,{index:ie||void 0,workId:e,transport:n,onNavigate:b,activeJuan:Ne,onJuanChange:je});if(s==="fulltext"&&R.type==="work"){const X=T??((ze=ne[0])==null?void 0:ze.key);return X?t.jsx(ni,{bookId:e,workKey:X,versions:ne,onVersionChange:Ie=>{z(Ie),je(null)},transport:n,activeChapter:Ne,onChapterChange:je},X):t.jsx("div",{style:{padding:24,color:o("desc-fg")},children:q?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(ni,{index:ve||void 0,bookId:e,transport:n,activeChapter:Ne,onChapterChange:je});if(s==="lineage"){if(!L)return t.jsx("div",{style:{color:o("label-fg"),padding:"24px 0"},children:G?"加載中…":"暫無版本圖數據"});const X=R.type==="work"?R:null;return t.jsx(Hi,{graph:L,renderLink:y,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:d,selectedNodeId:m,collection:u??((Be=X==null?void 0:X.version_graph)==null?void 0:Be.default_collection),onCollectionChange:g,collectionsAvailable:(Ze=X==null?void 0:X.version_graph)==null?void 0:Ze.collections,collectionCounts:(()=>{var Ji,Zi,Xi,Qi,eo,to,no;if(!X)return;const Ie={},De=((Ji=ue.current)==null?void 0:Ji.books)??[];Ie.all=(((Zi=X.books)==null?void 0:Zi.length)??0)-(((Qi=(Xi=X.version_graph)==null?void 0:Xi.excluded_books)==null?void 0:Qi.length)??0);const Xe=(eo=X.version_graph)==null?void 0:eo.collections;if(Xe)for(const io of Object.keys(Xe))Ie[io]=un(X,De,io).nodes.filter(oo=>oo.kind==="book"&&!oo.bridge).length;return Ie.core==null&&((no=(to=X.version_graph)==null?void 0:to.core_books)!=null&&no.length)&&(Ie.core=X.version_graph.core_books.length),Ie})()})}if(s==="feedback"&&w)return t.jsx(Zs,{resourceId:e,apiUrl:C});const U=$.find(X=>X.key===s);return U?U.render({detail:R,entry:Y,transport:n,onNavigate:b}):null};if(H)return t.jsx(Dt,{style:{minHeight:N,...O},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((U,ye)=>t.jsx("div",{style:{height:ye===1?40:16,width:U,opacity:.35,background:o("rule")}},ye))})});if(ee||!R||!Y||!Oe)return t.jsx(Dt,{style:{minHeight:N,...O},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:o("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const kt=s==="basic"||s==="emendated",rn=[{label:h??A.detailTab.backToIndex,onClick:k}];if(R.type==="book"&&R.work_id){const U=R.work_id;rn.push({label:A.indexType.work,id:U,onClick:()=>b==null?void 0:b(U)})}rn.push({label:A.indexType[R.type]});const sn=s==="collated"||s==="fulltext",Yi=typeof E=="string"?A.status[E.trim()]??E:E,Ki=t.jsx(ds,{left:t.jsxs(t.Fragment,{children:[Yi,Yi?" · ":"",t.jsx(bx,{id:R.id,label:A.label.id,copied:A.action.copied,copyLabel:A.action.copy})]}),right:t.jsxs(t.Fragment,{children:[w&&!kt&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:A.detailTab.submitVersion}),$e&&t.jsx("a",{href:$e.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:o("meta-fg")},children:A.detailTab.dataLicense})]})});return kt?t.jsx("div",{className:I,children:t.jsxs(Dt,{grid:!0,style:{minHeight:N,...O},children:[t.jsx(Jn,{breadcrumb:t.jsx(Zn,{items:rn}),actions:t.jsxs(t.Fragment,{children:[t.jsx(li,{style:{border:"none",background:"transparent"}}),$e&&t.jsx(ai,{...$e})]})}),Je(),Ki]})}):t.jsx("div",{className:I,children:t.jsxs(Dt,{wide:sn,style:{minHeight:N,...O},children:[t.jsx(Jn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(ki,{char:"籍"}),t.jsx(Zn,{items:rn})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(li,{}),w&&t.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:o("meta-fg")},children:A.detailTab.feedback}),$e&&t.jsx(ai,{...$e})]})}),t.jsx(ts,{...Oe,aside:sn?t.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:o("accent"),borderBottom:`1px solid ${o("rule")}`},children:[M("作品信息")," →"]}):Oe.aside}),!sn&&xe.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:xe.map(U=>t.jsx(ns,{label:U.label,active:U.key===s||kt&&U.key==="basic",onClick:()=>l(U.key)},U.key))}),t.jsx("div",{style:{marginTop:!sn&&xe.length>1?8:0},children:Te()}),Ki]})})};function bx({id:e,label:n,copied:i,copyLabel:r}){const[s,l]=f.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var a;(a=navigator.clipboard)==null||a.writeText(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?i:r,"aria-label":s?i:r,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:o("aux-fg")},children:s?"✓":"⧉"})]})}function yx(e,n){return n?e.workSubtype[n]??n:""}const hl=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛藍"}],zn="zhusha",Cn="bim-theme";function bl(e){return e==="zhusha"||e==="indigo"}function In(e){return bl(e)?e:zn}function jx(){try{return In(window.localStorage.getItem(Cn))}catch{return zn}}function yl(e){try{window.localStorage.setItem(Cn,e)}catch{}}function jl(e){const n=In(e);return document.documentElement.setAttribute("data-theme",n),n}function vl(){return In(document.documentElement.getAttribute("data-theme"))}const vx=`try{if(localStorage.getItem(${JSON.stringify(Cn)})==='indigo')document.documentElement.setAttribute('data-theme','indigo')}catch(e){}`,kx={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo"},Sx=({onChange:e,style:n})=>{const{convert:i}=V(),[r,s]=f.useState(zn);f.useEffect(()=>{s(vl())},[]);const l=a=>{s(jl(a)),yl(a),e==null||e(a)};return t.jsx("div",{role:"radiogroup","aria-label":i("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:hl.map(a=>{const p=r===a.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":p,"aria-label":i(a.label),title:i(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:t.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:"50%",boxSizing:"border-box",background:o(kx[a.name]),boxShadow:p?`0 0 0 2px ${o("page-bg")}, 0 0 0 3.5px ${o("aux-fg")}`:"none"}})},a.name)})})};exports.BidLink=ke.BidLink;exports.BookIndexError=ke.BookIndexError;exports.BookIndexManager=ke.BookIndexManager;exports.BookIndexStorage=ke.BookIndexStorage;exports.BundleStorage=ke.BundleStorage;exports.ConfigError=ke.ConfigError;exports.GithubStorage=ke.GithubStorage;exports.IdGenerationError=ke.IdGenerationError;exports.IdGenerator=ke.IdGenerator;exports.LocalStorage=ke.LocalStorage;exports.MigrationError=ke.MigrationError;exports.StorageError=ke.StorageError;exports.base36Decode=ke.base36Decode;exports.base36Encode=ke.base36Encode;exports.base58Decode=ke.base58Decode;exports.buildId=ke.buildId;exports.buildPromotionMap=ke.buildPromotionMap;exports.cleanName=ke.cleanName;exports.decodeId=ke.decodeId;exports.decodeIdString=ke.decodeIdString;exports.encodeId=ke.encodeId;exports.extractIdFromUrl=ke.extractIdFromUrl;exports.extractStatus=ke.extractStatus;exports.extractType=ke.extractType;exports.normalizeCatalog=ke.normalizeCatalog;exports.parseId=ke.parseId;exports.shardOf=ke.shardOf;exports.smartDecode=ke.smartDecode;exports.validateResource=ke.validateResource;exports.Badge=mn;exports.BidUrlProvider=Rl;exports.BookDetailLayout=hx;exports.BookFullText=ni;exports.BookPage=rl;exports.Breadcrumb=Zn;exports.CATALOG_ALL_ID=ot;exports.CATALOG_CSS=al;exports.CATALOG_NARROW_QUERY=Gi;exports.CATALOG_PAGE_SIZE=Ui;exports.CATALOG_UNCLASSIFIED_ID=Yt;exports.CardFoot=Xt;exports.CatalogPage=gx;exports.CatalogPager=gl;exports.CatalogTree=dl;exports.CheckFilter=Qr;exports.Chip=is;exports.ChipWall=wc;exports.CollatedEdition=Fi;exports.CollectionCatalog=gi;exports.CollectionPage=sl;exports.CreateEntityDialog=Hs;exports.DEFAULT_READER_PREFS=_i;exports.DEFAULT_THEME=zn;exports.DETAIL_CSS=es;exports.Dash=Tc;exports.DataTable=$c;exports.DetailFooter=ds;exports.DetailGrid=Jt;exports.DetailHeader=ts;exports.EmendatedBySection=Br;exports.EmptyNote=Wc;exports.EntityDetail=Ir;exports.EntityPage=ll;exports.EntityPickerDialog=Us;exports.EntitySelector=Ds;exports.ExpandRow=Ec;exports.ExtLink=Mc;exports.FEEDBACK_FAB_OFFSET_VAR=oi;exports.FONT_SIZE_STEPS=$t;exports.FactList=jc;exports.FeedbackButton=su;exports.FeedbackDialog=qs;exports.FeedbackForm=Js;exports.FeedbackList=Pi;exports.FeedbackTab=Zs;exports.FilterChip=ns;exports.FormInput=Ge;exports.FormTextArea=bt;exports.GUJI_MARKDOWN_FIELD=sc;exports.GUJI_TABLE_NOTATION=vs;exports.GlyphBadge=ki;exports.GujiTable=Ii;exports.HomePage=ti;exports.ImagePanel=ms;exports.IndexApp=pp;exports.IndexBrowser=Un;exports.IndexDetail=fi;exports.IndexEditor=Vs;exports.IndexView=Yp;exports.IntroGrid=yc;exports.LocaleContext=Rt;exports.LocaleProvider=Vl;exports.LocaleToggle=li;exports.MetaLine=We;exports.ModeIndicator=$r;exports.MoreButton=Sc;exports.MoreLink=Bt;exports.PAGE_MAX_WIDTH=dn;exports.PageFrame=Dt;exports.Quote=Nc;exports.READER_CSS=xs;exports.RECENT_IDS_STORAGE_KEY=Ct;exports.ROLE_CLASS_ORDER=Dr;exports.ReadButton=qn;exports.ReaderMdText=Ni;exports.ReaderShell=zi;exports.ReaderToc=gs;exports.RelationPanel=Ps;exports.RepoSourceLink=ai;exports.ResourceEditor=Gn;exports.ResourceGroup=Lc;exports.ResourceLine=Bc;exports.ResourceList=xi;exports.ResourceRow=as;exports.SNIPPET_MARK_END=yr;exports.SNIPPET_MARK_START=br;exports.SearchInput=zr;exports.Sec=Me;exports.Section=Ye;exports.SectionHead=vc;exports.SideList=ht;exports.SmartBidInput=pn;exports.SourceEditor=Ws;exports.SummaryCard=Zt;exports.THEMES=hl;exports.THEME_INIT_SCRIPT=vx;exports.THEME_STORAGE_KEY=Cn;exports.TabFilter=wn;exports.TableHead=zc;exports.TableRow=Cc;exports.TagRow=cs;exports.TagRows=Ac;exports.TextButton=kc;exports.ThemeToggle=Sx;exports.TopStrip=Jn;exports.VersionLineageGraph=ol;exports.VersionLineageList=il;exports.VersionLineageView=Hi;exports.VolumeChips=_c;exports.VolumeLinks=Si;exports.WorkCard=xl;exports.WorkCardGrid=ml;exports.WorkCatalog=up;exports.WorkPage=tl;exports.WorkRow=fl;exports.applyTheme=jl;exports.bucketResources=bi;exports.buildCatalogTree=sx;exports.buildCollectionTable=Gr;exports.buildLineageGraph=un;exports.buildPageUrl=ui;exports.buildParagraphBlocks=Is;exports.buildVersionRow=Pr;exports.buildVersionTable=Or;exports.canParagraphize=$n;exports.catalogNodeIdOf=ox;exports.catalogNodeIdsOf=rx;exports.catalogPageCount=dx;exports.catalogTotal=Vi;exports.classificationPath=en;exports.compareCatalogCards=cx;exports.computeVersionPartition=nc;exports.currentTheme=vl;exports.defaultWorkLink=pl;exports.deriveDating=Qa;exports.deriveEditionType=Vr;exports.deriveEra=qt;exports.deriveYear=vn;exports.deriveYearRange=hi;exports.detailToEditor=Ks;exports.detectGenre=_n;exports.displayAuthorRole=ji;exports.editorToDetail=Vp;exports.eraRank=Yn;exports.findCatalogPath=zt;exports.flattenTitles=Xn;exports.flattenToc=js;exports.formatTemplate=Kt;exports.formatVolumeRange=Sn;exports.getDisplayNameFromUrl=Nt;exports.getStartPage=pi;exports.getTypeGroupKey=ci;exports.groupRelatedWorks=ec;exports.gujiInlineToPlain=Jr;exports.hasGujiMarkdownV02=Kn;exports.hasGujiTableNotation=ks;exports.isThemeName=bl;exports.measureText=lt;exports.mergeVolumeResources=di;exports.normalizeEra=Ae;exports.normalizeRole=yi;exports.normalizeTheme=In;exports.normalizeVolumeIndex=Gt;exports.normalizeVolumes=_r;exports.numberToChinese=Ur;exports.paginationItems=cl;exports.parseChineseNumber=xn;exports.parseGujiInline=qr;exports.parseGujiTable=ws;exports.parseSourceString=Ms;exports.pickReaderVersion=ys;exports.readStoredTheme=jx;exports.readerVersionOptionLabel=ei;exports.readerVersionsFromFullText=bs;exports.renderFullTextBody=ld;exports.renderProperNames=Es;exports.renderReaderInline=Ri;exports.resourceHref=Lt;exports.resourceNote=kn;exports.roleFacets=Hr;exports.rowNo=Ic;exports.sortYear=fn;exports.splitFullTextTables=Ci;exports.splitHighlightSnippet=jr;exports.splitTableRow=Ss;exports.storeTheme=yl;exports.stringifySources=Fs;exports.toCatalogWorkCard=ax;exports.useBidUrl=Fe;exports.useConvert=V;exports.useReaderPrefs=$i;exports.useT=de;exports.validateLineageGraph=zu;exports.volumeStats=hn;
|
|
932
|
+
`,qt="未分類",rt="all",Ui=20;function tn(e){if(!e)return[];const n=[];for(const i of[e.l1,e.l2,e.l3,e.l4]){const r=(i??"").trim();if(!r)break;n.push(r)}return n}function ox(e){const n=tn(e);return n.length?n.join("/"):qt}function rx(e){const n=tn(e);return n.length?n.map((i,r)=>n.slice(0,r+1).join("/")):[qt]}function sx(e,n=[]){const i=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,g)=>{const x=d.slice(0,g+1).join("/");i.has(x)||i.set(x,c)})});const r=new Map;let s=0;for(const p of e){const c=tn(p.classification);if(!c.length){s++;continue}let d=r;c.forEach((u,g)=>{const x=c.slice(0,g+1).join("/");let m=d.get(u);m||(m={id:x,label:u,count:0,children:new Map},d.set(u,m)),m.count++,d=m.children})}const l=p=>[...p.values()].sort((c,d)=>{const u=i.get(c.id)??1/0,g=i.get(d.id)??1/0;return u!==g?u-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(r);return s>0&&a.push({id:qt,label:qt,count:s}),a}function zt(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const r=zt(i.children,n);if(r.length)return[i,...r]}}return[]}function Vi(e){return e.reduce((n,i)=>n+i.count,0)}function lx(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function ax(e){var p;const n={id:e.id,title:e.title||e.id},i=e.juan_count,r=typeof i=="number"?i:i==null?void 0:i.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(c=>c==null?void 0:c.name).map(c=>{const d=c.dynasty||(e.authors.length===1?e.dynasty:void 0);return d?{name:c.name,dynasty:d}:{name:c.name}});s.length&&(n.authors=s);const l=lx(typeof e.description=="string"?e.description:(p=e.description)==null?void 0:p.text);l&&(n.summary=l);const a=tn(e.classification);return a.length&&(n.classification=a),n}function cx(e,n){const i=e.summary?0:1,r=n.summary?0:1;return i!==r?i-r:e.title.localeCompare(n.title,"zh")}function dx(e,n=Ui){return Math.max(1,Math.ceil(e/n))}function cl(e,n,i=2){if(n<=1)return[1];const r=new Set([1,n]);for(let a=e-i;a<=e+i;a++)a>=1&&a<=n&&r.add(a);const s=[...r].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 px=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function ux(e,n,i){const r=[];i&&r.push({id:rt,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;r.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(e,null),r}function dl({tree:e,selectedId:n,onSelect:i,allLabel:r="全部",label:s="分類"}){const{convert:l}=q(),a=f.useRef(null),p=n&&n!==rt?n:null,c=r!==null,[d,u]=f.useState(()=>{const v=new Set;for(const _ of zt(e,p))v.add(_.id);return v});f.useEffect(()=>{const v=zt(e,p);v.length&&u(_=>{if(v.every(z=>_.has(z.id)))return _;const w=new Set(_);for(const z of v)w.add(z.id);return w})},[e,p]);const g=f.useMemo(()=>ux(e,d,c),[e,d,c]),[x,m]=f.useState(null);f.useEffect(()=>{m(null)},[n]);const b=p??(c?rt:null),S=f.useMemo(()=>{var w;const v=new Set(g.map(z=>z.id));if(x&&v.has(x))return x;if(b&&v.has(b))return b;const _=zt(e,p).map(z=>z.id).filter(z=>v.has(z));return _.length?_[_.length-1]:((w=g[0])==null?void 0:w.id)??null},[g,x,b,e,p]),h=f.useCallback((v,_)=>{u(w=>{const z=w.has(v),N=_??!z;if(N===z)return w;const T=new Set(w);return N?T.add(v):T.delete(v),T})},[]),y=f.useCallback(v=>{m(v),requestAnimationFrame(()=>{var w;const _=Array.from(((w=a.current)==null?void 0:w.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===v);_==null||_.focus()})},[]),j=f.useCallback((v,_)=>{_&&h(v,!0),i(v)},[i,h]),k=f.useCallback(v=>{const _=v.target.closest("[data-ct-id]");if(!_)return;const w=_.dataset.ctId,z=g.findIndex(C=>C.id===w);if(z<0)return;const N=g[z];let T=null;switch(v.key){case"ArrowDown":T=g[Math.min(g.length-1,z+1)].id;break;case"ArrowUp":T=g[Math.max(0,z-1)].id;break;case"Home":T=g[0].id;break;case"End":T=g[g.length-1].id;break;case"ArrowRight":if(!N.hasChildren)break;d.has(w)?T=N.firstChildId:h(w,!0);break;case"ArrowLeft":N.hasChildren&&d.has(w)?h(w,!1):T=N.parentId;break;case"Enter":case" ":v.preventDefault(),j(w,N.hasChildren);return;default:return}v.preventDefault(),T&&T!==w&&y(T)},[g,d,h,y,j]),$=(v,_)=>v.map((w,z)=>{var B;const N=(B=w.children)!=null&&B.length?w.children:null,T=!!N&&d.has(w.id),C=w.id===p,P=_===1&&v.length>1&&z===v.length-1;return t.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":N?T:void 0,"aria-selected":C,tabIndex:S===w.id?0:-1,"data-ct-id":w.id,className:P?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{m(w.id),j(w.id,!!N)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:N?A=>{A.stopPropagation(),m(w.id),h(w.id)}:void 0,children:N?t.jsx(px,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(w.label)}),t.jsx("span",{className:"bim-ct-n",children:w.count.toLocaleString("en-US")})]}),T&&t.jsx("ul",{role:"group",children:$(N,_+1)})]},w.id)});return t.jsxs("ul",{ref:a,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:k,children:[c&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:S===rt?0:-1,"data-ct-id":rt,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{m(rt),i(rt)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),t.jsx("span",{className:"bim-ct-lb",children:l(r)}),t.jsx("span",{className:"bim-ct-n",children:Vi(e).toLocaleString("en-US")})]})}),$(e,1)]})}const pl=e=>`/item/${encodeURIComponent(e)}`;function xx(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function ul(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function xl({work:e,href:n}){var a,p;const{convert:i}=q(),r=ul(e.juan),s=((a=e.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:n,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:i(e.title)}),r&&t.jsx("span",{className:"bim-ct-juan",children:i(r)})]}),s.length>0&&t.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>t.jsxs(f.Fragment,{children:[d>0&&"、",c.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(c.dynasty),"〕"]}),i(c.name)]},d))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:i(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(c=>i(c)).join(" · ")})]})})}function fl({work:e,href:n}){var a,p;const{convert:i}=q(),r=ul(e.juan),s=((a=e.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-lrow",children:t.jsxs("a",{href:n,children:[t.jsxs("span",{className:"bim-ct-lt",children:[i(e.title),r&&t.jsx("span",{className:"bim-ct-juan",children:i(r)})]}),t.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>t.jsxs(f.Fragment,{children:[d>0&&"、",c.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(c.dynasty),"〕"]}),i(c.name)]},d))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(c=>i(c)).join(" · ")})]})})}function gl({page:e,pageCount:n,onPage:i,pageHref:r,label:s="分頁"}){const{convert:l}=q();if(n<=1)return null;const a=c=>d=>{i&&(r&&!xx(d)||(d.preventDefault(),i(c)))},p=(c,d,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const g={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...g,href:r(c),onClick:a(c),children:d}):t.jsx("button",{type:"button",...g,onClick:u.current?void 0:a(c),children:d})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:cl(e,n).map((c,d)=>t.jsx("li",{style:{display:"contents"},children:c===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(c,c,{current:c===e,aria:l(`第 ${c} 頁`)})},c??`gap${d}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),p(e+1,l("下一頁"),{disabled:e>=n})]})}function ml({works:e,workLink:n=pl,emptyText:i="此類暫無作品",view:r="card",...s}){const{convert:l}=q();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:typeof i=="string"?l(i):i}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(a=>t.jsx(fl,{work:a,href:n(a.id)},a.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(a=>t.jsx(xl,{work:a,href:n(a.id)},a.id))}),t.jsx(gl,{...s})]})}const fx=()=>t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:t.jsx("path",{d:"M2.5 4.5 6 8l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function gx({tree:e,selectedId:n,page:i,pageCount:r,works:s,onSelect:l,onPage:a,searchSlot:p,workLink:c,pageHref:d,allLabel:u="全部",allTitle:g="全部典籍",pageSize:x=Ui,className:m,view:b,onViewChange:S}){const{convert:h}=q(),j=`bim-ct-drawer-${f.useId().replace(/:/g,"")}`,[k,$]=f.useState(!1),[v,_]=f.useState("card"),w=b??v,z=A=>{_(A),S==null||S(A)},N=zt(e,n&&n!==rt?n:null),T=N.length?N[N.length-1]:null,C=T?T.label:g,P=T?T.count:Vi(e),B=f.useCallback(A=>{$(!1),l(A)},[l]);return t.jsxs("div",{className:m?`bim-ct ${m}`:"bim-ct","data-drawer":k?"open":"closed",children:[t.jsx("style",{children:al}),t.jsxs("aside",{className:"bim-ct-side","aria-label":h("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":k,"aria-controls":j,onClick:()=>$(A=>!A),children:[t.jsxs("span",{children:[h("分類"),":",h(N.length?N.map(A=>A.label).join(" › "):u??g)]}),t.jsx(fx,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:j,children:[t.jsx("h2",{className:"bim-ct-side-h",children:h("分類")}),t.jsx(dl,{tree:e,selectedId:n,onSelect:B,allLabel:u})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:h(C)}),N.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:h(N.slice(0,-1).map(A=>A.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[h(`共 ${P.toLocaleString("en-US")} 種 · 每頁 ${x} 條`),r>1&&h(` · 第 ${i} / ${r} 頁`)]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":h("呈現方式"),children:[t.jsx("button",{type:"button","aria-pressed":w==="card",onClick:()=>z("card"),children:h("卡片")}),t.jsx("button",{type:"button","aria-pressed":w==="list",onClick:()=>z("list"),children:h("列表")})]})]}),p&&t.jsx("div",{className:"bim-ct-search",children:p}),t.jsx(ml,{works:s,view:w,workLink:c,page:i,pageCount:r,onPage:a,pageHref:d})]})]})}const li=({style:e})=>{const n=f.useContext(Rt);if(!n)return null;const{locale:i,setLocale:r}=n,s=i==="zh-Hant",l=()=>r(s?"zh-Hans":"zh-Hant");return t.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 ${o("border")}`,borderRadius:"4px",background:o("bg"),color:o("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:s?o("primary"):void 0,fontWeight:s?700:400},children:"繁"}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:s?void 0:o("primary"),fontWeight:s?400:700},children:"简"})]})},ai=({href:e,label:n="在 GitHub 查看本条目源文件",size:i=16,className:r,style:s})=>t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:o("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:l=>{l.currentTarget.style.color=o("fg")},onMouseLeave:l=>{l.currentTarget.style.color=o("desc-fg")},children:t.jsx("svg",{width:i,height:i,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:t.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 Dn(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function mx(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const hx=({id:e,transport:n,initialDetail:i,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:a,onJuanChange:p,lineageMode:c="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:g,initialPage:x=1,selectedLineageNodeId:m,onNavigate:b,onBack:S,backLabel:h,renderLink:y,enrichDetail:j,getSourceLink:k,readLink:$,railTop:v,extraTabs:_=[],showFeedbackTab:w=!0,feedbackApiUrl:z,height:N,footerExtra:T,className:C,style:P})=>{var Ki;const B=ue(),{convert:A}=q(),[W]=f.useState(()=>{if(!mx(e,i))return null;const Y={...i},je=r??Dn(e,Y);return j&&j(je,Y),{id:e,entry:je,detail:Y}}),[V,K]=f.useState((W==null?void 0:W.entry)??null),[E,le]=f.useState((W==null?void 0:W.detail)??null),[G,ae]=f.useState(!W),[pe,ee]=f.useState(!1),[X,ie]=f.useState([]),[me,te]=f.useState(!1),[se,fe]=f.useState(null),[be,ze]=f.useState(!1),[ve,ke]=f.useState(null),[Ne,Ee]=f.useState(!1),[O,ce]=f.useState(null),[oe,he]=f.useState([]),[Z,F]=f.useState(!1),[I,D]=f.useState(null),[M,ne]=f.useState(null),[R,J]=f.useState(!1),H=f.useRef(null),[U,re]=f.useState(null),Se=a!==void 0?a:U,ye=f.useCallback(Y=>{p?p(Y):re(Y)},[p]),Le=f.useCallback(async Y=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){ie([]);return}te(!0);try{if(n.getCollectionCatalogs)ie(await n.getCollectionCatalogs(Y)||[]);else if(n.getCollectionCatalog){const je=await n.getCollectionCatalog(Y);ie(je?[{resource_id:"",data:je}]:[])}}catch{ie([])}finally{te(!1)}},[n]),Ye=f.useCallback(async Y=>{if(!n.getCollatedEditionIndex){fe(null);return}ze(!0);try{fe(await n.getCollatedEditionIndex(Y))}catch{fe(null)}finally{ze(!1)}},[n]),L=f.useCallback(async Y=>{if(!n.getBookFullTextIndex){ke(null);return}Ee(!0);try{ke(await n.getBookFullTextIndex(Y))}catch{ke(null)}finally{Ee(!1),ce(Y)}},[n]),de=f.useCallback(async Y=>{var je;if(!n.getWorkFullTextList){he([]);return}F(!0);try{const Ie=(await n.getWorkFullTextList(Y)??[]).filter(Ae=>Ae.owner_type!=="Book");he(Ie),D(((je=Ie.find(Ae=>Ae.primary)??Ie[0])==null?void 0:je.key)??null)}catch{he([])}finally{F(!1)}},[n]),ge=f.useCallback(async(Y,je)=>{J(!0);try{if(n.getLineageGraph){const De=await n.getLineageGraph(Y);De&&ne(De)}const Ie=je.version_graph;if(!Ie||!Ie.enabled){M||ne(null),H.current=null;return}const Ae=je.books??[],Xe=[];for(const De of Ae)try{const Qe=await n.getItem(De);Qe&&Xe.push(Qe)}catch{}H.current={work:je,books:Xe};const Q=u??Ie.default_collection??(Ie.core_books&&Ie.core_books.length>0?"core":"all"),Te=Q==="core"&&Array.isArray(Ie.core_books)&&Ie.core_books.length>0?"core":Q??"all";ne(xn(je,Xe,Te))}catch{ne(null),H.current=null}finally{J(!1)}},[n]),$e=f.useRef({initialDetail:i,initialEntry:r});$e.current={initialDetail:i,initialEntry:r},f.useEffect(()=>{let Y=!1;const je=Q=>{Q.type==="collection"?Le(e):Q.type==="work"?(Q.has_collated&&Ye(e),(Q.version_graph||n.getLineageGraph)&&ge(e,Q),n.getWorkFullTextList&&de(e)):Q.type==="book"&&Q.has_full_text&&n.getBookFullTextIndex&&L(e)},Ie=$e.current;let Ae=null;if(W&&W.id===e)Ae=W;else if(Ie.initialDetail&&Ie.initialDetail.id===e){const Q={...Ie.initialDetail},Te=Ie.initialEntry??Dn(e,Q);j&&j(Te,Q),Ae={entry:Te,detail:Q}}return Ae?(ee(!1),ie(Q=>Q.length?[]:Q),fe(null),ke(null),he(Q=>Q.length?[]:Q),D(null),ne(null),H.current=null,K(Ae.entry),le(Ae.detail),ae(!1),je(Ae.detail),()=>{Y=!0}):((async()=>{ae(!0),ee(!1),K(null),le(null),ie([]),fe(null),ke(null),he([]),D(null),ne(null),H.current=null;try{const Q=await n.getItem(e);if(Y)return;if(!Q){ee(!0);return}const Te=Q;let De=null;if(n.getEntry&&(De=await n.getEntry(e),Y))return;De||(De=Dn(e,Te)),j&&j(De,Te),K(De),le(Te),je(Te)}catch{Y||ee(!0)}finally{Y||ae(!1)}})(),()=>{Y=!0})},[e,n,W,j,Le,Ye,ge,L,de]),f.useEffect(()=>{const Y=H.current;!Y||!u||ne(xn(Y.work,Y.books,u))},[u]);const xe=[];if(E){if(xe.push({key:"basic",label:B.detailTab.basicInfo}),E.type==="collection"){me&&X.length===0&&xe.push({key:"catalog:loading",label:`${B.detailTab.catalog}…`});for(const Y of X)xe.push({key:`catalog:${Y.resource_id}`,label:Y.short_name?`${A(Y.short_name)}${B.detailTab.catalogSuffix}`:B.detailTab.collectionCatalog})}E.type==="work"&&(se||be)&&s==="collated"&&xe.push({key:"collated",label:be?`${B.detailTab.collatedEdition}…`:B.detailTab.collatedEdition}),E.type==="book"&&(ve||Ne)&&s==="fulltext"&&xe.push({key:"fulltext",label:Ne?`${B.detailTab.fullText}…`:B.detailTab.fullText}),E.type==="work"&&(oe.length>0||Z)&&s==="fulltext"&&xe.push({key:"fulltext",label:Z?`${B.detailTab.fullText}…`:B.detailTab.fullText}),E.type==="work"&&(M||R)&&xe.push({key:"lineage",label:R?`${B.detailTab.lineage}…`:B.detailTab.lineage});for(const Y of _)(Y.position??"before-feedback")==="before-feedback"&&Y.shouldShow(E)&&xe.push({key:Y.key,label:Y.label});w&&s==="feedback"&&xe.push({key:"feedback",label:B.detailTab.feedback});for(const Y of _)Y.position==="after-feedback"&&Y.shouldShow(E)&&xe.push({key:Y.key,label:Y.label})}f.useEffect(()=>{if(s!=="emendated"||!E)return;l("basic");const Y=setTimeout(()=>{var je;(je=document.getElementById("studies"))==null||je.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(Y)},[s,E,l]);const Ce=V&&E&&k?k({activeTab:s,activeJuan:Se,entry:V,detail:E}):null,Oe=f.useMemo(()=>{var Xe;if(!E)return null;const je=(E.authors??[]).map(Q=>{const Te=ji(Q.role);return`${Q.dynasty?`〔${A(Q.dynasty)}〕`:""}${A(Q.name)}${Te?` ${A(Te)}`:""}`}).join(" · ");let Ie=!1;try{Ie=we.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const Q=E;return{title:A(Q.title),subtitle:Q.edition?A(Q.edition):je||void 0,aside:[Ie?B.status.draft:"",je&&Q.edition?je:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const Q=E;return{title:A(Q.title),subtitle:A(at(Q,B.unit.juan))||void 0,aside:[(Xe=Q.publication_info)==null?void 0:Xe.year,Ie?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:je||void 0}}if(E.type==="entity"){const Q=E,Te=Qe=>Qe==null?"":Qe<0?`前${-Qe}`:String(Qe),De=Q.birth_year!=null||Q.death_year!=null?`${Te(Q.birth_year)||"?"}—${Te(Q.death_year)||"?"}`:"";return{title:A(Q.primary_name||Q.title),subtitle:[Q.dynasty?`〔${A(Q.dynasty)}〕`:"",De].filter(Boolean).join(" ")||void 0,aside:Ie?B.status.draft:void 0,secondLine:void 0}}const Ae=A(at(E,B.unit.juan));return{title:A(E.title),subtitle:[Ae,je].filter(Boolean).join(" · ")||void 0,aside:[yx(B,E.subtype),Ie?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,A,B]),Je=E?E.type==="work"?(((Ki=se==null?void 0:se.juan_files)==null?void 0:Ki.length)??0)>0?"collated":oe.length>0?"fulltext":null:E.type==="book"&&(((ve==null?void 0:ve.chapters.length)??0)>0||E.has_full_text&&n.getBookFullTextIndex&&O!==E.id)?"fulltext":null:null,ct=oe.find(Y=>Y.primary)??oe[0],nn=()=>{var Y;Je==="collated"&&((Y=se==null?void 0:se.juan_files)!=null&&Y.length)?(ye(se.juan_files[0]),l("collated")):Je==="fulltext"&&((E==null?void 0:E.type)==="work"&&ct&&D(ct.key),ye(null),l("fulltext"))};let dt=null;if(E&&$){const Y=$({detail:E,kind:Je,fullTextKey:E.type==="work"?ct==null?void 0:ct.key:void 0});Y&&(dt=t.jsx(Kn,{href:Y}))}else Je&&(dt=t.jsx(Kn,{onClick:nn}));const on=Y=>{if(!E)return null;const je=Y.replace(/\.[^.]+$/,"");if($){const Ie=$({detail:E,kind:"fulltext",juan:je});return Ie?{href:Ie}:null}return{onClick:()=>{ye(je),l("fulltext")}}},rn=new Set(_.map(Y=>Y.key)),_e=xe.filter(Y=>Y.key.startsWith("catalog:")&&Y.key!=="catalog:loading"||rn.has(Y.key)).map(Y=>({key:Y.key,label:Y.label,onClick:()=>l(Y.key)})),Ze=()=>{var Y;return E?E.type==="work"?t.jsx(tl,{data:E,transport:n,onNavigate:b,renderLink:y,readAction:dt,railTop:v,railLinks:_e}):E.type==="book"?t.jsx(rl,{data:E,transport:n,onNavigate:b,renderLink:y,readAction:dt,fullText:ve,fullTextPending:!!E.has_full_text&&!!n.getBookFullTextIndex&&O!==E.id,chapterLink:on,railTop:v,railLinks:_e}):E.type==="collection"?t.jsx(sl,{data:E,catalog:(Y=X[0])==null?void 0:Y.data,transport:n,onNavigate:b,renderLink:y,readAction:dt,railTop:v,railLinks:_e,catalogAction:X.length>0?t.jsxs("a",{href:"#catalog",onClick:je=>{je.preventDefault(),l(`catalog:${X[0].resource_id}`)},children:[A(B.detailTab.collectionCatalog)," →"]}):null}):t.jsx(ll,{data:E,transport:n,onNavigate:b,renderLink:y,railTop:v,railLinks:_e}):null},Re=()=>{var je,Ie,Ae,Xe;if(!V||!E)return null;if(s==="basic"||s==="emendated")return Ze();if(typeof s=="string"&&s.startsWith("catalog:")){const Q=(je=X.find(Te=>`catalog:${Te.resource_id}`===s))==null?void 0:je.data;return t.jsx(gi,{data:Q,onNavigate:b,renderLink:y})}if(s==="collated")return t.jsx(Fi,{index:se||void 0,workId:e,transport:n,onNavigate:b,activeJuan:Se,onJuanChange:ye});if(s==="fulltext"&&E.type==="work"){const Q=I??((Ie=oe[0])==null?void 0:Ie.key);return Q?t.jsx(ni,{bookId:e,workKey:Q,versions:oe,onVersionChange:Te=>{D(Te),ye(null)},transport:n,activeChapter:Se,onChapterChange:ye},Q):t.jsx("div",{style:{padding:24,color:o("desc-fg")},children:Z?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(ni,{index:ve||void 0,bookId:e,transport:n,activeChapter:Se,onChapterChange:ye});if(s==="lineage"){if(!M)return t.jsx("div",{style:{color:o("label-fg"),padding:"24px 0"},children:R?"加載中…":"暫無版本圖數據"});const Q=E.type==="work"?E:null;return t.jsx(Hi,{graph:M,renderLink:y,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:d,selectedNodeId:m,collection:u??((Ae=Q==null?void 0:Q.version_graph)==null?void 0:Ae.default_collection),onCollectionChange:g,collectionsAvailable:(Xe=Q==null?void 0:Q.version_graph)==null?void 0:Xe.collections,collectionCounts:(()=>{var Ji,Zi,Xi,Qi,eo,to,no;if(!Q)return;const Te={},De=((Ji=H.current)==null?void 0:Ji.books)??[];Te.all=(((Zi=Q.books)==null?void 0:Zi.length)??0)-(((Qi=(Xi=Q.version_graph)==null?void 0:Xi.excluded_books)==null?void 0:Qi.length)??0);const Qe=(eo=Q.version_graph)==null?void 0:eo.collections;if(Qe)for(const io of Object.keys(Qe))Te[io]=xn(Q,De,io).nodes.filter(oo=>oo.kind==="book"&&!oo.bridge).length;return Te.core==null&&((no=(to=Q.version_graph)==null?void 0:to.core_books)!=null&&no.length)&&(Te.core=Q.version_graph.core_books.length),Te})()})}if(s==="feedback"&&w)return t.jsx(Zs,{resourceId:e,apiUrl:z});const Y=_.find(Q=>Q.key===s);return Y?Y.render({detail:E,entry:V,transport:n,onNavigate:b}):null};if(G)return t.jsx(Ht,{style:{minHeight:N,...P},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((Y,je)=>t.jsx("div",{style:{height:je===1?40:16,width:Y,opacity:.35,background:o("rule")}},je))})});if(pe||!E||!V||!Oe)return t.jsx(Ht,{style:{minHeight:N,...P},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:o("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const kt=s==="basic"||s==="emendated",sn=[{label:h??B.detailTab.backToIndex,onClick:S}];if(E.type==="book"&&E.work_id){const Y=E.work_id;sn.push({label:B.indexType.work,id:Y,onClick:()=>b==null?void 0:b(Y)})}sn.push({label:B.indexType[E.type]});const ln=s==="collated"||s==="fulltext",Yi=typeof T=="string"?B.status[T.trim()]??T:T,qi=t.jsx(ds,{left:t.jsxs(t.Fragment,{children:[Yi,Yi?" · ":"",t.jsx(bx,{id:E.id,label:B.label.id,copied:B.action.copied,copyLabel:B.action.copy})]}),right:t.jsxs(t.Fragment,{children:[w&&!kt&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:B.detailTab.submitVersion}),Ce&&t.jsx("a",{href:Ce.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:o("meta-fg")},children:B.detailTab.dataLicense})]})});return kt?t.jsx("div",{className:C,children:t.jsxs(Ht,{grid:!0,style:{minHeight:N,...P},children:[t.jsx(Jn,{breadcrumb:t.jsx(Zn,{items:sn}),actions:t.jsxs(t.Fragment,{children:[t.jsx(li,{style:{border:"none",background:"transparent"}}),Ce&&t.jsx(ai,{...Ce})]})}),Ze(),qi]})}):t.jsx("div",{className:C,children:t.jsxs(Ht,{wide:ln,style:{minHeight:N,...P},children:[t.jsx(Jn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(ki,{char:"籍"}),t.jsx(Zn,{items:sn})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(li,{}),w&&t.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:o("meta-fg")},children:B.detailTab.feedback}),Ce&&t.jsx(ai,{...Ce})]})}),t.jsx(ts,{...Oe,aside:ln?t.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:o("accent"),borderBottom:`1px solid ${o("rule")}`},children:[A("作品信息")," →"]}):Oe.aside}),!ln&&xe.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:xe.map(Y=>t.jsx(ns,{label:Y.label,active:Y.key===s||kt&&Y.key==="basic",onClick:()=>l(Y.key)},Y.key))}),t.jsx("div",{style:{marginTop:!ln&&xe.length>1?8:0},children:Re()}),qi]})})};function bx({id:e,label:n,copied:i,copyLabel:r}){const[s,l]=f.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var a;(a=navigator.clipboard)==null||a.writeText(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?i:r,"aria-label":s?i:r,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:o("aux-fg")},children:s?"✓":"⧉"})]})}function yx(e,n){return n?e.workSubtype[n]??n:""}const hl=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛藍"}],Cn="zhusha",In="bim-theme";function bl(e){return e==="zhusha"||e==="indigo"}function Tn(e){return bl(e)?e:Cn}function jx(){try{return Tn(window.localStorage.getItem(In))}catch{return Cn}}function yl(e){try{window.localStorage.setItem(In,e)}catch{}}function jl(e){const n=Tn(e);return document.documentElement.setAttribute("data-theme",n),n}function vl(){return Tn(document.documentElement.getAttribute("data-theme"))}const vx=`try{if(localStorage.getItem(${JSON.stringify(In)})==='indigo')document.documentElement.setAttribute('data-theme','indigo')}catch(e){}`,kx={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo"},Sx=({onChange:e,style:n})=>{const{convert:i}=q(),[r,s]=f.useState(Cn);f.useEffect(()=>{s(vl())},[]);const l=a=>{s(jl(a)),yl(a),e==null||e(a)};return t.jsx("div",{role:"radiogroup","aria-label":i("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:hl.map(a=>{const p=r===a.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":p,"aria-label":i(a.label),title:i(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:t.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:"50%",boxSizing:"border-box",background:o(kx[a.name]),boxShadow:p?`0 0 0 2px ${o("page-bg")}, 0 0 0 3.5px ${o("aux-fg")}`:"none"}})},a.name)})})};exports.BidLink=we.BidLink;exports.BookIndexError=we.BookIndexError;exports.BookIndexManager=we.BookIndexManager;exports.BookIndexStorage=we.BookIndexStorage;exports.BundleStorage=we.BundleStorage;exports.ConfigError=we.ConfigError;exports.GithubStorage=we.GithubStorage;exports.IdGenerationError=we.IdGenerationError;exports.IdGenerator=we.IdGenerator;exports.LocalStorage=we.LocalStorage;exports.MigrationError=we.MigrationError;exports.StorageError=we.StorageError;exports.base36Decode=we.base36Decode;exports.base36Encode=we.base36Encode;exports.base58Decode=we.base58Decode;exports.buildId=we.buildId;exports.buildPromotionMap=we.buildPromotionMap;exports.cleanName=we.cleanName;exports.decodeId=we.decodeId;exports.decodeIdString=we.decodeIdString;exports.encodeId=we.encodeId;exports.extractIdFromUrl=we.extractIdFromUrl;exports.extractStatus=we.extractStatus;exports.extractType=we.extractType;exports.normalizeCatalog=we.normalizeCatalog;exports.parseId=we.parseId;exports.shardOf=we.shardOf;exports.smartDecode=we.smartDecode;exports.validateResource=we.validateResource;exports.Badge=hn;exports.BidUrlProvider=Rl;exports.BookDetailLayout=hx;exports.BookFullText=ni;exports.BookPage=rl;exports.Breadcrumb=Zn;exports.CATALOG_ALL_ID=rt;exports.CATALOG_CSS=al;exports.CATALOG_NARROW_QUERY=Gi;exports.CATALOG_PAGE_SIZE=Ui;exports.CATALOG_UNCLASSIFIED_ID=qt;exports.CardFoot=Qt;exports.CatalogPage=gx;exports.CatalogPager=gl;exports.CatalogTree=dl;exports.CheckFilter=Qr;exports.Chip=is;exports.ChipWall=wc;exports.CollatedEdition=Fi;exports.CollectionCatalog=gi;exports.CollectionPage=sl;exports.CreateEntityDialog=Hs;exports.DEFAULT_READER_PREFS=_i;exports.DEFAULT_THEME=Cn;exports.DETAIL_CSS=es;exports.Dash=Tc;exports.DataTable=$c;exports.DetailFooter=ds;exports.DetailGrid=Zt;exports.DetailHeader=ts;exports.EmendatedBySection=Br;exports.EmptyNote=Wc;exports.EntityDetail=Ir;exports.EntityPage=ll;exports.EntityPickerDialog=Us;exports.EntitySelector=Ds;exports.ExpandRow=Ec;exports.ExtLink=Mc;exports.FEEDBACK_FAB_OFFSET_VAR=oi;exports.FONT_SIZE_STEPS=$t;exports.FactList=jc;exports.FeedbackButton=su;exports.FeedbackDialog=Ks;exports.FeedbackForm=Js;exports.FeedbackList=Pi;exports.FeedbackTab=Zs;exports.FilterChip=ns;exports.FormInput=Ge;exports.FormTextArea=bt;exports.GUJI_MARKDOWN_FIELD=sc;exports.GUJI_TABLE_NOTATION=vs;exports.GlyphBadge=ki;exports.GujiTable=Ii;exports.HomePage=ti;exports.ImagePanel=ms;exports.IndexApp=pp;exports.IndexBrowser=Un;exports.IndexDetail=fi;exports.IndexEditor=Vs;exports.IndexView=Yp;exports.IntroGrid=yc;exports.LocaleContext=Rt;exports.LocaleProvider=Vl;exports.LocaleToggle=li;exports.MetaLine=Me;exports.ModeIndicator=$r;exports.MoreButton=Sc;exports.MoreLink=Bt;exports.PAGE_MAX_WIDTH=pn;exports.PageFrame=Ht;exports.Quote=Nc;exports.READER_CSS=xs;exports.RECENT_IDS_STORAGE_KEY=Ct;exports.ROLE_CLASS_ORDER=Dr;exports.ReadButton=Kn;exports.ReaderMdText=Ni;exports.ReaderShell=zi;exports.ReaderToc=gs;exports.RelationPanel=Ps;exports.RepoSourceLink=ai;exports.ResourceEditor=Gn;exports.ResourceGroup=Lc;exports.ResourceLine=Bc;exports.ResourceList=xi;exports.ResourceRow=as;exports.SNIPPET_MARK_END=yr;exports.SNIPPET_MARK_START=br;exports.SearchInput=zr;exports.Sec=Fe;exports.Section=qe;exports.SectionHead=vc;exports.SideList=ht;exports.SmartBidInput=un;exports.SourceEditor=Ws;exports.SummaryCard=Xt;exports.THEMES=hl;exports.THEME_INIT_SCRIPT=vx;exports.THEME_STORAGE_KEY=In;exports.TabFilter=_n;exports.TableHead=zc;exports.TableRow=Cc;exports.TagRow=cs;exports.TagRows=Ac;exports.TextButton=kc;exports.ThemeToggle=Sx;exports.TopStrip=Jn;exports.VersionLineageGraph=ol;exports.VersionLineageList=il;exports.VersionLineageView=Hi;exports.VolumeChips=_c;exports.VolumeLinks=Si;exports.WorkCard=xl;exports.WorkCardGrid=ml;exports.WorkCatalog=up;exports.WorkPage=tl;exports.WorkRow=fl;exports.applyTheme=jl;exports.bucketResources=bi;exports.buildCatalogTree=sx;exports.buildCollectionTable=Gr;exports.buildLineageGraph=xn;exports.buildPageUrl=ui;exports.buildParagraphBlocks=Is;exports.buildVersionRow=Pr;exports.buildVersionTable=Or;exports.canParagraphize=zn;exports.catalogNodeIdOf=ox;exports.catalogNodeIdsOf=rx;exports.catalogPageCount=dx;exports.catalogTotal=Vi;exports.classificationPath=tn;exports.compareCatalogCards=cx;exports.computeVersionPartition=nc;exports.currentTheme=vl;exports.defaultWorkLink=pl;exports.deriveDating=Qa;exports.deriveEditionType=Vr;exports.deriveEra=Jt;exports.deriveYear=kn;exports.deriveYearRange=hi;exports.detailToEditor=qs;exports.detectGenre=$n;exports.displayAuthorRole=ji;exports.editorToDetail=Vp;exports.eraRank=Yn;exports.findCatalogPath=zt;exports.flattenTitles=Xn;exports.flattenToc=js;exports.formatTemplate=Kt;exports.formatVolumeRange=wn;exports.getDisplayNameFromUrl=Nt;exports.getStartPage=pi;exports.getTypeGroupKey=ci;exports.groupRelatedWorks=ec;exports.gujiInlineToPlain=Jr;exports.hasGujiMarkdownV02=qn;exports.hasGujiTableNotation=ks;exports.isThemeName=bl;exports.measureText=at;exports.mergeVolumeResources=di;exports.normalizeEra=We;exports.normalizeRole=yi;exports.normalizeTheme=Tn;exports.normalizeVolumeIndex=Ut;exports.normalizeVolumes=_r;exports.numberToChinese=Ur;exports.paginationItems=cl;exports.parseChineseNumber=fn;exports.parseGujiInline=Kr;exports.parseGujiTable=ws;exports.parseSourceString=Ms;exports.pickReaderVersion=ys;exports.readStoredTheme=jx;exports.readerVersionOptionLabel=ei;exports.readerVersionsFromFullText=bs;exports.renderFullTextBody=ld;exports.renderProperNames=Es;exports.renderReaderInline=Ri;exports.resourceHref=Lt;exports.resourceNote=Sn;exports.roleFacets=Hr;exports.rowNo=Ic;exports.sortYear=gn;exports.splitFullTextTables=Ci;exports.splitHighlightSnippet=jr;exports.splitTableRow=Ss;exports.storeTheme=yl;exports.stringifySources=Fs;exports.toCatalogWorkCard=ax;exports.useBidUrl=Pe;exports.useConvert=q;exports.useReaderPrefs=$i;exports.useT=ue;exports.validateLineageGraph=zu;exports.volumeStats=bn;
|