book-index-ui 0.19.1 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,21 +1,21 @@
1
- "use strict";var bl=Object.create;var io=Object.defineProperty;var yl=Object.getOwnPropertyDescriptor;var jl=Object.getOwnPropertyNames;var vl=Object.getPrototypeOf,kl=Object.prototype.hasOwnProperty;var Sl=(e,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of jl(n))!kl.call(e,s)&&s!==i&&io(e,s,{get:()=>n[s],enumerable:!(r=yl(n,s))||r.enumerable});return e};var sn=(e,n,i)=>(i=e!=null?bl(vl(e)):{},Sl(n||!e||!e.__esModule?io(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const be=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),f=require("react"),wl=require("opencc-js/t2cn"),_l=require("react-markdown"),$l=require("remark-gfm"),zl=e=>`/book-index?id=${e}`,fr=f.createContext(zl);function Cl({buildUrl:e,children:n}){const i=f.useMemo(()=>e,[e]);return t.jsx(fr.Provider,{value:i,children:n})}function Pe(){return f.useContext(fr)}const gr="",mr="";function hr(e){const n=[];let i=!1,r=e;for(;r.length;){const s=i?mr:gr,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 De(e,n){return{title:e,tokens:n}}const oo='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Il=[De("基础(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"}}),De("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),De("提示与警告",{"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)"}}),De("遮罩与阴影",{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)"}}),De("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),De("资源",{"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"}}),De("整理本(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"}}),De("版本传承(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"}}),De("编辑器视图(主要在 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")'}}),De("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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}}),De("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),De("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),De("字体(全站无衬线,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:oo,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:oo,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Tl=Object.assign({},...Il.map(e=>e.tokens)),br={};for(const[e,n]of Object.entries(Tl))br[e]=`var(--bim-${e}, ${n.value})`;function o(e){const n=br[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function bt(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function El(e,n){return bt(e).includes(n)}const Dn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Rl={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};o("quality-published"),o("quality-fine"),o("quality-rough"),o("quality-ocr");const Tt=f.createContext(null),yr={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:"搜索古籍索引",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:"圖片資源"}},Nl={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:"搜索古籍索引",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:"图片资源"}},Ll=["曹霑"];function Bl(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Al(e,n=Ll){const i=[...new Set(n.filter(Boolean))].sort((l,d)=>d.length-l.length);if(!i.length)return e;const r=new RegExp(`(${i.map(Bl).join("|")})`,"g"),s=new Set(i);return l=>{if(!l)return e(l);const d=l.split(r);return d.length===1?e(l):d.map((p,a)=>a%2===1&&s.has(p)?p:p&&e(p)).join("")}}let Bt=null;function Wl(){if(Bt)return Bt;try{Bt=Al(wl.Converter({from:"tw",to:"cn"}))}catch{Bt=e=>e}return Bt}const Ml={"zh-Hant":yr,"zh-Hans":Nl},jr="bim-locale";function Fl(){try{const e=localStorage.getItem(jr);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Pl(e){try{localStorage.setItem(jr,e)}catch{}}const Ol="zh-Hans",Dl=({locale:e,onLocaleChange:n,converter:i,children:r})=>{const[s,l]=f.useState(e??Ol),d=e??s;f.useEffect(()=>{if(e)return;const u=Fl();u&&u!==s&&l(u)},[]);const p=f.useMemo(()=>d==="zh-Hans"?i??Wl():null,[d,i]),a=f.useCallback(u=>{l(u),Pl(u),n==null||n(u)},[n]),c=f.useMemo(()=>({locale:d,setLocale:a,messages:Ml[d],converter:p}),[d,a,p]);return t.jsx(Tt.Provider,{value:c,children:r})};function de(){const e=f.useContext(Tt);return(e==null?void 0:e.messages)??yr}const Hl=2e3;function Y(){const e=f.useContext(Tt),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(d=>{if(!d)return"";if(!i)return d;const p=r.current.get(d);if(p!==void 0)return p;const a=i(d);if(r.current.size>=Hl){const c=r.current.keys().next().value;c!==void 0&&r.current.delete(c)}return r.current.set(d,a),a},[i]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Yt(e,n){return e.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function Gl(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 Ul(){return{id:"",name:"",url:"",type:"text",details:""}}const Hn=({items:e,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const l=de(),[d,p]=f.useState(null),a=[{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}],c=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=y=>{if(!s)return!0;const j=bt(y);return s==="text"?j.includes("text"):s==="image"?j.includes("image")||j.includes("physical"):s==="physical"?j.includes("physical"):j.includes(s)},g=e.map((y,j)=>({item:y,originalIndex:j})).filter(({item:y})=>u(y)),x=()=>{const y=Ul();s&&(y.type=s),n([...e,y]),p(e.length)},m=y=>{n(e.filter((j,_)=>_!==y)),p(null)},b=(y,j,_)=>{const k=[...e];if(k[y]={...k[y],[j]:_},j==="url"&&!k[y].id){const z=Gl(_);z&&(k[y].id=z)}n(k)},S=(y,j,_)=>{const z={...e[y].metadata||{}};_?z[j]=_:delete z[j],b(y,"metadata",Object.keys(z).length>0?z:void 0)},h=(y,j)=>{const _=j.trim()?j.split(/[,,、]/).map(k=>k.trim()).filter(Boolean):void 0;b(y,"structure",_)},v=(y,j,_)=>{const z=e[y].coverage||{level:1,ranges:""};j==="level"?z.level=parseInt(_)||1:z.ranges=_,b(y,"coverage",z.ranges?z:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[g.map(({item:y,originalIndex:j})=>{var _,k,z;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(d===j?null:j),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:d===j?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Vl(y.type??"text"),color:o("on-color-fg")},children:(()=>{var C,E;const w=bt(y);return w.length===0?y.type??"text":w.length===1?((C=a.find(R=>R.value===w[0]))==null?void 0:C.label)??w[0]:w.includes("text")&&w.includes("image")?((E=a.find(R=>R.value==="text+image"))==null?void 0:E.label)??"text+image":w.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${l.editor.resourcePlaceholder} ${j+1}`}),y.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:y.id}),y.url&&t.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:w=>w.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&y.url&&Yl(j,r==null?void 0:r[j],i,l),t.jsx("button",{onClick:w=>{w.stopPropagation(),m(j)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),d===j&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:[El(y,"image")&&y.url&&Kl(y,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:At,children:[t.jsx("span",{style:Wt,children:l.label.type}),t.jsx("select",{value:y.type,onChange:w=>b(j,"type",w.target.value),style:{...Ze,flex:1},children:a.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]}),t.jsxs("label",{style:At,children:[t.jsx("span",{style:Wt,children:l.label.rootType}),t.jsx("select",{value:y.root_type||"catalog",onChange:w=>b(j,"root_type",w.target.value),style:{...Ze,flex:1},children:c.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:y.id,onChange:w=>b(j,"id",w.target.value),placeholder:l.editor.idAutoExtract,style:{...Ze,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:y.name,onChange:w=>b(j,"name",w.target.value),placeholder:l.editor.resourceName,style:{...Ze,flex:1}})]}),t.jsx("input",{type:"text",value:y.url,onChange:w=>b(j,"url",w.target.value),placeholder:l.editor.resourceUrl,style:Ze}),t.jsx("input",{type:"text",value:((_=y.structure)==null?void 0:_.join("、"))||"",onChange:w=>h(j,w.target.value),placeholder:l.editor.structurePlaceholder,style:Ze}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:At,children:[t.jsx("span",{style:Wt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((k=y.coverage)==null?void 0:k.level)??"",onChange:w=>v(j,"level",w.target.value),placeholder:"1",style:{...Ze,width:"60px"}})]}),t.jsxs("label",{style:{...At,flex:1},children:[t.jsx("span",{style:Wt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:((z=y.coverage)==null?void 0:z.ranges)||"",onChange:w=>v(j,"ranges",w.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...Ze,flex:1}})]})]}),t.jsx("textarea",{value:y.details||"",onChange:w=>b(j,"details",w.target.value),placeholder:l.editor.detailsPlaceholder,style:{...Ze,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 E;return t.jsxs("label",{style:{...At,gap:"4px"},children:[t.jsx("span",{style:{...Wt,minWidth:"56px"},children:C}),t.jsx("input",{type:"text",value:((E=y.metadata)==null?void 0:E[w])||"",onChange:R=>S(j,w,R.target.value),placeholder:C,style:{...Ze,flex:1}})]},w)})})]})]})]})]},j)}),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 Vl(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 Yl(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:d=>{d.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 Kl(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 Ze={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"},At={display:"flex",alignItems:"center",gap:"6px"},Wt={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 Et(e){try{return ql[new URL(e).hostname]}catch{return}}const ro={text:0,image:1,physical:2};function ai(e){return e.length===0?"physical":[...e].sort((n,i)=>(ro[n]??99)-(ro[i]??99)).join("+")}function ci(e){var d;const n=p=>{const a=p.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const c=p.match(/^(.+?)[·(](\d+)[)]?$/);return c?[c[1],parseInt(c[2])]:null},i=new Map;for(let p=0;p<e.length;p++){const a=e[p];if(a.volumes&&a.volumes.length>0)continue;const c=n(a.name);if(!c)continue;const[u,g]=c,x=`${u}|${ai(bt(a))}`;i.has(x)||i.set(x,{base:{...a,name:u,url:"",volumes:[]},volumes:[],indices:[]});const m=i.get(x);m.volumes.push({volume:g,url:a.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((a,c)=>a.volume-c.volume),p.base.volumes=p.volumes,p.base.expected_volumes=p.volumes.length,p.base.url||(p.base.url=((d=p.volumes.find(a=>a.url))==null?void 0:d.url)??""),r.push(p.base);for(const a of p.indices)s.add(a)}const l=[...r];for(let p=0;p<e.length;p++)s.has(p)||l.push(e[p]);return l}function vr(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 kr(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||vr(n)}))}function mn(e){const n=kr(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 di(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 pi(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 Rt(e){if(!e.url)return;const n=di(e.metadata);return n?pi(e.url,n):e.url}const so={text:o("restype-text"),image:o("restype-image"),"text+image":o("restype-text-image"),physical:o("restype-physical")};function Jl(e){return e.includes("text")&&e.includes("image")?so["text+image"]:so[e[0]||"physical"]}const ui=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const l=de(),{convert:d}=Y(),p=f.useMemo(()=>ci(e||[]),[e]),{mirrorGroups:a,ungroupedItems:c}=f.useMemo(()=>{const h=new Map,v=[];for(const y of p){const j=y.group;j?(h.has(j)||h.set(j,[]),h.get(j).push(y)):v.push(y)}for(const y of h.values())y.sort((j,_)=>{const k=z=>z.group_role==="origin"?0:z.group_role==="mirror"?1:2;return k(j)-k(_)});return{mirrorGroups:h,ungroupedItems:v}},[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(v=>u[v]||v).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,v)=>t.jsx(In,{item:h},h.id||v))});const x=(h,v)=>{const y=i==null?void 0:i[h],j=(y==null?void 0:y.label)||h,_=y==null?void 0:y.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:d(j)}),_&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.5},children:d(_)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((k,z)=>t.jsx(In,{item:k,onNavigate:r,renderLink:s},k.id||z))})]},`group-${h}`)},m=new Map;for(const h of c){const v=ai(bt(h));m.has(v)||m.set(v,[]),m.get(v).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:[[...a.entries()].map(([h,v])=>x(h,v)),S.map(h=>{const v=m.get(h),y=Jl(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:y,whiteSpace:"nowrap",flexShrink:0},children:g(h)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((j,_)=>t.jsx(In,{item:j,onNavigate:r,renderLink:s},j.id||_))})]},h)})]})},Zl={bw:{label:"",bg:o("colormode-bw-bg"),fg:o("colormode-bw-fg")},color:{label:"",bg:o("colormode-color-bg"),fg:o("colormode-color-fg")}},In=({item:e})=>{const n=de(),{convert:i}=Y(),[r,s]=f.useState(!1),l=f.useMemo(()=>(e.url?Et(e.url):void 0)||i(e.name),[e.url,e.name,i]),d=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(b=>({...b,url:b.url||vr(b)})),[e.volumes]),p=d&&d.length>0,a=p?new Set(d.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,c=p?new Set(d.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=e.expected_volumes??(p?a+c:0),g=e.color_mode?{...Zl[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:[a,"/",u,n.unit.volume,c>0&&t.jsxs("span",{style:{color:o("missing-fg"),marginLeft:"3px"},children:["缺",c]})]}),e.url&&t.jsx("a",{href:(()=>{const b=di(e.metadata);return b?pi(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:d.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)})})]})},Sr=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:d})=>{const p=de(),a=e==="local",c=(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:c?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...x,background:o(c?"warning":"success"),color:o("on-color-fg")},...m,children:[t.jsx("span",{children:c?"📝":"📚"}),t.jsx("span",{children:c?"draft":"official"})]});return i==="index-browser"?a?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:d,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:a?p.mode.switchToGithub:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:a?"📁":"🌐"}),t.jsx("span",{children:a?p.mode.localMode:p.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&t.jsxs("div",{onClick:d,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})]}),!a&&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})]})]})},hn="bim-search-history",lo=10,ao=8;function Dt(){try{const e=localStorage.getItem(hn);return e?JSON.parse(e):[]}catch{return[]}}function Xl(e){try{const n=Dt().filter(i=>i!==e);n.unshift(e),n.length>lo&&(n.length=lo),localStorage.setItem(hn,JSON.stringify(n))}catch{}}function Ql(e){try{const n=Dt().filter(i=>i!==e);localStorage.setItem(hn,JSON.stringify(n))}catch{}}function ea(){try{localStorage.removeItem(hn)}catch{}}const wr=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:l})=>{const d=de(),p=l??d.search.placeholder,a={work:d.indexType.work,book:d.indexType.book,collection:d.indexType.collection,entity:d.indexType.entity},[c,u]=f.useState(!1),[g,x]=f.useState([]),[m,b]=f.useState(-1),[S,h]=f.useState(Dt),v=f.useRef(null),y=f.useRef(null),j=f.useRef(null),_=f.useRef(!1);f.useEffect(()=>{b(-1);const T=n.trim();if(!T){x(S.map(W=>({type:"history",text:W})));return}if(!e.searchAll){x([]);return}let O=!1;const M=setTimeout(()=>{e.searchAll(T,ao).then(W=>{if(O)return;const P=[...W.works,...W.books,...W.collections,...W.entities??[]];x(P.slice(0,ao).map(V=>({type:"entry",text:V.title||V.id,entry:V})))}).catch(()=>{O||x([])})},80);return()=>{O=!0,clearTimeout(M)}},[n,S,e]),f.useEffect(()=>{const T=O=>{j.current&&!j.current.contains(O.target)&&u(!1)};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[]),f.useEffect(()=>{const T=O=>{var M,W;if(O.key==="/"&&document.activeElement!==v.current){const P=(M=document.activeElement)==null?void 0:M.tagName;if(P==="INPUT"||P==="TEXTAREA"||P==="SELECT")return;O.preventDefault(),(W=v.current)==null||W.focus()}};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[]);const k=f.useCallback(T=>{T.trim()&&(Xl(T.trim()),h(Dt())),r(T),u(!1)},[r]),z=f.useCallback(T=>{T.type==="history"?(i(T.text),k(T.text)):T.entry&&(s?(s(T.entry),u(!1)):(i(T.text),k(T.text)))},[i,k,s]),w=f.useCallback(T=>{if(!c||g.length===0){T.key==="Enter"&&k(n);return}switch(T.key){case"ArrowDown":T.preventDefault(),b(O=>(O+1)%g.length);break;case"ArrowUp":T.preventDefault(),b(O=>(O-1+g.length)%g.length);break;case"Enter":T.preventDefault(),m>=0&&m<g.length?z(g[m]):k(n);break;case"Escape":T.preventDefault(),u(!1);break}},[c,g,m,n,k,z]),C=f.useCallback((T,O)=>{O.stopPropagation(),Ql(T),h(Dt()),x(M=>M.filter(W=>!(W.type==="history"&&W.text===T)))},[]),E=f.useCallback(T=>{T.stopPropagation(),ea(),h([]),x([])},[]);f.useEffect(()=>{if(m>=0&&y.current){const T=y.current.children;T[m]&&T[m].scrollIntoView({block:"nearest"})}},[m]);const R=!n.trim()&&S.length>0;return t.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:v,type:"text",placeholder:p,value:n,onChange:T=>{i(T.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"}}),c&&g.length>0&&t.jsxs("div",{ref:y,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:[R&&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:d.search.history}),t.jsx("button",{onClick:E,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:d.search.clearAll})]}),g.map((T,O)=>t.jsxs("div",{onClick:()=>z(T),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:T.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:T.text}),T.entry&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:[a[T.entry.type],T.entry.edition&&` · ${T.entry.edition}`,T.entry.author&&` · ${T.entry.author}`]}),T.type==="history"&&t.jsx("button",{onClick:M=>C(T.text,M),style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:d.action.remove,children:"×"})]},`${T.type}-${T.text}-${O}`))]})]})},$t="bim-recent-ids",co="bim-recent-entries",po=50,Tn=5,ta=50,na=200;function St(){try{const e=localStorage.getItem($t);if(e)return JSON.parse(e);const n=localStorage.getItem(co);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem($t,JSON.stringify(i)),localStorage.removeItem(co),i}return[]}catch{return[]}}function uo(e){try{const n=St().filter(i=>i!==e);n.unshift(e),n.length>po&&(n.length=po),localStorage.setItem($t,JSON.stringify(n))}catch{}}function ia(e){try{const n=St().filter(i=>i!==e);localStorage.setItem($t,JSON.stringify(n))}catch{}}function oa(){try{localStorage.removeItem($t)}catch{}}const ra={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Gn=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:d,onConfigurePath:p,onSelectFolder:a,hideModeIndicator:c,resultVariant:u="compact",renderEntry:g,initialQuery:x,onQueryChange:m,headerRight:b,reserveViewportHeight:S=!1})=>{const h=de(),v=[{type:"work",icon:"✍️",name:h.indexType.work,key:"works"},{type:"book",icon:"📖",name:h.indexType.book,key:"books"},{type:"collection",icon:"📚",name:h.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:h.indexType.entity,key:"entities"}],[y,j]=f.useState(x??""),[_,k]=f.useState(null),[z,w]=f.useState(null),[C,E]=f.useState(!1),[R,T]=f.useState(null),[O,M]=f.useState(""),[W,P]=f.useState(!(x!=null&&x.trim())),[V,K]=f.useState(St),[N,le]=f.useState([]),[G,se]=f.useState(!1),[ne,Q]=f.useState(!1),[H,te]=f.useState(null),[pe,re]=f.useState(null),ee=f.useRef(void 0),ye=f.useRef(!1),ae=f.useCallback(async(L,I)=>{if(!L.trim()){P(!0),k(null),w(null);return}P(!1),E(!0),M("");try{if(e.searchAll){const $=await e.searchAll(L,I??Tn);k($)}else{const $=["work","book","collection","entity"],F=await Promise.all($.map(A=>e.search(L,A,{page:1,pageSize:I??Tn})));k({works:F[0].entries,books:F[1].entries,collections:F[2].entries,entities:F[3].entries,totalWorks:F[0].total,totalBooks:F[1].total,totalCollections:F[2].total,totalEntities:F[3].total})}}catch($){M($ instanceof Error?$.message:String($)),k(null)}finally{E(!1)}},[e]);f.useEffect(()=>{let L=!1;const I=()=>{var J,fe;const $=["work","book","collection","entity"],F=Promise.all($.map(we=>e.loadEntries(we,{page:1,pageSize:1}).catch(()=>({total:0})))),A=((J=e.getResourceCounts)==null?void 0:J.call(e).catch(()=>null))??Promise.resolve(null),Z=((fe=e.getSubtypeStats)==null?void 0:fe.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([F,A,Z]).then(([we,_e,Ne])=>{L||(te({works:we[0].total,books:we[1].total,collections:we[2].total,entities:we[3].total,hasText:_e==null?void 0:_e.hasText,hasImage:_e==null?void 0:_e.hasImage}),Ne&&re(Ne))})};return e.getCounts?e.getCounts().then($=>{var F,A;L||(te({works:$.works,books:$.books,collections:$.collections,entities:$.entities,hasText:(F=$.resourceCounts)==null?void 0:F.hasText,hasImage:(A=$.resourceCounts)==null?void 0:A.hasImage}),$.subtypeStats&&re($.subtypeStats))}).catch(()=>{L||I()}):I(),()=>{L=!0}},[e]),f.useEffect(()=>{ye.current||!(x!=null&&x.trim())||(ye.current=!0,ae(x))},[x,ae]);const Te=f.useCallback(L=>{if(j(L),!L.trim()){m==null||m(L),P(!0),k(null),w(null);return}ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{w(null),m==null||m(L),ae(L)},na)},[ae,m]),je=f.useCallback(L=>{ee.current&&clearTimeout(ee.current),m==null||m(L),ae(L)},[ae,m]),Ce=f.useCallback(L=>{w(L),ae(y,ta)},[y,ae]);f.useEffect(()=>{if(!V.length){le([]);return}let L=!1;return se(!0),Promise.all(V.slice(0,10).map(async I=>{var $,F,A;try{if(e.getEntry){const J=await e.getEntry(I);if(J)return J}const Z=await e.getItem(I);if(Z){const J=Z.authors;return{id:I,title:Z.title||I,type:Z.type||"work",author:($=J==null?void 0:J[0])==null?void 0:$.name,dynasty:(F=J==null?void 0:J[0])==null?void 0:F.dynasty,role:(A=J==null?void 0:J[0])==null?void 0:A.role,edition:Z.edition||void 0}}}catch{}return{id:I,title:I,type:"work",notFound:!0}})).then(I=>{L||(le(I),se(!1))}),()=>{L=!0}},[V,e]);const Re=L=>{T(L.id),uo(L.id),K(St()),r==null||r(L)},Ie=(L,I)=>{if(r&&la(I)){I.preventDefault(),Re(L);return}uo(L.id),K(St())},D=L=>{ia(L),K(St())},oe=()=>{oa(),K([])},ie=L=>v.find(I=>I.type===L),xe=!W&&!_&&!O,q=_&&(_.works.length>0||_.books.length>0||_.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",style:S?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:aa}),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,!c&&t.jsx(Sr,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:l,onToggleDraft:d,onConfigurePath:p,onSelectFolder:a})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(wr,{transport:e,value:y,onChange:Te,onSearch:je,onEntrySelect:Re}),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})]}),W&&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:H&&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:H.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:H.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[h.indexType.work," ",t.jsx("strong",{style:{color:o("fg")},children:H.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.book," ",t.jsx("strong",{style:{color:o("fg")},children:H.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.collection," ",t.jsx("strong",{style:{color:o("fg")},children:H.collections.toLocaleString()}),H.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:H.entities.toLocaleString()})]})]})}),H.hasImage!=null&&H.hasText!=null&&t.jsxs("span",{children:[h.resourceType.image," ",t.jsx("strong",{style:{color:o("fg")},children:H.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.resourceType.text," ",t.jsx("strong",{style:{color:o("fg")},children:H.hasText.toLocaleString()})]})]})}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:C||xe?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg"),minHeight:sa,boxSizing:"border-box"},children:h.search.searching}):O?t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),t.jsx("p",{style:{color:o("desc-fg")},children:O})]}):W?t.jsx("div",{style:{flex:1},children:G?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:h.search.loading}):N.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:oe,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:N.slice(0,ne?10:3).map(L=>L.notFound?t.jsx(ua,{id:L.id,onRemove:D,t:h},L.id):t.jsx(xo,{entry:L,selected:R===L.id,onClick:Ie,getConfig:ie,onRemove:D},L.id))}),!ne&&N.length>3&&t.jsx("button",{onClick:()=>Q(!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("div",{style:{fontSize:"32px",marginBottom:"8px"},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})]})}):q?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:ca}),v.map(({type:L,icon:I,name:$,key:F})=>{const A=_[F]??[],Z=ra[F],J=_[Z]??0;if(A.length===0)return null;const we=!(z===L)&&J>Tn;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:[I," ",$,t.jsxs("span",{style:{fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[J," ",h.unit.items]})]}),we&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>Ce(L),style:{border:"none",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"12px"},children:h.action.viewAll})]}),t.jsx("div",{style:u==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:A.map(_e=>{if(g)return t.jsx(f.Fragment,{children:g(_e)},_e.id);const Ne=u==="card"?pa:xo;return t.jsx(Ne,{entry:_e,selected:R===_e.id,onClick:Ie,getConfig:ie,query:y},_e.id)})})]},L)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:Yt(h.search.noResultsFor,{query:y})}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:h.search.tryOther})]})})]})},sa=240;function la(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const aa=`
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=`
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
- `,ca=`
4
+ `,ua=`
5
5
  @media (max-width: 719px), (pointer: coarse) {
6
6
  .bim-ib-viewall { position: relative; }
7
7
  .bim-ib-viewall::after {
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
- }`,_r={color:"inherit",textDecoration:"none"},da=({snippet:e})=>{const{convert:n}=Y();return t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.6},children:hr(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))})},pa=({entry:e,selected:n,onClick:i,getConfig:r,query:s})=>{const l=de(),{convert:d}=Y(),p=d(e.title||e.primary_name||e.id),a=e.measure_info?d(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",c=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&c.length?c.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:{..._r,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}),a&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:a})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",d(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:d(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",d(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",d(e.era),"〕"]}),e.edition&&t.jsx("span",{children:d(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[l.search.alias,":",d(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(da,{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:[r(e.type).icon," ",r(e.type).name]}),e.has_text&&t.jsxs("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.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:["🖼️ ",l.misc.imageResource]})]})]})]})},xo=({entry:e,selected:n,onClick:i,getConfig:r,query:s,onRemove:l})=>{const d=de(),{convert:p}=Y(),a=[...e.additional_titles||[],...e.attached_texts||[]],c=s&&a.length?a.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:{..._r,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("span",{style:{fontSize:"16px"},children:r(e.type).icon}),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",{title:d.misc.textResource,children:"📝"}),e.has_image&&t.jsx("span",{title:d.misc.imageResource,children:"🖼️"})]}),(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,d.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??"?"]})]}),c&&t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:[d.search.alias,":",p(c)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:d.search.removeFromRecent,"aria-label":d.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:"×"})]})},ua=({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 xa(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 fa({data:e}){const{convert:n}=Y(),{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 ga({alt_names:e}){const{convert:n}=Y(),i=new Map;for(const l of e){const d=l.type||"別名";i.has(d)||i.set(d,[]),i.get(d).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((l,d)=>{const p=r.indexOf(l),a=r.indexOf(d);return p===-1&&a===-1?0:p===-1?1:a===-1?-1:p-a});return t.jsx("div",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const d=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:d.map((p,a)=>t.jsxs("span",{children:[a>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},a))})]},l)})})}function ma({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 ha({works:e,transport:n,onNavigate:i,renderLink:r}){const s=de(),{convert:l}=Y(),d=Pe(),[p,a]=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 j=await n.getEntriesByIds(m);let _=!0;for(let k=0;k<m.length;k++){const z=j[k];z!=null&&z.title?S.set(m[k],z.title):z!=null&&z.primary_name?S.set(m[k],z.primary_name):_=!1}if(_)return S}catch{}const h=[...m],v=8,y=new Array(v).fill(0).map(async()=>{for(;h.length;){const j=h.shift();if(!j)break;if(!S.has(j))try{if(n.getEntry){const z=await n.getEntry(j);if(z!=null&&z.title){S.set(j,z.title);continue}}const _=await n.getItem(j),k=_&&(_.title||_.primary_name)||j;S.set(j,k)}catch{S.set(j,j)}}});return await Promise.all(y),S})().then(S=>{x||a(S)}),()=>{x=!0}},[e,n]);const c=new Map;for(const x of e){const m=x.role||"";c.has(m)||c.set(m,[]),c.get(m).push(x)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],g=[...c.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=c.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:d(b.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.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 $r=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:l})=>{var g;const d=de(),{convert:p}=Y();let a=!1;try{a=be.extractStatus(e.id)==="draft"}catch{}const c=xa(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(fa,{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:d.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),a&&t.jsx("span",{style:{padding:"1px 6px",background:o("warn-bg"),border:`1px solid ${o("warn-border")}`,borderRadius:"2px",color:o("warn-fg")},children:d.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),c&&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(ga,{alt_names:e.alt_names}),t.jsx(ma,{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(ha,{works:e.works,transport:n,onNavigate:i,renderLink:r})]})},ba=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function ya(e){const n=e.search(ba);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const zr={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===ja(e))){const[l,d]=ya(n);d&&(i=encodeURI(l),s=l,r=d)}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 ja(e){try{return decodeURI(e)}catch{return e}}const va={...zr,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},rt=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:s}=Y(),l=n?va:zr;return t.jsx("div",{className:r,style:i,children:t.jsx(_l,{remarkPlugins:[$l],components:l,children:s(e)})})},ka=["〇","一","二","三","四","五","六","七","八","九"],fo=["","十","百","千"];function Cr(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 d=parseInt(n[l]),p=i-1-l;d===0?s=!0:(s&&r&&(r+="〇"),s=!1,d===1&&p===1&&l===0?r+=fo[p]:r+=ka[d]+fo[p])}return r}function Ir(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 Sa={book:o("type-book"),work:o("type-work"),collection:o("type-collection"),entity:o("type-entity")};function wa({type:e}){const n=de();return t.jsx("span",{style:Ir(Sa[e]),children:n.indexType[e]})}function _a({isDraft:e}){const n=de(),i=o(e?"status-draft":"status-official");return t.jsx("span",{style:Ir(i),children:e?n.status.draft:n.status.official})}function $a({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 Xe({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 Tr({authors:e,type:n,onNavigate:i,renderLink:r}){const{convert:s}=Y();return t.jsx("span",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.6},children:e.map((l,d)=>{const p=s(l.name),a=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:[d>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),"〕"]}),a,l.role&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},d)})})}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 za({id:e,title:n,edition:i,type:r,isDraft:s,authors:l,volumeText:d,meta:p,headerExtra:a,onNavigate:c,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}),d&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:d})]}),a&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(wa,{type:r}),t.jsx(_a,{isDraft:s}),t.jsx($a,{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(Tr,{authors:l,type:r,onNavigate:c,renderLink:u}),p]})]})}function Er({items:e,label:n,showMeta:i,onNavigate:r,renderLink:s}){const l=de(),{convert:d}=Y();if(!e.length)return null;const[p,a]=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((c,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:()=>a(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:d(c.source)}),!g&&i&&c.title_info&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d(c.title_info)}),c.source_bid&&t.jsx("span",{onClick:x=>x.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Ke,{id:c.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&&(c.title_info||c.author_info||c.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[c.title_info&&t.jsx(Xe,{label:l.label.titleInfo,children:d(c.title_info)}),c.author_info&&t.jsx(Xe,{label:l.label.authorInfo,children:d(c.author_info)}),c.edition&&t.jsx(Xe,{label:l.label.edition,children:d(c.edition)})]}),c.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:d(c.summary)})]}),c.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:d(c.comment)})]}),c.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:d(c.additional_comment)})]})]})]},u)})})]})}function Ca({items:e,onNavigate:n,renderLink:i}){const r=de();return t.jsx(Er,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Rr({items:e,onNavigate:n,renderLink:i}){const r=de();return t.jsx(Er,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function Nr({label:e,items:n}){const{convert:i}=Y();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 Ia({items:e}){const n=de();return t.jsx(Nr,{label:n.section.aliases,items:e})}function Ta({items:e}){const n=de();return t.jsx(Nr,{label:n.section.attachedTexts,items:e})}function Ea({items:e}){const n=de(),{convert:i}=Y();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 Ra({items:e}){const n=de(),{convert:i}=Y();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 Na({items:e}){const n=de(),{convert:i}=Y();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 go({title:e,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:l}=Y(),[d,p]=f.useState([]);return f.useEffect(()=>{if(!n.length){p([]);return}if(!i){p(n.map(c=>({id:c})));return}let a=!1;return Promise.all(n.map(c=>i.getItem(c).then(u=>({id:c,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:c})))).then(c=>{a||p(c)}),()=>{a=!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:(d.length?d:n.map(a=>({id:a}))).map(a=>{const c=a.edition?`${l(a.title)||a.id}(${l(a.edition)})`:l(a.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:a.id,label:c,onNavigate:r,renderLink:s})},a.id)})})]}):null}function En({book:e,onNavigate:n,renderLink:i}){const r=de(),{convert:s}=Y(),[l,d]=f.useState(!1),p=e.resources&&e.resources.length>0,a=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:a,onNavigate:n,renderLink:i})}),p&&t.jsx("span",{onClick:()=>d(c=>!c),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(ui,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function La({ids:e,workData:n,transport:i,onNavigate:r,renderLink:s,footer:l}){const d=de(),{convert:p}=Y(),[a,c]=f.useState([]);if(f.useEffect(()=>{if(!e.length){c([]);return}if(!i){c(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||c(S)}),()=>{b=!0}},[e,i]),!e.length)return null;const u=a.length?a:e.map(b=>({id:b})),g=new Map(u.map(b=>[b.id,b])),x=n==null?void 0:n.version_graph,m=Ba(e,x);return t.jsxs(t.Fragment,{children:[t.jsxs(Ve,{children:[d.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(En,{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(En,{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(En,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Ba(e,n){var h,v;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,d=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&d.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...d]),c=y=>{if(a.has(y))return!0;const j=n.node_groups[y];return j!=null&&p.has(j)},u=[],g=new Map,x=[];for(const y of e)if(!((v=n.excluded_books)!=null&&v.includes(y)))if(c(y))u.push(y);else{const j=n.node_groups[y];j?(g.has(j)||g.set(j,[]),g.get(j).push(y)):x.push(y)}if(x.length+[...g.values()].reduce((y,j)=>y+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(y=>[y.id,y])),S=[...g.entries()].map(([y,j])=>{const _=b.get(y);return{id:y,label:(_==null?void 0:_.label)??y,description:_==null?void 0:_.description,ids:j}});return x.length>0&&S.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:S}}function Aa({workData:e,onNavigate:n,renderLink:i}){var d,p,a,c;const r=de(),{convert:s}=Y(),l=!!((d=e.description)!=null&&d.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:[Cr(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(Tr,{authors:e.authors,type:"work",onNavigate:n,renderLink:i})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((a=e.description)==null?void 0:a.text)&&t.jsx(rt,{text:e.description.text,style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(c=e.description)!=null&&c.text?"8px":0,fontSize:"13px"},children:t.jsx(Xe,{label:r.label.parentWork,children:t.jsx(Ke,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Wa({items:e,onNavigate:n,renderLink:i}){const r=de(),{convert:s}=Y();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:Yt(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const xi=({data:e,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:d,className:p,style:a})=>{var O,M,W,P,V,K,N,le;const c=de(),{convert:u}=Y(),[g,x]=f.useState(null),[m,b]=f.useState(!1),[S,h]=f.useState(null),[v,y]=f.useState(null),[j,_]=f.useState([]),k=e||g;if(f.useEffect(()=>{if(e||!n||!i)return;let G=!1;return b(!0),h(null),i.getItem(n).then(se=>{G||(se?x(se):h(c.misc.notFoundEntry))}).catch(se=>{G||h(se instanceof Error?se.message:c.misc.loadFailed)}).finally(()=>{G||b(!1)}),()=>{G=!0}},[e,n,i]),f.useEffect(()=>{if(!k||!i){y(null),_([]);return}let G=!1;const se=k.type==="book"||k.type==="collection"?k.work_id:void 0;if(se?i.getItem(se).then(ne=>{!G&&ne&&ne.type==="work"&&y(ne)}).catch(()=>{}):y(null),k.type==="book"){const ne=k;ne.contained_in&&ne.contained_in.length>0?Promise.all(ne.contained_in.map(Q=>{const H=typeof Q=="string"?Q:Q.id,te=typeof Q=="string"?void 0:Q.volume_index;return i.getItem(H).then(pe=>({id:H,title:pe&&pe.title||H,volume_index:te})).catch(()=>({id:H,title:H,volume_index:te}))})).then(Q=>{G||_(Q)}):_([])}else _([]);return()=>{G=!0}},[k,i]),m)return t.jsx("div",{className:p,style:{...a,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((G,se)=>t.jsx("div",{style:{height:se===1?"32px":"16px",width:`${G}px`,background:o("widget-border"),borderRadius:"4px",opacity:.4}},se))})});if(S)return t.jsx("div",{className:p,style:{...a,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:S});if(!k)return null;if(k.type==="entity")return t.jsx("div",{className:p,style:a,children:t.jsx($r,{data:k,transport:i,onNavigate:r,renderLink:s,headerExtra:l})});const z=k.type==="book"?k:null,w=k.type==="collection"?k:null,C=k.type==="work"?k:null;let E=!1;try{E=be.extractStatus(k.id)==="draft"}catch{}let R="";k.measure_info?R=u(k.measure_info):(O=k.juan_count)!=null&&O.number?R=Cr(k.juan_count.number)+c.unit.juan:(M=k.juan_count)!=null&&M.description&&(R=u(k.juan_count.description));const T=[];return(W=k.publication_info)!=null&&W.year&&T.push(t.jsx(Xe,{label:c.label.year,children:k.publication_info.year},"year")),(P=k.current_location)!=null&&P.name&&T.push(t.jsx(Xe,{label:c.label.currentLocation,children:u(k.current_location.name)},"loc")),(V=k.page_count)!=null&&V.description&&T.push(t.jsx(Xe,{label:c.label.pageCount,children:k.page_count.description},"page")),z!=null&&z.edition&&T.push(t.jsx(Xe,{label:c.label.edition,children:u(z.edition)},"ver")),C!=null&&C.parent_work&&T.push(t.jsx(Xe,{label:c.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&&T.push(t.jsx(Xe,{label:c.label.parentWork,children:C.parent_works.map((G,se)=>t.jsxs("span",{children:[se>0&&"、",t.jsx(Ke,{id:G,onNavigate:r,renderLink:s})]},G))},"pws")),t.jsxs("div",{className:p,style:a,children:[t.jsx(za,{id:k.id,title:u(k.title),edition:k.edition?u(k.edition):void 0,type:k.type,isDraft:E,authors:k.authors,volumeText:R,meta:T,headerExtra:l,onNavigate:r,renderLink:s}),((K=k.description)==null?void 0:K.text)&&t.jsx(rt,{text:k.description.text,style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),k.appendix&&k.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:k.appendix.map((G,se)=>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(rt,{text:G.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:o("fg")}})]},se))}),j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:c.section.containedIn}),t.jsx(Wa,{items:j,onNavigate:r,renderLink:s})]}),v&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:c.section.belongsToWork}),t.jsx(Aa,{workData:v,onNavigate:r,renderLink:s})]}),k.additional_works&&k.additional_works.length>0&&t.jsx(Ea,{items:k.additional_works}),k.additional_titles&&k.additional_titles.length>0&&t.jsx(Ia,{items:k.additional_titles}),k.attached_texts&&k.attached_texts.length>0&&t.jsx(Ta,{items:k.attached_texts}),k.indexed_by&&k.indexed_by.length>0&&t.jsx(Ca,{items:k.indexed_by,onNavigate:r,renderLink:s}),k.emendated_by&&k.emendated_by.length>0&&t.jsx(Rr,{items:k.emendated_by,onNavigate:r,renderLink:s}),k.resources&&k.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:c.section.resources}),t.jsx(ui,{items:k.resources,resourceGroups:k.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(z==null?void 0:z.location_history)&&z.location_history.length>0&&t.jsx(Ra,{items:z.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&t.jsx(Na,{items:w.history}),(z==null?void 0:z.related_books)&&z.related_books.length>0&&t.jsx(go,{title:c.section.relatedVersions,ids:z.related_books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.books)&&w.books.length>0&&t.jsx(go,{title:c.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:[c.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))})]}),(((N=C==null?void 0:C.books)==null?void 0:N.length)||0)+(((le=C==null?void 0:C.collections)==null?void 0:le.length)||0)>0&&t.jsx(La,{ids:[...(C==null?void 0:C.books)||[],...(C==null?void 0:C.collections)||[]],workData:C??void 0,transport:i,onNavigate:r,renderLink:s,footer:d}),(C==null?void 0:C.related_works)&&C.related_works.length>0&&(()=>{const G=[],se=C.related_works.filter(re=>re.relation==="part_of"),ne=C.related_works.filter(re=>re.relation==="has_part"),Q=C.related_works.filter(re=>re.relation==="has_adaptation"),H=C.related_works.filter(re=>re.relation==="text_carried_by"),te=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),pe=C.related_works.filter(re=>!re.relation||!te.has(re.relation));return se.length>0&&G.push({label:c.section.belongsToWork,items:se}),ne.length>0&&G.push({label:c.section.containedWorks,items:ne}),Q.length>0&&G.push({label:c.section.adaptations,items:Q}),H.length>0&&G.push({label:c.section.derivativeWorks,items:H}),pe.length>0&&G.push({label:c.section.relatedWorks,items:pe}),G.map(re=>t.jsxs("div",{children:[t.jsxs(Ve,{children:[re.label,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",re.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:re.items.map(ee=>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:ee.id,label:u(ee.title),onNavigate:r,renderLink:s})},ee.id))})]},re.label))})()]})};function Ma({data:e}){const n=de(),{convert:i}=Y(),{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 Fa({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:mo(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:mo(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 mo(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 Pa({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 Oa(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 ho({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const s=de(),{convert:l}=Y(),d=e.book_id||e.work_id,p=r&&e.volumes.length>0?Oa(e.volumes,s.unit.volume):null,a=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(c=>l(c)).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(a?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),d&&t.jsx(Pa,{id:d,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!d&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const fi=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:l,style:d})=>{const p=de(),[a,c]=f.useState(null),[u,g]=f.useState(!1),[x,m]=f.useState(null),[b,S]=f.useState(null),[h,v]=f.useState(""),y=e||a;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?c(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 j=(y==null?void 0:y.sections)&&y.sections.length>0,_=f.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const w=y.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(w).size<w.length},[y]),k=f.useMemo(()=>{if(!y)return[];let w=y.books;if(b&&(w=w.filter(C=>C.section===b)),h.trim()){const C=h.trim().toLowerCase();w=w.filter(E=>E.title.toLowerCase().includes(C)||E.sub_items&&E.sub_items.some(R=>R.toLowerCase().includes(C))||E.edition&&E.edition.toLowerCase().includes(C))}return w},[y,b,h]),z=f.useMemo(()=>{if(!_)return null;const w=[],C=new Map;for(const R of k){if(!R.volumes||R.volumes.length===0)continue;const T=R.volumes[0];C.has(T)||C.set(T,[]),C.get(T).push(R)}const E=[...C.keys()].sort((R,T)=>R-T);for(const R of E)w.push({volume:R,books:C.get(R)});return w},[k,_]);return u?t.jsx("div",{className:l,style:{...d,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):x?t.jsx("div",{className:l,style:{...d,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:x}):y?t.jsxs("div",{className:l,style:d,children:[t.jsx(Ma,{data:y}),j&&t.jsx(Fa,{sections:y.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=>v(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:[k.length," ",p.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[z?z.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:Yt(p.catalog.volume,{n:w.volume})}),w.books.map((E,R)=>t.jsx(ho,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${w.volume}-${R}`))]},`${w.volume}-${C}`)):k.map((w,C)=>t.jsx(ho,{book:w,onNavigate:r,renderLink:s,showVolumes:!0},C)),k.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},yt=()=>{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)})},Lr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Da={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Me(e){return Da[e]??e}const zt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],Ct={熹平: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},Br={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function bn(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 Ha(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 Ga=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,bo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function gi(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(bo))if(n.startsWith(s))return bo[s];const i=Me(n);if(ft[i]!=null)return i;const r=ot(n);if(r&&n.length<=r.length+1)return Me(r)}function xt(e,n){if(n){const i=Br[`${n}|${e}`];if(i!=null)return i}return Ct[e]}const Ua=1911;function Va(e){const n=Ct[e];if(n==null)return;const i=Qe[e];let r;for(const[s,l]of Object.entries(Ct))Qe[s]===i&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const Ya={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function un(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 d=Ya[l];if(d===void 0)return;r=!0,l==="十"?i=(i||1)*10:l==="廿"||l==="卅"?(n+=d,i=0):i>=10?(n+=i+d,i=0):i=i*10+d}const s=n+i;return r&&s>0?s:void 0}function ot(e){for(const n of Lr)if(e.startsWith(n))return n}const Qe={};{const e=(n,i)=>{for(const r of i)Qe[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function gt(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(Ct))if(e.includes(r)&&!(i&&Qe[r]&&Qe[r]!==i&&Br[`${i}|${r}`]==null))return r}function Kt(e){var d,p,a;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=(d=e.lineage)==null?void 0:d.year_text;if(r){const c=ot(r)??"";return{era:Me(c),reign:gt(r,c)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const c=bn(s);if(c)return{era:Ha(c.from),reign:"",source:"publication"};const u=ot(s)??gi(s)??((a=zt.find(m=>m.pattern.test(s)))==null?void 0:a.era)??"",g=gt(s,u)??"",x=u||(g?Qe[g]??"":"");if(x||g)return{era:Me(x),reign:g,source:"publication"}}const l=e.edition||e.title||"";if(l){const c=ot(l);if(c)return{era:Me(c),reign:gt(l,c)??"",source:"edition"};const u=zt.find(g=>g.pattern.test(l));if(u)return{era:Me(u.era),reign:gt(l,u.era)??u.reign??"",source:"edition"}}return n}function yn(e){var r,s,l,d,p,a,c,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=bn(n);if(x)return x.from}const i=[(d=e.lineage)==null?void 0:d.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=((a=e.publication_info)==null?void 0:a.year)||((c=e.lineage)==null?void 0:c.year_text);if(m&&x!==m&&(ot(m)||gi(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 j=parseInt(b[1],10);if(j>=100&&j<=2100)return j}const S=x.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(S){const j=ot(x);if(!j||Me(j)==="民國"){const k=un(S[1]);if(k!=null&&k>=1&&k<=120)return Ua+k}}const h=ot(x)??((u=zt.find(j=>j.pattern.test(x)))==null?void 0:u.era),v=h?Me(h):void 0,y=gt(x,v)??(ot(x)||(g=zt.find(j=>j.pattern.test(x)))==null?void 0:g.reign);if(y){const j=xt(y,v);if(j==null)continue;const _=x.indexOf(y),k=_>=0?x.slice(_+y.length):"",z=k.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??k.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),w=z?un(z[1]):void 0;return j+(w?w-1:0)}}}function mi(e){var d,p,a,c,u,g;const n=(d=e.dating)==null?void 0:d.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=(a=e.lineage)==null?void 0:a.year_text;if(r){const x=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(x){const m=Un[Me(x[1])],b=ft[Me(x[2])];if(m!=null&&b!=null)return{from:Math.min(m,b)-20,to:Math.max(m,b)+40}}}const s=(c=e.publication_info)==null?void 0:c.year;if(s){const x=bn(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=Un[Me(m[1])],S=ft[Me(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=ot(x)??gi(x)??((g=zt.find(h=>h.pattern.test(x)))==null?void 0:g.era),b=m?Me(m):void 0,S=[];for(const h of Object.keys(Ct))x.includes(h)&&(b&&Qe[h]&&Qe[h]!==b||xt(h,b)!=null&&S.push(h));if(S.length===0){const h=x.match(/([一-鿿])([一-鿿])[間间]/);if(h&&b){for(const v of[h[1],h[2]])for(const y of Object.keys(Ct))if(Qe[y]===b&&!(y[0]!==v&&y[y.length-1]!==v)&&xt(y,b)!=null){S.push(y);break}}}if(S.length>0){const h=S.map(_=>xt(_,b)).filter(_=>_!=null),v=Math.min(...h),y=S.reduce((_,k)=>xt(_,b)>=xt(k,b)?_:k),j=Va(y)??Rn(b??"")??Math.max(...h);return{from:v,to:j>v?j:Rn(b??Qe[y]??"")??v}}if(b&&ft[b]!=null)return{from:ft[b],to:Rn(b)??ft[b]}}}const ft={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Ka=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],qa=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,yo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function jo(e,n){for(const i of Lr){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const a=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(a)&&!gt(e.slice(r),Me(i)))continue}const s=Me(i);if(s===n)continue;const l=e.slice(r),d=gt(l,s)??"";let p;if(d){const a=xt(d,s);if(a!=null){const u=l.slice(l.indexOf(d)+d.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),g=u?un(u[1]):void 0;p=a+(g?g-1:0)}}return{era:s,reign:d,year:p}}for(const i of zt)if(i.pattern.test(e))return{era:Me(i.era),reign:i.reign??""}}function Ja(e){var v,y,j,_,k;const n=Kt(e),i=((v=e.publication_info)==null?void 0:v.year)??"",r=i?bn(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),d=((y=e.lineage)==null?void 0:y.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(d),a=n.source==="publication"&&Ga.test(i),c=n.source==="publication"&&/[間间]/.test(i),u=d.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let g;l||p||a||c?g=void 0:u?g=parseInt(u[2],10):g=yn(e);const x=g==null?mi(e):void 0;let m;n.source==="publication"&&(a||yo.test(i))?m="uncertain":n.source==="lineage"||n.source==="publication"?m="attested":yo.test(s)||!n.reign&&g==null?m="uncertain":m="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((j=e.lineage)==null?void 0:j.year_text)??((_=e.lineage)==null?void 0:_.year)??""}」`:`出版著錄「${((k=e.publication_info)==null?void 0:k.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 z=d.match(/[、,,]\s*([宋元明清])/);z&&z[1]!==S.era&&(S.laterRepair={era:z[1]})}if(!S.laterRepair&&qa.test(s)){const z=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);z&&z[1]!==n.era&&(S.laterRepair={era:z[1]})}const h=Ka.find(z=>z.re.test(s));if(h){const z=s.search(h.re),w=s.slice(z),C=jo(w,n.era)??jo(s,n.era);C&&(S.basedOn={era:C.era,reign:C.reign,year:C.year,relation:h.relation})}return S}const Un={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Rn(e){return Un[e]}function xn(e){const n=yn(e);if(n!=null)return n;const i=mi(e);if(i)return i.from;const r=Kt(e).era;return r?ft[r]:void 0}const vo=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Vn(e){const n=vo.indexOf(e);return n===-1?vo.length:n}function Za(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 hi(e,n){const i=ci(e||[]),r=new Map,s=[];for(const c of i)c.group?(r.has(c.group)||r.set(c.group,[]),r.get(c.group).push(c)):s.push(c);for(const c of r.values())c.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 c of s){const u=bt(c),g=u.includes("text"),x=u.includes("image");g&&x?l.textImage.push(c):g?l.text.push(c):x?l.image.push(c):l.physical.push(c)}const p=["text","image","textImage","physical"].filter(c=>l[c].length>0).map(c=>({key:c,items:l[c]})),a=[...r.entries()].map(([c,u])=>{var g,x;return{key:c,label:((g=n==null?void 0:n[c])==null?void 0:g.label)||c,description:(x=n==null?void 0:n[c])==null?void 0:x.description,items:u}});return{buckets:p,mirrors:a,total:i.length}}function jn(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=mn(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 Ar(e,n){if(jn(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 Wr(e,n){var l,d;const i=e.resources||[],r=[],s=[];for(const p of i){const a=bt(p);a.includes("image")&&r.push(p),a.includes("physical")&&s.push(p)}return{id:e.id,name:e.edition||e.title||e.id,era:Kt(e),year:yn(e),sortYear:xn(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:Xa(e.id,n),group:(d=n==null?void 0:n.node_groups)==null?void 0:d[e.id],hasImage:r.length>0}}function Xa(e,n){var p,a;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)??[],d=(a=n.node_groups)==null?void 0:a[e];return!!d&&l.includes(d)}function Mr(e,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(a=>!r.has(a.id)).map(a=>Wr(a,n));let l=s;i.era&&(l=l.filter(a=>a.era.era===i.era)),i.scanOnly&&(l=l.filter(a=>a.hasImage)),i.sort==="year"?l=l.map((a,c)=>({r:a,i:c})).sort((a,c)=>{const u=a.r.sortYear,g=c.r.sortYear;return u!=null&&g!=null?u-g||a.i-c.i:u!=null?-1:g!=null?1:a.i-c.i}).map(a=>a.r):l=l.map((a,c)=>({r:a,i:c})).sort((a,c)=>{const u=g=>(g.important?0:1)*2+(g.hasImage?0:1);return u(a.r)-u(c.r)||a.i-c.i}).map(a=>a.r);const p=[...new Set(s.map(a=>a.era.era).filter(Boolean))].sort((a,c)=>Vn(a)-Vn(c));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(a=>a.era.source==="edition")}}function Qa(e,n){var h,v;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,d=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&d.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...d]),c=y=>{if(a.has(y))return!0;const j=n.node_groups[y];return j!=null&&p.has(j)},u=[],g=new Map,x=[];for(const y of e)if(!((v=n.excluded_books)!=null&&v.includes(y)))if(c(y))u.push(y);else{const j=n.node_groups[y];j?(g.has(j)||g.set(j,[]),g.get(j).push(y)):x.push(y)}if(x.length+[...g.values()].reduce((y,j)=>y+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(y=>[y.id,y])),S=[...g.entries()].map(([y,j])=>{const _=b.get(y);return{id:y,label:(_==null?void 0:_.label)??y,description:_==null?void 0:_.description,ids:j}});return x.length>0&&S.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:S}}const Fr=["撰","編","注","校","譯","繪","其他"],ec=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function bi(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of ec)if(r.test(n))return i;return"其他"}function yi(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Pr(e){const n=new Map;for(const r of e){const s=bi(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:e.length}];for(const r of Fr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function Or(e,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(d=>({id:d.work_id||d.book_id||void 0,title:d.title,section:d.section,volumes:d.volumes||[],subItems:d.sub_items,edition:d.edition,found:d.found_volumes,expected:d.expected_volumes})),l=[...new Set(s.map(d=>d.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:Ht(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,d;return{id:s,title:((l=i==null?void 0:i.get(s))==null?void 0:l.title)||s,edition:(d=i==null?void 0:i.get(s))==null?void 0:d.edition,volumes:[]}}),source:"books",sections:[]}}function Ht(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 vn(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((l,d)=>l-d),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 tc=["〇","一","二","三","四","五","六","七","八","九"],ko=["","十","百","千"];function Dr(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 d=parseInt(n[l]),p=i-1-l;d===0?s=!0:(s&&r&&(r+="〇"),s=!1,d===1&&p===1&&l===0?r+=ko[p]:r+=tc[d]+ko[p])}return r}function nc(e){return e==null?"":typeof e=="string"?e:e.title??""}function st(e,n="卷"){var r,s;const i=e;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?Dr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Hr(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 ic="guji_markdown";function Yn(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 oc=/^□\{guess=([^\s{}]+)\}/;function rc(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function Gr(e,n){let i=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
12
- `)return-1;if(s==="\\"){r++;continue}if(s==="[")i++;else if(s==="]"&&(i--,i===0))return r}return-1}function sc(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function lc(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=Gr(e,n+3);return r>n+4?{node:{type:"zi",label:sc(e.slice(n+4,r))},end:r+1}:null}if(i==="□"&&e[n+1]==="{"){const r=oc.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function Ur(e,n,i,r){const s=[];let l="";const d=()=>{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 d(),{nodes:s,end:n};if(p===`
14
- `)return null}const a=lc(e,n);if(a){d(),s.push(a.node),n=a.end;continue}let c=null;if(p==="⟨"?c="⟩":p==="<"&&rc(e,n)&&(c=">"),c){const u=Ur(e,n+1,c,!0);if(u){d(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return i!==null?null:(d(),{nodes:s,end:n})}function Vr(e){return Ur(e,0,null,!1).nodes}function ac(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function Yr(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Yr(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const cc=216,So="clamp(280px, 23vw, 360px)",dc=1440,Kr="(max-width: 719px)",pc=`${Kr}, (pointer: coarse)`,uc=`
15
- .bim-d-main.bim-d-main-grid { max-width: ${dc}px; padding: 16px 32px 0; }
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&&gt[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===`
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 Kr(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=Kr(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 qr(e){return Kr(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
+ .bim-d-main.bim-d-main-grid { max-width: ${xc}px; padding: 16px 32px 0; }
16
16
  .bim-d-grid {
17
17
  display: grid;
18
- grid-template-columns: ${cc}px minmax(0, 1fr) ${So};
18
+ grid-template-columns: ${uc}px minmax(0, 1fr) ${$o};
19
19
  grid-template-rows: auto 1fr;
20
20
  grid-template-areas: "rail main card" "rail main side";
21
21
  column-gap: 32px; row-gap: 28px; align-items: start;
@@ -238,6 +238,60 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
238
238
  .bim-d-side-sub { margin: -2px 0 6px; font-size: 12px; color: ${o("aux-fg")}; }
239
239
  .bim-d-side li .bim-d-kind { padding: 0 6px; border-radius: 3px; background: ${o("zebra-bg")}; line-height: 18px; }
240
240
 
241
+ /* 提要卡:版本类型/年代/卷帙 三个标签 */
242
+ .bim-d-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
243
+ .bim-d-tag { padding: 1px 8px; border-radius: 3px; font-size: 12px; line-height: 20px; color: ${o("quiet-fg")};
244
+ background: ${o("zebra-bg")}; }
245
+ .bim-d-tag-0 { background: ${o("flag-bg")}; color: ${o("accent")}; }
246
+ .bim-d-tag-2 { background: none; box-shadow: inset 0 0 0 1px ${o("rule")}; }
247
+
248
+ /* 分段切换(卡片/关系图) */
249
+ .bim-d-seg { display: inline-flex; border-radius: 6px; box-shadow: inset 0 0 0 1px ${o("rule")}; overflow: hidden; }
250
+ .bim-d-seg button { min-height: 28px; padding: 0 12px; border: 0; background: none; cursor: pointer; font: inherit;
251
+ font-size: 13px; color: ${o("quiet-fg")}; }
252
+ .bim-d-seg button[aria-pressed="true"] { background: ${o("flag-bg")}; color: ${o("accent")}; font-weight: 700; }
253
+
254
+ /* 版本源流·卡片流 */
255
+ .bim-d-lf-list { list-style: none; margin: 0; padding: 0 0 0 22px; position: relative; }
256
+ .bim-d-lf-list::before { content: ""; position: absolute; left: 4px; top: 12px; bottom: 12px; width: 1px; background: ${o("rule")}; }
257
+ .bim-d-lf-node { position: relative; padding: 6px 0; }
258
+ .bim-d-lf-node::before { content: ""; position: absolute; left: -22px; top: 22px; width: 9px; height: 9px; border-radius: 50%;
259
+ box-sizing: border-box; background: ${o("page-bg")}; border: 1px solid ${o("aux-fg")}; }
260
+ .bim-d-lf-cur::before { background: ${o("accent")}; border-color: ${o("accent")}; }
261
+ .bim-d-lf-out::before { top: 16px; }
262
+ .bim-d-lf-card, .bim-d-lf-dash { padding: 12px 16px; border-radius: 8px; min-width: 0; }
263
+ .bim-d-lf-card { background: ${o("card-bg")}; box-shadow: inset 0 0 0 1px ${o("rule")}; }
264
+ .bim-d-lf-dash { box-shadow: inset 0 0 0 1px ${o("rule-dashed")}; }
265
+ .bim-d-lf-tag { display: inline-block; margin-right: 10px; padding: 0 7px; border-radius: 3px; font-size: 12px; line-height: 20px;
266
+ background: ${o("zebra-bg")}; color: ${o("quiet-fg")}; }
267
+ .bim-d-lf-name { font-weight: 700; color: ${o("ink")}; }
268
+ .bim-d-lf-ev { margin: 6px 0 0; font-size: 13px; line-height: 1.8; color: ${o("quiet-fg")}; }
269
+ .bim-d-lf-cur { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
270
+ .bim-d-lf-here { padding: 12px 16px; border-radius: 8px; background: ${o("accent")}; color: ${o("on-color-fg")}; min-width: 0; }
271
+ .bim-d-lf-here .bim-d-lf-name { color: ${o("on-color-fg")}; }
272
+ .bim-d-lf-here .bim-d-lf-tag { background: color-mix(in srgb, ${o("on-color-fg")} 18%, transparent); color: ${o("on-color-fg")}; }
273
+ .bim-d-lf-yr { display: block; margin-top: 4px; font-size: 13px; opacity: .9; }
274
+ .bim-d-lf-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
275
+ .bim-d-lf-out { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
276
+ .bim-d-lf-out-h { font-size: 12px; letter-spacing: .1em; color: ${o("aux-fg")}; }
277
+ .bim-d-lf-chips { display: flex; flex-wrap: wrap; gap: 8px; }
278
+ .bim-d-lf-chip { display: inline-flex; align-items: baseline; gap: 6px; padding: 3px 10px; border-radius: 6px;
279
+ box-shadow: inset 0 0 0 1px ${o("rule")}; font-size: 14px; }
280
+ .bim-d-lf-app { margin-top: 10px; font-size: 14px; }
281
+ .bim-d-lf-app summary { cursor: pointer; min-height: 28px; display: inline-flex; align-items: center; gap: 6px; color: ${o("accent")}; }
282
+
283
+ /* 影印分组:一组一张卡 */
284
+ .bim-d-rg { padding: 14px 16px 10px; border-radius: 10px; background: ${o("card-bg")}; box-shadow: inset 0 0 0 1px ${o("rule")}; }
285
+ .bim-d-rg .bim-d-zt tbody tr:nth-child(odd) td { background: none; }
286
+
287
+ /* 旁栏:时间轴点(同作品版本) */
288
+ .bim-d-side-tl ul { position: relative; padding-left: 16px; }
289
+ .bim-d-side-tl ul::before { content: ""; position: absolute; left: 3px; top: 12px; bottom: 12px; width: 1px; background: ${o("rule")}; }
290
+ .bim-d-side-tl li { position: relative; }
291
+ .bim-d-side-tl li::before { content: ""; position: absolute; left: -16px; top: 14px; width: 7px; height: 7px; border-radius: 50%;
292
+ box-sizing: border-box; background: ${o("page-bg")}; border: 1px solid ${o("aux-fg")}; }
293
+ .bim-d-side-tl li.bim-d-side-cur::before { background: ${o("accent")}; border-color: ${o("accent")}; }
294
+
241
295
  /* 本页内检索(丛编子目) */
242
296
  .bim-d-find { height: 30px; min-width: 190px; padding: 0 12px; border: 0; border-radius: 6px; box-sizing: border-box;
243
297
  background: ${o("tint-bg")}; color: ${o("ink")}; font: inherit; font-size: 13px; }
@@ -265,8 +319,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
265
319
  text-decoration: none !important;
266
320
  }
267
321
  .bim-d-btn:hover { background: ${o("accent-deep")}; }
268
- .bim-d-card-alt { display: flex; align-items: center; justify-content: center; min-height: 32px; margin-top: 8px;
269
- font-size: 13px; color: ${o("accent")} !important; }
322
+ .bim-d-card-alt { display: flex; align-items: center; justify-content: center; min-height: 40px; margin-top: 8px;
323
+ border-radius: 6px; background: ${o("flag-bg")}; font-size: 14px; color: ${o("accent")} !important; }
324
+ .bim-d-card-alt:hover { text-decoration: none !important; background: ${o("tint-bg")}; }
270
325
 
271
326
  /* 旁栏清单:小标题是 h2(提要卡 h1 之下不跳级,INT Q5),外观仍是 15px 小标题 */
272
327
  .bim-d-side h3, .bim-d-side .bim-d-side-h { margin: 0 0 6px; font-size: 15px; font-weight: 700; color: ${o("ink")};
@@ -279,7 +334,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
279
334
  .bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
280
335
 
281
336
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
282
- @media ${pc} {
337
+ @media ${fc} {
283
338
  .bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
284
339
  .bim-d-card-foot summary, .bim-d-card-toggle, .bim-d-card details.bim-d-more-names summary,
285
340
  .bim-d-tl summary, .bim-d-chap a { min-height: 44px; }
@@ -317,7 +372,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
317
372
  /* 中等宽度:左栏折到顶部一行 */
318
373
  @media (max-width: 1100px) {
319
374
  .bim-d-grid {
320
- grid-template-columns: minmax(0, 1fr) ${So};
375
+ grid-template-columns: minmax(0, 1fr) ${$o};
321
376
  grid-template-rows: auto auto 1fr;
322
377
  grid-template-areas: "rail rail" "main card" "main side";
323
378
  }
@@ -331,7 +386,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
331
386
  }
332
387
 
333
388
  /* 手机:左栏收起,提要卡 → 正文 → 旁栏 */
334
- @media ${Kr} {
389
+ @media ${Zr} {
335
390
  .bim-d-main.bim-d-main-grid { padding: 8px 16px 0; }
336
391
  .bim-d-grid {
337
392
  grid-template-columns: minmax(0, 1fr);
@@ -362,6 +417,8 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
362
417
  .bim-d-up { display: inline-flex; gap: 8px; align-items: baseline; margin-top: 10px; padding: 6px 12px; }
363
418
  .bim-d-up a { font-size: 14px; }
364
419
  .bim-d-ft { grid-template-columns: minmax(0, 1fr); }
420
+ .bim-d-lf-cur { grid-template-columns: minmax(0, 1fr); }
421
+ .bim-d-seg button { min-height: 44px; }
365
422
  .bim-d-ft-go { grid-column: 1; grid-row: auto; margin-top: 6px; }
366
423
  .bim-d-chap { grid-template-columns: 1fr 1fr; }
367
424
  .bim-d-chap-pending { height: 270px; }
@@ -370,7 +427,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
370
427
  .bim-d-pick-n { margin: 0; grid-column: 2; grid-row: 1 / span 2; }
371
428
  .bim-d-find { flex-basis: 100%; min-height: 40px; }
372
429
  }
373
- `;function qt({railTop:e,back:n,up:i,nav:r,railLinks:s,main:l,card:d,side:p}){const{convert:a}=Y(),c=(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,c.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":a("本頁導航"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:a("本頁")}),t.jsx("ul",{className:"bim-d-rail-nav",children:c.map(u=>t.jsx("li",{children:t.jsxs("a",{href:`#${u.id}`,children:[t.jsx("span",{children:a(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":a("更多"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:a("更多")}),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:a(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:d}),t.jsx("div",{className:"bim-d-g-side",children:p})]})}function qr({caption:e,children:n}){const{convert:i}=Y();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}=Y();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 Be({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 kn({items:e,value:n,onChange:i}){const{convert:r}=Y();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 Jr({label:e,checked:n,onChange:i}){const{convert:r}=Y();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 Nt({label:e,onClick:n}){const{convert:i}=Y();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:i(e)})}function Jt({kind:e,title:n,subtitle:i,byline:r,meta:s,description:l,clampDescription:d,facts:p,stats:a,readAction:c,secondaryAction:u,children:g,foot:x}){const{convert:m}=Y(),b=(p||[]).filter(j=>j.value!=null&&j.value!==""),S=(a||[]).filter(j=>j.value!=null&&j.value!==""&&j.value!==0),[h,v]=f.useState(!1),y=!!d&&!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:y?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:y?{"--detail-clamp":d}:void 0,children:l}),l&&!!d&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":h,onClick:()=>v(j=>!j),children:m(h?"收起":"展開")}),S.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:S.map((j,_)=>t.jsxs("div",{children:[t.jsx("b",{children:j.value}),t.jsx("span",{children:m(j.label)})]},_))}),b.length>0&&t.jsx("dl",{className:"bim-d-ui",children:b.map((j,_)=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:m(j.label)}),t.jsx("dd",{title:j.title,children:j.value})]},_))}),g,c,u,x&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:x})]})}function ji(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function Kn({href:e,onClick:n,label:i="閱讀全文"}){const{convert:r}=Y();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 mt({id:e,title:n,meta:i,items:r,metas:s,currentIndex:l,cap:d=8,moreLabel:p,foot:a,sub:c}){const{convert:u}=Y(),[g,x]=f.useState(!1);if(!r.length)return null;const m=g?r:r.slice(0,d),b=r.length-m.length;return t.jsxs("div",{id:e,className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[u(n),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i})]}),c&&t.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:c}),t.jsx("ul",{children:m.map((S,h)=>t.jsxs("li",{className:h===l?"bim-d-side-cur":void 0,"aria-current":h===l?"page":void 0,children:[S,s!=null&&s[h]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[h]}):null]},h))}),b>0&&t.jsx(Nt,{label:p?p(b):`顯示更多(${b})`,onClick:()=>x(!0)}),a&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:a})]})}const xc={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function Zt({revision:e,revisedAt:n,review:i,todo:r}){const{convert:s}=Y(),l=i?xc[i.status]:void 0,d=i&&i.status!=="unreviewed"&&l?[l,i.by,i.date].filter(Boolean).join(" "):"",p=[e!=null&&e!==""?`${s("數據版本")} ${e}`:"",n??"",s(d)].filter(Boolean),a=(r||[]).filter(c=>c&&c.what);return!p.length&&!a.length?null:t.jsxs(t.Fragment,{children:[p.length>0&&t.jsx(Be,{items:p,style:{fontSize:12}}),a.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s(`待核 ${a.length} 項`)}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:a.map((c,u)=>t.jsxs("li",{children:[s(c.what),(c.by||c.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[c.by&&s(c.by),c.date].filter(Boolean).join(" · "),")"]})]},u))})]})]})}const cn=1e3,wo=208,fc=1440,gc="(max-width: 719px)",Zr=`
430
+ `;function Jt({railTop:e,back:n,up:i,nav:r,railLinks:s,main:l,card:a,side:p}){const{convert:c}=V(),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}=V();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 Me({id:e,title:n,meta:i,action:r,children:s}){const{convert:l}=V();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 We({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 wn({items:e,value:n,onChange:i}){const{convert:r}=V();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}=V();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}=V();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:i(e)})}function Zt({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}=V(),b=(p||[]).filter(v=>v.value!=null&&v.value!==""),k=(c||[]).filter(v=>v.value!=null&&v.value!==""&&v.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(v=>!v),children:m(h?"收起":"展開")}),k.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:k.map((v,_)=>t.jsxs("div",{children:[t.jsx("b",{children:v.value}),t.jsx("span",{children:m(v.label)})]},_))}),b.length>0&&t.jsx("dl",{className:"bim-d-ui",children:b.map((v,_)=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:m(v.label)}),t.jsx("dd",{title:v.title,children:v.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 qn({href:e,onClick:n,label:i="閱讀全文"}){const{convert:r}=V();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}=V(),[x,m]=f.useState(!1);if(!r.length)return null;const b=x?r:r.slice(0,a),k=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))}),k>0&&t.jsx(Bt,{label:p?p(k):`顯示更多(${k})`,onClick:()=>m(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const mc={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function Xt({revision:e,revisedAt:n,review:i,todo:r}){const{convert:s}=V(),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(We,{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 dn=1e3,zo=208,hc=1440,bc="(max-width: 719px)",es=`
374
431
  .bim-d-page {
375
432
  background: ${o("page-bg")};
376
433
  color: ${o("ink")};
@@ -379,7 +436,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
379
436
  padding-bottom: 64px;
380
437
  }
381
438
  .bim-d-main {
382
- max-width: ${cn}px;
439
+ max-width: ${dn}px;
383
440
  margin: 0 auto;
384
441
  padding: 24px clamp(16px, 4vw, 28px) 0;
385
442
  }
@@ -390,7 +447,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
390
447
  * PAGE_MAX_WIDTH,读者的行宽体验不变。
391
448
  */
392
449
  .bim-d-main.bim-d-main-wide {
393
- max-width: ${fc}px;
450
+ max-width: ${hc}px;
394
451
  }
395
452
  .bim-d-ui { font-family: var(--bim-font-ui, system-ui, sans-serif); }
396
453
 
@@ -422,9 +479,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
422
479
  */
423
480
  .bim-d-reader {
424
481
  display: grid;
425
- grid-template-columns: ${wo}px minmax(0, ${cn}px);
482
+ grid-template-columns: ${zo}px minmax(0, ${dn}px);
426
483
  gap: 32px;
427
- max-width: ${wo+cn+32}px;
484
+ max-width: ${zo+dn+32}px;
428
485
  margin: 0 auto;
429
486
  align-items: start;
430
487
  }
@@ -447,7 +504,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
447
504
  align-items: start; margin-bottom: 48px; }
448
505
  .bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
449
506
 
450
- @media ${gc} {
507
+ @media ${bc} {
451
508
  .bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
452
509
  .bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
453
510
  /* 表格:meta 列折到第二行,表头隐藏 */
@@ -465,14 +522,14 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
465
522
  padding-right: 0; padding-bottom: 12px;
466
523
  }
467
524
  }
468
- ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Zr}),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 qn({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 vi({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 Jn({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}`),d=i.id?n(i.id):i.href,p=s||!i.onClick&&!d?t.jsx("span",{style:{color:o("ink")},children:i.label},r):t.jsx("a",{href:d??"#",onClick:i.onClick?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i.onClick())}:void 0,style:{color:o("meta-fg")},children:i.label},r);return t.jsxs(f.Fragment,{children:[l,p]},r)})})}function Xr({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 mc({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 hc({items:e,horizontal:n}){const{convert:i}=Y();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 bc({glyph:e,tone:n,title:i,count:r,actions:s,id:l}){const{convert:d}=Y();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(vi,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:d(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 Qr({label:e,active:n,onClick:i,dashed:r}){const{convert:s}=Y();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 yc({label:e,onClick:n}){const{convert:i}=Y();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 jc({label:e,onClick:n,inline:i}){const{convert:r}=Y();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 es({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 vc({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function kc({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(d=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${o("rule")}`,color:o("meta-fg")},children:d},d)),!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 Sc({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${o("rule-strong")}`},children:e})}function wc({spec:e}){const{convert:n}=Y();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 _c({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 $c(e){return String(e+1).padStart(2,"0")}function zc(){return t.jsx("span",{style:{color:o("hint-fg")},children:"—"})}function Cc({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 ts(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 d=e.slice(i+1,l);d.includes(`
469
- `)||(n.push({start:i,end:l+1,inner:d}),i=l)}return n}function ns(e,n){if(e.length<=n)return e;let i=n;for(const r of ts(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 is={fontSize:".78em",color:o("meta-fg"),lineHeight:1.55},Ic={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 os(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?is:void 0,children:os(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:Ic,children:r.label},s)}})}function Ge(e,n=r=>r,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return ac(e)?os(Vr(e),n,0):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let s=0,l=0;for(const d of ts(e))d.start>s&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s,d.start))},l++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:is,children:n(d.inner)},l++)),s=d.end;return s<e.length&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),r}function Tc({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 Ec({title:e,tag:n,children:i}){const{convert:r}=Y();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 rs({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 Rc({item:e,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=Y(),[l,d]=f.useState(!1),p=mn(e),a=i&&!!p&&p.expected>0,c=(e.url?Et(e.url):void 0)||s(e.name),u=n?Ar(e,n):"",g=u?`${c}(${u})`:c;return t.jsx(rs,{name:g,note:jn(e)||r,href:Rt(e),extra:a?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>d(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(ki,{item:e})]}):void 0})}function ki({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 ss({label:e,items:n}){const{convert:i}=Y();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(es,{children:i(r)},s))]}):null}function Nc({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(ss,{label:i.label,items:i.items},i.label))}):null}function Zn(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ls({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 Lc({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 Le({id:e,label:n,onNavigate:i,renderLink:r,style:s,dense:l}){const d=Pe();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:l})}):t.jsx("a",{href:d(e),onClick:i?p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(e))}:void 0,style:s,children:n??e})}function Bc({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 as="(min-width: 1100px)",cs="(max-width: 719px)",Ac=`${cs}, (pointer: coarse)`,ct=o("reader-top"),Wc="48px",ds=`
525
+ ${gc}`;function Dt({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=Fe();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}=V();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}=V();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}=V();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}=V();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}=V();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}=V();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(`
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(qr(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}=V();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}=V(),[l,a]=f.useState(!1),p=hn(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:kn(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}=V();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 Le({id:e,label:n,onNavigate:i,renderLink:r,style:s,dense:l}){const a=Fe();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=`
470
527
  .bim-rd {
471
528
  position: relative;
472
529
  background: ${o("page-bg")};
473
530
  color: ${o("ink")};
474
531
  font-family: ${o("font-ui")};
475
- --bimrd-bar-h: ${Wc};
532
+ --bimrd-bar-h: ${Pc};
476
533
  }
477
534
  .bim-rd *, .bim-rd *::before, .bim-rd *::after { box-sizing: border-box; }
478
535
 
@@ -498,7 +555,7 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
498
555
 
499
556
  /* ── 工具条:文字 + 图标,不画按钮外框 ── */
500
557
  .bim-rd-bar {
501
- position: sticky; top: ${ct}; z-index: 30;
558
+ position: sticky; top: ${pt}; z-index: 30;
502
559
  height: var(--bimrd-bar-h);
503
560
  display: flex; align-items: center; gap: 16px;
504
561
  padding: 0 20px;
@@ -535,14 +592,14 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
535
592
  display: grid;
536
593
  grid-template-columns: auto auto minmax(0, 1fr);
537
594
  align-items: start;
538
- min-height: calc(100vh - ${ct} - var(--bimrd-bar-h));
595
+ min-height: calc(100vh - ${pt} - var(--bimrd-bar-h));
539
596
  }
540
597
 
541
598
  /* 目录:宽屏是侧栏 */
542
599
  .bim-rd-toc {
543
600
  grid-column: 1;
544
- position: sticky; top: calc(${ct} + var(--bimrd-bar-h));
545
- width: 248px; height: calc(100vh - ${ct} - var(--bimrd-bar-h));
601
+ position: sticky; top: calc(${pt} + var(--bimrd-bar-h));
602
+ width: 248px; height: calc(100vh - ${pt} - var(--bimrd-bar-h));
546
603
  overflow-y: auto; overscroll-behavior: contain;
547
604
  padding: 0 10px 40px;
548
605
  background: ${o("sidebar-bg")};
@@ -579,8 +636,8 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
579
636
  /* 书影:正文左侧 */
580
637
  .bim-rd-img {
581
638
  grid-column: 2;
582
- position: sticky; top: calc(${ct} + var(--bimrd-bar-h));
583
- width: clamp(300px, 32vw, 560px); height: calc(100vh - ${ct} - var(--bimrd-bar-h));
639
+ position: sticky; top: calc(${pt} + var(--bimrd-bar-h));
640
+ width: clamp(300px, 32vw, 560px); height: calc(100vh - ${pt} - var(--bimrd-bar-h));
584
641
  padding: 16px 0 16px 20px;
585
642
  display: flex; flex-direction: column; gap: 8px;
586
643
  }
@@ -591,7 +648,7 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
591
648
  display: flex; align-items: center; justify-content: center; overflow: hidden;
592
649
  }
593
650
  .bim-rd-img-fig { position: relative; margin: 0; max-width: 100%; max-height: 100%; }
594
- .bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${ct} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
651
+ .bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${pt} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
595
652
  .bim-rd-img-fig svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
596
653
  .bim-rd-img-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 24px; text-align: center; font-size: 13px; color: ${o("meta-fg")}; }
597
654
  .bim-rd-img-empty b { font-size: 15px; font-weight: 500; color: ${o("quiet-fg")}; }
@@ -656,7 +713,7 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
656
713
 
657
714
  /* 竖排(预留):只在宿主打开 allowVertical 时可切换 */
658
715
  .bim-rd-vertical .bim-rd-prose {
659
- writing-mode: vertical-rl; max-height: calc(100vh - ${ct} - var(--bimrd-bar-h) - 120px);
716
+ writing-mode: vertical-rl; max-height: calc(100vh - ${pt} - var(--bimrd-bar-h) - 120px);
660
717
  overflow-x: auto; text-align: start;
661
718
  }
662
719
 
@@ -674,7 +731,7 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
674
731
 
675
732
  /* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
676
733
  A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
677
- @media ${Ac} {
734
+ @media ${Fc} {
678
735
  .bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
679
736
  .bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
680
737
  content: ""; position: absolute; left: 50%; top: 50%;
@@ -686,7 +743,7 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
686
743
  }
687
744
 
688
745
  /* ── 中屏以下:目录改抽屉 ── */
689
- @media not all and ${as} {
746
+ @media not all and ${ps} {
690
747
  .bim-rd-toc {
691
748
  position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto;
692
749
  width: min(86vw, 320px);
@@ -700,7 +757,7 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
700
757
  }
701
758
 
702
759
  /* ── 窄屏:书影收起,只留正文 ── */
703
- @media ${cs} {
760
+ @media ${us} {
704
761
  .bim-rd-bar { padding: 0 12px; gap: 10px; }
705
762
  .bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
706
763
  .bim-rd-ttl { flex: 1 1 auto; }
@@ -716,19 +773,19 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
716
773
  .bim-rd-h1 { font-size: 20px; letter-spacing: 0.06em; }
717
774
  .bim-rd-prose { margin-top: 20px; }
718
775
  }
719
- `;function Si(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(r=>Si(r,n))):!1}const Mc=()=>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 Fc({item:e,activeKey:n,onSelect:i,tabKey:r}){const s=Si(e,n),[l,d]=f.useState(s||!!e.defaultExpanded);return f.useEffect(()=>{s&&d(!0)},[s]),f.useEffect(()=>{e.defaultExpanded&&d(!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:()=>d(p=>!p),children:[t.jsx(Mc,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(ps,{items:e.children,activeKey:n,onSelect:i,tabKey:r})]})}function ps({items:e,activeKey:n,onSelect:i,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Fc,{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 _o(e,n){var i;for(const r of e)if(r.key===n||Si(r,n))return r.key;return((i=e[0])==null?void 0:i.key)??null}function us({items:e,activeKey:n,onSelect:i,label:r="目录"}){const s=f.useRef(null),[l,d]=f.useState(null);f.useEffect(()=>{d(null)},[n]);const p=f.useMemo(()=>l||(n??_o(e,n)),[l,n,e]);f.useEffect(()=>{const c=s.current;if(!c)return;const u=Array.from(c.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===_o(e,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===g?0:-1}),f.useEffect(()=>{const c=s.current,u=c==null?void 0:c.closest(".bim-rd-toc");if(!c||!u||!n)return;const g=Array.from(c.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 a=f.useCallback(c=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(c.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(c.key==="ArrowDown"?b=Math.min(x.length-1,m+1):c.key==="ArrowUp"?b=Math.max(0,m-1):c.key==="Home"?b=0:c.key==="End"&&(b=x.length-1),b<0||b===m)return;c.preventDefault();const S=x[b];for(const h of x)h.tabIndex=-1;S.tabIndex=0,S.focus(),d(S.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:a,children:t.jsx(ps,{items:e,activeKey:n,onSelect:i,tabKey:p})})}function Pc({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 xs({pages:e,loading:n,page:i,onPageChange:r,renderOverlay:s}){const[l,d]=f.useState(0),p=i??l,a=x=>{r?r(x):d(x)};if(f.useEffect(()=>{i===void 0&&d(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 c=Math.max(0,Math.min(e.length-1,p)),u=e[c],g=u.label??`${c+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(Pc,{page:u}),s==null?void 0:s(u,c)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:c===0,onClick:()=>a(c-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${c+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:c===e.length-1,onClick:()=>a(c+1),children:"›"})]})]})}const wi={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal"},wt=[15,16,17,18,20,22,24],Xn=18,fs="bim-reader-prefs",Oc="bim-reading-mode";function Dc(){const e={...wi};try{const n=localStorage.getItem(fs),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&wt.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(Oc))==="paragraph"&&(e.readingMode="paragraph"),i.properNames===!0&&(e.properNames=!0),i.writingMode==="vertical"&&(e.writingMode="vertical")}catch{}return e}function Hc(e){try{localStorage.setItem(fs,JSON.stringify(e))}catch{}}function $o(e,n){const i=e??Xn,r=wt;let s=r.indexOf(i);return s<0&&(s=r.indexOf(Xn)),r[Math.max(0,Math.min(r.length-1,s+n))]}function _i(){const[e,n]=f.useState(wi);f.useEffect(()=>{n(Dc())},[]);const i=f.useCallback(r=>{n(s=>{const l={...s,...r};return Hc(l),l})},[]);return[e,i]}function gs(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 Qn(e){const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function ms(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 hs(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 Gc=()=>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"})}),Uc=()=>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 Vc(e,n){if(!n)return;const i=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(d=>d.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 Yc(e,n){const[i,r]=f.useState(n);return f.useEffect(()=>{var d;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(s.matches);return(d=s.addEventListener)==null||d.call(s,"change",l),()=>{var p;return(p=s.removeEventListener)==null?void 0:p.call(s,"change",l)}},[e]),i}function Kc(){const e=f.useContext(Tt);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 $i({title:e,subtitle:n,toc:i,activeKey:r,onSelect:s,tocHeader:l,tocCaption:d,images:p,imagesLoading:a,renderImageOverlay:c,imagePanel:u="auto",prefs:g,onPrefsChange:x,paragraphToggle:m,properNameToggle:b=!0,allowVertical:S,pager:h=!0,versions:v,currentVersionKey:y,onVersionChange:j,versionSource:_=!0,children:k,className:z,style:w}){const C=f.useId().replace(/:/g,""),E=`bim-rd-toc-${C}`,R=`bim-rd-text-${C}`,T=f.useRef(null),O=f.useRef(null),M=f.useRef(null),W=f.useRef(null),P=Yc(as,!0),[V,K]=f.useState("auto"),N=V==="auto"?P:V==="open",le=!P,G=!!p&&p.length>0,[se,ne]=f.useState(u);f.useEffect(()=>{ne(u)},[u]);const Q=se==="auto"?G||!!a:se==="open",H=f.useCallback(q=>{var L;K("auto"),q&&((L=W.current)==null||L.focus())},[]),te=()=>K(N?"closed":"open");f.useEffect(()=>{if(!le||V!=="open")return;const q=M.current,L=q==null?void 0:q.querySelector('input, [data-rd-toc-key][tabindex="0"]');L==null||L.focus()},[le,V]);const pe=f.useCallback(q=>{s(q),le&&H(!1);const L=O.current,I=T.current;if(L&&I&&typeof window<"u"){const $=L.getBoundingClientRect().top-I.getBoundingClientRect().bottom;$<0&&window.scrollBy({top:$})}},[s,le,H]),re=f.useMemo(()=>hs(i),[i]),[ee,ye]=f.useState(null),ae=ms(v,y!==void 0?y:ee),Te=(ae==null?void 0:ae.key)??null,je=f.useMemo(()=>re.map(q=>q.key).join(`
720
- `),[re]),Ce=f.useRef(null),Re=q=>{q!==Te&&(Ce.current={key:q,sig:je,done:!1},y===void 0&&ye(q),j==null||j(q))};f.useEffect(()=>{const q=Ce.current;if(!q||q.key!==Te)return;const L=re.find($=>!$.disabled);if(!L)return;const I=je!==q.sig;!I&&q.done||(I?Ce.current=null:q.done=!0,L.key!==r&&pe(L.key))},[Te,je,re,r,pe]);const Ie=re.findIndex(q=>q.key===r),D=Ie>0?re.slice(0,Ie).reverse().find(q=>!q.disabled):void 0,oe=Ie>=0?re.slice(Ie+1).find(q=>!q.disabled):void 0,ie=g.fontSize??Xn,xe={...w,...g.fontSize?{"--bimrd-fs":`${g.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",g.writingMode==="vertical"&&S?"bim-rd-vertical":"",z].filter(Boolean).join(" "),"data-toc":V,"data-img":Q?"open":"closed",style:xe,children:[t.jsx("style",{children:ds}),t.jsx("a",{className:"bim-rd-skip",href:`#${R}`,onClick:q=>{var L,I,$;q.preventDefault(),(L=O.current)==null||L.focus(),($=(I=O.current)==null?void 0:I.scrollIntoView)==null||$.call(I,{block:"start"})},children:"跳到正文"}),t.jsxs("div",{className:"bim-rd-bar",ref:T,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:[v&&v.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:ae?Qn(ae):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:Te??"",onChange:q=>Re(q.target.value),children:v.map(q=>t.jsx("option",{value:q.key,children:Qn(q)},q.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),t.jsxs("button",{ref:W,type:"button",className:"bim-rd-t","aria-expanded":N,"aria-controls":E,onClick:te,children:[t.jsx(Gc,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":Q,onClick:()=>ne(Q?"closed":"open"),children:[t.jsx(Uc,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Kc,{}),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:ie<=wt[0],onClick:()=>x({fontSize:$o(g.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"放大字号",disabled:ie>=wt[wt.length-1],onClick:()=>x({fontSize:$o(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:E,ref:M,role:le&&N?"dialog":void 0,"aria-modal":le&&N?!0:void 0,"aria-label":le&&N?"目录":void 0,onKeyDown:q=>{if(!(!le||!N)){if(q.key==="Escape"){q.stopPropagation(),H(!0);return}q.key==="Tab"&&Vc(q,M.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:d??"目录"}),le&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>H(!0),children:"✕"})]}),l]}),t.jsx(us,{items:i,activeKey:r,onSelect:pe})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>H(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:Q&&t.jsx(xs,{pages:p??null,loading:a,renderOverlay:c})}),t.jsx("div",{className:"bim-rd-text",id:R,ref:O,tabIndex:-1,children:t.jsxs("div",{className:"bim-rd-col",children:[k,_&&ae&&(ae.sourceName||ae.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":ae.key,children:[ae.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",ae.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:ae.sourceUrl,target:"_blank",rel:"noreferrer",children:ae.sourceName}):ae.sourceName]}),ae.sourceName&&ae.license&&t.jsx("span",{className:"bim-rd-dot"}),ae.license&&t.jsxs(t.Fragment,{children:["授权 ",ae.license]})]}),h&&(D||oe)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[t.jsx("span",{children:D&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>pe(D.key),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-pglabel",children:D.label})]})}),t.jsx("span",{children:oe&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>pe(oe.key),children:[t.jsx("span",{className:"bim-rd-pglabel",children:oe.label}),t.jsx("span",{"aria-hidden":"true",children:"›"})]})})]})]})})]})]})}const bs="guji-table-v1";function ys(e){return!!e&&e.table_notation===bs}const qc=/^:::table(?:\{[^}]*\})?[ \t]*$/,Jc=/^:::[ \t]*$/;function js(e){const n=[];let i="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const d=Gr(e,r+3);if(d>r+4){i+=e.slice(r,d+1),r=d;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const d=e[r+1];d!==void 0&&!/[A-Za-z/!?>\s]/.test(d)&&(l=">")}if(l){const d=e.indexOf(l,r+1);if(d>0){i+=e.slice(r,d+1),r=d;continue}}s==="|"?(n.push(i),i=""):i+=s}return n.push(i),n.map(r=>r.trim())}const Zc=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function Xc(e){if(e==="^")return{cont:!0};const n=Zc.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 vs(e,n=1){const i=[],r=[],s=[];let l=[];e.forEach((p,a)=>{const c=a+n+1;let u=p.trim();if(!u)return;let g=!1;u.startsWith("!")&&(g=!0,u=u.slice(1));const x=js(u).map(Xc),m=l.map(v=>v>0),b=l.map(v=>v>0?v-1:0),S=[];let h=0;for(const v of x){if(v.cont){m[h]||i.push(`第 ${c} 行第 ${h+1} 列:续格 ^ 上方没有跨行格`),h+=1;continue}const{cell:y}=v;for(let j=h;j<h+y.colspan;j++)if(m[j]){i.push(`第 ${c} 行第 ${j+1} 列:此处被上方跨行格占住,应写 ^`);break}if(y.rowspan>1)for(let j=h;j<h+y.colspan;j++)b[j]=y.rowspan-1;S.push(y),h+=y.colspan}for(let v=h;v<m.length;v++)m[v]&&i.push(`第 ${c} 行第 ${v+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let v=0;v<b.length;v++)b[v]===void 0&&(b[v]=0);l=b,r.push({header:g,cells:S}),s.push({width:h,line:c})});const d=s.reduce((p,a)=>Math.max(p,a.width),0);for(const p of s)p.width!==d&&i.push(`第 ${p.line} 行:占 ${p.width} 列,与总列数 ${d} 不符`);return l.some(p=>p>0)&&i.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&i.push("空表"),{rows:r,columns:d,warnings:i}}function zi(e){const n=e.split(`
721
- `),i=[];let r=[];const s=()=>{if(r.length===0)return;const d=r.join(`
722
- `);r=[],i.push({type:"text",text:d})};let l=0;for(;l<n.length;){if(qc.test(n[l].trim())){let d=l+1;for(;d<n.length&&!Jc.test(n[d].trim());)d++;if(d<n.length){s();const p=n.slice(l+1,d);i.push({type:"table",table:vs(p,l+1),source:n.slice(l,d+1).join(`
723
- `)}),l=d+1;continue}}r.push(n[l]),l++}return s(),i.map((d,p)=>{var c,u;if(d.type!=="text")return d;let a=d.text;return((c=i[p-1])==null?void 0:c.type)==="table"&&(a=a.replace(/^\n+/,"")),((u=i[p+1])==null?void 0:u.type)==="table"&&(a=a.replace(/\n+$/,"")),{type:"text",text:a}}).filter(d=>d.type!=="text"||d.text!=="")}const Qc={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},ed={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},td=`1px solid ${o("table-border")}`,ks={border:td,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},nd={...ks,background:o("table-head-bg"),fontWeight:600};function Ci({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:Qc,children:t.jsx("table",{className:"bim-guji-table",style:ed,children:t.jsx("tbody",{children:e.rows.map((i,r)=>t.jsx("tr",{children:i.cells.map((s,l)=>{const d=i.header?"th":"td";return t.jsx(d,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:i.header?nd:ks,children:s.empty?null:Ge(s.text,void 0,n)},l)})},r))})})})}function id(e,n){return e.indexOf("**")<0?Ge(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:Ge(r.trim().slice(2,-2),void 0,n)},s):t.jsx(f.Fragment,{children:Ge(r,void 0,n)},s))}function od(e,n,i=!1){const r=i?{gujiMarkdown:!0}:void 0;return n?zi(e).map((s,l)=>s.type==="table"?t.jsx(Ci,{table:s.table,opts:r},l):t.jsx(f.Fragment,{children:id(s.text,r)},l)):Ge(e,void 0,r)}const rd=/^(#{1,6})\s+(.*)$/,sd=/^\*\*([^*\n]+)\*\*\s*$/;function Ii(e){const n=e.match(rd);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(sd);return i?{level:3,text:i[1].trim()}:null}const Ti=/^<!--.*-->$/;function Ss(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function ws(e){return e.split(`
724
- `).map(n=>n.trim()).filter(n=>n&&!Ti.test(n))}const ld=60;function _s(e){let n=0,i=0;for(const r of e.split(`
725
- `)){const s=r.trim();if(!s||Ti.test(s)||Ii(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>ld&&(i+=l)}return n>0&&i*2>=n}function ad(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function Sn(e){if(e=ad(e),_s(e))return"unknown";const n=Ss(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>ws(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 cd(e){const n=e.split(`
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 k=x[b];for(const h of x)h.tabIndex=-1;k.tabIndex=0,k.focus(),a(k.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"})}),Kc=()=>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 qc(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:k,pager:h=!0,versions:y,currentVersionKey:j,onVersionChange:v,versionSource:_=!0,children:S,className:$,style:w}){const C=f.useId().replace(/:/g,""),N=`bim-rd-toc-${C}`,E=`bim-rd-text-${C}`,I=f.useRef(null),O=f.useRef(null),A=f.useRef(null),M=f.useRef(null),F=Jc(ps,!0),[Y,K]=f.useState("auto"),R=Y==="auto"?F:Y==="open",oe=!F,H=!!p&&p.length>0,[re,ee]=f.useState(u);f.useEffect(()=>{ee(u)},[u]);const Q=re==="auto"?H||!!c:re==="open",J=f.useCallback(q=>{var P;K("auto"),q&&((P=M.current)==null||P.focus())},[]),ce=()=>K(R?"closed":"open");f.useEffect(()=>{if(!oe||Y!=="open")return;const q=A.current,P=q==null?void 0:q.querySelector('input, [data-rd-toc-key][tabindex="0"]');P==null||P.focus()},[oe,Y]);const me=f.useCallback(q=>{s(q),oe&&J(!1);const P=O.current,T=I.current;if(P&&T&&typeof window<"u"){const z=P.getBoundingClientRect().top-T.getBoundingClientRect().bottom;z<0&&window.scrollBy({top:z})}},[s,oe,J]),te=f.useMemo(()=>js(i),[i]),[ie,pe]=f.useState(null),ge=ys(y,j!==void 0?j:ie),Ce=(ge==null?void 0:ge.key)??null,ve=f.useMemo(()=>te.map(q=>q.key).join(`
777
+ `),[te]),we=f.useRef(null),Ee=q=>{q!==Ce&&(we.current={key:q,sig:ve,done:!1},j===void 0&&pe(q),v==null||v(q))};f.useEffect(()=>{const q=we.current;if(!q||q.key!==Ce)return;const P=te.find(z=>!z.disabled);if(!P)return;const T=ve!==q.sig;!T&&q.done||(T?we.current=null:q.done=!0,P.key!==r&&me(P.key))},[Ce,ve,te,r,me]);const Re=te.findIndex(q=>q.key===r),D=Re>0?te.slice(0,Re).reverse().find(q=>!q.disabled):void 0,se=Re>=0?te.slice(Re+1).find(q=>!q.disabled):void 0,ne=g.fontSize??Qn,he={...w,...g.fontSize?{"--bimrd-fs":`${g.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",g.writingMode==="vertical"&&k?"bim-rd-vertical":"",$].filter(Boolean).join(" "),"data-toc":Y,"data-img":Q?"open":"closed",style:he,children:[t.jsx("style",{children:xs}),t.jsx("a",{className:"bim-rd-skip",href:`#${E}`,onClick:q=>{var P,T,z;q.preventDefault(),(P=O.current)==null||P.focus(),(z=(T=O.current)==null?void 0:T.scrollIntoView)==null||z.call(T,{block:"start"})},children:"跳到正文"}),t.jsxs("div",{className:"bim-rd-bar",ref:I,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:ge?ei(ge):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:Ce??"",onChange:q=>Ee(q.target.value),children:y.map(q=>t.jsx("option",{value:q.key,children:ei(q)},q.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),t.jsxs("button",{ref:M,type:"button",className:"bim-rd-t","aria-expanded":R,"aria-controls":N,onClick:ce,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":Q,onClick:()=>ee(Q?"closed":"open"),children:[t.jsx(Kc,{}),"书影"]}),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:ne<=$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:ne>=$t[$t.length-1],onClick:()=>x({fontSize:Io(g.fontSize,1)}),children:"A+"}),(m||b||k)&&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:"专名线"}),k&&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:A,role:oe&&R?"dialog":void 0,"aria-modal":oe&&R?!0:void 0,"aria-label":oe&&R?"目录":void 0,onKeyDown:q=>{if(!(!oe||!R)){if(q.key==="Escape"){q.stopPropagation(),J(!0);return}q.key==="Tab"&&qc(q,A.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??"目录"}),oe&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>J(!0),children:"✕"})]}),l]}),t.jsx(gs,{items:i,activeKey:r,onSelect:me})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>J(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:Q&&t.jsx(ms,{pages:p??null,loading:c,renderOverlay:d})}),t.jsx("div",{className:"bim-rd-text",id:E,ref:O,tabIndex:-1,children:t.jsxs("div",{className:"bim-rd-col",children:[S,_&&ge&&(ge.sourceName||ge.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":ge.key,children:[ge.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",ge.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:ge.sourceUrl,target:"_blank",rel:"noreferrer",children:ge.sourceName}):ge.sourceName]}),ge.sourceName&&ge.license&&t.jsx("span",{className:"bim-rd-dot"}),ge.license&&t.jsxs(t.Fragment,{children:["授权 ",ge.license]})]}),h&&(D||se)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[t.jsx("span",{children:D&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>me(D.key),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-pglabel",children:D.label})]})}),t.jsx("span",{children:se&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>me(se.key),children:[t.jsx("span",{className:"bim-rd-pglabel",children:se.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),k=[];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 v=h;v<h+j.colspan;v++)if(m[v]){i.push(`第 ${d} 行第 ${v+1} 列:此处被上方跨行格占住,应写 ^`);break}if(j.rowspan>1)for(let v=h;v<h+j.colspan;v++)b[v]=j.rowspan-1;k.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:k}),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
+ `),i=[];let r=[];const s=()=>{if(r.length===0)return;const a=r.join(`
779
+ `);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
+ `)}),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
+ `).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 _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(`
726
783
  `),i=[];let r=null,s=[];const l=()=>{i.push({heading:r,body:s.join(`
727
- `)}),s=[]};for(const d of n){const p=Ii(d);if(p){l(),r={kind:"heading",level:p.level,text:p.text};continue}s.push(d)}return l(),i}function zo(e){const n=[];for(const i of e.split(`
728
- `)){const r=Ii(i);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=i.trim();!s||Ti.test(s)||n.push({kind:"body",text:i})}return n}function $s(e){if(!e)return[];const n=Sn(e);if(n==="unknown")return zo(e);const i=[];for(const{heading:r,body:s}of cd(e)){r&&i.push(r);const l=Ss(s);if(l.length!==0){if(_s(s)){i.push(...zo(s));continue}if(n==="record"){const d=l.join(" ");d&&i.push({kind:"body",text:d})}else for(const d of l){const p=ws(d);p.length&&i.push({kind:"body",text:p.join(" ")})}}}return i}const zs=e=>e;function Cs(e,n=zs){if(e.indexOf("《")<0)return n(e);const i=[],r=/《([^《》\n]+)》/g;let s=0,l=0,d;for(;d=r.exec(e);)d.index>s&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s,d.index))},l++)),i.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(d[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=d.index+d[0].length;return s===0?n(e):(s<e.length&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),i)}function Ei(e,n={}){const i=n.renderText??zs,r=n.properNames?l=>Cs(l,i):i,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Ge(e,r,s)}function Co(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 Nn=/^(#{1,6})\s+(.*)$/,dd=/^\s*<!--.*-->\s*$/;function Is(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
729
- `)?"":n)}function pd(e){return e<=1?2:e===2?3:4}function ud(){let e=1;return n=>{const i=pd(n),r=Math.min(i,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${i}`}}}function wn(e){return e?Sn(Is(e))!=="unknown":!1}function Io({text:e,mode:n,inline:i,dropTitle:r}){const s=Is(e),l=(c,u,g)=>!!r&&g<=1&&c<=2&&u.trim()===r.trim(),d=ud();if(n==="paragraph"&&Sn(s)!=="unknown"){const c=$s(s);return t.jsx(t.Fragment,{children:c.map((u,g)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,g))return null;const{Tag:x,className:m}=d(u.level??1);return t.jsx(x,{className:m,children:i(u.text)},g)}return t.jsx("p",{children:Co(u.text,i,g)},g)})})}const p=s.split(`
730
- `);let a=0;return t.jsx(t.Fragment,{children:p.map((c,u)=>{const g=c.match(Nn);if(g){const m=a++;if(l(g[1].length,g[2],m))return null;const{Tag:b,className:S}=d(g[1].length);return t.jsx(b,{className:S,children:i(g[2])},u)}if(!c.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Nn.test(p[u-1])&&!Nn.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(dd.test(c))return null;if(a++,/^\*\*[^*]+\*\*\s*$/.test(c.trim())){const{Tag:m,className:b}=d(3);return t.jsx(m,{className:b,children:i(c.trim().slice(2,-2))},u)}return t.jsx("p",{children:Co(c,i,u)},u)})})}function xd(e){const{convert:n}=Y();return f.useMemo(()=>e?n(e):"",[e,n])}function Ri({text:e,mode:n,tables:i=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:d}){const p=xd(e),{convert:a}=Y(),c=x=>Ei(x,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,g=d?a(d):void 0;return!i||p.indexOf(":::")<0?t.jsx(Io,{text:p,mode:n,inline:c,dropTitle:g}):t.jsx(t.Fragment,{children:zi(p).map((x,m)=>x.type==="table"?t.jsx(Ci,{table:x.table,opts:u},m):t.jsx(Io,{text:x.text,mode:n,inline:c,dropTitle:m===0?g:void 0},m))})}function Ts(e,n){const[i,r]=f.useState(null),[s,l]=f.useState(!1),d=f.useRef(0);return f.useEffect(()=>{const p=++d.current;if(!e||!n){r(null),l(!1);return}let a;try{a=e(n)}catch{r(null),l(!1);return}if(!a||typeof a.then!="function"){r(a??null),l(!1);return}l(!0),a.then(c=>{p===d.current&&r(c??null)}).catch(()=>{p===d.current&&r(null)}).finally(()=>{p===d.current&&l(!1)})},[e,n]),{images:i,loading:s}}const To={A:"fine",B:"rough",C:"rough",D:"ocr"};function fd(e){return typeof e!="string"?null:e in Dn?e:e in To?To[e]:null}const gd={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},md={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function et(e){return typeof e!="string"?"":gd[e]??md[e]??e}const hd=["〇","一","二","三","四","五","六","七","八","九"],Eo=["","十","百","千"],bd=["","萬","億"];function Ni(e){if(e===0)return"〇";if(e<0)return`負${Ni(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(yd(s,r>0)+bd[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function yd(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 d=i[l],p=i.length-1-l;d===0?s&&!s.endsWith("〇")&&(s+="〇"):d===1&&p===1&&l===0&&!n?s+=Eo[p]:s+=hd[d]+Eo[p]}return s.replace(/〇$/,"")}let Gt=null,ln=null;const fn=new Set;function jd(){return Gt?Promise.resolve():ln||(ln=import("opencc-js/t2cn").then(e=>{Gt=e.Converter({from:"tw",to:"cn"}),fn.forEach(n=>n())}).catch(()=>{Gt=e=>e,fn.forEach(e=>e())}),ln)}const vd=e=>e;function jt(){const[,e]=f.useState(0);return f.useEffect(()=>{if(Gt)return;const n=()=>e(i=>i+1);return fn.add(n),jd(),()=>{fn.delete(n)}},[]),Gt??vd}function It(e,n){return n(e).toLowerCase()}const kd=o("highlight-bg");function Xt(e,n,i){if(!n)return e;const r=It(n,i);if(!r)return e;const s=It(e,i);if(s.length!==e.length)return e;const l=[];let d=0,p=0;for(;d<e.length;){const a=s.indexOf(r,d);if(a===-1){l.push(e.slice(d));break}a>d&&l.push(e.slice(d,a)),l.push(t.jsx("mark",{style:{background:kd,padding:0,color:"inherit"},children:e.slice(a,a+r.length)},p++)),d=a+r.length}return t.jsx(t.Fragment,{children:l})}function Li(e,n,i,r){if(!n)return!0;const s=It(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(d=>typeof d=="string"&&It(d,r).includes(s))}function Sd(e,n,i){return n?It(e,i).includes(It(n,i)):!0}const Bi={类:o("section-lei"),书:o("section-shu"),序:o("section-xu"),结语:o("section-jieyu"),注释:o("section-zhushi")},wd={考证:o("section-kaozhen")};function _d(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 Es(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((s,l)=>s+Es(l),0))||0;return n+i}function $d(e,n){const i=[],r=d=>{var p;i.push(...d.files),(p=d.children)==null||p.forEach(r)};if(r(e),i.length===0)return;const s=i.map(d=>n[d]);if(s.every(d=>d===void 0))return;if(s.some(d=>d==="loading"))return"loading";let l=0;for(const d of s)typeof d=="number"&&(l+=d);return l}const zd={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Ai({enabled:e,expanded:n,onClick:i,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...zd,...r},children:s}):t.jsx("span",{style:r,children:s})}function Cd({type:e}){const n=et(e),i=Bi[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 Id({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=Y(),s=Pe(),l=jt(),d=S=>S?Ge(r(S),h=>i?Xt(h,i,l):h):"",[p,a]=f.useState(!1),c=!!e.summary,u=!!e.comment,g=!!e.additional_comment,x=!!(e.content&&e.content.length>60),m=c||u||g||x;f.useEffect(()=>{i&&a(!0)},[i]);const b=!p&&x?ns(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&&a(!p),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:m?"pointer":"default",userSelect:"none",background:o("input-bg")},children:[t.jsxs(Ai,{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:["《",d(e.book_title),"》"]}):d(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[Ni(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:d(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:d(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:d(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:d(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:d(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:d(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:d(e.additional_comment)})]}),x&&!c&&!u&&!g&&t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:d(e.content)})]})]})}function Td({section:e,highlightQuery:n=""}){const{convert:i}=Y(),r=jt(),s=a=>a?Ge(i(a),c=>n?Xt(c,n,r):c):"",[l,d]=f.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(Ai,{enabled:p,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(Cd,{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, ${Bi[et(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 Ed=100;function Wi(e){return et(e.type)!=="page_header"?!1:(e.content||"").length>=Ed}function Rd({section:e,highlightQuery:n=""}){const{convert:i}=Y(),r=jt();if(et(e.type)==="page_header"&&!Wi(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
731
- `)),l=Ge(s,c=>n?Xt(c,n,r):c),d=et(e.type),p=Bi[d]||o("desc-fg"),a=d==="序"||d==="结语"||d==="注释";return t.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:o("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${p}40`:void 0,background:a?o("bg"):void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&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:d}),l]})}function Nd(e,n,i){const[r,s]=f.useState({});return f.useEffect(()=>{var c;if(!n||e.length===0)return;let l=!1;const d=e.filter(u=>{var g;return!((g=i==null?void 0:i.current)!=null&&g.has(u))}),p={};for(const u of e)(c=i==null?void 0:i.current)!=null&&c.has(u)&&(p[u]=i.current.get(u));if(Object.keys(p).length>0&&s(p),d.length===0)return;const a=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(d.map(async u=>{var x;const g=await a(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 Ld({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=Y(),d=Pe(),p=jt(),a=y=>y?Ge(l(y),j=>s?Xt(j,s,p):j):"",[c,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const g=et(e.type),x=wd[g]||o("desc-fg"),m=!!e.content,b=e.work_ids||[],S=b.length>1,h=Nd(S?b:[],i,r),v=m&&!c&&e.content.length>80?ns(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(!c),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:m?"pointer":"default",userSelect:"none"},children:[t.jsxs(Ai,{enabled:m,expanded:c,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:c?"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?a(e.header_line):a(e.title)}),!c&&v&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:a(v)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:d(b[0]),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.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(y=>{const j=h[y],_=j?`${l(j.title)}${j.author?`(${l(j.author)})`:""}`:y.slice(0,8)+"…";return t.jsxs("a",{href:d(y),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),n(y))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",_]},y)})}),c&&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:a(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:a(e.comment)})]})]})}function Bd({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=jt(),d=n.trim(),p=f.useMemo(()=>d?e.sections.filter(a=>Li(a,d,!0,l)):e.sections,[e.sections,d,l]);return t.jsxs("div",{children:[t.jsx("div",{children:p.map((a,c)=>t.jsx(Ld,{section:a,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:d},c))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Ad(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Wd({sections:e,onNavigate:n,inline:i}){const r=Pe(),{convert:s}=Y(),l=Ad();return t.jsx(t.Fragment,{children:e.map((d,p)=>{const a=et(d.type);if(a==="page_header"&&!Wi(d))return null;if(a==="类")return t.jsxs(f.Fragment,{children:[f.createElement(l("类"),null,i(s(d.title))),d.content&&t.jsx("p",{children:i(s(d.content))})]},p);if(a==="书"||a==="诗"||a==="考证"||a==="注释"){const c=d.book_title?`《${d.book_title}》${d.n_juan!=null?Ni(d.n_juan)+"卷":""}`:d.title,u=i(s(c));return t.jsxs("section",{className:"bim-rd-entry",children:[f.createElement(l("条目"),{className:"bim-rd-entry-h"},d.work_id&&n?t.jsx("a",{href:r(d.work_id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),n(d.work_id))},title:"查看作品",children:u}):u),d.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(d.author_info))}),d.content&&d.content.split(/\n+/).map((g,x)=>t.jsx("p",{children:i(s(g))},x)),d.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(d.summary))]}),d.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(d.comment))]}),d.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(d.additional_comment))]})]},p)}return d.content?t.jsx("p",{children:i(s(d.content))},p):null})})}function Md(e){return e.some(n=>{const i=et(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&Wi(n)})}function Fd({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:d,workLabelCache:p,prefs:a}){var M;const{convert:c}=Y(),u=jt(),[g,x]=f.useState("text"),m=s.trim(),b=(r==null?void 0:r.type)==="kaozhen",S=f.useCallback(W=>m?Xt(W,m,u):W,[m,u]),h=W=>Ei(W,{renderText:S,properNames:a.properNames}),v=f.useMemo(()=>m?e.sections.filter(W=>Li(W,m,b,u)):e.sections,[e.sections,m,b,u]),y=(W,P)=>P.filter(V=>et(V.type)===W).length,j=y("书",e.sections),_=y("诗",e.sections),k=y("考证",e.sections);let z="";b?z=m?`${y("考证",v)} / ${k} ${c("條")}`:`${k} ${c("條")}`:_>0?z=m?`${y("诗",v)} / ${_} 首`:`${_} 首`:j>0&&(z=m?`${y("书",v)} / ${j} ${c("部書")}`:`${j} ${c("部書")}`);const w=r!=null&&r.text_quality?fd(r.text_quality.grade):null,C=[];i&&C.push(i),z&&C.push(z),b&&(r!=null&&r.target_source)&&C.push(t.jsxs(t.Fragment,{children:[c("考證對象")," ",c(r.target_source)]})),w&&C.push(t.jsx("span",{title:Rl[w],children:(M=r==null?void 0:r.text_quality)!=null&&M.source_note?t.jsxs(t.Fragment,{children:["底本 ",c(r.text_quality.source_note),"(",c(Dn[w]),")"]}):t.jsxs(t.Fragment,{children:[c("文本質量")," ",c(Dn[w])]})})),e.source_url&&C.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:c("原文來源")}));const E=!b&&Md(e.sections),R=!!n&&(!E||a.readingMode==="paragraph"&&wn(n)),T=!b&&(E||!!n),O=b||!T?"entries":g;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:c(e.title)}),C.length>0&&t.jsx("p",{className:"bim-rd-meta",children:C.map((W,P)=>t.jsxs(f.Fragment,{children:[P>0&&t.jsx("span",{className:"bim-rd-dot"}),W]},P))}),T&&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:c("條目")})]})]}),O==="text"&&t.jsx("article",{className:"bim-rd-prose",children:R?t.jsx(Ri,{text:n,mode:a.readingMode,properNames:a.properNames,renderText:S,dropTitle:e.title}):t.jsx(Wd,{sections:e.sections,onNavigate:l,inline:h})}),O==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:b?t.jsx(Bd,{juan:e,searchQuery:s,onNavigate:l,transport:d,workLabelCache:p}):t.jsxs(t.Fragment,{children:[v.map((W,P)=>{const V=et(W.type);return V==="书"||V==="诗"||V==="考证"?t.jsx(Id,{section:W,onNavigate:l,highlightQuery:m},P):V==="类"?t.jsx(Td,{section:W,highlightQuery:m},P):t.jsx(Rd,{section:W,highlightQuery:m},P)}),v.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function Rs(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 Pd(e){const n=Rs(e);return n.length>0?n[0]:null}function Od(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:d,query:p,isKaozhen:a}=e,c=jt(),u=f.useRef(new Map),[g,x]=f.useState({}),[m,b]=f.useState({}),S=f.useCallback((v,y)=>{const j=y==null?void 0:y.title;j&&b(_=>_[v]===j?_:{..._,[v]:j})},[]);f.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:d}),S(s,l))},[s,l,d,S]),f.useEffect(()=>{u.current.clear(),x({}),b({})},[n]);const h=f.useCallback((v,y)=>{let j=0;if(v.juan)for(const _ of v.juan.sections)Li(_,y,a,c)&&j++;return j===0&&v.rawText&&Sd(v.rawText,y,c)&&(j=1),j},[a,c]);return f.useEffect(()=>{const v=p.trim();if(!v){x({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let y=!1;const j={},_=[];for(const E of r){const R=u.current.get(E);R?j[E]=h(R,v):(j[E]="loading",_.push(E))}x(j);const k=8;let z=0;const w=async()=>{var E;for(;z<_.length;){if(y)return;const R=z++,T=_[R];try{const[O,M]=await Promise.all([i.getCollatedJuan(n,T),((E=i.getCollatedJuanText)==null?void 0:E.call(i,n,T))??Promise.resolve(null)]),W={juan:O,rawText:M};if(u.current.set(T,W),S(T,O),y)return;x(P=>({...P,[T]:h(W,v)}))}catch{if(y)return;x(O=>({...O,[T]:0}))}}},C=Array.from({length:Math.min(k,_.length)},()=>w());return Promise.all(C),()=>{y=!0}},[p,n,i,r.join(","),h,c,S]),{matchStates:g,titles:m}}const Mi=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:d,style:p,title:a,subtitle:c,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m})=>{const[b,S]=f.useState(null),[h,v]=f.useState(!1),[y,j]=f.useState(null),[_,k]=f.useState(null),[z,w]=f.useState(null),[C,E]=f.useState(!1),[R,T]=f.useState(null),[O,M]=f.useState(""),W=f.useRef(new Map),P=f.useRef(0),V=s??_,K=f.useCallback(H=>{k(H),l==null||l(H)},[l]),N=e||b;f.useEffect(()=>{e&&(v(!1),j(null))},[e]),f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let H=!1;return v(!0),j(null),i.getCollatedEditionIndex(n).then(te=>{H||(te?S(te):j("未找到整理本数据"))}).catch(te=>{H||j(te instanceof Error?te.message:"加载失败")}).finally(()=>{H||v(!1)}),()=>{H=!0}},[e,n,i]),f.useEffect(()=>{if(N&&!V){const H=Pd(N);H&&K(H)}},[N,V,K]);const le=n||(N==null?void 0:N.work_id),G=f.useCallback(async H=>{var pe;if(!le||!(i!=null&&i.getCollatedJuan))return;const te=++P.current;E(!0),w(null),T(null);try{const[re,ee]=await Promise.all([i.getCollatedJuan(le,H),((pe=i.getCollatedJuanText)==null?void 0:pe.call(i,le,H))??Promise.resolve(null)]);if(te!==P.current)return;w(re),T(ee)}catch{if(te!==P.current)return;w(null),T(null)}finally{te===P.current&&E(!1)}},[le,i]);f.useEffect(()=>{V&&G(V)},[V,G]);const se=H=>{K(H)};if(h)return t.jsx("div",{className:d,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(y)return t.jsx("div",{className:d,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:y});if(!N)return null;const ne=N.type==="kaozhen",Q=Rs(N);return t.jsx(Hd,{className:d,style:p,index:N,allFiles:Q,isKaozhen:ne,effectiveWorkId:le,transport:i,activeFile:V,handleSelectFile:se,juanData:z,juanRawText:R,juanLoading:C,searchQuery:O,setSearchQuery:M,onNavigate:r,workLabelCacheRef:W,reader:{title:a,subtitle:c,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m}})};function Ns(e,n,i,r){var c,u,g,x;const s=(u=(c=n.juan_metadata)==null?void 0:c[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:_d(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 a=r(p);return{position:l,label:l===p||l===a?a:`${l} ${a}`}}function Dd(e,n,i,r,s){const l=a=>a==="loading"?"…":typeof a=="number"&&a>0?a:void 0,d=(a,c)=>({key:a,label:c??Ns(a,e,r,s).label,hint:l(i[a]),disabled:i[a]===0}),p=(a,c)=>{var g;if(a.files.length===1&&!((g=a.children)!=null&&g.length))return d(a.files[0],s(a.label));const u=$d(a,i);return{key:`group:${c}`,label:s(a.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:Es(a),defaultExpanded:typeof u=="number"&&u>0,children:[...a.files.map(x=>d(x)),...(a.children??[]).map((x,m)=>p(x,`${c}.${m}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((a,c)=>p(a,`${c}`)):n.map(a=>d(a))}const Hd=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:d,activeFile:p,handleSelectFile:a,juanData:c,juanRawText:u,juanLoading:g,searchQuery:x,setSearchQuery:m,onNavigate:b,workLabelCacheRef:S,reader:h})=>{const{convert:v}=Y(),[y,j]=_i(),{matchStates:_,titles:k}=Od({workId:l,transport:d,files:r,activeFile:p,activeJuan:c,activeRawText:u,query:x,isKaozhen:s}),z=Ts(h.resolveImages,p),w=f.useMemo(()=>Dd(i,r,_,k,v),[i,r,_,k,v]),C=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:T=>m(T.target.value)}),E=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(T=>T.vol_label)?"冊":"卷",R=p?Ns(p,i,k,v).position:void 0;return t.jsxs($i,{className:e,style:n,title:h.title??(i.title?v(i.title):void 0),subtitle:h.subtitle??v(s?"考證":"整理本"),toc:w,tocCaption:`目录 · ${r.length} ${v(E)}`,tocHeader:C,activeKey:p,onSelect:a,images:z.images,imagesLoading:z.loading,renderImageOverlay:h.renderImageOverlay,imagePanel:h.imagePanel,prefs:y,onPrefsChange:j,paragraphToggle:!s&&wn(u),allowVertical:h.allowVertical,children:[g?t.jsx(yt,{}):c?t.jsx(Fd,{juan:c,rawText:u,positionLabel:R,index:i,searchQuery:x,onNavigate:b,transport:d,workLabelCache:S,prefs:y},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:v("參考文獻")}),t.jsx("ol",{children:i.references.map((T,O)=>t.jsxs("li",{children:[T.url?t.jsx("a",{className:"bim-rd-link",href:T.url,target:"_blank",rel:"noopener noreferrer",children:T.title}):t.jsx("span",{children:T.title}),T.author&&t.jsxs("span",{children:[",",T.author]}),T.note&&t.jsxs("span",{children:["。",T.note]})]},O))})]})]})},Gd={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},Ud={label:"其他",color:o("desc-fg")},Vd={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")}},Yd={label:"待处理",color:o("warning")};function Kd(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 qd(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 Fi=({items:e,loading:n})=>{const i=Pe();return n?t.jsx(yt,{}):e.length===0?t.jsx("div",{style:Jd,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Gd[r.type]||Ud,l=Vd[r.status]||Yd,d=typeof window<"u"&&qd(r.pageUrl,window.location.href);return t.jsxs("div",{style:Zd,children:[t.jsxs("div",{style:Xd,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Ro,background:s.color},children:s.label}),t.jsx("span",{style:{...Ro,background:l.color},children:l.label})]}),t.jsx("span",{style:Qd,children:Kd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:ep,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:Ln,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(d?t.jsx("a",{href:r.pageUrl,style:Ln,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Ln,children:r.pageUrl}))]}),t.jsx("div",{style:tp,children:r.content}),r.reply&&t.jsxs("div",{style:np,children:[t.jsx("div",{style:ip,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Jd={textAlign:"center",padding:"40px 0",color:o("desc-fg"),fontSize:"14px"},Zd={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"16px"},Xd={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ro={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Qd={fontSize:"12px",color:o("desc-fg")},ep={fontSize:"12px",marginBottom:"6px"},Ln={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},tp={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},np={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},ip={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},ei=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const d=de(),[p,a]=f.useState(null),[c,u]=f.useState([]),[g,x]=f.useState("recommend"),[m,b]=f.useState([]),[S,h]=f.useState(!1),v=r??g,y=P=>{x(P),s==null||s(P)},[j,_]=f.useState(!0),[k,z]=f.useState(null),[w,C]=f.useState(null),[E,R]=f.useState(null);f.useEffect(()=>{let P=!1;if(e.getCounts)return e.getCounts().then(V=>{P||a({works:V.works,books:V.books,collections:V.collections})}).catch(()=>{}),()=>{P=!0}},[e]),f.useEffect(()=>{let P=!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(N=>N.items.map(le=>({...le,group:N.name})))}catch{}return[]})().then(async K=>{if(P)return;const N=K.filter(G=>G.id);if(N.length===0){_(!1);return}const le=await Promise.all(N.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 se=null;if(e.getEntry)se=await e.getEntry(G.id);else{const ne=await e.getItem(G.id);ne&&(se={id:G.id,title:ne.title||G.id,type:ne.type||"work"})}if(se)return{...se,group:G.group,fallbackDescription:G.description}}catch{}return{id:G.id,title:G.title,type:be.extractType(G.id),group:G.group,fallbackDescription:G.description}}));P||(u(le.filter(G=>G!==null)),_(!1))}),()=>{P=!0}},[e,i]);const T=f.useRef(!1),O=f.useRef(!1),M=f.useRef(!1);f.useEffect(()=>{if(v!=="catalog"||T.current)return;const P=e.getCatalogProgress??e.getResourceProgress;if(!P)return;T.current=!0;let V=!1;return P.call(e).then(K=>{V||z(K)}).catch(()=>{T.current=!1}),()=>{V=!0}},[e,v]),f.useEffect(()=>{if(v!=="collection"||O.current||!e.getCollectionProgress)return;O.current=!0;let P=!1;return e.getCollectionProgress().then(V=>{P||C(V)}).catch(()=>{O.current=!1}),()=>{P=!0}},[e,v]),f.useEffect(()=>{if(v!=="site"||M.current||!e.getSiteProgress)return;M.current=!0;let P=!1;return e.getSiteProgress().then(V=>{P||R(V)}).catch(()=>{M.current=!1}),()=>{P=!0}},[e,v]),f.useEffect(()=>{if(!l||v!=="feedback")return;let P=!1;return h(!0),fetch(l).then(V=>V.json()).then(V=>{!P&&V.success&&b(V.items||[])}).catch(()=>{}).finally(()=>{P||h(!1)}),()=>{P=!0}},[l,v]);const W=P=>{switch(P){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};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(Mt,{label:d.home.recommendTab,active:v==="recommend",onClick:()=>y("recommend")}),t.jsx(Mt,{label:d.home.catalogTab,active:v==="catalog",onClick:()=>y("catalog")}),t.jsx(Mt,{label:d.home.collectionTab,active:v==="collection",onClick:()=>y("collection")}),t.jsx(Mt,{label:d.home.siteTab,active:v==="site",onClick:()=>y("site")}),l&&t.jsx(Mt,{label:d.home.feedbackTab,active:v==="feedback",onClick:()=>y("feedback")})]}),v==="recommend"&&t.jsx(op,{recommended:c,loading:j,onNavigate:n,getIcon:W,t:d}),v==="catalog"&&t.jsx(No,{progress:k,t:d,onNavigate:n}),v==="collection"&&t.jsx(No,{progress:w,t:d,onNavigate:n}),v==="site"&&t.jsx(sp,{progress:E,t:d,totalWorks:(p==null?void 0:p.works)??0}),v==="feedback"&&l&&t.jsx(Fi,{items:m,loading:S})]})})},Mt=({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}),op=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=Pe();if(n)return t.jsx(yt,{});if(e.length===0)return null;const d=new Map;for(const p of e){const a=p.group||s.home.recommendedBrowse;d.has(a)||d.set(a,[]),d.get(a).push(p)}return t.jsx(t.Fragment,{children:Array.from(d.entries()).map(([p,a])=>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:a.map(c=>{const u=c.dynasty||c.author?`${c.dynasty?`〔${c.dynasty}〕`:""}${c.author||""}`:c.fallbackDescription;return t.jsxs("a",{href:l(c.id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),i==null||i(c.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(c.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[c.title,c.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:c.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},c.id)})})]},p))})},No=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(yt,{});const r=[...e.resources].sort((p,a)=>p.priority-a.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},d={in_progress:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(p=>{const a=r.filter(c=>c.status===p);return a.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:d[p]}}),l[p]," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(c=>t.jsx(rp,{item:c,t:n,statusColor:d[p],onNavigate:i},c.id))})]},p)})})},rp=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=Pe(),l=e.total>0?Math.round(e.imported/e.total*100):0,d=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,a=e.collection_id||e.work_id;return a&&r?t.jsx("a",{href:s(a),onClick:c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:c=>c.currentTarget.style.borderBottomStyle="solid",onMouseLeave:c=>c.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:d})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Yt(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})]})},sp=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(yt,{});const r=[...e.resources].sort((a,c)=>a.priority-c.priority),s=r.filter(a=>a.imported>0),l=r.filter(a=>a.imported===0),d=s.reduce((a,c)=>Math.max(a,c.imported),0),p=i>0?Math.round(d/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:d.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(a=>t.jsx(Lo,{item:a,t:n,totalWorks:i},a.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(a=>t.jsx(Lo,{item:a,t:n,totalWorks:i},a.id))})]})]})},Lo=({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})]})},Bo="(max-width: 768px)";function lp(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Bo).matches);return f.useEffect(()=>{const i=window.matchMedia(Bo),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),e}const ap=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var V;const l=de(),{convert:d}=Y(),p=lp(),[a,c]=f.useState(null),[u,g]=f.useState(null),[x,m]=f.useState(!1),[b,S]=f.useState("detail"),[h,v]=f.useState([]),[y,j]=f.useState(!1),[_,k]=f.useState(null),[z,w]=f.useState(!1),C=f.useCallback(async K=>{if(!e.getCollatedEditionIndex){k(null);return}w(!0);try{const N=await e.getCollatedEditionIndex(K);k(N)}catch{k(null)}finally{w(!1)}},[e]),E=f.useCallback(async K=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){v([]);return}j(!0);try{if(e.getCollectionCatalogs){const N=await e.getCollectionCatalogs(K);v(N||[])}else if(e.getCollectionCatalog){const N=await e.getCollectionCatalog(K);v(N?[{resource_id:"",data:N}]:[])}}catch{v([])}finally{j(!1)}},[e]),R=f.useCallback(async K=>{if(i){i(K);return}c(K),g(null),v([]),k(null),S("detail"),m(!0);try{const N=await e.getItem(K.id);N&&(g(N),N.type==="collection"?E(K.id):N.type==="work"&&N.has_collated&&C(K.id))}catch(N){console.error("加载详情失败:",N)}finally{m(!1)}},[e,i,E,C]),T=f.useCallback(async K=>{g(null),v([]),k(null),S("detail"),m(!0);try{const N=await e.getItem(K);N&&(g(N),c({id:K,title:N.title||K,type:N.type||"book"}),N.type==="collection"?E(K):N.type==="work"&&N.has_collated&&C(K))}catch(N){console.error("导航失败:",N)}finally{m(!1)}},[e,E,C]),O=(u==null?void 0:u.type)==="collection"&&(h.length>0||y)||(u==null?void 0:u.type)==="work"&&(_||z),M=p&&(x||u),W=f.useCallback(()=>{c(null),g(null),v([]),k(null),S("detail")},[]),P=t.jsx(t.Fragment,{children:x?t.jsx(yt,{}):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:()=>S("detail"),style:an(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&y&&h.length===0&&t.jsxs("button",{onClick:()=>{},style:an(!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:an(b===`catalog:${K.resource_id}`),children:K.short_name?`${d(K.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},K.resource_id)),u.type==="work"&&(_||z)&&t.jsxs("button",{onClick:()=>S("collated"),style:an(b==="collated"),children:[l.detailTab.collatedEdition,z&&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(xi,{data:u,transport:e,onNavigate:T}):b.startsWith("catalog:")?t.jsx(fi,{data:(V=h.find(K=>`catalog:${K.resource_id}`===b))==null?void 0:V.data,onNavigate:T}):b==="collated"?t.jsx(Mi,{index:_||void 0,workId:u.id,transport:e,onNavigate:T}):null})]}):t.jsx(ei,{transport:e,onNavigate:T,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:M?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:W,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:P})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Gn,{transport:e,onEntryClick:R,hideModeIndicator:n}),!u&&t.jsx(ei,{transport:e,onNavigate:T,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(Gn,{transport:e,onEntryClick:R,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:P})]})};function an(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 dt(e){return e.replace(/\.md$/,"")}function Ao(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 Wo={padding:24,color:o("desc-fg")},ti=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:d,onVersionChange:p,title:a,subtitle:c,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m,className:b,style:S})=>{const[h,v]=f.useState(e??null),[y,j]=f.useState(!1),[_,k]=f.useState(null),z=r!==void 0?r:_,w=f.useCallback(Q=>{s?s(Q):k(Q)},[s]),[C,E]=f.useState(null),[R,T]=f.useState(!1);f.useEffect(()=>{e&&v(e)},[e]),f.useEffect(()=>{if(e)return;v(null),j(!1);const Q=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!Q){j(!0);return}let H=!1;return Promise.resolve().then(Q).then(te=>{H||(te?v(te):j(!0))}).catch(()=>{H||j(!0)}),()=>{H=!0}},[n,i,e,l]),f.useEffect(()=>{if(!h||h.chapters.length===0)return;const Q=dt(h.chapters[0].file);if(!z){w(Q);return}const H=dt(z);h.chapters.some(pe=>dt(pe.file)===H)||w(Q)},[h,z,w]);const O=f.useMemo(()=>{if(!h||!z)return null;const Q=dt(z);return h.chapters.find(H=>dt(H.file)===Q)??null},[h,z]);f.useEffect(()=>{if(!n||!O)return;const Q=l!==void 0?i.getWorkFullTextChapter?te=>i.getWorkFullTextChapter(n,l,te):null:i.getBookFullTextChapter?te=>i.getBookFullTextChapter(n,te):null;if(!Q)return;let H=!1;return T(!0),E(null),Promise.resolve(O.file).then(Q).then(te=>{H||E(te)}).catch(()=>{H||E(null)}).finally(()=>{H||T(!1)}),()=>{H=!0}},[n,O,i,l]);const M=Ts(u,O?dt(O.file):null),[W,P]=_i(),{convert:V}=Y(),K=!!(d&&d.length>1&&p),N=f.useMemo(()=>K?gs(d).map((Q,H)=>({...Q,label:Ao(d[H])})):void 0,[K,d]),le=K?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:Q=>p(Q.target.value),children:d.map(Q=>t.jsx("option",{value:Q.key,children:Ao(Q)},Q.key))})]}):null;if(!h)return t.jsxs("div",{style:Wo,children:[le&&t.jsx("div",{style:{marginBottom:12},children:le}),y?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:Wo,children:[le&&t.jsx("div",{style:{marginBottom:12},children:le}),"全文目录为空"]});const G=h.chapters.map(Q=>({key:dt(Q.file),label:V(Q.title)})),se=ys(h)||Yn(h),ne=C?C.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs($i,{title:a??V(h.version_label),subtitle:c??"全文",toc:G,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:z?dt(z):null,onSelect:w,images:M.images,imagesLoading:M.loading,renderImageOverlay:g,imagePanel:x,prefs:W,onPrefsChange:P,versions:N,currentVersionKey:N?l??null:void 0,onVersionChange:N?p:void 0,versionSource:!1,paragraphToggle:wn(ne),allowVertical:m,className:b,style:S,children:[O&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:V(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:V(h.source.name)}),h.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),h.source.license]})]})]}),R&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!R&&ne!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Ri,{text:ne,mode:W.readingMode,tables:se,gujiMarkdown:Yn(h),properNames:W.properNames})}),!R&&!C&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},cp=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=de(),{convert:l}=Y(),[d,p]=f.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[a,c]=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(dp,{division:g,expanded:d===g.name,onToggle:()=>p(d===g.name?null:g.name),expandedCat:a,onCatToggle:x=>c(a===x?null:x),onNavigate:n},g.name))})]})},dp=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:d}=Y(),p=e.categories.reduce((a,c)=>{const u=c.stats||{zhulu:0,cunmu:0};return a+(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:d(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(a=>{const c=`${e.name}/${a.name}`;return t.jsx(pp,{category:a,expanded:r===c,onToggle:()=>s(c),onNavigate:l},a.name)})})]})},pp=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var a,c,u,g;const{convert:s}=Y(),l=((a=e.books)==null?void 0:a.zhulu)||[],d=((c=e.books)==null?void 0:c.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((g=e.stats)==null?void 0:g.cunmu)||d.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||d.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Mo,{label:"著錄",books:l,onNavigate:r}),d.length>0&&t.jsx(Mo,{label:"存目",books:d,onNavigate:r})]})]})},Mo=({label:e,books:n,onNavigate:i})=>{const{convert:r}=Y(),s=Pe(),[l,d]=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((a,c)=>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:a.work_id&&i?t.jsx("a",{href:s(a.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},children:r(a.title)}):r(a.title)}),a.volumes&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.volumes)}),a.author&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.author).slice(0,20)})]},c))}),!l&&t.jsxs("button",{onClick:()=>d(!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:xp,children:"AI"}),n&&t.jsx("button",{onClick:n,style:up,children:l.action.save})]})]}),s]})},up={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},xp={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},He=({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"}})]}),ht=({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"}})},gn=({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 fp(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const dn=({value:e,onChange:n,label:i})=>{const[r,s]=f.useState(!1),l=f.useRef(null),d=fp(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&d?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Fo,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:d.name}),t.jsx(gn,{children:d.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Fo,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"}})]})},Fo={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function gp(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function mp(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ls=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=de(),[s,l]=f.useState(null),d=()=>{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)},a=(g,x,m)=>{const b=[...e];b[g]={...b[g],[x]:m},n(b)},c=(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:gp(g.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:mp(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:nt,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>c(x,"bookID"),style:{...Po,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:()=>c(x,"url"),style:{...Po,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:nt,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Oo,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:nt,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Oo,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:g.name,onChange:m=>a(x,"name",m.target.value),placeholder:r.editor.sourceNamePlaceholder,style:vt})]}),t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:g.id,onChange:m=>a(x,"id",m.target.value),placeholder:"https://...",style:vt})]})]}),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:{...nt,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:nt,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:g.details,onChange:m=>a(x,"details",m.target.value),placeholder:r.editor.detailsPlaceholder,style:vt})]}),t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:g.position,onChange:m=>a(x,"position",m.target.value),placeholder:"如: 卷三, p.52",style:vt})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:g.version,onChange:m=>a(x,"version",m.target.value),placeholder:"如: v1.0, 2024-01",style:vt})]}),t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:g.processor_version,onChange:m=>a(x,"processor_version",m.target.value),placeholder:"如: v0.1",style:vt})]})]})]})]})})]},x)),t.jsxs("button",{onClick:d,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})]})]})},nt={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},vt={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"},Po={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"},Oo={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Bs(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 As(e){return!e||e.length===0?"":JSON.stringify(e)}const Ws=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:d,childWorks:p,childCollections:a,containedBooks:c,siblingBooks:u,onLinkEntity:g,onUnlinkEntity:x,onViewEntity:m,onCreateAndLink:b,onSaveRelations:S})=>{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})]}),S&&t.jsx("button",{onClick:S,style:hp,children:h.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Ft,{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(Ft,{direction:"up",title:h.relation.containedInCollection,entity:d,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(kt,{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(Ft,{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(kt,{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}),a&&a.length>0&&t.jsx(kt,{direction:"down",title:`${h.relation.collectionImpl} (${a.length})`,entities:a,onView:m,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(kt,{direction:"down",title:`${h.relation.allVersions} (${(c==null?void 0:c.length)??0})`,entities:c||[],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(Ft,{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(Ft,{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(kt,{direction:"down",title:`${h.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:m,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(kt,{direction:"down",title:`${h.relation.containedBooks} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:m,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},Ft=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:d,linkLabel:p,createLabel:a,notLinkedLabel:c,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:Ms(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(Do,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(Do,{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:c}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(ni,{onClick:l,children:p}),t.jsx(ni,{onClick:d,primary:!0,children:a})]})]})},kt=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:d,expandMoreLabel:p})=>{const[a,c]=f.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),g=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=a?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:Ms(m.type)}),t.jsx("span",{children:m.title})]},m.id)),i.length>5&&!a&&t.jsxs("div",{onClick:()=>c(!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:d}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(ni,{onClick:s,primary:!0,children:["+ ",l]})})]})},Do=({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}),ni=({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 Ms(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const hp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Fs=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:d,onSearch:p,isLoading:a,excludeId:c})=>{const[u,g]=f.useState(""),x=c?d.filter(h=>h.id!==c):d;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:bp,children:t.jsxs("div",{style:yp,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:jp,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:vp})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?t.jsx("div",{style:Bn,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:kp,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:Bn,children:["未找到匹配的",b]}):t.jsxs("div",{style:Bn,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:Sp,children:["创建新",b,"并关联"]})]})]})})},bp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},yp={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")},jp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},vp={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"},kp={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:o("primary-soft")},Bn={padding:"20px",textAlign:"center",color:o("desc-fg")},Sp={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Ho={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},wp={work:"📜",book:"📖",collection:"📚",entity:"👤"},Ps=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[d,p]=f.useState(""),a=f.useRef(null);f.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,m;(x=a.current)==null||x.focus(),(m=a.current)==null||m.select()},100))},[e,r==null?void 0:r.title]);const c=x=>{x.key==="Enter"&&d.trim()?u():x.key==="Escape"&&l()},u=()=>{d.trim()&&s(d.trim(),{...r,title:d.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`创建新${Ho[n]}`}};return t.jsx("div",{style:_p,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:$p,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:wp[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:a,type:"text",value:d,onChange:x=>p(x.target.value),onKeyDown:c,placeholder:`请输入${Ho[n]}名称...`,style:zp})]}),((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:Cp,children:"取消"}),t.jsx("button",{onClick:u,disabled:!d.trim(),style:{...Ip,opacity:d.trim()?1:.6,cursor:d.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},_p={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},$p={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")},zp={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"},Cp={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Ip={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function Tp(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Os(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ep(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 Ds=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:d,onSelect:p,onCancel:a,onCreate:c,onSearch:u})=>{const[g,x]=f.useState(""),[m,b]=f.useState([]),[S,h]=f.useState(!1),[v,y]=f.useState("recent");f.useEffect(()=>{e&&(x(""),b([]),y(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 j=f.useCallback(C=>{x(C.target.value),C.target.value.trim()&&y("search")},[]),_=f.useCallback(C=>s?C.filter(E=>E.id!==s):C,[s]);if(!e)return null;const k=n||(i==="all"?"选择实体":`选择${Os(i)}`),z=_(r),w=_(m);return t.jsx("div",{style:Np,children:t.jsxs("div",{style:Lp,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:k}),t.jsx("button",{onClick:a,style:Bp,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:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Ap}),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:"搜索中..."})]})}),z.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs(Go,{active:v==="recent",onClick:()=>y("recent"),children:["最近使用 (",z.length,")"]}),t.jsxs(Go,{active:v==="search",onClick:()=>y("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:v==="recent"&&z.length>0?t.jsx(Uo,{entities:z,onSelect:p}):g.trim()?S?t.jsx(An,{message:"搜索中..."}):w.length>0?t.jsx(Uo,{entities:w,onSelect:p}):t.jsx(An,{message:"未找到匹配的结果"}):t.jsx(An,{message:"输入关键词开始搜索"})}),l&&c&&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:c,style:Wp,children:d||"创建新实体"})]})]})})},Go=({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}),Uo=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(Rp,{entity:i,onClick:()=>n(i)},i.id))}),Rp=({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:Tp(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:Ep(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Os(e.type)})]})},An=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),Np={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Lp={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")},Bp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Ap={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"},Wp={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Mp={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},Fp={work:"📜",collection:"📚",book:"📖",entity:"👤"},Hs=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:d,onAskAI:p,renderSectionActions:a,onDownloadResource:c,downloadStatuses:u,relations:g,onRelationsChange:x})=>{var q;const m=de(),[b,S]=f.useState(!1),[h,v]=f.useState("work"),[y,j]=f.useState(""),[_,k]=f.useState(""),[z,w]=f.useState([]),[C,E]=f.useState(!1),[R,T]=f.useState(!1),[O,M]=f.useState("work"),[W,P]=f.useState(""),[V,K]=f.useState(),[N,le]=f.useState(!1),[G,se]=f.useState(null),[ne,Q]=f.useState([]);f.useRef(null);const H=e.type,te=H==="work",pe=H==="collection",re=H==="book",ee=f.useCallback((L,I)=>{n({...e,[L]:I})},[e,n]),ye=f.useCallback((L,I)=>{j(L),v(I),k(m.editor.selectToLink+m.indexType[I]),w([]),S(!0)},[m]),ae=f.useCallback(L=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,L)},[r,e.id]),Te=f.useCallback(L=>{s==null||s(L.id,L.type)},[s]),je=f.useCallback((L,I,$)=>{const F={...$,author:($==null?void 0:$.author)||e.author,dynasty:$==null?void 0:$.dynasty};M(I),P(L),K(F),T(!0)},[e.author]),Ce=f.useCallback((L,I)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,W,{type:O,title:L,inheritData:I}),T(!1)},[r,e.id,W,O]),Re=f.useCallback(L=>{if(!L.trim()){w([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(L,h).then(I=>{w(I),E(!1)}).catch(()=>{w([]),E(!1)})},[r,h]),Ie=f.useCallback(L=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,y,L.id),S(!1)},[r,e.id,y]),D=f.useCallback(()=>{i()},[i]),oe=f.useCallback(L=>{se(()=>L),le(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Q).catch(()=>{})},[r]),ie=f.useCallback((L,I)=>r!=null&&r.searchEntities?r.searchEntities(L,I==="all"?void 0:I):Promise.resolve([]),[r]),xe=f.useCallback(L=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(L),Q(I=>[L,...I.filter($=>$.id!==L.id)].slice(0,10)),G==null||G(L),le(!1),se(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:Fp[H]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(gn,{children:e.id}),t.jsx(gn,{color:Mp[H],children:m.indexType[H]})]})}),t.jsx(Ye,{title:m.section.basicInfo,onSave:i,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(dn,{label:te?m.editor.workTitle:pe?m.editor.collectionTitle:m.editor.bookTitle,value:e.title,onChange:L=>ee("title",L)}),re&&t.jsx(dn,{label:m.editor.belongsToWork,value:e.workName||"",onChange:L=>ee("workName",L)}),t.jsx(He,{label:m.editor.authorLabel,value:e.author||"",onChange:L=>ee("author",L)}),t.jsx(He,{label:m.editor.publicationYearLabel,value:e.publicationYear||"",onChange:L=>ee("publicationYear",L)}),(re||pe)&&t.jsx(dn,{label:m.editor.containedIn,value:e.collection||"",onChange:L=>ee("collection",L)}),(re||pe)&&t.jsx(He,{label:m.editor.holderLabel,value:e.holder||"",onChange:L=>ee("holder",L)}),(re||pe)&&t.jsx(He,{label:re?m.editor.pageLabel:m.editor.volumeLabel,value:e.pages||"",onChange:L=>ee("pages",L)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(He,{label:m.editor.firstImageLabel,value:e.firstImage||"",onChange:L=>ee("firstImage",L)})})]})}),t.jsx(Ye,{title:m.section.description,onSave:i,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(ht,{value:e.description||"",onChange:L=>ee("description",L),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(Pp,{items:e.additional_works||[],onChange:L=>ee("additional_works",L)})}),t.jsx(Ye,{title:m.section.indexedBy,onSave:i,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Op,{items:e.indexed_by||[],onChange:L=>ee("indexed_by",L)})}),t.jsx(Ye,{title:m.section.emendatedBy,onSave:i,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Dp,{items:e.emendated_by||[],onChange:L=>ee("emendated_by",L)})}),t.jsx(Ye,{title:m.section.textResources,onSave:i,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(Hn,{items:e.resources||[],onChange:L=>ee("resources",L),onDownload:c,downloadStatuses:u,filterType:"text"})}),t.jsx(Ye,{title:m.section.imageResources,onSave:i,children:t.jsx(Hn,{items:e.resources||[],onChange:L=>ee("resources",L),onDownload:c,downloadStatuses:u,filterType:"image"})}),t.jsx(Ye,{title:m.section.sources,onSave:i,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(Ls,{items:Bs(e.sources||""),onChange:L=>ee("sources",As(L)),onOpenEntityPicker:oe})}),(re||pe)&&t.jsx(Ye,{title:m.section.provenance,onSave:i,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(ht,{value:e.provenance||"",onChange:L=>ee("provenance",L),placeholder:m.editor.provenancePlaceholder})}),re&&t.jsx(Ye,{title:m.section.otherEditions,onSave:i,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(ht,{value:e.otherEditions||"",onChange:L=>ee("otherEditions",L),placeholder:m.editor.otherEditionsPlaceholder})}),t.jsx(Ws,{entityType:H,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:ye,onUnlinkEntity:ae,onViewEntity:Te,onCreateAndLink:je,onSaveRelations:D}),l&&d&&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:d,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(Fs,{isOpen:b,entityType:h,title:_,onSelect:Ie,onCancel:()=>S(!1),onCreate:()=>{S(!1),je(y,h)},searchResults:z,onSearch:Re,isLoading:C,excludeId:e.id}),t.jsx(Ps,{isOpen:R,entityType:O,relationField:W,inheritData:V,onConfirm:Ce,onCancel:()=>T(!1)}),t.jsx(Ds,{isOpen:N,title:m.action.selectBookOrWork,filterType:"all",recentEntities:ne,excludeId:e.id,onSelect:xe,onCancel:()=>{le(!1),se(null)},onSearch:ie})]})};function Pp({items:e,onChange:n}){const i=de(),r=(d,p,a)=>{const c=e.map((u,g)=>g===d?{...u,[p]:a}:u);n(c)},s=d=>n(e.filter((p,a)=>a!==d)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((d,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(He,{label:i.editor.bookNameLabel,value:d.book_title,onChange:a=>r(p,"book_title",a)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(He,{label:i.label.juanCount,value:d.n_juan!=null?String(d.n_juan):"",onChange:a=>r(p,"n_juan",a&&parseInt(a,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 Gs({items:e,onChange:n,showMeta:i,addLabel:r}){const s=de(),[l,d]=f.useState(null),p=(u,g,x)=>{const m=e.map((b,S)=>S===u?{...b,[g]:x||void 0}:b);n(m)},a=u=>{n(e.filter((g,x)=>x!==u)),l===u&&d(null)},c=()=>{n([...e,{source:""}]),d(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:()=>d(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(),a(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(He,{label:s.label.sourceName,value:u.source,onChange:m=>p(g,"source",m)}),t.jsx(He,{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(He,{label:s.label.titleInfo,value:u.title_info||"",onChange:m=>p(g,"title_info",m)}),t.jsx(He,{label:s.label.authorInfo,value:u.author_info||"",onChange:m=>p(g,"author_info",m)})]}),t.jsx(He,{label:s.label.edition,value:u.edition||"",onChange:m=>p(g,"edition",m)})]}),t.jsx(ht,{value:u.summary||"",onChange:m=>p(g,"summary",m),placeholder:s.editor.summaryPlaceholder}),t.jsx(ht,{value:u.comment||"",onChange:m=>p(g,"comment",m),placeholder:s.editor.commentPlaceholder}),t.jsx(ht,{value:u.additional_comment||"",onChange:m=>p(g,"additional_comment",m),placeholder:s.editor.additionalCommentPlaceholder})]})]},g)}),t.jsx("button",{onClick:c,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 Op({items:e,onChange:n}){const i=de();return t.jsx(Gs,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Dp({items:e,onChange:n}){const i=de();return t.jsx(Gs,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function Us(e){var p,a,c,u,g,x,m;const n=((a=(p=e.authors)==null?void 0:p[0])==null?void 0:a.name)||"",i=((c=e.publication_info)==null?void 0:c.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||"",d={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&&(d.parentWorkId=S.id,d.parentWorkName=S.title)}}if(e.type==="book"){const b=e;d.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(d.collectionId=(m=b.contained_in[0])==null?void 0:m.id)}return d}function Hp(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 Gp=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:d,onSave:p,onDelete:a,onNavigate:c,renderLink:u,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:S,onRelationsChange:h,headerExtra:v,className:y,style:j}=e;de();const[_,k]=f.useState(s),z=l?s:_;f.useEffect(()=>{s!==_&&k(s)},[s]);const w=f.useCallback(()=>{const W=z==="view"?"edit":"view";l?l(W):k(W)},[z,l]),[C,E]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(W=>{W&&E(W)})},[i,r]);const R=n||C,T=f.useMemo(()=>R?Us(R):null,[R]),O=l||!n?t.jsx("button",{onClick:w,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:z==="edit"?o("accent-bg"):"transparent",color:o(z==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:z==="view"?"切换到编辑模式":"切换到查看模式",children:z==="view"?"✏️ 编辑":"👁 查看"}):null,M=t.jsxs(t.Fragment,{children:[O,v]});return!R&&!T?t.jsx(yt,{}):z==="view"?t.jsx(xi,{data:R,transport:r,onNavigate:c?W=>c(W):void 0,renderLink:u,headerExtra:M,className:y,style:j}):T?t.jsxs("div",{className:y,style:j,children:[M&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:M}),t.jsx(Hs,{data:T,onChange:d||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:c,showDelete:!!a,onDelete:a,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:S,onRelationsChange:h})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},Vo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Vs=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,l]=f.useState(null),[d,p]=f.useState(""),[a,c]=f.useState(""),[u,g]=f.useState("idle"),[x,m]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{e&&(l(null),p(""),c(""),g("idle"),m(""))},[e]),f.useEffect(()=>{s&&setTimeout(()=>{var y;return(y=b.current)==null?void 0:y.focus()},100)},[s]),f.useEffect(()=>{if(u==="success"){const y=setTimeout(n,2e3);return()=>clearTimeout(y)}},[u,n]),f.useEffect(()=>{if(!e)return;const y=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[e,n]);const S=async()=>{if(!(!s||!d.trim())){g("submitting"),m("");try{await i({type:s,content:d.trim(),...a.trim()?{contact:a.trim()}:{}}),g("success")}catch(y){g("error"),m(y instanceof Error?y.message:"提交失败,请稍后重试")}}};if(!e)return null;const h=s&&d.trim()&&u!=="submitting",v=Vo.find(y=>y.value===s);return t.jsx("div",{style:Up,onClick:y=>{y.target===y.currentTarget&&n()},children:t.jsxs("div",{style:Vp,onClick:y=>y.stopPropagation(),children:[t.jsxs("div",{style:Yp,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:Kp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:Qp,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:Vo.map(y=>t.jsxs("button",{onClick:()=>l(y.value),style:{...qp,...s===y.value?Jp:{}},children:[t.jsx("span",{children:y.icon})," ",y.label]},y.value))}),t.jsx("textarea",{ref:b,value:d,onChange:y=>p(y.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...Zp,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:a,onChange:y=>c(y.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:tu}),t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),u==="error"&&t.jsx("div",{style:eu,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:S,disabled:!h,style:{...Xp,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},Up={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Vp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},Yp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Kp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:o("desc-fg"),padding:"4px 8px",borderRadius:"4px"},qp={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"},Jp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},Zp={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"},Xp={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},Qp={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},eu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginBottom:"12px"},tu={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"},ii="--bim-feedback-fab-offset",oi=48,nu=16,iu=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,d]=f.useState(!1),p=n.bottom??24;return f.useEffect(()=>{if(r||typeof document>"u")return;const a=document.documentElement;return a.style.setProperty(ii,`calc(${p+oi+nu}px + env(safe-area-inset-bottom, 0px))`),()=>{a.style.removeProperty(ii)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...ou,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(Vs,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:i})]})},ou={position:"fixed",width:`${oi}px`,height:`${oi}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"},Yo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ys=({onSubmit:e})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[l,d]=f.useState(""),[p,a]=f.useState("idle"),[c,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())){a("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),a("success"),s(""),d(""),i("bug")}catch(S){a("error"),u(S instanceof Error?S.message:"提交失败,请稍后重试")}}},m=n&&r.trim()&&p!=="submitting",b=Yo.find(S=>S.value===n);return p==="success"?t.jsx("div",{style:Ko,children:t.jsxs("div",{style:cu,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>a("idle"),style:du,children:"继续提交"})]})}):t.jsxs("div",{style:Ko,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Yo.map(S=>t.jsxs("button",{onClick:()=>i(S.value),style:{...ru,...n===S.value?su:{}},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:{...lu}}),t.jsx("input",{type:"text",value:l,onChange:S=>d(S.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:uu}),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:{...au,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:pu,children:c})]})},Ko={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},ru={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"},su={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},lu={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"},au={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},cu={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},du={background:"none",border:"none",color:o("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},pu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginTop:"8px"},uu={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 qo(e){return typeof e=="function"?e():e??"/api/feedback"}const Ks=({resourceId:e,apiUrl:n})=>{const[i,r]=f.useState([]),[s,l]=f.useState(!0),d=f.useCallback(async()=>{const a=qo(n);l(!0);try{const u=await(await fetch(`${a}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);f.useEffect(()=>{d()},[d]);const p=async a=>{const c=qo(n),u=await fetch(c,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,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(()=>d(),500)};return t.jsxs("div",{children:[t.jsx(Fi,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Ys,{onSubmit:p})})]})},Jo={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 Zo(e){return e?Jo[e]??e:Jo.related}const xu={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function fu(e){return xu[e]??e}const gu={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function mu(e){return gu[e]??""}function Pi({authors:e,onNavigate:n,renderLink:i}){const{convert:r}=Y(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,d)=>{const p=yi(l.role);return t.jsxs(f.Fragment,{children:[d>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)})]},d)})}):null}function qs(e,n){var p,a;const i=hi(e,n),r=i.mirrors.map(c=>({key:c.key,label:c.label,description:c.description,rows:c.items.filter(u=>u.group_role!=="mirror"),mirrors:c.items.filter(u=>u.group_role==="mirror")})),s=i.buckets.filter(c=>c.key==="image"||c.key==="textImage").flatMap(c=>c.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=i.buckets.find(c=>c.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((a=i.buckets.find(c=>c.key==="text"))==null?void 0:a.items)??[],groups:r}}function Js(e,n){const i=(e.url?Et(e.url):void 0)||e.name,r=Ar(e,n);return r?`${i}(${r})`:i}function Oi({item:e,siblings:n,listedVolumeCounts:i}){const{convert:r}=Y(),[s,l]=f.useState(!1),d=mn(e),p=!!d&&d.expected>0&&!(i!=null&&i.has(d.expected)),a=r(Js(e,n)),c=Rt(e),u=jn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[c?t.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",children:[a," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:a}),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(ki,{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?"收起分冊":`展開 ${d.expected} 冊`)})})]})}function Zs({groups:e,listedVolumeCounts:n}){const{convert:i}=Y();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(Oi,{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 d=Rt(s),p=i(Js(s,r.mirrors));return d?t.jsxs("a",{href:d,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 Ut=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function ri(e){var i;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(i=Ut.find(r=>n.startsWith(r.key[0])))==null?void 0:i.key}const Xo=12,hu=60,Xs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:d,railLinks:p})=>{var Ce,Re,Ie;const a=de(),{convert:c}=Y(),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(""),[v,y]=f.useState(!1),j=u.length<=hu,_=j||m||!!S||v,k=f.useMemo(()=>_?u:u.slice(0,Xo),[u,_]);f.useEffect(()=>{if(!n||k.length===0)return;const D=k.filter(ie=>!g.has(ie));if(D.length===0)return;let oe=!1;return Promise.all(D.map(ie=>n.getItem(ie).then(xe=>{const q=xe??{};return[ie,{id:ie,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(()=>[ie,{id:ie}]))).then(ie=>{oe||x(xe=>{const q=new Map(xe);for(const[L,I]of ie)q.set(L,I);return q})}),()=>{oe=!0}},[n,k,g]);const z=f.useMemo(()=>u.map(D=>g.get(D)??{id:D}),[u,g]),w=u.length>0&&u.every(D=>g.has(D)),C=!!n&&k.some(D=>!g.has(D)),E=j||_,R=f.useMemo(()=>Mr(z,e.version_graph,{era:S,scanOnly:v,sort:E?"year":"default"}),[z,e.version_graph,S,v,E]),T=m?R.rows:R.rows.slice(0,Xo),O=R.allRows.filter(D=>D.hasImage).length,M=e.related_works||[],W=M.filter(D=>D.relation==="collected_in"),P=f.useMemo(()=>{const D=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],oe=ie=>{const xe=D.indexOf(ie??"");return xe<0?D.length:xe};return M.filter(ie=>ie.relation!=="collected_in").map((ie,xe)=>({r:ie,i:xe})).sort((ie,xe)=>oe(ie.r.relation)-oe(xe.r.relation)||ie.i-xe.i).map(ie=>ie.r)},[M]),V=f.useMemo(()=>{const D=hi(e.resources,e.resource_groups);return[...D.mirrors.flatMap(oe=>oe.items.map(ie=>({r:ie,kind:c(oe.label)}))),...D.buckets.flatMap(oe=>oe.items.map(ie=>({r:ie,kind:c(mu(oe.key))})))]},[e.resources,e.resource_groups,c]),K=e.indexed_by||[],N=e.emendated_by||[],le=f.useMemo(()=>{var F,A,Z;const D=[],oe=(A=(F=e.authors)==null?void 0:F[0])==null?void 0:A.dynasty;oe&&D.push({label:"成書",value:c(oe)});const ie=st(e,a.unit.juan);if(ie){const J=(Z=e.juan_count)==null?void 0:Z.description;D.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[c(ie),J&&J!==ie?t.jsxs("span",{className:"bim-d-meta",children:["(",c(J),")"]}):null]})})}e.loss_status&&D.push({label:"存佚",value:c(fu(e.loss_status))});const xe=R.allRows.filter(J=>J.sortYear!=null),q=xe.length>0?xe.reduce((J,fe)=>J.sortYear<=fe.sortYear?J:fe):null;q!=null&&q.era.era?D.push({label:"最早存世",value:c([q.era.era,q.era.reign].filter(Boolean).join(" ")),title:q.era.source==="edition"?c("據版本題名推斷"):void 0}):C&&D.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":c("載入中"),children:"…"})}),N.length&&D.push({label:"考證",value:`${N.length} ${c("條")}`});const L=Qo(e.additional_titles);L.length&&D.push({label:"又名",value:L.map(c).join("、")});const I=Qo(e.attached_texts);I.length&&D.push({label:"附載",value:I.map(c).join("、")});const $=(e.additional_works||[]).map(J=>c(J.book_title)+(J.n_juan!=null?` ${J.n_juan}${c(a.unit.juan)}`:""));return $.length&&D.push({label:"附錄",value:$.join("、")}),D},[e,c,a,C,R.allRows,N.length]),se=[{value:e._edition_count??u.length,label:"版本"},{value:w?O:0,label:"有影印"},{value:K.length,label:"家著錄"}],ne=e.classification,Q=ne?[ne.l1,ne.l2,ne.l3,ne.l4].filter(Boolean).map(D=>c(D)):[],H=e.subtype?c(a.workSubtype[e.subtype]??e.subtype):"",te=t.jsx(Jt,{title:c(e.title),byline:t.jsx(Pi,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(Be,{items:[...Q,ne!=null&&ne.source?c(`據《${ne.source.split("/")[0]}》`):"",H]}),description:(Ce=e.description)!=null&&Ce.text?t.jsxs(t.Fragment,{children:[t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Re=e.description.sources)!=null&&Re.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(D=>c(nc(D))).filter(Boolean).join(" · ")}):null]}):void 0,stats:se,facts:le,readAction:s,foot:t.jsx(Zt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Ie=e.appendix)==null?void 0:Ie.map((D,oe)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:c(D.title)}),t.jsx(rt,{text:D.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},oe))}),pe=R.eras.length>=2?[{key:"",label:a.catalog.all},...R.eras.map(D=>({key:D,label:`${D} ${R.allRows.filter(oe=>oe.era.era===D).length}`}))]:[],re=[];u.length&&re.push({id:"versions",label:"版本",count:u.length}),K.length&&re.push({id:"catalogs",label:"著錄",count:K.length}),W.length&&re.push({id:"collected",label:"收入叢編",count:W.length}),P.length&&re.push({id:"related",label:"相關書目",count:P.length}),V.length&&re.push({id:"resources",label:"在線資源",count:V.length});const ee=u.length===0&&K.length===0,ye=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Fe,{id:"versions",title:"版本",meta:t.jsx(Be,{items:[c(`共 ${u.length} 種`),w&&O?c(`${O} 種有影印`):"",R.rows.length!==R.allRows.length?c(`當前 ${R.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":C&&pe.length===0&&u.length>1?"":void 0,children:[pe.length>0&&t.jsx(kn,{items:pe,value:S,onChange:D=>{h(D),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Jr,{label:"只看有影印",checked:v,onChange:D=>{y(D),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(E?"按年代排列":"按著錄順序")})]}),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:c("版本")}),t.jsx("th",{children:c("年代")}),t.jsx("th",{children:c("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:c("影印")})})]})}),t.jsx("tbody",{children:T.map(D=>{var oe;return t.jsx(bu,{row:D,measure:(oe=g.get(D.id))==null?void 0:oe.measure_info,loaded:g.has(D.id),onNavigate:i,renderLink:r},`${D.id}:${g.has(D.id)?"r":"p"}`)})})]}),T.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(S||v?"當前篩選下沒有版本":"暫無版本著錄")}),R.rows.length>T.length&&t.jsx(Nt,{label:`展開其餘 ${R.rows.length-T.length} 種版本`,onClick:()=>b(!0)}),R.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("部分年代據版本題名推斷,非著錄原文")})]}),K.length>0&&t.jsx(yu,{items:K,transport:n,onNavigate:i,renderLink:r}),ee&&t.jsx(Fe,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該作品的版本與書目收錄。")})})]}),ae=(D,oe)=>t.jsx(Le,{id:D,label:c(oe),onNavigate:i,renderLink:r,dense:!0}),Te=f.useMemo(()=>{const D=new Map;for(const oe of P){const ie=Zo(oe.relation);D.set(ie,(D.get(ie)??0)+1)}return D.size>1?[...D.entries()].sort((oe,ie)=>ie[1]-oe[1]).slice(0,4).map(([oe,ie])=>`${c(oe)} ${ie}`).join(" · "):void 0},[P,c]),je=t.jsxs(t.Fragment,{children:[t.jsx(mt,{id:"collected",title:"收入叢編",items:W.map(D=>ae(D.id,D.title))}),t.jsx(mt,{id:"related",title:"相關書目",meta:c(`${P.length} 部`),sub:Te,items:P.map(D=>t.jsxs(t.Fragment,{children:[ae(D.id,D.title),t.jsx("span",{className:"bim-d-meta",title:D.note?c(D.note):void 0,children:c(Zo(D.relation))})]}))}),t.jsx(mt,{id:"resources",title:"在線資源",cap:6,items:V.map(({r:D,kind:oe})=>{const ie=c((D.url?Et(D.url):void 0)||D.name),xe=Rt(D);return t.jsxs(t.Fragment,{children:[xe?t.jsxs("a",{href:xe,target:"_blank",rel:"noopener noreferrer",children:[ie," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:ie}),oe&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:oe})]})})})]});return t.jsx(qt,{railTop:l,back:d,nav:re,railLinks:p,main:ye,card:te,side:je})};function Qo(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function er(e,n){return n((e.url?Et(e.url):void 0)||e.name)}function bu({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=Y(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",a=e.holders[0],c=a?er(a,l):e.locationName?l(e.locationName):"",u=e.images[0],g=u?Rt(u):void 0,x=e.images.map(m=>er(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${d?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:d?l(d):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${c?"":" bim-d-zt-blank"}`,children:[c||(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 yu({items:e,transport:n,onNavigate:i,renderLink:r}){const s=de(),{convert:l}=Y(),[d,p]=f.useState(0),a=Math.min(d,e.length-1),c=e[a],[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,v;return[b,((v=(h=S==null?void 0:S.authors)==null?void 0:h[0])==null?void 0:v.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(Be,{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===a,"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:[c.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:l(c.title_info)}),t.jsx(Be,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[c.source_bid?t.jsx(Le,{id:c.source_bid,label:l(c.source),onNavigate:i,renderLink:r,dense:!0}):l(c.source),c.section?l(c.section):"",c.author_info?`${l(s.label.authorInfo)} ${l(c.author_info)}`:"",c.edition?`${l(s.label.edition)} ${l(c.edition)}`:"",c.page??""]}),c.summary&&t.jsx("p",{className:"bim-d-quote",children:Ge(l(c.summary))}),c.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:Ge(l(c.comment))})]}),c.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:Ge(l(c.additional_comment))})]}),!c.summary&&!c.comment&&!c.additional_comment&&!c.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:[a>0?t.jsx("button",{type:"button","aria-label":l(`上一家:${e[a-1].source}`),onClick:()=>p(a-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",l(e[a-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[a+1," / ",e.length]}),a<e.length-1?t.jsx("button",{type:"button","aria-label":l(`下一家:${e[a+1].source}`),onClick:()=>p(a+1),children:t.jsxs("span",{"aria-hidden":"true",children:[l(e[a+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}const tr=40,nr=2,ju=9,ir={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function Wn(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Qs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,fullText:l,fullTextPending:d,chapterLink:p,railTop:a,back:c,railLinks:u})=>{var q,L,I,$,F,A,Z,J,fe,we,_e,Ne,Ee,Lt;const g=de(),{convert:x}=Y(),[m,b]=f.useState(null),[S,h]=f.useState(new Map),[v,y]=f.useState([]),[j,_]=f.useState(new Map),[k,z]=f.useState(!1);f.useEffect(()=>{if(!n||!e.work_id){b(null);return}let B=!1;return n.getItem(e.work_id).then(ce=>{!B&&ce&&ce.type==="work"&&b(ce)}).catch(()=>{}),()=>{B=!0}},[n,e.work_id]),f.useEffect(()=>{const B=e.contained_in||[];if(!n||B.length===0){h(new Map);return}let ce=!1;return Promise.all(B.map(ue=>{const ve=typeof ue=="string"?ue:ue.id;return n.getItem(ve).then(he=>[ve,he]).catch(()=>[ve,null])})).then(ue=>{if(ce)return;const ve=new Map;for(const[he,ge]of ue)ge&&ve.set(he,ge);h(ve)}),()=>{ce=!0}},[n,e.contained_in]);const w=f.useMemo(()=>{const B=new Set([...(m==null?void 0:m.books)||[],...e.related_books||[]]);return B.add(e.id),[...B]},[m==null?void 0:m.books,e.related_books,e.id]),C=w.length-1;f.useEffect(()=>{if(!n||C<=0){y([]);return}const B=w.length<=tr,ce=B?w:w.slice(0,8);let ue=!1;return Promise.all(ce.map(ve=>ve===e.id?Promise.resolve({id:ve,title:e.title,edition:e.edition,year:xn(e)}):n.getItem(ve).then(he=>{const ge=he??{};return{id:ve,title:ge.title,edition:ge.edition,year:he?xn(ge):void 0}}).catch(()=>({id:ve})))).then(ve=>{if(ue)return;const he=ve.filter(ge=>ge.id===e.id||ge.title||ge.edition);B&&he.sort((ge,Ae)=>(ge.year??1/0)-(Ae.year??1/0)),y(he)}),()=>{ue=!0}},[n,w,C,e]);const E=e.lineage,R=f.useMemo(()=>[...((E==null?void 0:E.derived_from)||[]).filter(B=>B.ref_type==="book").map(B=>B.ref),...((E==null?void 0:E.related_to)||[]).map(B=>B.book_id)].filter(Boolean),[E]);f.useEffect(()=>{if(!n||R.length===0){_(new Map);return}let B=!1;return Promise.all(R.map(ce=>n.getItem(ce).then(ue=>[ce,{id:ce,title:ue==null?void 0:ue.title,edition:ue==null?void 0:ue.edition}]).catch(()=>[ce,{id:ce}]))).then(ce=>{B||_(new Map(ce))}),()=>{B=!0}},[n,R]);const T=f.useMemo(()=>qs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),O=T.groups.reduce((B,ce)=>B+ce.rows.length+ce.mirrors.length,0),M=T.groups.length>0&&T.groups.every(B=>B.key==="_physical"),W=Kt(e),P=Hr(e),V=st(e,g.unit.juan),K=new Set((e.contained_in||[]).map(B=>typeof B=="string"?0:Ht(B.volume_index).length).filter(B=>B>0)),N=B=>{var ve;const ce=(ve=e.base_edition)==null?void 0:ve.find(he=>he.book_id===B&&he.name);if(ce!=null&&ce.name)return ce.name;const ue=j.get(B);return(ue==null?void 0:ue.edition)||(ue==null?void 0:ue.title)||""},le=f.useMemo(()=>{var ut,lt,en,at,tn;const B=[];P&&B.push({label:"版本類型",value:x(P),title:e.edition_type||(ut=e.lineage)!=null&&ut.category?void 0:x("據版本題名推斷")}),(lt=e.publication_info)!=null&&lt.details?B.push({label:"刊印",value:x(e.publication_info.details)}):(W.era||W.reign)&&B.push({label:"刊寫年代",value:x([W.era,W.reign].filter(Boolean).join(" ")),title:W.source==="edition"?x("據版本題名推斷"):void 0}),V&&B.push({label:"卷帙",value:x(V)});const ce=(e.contained_in||[]).flatMap(ke=>typeof ke=="string"?[]:Ht(ke.volume_index));ce.length&&B.push({label:"冊次",value:x(`第 ${vn(ce,g.unit.volume)} ${g.unit.volume}(${ce.length} ${g.unit.volume})`)});const ue=(((en=e.lineage)==null?void 0:en.derived_from)||[]).find(ke=>ke.relation==="底本"&&ke.ref_type==="book");ue&&N(ue.ref)&&B.push({label:"底本",value:t.jsx(Le,{id:ue.ref,label:x(N(ue.ref)),onNavigate:i,renderLink:r,dense:!0})});const ve=(e.base_edition||[]).filter(ke=>ke&&ke.name);for(const ke of["底本","配補","參校"]){if(ke==="底本"&&ue&&N(ue.ref))continue;const Ue=ve.filter(ze=>ze.role===ke);Ue.length&&B.push({label:ke,value:Ue.map((ze,nn)=>t.jsxs(f.Fragment,{children:[nn>0&&"、",ze.book_id?t.jsx(Le,{id:ze.book_id,label:x(ze.name),onNavigate:i,renderLink:r,dense:!0}):x(ze.name)]},nn))})}const he=(e.provenance||[]).filter(ke=>ke&&ke.institution),ge=(e.resources||[]).filter(ke=>(ke.types||(ke.type?[ke.type]:[])).includes("physical"));if(he.length){B.push({label:"存藏",value:he.slice(0,2).map(ze=>x(ze.institution)).join("、")+(he.length>2?x(` 等 ${he.length} 處`):"")});const ke=he.filter(ze=>ze.call_number).slice(0,2).map(ze=>`${x(ze.institution)} ${ze.call_number}`);ke.length&&B.push({label:"索書號",value:ke.join(";")+(he.filter(ze=>ze.call_number).length>2?"…":"")});const Ue=he.flatMap(ze=>ze.seals||[]).filter(Boolean);Ue.length&&B.push({label:"藏印",value:x(Ue.join("、"))})}else ge.length?B.push({label:"存藏",value:ge.slice(0,2).map(ke=>x(ke.name)).join("、")+(ge.length>2?x(` 等 ${ge.length} 處`):"")}):(at=e.current_location)!=null&&at.name&&B.push({label:"存藏",value:x(e.current_location.name)});const Ae=e.physical_description;if(Ae){const ke=[["行款",Ae.leaf_style],["裝幀",Ae.binding],["尺寸",Ae.dimensions],["品相",Ae.condition]];for(const[Ue,ze]of ke)ze&&ze.trim()&&B.push({label:Ue,value:x(ze)})}(tn=e.page_count)!=null&&tn.description&&B.push({label:g.label.pageCount,value:x(e.page_count.description)});const tt=[...Zn(e.additional_titles),...Zn(e.attached_texts)];return tt.length&&B.push({label:"又名",value:tt.map(x).join("、")}),B},[e,x,g,W,P,V,j,i,r]),G=x(e.title),se=e.edition?x(e.edition):void 0,ne=((q=e.lineage)==null?void 0:q.year_text)||"",Q=t.jsx(Jt,{kind:"版本",title:G,subtitle:se,byline:t.jsx(Pi,{authors:e.authors??(m==null?void 0:m.authors),onNavigate:i,renderLink:r}),meta:t.jsx(Be,{items:[P?x(P):"",W.era?x([W.era,W.reign].filter(Boolean).join("")):"",V?x(V):""]}),description:(L=e.description)!=null&&L.text?t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ji((I=e.description)==null?void 0:I.text)?6:void 0,facts:le,readAction:s,secondaryAction:s&&O>0&&!M?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(Zt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),H=e.contained_in||[],te=(l==null?void 0:l.chapters)||[],pe=te[0]&&Wn(te[0].title)[0].slice(-1)||"章",re=!!(($=E==null?void 0:E.derived_from)!=null&&$.length||(F=E==null?void 0:E.related_to)!=null&&F.length||(A=e.appendix)!=null&&A.length),ee=[];(te.length||T.text.length||d)&&ee.push({id:"fulltext",label:"全文",count:te.length?x(`${te.length} ${pe}`):void 0}),T.groups.length&&ee.push({id:"images",label:M?"館藏":"影印",count:O}),re&&ee.push({id:"lineage",label:"版本源流"}),H.length&&ee.push({id:"collections",label:"收入叢編",count:H.length}),(Z=e.location_history)!=null&&Z.length&&ee.push({id:"provenance",label:"流轉歷史"});const ye=B=>(p==null?void 0:p(B))??null,ae=te[0],Te=ae?ye(ae.file):null,je=k?te:te.slice(0,ju),Ce=(B,ce,ue)=>B?t.jsx("a",{className:ue,href:B.href??"#",onClick:B.onClick?ve=>{ve.metaKey||ve.ctrlKey||(ve.preventDefault(),B.onClick())}:void 0,children:ce}):t.jsx("span",{className:ue,children:ce}),Re=t.jsxs(t.Fragment,{children:[(te.length>0||T.text.length>0||d)&&t.jsxs(Fe,{id:"fulltext",title:"全文",meta:te.length>0?t.jsx(Be,{items:[x(`${te.length} ${pe}`),(J=l==null?void 0:l.source)!=null&&J.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[d&&!ae&&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"})]}),ae&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${Wn(ae.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((ae.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),Ce(Te,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),te.length>1&&t.jsx("ul",{className:"bim-d-chap",children:je.map(B=>{const[ce,ue]=Wn(B.title);return t.jsx("li",{children:Ce(ye(B.file),t.jsxs(t.Fragment,{children:[ce&&t.jsx("b",{children:x(ce)}),x(ue||B.file)]}))},B.file)})}),te.length>je.length&&t.jsx(Nt,{label:`展開其餘 ${te.length-je.length} ${pe}`,onClick:()=>z(!0)}),T.text.length>0&&t.jsxs(t.Fragment,{children:[(te.length>0||d)&&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:T.text.map((B,ce)=>t.jsx(Oi,{item:B,siblings:T.text,listedVolumeCounts:K},`${B.id||B.url||B.name}-${ce}`))})})]})]}),T.groups.length>0&&t.jsx(Fe,{id:"images",title:M?"館藏":"影印",meta:t.jsx(Be,{items:[T.groups.length>1?x(`${T.groups.length} 組`):"",x(`${O} 處`)]}),children:t.jsx(Zs,{groups:T.groups,listedVolumeCounts:K})}),re&&t.jsxs(Fe,{id:"lineage",title:"版本源流",meta:(fe=E==null?void 0:E.derived_from)!=null&&fe.length?x("據版本傳承著錄"):void 0,children:[t.jsxs("ul",{className:"bim-d-tl",children:[((E==null?void 0:E.derived_from)||[]).map((B,ce)=>{const ue=B.ref_type==="book"?N(B.ref):"";return t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(B.relation)}),B.ref_type==="book"?t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(Le,{id:B.ref,label:x(ue||B.ref),onNavigate:i,renderLink:r,dense:!0})}):t.jsx("span",{className:"bim-d-tl-t",children:x("擬構祖本")}),(B.evidence||B.confidence)&&t.jsxs("span",{className:"bim-d-tl-ev",children:[B.evidence?x(B.evidence):"",B.confidence&&ir[B.confidence]?x(`(${ir[B.confidence]})`):""]})]},`d-${ce}`)}),(we=E==null?void 0:E.derived_from)!=null&&we.length||(_e=E==null?void 0:E.related_to)!=null&&_e.length?t.jsxs("li",{className:"bim-d-tl-cur",children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("本版")}),t.jsx("span",{className:"bim-d-tl-t",children:se||G}),ne&&t.jsxs("span",{className:"bim-d-meta",children:[t.jsx("span",{className:"bim-d-dot"}),x(ne)]})]}):null,((E==null?void 0:E.related_to)||[]).map((B,ce)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(B.relation)}),t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(Le,{id:B.book_id,label:x(N(B.book_id)||B.book_id),onNavigate:i,renderLink:r,dense:!0})}),B.evidence&&t.jsx("span",{className:"bim-d-tl-ev",children:x(B.evidence)})]},`r-${ce}`)),(Ne=e.appendix)==null?void 0:Ne.map((B,ce)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("附記")}),t.jsx("span",{className:"bim-d-tl-t",children:x(B.title)}),t.jsxs("details",{children:[t.jsx("summary",{className:"bim-d-ui",children:x("展開")}),t.jsx(rt,{text:B.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]})]},`a-${ce}`))]}),(E==null?void 0:E.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"10px 0 0",maxWidth:"46em"},children:x(E.note)})]}),H.length>0&&t.jsx(Fe,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:H.map((B,ce)=>{var Ae,tt;const ue=typeof B=="string"?B:B.id,ve=typeof B=="string"?[]:Ht(B.volume_index),he=S.get(ue),ge=(he==null?void 0:he._member_count)||((Ae=he==null?void 0:he.books)==null?void 0:Ae.length)||((tt=he==null?void 0:he.contained_works)==null?void 0:tt.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Le,{id:ue,label:he?x(he.title):ue,onNavigate:i,renderLink:r,dense:!0}),ve.length>0&&t.jsx(vu,{volumes:ve,unit:g.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ge?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ge>0&&x(`全 ${ge} ${g.unit.bu}`)})]},`${ue}-${ce}`)})})})}),(Ee=e.location_history)!=null&&Ee.length?t.jsx(Fe,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((B,ce)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(B.name)}),([B.start_date,B.end_date].filter(Boolean).join("—")||B.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(Be,{items:[[B.start_date,B.end_date].filter(Boolean).join("—"),B.description?x(B.description):""]})})]},ce))})}):null,ee.length===0&&t.jsx(Fe,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),Ie=v.findIndex(B=>B.id===e.id),D=w.length<=tr,oe=D&&Ie>=0?v.slice(Math.max(0,Ie-nr),Ie+nr+1):v.filter(B=>B.id!==e.id),ie=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(Be,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(m.authors||[]).slice(0,2).map(B=>`${B.dynasty?`〔${x(B.dynasty)}〕`:""}${x(B.name)}`),x(st(m,g.unit.juan)),m._edition_count?x(`${m._edition_count} 種版本`):""]}),((Lt=m.description)==null?void 0:Lt.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,""))})]}),C>0&&oe.length>0&&t.jsxs("div",{children:[t.jsx(mt,{id:"siblings",title:D?"同作品版本":g.relation.siblingVersions,meta:x(D?"按年代":`${C} 種`),cap:oe.length,items:oe.map(B=>B.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(B.edition||B.title||B.id)}):t.jsx(Le,{id:B.id,label:x(B.edition||B.title||B.id),onNavigate:i,renderLink:r,dense:!0})),metas:oe.map(B=>[B.year!=null?B.year<0?`前${-B.year}`:String(B.year):"",B.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:oe.findIndex(B=>B.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(`在作品頁看全部 ${w.length} 種 →`),onNavigate:i,renderLink:r,dense:!0})})]})]}),xe=e.work_id?t.jsx(qr,{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(qt,{railTop:a,back:c,up:xe,nav:ee,railLinks:u,main:Re,card:Q,side:ie})};function vu({volumes:e,unit:n}){const{convert:i}=Y();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${vn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}const Mn=16,ku=200,Su=16,el=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,railTop:d,back:p,railLinks:a})=>{var D,oe,ie,xe,q,L,I;const c=de(),{convert:u}=Y(),[g,x]=f.useState(""),[m,b]=f.useState(!1),[S,h]=f.useState(null),[v,y]=f.useState(""),j=f.useMemo(()=>Or(e,n),[e,n]),[_,k]=f.useState(new Map),z=!!i&&j.rows.length>0&&j.rows.length<=ku,w=z&&j.rows.every($=>!$.id||_.has($.id)),C=$=>{var F;return ri($?(F=_.get($))==null?void 0:F.l1:void 0)},E=f.useMemo(()=>{const $=g.trim(),F=$?u($):"";return j.rows.filter(A=>{var J,fe;if(v&&ri(A.id?(J=_.get(A.id))==null?void 0:J.l1:void 0)!==v)return!1;if(!F)return!0;const Z=A.id&&((fe=_.get(A.id))==null?void 0:fe.title)||A.title;return u(Z).includes(F)||(A.subItems||[]).some(we=>u(we).includes(F))})},[j.rows,g,v,_,u]),R=m?E:E.slice(0,Mn),T=f.useMemo(()=>(z?j.rows:R).filter($=>$.id&&!_.has($.id)).map($=>$.id),[z,j.rows,R,_]);f.useEffect(()=>{if(!i||T.length===0)return;let $=!1;const F=T.slice(0,Su);return Promise.all(F.map(A=>i.getItem(A).then(Z=>{var we,_e;const J=Z??{},fe={title:J.title,edition:J.edition,authors:J.authors,measure:Z?st(Z,c.unit.juan):void 0,versionCount:J._edition_count??((we=J.books)==null?void 0:we.length),l1:((_e=J.classification)==null?void 0:_e.l1)||void 0};return[A,fe]}).catch(()=>[A,{}]))).then(A=>{$||k(Z=>{const J=new Map(Z);for(const[fe,we]of A)J.set(fe,we);return J})}),()=>{$=!0}},[i,T,c.unit.juan]);const O=(e.contained_in||[])[0];f.useEffect(()=>{if(!O){h(null);return}if(h({id:O}),!i)return;let $=!1;return i.getItem(O).then(F=>{$||h({id:O,title:F==null?void 0:F.title})}).catch(()=>{}),()=>{$=!0}},[i,O]);const M=f.useMemo(()=>qs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),W=M.text.length+M.groups.reduce(($,F)=>$+F.rows.length+F.mirrors.length,0),P=e.contained_works||[],V=new Set(j.rows.map($=>$.id).filter(Boolean)),K=P.length>0&&!P.every($=>V.has($.id)),N=(()=>{const $=j.rows.map(F=>F.edition).filter(Boolean);return $.length>1&&new Set($).size===1})(),le=j.rows.some($=>$.volumes.length>0||$.expected!=null),G=e._member_count||((D=e.books)==null?void 0:D.length)||P.length,se=st(e,c.unit.juan),ne=e.count,Q=$=>typeof $=="number"&&Number.isFinite($)?$:null,H=Q(ne==null?void 0:ne.juan)??Q((oe=e.juan_count)==null?void 0:oe.number),te=Q(ne==null?void 0:ne.ce)??(j.totalVolumes||null),pe=[{value:j.rows.length,label:"子目"},{value:H??0,label:c.unit.juan},{value:te??0,label:c.unit.volume}],re=f.useMemo(()=>{var A,Z;const $=[];if((A=e.publication_info)!=null&&A.details&&$.push({label:"刊印",value:u(e.publication_info.details)}),G&&G!==j.rows.length){const J=e._member_type==="Book"?"所收版本":e._member_type==="Work"?"所收作品":"成員";$.push({label:u(J),value:`${G} ${u(c.unit.bu)}`,title:u("子目與其各版本合計")})}const F=[Q(ne==null?void 0:ne.zhong)!=null?`${ne.zhong} 種`:"",Q(ne==null?void 0:ne.han)!=null?`${ne.han} 函`:""].filter(Boolean);return F.length&&$.push({label:"應收",value:u(F.join(" "))}),H==null&&se&&$.push({label:"卷帙",value:u(se),title:(Z=e.juan_count)!=null&&Z.description?u(e.juan_count.description):void 0}),$},[e,G,j.rows.length,H,se,ne,u,c]),ee=f.useMemo(()=>{if(!w)return[];const $=new Map;for(const A of j.rows){const Z=C(A.id);Z&&$.set(Z,($.get(Z)??0)+1)}const F=Ut.filter(A=>($.get(A.key)??0)>0);return F.length<2?[]:[{key:"",label:`${c.catalog.all} ${j.rows.length}`},...F.map(A=>({key:A.key,label:`${A.label} ${$.get(A.key)}`}))]},[w,j.rows,_,c]),ye=f.useMemo(()=>{if(!w||!j.rows.some(Z=>Z.volumes.length>0))return null;const $=[],F=j.rows.filter(Z=>Z.volumes.length>0).map(Z=>({k:C(Z.id)??"",from:Math.min(...Z.volumes),to:Math.max(...Z.volumes)})).sort((Z,J)=>Z.from-J.from);for(const Z of F){const J=Z.to-Z.from+1,fe=$[$.length-1];fe&&fe.key===Z.k?(fe.to=Math.max(fe.to,Z.to),fe.n+=J):$.push({key:Z.k,from:Z.from,to:Z.to,n:J})}const A=F.reduce((Z,J)=>Math.max(Z,J.to),0);return $.length>1&&$.some(Z=>Z.key)?{segs:$,last:A}:null},[w,j.rows,_]),ae=(ie=e.description)==null?void 0:ie.text,Te=t.jsx(Jt,{kind:"叢編",title:u(e.title),byline:t.jsx(Pi,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Be,{items:[e.subtype==="work_collection"?u("作品集"):"",(xe=e.publication_info)!=null&&xe.year?u(e.publication_info.year):""]}),description:ae||(q=e.history)!=null&&q.length?t.jsxs(t.Fragment,{children:[ae&&t.jsx(rt,{text:ae,style:{fontSize:15,lineHeight:1.85}}),(L=e.history)!=null&&L.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map(($,F)=>t.jsx("li",{children:u($)},F))}):null]}):void 0,clampDescription:ji(ae)||(((I=e.history)==null?void 0:I.length)??0)>2?6:void 0,stats:pe,facts:re,foot:t.jsx(Zt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ye&&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:ye.segs.map(($,F)=>{const A=Ut.find(Z=>Z.key===$.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!A,title:A?u(`${A.label} 第 ${$.from}–${$.to} 冊`):void 0,"aria-label":u(A?`只看${A.label}`:"未分類"),"aria-pressed":!!A&&v===$.key,style:{flexGrow:$.n,background:o(A?A.token:"rule")},onClick:()=>{A&&(y(v===$.key?"":$.key),b(!1))}},F)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:u(`第 1 ${c.unit.volume}`)}),t.jsx("span",{children:u("點色段篩選部類")}),t.jsx("span",{children:u(`第 ${ye.last} ${c.unit.volume}`)})]})]})}),je=[];j.rows.length&&je.push({id:"titles",label:"子目",count:j.rows.length}),W&&je.push({id:"resources",label:"影印與全文",count:W}),K&&je.push({id:"works",label:c.section.containedWorks,count:P.length});const Ce=t.jsxs(t.Fragment,{children:[j.rows.length>0&&t.jsxs(Fe,{id:"titles",title:"子目",meta:t.jsx(Be,{items:[u(`${j.rows.length} ${c.unit.items}`),j.totalVolumes?u(`全帙 ${j.totalVolumes} ${c.unit.volume}`):"",E.length!==j.rows.length?u(`當前 ${E.length} ${c.unit.items}`):""]}),action:l,children:[(j.rows.length>Mn||ee.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ee.length>0&&t.jsx(kn,{items:ee,value:v,onChange:$=>{y($),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),j.rows.length>Mn&&t.jsx("input",{type:"search",className:"bim-d-find",value:g,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:$=>{x($.target.value),b(!1)}})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[le&&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:R.map(($,F)=>{var Ne;const A=$.id?_.get($.id):void 0,Z=A!=null&&A.title&&$.title===$.id?A.title:$.title,J=((A==null?void 0:A.authors)||[]).find(Ee=>Ee&&Ee.name),fe=[J?`${J.dynasty?`〔${u(J.dynasty)}〕`:""}${u(J.name)}${J.role?` ${u(J.role)}`:""}`:"",A!=null&&A.measure?u(A.measure):"",(Ne=$.subItems)!=null&&Ne.length?$.subItems.map(Ee=>u(Ee)).join("、"):"",(A!=null&&A.edition||$.edition)&&!N?u((A==null?void 0:A.edition)||$.edition||""):""].filter(Boolean),we=Ut.find(Ee=>Ee.key===C($.id)),_e=$.volumes.length>0?u(`第 ${vn($.volumes,c.unit.volume)} ${c.unit.volume}`):$.expected!=null?u(`${$.found??0}/${$.expected} ${c.unit.volume}`):"";return t.jsxs("tr",{children:[le&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${_e?"":" bim-d-zt-blank"}`,children:[we&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:o(we.token)}}),_e||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[$.id?t.jsx(Le,{id:$.id,label:u(Z),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(Z)}),fe.length>0?t.jsx(Be,{items:fe}):$.id&&!A&&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${A!=null&&A.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:A!=null&&A.versionCount?u(`${A.versionCount} 種`):""})]},`${$.id??$.title}-${F}`)})})]}),R.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(c.catalog.noMatch)}),E.length>R.length&&t.jsx(Nt,{label:`展開其餘 ${E.length-R.length} ${c.unit.items}`,onClick:()=>b(!0)})]}),W>0&&t.jsxs(Fe,{id:"resources",title:"影印與全文",meta:u(`${W} 處`),children:[M.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[M.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:M.text.map(($,F)=>t.jsx(Oi,{item:$,siblings:M.text},`${$.id||$.url||$.name}-${F}`))})})]}),t.jsx(Zs,{groups:M.groups})]}),j.rows.length===0&&W===0&&t.jsx(Fe,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),Re=K?t.jsx(mt,{id:"works",title:c.section.containedWorks,meta:u(`${P.length} 種`),cap:12,items:P.map($=>t.jsx(Le,{id:$.id,label:u($.title),onNavigate:r,renderLink:s,dense:!0}))}):null,Ie=S?t.jsx(qr,{caption:"上級叢編",children:t.jsx(Le,{id:S.id,label:u(S.title||S.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(qt,{railTop:d,back:p,up:Ie,nav:je,railLinks:a,main:Ce,card:Te,side:Re})},wu=16,Fn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function or(e){if(!e)return Fn.length;const n=Fn.indexOf(e);return n===-1?Fn.length:n}const _u={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function pt(e){return e==null?"":e<0?`前${-e}`:String(e)}const $u={秦:[-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]},tl=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:d})=>{var oe,ie,xe,q,L;const p=de(),{convert:a}=Y(),[c,u]=f.useState("全部"),[g,x]=f.useState(!1),[m,b]=f.useState("default"),[S,h]=f.useState(new Map),v=f.useMemo(()=>(e.works||[]).map(I=>{const $=S.get(I.work_id);return{id:I.work_id,title:($==null?void 0:$.title)??I.title??I.work_id,role:I.role||"",cls:bi(I.role),versionCount:$==null?void 0:$.versionCount,section:$==null?void 0:$.cls,l1:$==null?void 0:$.l1,measure:$==null?void 0:$.measure,hasImage:$==null?void 0:$.hasImage,loaded:!!($!=null&&$.loaded)}}),[e.works,S]),y=f.useMemo(()=>Pr((e.works||[]).map(I=>I.role)),[e.works]),j=f.useMemo(()=>{const I=c==="全部"?v:v.filter($=>$.cls===c);return m==="versions"?[...I].sort(($,F)=>(F.versionCount??-1)-($.versionCount??-1)):I},[v,c,m]),_=g?j:j.slice(0,wu),k=f.useMemo(()=>_.filter(I=>!S.has(I.id)).map(I=>I.id),[_,S]);f.useEffect(()=>{if(!n||k.length===0)return;let I=!1;return Promise.all(k.map($=>n.getItem($).then(F=>{var fe,we,_e,Ne,Ee;const A=F??{},Z=A._edition_count??(((fe=A.books)==null?void 0:fe.length)??0)+(((we=A.collections)==null?void 0:we.length)??0),J=[(_e=A.classification)==null?void 0:_e.l1,(Ne=A.classification)==null?void 0:Ne.l2].filter(Boolean).join(" ");return[$,{id:$,title:A.title,versionCount:Z,loaded:!0,cls:J||void 0,l1:((Ee=A.classification)==null?void 0:Ee.l1)||void 0,measure:F&&st(F,p.unit.juan)||void 0,hasImage:!!(A.has_image??A._has_image)}]}).catch(()=>[$,{id:$,loaded:!0}]))).then($=>{I||h(F=>{const A=new Map(F);for(const[Z,J]of $)A.set(Z,J);return A})}),()=>{I=!0}},[n,k,p.unit.juan]);const z=f.useMemo(()=>{const I=new Map;for(const $ of e.alt_names||[]){const F=$.type||p.section.aliases;I.has(F)||I.set(F,[]),I.get(F).push($.name)}return[...I.entries()].sort(($,F)=>or($[0])-or(F[0])).map(([$,F])=>({label:$,names:F}))},[e.alt_names,p]),w=e.birth_year??((oe=e.dates)==null?void 0:oe.birth)??void 0,C=e.death_year??((ie=e.dates)==null?void 0:ie.death)??void 0,E=(xe=e.dates)==null?void 0:xe.floruit,R=w!=null||C!=null?`${pt(w)||"?"}—${pt(C)||"?"}`:Array.isArray(E)&&E.length===2&&E.every(I=>Number.isFinite(I))?`活躍於 ${pt(E[0])}—${pt(E[1])}`:"",T=new Set(["本名","字","號","号"]),O=z.filter(I=>T.has(I.label)),M=z.filter(I=>!T.has(I.label)),W=M.reduce((I,$)=>I+$.names.length,0),P=f.useMemo(()=>{const I=[];for(const F of O)I.push({label:F.label,value:F.names.map(A=>a(A)).join("、")});const $=(e.works||[]).length;return $&&I.push({label:"著作",value:`${$} ${a("種")}`}),I},[e.works,O,a]),V=I=>{var $;return($=z.find(F=>I.includes(F.label)))==null?void 0:$.names[0]},K=V(["字"]),N=V(["號","号"]),le=[K?`字${K}`:"",N?`號${N}`:""].filter(Boolean).join(","),G=e.native_place,se=e.dynasty?$u[e.dynasty]:void 0,ne=(()=>{if(!se||w==null||C==null||C<w)return null;const[I,$]=se,F=Math.max(w,I),A=Math.min(C,$);if(A<=F)return null;const Z=$-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":a(`${pt(w)}—${pt(C)},一生 ${C-w+1} 年`),children:t.jsx("i",{style:{left:`${(F-I)/Z*100}%`,width:`${(A-F)/Z*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:a(`${pt(I)} ${e.dynasty}`)}),t.jsx("span",{children:a(`一生 ${C-w+1} 年`)}),t.jsx("span",{children:pt($)})]})]})})(),Q=f.useMemo(()=>{if(!n||v.length===0||v.some(F=>!F.loaded))return null;const I=new Map;for(const F of v){const A=ri(F.l1);A&&I.set(A,(I.get(A)??0)+1)}const $=Ut.map(F=>({...F,n:I.get(F.key)??0})).filter(F=>F.n>0);return $.length?$:null},[v,n]),H=t.jsxs(Jt,{kind:_u[e.subtype]??"人物",title:a(e.primary_name||e.title),subtitle:le?a(le):void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(Be,{items:[e.dynasty?a(e.dynasty):"",R?a(R):"",G?a(`${G}人`):""]}),ne]}),description:(q=e.description)!=null&&q.text?t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ji((L=e.description)==null?void 0:L.text)?6:void 0,facts:P,foot:t.jsx(Zt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[W>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:a(`更多別名(${W})`)}),t.jsx("dl",{children:M.map(I=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:a(I.label)}),t.jsx("dd",{children:I.names.map($=>a($)).join("、")})]},I.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:a("著作分佈")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:Q.map(I=>t.jsx("i",{style:{flexGrow:I.n,background:o(I.token)}},I.key))}),t.jsx("div",{className:"bim-d-dist-key",children:Q.map(I=>t.jsxs("span",{children:[t.jsx("i",{style:{background:o(I.token)}}),a(I.label)," ",I.n]},I.key))})]})]}),te=f.useMemo(()=>v.filter(I=>I.loaded&&(I.versionCount??0)>0).sort((I,$)=>($.versionCount??0)-(I.versionCount??0)).slice(0,3),[v]),pe=!!n&&v.length>=3&&_.some(I=>!I.loaded),re=c==="全部"&&(pe||te.length>=2),ee=e.external_ids||{},ye=[];ee.cbdb_id!=null&&ye.push({label:"CBDB",id:String(ee.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${ee.cbdb_id}`,note:ee.cbdb_match==="auto"?"自動匹配":void 0});const ae=ee.wikidata_id;ae&&ye.push({label:"Wikidata",id:ae,href:`https://www.wikidata.org/wiki/${ae}`});const Te=ee.viaf_id;Te&&ye.push({label:"VIAF",id:Te,href:`https://viaf.org/viaf/${Te}`});const je=y.map(I=>({key:I.cls,label:`${I.label} ${I.count}`})),Ce=[...re&&!pe?[{id:"featured",label:"著作舉要",count:te.length}]:[],...v.length?[{id:"works",label:"全部著作",count:v.length}]:[],...ye.length?[{id:"external",label:"站外資料",count:ye.length}]:[]],Re=re?t.jsxs(Fe,{id:"featured",title:"著作舉要",children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:a("存世版本最多的三部")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":pe||void 0,children:[pe&&[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)),!pe&&te.map(I=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Le,{id:I.id,label:a(I.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx(Be,{items:[I.section?a(I.section):"",I.measure?a(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:a("種版本")}),I.hasImage&&t.jsx("span",{className:"bim-d-flag",children:a("有影印")})]})]},I.id))]})]}):null,Ie=v.length===0?t.jsx(Fe,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該人物的關聯作品。")})}):t.jsxs(t.Fragment,{children:[Re,t.jsxs(Fe,{id:"works",title:"著作",meta:t.jsx(Be,{items:[a(`共 ${v.length} 種`),j.length!==v.length?a(`當前 ${j.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[je.length>1&&t.jsx(kn,{items:je,value:c,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:a(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:a("作品")}),t.jsx("th",{children:a("部類")}),t.jsx("th",{children:a("職任")}),t.jsx("th",{children:a("存世版本")}),t.jsx("th",{"aria-label":a("影印")})]})}),t.jsx("tbody",{children:_.map(I=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Le,{id:I.id,label:a(I.title),onNavigate:i,renderLink:r,dense:!0}),I.measure?t.jsx(Be,{items:[a(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?a(I.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.role?"":" bim-d-zt-blank"}`,children:I.role?a(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?a(`${I.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:a("未著錄")}):""}),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:a("有影印")})})]},I.id))})]}),_.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a("該職任下的著作尚未著錄。")}),j.length>_.length&&t.jsx(Nt,{label:`展開其餘 ${j.length-_.length} 種著作`,onClick:()=>x(!0)})]})]}),D=ye.length>0?t.jsx(mt,{id:"external",title:"站外資料",items:ye.map(I=>t.jsxs("a",{href:I.href,target:"_blank",rel:"noopener noreferrer",children:[I.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:ye.map(I=>I.id),foot:ee.cbdb_id!=null&&ee.cbdb_match==="auto"?a("CBDB 為自動匹配,未經人工核對"):void 0}):null;return t.jsx(qt,{railTop:s,back:l,nav:Ce,railLinks:d,main:Ie,card:H,side:D})},Di="(max-width: 719px)",zu=`${Di}, (pointer: coarse)`,nl=`
784
+ `)}),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=_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 Ln=/^(#{1,6})\s+(.*)$/,xd=/^\s*<!--.*-->\s*$/;function Rs(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
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 $n(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(`
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&&lt(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=`
732
789
  .bim-ct {
733
790
  display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
734
791
  max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
@@ -774,6 +831,10 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
774
831
  .bim-ct-crumb { font-size: 13px; color: ${o("aux-fg")}; }
775
832
  .bim-ct-stat { font-size: 13px; color: ${o("aux-fg")}; }
776
833
  .bim-ct-search { margin: 0 0 16px; }
834
+ .bim-ct-view { margin-left: auto; display: inline-flex; border-radius: 6px; box-shadow: inset 0 0 0 1px ${o("rule")}; overflow: hidden; }
835
+ .bim-ct-view button { min-height: 28px; padding: 0 12px; border: 0; background: none; cursor: pointer; font: inherit; font-size: 13px; color: ${o("quiet-fg")}; }
836
+ .bim-ct-view button[aria-pressed="true"] { background: ${o("flag-bg")}; color: ${o("accent")}; font-weight: 700; }
837
+ .bim-ct-view button:focus-visible { outline: 2px solid ${o("accent")}; outline-offset: -2px; }
777
838
 
778
839
  /* ── 卡片网格 ── */
779
840
  .bim-ct-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@@ -799,6 +860,20 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
799
860
  .bim-ct-cls { margin-top: auto; padding-top: 2px; font-size: 12px; color: ${o("aux-fg")}; }
800
861
  .bim-ct-empty { padding: 48px 0; text-align: center; font-size: 14px; color: ${o("aux-fg")}; }
801
862
 
863
+ /* ── 列表视图 ── */
864
+ .bim-ct-list { list-style: none; margin: 0; padding: 0; }
865
+ .bim-ct-lrow:nth-child(odd) { background: ${o("zebra-bg")}; border-radius: 6px; }
866
+ .bim-ct-lrow > a {
867
+ display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr) minmax(0, 2fr); gap: 4px 20px; align-items: baseline;
868
+ min-height: 44px; padding: 10px 14px; color: inherit; text-decoration: none; border-radius: 6px;
869
+ }
870
+ .bim-ct-lrow > a:hover { background: ${o("tint-bg")}; }
871
+ .bim-ct-lrow > a:hover .bim-ct-lt { color: ${o("accent")}; }
872
+ .bim-ct-lrow > a:focus-visible { outline: 2px solid ${o("accent")}; outline-offset: -2px; }
873
+ .bim-ct-lt { font-size: 16px; font-weight: 700; color: ${o("ink")}; overflow-wrap: anywhere; }
874
+ .bim-ct-lt .bim-ct-juan { margin-left: 8px; font-weight: 400; }
875
+ .bim-ct-lrow .bim-ct-cls { margin: 0; padding: 0; }
876
+
802
877
  /* ── 分页 ── */
803
878
  .bim-ct-pager { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px; margin: 24px 0 0; font-size: 14px; }
804
879
  .bim-ct-pager ol { display: contents; list-style: none; }
@@ -818,9 +893,11 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
818
893
  .bim-ct-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
819
894
  }
820
895
 
821
- @media ${Di} {
896
+ @media ${Gi} {
822
897
  .bim-ct { display: block; padding: 12px 16px 40px; }
823
898
  .bim-ct-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
899
+ .bim-ct-lrow > a { grid-template-columns: minmax(0, 1fr); }
900
+ .bim-ct-view button { min-height: 44px; }
824
901
  .bim-ct-side { position: static; max-height: none; overflow: visible; margin: 0 0 12px; }
825
902
  .bim-ct-side-h { display: none; }
826
903
  .bim-ct-drawer-btn {
@@ -841,9 +918,9 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
841
918
  }
842
919
 
843
920
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
844
- @media ${zu} {
921
+ @media ${ix} {
845
922
  .bim-ct-row { min-height: 44px; }
846
923
  .bim-ct-tw { width: 44px; }
847
924
  .bim-ct-pg { min-width: 44px; height: 44px; }
848
925
  }
849
- `,Vt="未分類",it="all",Hi=20;function Qt(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 Cu(e){const n=Qt(e);return n.length?n.join("/"):Vt}function Iu(e){const n=Qt(e);return n.length?n.map((i,r)=>n.slice(0,r+1).join("/")):[Vt]}function Tu(e,n=[]){const i=new Map;n.forEach((p,a)=>{const c=[p.cata_l1,p.cata_l2,p.cata_l3,p.cata_l4].filter(u=>!!u);c.forEach((u,g)=>{const x=c.slice(0,g+1).join("/");i.has(x)||i.set(x,a)})});const r=new Map;let s=0;for(const p of e){const a=Qt(p.classification);if(!a.length){s++;continue}let c=r;a.forEach((u,g)=>{const x=a.slice(0,g+1).join("/");let m=c.get(u);m||(m={id:x,label:u,count:0,children:new Map},c.set(u,m)),m.count++,c=m.children})}const l=p=>[...p.values()].sort((a,c)=>{const u=i.get(a.id)??1/0,g=i.get(c.id)??1/0;return u!==g?u-g:a.label.localeCompare(c.label,"zh")}).map(a=>{const c={id:a.id,label:a.label,count:a.count};return a.children.size&&(c.children=l(a.children)),c}),d=l(r);return s>0&&d.push({id:Vt,label:Vt,count:s}),d}function _t(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const r=_t(i.children,n);if(r.length)return[i,...r]}}return[]}function Gi(e){return e.reduce((n,i)=>n+i.count,0)}function Eu(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function Ru(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(a=>a==null?void 0:a.name).map(a=>{const c=a.dynasty||(e.authors.length===1?e.dynasty:void 0);return c?{name:a.name,dynasty:c}:{name:a.name}});s.length&&(n.authors=s);const l=Eu(typeof e.description=="string"?e.description:(p=e.description)==null?void 0:p.text);l&&(n.summary=l);const d=Qt(e.classification);return d.length&&(n.classification=d),n}function Nu(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 Lu(e,n=Hi){return Math.max(1,Math.ceil(e/n))}function il(e,n,i=2){if(n<=1)return[1];const r=new Set([1,n]);for(let d=e-i;d<=e+i;d++)d>=1&&d<=n&&r.add(d);const s=[...r].sort((d,p)=>d-p),l=[];return s.forEach((d,p)=>{if(p>0){const a=d-s[p-1];a===2?l.push(d-1):a>2&&l.push(null)}l.push(d)}),l}const Bu=()=>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 Au(e,n,i){const r=[];i&&r.push({id:it,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,d)=>{var p;for(const a of l){const c=(p=a.children)!=null&&p.length?a.children:null;r.push({id:a.id,parentId:d,hasChildren:!!c,firstChildId:c?c[0].id:null}),c&&n.has(a.id)&&s(c,a.id)}};return s(e,null),r}function ol({tree:e,selectedId:n,onSelect:i,allLabel:r="全部",label:s="分類"}){const{convert:l}=Y(),d=f.useRef(null),p=n&&n!==it?n:null,a=r!==null,[c,u]=f.useState(()=>{const k=new Set;for(const z of _t(e,p))k.add(z.id);return k});f.useEffect(()=>{const k=_t(e,p);k.length&&u(z=>{if(k.every(C=>z.has(C.id)))return z;const w=new Set(z);for(const C of k)w.add(C.id);return w})},[e,p]);const g=f.useMemo(()=>Au(e,c,a),[e,c,a]),[x,m]=f.useState(null);f.useEffect(()=>{m(null)},[n]);const b=p??(a?it:null),S=f.useMemo(()=>{var w;const k=new Set(g.map(C=>C.id));if(x&&k.has(x))return x;if(b&&k.has(b))return b;const z=_t(e,p).map(C=>C.id).filter(C=>k.has(C));return z.length?z[z.length-1]:((w=g[0])==null?void 0:w.id)??null},[g,x,b,e,p]),h=f.useCallback((k,z)=>{u(w=>{const C=w.has(k),E=z??!C;if(E===C)return w;const R=new Set(w);return E?R.add(k):R.delete(k),R})},[]),v=f.useCallback(k=>{m(k),requestAnimationFrame(()=>{var w;const z=Array.from(((w=d.current)==null?void 0:w.querySelectorAll("[data-ct-id]"))??[]).find(C=>C.dataset.ctId===k);z==null||z.focus()})},[]),y=f.useCallback((k,z)=>{z&&h(k,!0),i(k)},[i,h]),j=f.useCallback(k=>{const z=k.target.closest("[data-ct-id]");if(!z)return;const w=z.dataset.ctId,C=g.findIndex(T=>T.id===w);if(C<0)return;const E=g[C];let R=null;switch(k.key){case"ArrowDown":R=g[Math.min(g.length-1,C+1)].id;break;case"ArrowUp":R=g[Math.max(0,C-1)].id;break;case"Home":R=g[0].id;break;case"End":R=g[g.length-1].id;break;case"ArrowRight":if(!E.hasChildren)break;c.has(w)?R=E.firstChildId:h(w,!0);break;case"ArrowLeft":E.hasChildren&&c.has(w)?h(w,!1):R=E.parentId;break;case"Enter":case" ":k.preventDefault(),y(w,E.hasChildren);return;default:return}k.preventDefault(),R&&R!==w&&v(R)},[g,c,h,v,y]),_=(k,z)=>k.map((w,C)=>{var M;const E=(M=w.children)!=null&&M.length?w.children:null,R=!!E&&c.has(w.id),T=w.id===p,O=z===1&&k.length>1&&C===k.length-1;return t.jsxs("li",{role:"treeitem","aria-level":z,"aria-expanded":E?R:void 0,"aria-selected":T,tabIndex:S===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":z-1},onClick:()=>{m(w.id),y(w.id,!!E)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:E?W=>{W.stopPropagation(),m(w.id),h(w.id)}:void 0,children:E?t.jsx(Bu,{}):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")})]}),R&&t.jsx("ul",{role:"group",children:_(E,z+1)})]},w.id)});return t.jsxs("ul",{ref:d,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:j,children:[a&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:S===it?0:-1,"data-ct-id":it,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{m(it),i(it)},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:Gi(e).toLocaleString("en-US")})]})}),_(e,1)]})}const rl=e=>`/item/${encodeURIComponent(e)}`;function Wu(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Mu(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function sl({work:e,href:n}){var d,p;const{convert:i}=Y(),r=Mu(e.juan),s=((d=e.authors)==null?void 0:d.filter(a=>a.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((a,c)=>t.jsxs(f.Fragment,{children:[c>0&&"、",a.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(a.dynasty),"〕"]}),i(a.name)]},c))}),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(a=>i(a)).join(" · ")})]})})}function ll({page:e,pageCount:n,onPage:i,pageHref:r,label:s="分頁"}){const{convert:l}=Y();if(n<=1)return null;const d=a=>c=>{i&&(r&&!Wu(c)||(c.preventDefault(),i(a)))},p=(a,c,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:c});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(a),onClick:d(a),children:c}):t.jsx("button",{type:"button",...g,onClick:u.current?void 0:d(a),children:c})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:il(e,n).map((a,c)=>t.jsx("li",{style:{display:"contents"},children:a===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(a,a,{current:a===e,aria:l(`第 ${a} 頁`)})},a??`gap${c}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),p(e+1,l("下一頁"),{disabled:e>=n})]})}function al({works:e,workLink:n=rl,emptyText:i="此類暫無作品",...r}){const{convert:s}=Y();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:typeof i=="string"?s(i):i}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(l=>t.jsx(sl,{work:l,href:n(l.id)},l.id))}),t.jsx(ll,{...r})]})}const Fu=()=>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 Pu({tree:e,selectedId:n,page:i,pageCount:r,works:s,onSelect:l,onPage:d,searchSlot:p,workLink:a,pageHref:c,allLabel:u="全部",allTitle:g="全部典籍",pageSize:x=Hi,className:m}){const{convert:b}=Y(),h=`bim-ct-drawer-${f.useId().replace(/:/g,"")}`,[v,y]=f.useState(!1),j=_t(e,n&&n!==it?n:null),_=j.length?j[j.length-1]:null,k=_?_.label:g,z=_?_.count:Gi(e),w=f.useCallback(C=>{y(!1),l(C)},[l]);return t.jsxs("div",{className:m?`bim-ct ${m}`:"bim-ct","data-drawer":v?"open":"closed",children:[t.jsx("style",{children:nl}),t.jsxs("aside",{className:"bim-ct-side","aria-label":b("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":v,"aria-controls":h,onClick:()=>y(C=>!C),children:[t.jsxs("span",{children:[b("分類"),":",b(j.length?j.map(C=>C.label).join(" › "):u??g)]}),t.jsx(Fu,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:h,children:[t.jsx("h2",{className:"bim-ct-side-h",children:b("分類")}),t.jsx(ol,{tree:e,selectedId:n,onSelect:w,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:b(k)}),j.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:b(j.slice(0,-1).map(C=>C.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[b(`共 ${z.toLocaleString("en-US")} 種 · 每頁 ${x} 條`),r>1&&b(` · 第 ${i} / ${r} 頁`)]})]}),p&&t.jsx("div",{className:"bim-ct-search",children:p}),t.jsx(al,{works:s,workLink:a,page:i,pageCount:r,onPage:d,pageHref:c})]})]})}function Ou(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 Du(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 rr(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 Hu(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 Gu(e,n){var c;if(n==="all")return null;const i=(c=e.collections)==null?void 0:c[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 d=r?new Set(i.groups):null,p=new Set(i.book_ids??[]);if(d&&e.node_groups)for(const[u,g]of Object.entries(e.node_groups))d.has(g)&&p.add(u);let a=null;if(i.hypothetical_ids&&(a=new Set(i.hypothetical_ids)),d){a||(a=new Set);for(const u of e.hypothetical_nodes??[])u.group&&d.has(u.group)&&a.add(u.id)}return{books:p,hypos:a}}function pn(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??[]),d=r.node_groups??{},p=Gu(r,i??r.default_collection??"all"),a=p!==null,c=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,g=new Set,x=new Set;if(a){const _=new Map(n.map(R=>[R.id,R])),k=new Map((r.hypothetical_nodes??[]).map(R=>[R.id,R])),z=R=>{const T=_.get(R);if(T&&T.lineage)return(T.lineage.derived_from??[]).map(M=>M.ref);const O=k.get(R);return O?(O.derived_from??[]).map(M=>M.ref):[]},w=R=>k.has(R)?!u||u.has(R):!c||c.has(R),C=new Set,E=R=>{if(!C.has(R)){C.add(R);for(const T of z(R))l.has(T)||(w(T)||(k.has(T)?x.add(T):_.has(T)&&g.add(T)),E(T))}};for(const R of n)c&&c.has(R.id)&&!l.has(R.id)&&E(R.id);for(const R of r.hypothetical_nodes??[])u&&u.has(R.id)&&E(R.id)}const m=n.filter(_=>!l.has(_.id)).filter(_=>!c||c.has(_.id)||g.has(_.id)).map(_=>{const k=Du(_,d);return k&&g.has(_.id)&&(k.bridge=!0),k}).filter(_=>_!==null),b=(r.hypothetical_nodes??[]).filter(_=>!u||u.has(_.id)||x.has(_.id)).map(_=>{const k=Ou(_);return x.has(_.id)&&(k.bridge=!0),k}),S=[...m,...b],h=new Set(S.map(_=>_.id)),v=new Set,y=[],j=_=>{v.has(_.id)||!h.has(_.source)||!h.has(_.target)||(v.add(_.id),y.push(_))};for(const _ of n)l.has(_.id)||!_.lineage||c&&!c.has(_.id)&&!g.has(_.id)||((_.lineage.derived_from??[]).forEach((k,z)=>{j(rr(_.id,k,z))}),(_.lineage.related_to??[]).forEach((k,z)=>{j(Hu(_.id,k,z))}));for(const _ of r.hypothetical_nodes??[])u&&!u.has(_.id)&&!x.has(_.id)||(_.derived_from??[]).forEach((k,z)=>{j(rr(_.id,k,z))});return{nodes:S,edges:y,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function cl(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Uu(e,n){const i=[],r=e.version_graph;if(!r)return i;const s=new Set(n.map(a=>a.id)),l=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),d=new Set([...s,...l]),p=(a,c)=>{d.has(c.ref)||i.push(`${a}: derived_from.ref "${c.ref}" 未在 books 或 hypothetical_nodes 中找到`),c.ref_type==="book"&&!s.has(c.ref)&&i.push(`${a}: derived_from.ref "${c.ref}" 标记为 book 但不在 books 列表中`),c.ref_type==="hypothetical"&&!l.has(c.ref)&&i.push(`${a}: derived_from.ref "${c.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const c=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(u=>p(c,u)),(a.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||i.push(`${c}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const c=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(u=>p(c,u))}return i}const dl=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:s}=Y();if(!e.nodes.length)return t.jsx("div",{style:{...rx,...r},className:i,children:"暂无版本图数据"});const l=new Map,d=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=d.get(m)??[];b.push(x),d.set(m,b)}const p=new Map(e.nodes.map(x=>[x.id,x])),a=new Map,c=[];for(const x of e.nodes)if(x.group){const m=a.get(x.group)??[];m.push(x),a.set(x.group,m)}else c.push(x);const u=(x,m)=>(x.year??9999)-(m.year??9999);a.forEach(x=>x.sort(u)),c.sort(u);const g=e.groups.filter(x=>a.has(x.id));return t.jsxs("div",{className:i,style:{...Yu,...r},children:[e.title&&t.jsx("div",{style:Ku,children:s(e.title)}),e.description&&t.jsx("div",{style:qu,children:s(e.description)}),g.map(x=>t.jsx(sr,{label:x.label,color:x.color,nodes:a.get(x.id),incomingMap:l,siblingMap:d,nodeMap:p,renderLink:n},x.id)),c.length>0&&t.jsx(sr,{label:"其他",nodes:c,incomingMap:l,siblingMap:d,nodeMap:p,renderLink:n})]})},sr=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:d})=>{const{convert:p}=Y();return t.jsxs("div",{style:Ju,children:[t.jsx("div",{style:{...Zu,borderLeftColor:n??o("widget-border")},children:p(e)}),i.map(a=>t.jsx(Vu,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:l,renderLink:d},a.id))]})},Vu=({node:e,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",d=e.bridge,{convert:p}=Y();return t.jsxs("div",{style:{...Xu,borderStyle:l||d?"dashed":"solid",opacity:d?.55:e.status==="lost"?.7:1,background:d?o("bg-subtle"):void 0},title:d?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:Qu,children:[t.jsx("span",{style:ex,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:tx,children:cl(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:nx,children:[e.category&&t.jsx(Pt,{children:p(e.category)}),e.status==="lost"&&t.jsx(Pt,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(Pt,{tone:"warn",children:"残本"}),l&&t.jsx(Pt,{tone:"info",children:"假想祖本"}),d&&t.jsx(Pt,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:ix,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:ox,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:ar,children:[t.jsx("div",{style:cr,children:"来源:"}),n.map(a=>{const c=r.get(a.source);return t.jsxs("div",{style:dr(a.confidence),children:[t.jsx("span",{style:pr,children:p(a.relation)}),t.jsx("span",{children:(c==null?void 0:c.kind)==="book"&&s?s(c.id,p(c.label)):p((c==null?void 0:c.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&t.jsx(lr,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:ur,children:["· ",p(a.evidence)]})]},a.id)})]}),i.length>0&&t.jsxs("div",{style:ar,children:[t.jsx("div",{style:cr,children:"关联:"}),i.map(a=>{const c=a.source===e.id?a.target:a.source,u=r.get(c);return t.jsxs("div",{style:dr(a.confidence),children:[t.jsx("span",{style:pr,children:p(a.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)??c)}),t.jsx(lr,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:ur,children:["· ",p(a.evidence)]})]},a.id)})]})]})},Pt=({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})},lr=({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},Yu={fontSize:"14px",color:o("fg")},Ku={fontSize:"16px",fontWeight:600,marginBottom:"8px"},qu={fontSize:"13px",color:o("muted"),marginBottom:"16px",lineHeight:1.6},Ju={marginBottom:"16px"},Zu={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:o("fg")},Xu={border:`1px solid ${o("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:o("bg")},Qu={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},ex={fontSize:"15px",fontWeight:600},tx={fontSize:"12px",color:o("muted")},nx={marginBottom:"6px"},ix={fontSize:"12px",color:o("muted"),margin:"2px 0"},ox={fontSize:"12px",color:o("muted"),fontStyle:"italic",margin:"4px 0"},ar={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${o("widget-border")}`},cr={fontSize:"11px",color:o("muted"),marginBottom:"2px"},dr=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),pr={display:"inline-block",padding:"0 6px",fontSize:"11px",background:o("tag-bg"),color:o("fg"),borderRadius:"3px",marginRight:"6px"},ur={fontSize:"11px",color:o("muted")},rx={padding:"20px",textAlign:"center",color:o("muted"),fontSize:"13px"},pl=({selectedNodeId:e,...n})=>{const[i,r]=f.useState("loading"),[s,l]=f.useState(null);return f.useEffect(()=>{let d=!1;return sx().then(p=>{d||(p?(l(p),r("ready")):r("missing"))}),()=>{d=!0}},[]),i==="loading"?t.jsx("div",{style:xr,children:"加载图组件中…"}):i==="missing"||!s?t.jsxs("div",{style:xr,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(lx,{modules:s,selectedNodeId:e,...n})};async function sx(){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 lx=({graph:e,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:l,modules:d})=>{const{ReactFlow:p,Background:a,Controls:c,Handle:u,Position:g,BaseEdge:x,EdgeLabelRenderer:m,getSmoothStepPath:b,dagre:S}=d,h=f.useMemo(()=>({lineage:z=>{var V,K,N,le;const w=((V=z.data)==null?void 0:V.stepPosition)??.85,[C,E,R]=b({sourceX:z.sourceX,sourceY:z.sourceY,sourcePosition:z.sourcePosition,targetX:z.targetX,targetY:z.targetY,targetPosition:z.targetPosition,stepPosition:w,borderRadius:5}),T=!!((K=z.data)!=null&&K.isSibling),O=T?E:z.targetX-18,M=T?R:z.targetY-12,W=(N=z.data)==null?void 0:N.labelStyle,P=(le=z.data)==null?void 0:le.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(x,{id:z.id,path:C,style:z.style,markerStart:z.markerStart,markerEnd:z.markerEnd}),z.label&&t.jsx(m,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${O}px,${M}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:o("bg"),border:`0.5px solid ${o("widget-border")}`,...P,...W},children:z.label})})]})}}),[x,m,b]),v=f.useMemo(()=>({version:z=>{const w=z.data,C=w.kind==="hypothetical",E=w.status==="lost",R=w.isSelected,T=w.bridge,O=w.borderColor??o("muted"),M=T||C?"dashed":"solid",W=T?.5:E?.6:1;return t.jsxs("div",{style:{background:o(T?"bg-subtle":"bg"),border:`2px ${M} ${R?o("primary"):O}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:W,boxShadow:R?o("shadow-node-selected"):C||T?"none":o("shadow-node")},title:T?"桥接节点:本身不在核心集,为保持派生链完整而显示":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("muted"),lineHeight:1.25,marginTop:1},children:w.description}),w.yearText&&t.jsx("div",{style:{fontSize:10,color:o("muted"),lineHeight:1.2},children:cl(w.yearText,void 0,w.uncertain)}),E&&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:y}=Y(),{rfNodes:j,rfEdges:_}=f.useMemo(()=>ax(e,S,n,l,y),[e,S,n,l,y]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:t.jsxs(p,{nodes:j,edges:_,nodeTypes:v,edgeTypes:h,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(a,{gap:16}),t.jsx(c,{showInteractive:!1})]})})};function ax(e,n,i,r,s=l=>l??""){const p=e.layout==="LR"||!e.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:p?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const c=new Map(e.groups.map(v=>[v.id,v.color??o("muted")]));for(const v of e.nodes)a.setNode(v.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const v of e.edges)v.kind==="derive"&&(u.has(v.relation)||a.setEdge(v.source,v.target));n.layout(a);const g=e.nodes.map(v=>{const y=a.node(v.id),j=r?v.id===r:void 0,_={kind:v.kind,label:s(v.label),bookId:v.kind==="book"?v.id:void 0,yearText:s(v.year_text??dx(v)),uncertain:v.year_uncertain,category:v.category,status:v.status,borderColor:v.group?c.get(v.group):void 0,renderLink:i,isSelected:j,description:s(v.description),bridge:v.bridge};return{id:v.id,type:"version",position:{x:y.x-160/2,y:y.y-90/2},data:_,draggable:!1,selected:j}}),x=.78,m=.06,b=new Map;for(const v of e.edges)v.kind==="derive"&&(b.has(v.source)||b.set(v.source,[]),b.get(v.source).push(v));const S=new Map;for(const[v,y]of b){if(y.length<=1)continue;const j=[...y].sort((k,z)=>{var E,R;const w=((E=a.node(k.target))==null?void 0:E.y)??0,C=((R=a.node(z.target))==null?void 0:R.y)??0;return w-C}),_=j.length;j.forEach((k,z)=>{const w=(z-(_-1)/2)*m;S.set(k.id,x+w)})}const h=e.edges.map(v=>cx(v,S.get(v.id),s));return{rfNodes:g,rfEdges:h}}function cx(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=px(e.confidence),d={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:d,markerStart:s?d:void 0,zIndex:1e3}}function dx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function px(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 xr={padding:"40px 20px",textAlign:"center",color:o("muted"),fontSize:"13px",border:`1px dashed ${o("widget-border")}`,borderRadius:8,background:o("bg")},ul=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:d,onCollectionChange:p,collectionsAvailable:a,collectionCounts:c,className:u,style:g})=>{var y;const[x,m]=f.useState(n),b=j=>{m(j),l==null||l(j)},S=(()=>{if(!a)return[];const j=Object.entries(a);return j.length===0||a.all?j:[...j,["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 v=d?(y=a==null?void 0:a[d])==null?void 0:y.description:void 0;return t.jsxs("div",{className:u,style:g,children:[t.jsxs("div",{style:ux,children:[t.jsx("button",{onClick:()=>b("list"),style:Pn(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:Pn(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(([j,_])=>{const k=c==null?void 0:c[j];return t.jsxs("button",{onClick:()=>p==null?void 0:p(j),style:Pn(d===j),title:_.description,children:[_.label,k!=null?` ${k}`:""]},j)})]})]}),h&&v&&t.jsx("div",{style:{fontSize:12,color:o("muted"),marginBottom:8,padding:"4px 8px",background:o("bg-subtle"),borderRadius:4},children:v}),x==="list"?t.jsx(dl,{graph:e,renderLink:i}):t.jsx(pl,{graph:e,renderLink:i,height:r,selectedNodeId:s})]})},ux={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Pn=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"}),si=({style:e})=>{const n=f.useContext(Tt);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:"简"})]})},li=({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 On(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function xx(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const fx=({id:e,transport:n,initialDetail:i,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:d,onJuanChange:p,lineageMode:a="list",onLineageModeChange:c,lineageCollection:u,onLineageCollectionChange:g,initialPage:x=1,selectedLineageNodeId:m,onNavigate:b,onBack:S,backLabel:h,renderLink:v,enrichDetail:y,getSourceLink:j,readLink:_,railTop:k,extraTabs:z=[],showFeedbackTab:w=!0,feedbackApiUrl:C,height:E,footerExtra:R,className:T,style:O})=>{var Yi;const M=de(),{convert:W}=Y(),[P]=f.useState(()=>{if(!xx(e,i))return null;const U={...i},me=r??On(e,U);return y&&y(me,U),{id:e,entry:me,detail:U}}),[V,K]=f.useState((P==null?void 0:P.entry)??null),[N,le]=f.useState((P==null?void 0:P.detail)??null),[G,se]=f.useState(!P),[ne,Q]=f.useState(!1),[H,te]=f.useState([]),[pe,re]=f.useState(!1),[ee,ye]=f.useState(null),[ae,Te]=f.useState(!1),[je,Ce]=f.useState(null),[Re,Ie]=f.useState(!1),[D,oe]=f.useState(null),[ie,xe]=f.useState([]),[q,L]=f.useState(!1),[I,$]=f.useState(null),[F,A]=f.useState(null),[Z,J]=f.useState(!1),fe=f.useRef(null),[we,_e]=f.useState(null),Ne=d!==void 0?d:we,Ee=f.useCallback(U=>{p?p(U):_e(U)},[p]),Lt=f.useCallback(async U=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){te([]);return}re(!0);try{if(n.getCollectionCatalogs)te(await n.getCollectionCatalogs(U)||[]);else if(n.getCollectionCatalog){const me=await n.getCollectionCatalog(U);te(me?[{resource_id:"",data:me}]:[])}}catch{te([])}finally{re(!1)}},[n]),B=f.useCallback(async U=>{if(!n.getCollatedEditionIndex){ye(null);return}Te(!0);try{ye(await n.getCollatedEditionIndex(U))}catch{ye(null)}finally{Te(!1)}},[n]),ce=f.useCallback(async U=>{if(!n.getBookFullTextIndex){Ce(null);return}Ie(!0);try{Ce(await n.getBookFullTextIndex(U))}catch{Ce(null)}finally{Ie(!1),oe(U)}},[n]),ue=f.useCallback(async U=>{var me;if(!n.getWorkFullTextList){xe([]);return}L(!0);try{const Se=(await n.getWorkFullTextList(U)??[]).filter(We=>We.owner_type!=="Book");xe(Se),$(((me=Se.find(We=>We.primary)??Se[0])==null?void 0:me.key)??null)}catch{xe([])}finally{L(!1)}},[n]),ve=f.useCallback(async(U,me)=>{J(!0);try{if(n.getLineageGraph){const Oe=await n.getLineageGraph(U);Oe&&A(Oe)}const Se=me.version_graph;if(!Se||!Se.enabled){F||A(null),fe.current=null;return}const We=me.books??[],qe=[];for(const Oe of We)try{const Je=await n.getItem(Oe);Je&&qe.push(Je)}catch{}fe.current={work:me,books:qe};const X=u??Se.default_collection??(Se.core_books&&Se.core_books.length>0?"core":"all"),$e=X==="core"&&Array.isArray(Se.core_books)&&Se.core_books.length>0?"core":X??"all";A(pn(me,qe,$e))}catch{A(null),fe.current=null}finally{J(!1)}},[n]),he=f.useRef({initialDetail:i,initialEntry:r});he.current={initialDetail:i,initialEntry:r},f.useEffect(()=>{let U=!1;const me=X=>{X.type==="collection"?Lt(e):X.type==="work"?(X.has_collated&&B(e),(X.version_graph||n.getLineageGraph)&&ve(e,X),n.getWorkFullTextList&&ue(e)):X.type==="book"&&X.has_full_text&&n.getBookFullTextIndex&&ce(e)},Se=he.current;let We=null;if(P&&P.id===e)We=P;else if(Se.initialDetail&&Se.initialDetail.id===e){const X={...Se.initialDetail},$e=Se.initialEntry??On(e,X);y&&y($e,X),We={entry:$e,detail:X}}return We?(Q(!1),te(X=>X.length?[]:X),ye(null),Ce(null),xe(X=>X.length?[]:X),$(null),A(null),fe.current=null,K(We.entry),le(We.detail),se(!1),me(We.detail),()=>{U=!0}):((async()=>{se(!0),Q(!1),K(null),le(null),te([]),ye(null),Ce(null),xe([]),$(null),A(null),fe.current=null;try{const X=await n.getItem(e);if(U)return;if(!X){Q(!0);return}const $e=X;let Oe=null;if(n.getEntry&&(Oe=await n.getEntry(e),U))return;Oe||(Oe=On(e,$e)),y&&y(Oe,$e),K(Oe),le($e),me($e)}catch{U||Q(!0)}finally{U||se(!1)}})(),()=>{U=!0})},[e,n,P,y,Lt,B,ve,ce,ue]),f.useEffect(()=>{const U=fe.current;!U||!u||A(pn(U.work,U.books,u))},[u]);const ge=[];if(N){if(ge.push({key:"basic",label:M.detailTab.basicInfo}),N.type==="collection"){pe&&H.length===0&&ge.push({key:"catalog:loading",label:`${M.detailTab.catalog}…`});for(const U of H)ge.push({key:`catalog:${U.resource_id}`,label:U.short_name?`${W(U.short_name)}${M.detailTab.catalogSuffix}`:M.detailTab.collectionCatalog})}N.type==="work"&&(ee||ae)&&s==="collated"&&ge.push({key:"collated",label:ae?`${M.detailTab.collatedEdition}…`:M.detailTab.collatedEdition}),N.type==="book"&&(je||Re)&&s==="fulltext"&&ge.push({key:"fulltext",label:Re?`${M.detailTab.fullText}…`:M.detailTab.fullText}),N.type==="work"&&(ie.length>0||q)&&s==="fulltext"&&ge.push({key:"fulltext",label:q?`${M.detailTab.fullText}…`:M.detailTab.fullText}),N.type==="work"&&(F||Z)&&ge.push({key:"lineage",label:Z?`${M.detailTab.lineage}…`:M.detailTab.lineage});for(const U of z)(U.position??"before-feedback")==="before-feedback"&&U.shouldShow(N)&&ge.push({key:U.key,label:U.label});w&&s==="feedback"&&ge.push({key:"feedback",label:M.detailTab.feedback});for(const U of z)U.position==="after-feedback"&&U.shouldShow(N)&&ge.push({key:U.key,label:U.label})}f.useEffect(()=>{if(s!=="emendated"||!N)return;l("basic");const U=setTimeout(()=>{var me;(me=document.getElementById("studies"))==null||me.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(U)},[s,N,l]);const Ae=V&&N&&j?j({activeTab:s,activeJuan:Ne,entry:V,detail:N}):null,tt=f.useMemo(()=>{var qe;if(!N)return null;const me=(N.authors??[]).map(X=>{const $e=yi(X.role);return`${X.dynasty?`〔${W(X.dynasty)}〕`:""}${W(X.name)}${$e?` ${W($e)}`:""}`}).join(" · ");let Se=!1;try{Se=be.extractStatus(N.id)==="draft"}catch{}if(N.type==="book"){const X=N;return{title:W(X.title),subtitle:X.edition?W(X.edition):me||void 0,aside:[Se?M.status.draft:"",me&&X.edition?me:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(N.type==="collection"){const X=N;return{title:W(X.title),subtitle:W(st(X,M.unit.juan))||void 0,aside:[(qe=X.publication_info)==null?void 0:qe.year,Se?M.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:me||void 0}}if(N.type==="entity"){const X=N,$e=Je=>Je==null?"":Je<0?`前${-Je}`:String(Je),Oe=X.birth_year!=null||X.death_year!=null?`${$e(X.birth_year)||"?"}—${$e(X.death_year)||"?"}`:"";return{title:W(X.primary_name||X.title),subtitle:[X.dynasty?`〔${W(X.dynasty)}〕`:"",Oe].filter(Boolean).join(" ")||void 0,aside:Se?M.status.draft:void 0,secondLine:void 0}}const We=W(st(N,M.unit.juan));return{title:W(N.title),subtitle:[We,me].filter(Boolean).join(" · ")||void 0,aside:[mx(M,N.subtype),Se?M.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[N,W,M]),ut=N?N.type==="work"?(((Yi=ee==null?void 0:ee.juan_files)==null?void 0:Yi.length)??0)>0?"collated":ie.length>0?"fulltext":null:N.type==="book"&&(((je==null?void 0:je.chapters.length)??0)>0||N.has_full_text&&n.getBookFullTextIndex&&D!==N.id)?"fulltext":null:null,lt=ie.find(U=>U.primary)??ie[0],en=()=>{var U;ut==="collated"&&((U=ee==null?void 0:ee.juan_files)!=null&&U.length)?(Ee(ee.juan_files[0]),l("collated")):ut==="fulltext"&&((N==null?void 0:N.type)==="work"&&lt&&$(lt.key),Ee(null),l("fulltext"))};let at=null;if(N&&_){const U=_({detail:N,kind:ut,fullTextKey:N.type==="work"?lt==null?void 0:lt.key:void 0});U&&(at=t.jsx(Kn,{href:U}))}else ut&&(at=t.jsx(Kn,{onClick:en}));const tn=U=>{if(!N)return null;const me=U.replace(/\.[^.]+$/,"");if(_){const Se=_({detail:N,kind:"fulltext",juan:me});return Se?{href:Se}:null}return{onClick:()=>{Ee(me),l("fulltext")}}},ke=new Set(z.map(U=>U.key)),Ue=ge.filter(U=>U.key.startsWith("catalog:")&&U.key!=="catalog:loading"||ke.has(U.key)).map(U=>({key:U.key,label:U.label,onClick:()=>l(U.key)})),ze=()=>{var U;return N?N.type==="work"?t.jsx(Xs,{data:N,transport:n,onNavigate:b,renderLink:v,readAction:at,railTop:k,railLinks:Ue}):N.type==="book"?t.jsx(Qs,{data:N,transport:n,onNavigate:b,renderLink:v,readAction:at,fullText:je,fullTextPending:!!N.has_full_text&&!!n.getBookFullTextIndex&&D!==N.id,chapterLink:tn,railTop:k,railLinks:Ue}):N.type==="collection"?t.jsx(el,{data:N,catalog:(U=H[0])==null?void 0:U.data,transport:n,onNavigate:b,renderLink:v,readAction:at,railTop:k,railLinks:Ue,catalogAction:H.length>0?t.jsxs("a",{href:"#catalog",onClick:me=>{me.preventDefault(),l(`catalog:${H[0].resource_id}`)},children:[W(M.detailTab.collectionCatalog)," →"]}):null}):t.jsx(tl,{data:N,transport:n,onNavigate:b,renderLink:v,railTop:k,railLinks:Ue}):null},nn=()=>{var me,Se,We,qe;if(!V||!N)return null;if(s==="basic"||s==="emendated")return ze();if(typeof s=="string"&&s.startsWith("catalog:")){const X=(me=H.find($e=>`catalog:${$e.resource_id}`===s))==null?void 0:me.data;return t.jsx(fi,{data:X,onNavigate:b,renderLink:v})}if(s==="collated")return t.jsx(Mi,{index:ee||void 0,workId:e,transport:n,onNavigate:b,activeJuan:Ne,onJuanChange:Ee});if(s==="fulltext"&&N.type==="work"){const X=I??((Se=ie[0])==null?void 0:Se.key);return X?t.jsx(ti,{bookId:e,workKey:X,versions:ie,onVersionChange:$e=>{$($e),Ee(null)},transport:n,activeChapter:Ne,onChapterChange:Ee},X):t.jsx("div",{style:{padding:24,color:o("desc-fg")},children:q?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(ti,{index:je||void 0,bookId:e,transport:n,activeChapter:Ne,onChapterChange:Ee});if(s==="lineage"){if(!F)return t.jsx("div",{style:{color:o("label-fg"),padding:"24px 0"},children:Z?"加載中…":"暫無版本圖數據"});const X=N.type==="work"?N:null;return t.jsx(ul,{graph:F,renderLink:v,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:a,onModeChange:c,selectedNodeId:m,collection:u??((We=X==null?void 0:X.version_graph)==null?void 0:We.default_collection),onCollectionChange:g,collectionsAvailable:(qe=X==null?void 0:X.version_graph)==null?void 0:qe.collections,collectionCounts:(()=>{var Ki,qi,Ji,Zi,Xi,Qi,eo;if(!X)return;const $e={},Oe=((Ki=fe.current)==null?void 0:Ki.books)??[];$e.all=(((qi=X.books)==null?void 0:qi.length)??0)-(((Zi=(Ji=X.version_graph)==null?void 0:Ji.excluded_books)==null?void 0:Zi.length)??0);const Je=(Xi=X.version_graph)==null?void 0:Xi.collections;if(Je)for(const to of Object.keys(Je))$e[to]=pn(X,Oe,to).nodes.filter(no=>no.kind==="book"&&!no.bridge).length;return $e.core==null&&((eo=(Qi=X.version_graph)==null?void 0:Qi.core_books)!=null&&eo.length)&&($e.core=X.version_graph.core_books.length),$e})()})}if(s==="feedback"&&w)return t.jsx(Ks,{resourceId:e,apiUrl:C});const U=z.find(X=>X.key===s);return U?U.render({detail:N,entry:V,transport:n,onNavigate:b}):null};if(G)return t.jsx(Ot,{style:{minHeight:E,...O},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((U,me)=>t.jsx("div",{style:{height:me===1?40:16,width:U,opacity:.35,background:o("rule")}},me))})});if(ne||!N||!V||!tt)return t.jsx(Ot,{style:{minHeight:E,...O},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:o("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const Cn=s==="basic"||s==="emendated",on=[{label:h??M.detailTab.backToIndex,onClick:S}];if(N.type==="book"&&N.work_id){const U=N.work_id;on.push({label:M.indexType.work,id:U,onClick:()=>b==null?void 0:b(U)})}on.push({label:M.indexType[N.type]});const rn=s==="collated"||s==="fulltext",Ui=typeof R=="string"?M.status[R.trim()]??R:R,Vi=t.jsx(ls,{left:t.jsxs(t.Fragment,{children:[Ui,Ui?" · ":"",t.jsx(gx,{id:N.id,label:M.label.id,copied:M.action.copied,copyLabel:M.action.copy})]}),right:t.jsxs(t.Fragment,{children:[w&&!Cn&&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:M.detailTab.submitVersion}),Ae&&t.jsx("a",{href:Ae.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:o("meta-fg")},children:M.detailTab.dataLicense})]})});return Cn?t.jsx("div",{className:T,children:t.jsxs(Ot,{grid:!0,style:{minHeight:E,...O},children:[t.jsx(qn,{breadcrumb:t.jsx(Jn,{items:on}),actions:t.jsxs(t.Fragment,{children:[t.jsx(si,{style:{border:"none",background:"transparent"}}),Ae&&t.jsx(li,{...Ae})]})}),ze(),Vi]})}):t.jsx("div",{className:T,children:t.jsxs(Ot,{wide:rn,style:{minHeight:E,...O},children:[t.jsx(qn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(vi,{char:"籍"}),t.jsx(Jn,{items:on})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(si,{}),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:M.detailTab.feedback}),Ae&&t.jsx(li,{...Ae})]})}),t.jsx(Xr,{...tt,aside:rn?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:[W("作品信息")," →"]}):tt.aside}),!rn&&ge.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:ge.map(U=>t.jsx(Qr,{label:U.label,active:U.key===s||Cn&&U.key==="basic",onClick:()=>l(U.key)},U.key))}),t.jsx("div",{style:{marginTop:!rn&&ge.length>1?8:0},children:nn()}),Vi]})})};function gx({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 d;(d=navigator.clipboard)==null||d.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 mx(e,n){return n?e.workSubtype[n]??n:""}const xl=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛藍"}],_n="zhusha",$n="bim-theme";function fl(e){return e==="zhusha"||e==="indigo"}function zn(e){return fl(e)?e:_n}function hx(){try{return zn(window.localStorage.getItem($n))}catch{return _n}}function gl(e){try{window.localStorage.setItem($n,e)}catch{}}function ml(e){const n=zn(e);return document.documentElement.setAttribute("data-theme",n),n}function hl(){return zn(document.documentElement.getAttribute("data-theme"))}const bx=`try{if(localStorage.getItem(${JSON.stringify($n)})==='indigo')document.documentElement.setAttribute('data-theme','indigo')}catch(e){}`,yx={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo"},jx=({onChange:e,style:n})=>{const{convert:i}=Y(),[r,s]=f.useState(_n);f.useEffect(()=>{s(hl())},[]);const l=d=>{s(ml(d)),gl(d),e==null||e(d)};return t.jsx("div",{role:"radiogroup","aria-label":i("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:xl.map(d=>{const p=r===d.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":p,"aria-label":i(d.label),title:i(d.label),onClick:()=>l(d.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(yx[d.name]),boxShadow:p?`0 0 0 2px ${o("page-bg")}, 0 0 0 3.5px ${o("aux-fg")}`:"none"}})},d.name)})})};exports.BidLink=be.BidLink;exports.BookIndexError=be.BookIndexError;exports.BookIndexManager=be.BookIndexManager;exports.BookIndexStorage=be.BookIndexStorage;exports.BundleStorage=be.BundleStorage;exports.ConfigError=be.ConfigError;exports.GithubStorage=be.GithubStorage;exports.IdGenerationError=be.IdGenerationError;exports.IdGenerator=be.IdGenerator;exports.LocalStorage=be.LocalStorage;exports.MigrationError=be.MigrationError;exports.StorageError=be.StorageError;exports.base36Decode=be.base36Decode;exports.base36Encode=be.base36Encode;exports.base58Decode=be.base58Decode;exports.buildId=be.buildId;exports.buildPromotionMap=be.buildPromotionMap;exports.cleanName=be.cleanName;exports.decodeId=be.decodeId;exports.decodeIdString=be.decodeIdString;exports.encodeId=be.encodeId;exports.extractIdFromUrl=be.extractIdFromUrl;exports.extractStatus=be.extractStatus;exports.extractType=be.extractType;exports.normalizeCatalog=be.normalizeCatalog;exports.parseId=be.parseId;exports.shardOf=be.shardOf;exports.smartDecode=be.smartDecode;exports.validateResource=be.validateResource;exports.Badge=gn;exports.BidUrlProvider=Cl;exports.BookDetailLayout=fx;exports.BookFullText=ti;exports.BookPage=Qs;exports.Breadcrumb=Jn;exports.CATALOG_ALL_ID=it;exports.CATALOG_CSS=nl;exports.CATALOG_NARROW_QUERY=Di;exports.CATALOG_PAGE_SIZE=Hi;exports.CATALOG_UNCLASSIFIED_ID=Vt;exports.CardFoot=Zt;exports.CatalogPage=Pu;exports.CatalogPager=ll;exports.CatalogTree=ol;exports.CheckFilter=Jr;exports.Chip=es;exports.ChipWall=vc;exports.CollatedEdition=Mi;exports.CollectionCatalog=fi;exports.CollectionPage=el;exports.CreateEntityDialog=Ps;exports.DEFAULT_READER_PREFS=wi;exports.DEFAULT_THEME=_n;exports.DETAIL_CSS=Zr;exports.Dash=zc;exports.DataTable=Sc;exports.DetailFooter=ls;exports.DetailGrid=qt;exports.DetailHeader=Xr;exports.EmendatedBySection=Rr;exports.EmptyNote=Lc;exports.EntityDetail=$r;exports.EntityPage=tl;exports.EntityPickerDialog=Ds;exports.EntitySelector=Fs;exports.ExpandRow=Cc;exports.ExtLink=Bc;exports.FEEDBACK_FAB_OFFSET_VAR=ii;exports.FONT_SIZE_STEPS=wt;exports.FactList=hc;exports.FeedbackButton=iu;exports.FeedbackDialog=Vs;exports.FeedbackForm=Ys;exports.FeedbackList=Fi;exports.FeedbackTab=Ks;exports.FilterChip=Qr;exports.FormInput=He;exports.FormTextArea=ht;exports.GUJI_MARKDOWN_FIELD=ic;exports.GUJI_TABLE_NOTATION=bs;exports.GlyphBadge=vi;exports.GujiTable=Ci;exports.HomePage=ei;exports.ImagePanel=xs;exports.IndexApp=ap;exports.IndexBrowser=Gn;exports.IndexDetail=xi;exports.IndexEditor=Hs;exports.IndexView=Gp;exports.IntroGrid=mc;exports.LocaleContext=Tt;exports.LocaleProvider=Dl;exports.LocaleToggle=si;exports.MetaLine=Be;exports.ModeIndicator=Sr;exports.MoreButton=jc;exports.MoreLink=Nt;exports.PAGE_MAX_WIDTH=cn;exports.PageFrame=Ot;exports.Quote=Tc;exports.READER_CSS=ds;exports.RECENT_IDS_STORAGE_KEY=$t;exports.ROLE_CLASS_ORDER=Fr;exports.ReadButton=Kn;exports.ReaderMdText=Ri;exports.ReaderShell=$i;exports.ReaderToc=us;exports.RelationPanel=Ws;exports.RepoSourceLink=li;exports.ResourceEditor=Hn;exports.ResourceGroup=Ec;exports.ResourceLine=Rc;exports.ResourceList=ui;exports.ResourceRow=rs;exports.SNIPPET_MARK_END=mr;exports.SNIPPET_MARK_START=gr;exports.SearchInput=wr;exports.Sec=Fe;exports.Section=Ye;exports.SectionHead=bc;exports.SideList=mt;exports.SmartBidInput=dn;exports.SourceEditor=Ls;exports.SummaryCard=Jt;exports.THEMES=xl;exports.THEME_INIT_SCRIPT=bx;exports.THEME_STORAGE_KEY=$n;exports.TabFilter=kn;exports.TableHead=wc;exports.TableRow=_c;exports.TagRow=ss;exports.TagRows=Nc;exports.TextButton=yc;exports.ThemeToggle=jx;exports.TopStrip=qn;exports.VersionLineageGraph=pl;exports.VersionLineageList=dl;exports.VersionLineageView=ul;exports.VolumeChips=kc;exports.VolumeLinks=ki;exports.WorkCard=sl;exports.WorkCardGrid=al;exports.WorkCatalog=cp;exports.WorkPage=Xs;exports.applyTheme=ml;exports.bucketResources=hi;exports.buildCatalogTree=Tu;exports.buildCollectionTable=Or;exports.buildLineageGraph=pn;exports.buildPageUrl=pi;exports.buildParagraphBlocks=$s;exports.buildVersionRow=Wr;exports.buildVersionTable=Mr;exports.canParagraphize=wn;exports.catalogNodeIdOf=Cu;exports.catalogNodeIdsOf=Iu;exports.catalogPageCount=Lu;exports.catalogTotal=Gi;exports.classificationPath=Qt;exports.compareCatalogCards=Nu;exports.computeVersionPartition=Qa;exports.currentTheme=hl;exports.defaultWorkLink=rl;exports.deriveDating=Ja;exports.deriveEditionType=Hr;exports.deriveEra=Kt;exports.deriveYear=yn;exports.deriveYearRange=mi;exports.detailToEditor=Us;exports.detectGenre=Sn;exports.displayAuthorRole=yi;exports.editorToDetail=Hp;exports.eraRank=Vn;exports.findCatalogPath=_t;exports.flattenTitles=Zn;exports.flattenToc=hs;exports.formatTemplate=Yt;exports.formatVolumeRange=vn;exports.getDisplayNameFromUrl=Et;exports.getStartPage=di;exports.getTypeGroupKey=ai;exports.groupRelatedWorks=Za;exports.gujiInlineToPlain=Yr;exports.hasGujiMarkdownV02=Yn;exports.hasGujiTableNotation=ys;exports.isThemeName=fl;exports.measureText=st;exports.mergeVolumeResources=ci;exports.normalizeEra=Me;exports.normalizeRole=bi;exports.normalizeTheme=zn;exports.normalizeVolumeIndex=Ht;exports.normalizeVolumes=kr;exports.numberToChinese=Dr;exports.paginationItems=il;exports.parseChineseNumber=un;exports.parseGujiInline=Vr;exports.parseGujiTable=vs;exports.parseSourceString=Bs;exports.pickReaderVersion=ms;exports.readStoredTheme=hx;exports.readerVersionOptionLabel=Qn;exports.readerVersionsFromFullText=gs;exports.renderFullTextBody=od;exports.renderProperNames=Cs;exports.renderReaderInline=Ei;exports.resourceHref=Rt;exports.resourceNote=jn;exports.roleFacets=Pr;exports.rowNo=$c;exports.sortYear=xn;exports.splitFullTextTables=zi;exports.splitHighlightSnippet=hr;exports.splitTableRow=js;exports.storeTheme=gl;exports.stringifySources=As;exports.toCatalogWorkCard=Ru;exports.useBidUrl=Pe;exports.useConvert=Y;exports.useReaderPrefs=_i;exports.useT=de;exports.validateLineageGraph=Uu;exports.volumeStats=mn;
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;