book-index-ui 0.20.0 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,21 +1,21 @@
1
- "use strict";var bl=Object.create;var oo=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&&oo(e,s,{get:()=>n[s],enumerable:!(r=yl(n,s))||r.enumerable});return e};var ln=(e,n,i)=>(i=e!=null?bl(vl(e)):{},Sl(n||!e||!e.__esModule?oo(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ye=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}`,gr=f.createContext(zl);function Cl({buildUrl:e,children:n}){const i=f.useMemo(()=>e,[e]);return t.jsx(gr.Provider,{value:i,children:n})}function Fe(){return f.useContext(gr)}const mr="",hr="";function br(e){const n=[];let i=!1,r=e;for(;r.length;){const s=i?hr:mr,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 ro='"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:ro,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:ro,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Tl=Object.assign({},...Il.map(e=>e.tokens)),yr={};for(const[e,n]of Object.entries(Tl))yr[e]=`var(--bim-${e}, ${n.value})`;function o(e){const n=yr[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function ht(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 ht(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),jr={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,a)=>a.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 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 Wl(){if(At)return At;try{At=Al(wl.Converter({from:"tw",to:"cn"}))}catch{At=e=>e}return At}const Ml={"zh-Hant":jr,"zh-Hans":Nl},vr="bim-locale";function Fl(){try{const e=localStorage.getItem(vr);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Pl(e){try{localStorage.setItem(vr,e)}catch{}}const Ol="zh-Hans",Dl=({locale:e,onLocaleChange:n,converter:i,children:r})=>{const[s,l]=f.useState(e??Ol),a=e??s;f.useEffect(()=>{if(e)return;const u=Fl();u&&u!==s&&l(u)},[]);const p=f.useMemo(()=>a==="zh-Hans"?i??Wl():null,[a,i]),c=f.useCallback(u=>{l(u),Pl(u),n==null||n(u)},[n]),d=f.useMemo(()=>({locale:a,setLocale:c,messages:Ml[a],converter:p}),[a,c,p]);return t.jsx(Tt.Provider,{value:d,children:r})};function ce(){const e=f.useContext(Tt);return(e==null?void 0:e.messages)??jr}const Hl=2e3;function V(){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(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>=Hl){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 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=ce(),[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=y=>{if(!s)return!0;const v=ht(y);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((y,v)=>({item:y,originalIndex:v})).filter(({item:y})=>u(y)),x=()=>{const y=Ul();s&&(y.type=s),n([...e,y]),p(e.length)},m=y=>{n(e.filter((v,_)=>_!==y)),p(null)},b=(y,v,_)=>{const S=[...e];if(S[y]={...S[y],[v]:_},v==="url"&&!S[y].id){const z=Gl(_);z&&(S[y].id=z)}n(S)},k=(y,v,_)=>{const z={...e[y].metadata||{}};_?z[v]=_:delete z[v],b(y,"metadata",Object.keys(z).length>0?z:void 0)},h=(y,v)=>{const _=v.trim()?v.split(/[,,、]/).map(S=>S.trim()).filter(Boolean):void 0;b(y,"structure",_)},j=(y,v,_)=>{const z=e[y].coverage||{level:1,ranges:""};v==="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:v})=>{var _,S,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(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:Vl(y.type??"text"),color:o("on-color-fg")},children:(()=>{var C,L;const w=ht(y);return w.length===0?y.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")?((L=c.find(E=>E.value==="text+image"))==null?void 0:L.label)??"text+image":w.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${l.editor.resourcePlaceholder} ${v+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(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:[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:Wt,children:[t.jsx("span",{style:Mt,children:l.label.type}),t.jsx("select",{value:y.type,onChange:w=>b(v,"type",w.target.value),style:{...Xe,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:y.root_type||"catalog",onChange:w=>b(v,"root_type",w.target.value),style:{...Xe,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:y.id,onChange:w=>b(v,"id",w.target.value),placeholder:l.editor.idAutoExtract,style:{...Xe,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:y.name,onChange:w=>b(v,"name",w.target.value),placeholder:l.editor.resourceName,style:{...Xe,flex:1}})]}),t.jsx("input",{type:"text",value:y.url,onChange:w=>b(v,"url",w.target.value),placeholder:l.editor.resourceUrl,style:Xe}),t.jsx("input",{type:"text",value:((_=y.structure)==null?void 0:_.join("、"))||"",onChange:w=>h(v,w.target.value),placeholder:l.editor.structurePlaceholder,style:Xe}),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=y.coverage)==null?void 0:S.level)??"",onChange:w=>j(v,"level",w.target.value),placeholder:"1",style:{...Xe,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:((z=y.coverage)==null?void 0:z.ranges)||"",onChange:w=>j(v,"ranges",w.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...Xe,flex:1}})]})]}),t.jsx("textarea",{value:y.details||"",onChange:w=>b(v,"details",w.target.value),placeholder:l.editor.detailsPlaceholder,style:{...Xe,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 L;return t.jsxs("label",{style:{...Wt,gap:"4px"},children:[t.jsx("span",{style:{...Mt,minWidth:"56px"},children:C}),t.jsx("input",{type:"text",value:((L=y.metadata)==null?void 0:L[w])||"",onChange:E=>k(v,w,E.target.value),placeholder:C,style:{...Xe,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 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: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 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 Xe={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 Et(e){try{return ql[new URL(e).hostname]}catch{return}}const so={text:0,image:1,physical:2};function ai(e){return e.length===0?"physical":[...e].sort((n,i)=>(so[n]??99)-(so[i]??99)).join("+")}function ci(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}|${ai(ht(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 kr(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 Sr(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||kr(n)}))}function hn(e){const n=Sr(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 lo={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")?lo["text+image"]:lo[e[0]||"physical"]}const ui=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const l=ce(),{convert:a}=V(),p=f.useMemo(()=>ci(e||[]),[e]),{mirrorGroups:c,ungroupedItems:d}=f.useMemo(()=>{const h=new Map,j=[];for(const y of p){const v=y.group;v?(h.has(v)||h.set(v,[]),h.get(v).push(y)):j.push(y)}for(const y of h.values())y.sort((v,_)=>{const S=z=>z.group_role==="origin"?0:z.group_role==="mirror"?1:2;return S(v)-S(_)});return{mirrorGroups:h,ungroupedItems:j}},[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(j=>u[j]||j).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,j)=>t.jsx(In,{item:h},h.id||j))});const x=(h,j)=>{const y=i==null?void 0:i[h],v=(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: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:j.map((S,z)=>t.jsx(In,{item:S,onNavigate:r,renderLink:s},S.id||z))})]},`group-${h}`)},m=new Map;for(const h of d){const j=ai(ht(h));m.has(j)||m.set(j,[]),m.get(j).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,j])=>x(h,j)),k.map(h=>{const j=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:j.map((v,_)=>t.jsx(In,{item:v,onNavigate:r,renderLink:s},v.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=ce(),{convert:i}=V(),[r,s]=f.useState(!1),l=f.useMemo(()=>(e.url?Et(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||kr(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?{...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:[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=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: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)})})]})},wr=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:a})=>{const p=ce(),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",ao=10,co=8;function Ht(){try{const e=localStorage.getItem(bn);return e?JSON.parse(e):[]}catch{return[]}}function Xl(e){try{const n=Ht().filter(i=>i!==e);n.unshift(e),n.length>ao&&(n.length=ao),localStorage.setItem(bn,JSON.stringify(n))}catch{}}function Ql(e){try{const n=Ht().filter(i=>i!==e);localStorage.setItem(bn,JSON.stringify(n))}catch{}}function ea(){try{localStorage.removeItem(bn)}catch{}}const _r=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:l})=>{const a=ce(),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),j=f.useRef(null),y=f.useRef(null),v=f.useRef(null),_=f.useRef(!1);f.useEffect(()=>{b(-1);const T=n.trim();if(!T){x(k.map(F=>({type:"history",text:F})));return}if(!e.searchAll){x([]);return}let O=!1;const A=setTimeout(()=>{e.searchAll(T,co).then(F=>{if(O)return;const M=[...F.works,...F.books,...F.collections,...F.entities??[]];x(M.slice(0,co).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 T=O=>{v.current&&!v.current.contains(O.target)&&u(!1)};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[]),f.useEffect(()=>{const T=O=>{var A,F;if(O.key==="/"&&document.activeElement!==j.current){const M=(A=document.activeElement)==null?void 0:A.tagName;if(M==="INPUT"||M==="TEXTAREA"||M==="SELECT")return;O.preventDefault(),(F=j.current)==null||F.focus()}};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[]);const S=f.useCallback(T=>{T.trim()&&(Xl(T.trim()),h(Ht())),r(T),u(!1)},[r]),z=f.useCallback(T=>{T.type==="history"?(i(T.text),S(T.text)):T.entry&&(s?(s(T.entry),u(!1)):(i(T.text),S(T.text)))},[i,S,s]),w=f.useCallback(T=>{if(!d||g.length===0){T.key==="Enter"&&S(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]):S(n);break;case"Escape":T.preventDefault(),u(!1);break}},[d,g,m,n,S,z]),C=f.useCallback((T,O)=>{O.stopPropagation(),Ql(T),h(Ht()),x(A=>A.filter(F=>!(F.type==="history"&&F.text===T)))},[]),L=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 E=!n.trim()&&k.length>0;return t.jsxs("div",{ref:v,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:j,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"}}),d&&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:[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:L,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.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:[c[T.entry.type],T.entry.edition&&` · ${T.entry.edition}`,T.entry.author&&` · ${T.entry.author}`]}),T.type==="history"&&t.jsx("button",{onClick:A=>C(T.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:"×"})]},`${T.type}-${T.text}-${O}`))]})]})},$t="bim-recent-ids",po="bim-recent-entries",uo=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(po);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem($t,JSON.stringify(i)),localStorage.removeItem(po),i}return[]}catch{return[]}}function xo(e){try{const n=St().filter(i=>i!==e);n.unshift(e),n.length>uo&&(n.length=uo),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:a,onConfigurePath:p,onSelectFolder:c,hideModeIndicator:d,resultVariant:u="compact",renderEntry:g,initialQuery:x,onQueryChange:m,headerRight:b,reserveViewportHeight:k=!1})=>{const h=ce(),j=[{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,v]=f.useState(x??""),[_,S]=f.useState(null),[z,w]=f.useState(null),[C,L]=f.useState(!1),[E,T]=f.useState(null),[O,A]=f.useState(""),[F,M]=f.useState(!(x!=null&&x.trim())),[Y,K]=f.useState(St),[R,ie]=f.useState([]),[H,oe]=f.useState(!1),[ee,Q]=f.useState(!1),[G,ae]=f.useState(null),[ue,re]=f.useState(null),te=f.useRef(void 0),fe=f.useRef(!1),de=f.useCallback(async(N,I)=>{if(!N.trim()){M(!0),S(null),w(null);return}M(!1),L(!0),A("");try{if(e.searchAll){const $=await e.searchAll(N,I??Tn);S($)}else{const $=["work","book","collection","entity"],P=await Promise.all($.map(W=>e.search(N,W,{page:1,pageSize:I??Tn})));S({works:P[0].entries,books:P[1].entries,collections:P[2].entries,entities:P[3].entries,totalWorks:P[0].total,totalBooks:P[1].total,totalCollections:P[2].total,totalEntities:P[3].total})}}catch($){A($ instanceof Error?$.message:String($)),S(null)}finally{L(!1)}},[e]);f.useEffect(()=>{let N=!1;const I=()=>{var J,me;const $=["work","book","collection","entity"],P=Promise.all($.map(we=>e.loadEntries(we,{page:1,pageSize:1}).catch(()=>({total:0})))),W=((J=e.getResourceCounts)==null?void 0:J.call(e).catch(()=>null))??Promise.resolve(null),Z=((me=e.getSubtypeStats)==null?void 0:me.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([P,W,Z]).then(([we,_e,Ne])=>{N||(ae({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 P,W;N||(ae({works:$.works,books:$.books,collections:$.collections,entities:$.entities,hasText:(P=$.resourceCounts)==null?void 0:P.hasText,hasImage:(W=$.resourceCounts)==null?void 0:W.hasImage}),$.subtypeStats&&re($.subtypeStats))}).catch(()=>{N||I()}):I(),()=>{N=!0}},[e]),f.useEffect(()=>{fe.current||!(x!=null&&x.trim())||(fe.current=!0,de(x))},[x,de]);const Te=f.useCallback(N=>{if(v(N),!N.trim()){m==null||m(N),M(!0),S(null),w(null);return}te.current&&clearTimeout(te.current),te.current=setTimeout(()=>{w(null),m==null||m(N),de(N)},na)},[de,m]),be=f.useCallback(N=>{te.current&&clearTimeout(te.current),m==null||m(N),de(N)},[de,m]),ze=f.useCallback(N=>{w(N),de(y,ta)},[y,de]);f.useEffect(()=>{if(!Y.length){ie([]);return}let N=!1;return oe(!0),Promise.all(Y.slice(0,10).map(async I=>{var $,P,W;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:(P=J==null?void 0:J[0])==null?void 0:P.dynasty,role:(W=J==null?void 0:J[0])==null?void 0:W.role,edition:Z.edition||void 0}}}catch{}return{id:I,title:I,type:"work",notFound:!0}})).then(I=>{N||(ie(I),oe(!1))}),()=>{N=!0}},[Y,e]);const Ce=N=>{T(N.id),xo(N.id),K(St()),r==null||r(N)},Ee=(N,I)=>{if(r&&la(I)){I.preventDefault(),Ce(N);return}xo(N.id),K(St())},D=N=>{ia(N),K(St())},se=()=>{oa(),K([])},ne=N=>j.find(I=>I.type===N),ge=!F&&!_&&!O,q=_&&(_.works.length>0||_.books.length>0||_.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",style:k?{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,!d&&t.jsx(wr,{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(_r,{transport:e,value:y,onChange:Te,onSearch:be,onEntrySelect:Ce}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${o("primary")}`,borderRadius:"6px",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"13px"},children:h.action.newEntry})]}),F&&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:G&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:ue?t.jsxs(t.Fragment,{children:[(ue.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:o("fg")},children:ue.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:o("fg")},children:G.books.toLocaleString()})," 本"]}),ue.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:o("fg")},children:ue.article.toLocaleString()})," 篇"]}):null,ue.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:o("fg")},children:ue.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:o("fg")},children:G.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[h.indexType.work," ",t.jsx("strong",{style:{color:o("fg")},children:G.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.book," ",t.jsx("strong",{style:{color:o("fg")},children:G.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.collection," ",t.jsx("strong",{style:{color:o("fg")},children:G.collections.toLocaleString()}),G.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:G.entities.toLocaleString()})]})]})}),G.hasImage!=null&&G.hasText!=null&&t.jsxs("span",{children:[h.resourceType.image," ",t.jsx("strong",{style:{color:o("fg")},children:G.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.resourceType.text," ",t.jsx("strong",{style:{color:o("fg")},children:G.hasText.toLocaleString()})]})]})}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:C||ge?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})]}):F?t.jsx("div",{style:{flex:1},children:H?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:h.search.loading}):R.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:se,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:R.slice(0,ee?10:3).map(N=>N.notFound?t.jsx(ua,{id:N.id,onRemove:D,t:h},N.id):t.jsx(fo,{entry:N,selected:E===N.id,onClick:Ee,getConfig:ne,onRemove:D},N.id))}),!ee&&R.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}),j.map(({type:N,icon:I,name:$,key:P})=>{const W=_[P]??[],Z=ra[P],J=_[Z]??0;if(W.length===0)return null;const we=!(z===N)&&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:()=>ze(N),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:W.map(_e=>{if(g)return t.jsx(f.Fragment,{children:g(_e)},_e.id);const Ne=u==="card"?pa:fo;return t.jsx(Ne,{entry:_e,selected:E===_e.id,onClick:Ee,getConfig:ne,query:y},_e.id)})})]},N)})]}):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:Kt(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 an=(e,n,i)=>(i=e!=null?kl(_l(e)):{},zl(n||!e||!e.__esModule?ro(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const we=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),f=require("react"),Cl=require("opencc-js/t2cn"),Il=require("react-markdown"),Tl=require("remark-gfm"),El=e=>`/book-index?id=${e}`,hr=f.createContext(El);function Rl({buildUrl:e,children:n}){const i=f.useMemo(()=>e,[e]);return t.jsx(hr.Provider,{value:i,children:n})}function Pe(){return f.useContext(hr)}const br="",yr="";function jr(e){const n=[];let i=!1,r=e;for(;r.length;){const s=i?yr:br,l=r.indexOf(s);if(l===-1){n.push({text:r,marked:i});break}l>0&&n.push({text:r.slice(0,l),marked:i}),r=r.slice(l+1),i=!i}return n}function He(e,n){return{title:e,tokens:n}}const so='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Nl=[He("基础(VS Code 环境下跟随 --vscode-*)",{bg:{value:"#ffffff",vscode:"--vscode-editor-background"},fg:{value:"#333333",vscode:"--vscode-foreground"},"input-bg":{value:"#ffffff",vscode:"--vscode-input-background"},"input-fg":{value:"#333333",vscode:"--vscode-input-foreground"},"input-border":{value:"#cccccc",vscode:"--vscode-input-border"},"widget-border":{value:"#e0e0e0",vscode:"--vscode-widget-border"},"link-fg":{value:"#0066cc",vscode:"--vscode-textLink-foreground"},"desc-fg":{value:"#717171",vscode:"--vscode-descriptionForeground"},primary:{value:"#0078d4",vscode:"--vscode-button-background"},"primary-fg":{value:"#ffffff",vscode:"--vscode-button-foreground"},"primary-soft":{value:"rgba(0, 120, 212, 0.15)",css:"color-mix(in srgb, var(--bim-primary) 15%, transparent)"},danger:{value:"#f44336"},warning:{value:"#ff9800"},success:{value:"#4caf50"},"sidebar-bg":{value:"#f3f3f3",vscode:"--vscode-sideBar-background"},"list-hover-bg":{value:"rgba(0, 0, 0, 0.04)",vscode:"--vscode-list-hoverBackground"},"list-active-bg":{value:"rgba(0, 120, 212, 0.1)",vscode:"--vscode-list-activeSelectionBackground"},"focus-border":{value:"#0078d4",vscode:"--vscode-focusBorder"}}),He("底色层次 / 文字与描边 / 链接",{"bg-subtle":{value:"#fafafa"},"widget-bg":{value:"#f8f8f8"},muted:{value:"#888888"},border:{value:"#e5e5e5"},"primary-bg":{value:"#fdf4f4"},link:{value:"#1976d2"},"tag-bg":{value:"#f0f0f0"},"accent-bg":{value:"#1976d2"},"on-color-fg":{value:"#ffffff",note:"彩色底(徽章、选中态按钮)上的文字"}}),He("提示与警告",{"info-fg":{value:"#0c5380"},"info-bg":{value:"#e7f3ff"},"info-border":{value:"#b3dbff"},"warn-fg":{value:"#856404"},"warn-bg":{value:"#fff3cd"},"warn-border":{value:"#ffc107"},"danger-bg":{value:"rgba(244, 67, 54, 0.08)",note:"错误提示条底色"},"danger-soft-bg":{value:"rgba(244, 67, 54, 0.03)",note:"编辑器危险区块"},"danger-soft-border":{value:"rgba(244, 67, 54, 0.13)"}}),He("遮罩与阴影",{backdrop:{value:"rgba(0, 0, 0, 0.5)",note:"对话框遮罩"},"overlay-bg":{value:"#00000010",note:"轻量遮罩底(图片占位等)"},"shadow-dialog":{value:"0 4px 20px rgba(0, 0, 0, 0.3)"},"shadow-dropdown":{value:"0 4px 12px rgba(0, 0, 0, 0.1)"},"shadow-tooltip":{value:"0 2px 8px rgba(0, 0, 0, 0.08)"},"shadow-fab":{value:"0 2px 8px rgba(0, 0, 0, 0.25)",note:"悬浮按钮(反馈)"},"shadow-card":{value:"0 1px 4px rgba(0, 0, 0, 0.06)",note:"展开的卡片"},"shadow-node":{value:"0 1px 3px rgba(0, 0, 0, 0.1)",note:"谱系图节点"},"shadow-node-selected":{value:"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)"}}),He("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),He("资源",{"restype-text":{value:"#2196f3"},"restype-image":{value:"#ff9800"},"restype-text-image":{value:"#9c27b0"},"restype-physical":{value:"#795548"},"missing-fg":{value:"#e67e22",note:"资源缺册提示"},"colormode-bw-bg":{value:"#f5f5f5",note:"影印件色彩模式标记(黑白 / 彩色)"},"colormode-bw-fg":{value:"#757575"},"colormode-color-bg":{value:"#fff8e1"},"colormode-color-fg":{value:"#f57f17"},"progress-active":{value:"#f59e0b",note:"资源导入进度"},"progress-done":{value:"#10b981"},"progress-todo":{value:"#9ca3af"},"check-fine-bg":{value:"#e8f5e9",note:"文字资源校对程度徽章(精校 / 粗校 / AI整理)"},"check-fine-fg":{value:"#2e7d32"},"check-rough-bg":{value:"#fff3e0"},"check-rough-fg":{value:"#e65100"},"check-ai-bg":{value:"#e3f2fd"},"check-ai-fg":{value:"#1565c0"}}),He("整理本(CollatedEdition)",{"highlight-bg":{value:"#fff59d",note:"搜索命中高亮底"},"highlight-fg":{value:"inherit",root:!1},"section-lei":{value:"#8e6f3e",note:"章节类型标记:类 / 书 / 序 / 结语 / 考证 / 注释"},"section-shu":{value:"#c0392b"},"section-xu":{value:"#1a5276"},"section-jieyu":{value:"#7d6608"},"section-kaozhen":{value:"#5d6d7e"},"section-zhushi":{value:"#6c5b7b"},"section-tag-fg":{value:"#e74c3c",note:"章节标记(△ 等)"},"matchstate-fg":{value:"#b78900",note:"与底本匹配状态提示"},"quality-published":{value:"#1b5e20",note:"文本质量等级(出版 / 精校 / 粗校 / OCR)"},"quality-fine":{value:"#2e7d32"},"quality-rough":{value:"#1565c0"},"quality-ocr":{value:"#e65100"}}),He("版本传承(VersionLineageGraph / List) / 关系方向(RelationPanel)",{"lost-fg":{value:"#c62828",note:"佚失标记"},"confidence-certain":{value:"#2e7d32",note:"关系置信度"},"confidence-consensus":{value:"#1976d2"},"confidence-probable":{value:"#ed6c02"},"confidence-disputed":{value:"#c62828"},"lineage-edge-consensus":{value:"#555555",note:"⚠️ 同为 consensus,List 徽章用 --bim-confidence-consensus(蓝),Graph 连线用这个(灰)。若要统一,覆盖成 var(--bim-confidence-consensus)"},"relation-up":{value:"#2196f3"},"relation-down":{value:"#4caf50"},"relation-flat":{value:"#ff9800"}}),He("编辑器视图(主要在 guji-platform 插件中可见)",{"editor-type-work":{value:"#4caf50",note:"⚠️ 与展示视图的 --bim-type-* 是两套配色(历史如此)。若要统一,覆盖成对应的 var(--bim-type-*)"},"editor-type-collection":{value:"#2196f3"},"editor-type-book":{value:"#ff9800"},"editor-type-entity":{value:"#9c27b0"},"source-url":{value:"#2196f3",note:"来源类型(SourceEditor)"},"source-bookid":{value:"#4caf50"},"mode-active-bg":{value:"#2196f3",note:"模式指示器当前态(ModeIndicator)"},"cover-accent":{value:"#8e6f3e",note:'书目卡片「封面」点缀(IndexBrowser resultVariant="card")'}}),He("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --bim-primary 等控件色",{"page-bg":{value:"#fbf9f3",note:"纸"},"row-hover-bg":{value:"#f5f1e5"},"selection-bg":{value:"#ecdcbc",note:"选区"},"band-bg":{value:"#f0e4cb",note:"全文入口横幅(暖沙)"},"band-bg-hover":{value:"#e6d5b4"},ink:{value:"#2a231c",note:"文字层次:墨 → 正文 → 提要 → meta → 标签 → 提示"},"body-fg":{value:"#3b3228"},"quiet-fg":{value:"#5b4f40"},"meta-fg":{value:"#7b6a54"},"label-fg":{value:"#6f6457",note:"标签 / 提示:2026-09 N3a 调深,纸底与斑马底上对比度均 ≥4.5(原 #a3937b 2.8、#b3a385 2.3)"},"hint-fg":{value:"#756a5e"},accent:{value:"#9c3a2c",note:"朱"},"accent-deep":{value:"#6f2a20",note:"链接 hover"},"rule-strong":{value:"#2a231c",note:"分隔线:强 → 常规 → 虚线 → 提要左线"},rule:{value:"#e4dbc9"},"rule-dashed":{value:"#d6c9ae"},"rule-accent-soft":{value:"#e0d3b6"},"aux-fg":{value:"#6f6457",note:"辅助字(元数据、注记、「·」分隔的浅色小字)。须在 page-bg / zebra-bg 上对比度 ≥4.5(Q5 巡检)"},"card-bg":{value:"#fffdf9",note:"提要卡:抬起的面"},"zebra-bg":{value:"#f6f2eb",note:"表格斑马纹 / 左栏分组底(不画格线,靠这一阶底色分行)"},"tint-bg":{value:"#f3eee6",note:"检索框、悬停"},"shadow-summary":{value:"0 10px 32px rgba(60, 50, 40, 0.07)",note:"提要卡投影"},"flag-bg":{value:"rgba(158, 42, 43, 0.08)",note:"唯一的状态色块「有影印」"},"theme-dot-zhusha":{value:"#9c3a2c",note:"主题切换控件的色点:朱砂(不随主题变,两套主题下都要认得出)"},"theme-dot-indigo":{value:"#2e5266",note:"主题切换控件的色点:靛蓝"},"sect-jing":{value:"#2e5266",note:"四部分布条:經部(人物页提要卡;无别处使用)"},"sect-shi":{value:"#9a7a3b",note:"四部分布条:史部"},"sect-zi":{value:"#4f7a5c",note:"四部分布条:子部"},"sect-ji":{value:"#9fb3bc",note:"四部分布条:集部"},"table-border":{value:"color-mix(in srgb, currentColor 28%, transparent)",root:!1,note:"古籍表格(跟随当前文字色)"},"table-head-bg":{value:"color-mix(in srgb, currentColor 8%, transparent)",root:!1}}),He("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),He("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),He("字体(全站无衬线,2026-09-05 定)",{"font-ui":{value:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif'},"font-body":{value:"system-ui, sans-serif",css:"var(--bim-font-ui)"},"font-serif":{value:so,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:so,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Ll=Object.assign({},...Nl.map(e=>e.tokens)),vr={};for(const[e,n]of Object.entries(Ll))vr[e]=`var(--bim-${e}, ${n.value})`;function o(e){const n=vr[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function yt(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function Bl(e,n){return yt(e).includes(n)}const Hn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Al={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};o("quality-published"),o("quality-fine"),o("quality-rough"),o("quality-ocr");const Rt=f.createContext(null),kr={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:o("check-fine-bg"),fg:o("check-fine-fg")},粗校:{label:"粗校",bg:o("check-rough-bg"),fg:o("check-rough-fg")},AI整理:{label:"AI整理",bg:o("check-ai-bg"),fg:o("check-ai-fg")}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入叢編",collectedIn:"收入叢編",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評註",studies:"所考典籍"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"結果分類",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"概覽",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄",fullText:"全文",lineage:"版本傳承",feedback:"勘誤反饋",dataSource:"數據源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"數據源與授權"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},workSubtype:{book:"書",article:"篇",poem:"詩",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},Wl={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:o("check-fine-bg"),fg:o("check-fine-fg")},粗校:{label:"粗校",bg:o("check-rough-bg"),fg:o("check-rough-fg")},AI整理:{label:"AI整理",bg:o("check-ai-bg"),fg:o("check-ai-fg")}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入丛编",collectedIn:"收入丛编",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评注",studies:"所考典籍"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"结果分类",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"概览",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录",fullText:"全文",lineage:"版本传承",feedback:"勘误反馈",dataSource:"数据源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"数据源与授权"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},workSubtype:{book:"书",article:"篇",poem:"诗",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},Ml=["曹霑"];function Fl(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Pl(e,n=Ml){const i=[...new Set(n.filter(Boolean))].sort((l,a)=>a.length-l.length);if(!i.length)return e;const r=new RegExp(`(${i.map(Fl).join("|")})`,"g"),s=new Set(i);return l=>{if(!l)return e(l);const a=l.split(r);return a.length===1?e(l):a.map((p,c)=>c%2===1&&s.has(p)?p:p&&e(p)).join("")}}let At=null;function Ol(){if(At)return At;try{At=Pl(Cl.Converter({from:"tw",to:"cn"}))}catch{At=e=>e}return At}const Dl={"zh-Hant":kr,"zh-Hans":Wl},Sr="bim-locale";function Hl(){try{const e=localStorage.getItem(Sr);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Gl(e){try{localStorage.setItem(Sr,e)}catch{}}const Ul="zh-Hans",Vl=({locale:e,onLocaleChange:n,converter:i,children:r})=>{const[s,l]=f.useState(e??Ul),a=e??s;f.useEffect(()=>{if(e)return;const u=Hl();u&&u!==s&&l(u)},[]);const p=f.useMemo(()=>a==="zh-Hans"?i??Ol():null,[a,i]),c=f.useCallback(u=>{l(u),Gl(u),n==null||n(u)},[n]),d=f.useMemo(()=>({locale:a,setLocale:c,messages:Dl[a],converter:p}),[a,c,p]);return t.jsx(Rt.Provider,{value:d,children:r})};function ue(){const e=f.useContext(Rt);return(e==null?void 0:e.messages)??kr}const Yl=2e3;function q(){const e=f.useContext(Rt),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const l=f.useCallback(a=>{if(!a)return"";if(!i)return a;const p=r.current.get(a);if(p!==void 0)return p;const c=i(a);if(r.current.size>=Yl){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(a,c),c},[i]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Kt(e,n){return e.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function ql(e){if(!e)return"";try{const n=new URL(e).hostname,i={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(i[n])return i[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function Kl(){return{id:"",name:"",url:"",type:"text",details:""}}const Gn=({items:e,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const l=ue(),[a,p]=f.useState(null),c=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],d=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=j=>{if(!s)return!0;const k=yt(j);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},g=e.map((j,k)=>({item:j,originalIndex:k})).filter(({item:j})=>u(j)),x=()=>{const j=Kl();s&&(j.type=s),n([...e,j]),p(e.length)},m=j=>{n(e.filter((k,$)=>$!==j)),p(null)},b=(j,k,$)=>{const v=[...e];if(v[j]={...v[j],[k]:$},k==="url"&&!v[j].id){const _=ql($);_&&(v[j].id=_)}n(v)},S=(j,k,$)=>{const _={...e[j].metadata||{}};$?_[k]=$:delete _[k],b(j,"metadata",Object.keys(_).length>0?_:void 0)},h=(j,k)=>{const $=k.trim()?k.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;b(j,"structure",$)},y=(j,k,$)=>{const _=e[j].coverage||{level:1,ranges:""};k==="level"?_.level=parseInt($)||1:_.ranges=$,b(j,"coverage",_.ranges?_:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[g.map(({item:j,originalIndex:k})=>{var $,v,_;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(a===k?null:k),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===k?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Jl(j.type??"text"),color:o("on-color-fg")},children:(()=>{var z,N;const w=yt(j);return w.length===0?j.type??"text":w.length===1?((z=c.find(T=>T.value===w[0]))==null?void 0:z.label)??w[0]:w.includes("text")&&w.includes("image")?((N=c.find(T=>T.value==="text+image"))==null?void 0:N.label)??"text+image":w.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:j.name||`${l.editor.resourcePlaceholder} ${k+1}`}),j.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:j.id}),j.url&&t.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",onClick:w=>w.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&j.url&&Zl(k,r==null?void 0:r[k],i,l),t.jsx("button",{onClick:w=>{w.stopPropagation(),m(k)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),a===k&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:[Bl(j,"image")&&j.url&&Xl(j,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.type}),t.jsx("select",{value:j.type,onChange:w=>b(k,"type",w.target.value),style:{...et,flex:1},children:c.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]}),t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.rootType}),t.jsx("select",{value:j.root_type||"catalog",onChange:w=>b(k,"root_type",w.target.value),style:{...et,flex:1},children:d.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:j.id,onChange:w=>b(k,"id",w.target.value),placeholder:l.editor.idAutoExtract,style:{...et,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:j.name,onChange:w=>b(k,"name",w.target.value),placeholder:l.editor.resourceName,style:{...et,flex:1}})]}),t.jsx("input",{type:"text",value:j.url,onChange:w=>b(k,"url",w.target.value),placeholder:l.editor.resourceUrl,style:et}),t.jsx("input",{type:"text",value:(($=j.structure)==null?void 0:$.join("、"))||"",onChange:w=>h(k,w.target.value),placeholder:l.editor.structurePlaceholder,style:et}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((v=j.coverage)==null?void 0:v.level)??"",onChange:w=>y(k,"level",w.target.value),placeholder:"1",style:{...et,width:"60px"}})]}),t.jsxs("label",{style:{...Wt,flex:1},children:[t.jsx("span",{style:Mt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:((_=j.coverage)==null?void 0:_.ranges)||"",onChange:w=>y(k,"ranges",w.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...et,flex:1}})]})]}),t.jsx("textarea",{value:j.details||"",onChange:w=>b(k,"details",w.target.value),placeholder:l.editor.detailsPlaceholder,style:{...et,minHeight:"60px",resize:"vertical"}}),t.jsxs("div",{style:{borderTop:`1px solid ${o("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"6px"},children:l.label.metadata}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([w,z])=>{var N;return t.jsxs("label",{style:{...Wt,gap:"4px"},children:[t.jsx("span",{style:{...Mt,minWidth:"56px"},children:z}),t.jsx("input",{type:"text",value:((N=j.metadata)==null?void 0:N[w])||"",onChange:T=>S(k,w,T.target.value),placeholder:z,style:{...et,flex:1}})]},w)})})]})]})]})]},k)}),t.jsxs("button",{onClick:x,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:l.action.addResource})]})]})};function Jl(e){switch(e){case"text":return o("restype-text");case"image":return o("restype-image");case"text+image":return o("restype-text-image");case"physical":return o("restype-physical")}}function Zl(e,n,i,r){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:a=>{a.stopPropagation(),s||i(e,"")},disabled:s,style:{background:"transparent",border:"none",color:o(l?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:l?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":s?"⏳":"⬇"})}function Xl(e,n){const i=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(e.url)||e.url.includes("iiif")||e.url.includes("image");return t.jsx("div",{style:{marginBottom:"12px"},children:i?t.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:o("overlay-bg")},children:t.jsx("img",{src:e.url,alt:e.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):t.jsx("div",{style:{padding:"12px",background:o("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:o("desc-fg")},children:n.editor.imageResourceLink})})}const et={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Wt={display:"flex",alignItems:"center",gap:"6px"},Mt={fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap"},Ql={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive","www.shuge.org":"書格","shuge.org":"書格","pan.baidu.com":"百度網盤"};function Nt(e){try{return Ql[new URL(e).hostname]}catch{return}}const lo={text:0,image:1,physical:2};function ci(e){return e.length===0?"physical":[...e].sort((n,i)=>(lo[n]??99)-(lo[i]??99)).join("+")}function di(e){var a;const n=p=>{const c=p.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const d=p.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},i=new Map;for(let p=0;p<e.length;p++){const c=e[p];if(c.volumes&&c.volumes.length>0)continue;const d=n(c.name);if(!d)continue;const[u,g]=d,x=`${u}|${ci(yt(c))}`;i.has(x)||i.set(x,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const m=i.get(x);m.volumes.push({volume:g,url:c.url||void 0,status:"found"}),m.indices.push(p)}const r=[],s=new Set;for(const p of i.values())if(!(p.volumes.length<2)){p.volumes.sort((c,d)=>c.volume-d.volume),p.base.volumes=p.volumes,p.base.expected_volumes=p.volumes.length,p.base.url||(p.base.url=((a=p.volumes.find(c=>c.url))==null?void 0:a.url)??""),r.push(p.base);for(const c of p.indices)s.add(c)}const l=[...r];for(let p=0;p<e.length;p++)s.has(p)||l.push(e[p]);return l}function wr(e){if(e.url)return e.url;for(const[n,i]of Object.entries(e))if(n.endsWith("_url")&&typeof i=="string")return i}function _r(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||wr(n)}))}function bn(e){const n=_r(e);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,r=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:r,expected:e.expected_volumes??i+r}}function pi(e){if(!e)return;const n=e.file_page_range||e.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function ui(e,n){try{if(new URL(e).hostname.includes("wikimedia.org")){const r=e.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const s=new URL(e);return s.searchParams.set("page",String(n)),s.toString()}return e}catch{return e}}function Lt(e){if(!e.url)return;const n=pi(e.metadata);return n?ui(e.url,n):e.url}const ao={text:o("restype-text"),image:o("restype-image"),"text+image":o("restype-text-image"),physical:o("restype-physical")};function ea(e){return e.includes("text")&&e.includes("image")?ao["text+image"]:ao[e[0]||"physical"]}const xi=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const l=ue(),{convert:a}=q(),p=f.useMemo(()=>di(e||[]),[e]),{mirrorGroups:c,ungroupedItems:d}=f.useMemo(()=>{const h=new Map,y=[];for(const j of p){const k=j.group;k?(h.has(k)||h.set(k,[]),h.get(k).push(j)):y.push(j)}for(const j of h.values())j.sort((k,$)=>{const v=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return v(k)-v($)});return{mirrorGroups:h,ungroupedItems:y}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},g=h=>u[h]?u[h]:h.split("+").map(y=>u[y]||y).join("+");if(!p||p.length===0)return t.jsx("div",{style:{padding:"16px",color:o("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((h,y)=>t.jsx(En,{item:h},h.id||y))});const x=(h,y)=>{const j=i==null?void 0:i[h],k=(j==null?void 0:j.label)||h,$=j==null?void 0:j.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:a(k)}),$&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.5},children:a($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:y.map((v,_)=>t.jsx(En,{item:v,onNavigate:r,renderLink:s},v.id||_))})]},`group-${h}`)},m=new Map;for(const h of d){const y=ci(yt(h));m.has(y)||m.set(y,[]),m.get(y).push(h)}const b=["text","image","text+image","physical"],S=[...b.filter(h=>m.has(h)),...[...m.keys()].filter(h=>!b.includes(h)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([h,y])=>x(h,y)),S.map(h=>{const y=m.get(h),j=ea(h.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:j,whiteSpace:"nowrap",flexShrink:0},children:g(h)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:y.map((k,$)=>t.jsx(En,{item:k,onNavigate:r,renderLink:s},k.id||$))})]},h)})]})},ta={bw:{label:"",bg:o("colormode-bw-bg"),fg:o("colormode-bw-fg")},color:{label:"",bg:o("colormode-color-bg"),fg:o("colormode-color-fg")}},En=({item:e})=>{const n=ue(),{convert:i}=q(),[r,s]=f.useState(!1),l=f.useMemo(()=>(e.url?Nt(e.url):void 0)||i(e.name),[e.url,e.name,i]),a=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(b=>({...b,url:b.url||wr(b)})),[e.volumes]),p=a&&a.length>0,c=p?new Set(a.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=p?new Set(a.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=e.expected_volumes??(p?c+d:0),g=e.color_mode?{...ta[e.color_mode],label:n.colorMode[e.color_mode]}:null,x=e.details&&!p?i(e.details):null,m={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",background:o("input-bg"),fontSize:"12px",color:o("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:m,children:[t.jsx("span",{style:{fontWeight:500},children:l}),g&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:g.bg,color:g.fg},children:g.label}),x&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:x}),p&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[c,"/",u,n.unit.volume,d>0&&t.jsxs("span",{style:{color:o("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),e.url&&t.jsx("a",{href:(()=>{const b=pi(e.metadata);return b?ui(e.url,b):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:o("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),p&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),p&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:a.map(b=>{const S=b.status==="missing";return b.url&&!S?t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${o("widget-border")}`,color:o("link-fg"),textDecoration:"none"},children:b.volume},b.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:o(S?"missing-fg":"desc-fg"),textDecoration:S?"line-through":"none",opacity:S?.6:1},children:b.volume},b.volume)})})]})},$r=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:a})=>{const p=ue(),c=e==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",g=u?u.split(/[/\\]/).pop()||u:"",x={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:o("primary-soft"),color:o("primary")},m={onMouseOver:S=>S.currentTarget.style.opacity="0.8",onMouseOut:S=>S.currentTarget.style.opacity="1"},b=t.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...x,background:o(d?"warning":"success"),color:o("on-color-fg")},...m,children:[t.jsx("span",{children:d?"📝":"📚"}),t.jsx("span",{children:d?"draft":"official"})]});return i==="index-browser"?c?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,t.jsxs("div",{onClick:r,title:p.mode.switchToSync,style:x,...m,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:p.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px"},...m,children:[t.jsx("span",{children:"📂"}),g&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:g})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:p.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:g||p.mode.configurePath,style:{...x,background:"transparent",padding:"6px",fontSize:"12px"},...m,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:c?p.mode.switchToGithub:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:c?"📁":"🌐"}),t.jsx("span",{children:c?p.mode.localMode:p.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&t.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...m,children:[t.jsx("span",{children:"📂"}),g&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:g})]}),!c&&g&&t.jsxs("div",{style:{...x,background:o("mode-active-bg"),color:o("on-color-fg"),cursor:"default"},title:u,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:g})]})]})},yn="bim-search-history",co=10,po=8;function Gt(){try{const e=localStorage.getItem(yn);return e?JSON.parse(e):[]}catch{return[]}}function na(e){try{const n=Gt().filter(i=>i!==e);n.unshift(e),n.length>co&&(n.length=co),localStorage.setItem(yn,JSON.stringify(n))}catch{}}function ia(e){try{const n=Gt().filter(i=>i!==e);localStorage.setItem(yn,JSON.stringify(n))}catch{}}function oa(){try{localStorage.removeItem(yn)}catch{}}const zr=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:l})=>{const a=ue(),p=l??a.search.placeholder,c={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,u]=f.useState(!1),[g,x]=f.useState([]),[m,b]=f.useState(-1),[S,h]=f.useState(Gt),y=f.useRef(null),j=f.useRef(null),k=f.useRef(null),$=f.useRef(!1);f.useEffect(()=>{b(-1);const C=n.trim();if(!C){x(S.map(A=>({type:"history",text:A})));return}if(!e.searchAll){x([]);return}let P=!1;const B=setTimeout(()=>{e.searchAll(C,po).then(A=>{if(P)return;const W=[...A.works,...A.books,...A.collections,...A.entities??[]];x(W.slice(0,po).map(V=>({type:"entry",text:V.title||V.id,entry:V})))}).catch(()=>{P||x([])})},80);return()=>{P=!0,clearTimeout(B)}},[n,S,e]),f.useEffect(()=>{const C=P=>{k.current&&!k.current.contains(P.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=P=>{var B,A;if(P.key==="/"&&document.activeElement!==y.current){const W=(B=document.activeElement)==null?void 0:B.tagName;if(W==="INPUT"||W==="TEXTAREA"||W==="SELECT")return;P.preventDefault(),(A=y.current)==null||A.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const v=f.useCallback(C=>{C.trim()&&(na(C.trim()),h(Gt())),r(C),u(!1)},[r]),_=f.useCallback(C=>{C.type==="history"?(i(C.text),v(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(i(C.text),v(C.text)))},[i,v,s]),w=f.useCallback(C=>{if(!d||g.length===0){C.key==="Enter"&&v(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(P=>(P+1)%g.length);break;case"ArrowUp":C.preventDefault(),b(P=>(P-1+g.length)%g.length);break;case"Enter":C.preventDefault(),m>=0&&m<g.length?_(g[m]):v(n);break;case"Escape":C.preventDefault(),u(!1);break}},[d,g,m,n,v,_]),z=f.useCallback((C,P)=>{P.stopPropagation(),ia(C),h(Gt()),x(B=>B.filter(A=>!(A.type==="history"&&A.text===C)))},[]),N=f.useCallback(C=>{C.stopPropagation(),oa(),h([]),x([])},[]);f.useEffect(()=>{if(m>=0&&j.current){const C=j.current.children;C[m]&&C[m].scrollIntoView({block:"nearest"})}},[m]);const T=!n.trim()&&S.length>0;return t.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:y,type:"text",placeholder:p,value:n,onChange:C=>{i(C.target.value),u(!0)},onCompositionStart:()=>{$.current=!0},onCompositionEnd:()=>{$.current=!1},onFocus:()=>{u(!0)},onKeyDown:w,style:{width:"100%",padding:"8px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),d&&g.length>0&&t.jsxs("div",{ref:j,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:o("input-bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"6px",boxShadow:o("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[T&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:o("desc-fg"),borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("span",{children:a.search.history}),t.jsx("button",{onClick:N,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),g.map((C,P)=>t.jsxs("div",{onClick:()=>_(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:o("fg"),background:P===m?o("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:[c[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&t.jsx("button",{onClick:B=>z(C.text,B),style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${C.type}-${C.text}-${P}`))]})]})},jn=({type:e,size:n=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:n,borderRadius:1,flex:"none",background:o(`type-${e}`),verticalAlign:"middle"}}),Ct="bim-recent-ids",uo="bim-recent-entries",xo=50,Rn=5,ra=50,sa=200;function _t(){try{const e=localStorage.getItem(Ct);if(e)return JSON.parse(e);const n=localStorage.getItem(uo);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Ct,JSON.stringify(i)),localStorage.removeItem(uo),i}return[]}catch{return[]}}function fo(e){try{const n=_t().filter(i=>i!==e);n.unshift(e),n.length>xo&&(n.length=xo),localStorage.setItem(Ct,JSON.stringify(n))}catch{}}function la(e){try{const n=_t().filter(i=>i!==e);localStorage.setItem(Ct,JSON.stringify(n))}catch{}}function aa(){try{localStorage.removeItem(Ct)}catch{}}const go={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Un=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c,hideModeIndicator:d,resultVariant:u="compact",renderEntry:g,initialQuery:x,onQueryChange:m,headerRight:b,reserveViewportHeight:S=!1})=>{const h=ue(),y=[{type:"work",name:h.indexType.work,key:"works"},{type:"book",name:h.indexType.book,key:"books"},{type:"collection",name:h.indexType.collection,key:"collections"},{type:"entity",name:h.indexType.entity,key:"entities"}],j=["work","collection","book","entity"],[k,$]=f.useState(x??""),[v,_]=f.useState(null),[w,z]=f.useState(null),[N,T]=f.useState("all"),[C,P]=f.useState(!1),[B,A]=f.useState(null),[W,V]=f.useState(""),[K,E]=f.useState(!(x!=null&&x.trim())),[le,G]=f.useState(_t),[ae,pe]=f.useState([]),[ee,X]=f.useState(!1),[ie,me]=f.useState(!1),[te,se]=f.useState(null),[fe,be]=f.useState(null),ze=f.useRef(void 0),ve=f.useRef(!1),ke=f.useCallback(async(M,ne)=>{if(!M.trim()){E(!0),_(null),z(null);return}E(!1),P(!0),V("");try{if(e.searchAll){const R=await e.searchAll(M,ne??Rn);_(R)}else{const R=["work","book","collection","entity"],J=await Promise.all(R.map(H=>e.search(M,H,{page:1,pageSize:ne??Rn})));_({works:J[0].entries,books:J[1].entries,collections:J[2].entries,entities:J[3].entries,totalWorks:J[0].total,totalBooks:J[1].total,totalCollections:J[2].total,totalEntities:J[3].total})}}catch(R){V(R instanceof Error?R.message:String(R)),_(null)}finally{P(!1)}},[e]);f.useEffect(()=>{let M=!1;const ne=()=>{var re,Se;const R=["work","book","collection","entity"],J=Promise.all(R.map(ye=>e.loadEntries(ye,{page:1,pageSize:1}).catch(()=>({total:0})))),H=((re=e.getResourceCounts)==null?void 0:re.call(e).catch(()=>null))??Promise.resolve(null),U=((Se=e.getSubtypeStats)==null?void 0:Se.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([J,H,U]).then(([ye,Le,Ye])=>{M||(se({works:ye[0].total,books:ye[1].total,collections:ye[2].total,entities:ye[3].total,hasText:Le==null?void 0:Le.hasText,hasImage:Le==null?void 0:Le.hasImage}),Ye&&be(Ye))})};return e.getCounts?e.getCounts().then(R=>{var J,H;M||(se({works:R.works,books:R.books,collections:R.collections,entities:R.entities,hasText:(J=R.resourceCounts)==null?void 0:J.hasText,hasImage:(H=R.resourceCounts)==null?void 0:H.hasImage}),R.subtypeStats&&be(R.subtypeStats))}).catch(()=>{M||ne()}):ne(),()=>{M=!0}},[e]),f.useEffect(()=>{ve.current||!(x!=null&&x.trim())||(ve.current=!0,ke(x))},[x,ke]);const Ne=f.useCallback(M=>{if($(M),!M.trim()){m==null||m(M),E(!0),_(null),z(null),T("all");return}ze.current&&clearTimeout(ze.current),ze.current=setTimeout(()=>{z(null),T("all"),m==null||m(M),ke(M)},sa)},[ke,m]),Ee=f.useCallback(M=>{ze.current&&clearTimeout(ze.current),T("all"),m==null||m(M),ke(M)},[ke,m]),O=f.useCallback(M=>{z(M),ke(k,ra)},[k,ke]);f.useEffect(()=>{if(!le.length){pe([]);return}let M=!1;return X(!0),Promise.all(le.slice(0,10).map(async ne=>{var R,J,H;try{if(e.getEntry){const re=await e.getEntry(ne);if(re)return re}const U=await e.getItem(ne);if(U){const re=U.authors;return{id:ne,title:U.title||ne,type:U.type||"work",author:(R=re==null?void 0:re[0])==null?void 0:R.name,dynasty:(J=re==null?void 0:re[0])==null?void 0:J.dynasty,role:(H=re==null?void 0:re[0])==null?void 0:H.role,edition:U.edition||void 0}}}catch{}return{id:ne,title:ne,type:"work",notFound:!0}})).then(ne=>{M||(pe(ne),X(!1))}),()=>{M=!0}},[le,e]);const ce=M=>{A(M.id),fo(M.id),G(_t()),r==null||r(M)},oe=(M,ne)=>{if(r&&da(ne)){ne.preventDefault(),ce(M);return}fo(M.id),G(_t())},he=M=>{la(M),G(_t())},Z=()=>{aa(),G([])},F=M=>y.find(ne=>ne.type===M),I=!K&&!v&&!W,D=v&&(v.works.length>0||v.books.length>0||v.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",style:S?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:pa}),t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("h1",{style:{margin:0,fontSize:"18px",color:o("fg")},children:h.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&t.jsx($r,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(zr,{transport:e,value:k,onChange:Ne,onSearch:Ee,onEntrySelect:ce}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${o("primary")}`,borderRadius:"6px",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"13px"},children:h.action.newEntry})]}),K&&t.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:te&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:fe?t.jsxs(t.Fragment,{children:[(fe.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:o("fg")},children:fe.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:o("fg")},children:te.books.toLocaleString()})," 本"]}),fe.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:o("fg")},children:fe.article.toLocaleString()})," 篇"]}):null,fe.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:o("fg")},children:fe.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:o("fg")},children:te.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[h.indexType.work," ",t.jsx("strong",{style:{color:o("fg")},children:te.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.book," ",t.jsx("strong",{style:{color:o("fg")},children:te.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.collection," ",t.jsx("strong",{style:{color:o("fg")},children:te.collections.toLocaleString()}),te.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.entity," ",t.jsx("strong",{style:{color:o("fg")},children:te.entities.toLocaleString()})]})]})}),te.hasImage!=null&&te.hasText!=null&&t.jsxs("span",{children:[h.resourceType.image," ",t.jsx("strong",{style:{color:o("fg")},children:te.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.resourceType.text," ",t.jsx("strong",{style:{color:o("fg")},children:te.hasText.toLocaleString()})]})]})}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:C||I?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg"),minHeight:ca,boxSizing:"border-box"},children:h.search.searching}):W?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:o("desc-fg")},children:W})}):K?t.jsx("div",{style:{flex:1},children:ee?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:h.search.loading}):ae.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:h.search.recentBrowse}),t.jsx("button",{onClick:Z,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:h.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:ae.slice(0,ie?10:3).map(M=>M.notFound?t.jsx(ga,{id:M.id,onRemove:he,t:h},M.id):t.jsx(mo,{entry:M,selected:B===M.id,onClick:oe,getConfig:F,onRemove:he},M.id))}),!ie&&ae.length>3&&t.jsx("button",{onClick:()=>me(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:h.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:h.search.searchTitle}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:h.search.searchSubtitle})]})}):D?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:ua}),(()=>{const M=U=>v[go[U]]??0,ne=j.map(U=>y.find(re=>re.type===U)).filter(U=>M(U.key)>0);if(ne.length<2)return null;const R=ne.reduce((U,re)=>U+M(re.key),0),J=U=>{if(T(U),U!=="all"&&w!==U){const re=y.find(ye=>ye.type===U),Se=(v[re.key]??[]).length;M(re.key)>Se&&O(U)}},H=U=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:o(U?"fg":"desc-fg"),fontWeight:U?700:400,boxShadow:U?`inset 0 -2px 0 ${o("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":h.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":N==="all",style:H(N==="all"),onClick:()=>J("all"),children:[h.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:R.toLocaleString()})]}),ne.map(U=>t.jsxs("button",{type:"button","aria-pressed":N===U.type,style:H(N===U.type),onClick:()=>J(U.type),children:[U.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:M(U.key).toLocaleString()})]},U.type))]})})(),y.map(({type:M,name:ne,key:R})=>{const J=v[R]??[],H=go[R],U=v[H]??0;if(J.length===0||N!=="all"&&N!==M)return null;const Se=N==="all"&&!(w===M)&&U>Rn;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${o("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:[t.jsx(jn,{type:M})," ",ne,t.jsxs("span",{style:{fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[U," ",h.unit.items]})]}),Se&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>O(M),style:{border:"none",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"12px"},children:h.action.viewAll})]}),t.jsx("div",{style:u==="list"?{display:"flex",flexDirection:"column",gap:0}:u==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:J.map(ye=>{if(g)return t.jsx(f.Fragment,{children:g(ye)},ye.id);const Le=u==="card"?fa:mo;return t.jsx(Le,{entry:ye,selected:B===ye.id,onClick:oe,getConfig:F,query:k},ye.id)})})]},M)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:Kt(h.search.noResultsFor,{query:k})}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:h.search.tryOther})]})})]})},ca=240;function da(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const pa=`
2
2
  .bim-ib-stats { min-height: 25px; box-sizing: content-box; }
3
3
  @media (max-width: 719px) { .bim-ib-stats { min-height: 46px; } }
4
- `,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}=V();return t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.6},children:br(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=ce(),{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:{...$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}),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(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]})]})]})]})},fo=({entry:e,selected:n,onClick:i,getConfig:r,query:s,onRemove:l})=>{const a=ce(),{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:{...$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:a.misc.textResource,children:"📝"}),e.has_image&&t.jsx("span",{title:a.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,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:"×"})]})},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}=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 ga({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 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=ce(),{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 z=v[S];z!=null&&z.title?k.set(m[S],z.title):z!=null&&z.primary_name?k.set(m[S],z.primary_name):_=!1}if(_)return k}catch{}const h=[...m],j=8,y=new Array(j).fill(0).map(async()=>{for(;h.length;){const v=h.shift();if(!v)break;if(!k.has(v))try{if(n.getEntry){const z=await n.getEntry(v);if(z!=null&&z.title){k.set(v,z.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(y),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:j=>{j.metaKey||j.ctrlKey||(j.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 zr=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:l})=>{var g;const a=ce(),{convert:p}=V();let c=!1;try{c=ye.extractStatus(e.id)==="draft"}catch{}const d=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: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(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 Cr={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,a]=ya(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 ja(e){try{return decodeURI(e)}catch{return e}}const va={...Cr,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},rt=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:s}=V(),l=n?va:Cr;return t.jsx("div",{className:r,style:i,children:t.jsx(_l,{remarkPlugins:[$l],components:l,children:s(e)})})},ka=["〇","一","二","三","四","五","六","七","八","九"],go=["","十","百","千"];function Ir(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+=go[p]:r+=ka[a]+go[p])}return r}function Tr(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=ce();return t.jsx("span",{style:Tr(Sa[e]),children:n.indexType[e]})}function _a({isDraft:e}){const n=ce(),i=o(e?"status-draft":"status-official");return t.jsx("span",{style:Tr(i),children:e?n.status.draft:n.status.official})}function $a({id:e}){const n=ce(),[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 Ue({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 Qe({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 Er({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(Ye,{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 Ye({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 za({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(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(Er,{authors:l,type:r,onNavigate:d,renderLink:u}),p]})]})}function Rr({items:e,label:n,showMeta:i,onNavigate:r,renderLink:s}){const l=ce(),{convert:a}=V();if(!e.length)return null;const[p,c]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(Ue,{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(Ye,{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(Qe,{label:l.label.titleInfo,children:a(d.title_info)}),d.author_info&&t.jsx(Qe,{label:l.label.authorInfo,children:a(d.author_info)}),d.edition&&t.jsx(Qe,{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 Ca({items:e,onNavigate:n,renderLink:i}){const r=ce();return t.jsx(Rr,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Nr({items:e,onNavigate:n,renderLink:i}){const r=ce();return t.jsx(Rr,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function Lr({label:e,items:n}){const{convert:i}=V();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(Ue,{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=ce();return t.jsx(Lr,{label:n.section.aliases,items:e})}function Ta({items:e}){const n=ce();return t.jsx(Lr,{label:n.section.attachedTexts,items:e})}function Ea({items:e}){const n=ce(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ue,{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=ce(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ue,{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=ce(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ue,{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 mo({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(Ue,{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(Ye,{id:c.id,label:d,onNavigate:r,renderLink:s})},c.id)})})]}):null}function En({book:e,onNavigate:n,renderLink:i}){const r=ce(),{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(Ye,{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(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 a=ce(),{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=Ba(e,x);return t.jsxs(t.Fragment,{children:[t.jsxs(Ue,{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(En,{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(En,{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(En,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Ba(e,n){var h,j;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=y=>{if(c.has(y))return!0;const v=n.node_groups[y];return v!=null&&p.has(v)},u=[],g=new Map,x=[];for(const y of e)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))u.push(y);else{const v=n.node_groups[y];v?(g.has(v)||g.set(v,[]),g.get(v).push(y)):x.push(y)}if(x.length+[...g.values()].reduce((y,v)=>y+v.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(y=>[y.id,y])),k=[...g.entries()].map(([y,v])=>{const _=b.get(y);return{id:y,label:(_==null?void 0:_.label)??y,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 Aa({workData:e,onNavigate:n,renderLink:i}){var a,p,c,d;const r=ce(),{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(Ye,{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:[Ir(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(Er,{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(rt,{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(Qe,{label:r.label.parentWork,children:t.jsx(Ye,{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=ce(),{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(Ye,{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 xi=({data:e,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:a,className:p,style:c})=>{var O,A,F,M,Y,K,R,ie;const d=ce(),{convert:u}=V(),[g,x]=f.useState(null),[m,b]=f.useState(!1),[k,h]=f.useState(null),[j,y]=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(oe=>{H||(oe?x(oe):h(d.misc.notFoundEntry))}).catch(oe=>{H||h(oe instanceof Error?oe.message:d.misc.loadFailed)}).finally(()=>{H||b(!1)}),()=>{H=!0}},[e,n,i]),f.useEffect(()=>{if(!S||!i){y(null),_([]);return}let H=!1;const oe=S.type==="book"||S.type==="collection"?S.work_id:void 0;if(oe?i.getItem(oe).then(ee=>{!H&&ee&&ee.type==="work"&&y(ee)}).catch(()=>{}):y(null),S.type==="book"){const ee=S;ee.contained_in&&ee.contained_in.length>0?Promise.all(ee.contained_in.map(Q=>{const G=typeof Q=="string"?Q:Q.id,ae=typeof Q=="string"?void 0:Q.volume_index;return i.getItem(G).then(ue=>({id:G,title:ue&&ue.title||G,volume_index:ae})).catch(()=>({id:G,title:G,volume_index:ae}))})).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,oe)=>t.jsx("div",{style:{height:oe===1?"32px":"16px",width:`${H}px`,background:o("widget-border"),borderRadius:"4px",opacity:.4}},oe))})});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(zr,{data:S,transport:i,onNavigate:r,renderLink:s,headerExtra:l})});const z=S.type==="book"?S:null,w=S.type==="collection"?S:null,C=S.type==="work"?S:null;let L=!1;try{L=ye.extractStatus(S.id)==="draft"}catch{}let E="";S.measure_info?E=u(S.measure_info):(O=S.juan_count)!=null&&O.number?E=Ir(S.juan_count.number)+d.unit.juan:(A=S.juan_count)!=null&&A.description&&(E=u(S.juan_count.description));const T=[];return(F=S.publication_info)!=null&&F.year&&T.push(t.jsx(Qe,{label:d.label.year,children:S.publication_info.year},"year")),(M=S.current_location)!=null&&M.name&&T.push(t.jsx(Qe,{label:d.label.currentLocation,children:u(S.current_location.name)},"loc")),(Y=S.page_count)!=null&&Y.description&&T.push(t.jsx(Qe,{label:d.label.pageCount,children:S.page_count.description},"page")),z!=null&&z.edition&&T.push(t.jsx(Qe,{label:d.label.edition,children:u(z.edition)},"ver")),C!=null&&C.parent_work&&T.push(t.jsx(Qe,{label:d.label.parentWork,children:t.jsx(Ye,{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(Qe,{label:d.label.parentWork,children:C.parent_works.map((H,oe)=>t.jsxs("span",{children:[oe>0&&"、",t.jsx(Ye,{id:H,onNavigate:r,renderLink:s})]},H))},"pws")),t.jsxs("div",{className:p,style:c,children:[t.jsx(za,{id:S.id,title:u(S.title),edition:S.edition?u(S.edition):void 0,type:S.type,isDraft:L,authors:S.authors,volumeText:E,meta:T,headerExtra:l,onNavigate:r,renderLink:s}),((K=S.description)==null?void 0:K.text)&&t.jsx(rt,{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,oe)=>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(rt,{text:H.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:o("fg")}})]},oe))}),v.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{children:d.section.containedIn}),t.jsx(Wa,{items:v,onNavigate:r,renderLink:s})]}),j&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{children:d.section.belongsToWork}),t.jsx(Aa,{workData:j,onNavigate:r,renderLink:s})]}),S.additional_works&&S.additional_works.length>0&&t.jsx(Ea,{items:S.additional_works}),S.additional_titles&&S.additional_titles.length>0&&t.jsx(Ia,{items:S.additional_titles}),S.attached_texts&&S.attached_texts.length>0&&t.jsx(Ta,{items:S.attached_texts}),S.indexed_by&&S.indexed_by.length>0&&t.jsx(Ca,{items:S.indexed_by,onNavigate:r,renderLink:s}),S.emendated_by&&S.emendated_by.length>0&&t.jsx(Nr,{items:S.emendated_by,onNavigate:r,renderLink:s}),S.resources&&S.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{children:d.section.resources}),t.jsx(ui,{items:S.resources,resourceGroups:S.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(mo,{title:d.section.relatedVersions,ids:z.related_books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.books)&&w.books.length>0&&t.jsx(mo,{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(Ue,{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(Ye,{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)+(((ie=C==null?void 0:C.collections)==null?void 0:ie.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:a}),(C==null?void 0:C.related_works)&&C.related_works.length>0&&(()=>{const H=[],oe=C.related_works.filter(re=>re.relation==="part_of"),ee=C.related_works.filter(re=>re.relation==="has_part"),Q=C.related_works.filter(re=>re.relation==="has_adaptation"),G=C.related_works.filter(re=>re.relation==="text_carried_by"),ae=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ue=C.related_works.filter(re=>!re.relation||!ae.has(re.relation));return oe.length>0&&H.push({label:d.section.belongsToWork,items:oe}),ee.length>0&&H.push({label:d.section.containedWorks,items:ee}),Q.length>0&&H.push({label:d.section.adaptations,items:Q}),G.length>0&&H.push({label:d.section.derivativeWorks,items:G}),ue.length>0&&H.push({label:d.section.relatedWorks,items:ue}),H.map(re=>t.jsxs("div",{children:[t.jsxs(Ue,{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(te=>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(Ye,{id:te.id,label:u(te.title),onNavigate:r,renderLink:s})},te.id))})]},re.label))})()]})};function Ma({data:e}){const n=ce(),{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 Fa({sections:e,activeSection:n,onSelect:i}){const r=ce();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:ho(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:ho(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 ho(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=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 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 bo({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const s=ce(),{convert:l}=V(),a=e.book_id||e.work_id,p=r&&e.volumes.length>0?Oa(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(Pa,{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 fi=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:l,style:a})=>{const p=ce(),[c,d]=f.useState(null),[u,g]=f.useState(!1),[x,m]=f.useState(null),[b,k]=f.useState(null),[h,j]=f.useState(""),y=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=(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(L=>L.volumes[0]).filter(L=>L!=null);return new Set(w).size<w.length},[y]),S=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(L=>L.title.toLowerCase().includes(C)||L.sub_items&&L.sub_items.some(E=>E.toLowerCase().includes(C))||L.edition&&L.edition.toLowerCase().includes(C))}return w},[y,b,h]),z=f.useMemo(()=>{if(!_)return null;const w=[],C=new Map;for(const E of S){if(!E.volumes||E.volumes.length===0)continue;const T=E.volumes[0];C.has(T)||C.set(T,[]),C.get(T).push(E)}const L=[...C.keys()].sort((E,T)=>E-T);for(const E of L)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}):y?t.jsxs("div",{className:l,style:a,children:[t.jsx(Ma,{data:y}),v&&t.jsx(Fa,{sections:y.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=>j(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:[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:Kt(p.catalog.volume,{n:w.volume})}),w.books.map((L,E)=>t.jsx(bo,{book:L,onNavigate:r,renderLink:s,showVolumes:L.volumes.length>1},`${w.volume}-${E}`))]},`${w.volume}-${C}`)):S.map((w,C)=>t.jsx(bo,{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},bt=()=>{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)})},Br=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Da={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Ae(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},Ar={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function yn(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=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,yo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function gi(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(yo))if(n.startsWith(s))return yo[s];const i=Ae(n);if(xt[i]!=null)return i;const r=ot(n);if(r&&n.length<=r.length+1)return Ae(r)}function ut(e,n){if(n){const i=Ar[`${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=et[e];let r;for(const[s,l]of Object.entries(Ct))et[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 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=Ya[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 ot(e){for(const n of Br)if(e.startsWith(n))return n}const et={};{const e=(n,i)=>{for(const r of i)et[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function ft(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(Ct))if(e.includes(r)&&!(i&&et[r]&&et[r]!==i&&Ar[`${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=ot(r)??"";return{era:Ae(d),reign:ft(r,d)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const d=yn(s);if(d)return{era:Ha(d.from),reign:"",source:"publication"};const u=ot(s)??gi(s)??((c=zt.find(m=>m.pattern.test(s)))==null?void 0:c.era)??"",g=ft(s,u)??"",x=u||(g?et[g]??"":"");if(x||g)return{era:Ae(x),reign:g,source:"publication"}}const l=e.edition||e.title||"";if(l){const d=ot(l);if(d)return{era:Ae(d),reign:ft(l,d)??"",source:"edition"};const u=zt.find(g=>g.pattern.test(l));if(u)return{era:Ae(u.era),reign:ft(l,u.era)??u.reign??"",source:"edition"}}return n}function jn(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=yn(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&&(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 v=parseInt(b[1],10);if(v>=100&&v<=2100)return v}const k=x.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(k){const v=ot(x);if(!v||Ae(v)==="民國"){const S=xn(k[1]);if(S!=null&&S>=1&&S<=120)return Ua+S}}const h=ot(x)??((u=zt.find(v=>v.pattern.test(x)))==null?void 0:u.era),j=h?Ae(h):void 0,y=ft(x,j)??(ot(x)||(g=zt.find(v=>v.pattern.test(x)))==null?void 0:g.reign);if(y){const v=ut(y,j);if(v==null)continue;const _=x.indexOf(y),S=_>=0?x.slice(_+y.length):"",z=S.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??S.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),w=z?xn(z[1]):void 0;return v+(w?w-1:0)}}}function mi(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=Un[Ae(x[1])],b=xt[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=yn(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[Ae(m[1])],k=xt[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=ot(x)??gi(x)??((g=zt.find(h=>h.pattern.test(x)))==null?void 0:g.era),b=m?Ae(m):void 0,k=[];for(const h of Object.keys(Ct))x.includes(h)&&(b&&et[h]&&et[h]!==b||ut(h,b)!=null&&k.push(h));if(k.length===0){const h=x.match(/([一-鿿])([一-鿿])[間间]/);if(h&&b){for(const j of[h[1],h[2]])for(const y of Object.keys(Ct))if(et[y]===b&&!(y[0]!==j&&y[y.length-1]!==j)&&ut(y,b)!=null){k.push(y);break}}}if(k.length>0){const h=k.map(_=>ut(_,b)).filter(_=>_!=null),j=Math.min(...h),y=k.reduce((_,S)=>ut(_,b)>=ut(S,b)?_:S),v=Va(y)??Rn(b??"")??Math.max(...h);return{from:j,to:v>j?v:Rn(b??et[y]??"")??j}}if(b&&xt[b]!=null)return{from:xt[b],to:Rn(b)??xt[b]}}}const xt={漢:-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=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,jo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function vo(e,n){for(const i of Br){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!ft(e.slice(r),Ae(i)))continue}const s=Ae(i);if(s===n)continue;const l=e.slice(r),a=ft(l,s)??"";let p;if(a){const c=ut(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 zt)if(i.pattern.test(e))return{era:Ae(i.era),reign:i.reign??""}}function Ja(e){var j,y,v,_,S;const n=qt(e),i=((j=e.publication_info)==null?void 0:j.year)??"",r=i?yn(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),a=((y=e.lineage)==null?void 0:y.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(a),c=n.source==="publication"&&Ga.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=jn(e);const x=g==null?mi(e):void 0;let m;n.source==="publication"&&(c||jo.test(i))?m="uncertain":n.source==="lineage"||n.source==="publication"?m="attested":jo.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 z=a.match(/[、,,]\s*([宋元明清])/);z&&z[1]!==k.era&&(k.laterRepair={era:z[1]})}if(!k.laterRepair&&qa.test(s)){const z=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);z&&z[1]!==n.era&&(k.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=vo(w,n.era)??vo(s,n.era);C&&(k.basedOn={era:C.era,reign:C.reign,year:C.year,relation:h.relation})}return k}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 fn(e){const n=jn(e);if(n!=null)return n;const i=mi(e);if(i)return i.from;const r=qt(e).era;return r?xt[r]:void 0}const ko=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Vn(e){const n=ko.indexOf(e);return n===-1?ko.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 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=ht(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 vn(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 Wr(e,n){if(vn(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 Mr(e,n){var l,a;const i=e.resources||[],r=[],s=[];for(const p of i){const c=ht(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:jn(e),sortYear:fn(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:Xa(e.id,n),group:(a=n==null?void 0:n.node_groups)==null?void 0:a[e.id],hasImage:r.length>0}}function Xa(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 Fr(e,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!r.has(c.id)).map(c=>Mr(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)=>Vn(c)-Vn(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(c=>c.era.source==="edition")}}function Qa(e,n){var h,j;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=y=>{if(c.has(y))return!0;const v=n.node_groups[y];return v!=null&&p.has(v)},u=[],g=new Map,x=[];for(const y of e)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))u.push(y);else{const v=n.node_groups[y];v?(g.has(v)||g.set(v,[]),g.get(v).push(y)):x.push(y)}if(x.length+[...g.values()].reduce((y,v)=>y+v.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(y=>[y.id,y])),k=[...g.entries()].map(([y,v])=>{const _=b.get(y);return{id:y,label:(_==null?void 0:_.label)??y,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 Pr=["撰","編","注","校","譯","繪","其他"],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 Or(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 Pr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function Dr(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 kn(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 tc=["〇","一","二","三","四","五","六","七","八","九"],So=["","十","百","千"];function Hr(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+=So[p]:r+=tc[a]+So[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?Hr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Gr(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 Ur(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=Ur(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 Vr(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=lc(e,n);if(c){a(),s.push(c.node),n=c.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&rc(e,n)&&(d=">"),d){const u=Vr(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 Yr(e){return Vr(e,0,null,!1).nodes}function ac(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function Kr(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Kr(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const cc=216,wo="clamp(280px, 23vw, 360px)",dc=1440,qr="(max-width: 719px)",pc=`${qr}, (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}=q();return t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.6},children:jr(e).map((i,r)=>i.marked?t.jsx("mark",{style:{background:o("highlight-bg"),color:o("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(i.text)},r):t.jsx(f.Fragment,{children:n(i.text)},r))})},fa=({entry:e,selected:n,onClick:i,getConfig:r,query:s})=>{const l=ue(),{convert:a}=q(),p=a(e.title||e.primary_name||e.id),c=e.measure_info?a(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",d=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&d.length?d.find(m=>{const b=typeof m=="string"?m:m==null?void 0:m.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,g=o("cover-accent"),x=Pe();return t.jsxs("a",{href:x(e.id),onClick:m=>i(e,m),className:"bim-result-card",style:{...Cr,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:o("bg"),border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[t.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${g} 50%, ${o("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${g} 14%, ${o("bg")}), color-mix(in srgb, ${g} 7%, ${o("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[t.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${g} 45%, transparent)`}}),t.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:g},children:Array.from(p).map((m,b)=>t.jsx("span",{children:m},b))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:o("fg")},children:p}),c&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",a(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:a(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",a(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",a(e.era),"〕"]}),e.edition&&t.jsx("span",{children:a(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[l.search.alias,":",a(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(xa,{snippet:e.descriptionSnippet}),t.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[t.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:[t.jsx(jn,{type:e.type,size:8})," ",r(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:l.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:l.misc.imageResource})]})]})]})},mo=({entry:e,selected:n,onClick:i,getConfig:r,query:s,onRemove:l})=>{const a=ue(),{convert:p}=q(),c=[...e.additional_titles||[],...e.attached_texts||[]],d=s&&c.length?c.find(g=>{const x=typeof g=="string"?g:g==null?void 0:g.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,u=Pe();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("a",{href:u(e.id),onClick:g=>i(e,g),className:"bim-result-card",style:{...Cr,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx(jn,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:o("desc-fg"),lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:p(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{children:a.misc.textResource}),e.has_image&&t.jsx("span",{children:a.misc.imageResource})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",p(e.era),"〕"]}),e.edition&&p(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:p(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.juan_count,a.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",p(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:p(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",p(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),d&&t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:[a.search.alias,":",p(d)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:a.search.removeFromRecent,"aria-label":a.search.removeFromRecent,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},ga=({id:e,onRemove:n,t:i})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${o("widget-border")}`,background:o("input-bg"),opacity:.6},children:[t.jsx("span",{style:{fontSize:"16px"},children:"❓"}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:"13px",color:o("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:i.search.itemNotFound})]}),t.jsx("button",{onClick:()=>n(e),title:i.search.removeFromRecent,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function ma(e){var n;return!e.dynasty&&!e.birth_year&&!e.death_year&&(!e.alt_names||e.alt_names.length===0)&&!((n=e.description)!=null&&n.text)}function ha({data:e}){const{convert:n}=q(),{dynasty:i,birth_year:r,death_year:s}=e,l=[];return i&&l.push(`〔${n(i)}〕`),r!==void 0&&s!==void 0?l.push(`${r}—${s}`):r!==void 0?l.push(`${r}—?`):s!==void 0&&l.push(`?—${s}`),l.length===0?null:t.jsx("span",{style:{fontSize:"14px",color:o("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function ba({alt_names:e}){const{convert:n}=q(),i=new Map;for(const l of e){const a=l.type||"別名";i.has(a)||i.set(a,[]),i.get(a).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((l,a)=>{const p=r.indexOf(l),c=r.indexOf(a);return p===-1&&c===-1?0:p===-1?1:c===-1?-1:p-c});return t.jsx("div",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const a=i.get(l);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:o("desc-fg"),fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),t.jsx("span",{children:a.map((p,c)=>t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},c))})]},l)})})}function ya({data:e}){const n=e.external_ids;if(!n)return null;const i=[];return n.cbdb_id&&i.push(t.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:o("link-fg"),border:`1px solid ${o("link-fg")}40`,borderRadius:"3px",textDecoration:"none",background:`${o("link-fg")}08`},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),i.length===0?null:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:i})}function ja({works:e,transport:n,onNavigate:i,renderLink:r}){const s=ue(),{convert:l}=q(),a=Pe(),[p,c]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let x=!1;const m=e.map(S=>S.work_id);return(async()=>{const S=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(m);let $=!0;for(let v=0;v<m.length;v++){const _=k[v];_!=null&&_.title?S.set(m[v],_.title):_!=null&&_.primary_name?S.set(m[v],_.primary_name):$=!1}if($)return S}catch{}const h=[...m],y=8,j=new Array(y).fill(0).map(async()=>{for(;h.length;){const k=h.shift();if(!k)break;if(!S.has(k))try{if(n.getEntry){const _=await n.getEntry(k);if(_!=null&&_.title){S.set(k,_.title);continue}}const $=await n.getItem(k),v=$&&($.title||$.primary_name)||k;S.set(k,v)}catch{S.set(k,k)}}});return await Promise.all(j),S})().then(S=>{x||c(S)}),()=>{x=!0}},[e,n]);const d=new Map;for(const x of e){const m=x.role||"";d.has(m)||d.set(m,[]),d.get(m).push(x)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],g=[...d.keys()].sort((x,m)=>{const b=u.indexOf(x),S=u.indexOf(m);return b===-1&&S===-1?x.localeCompare(m):b===-1?1:S===-1?-1:b-S});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:o("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:o("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),g.map(x=>{const m=d.get(x);return t.jsxs("div",{style:{marginBottom:"8px"},children:[x&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"2px"},children:[l(x)," ",t.jsxs("span",{style:{color:o("desc-fg")},children:["(",m.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:x?"16px":"0",listStyle:x?"disc":"none",fontSize:"14px",lineHeight:1.8},children:m.map((b,S)=>{const h=l(p.get(b.work_id)||b.work_id);return r?t.jsx("li",{children:r(b.work_id,h)},S):i?t.jsx("li",{children:t.jsx("a",{href:a(b.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),i(b.work_id))},style:{color:o("link-fg"),textDecoration:"underline",cursor:"pointer"},children:h})},S):t.jsx("li",{children:h},S)})})]},x)})]})}const Ir=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:l})=>{var g;const a=ue(),{convert:p}=q();let c=!1;try{c=we.extractStatus(e.id)==="draft"}catch{}const d=ma(e),u=e.subtype==="people"?"人物":e.subtype==="place"?"地名":e.subtype==="dynasty"?"朝代":e.subtype==="anonymous"?"佚名":e.subtype==="collective"?"集体":e.subtype;return t.jsxs("div",{children:[!l&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:o("fg")},children:[p(e.primary_name),t.jsx(ha,{data:e})]}),s]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o("type-entity"),border:`1px solid color-mix(in srgb, ${o("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${o("type-entity")} 3%, transparent)`},children:a.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),c&&t.jsx("span",{style:{padding:"1px 6px",background:o("warn-bg"),border:`1px solid ${o("warn-border")}`,borderRadius:"2px",color:o("warn-fg")},children:a.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),d&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:o("widget-bg"),border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(ba,{alt_names:e.alt_names}),t.jsx(ya,{data:e}),((g=e.description)==null?void 0:g.text)&&t.jsx("p",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(e.description.text)}),e.works&&e.works.length>0&&t.jsx(ja,{works:e.works,transport:n,onNavigate:i,renderLink:r})]})},va=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function ka(e){const n=e.search(va);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const Tr={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>{let i=e,r="",s=n;if(e&&typeof n=="string"&&(n===e||n===Sa(e))){const[l,a]=ka(n);a&&(i=encodeURI(l),s=l,r=a)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:i,target:i!=null&&i.startsWith("http")?"_blank":void 0,rel:i!=null&&i.startsWith("http")?"noopener noreferrer":void 0,style:{color:o("link")},children:s}),r]})},code:({children:e})=>t.jsx("code",{style:{background:o("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function Sa(e){try{return decodeURI(e)}catch{return e}}const wa={...Tr,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},lt=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:s}=q(),l=n?wa:Tr;return t.jsx("div",{className:r,style:i,children:t.jsx(Il,{remarkPlugins:[Tl],components:l,children:s(e)})})},_a=["〇","一","二","三","四","五","六","七","八","九"],ho=["","十","百","千"];function Er(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const a=parseInt(n[l]),p=i-1-l;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&p===1&&l===0?r+=ho[p]:r+=_a[a]+ho[p])}return r}function Rr(e){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:e,border:`1px solid color-mix(in srgb, ${e} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${e} 3%, transparent)`}}const $a={book:o("type-book"),work:o("type-work"),collection:o("type-collection"),entity:o("type-entity")};function za({type:e}){const n=ue();return t.jsx("span",{style:Rr($a[e]),children:n.indexType[e]})}function Ca({isDraft:e}){const n=ue(),i=o(e?"status-draft":"status-official");return t.jsx("span",{style:Rr(i),children:e?n.status.draft:n.status.official})}function Ia({id:e}){const n=ue(),[i,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:o("desc-fg"),background:o("bg-subtle"),border:`1px solid ${o("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:o("fg")},children:e}),t.jsx("span",{onClick:s,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function Ve({children:e,extra:n}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("desc-fg"),letterSpacing:"1px"},children:e}),t.jsx("span",{style:{flex:1}}),n]})}function tt({label:e,children:n}){return t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[t.jsx("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:e}),t.jsx("span",{style:{color:o("fg")},children:n})]})}function Nr({authors:e,type:n,onNavigate:i,renderLink:r}){const{convert:s}=q();return t.jsx("span",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.6},children:e.map((l,a)=>{const p=s(l.name),c=l.entity_id?t.jsx(Ke,{id:l.entity_id,label:p,onNavigate:i,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:p});return t.jsxs("span",{children:[a>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),c,l.role&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},a)})})}function Ke({id:e,label:n,onNavigate:i,renderLink:r}){const s=Pe();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i(e))},style:{color:o("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`,paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{children:n||e})}function Ta({id:e,title:n,edition:i,type:r,isDraft:s,authors:l,volumeText:a,meta:p,headerExtra:c,onNavigate:d,renderLink:u}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:o("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:i}),a&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:a})]}),c&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(za,{type:r}),t.jsx(Ca,{isDraft:s}),t.jsx(Ia,{id:e})]}),((l==null?void 0:l.length)||p.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(Nr,{authors:l,type:r,onNavigate:d,renderLink:u}),p]})]})}function Lr({items:e,label:n,showMeta:i,onNavigate:r,renderLink:s}){const l=ue(),{convert:a}=q();if(!e.length)return null;const[p,c]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((d,u)=>{const g=p===u;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...g?{boxShadow:o("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>c(g?null:u),style:{padding:"8px 12px",background:o("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.15s",transform:g?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:a(d.source)}),!g&&i&&d.title_info&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a(d.title_info)}),d.source_bid&&t.jsx("span",{onClick:x=>x.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Ke,{id:d.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),g&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${o("widget-border")}`},children:[i&&(d.title_info||d.author_info||d.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&t.jsx(tt,{label:l.label.titleInfo,children:a(d.title_info)}),d.author_info&&t.jsx(tt,{label:l.label.authorInfo,children:a(d.author_info)}),d.edition&&t.jsx(tt,{label:l.label.edition,children:a(d.edition)})]}),d.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:a(d.summary)})]}),d.comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.comment)})]}),d.additional_comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.additional_comment)})]})]})]},u)})})]})}function Ea({items:e,onNavigate:n,renderLink:i}){const r=ue();return t.jsx(Lr,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Br({items:e,onNavigate:n,renderLink:i}){const r=ue();return t.jsx(Lr,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function Ar({label:e,items:n}){const{convert:i}=q();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const l=typeof r=="string"?r:r.book_title;return t.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:o("fg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:i(l)},s)})})]}):null}function Ra({items:e}){const n=ue();return t.jsx(Ar,{label:n.section.aliases,items:e})}function Na({items:e}){const n=ue();return t.jsx(Ar,{label:n.section.attachedTexts,items:e})}function La({items:e}){const n=ue(),{convert:i}=q();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.appendix}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:e.map((r,s)=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:o("fg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:["《",i(r.book_title),"》",r.n_juan!=null&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function Ba({items:e}){const n=ue(),{convert:i}=q();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.locationHistory}),t.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[t.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:o("widget-border")}}),e.map((r,s)=>t.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[t.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:o("primary"),border:`1.5px solid ${o("input-bg")}`}}),t.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:o("fg")},children:i(r.name)}),r.description&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),marginLeft:"8px"},children:i(r.description)})]},s))]})]}):null}function Aa({items:e}){const n=ue(),{convert:i}=q();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.historyOverview}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map((r,s)=>t.jsxs("div",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[t.jsx("span",{style:{position:"absolute",left:0,top:0,color:o("desc-fg")},children:"·"}),i(r)]},s))})]}):null}function bo({title:e,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:l}=q(),[a,p]=f.useState([]);return f.useEffect(()=>{if(!n.length){p([]);return}if(!i){p(n.map(d=>({id:d})));return}let c=!1;return Promise.all(n.map(d=>i.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{c||p(d)}),()=>{c=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(Ve,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",n.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(a.length?a:n.map(c=>({id:c}))).map(c=>{const d=c.edition?`${l(c.title)||c.id}(${l(c.edition)})`:l(c.title)||void 0;return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),transition:"border-color 0.15s"},children:t.jsx(Ke,{id:c.id,label:d,onNavigate:r,renderLink:s})},c.id)})})]}):null}function Nn({book:e,onNavigate:n,renderLink:i}){const r=ue(),{convert:s}=q(),[l,a]=f.useState(!1),p=e.resources&&e.resources.length>0,c=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:o("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(Ke,{id:e.id,label:c,onNavigate:n,renderLink:i})}),p&&t.jsx("span",{onClick:()=>a(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:o("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),p&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(xi,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Wa({ids:e,workData:n,transport:i,onNavigate:r,renderLink:s,footer:l}){const a=ue(),{convert:p}=q(),[c,d]=f.useState([]);if(f.useEffect(()=>{if(!e.length){d([]);return}if(!i){d(e.map(S=>({id:S})));return}let b=!1;return Promise.all(e.map(S=>i.getItem(S).then(h=>({id:S,title:h?h.title:void 0,edition:h?h.edition:void 0,resources:h?h.resources:void 0,resource_groups:h?h.resource_groups:void 0})).catch(()=>({id:S})))).then(S=>{b||d(S)}),()=>{b=!0}},[e,i]),!e.length)return null;const u=c.length?c:e.map(b=>({id:b})),g=new Map(u.map(b=>[b.id,b])),x=n==null?void 0:n.version_graph,m=Ma(e,x);return t.jsxs(t.Fragment,{children:[t.jsxs(Ve,{children:[a.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,m.useGrouping?t.jsxs(t.Fragment,{children:[m.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:m.coreIds.map(b=>{const S=g.get(b);return S?t.jsx(Nn,{book:S,onNavigate:r,renderLink:s},b):null})}),m.groupedIds.map(b=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${o("widget-border")}`,borderRadius:6,background:o("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:o("fg"),userSelect:"none"},children:[p(b.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:o("desc-fg"),fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:o("desc-fg"),fontWeight:400},children:p(b.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(S=>{const h=g.get(S);return h?t.jsx(Nn,{book:h,onNavigate:r,renderLink:s},S):null})})]},b.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(b=>t.jsx(Nn,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Ma(e,n){var h,y;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.length>0||s.length>0,a=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&a.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),c=new Set([...s,...a]),d=j=>{if(c.has(j))return!0;const k=n.node_groups[j];return k!=null&&p.has(k)},u=[],g=new Map,x=[];for(const j of e)if(!((y=n.excluded_books)!=null&&y.includes(j)))if(d(j))u.push(j);else{const k=n.node_groups[j];k?(g.has(k)||g.set(k,[]),g.get(k).push(j)):x.push(j)}if(x.length+[...g.values()].reduce((j,k)=>j+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(j=>[j.id,j])),S=[...g.entries()].map(([j,k])=>{const $=b.get(j);return{id:j,label:($==null?void 0:$.label)??j,description:$==null?void 0:$.description,ids:k}});return x.length>0&&S.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:S}}function Fa({workData:e,onNavigate:n,renderLink:i}){var a,p,c,d;const r=ue(),{convert:s}=q(),l=!!((a=e.description)!=null&&a.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:o("input-bg"),marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`},children:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:t.jsx(Ke,{id:e.id,label:s(e.title),onNavigate:n,renderLink:i})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:s(e.measure_info)}):((p=e.juan_count)==null?void 0:p.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[Er(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(Nr,{authors:e.authors,type:"work",onNavigate:n,renderLink:i})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((c=e.description)==null?void 0:c.text)&&t.jsx(lt,{text:e.description.text,style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(d=e.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:t.jsx(tt,{label:r.label.parentWork,children:t.jsx(Ke,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Pa({items:e,onNavigate:n,renderLink:i}){const r=ue(),{convert:s}=q();return e.length?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(l=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid color-mix(in srgb, ${o("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${o("type-collection")} 3%, transparent)`},children:[t.jsx("span",{style:{fontSize:"11px",color:o("type-collection")},children:r.indexType.collection}),t.jsx(Ke,{id:l.id,label:s(l.title)||l.id,onNavigate:n,renderLink:i}),l.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"2px"},children:Kt(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const fi=({data:e,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:a,className:p,style:c})=>{var P,B,A,W,V,K,E,le;const d=ue(),{convert:u}=q(),[g,x]=f.useState(null),[m,b]=f.useState(!1),[S,h]=f.useState(null),[y,j]=f.useState(null),[k,$]=f.useState([]),v=e||g;if(f.useEffect(()=>{if(e||!n||!i)return;let G=!1;return b(!0),h(null),i.getItem(n).then(ae=>{G||(ae?x(ae):h(d.misc.notFoundEntry))}).catch(ae=>{G||h(ae instanceof Error?ae.message:d.misc.loadFailed)}).finally(()=>{G||b(!1)}),()=>{G=!0}},[e,n,i]),f.useEffect(()=>{if(!v||!i){j(null),$([]);return}let G=!1;const ae=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(ae?i.getItem(ae).then(pe=>{!G&&pe&&pe.type==="work"&&j(pe)}).catch(()=>{}):j(null),v.type==="book"){const pe=v;pe.contained_in&&pe.contained_in.length>0?Promise.all(pe.contained_in.map(ee=>{const X=typeof ee=="string"?ee:ee.id,ie=typeof ee=="string"?void 0:ee.volume_index;return i.getItem(X).then(me=>({id:X,title:me&&me.title||X,volume_index:ie})).catch(()=>({id:X,title:X,volume_index:ie}))})).then(ee=>{G||$(ee)}):$([])}else $([]);return()=>{G=!0}},[v,i]),m)return t.jsx("div",{className:p,style:{...c,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((G,ae)=>t.jsx("div",{style:{height:ae===1?"32px":"16px",width:`${G}px`,background:o("widget-border"),borderRadius:"4px",opacity:.4}},ae))})});if(S)return t.jsx("div",{className:p,style:{...c,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:S});if(!v)return null;if(v.type==="entity")return t.jsx("div",{className:p,style:c,children:t.jsx(Ir,{data:v,transport:i,onNavigate:r,renderLink:s,headerExtra:l})});const _=v.type==="book"?v:null,w=v.type==="collection"?v:null,z=v.type==="work"?v:null;let N=!1;try{N=we.extractStatus(v.id)==="draft"}catch{}let T="";v.measure_info?T=u(v.measure_info):(P=v.juan_count)!=null&&P.number?T=Er(v.juan_count.number)+d.unit.juan:(B=v.juan_count)!=null&&B.description&&(T=u(v.juan_count.description));const C=[];return(A=v.publication_info)!=null&&A.year&&C.push(t.jsx(tt,{label:d.label.year,children:v.publication_info.year},"year")),(W=v.current_location)!=null&&W.name&&C.push(t.jsx(tt,{label:d.label.currentLocation,children:u(v.current_location.name)},"loc")),(V=v.page_count)!=null&&V.description&&C.push(t.jsx(tt,{label:d.label.pageCount,children:v.page_count.description},"page")),_!=null&&_.edition&&C.push(t.jsx(tt,{label:d.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&C.push(t.jsx(tt,{label:d.label.parentWork,children:t.jsx(Ke,{id:z.parent_work.id,label:u(z.parent_work.title),onNavigate:r,renderLink:s})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&C.push(t.jsx(tt,{label:d.label.parentWork,children:z.parent_works.map((G,ae)=>t.jsxs("span",{children:[ae>0&&"、",t.jsx(Ke,{id:G,onNavigate:r,renderLink:s})]},G))},"pws")),t.jsxs("div",{className:p,style:c,children:[t.jsx(Ta,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:N,authors:v.authors,volumeText:T,meta:C,headerExtra:l,onNavigate:r,renderLink:s}),((K=v.description)==null?void 0:K.text)&&t.jsx(lt,{text:v.description.text,style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((G,ae)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:o("bg-subtle"),borderRadius:4,border:`1px solid ${o("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:o("muted")},children:u(G.title)}),t.jsx(lt,{text:G.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:o("fg")}})]},ae))}),k.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:d.section.containedIn}),t.jsx(Pa,{items:k,onNavigate:r,renderLink:s})]}),y&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:d.section.belongsToWork}),t.jsx(Fa,{workData:y,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&t.jsx(La,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&t.jsx(Ra,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&t.jsx(Na,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&t.jsx(Ea,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&t.jsx(Br,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:d.section.resources}),t.jsx(xi,{items:v.resources,resourceGroups:v.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&t.jsx(Ba,{items:_.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&t.jsx(Aa,{items:w.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&t.jsx(bo,{title:d.section.relatedVersions,ids:_.related_books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.books)&&w.books.length>0&&t.jsx(bo,{title:d.section.containedBooks,ids:w.books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.contained_works)&&w.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(Ve,{children:[d.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",w.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.contained_works.map(G=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:t.jsx(Ke,{id:G.id,label:u(G.title),onNavigate:r,renderLink:s})},G.id))})]}),(((E=z==null?void 0:z.books)==null?void 0:E.length)||0)+(((le=z==null?void 0:z.collections)==null?void 0:le.length)||0)>0&&t.jsx(Wa,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z??void 0,transport:i,onNavigate:r,renderLink:s,footer:a}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const G=[],ae=z.related_works.filter(te=>te.relation==="part_of"),pe=z.related_works.filter(te=>te.relation==="has_part"),ee=z.related_works.filter(te=>te.relation==="has_adaptation"),X=z.related_works.filter(te=>te.relation==="text_carried_by"),ie=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),me=z.related_works.filter(te=>!te.relation||!ie.has(te.relation));return ae.length>0&&G.push({label:d.section.belongsToWork,items:ae}),pe.length>0&&G.push({label:d.section.containedWorks,items:pe}),ee.length>0&&G.push({label:d.section.adaptations,items:ee}),X.length>0&&G.push({label:d.section.derivativeWorks,items:X}),me.length>0&&G.push({label:d.section.relatedWorks,items:me}),G.map(te=>t.jsxs("div",{children:[t.jsxs(Ve,{children:[te.label,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",te.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:te.items.map(se=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:t.jsx(Ke,{id:se.id,label:u(se.title),onNavigate:r,renderLink:s})},se.id))})]},te.label))})()]})};function Oa({data:e}){const n=ue(),{convert:i}=q(),{stats:r}=e,s=r.processed_volumes??r.total_found_volumes,l=s!=null&&e.total_volumes>0?Math.round(s/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:i(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"6px"},children:i(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:o("desc-fg")},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:o("fg")},children:e.total_volumes})," ",n.unit.volume]}),l!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:o("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:o("fg")},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&t.jsxs("span",{children:[n.catalog.matched," ",t.jsx("strong",{style:{color:o("fg")},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&t.jsxs("span",{children:[n.catalog.unmatched," ",t.jsx("strong",{style:{color:o("missing-fg")},children:r.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:o("desc-fg")},children:[n.catalog.source," ",e.source]})]})}function Da({sections:e,activeSection:n,onSelect:i}){const r=ue();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:yo(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:yo(n===s.name),children:[s.name,s.volume_range&&t.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function yo(e){return{padding:"4px 12px",border:e?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${o("primary")} 8%, transparent)`:"transparent",color:o(e?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Ha({id:e,label:n,onNavigate:i,renderLink:r}){const s=Pe();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i(e))},style:{color:o("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:n||e})}function Ga(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=e[0],r=e[e.length-1];return r-i+1===e.length?`${i}–${r}`:e.length<=3?e.join(", "):`${i}–${r} (${e.length}${n})`}function jo({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const s=ue(),{convert:l}=q(),a=e.book_id||e.work_id,p=r&&e.volumes.length>0?Ga(e.volumes,s.unit.volume):null,c=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${o("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:o("desc-fg"),textAlign:"right"},children:p}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:o("fg")},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(d=>l(d)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:o(c?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),a&&t.jsx(Ha,{id:a,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!a&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const gi=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:l,style:a})=>{const p=ue(),[c,d]=f.useState(null),[u,g]=f.useState(!1),[x,m]=f.useState(null),[b,S]=f.useState(null),[h,y]=f.useState(""),j=e||c;f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let w=!1;return g(!0),m(null),i.getCollectionCatalog(n).then(z=>{w||(z?d(z):m(p.catalog.notFound))}).catch(z=>{w||m(z instanceof Error?z.message:p.catalog.loadFailed)}).finally(()=>{w||g(!1)}),()=>{w=!0}},[e,n,i,p]);const k=(j==null?void 0:j.sections)&&j.sections.length>0,$=f.useMemo(()=>{if(!j)return!1;if(j.volume_index&&Object.keys(j.volume_index).length>0)return!0;const w=j.books.map(N=>N.volumes[0]).filter(N=>N!=null);return new Set(w).size<w.length},[j]),v=f.useMemo(()=>{if(!j)return[];let w=j.books;if(b&&(w=w.filter(z=>z.section===b)),h.trim()){const z=h.trim().toLowerCase();w=w.filter(N=>N.title.toLowerCase().includes(z)||N.sub_items&&N.sub_items.some(T=>T.toLowerCase().includes(z))||N.edition&&N.edition.toLowerCase().includes(z))}return w},[j,b,h]),_=f.useMemo(()=>{if(!$)return null;const w=[],z=new Map;for(const T of v){if(!T.volumes||T.volumes.length===0)continue;const C=T.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(T)}const N=[...z.keys()].sort((T,C)=>T-C);for(const T of N)w.push({volume:T,books:z.get(T)});return w},[v,$]);return u?t.jsx("div",{className:l,style:{...a,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):x?t.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:x}):j?t.jsxs("div",{className:l,style:a,children:[t.jsx(Oa,{data:j}),k&&t.jsx(Da,{sections:j.sections,activeSection:b,onSelect:S}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:h,onChange:w=>y(w.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:o("desc-fg")},children:[v.length," ",p.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[_?_.map((w,z)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:o("bg"),borderBottom:`1px solid ${o("widget-border")}`,fontSize:"12px",fontWeight:600,color:o("desc-fg"),position:"sticky",top:0,zIndex:1},children:Kt(p.catalog.volume,{n:w.volume})}),w.books.map((N,T)=>t.jsx(jo,{book:N,onNavigate:r,renderLink:s,showVolumes:N.volumes.length>1},`${w.volume}-${T}`))]},`${w.volume}-${z}`)):v.map((w,z)=>t.jsx(jo,{book:w,onNavigate:r,renderLink:s,showVolumes:!0},z)),v.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},jt=()=>{const[e,n]=f.useState(1);return f.useEffect(()=>{const i=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(i)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:o("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(e)})},Wr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Ua={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function We(e){return Ua[e]??e}const It=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],Tt={熹平:172,建安:196,黃初:220,正始:240,廣政:938,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,開成:836,會昌:841,咸通:860,建隆:960,太平興國:976,咸平:998,天禧:1017,慶曆:1041,皇祐:1049,嘉祐:1056,治平:1064,熙寧:1068,元豐:1078,元祐:1086,紹聖:1094,崇寧:1102,大觀:1107,政和:1111,宣和:1119,建炎:1127,紹興:1131,隆興:1163,乾道:1165,淳熙:1174,紹熙:1190,慶元:1195,嘉泰:1201,開禧:1205,嘉定:1208,寶慶:1225,紹定:1228,端平:1234,嘉熙:1237,淳祐:1241,寶祐:1253,開慶:1259,景定:1260,咸淳:1265,大定:1161,明昌:1190,至元:1264,大德:1297,皇慶:1312,延祐:1314,泰定:1324,天曆:1328,至順:1330,至正:1341,洪武:1368,永樂:1403,宣德:1426,正統:1436,景泰:1450,天順:1457,成化:1465,弘治:1488,正德:1506,嘉靖:1522,隆慶:1567,萬曆:1573,泰昌:1620,天啟:1621,崇禎:1628,弘光:1645,隆武:1645,紹武:1646,永曆:1647,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,正保:1644,慶安:1648,承應:1652,明曆:1655,萬治:1658,寬文:1661,延寶:1673,天和:1681,貞享:1684,元祿:1688,寶永:1704,享保:1716,元文:1736,寬保:1741,延享:1744,寬延:1748,寶曆:1751,明和:1764,安永:1772,天明:1781,寬政:1789,享和:1801,文化:1804,文政:1818,天保:1830,弘化:1844,嘉永:1848,安政:1854,萬延:1860,文久:1861,元治:1864,慶應:1865,明治:1868,大正:1912,昭和:1926,天正:1573,文祿:1592,永祿:1558,天文:1532},Mr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function vn(e){const n=e.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const i=parseInt(n[1],10);if(i<100||i>2100)return;const r=n[2]?parseInt(n[2],10):void 0;return{from:i,to:r!=null&&r>=i&&r<=2100?r:void 0}}function Va(e){return e>=1950?"":e>=1912?"民國":e>=1645?"清":e>=1368?"明":e>=1279?"元":e>=960?"宋":e>=907?"五代":e>=618?"唐":e>=581?"隋":e>=420?"南北朝":e>=265?"晉":e>=220?"三國":e>=-202?"漢":""}const Ya=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,vo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function mi(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(vo))if(n.startsWith(s))return vo[s];const i=We(n);if(gt[i]!=null)return i;const r=st(n);if(r&&n.length<=r.length+1)return We(r)}function ft(e,n){if(n){const i=Mr[`${n}|${e}`];if(i!=null)return i}return Tt[e]}const qa=1911;function Ka(e){const n=Tt[e];if(n==null)return;const i=nt[e];let r;for(const[s,l]of Object.entries(Tt))nt[s]===i&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const Ja={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function fn(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,i=0,r=!1;for(const l of e){const a=Ja[l];if(a===void 0)return;r=!0,l==="十"?i=(i||1)*10:l==="廿"||l==="卅"?(n+=a,i=0):i>=10?(n+=i+a,i=0):i=i*10+a}const s=n+i;return r&&s>0?s:void 0}function st(e){for(const n of Wr)if(e.startsWith(n))return n}const nt={};{const e=(n,i)=>{for(const r of i)nt[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function mt(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(Tt))if(e.includes(r)&&!(i&&nt[r]&&nt[r]!==i&&Mr[`${i}|${r}`]==null))return r}function Jt(e){var a,p,c;const n={era:"",reign:"",source:"none"},i=e.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const r=(a=e.lineage)==null?void 0:a.year_text;if(r){const d=st(r)??"";return{era:We(d),reign:mt(r,d)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const d=vn(s);if(d)return{era:Va(d.from),reign:"",source:"publication"};const u=st(s)??mi(s)??((c=It.find(m=>m.pattern.test(s)))==null?void 0:c.era)??"",g=mt(s,u)??"",x=u||(g?nt[g]??"":"");if(x||g)return{era:We(x),reign:g,source:"publication"}}const l=e.edition||e.title||"";if(l){const d=st(l);if(d)return{era:We(d),reign:mt(l,d)??"",source:"edition"};const u=It.find(g=>g.pattern.test(l));if(u)return{era:We(u.era),reign:mt(l,u.era)??u.reign??"",source:"edition"}}return n}function kn(e){var r,s,l,a,p,c,d,u,g;if(((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;if(typeof((s=e.lineage)==null?void 0:s.year)=="number")return e.lineage.year;const n=(l=e.publication_info)==null?void 0:l.year;if(n){const x=vn(n);if(x)return x.from}const i=[(a=e.lineage)==null?void 0:a.year_text,(p=e.publication_info)==null?void 0:p.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const x of i){const m=((c=e.publication_info)==null?void 0:c.year)||((d=e.lineage)==null?void 0:d.year_text);if(m&&x!==m&&(st(m)||mi(m)))break;const b=x.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??x.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const k=parseInt(b[1],10);if(k>=100&&k<=2100)return k}const S=x.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(S){const k=st(x);if(!k||We(k)==="民國"){const v=fn(S[1]);if(v!=null&&v>=1&&v<=120)return qa+v}}const h=st(x)??((u=It.find(k=>k.pattern.test(x)))==null?void 0:u.era),y=h?We(h):void 0,j=mt(x,y)??(st(x)||(g=It.find(k=>k.pattern.test(x)))==null?void 0:g.reign);if(j){const k=ft(j,y);if(k==null)continue;const $=x.indexOf(j),v=$>=0?x.slice($+j.length):"",_=v.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??v.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),w=_?fn(_[1]):void 0;return k+(w?w-1:0)}}}function hi(e){var a,p,c,d,u,g;const n=(a=e.dating)==null?void 0:a.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(p=e.lineage)==null?void 0:p.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const x=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(x){const m=Vn[We(x[1])],b=gt[We(x[2])];if(m!=null&&b!=null)return{from:Math.min(m,b)-20,to:Math.max(m,b)+40}}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const x=vn(s);if((x==null?void 0:x.to)!=null)return{from:x.from,to:x.to};const m=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(m){const b=Vn[We(m[1])],S=gt[We(m[2])];if(b!=null&&S!=null)return{from:Math.min(b,S)-20,to:Math.max(b,S)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const x of l){if(!/[間间]/.test(x))continue;const m=st(x)??mi(x)??((g=It.find(h=>h.pattern.test(x)))==null?void 0:g.era),b=m?We(m):void 0,S=[];for(const h of Object.keys(Tt))x.includes(h)&&(b&&nt[h]&&nt[h]!==b||ft(h,b)!=null&&S.push(h));if(S.length===0){const h=x.match(/([一-鿿])([一-鿿])[間间]/);if(h&&b){for(const y of[h[1],h[2]])for(const j of Object.keys(Tt))if(nt[j]===b&&!(j[0]!==y&&j[j.length-1]!==y)&&ft(j,b)!=null){S.push(j);break}}}if(S.length>0){const h=S.map($=>ft($,b)).filter($=>$!=null),y=Math.min(...h),j=S.reduce(($,v)=>ft($,b)>=ft(v,b)?$:v),k=Ka(j)??Ln(b??"")??Math.max(...h);return{from:y,to:k>y?k:Ln(b??nt[j]??"")??y}}if(b&&gt[b]!=null)return{from:gt[b],to:Ln(b)??gt[b]}}}const gt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Za=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Xa=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,ko=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function So(e,n){for(const i of Wr){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!mt(e.slice(r),We(i)))continue}const s=We(i);if(s===n)continue;const l=e.slice(r),a=mt(l,s)??"";let p;if(a){const c=ft(a,s);if(c!=null){const u=l.slice(l.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),g=u?fn(u[1]):void 0;p=c+(g?g-1:0)}}return{era:s,reign:a,year:p}}for(const i of It)if(i.pattern.test(e))return{era:We(i.era),reign:i.reign??""}}function Qa(e){var y,j,k,$,v;const n=Jt(e),i=((y=e.publication_info)==null?void 0:y.year)??"",r=i?vn(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),a=((j=e.lineage)==null?void 0:j.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(a),c=n.source==="publication"&&Ya.test(i),d=n.source==="publication"&&/[間间]/.test(i),u=a.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let g;l||p||c||d?g=void 0:u?g=parseInt(u[2],10):g=kn(e);const x=g==null?hi(e):void 0;let m;n.source==="publication"&&(c||ko.test(i))?m="uncertain":n.source==="lineage"||n.source==="publication"?m="attested":ko.test(s)||!n.reign&&g==null?m="uncertain":m="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((k=e.lineage)==null?void 0:k.year_text)??(($=e.lineage)==null?void 0:$.year)??""}」`:`出版著錄「${((v=e.publication_info)==null?void 0:v.year)??""}」`,S={era:n.era,reign:n.reign,year:g,yearRange:x,certainty:m,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const _=a.match(/[、,,]\s*([宋元明清])/);_&&_[1]!==S.era&&(S.laterRepair={era:_[1]})}if(!S.laterRepair&&Xa.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(S.laterRepair={era:_[1]})}const h=Za.find(_=>_.re.test(s));if(h){const _=s.search(h.re),w=s.slice(_),z=So(w,n.era)??So(s,n.era);z&&(S.basedOn={era:z.era,reign:z.reign,year:z.year,relation:h.relation})}return S}const Vn={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Ln(e){return Vn[e]}function gn(e){const n=kn(e);if(n!=null)return n;const i=hi(e);if(i)return i.from;const r=Jt(e).era;return r?gt[r]:void 0}const wo=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Yn(e){const n=wo.indexOf(e);return n===-1?wo.length:n}function ec(e){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of e){const l=s.relation;l==="part_of"?n.belongsTo.push(s):l==="collected_in"?n.collected.push(s):l==="has_part"||l==="contains_text_of"?n.contains.push(s):l==="text_carried_by"||l==="studied_by"||l==="derived_from"||l==="followed_by"||l==="has_adaptation"?n.derivative.push(s):l==="studies"||l==="preceded_by"?n.studies.push(s):n.related.push(s)}const i=[],r=(s,l)=>{n[s].length&&i.push({key:s,labelKey:l,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),i}function bi(e,n){const i=di(e||[]),r=new Map,s=[];for(const d of i)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((u,g)=>{const x=m=>m.group_role==="origin"?0:m.group_role==="mirror"?1:2;return x(u)-x(g)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=yt(d),g=u.includes("text"),x=u.includes("image");g&&x?l.textImage.push(d):g?l.text.push(d):x?l.image.push(d):l.physical.push(d)}const p=["text","image","textImage","physical"].filter(d=>l[d].length>0).map(d=>({key:d,items:l[d]})),c=[...r.entries()].map(([d,u])=>{var g,x;return{key:d,label:((g=n==null?void 0:n[d])==null?void 0:g.label)||d,description:(x=n==null?void 0:n[d])==null?void 0:x.description,items:u}});return{buckets:p,mirrors:c,total:i.length}}function Sn(e){const n=[],i=e.metadata||{};i.edition&&n.push(String(i.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const r=bn(e);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),i.version&&n.push(String(i.version)),n.join(" · ")}function Fr(e,n){if(Sn(e)||n.filter(r=>r.name===e.name).length<2)return"";try{const r=new URL(e.url),s=r.searchParams.get("res")||r.searchParams.get("id");if(s)return s;const l=r.pathname.split("/").filter(Boolean).pop();if(l)return decodeURIComponent(l)}catch{}return""}function Pr(e,n){var l,a;const i=e.resources||[],r=[],s=[];for(const p of i){const c=yt(p);c.includes("image")&&r.push(p),c.includes("physical")&&s.push(p)}return{id:e.id,name:e.edition||e.title||e.id,era:Jt(e),year:kn(e),sortYear:gn(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:tc(e.id,n),group:(a=n==null?void 0:n.node_groups)==null?void 0:a[e.id],hasImage:r.length>0}}function tc(e,n){var p,c;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(p=n.collections)==null?void 0:p[i];if(((r==null?void 0:r.book_ids)??(i==="core"?n.core_books??[]:[])).includes(e))return!0;const l=(r==null?void 0:r.groups)??[],a=(c=n.node_groups)==null?void 0:c[e];return!!a&&l.includes(a)}function Or(e,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!r.has(c.id)).map(c=>Pr(c,n));let l=s;i.era&&(l=l.filter(c=>c.era.era===i.era)),i.scanOnly&&(l=l.filter(c=>c.hasImage)),i.sort==="year"?l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=c.r.sortYear,g=d.r.sortYear;return u!=null&&g!=null?u-g||c.i-d.i:u!=null?-1:g!=null?1:c.i-d.i}).map(c=>c.r):l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=g=>(g.important?0:1)*2+(g.hasImage?0:1);return u(c.r)-u(d.r)||c.i-d.i}).map(c=>c.r);const p=[...new Set(s.map(c=>c.era.era).filter(Boolean))].sort((c,d)=>Yn(c)-Yn(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(c=>c.era.source==="edition")}}function nc(e,n){var h,y;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.length>0||s.length>0,a=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&a.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),c=new Set([...s,...a]),d=j=>{if(c.has(j))return!0;const k=n.node_groups[j];return k!=null&&p.has(k)},u=[],g=new Map,x=[];for(const j of e)if(!((y=n.excluded_books)!=null&&y.includes(j)))if(d(j))u.push(j);else{const k=n.node_groups[j];k?(g.has(k)||g.set(k,[]),g.get(k).push(j)):x.push(j)}if(x.length+[...g.values()].reduce((j,k)=>j+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(j=>[j.id,j])),S=[...g.entries()].map(([j,k])=>{const $=b.get(j);return{id:j,label:($==null?void 0:$.label)??j,description:$==null?void 0:$.description,ids:k}});return x.length>0&&S.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:S}}const Dr=["撰","編","注","校","譯","繪","其他"],ic=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function yi(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of ic)if(r.test(n))return i;return"其他"}function ji(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Hr(e){const n=new Map;for(const r of e){const s=yi(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:e.length}];for(const r of Dr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function Gr(e,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(a=>({id:a.work_id||a.book_id||void 0,title:a.title,section:a.section,volumes:a.volumes||[],subItems:a.sub_items,edition:a.edition,found:a.found_volumes,expected:a.expected_volumes})),l=[...new Set(s.map(a=>a.section).filter(Boolean))];return{rows:s,source:"catalog",sections:l,totalVolumes:n.total_volumes}}return e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(l=>({id:l.id,title:l.title,volumes:Ut(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,a;return{id:s,title:((l=i==null?void 0:i.get(s))==null?void 0:l.title)||s,edition:(a=i==null?void 0:i.get(s))==null?void 0:a.edition,volumes:[]}}),source:"books",sections:[]}}function Ut(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(n=>typeof n=="number");if(typeof e=="string"){const n=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[i,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-i+1)},(s,l)=>i+l)}return e.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function wn(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((l,a)=>l-a),r=i[0],s=i[i.length-1];return s-r+1===i.length?`${r}–${s}`:i.length<=3?i.join(", "):`${r}–${s} (${i.length}${n})`}const oc=["〇","一","二","三","四","五","六","七","八","九"],_o=["","十","百","千"];function Ur(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const a=parseInt(n[l]),p=i-1-l;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&p===1&&l===0?r+=_o[p]:r+=oc[a]+_o[p])}return r}function rc(e){return e==null?"":typeof e=="string"?e:e.title??""}function at(e,n="卷"){var r,s;const i=e;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?Ur(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Vr(e){var r;if(e.edition_type)return e.edition_type;if((r=e.lineage)!=null&&r.category)return e.lineage.category;const n=e.edition||e.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,l]of i)if(s.test(n))return l;return""}const sc="guji_markdown";function qn(e){const n=e==null?void 0:e.guji_markdown;if(typeof n!="string")return!1;const i=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!i)return!1;const r=parseInt(i[1],10),s=parseInt(i[2],10);return r>0||s>=2}const lc=/^□\{guess=([^\s{}]+)\}/;function ac(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function Yr(e,n){let i=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
12
+ `)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 qr(e,n,i,r){const s=[];let l="";const a=()=>{if(!l)return;const p=r?l.replace(/\\?\|/g,""):l;p&&s.push({type:"text",text:p}),l=""};for(;n<e.length;){const p=e[n];if(i!==null){if(p===i)return a(),{nodes:s,end:n};if(p===`
14
+ `)return null}const c=dc(e,n);if(c){a(),s.push(c.node),n=c.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&ac(e,n)&&(d=">"),d){const u=qr(e,n+1,d,!0);if(u){a(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return i!==null?null:(a(),{nodes:s,end:n})}function Kr(e){return qr(e,0,null,!1).nodes}function pc(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function Jr(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Jr(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const uc=216,$o="clamp(280px, 23vw, 360px)",xc=1440,Zr="(max-width: 719px)",fc=`${Zr}, (pointer: coarse)`,gc=`
15
+ .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) ${wo};
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;
@@ -58,6 +58,12 @@
58
58
  }
59
59
  .bim-d-tab:hover { color: ${o("ink")}; }
60
60
  .bim-d-tab[aria-pressed="true"] { color: ${o("accent")}; font-weight: 700; box-shadow: inset 0 -2px 0 ${o("accent")}; }
61
+ .bim-d-groupbtn {
62
+ background: none; border: 1px dashed ${o("rule-strong")}; border-radius: 3px; padding: 2px 8px; cursor: pointer;
63
+ font: inherit; color: ${o("quiet-fg")};
64
+ }
65
+ .bim-d-groupbtn:hover:not(:disabled) { color: ${o("accent")}; border-color: ${o("accent")}; }
66
+ .bim-d-groupbtn:disabled { cursor: progress; }
61
67
  .bim-d-filters .bim-d-spacer { flex: 1; }
62
68
  .bim-d-check { display: inline-flex; align-items: center; gap: 6px; color: ${o("quiet-fg")}; cursor: pointer; }
63
69
  .bim-d-check input { accent-color: ${o("accent")}; margin: 0; width: 15px; height: 15px; }
@@ -334,7 +340,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
334
340
  .bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
335
341
 
336
342
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
337
- @media ${pc} {
343
+ @media ${fc} {
338
344
  .bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
339
345
  .bim-d-card-foot summary, .bim-d-card-toggle, .bim-d-card details.bim-d-more-names summary,
340
346
  .bim-d-tl summary, .bim-d-chap a { min-height: 44px; }
@@ -372,7 +378,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
372
378
  /* 中等宽度:左栏折到顶部一行 */
373
379
  @media (max-width: 1100px) {
374
380
  .bim-d-grid {
375
- grid-template-columns: minmax(0, 1fr) ${wo};
381
+ grid-template-columns: minmax(0, 1fr) ${$o};
376
382
  grid-template-rows: auto auto 1fr;
377
383
  grid-template-areas: "rail rail" "main card" "main side";
378
384
  }
@@ -386,7 +392,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
386
392
  }
387
393
 
388
394
  /* 手机:左栏收起,提要卡 → 正文 → 旁栏 */
389
- @media ${qr} {
395
+ @media ${Zr} {
390
396
  .bim-d-main.bim-d-main-grid { padding: 8px 16px 0; }
391
397
  .bim-d-grid {
392
398
  grid-template-columns: minmax(0, 1fr);
@@ -427,7 +433,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
427
433
  .bim-d-pick-n { margin: 0; grid-column: 2; grid-row: 1 / span 2; }
428
434
  .bim-d-find { flex-basis: 100%; min-height: 40px; }
429
435
  }
430
- `;function 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 Jr({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 Sn({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 Zr({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 Nt({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,j]=f.useState(!1),y=!!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:y?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:y?{"--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:()=>j(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 ji(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function Kn({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 gt({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,j)=>t.jsxs("li",{className:j===l?"bim-d-side-cur":void 0,"aria-current":j===l?"page":void 0,children:[h,s!=null&&s[j]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[j]}):null]},j))}),k>0&&t.jsx(Nt,{label:p?p(k):`顯示更多(${k})`,onClick:()=>m(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const xc={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function Xt({revision:e,revisedAt:n,review:i,todo:r}){const{convert:s}=V(),l=i?xc[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,_o=208,fc=1440,gc="(max-width: 719px)",Xr=`
436
+ `;function Zt({railTop:e,back:n,up:i,nav:r,railLinks:s,main:l,card:a,side:p}){const{convert:c}=q(),d=(r||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,n&&t.jsx("div",{style:{marginTop:e?12:0},children:n}),i,d.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":c("本頁導航"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:c("本頁")}),t.jsx("ul",{className:"bim-d-rail-nav",children:d.map(u=>t.jsx("li",{children:t.jsxs("a",{href:`#${u.id}`,children:[t.jsx("span",{children:c(u.label)}),u.count!=null&&t.jsx("span",{className:"bim-d-meta",children:u.count})]})},u.id))})]}),s&&s.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("更多"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:c("更多")}),t.jsx("ul",{className:"bim-d-rail-nav",children:s.map(u=>t.jsx("li",{children:t.jsxs("a",{href:u.href??"#",onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),u.onClick())},children:[t.jsx("span",{children:c(u.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},u.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:l}),t.jsx("div",{className:"bim-d-g-card",children:a}),t.jsx("div",{className:"bim-d-g-side",children:p})]})}function Xr({caption:e,children:n}){const{convert:i}=q();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:i(e)}),n]})}function Fe({id:e,title:n,meta:i,action:r,children:s}){const{convert:l}=q();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:l(n)}),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i}),r&&t.jsx("span",{className:"bim-d-sec-act",children:r})]}),s]})}function Me({items:e,className:n,style:i}){const r=e.filter(s=>s!=null&&s!==""&&s!==!1);return r.length?t.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:i,children:r.map((s,l)=>t.jsxs(f.Fragment,{children:[l>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},l))}):null}function _n({items:e,value:n,onChange:i}){const{convert:r}=q();return t.jsx(t.Fragment,{children:e.map(s=>t.jsx("button",{type:"button",className:[...r(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>i(s.key),children:r(s.label)},s.key))})}function Qr({label:e,checked:n,onChange:i}){const{convert:r}=q();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:s=>i(s.target.checked)}),r(e)]})}function Bt({label:e,onClick:n}){const{convert:i}=q();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:i(e)})}function Xt({kind:e,title:n,subtitle:i,byline:r,meta:s,description:l,clampDescription:a,facts:p,stats:c,readAction:d,secondaryAction:u,children:g,foot:x}){const{convert:m}=q(),b=(p||[]).filter(k=>k.value!=null&&k.value!==""),S=(c||[]).filter(k=>k.value!=null&&k.value!==""&&k.value!==0),[h,y]=f.useState(!1),j=!!a&&!h;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:m(e)}),t.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),i&&t.jsx("div",{className:"bim-d-card-sub",children:i}),r&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:r}),s&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),l&&t.jsx("div",{className:j?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:j?{"--detail-clamp":a}:void 0,children:l}),l&&!!a&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":h,onClick:()=>y(k=>!k),children:m(h?"收起":"展開")}),S.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:S.map((k,$)=>t.jsxs("div",{children:[t.jsx("b",{children:k.value}),t.jsx("span",{children:m(k.label)})]},$))}),b.length>0&&t.jsx("dl",{className:"bim-d-ui",children:b.map((k,$)=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:m(k.label)}),t.jsx("dd",{title:k.title,children:k.value})]},$))}),g,d,u,x&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:x})]})}function vi(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function Kn({href:e,onClick:n,label:i="閱讀全文"}){const{convert:r}=q();return e?t.jsx("a",{className:"bim-d-btn",href:e,onClick:n?s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),n())}:void 0,children:r(i)}):t.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:r(i)})}function ht({id:e,title:n,meta:i,items:r,metas:s,currentIndex:l,cap:a=8,moreLabel:p,foot:c,sub:d,timeline:u}){const{convert:g}=q(),[x,m]=f.useState(!1);if(!r.length)return null;const b=x?r:r.slice(0,a),S=r.length-b.length;return t.jsxs("div",{id:e,className:u?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[g(n),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i})]}),d&&t.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:d}),t.jsx("ul",{children:b.map((h,y)=>t.jsxs("li",{className:y===l?"bim-d-side-cur":void 0,"aria-current":y===l?"page":void 0,children:[h,s!=null&&s[y]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[y]}):null]},y))}),S>0&&t.jsx(Bt,{label:p?p(S):`顯示更多(${S})`,onClick:()=>m(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const mc={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function Qt({revision:e,revisedAt:n,review:i,todo:r}){const{convert:s}=q(),l=i?mc[i.status]:void 0,a=i&&i.status!=="unreviewed"&&l?[l,i.by,i.date].filter(Boolean).join(" "):"",p=[e!=null&&e!==""?`${s("數據版本")} ${e}`:"",n??"",s(a)].filter(Boolean),c=(r||[]).filter(d=>d&&d.what);return!p.length&&!c.length?null:t.jsxs(t.Fragment,{children:[p.length>0&&t.jsx(Me,{items:p,style:{fontSize:12}}),c.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s(`待核 ${c.length} 項`)}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:c.map((d,u)=>t.jsxs("li",{children:[s(d.what),(d.by||d.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[d.by&&s(d.by),d.date].filter(Boolean).join(" · "),")"]})]},u))})]})]})}const pn=1e3,zo=208,hc=1440,bc="(max-width: 719px)",es=`
431
437
  .bim-d-page {
432
438
  background: ${o("page-bg")};
433
439
  color: ${o("ink")};
@@ -436,7 +442,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
436
442
  padding-bottom: 64px;
437
443
  }
438
444
  .bim-d-main {
439
- max-width: ${dn}px;
445
+ max-width: ${pn}px;
440
446
  margin: 0 auto;
441
447
  padding: 24px clamp(16px, 4vw, 28px) 0;
442
448
  }
@@ -447,7 +453,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
447
453
  * PAGE_MAX_WIDTH,读者的行宽体验不变。
448
454
  */
449
455
  .bim-d-main.bim-d-main-wide {
450
- max-width: ${fc}px;
456
+ max-width: ${hc}px;
451
457
  }
452
458
  .bim-d-ui { font-family: var(--bim-font-ui, system-ui, sans-serif); }
453
459
 
@@ -479,9 +485,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
479
485
  */
480
486
  .bim-d-reader {
481
487
  display: grid;
482
- grid-template-columns: ${_o}px minmax(0, ${dn}px);
488
+ grid-template-columns: ${zo}px minmax(0, ${pn}px);
483
489
  gap: 32px;
484
- max-width: ${_o+dn+32}px;
490
+ max-width: ${zo+pn+32}px;
485
491
  margin: 0 auto;
486
492
  align-items: start;
487
493
  }
@@ -504,7 +510,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
504
510
  align-items: start; margin-bottom: 48px; }
505
511
  .bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
506
512
 
507
- @media ${gc} {
513
+ @media ${bc} {
508
514
  .bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
509
515
  .bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
510
516
  /* 表格:meta 列折到第二行,表头隐藏 */
@@ -522,14 +528,14 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
522
528
  padding-right: 0; padding-bottom: 12px;
523
529
  }
524
530
  }
525
- ${uc}`;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:Xr}),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=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 Qr({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}=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 bc({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(vi,{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 es({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 yc({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 jc({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 ts({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(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 Sc({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${o("rule-strong")}`},children:e})}function wc({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 _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 ns(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 is(e,n){if(e.length<=n)return e;let i=n;for(const r of ns(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 os={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 rs(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?os:void 0,children:rs(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)?rs(Yr(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 ns(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:os,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 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}=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 ss({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}=V(),[l,a]=f.useState(!1),p=hn(e),c=i&&!!p&&p.expected>0,d=(e.url?Et(e.url):void 0)||s(e.name),u=n?Wr(e,n):"",g=u?`${d}(${u})`:d;return t.jsx(ss,{name:g,note:vn(e)||r,href:Rt(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(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 ls({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(ts,{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(ls,{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 as({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 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 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 cs="(min-width: 1100px)",ds="(max-width: 719px)",Ac=`${ds}, (pointer: coarse)`,ct=o("reader-top"),Wc="48px",ps=`
531
+ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:es}),t.jsx("div",{className:r?"bim-d-main bim-d-main-grid":i?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function Jn({breadcrumb:e,actions:n}){return t.jsxs("div",{className:"bim-d-ui bim-d-top",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:o("aux-fg")},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:e}),n&&t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function ki({char:e,tone:n="accent"}){return t.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,flex:"none",fontSize:11,fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",background:o(n==="accent"?"accent":"ink"),color:o("page-bg")},children:e})}function Zn({items:e}){const n=Pe();return t.jsx(t.Fragment,{children:e.map((i,r)=>{const s=r===e.length-1,l=r>0&&t.jsx("span",{style:{color:o("hint-fg")},children:"/"},`s${r}`),a=i.id?n(i.id):i.href,p=s||!i.onClick&&!a?t.jsx("span",{style:{color:o("ink")},children:i.label},r):t.jsx("a",{href:a??"#",onClick:i.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i.onClick())}:void 0,style:{color:o("meta-fg")},children:i.label},r);return t.jsxs(f.Fragment,{children:[l,p]},r)})})}function ts({title:e,subtitle:n,aside:i,secondLine:r}){return t.jsxs("header",{style:{borderBottom:`2px solid ${o("rule-strong")}`,paddingBottom:18},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[t.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:e}),n&&t.jsx("span",{style:{fontSize:15,color:o("meta-fg"),letterSpacing:".06em"},children:n})]}),i&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg"),letterSpacing:".06em"},children:i})]}),r&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:o("quiet-fg")},children:r})]})}function yc({children:e,facts:n}){return!e&&n?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${o("rule")}`,marginBottom:40},children:n}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),n]})}function jc({items:e,horizontal:n}){const{convert:i}=q();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${o("accent")}`,paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:e.map((r,s)=>t.jsxs("div",{title:r.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[t.jsx("span",{className:"bim-d-ui",style:{color:o("label-fg"),letterSpacing:".08em",flex:"none"},children:i(r.label)}),t.jsx("span",{style:{color:o("body-fg"),textAlign:n?"left":"right",minWidth:0},children:r.value})]},s))}):null}function vc({glyph:e,tone:n,title:i,count:r,actions:s,id:l}){const{convert:a}=q();return t.jsxs("div",{id:l,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(ki,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:a(i)}),r!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg")},children:r})]}),s&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function ns({label:e,active:n,onClick:i,dashed:r}){const{convert:s}=q();return t.jsx("button",{type:"button",onClick:i,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!n?"dashed":"solid"} ${o(n?"accent":"rule")}`,background:n?o("accent"):"transparent",color:o(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(e)})}function kc({label:e,onClick:n}){const{convert:i}=q();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg"),borderBottom:`1px solid ${o("rule")}`},children:i(e)})}function Sc({label:e,onClick:n,inline:i}){const{convert:r}=q();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:i?0:12,width:i?void 0:"100%",padding:i?"4px 12px":9,background:"none",border:`1px dashed ${o("rule-dashed")}`,cursor:"pointer",fontSize:12,color:o("meta-fg"),letterSpacing:i?void 0:".08em"},children:r(e)})}function is({children:e,href:n,onClick:i,title:r}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${o("rule")}`,fontSize:13,color:o("body-fg"),lineHeight:1.5};return n||i?t.jsx("a",{href:n??"#",title:r,onClick:i?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i())}:void 0,style:s,children:e}):t.jsx("span",{title:r,style:s,children:e})}function wc({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function _c({volumes:e,unit:n="冊",max:i=60}){const[r,s]=f.useState(!1);if(!e.length)return null;const l=r?e:e.slice(0,i);return t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[l.map(a=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${o("rule")}`,color:o("meta-fg")},children:a},a)),!r&&e.length>i&&t.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${o("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:o("meta-fg")},children:["+",e.length-i]}),t.jsx("span",{style:{padding:"2px 6px",color:o("hint-fg")},children:n})]})}function $c({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${o("rule-strong")}`},children:e})}function zc({spec:e}){const{convert:n}=q();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${o("rule-strong")}`,fontSize:11,color:o("label-fg"),letterSpacing:".1em"},children:[t.jsx("span",{}),t.jsx("span",{children:n(e.mainLabel)}),t.jsx("span",{style:{display:"grid",gridTemplateColumns:e.columns.map(i=>i.width).join(" "),gap:12},children:e.columns.map(i=>t.jsx("span",{children:n(i.label)},i.label))})]})}function Cc({no:e,main:n,meta:i,spec:r}){return t.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${r.leadWidth}px 1fr ${r.metaWidth}px`,gap:12},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:o("hint-fg"),textAlign:"right"},children:e}),t.jsx("span",{style:{minWidth:0},children:n}),t.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:r.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:i})]})}function Ic(e){return String(e+1).padStart(2,"0")}function Tc(){return t.jsx("span",{style:{color:o("hint-fg")},children:"—"})}function Ec({open:e,onToggle:n,main:i,action:r,children:s}){return t.jsxs("div",{style:{borderBottom:`1px solid ${o("rule")}`},children:[t.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[t.jsx("button",{type:"button",onClick:n,"aria-expanded":e,className:"bim-d-ui",style:{width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",fontSize:12,lineHeight:1,border:`1px solid ${o(e?"accent":"rule-dashed")}`,background:e?o("accent"):"transparent",color:o(e?"page-bg":"accent")},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:i}),r]}),e&&s&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${o("rule-accent-soft")}`,marginLeft:12},children:s})]})}function os(e){const n=[];for(let i=0;i<e.length;i++){const r=e[i];let s;if(r==="⟨")s="⟩";else if(r==="<"){const p=e[i+1];if(p===void 0||/[A-Za-z/!?>\s]/.test(p))continue;s=">"}else continue;const l=e.indexOf(s,i+1);if(l<0)continue;const a=e.slice(i+1,l);a.includes(`
532
+ `)||(n.push({start:i,end:l+1,inner:a}),i=l)}return n}function rs(e,n){if(e.length<=n)return e;let i=n;for(const r of os(e)){if(r.start>=i)break;if(r.end>i){i=r.start>0?r.start:r.end;break}}return e.slice(0,i)}const ss={fontSize:".78em",color:o("meta-fg"),lineHeight:1.55},Rc={display:"inline-block",fontSize:"1em",lineHeight:1.15,padding:"0 .12em",margin:"0 .05em",border:"1px solid color-mix(in srgb, currentColor 40%, transparent)",borderRadius:2,verticalAlign:"baseline",whiteSpace:"nowrap"};function ls(e,n,i){return e.map((r,s)=>{switch(r.type){case"text":return t.jsx(f.Fragment,{children:n(r.text)},s);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:i===0?ss:void 0,children:ls(r.children,n,i+1)},s);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:r.label?`闕文:${r.label}`:"闕文",children:"□"},s);case"qz":return t.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":r.guess,children:"□"},s);case"zi":return t.jsx("span",{className:"bim-zi guji-zi",title:`組字:${r.label}`,style:Rc,children:r.label},s)}})}function Ue(e,n=r=>r,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return pc(e)?ls(Kr(e),n,0):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let s=0,l=0;for(const a of os(e))a.start>s&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s,a.start))},l++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:ss,children:n(a.inner)},l++)),s=a.end;return s<e.length&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),r}function Nc({label:e,children:n}){return t.jsxs("div",{style:{marginBottom:10},children:[e&&t.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:o("label-fg"),marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:o("quiet-fg"),textAlign:"justify"},children:n})]})}function Lc({title:e,tag:n,children:i}){const{convert:r}=q();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${o("rule-strong")}`,marginBottom:2},children:[t.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:r(e)}),n&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:o("accent"),letterSpacing:".06em"},children:r(n)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function as({name:e,note:n,href:i,extra:r}){const s=t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{fontSize:14,minWidth:0},children:e}),t.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:o("hint-fg"),flex:"none"},children:i?"↗":""}),n&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:o("label-fg")},children:n})]}),l={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${o("rule")}`,color:o("body-fg"),alignItems:"baseline"};return t.jsxs(t.Fragment,{children:[i?t.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:l,children:s}):t.jsx("div",{style:l,children:s}),r]})}function Bc({item:e,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=q(),[l,a]=f.useState(!1),p=bn(e),c=i&&!!p&&p.expected>0,d=(e.url?Nt(e.url):void 0)||s(e.name),u=n?Fr(e,n):"",g=u?`${d}(${u})`:d;return t.jsx(as,{name:g,note:Sn(e)||r,href:Lt(e),extra:c?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>a(x=>!x),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:o("meta-fg"),borderBottom:`1px solid ${o("rule")}`},children:l?"收起分冊":`展開 ${p.expected} 冊`}),l&&t.jsx(Si,{item:e})]}):void 0})}function Si({item:e}){return t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(e.volumes||[]).map((n,i)=>{const r=n.status==="missing";return n.url&&!r?t.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{padding:"4px 8px",borderRadius:4,background:o("zebra-bg")},children:n.volume},i):t.jsx("span",{style:{padding:"1px 5px",color:o(r?"missing-fg":"hint-fg"),textDecoration:r?"line-through":void 0},children:n.volume},i)})})}function cs({label:e,items:n}){const{convert:i}=q();return n.length?t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg"),letterSpacing:".08em"},children:e}),n.map((r,s)=>t.jsx(is,{children:i(r)},s))]}):null}function Ac({rows:e}){const n=e.filter(i=>i.items.length>0);return n.length?t.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(i=>t.jsx(cs,{label:i.label,items:i.items},i.label))}):null}function Xn(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ds({left:e,right:n}){return t.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${o("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:o("aux-fg")},children:[t.jsx("span",{children:e}),n&&t.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function Wc({children:e,action:n}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:o("aux-fg"),borderBottom:`1px solid ${o("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),n]})}function Be({id:e,label:n,onNavigate:i,renderLink:r,style:s,dense:l}){const a=Pe();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:l})}):t.jsx("a",{href:a(e),onClick:i?p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(e))}:void 0,style:s,children:n??e})}function Mc({href:e,children:n}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[n," ",t.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const ps="(min-width: 1100px)",us="(max-width: 719px)",Fc=`${us}, (pointer: coarse)`,pt=o("reader-top"),Pc="48px",xs=`
527
533
  .bim-rd {
528
534
  position: relative;
529
535
  background: ${o("page-bg")};
530
536
  color: ${o("ink")};
531
537
  font-family: ${o("font-ui")};
532
- --bimrd-bar-h: ${Wc};
538
+ --bimrd-bar-h: ${Pc};
533
539
  }
534
540
  .bim-rd *, .bim-rd *::before, .bim-rd *::after { box-sizing: border-box; }
535
541
 
@@ -555,7 +561,7 @@ ${uc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
555
561
 
556
562
  /* ── 工具条:文字 + 图标,不画按钮外框 ── */
557
563
  .bim-rd-bar {
558
- position: sticky; top: ${ct}; z-index: 30;
564
+ position: sticky; top: ${pt}; z-index: 30;
559
565
  height: var(--bimrd-bar-h);
560
566
  display: flex; align-items: center; gap: 16px;
561
567
  padding: 0 20px;
@@ -592,14 +598,14 @@ ${uc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
592
598
  display: grid;
593
599
  grid-template-columns: auto auto minmax(0, 1fr);
594
600
  align-items: start;
595
- min-height: calc(100vh - ${ct} - var(--bimrd-bar-h));
601
+ min-height: calc(100vh - ${pt} - var(--bimrd-bar-h));
596
602
  }
597
603
 
598
604
  /* 目录:宽屏是侧栏 */
599
605
  .bim-rd-toc {
600
606
  grid-column: 1;
601
- position: sticky; top: calc(${ct} + var(--bimrd-bar-h));
602
- width: 248px; height: calc(100vh - ${ct} - var(--bimrd-bar-h));
607
+ position: sticky; top: calc(${pt} + var(--bimrd-bar-h));
608
+ width: 248px; height: calc(100vh - ${pt} - var(--bimrd-bar-h));
603
609
  overflow-y: auto; overscroll-behavior: contain;
604
610
  padding: 0 10px 40px;
605
611
  background: ${o("sidebar-bg")};
@@ -636,8 +642,8 @@ ${uc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
636
642
  /* 书影:正文左侧 */
637
643
  .bim-rd-img {
638
644
  grid-column: 2;
639
- position: sticky; top: calc(${ct} + var(--bimrd-bar-h));
640
- width: clamp(300px, 32vw, 560px); height: calc(100vh - ${ct} - var(--bimrd-bar-h));
645
+ position: sticky; top: calc(${pt} + var(--bimrd-bar-h));
646
+ width: clamp(300px, 32vw, 560px); height: calc(100vh - ${pt} - var(--bimrd-bar-h));
641
647
  padding: 16px 0 16px 20px;
642
648
  display: flex; flex-direction: column; gap: 8px;
643
649
  }
@@ -648,7 +654,7 @@ ${uc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
648
654
  display: flex; align-items: center; justify-content: center; overflow: hidden;
649
655
  }
650
656
  .bim-rd-img-fig { position: relative; margin: 0; max-width: 100%; max-height: 100%; }
651
- .bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${ct} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
657
+ .bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${pt} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
652
658
  .bim-rd-img-fig svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
653
659
  .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")}; }
654
660
  .bim-rd-img-empty b { font-size: 15px; font-weight: 500; color: ${o("quiet-fg")}; }
@@ -713,7 +719,7 @@ ${uc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
713
719
 
714
720
  /* 竖排(预留):只在宿主打开 allowVertical 时可切换 */
715
721
  .bim-rd-vertical .bim-rd-prose {
716
- writing-mode: vertical-rl; max-height: calc(100vh - ${ct} - var(--bimrd-bar-h) - 120px);
722
+ writing-mode: vertical-rl; max-height: calc(100vh - ${pt} - var(--bimrd-bar-h) - 120px);
717
723
  overflow-x: auto; text-align: start;
718
724
  }
719
725
 
@@ -731,7 +737,7 @@ ${uc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
731
737
 
732
738
  /* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
733
739
  A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
734
- @media ${Ac} {
740
+ @media ${Fc} {
735
741
  .bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
736
742
  .bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
737
743
  content: ""; position: absolute; left: 50%; top: 50%;
@@ -743,7 +749,7 @@ ${uc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
743
749
  }
744
750
 
745
751
  /* ── 中屏以下:目录改抽屉 ── */
746
- @media not all and ${cs} {
752
+ @media not all and ${ps} {
747
753
  .bim-rd-toc {
748
754
  position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto;
749
755
  width: min(86vw, 320px);
@@ -757,7 +763,7 @@ ${uc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
757
763
  }
758
764
 
759
765
  /* ── 窄屏:书影收起,只留正文 ── */
760
- @media ${ds} {
766
+ @media ${us} {
761
767
  .bim-rd-bar { padding: 0 12px; gap: 10px; }
762
768
  .bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
763
769
  .bim-rd-ttl { flex: 1 1 auto; }
@@ -773,19 +779,19 @@ ${uc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
773
779
  .bim-rd-h1 { font-size: 20px; letter-spacing: 0.06em; }
774
780
  .bim-rd-prose { margin-top: 20px; }
775
781
  }
776
- `;function 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,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(Mc,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(us,{items:e.children,activeKey:n,onSelect:i,tabKey:r})]})}function us({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 xs({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??$o(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===$o(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(us,{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 fs({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(Pc,{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 wi={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal"},wt=[15,16,17,18,20,22,24],Xn=18,gs="bim-reader-prefs",Oc="bim-reading-mode";function Dc(){const e={...wi};try{const n=localStorage.getItem(gs),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(gs,JSON.stringify(e))}catch{}}function zo(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 ms(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 hs(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 bs(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(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 Yc(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 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: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:j,currentVersionKey:y,onVersionChange:v,versionSource:_=!0,children:S,className:z,style:w}){const C=f.useId().replace(/:/g,""),L=`bim-rd-toc-${C}`,E=`bim-rd-text-${C}`,T=f.useRef(null),O=f.useRef(null),A=f.useRef(null),F=f.useRef(null),M=Yc(cs,!0),[Y,K]=f.useState("auto"),R=Y==="auto"?M:Y==="open",ie=!M,H=!!p&&p.length>0,[oe,ee]=f.useState(u);f.useEffect(()=>{ee(u)},[u]);const Q=oe==="auto"?H||!!c:oe==="open",G=f.useCallback(q=>{var N;K("auto"),q&&((N=F.current)==null||N.focus())},[]),ae=()=>K(R?"closed":"open");f.useEffect(()=>{if(!ie||Y!=="open")return;const q=A.current,N=q==null?void 0:q.querySelector('input, [data-rd-toc-key][tabindex="0"]');N==null||N.focus()},[ie,Y]);const ue=f.useCallback(q=>{s(q),ie&&G(!1);const N=O.current,I=T.current;if(N&&I&&typeof window<"u"){const $=N.getBoundingClientRect().top-I.getBoundingClientRect().bottom;$<0&&window.scrollBy({top:$})}},[s,ie,G]),re=f.useMemo(()=>bs(i),[i]),[te,fe]=f.useState(null),de=hs(j,y!==void 0?y:te),Te=(de==null?void 0:de.key)??null,be=f.useMemo(()=>re.map(q=>q.key).join(`
777
- `),[re]),ze=f.useRef(null),Ce=q=>{q!==Te&&(ze.current={key:q,sig:be,done:!1},y===void 0&&fe(q),v==null||v(q))};f.useEffect(()=>{const q=ze.current;if(!q||q.key!==Te)return;const N=re.find($=>!$.disabled);if(!N)return;const I=be!==q.sig;!I&&q.done||(I?ze.current=null:q.done=!0,N.key!==r&&ue(N.key))},[Te,be,re,r,ue]);const Ee=re.findIndex(q=>q.key===r),D=Ee>0?re.slice(0,Ee).reverse().find(q=>!q.disabled):void 0,se=Ee>=0?re.slice(Ee+1).find(q=>!q.disabled):void 0,ne=g.fontSize??Xn,ge={...w,...g.fontSize?{"--bimrd-fs":`${g.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",g.writingMode==="vertical"&&k?"bim-rd-vertical":"",z].filter(Boolean).join(" "),"data-toc":Y,"data-img":Q?"open":"closed",style:ge,children:[t.jsx("style",{children:ps}),t.jsx("a",{className:"bim-rd-skip",href:`#${E}`,onClick:q=>{var N,I,$;q.preventDefault(),(N=O.current)==null||N.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:[j&&j.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:de?Qn(de):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=>Ce(q.target.value),children:j.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:F,type:"button",className:"bim-rd-t","aria-expanded":R,"aria-controls":L,onClick:ae,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:()=>ee(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:ne<=wt[0],onClick:()=>x({fontSize:zo(g.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"放大字号",disabled:ne>=wt[wt.length-1],onClick:()=>x({fontSize:zo(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:L,ref:A,role:ie&&R?"dialog":void 0,"aria-modal":ie&&R?!0:void 0,"aria-label":ie&&R?"目录":void 0,onKeyDown:q=>{if(!(!ie||!R)){if(q.key==="Escape"){q.stopPropagation(),G(!0);return}q.key==="Tab"&&Vc(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??"目录"}),ie&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>G(!0),children:"✕"})]}),l]}),t.jsx(xs,{items:i,activeKey:r,onSelect:ue})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>G(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:Q&&t.jsx(fs,{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,_&&de&&(de.sourceName||de.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":de.key,children:[de.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",de.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:de.sourceUrl,target:"_blank",rel:"noreferrer",children:de.sourceName}):de.sourceName]}),de.sourceName&&de.license&&t.jsx("span",{className:"bim-rd-dot"}),de.license&&t.jsxs(t.Fragment,{children:["授权 ",de.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:()=>ue(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:()=>ue(se.key),children:[t.jsx("span",{className:"bim-rd-pglabel",children:se.label}),t.jsx("span",{"aria-hidden":"true",children:"›"})]})})]})]})})]})]})}const ys="guji-table-v1";function js(e){return!!e&&e.table_notation===ys}const qc=/^:::table(?:\{[^}]*\})?[ \t]*$/,Jc=/^:::[ \t]*$/;function vs(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=Ur(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 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 ks(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=vs(u).map(Xc),m=l.map(j=>j>0),b=l.map(j=>j>0?j-1:0),k=[];let h=0;for(const j of x){if(j.cont){m[h]||i.push(`第 ${d} 行第 ${h+1} 列:续格 ^ 上方没有跨行格`),h+=1;continue}const{cell:y}=j;for(let v=h;v<h+y.colspan;v++)if(m[v]){i.push(`第 ${d} 行第 ${v+1} 列:此处被上方跨行格占住,应写 ^`);break}if(y.rowspan>1)for(let v=h;v<h+y.colspan;v++)b[v]=y.rowspan-1;k.push(y),h+=y.colspan}for(let j=h;j<m.length;j++)m[j]&&i.push(`第 ${d} 行第 ${j+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let j=0;j<b.length;j++)b[j]===void 0&&(b[j]=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 zi(e){const n=e.split(`
782
+ `;function wi(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(r=>wi(r,n))):!1}const Oc=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Dc({item:e,activeKey:n,onSelect:i,tabKey:r}){const s=wi(e,n),[l,a]=f.useState(s||!!e.defaultExpanded);return f.useEffect(()=>{s&&a(!0)},[s]),f.useEffect(()=>{e.defaultExpanded&&a(!0)},[e.defaultExpanded]),t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>a(p=>!p),children:[t.jsx(Oc,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(fs,{items:e.children,activeKey:n,onSelect:i,tabKey:r})]})}function fs({items:e,activeKey:n,onSelect:i,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Dc,{item:s,activeKey:n,onSelect:i,tabKey:r},s.key):t.jsx("li",{children:t.jsxs("button",{type:"button",className:"bim-rd-ti","aria-current":s.key===n?"true":void 0,disabled:s.disabled,"data-rd-toc-key":s.key,tabIndex:r===s.key?0:-1,onClick:()=>i(s.key),children:[t.jsx("span",{children:s.label}),s.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:s.hint})]})},s.key))})}function Co(e,n){var i;for(const r of e)if(r.key===n||wi(r,n))return r.key;return((i=e[0])==null?void 0:i.key)??null}function gs({items:e,activeKey:n,onSelect:i,label:r="目录"}){const s=f.useRef(null),[l,a]=f.useState(null);f.useEffect(()=>{a(null)},[n]);const p=f.useMemo(()=>l||(n??Co(e,n)),[l,n,e]);f.useEffect(()=>{const d=s.current;if(!d)return;const u=Array.from(d.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const g=u.find(x=>x.dataset.rdTocKey===p)??u.find(x=>x.dataset.rdTocKey===Co(e,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===g?0:-1}),f.useEffect(()=>{const d=s.current,u=d==null?void 0:d.closest(".bim-rd-toc");if(!d||!u||!n)return;const g=Array.from(d.querySelectorAll("[data-rd-toc-key]")).find(m=>m.dataset.rdTocKey===n);if(!g)return;const x=g.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(x<u.scrollTop+80||x>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,x-u.clientHeight/3))},[n]);const c=f.useCallback(d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const g=s.current;if(!g)return;const x=Array.from(g.querySelectorAll("[data-rd-toc-key]")).filter(h=>!h.disabled),m=x.indexOf(document.activeElement);let b=m;if(d.key==="ArrowDown"?b=Math.min(x.length-1,m+1):d.key==="ArrowUp"?b=Math.max(0,m-1):d.key==="Home"?b=0:d.key==="End"&&(b=x.length-1),b<0||b===m)return;d.preventDefault();const S=x[b];for(const h of x)h.tabIndex=-1;S.tabIndex=0,S.focus(),a(S.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:c,children:t.jsx(fs,{items:e,activeKey:n,onSelect:i,tabKey:p})})}function Hc({page:e}){var n;return!((n=e.boxes)!=null&&n.length)||!e.width||!e.height||e.boxFormat&&e.boxFormat!=="bim-charbox-v0"?null:t.jsx("svg",{viewBox:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:e.boxes.map((i,r)=>t.jsx("rect",{x:i.x,y:i.y,width:i.w,height:i.h,fill:"none",stroke:o("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},r))})}function ms({pages:e,loading:n,page:i,onPageChange:r,renderOverlay:s}){const[l,a]=f.useState(0),p=i??l,c=x=>{r?r(x):a(x)};if(f.useEffect(()=>{i===void 0&&a(0)},[e,i]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:"加载书影…"})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:"暂无书影"}),t.jsx("span",{children:"这一卷还没有配上影像;接入后在此与正文逐页对看"})]})});const d=Math.max(0,Math.min(e.length-1,p)),u=e[d],g=u.label??`${d+1}`;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${g} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(Hc,{page:u}),s==null?void 0:s(u,d)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:d===0,onClick:()=>c(d-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${d+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:d===e.length-1,onClick:()=>c(d+1),children:"›"})]})]})}const _i={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal"},$t=[15,16,17,18,20,22,24],Qn=18,hs="bim-reader-prefs",Gc="bim-reading-mode";function Uc(){const e={..._i};try{const n=localStorage.getItem(hs),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&$t.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(Gc))==="paragraph"&&(e.readingMode="paragraph"),i.properNames===!0&&(e.properNames=!0),i.writingMode==="vertical"&&(e.writingMode="vertical")}catch{}return e}function Vc(e){try{localStorage.setItem(hs,JSON.stringify(e))}catch{}}function Io(e,n){const i=e??Qn,r=$t;let s=r.indexOf(i);return s<0&&(s=r.indexOf(Qn)),r[Math.max(0,Math.min(r.length-1,s+n))]}function $i(){const[e,n]=f.useState(_i);f.useEffect(()=>{n(Uc())},[]);const i=f.useCallback(r=>{n(s=>{const l={...s,...r};return Vc(l),l})},[]);return[e,i]}function bs(e){return e.map(n=>({key:n.key,label:n.version_label||n.key,sourceName:n.source_name,license:n.license,sourceUrl:n.source_url,primary:n.primary}))}function ei(e){const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function ys(e,n){if(!(!e||e.length===0))return(n!=null?e.find(i=>i.key===n):void 0)??e.find(i=>i.primary)??e[0]}function js(e){const n=[],i=r=>{for(const s of r)s.children&&s.children.length>0?i(s.children):n.push(s)};return i(e),n}const Yc=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),qc=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),t.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function Kc(e,n){if(!n)return;const i=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(a=>a.tabIndex>=0);if(i.length===0)return;const r=i[0],s=i[i.length-1],l=document.activeElement;e.shiftKey&&(l===r||!n.contains(l))?(e.preventDefault(),s.focus()):!e.shiftKey&&(l===s||!n.contains(l))&&(e.preventDefault(),r.focus())}function Jc(e,n){const[i,r]=f.useState(n);return f.useEffect(()=>{var a;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(s.matches);return(a=s.addEventListener)==null||a.call(s,"change",l),()=>{var p;return(p=s.removeEventListener)==null?void 0:p.call(s,"change",l)}},[e]),i}function Zc(){const e=f.useContext(Rt);if(!e)return null;const n=e.locale==="zh-Hant";return t.jsxs("button",{type:"button",className:"bim-rd-t",title:n?"切换为简体":"切換為繁體","aria-label":n?"切换为简体":"切換為繁體",onClick:()=>e.setLocale(n?"zh-Hans":"zh-Hant"),children:[t.jsx("span",{className:n?"bim-rd-on":"bim-rd-off",children:"繁"}),t.jsx("span",{className:"bim-rd-off",children:"|"}),t.jsx("span",{className:n?"bim-rd-off":"bim-rd-on",children:"简"})]})}function zi({title:e,subtitle:n,toc:i,activeKey:r,onSelect:s,tocHeader:l,tocCaption:a,images:p,imagesLoading:c,renderImageOverlay:d,imagePanel:u="auto",prefs:g,onPrefsChange:x,paragraphToggle:m,properNameToggle:b=!0,allowVertical:S,pager:h=!0,versions:y,currentVersionKey:j,onVersionChange:k,versionSource:$=!0,children:v,className:_,style:w}){const z=f.useId().replace(/:/g,""),N=`bim-rd-toc-${z}`,T=`bim-rd-text-${z}`,C=f.useRef(null),P=f.useRef(null),B=f.useRef(null),A=f.useRef(null),W=Jc(ps,!0),[V,K]=f.useState("auto"),E=V==="auto"?W:V==="open",le=!W,G=!!p&&p.length>0,[ae,pe]=f.useState(u);f.useEffect(()=>{pe(u)},[u]);const ee=ae==="auto"?G||!!c:ae==="open",X=f.useCallback(Z=>{var F;K("auto"),Z&&((F=A.current)==null||F.focus())},[]),ie=()=>K(E?"closed":"open");f.useEffect(()=>{if(!le||V!=="open")return;const Z=B.current,F=Z==null?void 0:Z.querySelector('input, [data-rd-toc-key][tabindex="0"]');F==null||F.focus()},[le,V]);const me=f.useCallback(Z=>{s(Z),le&&X(!1);const F=P.current,I=C.current;if(F&&I&&typeof window<"u"){const D=F.getBoundingClientRect().top-I.getBoundingClientRect().bottom;D<0&&window.scrollBy({top:D})}},[s,le,X]),te=f.useMemo(()=>js(i),[i]),[se,fe]=f.useState(null),be=ys(y,j!==void 0?j:se),ze=(be==null?void 0:be.key)??null,ve=f.useMemo(()=>te.map(Z=>Z.key).join(`
783
+ `),[te]),ke=f.useRef(null),Ne=Z=>{Z!==ze&&(ke.current={key:Z,sig:ve,done:!1},j===void 0&&fe(Z),k==null||k(Z))};f.useEffect(()=>{const Z=ke.current;if(!Z||Z.key!==ze)return;const F=te.find(D=>!D.disabled);if(!F)return;const I=ve!==Z.sig;!I&&Z.done||(I?ke.current=null:Z.done=!0,F.key!==r&&me(F.key))},[ze,ve,te,r,me]);const Ee=te.findIndex(Z=>Z.key===r),O=Ee>0?te.slice(0,Ee).reverse().find(Z=>!Z.disabled):void 0,ce=Ee>=0?te.slice(Ee+1).find(Z=>!Z.disabled):void 0,oe=g.fontSize??Qn,he={...w,...g.fontSize?{"--bimrd-fs":`${g.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",g.writingMode==="vertical"&&S?"bim-rd-vertical":"",_].filter(Boolean).join(" "),"data-toc":V,"data-img":ee?"open":"closed",style:he,children:[t.jsx("style",{children:xs}),t.jsx("a",{className:"bim-rd-skip",href:`#${T}`,onClick:Z=>{var F,I,D;Z.preventDefault(),(F=P.current)==null||F.focus(),(D=(I=P.current)==null?void 0:I.scrollIntoView)==null||D.call(I,{block:"start"})},children:"跳到正文"}),t.jsxs("div",{className:"bim-rd-bar",ref:C,children:[(e||n)&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),n&&t.jsx("span",{children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":"阅读设置",children:[y&&y.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:be?ei(be):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:"版本"}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:"版本▾"}),t.jsx("select",{"aria-label":"版本",value:ze??"",onChange:Z=>Ne(Z.target.value),children:y.map(Z=>t.jsx("option",{value:Z.key,children:ei(Z)},Z.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),t.jsxs("button",{ref:A,type:"button",className:"bim-rd-t","aria-expanded":E,"aria-controls":N,onClick:ie,children:[t.jsx(Yc,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":ee,onClick:()=>pe(ee?"closed":"open"),children:[t.jsx(qc,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Zc,{}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"缩小字号",disabled:oe<=$t[0],onClick:()=>x({fontSize:Io(g.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"放大字号",disabled:oe>=$t[$t.length-1],onClick:()=>x({fontSize:Io(g.fontSize,1)}),children:"A+"}),(m||b||S)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),m&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":g.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>x({readingMode:g.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),b&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":g.properNames,title:"书名加波浪线",onClick:()=>x({properNames:!g.properNames}),children:"专名线"}),S&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":g.writingMode==="vertical",onClick:()=>x({writingMode:g.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:N,ref:B,role:le&&E?"dialog":void 0,"aria-modal":le&&E?!0:void 0,"aria-label":le&&E?"目录":void 0,onKeyDown:Z=>{if(!(!le||!E)){if(Z.key==="Escape"){Z.stopPropagation(),X(!0);return}Z.key==="Tab"&&Kc(Z,B.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:a??"目录"}),le&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>X(!0),children:"✕"})]}),l]}),t.jsx(gs,{items:i,activeKey:r,onSelect:me})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>X(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:ee&&t.jsx(ms,{pages:p??null,loading:c,renderOverlay:d})}),t.jsx("div",{className:"bim-rd-text",id:T,ref:P,tabIndex:-1,children:t.jsxs("div",{className:"bim-rd-col",children:[v,$&&be&&(be.sourceName||be.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":be.key,children:[be.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",be.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:be.sourceUrl,target:"_blank",rel:"noreferrer",children:be.sourceName}):be.sourceName]}),be.sourceName&&be.license&&t.jsx("span",{className:"bim-rd-dot"}),be.license&&t.jsxs(t.Fragment,{children:["授权 ",be.license]})]}),h&&(O||ce)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[t.jsx("span",{children:O&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>me(O.key),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-pglabel",children:O.label})]})}),t.jsx("span",{children:ce&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>me(ce.key),children:[t.jsx("span",{className:"bim-rd-pglabel",children:ce.label}),t.jsx("span",{"aria-hidden":"true",children:"›"})]})})]})]})})]})]})}const vs="guji-table-v1";function ks(e){return!!e&&e.table_notation===vs}const Xc=/^:::table(?:\{[^}]*\})?[ \t]*$/,Qc=/^:::[ \t]*$/;function Ss(e){const n=[];let i="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const a=Yr(e,r+3);if(a>r+4){i+=e.slice(r,a+1),r=a;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const a=e[r+1];a!==void 0&&!/[A-Za-z/!?>\s]/.test(a)&&(l=">")}if(l){const a=e.indexOf(l,r+1);if(a>0){i+=e.slice(r,a+1),r=a;continue}}s==="|"?(n.push(i),i=""):i+=s}return n.push(i),n.map(r=>r.trim())}const ed=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function td(e){if(e==="^")return{cont:!0};const n=ed.exec(e),i=n[1].trim(),r=n[2]?Math.max(1,parseInt(n[2],10)):1,s=n[3]?Math.max(1,parseInt(n[3],10)):1,l=i==="_";return{cont:!1,cell:{text:l?"":i,empty:l,colspan:r,rowspan:s}}}function ws(e,n=1){const i=[],r=[],s=[];let l=[];e.forEach((p,c)=>{const d=c+n+1;let u=p.trim();if(!u)return;let g=!1;u.startsWith("!")&&(g=!0,u=u.slice(1));const x=Ss(u).map(td),m=l.map(y=>y>0),b=l.map(y=>y>0?y-1:0),S=[];let h=0;for(const y of x){if(y.cont){m[h]||i.push(`第 ${d} 行第 ${h+1} 列:续格 ^ 上方没有跨行格`),h+=1;continue}const{cell:j}=y;for(let k=h;k<h+j.colspan;k++)if(m[k]){i.push(`第 ${d} 行第 ${k+1} 列:此处被上方跨行格占住,应写 ^`);break}if(j.rowspan>1)for(let k=h;k<h+j.colspan;k++)b[k]=j.rowspan-1;S.push(j),h+=j.colspan}for(let y=h;y<m.length;y++)m[y]&&i.push(`第 ${d} 行第 ${y+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let y=0;y<b.length;y++)b[y]===void 0&&(b[y]=0);l=b,r.push({header:g,cells:S}),s.push({width:h,line:d})});const a=s.reduce((p,c)=>Math.max(p,c.width),0);for(const p of s)p.width!==a&&i.push(`第 ${p.line} 行:占 ${p.width} 列,与总列数 ${a} 不符`);return l.some(p=>p>0)&&i.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&i.push("空表"),{rows:r,columns:a,warnings:i}}function Ci(e){const n=e.split(`
778
784
  `),i=[];let r=[];const s=()=>{if(r.length===0)return;const a=r.join(`
779
- `);r=[],i.push({type:"text",text:a})};let l=0;for(;l<n.length;){if(qc.test(n[l].trim())){let a=l+1;for(;a<n.length&&!Jc.test(n[a].trim());)a++;if(a<n.length){s();const p=n.slice(l+1,a);i.push({type:"table",table:ks(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 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")}`,Ss={border:td,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},nd={...Ss,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 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?nd:Ss,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 ws(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function _s(e){return e.split(`
781
- `).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(`
782
- `)){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 wn(e){if(e=ad(e),$s(e))return"unknown";const n=ws(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>_s(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(`
785
+ `);r=[],i.push({type:"text",text:a})};let l=0;for(;l<n.length;){if(Xc.test(n[l].trim())){let a=l+1;for(;a<n.length&&!Qc.test(n[a].trim());)a++;if(a<n.length){s();const p=n.slice(l+1,a);i.push({type:"table",table:ws(p,l+1),source:n.slice(l,a+1).join(`
786
+ `)}),l=a+1;continue}}r.push(n[l]),l++}return s(),i.map((a,p)=>{var d,u;if(a.type!=="text")return a;let c=a.text;return((d=i[p-1])==null?void 0:d.type)==="table"&&(c=c.replace(/^\n+/,"")),((u=i[p+1])==null?void 0:u.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(a=>a.type!=="text"||a.text!=="")}const nd={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},id={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},od=`1px solid ${o("table-border")}`,_s={border:od,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},rd={..._s,background:o("table-head-bg"),fontWeight:600};function Ii({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:nd,children:t.jsx("table",{className:"bim-guji-table",style:id,children:t.jsx("tbody",{children:e.rows.map((i,r)=>t.jsx("tr",{children:i.cells.map((s,l)=>{const a=i.header?"th":"td";return t.jsx(a,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:i.header?rd:_s,children:s.empty?null:Ue(s.text,void 0,n)},l)})},r))})})})}function sd(e,n){return e.indexOf("**")<0?Ue(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:Ue(r.trim().slice(2,-2),void 0,n)},s):t.jsx(f.Fragment,{children:Ue(r,void 0,n)},s))}function ld(e,n,i=!1){const r=i?{gujiMarkdown:!0}:void 0;return n?Ci(e).map((s,l)=>s.type==="table"?t.jsx(Ii,{table:s.table,opts:r},l):t.jsx(f.Fragment,{children:sd(s.text,r)},l)):Ue(e,void 0,r)}const ad=/^(#{1,6})\s+(.*)$/,cd=/^\*\*([^*\n]+)\*\*\s*$/;function Ti(e){const n=e.match(ad);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(cd);return i?{level:3,text:i[1].trim()}:null}const Ei=/^<!--.*-->$/;function $s(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function zs(e){return e.split(`
787
+ `).map(n=>n.trim()).filter(n=>n&&!Ei.test(n))}const dd=60;function Cs(e){let n=0,i=0;for(const r of e.split(`
788
+ `)){const s=r.trim();if(!s||Ei.test(s)||Ti(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>dd&&(i+=l)}return n>0&&i*2>=n}function pd(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function $n(e){if(e=pd(e),Cs(e))return"unknown";const n=$s(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>zs(s).length).filter(s=>s>0);if(i.length===0)return"unknown";const r=i.reduce((s,l)=>s+l,0)/i.length;return r<=4?"record":r>=8?"catalog":"unknown"}function ud(e){const n=e.split(`
783
789
  `),i=[];let r=null,s=[];const l=()=>{i.push({heading:r,body:s.join(`
784
- `)}),s=[]};for(const a of n){const p=Ii(a);if(p){l(),r={kind:"heading",level:p.level,text:p.text};continue}s.push(a)}return l(),i}function Co(e){const n=[];for(const i of e.split(`
785
- `)){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 zs(e){if(!e)return[];const n=wn(e);if(n==="unknown")return Co(e);const i=[];for(const{heading:r,body:s}of cd(e)){r&&i.push(r);const l=ws(s);if(l.length!==0){if($s(s)){i.push(...Co(s));continue}if(n==="record"){const a=l.join(" ");a&&i.push({kind:"body",text:a})}else for(const a of l){const p=_s(a);p.length&&i.push({kind:"body",text:p.join(" ")})}}}return i}const Cs=e=>e;function Is(e,n=Cs){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 Ei(e,n={}){const i=n.renderText??Cs,r=n.properNames?l=>Is(l,i):i,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Ge(e,r,s)}function Io(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 Ts(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
786
- `)?"":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 _n(e){return e?wn(Ts(e))!=="unknown":!1}function To({text:e,mode:n,inline:i,dropTitle:r}){const s=Ts(e),l=(d,u,g)=>!!r&&g<=1&&d<=2&&u.trim()===r.trim(),a=ud();if(n==="paragraph"&&wn(s)!=="unknown"){const d=zs(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:Io(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(Nn);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()&&!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(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:Io(d,i,u)},u)})})}function xd(e){const{convert:n}=V();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:a}){const p=xd(e),{convert:c}=V(),d=x=>Ei(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(To,{text:p,mode:n,inline:d,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(To,{text:x.text,mode:n,inline:d,dropTitle:m===0?g:void 0},m))})}function Es(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 Eo={A:"fine",B:"rough",C:"rough",D:"ocr"};function fd(e){return typeof e!="string"?null:e in Dn?e:e in Eo?Eo[e]:null}const gd={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},md={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function tt(e){return typeof e!="string"?"":gd[e]??md[e]??e}const hd=["〇","一","二","三","四","五","六","七","八","九"],Ro=["","十","百","千"],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 a=i[l],p=i.length-1-l;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&p===1&&l===0&&!n?s+=Ro[p]:s+=hd[a]+Ro[p]}return s.replace(/〇$/,"")}let Ut=null,an=null;const gn=new Set;function jd(){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 vd=e=>e;function yt(){const[,e]=f.useState(0);return f.useEffect(()=>{if(Ut)return;const n=()=>e(i=>i+1);return gn.add(n),jd(),()=>{gn.delete(n)}},[]),Ut??vd}function It(e,n){return n(e).toLowerCase()}const kd=o("highlight-bg");function Qt(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 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:kd,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},p++)),a=c+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(a=>typeof a=="string"&&It(a,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 Rs(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((s,l)=>s+Rs(l),0))||0;return n+i}function $d(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 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=tt(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}=V(),s=Fe(),l=yt(),a=k=>k?Ge(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?is(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(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:["《",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:[Ni(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 Td({section:e,highlightQuery:n=""}){const{convert:i}=V(),r=yt(),s=c=>c?Ge(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(Ai,{enabled:p,expanded:l,onClick:()=>a(!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[tt(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 tt(e.type)!=="page_header"?!1:(e.content||"").length>=Ed}function Rd({section:e,highlightQuery:n=""}){const{convert:i}=V(),r=yt();if(tt(e.type)==="page_header"&&!Wi(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
788
- `)),l=Ge(s,d=>n?Qt(d,n,r):d),a=tt(e.type),p=Bi[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 Nd(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 Ld({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=V(),a=Fe(),p=yt(),c=y=>y?Ge(l(y),v=>s?Qt(v,s,p):v):"",[d,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const g=tt(e.type),x=wd[g]||o("desc-fg"),m=!!e.content,b=e.work_ids||[],k=b.length>1,h=Nd(k?b:[],i,r),j=m&&!d&&e.content.length>80?is(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(Ai,{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&&j&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:c(j)})]})]}),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: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:"→作品"}),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(y=>{const v=h[y],_=v?`${l(v.title)}${v.author?`(${l(v.author)})`:""}`:y.slice(0,8)+"…";return t.jsxs("a",{href:a(y),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(y))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",_]},y)})}),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 Bd({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=yt(),a=n.trim(),p=f.useMemo(()=>a?e.sections.filter(c=>Li(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(Ld,{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 Ad(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Wd({sections:e,onNavigate:n,inline:i}){const r=Fe(),{convert:s}=V(),l=Ad();return t.jsx(t.Fragment,{children:e.map((a,p)=>{const c=tt(a.type);if(c==="page_header"&&!Wi(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?Ni(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 Md(e){return e.some(n=>{const i=tt(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:a,workLabelCache:p,prefs:c}){var A;const{convert:d}=V(),u=yt(),[g,x]=f.useState("text"),m=s.trim(),b=(r==null?void 0:r.type)==="kaozhen",k=f.useCallback(F=>m?Qt(F,m,u):F,[m,u]),h=F=>Ei(F,{renderText:k,properNames:c.properNames}),j=f.useMemo(()=>m?e.sections.filter(F=>Li(F,m,b,u)):e.sections,[e.sections,m,b,u]),y=(F,M)=>M.filter(Y=>tt(Y.type)===F).length,v=y("书",e.sections),_=y("诗",e.sections),S=y("考证",e.sections);let z="";b?z=m?`${y("考证",j)} / ${S} ${d("條")}`:`${S} ${d("條")}`:_>0?z=m?`${y("诗",j)} / ${_} 首`:`${_} 首`:v>0&&(z=m?`${y("书",j)} / ${v} ${d("部書")}`:`${v} ${d("部書")}`);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:[d("考證對象")," ",d(r.target_source)]})),w&&C.push(t.jsx("span",{title:Rl[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(Dn[w]),")"]}):t.jsxs(t.Fragment,{children:[d("文本質量")," ",d(Dn[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 L=!b&&Md(e.sections),E=!!n&&(!L||c.readingMode==="paragraph"&&_n(n)),T=!b&&(L||!!n),O=b||!T?"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((F,M)=>t.jsxs(f.Fragment,{children:[M>0&&t.jsx("span",{className:"bim-rd-dot"}),F]},M))}),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:d("條目")})]})]}),O==="text"&&t.jsx("article",{className:"bim-rd-prose",children:E?t.jsx(Ri,{text:n,mode:c.readingMode,properNames:c.properNames,renderText:k,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:a,workLabelCache:p}):t.jsxs(t.Fragment,{children:[j.map((F,M)=>{const Y=tt(F.type);return Y==="书"||Y==="诗"||Y==="考证"?t.jsx(Id,{section:F,onNavigate:l,highlightQuery:m},M):Y==="类"?t.jsx(Td,{section:F,highlightQuery:m},M):t.jsx(Rd,{section:F,highlightQuery:m},M)}),j.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function Ns(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=Ns(e);return n.length>0?n[0]:null}function Od(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:a,query:p,isKaozhen:c}=e,d=yt(),u=f.useRef(new Map),[g,x]=f.useState({}),[m,b]=f.useState({}),k=f.useCallback((j,y)=>{const v=y==null?void 0:y.title;v&&b(_=>_[j]===v?_:{..._,[j]: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((j,y)=>{let v=0;if(j.juan)for(const _ of j.juan.sections)Li(_,y,c,d)&&v++;return v===0&&j.rawText&&Sd(j.rawText,y,d)&&(v=1),v},[c,d]);return f.useEffect(()=>{const j=p.trim();if(!j){x({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let y=!1;const v={},_=[];for(const L of r){const E=u.current.get(L);E?v[L]=h(E,j):(v[L]="loading",_.push(L))}x(v);const S=8;let z=0;const w=async()=>{var L;for(;z<_.length;){if(y)return;const E=z++,T=_[E];try{const[O,A]=await Promise.all([i.getCollatedJuan(n,T),((L=i.getCollatedJuanText)==null?void 0:L.call(i,n,T))??Promise.resolve(null)]),F={juan:O,rawText:A};if(u.current.set(T,F),k(T,O),y)return;x(M=>({...M,[T]:h(F,j)}))}catch{if(y)return;x(O=>({...O,[T]:0}))}}},C=Array.from({length:Math.min(S,_.length)},()=>w());return Promise.all(C),()=>{y=!0}},[p,n,i,r.join(","),h,d,k]),{matchStates:g,titles:m}}const Mi=({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,j]=f.useState(!1),[y,v]=f.useState(null),[_,S]=f.useState(null),[z,w]=f.useState(null),[C,L]=f.useState(!1),[E,T]=f.useState(null),[O,A]=f.useState(""),F=f.useRef(new Map),M=f.useRef(0),Y=s??_,K=f.useCallback(G=>{S(G),l==null||l(G)},[l]),R=e||b;f.useEffect(()=>{e&&(j(!1),v(null))},[e]),f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let G=!1;return j(!0),v(null),i.getCollatedEditionIndex(n).then(ae=>{G||(ae?k(ae):v("未找到整理本数据"))}).catch(ae=>{G||v(ae instanceof Error?ae.message:"加载失败")}).finally(()=>{G||j(!1)}),()=>{G=!0}},[e,n,i]),f.useEffect(()=>{if(R&&!Y){const G=Pd(R);G&&K(G)}},[R,Y,K]);const ie=n||(R==null?void 0:R.work_id),H=f.useCallback(async G=>{var ue;if(!ie||!(i!=null&&i.getCollatedJuan))return;const ae=++M.current;L(!0),w(null),T(null);try{const[re,te]=await Promise.all([i.getCollatedJuan(ie,G),((ue=i.getCollatedJuanText)==null?void 0:ue.call(i,ie,G))??Promise.resolve(null)]);if(ae!==M.current)return;w(re),T(te)}catch{if(ae!==M.current)return;w(null),T(null)}finally{ae===M.current&&L(!1)}},[ie,i]);f.useEffect(()=>{Y&&H(Y)},[Y,H]);const oe=G=>{K(G)};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(y)return t.jsx("div",{className:a,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:y});if(!R)return null;const ee=R.type==="kaozhen",Q=Ns(R);return t.jsx(Hd,{className:a,style:p,index:R,allFiles:Q,isKaozhen:ee,effectiveWorkId:ie,transport:i,activeFile:Y,handleSelectFile:oe,juanData:z,juanRawText:E,juanLoading:C,searchQuery:O,setSearchQuery:A,onNavigate:r,workLabelCacheRef:F,reader:{title:c,subtitle:d,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m}})};function Ls(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}冊`:_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 c=r(p);return{position:l,label:l===p||l===c?c:`${l} ${c}`}}function Dd(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??Ls(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=$d(c,i);return{key:`group:${d}`,label:s(c.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:Rs(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 Hd=({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:j}=V(),[y,v]=_i(),{matchStates:_,titles:S}=Od({workId:l,transport:a,files:r,activeFile:p,activeJuan:d,activeRawText:u,query:x,isKaozhen:s}),z=Es(h.resolveImages,p),w=f.useMemo(()=>Dd(i,r,_,S,j),[i,r,_,S,j]),C=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:T=>m(T.target.value)}),L=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(T=>T.vol_label)?"冊":"卷",E=p?Ls(p,i,S,j).position:void 0;return t.jsxs($i,{className:e,style:n,title:h.title??(i.title?j(i.title):void 0),subtitle:h.subtitle??j(s?"考證":"整理本"),toc:w,tocCaption:`目录 · ${r.length} ${j(L)}`,tocHeader:C,activeKey:p,onSelect:c,images:z.images,imagesLoading:z.loading,renderImageOverlay:h.renderImageOverlay,imagePanel:h.imagePanel,prefs:y,onPrefsChange:v,paragraphToggle:!s&&_n(u),allowVertical:h.allowVertical,children:[g?t.jsx(bt,{}):d?t.jsx(Fd,{juan:d,rawText:u,positionLabel:E,index:i,searchQuery:x,onNavigate:b,transport:a,workLabelCache:k,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:j("參考文獻")}),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=Fe();return n?t.jsx(bt,{}):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,a=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:{...No,background:s.color},children:s.label}),t.jsx("span",{style:{...No,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&&(a?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"},No={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 a=ce(),[p,c]=f.useState(null),[d,u]=f.useState([]),[g,x]=f.useState("recommend"),[m,b]=f.useState([]),[k,h]=f.useState(!1),j=r??g,y=M=>{x(M),s==null||s(M)},[v,_]=f.useState(!0),[S,z]=f.useState(null),[w,C]=f.useState(null),[L,E]=f.useState(null);f.useEffect(()=>{let M=!1;if(e.getCounts)return e.getCounts().then(Y=>{M||c({works:Y.works,books:Y.books,collections:Y.collections})}).catch(()=>{}),()=>{M=!0}},[e]),f.useEffect(()=>{let M=!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(ie=>({...ie,group:R.name})))}catch{}return[]})().then(async K=>{if(M)return;const R=K.filter(H=>H.id);if(R.length===0){_(!1);return}const ie=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 oe=null;if(e.getEntry)oe=await e.getEntry(H.id);else{const ee=await e.getItem(H.id);ee&&(oe={id:H.id,title:ee.title||H.id,type:ee.type||"work"})}if(oe)return{...oe,group:H.group,fallbackDescription:H.description}}catch{}return{id:H.id,title:H.title,type:ye.extractType(H.id),group:H.group,fallbackDescription:H.description}}));M||(u(ie.filter(H=>H!==null)),_(!1))}),()=>{M=!0}},[e,i]);const T=f.useRef(!1),O=f.useRef(!1),A=f.useRef(!1);f.useEffect(()=>{if(j!=="catalog"||T.current)return;const M=e.getCatalogProgress??e.getResourceProgress;if(!M)return;T.current=!0;let Y=!1;return M.call(e).then(K=>{Y||z(K)}).catch(()=>{T.current=!1}),()=>{Y=!0}},[e,j]),f.useEffect(()=>{if(j!=="collection"||O.current||!e.getCollectionProgress)return;O.current=!0;let M=!1;return e.getCollectionProgress().then(Y=>{M||C(Y)}).catch(()=>{O.current=!1}),()=>{M=!0}},[e,j]),f.useEffect(()=>{if(j!=="site"||A.current||!e.getSiteProgress)return;A.current=!0;let M=!1;return e.getSiteProgress().then(Y=>{M||E(Y)}).catch(()=>{A.current=!1}),()=>{M=!0}},[e,j]),f.useEffect(()=>{if(!l||j!=="feedback")return;let M=!1;return h(!0),fetch(l).then(Y=>Y.json()).then(Y=>{!M&&Y.success&&b(Y.items||[])}).catch(()=>{}).finally(()=>{M||h(!1)}),()=>{M=!0}},[l,j]);const F=M=>{switch(M){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(Ft,{label:a.home.recommendTab,active:j==="recommend",onClick:()=>y("recommend")}),t.jsx(Ft,{label:a.home.catalogTab,active:j==="catalog",onClick:()=>y("catalog")}),t.jsx(Ft,{label:a.home.collectionTab,active:j==="collection",onClick:()=>y("collection")}),t.jsx(Ft,{label:a.home.siteTab,active:j==="site",onClick:()=>y("site")}),l&&t.jsx(Ft,{label:a.home.feedbackTab,active:j==="feedback",onClick:()=>y("feedback")})]}),j==="recommend"&&t.jsx(op,{recommended:d,loading:v,onNavigate:n,getIcon:F,t:a}),j==="catalog"&&t.jsx(Lo,{progress:S,t:a,onNavigate:n}),j==="collection"&&t.jsx(Lo,{progress:w,t:a,onNavigate:n}),j==="site"&&t.jsx(sp,{progress:L,t:a,totalWorks:(p==null?void 0:p.works)??0}),j==="feedback"&&l&&t.jsx(Fi,{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}),op=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=Fe();if(n)return t.jsx(bt,{});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))})},Lo=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(bt,{});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(rp,{item:d,t:n,statusColor:a[p],onNavigate:i},d.id))})]},p)})})},rp=({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})]})},sp=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(bt,{});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(Bo,{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(Bo,{item:c,t:n,totalWorks:i},c.id))})]})]})},Bo=({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})]})},Ao="(max-width: 768px)";function lp(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Ao).matches);return f.useEffect(()=>{const i=window.matchMedia(Ao),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 Y;const l=ce(),{convert:a}=V(),p=lp(),[c,d]=f.useState(null),[u,g]=f.useState(null),[x,m]=f.useState(!1),[b,k]=f.useState("detail"),[h,j]=f.useState([]),[y,v]=f.useState(!1),[_,S]=f.useState(null),[z,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]),L=f.useCallback(async K=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){j([]);return}v(!0);try{if(e.getCollectionCatalogs){const R=await e.getCollectionCatalogs(K);j(R||[])}else if(e.getCollectionCatalog){const R=await e.getCollectionCatalog(K);j(R?[{resource_id:"",data:R}]:[])}}catch{j([])}finally{v(!1)}},[e]),E=f.useCallback(async K=>{if(i){i(K);return}d(K),g(null),j([]),S(null),k("detail"),m(!0);try{const R=await e.getItem(K.id);R&&(g(R),R.type==="collection"?L(K.id):R.type==="work"&&R.has_collated&&C(K.id))}catch(R){console.error("加载详情失败:",R)}finally{m(!1)}},[e,i,L,C]),T=f.useCallback(async K=>{g(null),j([]),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"?L(K):R.type==="work"&&R.has_collated&&C(K))}catch(R){console.error("导航失败:",R)}finally{m(!1)}},[e,L,C]),O=(u==null?void 0:u.type)==="collection"&&(h.length>0||y)||(u==null?void 0:u.type)==="work"&&(_||z),A=p&&(x||u),F=f.useCallback(()=>{d(null),g(null),j([]),S(null),k("detail")},[]),M=t.jsx(t.Fragment,{children:x?t.jsx(bt,{}):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"&&y&&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"&&(_||z)&&t.jsxs("button",{onClick:()=>k("collated"),style:cn(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:(Y=h.find(K=>`catalog:${K.resource_id}`===b))==null?void 0:Y.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: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:F,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:M})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Gn,{transport:e,onEntryClick:E,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:E,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:M})]})};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 dt(e){return e.replace(/\.md$/,"")}function Wo(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 Mo={padding:24,color:o("desc-fg")},ti=({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,j]=f.useState(e??null),[y,v]=f.useState(!1),[_,S]=f.useState(null),z=r!==void 0?r:_,w=f.useCallback(Q=>{s?s(Q):S(Q)},[s]),[C,L]=f.useState(null),[E,T]=f.useState(!1);f.useEffect(()=>{e&&j(e)},[e]),f.useEffect(()=>{if(e)return;j(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 G=!1;return Promise.resolve().then(Q).then(ae=>{G||(ae?j(ae):v(!0))}).catch(()=>{G||v(!0)}),()=>{G=!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 G=dt(z);h.chapters.some(ue=>dt(ue.file)===G)||w(Q)},[h,z,w]);const O=f.useMemo(()=>{if(!h||!z)return null;const Q=dt(z);return h.chapters.find(G=>dt(G.file)===Q)??null},[h,z]);f.useEffect(()=>{if(!n||!O)return;const Q=l!==void 0?i.getWorkFullTextChapter?ae=>i.getWorkFullTextChapter(n,l,ae):null:i.getBookFullTextChapter?ae=>i.getBookFullTextChapter(n,ae):null;if(!Q)return;let G=!1;return T(!0),L(null),Promise.resolve(O.file).then(Q).then(ae=>{G||L(ae)}).catch(()=>{G||L(null)}).finally(()=>{G||T(!1)}),()=>{G=!0}},[n,O,i,l]);const A=Es(u,O?dt(O.file):null),[F,M]=_i(),{convert:Y}=V(),K=!!(a&&a.length>1&&p),R=f.useMemo(()=>K?ms(a).map((Q,G)=>({...Q,label:Wo(a[G])})):void 0,[K,a]),ie=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:Wo(Q)},Q.key))})]}):null;if(!h)return t.jsxs("div",{style:Mo,children:[ie&&t.jsx("div",{style:{marginBottom:12},children:ie}),y?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:Mo,children:[ie&&t.jsx("div",{style:{marginBottom:12},children:ie}),"全文目录为空"]});const H=h.chapters.map(Q=>({key:dt(Q.file),label:Y(Q.title)})),oe=js(h)||Yn(h),ee=C?C.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs($i,{title:c??Y(h.version_label),subtitle:d??"全文",toc:H,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:z?dt(z):null,onSelect:w,images:A.images,imagesLoading:A.loading,renderImageOverlay:g,imagePanel:x,prefs:F,onPrefsChange:M,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(Ri,{text:ee,mode:F.readingMode,tables:oe,gujiMarkdown:Yn(h),properNames:F.properNames})}),!E&&!C&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},cp=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=ce(),{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(dp,{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))})]})},dp=({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(pp,{category:c,expanded:r===d,onToggle:()=>s(d),onNavigate:l},c.name)})})]})},pp=({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(Fo,{label:"著錄",books:l,onNavigate:r}),a.length>0&&t.jsx(Fo,{label:"存目",books:a,onNavigate:r})]})]})},Fo=({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," 條"]})]})},Ve=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=ce();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"}})]}),mt=({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 fp(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=fp(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&a?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Po,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:Po,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"}})]})},Po={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 Bs=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=ce(),[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: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:()=>d(x,"bookID"),style:{...Oo,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:{...Oo,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:Do,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:Do,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:vt})]}),t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:g.id,onChange:m=>c(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=>c(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=>c(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=>c(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=>c(x,"processor_version",m.target.value),placeholder:"如: v0.1",style:vt})]})]})]})]})})]},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})]})]})},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"},Oo={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"},Do={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function As(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 Ws(e){return!e||e.length===0?"":JSON.stringify(e)}const Ms=({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=ce();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: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(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(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(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(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}),c&&c.length>0&&t.jsx(kt,{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(kt,{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(kt,{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(kt,{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:Fs(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(Ho,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(Ho,{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(ni,{onClick:l,children:p}),t.jsx(ni,{onClick:a,primary:!0,children:c})]})]})},kt=({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:Fs(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(ni,{onClick:s,primary:!0,children:["+ ",l]})})]})},Ho=({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 Fs(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"},Ps=({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: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:c?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: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: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"},Go={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},wp={work:"📜",book:"📖",collection:"📚",entity:"👤"},Os=({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`创建新${Go[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:c,type:"text",value:a,onChange:x=>p(x.target.value),onKeyDown:d,placeholder:`请输入${Go[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:!a.trim(),style:{...Ip,opacity:a.trim()?1:.6,cursor:a.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 Ds(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 Hs=({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),[j,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 v=f.useCallback(C=>{x(C.target.value),C.target.value.trim()&&y("search")},[]),_=f.useCallback(C=>s?C.filter(L=>L.id!==s):C,[s]);if(!e)return null;const S=n||(i==="all"?"选择实体":`选择${Ds(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:S}),t.jsx("button",{onClick:c,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:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Ap}),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:"搜索中..."})]})}),z.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs(Uo,{active:j==="recent",onClick:()=>y("recent"),children:["最近使用 (",z.length,")"]}),t.jsxs(Uo,{active:j==="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:j==="recent"&&z.length>0?t.jsx(Vo,{entities:z,onSelect:p}):g.trim()?k?t.jsx(An,{message:"搜索中..."}):w.length>0?t.jsx(Vo,{entities:w,onSelect:p}):t.jsx(An,{message:"未找到匹配的结果"}):t.jsx(An,{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:Wp,children:a||"创建新实体"})]})]})})},Uo=({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}),Vo=({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:Ds(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:"👤"},Gs=({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=ce(),[b,k]=f.useState(!1),[h,j]=f.useState("work"),[y,v]=f.useState(""),[_,S]=f.useState(""),[z,w]=f.useState([]),[C,L]=f.useState(!1),[E,T]=f.useState(!1),[O,A]=f.useState("work"),[F,M]=f.useState(""),[Y,K]=f.useState(),[R,ie]=f.useState(!1),[H,oe]=f.useState(null),[ee,Q]=f.useState([]);f.useRef(null);const G=e.type,ae=G==="work",ue=G==="collection",re=G==="book",te=f.useCallback((N,I)=>{n({...e,[N]:I})},[e,n]),fe=f.useCallback((N,I)=>{v(N),j(I),S(m.editor.selectToLink+m.indexType[I]),w([]),k(!0)},[m]),de=f.useCallback(N=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,N)},[r,e.id]),Te=f.useCallback(N=>{s==null||s(N.id,N.type)},[s]),be=f.useCallback((N,I,$)=>{const P={...$,author:($==null?void 0:$.author)||e.author,dynasty:$==null?void 0:$.dynasty};A(I),M(N),K(P),T(!0)},[e.author]),ze=f.useCallback((N,I)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,F,{type:O,title:N,inheritData:I}),T(!1)},[r,e.id,F,O]),Ce=f.useCallback(N=>{if(!N.trim()){w([]);return}L(!0),r!=null&&r.searchEntities&&r.searchEntities(N,h).then(I=>{w(I),L(!1)}).catch(()=>{w([]),L(!1)})},[r,h]),Ee=f.useCallback(N=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,y,N.id),k(!1)},[r,e.id,y]),D=f.useCallback(()=>{i()},[i]),se=f.useCallback(N=>{oe(()=>N),ie(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Q).catch(()=>{})},[r]),ne=f.useCallback((N,I)=>r!=null&&r.searchEntities?r.searchEntities(N,I==="all"?void 0:I):Promise.resolve([]),[r]),ge=f.useCallback(N=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(N),Q(I=>[N,...I.filter($=>$.id!==N.id)].slice(0,10)),H==null||H(N),ie(!1),oe(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:Fp[G]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(mn,{children:e.id}),t.jsx(mn,{color:Mp[G],children:m.indexType[G]})]})}),t.jsx(Ve,{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:ae?m.editor.workTitle:ue?m.editor.collectionTitle:m.editor.bookTitle,value:e.title,onChange:N=>te("title",N)}),re&&t.jsx(pn,{label:m.editor.belongsToWork,value:e.workName||"",onChange:N=>te("workName",N)}),t.jsx(He,{label:m.editor.authorLabel,value:e.author||"",onChange:N=>te("author",N)}),t.jsx(He,{label:m.editor.publicationYearLabel,value:e.publicationYear||"",onChange:N=>te("publicationYear",N)}),(re||ue)&&t.jsx(pn,{label:m.editor.containedIn,value:e.collection||"",onChange:N=>te("collection",N)}),(re||ue)&&t.jsx(He,{label:m.editor.holderLabel,value:e.holder||"",onChange:N=>te("holder",N)}),(re||ue)&&t.jsx(He,{label:re?m.editor.pageLabel:m.editor.volumeLabel,value:e.pages||"",onChange:N=>te("pages",N)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(He,{label:m.editor.firstImageLabel,value:e.firstImage||"",onChange:N=>te("firstImage",N)})})]})}),t.jsx(Ve,{title:m.section.description,onSave:i,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(mt,{value:e.description||"",onChange:N=>te("description",N),placeholder:m.editor.descriptionPlaceholder})}),(((q=e.additional_works)==null?void 0:q.length)||0)>0&&t.jsx(Ve,{title:m.section.additionalWorks,onSave:i,children:t.jsx(Pp,{items:e.additional_works||[],onChange:N=>te("additional_works",N)})}),t.jsx(Ve,{title:m.section.indexedBy,onSave:i,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Op,{items:e.indexed_by||[],onChange:N=>te("indexed_by",N)})}),t.jsx(Ve,{title:m.section.emendatedBy,onSave:i,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Dp,{items:e.emendated_by||[],onChange:N=>te("emendated_by",N)})}),t.jsx(Ve,{title:m.section.textResources,onSave:i,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(Hn,{items:e.resources||[],onChange:N=>te("resources",N),onDownload:d,downloadStatuses:u,filterType:"text"})}),t.jsx(Ve,{title:m.section.imageResources,onSave:i,children:t.jsx(Hn,{items:e.resources||[],onChange:N=>te("resources",N),onDownload:d,downloadStatuses:u,filterType:"image"})}),t.jsx(Ve,{title:m.section.sources,onSave:i,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(Bs,{items:As(e.sources||""),onChange:N=>te("sources",Ws(N)),onOpenEntityPicker:se})}),(re||ue)&&t.jsx(Ve,{title:m.section.provenance,onSave:i,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(mt,{value:e.provenance||"",onChange:N=>te("provenance",N),placeholder:m.editor.provenancePlaceholder})}),re&&t.jsx(Ve,{title:m.section.otherEditions,onSave:i,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(mt,{value:e.otherEditions||"",onChange:N=>te("otherEditions",N),placeholder:m.editor.otherEditionsPlaceholder})}),t.jsx(Ms,{entityType:G,entityId:e.id,entityTitle:e.title,parentWork:g==null?void 0:g.parentWork,parentCollection:g==null?void 0:g.parentCollection,belongsToWork:g==null?void 0:g.belongsToWork,belongsToCollection:g==null?void 0:g.belongsToCollection,childWorks:g==null?void 0:g.childWorks,childCollections:g==null?void 0:g.childCollections,containedBooks:g==null?void 0:g.containedBooks,siblingBooks:g==null?void 0:g.siblingBooks,onLinkEntity:fe,onUnlinkEntity:de,onViewEntity:Te,onCreateAndLink:be,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(Ps,{isOpen:b,entityType:h,title:_,onSelect:Ee,onCancel:()=>k(!1),onCreate:()=>{k(!1),be(y,h)},searchResults:z,onSearch:Ce,isLoading:C,excludeId:e.id}),t.jsx(Os,{isOpen:E,entityType:O,relationField:F,inheritData:Y,onConfirm:ze,onCancel:()=>T(!1)}),t.jsx(Hs,{isOpen:R,title:m.action.selectBookOrWork,filterType:"all",recentEntities:ee,excludeId:e.id,onSelect:ge,onCancel:()=>{ie(!1),oe(null)},onSearch:ne})]})};function Pp({items:e,onChange:n}){const i=ce(),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(He,{label:i.editor.bookNameLabel,value:a.book_title,onChange:c=>r(p,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(He,{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 Us({items:e,onChange:n,showMeta:i,addLabel:r}){const s=ce(),[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(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(mt,{value:u.summary||"",onChange:m=>p(g,"summary",m),placeholder:s.editor.summaryPlaceholder}),t.jsx(mt,{value:u.comment||"",onChange:m=>p(g,"comment",m),placeholder:s.editor.commentPlaceholder}),t.jsx(mt,{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 Op({items:e,onChange:n}){const i=ce();return t.jsx(Us,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Dp({items:e,onChange:n}){const i=ce();return t.jsx(Us,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function Vs(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 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:a,onSave:p,onDelete:c,onNavigate:d,renderLink:u,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:k,onRelationsChange:h,headerExtra:j,className:y,style:v}=e;ce();const[_,S]=f.useState(s),z=l?s:_;f.useEffect(()=>{s!==_&&S(s)},[s]);const w=f.useCallback(()=>{const F=z==="view"?"edit":"view";l?l(F):S(F)},[z,l]),[C,L]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(F=>{F&&L(F)})},[i,r]);const E=n||C,T=f.useMemo(()=>E?Vs(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: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,A=t.jsxs(t.Fragment,{children:[O,j]});return!E&&!T?t.jsx(bt,{}):z==="view"?t.jsx(xi,{data:E,transport:r,onNavigate:d?F=>d(F):void 0,renderLink:u,headerExtra:A,className:y,style:v}):T?t.jsxs("div",{className:y,style:v,children:[A&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:A}),t.jsx(Gs,{data:T,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:"无数据"})},Yo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ys=({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 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=v=>{v.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[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(y){g("error"),m(y instanceof Error?y.message:"提交失败,请稍后重试")}}};if(!e)return null;const h=s&&a.trim()&&u!=="submitting",j=Yo.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:Yo.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:a,onChange:y=>p(y.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...Zp,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:c,onChange:y=>d(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:[a.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:k,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,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(ii,`calc(${p+oi+nu}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(ii)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>a(!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(Ys,{isOpen:l,onClose:()=>a(!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"},Ko=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ks=({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=Ko.find(k=>k.value===n);return p==="success"?t.jsx("div",{style:qo,children:t.jsxs("div",{style:cu,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>c("idle"),style:du,children:"继续提交"})]})}):t.jsxs("div",{style:qo,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Ko.map(k=>t.jsxs("button",{onClick:()=>i(k.value),style:{...ru,...n===k.value?su:{}},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:{...lu}}),t.jsx("input",{type:"text",value:l,onChange:k=>a(k.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:d})]})},qo={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 Jo(e){return typeof e=="function"?e():e??"/api/feedback"}const qs=({resourceId:e,apiUrl:n})=>{const[i,r]=f.useState([]),[s,l]=f.useState(!0),a=f.useCallback(async()=>{const c=Jo(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=Jo(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(Fi,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Ks,{onSubmit:p})})]})},Zo={part_of:"所屬",has_part:"包含",contains_text_of:"收錄",collected_in:"叢編",text_carried_by:"載錄",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"後繼",derived_from:"衍生",has_adaptation:"改編",related:"相關"};function Xo(e){return e?Zo[e]??e:Zo.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}=V(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,a)=>{const p=yi(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 Js(e,n){var p,c;const i=hi(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 Zs(e,n){const i=(e.url?Et(e.url):void 0)||e.name,r=Wr(e,n);return r?`${i}(${r})`:i}function Oi({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(Zs(e,n)),d=Rt(e),u=vn(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(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?"收起分冊":`展開 ${a.expected} 冊`)})})]})}function Xs({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(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 a=Rt(s),p=i(Zs(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 ri(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 Qo=12,hu=60,Qs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:a,railLinks:p})=>{var ze,Ce,Ee;const c=ce(),{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(""),[j,y]=f.useState(!1),v=u.length<=hu,_=v||m||!!k||j,S=f.useMemo(()=>_?u:u.slice(0,Qo),[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(ge=>{const q=ge??{};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(ge=>{const q=new Map(ge);for(const[N,I]of ne)q.set(N,I);return q})}),()=>{se=!0}},[n,S,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&&S.some(D=>!g.has(D)),L=v||_,E=f.useMemo(()=>Fr(z,e.version_graph,{era:k,scanOnly:j,sort:L?"year":"default"}),[z,e.version_graph,k,j,L]),T=m?E.rows:E.rows.slice(0,Qo),O=E.allRows.filter(D=>D.hasImage).length,A=e.related_works||[],F=A.filter(D=>D.relation==="collected_in"),M=f.useMemo(()=>{const D=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],se=ne=>{const ge=D.indexOf(ne??"");return ge<0?D.length:ge};return A.filter(ne=>ne.relation!=="collected_in").map((ne,ge)=>({r:ne,i:ge})).sort((ne,ge)=>se(ne.r.relation)-se(ge.r.relation)||ne.i-ge.i).map(ne=>ne.r)},[A]),Y=f.useMemo(()=>{const D=hi(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(mu(se.key))})))]},[e.resources,e.resource_groups,d]),K=e.indexed_by||[],R=e.emendated_by||[],ie=f.useMemo(()=>{var P,W,Z;const D=[],se=(W=(P=e.authors)==null?void 0:P[0])==null?void 0:W.dynasty;se&&D.push({label:"成書",value:d(se)});const ne=st(e,c.unit.juan);if(ne){const J=(Z=e.juan_count)==null?void 0:Z.description;D.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[d(ne),J&&J!==ne?t.jsxs("span",{className:"bim-d-meta",children:["(",d(J),")"]}):null]})})}e.loss_status&&D.push({label:"存佚",value:d(fu(e.loss_status))});const ge=E.allRows.filter(J=>J.sortYear!=null),q=ge.length>0?ge.reduce((J,me)=>J.sortYear<=me.sortYear?J:me):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 N=er(e.additional_titles);N.length&&D.push({label:"又名",value:N.map(d).join("、")});const I=er(e.attached_texts);I.length&&D.push({label:"附載",value:I.map(d).join("、")});const $=(e.additional_works||[]).map(J=>d(J.book_title)+(J.n_juan!=null?` ${J.n_juan}${d(c.unit.juan)}`:""));return $.length&&D.push({label:"附錄",value:$.join("、")}),D},[e,d,c,C,E.allRows,R.length]),oe=[{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)):[],G=e.subtype?d(c.workSubtype[e.subtype]??e.subtype):"",ae=t.jsx(Zt,{title:d(e.title),byline:t.jsx(Pi,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(We,{items:[...Q,ee!=null&&ee.source?d(`據《${ee.source.split("/")[0]}》`):"",G]}),description:(ze=e.description)!=null&&ze.text?t.jsxs(t.Fragment,{children:[t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Ce=e.description.sources)!=null&&Ce.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(D=>d(nc(D))).filter(Boolean).join(" · ")}):null]}):void 0,stats:oe,facts:ie,readAction:s,foot:t.jsx(Xt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Ee=e.appendix)==null?void 0:Ee.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(rt,{text:D.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},se))}),ue=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}`}))]:[],re=[];u.length&&re.push({id:"versions",label:"版本",count:u.length}),K.length&&re.push({id:"catalogs",label:"著錄",count:K.length}),F.length&&re.push({id:"collected",label:"收入叢編",count:F.length}),M.length&&re.push({id:"related",label:"相關書目",count:M.length}),Y.length&&re.push({id:"resources",label:"在線資源",count:Y.length});const te=u.length===0&&K.length===0,fe=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&&ue.length===0&&u.length>1?"":void 0,children:[ue.length>0&&t.jsx(Sn,{items:ue,value:k,onChange:D=>{h(D),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Zr,{label:"只看有影印",checked:j,onChange:D=>{y(D),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:d(L?"按年代排列":"按著錄順序")})]}),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:T.map(D=>{var se;return t.jsx(bu,{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"}`)})})]}),T.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(k||j?"當前篩選下沒有版本":"暫無版本著錄")}),E.rows.length>T.length&&t.jsx(Nt,{label:`展開其餘 ${E.rows.length-T.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(yu,{items:K,transport:n,onNavigate:i,renderLink:r}),te&&t.jsx(Me,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),de=(D,se)=>t.jsx(Le,{id:D,label:d(se),onNavigate:i,renderLink:r,dense:!0}),Te=f.useMemo(()=>{const D=new Map;for(const se of M){const ne=Xo(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},[M,d]),be=t.jsxs(t.Fragment,{children:[t.jsx(gt,{id:"collected",title:"收入叢編",items:F.map(D=>de(D.id,D.title))}),t.jsx(gt,{id:"related",title:"相關書目",meta:d(`${M.length} 部`),sub:Te,items:M.map(D=>t.jsxs(t.Fragment,{children:[de(D.id,D.title),t.jsx("span",{className:"bim-d-meta",title:D.note?d(D.note):void 0,children:d(Xo(D.relation))})]}))}),t.jsx(gt,{id:"resources",title:"在線資源",cap:6,items:Y.map(({r:D,kind:se})=>{const ne=d((D.url?Et(D.url):void 0)||D.name),ge=Rt(D);return t.jsxs(t.Fragment,{children:[ge?t.jsxs("a",{href:ge,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:re,railLinks:p,main:fe,card:ae,side:be})};function er(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function tr(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}=V(),a=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",c=e.holders[0],d=c?tr(c,l):e.locationName?l(e.locationName):"",u=e.images[0],g=u?Rt(u):void 0,x=e.images.map(m=>tr(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 yu({items:e,transport:n,onNavigate:i,renderLink:r}){const s=ce(),{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,j;return[b,((j=(h=k==null?void 0:k.authors)==null?void 0:h[0])==null?void 0:j.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:Ge(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:Ge(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:Ge(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 ju(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 vu(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 nr(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 ku(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 Su(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=Su(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])),z=E=>{const T=_.get(E);if(T&&T.lineage)return(T.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,L=E=>{if(!C.has(E)){C.add(E);for(const T of z(E))l.has(T)||(w(T)||(S.has(T)?x.add(T):_.has(T)&&g.add(T)),L(T))}};for(const E of n)d&&d.has(E.id)&&!l.has(E.id)&&L(E.id);for(const E of r.hypothetical_nodes??[])u&&u.has(E.id)&&L(E.id)}const m=n.filter(_=>!l.has(_.id)).filter(_=>!d||d.has(_.id)||g.has(_.id)).map(_=>{const S=vu(_,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=ju(_);return x.has(_.id)&&(S.bridge=!0),S}),k=[...m,...b],h=new Set(k.map(_=>_.id)),j=new Set,y=[],v=_=>{j.has(_.id)||!h.has(_.source)||!h.has(_.target)||(j.add(_.id),y.push(_))};for(const _ of n)l.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!g.has(_.id)||((_.lineage.derived_from??[]).forEach((S,z)=>{v(nr(_.id,S,z))}),(_.lineage.related_to??[]).forEach((S,z)=>{v(ku(_.id,S,z))}));for(const _ of r.hypothetical_nodes??[])u&&!u.has(_.id)&&!x.has(_.id)||(_.derived_from??[]).forEach((S,z)=>{v(nr(_.id,S,z))});return{nodes:k,edges:y,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function el(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function wu(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 tl=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:s}=V();if(!e.nodes.length)return t.jsx("div",{style:{...Mu,...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:{...$u,...r},children:[e.title&&t.jsx("div",{style:zu,children:s(e.title)}),e.description&&t.jsx("div",{style:Cu,children:s(e.description)}),g.map(x=>t.jsx(ir,{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(ir,{label:"其他",nodes:d,incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n})]})},ir=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:a})=>{const{convert:p}=V();return t.jsxs("div",{style:Iu,children:[t.jsx("div",{style:{...Tu,borderLeftColor:n??o("widget-border")},children:p(e)}),i.map(c=>t.jsx(_u,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:a},c.id))]})},_u=({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:{...Eu,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:Ru,children:[t.jsx("span",{style:Nu,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Lu,children:el(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Bu,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:Au,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:Wu,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:rr,children:[t.jsx("div",{style:sr,children:"来源:"}),n.map(c=>{const d=r.get(c.source);return t.jsxs("div",{style:lr(c.confidence),children:[t.jsx("span",{style:ar,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(or,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:cr,children:["· ",p(c.evidence)]})]},c.id)})]}),i.length>0&&t.jsxs("div",{style:rr,children:[t.jsx("div",{style:sr,children:"关联:"}),i.map(c=>{const d=c.source===e.id?c.target:c.source,u=r.get(d);return t.jsxs("div",{style:lr(c.confidence),children:[t.jsx("span",{style:ar,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(or,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:cr,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})},or=({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},$u={fontSize:"14px",color:o("fg")},zu={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Cu={fontSize:"13px",color:o("muted"),marginBottom:"16px",lineHeight:1.6},Iu={marginBottom:"16px"},Tu={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:o("fg")},Eu={border:`1px solid ${o("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:o("bg")},Ru={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Nu={fontSize:"15px",fontWeight:600},Lu={fontSize:"12px",color:o("muted")},Bu={marginBottom:"6px"},Au={fontSize:"12px",color:o("muted"),margin:"2px 0"},Wu={fontSize:"12px",color:o("muted"),fontStyle:"italic",margin:"4px 0"},rr={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${o("widget-border")}`},sr={fontSize:"11px",color:o("muted"),marginBottom:"2px"},lr=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),ar={display:"inline-block",padding:"0 6px",fontSize:"11px",background:o("tag-bg"),color:o("fg"),borderRadius:"3px",marginRight:"6px"},cr={fontSize:"11px",color:o("muted")},Mu={padding:"20px",textAlign:"center",color:o("muted"),fontSize:"13px"},nl=({selectedNodeId:e,...n})=>{const[i,r]=f.useState("loading"),[s,l]=f.useState(null);return f.useEffect(()=>{let a=!1;return Fu().then(p=>{a||(p?(l(p),r("ready")):r("missing"))}),()=>{a=!0}},[]),i==="loading"?t.jsx("div",{style:dr,children:"加载图组件中…"}):i==="missing"||!s?t.jsxs("div",{style:dr,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(Pu,{modules:s,selectedNodeId:e,...n})};async function Fu(){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 Pu=({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:z=>{var Y,K,R,ie;const w=((Y=z.data)==null?void 0:Y.stepPosition)??.85,[C,L,E]=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?L:z.targetX-18,A=T?E:z.targetY-12,F=(R=z.data)==null?void 0:R.labelStyle,M=(ie=z.data)==null?void 0:ie.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,${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")}`,...M,...F},children:z.label})})]})}}),[x,m,b]),j=f.useMemo(()=>({version:z=>{const w=z.data,C=w.kind==="hypothetical",L=w.status==="lost",E=w.isSelected,T=w.bridge,O=w.borderColor??o("muted"),A=T||C?"dashed":"solid",F=T?.5:L?.6:1;return t.jsxs("div",{style:{background:o(T?"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:F,boxShadow:E?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("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:el(w.yearText,void 0,w.uncertain)}),L&&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}=V(),{rfNodes:v,rfEdges:_}=f.useMemo(()=>Ou(e,k,n,l,y),[e,k,n,l,y]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:t.jsxs(p,{nodes:v,edges:_,nodeTypes:j,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 Ou(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(j=>[j.id,j.color??o("muted")]));for(const j of e.nodes)c.setNode(j.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of e.edges)j.kind==="derive"&&(u.has(j.relation)||c.setEdge(j.source,j.target));n.layout(c);const g=e.nodes.map(j=>{const y=c.node(j.id),v=r?j.id===r:void 0,_={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??Hu(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:i,isSelected:v,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:y.x-160/2,y:y.y-90/2},data:_,draggable:!1,selected:v}}),x=.78,m=.06,b=new Map;for(const j of e.edges)j.kind==="derive"&&(b.has(j.source)||b.set(j.source,[]),b.get(j.source).push(j));const k=new Map;for(const[j,y]of b){if(y.length<=1)continue;const v=[...y].sort((S,z)=>{var L,E;const w=((L=c.node(S.target))==null?void 0:L.y)??0,C=((E=c.node(z.target))==null?void 0:E.y)??0;return w-C}),_=v.length;v.forEach((S,z)=>{const w=(z-(_-1)/2)*m;k.set(S.id,x+w)})}const h=e.edges.map(j=>Du(j,k.get(j.id),s));return{rfNodes:g,rfEdges:h}}function Du(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Gu(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 Hu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Gu(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 dr={padding:"40px 20px",textAlign:"center",color:o("muted"),fontSize:"13px",border:`1px dashed ${o("widget-border")}`,borderRadius:8,background:o("bg")},Di=({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 y;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 j=a?(y=c==null?void 0:c[a])==null?void 0:y.description:void 0;return t.jsxs("div",{className:u,style:g,children:[t.jsxs("div",{style:Uu,children:[t.jsx("button",{onClick:()=>b("list"),style:Wn(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:Wn(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:Wn(a===v),title:_.description,children:[_.label,S!=null?` ${S}`:""]},v)})]})]}),h&&j&&t.jsx("div",{style:{fontSize:12,color:o("muted"),marginBottom:8,padding:"4px 8px",background:o("bg-subtle"),borderRadius:4},children:j}),x==="list"?t.jsx(tl,{graph:e,renderLink:i}):t.jsx(nl,{graph:e,renderLink:i,height:r,selectedNodeId:s})]})},Uu={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Wn=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"}),pr=40,ur=2,Vu=9,xr={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function Mn(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const il=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,fullText:l,fullTextPending:a,chapterLink:p,railTop:c,back:d,railLinks:u})=>{var P,W,Z,J,me,we,_e,Ne,Re,Lt,Bt;const g=ce(),{convert:x}=V(),[m,b]=f.useState(null),[k,h]=f.useState(new Map),[j,y]=f.useState([]),[v,_]=f.useState(new Map),[S,z]=f.useState(!1),[w,C]=f.useState("flow"),[L,E]=f.useState(null);f.useEffect(()=>{if(!n||!e.work_id){b(null);return}let B=!1;return n.getItem(e.work_id).then(le=>{!B&&le&&le.type==="work"&&b(le)}).catch(()=>{}),()=>{B=!0}},[n,e.work_id]),f.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){E(null);return}let B=!1;return n.getLineageGraph(e.work_id).then(le=>{B||E(le&&le.nodes.length>1?le:null)}).catch(()=>{B||E(null)}),()=>{B=!0}},[n,e.work_id]),f.useEffect(()=>{const B=e.contained_in||[];if(!n||B.length===0){h(new Map);return}let le=!1;return Promise.all(B.map(xe=>{const ve=typeof xe=="string"?xe:xe.id;return n.getItem(ve).then(pe=>[ve,pe]).catch(()=>[ve,null])})).then(xe=>{if(le)return;const ve=new Map;for(const[pe,ke]of xe)ke&&ve.set(pe,ke);h(ve)}),()=>{le=!0}},[n,e.contained_in]);const T=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]),O=T.length-1;f.useEffect(()=>{if(!n||O<=0){y([]);return}const B=T.length<=pr,le=B?T:T.slice(0,8);let xe=!1;return Promise.all(le.map(ve=>ve===e.id?Promise.resolve({id:ve,title:e.title,edition:e.edition,year:fn(e)}):n.getItem(ve).then(pe=>{const ke=pe??{};return{id:ve,title:ke.title,edition:ke.edition,year:pe?fn(ke):void 0}}).catch(()=>({id:ve})))).then(ve=>{if(xe)return;const pe=ve.filter(ke=>ke.id===e.id||ke.title||ke.edition);B&&pe.sort((ke,Pe)=>(ke.year??1/0)-(Pe.year??1/0)),y(pe)}),()=>{xe=!0}},[n,T,O,e]);const A=e.lineage,F=f.useMemo(()=>[...((A==null?void 0:A.derived_from)||[]).filter(B=>B.ref_type==="book").map(B=>B.ref),...((A==null?void 0:A.related_to)||[]).map(B=>B.book_id)].filter(Boolean),[A]);f.useEffect(()=>{if(!n||F.length===0){_(new Map);return}let B=!1;return Promise.all(F.map(le=>n.getItem(le).then(xe=>[le,{id:le,title:xe==null?void 0:xe.title,edition:xe==null?void 0:xe.edition}]).catch(()=>[le,{id:le}]))).then(le=>{B||_(new Map(le))}),()=>{B=!0}},[n,F]);const M=f.useMemo(()=>Js(e.resources,e.resource_groups),[e.resources,e.resource_groups]),Y=M.groups.reduce((B,le)=>B+le.rows.length+le.mirrors.length,0),K=M.groups.length>0&&M.groups.every(B=>B.key==="_physical"),R=qt(e),ie=Gr(e),H=st(e,g.unit.juan),oe=new Set((e.contained_in||[]).map(B=>typeof B=="string"?0:Gt(B.volume_index).length).filter(B=>B>0)),ee=B=>{var ve;const le=(ve=e.base_edition)==null?void 0:ve.find(pe=>pe.book_id===B&&pe.name);if(le!=null&&le.name)return le.name;const xe=v.get(B);return(xe==null?void 0:xe.edition)||(xe==null?void 0:xe.title)||""},Q=f.useMemo(()=>{var lt,tn,at,nn,on;const B=[];ie&&B.push({label:"版本類型",value:x(ie),title:e.edition_type||(lt=e.lineage)!=null&&lt.category?void 0:x("據版本題名推斷")}),(tn=e.publication_info)!=null&&tn.details?B.push({label:"刊印",value:x(e.publication_info.details)}):(R.era||R.reign)&&B.push({label:"刊寫年代",value:x([R.era,R.reign].filter(Boolean).join(" ")),title:R.source==="edition"?x("據版本題名推斷"):void 0}),H&&B.push({label:"卷帙",value:x(H)});const le=(e.contained_in||[]).flatMap(je=>typeof je=="string"?[]:Gt(je.volume_index));le.length&&B.push({label:"冊次",value:x(`第 ${kn(le,g.unit.volume)} ${g.unit.volume}(${le.length} ${g.unit.volume})`)});const xe=(((at=e.lineage)==null?void 0:at.derived_from)||[]).find(je=>je.relation==="底本"&&je.ref_type==="book");xe&&ee(xe.ref)&&B.push({label:"底本",value:t.jsx(Le,{id:xe.ref,label:x(ee(xe.ref)),onNavigate:i,renderLink:r,dense:!0})});const ve=(e.base_edition||[]).filter(je=>je&&je.name);for(const je of["底本","配補","參校"]){if(je==="底本"&&xe&&ee(xe.ref))continue;const qe=ve.filter(Ie=>Ie.role===je);qe.length&&B.push({label:je,value:qe.map((Ie,jt)=>t.jsxs(f.Fragment,{children:[jt>0&&"、",Ie.book_id?t.jsx(Le,{id:Ie.book_id,label:x(Ie.name),onNavigate:i,renderLink:r,dense:!0}):x(Ie.name)]},jt))})}const pe=(e.provenance||[]).filter(je=>je&&je.institution),ke=(e.resources||[]).filter(je=>(je.types||(je.type?[je.type]:[])).includes("physical"));if(pe.length){B.push({label:"存藏",value:pe.slice(0,2).map(Ie=>x(Ie.institution)).join("、")+(pe.length>2?x(` 等 ${pe.length} 處`):"")});const je=pe.filter(Ie=>Ie.call_number).slice(0,2).map(Ie=>`${x(Ie.institution)} ${Ie.call_number}`);je.length&&B.push({label:"索書號",value:je.join(";")+(pe.filter(Ie=>Ie.call_number).length>2?"…":"")});const qe=pe.flatMap(Ie=>Ie.seals||[]).filter(Boolean);qe.length&&B.push({label:"藏印",value:x(qe.join("、"))})}else ke.length?B.push({label:"存藏",value:ke.slice(0,2).map(je=>x(je.name)).join("、")+(ke.length>2?x(` 等 ${ke.length} 處`):"")}):(nn=e.current_location)!=null&&nn.name&&B.push({label:"存藏",value:x(e.current_location.name)});const Pe=e.physical_description;if(Pe){const je=[["行款",Pe.leaf_style],["裝幀",Pe.binding],["尺寸",Pe.dimensions],["品相",Pe.condition]];for(const[qe,Ie]of je)Ie&&Ie.trim()&&B.push({label:qe,value:x(Ie)})}(on=e.page_count)!=null&&on.description&&B.push({label:g.label.pageCount,value:x(e.page_count.description)});const Ke=[...Zn(e.additional_titles),...Zn(e.attached_texts)];return Ke.length&&B.push({label:"又名",value:Ke.map(x).join("、")}),B},[e,x,g,R,ie,H,v,i,r]),G=x(e.title),ae=e.edition?x(e.edition):void 0,ue=((P=e.lineage)==null?void 0:P.year_text)||"",re=t.jsx(Zt,{kind:"版本",title:G,subtitle:ae,byline:t.jsx(Pi,{authors:e.authors??(m==null?void 0:m.authors),onNavigate:i,renderLink:r}),meta:(()=>{const B=[ie?x(ie):"",R.era?x([R.era,R.reign].filter(Boolean).join("")):"",H?x(H):""].filter(Boolean);return B.length?t.jsx("span",{className:"bim-d-tags",children:B.map((le,xe)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(xe,2)}`,children:le},xe))}):null})(),description:(W=e.description)!=null&&W.text?t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ji((Z=e.description)==null?void 0:Z.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})}),te=e.contained_in||[],fe=(l==null?void 0:l.chapters)||[],de=fe[0]&&Mn(fe[0].title)[0].slice(-1)||"章",Te=!!((J=A==null?void 0:A.derived_from)!=null&&J.length||(me=A==null?void 0:A.related_to)!=null&&me.length||(we=e.appendix)!=null&&we.length),be=[];(fe.length||M.text.length||a)&&be.push({id:"fulltext",label:"全文",count:fe.length?x(`${fe.length} ${de}`):void 0}),M.groups.length&&be.push({id:"images",label:K?"館藏":"影印",count:Y}),Te&&be.push({id:"lineage",label:"版本源流"}),te.length&&be.push({id:"collections",label:"收入叢編",count:te.length}),(_e=e.location_history)!=null&&_e.length&&be.push({id:"provenance",label:"流轉歷史"});const ze=B=>(p==null?void 0:p(B))??null,Ce=fe[0],Ee=Ce?ze(Ce.file):null,D=S?fe:fe.slice(0,Vu),se=(B,le,xe)=>B?t.jsx("a",{className:xe,href:B.href??"#",onClick:B.onClick?ve=>{ve.metaKey||ve.ctrlKey||(ve.preventDefault(),B.onClick())}:void 0,children:le}):t.jsx("span",{className:xe,children:le}),ne=t.jsxs(t.Fragment,{children:[(fe.length>0||M.text.length>0||a)&&t.jsxs(Me,{id:"fulltext",title:"全文",meta:fe.length>0?t.jsx(We,{items:[x(`${fe.length} ${de}`),(Ne=l==null?void 0:l.source)!=null&&Ne.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[a&&!Ce&&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"})]}),Ce&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${Mn(Ce.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((Ce.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),se(Ee,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),fe.length>1&&t.jsx("ul",{className:"bim-d-chap",children:D.map(B=>{const[le,xe]=Mn(B.title);return t.jsx("li",{children:se(ze(B.file),t.jsxs(t.Fragment,{children:[le&&t.jsx("b",{children:x(le)}),x(xe||B.file)]}))},B.file)})}),fe.length>D.length&&t.jsx(Nt,{label:`展開其餘 ${fe.length-D.length} ${de}`,onClick:()=>z(!0)}),M.text.length>0&&t.jsxs(t.Fragment,{children:[(fe.length>0||a)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:M.text.map((B,le)=>t.jsx(Oi,{item:B,siblings:M.text,listedVolumeCounts:oe},`${B.id||B.url||B.name}-${le}`))})})]})]}),M.groups.length>0&&t.jsx(Me,{id:"images",title:K?"館藏":"影印",meta:t.jsx(We,{items:[M.groups.length>1?x(`${M.groups.length} 組`):"",x(`${Y} 處`)]}),children:t.jsx(Xs,{groups:M.groups,listedVolumeCounts:oe})}),Te&&t.jsx(Me,{id:"lineage",title:"版本源流",meta:(Re=A==null?void 0:A.derived_from)!=null&&Re.length?x("據版本傳承著錄"):void 0,action:L?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"&&L?t.jsx(Di,{graph:L,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(B,le)=>t.jsx(Le,{id:B,label:x(le),onNavigate:i,renderLink:r,dense:!0})}):t.jsx(Ku,{data:e,heading:ae||G,yearText:ue,refName:ee,onNavigate:i,renderLink:r})}),te.length>0&&t.jsx(Me,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:te.map((B,le)=>{var Pe,Ke;const xe=typeof B=="string"?B:B.id,ve=typeof B=="string"?[]:Gt(B.volume_index),pe=k.get(xe),ke=(pe==null?void 0:pe._member_count)||((Pe=pe==null?void 0:pe.books)==null?void 0:Pe.length)||((Ke=pe==null?void 0:pe.contained_works)==null?void 0:Ke.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Le,{id:xe,label:pe?x(pe.title):xe,onNavigate:i,renderLink:r,dense:!0}),ve.length>0&&t.jsx(Yu,{volumes:ve,unit:g.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ke?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ke>0&&x(`全 ${ke} ${g.unit.bu}`)})]},`${xe}-${le}`)})})})}),(Lt=e.location_history)!=null&&Lt.length?t.jsx(Me,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((B,le)=>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(We,{items:[[B.start_date,B.end_date].filter(Boolean).join("—"),B.description?x(B.description):""]})})]},le))})}):null,be.length===0&&t.jsx(Me,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),ge=j.findIndex(B=>B.id===e.id),q=T.length<=pr,N=q&&ge>=0?j.slice(Math.max(0,ge-ur),ge+ur+1):j.filter(B=>B.id!==e.id),I=t.jsxs(t.Fragment,{children:[m&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:x(g.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(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(B=>`${B.dynasty?`〔${x(B.dynasty)}〕`:""}${x(B.name)}`),x(st(m,g.unit.juan)),m._edition_count?x(`${m._edition_count} 種版本`):""]}),((Bt=m.description)==null?void 0:Bt.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&&N.length>0&&t.jsxs("div",{children:[t.jsx(gt,{id:"siblings",timeline:!0,title:q?"同作品版本":g.relation.siblingVersions,meta:x(q?"按年代":`${O} 種`),cap:N.length,items:N.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:N.map(B=>[B.year!=null?B.year<0?`前${-B.year}`:String(B.year):"",B.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:N.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(`在作品頁看全部 ${T.length} 種 →`),onNavigate:i,renderLink:r,dense:!0})})]})]}),$=e.work_id?t.jsx(Jr,{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:$,nav:be,railLinks:u,main:ne,card:re,side:I})};function Yu({volumes:e,unit:n}){const{convert:i}=V();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${kn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}function Ku({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(j=>j.ref_type!=="book"),u=c.filter(j=>j.ref_type==="book"&&j.relation==="底本"),g=c.filter(j=>j.ref_type==="book"&&j.relation!=="底本"),x=(p==null?void 0:p.related_to)||[],m=c.length>0||x.length>0,b=j=>j&&xr[j]?a(`(${xr[j]})`):"",k=(j,y)=>t.jsx(Le,{id:j,label:a(y||j),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((j,y)=>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(j.relation||"祖本")}),t.jsx("span",{className:"bim-d-lf-name",children:a("擬構祖本")}),j.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[a(j.evidence),b(j.confidence)]})]})},`a-${y}`)),u.map((j,y)=>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(j.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:k(j.ref,r(j.ref))}),j.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[a(j.evidence),b(j.confidence)]})]})},`b-${y}`)),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((j,y)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(j.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:k(j.ref,r(j.ref))}),j.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[a(j.evidence),b(j.confidence)]})]},y))})]}),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((j,y)=>t.jsxs("span",{className:"bim-d-lf-chip",title:j.evidence?a(j.evidence):void 0,children:[k(j.book_id,r(j.book_id)),t.jsx("span",{className:"bim-d-meta",children:a(j.relation)})]},y))})]})]}),(h=e.appendix)==null?void 0:h.map((j,y)=>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(j.title)]}),t.jsx(rt,{text:j.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${y}`)),(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 Fn=16,qu=200,Ju=16,ol=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,railTop:a,back:p,railLinks:c})=>{var D,se,ne,ge,q,N,I;const d=ce(),{convert:u}=V(),[g,x]=f.useState(""),[m,b]=f.useState(!1),[k,h]=f.useState(null),[j,y]=f.useState(""),v=f.useMemo(()=>Dr(e,n),[e,n]),[_,S]=f.useState(new Map),z=!!i&&v.rows.length>0&&v.rows.length<=qu,w=z&&v.rows.every($=>!$.id||_.has($.id)),C=$=>{var P;return ri($?(P=_.get($))==null?void 0:P.l1:void 0)},L=f.useMemo(()=>{const $=g.trim(),P=$?u($):"";return v.rows.filter(W=>{var J,me;if(j&&ri(W.id?(J=_.get(W.id))==null?void 0:J.l1:void 0)!==j)return!1;if(!P)return!0;const Z=W.id&&((me=_.get(W.id))==null?void 0:me.title)||W.title;return u(Z).includes(P)||(W.subItems||[]).some(we=>u(we).includes(P))})},[v.rows,g,j,_,u]),E=m?L:L.slice(0,Fn),T=f.useMemo(()=>(z?v.rows:E).filter($=>$.id&&!_.has($.id)).map($=>$.id),[z,v.rows,E,_]);f.useEffect(()=>{if(!i||T.length===0)return;let $=!1;const P=T.slice(0,Ju);return Promise.all(P.map(W=>i.getItem(W).then(Z=>{var we,_e;const J=Z??{},me={title:J.title,edition:J.edition,authors:J.authors,measure:Z?st(Z,d.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[W,me]}).catch(()=>[W,{}]))).then(W=>{$||S(Z=>{const J=new Map(Z);for(const[me,we]of W)J.set(me,we);return J})}),()=>{$=!0}},[i,T,d.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(P=>{$||h({id:O,title:P==null?void 0:P.title})}).catch(()=>{}),()=>{$=!0}},[i,O]);const A=f.useMemo(()=>Js(e.resources,e.resource_groups),[e.resources,e.resource_groups]),F=A.text.length+A.groups.reduce(($,P)=>$+P.rows.length+P.mirrors.length,0),M=e.contained_works||[],Y=new Set(v.rows.map($=>$.id).filter(Boolean)),K=M.length>0&&!M.every($=>Y.has($.id)),R=(()=>{const $=v.rows.map(P=>P.edition).filter(Boolean);return $.length>1&&new Set($).size===1})(),ie=v.rows.some($=>$.volumes.length>0||$.expected!=null),H=e._member_count||((D=e.books)==null?void 0:D.length)||M.length,oe=st(e,d.unit.juan),ee=e.count,Q=$=>typeof $=="number"&&Number.isFinite($)?$:null,G=Q(ee==null?void 0:ee.juan)??Q((se=e.juan_count)==null?void 0:se.number),ae=Q(ee==null?void 0:ee.ce)??(v.totalVolumes||null),ue=[{value:v.rows.length,label:"子目"},{value:G??0,label:d.unit.juan},{value:ae??0,label:d.unit.volume}],re=f.useMemo(()=>{var W,Z;const $=[];if((W=e.publication_info)!=null&&W.details&&$.push({label:"刊印",value:u(e.publication_info.details)}),H&&H!==v.rows.length){const J=e._member_type==="Book"?"所收版本":e._member_type==="Work"?"所收作品":"成員";$.push({label:u(J),value:`${H} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")})}const P=[Q(ee==null?void 0:ee.zhong)!=null?`${ee.zhong} 種`:"",Q(ee==null?void 0:ee.han)!=null?`${ee.han} 函`:""].filter(Boolean);return P.length&&$.push({label:"應收",value:u(P.join(" "))}),G==null&&oe&&$.push({label:"卷帙",value:u(oe),title:(Z=e.juan_count)!=null&&Z.description?u(e.juan_count.description):void 0}),$},[e,H,v.rows.length,G,oe,ee,u,d]),te=f.useMemo(()=>{if(!w)return[];const $=new Map;for(const W of v.rows){const Z=C(W.id);Z&&$.set(Z,($.get(Z)??0)+1)}const P=Vt.filter(W=>($.get(W.key)??0)>0);return P.length<2?[]:[{key:"",label:`${d.catalog.all} ${v.rows.length}`},...P.map(W=>({key:W.key,label:`${W.label} ${$.get(W.key)}`}))]},[w,v.rows,_,d]),fe=f.useMemo(()=>{if(!w||!v.rows.some(Z=>Z.volumes.length>0))return null;const $=[],P=v.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 P){const J=Z.to-Z.from+1,me=$[$.length-1];me&&me.key===Z.k?(me.to=Math.max(me.to,Z.to),me.n+=J):$.push({key:Z.k,from:Z.from,to:Z.to,n:J})}const W=P.reduce((Z,J)=>Math.max(Z,J.to),0);return $.length>1&&$.some(Z=>Z.key)?{segs:$,last:W}:null},[w,v.rows,_]),de=(ne=e.description)==null?void 0:ne.text,Te=t.jsx(Zt,{kind:"叢編",title:u(e.title),byline:t.jsx(Pi,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(We,{items:[e.subtype==="work_collection"?u("作品集"):"",(ge=e.publication_info)!=null&&ge.year?u(e.publication_info.year):""]}),description:de||(q=e.history)!=null&&q.length?t.jsxs(t.Fragment,{children:[de&&t.jsx(rt,{text:de,style:{fontSize:15,lineHeight:1.85}}),(N=e.history)!=null&&N.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map(($,P)=>t.jsx("li",{children:u($)},P))}):null]}):void 0,clampDescription:ji(de)||(((I=e.history)==null?void 0:I.length)??0)>2?6:void 0,stats:ue,facts:re,foot:t.jsx(Xt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:fe&&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:fe.segs.map(($,P)=>{const W=Vt.find(Z=>Z.key===$.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!W,title:W?u(`${W.label} 第 ${$.from}–${$.to} 冊`):void 0,"aria-label":u(W?`只看${W.label}`:"未分類"),"aria-pressed":!!W&&j===$.key,style:{flexGrow:$.n,background:o(W?W.token:"rule")},onClick:()=>{W&&(y(j===$.key?"":$.key),b(!1))}},P)})}),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(`第 ${fe.last} ${d.unit.volume}`)})]})]})}),be=[];v.rows.length&&be.push({id:"titles",label:"子目",count:v.rows.length}),F&&be.push({id:"resources",label:"影印與全文",count:F}),K&&be.push({id:"works",label:d.section.containedWorks,count:M.length});const ze=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}`):"",L.length!==v.rows.length?u(`當前 ${L.length} ${d.unit.items}`):""]}),action:l,children:[(v.rows.length>Fn||te.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[te.length>0&&t.jsx(Sn,{items:te,value:j,onChange:$=>{y($),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),v.rows.length>Fn&&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:[ie&&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(($,P)=>{var Ne;const W=$.id?_.get($.id):void 0,Z=W!=null&&W.title&&$.title===$.id?W.title:$.title,J=((W==null?void 0:W.authors)||[]).find(Re=>Re&&Re.name),me=[J?`${J.dynasty?`〔${u(J.dynasty)}〕`:""}${u(J.name)}${J.role?` ${u(J.role)}`:""}`:"",W!=null&&W.measure?u(W.measure):"",(Ne=$.subItems)!=null&&Ne.length?$.subItems.map(Re=>u(Re)).join("、"):"",(W!=null&&W.edition||$.edition)&&!R?u((W==null?void 0:W.edition)||$.edition||""):""].filter(Boolean),we=Vt.find(Re=>Re.key===C($.id)),_e=$.volumes.length>0?u(`第 ${kn($.volumes,d.unit.volume)} ${d.unit.volume}`):$.expected!=null?u(`${$.found??0}/${$.expected} ${d.unit.volume}`):"";return t.jsxs("tr",{children:[ie&&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)}),me.length>0?t.jsx(We,{items:me}):$.id&&!W&&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${W!=null&&W.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:W!=null&&W.versionCount?u(`${W.versionCount} 種`):""})]},`${$.id??$.title}-${P}`)})})]}),E.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),L.length>E.length&&t.jsx(Nt,{label:`展開其餘 ${L.length-E.length} ${d.unit.items}`,onClick:()=>b(!0)})]}),F>0&&t.jsxs(Me,{id:"resources",title:"影印與全文",meta:u(`${F} 處`),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(($,P)=>t.jsx(Oi,{item:$,siblings:A.text},`${$.id||$.url||$.name}-${P}`))})})]}),t.jsx(Xs,{groups:A.groups})]}),v.rows.length===0&&F===0&&t.jsx(Me,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),Ce=K?t.jsx(gt,{id:"works",title:d.section.containedWorks,meta:u(`${M.length} 種`),cap:12,items:M.map($=>t.jsx(Le,{id:$.id,label:u($.title),onNavigate:r,renderLink:s,dense:!0}))}):null,Ee=k?t.jsx(Jr,{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:Ee,nav:be,railLinks:c,main:ze,card:Te,side:Ce})},Zu=16,Pn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function fr(e){if(!e)return Pn.length;const n=Pn.indexOf(e);return n===-1?Pn.length:n}const Xu={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function pt(e){return e==null?"":e<0?`前${-e}`:String(e)}const Qu={秦:[-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]},rl=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:a})=>{var se,ne,ge,q,N;const p=ce(),{convert:c}=V(),[d,u]=f.useState("全部"),[g,x]=f.useState(!1),[m,b]=f.useState("default"),[k,h]=f.useState(new Map),j=f.useMemo(()=>(e.works||[]).map(I=>{const $=k.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,k]),y=f.useMemo(()=>Or((e.works||[]).map(I=>I.role)),[e.works]),v=f.useMemo(()=>{const I=d==="全部"?j:j.filter($=>$.cls===d);return m==="versions"?[...I].sort(($,P)=>(P.versionCount??-1)-($.versionCount??-1)):I},[j,d,m]),_=g?v:v.slice(0,Zu),S=f.useMemo(()=>_.filter(I=>!k.has(I.id)).map(I=>I.id),[_,k]);f.useEffect(()=>{if(!n||S.length===0)return;let I=!1;return Promise.all(S.map($=>n.getItem($).then(P=>{var me,we,_e,Ne,Re;const W=P??{},Z=W._edition_count??(((me=W.books)==null?void 0:me.length)??0)+(((we=W.collections)==null?void 0:we.length)??0),J=[(_e=W.classification)==null?void 0:_e.l1,(Ne=W.classification)==null?void 0:Ne.l2].filter(Boolean).join(" ");return[$,{id:$,title:W.title,versionCount:Z,loaded:!0,cls:J||void 0,l1:((Re=W.classification)==null?void 0:Re.l1)||void 0,measure:P&&st(P,p.unit.juan)||void 0,hasImage:!!(W.has_image??W._has_image)}]}).catch(()=>[$,{id:$,loaded:!0}]))).then($=>{I||h(P=>{const W=new Map(P);for(const[Z,J]of $)W.set(Z,J);return W})}),()=>{I=!0}},[n,S,p.unit.juan]);const z=f.useMemo(()=>{const I=new Map;for(const $ of e.alt_names||[]){const P=$.type||p.section.aliases;I.has(P)||I.set(P,[]),I.get(P).push($.name)}return[...I.entries()].sort(($,P)=>fr($[0])-fr(P[0])).map(([$,P])=>({label:$,names:P}))},[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,L=(ge=e.dates)==null?void 0:ge.floruit,E=w!=null||C!=null?`${pt(w)||"?"}—${pt(C)||"?"}`:Array.isArray(L)&&L.length===2&&L.every(I=>Number.isFinite(I))?`活躍於 ${pt(L[0])}—${pt(L[1])}`:"",T=new Set(["本名","字","號","号"]),O=z.filter(I=>T.has(I.label)),A=z.filter(I=>!T.has(I.label)),F=A.reduce((I,$)=>I+$.names.length,0),M=f.useMemo(()=>{const I=[];for(const P of O)I.push({label:P.label,value:P.names.map(W=>c(W)).join("、")});const $=(e.works||[]).length;return $&&I.push({label:"著作",value:`${$} ${c("種")}`}),I},[e.works,O,c]),Y=I=>{var $;return($=z.find(P=>I.includes(P.label)))==null?void 0:$.names[0]},K=Y(["字"]),R=Y(["號","号"]),ie=[K?`字${K}`:"",R?`號${R}`:""].filter(Boolean).join(","),H=e.native_place,oe=e.dynasty?Qu[e.dynasty]:void 0,ee=(()=>{if(!oe||w==null||C==null||C<w)return null;const[I,$]=oe,P=Math.max(w,I),W=Math.min(C,$);if(W<=P)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":c(`${pt(w)}—${pt(C)},一生 ${C-w+1} 年`),children:t.jsx("i",{style:{left:`${(P-I)/Z*100}%`,width:`${(W-P)/Z*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:c(`${pt(I)} ${e.dynasty}`)}),t.jsx("span",{children:c(`一生 ${C-w+1} 年`)}),t.jsx("span",{children:pt($)})]})]})})(),Q=f.useMemo(()=>{if(!n||j.length===0||j.some(P=>!P.loaded))return null;const I=new Map;for(const P of j){const W=ri(P.l1);W&&I.set(W,(I.get(W)??0)+1)}const $=Vt.map(P=>({...P,n:I.get(P.key)??0})).filter(P=>P.n>0);return $.length?$:null},[j,n]),G=t.jsxs(Zt,{kind:Xu[e.subtype]??"人物",title:c(e.primary_name||e.title),subtitle:ie?c(ie):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(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ji((N=e.description)==null?void 0:N.text)?6:void 0,facts:M,foot:t.jsx(Xt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[F>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c(`更多別名(${F})`)}),t.jsx("dl",{children:A.map(I=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:c(I.label)}),t.jsx("dd",{children:I.names.map($=>c($)).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:c("著作分佈")})}),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)}}),c(I.label)," ",I.n]},I.key))})]})]}),ae=f.useMemo(()=>j.filter(I=>I.loaded&&(I.versionCount??0)>0).sort((I,$)=>($.versionCount??0)-(I.versionCount??0)).slice(0,3),[j]),ue=!!n&&j.length>=3&&_.some(I=>!I.loaded),re=d==="全部"&&(ue||ae.length>=2),te=e.external_ids||{},fe=[];te.cbdb_id!=null&&fe.push({label:"CBDB",id:String(te.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${te.cbdb_id}`,note:te.cbdb_match==="auto"?"自動匹配":void 0});const de=te.wikidata_id;de&&fe.push({label:"Wikidata",id:de,href:`https://www.wikidata.org/wiki/${de}`});const Te=te.viaf_id;Te&&fe.push({label:"VIAF",id:Te,href:`https://viaf.org/viaf/${Te}`});const be=y.map(I=>({key:I.cls,label:`${I.label} ${I.count}`})),ze=[...re&&!ue?[{id:"featured",label:"著作舉要",count:ae.length}]:[],...j.length?[{id:"works",label:"全部著作",count:j.length}]:[],...fe.length?[{id:"external",label:"站外資料",count:fe.length}]:[]],Ce=re?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":ue||void 0,children:[ue&&[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)),!ue&&ae.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:c(I.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx(We,{items:[I.section?c(I.section):"",I.measure?c(I.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:I.versionCount}),t.jsx("span",{children:c("種版本")}),I.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("有影印")})]})]},I.id))]})]}):null,Ee=j.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:[Ce,t.jsxs(Me,{id:"works",title:"著作",meta:t.jsx(We,{items:[c(`共 ${j.length} 種`),v.length!==j.length?c(`當前 ${v.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[be.length>1&&t.jsx(Sn,{items:be,value:d,onChange:I=>{u(I),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":m==="versions",onClick:()=>{m==="default"&&x(!0),b(I=>I==="default"?"versions":"default")},children:c(m==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("作品")}),t.jsx("th",{children:c("部類")}),t.jsx("th",{children:c("職任")}),t.jsx("th",{children:c("存世版本")}),t.jsx("th",{"aria-label":c("影印")})]})}),t.jsx("tbody",{children:_.map(I=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Le,{id:I.id,label:c(I.title),onNavigate:i,renderLink:r,dense:!0}),I.measure?t.jsx(We,{items:[c(I.measure)]}):!I.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.section||I.loaded?"":" bim-d-zt-blank"}`,children:I.section?c(I.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.role?"":" bim-d-zt-blank"}`,children:I.role?c(I.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.loaded?"":" bim-d-zt-blank"}`,children:I.loaded?I.versionCount?c(`${I.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:c("未著錄")}):""}),t.jsx("td",{className:I.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:I.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("有影印")})})]},I.id))})]}),_.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("該職任下的著作尚未著錄。")}),v.length>_.length&&t.jsx(Nt,{label:`展開其餘 ${v.length-_.length} 種著作`,onClick:()=>x(!0)})]})]}),D=fe.length>0?t.jsx(gt,{id:"external",title:"站外資料",items:fe.map(I=>t.jsxs("a",{href:I.href,target:"_blank",rel:"noopener noreferrer",children:[I.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:fe.map(I=>I.id),foot:te.cbdb_id!=null&&te.cbdb_match==="auto"?c("CBDB 為自動匹配,未經人工核對"):void 0}):null;return t.jsx(Jt,{railTop:s,back:l,nav:ze,railLinks:a,main:Ee,card:G,side:D})},Hi="(max-width: 719px)",ex=`${Hi}, (pointer: coarse)`,sl=`
790
+ `)}),s=[]};for(const a of n){const p=Ti(a);if(p){l(),r={kind:"heading",level:p.level,text:p.text};continue}s.push(a)}return l(),i}function To(e){const n=[];for(const i of e.split(`
791
+ `)){const r=Ti(i);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=i.trim();!s||Ei.test(s)||n.push({kind:"body",text:i})}return n}function Is(e){if(!e)return[];const n=$n(e);if(n==="unknown")return To(e);const i=[];for(const{heading:r,body:s}of ud(e)){r&&i.push(r);const l=$s(s);if(l.length!==0){if(Cs(s)){i.push(...To(s));continue}if(n==="record"){const a=l.join(" ");a&&i.push({kind:"body",text:a})}else for(const a of l){const p=zs(a);p.length&&i.push({kind:"body",text:p.join(" ")})}}}return i}const Ts=e=>e;function Es(e,n=Ts){if(e.indexOf("《")<0)return n(e);const i=[],r=/《([^《》\n]+)》/g;let s=0,l=0,a;for(;a=r.exec(e);)a.index>s&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s,a.index))},l++)),i.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(a[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=a.index+a[0].length;return s===0?n(e):(s<e.length&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),i)}function Ri(e,n={}){const i=n.renderText??Ts,r=n.properNames?l=>Es(l,i):i,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Ue(e,r,s)}function Eo(e,n,i){return e.indexOf("**")<0?n(e):e.split(/(\*\*[^*]+\*\*)/g).map((s,l)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?t.jsx("strong",{children:n(s.slice(2,-2))},`${i}-${l}`):t.jsx(f.Fragment,{children:n(s)},`${i}-${l}`))}const Bn=/^(#{1,6})\s+(.*)$/,xd=/^\s*<!--.*-->\s*$/;function Rs(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
792
+ `)?"":n)}function fd(e){return e<=1?2:e===2?3:4}function gd(){let e=1;return n=>{const i=fd(n),r=Math.min(i,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${i}`}}}function zn(e){return e?$n(Rs(e))!=="unknown":!1}function Ro({text:e,mode:n,inline:i,dropTitle:r}){const s=Rs(e),l=(d,u,g)=>!!r&&g<=1&&d<=2&&u.trim()===r.trim(),a=gd();if(n==="paragraph"&&$n(s)!=="unknown"){const d=Is(s);return t.jsx(t.Fragment,{children:d.map((u,g)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,g))return null;const{Tag:x,className:m}=a(u.level??1);return t.jsx(x,{className:m,children:i(u.text)},g)}return t.jsx("p",{children:Eo(u.text,i,g)},g)})})}const p=s.split(`
793
+ `);let c=0;return t.jsx(t.Fragment,{children:p.map((d,u)=>{const g=d.match(Bn);if(g){const m=c++;if(l(g[1].length,g[2],m))return null;const{Tag:b,className:S}=a(g[1].length);return t.jsx(b,{className:S,children:i(g[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Bn.test(p[u-1])&&!Bn.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(xd.test(d))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:m,className:b}=a(3);return t.jsx(m,{className:b,children:i(d.trim().slice(2,-2))},u)}return t.jsx("p",{children:Eo(d,i,u)},u)})})}function md(e){const{convert:n}=q();return f.useMemo(()=>e?n(e):"",[e,n])}function Ni({text:e,mode:n,tables:i=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:a}){const p=md(e),{convert:c}=q(),d=x=>Ri(x,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,g=a?c(a):void 0;return!i||p.indexOf(":::")<0?t.jsx(Ro,{text:p,mode:n,inline:d,dropTitle:g}):t.jsx(t.Fragment,{children:Ci(p).map((x,m)=>x.type==="table"?t.jsx(Ii,{table:x.table,opts:u},m):t.jsx(Ro,{text:x.text,mode:n,inline:d,dropTitle:m===0?g:void 0},m))})}function Ns(e,n){const[i,r]=f.useState(null),[s,l]=f.useState(!1),a=f.useRef(0);return f.useEffect(()=>{const p=++a.current;if(!e||!n){r(null),l(!1);return}let c;try{c=e(n)}catch{r(null),l(!1);return}if(!c||typeof c.then!="function"){r(c??null),l(!1);return}l(!0),c.then(d=>{p===a.current&&r(d??null)}).catch(()=>{p===a.current&&r(null)}).finally(()=>{p===a.current&&l(!1)})},[e,n]),{images:i,loading:s}}const No={A:"fine",B:"rough",C:"rough",D:"ocr"};function hd(e){return typeof e!="string"?null:e in Hn?e:e in No?No[e]:null}const bd={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},yd={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function it(e){return typeof e!="string"?"":bd[e]??yd[e]??e}const jd=["〇","一","二","三","四","五","六","七","八","九"],Lo=["","十","百","千"],vd=["","萬","億"];function Li(e){if(e===0)return"〇";if(e<0)return`負${Li(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(kd(s,r>0)+vd[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function kd(e,n){const i=[];let r=e;for(;r>0;)i.unshift(r%10),r=Math.floor(r/10);let s="";for(let l=0;l<i.length;l++){const a=i[l],p=i.length-1-l;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&p===1&&l===0&&!n?s+=Lo[p]:s+=jd[a]+Lo[p]}return s.replace(/〇$/,"")}let Vt=null,cn=null;const mn=new Set;function Sd(){return Vt?Promise.resolve():cn||(cn=import("opencc-js/t2cn").then(e=>{Vt=e.Converter({from:"tw",to:"cn"}),mn.forEach(n=>n())}).catch(()=>{Vt=e=>e,mn.forEach(e=>e())}),cn)}const wd=e=>e;function vt(){const[,e]=f.useState(0);return f.useEffect(()=>{if(Vt)return;const n=()=>e(i=>i+1);return mn.add(n),Sd(),()=>{mn.delete(n)}},[]),Vt??wd}function Et(e,n){return n(e).toLowerCase()}const _d=o("highlight-bg");function en(e,n,i){if(!n)return e;const r=Et(n,i);if(!r)return e;const s=Et(e,i);if(s.length!==e.length)return e;const l=[];let a=0,p=0;for(;a<e.length;){const c=s.indexOf(r,a);if(c===-1){l.push(e.slice(a));break}c>a&&l.push(e.slice(a,c)),l.push(t.jsx("mark",{style:{background:_d,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},p++)),a=c+r.length}return t.jsx(t.Fragment,{children:l})}function Bi(e,n,i,r){if(!n)return!0;const s=Et(n,r);return(i?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(a=>typeof a=="string"&&Et(a,r).includes(s))}function $d(e,n,i){return n?Et(e,i).includes(Et(n,i)):!0}const Ai={类:o("section-lei"),书:o("section-shu"),序:o("section-xu"),结语:o("section-jieyu"),注释:o("section-zhushi")},zd={考证:o("section-kaozhen")};function Cd(e){const n=e.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Ls(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((s,l)=>s+Ls(l),0))||0;return n+i}function Id(e,n){const i=[],r=a=>{var p;i.push(...a.files),(p=a.children)==null||p.forEach(r)};if(r(e),i.length===0)return;const s=i.map(a=>n[a]);if(s.every(a=>a===void 0))return;if(s.some(a=>a==="loading"))return"loading";let l=0;for(const a of s)typeof a=="number"&&(l+=a);return l}const Td={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Wi({enabled:e,expanded:n,onClick:i,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...Td,...r},children:s}):t.jsx("span",{style:r,children:s})}function Ed({type:e}){const n=it(e),i=Ai[n]||o("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:i,border:`1px solid ${i}40`,borderRadius:"2px",background:`${i}08`,flexShrink:0},children:n})}function Rd({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=q(),s=Pe(),l=vt(),a=S=>S?Ue(r(S),h=>i?en(h,i,l):h):"",[p,c]=f.useState(!1),d=!!e.summary,u=!!e.comment,g=!!e.additional_comment,x=!!(e.content&&e.content.length>60),m=d||u||g||x;f.useEffect(()=>{i&&c(!0)},[i]);const b=!p&&x?rs(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[t.jsxs("div",{onClick:()=>m&&c(!p),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:m?"pointer":"default",userSelect:"none",background:o("input-bg")},children:[t.jsxs(Wi,{enabled:m,expanded:p,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",a(e.book_title),"》"]}):a(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[Li(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:a(e.author_info||e.author)})]}),!p&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:a(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:a(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:o("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:s(e.work_id),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),p&&m&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${o("widget-border")}`,background:o("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"8px"},children:a(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:a(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(e.additional_comment)})]}),x&&!d&&!u&&!g&&t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)})]})]})}function Nd({section:e,highlightQuery:n=""}){const{convert:i}=q(),r=vt(),s=c=>c?Ue(i(c),d=>n?en(d,n,r):d):"",[l,a]=f.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(Wi,{enabled:p,expanded:l,onClick:()=>a(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(Ed,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:s(e.title)}),p&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&p&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${Ai[it(e.type)]||o("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:o("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(e.content)})})]})}const Ld=100;function Mi(e){return it(e.type)!=="page_header"?!1:(e.content||"").length>=Ld}function Bd({section:e,highlightQuery:n=""}){const{convert:i}=q(),r=vt();if(it(e.type)==="page_header"&&!Mi(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
794
+ `)),l=Ue(s,d=>n?en(d,n,r):d),a=it(e.type),p=Ai[a]||o("desc-fg"),c=a==="序"||a==="结语"||a==="注释";return t.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:o("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${p}40`:void 0,background:c?o("bg"):void 0,borderRadius:c?"0 4px 4px 0":void 0,position:"relative"},children:[c&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:a}),l]})}function Ad(e,n,i){const[r,s]=f.useState({});return f.useEffect(()=>{var d;if(!n||e.length===0)return;let l=!1;const a=e.filter(u=>{var g;return!((g=i==null?void 0:i.current)!=null&&g.has(u))}),p={};for(const u of e)(d=i==null?void 0:i.current)!=null&&d.has(u)&&(p[u]=i.current.get(u));if(Object.keys(p).length>0&&s(p),a.length===0)return;const c=async u=>{var g;try{if(n.getEntry){const h=await n.getEntry(u);if(h)return{title:h.title,author:h.author}}const x=await n.getItem(u);if(!x)return null;const m=x.title||u,b=x.authors,S=(g=b==null?void 0:b[0])==null?void 0:g.name;return{title:m,author:S}}catch{return null}};return Promise.all(a.map(async u=>{var x;const g=await c(u);return(x=i==null?void 0:i.current)==null||x.set(u,g),[u,g]})).then(u=>{l||s(g=>{const x={...g};for(const[m,b]of u)x[m]=b;return x})}),()=>{l=!0}},[e.join(","),n]),r}function Wd({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=q(),a=Pe(),p=vt(),c=j=>j?Ue(l(j),k=>s?en(k,s,p):k):"",[d,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const g=it(e.type),x=zd[g]||o("desc-fg"),m=!!e.content,b=e.work_ids||[],S=b.length>1,h=Ad(S?b:[],i,r),y=m&&!d&&e.content.length>80?rs(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${o("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>m&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:m?"pointer":"default",userSelect:"none"},children:[t.jsxs(Wi,{enabled:m,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg"),lineHeight:1.6},children:e.header_line?c(e.header_line):c(e.title)}),!d&&y&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:c(y)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:a(b[0]),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),S&&t.jsxs("span",{style:{fontSize:"11px",color:o("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:g})]})]}),S&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(j=>{const k=h[j],$=k?`${l(k.title)}${k.author?`(${l(k.author)})`:""}`:j.slice(0,8)+"…";return t.jsxs("a",{href:a(j),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(j))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:j,children:["→",$]},j)})}),d&&m&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:o("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${o("widget-border")}`,fontSize:"12px",color:o("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:c(e.comment)})]})]})}function Md({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=vt(),a=n.trim(),p=f.useMemo(()=>a?e.sections.filter(c=>Bi(c,a,!0,l)):e.sections,[e.sections,a,l]);return t.jsxs("div",{children:[t.jsx("div",{children:p.map((c,d)=>t.jsx(Wd,{section:c,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:a},d))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Fd(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Pd({sections:e,onNavigate:n,inline:i}){const r=Pe(),{convert:s}=q(),l=Fd();return t.jsx(t.Fragment,{children:e.map((a,p)=>{const c=it(a.type);if(c==="page_header"&&!Mi(a))return null;if(c==="类")return t.jsxs(f.Fragment,{children:[f.createElement(l("类"),null,i(s(a.title))),a.content&&t.jsx("p",{children:i(s(a.content))})]},p);if(c==="书"||c==="诗"||c==="考证"||c==="注释"){const d=a.book_title?`《${a.book_title}》${a.n_juan!=null?Li(a.n_juan)+"卷":""}`:a.title,u=i(s(d));return t.jsxs("section",{className:"bim-rd-entry",children:[f.createElement(l("条目"),{className:"bim-rd-entry-h"},a.work_id&&n?t.jsx("a",{href:r(a.work_id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),n(a.work_id))},title:"查看作品",children:u}):u),a.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(a.author_info))}),a.content&&a.content.split(/\n+/).map((g,x)=>t.jsx("p",{children:i(s(g))},x)),a.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(a.summary))]}),a.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(a.comment))]}),a.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(a.additional_comment))]})]},p)}return a.content?t.jsx("p",{children:i(s(a.content))},p):null})})}function Od(e){return e.some(n=>{const i=it(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&Mi(n)})}function Dd({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:a,workLabelCache:p,prefs:c}){var B;const{convert:d}=q(),u=vt(),[g,x]=f.useState("text"),m=s.trim(),b=(r==null?void 0:r.type)==="kaozhen",S=f.useCallback(A=>m?en(A,m,u):A,[m,u]),h=A=>Ri(A,{renderText:S,properNames:c.properNames}),y=f.useMemo(()=>m?e.sections.filter(A=>Bi(A,m,b,u)):e.sections,[e.sections,m,b,u]),j=(A,W)=>W.filter(V=>it(V.type)===A).length,k=j("书",e.sections),$=j("诗",e.sections),v=j("考证",e.sections);let _="";b?_=m?`${j("考证",y)} / ${v} ${d("條")}`:`${v} ${d("條")}`:$>0?_=m?`${j("诗",y)} / ${$} 首`:`${$} 首`:k>0&&(_=m?`${j("书",y)} / ${k} ${d("部書")}`:`${k} ${d("部書")}`);const w=r!=null&&r.text_quality?hd(r.text_quality.grade):null,z=[];i&&z.push(i),_&&z.push(_),b&&(r!=null&&r.target_source)&&z.push(t.jsxs(t.Fragment,{children:[d("考證對象")," ",d(r.target_source)]})),w&&z.push(t.jsx("span",{title:Al[w],children:(B=r==null?void 0:r.text_quality)!=null&&B.source_note?t.jsxs(t.Fragment,{children:["底本 ",d(r.text_quality.source_note),"(",d(Hn[w]),")"]}):t.jsxs(t.Fragment,{children:[d("文本質量")," ",d(Hn[w])]})})),e.source_url&&z.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:d("原文來源")}));const N=!b&&Od(e.sections),T=!!n&&(!N||c.readingMode==="paragraph"&&zn(n)),C=!b&&(N||!!n),P=b||!C?"entries":g;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:d(e.title)}),z.length>0&&t.jsx("p",{className:"bim-rd-meta",children:z.map((A,W)=>t.jsxs(f.Fragment,{children:[W>0&&t.jsx("span",{className:"bim-rd-dot"}),A]},W))}),C&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":"看法",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":P==="text",onClick:()=>x("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":P==="entries",onClick:()=>x("entries"),children:d("條目")})]})]}),P==="text"&&t.jsx("article",{className:"bim-rd-prose",children:T?t.jsx(Ni,{text:n,mode:c.readingMode,properNames:c.properNames,renderText:S,dropTitle:e.title}):t.jsx(Pd,{sections:e.sections,onNavigate:l,inline:h})}),P==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:b?t.jsx(Md,{juan:e,searchQuery:s,onNavigate:l,transport:a,workLabelCache:p}):t.jsxs(t.Fragment,{children:[y.map((A,W)=>{const V=it(A.type);return V==="书"||V==="诗"||V==="考证"?t.jsx(Rd,{section:A,onNavigate:l,highlightQuery:m},W):V==="类"?t.jsx(Nd,{section:A,highlightQuery:m},W):t.jsx(Bd,{section:A,highlightQuery:m},W)}),y.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function Bs(e){return e.juan_files&&e.juan_files.length>0?e.juan_files:e.files&&e.files.length>0?e.files.map(n=>n.filename):[]}function Hd(e){const n=Bs(e);return n.length>0?n[0]:null}function Gd(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:a,query:p,isKaozhen:c}=e,d=vt(),u=f.useRef(new Map),[g,x]=f.useState({}),[m,b]=f.useState({}),S=f.useCallback((y,j)=>{const k=j==null?void 0:j.title;k&&b($=>$[y]===k?$:{...$,[y]:k})},[]);f.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:a}),S(s,l))},[s,l,a,S]),f.useEffect(()=>{u.current.clear(),x({}),b({})},[n]);const h=f.useCallback((y,j)=>{let k=0;if(y.juan)for(const $ of y.juan.sections)Bi($,j,c,d)&&k++;return k===0&&y.rawText&&$d(y.rawText,j,d)&&(k=1),k},[c,d]);return f.useEffect(()=>{const y=p.trim();if(!y){x({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let j=!1;const k={},$=[];for(const N of r){const T=u.current.get(N);T?k[N]=h(T,y):(k[N]="loading",$.push(N))}x(k);const v=8;let _=0;const w=async()=>{var N;for(;_<$.length;){if(j)return;const T=_++,C=$[T];try{const[P,B]=await Promise.all([i.getCollatedJuan(n,C),((N=i.getCollatedJuanText)==null?void 0:N.call(i,n,C))??Promise.resolve(null)]),A={juan:P,rawText:B};if(u.current.set(C,A),S(C,P),j)return;x(W=>({...W,[C]:h(A,y)}))}catch{if(j)return;x(P=>({...P,[C]:0}))}}},z=Array.from({length:Math.min(v,$.length)},()=>w());return Promise.all(z),()=>{j=!0}},[p,n,i,r.join(","),h,d,S]),{matchStates:g,titles:m}}const Fi=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:a,style:p,title:c,subtitle:d,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m})=>{const[b,S]=f.useState(null),[h,y]=f.useState(!1),[j,k]=f.useState(null),[$,v]=f.useState(null),[_,w]=f.useState(null),[z,N]=f.useState(!1),[T,C]=f.useState(null),[P,B]=f.useState(""),A=f.useRef(new Map),W=f.useRef(0),V=s??$,K=f.useCallback(X=>{v(X),l==null||l(X)},[l]),E=e||b;f.useEffect(()=>{e&&(y(!1),k(null))},[e]),f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let X=!1;return y(!0),k(null),i.getCollatedEditionIndex(n).then(ie=>{X||(ie?S(ie):k("未找到整理本数据"))}).catch(ie=>{X||k(ie instanceof Error?ie.message:"加载失败")}).finally(()=>{X||y(!1)}),()=>{X=!0}},[e,n,i]),f.useEffect(()=>{if(E&&!V){const X=Hd(E);X&&K(X)}},[E,V,K]);const le=n||(E==null?void 0:E.work_id),G=f.useCallback(async X=>{var me;if(!le||!(i!=null&&i.getCollatedJuan))return;const ie=++W.current;N(!0),w(null),C(null);try{const[te,se]=await Promise.all([i.getCollatedJuan(le,X),((me=i.getCollatedJuanText)==null?void 0:me.call(i,le,X))??Promise.resolve(null)]);if(ie!==W.current)return;w(te),C(se)}catch{if(ie!==W.current)return;w(null),C(null)}finally{ie===W.current&&N(!1)}},[le,i]);f.useEffect(()=>{V&&G(V)},[V,G]);const ae=X=>{K(X)};if(h)return t.jsx("div",{className:a,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(j)return t.jsx("div",{className:a,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:j});if(!E)return null;const pe=E.type==="kaozhen",ee=Bs(E);return t.jsx(Vd,{className:a,style:p,index:E,allFiles:ee,isKaozhen:pe,effectiveWorkId:le,transport:i,activeFile:V,handleSelectFile:ae,juanData:_,juanRawText:T,juanLoading:z,searchQuery:P,setSearchQuery:B,onNavigate:r,workLabelCacheRef:A,reader:{title:c,subtitle:d,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m}})};function As(e,n,i,r){var d,u,g,x;const s=(u=(d=n.juan_metadata)==null?void 0:d[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:Cd(e)),p=((x=(g=n.files)==null?void 0:g.find(m=>m.filename===e))==null?void 0:x.title)??i[e];if(!p)return{position:l,label:l};const c=r(p);return{position:l,label:l===p||l===c?c:`${l} ${c}`}}function Ud(e,n,i,r,s){const l=c=>c==="loading"?"…":typeof c=="number"&&c>0?c:void 0,a=(c,d)=>({key:c,label:d??As(c,e,r,s).label,hint:l(i[c]),disabled:i[c]===0}),p=(c,d)=>{var g;if(c.files.length===1&&!((g=c.children)!=null&&g.length))return a(c.files[0],s(c.label));const u=Id(c,i);return{key:`group:${d}`,label:s(c.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:Ls(c),defaultExpanded:typeof u=="number"&&u>0,children:[...c.files.map(x=>a(x)),...(c.children??[]).map((x,m)=>p(x,`${d}.${m}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((c,d)=>p(c,`${d}`)):n.map(c=>a(c))}const Vd=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:a,activeFile:p,handleSelectFile:c,juanData:d,juanRawText:u,juanLoading:g,searchQuery:x,setSearchQuery:m,onNavigate:b,workLabelCacheRef:S,reader:h})=>{const{convert:y}=q(),[j,k]=$i(),{matchStates:$,titles:v}=Gd({workId:l,transport:a,files:r,activeFile:p,activeJuan:d,activeRawText:u,query:x,isKaozhen:s}),_=Ns(h.resolveImages,p),w=f.useMemo(()=>Ud(i,r,$,v,y),[i,r,$,v,y]),z=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:C=>m(C.target.value)}),N=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(C=>C.vol_label)?"冊":"卷",T=p?As(p,i,v,y).position:void 0;return t.jsxs(zi,{className:e,style:n,title:h.title??(i.title?y(i.title):void 0),subtitle:h.subtitle??y(s?"考證":"整理本"),toc:w,tocCaption:`目录 · ${r.length} ${y(N)}`,tocHeader:z,activeKey:p,onSelect:c,images:_.images,imagesLoading:_.loading,renderImageOverlay:h.renderImageOverlay,imagePanel:h.imagePanel,prefs:j,onPrefsChange:k,paragraphToggle:!s&&zn(u),allowVertical:h.allowVertical,children:[g?t.jsx(jt,{}):d?t.jsx(Dd,{juan:d,rawText:u,positionLabel:T,index:i,searchQuery:x,onNavigate:b,transport:a,workLabelCache:S,prefs:j},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,i.references&&i.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:y("參考文獻")}),t.jsx("ol",{children:i.references.map((C,P)=>t.jsxs("li",{children:[C.url?t.jsx("a",{className:"bim-rd-link",href:C.url,target:"_blank",rel:"noopener noreferrer",children:C.title}):t.jsx("span",{children:C.title}),C.author&&t.jsxs("span",{children:[",",C.author]}),C.note&&t.jsxs("span",{children:["。",C.note]})]},P))})]})]})},Yd={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},qd={label:"其他",color:o("desc-fg")},Kd={pending:{label:"待处理",color:o("warning")},in_progress:{label:"处理中",color:o("primary")},resolved:{label:"已处理",color:o("success")},wontfix:{label:"不采纳",color:o("desc-fg")},duplicate:{label:"重复",color:o("desc-fg")}},Jd={label:"待处理",color:o("warning")};function Zd(e){try{const n=new Date(e),i=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return e}}function Xd(e,n){if(!e)return!1;try{const i=new URL(e,n);if(i.protocol!=="http:"&&i.protocol!=="https:")return!1;const r=new URL(n);return i.hostname===r.hostname}catch{return!1}}const Pi=({items:e,loading:n})=>{const i=Pe();return n?t.jsx(jt,{}):e.length===0?t.jsx("div",{style:Qd,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Yd[r.type]||qd,l=Kd[r.status]||Jd,a=typeof window<"u"&&Xd(r.pageUrl,window.location.href);return t.jsxs("div",{style:ep,children:[t.jsxs("div",{style:tp,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Bo,background:s.color},children:s.label}),t.jsx("span",{style:{...Bo,background:l.color},children:l.label})]}),t.jsx("span",{style:np,children:Zd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:ip,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:An,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(a?t.jsx("a",{href:r.pageUrl,style:An,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:An,children:r.pageUrl}))]}),t.jsx("div",{style:op,children:r.content}),r.reply&&t.jsxs("div",{style:rp,children:[t.jsx("div",{style:sp,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Qd={textAlign:"center",padding:"40px 0",color:o("desc-fg"),fontSize:"14px"},ep={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"16px"},tp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Bo={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},np={fontSize:"12px",color:o("desc-fg")},ip={fontSize:"12px",marginBottom:"6px"},An={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},op={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},rp={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},sp={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},ti=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const a=ue(),[p,c]=f.useState(null),[d,u]=f.useState([]),[g,x]=f.useState("recommend"),[m,b]=f.useState([]),[S,h]=f.useState(!1),y=r??g,j=W=>{x(W),s==null||s(W)},[k,$]=f.useState(!0),[v,_]=f.useState(null),[w,z]=f.useState(null),[N,T]=f.useState(null);f.useEffect(()=>{let W=!1;if(e.getCounts)return e.getCounts().then(V=>{W||c({works:V.works,books:V.books,collections:V.collections})}).catch(()=>{}),()=>{W=!0}},[e]),f.useEffect(()=>{let W=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const K=await e.getRecommended();if(K!=null&&K.groups)return K.groups.flatMap(E=>E.items.map(le=>({...le,group:E.name})))}catch{}return[]})().then(async K=>{if(W)return;const E=K.filter(G=>G.id);if(E.length===0){$(!1);return}const le=await Promise.all(E.map(async G=>{if(G.type)return{id:G.id,title:G.title,type:G.type,author:G.author,dynasty:G.dynasty,role:G.role,edition:G.edition,has_text:G.has_text,has_image:G.has_image,has_collated:G.has_collated,subtype:G.subtype,primary_name:G.primary_name,group:G.group,fallbackDescription:G.description};try{let ae=null;if(e.getEntry)ae=await e.getEntry(G.id);else{const pe=await e.getItem(G.id);pe&&(ae={id:G.id,title:pe.title||G.id,type:pe.type||"work"})}if(ae)return{...ae,group:G.group,fallbackDescription:G.description}}catch{}return{id:G.id,title:G.title,type:we.extractType(G.id),group:G.group,fallbackDescription:G.description}}));W||(u(le.filter(G=>G!==null)),$(!1))}),()=>{W=!0}},[e,i]);const C=f.useRef(!1),P=f.useRef(!1),B=f.useRef(!1);f.useEffect(()=>{if(y!=="catalog"||C.current)return;const W=e.getCatalogProgress??e.getResourceProgress;if(!W)return;C.current=!0;let V=!1;return W.call(e).then(K=>{V||_(K)}).catch(()=>{C.current=!1}),()=>{V=!0}},[e,y]),f.useEffect(()=>{if(y!=="collection"||P.current||!e.getCollectionProgress)return;P.current=!0;let W=!1;return e.getCollectionProgress().then(V=>{W||z(V)}).catch(()=>{P.current=!1}),()=>{W=!0}},[e,y]),f.useEffect(()=>{if(y!=="site"||B.current||!e.getSiteProgress)return;B.current=!0;let W=!1;return e.getSiteProgress().then(V=>{W||T(V)}).catch(()=>{B.current=!1}),()=>{W=!0}},[e,y]),f.useEffect(()=>{if(!l||y!=="feedback")return;let W=!1;return h(!0),fetch(l).then(V=>V.json()).then(V=>{!W&&V.success&&b(V.items||[])}).catch(()=>{}).finally(()=>{W||h(!1)}),()=>{W=!0}},[l,y]);const A=W=>t.jsx(jn,{type:W,size:12});return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:o("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${o("widget-border")}`,marginBottom:"16px"},children:[t.jsx(Ft,{label:a.home.recommendTab,active:y==="recommend",onClick:()=>j("recommend")}),t.jsx(Ft,{label:a.home.catalogTab,active:y==="catalog",onClick:()=>j("catalog")}),t.jsx(Ft,{label:a.home.collectionTab,active:y==="collection",onClick:()=>j("collection")}),t.jsx(Ft,{label:a.home.siteTab,active:y==="site",onClick:()=>j("site")}),l&&t.jsx(Ft,{label:a.home.feedbackTab,active:y==="feedback",onClick:()=>j("feedback")})]}),y==="recommend"&&t.jsx(lp,{recommended:d,loading:k,onNavigate:n,getIcon:A,t:a}),y==="catalog"&&t.jsx(Ao,{progress:v,t:a,onNavigate:n}),y==="collection"&&t.jsx(Ao,{progress:w,t:a,onNavigate:n}),y==="site"&&t.jsx(cp,{progress:N,t:a,totalWorks:(p==null?void 0:p.works)??0}),y==="feedback"&&l&&t.jsx(Pi,{items:m,loading:S})]})})},Ft=({label:e,active:n,onClick:i})=>t.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:o(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${o("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),lp=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=Pe();if(n)return t.jsx(jt,{});if(e.length===0)return null;const a=new Map;for(const p of e){const c=p.group||s.home.recommendedBrowse;a.has(c)||a.set(c,[]),a.get(c).push(p)}return t.jsx(t.Fragment,{children:Array.from(a.entries()).map(([p,c])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:p}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return t.jsxs("a",{href:l(d.id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),i==null||i(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,cursor:"pointer",background:o("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},Ao=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(jt,{});const r=[...e.resources].sort((p,c)=>p.priority-c.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},a={in_progress:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(p=>{const c=r.filter(d=>d.status===p);return c.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:a[p]}}),l[p]," (",c.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(d=>t.jsx(ap,{item:d,t:n,statusColor:a[p],onNavigate:i},d.id))})]},p)})})},ap=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=Pe(),l=e.total>0?Math.round(e.imported/e.total*100):0,a=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=e.edition?`${e.name}·${e.edition}`:e.name,c=e.collection_id||e.work_id;return c&&r?t.jsx("a",{href:s(c),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:p}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:o("widget-border"),color:o("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:a})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Kt(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},cp=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(jt,{});const r=[...e.resources].sort((c,d)=>c.priority-d.priority),s=r.filter(c=>c.imported>0),l=r.filter(c=>c.imported===0),a=s.reduce((c,d)=>Math.max(c,d.imported),0),p=i>0?Math.round(a/i*100):0;return t.jsxs("div",{children:[i>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${o("primary")} 6%, transparent)`,fontSize:"13px",color:o("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:a.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>t.jsx(Wo,{item:c,t:n,totalWorks:i},c.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(c=>t.jsx(Wo,{item:c,t:n,totalWorks:i},c.id))})]})]})},Wo=({item:e,t:n,totalWorks:i})=>{const r=i>0?Math.round(e.imported/i*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:t.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&i>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:o("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},Mo="(max-width: 768px)";function dp(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Mo).matches);return f.useEffect(()=>{const i=window.matchMedia(Mo),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),e}const pp=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var V;const l=ue(),{convert:a}=q(),p=dp(),[c,d]=f.useState(null),[u,g]=f.useState(null),[x,m]=f.useState(!1),[b,S]=f.useState("detail"),[h,y]=f.useState([]),[j,k]=f.useState(!1),[$,v]=f.useState(null),[_,w]=f.useState(!1),z=f.useCallback(async K=>{if(!e.getCollatedEditionIndex){v(null);return}w(!0);try{const E=await e.getCollatedEditionIndex(K);v(E)}catch{v(null)}finally{w(!1)}},[e]),N=f.useCallback(async K=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){y([]);return}k(!0);try{if(e.getCollectionCatalogs){const E=await e.getCollectionCatalogs(K);y(E||[])}else if(e.getCollectionCatalog){const E=await e.getCollectionCatalog(K);y(E?[{resource_id:"",data:E}]:[])}}catch{y([])}finally{k(!1)}},[e]),T=f.useCallback(async K=>{if(i){i(K);return}d(K),g(null),y([]),v(null),S("detail"),m(!0);try{const E=await e.getItem(K.id);E&&(g(E),E.type==="collection"?N(K.id):E.type==="work"&&E.has_collated&&z(K.id))}catch(E){console.error("加载详情失败:",E)}finally{m(!1)}},[e,i,N,z]),C=f.useCallback(async K=>{g(null),y([]),v(null),S("detail"),m(!0);try{const E=await e.getItem(K);E&&(g(E),d({id:K,title:E.title||K,type:E.type||"book"}),E.type==="collection"?N(K):E.type==="work"&&E.has_collated&&z(K))}catch(E){console.error("导航失败:",E)}finally{m(!1)}},[e,N,z]),P=(u==null?void 0:u.type)==="collection"&&(h.length>0||j)||(u==null?void 0:u.type)==="work"&&($||_),B=p&&(x||u),A=f.useCallback(()=>{d(null),g(null),y([]),v(null),S("detail")},[]),W=t.jsx(t.Fragment,{children:x?t.jsx(jt,{}):u?t.jsxs(t.Fragment,{children:[(P||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${o("widget-border")}`,padding:p?"0 12px":"0 48px",background:o("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[P&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>S("detail"),style:dn(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&j&&h.length===0&&t.jsxs("button",{onClick:()=>{},style:dn(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&h.map(K=>t.jsx("button",{onClick:()=>S(`catalog:${K.resource_id}`),style:dn(b===`catalog:${K.resource_id}`),children:K.short_name?`${a(K.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},K.resource_id)),u.type==="work"&&($||_)&&t.jsxs("button",{onClick:()=>S("collated"),style:dn(b==="collated"),children:[l.detailTab.collatedEdition,_&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?t.jsx(fi,{data:u,transport:e,onNavigate:C}):b.startsWith("catalog:")?t.jsx(gi,{data:(V=h.find(K=>`catalog:${K.resource_id}`===b))==null?void 0:V.data,onNavigate:C}):b==="collated"?t.jsx(Fi,{index:$||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(ti,{transport:e,onNavigate:C,recommendedIds:r})});return p?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:B?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${o("widget-border")}`,background:o("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:A,style:{padding:"4px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:W})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Un,{transport:e,onEntryClick:T,hideModeIndicator:n}),!u&&t.jsx(ti,{transport:e,onNavigate:C,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${o("widget-border")}`,display:"flex",flexDirection:"column",background:o("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(Un,{transport:e,onEntryClick:T,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:W})]})};function dn(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function ut(e){return e.replace(/\.md$/,"")}function Fo(e){let n="";if(e.source_url)try{const r=new URL(e.source_url).pathname.split("/").filter(Boolean).pop()??"";n=decodeURIComponent(r).replace(/_/g," ")}catch{}return[e.source_name,n||e.version_label].filter(Boolean).join(" · ")||e.key}const Po={padding:24,color:o("desc-fg")},ni=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:a,onVersionChange:p,title:c,subtitle:d,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m,className:b,style:S})=>{const[h,y]=f.useState(e??null),[j,k]=f.useState(!1),[$,v]=f.useState(null),_=r!==void 0?r:$,w=f.useCallback(ee=>{s?s(ee):v(ee)},[s]),[z,N]=f.useState(null),[T,C]=f.useState(!1);f.useEffect(()=>{e&&y(e)},[e]),f.useEffect(()=>{if(e)return;y(null),k(!1);const ee=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!ee){k(!0);return}let X=!1;return Promise.resolve().then(ee).then(ie=>{X||(ie?y(ie):k(!0))}).catch(()=>{X||k(!0)}),()=>{X=!0}},[n,i,e,l]),f.useEffect(()=>{if(!h||h.chapters.length===0)return;const ee=ut(h.chapters[0].file);if(!_){w(ee);return}const X=ut(_);h.chapters.some(me=>ut(me.file)===X)||w(ee)},[h,_,w]);const P=f.useMemo(()=>{if(!h||!_)return null;const ee=ut(_);return h.chapters.find(X=>ut(X.file)===ee)??null},[h,_]);f.useEffect(()=>{if(!n||!P)return;const ee=l!==void 0?i.getWorkFullTextChapter?ie=>i.getWorkFullTextChapter(n,l,ie):null:i.getBookFullTextChapter?ie=>i.getBookFullTextChapter(n,ie):null;if(!ee)return;let X=!1;return C(!0),N(null),Promise.resolve(P.file).then(ee).then(ie=>{X||N(ie)}).catch(()=>{X||N(null)}).finally(()=>{X||C(!1)}),()=>{X=!0}},[n,P,i,l]);const B=Ns(u,P?ut(P.file):null),[A,W]=$i(),{convert:V}=q(),K=!!(a&&a.length>1&&p),E=f.useMemo(()=>K?bs(a).map((ee,X)=>({...ee,label:Fo(a[X])})):void 0,[K,a]),le=K?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:ee=>p(ee.target.value),children:a.map(ee=>t.jsx("option",{value:ee.key,children:Fo(ee)},ee.key))})]}):null;if(!h)return t.jsxs("div",{style:Po,children:[le&&t.jsx("div",{style:{marginBottom:12},children:le}),j?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:Po,children:[le&&t.jsx("div",{style:{marginBottom:12},children:le}),"全文目录为空"]});const G=h.chapters.map(ee=>({key:ut(ee.file),label:V(ee.title)})),ae=ks(h)||qn(h),pe=z?z.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(zi,{title:c??V(h.version_label),subtitle:d??"全文",toc:G,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:_?ut(_):null,onSelect:w,images:B.images,imagesLoading:B.loading,renderImageOverlay:g,imagePanel:x,prefs:A,onPrefsChange:W,versions:E,currentVersionKey:E?l??null:void 0,onVersionChange:E?p:void 0,versionSource:!1,paragraphToggle:zn(pe),allowVertical:m,className:b,style:S,children:[P&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:V(P.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:h.source.url,target:"_blank",rel:"noreferrer",children:V(h.source.name)}),h.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),h.source.license]})]})]}),T&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!T&&pe!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Ni,{text:pe,mode:A.readingMode,tables:ae,gujiMarkdown:qn(h),properNames:A.properNames})}),!T&&!z&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},up=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=ue(),{convert:l}=q(),[a,p]=f.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[c,d]=f.useState(null);return t.jsxs("div",{className:i,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:l(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[s.catalog.totalVolumes," ",t.jsx("strong",{children:e.total_volumes})," ",s.unit.juan]}),e.stats.zhulu!=null&&t.jsxs("span",{children:["著錄 ",t.jsx("strong",{children:e.stats.zhulu})," ",s.unit.bu]}),e.stats.cunmu!=null&&t.jsxs("span",{children:["存目 ",t.jsx("strong",{children:e.stats.cunmu})," ",s.unit.bu]}),e.stats.categories!=null&&t.jsxs("span",{children:[e.stats.categories," 類"]})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(g=>t.jsx(xp,{division:g,expanded:a===g.name,onToggle:()=>p(a===g.name?null:g.name),expandedCat:c,onCatToggle:x=>d(c===x?null:x),onNavigate:n},g.name))})]})},xp=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:a}=q(),p=e.categories.reduce((c,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return c+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${o("primary")} 6%, transparent)`:o("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:o("fg"),textAlign:"left"},children:[t.jsx("span",{children:a(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg")},children:[e.categories.length," 類 · ",p," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(c=>{const d=`${e.name}/${c.name}`;return t.jsx(fp,{category:c,expanded:r===d,onToggle:()=>s(d),onNavigate:l},c.name)})})]})},fp=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var c,d,u,g;const{convert:s}=q(),l=((c=e.books)==null?void 0:c.zhulu)||[],a=((d=e.books)==null?void 0:d.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((g=e.stats)==null?void 0:g.cunmu)||a.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?o("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:o("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||a.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Oo,{label:"著錄",books:l,onNavigate:r}),a.length>0&&t.jsx(Oo,{label:"存目",books:a,onNavigate:r})]})]})},Oo=({label:e,books:n,onNavigate:i})=>{const{convert:r}=q(),s=Pe(),[l,a]=f.useState(n.length<=20),p=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((c,d)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:o("fg")},children:c.work_id&&i?t.jsx("a",{href:s(c.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},children:r(c.title)}):r(c.title)}),c.volumes&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(c.volumes)}),c.author&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(c.author).slice(0,20)})]},d))}),!l&&t.jsxs("button",{onClick:()=>a(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},qe=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=ue();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:o("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&t.jsx("button",{onClick:i,style:mp,children:"AI"}),n&&t.jsx("button",{onClick:n,style:gp,children:l.action.save})]})]}),s]})},gp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},mp={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Ge=({label:e,value:n,onChange:i,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:l=>i(l.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),bt=({value:e,onChange:n,placeholder:i})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},hn=({children:e,color:n,style:i})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||o("primary-soft"),color:o(n?"on-color-fg":"fg"),...i},children:e});function hp(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const un=({value:e,onChange:n,label:i})=>{const[r,s]=f.useState(!1),l=f.useRef(null),a=hp(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&a?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Do,children:i}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${o("input-border")}`,borderRadius:"2px",background:o("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:o("fg")},children:a.name}),t.jsx(hn,{children:a.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Do,children:i}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Do={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function bp(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function yp(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ws=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=ue(),[s,l]=f.useState(null),a=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},p=g=>{n(e.filter((x,m)=>m!==g)),s===g&&l(null)},c=(g,x,m)=>{const b=[...e];b[g]={...b[g],[x]:m},n(b)},d=(g,x)=>{const m=[...e];m[g]={...m[g],type:x,id:"",name:""},n(m),x==="bookID"&&i&&i(b=>{const S=[...e];S[g]={...S[g],id:b.id,name:b.title,type:"bookID"},n(S)})},u=g=>{i&&i(x=>{const m=[...e];m[g]={...m[g],id:x.id,name:x.title,type:"bookID"},n(m)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((g,x)=>t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===x?null:x),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===x?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:o("fg")},children:g.name||`${r.editor.sourcePlaceholder} ${x+1}`}),g.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:bp(g.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:yp(g.type)}),t.jsx("button",{onClick:m=>{m.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===x&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!g.type&&t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>d(x,"bookID"),style:{...Ho,borderColor:o("source-bookid"),color:o("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>d(x,"url"),style:{...Ho,borderColor:o("source-url"),color:o("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),g.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:ot,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Go,children:r.action.changeType})]}),g.id&&g.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:o("bg"),border:`1px solid ${o("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:o("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:g.name}),t.jsx("code",{style:{fontSize:"11px",background:o("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:g.id})]}),t.jsx("button",{onClick:()=>u(x),style:{background:"transparent",border:`1px solid ${o("widget-border")}`,color:o("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(x),style:{width:"100%",padding:"14px",border:`2px dashed ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),g.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:ot,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Go,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:g.name,onChange:m=>c(x,"name",m.target.value),placeholder:r.editor.sourceNamePlaceholder,style:St})]}),t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:g.id,onChange:m=>c(x,"id",m.target.value),placeholder:"https://...",style:St})]})]}),g.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${o("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...ot,opacity:.7},children:r.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:g.details,onChange:m=>c(x,"details",m.target.value),placeholder:r.editor.detailsPlaceholder,style:St})]}),t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:g.position,onChange:m=>c(x,"position",m.target.value),placeholder:"如: 卷三, p.52",style:St})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:g.version,onChange:m=>c(x,"version",m.target.value),placeholder:"如: v1.0, 2024-01",style:St})]}),t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:g.processor_version,onChange:m=>c(x,"processor_version",m.target.value),placeholder:"如: v0.1",style:St})]})]})]})]})})]},x)),t.jsxs("button",{onClick:a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},ot={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},St={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Ho={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:o("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},Go={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Ms(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(i=>({id:i.id||"",name:i.name||"",type:i.type||"",details:i.details||"",position:i.position||"",version:i.version||"",processor_version:i.processor_version||""}))}catch{}return[]}function Fs(e){return!e||e.length===0?"":JSON.stringify(e)}const Ps=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:a,childWorks:p,childCollections:c,containedBooks:d,siblingBooks:u,onLinkEntity:g,onUnlinkEntity:x,onViewEntity:m,onCreateAndLink:b,onSaveRelations:S})=>{const h=ue();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:h.section.relations})]}),S&&t.jsx("button",{onClick:S,style:jp,children:h.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.belongsToWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>g("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Pt,{direction:"up",title:h.relation.containedInCollection,entity:a,onView:m,onUnlink:()=>x("collectionId"),onLink:()=>g("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),l&&u&&u.length>0&&t.jsx(wt,{direction:"horizontal",title:`${h.relation.siblingVersions} (${u.length})`,entities:u,onView:m,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.parentWork,entity:r,onView:m,onUnlink:()=>x("parentWorkId"),onLink:()=>g("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),p&&p.length>0&&t.jsx(wt,{direction:"down",title:`${h.relation.childWorks} (${p.length})`,entities:p,onView:m,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),c&&c.length>0&&t.jsx(wt,{direction:"down",title:`${h.relation.collectionImpl} (${c.length})`,entities:c,onView:m,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(wt,{direction:"down",title:`${h.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>b("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.correspondingWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>g("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Pt,{direction:"up",title:h.relation.parentCollection,entity:s,onView:m,onUnlink:()=>x("parentCollectionId"),onLink:()=>g("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(wt,{direction:"down",title:`${h.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:m,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(wt,{direction:"down",title:`${h.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},Pt=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:a,linkLabel:p,createLabel:c,notLinkedLabel:d,viewLabel:u,unlinkLabel:g})=>{const x=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:o("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Os(i.type)}),t.jsx("span",{style:{fontWeight:500},children:i.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(Uo,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(Uo,{onClick:s,title:g,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(ii,{onClick:l,children:p}),t.jsx(ii,{onClick:a,primary:!0,children:c})]})]})},wt=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:a,expandMoreLabel:p})=>{const[c,d]=f.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),g=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=c?i:i.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:g}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[x.map(m=>t.jsxs("div",{onClick:()=>r(m),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:o("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:Os(m.type)}),t.jsx("span",{children:m.title})]},m.id)),i.length>5&&!c&&t.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:o("link-fg"),cursor:"pointer"},children:[p," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:a}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(ii,{onClick:s,primary:!0,children:["+ ",l]})})]})},Uo=({onClick:e,title:n,danger:i,children:r})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?o("danger"):"inherit",opacity:.7},children:r}),ii=({onClick:e,primary:n,children:i})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${o("widget-border")}`,borderRadius:"4px",background:n?o("primary"):"transparent",color:n?o("primary-fg"):"inherit",cursor:"pointer"},children:i});function Os(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const jp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Ds=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:a,onSearch:p,isLoading:c,excludeId:d})=>{const[u,g]=f.useState(""),x=d?a.filter(h=>h.id!==d):a;f.useEffect(()=>{e&&(g(""),p(""))},[e]);const m=h=>{g(h),p(h)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",S=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:vp,children:t.jsxs("div",{style:kp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),t.jsx("button",{onClick:s,style:Sp,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:h=>m(h.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:wp})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:Wn,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(h=>t.jsxs("div",{onClick:()=>r(h),style:_p,children:[t.jsx("span",{style:{fontSize:"16px"},children:S}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):u?t.jsxs("div",{style:Wn,children:["未找到匹配的",b]}):t.jsxs("div",{style:Wn,children:["输入关键词搜索",b]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:l,style:$p,children:["创建新",b,"并关联"]})]})]})})},vp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},kp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},Sp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},wp={width:"100%",padding:"10px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},_p={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:o("primary-soft")},Wn={padding:"20px",textAlign:"center",color:o("desc-fg")},$p={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Vo={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},zp={work:"📜",book:"📖",collection:"📚",entity:"👤"},Hs=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[a,p]=f.useState(""),c=f.useRef(null);f.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,m;(x=c.current)==null||x.focus(),(m=c.current)==null||m.select()},100))},[e,r==null?void 0:r.title]);const d=x=>{x.key==="Enter"&&a.trim()?u():x.key==="Escape"&&l()},u=()=>{a.trim()&&s(a.trim(),{...r,title:a.trim()})};if(!e)return null;const g=()=>{switch(i){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Vo[n]}`}};return t.jsx("div",{style:Cp,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:Ip,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:zp[n]}),t.jsx("span",{children:g()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:o("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:o("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:c,type:"text",value:a,onChange:x=>p(x.target.value),onKeyDown:d,placeholder:`请输入${Vo[n]}名称...`,style:Tp})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),background:o("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&t.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:l,style:Ep,children:"取消"}),t.jsx("button",{onClick:u,disabled:!a.trim(),style:{...Rp,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Cp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ip={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:o("shadow-dialog")},Tp={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box"},Ep={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Rp={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function Np(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Gs(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Lp(e){switch(e){case"work":return o("editor-type-work");case"collection":return o("editor-type-collection");case"book":return o("editor-type-book");default:return o("desc-fg")}}const Us=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:a,onSelect:p,onCancel:c,onCreate:d,onSearch:u})=>{const[g,x]=f.useState(""),[m,b]=f.useState([]),[S,h]=f.useState(!1),[y,j]=f.useState("recent");f.useEffect(()=>{e&&(x(""),b([]),j(r.length>0?"recent":"search"))},[e,r.length]),f.useEffect(()=>{if(!g.trim()){b([]);return}const z=setTimeout(async()=>{h(!0);try{b(await u(g,i))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(z)},[g,i,u]);const k=f.useCallback(z=>{x(z.target.value),z.target.value.trim()&&j("search")},[]),$=f.useCallback(z=>s?z.filter(N=>N.id!==s):z,[s]);if(!e)return null;const v=n||(i==="all"?"选择实体":`选择${Gs(i)}`),_=$(r),w=$(m);return t.jsx("div",{style:Ap,children:t.jsxs("div",{style:Wp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:v}),t.jsx("button",{onClick:c,style:Mp,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:g,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Fp}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),S&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),_.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs(Yo,{active:y==="recent",onClick:()=>j("recent"),children:["最近使用 (",_.length,")"]}),t.jsxs(Yo,{active:y==="search",onClick:()=>j("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:y==="recent"&&_.length>0?t.jsx(qo,{entities:_,onSelect:p}):g.trim()?S?t.jsx(Mn,{message:"搜索中..."}):w.length>0?t.jsx(qo,{entities:w,onSelect:p}):t.jsx(Mn,{message:"未找到匹配的结果"}):t.jsx(Mn,{message:"输入关键词开始搜索"})}),l&&d&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:d,style:Pp,children:a||"创建新实体"})]})]})})},Yo=({active:e,onClick:n,children:i})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:i}),qo=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(Bp,{entity:i,onClick:()=>n(i)},i.id))}),Bp=({entity:e,onClick:n})=>{const[i,r]=f.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Np(e.type)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:e.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[t.jsx("code",{style:{fontSize:"10px",background:o("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&t.jsx("span",{children:e.author}),e.dynasty&&t.jsx("span",{children:e.dynasty})]})]}),t.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Lp(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Gs(e.type)})]})},Mn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),Ap={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Wp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},Mp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Fp={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},Pp={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Op={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},Dp={work:"📜",collection:"📚",book:"📖",entity:"👤"},Vs=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:a,onAskAI:p,renderSectionActions:c,onDownloadResource:d,downloadStatuses:u,relations:g,onRelationsChange:x})=>{var Z;const m=ue(),[b,S]=f.useState(!1),[h,y]=f.useState("work"),[j,k]=f.useState(""),[$,v]=f.useState(""),[_,w]=f.useState([]),[z,N]=f.useState(!1),[T,C]=f.useState(!1),[P,B]=f.useState("work"),[A,W]=f.useState(""),[V,K]=f.useState(),[E,le]=f.useState(!1),[G,ae]=f.useState(null),[pe,ee]=f.useState([]);f.useRef(null);const X=e.type,ie=X==="work",me=X==="collection",te=X==="book",se=f.useCallback((F,I)=>{n({...e,[F]:I})},[e,n]),fe=f.useCallback((F,I)=>{k(F),y(I),v(m.editor.selectToLink+m.indexType[I]),w([]),S(!0)},[m]),be=f.useCallback(F=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,F)},[r,e.id]),ze=f.useCallback(F=>{s==null||s(F.id,F.type)},[s]),ve=f.useCallback((F,I,D)=>{const M={...D,author:(D==null?void 0:D.author)||e.author,dynasty:D==null?void 0:D.dynasty};B(I),W(F),K(M),C(!0)},[e.author]),ke=f.useCallback((F,I)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,A,{type:P,title:F,inheritData:I}),C(!1)},[r,e.id,A,P]),Ne=f.useCallback(F=>{if(!F.trim()){w([]);return}N(!0),r!=null&&r.searchEntities&&r.searchEntities(F,h).then(I=>{w(I),N(!1)}).catch(()=>{w([]),N(!1)})},[r,h]),Ee=f.useCallback(F=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,j,F.id),S(!1)},[r,e.id,j]),O=f.useCallback(()=>{i()},[i]),ce=f.useCallback(F=>{ae(()=>F),le(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(ee).catch(()=>{})},[r]),oe=f.useCallback((F,I)=>r!=null&&r.searchEntities?r.searchEntities(F,I==="all"?void 0:I):Promise.resolve([]),[r]),he=f.useCallback(F=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(F),ee(I=>[F,...I.filter(D=>D.id!==F.id)].slice(0,10)),G==null||G(F),le(!1),ae(null)},[r,G]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${o("widget-border")}`,paddingBottom:"16px"},children:t.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Dp[X]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(hn,{children:e.id}),t.jsx(hn,{color:Op[X],children:m.indexType[X]})]})}),t.jsx(qe,{title:m.section.basicInfo,onSave:i,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(un,{label:ie?m.editor.workTitle:me?m.editor.collectionTitle:m.editor.bookTitle,value:e.title,onChange:F=>se("title",F)}),te&&t.jsx(un,{label:m.editor.belongsToWork,value:e.workName||"",onChange:F=>se("workName",F)}),t.jsx(Ge,{label:m.editor.authorLabel,value:e.author||"",onChange:F=>se("author",F)}),t.jsx(Ge,{label:m.editor.publicationYearLabel,value:e.publicationYear||"",onChange:F=>se("publicationYear",F)}),(te||me)&&t.jsx(un,{label:m.editor.containedIn,value:e.collection||"",onChange:F=>se("collection",F)}),(te||me)&&t.jsx(Ge,{label:m.editor.holderLabel,value:e.holder||"",onChange:F=>se("holder",F)}),(te||me)&&t.jsx(Ge,{label:te?m.editor.pageLabel:m.editor.volumeLabel,value:e.pages||"",onChange:F=>se("pages",F)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(Ge,{label:m.editor.firstImageLabel,value:e.firstImage||"",onChange:F=>se("firstImage",F)})})]})}),t.jsx(qe,{title:m.section.description,onSave:i,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(bt,{value:e.description||"",onChange:F=>se("description",F),placeholder:m.editor.descriptionPlaceholder})}),(((Z=e.additional_works)==null?void 0:Z.length)||0)>0&&t.jsx(qe,{title:m.section.additionalWorks,onSave:i,children:t.jsx(Hp,{items:e.additional_works||[],onChange:F=>se("additional_works",F)})}),t.jsx(qe,{title:m.section.indexedBy,onSave:i,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Gp,{items:e.indexed_by||[],onChange:F=>se("indexed_by",F)})}),t.jsx(qe,{title:m.section.emendatedBy,onSave:i,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Up,{items:e.emendated_by||[],onChange:F=>se("emendated_by",F)})}),t.jsx(qe,{title:m.section.textResources,onSave:i,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(Gn,{items:e.resources||[],onChange:F=>se("resources",F),onDownload:d,downloadStatuses:u,filterType:"text"})}),t.jsx(qe,{title:m.section.imageResources,onSave:i,children:t.jsx(Gn,{items:e.resources||[],onChange:F=>se("resources",F),onDownload:d,downloadStatuses:u,filterType:"image"})}),t.jsx(qe,{title:m.section.sources,onSave:i,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(Ws,{items:Ms(e.sources||""),onChange:F=>se("sources",Fs(F)),onOpenEntityPicker:ce})}),(te||me)&&t.jsx(qe,{title:m.section.provenance,onSave:i,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(bt,{value:e.provenance||"",onChange:F=>se("provenance",F),placeholder:m.editor.provenancePlaceholder})}),te&&t.jsx(qe,{title:m.section.otherEditions,onSave:i,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(bt,{value:e.otherEditions||"",onChange:F=>se("otherEditions",F),placeholder:m.editor.otherEditionsPlaceholder})}),t.jsx(Ps,{entityType:X,entityId:e.id,entityTitle:e.title,parentWork:g==null?void 0:g.parentWork,parentCollection:g==null?void 0:g.parentCollection,belongsToWork:g==null?void 0:g.belongsToWork,belongsToCollection:g==null?void 0:g.belongsToCollection,childWorks:g==null?void 0:g.childWorks,childCollections:g==null?void 0:g.childCollections,containedBooks:g==null?void 0:g.containedBooks,siblingBooks:g==null?void 0:g.siblingBooks,onLinkEntity:fe,onUnlinkEntity:be,onViewEntity:ze,onCreateAndLink:ve,onSaveRelations:O}),l&&a&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${o("danger-soft-border")}`,background:o("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:o("danger"),fontWeight:600,marginBottom:"8px"},children:m.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"12px"},children:m.editor.dangerZoneDesc}),t.jsx("button",{onClick:a,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("danger")}`,borderRadius:"4px",background:"transparent",color:o("danger"),cursor:"pointer"},children:m.editor.deleteEntity})]}),t.jsx(Ds,{isOpen:b,entityType:h,title:$,onSelect:Ee,onCancel:()=>S(!1),onCreate:()=>{S(!1),ve(j,h)},searchResults:_,onSearch:Ne,isLoading:z,excludeId:e.id}),t.jsx(Hs,{isOpen:T,entityType:P,relationField:A,inheritData:V,onConfirm:ke,onCancel:()=>C(!1)}),t.jsx(Us,{isOpen:E,title:m.action.selectBookOrWork,filterType:"all",recentEntities:pe,excludeId:e.id,onSelect:he,onCancel:()=>{le(!1),ae(null)},onSearch:oe})]})};function Hp({items:e,onChange:n}){const i=ue(),r=(a,p,c)=>{const d=e.map((u,g)=>g===a?{...u,[p]:c}:u);n(d)},s=a=>n(e.filter((p,c)=>c!==a)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((a,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(Ge,{label:i.editor.bookNameLabel,value:a.book_title,onChange:c=>r(p,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(Ge,{label:i.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:c=>r(p,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Ys({items:e,onChange:n,showMeta:i,addLabel:r}){const s=ue(),[l,a]=f.useState(null),p=(u,g,x)=>{const m=e.map((b,S)=>S===u?{...b,[g]:x||void 0}:b);n(m)},c=u=>{n(e.filter((g,x)=>x!==u)),l===u&&a(null)},d=()=>{n([...e,{source:""}]),a(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,g)=>{const x=l===g;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:x?`color-mix(in srgb, ${o("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>a(x?null:g),children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.2s",transform:x?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:m=>{m.stopPropagation(),c(g)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${o("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:o("muted")},children:"✕"})]}),!x&&i&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:o("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),x&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ge,{label:s.label.sourceName,value:u.source,onChange:m=>p(g,"source",m)}),t.jsx(Ge,{label:s.label.sourceBid,value:u.source_bid||"",onChange:m=>p(g,"source_bid",m)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ge,{label:s.label.titleInfo,value:u.title_info||"",onChange:m=>p(g,"title_info",m)}),t.jsx(Ge,{label:s.label.authorInfo,value:u.author_info||"",onChange:m=>p(g,"author_info",m)})]}),t.jsx(Ge,{label:s.label.edition,value:u.edition||"",onChange:m=>p(g,"edition",m)})]}),t.jsx(bt,{value:u.summary||"",onChange:m=>p(g,"summary",m),placeholder:s.editor.summaryPlaceholder}),t.jsx(bt,{value:u.comment||"",onChange:m=>p(g,"comment",m),placeholder:s.editor.commentPlaceholder}),t.jsx(bt,{value:u.additional_comment||"",onChange:m=>p(g,"additional_comment",m),placeholder:s.editor.additionalCommentPlaceholder})]})]},g)}),t.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Gp({items:e,onChange:n}){const i=ue();return t.jsx(Ys,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Up({items:e,onChange:n}){const i=ue();return t.jsx(Ys,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function qs(e){var p,c,d,u,g,x,m;const n=((c=(p=e.authors)==null?void 0:p[0])==null?void 0:c.name)||"",i=((d=e.publication_info)==null?void 0:d.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(g=e.page_count)!=null&&g.number?String(e.page_count.number):((x=e.page_count)==null?void 0:x.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",a={id:e.id,title:e.title,type:e.type,author:n,publicationYear:i,holder:r,pages:s,description:l,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const b=e;if(Array.isArray(b.related_works)){const S=b.related_works.find(h=>h.relation==="part_of");S&&(a.parentWorkId=S.id,a.parentWorkName=S.title)}}if(e.type==="book"){const b=e;a.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(a.collectionId=(m=b.contained_in[0])==null?void 0:m.id)}return a}function Vp(e){const n={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.publicationYear?{year:e.publicationYear}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(n.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(n.work_id=e.workId,e.collectionId&&(n.contained_in=[{id:e.collectionId}])),n}const Yp=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:a,onSave:p,onDelete:c,onNavigate:d,renderLink:u,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:S,onRelationsChange:h,headerExtra:y,className:j,style:k}=e;ue();const[$,v]=f.useState(s),_=l?s:$;f.useEffect(()=>{s!==$&&v(s)},[s]);const w=f.useCallback(()=>{const A=_==="view"?"edit":"view";l?l(A):v(A)},[_,l]),[z,N]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(A=>{A&&N(A)})},[i,r]);const T=n||z,C=f.useMemo(()=>T?qs(T):null,[T]),P=l||!n?t.jsx("button",{onClick:w,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:_==="edit"?o("accent-bg"):"transparent",color:o(_==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?"切换到编辑模式":"切换到查看模式",children:_==="view"?"✏️ 编辑":"👁 查看"}):null,B=t.jsxs(t.Fragment,{children:[P,y]});return!T&&!C?t.jsx(jt,{}):_==="view"?t.jsx(fi,{data:T,transport:r,onNavigate:d?A=>d(A):void 0,renderLink:u,headerExtra:B,className:j,style:k}):C?t.jsxs("div",{className:j,style:k,children:[B&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:B}),t.jsx(Vs,{data:C,onChange:a||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:d,showDelete:!!c,onDelete:c,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:S,onRelationsChange:h})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},Ko=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ks=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,l]=f.useState(null),[a,p]=f.useState(""),[c,d]=f.useState(""),[u,g]=f.useState("idle"),[x,m]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{e&&(l(null),p(""),d(""),g("idle"),m(""))},[e]),f.useEffect(()=>{s&&setTimeout(()=>{var j;return(j=b.current)==null?void 0:j.focus()},100)},[s]),f.useEffect(()=>{if(u==="success"){const j=setTimeout(n,2e3);return()=>clearTimeout(j)}},[u,n]),f.useEffect(()=>{if(!e)return;const j=k=>{k.key==="Escape"&&n()};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[e,n]);const S=async()=>{if(!(!s||!a.trim())){g("submitting"),m("");try{await i({type:s,content:a.trim(),...c.trim()?{contact:c.trim()}:{}}),g("success")}catch(j){g("error"),m(j instanceof Error?j.message:"提交失败,请稍后重试")}}};if(!e)return null;const h=s&&a.trim()&&u!=="submitting",y=Ko.find(j=>j.value===s);return t.jsx("div",{style:qp,onClick:j=>{j.target===j.currentTarget&&n()},children:t.jsxs("div",{style:Kp,onClick:j=>j.stopPropagation(),children:[t.jsxs("div",{style:Jp,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:Zp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:nu,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:o("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Ko.map(j=>t.jsxs("button",{onClick:()=>l(j.value),style:{...Xp,...s===j.value?Qp:{}},children:[t.jsx("span",{children:j.icon})," ",j.label]},j.value))}),t.jsx("textarea",{ref:b,value:a,onChange:j=>p(j.target.value),placeholder:(y==null?void 0:y.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...eu,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:c,onChange:j=>d(j.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:ou}),t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[a.length," / 2000"]}),u==="error"&&t.jsx("div",{style:iu,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:S,disabled:!h,style:{...tu,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},qp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Kp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},Jp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Zp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:o("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Xp={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Qp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},eu={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},tu={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},nu={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},iu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginBottom:"12px"},ou={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},oi="--bim-feedback-fab-offset",ri=48,ru=16,su=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,a]=f.useState(!1),p=n.bottom??24;return f.useEffect(()=>{if(r||typeof document>"u")return;const c=document.documentElement;return c.style.setProperty(oi,`calc(${p+ri+ru}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(oi)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>a(!0),style:{...lu,zIndex:s??o("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(Ks,{isOpen:l,onClose:()=>a(!1),onSubmit:e,feedbackListUrl:i})]})},lu={position:"fixed",width:`${ri}px`,height:`${ri}px`,borderRadius:"50%",border:"none",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:o("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},Jo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Js=({onSubmit:e})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[l,a]=f.useState(""),[p,c]=f.useState("idle"),[d,u]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var S;return(S=g.current)==null?void 0:S.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){c("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),c("success"),s(""),a(""),i("bug")}catch(S){c("error"),u(S instanceof Error?S.message:"提交失败,请稍后重试")}}},m=n&&r.trim()&&p!=="submitting",b=Jo.find(S=>S.value===n);return p==="success"?t.jsx("div",{style:Zo,children:t.jsxs("div",{style:uu,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>c("idle"),style:xu,children:"继续提交"})]})}):t.jsxs("div",{style:Zo,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Jo.map(S=>t.jsxs("button",{onClick:()=>i(S.value),style:{...au,...n===S.value?cu:{}},children:[t.jsx("span",{children:S.icon})," ",S.label]},S.value))}),t.jsx("textarea",{ref:g,value:r,onChange:S=>s(S.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...du}}),t.jsx("input",{type:"text",value:l,onChange:S=>a(S.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:gu}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:x,disabled:!m,style:{...pu,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:fu,children:d})]})},Zo={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},au={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},cu={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},du={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},pu={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},uu={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},xu={background:"none",border:"none",color:o("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},fu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginTop:"8px"},gu={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function Xo(e){return typeof e=="function"?e():e??"/api/feedback"}const Zs=({resourceId:e,apiUrl:n})=>{const[i,r]=f.useState([]),[s,l]=f.useState(!0),a=f.useCallback(async()=>{const c=Xo(n);l(!0);try{const u=await(await fetch(`${c}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);f.useEffect(()=>{a()},[a]);const p=async c=>{const d=Xo(n),u=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...c,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const g=await u.json().catch(()=>null);throw new Error((g==null?void 0:g.error)||"提交失败")}setTimeout(()=>a(),500)};return t.jsxs("div",{children:[t.jsx(Pi,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Js,{onSubmit:p})})]})},Qo={part_of:"所屬",has_part:"包含",contains_text_of:"收錄",collected_in:"叢編",text_carried_by:"載錄",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"後繼",derived_from:"衍生",has_adaptation:"改編",related:"相關"};function er(e){return e?Qo[e]??e:Qo.related}const mu={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function hu(e){return mu[e]??e}const bu={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function yu(e){return bu[e]??""}function Oi({authors:e,onNavigate:n,renderLink:i}){const{convert:r}=q(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,a)=>{const p=ji(l.role);return t.jsxs(f.Fragment,{children:[a>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Be,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:i,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},a)})}):null}function Xs(e,n){var p,c;const i=bi(e,n),r=i.mirrors.map(d=>({key:d.key,label:d.label,description:d.description,rows:d.items.filter(u=>u.group_role!=="mirror"),mirrors:d.items.filter(u=>u.group_role==="mirror")})),s=i.buckets.filter(d=>d.key==="image"||d.key==="textImage").flatMap(d=>d.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=i.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((c=i.buckets.find(d=>d.key==="text"))==null?void 0:c.items)??[],groups:r}}function Qs(e,n){const i=(e.url?Nt(e.url):void 0)||e.name,r=Fr(e,n);return r?`${i}(${r})`:i}function Di({item:e,siblings:n,listedVolumeCounts:i}){const{convert:r}=q(),[s,l]=f.useState(!1),a=bn(e),p=!!a&&a.expected>0&&!(i!=null&&i.has(a.expected)),c=r(Qs(e,n)),d=Lt(e),u=Sn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var x,m;const g=(x=e.metadata)!=null&&x.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((m=e.metadata)==null?void 0:m.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("殘片")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:r(e.color_mode==="color"?"彩色":"黑白")})]}):null;return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[c," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),g]}):t.jsxs("span",{className:"bim-d-zt-name",children:[c,g]})})(),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(Si,{item:e})})]}),t.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(g=>!g),children:r(s?"收起分冊":`展開 ${a.expected} 冊`)})})]})}function el({groups:e,listedVolumeCounts:n}){const{convert:i}=q();return t.jsx(t.Fragment,{children:e.map(r=>t.jsxs("div",{className:"bim-d-rg",children:[r.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:i(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:i(r.description)}),r.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:r.rows.map((s,l)=>t.jsx(Di,{item:s,siblings:r.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),r.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[r.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:i("鏡像")}),r.mirrors.map((s,l)=>{const a=Lt(s),p=i(Qs(s,r.mirrors));return a?t.jsxs("a",{href:a,target:"_blank",rel:"noopener noreferrer",title:s.details?i(s.details):void 0,children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:p},l)})]})]},r.key))})}const Yt=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function si(e){var i;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(i=Yt.find(r=>n.startsWith(r.key[0])))==null?void 0:i.key}const tr=12,ju=60,tl=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:a,railLinks:p})=>{var ke,Ne,Ee;const c=ue(),{convert:d}=q(),u=f.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[g,x]=f.useState(new Map),[m,b]=f.useState(!1),[S,h]=f.useState(""),[y,j]=f.useState(!1),k=u.length<=ju,$=k||m||!!S||y,v=f.useMemo(()=>$?u:u.slice(0,tr),[u,$]);f.useEffect(()=>{if(!n||v.length===0)return;const O=v.filter(oe=>!g.has(oe));if(O.length===0)return;let ce=!1;return Promise.all(O.map(oe=>n.getItem(oe).then(he=>{const Z=he??{};return[oe,{id:oe,title:Z.title,edition:Z.edition,resources:Z.resources,publication_info:Z.publication_info,current_location:Z.current_location,lineage:Z.lineage,measure_info:Z.measure_info}]}).catch(()=>[oe,{id:oe}]))).then(oe=>{ce||x(he=>{const Z=new Map(he);for(const[F,I]of oe)Z.set(F,I);return Z})}),()=>{ce=!0}},[n,v,g]);const _=f.useMemo(()=>u.map(O=>g.get(O)??{id:O}),[u,g]),w=u.length>0&&u.every(O=>g.has(O)),z=!!n&&v.some(O=>!g.has(O)),N=k||$,T=f.useMemo(()=>Or(_,e.version_graph,{era:S,scanOnly:y,sort:N?"year":"default"}),[_,e.version_graph,S,y,N]),C=m?T.rows:T.rows.slice(0,tr),P=T.allRows.filter(O=>O.hasImage).length,B=e.related_works||[],A=B.filter(O=>O.relation==="collected_in"),W=f.useMemo(()=>{const O=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],ce=oe=>{const he=O.indexOf(oe??"");return he<0?O.length:he};return B.filter(oe=>oe.relation!=="collected_in").map((oe,he)=>({r:oe,i:he})).sort((oe,he)=>ce(oe.r.relation)-ce(he.r.relation)||oe.i-he.i).map(oe=>oe.r)},[B]),V=f.useMemo(()=>{const O=bi(e.resources,e.resource_groups);return[...O.mirrors.flatMap(ce=>ce.items.map(oe=>({r:oe,kind:d(ce.label)}))),...O.buckets.flatMap(ce=>ce.items.map(oe=>({r:oe,kind:d(yu(ce.key))})))]},[e.resources,e.resource_groups,d]),K=e.indexed_by||[],E=e.emendated_by||[],le=f.useMemo(()=>{var M,ne,R;const O=[],ce=(ne=(M=e.authors)==null?void 0:M[0])==null?void 0:ne.dynasty;ce&&O.push({label:"成書",value:d(ce)});const oe=at(e,c.unit.juan);if(oe){const J=(R=e.juan_count)==null?void 0:R.description;O.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[d(oe),J&&J!==oe?t.jsxs("span",{className:"bim-d-meta",children:["(",d(J),")"]}):null]})})}e.loss_status&&O.push({label:"存佚",value:d(hu(e.loss_status))});const he=T.allRows.filter(J=>J.sortYear!=null),Z=he.length>0?he.reduce((J,H)=>J.sortYear<=H.sortYear?J:H):null;Z!=null&&Z.era.era?O.push({label:"最早存世",value:d([Z.era.era,Z.era.reign].filter(Boolean).join(" ")),title:Z.era.source==="edition"?d("據版本題名推斷"):void 0}):z&&O.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),E.length&&O.push({label:"考證",value:`${E.length} ${d("條")}`});const F=nr(e.additional_titles);F.length&&O.push({label:"又名",value:F.map(d).join("、")});const I=nr(e.attached_texts);I.length&&O.push({label:"附載",value:I.map(d).join("、")});const D=(e.additional_works||[]).map(J=>d(J.book_title)+(J.n_juan!=null?` ${J.n_juan}${d(c.unit.juan)}`:""));return D.length&&O.push({label:"附錄",value:D.join("、")}),O},[e,d,c,z,T.allRows,E.length]),ae=[{value:e._edition_count??u.length,label:"版本"},{value:w?P:0,label:"有影印"},{value:K.length,label:"家著錄"}],pe=e.classification,ee=pe?[pe.l1,pe.l2,pe.l3,pe.l4].filter(Boolean).map(O=>d(O)):[],X=e.subtype?d(c.workSubtype[e.subtype]??e.subtype):"",ie=t.jsx(Xt,{title:d(e.title),byline:t.jsx(Oi,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(Me,{items:[...ee,pe!=null&&pe.source?d(`據《${pe.source.split("/")[0]}》`):"",X]}),description:(ke=e.description)!=null&&ke.text?t.jsxs(t.Fragment,{children:[t.jsx(lt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Ne=e.description.sources)!=null&&Ne.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(O=>d(rc(O))).filter(Boolean).join(" · ")}):null]}):void 0,stats:ae,facts:le,readAction:s,foot:t.jsx(Qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Ee=e.appendix)==null?void 0:Ee.map((O,ce)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(O.title)}),t.jsx(lt,{text:O.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},ce))}),me=T.eras.length>=2?[{key:"",label:c.catalog.all},...T.eras.map(O=>({key:O,label:`${O} ${T.allRows.filter(ce=>ce.era.era===O).length}`}))]:[],te=[];u.length&&te.push({id:"versions",label:"版本",count:u.length}),K.length&&te.push({id:"catalogs",label:"著錄",count:K.length}),A.length&&te.push({id:"collected",label:"收入叢編",count:A.length}),W.length&&te.push({id:"related",label:"相關書目",count:W.length}),V.length&&te.push({id:"resources",label:"在線資源",count:V.length});const se=u.length===0&&K.length===0,fe=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Fe,{id:"versions",title:"版本",meta:t.jsx(Me,{items:[d(`共 ${u.length} 種`),w&&P?d(`${P} 種有影印`):"",T.rows.length!==T.allRows.length?d(`當前 ${T.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&me.length===0&&u.length>1?"":void 0,children:[me.length>0&&t.jsx(_n,{items:me,value:S,onChange:O=>{h(O),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Qr,{label:"只看有影印",checked:y,onChange:O=>{j(O),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:d(N?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("版本")}),t.jsx("th",{children:d("年代")}),t.jsx("th",{children:d("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:d("影印")})})]})}),t.jsx("tbody",{children:C.map(O=>{var ce;return t.jsx(vu,{row:O,measure:(ce=g.get(O.id))==null?void 0:ce.measure_info,loaded:g.has(O.id),onNavigate:i,renderLink:r},`${O.id}:${g.has(O.id)?"r":"p"}`)})})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(S||y?"當前篩選下沒有版本":"暫無版本著錄")}),T.rows.length>C.length&&t.jsx(Bt,{label:`展開其餘 ${T.rows.length-C.length} 種版本`,onClick:()=>b(!0)}),T.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:d("部分年代據版本題名推斷,非著錄原文")})]}),K.length>0&&t.jsx(ku,{items:K,transport:n,onNavigate:i,renderLink:r}),se&&t.jsx(Fe,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),be=(O,ce)=>t.jsx(Be,{id:O,label:d(ce),onNavigate:i,renderLink:r,dense:!0}),ze=f.useMemo(()=>{const O=new Map;for(const ce of W){const oe=er(ce.relation);O.set(oe,(O.get(oe)??0)+1)}return O.size>1?[...O.entries()].sort((ce,oe)=>oe[1]-ce[1]).slice(0,4).map(([ce,oe])=>`${d(ce)} ${oe}`).join(" · "):void 0},[W,d]),ve=t.jsxs(t.Fragment,{children:[t.jsx(ht,{id:"collected",title:"收入叢編",items:A.map(O=>be(O.id,O.title))}),t.jsx(ht,{id:"related",title:"相關書目",meta:d(`${W.length} 部`),sub:ze,items:W.map(O=>t.jsxs(t.Fragment,{children:[be(O.id,O.title),t.jsx("span",{className:"bim-d-meta",title:O.note?d(O.note):void 0,children:d(er(O.relation))})]}))}),t.jsx(ht,{id:"resources",title:"在線資源",cap:6,items:V.map(({r:O,kind:ce})=>{const oe=d((O.url?Nt(O.url):void 0)||O.name),he=Lt(O);return t.jsxs(t.Fragment,{children:[he?t.jsxs("a",{href:he,target:"_blank",rel:"noopener noreferrer",children:[oe," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:oe}),ce&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:ce})]})})})]});return t.jsx(Zt,{railTop:l,back:a,nav:te,railLinks:p,main:fe,card:ie,side:ve})};function nr(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ir(e,n){return n((e.url?Nt(e.url):void 0)||e.name)}function vu({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=q(),a=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",c=e.holders[0],d=c?ir(c,l):e.locationName?l(e.locationName):"",u=e.images[0],g=u?Lt(u):void 0,x=e.images.map(m=>ir(m,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Be,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${a?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:a?l(a):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${d?"":" bim-d-zt-blank"}`,children:[d||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(g?t.jsx("a",{className:"bim-d-flag",href:g,target:"_blank",rel:"noopener noreferrer",title:x,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:x,children:l("有影印")}))})]})}function ku({items:e,transport:n,onNavigate:i,renderLink:r}){const s=ue(),{convert:l}=q(),[a,p]=f.useState(0),c=Math.min(a,e.length-1),d=e[c],[u,g]=f.useState(new Map);return f.useEffect(()=>{if(!n)return;const x=[...new Set(e.map(b=>b.source_bid).filter(b=>!!b))];if(x.length===0)return;let m=!1;return Promise.all(x.map(b=>n.getItem(b).then(S=>{var h,y;return[b,((y=(h=S==null?void 0:S.authors)==null?void 0:h[0])==null?void 0:y.dynasty)??""]}).catch(()=>[b,""]))).then(b=>{m||g(new Map(b.filter(([,S])=>S)))}),()=>{m=!0}},[n,e]),t.jsx(Fe,{id:"catalogs",title:"著錄",meta:t.jsx(Me,{items:[l(`歷代書目 ${e.length} 家`),l("按著錄順序")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":l("著錄書目"),children:e.map((x,m)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":m===c,"aria-label":l(x.source),onClick:()=>p(m),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(x.source_bid??"")?l(u.get(x.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...l(x.source)].slice(0,9).map((b,S)=>t.jsx("span",{children:b},S))})]})},m))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:l(d.title_info)}),t.jsx(Me,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?t.jsx(Be,{id:d.source_bid,label:l(d.source),onNavigate:i,renderLink:r,dense:!0}):l(d.source),d.section?l(d.section):"",d.author_info?`${l(s.label.authorInfo)} ${l(d.author_info)}`:"",d.edition?`${l(s.label.edition)} ${l(d.edition)}`:"",d.page??""]}),d.summary&&t.jsx("p",{className:"bim-d-quote",children:Ue(l(d.summary))}),d.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:Ue(l(d.comment))})]}),d.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:Ue(l(d.additional_comment))})]}),!d.summary&&!d.comment&&!d.additional_comment&&!d.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:l("僅著錄書名,無提要。")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?t.jsx("button",{type:"button","aria-label":l(`上一家:${e[c-1].source}`),onClick:()=>p(c-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",l(e[c-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",e.length]}),c<e.length-1?t.jsx("button",{type:"button","aria-label":l(`下一家:${e[c+1].source}`),onClick:()=>p(c+1),children:t.jsxs("span",{"aria-hidden":"true",children:[l(e[c+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function Su(e){var n;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((n=e.year_range)==null?void 0:n[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function wu(e,n){if(!e.lineage)return null;const i=e.lineage;return{id:e.id,kind:"book",label:e.title,year:i.year,year_text:i.year_text,year_uncertain:i.year_uncertain,category:i.category,status:i.status,extant_juan:i.extant_juan,group:n[e.id],note:i.note}}function or(e,n,i){return{id:`derive:${n.ref}->${e}:${i}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function _u(e,n,i){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${i}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function $u(e,n){var d;if(n==="all")return null;const i=(d=e.collections)==null?void 0:d[n],r=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,l=r||s||!!(i!=null&&i.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!i||!l)return null;const a=r?new Set(i.groups):null,p=new Set(i.book_ids??[]);if(a&&e.node_groups)for(const[u,g]of Object.entries(e.node_groups))a.has(g)&&p.add(u);let c=null;if(i.hypothetical_ids&&(c=new Set(i.hypothetical_ids)),a){c||(c=new Set);for(const u of e.hypothetical_nodes??[])u.group&&a.has(u.group)&&c.add(u.id)}return{books:p,hypos:c}}function xn(e,n,i){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const l=new Set(r.excluded_books??[]),a=r.node_groups??{},p=$u(r,i??r.default_collection??"all"),c=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,g=new Set,x=new Set;if(c){const $=new Map(n.map(T=>[T.id,T])),v=new Map((r.hypothetical_nodes??[]).map(T=>[T.id,T])),_=T=>{const C=$.get(T);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(B=>B.ref);const P=v.get(T);return P?(P.derived_from??[]).map(B=>B.ref):[]},w=T=>v.has(T)?!u||u.has(T):!d||d.has(T),z=new Set,N=T=>{if(!z.has(T)){z.add(T);for(const C of _(T))l.has(C)||(w(C)||(v.has(C)?x.add(C):$.has(C)&&g.add(C)),N(C))}};for(const T of n)d&&d.has(T.id)&&!l.has(T.id)&&N(T.id);for(const T of r.hypothetical_nodes??[])u&&u.has(T.id)&&N(T.id)}const m=n.filter($=>!l.has($.id)).filter($=>!d||d.has($.id)||g.has($.id)).map($=>{const v=wu($,a);return v&&g.has($.id)&&(v.bridge=!0),v}).filter($=>$!==null),b=(r.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||x.has($.id)).map($=>{const v=Su($);return x.has($.id)&&(v.bridge=!0),v}),S=[...m,...b],h=new Set(S.map($=>$.id)),y=new Set,j=[],k=$=>{y.has($.id)||!h.has($.source)||!h.has($.target)||(y.add($.id),j.push($))};for(const $ of n)l.has($.id)||!$.lineage||d&&!d.has($.id)&&!g.has($.id)||(($.lineage.derived_from??[]).forEach((v,_)=>{k(or($.id,v,_))}),($.lineage.related_to??[]).forEach((v,_)=>{k(_u($.id,v,_))}));for(const $ of r.hypothetical_nodes??[])u&&!u.has($.id)&&!x.has($.id)||($.derived_from??[]).forEach((v,_)=>{k(or($.id,v,_))});return{nodes:S,edges:j,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function nl(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function zu(e,n){const i=[],r=e.version_graph;if(!r)return i;const s=new Set(n.map(c=>c.id)),l=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),a=new Set([...s,...l]),p=(c,d)=>{a.has(d.ref)||i.push(`${c}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${c}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&i.push(`${c}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const d=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>p(d,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||i.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const d=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>p(d,u))}return i}const il=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:s}=q();if(!e.nodes.length)return t.jsx("div",{style:{...Ou,...r},className:i,children:"暂无版本图数据"});const l=new Map,a=new Map;for(const x of e.edges)if(x.kind==="derive"){const m=l.get(x.target)??[];m.push(x),l.set(x.target,m)}else for(const m of[x.source,x.target]){const b=a.get(m)??[];b.push(x),a.set(m,b)}const p=new Map(e.nodes.map(x=>[x.id,x])),c=new Map,d=[];for(const x of e.nodes)if(x.group){const m=c.get(x.group)??[];m.push(x),c.set(x.group,m)}else d.push(x);const u=(x,m)=>(x.year??9999)-(m.year??9999);c.forEach(x=>x.sort(u)),d.sort(u);const g=e.groups.filter(x=>c.has(x.id));return t.jsxs("div",{className:i,style:{...Iu,...r},children:[e.title&&t.jsx("div",{style:Tu,children:s(e.title)}),e.description&&t.jsx("div",{style:Eu,children:s(e.description)}),g.map(x=>t.jsx(rr,{label:x.label,color:x.color,nodes:c.get(x.id),incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n},x.id)),d.length>0&&t.jsx(rr,{label:"其他",nodes:d,incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n})]})},rr=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:a})=>{const{convert:p}=q();return t.jsxs("div",{style:Ru,children:[t.jsx("div",{style:{...Nu,borderLeftColor:n??o("widget-border")},children:p(e)}),i.map(c=>t.jsx(Cu,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:a},c.id))]})},Cu=({node:e,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",a=e.bridge,{convert:p}=q();return t.jsxs("div",{style:{...Lu,borderStyle:l||a?"dashed":"solid",opacity:a?.55:e.status==="lost"?.7:1,background:a?o("bg-subtle"):void 0},title:a?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:Bu,children:[t.jsx("span",{style:Au,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Wu,children:nl(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Mu,children:[e.category&&t.jsx(Ot,{children:p(e.category)}),e.status==="lost"&&t.jsx(Ot,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(Ot,{tone:"warn",children:"残本"}),l&&t.jsx(Ot,{tone:"info",children:"假想祖本"}),a&&t.jsx(Ot,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Fu,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:Pu,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:lr,children:[t.jsx("div",{style:ar,children:"来源:"}),n.map(c=>{const d=r.get(c.source);return t.jsxs("div",{style:cr(c.confidence),children:[t.jsx("span",{style:dr,children:p(c.relation)}),t.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,p(d.label)):p((d==null?void 0:d.label)??c.source)}),c.confidence!=="consensus"&&c.confidence!=="certain"&&t.jsx(sr,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:pr,children:["· ",p(c.evidence)]})]},c.id)})]}),i.length>0&&t.jsxs("div",{style:lr,children:[t.jsx("div",{style:ar,children:"关联:"}),i.map(c=>{const d=c.source===e.id?c.target:c.source,u=r.get(d);return t.jsxs("div",{style:cr(c.confidence),children:[t.jsx("span",{style:dr,children:p(c.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,p(u.label)):p((u==null?void 0:u.label)??d)}),t.jsx(sr,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:pr,children:["· ",p(c.evidence)]})]},c.id)})]})]})},Ot=({children:e,tone:n="default"})=>{const r={default:{bg:o("tag-bg"),fg:o("fg")},warn:{bg:o("warn-bg"),fg:o("warn-fg")},info:{bg:o("info-bg"),fg:o("info-fg")}}[n];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},sr=({level:e})=>{const i={certain:{label:"确定",color:o("confidence-certain")},consensus:{label:"共识",color:o("confidence-consensus")},probable:{label:"推测",color:o("confidence-probable")},disputed:{label:"有争议",color:o("confidence-disputed")}}[e];return i?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${i.color}`,color:i.color,borderRadius:"8px",marginLeft:"4px"},children:i.label}):null},Iu={fontSize:"14px",color:o("fg")},Tu={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Eu={fontSize:"13px",color:o("muted"),marginBottom:"16px",lineHeight:1.6},Ru={marginBottom:"16px"},Nu={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:o("fg")},Lu={border:`1px solid ${o("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:o("bg")},Bu={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Au={fontSize:"15px",fontWeight:600},Wu={fontSize:"12px",color:o("muted")},Mu={marginBottom:"6px"},Fu={fontSize:"12px",color:o("muted"),margin:"2px 0"},Pu={fontSize:"12px",color:o("muted"),fontStyle:"italic",margin:"4px 0"},lr={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${o("widget-border")}`},ar={fontSize:"11px",color:o("muted"),marginBottom:"2px"},cr=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),dr={display:"inline-block",padding:"0 6px",fontSize:"11px",background:o("tag-bg"),color:o("fg"),borderRadius:"3px",marginRight:"6px"},pr={fontSize:"11px",color:o("muted")},Ou={padding:"20px",textAlign:"center",color:o("muted"),fontSize:"13px"},ol=({selectedNodeId:e,...n})=>{const[i,r]=f.useState("loading"),[s,l]=f.useState(null);return f.useEffect(()=>{let a=!1;return Du().then(p=>{a||(p?(l(p),r("ready")):r("missing"))}),()=>{a=!0}},[]),i==="loading"?t.jsx("div",{style:ur,children:"加载图组件中…"}):i==="missing"||!s?t.jsxs("div",{style:ur,children:[t.jsxs("div",{children:["图组件未安装。请安装 ",t.jsx("code",{children:"@xyflow/react"})," 与 ",t.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),t.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",t.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):t.jsx(Hu,{modules:s,selectedNodeId:e,...n})};async function Du(){try{const[e,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let i=!1;try{await import("@xyflow/react/dist/style.css"),i=!0}catch{i=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:n,cssLoaded:i}}catch{return null}}const Hu=({graph:e,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:l,modules:a})=>{const{ReactFlow:p,Background:c,Controls:d,Handle:u,Position:g,BaseEdge:x,EdgeLabelRenderer:m,getSmoothStepPath:b,dagre:S}=a,h=f.useMemo(()=>({lineage:_=>{var V,K,E,le;const w=((V=_.data)==null?void 0:V.stepPosition)??.85,[z,N,T]=b({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:w,borderRadius:5}),C=!!((K=_.data)!=null&&K.isSibling),P=C?N:_.targetX-18,B=C?T:_.targetY-12,A=(E=_.data)==null?void 0:E.labelStyle,W=(le=_.data)==null?void 0:le.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(x,{id:_.id,path:z,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&t.jsx(m,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${P}px,${B}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:o("bg"),border:`0.5px solid ${o("widget-border")}`,...W,...A},children:_.label})})]})}}),[x,m,b]),y=f.useMemo(()=>({version:_=>{const w=_.data,z=w.kind==="hypothetical",N=w.status==="lost",T=w.isSelected,C=w.bridge,P=w.borderColor??o("muted"),B=C||z?"dashed":"solid",A=C?.5:N?.6:1;return t.jsxs("div",{style:{background:o(C?"bg-subtle":"bg"),border:`2px ${B} ${T?o("primary"):P}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:A,boxShadow:T?o("shadow-node-selected"):z||C?"none":o("shadow-node")},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:g.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!w.renderLink?w.label:w.renderLink(w.bookId,w.label)}),w.description&&t.jsx("div",{style:{fontSize:10,color:o("aux-fg"),lineHeight:1.25,marginTop:1},children:w.description}),w.yearText&&t.jsx("div",{style:{fontSize:10,color:o("aux-fg"),lineHeight:1.2},children:nl(w.yearText,void 0,w.uncertain)}),N&&t.jsx("div",{style:{fontSize:9,color:o("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:g.Right,style:{visibility:"hidden"}})]})}}),[u,g]),{convert:j}=q(),{rfNodes:k,rfEdges:$}=f.useMemo(()=>Gu(e,S,n,l,j),[e,S,n,l,j]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:t.jsxs(p,{nodes:k,edges:$,nodeTypes:y,edgeTypes:h,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(d,{showInteractive:!1})]})})};function Gu(e,n,i,r,s=l=>l??""){const p=e.layout==="LR"||!e.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:p?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const d=new Map(e.groups.map(y=>[y.id,y.color??o("muted")]));for(const y of e.nodes)c.setNode(y.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const y of e.edges)y.kind==="derive"&&(u.has(y.relation)||c.setEdge(y.source,y.target));n.layout(c);const g=e.nodes.map(y=>{const j=c.node(y.id),k=r?y.id===r:void 0,$={kind:y.kind,label:s(y.label),bookId:y.kind==="book"?y.id:void 0,yearText:s(y.year_text??Vu(y)),uncertain:y.year_uncertain,category:y.category,status:y.status,borderColor:y.group?d.get(y.group):void 0,renderLink:i,isSelected:k,description:s(y.description),bridge:y.bridge};return{id:y.id,type:"version",position:{x:j.x-160/2,y:j.y-90/2},data:$,draggable:!1,selected:k}}),x=.78,m=.06,b=new Map;for(const y of e.edges)y.kind==="derive"&&(b.has(y.source)||b.set(y.source,[]),b.get(y.source).push(y));const S=new Map;for(const[y,j]of b){if(j.length<=1)continue;const k=[...j].sort((v,_)=>{var N,T;const w=((N=c.node(v.target))==null?void 0:N.y)??0,z=((T=c.node(_.target))==null?void 0:T.y)??0;return w-z}),$=k.length;k.forEach((v,_)=>{const w=(_-($-1)/2)*m;S.set(v.id,x+w)})}const h=e.edges.map(y=>Uu(y,S.get(y.id),s));return{rfNodes:g,rfEdges:h}}function Uu(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Yu(e.confidence),a={type:"arrowclosed",color:l,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:i(e.relation),data:{labelStyle:{color:o("fg")},isSibling:s,stepPosition:n},style:{stroke:l,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:a,markerStart:s?a:void 0,zIndex:1e3}}function Vu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Yu(e){switch(e){case"certain":return o("confidence-certain");case"consensus":return o("lineage-edge-consensus");case"probable":return o("confidence-probable");case"disputed":return o("confidence-disputed");default:return o("muted")}}const ur={padding:"40px 20px",textAlign:"center",color:o("muted"),fontSize:"13px",border:`1px dashed ${o("widget-border")}`,borderRadius:8,background:o("bg")},Hi=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:a,onCollectionChange:p,collectionsAvailable:c,collectionCounts:d,className:u,style:g})=>{var j;const[x,m]=f.useState(n),b=k=>{m(k),l==null||l(k)},S=(()=>{if(!c)return[];const k=Object.entries(c);return k.length===0||c.all?k:[...k,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),h=!!(p&&S.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:o("muted"),textAlign:"center"},children:"暂无版本传承数据"});const y=a?(j=c==null?void 0:c[a])==null?void 0:j.description:void 0;return t.jsxs("div",{className:u,style:g,children:[t.jsxs("div",{style:qu,children:[t.jsx("button",{onClick:()=>b("list"),style:Fn(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:Fn(x==="graph"),children:"关系图"}),h&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:o("muted"),marginRight:4},children:"集合:"}),S.map(([k,$])=>{const v=d==null?void 0:d[k];return t.jsxs("button",{onClick:()=>p==null?void 0:p(k),style:Fn(a===k),title:$.description,children:[$.label,v!=null?` ${v}`:""]},k)})]})]}),h&&y&&t.jsx("div",{style:{fontSize:12,color:o("muted"),marginBottom:8,padding:"4px 8px",background:o("bg-subtle"),borderRadius:4},children:y}),x==="list"?t.jsx(il,{graph:e,renderLink:i}):t.jsx(ol,{graph:e,renderLink:i,height:r,selectedNodeId:s})]})},qu={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Fn=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${o("widget-border")}`,borderRadius:4,background:e?o("primary"):"transparent",color:o(e?"primary-fg":"fg"),cursor:"pointer"}),xr=40,fr=2,Ku=9,gr={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function Pn(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const rl=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,fullText:l,fullTextPending:a,chapterLink:p,railTop:c,back:d,railLinks:u})=>{var M,ne,R,J,H,U,re,Se,ye,Le,Ye;const g=ue(),{convert:x}=q(),[m,b]=f.useState(null),[S,h]=f.useState(new Map),[y,j]=f.useState([]),[k,$]=f.useState(new Map),[v,_]=f.useState(!1),[w,z]=f.useState("flow"),[N,T]=f.useState(null);f.useEffect(()=>{if(!n||!e.work_id){b(null);return}let L=!1;return n.getItem(e.work_id).then(de=>{!L&&de&&de.type==="work"&&b(de)}).catch(()=>{}),()=>{L=!0}},[n,e.work_id]),f.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){T(null);return}let L=!1;return n.getLineageGraph(e.work_id).then(de=>{L||T(de&&de.nodes.length>1?de:null)}).catch(()=>{L||T(null)}),()=>{L=!0}},[n,e.work_id]),f.useEffect(()=>{const L=e.contained_in||[];if(!n||L.length===0){h(new Map);return}let de=!1;return Promise.all(L.map(ge=>{const $e=typeof ge=="string"?ge:ge.id;return n.getItem($e).then(xe=>[$e,xe]).catch(()=>[$e,null])})).then(ge=>{if(de)return;const $e=new Map;for(const[xe,Ce]of ge)Ce&&$e.set(xe,Ce);h($e)}),()=>{de=!0}},[n,e.contained_in]);const C=f.useMemo(()=>{const L=new Set([...(m==null?void 0:m.books)||[],...e.related_books||[]]);return L.add(e.id),[...L]},[m==null?void 0:m.books,e.related_books,e.id]),P=C.length-1;f.useEffect(()=>{if(!n||P<=0){j([]);return}const L=C.length<=xr,de=L?C:C.slice(0,8);let ge=!1;return Promise.all(de.map($e=>$e===e.id?Promise.resolve({id:$e,title:e.title,edition:e.edition,year:gn(e)}):n.getItem($e).then(xe=>{const Ce=xe??{};return{id:$e,title:Ce.title,edition:Ce.edition,year:xe?gn(Ce):void 0}}).catch(()=>({id:$e})))).then($e=>{if(ge)return;const xe=$e.filter(Ce=>Ce.id===e.id||Ce.title||Ce.edition);L&&xe.sort((Ce,Oe)=>(Ce.year??1/0)-(Oe.year??1/0)),j(xe)}),()=>{ge=!0}},[n,C,P,e]);const B=e.lineage,A=f.useMemo(()=>[...((B==null?void 0:B.derived_from)||[]).filter(L=>L.ref_type==="book").map(L=>L.ref),...((B==null?void 0:B.related_to)||[]).map(L=>L.book_id)].filter(Boolean),[B]);f.useEffect(()=>{if(!n||A.length===0){$(new Map);return}let L=!1;return Promise.all(A.map(de=>n.getItem(de).then(ge=>[de,{id:de,title:ge==null?void 0:ge.title,edition:ge==null?void 0:ge.edition}]).catch(()=>[de,{id:de}]))).then(de=>{L||$(new Map(de))}),()=>{L=!0}},[n,A]);const W=f.useMemo(()=>Xs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),V=W.groups.reduce((L,de)=>L+de.rows.length+de.mirrors.length,0),K=W.groups.length>0&&W.groups.every(L=>L.key==="_physical"),E=Jt(e),le=Vr(e),G=at(e,g.unit.juan),ae=new Set((e.contained_in||[]).map(L=>typeof L=="string"?0:Ut(L.volume_index).length).filter(L=>L>0)),pe=L=>{var $e;const de=($e=e.base_edition)==null?void 0:$e.find(xe=>xe.book_id===L&&xe.name);if(de!=null&&de.name)return de.name;const ge=k.get(L);return(ge==null?void 0:ge.edition)||(ge==null?void 0:ge.title)||""},ee=f.useMemo(()=>{var ct,nn,dt,on,rn;const L=[];le&&L.push({label:"版本類型",value:x(le),title:e.edition_type||(ct=e.lineage)!=null&&ct.category?void 0:x("據版本題名推斷")}),(nn=e.publication_info)!=null&&nn.details?L.push({label:"刊印",value:x(e.publication_info.details)}):(E.era||E.reign)&&L.push({label:"刊寫年代",value:x([E.era,E.reign].filter(Boolean).join(" ")),title:E.source==="edition"?x("據版本題名推斷"):void 0}),G&&L.push({label:"卷帙",value:x(G)});const de=(e.contained_in||[]).flatMap(_e=>typeof _e=="string"?[]:Ut(_e.volume_index));de.length&&L.push({label:"冊次",value:x(`第 ${wn(de,g.unit.volume)} ${g.unit.volume}(${de.length} ${g.unit.volume})`)});const ge=(((dt=e.lineage)==null?void 0:dt.derived_from)||[]).find(_e=>_e.relation==="底本"&&_e.ref_type==="book");ge&&pe(ge.ref)&&L.push({label:"底本",value:t.jsx(Be,{id:ge.ref,label:x(pe(ge.ref)),onNavigate:i,renderLink:r,dense:!0})});const $e=(e.base_edition||[]).filter(_e=>_e&&_e.name);for(const _e of["底本","配補","參校"]){if(_e==="底本"&&ge&&pe(ge.ref))continue;const Ze=$e.filter(Re=>Re.role===_e);Ze.length&&L.push({label:_e,value:Ze.map((Re,kt)=>t.jsxs(f.Fragment,{children:[kt>0&&"、",Re.book_id?t.jsx(Be,{id:Re.book_id,label:x(Re.name),onNavigate:i,renderLink:r,dense:!0}):x(Re.name)]},kt))})}const xe=(e.provenance||[]).filter(_e=>_e&&_e.institution),Ce=(e.resources||[]).filter(_e=>(_e.types||(_e.type?[_e.type]:[])).includes("physical"));if(xe.length){L.push({label:"存藏",value:xe.slice(0,2).map(Re=>x(Re.institution)).join("、")+(xe.length>2?x(` 等 ${xe.length} 處`):"")});const _e=xe.filter(Re=>Re.call_number).slice(0,2).map(Re=>`${x(Re.institution)} ${Re.call_number}`);_e.length&&L.push({label:"索書號",value:_e.join(";")+(xe.filter(Re=>Re.call_number).length>2?"…":"")});const Ze=xe.flatMap(Re=>Re.seals||[]).filter(Boolean);Ze.length&&L.push({label:"藏印",value:x(Ze.join("、"))})}else Ce.length?L.push({label:"存藏",value:Ce.slice(0,2).map(_e=>x(_e.name)).join("、")+(Ce.length>2?x(` 等 ${Ce.length} 處`):"")}):(on=e.current_location)!=null&&on.name&&L.push({label:"存藏",value:x(e.current_location.name)});const Oe=e.physical_description;if(Oe){const _e=[["行款",Oe.leaf_style],["裝幀",Oe.binding],["尺寸",Oe.dimensions],["品相",Oe.condition]];for(const[Ze,Re]of _e)Re&&Re.trim()&&L.push({label:Ze,value:x(Re)})}(rn=e.page_count)!=null&&rn.description&&L.push({label:g.label.pageCount,value:x(e.page_count.description)});const Je=[...Xn(e.additional_titles),...Xn(e.attached_texts)];return Je.length&&L.push({label:"又名",value:Je.map(x).join("、")}),L},[e,x,g,E,le,G,k,i,r]),X=x(e.title),ie=e.edition?x(e.edition):void 0,me=((M=e.lineage)==null?void 0:M.year_text)||"",te=t.jsx(Xt,{kind:"版本",title:X,subtitle:ie,byline:t.jsx(Oi,{authors:e.authors??(m==null?void 0:m.authors),onNavigate:i,renderLink:r}),meta:(()=>{const L=[le?x(le):"",E.era?x([E.era,E.reign].filter(Boolean).join("")):"",G?x(G):""].filter(Boolean);return L.length?t.jsx("span",{className:"bim-d-tags",children:L.map((de,ge)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ge,2)}`,children:de},ge))}):null})(),description:(ne=e.description)!=null&&ne.text?t.jsx(lt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:vi((R=e.description)==null?void 0:R.text)?6:void 0,facts:ee,readAction:s,secondaryAction:s&&V>0&&!K?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(Qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),se=e.contained_in||[],fe=(l==null?void 0:l.chapters)||[],be=fe[0]&&Pn(fe[0].title)[0].slice(-1)||"章",ze=!!((J=B==null?void 0:B.derived_from)!=null&&J.length||(H=B==null?void 0:B.related_to)!=null&&H.length||(U=e.appendix)!=null&&U.length),ve=[];(fe.length||W.text.length||a)&&ve.push({id:"fulltext",label:"全文",count:fe.length?x(`${fe.length} ${be}`):void 0}),W.groups.length&&ve.push({id:"images",label:K?"館藏":"影印",count:V}),ze&&ve.push({id:"lineage",label:"版本源流"}),se.length&&ve.push({id:"collections",label:"收入叢編",count:se.length}),(re=e.location_history)!=null&&re.length&&ve.push({id:"provenance",label:"流轉歷史"});const ke=L=>(p==null?void 0:p(L))??null,Ne=fe[0],Ee=Ne?ke(Ne.file):null,O=v?fe:fe.slice(0,Ku),ce=(L,de,ge)=>L?t.jsx("a",{className:ge,href:L.href??"#",onClick:L.onClick?$e=>{$e.metaKey||$e.ctrlKey||($e.preventDefault(),L.onClick())}:void 0,children:de}):t.jsx("span",{className:ge,children:de}),oe=t.jsxs(t.Fragment,{children:[(fe.length>0||W.text.length>0||a)&&t.jsxs(Fe,{id:"fulltext",title:"全文",meta:fe.length>0?t.jsx(Me,{items:[x(`${fe.length} ${be}`),(Se=l==null?void 0:l.source)!=null&&Se.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[a&&!Ne&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),Ne&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${Pn(Ne.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((Ne.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),ce(Ee,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),fe.length>1&&t.jsx("ul",{className:"bim-d-chap",children:O.map(L=>{const[de,ge]=Pn(L.title);return t.jsx("li",{children:ce(ke(L.file),t.jsxs(t.Fragment,{children:[de&&t.jsx("b",{children:x(de)}),x(ge||L.file)]}))},L.file)})}),fe.length>O.length&&t.jsx(Bt,{label:`展開其餘 ${fe.length-O.length} ${be}`,onClick:()=>_(!0)}),W.text.length>0&&t.jsxs(t.Fragment,{children:[(fe.length>0||a)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:W.text.map((L,de)=>t.jsx(Di,{item:L,siblings:W.text,listedVolumeCounts:ae},`${L.id||L.url||L.name}-${de}`))})})]})]}),W.groups.length>0&&t.jsx(Fe,{id:"images",title:K?"館藏":"影印",meta:t.jsx(Me,{items:[W.groups.length>1?x(`${W.groups.length} 組`):"",x(`${V} 處`)]}),children:t.jsx(el,{groups:W.groups,listedVolumeCounts:ae})}),ze&&t.jsx(Fe,{id:"lineage",title:"版本源流",meta:(ye=B==null?void 0:B.derived_from)!=null&&ye.length?x("據版本傳承著錄"):void 0,action:N?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":x("源流視圖"),children:[t.jsx("button",{type:"button","aria-pressed":w==="flow",onClick:()=>z("flow"),children:x("卡片")}),t.jsx("button",{type:"button","aria-pressed":w==="graph",onClick:()=>z("graph"),children:x("關係圖")})]}):void 0,children:w==="graph"&&N?t.jsx(Hi,{graph:N,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(L,de)=>t.jsx(Be,{id:L,label:x(de),onNavigate:i,renderLink:r,dense:!0})}):t.jsx(Zu,{data:e,heading:ie||X,yearText:me,refName:pe,onNavigate:i,renderLink:r})}),se.length>0&&t.jsx(Fe,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:se.map((L,de)=>{var Oe,Je;const ge=typeof L=="string"?L:L.id,$e=typeof L=="string"?[]:Ut(L.volume_index),xe=S.get(ge),Ce=(xe==null?void 0:xe._member_count)||((Oe=xe==null?void 0:xe.books)==null?void 0:Oe.length)||((Je=xe==null?void 0:xe.contained_works)==null?void 0:Je.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Be,{id:ge,label:xe?x(xe.title):ge,onNavigate:i,renderLink:r,dense:!0}),$e.length>0&&t.jsx(Ju,{volumes:$e,unit:g.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Ce?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Ce>0&&x(`全 ${Ce} ${g.unit.bu}`)})]},`${ge}-${de}`)})})})}),(Le=e.location_history)!=null&&Le.length?t.jsx(Fe,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((L,de)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(L.name)}),([L.start_date,L.end_date].filter(Boolean).join("—")||L.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(Me,{items:[[L.start_date,L.end_date].filter(Boolean).join("—"),L.description?x(L.description):""]})})]},de))})}):null,ve.length===0&&t.jsx(Fe,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),he=y.findIndex(L=>L.id===e.id),Z=C.length<=xr,F=Z&&he>=0?y.slice(Math.max(0,he-fr),he+fr+1):y.filter(L=>L.id!==e.id),I=t.jsxs(t.Fragment,{children:[m&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:x(g.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Be,{id:m.id,label:x(m.title),onNavigate:i,renderLink:r})}),t.jsx(Me,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(m.authors||[]).slice(0,2).map(L=>`${L.dynasty?`〔${x(L.dynasty)}〕`:""}${x(L.name)}`),x(at(m,g.unit.juan)),m._edition_count?x(`${m._edition_count} 種版本`):""]}),((Ye=m.description)==null?void 0:Ye.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:x(m.description.text.replace(/[#*_>`[\]]/g,""))})]}),P>0&&F.length>0&&t.jsxs("div",{children:[t.jsx(ht,{id:"siblings",timeline:!0,title:Z?"同作品版本":g.relation.siblingVersions,meta:x(Z?"按年代":`${P} 種`),cap:F.length,items:F.map(L=>L.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(L.edition||L.title||L.id)}):t.jsx(Be,{id:L.id,label:x(L.edition||L.title||L.id),onNavigate:i,renderLink:r,dense:!0})),metas:F.map(L=>[L.year!=null?L.year<0?`前${-L.year}`:String(L.year):"",L.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:F.findIndex(L=>L.id===e.id)}),m&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Be,{id:m.id,label:x(`在作品頁看全部 ${C.length} 種 →`),onNavigate:i,renderLink:r,dense:!0})})]})]}),D=e.work_id?t.jsx(Xr,{caption:g.section.belongsToWork,children:t.jsx(Be,{id:e.work_id,label:m?x(m.title):" ",onNavigate:i,renderLink:r,dense:!0})}):void 0;return t.jsx(Zt,{railTop:c,back:d,up:D,nav:ve,railLinks:u,main:oe,card:te,side:I})};function Ju({volumes:e,unit:n}){const{convert:i}=q();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${wn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}function Zu({data:e,heading:n,yearText:i,refName:r,onNavigate:s,renderLink:l}){var h;const{convert:a}=q(),p=e.lineage,c=(p==null?void 0:p.derived_from)||[],d=c.filter(y=>y.ref_type!=="book"),u=c.filter(y=>y.ref_type==="book"&&y.relation==="底本"),g=c.filter(y=>y.ref_type==="book"&&y.relation!=="底本"),x=(p==null?void 0:p.related_to)||[],m=c.length>0||x.length>0,b=y=>y&&gr[y]?a(`(${gr[y]})`):"",S=(y,j)=>t.jsx(Be,{id:y,label:a(j||y),onNavigate:s,renderLink:l,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[m&&t.jsxs("ol",{className:"bim-d-lf-list",children:[d.map((y,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(y.relation||"祖本")}),t.jsx("span",{className:"bim-d-lf-name",children:a("擬構祖本")}),y.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[a(y.evidence),b(y.confidence)]})]})},`a-${j}`)),u.map((y,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(y.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:S(y.ref,r(y.ref))}),y.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[a(y.evidence),b(y.confidence)]})]})},`b-${j}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a("本版")}),t.jsx("span",{className:"bim-d-lf-name",children:n}),i&&t.jsx("span",{className:"bim-d-lf-yr",children:a(i)})]}),g.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:g.map((y,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(y.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:S(y.ref,r(y.ref))}),y.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[a(y.evidence),b(y.confidence)]})]},j))})]}),x.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:a("翻刻 · 衍生")}),t.jsx("span",{className:"bim-d-lf-chips",children:x.map((y,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:y.evidence?a(y.evidence):void 0,children:[S(y.book_id,r(y.book_id)),t.jsx("span",{className:"bim-d-meta",children:a(y.relation)})]},j))})]})]}),(h=e.appendix)==null?void 0:h.map((y,j)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:a("附記")})," ",a(y.title)]}),t.jsx(lt,{text:y.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${j}`)),(p==null?void 0:p.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:a(p.note)})]})}const Dt=16,Xu=200,Qu=16,sl=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,railTop:a,back:p,railLinks:c})=>{var he,Z,F,I,D,M,ne;const d=ue(),{convert:u}=q(),[g,x]=f.useState(""),[m,b]=f.useState(!1),[S,h]=f.useState(null),[y,j]=f.useState(""),[k,$]=f.useState(!1),v=f.useMemo(()=>Gr(e,n),[e,n]),[_,w]=f.useState(new Map),z=!!i&&v.rows.length>0&&v.rows.length<=Xu,N=z&&(v.rows.length<=Dt||k),T=N&&v.rows.every(R=>!R.id||_.has(R.id)),C=R=>{var J;return si(R?(J=_.get(R))==null?void 0:J.l1:void 0)},P=f.useMemo(()=>{const R=g.trim(),J=R?u(R):"";return v.rows.filter(H=>{var re,Se;if(y&&si(H.id?(re=_.get(H.id))==null?void 0:re.l1:void 0)!==y)return!1;if(!J)return!0;const U=H.id&&((Se=_.get(H.id))==null?void 0:Se.title)||H.title;return u(U).includes(J)||(H.subItems||[]).some(ye=>u(ye).includes(J))})},[v.rows,g,y,_,u]),B=m?P:P.slice(0,Dt),A=f.useMemo(()=>(N?v.rows:B).filter(R=>R.id&&!_.has(R.id)).map(R=>R.id),[N,v.rows,B,_]);f.useEffect(()=>{if(!i||A.length===0)return;let R=!1;const J=A.slice(0,Qu);return Promise.all(J.map(H=>i.getItem(H).then(U=>{var ye,Le;const re=U??{},Se={title:re.title,edition:re.edition,authors:re.authors,measure:U?at(U,d.unit.juan):void 0,versionCount:re._edition_count??((ye=re.books)==null?void 0:ye.length),l1:((Le=re.classification)==null?void 0:Le.l1)||void 0};return[H,Se]}).catch(()=>[H,{}]))).then(H=>{R||w(U=>{const re=new Map(U);for(const[Se,ye]of H)re.set(Se,ye);return re})}),()=>{R=!0}},[i,A,d.unit.juan]);const W=(e.contained_in||[])[0];f.useEffect(()=>{if(!W){h(null);return}if(h({id:W}),!i)return;let R=!1;return i.getItem(W).then(J=>{R||h({id:W,title:J==null?void 0:J.title})}).catch(()=>{}),()=>{R=!0}},[i,W]);const V=f.useMemo(()=>Xs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),K=V.text.length+V.groups.reduce((R,J)=>R+J.rows.length+J.mirrors.length,0),E=e.contained_works||[],le=new Set(v.rows.map(R=>R.id).filter(Boolean)),G=E.length>0&&!E.every(R=>le.has(R.id)),ae=(()=>{const R=v.rows.map(J=>J.edition).filter(Boolean);return R.length>1&&new Set(R).size===1})(),pe=v.rows.some(R=>R.volumes.length>0||R.expected!=null),ee=e._member_count||((he=e.books)==null?void 0:he.length)||E.length,X=at(e,d.unit.juan),ie=e.count,me=R=>typeof R=="number"&&Number.isFinite(R)?R:null,te=me(ie==null?void 0:ie.juan)??me((Z=e.juan_count)==null?void 0:Z.number),se=me(ie==null?void 0:ie.ce)??(v.totalVolumes||null),fe=[{value:v.rows.length,label:"子目"},{value:te??0,label:d.unit.juan},{value:se??0,label:d.unit.volume}],be=f.useMemo(()=>{var H,U;const R=[];if((H=e.publication_info)!=null&&H.details&&R.push({label:"刊印",value:u(e.publication_info.details)}),ee&&ee!==v.rows.length){const re=e._member_type==="Book"?"所收版本":e._member_type==="Work"?"所收作品":"成員";R.push({label:u(re),value:`${ee} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")})}const J=[me(ie==null?void 0:ie.zhong)!=null?`${ie.zhong} 種`:"",me(ie==null?void 0:ie.han)!=null?`${ie.han} 函`:""].filter(Boolean);return J.length&&R.push({label:"應收",value:u(J.join(" "))}),te==null&&X&&R.push({label:"卷帙",value:u(X),title:(U=e.juan_count)!=null&&U.description?u(e.juan_count.description):void 0}),R},[e,ee,v.rows.length,te,X,ie,u,d]),ze=f.useMemo(()=>{if(!T)return[];const R=new Map;for(const H of v.rows){const U=C(H.id);U&&R.set(U,(R.get(U)??0)+1)}const J=Yt.filter(H=>(R.get(H.key)??0)>0);return J.length<2?[]:[{key:"",label:`${d.catalog.all} ${v.rows.length}`},...J.map(H=>({key:H.key,label:`${H.label} ${R.get(H.key)}`}))]},[T,v.rows,_,d]),ve=f.useMemo(()=>{if(!T||!v.rows.some(U=>U.volumes.length>0))return null;const R=[],J=v.rows.filter(U=>U.volumes.length>0).map(U=>({k:C(U.id)??"",from:Math.min(...U.volumes),to:Math.max(...U.volumes)})).sort((U,re)=>U.from-re.from);for(const U of J){const re=U.to-U.from+1,Se=R[R.length-1];Se&&Se.key===U.k?(Se.to=Math.max(Se.to,U.to),Se.n+=re):R.push({key:U.k,from:U.from,to:U.to,n:re})}const H=J.reduce((U,re)=>Math.max(U,re.to),0);return R.length>1&&R.some(U=>U.key)?{segs:R,last:H}:null},[T,v.rows,_]),ke=(F=e.description)==null?void 0:F.text,Ne=t.jsx(Xt,{kind:"叢編",title:u(e.title),byline:t.jsx(Oi,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Me,{items:[e.subtype==="work_collection"?u("作品集"):"",(I=e.publication_info)!=null&&I.year?u(e.publication_info.year):""]}),description:ke||(D=e.history)!=null&&D.length?t.jsxs(t.Fragment,{children:[ke&&t.jsx(lt,{text:ke,style:{fontSize:15,lineHeight:1.85}}),(M=e.history)!=null&&M.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((R,J)=>t.jsx("li",{children:u(R)},J))}):null]}):void 0,clampDescription:vi(ke)||(((ne=e.history)==null?void 0:ne.length)??0)>2?6:void 0,stats:fe,facts:be,foot:t.jsx(Qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ve&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:u("全帙冊次分佈")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":u("全帙冊次分佈"),children:ve.segs.map((R,J)=>{const H=Yt.find(U=>U.key===R.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!H,title:H?u(`${H.label} 第 ${R.from}–${R.to} 冊`):void 0,"aria-label":u(H?`只看${H.label}`:"未分類"),"aria-pressed":!!H&&y===R.key,style:{flexGrow:R.n,background:o(H?H.token:"rule")},onClick:()=>{H&&(j(y===R.key?"":R.key),b(!1))}},J)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:u(`第 1 ${d.unit.volume}`)}),t.jsx("span",{children:u("點色段篩選部類")}),t.jsx("span",{children:u(`第 ${ve.last} ${d.unit.volume}`)})]})]})}),Ee=[];v.rows.length&&Ee.push({id:"titles",label:"子目",count:v.rows.length}),K&&Ee.push({id:"resources",label:"影印與全文",count:K}),G&&Ee.push({id:"works",label:d.section.containedWorks,count:E.length});const O=t.jsxs(t.Fragment,{children:[v.rows.length>0&&t.jsxs(Fe,{id:"titles",title:"子目",meta:t.jsx(Me,{items:[u(`${v.rows.length} ${d.unit.items}`),v.totalVolumes?u(`全帙 ${v.totalVolumes} ${d.unit.volume}`):"",P.length!==v.rows.length?u(`當前 ${P.length} ${d.unit.items}`):""]}),action:l,children:[(v.rows.length>Dt||ze.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ze.length>0&&t.jsx(_n,{items:ze,value:y,onChange:R=>{j(R),b(!1)}}),z&&v.rows.length>Dt&&!T&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:k,onClick:()=>$(!0),title:u(`將載入全部 ${v.rows.length} ${d.unit.items}`),children:u(k?"正在按部類分組…":"按部類分組")}),t.jsx("span",{className:"bim-d-spacer"}),v.rows.length>Dt&&t.jsx("input",{type:"search",className:"bim-d-find",value:g,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:R=>{x(R.target.value),b(!1)}})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[pe&&t.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),t.jsx("th",{children:u("書名")}),t.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),t.jsx("tbody",{children:B.map((R,J)=>{var Ye;const H=R.id?_.get(R.id):void 0,U=H!=null&&H.title&&R.title===R.id?H.title:R.title,re=((H==null?void 0:H.authors)||[]).find(L=>L&&L.name),Se=[re?`${re.dynasty?`〔${u(re.dynasty)}〕`:""}${u(re.name)}${re.role?` ${u(re.role)}`:""}`:"",H!=null&&H.measure?u(H.measure):"",(Ye=R.subItems)!=null&&Ye.length?R.subItems.map(L=>u(L)).join("、"):"",(H!=null&&H.edition||R.edition)&&!ae?u((H==null?void 0:H.edition)||R.edition||""):""].filter(Boolean),ye=Yt.find(L=>L.key===C(R.id)),Le=R.volumes.length>0?u(`第 ${wn(R.volumes,d.unit.volume)} ${d.unit.volume}`):R.expected!=null?u(`${R.found??0}/${R.expected} ${d.unit.volume}`):"";return t.jsxs("tr",{children:[pe&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Le?"":" bim-d-zt-blank"}`,children:[ye&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:o(ye.token)}}),Le||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[R.id?t.jsx(Be,{id:R.id,label:u(U),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(U)}),Se.length>0?t.jsx(Me,{items:Se}):R.id&&!H&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${H!=null&&H.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:H!=null&&H.versionCount?u(`${H.versionCount} 種`):""})]},`${R.id??R.title}-${J}`)})})]}),B.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),P.length>B.length&&t.jsx(Bt,{label:`展開其餘 ${P.length-B.length} ${d.unit.items}`,onClick:()=>b(!0)})]}),K>0&&t.jsxs(Fe,{id:"resources",title:"影印與全文",meta:u(`${K} 處`),children:[V.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[V.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:V.text.map((R,J)=>t.jsx(Di,{item:R,siblings:V.text},`${R.id||R.url||R.name}-${J}`))})})]}),t.jsx(el,{groups:V.groups})]}),v.rows.length===0&&K===0&&t.jsx(Fe,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),ce=G?t.jsx(ht,{id:"works",title:d.section.containedWorks,meta:u(`${E.length} 種`),cap:12,items:E.map(R=>t.jsx(Be,{id:R.id,label:u(R.title),onNavigate:r,renderLink:s,dense:!0}))}):null,oe=S?t.jsx(Xr,{caption:"上級叢編",children:t.jsx(Be,{id:S.id,label:u(S.title||S.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(Zt,{railTop:a,back:p,up:oe,nav:Ee,railLinks:c,main:O,card:Ne,side:ce})},ex=16,On=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function mr(e){if(!e)return On.length;const n=On.indexOf(e);return n===-1?On.length:n}const tx={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function xt(e){return e==null?"":e<0?`前${-e}`:String(e)}const nx={秦:[-221,-207],西漢:[-202,8],西汉:[-202,8],東漢:[25,220],东汉:[25,220],漢:[-202,220],汉:[-202,220],三國:[220,280],三国:[220,280],西晉:[265,316],西晋:[265,316],東晉:[317,420],东晋:[317,420],隋:[581,618],唐:[618,907],五代:[907,960],北宋:[960,1127],南宋:[1127,1279],宋:[960,1279],遼:[916,1125],辽:[916,1125],金:[1115,1234],元:[1271,1368],明:[1368,1644],清:[1636,1912]},ll=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:a})=>{var ce,oe,he,Z,F;const p=ue(),{convert:c}=q(),[d,u]=f.useState("全部"),[g,x]=f.useState(!1),[m,b]=f.useState("default"),[S,h]=f.useState(new Map),y=f.useMemo(()=>(e.works||[]).map(I=>{const D=S.get(I.work_id);return{id:I.work_id,title:(D==null?void 0:D.title)??I.title??I.work_id,role:I.role||"",cls:yi(I.role),versionCount:D==null?void 0:D.versionCount,section:D==null?void 0:D.cls,l1:D==null?void 0:D.l1,measure:D==null?void 0:D.measure,hasImage:D==null?void 0:D.hasImage,loaded:!!(D!=null&&D.loaded)}}),[e.works,S]),j=f.useMemo(()=>Hr((e.works||[]).map(I=>I.role)),[e.works]),k=f.useMemo(()=>{const I=d==="全部"?y:y.filter(D=>D.cls===d);return m==="versions"?[...I].sort((D,M)=>(M.versionCount??-1)-(D.versionCount??-1)):I},[y,d,m]),$=g?k:k.slice(0,ex),v=f.useMemo(()=>$.filter(I=>!S.has(I.id)).map(I=>I.id),[$,S]);f.useEffect(()=>{if(!n||v.length===0)return;let I=!1;return Promise.all(v.map(D=>n.getItem(D).then(M=>{var H,U,re,Se,ye;const ne=M??{},R=ne._edition_count??(((H=ne.books)==null?void 0:H.length)??0)+(((U=ne.collections)==null?void 0:U.length)??0),J=[(re=ne.classification)==null?void 0:re.l1,(Se=ne.classification)==null?void 0:Se.l2].filter(Boolean).join(" ");return[D,{id:D,title:ne.title,versionCount:R,loaded:!0,cls:J||void 0,l1:((ye=ne.classification)==null?void 0:ye.l1)||void 0,measure:M&&at(M,p.unit.juan)||void 0,hasImage:!!(ne.has_image??ne._has_image)}]}).catch(()=>[D,{id:D,loaded:!0}]))).then(D=>{I||h(M=>{const ne=new Map(M);for(const[R,J]of D)ne.set(R,J);return ne})}),()=>{I=!0}},[n,v,p.unit.juan]);const _=f.useMemo(()=>{const I=new Map;for(const D of e.alt_names||[]){const M=D.type||p.section.aliases;I.has(M)||I.set(M,[]),I.get(M).push(D.name)}return[...I.entries()].sort((D,M)=>mr(D[0])-mr(M[0])).map(([D,M])=>({label:D,names:M}))},[e.alt_names,p]),w=e.birth_year??((ce=e.dates)==null?void 0:ce.birth)??void 0,z=e.death_year??((oe=e.dates)==null?void 0:oe.death)??void 0,N=(he=e.dates)==null?void 0:he.floruit,T=w!=null||z!=null?`${xt(w)||"?"}—${xt(z)||"?"}`:Array.isArray(N)&&N.length===2&&N.every(I=>Number.isFinite(I))?`活躍於 ${xt(N[0])}—${xt(N[1])}`:"",C=new Set(["本名","字","號","号"]),P=_.filter(I=>C.has(I.label)),B=_.filter(I=>!C.has(I.label)),A=B.reduce((I,D)=>I+D.names.length,0),W=f.useMemo(()=>{const I=[];for(const M of P)I.push({label:M.label,value:M.names.map(ne=>c(ne)).join("、")});const D=(e.works||[]).length;return D&&I.push({label:"著作",value:`${D} ${c("種")}`}),I},[e.works,P,c]),V=I=>{var D;return(D=_.find(M=>I.includes(M.label)))==null?void 0:D.names[0]},K=V(["字"]),E=V(["號","号"]),le=[K?`字${K}`:"",E?`號${E}`:""].filter(Boolean).join(","),G=e.native_place,ae=e.dynasty?nx[e.dynasty]:void 0,pe=(()=>{if(!ae||w==null||z==null||z<w)return null;const[I,D]=ae,M=Math.max(w,I),ne=Math.min(z,D);if(ne<=M)return null;const R=D-I;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":c(`${xt(w)}—${xt(z)},一生 ${z-w+1} 年`),children:t.jsx("i",{style:{left:`${(M-I)/R*100}%`,width:`${(ne-M)/R*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:c(`${xt(I)} ${e.dynasty}`)}),t.jsx("span",{children:c(`一生 ${z-w+1} 年`)}),t.jsx("span",{children:xt(D)})]})]})})(),ee=f.useMemo(()=>{if(!n||y.length===0||y.some(M=>!M.loaded))return null;const I=new Map;for(const M of y){const ne=si(M.l1);ne&&I.set(ne,(I.get(ne)??0)+1)}const D=Yt.map(M=>({...M,n:I.get(M.key)??0})).filter(M=>M.n>0);return D.length?D:null},[y,n]),X=t.jsxs(Xt,{kind:tx[e.subtype]??"人物",title:c(e.primary_name||e.title),subtitle:le?c(le):void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(Me,{items:[e.dynasty?c(e.dynasty):"",T?c(T):"",G?c(`${G}人`):""]}),pe]}),description:(Z=e.description)!=null&&Z.text?t.jsx(lt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:vi((F=e.description)==null?void 0:F.text)?6:void 0,facts:W,foot:t.jsx(Qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[A>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c(`更多別名(${A})`)}),t.jsx("dl",{children:B.map(I=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:c(I.label)}),t.jsx("dd",{children:I.names.map(D=>c(D)).join("、")})]},I.label))})]}),ee&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:c("著作分佈")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:ee.map(I=>t.jsx("i",{style:{flexGrow:I.n,background:o(I.token)}},I.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ee.map(I=>t.jsxs("span",{children:[t.jsx("i",{style:{background:o(I.token)}}),c(I.label)," ",I.n]},I.key))})]})]}),ie=f.useMemo(()=>y.filter(I=>I.loaded&&(I.versionCount??0)>0).sort((I,D)=>(D.versionCount??0)-(I.versionCount??0)).slice(0,3),[y]),me=!!n&&y.length>=3&&$.some(I=>!I.loaded),te=d==="全部"&&(me||ie.length>=2),se=e.external_ids||{},fe=[];se.cbdb_id!=null&&fe.push({label:"CBDB",id:String(se.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${se.cbdb_id}`,note:se.cbdb_match==="auto"?"自動匹配":void 0});const be=se.wikidata_id;be&&fe.push({label:"Wikidata",id:be,href:`https://www.wikidata.org/wiki/${be}`});const ze=se.viaf_id;ze&&fe.push({label:"VIAF",id:ze,href:`https://viaf.org/viaf/${ze}`});const ve=j.map(I=>({key:I.cls,label:`${I.label} ${I.count}`})),ke=[...te&&!me?[{id:"featured",label:"著作舉要",count:ie.length}]:[],...y.length?[{id:"works",label:"全部著作",count:y.length}]:[],...fe.length?[{id:"external",label:"站外資料",count:fe.length}]:[]],Ne=te?t.jsxs(Fe,{id:"featured",title:"著作舉要",children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:c("存世版本最多的三部")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":me||void 0,children:[me&&[0,1,2].map(I=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},I)),!me&&ie.map(I=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Be,{id:I.id,label:c(I.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx(Me,{items:[I.section?c(I.section):"",I.measure?c(I.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:I.versionCount}),t.jsx("span",{children:c("種版本")}),I.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("有影印")})]})]},I.id))]})]}):null,Ee=y.length===0?t.jsx(Fe,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該人物的關聯作品。")})}):t.jsxs(t.Fragment,{children:[Ne,t.jsxs(Fe,{id:"works",title:"著作",meta:t.jsx(Me,{items:[c(`共 ${y.length} 種`),k.length!==y.length?c(`當前 ${k.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ve.length>1&&t.jsx(_n,{items:ve,value:d,onChange:I=>{u(I),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":m==="versions",onClick:()=>{m==="default"&&x(!0),b(I=>I==="default"?"versions":"default")},children:c(m==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("作品")}),t.jsx("th",{children:c("部類")}),t.jsx("th",{children:c("職任")}),t.jsx("th",{children:c("存世版本")}),t.jsx("th",{"aria-label":c("影印")})]})}),t.jsx("tbody",{children:$.map(I=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Be,{id:I.id,label:c(I.title),onNavigate:i,renderLink:r,dense:!0}),I.measure?t.jsx(Me,{items:[c(I.measure)]}):!I.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.section||I.loaded?"":" bim-d-zt-blank"}`,children:I.section?c(I.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.role?"":" bim-d-zt-blank"}`,children:I.role?c(I.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.loaded?"":" bim-d-zt-blank"}`,children:I.loaded?I.versionCount?c(`${I.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:c("未著錄")}):""}),t.jsx("td",{className:I.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:I.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("有影印")})})]},I.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("該職任下的著作尚未著錄。")}),k.length>$.length&&t.jsx(Bt,{label:`展開其餘 ${k.length-$.length} 種著作`,onClick:()=>x(!0)})]})]}),O=fe.length>0?t.jsx(ht,{id:"external",title:"站外資料",items:fe.map(I=>t.jsxs("a",{href:I.href,target:"_blank",rel:"noopener noreferrer",children:[I.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:fe.map(I=>I.id),foot:se.cbdb_id!=null&&se.cbdb_match==="auto"?c("CBDB 為自動匹配,未經人工核對"):void 0}):null;return t.jsx(Zt,{railTop:s,back:l,nav:ke,railLinks:a,main:Ee,card:X,side:O})},Gi="(max-width: 719px)",ix=`${Gi}, (pointer: coarse)`,al=`
789
795
  .bim-ct {
790
796
  display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
791
797
  max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
@@ -831,6 +837,10 @@ ${uc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
831
837
  .bim-ct-crumb { font-size: 13px; color: ${o("aux-fg")}; }
832
838
  .bim-ct-stat { font-size: 13px; color: ${o("aux-fg")}; }
833
839
  .bim-ct-search { margin: 0 0 16px; }
840
+ .bim-ct-view { margin-left: auto; display: inline-flex; border-radius: 6px; box-shadow: inset 0 0 0 1px ${o("rule")}; overflow: hidden; }
841
+ .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")}; }
842
+ .bim-ct-view button[aria-pressed="true"] { background: ${o("flag-bg")}; color: ${o("accent")}; font-weight: 700; }
843
+ .bim-ct-view button:focus-visible { outline: 2px solid ${o("accent")}; outline-offset: -2px; }
834
844
 
835
845
  /* ── 卡片网格 ── */
836
846
  .bim-ct-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@@ -856,6 +866,20 @@ ${uc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
856
866
  .bim-ct-cls { margin-top: auto; padding-top: 2px; font-size: 12px; color: ${o("aux-fg")}; }
857
867
  .bim-ct-empty { padding: 48px 0; text-align: center; font-size: 14px; color: ${o("aux-fg")}; }
858
868
 
869
+ /* ── 列表视图 ── */
870
+ .bim-ct-list { list-style: none; margin: 0; padding: 0; }
871
+ .bim-ct-lrow:nth-child(odd) { background: ${o("zebra-bg")}; border-radius: 6px; }
872
+ .bim-ct-lrow > a {
873
+ display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr) minmax(0, 2fr); gap: 4px 20px; align-items: baseline;
874
+ min-height: 44px; padding: 10px 14px; color: inherit; text-decoration: none; border-radius: 6px;
875
+ }
876
+ .bim-ct-lrow > a:hover { background: ${o("tint-bg")}; }
877
+ .bim-ct-lrow > a:hover .bim-ct-lt { color: ${o("accent")}; }
878
+ .bim-ct-lrow > a:focus-visible { outline: 2px solid ${o("accent")}; outline-offset: -2px; }
879
+ .bim-ct-lt { font-size: 16px; font-weight: 700; color: ${o("ink")}; overflow-wrap: anywhere; }
880
+ .bim-ct-lt .bim-ct-juan { margin-left: 8px; font-weight: 400; }
881
+ .bim-ct-lrow .bim-ct-cls { margin: 0; padding: 0; }
882
+
859
883
  /* ── 分页 ── */
860
884
  .bim-ct-pager { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px; margin: 24px 0 0; font-size: 14px; }
861
885
  .bim-ct-pager ol { display: contents; list-style: none; }
@@ -875,9 +899,11 @@ ${uc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
875
899
  .bim-ct-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
876
900
  }
877
901
 
878
- @media ${Hi} {
902
+ @media ${Gi} {
879
903
  .bim-ct { display: block; padding: 12px 16px 40px; }
880
904
  .bim-ct-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
905
+ .bim-ct-lrow > a { grid-template-columns: minmax(0, 1fr); }
906
+ .bim-ct-view button { min-height: 44px; }
881
907
  .bim-ct-side { position: static; max-height: none; overflow: visible; margin: 0 0 12px; }
882
908
  .bim-ct-side-h { display: none; }
883
909
  .bim-ct-drawer-btn {
@@ -898,9 +924,9 @@ ${uc}`;function Dt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
898
924
  }
899
925
 
900
926
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
901
- @media ${ex} {
927
+ @media ${ix} {
902
928
  .bim-ct-row { min-height: 44px; }
903
929
  .bim-ct-tw { width: 44px; }
904
930
  .bim-ct-pg { min-width: 44px; height: 44px; }
905
931
  }
906
- `,Yt="未分類",it="all",Gi=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 tx(e){const n=en(e);return n.length?n.join("/"):Yt}function nx(e){const n=en(e);return n.length?n.map((i,r)=>n.slice(0,r+1).join("/")):[Yt]}function ix(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 _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 Ui(e){return e.reduce((n,i)=>n+i.count,0)}function ox(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function rx(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=ox(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 sx(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 lx(e,n=Gi){return Math.max(1,Math.ceil(e/n))}function ll(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 ax=()=>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 cx(e,n,i){const r=[];i&&r.push({id:it,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 al({tree:e,selectedId:n,onSelect:i,allLabel:r="全部",label:s="分類"}){const{convert:l}=V(),a=f.useRef(null),p=n&&n!==it?n:null,c=r!==null,[d,u]=f.useState(()=>{const S=new Set;for(const z of _t(e,p))S.add(z.id);return S});f.useEffect(()=>{const S=_t(e,p);S.length&&u(z=>{if(S.every(C=>z.has(C.id)))return z;const w=new Set(z);for(const C of S)w.add(C.id);return w})},[e,p]);const g=f.useMemo(()=>cx(e,d,c),[e,d,c]),[x,m]=f.useState(null);f.useEffect(()=>{m(null)},[n]);const b=p??(c?it: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 z=_t(e,p).map(C=>C.id).filter(C=>S.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((S,z)=>{u(w=>{const C=w.has(S),L=z??!C;if(L===C)return w;const E=new Set(w);return L?E.add(S):E.delete(S),E})},[]),j=f.useCallback(S=>{m(S),requestAnimationFrame(()=>{var w;const z=Array.from(((w=a.current)==null?void 0:w.querySelectorAll("[data-ct-id]"))??[]).find(C=>C.dataset.ctId===S);z==null||z.focus()})},[]),y=f.useCallback((S,z)=>{z&&h(S,!0),i(S)},[i,h]),v=f.useCallback(S=>{const z=S.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 L=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(!L.hasChildren)break;d.has(w)?E=L.firstChildId:h(w,!0);break;case"ArrowLeft":L.hasChildren&&d.has(w)?h(w,!1):E=L.parentId;break;case"Enter":case" ":S.preventDefault(),y(w,L.hasChildren);return;default:return}S.preventDefault(),E&&E!==w&&j(E)},[g,d,h,j,y]),_=(S,z)=>S.map((w,C)=>{var A;const L=(A=w.children)!=null&&A.length?w.children:null,E=!!L&&d.has(w.id),T=w.id===p,O=z===1&&S.length>1&&C===S.length-1;return t.jsxs("li",{role:"treeitem","aria-level":z,"aria-expanded":L?E:void 0,"aria-selected":T,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":z-1},onClick:()=>{m(w.id),y(w.id,!!L)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:L?F=>{F.stopPropagation(),m(w.id),h(w.id)}:void 0,children:L?t.jsx(ax,{}):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:_(L,z+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===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:Ui(e).toLocaleString("en-US")})]})}),_(e,1)]})}const cl=e=>`/item/${encodeURIComponent(e)}`;function dx(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function px(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function dl({work:e,href:n}){var a,p;const{convert:i}=V(),r=px(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 pl({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&&!dx(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:ll(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 ul({works:e,workLink:n=cl,emptyText:i="此類暫無作品",...r}){const{convert:s}=V();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(dl,{work:l,href:n(l.id)},l.id))}),t.jsx(pl,{...r})]})}const ux=()=>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 xx({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=Gi,className:m}){const{convert:b}=V(),h=`bim-ct-drawer-${f.useId().replace(/:/g,"")}`,[j,y]=f.useState(!1),v=_t(e,n&&n!==it?n:null),_=v.length?v[v.length-1]:null,S=_?_.label:g,z=_?_.count:Ui(e),w=f.useCallback(C=>{y(!1),l(C)},[l]);return t.jsxs("div",{className:m?`bim-ct ${m}`:"bim-ct","data-drawer":j?"open":"closed",children:[t.jsx("style",{children:sl}),t.jsxs("aside",{className:"bim-ct-side","aria-label":b("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":j,"aria-controls":h,onClick:()=>y(C=>!C),children:[t.jsxs("span",{children:[b("分類"),":",b(v.length?v.map(C=>C.label).join(" › "):u??g)]}),t.jsx(ux,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:h,children:[t.jsx("h2",{className:"bim-ct-side-h",children:b("分類")}),t.jsx(al,{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(S)}),v.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:b(v.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(ul,{works:s,workLink:c,page:i,pageCount:r,onPage:a,pageHref:d})]})]})}const 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 fx(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const gx=({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:j,enrichDetail:y,getSourceLink:v,readLink:_,railTop:S,extraTabs:z=[],showFeedbackTab:w=!0,feedbackApiUrl:C,height:L,footerExtra:E,className:T,style:O})=>{var Ki;const A=ce(),{convert:F}=V(),[M]=f.useState(()=>{if(!fx(e,i))return null;const U={...i},he=r??On(e,U);return y&&y(he,U),{id:e,entry:he,detail:U}}),[Y,K]=f.useState((M==null?void 0:M.entry)??null),[R,ie]=f.useState((M==null?void 0:M.detail)??null),[H,oe]=f.useState(!M),[ee,Q]=f.useState(!1),[G,ae]=f.useState([]),[ue,re]=f.useState(!1),[te,fe]=f.useState(null),[de,Te]=f.useState(!1),[be,ze]=f.useState(null),[Ce,Ee]=f.useState(!1),[D,se]=f.useState(null),[ne,ge]=f.useState([]),[q,N]=f.useState(!1),[I,$]=f.useState(null),[P,W]=f.useState(null),[Z,J]=f.useState(!1),me=f.useRef(null),[we,_e]=f.useState(null),Ne=a!==void 0?a:we,Re=f.useCallback(U=>{p?p(U):_e(U)},[p]),Lt=f.useCallback(async U=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){ae([]);return}re(!0);try{if(n.getCollectionCatalogs)ae(await n.getCollectionCatalogs(U)||[]);else if(n.getCollectionCatalog){const he=await n.getCollectionCatalog(U);ae(he?[{resource_id:"",data:he}]:[])}}catch{ae([])}finally{re(!1)}},[n]),Bt=f.useCallback(async U=>{if(!n.getCollatedEditionIndex){fe(null);return}Te(!0);try{fe(await n.getCollatedEditionIndex(U))}catch{fe(null)}finally{Te(!1)}},[n]),B=f.useCallback(async U=>{if(!n.getBookFullTextIndex){ze(null);return}Ee(!0);try{ze(await n.getBookFullTextIndex(U))}catch{ze(null)}finally{Ee(!1),se(U)}},[n]),le=f.useCallback(async U=>{var he;if(!n.getWorkFullTextList){ge([]);return}N(!0);try{const Se=(await n.getWorkFullTextList(U)??[]).filter(Be=>Be.owner_type!=="Book");ge(Se),$(((he=Se.find(Be=>Be.primary)??Se[0])==null?void 0:he.key)??null)}catch{ge([])}finally{N(!1)}},[n]),xe=f.useCallback(async(U,he)=>{J(!0);try{if(n.getLineageGraph){const Oe=await n.getLineageGraph(U);Oe&&W(Oe)}const Se=he.version_graph;if(!Se||!Se.enabled){P||W(null),me.current=null;return}const Be=he.books??[],Je=[];for(const Oe of Be)try{const Ze=await n.getItem(Oe);Ze&&Je.push(Ze)}catch{}me.current={work:he,books:Je};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";W(un(he,Je,$e))}catch{W(null),me.current=null}finally{J(!1)}},[n]),ve=f.useRef({initialDetail:i,initialEntry:r});ve.current={initialDetail:i,initialEntry:r},f.useEffect(()=>{let U=!1;const he=X=>{X.type==="collection"?Lt(e):X.type==="work"?(X.has_collated&&Bt(e),(X.version_graph||n.getLineageGraph)&&xe(e,X),n.getWorkFullTextList&&le(e)):X.type==="book"&&X.has_full_text&&n.getBookFullTextIndex&&B(e)},Se=ve.current;let Be=null;if(M&&M.id===e)Be=M;else if(Se.initialDetail&&Se.initialDetail.id===e){const X={...Se.initialDetail},$e=Se.initialEntry??On(e,X);y&&y($e,X),Be={entry:$e,detail:X}}return Be?(Q(!1),ae(X=>X.length?[]:X),fe(null),ze(null),ge(X=>X.length?[]:X),$(null),W(null),me.current=null,K(Be.entry),ie(Be.detail),oe(!1),he(Be.detail),()=>{U=!0}):((async()=>{oe(!0),Q(!1),K(null),ie(null),ae([]),fe(null),ze(null),ge([]),$(null),W(null),me.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),ie($e),he($e)}catch{U||Q(!0)}finally{U||oe(!1)}})(),()=>{U=!0})},[e,n,M,y,Lt,Bt,xe,B,le]),f.useEffect(()=>{const U=me.current;!U||!u||W(un(U.work,U.books,u))},[u]);const pe=[];if(R){if(pe.push({key:"basic",label:A.detailTab.basicInfo}),R.type==="collection"){ue&&G.length===0&&pe.push({key:"catalog:loading",label:`${A.detailTab.catalog}…`});for(const U of G)pe.push({key:`catalog:${U.resource_id}`,label:U.short_name?`${F(U.short_name)}${A.detailTab.catalogSuffix}`:A.detailTab.collectionCatalog})}R.type==="work"&&(te||de)&&s==="collated"&&pe.push({key:"collated",label:de?`${A.detailTab.collatedEdition}…`:A.detailTab.collatedEdition}),R.type==="book"&&(be||Ce)&&s==="fulltext"&&pe.push({key:"fulltext",label:Ce?`${A.detailTab.fullText}…`:A.detailTab.fullText}),R.type==="work"&&(ne.length>0||q)&&s==="fulltext"&&pe.push({key:"fulltext",label:q?`${A.detailTab.fullText}…`:A.detailTab.fullText}),R.type==="work"&&(P||Z)&&pe.push({key:"lineage",label:Z?`${A.detailTab.lineage}…`:A.detailTab.lineage});for(const U of z)(U.position??"before-feedback")==="before-feedback"&&U.shouldShow(R)&&pe.push({key:U.key,label:U.label});w&&s==="feedback"&&pe.push({key:"feedback",label:A.detailTab.feedback});for(const U of z)U.position==="after-feedback"&&U.shouldShow(R)&&pe.push({key:U.key,label:U.label})}f.useEffect(()=>{if(s!=="emendated"||!R)return;l("basic");const U=setTimeout(()=>{var he;(he=document.getElementById("studies"))==null||he.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(U)},[s,R,l]);const ke=Y&&R&&v?v({activeTab:s,activeJuan:Ne,entry:Y,detail:R}):null,Pe=f.useMemo(()=>{var Je;if(!R)return null;const he=(R.authors??[]).map(X=>{const $e=yi(X.role);return`${X.dynasty?`〔${F(X.dynasty)}〕`:""}${F(X.name)}${$e?` ${F($e)}`:""}`}).join(" · ");let Se=!1;try{Se=ye.extractStatus(R.id)==="draft"}catch{}if(R.type==="book"){const X=R;return{title:F(X.title),subtitle:X.edition?F(X.edition):he||void 0,aside:[Se?A.status.draft:"",he&&X.edition?he:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(R.type==="collection"){const X=R;return{title:F(X.title),subtitle:F(st(X,A.unit.juan))||void 0,aside:[(Je=X.publication_info)==null?void 0:Je.year,Se?A.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:he||void 0}}if(R.type==="entity"){const X=R,$e=Ze=>Ze==null?"":Ze<0?`前${-Ze}`:String(Ze),Oe=X.birth_year!=null||X.death_year!=null?`${$e(X.birth_year)||"?"}—${$e(X.death_year)||"?"}`:"";return{title:F(X.primary_name||X.title),subtitle:[X.dynasty?`〔${F(X.dynasty)}〕`:"",Oe].filter(Boolean).join(" ")||void 0,aside:Se?A.status.draft:void 0,secondLine:void 0}}const Be=F(st(R,A.unit.juan));return{title:F(R.title),subtitle:[Be,he].filter(Boolean).join(" · ")||void 0,aside:[hx(A,R.subtype),Se?A.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[R,F,A]),Ke=R?R.type==="work"?(((Ki=te==null?void 0:te.juan_files)==null?void 0:Ki.length)??0)>0?"collated":ne.length>0?"fulltext":null:R.type==="book"&&(((be==null?void 0:be.chapters.length)??0)>0||R.has_full_text&&n.getBookFullTextIndex&&D!==R.id)?"fulltext":null:null,lt=ne.find(U=>U.primary)??ne[0],tn=()=>{var U;Ke==="collated"&&((U=te==null?void 0:te.juan_files)!=null&&U.length)?(Re(te.juan_files[0]),l("collated")):Ke==="fulltext"&&((R==null?void 0:R.type)==="work"&&lt&&$(lt.key),Re(null),l("fulltext"))};let at=null;if(R&&_){const U=_({detail:R,kind:Ke,fullTextKey:R.type==="work"?lt==null?void 0:lt.key:void 0});U&&(at=t.jsx(Kn,{href:U}))}else Ke&&(at=t.jsx(Kn,{onClick:tn}));const nn=U=>{if(!R)return null;const he=U.replace(/\.[^.]+$/,"");if(_){const Se=_({detail:R,kind:"fulltext",juan:he});return Se?{href:Se}:null}return{onClick:()=>{Re(he),l("fulltext")}}},on=new Set(z.map(U=>U.key)),je=pe.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)})),qe=()=>{var U;return R?R.type==="work"?t.jsx(Qs,{data:R,transport:n,onNavigate:b,renderLink:j,readAction:at,railTop:S,railLinks:je}):R.type==="book"?t.jsx(il,{data:R,transport:n,onNavigate:b,renderLink:j,readAction:at,fullText:be,fullTextPending:!!R.has_full_text&&!!n.getBookFullTextIndex&&D!==R.id,chapterLink:nn,railTop:S,railLinks:je}):R.type==="collection"?t.jsx(ol,{data:R,catalog:(U=G[0])==null?void 0:U.data,transport:n,onNavigate:b,renderLink:j,readAction:at,railTop:S,railLinks:je,catalogAction:G.length>0?t.jsxs("a",{href:"#catalog",onClick:he=>{he.preventDefault(),l(`catalog:${G[0].resource_id}`)},children:[F(A.detailTab.collectionCatalog)," →"]}):null}):t.jsx(rl,{data:R,transport:n,onNavigate:b,renderLink:j,railTop:S,railLinks:je}):null},Ie=()=>{var he,Se,Be,Je;if(!Y||!R)return null;if(s==="basic"||s==="emendated")return qe();if(typeof s=="string"&&s.startsWith("catalog:")){const X=(he=G.find($e=>`catalog:${$e.resource_id}`===s))==null?void 0:he.data;return t.jsx(fi,{data:X,onNavigate:b,renderLink:j})}if(s==="collated")return t.jsx(Mi,{index:te||void 0,workId:e,transport:n,onNavigate:b,activeJuan:Ne,onJuanChange:Re});if(s==="fulltext"&&R.type==="work"){const X=I??((Se=ne[0])==null?void 0:Se.key);return X?t.jsx(ti,{bookId:e,workKey:X,versions:ne,onVersionChange:$e=>{$($e),Re(null)},transport:n,activeChapter:Ne,onChapterChange:Re},X):t.jsx("div",{style:{padding:24,color:o("desc-fg")},children:q?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(ti,{index:be||void 0,bookId:e,transport:n,activeChapter:Ne,onChapterChange:Re});if(s==="lineage"){if(!P)return t.jsx("div",{style:{color:o("label-fg"),padding:"24px 0"},children:Z?"加載中…":"暫無版本圖數據"});const X=R.type==="work"?R:null;return t.jsx(Di,{graph:P,renderLink:j,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:(Je=X==null?void 0:X.version_graph)==null?void 0:Je.collections,collectionCounts:(()=>{var qi,Ji,Zi,Xi,Qi,eo,to;if(!X)return;const $e={},Oe=((qi=me.current)==null?void 0:qi.books)??[];$e.all=(((Ji=X.books)==null?void 0:Ji.length)??0)-(((Xi=(Zi=X.version_graph)==null?void 0:Zi.excluded_books)==null?void 0:Xi.length)??0);const Ze=(Qi=X.version_graph)==null?void 0:Qi.collections;if(Ze)for(const no of Object.keys(Ze))$e[no]=un(X,Oe,no).nodes.filter(io=>io.kind==="book"&&!io.bridge).length;return $e.core==null&&((to=(eo=X.version_graph)==null?void 0:eo.core_books)!=null&&to.length)&&($e.core=X.version_graph.core_books.length),$e})()})}if(s==="feedback"&&w)return t.jsx(qs,{resourceId:e,apiUrl:C});const U=z.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:L,...O},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((U,he)=>t.jsx("div",{style:{height:he===1?40:16,width:U,opacity:.35,background:o("rule")}},he))})});if(ee||!R||!Y||!Pe)return t.jsx(Dt,{style:{minHeight:L,...O},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:o("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const jt=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",Vi=typeof E=="string"?A.status[E.trim()]??E:E,Yi=t.jsx(as,{left:t.jsxs(t.Fragment,{children:[Vi,Vi?" · ":"",t.jsx(mx,{id:R.id,label:A.label.id,copied:A.action.copied,copyLabel:A.action.copy})]}),right:t.jsxs(t.Fragment,{children:[w&&!jt&&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}),ke&&t.jsx("a",{href:ke.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:o("meta-fg")},children:A.detailTab.dataLicense})]})});return jt?t.jsx("div",{className:T,children:t.jsxs(Dt,{grid:!0,style:{minHeight:L,...O},children:[t.jsx(qn,{breadcrumb:t.jsx(Jn,{items:rn}),actions:t.jsxs(t.Fragment,{children:[t.jsx(si,{style:{border:"none",background:"transparent"}}),ke&&t.jsx(li,{...ke})]})}),qe(),Yi]})}):t.jsx("div",{className:T,children:t.jsxs(Dt,{wide:sn,style:{minHeight:L,...O},children:[t.jsx(qn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(vi,{char:"籍"}),t.jsx(Jn,{items:rn})]}),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:A.detailTab.feedback}),ke&&t.jsx(li,{...ke})]})}),t.jsx(Qr,{...Pe,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:[F("作品信息")," →"]}):Pe.aside}),!sn&&pe.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:pe.map(U=>t.jsx(es,{label:U.label,active:U.key===s||jt&&U.key==="basic",onClick:()=>l(U.key)},U.key))}),t.jsx("div",{style:{marginTop:!sn&&pe.length>1?8:0},children:Ie()}),Yi]})})};function mx({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 hx(e,n){return n?e.workSubtype[n]??n:""}const xl=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛藍"}],$n="zhusha",zn="bim-theme";function fl(e){return e==="zhusha"||e==="indigo"}function Cn(e){return fl(e)?e:$n}function bx(){try{return Cn(window.localStorage.getItem(zn))}catch{return $n}}function gl(e){try{window.localStorage.setItem(zn,e)}catch{}}function ml(e){const n=Cn(e);return document.documentElement.setAttribute("data-theme",n),n}function hl(){return Cn(document.documentElement.getAttribute("data-theme"))}const yx=`try{if(localStorage.getItem(${JSON.stringify(zn)})==='indigo')document.documentElement.setAttribute('data-theme','indigo')}catch(e){}`,jx={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo"},vx=({onChange:e,style:n})=>{const{convert:i}=V(),[r,s]=f.useState($n);f.useEffect(()=>{s(hl())},[]);const l=a=>{s(ml(a)),gl(a),e==null||e(a)};return t.jsx("div",{role:"radiogroup","aria-label":i("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:xl.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(jx[a.name]),boxShadow:p?`0 0 0 2px ${o("page-bg")}, 0 0 0 3.5px ${o("aux-fg")}`:"none"}})},a.name)})})};exports.BidLink=ye.BidLink;exports.BookIndexError=ye.BookIndexError;exports.BookIndexManager=ye.BookIndexManager;exports.BookIndexStorage=ye.BookIndexStorage;exports.BundleStorage=ye.BundleStorage;exports.ConfigError=ye.ConfigError;exports.GithubStorage=ye.GithubStorage;exports.IdGenerationError=ye.IdGenerationError;exports.IdGenerator=ye.IdGenerator;exports.LocalStorage=ye.LocalStorage;exports.MigrationError=ye.MigrationError;exports.StorageError=ye.StorageError;exports.base36Decode=ye.base36Decode;exports.base36Encode=ye.base36Encode;exports.base58Decode=ye.base58Decode;exports.buildId=ye.buildId;exports.buildPromotionMap=ye.buildPromotionMap;exports.cleanName=ye.cleanName;exports.decodeId=ye.decodeId;exports.decodeIdString=ye.decodeIdString;exports.encodeId=ye.encodeId;exports.extractIdFromUrl=ye.extractIdFromUrl;exports.extractStatus=ye.extractStatus;exports.extractType=ye.extractType;exports.normalizeCatalog=ye.normalizeCatalog;exports.parseId=ye.parseId;exports.shardOf=ye.shardOf;exports.smartDecode=ye.smartDecode;exports.validateResource=ye.validateResource;exports.Badge=mn;exports.BidUrlProvider=Cl;exports.BookDetailLayout=gx;exports.BookFullText=ti;exports.BookPage=il;exports.Breadcrumb=Jn;exports.CATALOG_ALL_ID=it;exports.CATALOG_CSS=sl;exports.CATALOG_NARROW_QUERY=Hi;exports.CATALOG_PAGE_SIZE=Gi;exports.CATALOG_UNCLASSIFIED_ID=Yt;exports.CardFoot=Xt;exports.CatalogPage=xx;exports.CatalogPager=pl;exports.CatalogTree=al;exports.CheckFilter=Zr;exports.Chip=ts;exports.ChipWall=vc;exports.CollatedEdition=Mi;exports.CollectionCatalog=fi;exports.CollectionPage=ol;exports.CreateEntityDialog=Os;exports.DEFAULT_READER_PREFS=wi;exports.DEFAULT_THEME=$n;exports.DETAIL_CSS=Xr;exports.Dash=zc;exports.DataTable=Sc;exports.DetailFooter=as;exports.DetailGrid=Jt;exports.DetailHeader=Qr;exports.EmendatedBySection=Nr;exports.EmptyNote=Lc;exports.EntityDetail=zr;exports.EntityPage=rl;exports.EntityPickerDialog=Hs;exports.EntitySelector=Ps;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=Ys;exports.FeedbackForm=Ks;exports.FeedbackList=Fi;exports.FeedbackTab=qs;exports.FilterChip=es;exports.FormInput=He;exports.FormTextArea=mt;exports.GUJI_MARKDOWN_FIELD=ic;exports.GUJI_TABLE_NOTATION=ys;exports.GlyphBadge=vi;exports.GujiTable=Ci;exports.HomePage=ei;exports.ImagePanel=fs;exports.IndexApp=ap;exports.IndexBrowser=Gn;exports.IndexDetail=xi;exports.IndexEditor=Gs;exports.IndexView=Gp;exports.IntroGrid=mc;exports.LocaleContext=Tt;exports.LocaleProvider=Dl;exports.LocaleToggle=si;exports.MetaLine=We;exports.ModeIndicator=wr;exports.MoreButton=jc;exports.MoreLink=Nt;exports.PAGE_MAX_WIDTH=dn;exports.PageFrame=Dt;exports.Quote=Tc;exports.READER_CSS=ps;exports.RECENT_IDS_STORAGE_KEY=$t;exports.ROLE_CLASS_ORDER=Pr;exports.ReadButton=Kn;exports.ReaderMdText=Ri;exports.ReaderShell=$i;exports.ReaderToc=xs;exports.RelationPanel=Ms;exports.RepoSourceLink=li;exports.ResourceEditor=Hn;exports.ResourceGroup=Ec;exports.ResourceLine=Rc;exports.ResourceList=ui;exports.ResourceRow=ss;exports.SNIPPET_MARK_END=hr;exports.SNIPPET_MARK_START=mr;exports.SearchInput=_r;exports.Sec=Me;exports.Section=Ve;exports.SectionHead=bc;exports.SideList=gt;exports.SmartBidInput=pn;exports.SourceEditor=Bs;exports.SummaryCard=Zt;exports.THEMES=xl;exports.THEME_INIT_SCRIPT=yx;exports.THEME_STORAGE_KEY=zn;exports.TabFilter=Sn;exports.TableHead=wc;exports.TableRow=_c;exports.TagRow=ls;exports.TagRows=Nc;exports.TextButton=yc;exports.ThemeToggle=vx;exports.TopStrip=qn;exports.VersionLineageGraph=nl;exports.VersionLineageList=tl;exports.VersionLineageView=Di;exports.VolumeChips=kc;exports.VolumeLinks=ki;exports.WorkCard=dl;exports.WorkCardGrid=ul;exports.WorkCatalog=cp;exports.WorkPage=Qs;exports.applyTheme=ml;exports.bucketResources=hi;exports.buildCatalogTree=ix;exports.buildCollectionTable=Dr;exports.buildLineageGraph=un;exports.buildPageUrl=pi;exports.buildParagraphBlocks=zs;exports.buildVersionRow=Mr;exports.buildVersionTable=Fr;exports.canParagraphize=_n;exports.catalogNodeIdOf=tx;exports.catalogNodeIdsOf=nx;exports.catalogPageCount=lx;exports.catalogTotal=Ui;exports.classificationPath=en;exports.compareCatalogCards=sx;exports.computeVersionPartition=Qa;exports.currentTheme=hl;exports.defaultWorkLink=cl;exports.deriveDating=Ja;exports.deriveEditionType=Gr;exports.deriveEra=qt;exports.deriveYear=jn;exports.deriveYearRange=mi;exports.detailToEditor=Vs;exports.detectGenre=wn;exports.displayAuthorRole=yi;exports.editorToDetail=Hp;exports.eraRank=Vn;exports.findCatalogPath=_t;exports.flattenTitles=Zn;exports.flattenToc=bs;exports.formatTemplate=Kt;exports.formatVolumeRange=kn;exports.getDisplayNameFromUrl=Et;exports.getStartPage=di;exports.getTypeGroupKey=ai;exports.groupRelatedWorks=Za;exports.gujiInlineToPlain=Kr;exports.hasGujiMarkdownV02=Yn;exports.hasGujiTableNotation=js;exports.isThemeName=fl;exports.measureText=st;exports.mergeVolumeResources=ci;exports.normalizeEra=Ae;exports.normalizeRole=bi;exports.normalizeTheme=Cn;exports.normalizeVolumeIndex=Gt;exports.normalizeVolumes=Sr;exports.numberToChinese=Hr;exports.paginationItems=ll;exports.parseChineseNumber=xn;exports.parseGujiInline=Yr;exports.parseGujiTable=ks;exports.parseSourceString=As;exports.pickReaderVersion=hs;exports.readStoredTheme=bx;exports.readerVersionOptionLabel=Qn;exports.readerVersionsFromFullText=ms;exports.renderFullTextBody=od;exports.renderProperNames=Is;exports.renderReaderInline=Ei;exports.resourceHref=Rt;exports.resourceNote=vn;exports.roleFacets=Or;exports.rowNo=$c;exports.sortYear=fn;exports.splitFullTextTables=zi;exports.splitHighlightSnippet=br;exports.splitTableRow=vs;exports.storeTheme=gl;exports.stringifySources=Ws;exports.toCatalogWorkCard=rx;exports.useBidUrl=Fe;exports.useConvert=V;exports.useReaderPrefs=_i;exports.useT=ce;exports.validateLineageGraph=wu;exports.volumeStats=hn;
932
+ `,qt="未分類",rt="all",Ui=20;function tn(e){if(!e)return[];const n=[];for(const i of[e.l1,e.l2,e.l3,e.l4]){const r=(i??"").trim();if(!r)break;n.push(r)}return n}function ox(e){const n=tn(e);return n.length?n.join("/"):qt}function rx(e){const n=tn(e);return n.length?n.map((i,r)=>n.slice(0,r+1).join("/")):[qt]}function sx(e,n=[]){const i=new Map;n.forEach((p,c)=>{const d=[p.cata_l1,p.cata_l2,p.cata_l3,p.cata_l4].filter(u=>!!u);d.forEach((u,g)=>{const x=d.slice(0,g+1).join("/");i.has(x)||i.set(x,c)})});const r=new Map;let s=0;for(const p of e){const c=tn(p.classification);if(!c.length){s++;continue}let d=r;c.forEach((u,g)=>{const x=c.slice(0,g+1).join("/");let m=d.get(u);m||(m={id:x,label:u,count:0,children:new Map},d.set(u,m)),m.count++,d=m.children})}const l=p=>[...p.values()].sort((c,d)=>{const u=i.get(c.id)??1/0,g=i.get(d.id)??1/0;return u!==g?u-g:c.label.localeCompare(d.label,"zh")}).map(c=>{const d={id:c.id,label:c.label,count:c.count};return c.children.size&&(d.children=l(c.children)),d}),a=l(r);return s>0&&a.push({id:qt,label:qt,count:s}),a}function zt(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const r=zt(i.children,n);if(r.length)return[i,...r]}}return[]}function Vi(e){return e.reduce((n,i)=>n+i.count,0)}function lx(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function ax(e){var p;const n={id:e.id,title:e.title||e.id},i=e.juan_count,r=typeof i=="number"?i:i==null?void 0:i.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(c=>c==null?void 0:c.name).map(c=>{const d=c.dynasty||(e.authors.length===1?e.dynasty:void 0);return d?{name:c.name,dynasty:d}:{name:c.name}});s.length&&(n.authors=s);const l=lx(typeof e.description=="string"?e.description:(p=e.description)==null?void 0:p.text);l&&(n.summary=l);const a=tn(e.classification);return a.length&&(n.classification=a),n}function cx(e,n){const i=e.summary?0:1,r=n.summary?0:1;return i!==r?i-r:e.title.localeCompare(n.title,"zh")}function dx(e,n=Ui){return Math.max(1,Math.ceil(e/n))}function cl(e,n,i=2){if(n<=1)return[1];const r=new Set([1,n]);for(let a=e-i;a<=e+i;a++)a>=1&&a<=n&&r.add(a);const s=[...r].sort((a,p)=>a-p),l=[];return s.forEach((a,p)=>{if(p>0){const c=a-s[p-1];c===2?l.push(a-1):c>2&&l.push(null)}l.push(a)}),l}const px=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function ux(e,n,i){const r=[];i&&r.push({id:rt,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,a)=>{var p;for(const c of l){const d=(p=c.children)!=null&&p.length?c.children:null;r.push({id:c.id,parentId:a,hasChildren:!!d,firstChildId:d?d[0].id:null}),d&&n.has(c.id)&&s(d,c.id)}};return s(e,null),r}function dl({tree:e,selectedId:n,onSelect:i,allLabel:r="全部",label:s="分類"}){const{convert:l}=q(),a=f.useRef(null),p=n&&n!==rt?n:null,c=r!==null,[d,u]=f.useState(()=>{const v=new Set;for(const _ of zt(e,p))v.add(_.id);return v});f.useEffect(()=>{const v=zt(e,p);v.length&&u(_=>{if(v.every(z=>_.has(z.id)))return _;const w=new Set(_);for(const z of v)w.add(z.id);return w})},[e,p]);const g=f.useMemo(()=>ux(e,d,c),[e,d,c]),[x,m]=f.useState(null);f.useEffect(()=>{m(null)},[n]);const b=p??(c?rt:null),S=f.useMemo(()=>{var w;const v=new Set(g.map(z=>z.id));if(x&&v.has(x))return x;if(b&&v.has(b))return b;const _=zt(e,p).map(z=>z.id).filter(z=>v.has(z));return _.length?_[_.length-1]:((w=g[0])==null?void 0:w.id)??null},[g,x,b,e,p]),h=f.useCallback((v,_)=>{u(w=>{const z=w.has(v),N=_??!z;if(N===z)return w;const T=new Set(w);return N?T.add(v):T.delete(v),T})},[]),y=f.useCallback(v=>{m(v),requestAnimationFrame(()=>{var w;const _=Array.from(((w=a.current)==null?void 0:w.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===v);_==null||_.focus()})},[]),j=f.useCallback((v,_)=>{_&&h(v,!0),i(v)},[i,h]),k=f.useCallback(v=>{const _=v.target.closest("[data-ct-id]");if(!_)return;const w=_.dataset.ctId,z=g.findIndex(C=>C.id===w);if(z<0)return;const N=g[z];let T=null;switch(v.key){case"ArrowDown":T=g[Math.min(g.length-1,z+1)].id;break;case"ArrowUp":T=g[Math.max(0,z-1)].id;break;case"Home":T=g[0].id;break;case"End":T=g[g.length-1].id;break;case"ArrowRight":if(!N.hasChildren)break;d.has(w)?T=N.firstChildId:h(w,!0);break;case"ArrowLeft":N.hasChildren&&d.has(w)?h(w,!1):T=N.parentId;break;case"Enter":case" ":v.preventDefault(),j(w,N.hasChildren);return;default:return}v.preventDefault(),T&&T!==w&&y(T)},[g,d,h,y,j]),$=(v,_)=>v.map((w,z)=>{var B;const N=(B=w.children)!=null&&B.length?w.children:null,T=!!N&&d.has(w.id),C=w.id===p,P=_===1&&v.length>1&&z===v.length-1;return t.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":N?T:void 0,"aria-selected":C,tabIndex:S===w.id?0:-1,"data-ct-id":w.id,className:P?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{m(w.id),j(w.id,!!N)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:N?A=>{A.stopPropagation(),m(w.id),h(w.id)}:void 0,children:N?t.jsx(px,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(w.label)}),t.jsx("span",{className:"bim-ct-n",children:w.count.toLocaleString("en-US")})]}),T&&t.jsx("ul",{role:"group",children:$(N,_+1)})]},w.id)});return t.jsxs("ul",{ref:a,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:k,children:[c&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:S===rt?0:-1,"data-ct-id":rt,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{m(rt),i(rt)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),t.jsx("span",{className:"bim-ct-lb",children:l(r)}),t.jsx("span",{className:"bim-ct-n",children:Vi(e).toLocaleString("en-US")})]})}),$(e,1)]})}const pl=e=>`/item/${encodeURIComponent(e)}`;function xx(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function ul(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function xl({work:e,href:n}){var a,p;const{convert:i}=q(),r=ul(e.juan),s=((a=e.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:n,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:i(e.title)}),r&&t.jsx("span",{className:"bim-ct-juan",children:i(r)})]}),s.length>0&&t.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>t.jsxs(f.Fragment,{children:[d>0&&"、",c.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(c.dynasty),"〕"]}),i(c.name)]},d))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:i(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(c=>i(c)).join(" · ")})]})})}function fl({work:e,href:n}){var a,p;const{convert:i}=q(),r=ul(e.juan),s=((a=e.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-lrow",children:t.jsxs("a",{href:n,children:[t.jsxs("span",{className:"bim-ct-lt",children:[i(e.title),r&&t.jsx("span",{className:"bim-ct-juan",children:i(r)})]}),t.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>t.jsxs(f.Fragment,{children:[d>0&&"、",c.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(c.dynasty),"〕"]}),i(c.name)]},d))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(c=>i(c)).join(" · ")})]})})}function gl({page:e,pageCount:n,onPage:i,pageHref:r,label:s="分頁"}){const{convert:l}=q();if(n<=1)return null;const a=c=>d=>{i&&(r&&!xx(d)||(d.preventDefault(),i(c)))},p=(c,d,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const g={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...g,href:r(c),onClick:a(c),children:d}):t.jsx("button",{type:"button",...g,onClick:u.current?void 0:a(c),children:d})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:cl(e,n).map((c,d)=>t.jsx("li",{style:{display:"contents"},children:c===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(c,c,{current:c===e,aria:l(`第 ${c} 頁`)})},c??`gap${d}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),p(e+1,l("下一頁"),{disabled:e>=n})]})}function ml({works:e,workLink:n=pl,emptyText:i="此類暫無作品",view:r="card",...s}){const{convert:l}=q();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:typeof i=="string"?l(i):i}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(a=>t.jsx(fl,{work:a,href:n(a.id)},a.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(a=>t.jsx(xl,{work:a,href:n(a.id)},a.id))}),t.jsx(gl,{...s})]})}const fx=()=>t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:t.jsx("path",{d:"M2.5 4.5 6 8l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function gx({tree:e,selectedId:n,page:i,pageCount:r,works:s,onSelect:l,onPage:a,searchSlot:p,workLink:c,pageHref:d,allLabel:u="全部",allTitle:g="全部典籍",pageSize:x=Ui,className:m,view:b,onViewChange:S}){const{convert:h}=q(),j=`bim-ct-drawer-${f.useId().replace(/:/g,"")}`,[k,$]=f.useState(!1),[v,_]=f.useState("card"),w=b??v,z=A=>{_(A),S==null||S(A)},N=zt(e,n&&n!==rt?n:null),T=N.length?N[N.length-1]:null,C=T?T.label:g,P=T?T.count:Vi(e),B=f.useCallback(A=>{$(!1),l(A)},[l]);return t.jsxs("div",{className:m?`bim-ct ${m}`:"bim-ct","data-drawer":k?"open":"closed",children:[t.jsx("style",{children:al}),t.jsxs("aside",{className:"bim-ct-side","aria-label":h("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":k,"aria-controls":j,onClick:()=>$(A=>!A),children:[t.jsxs("span",{children:[h("分類"),":",h(N.length?N.map(A=>A.label).join(" › "):u??g)]}),t.jsx(fx,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:j,children:[t.jsx("h2",{className:"bim-ct-side-h",children:h("分類")}),t.jsx(dl,{tree:e,selectedId:n,onSelect:B,allLabel:u})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:h(C)}),N.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:h(N.slice(0,-1).map(A=>A.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[h(`共 ${P.toLocaleString("en-US")} 種 · 每頁 ${x} 條`),r>1&&h(` · 第 ${i} / ${r} 頁`)]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":h("呈現方式"),children:[t.jsx("button",{type:"button","aria-pressed":w==="card",onClick:()=>z("card"),children:h("卡片")}),t.jsx("button",{type:"button","aria-pressed":w==="list",onClick:()=>z("list"),children:h("列表")})]})]}),p&&t.jsx("div",{className:"bim-ct-search",children:p}),t.jsx(ml,{works:s,view:w,workLink:c,page:i,pageCount:r,onPage:a,pageHref:d})]})]})}const li=({style:e})=>{const n=f.useContext(Rt);if(!n)return null;const{locale:i,setLocale:r}=n,s=i==="zh-Hant",l=()=>r(s?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:`1px solid ${o("border")}`,borderRadius:"4px",background:o("bg"),color:o("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:s?o("primary"):void 0,fontWeight:s?700:400},children:"繁"}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:s?void 0:o("primary"),fontWeight:s?400:700},children:"简"})]})},ai=({href:e,label:n="在 GitHub 查看本条目源文件",size:i=16,className:r,style:s})=>t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:o("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:l=>{l.currentTarget.style.color=o("fg")},onMouseLeave:l=>{l.currentTarget.style.color=o("desc-fg")},children:t.jsx("svg",{width:i,height:i,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:t.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})});function Dn(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function mx(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const hx=({id:e,transport:n,initialDetail:i,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:a,onJuanChange:p,lineageMode:c="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:g,initialPage:x=1,selectedLineageNodeId:m,onNavigate:b,onBack:S,backLabel:h,renderLink:y,enrichDetail:j,getSourceLink:k,readLink:$,railTop:v,extraTabs:_=[],showFeedbackTab:w=!0,feedbackApiUrl:z,height:N,footerExtra:T,className:C,style:P})=>{var Ki;const B=ue(),{convert:A}=q(),[W]=f.useState(()=>{if(!mx(e,i))return null;const Y={...i},je=r??Dn(e,Y);return j&&j(je,Y),{id:e,entry:je,detail:Y}}),[V,K]=f.useState((W==null?void 0:W.entry)??null),[E,le]=f.useState((W==null?void 0:W.detail)??null),[G,ae]=f.useState(!W),[pe,ee]=f.useState(!1),[X,ie]=f.useState([]),[me,te]=f.useState(!1),[se,fe]=f.useState(null),[be,ze]=f.useState(!1),[ve,ke]=f.useState(null),[Ne,Ee]=f.useState(!1),[O,ce]=f.useState(null),[oe,he]=f.useState([]),[Z,F]=f.useState(!1),[I,D]=f.useState(null),[M,ne]=f.useState(null),[R,J]=f.useState(!1),H=f.useRef(null),[U,re]=f.useState(null),Se=a!==void 0?a:U,ye=f.useCallback(Y=>{p?p(Y):re(Y)},[p]),Le=f.useCallback(async Y=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){ie([]);return}te(!0);try{if(n.getCollectionCatalogs)ie(await n.getCollectionCatalogs(Y)||[]);else if(n.getCollectionCatalog){const je=await n.getCollectionCatalog(Y);ie(je?[{resource_id:"",data:je}]:[])}}catch{ie([])}finally{te(!1)}},[n]),Ye=f.useCallback(async Y=>{if(!n.getCollatedEditionIndex){fe(null);return}ze(!0);try{fe(await n.getCollatedEditionIndex(Y))}catch{fe(null)}finally{ze(!1)}},[n]),L=f.useCallback(async Y=>{if(!n.getBookFullTextIndex){ke(null);return}Ee(!0);try{ke(await n.getBookFullTextIndex(Y))}catch{ke(null)}finally{Ee(!1),ce(Y)}},[n]),de=f.useCallback(async Y=>{var je;if(!n.getWorkFullTextList){he([]);return}F(!0);try{const Ie=(await n.getWorkFullTextList(Y)??[]).filter(Ae=>Ae.owner_type!=="Book");he(Ie),D(((je=Ie.find(Ae=>Ae.primary)??Ie[0])==null?void 0:je.key)??null)}catch{he([])}finally{F(!1)}},[n]),ge=f.useCallback(async(Y,je)=>{J(!0);try{if(n.getLineageGraph){const De=await n.getLineageGraph(Y);De&&ne(De)}const Ie=je.version_graph;if(!Ie||!Ie.enabled){M||ne(null),H.current=null;return}const Ae=je.books??[],Xe=[];for(const De of Ae)try{const Qe=await n.getItem(De);Qe&&Xe.push(Qe)}catch{}H.current={work:je,books:Xe};const Q=u??Ie.default_collection??(Ie.core_books&&Ie.core_books.length>0?"core":"all"),Te=Q==="core"&&Array.isArray(Ie.core_books)&&Ie.core_books.length>0?"core":Q??"all";ne(xn(je,Xe,Te))}catch{ne(null),H.current=null}finally{J(!1)}},[n]),$e=f.useRef({initialDetail:i,initialEntry:r});$e.current={initialDetail:i,initialEntry:r},f.useEffect(()=>{let Y=!1;const je=Q=>{Q.type==="collection"?Le(e):Q.type==="work"?(Q.has_collated&&Ye(e),(Q.version_graph||n.getLineageGraph)&&ge(e,Q),n.getWorkFullTextList&&de(e)):Q.type==="book"&&Q.has_full_text&&n.getBookFullTextIndex&&L(e)},Ie=$e.current;let Ae=null;if(W&&W.id===e)Ae=W;else if(Ie.initialDetail&&Ie.initialDetail.id===e){const Q={...Ie.initialDetail},Te=Ie.initialEntry??Dn(e,Q);j&&j(Te,Q),Ae={entry:Te,detail:Q}}return Ae?(ee(!1),ie(Q=>Q.length?[]:Q),fe(null),ke(null),he(Q=>Q.length?[]:Q),D(null),ne(null),H.current=null,K(Ae.entry),le(Ae.detail),ae(!1),je(Ae.detail),()=>{Y=!0}):((async()=>{ae(!0),ee(!1),K(null),le(null),ie([]),fe(null),ke(null),he([]),D(null),ne(null),H.current=null;try{const Q=await n.getItem(e);if(Y)return;if(!Q){ee(!0);return}const Te=Q;let De=null;if(n.getEntry&&(De=await n.getEntry(e),Y))return;De||(De=Dn(e,Te)),j&&j(De,Te),K(De),le(Te),je(Te)}catch{Y||ee(!0)}finally{Y||ae(!1)}})(),()=>{Y=!0})},[e,n,W,j,Le,Ye,ge,L,de]),f.useEffect(()=>{const Y=H.current;!Y||!u||ne(xn(Y.work,Y.books,u))},[u]);const xe=[];if(E){if(xe.push({key:"basic",label:B.detailTab.basicInfo}),E.type==="collection"){me&&X.length===0&&xe.push({key:"catalog:loading",label:`${B.detailTab.catalog}…`});for(const Y of X)xe.push({key:`catalog:${Y.resource_id}`,label:Y.short_name?`${A(Y.short_name)}${B.detailTab.catalogSuffix}`:B.detailTab.collectionCatalog})}E.type==="work"&&(se||be)&&s==="collated"&&xe.push({key:"collated",label:be?`${B.detailTab.collatedEdition}…`:B.detailTab.collatedEdition}),E.type==="book"&&(ve||Ne)&&s==="fulltext"&&xe.push({key:"fulltext",label:Ne?`${B.detailTab.fullText}…`:B.detailTab.fullText}),E.type==="work"&&(oe.length>0||Z)&&s==="fulltext"&&xe.push({key:"fulltext",label:Z?`${B.detailTab.fullText}…`:B.detailTab.fullText}),E.type==="work"&&(M||R)&&xe.push({key:"lineage",label:R?`${B.detailTab.lineage}…`:B.detailTab.lineage});for(const Y of _)(Y.position??"before-feedback")==="before-feedback"&&Y.shouldShow(E)&&xe.push({key:Y.key,label:Y.label});w&&s==="feedback"&&xe.push({key:"feedback",label:B.detailTab.feedback});for(const Y of _)Y.position==="after-feedback"&&Y.shouldShow(E)&&xe.push({key:Y.key,label:Y.label})}f.useEffect(()=>{if(s!=="emendated"||!E)return;l("basic");const Y=setTimeout(()=>{var je;(je=document.getElementById("studies"))==null||je.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(Y)},[s,E,l]);const Ce=V&&E&&k?k({activeTab:s,activeJuan:Se,entry:V,detail:E}):null,Oe=f.useMemo(()=>{var Xe;if(!E)return null;const je=(E.authors??[]).map(Q=>{const Te=ji(Q.role);return`${Q.dynasty?`〔${A(Q.dynasty)}〕`:""}${A(Q.name)}${Te?` ${A(Te)}`:""}`}).join(" · ");let Ie=!1;try{Ie=we.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const Q=E;return{title:A(Q.title),subtitle:Q.edition?A(Q.edition):je||void 0,aside:[Ie?B.status.draft:"",je&&Q.edition?je:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const Q=E;return{title:A(Q.title),subtitle:A(at(Q,B.unit.juan))||void 0,aside:[(Xe=Q.publication_info)==null?void 0:Xe.year,Ie?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:je||void 0}}if(E.type==="entity"){const Q=E,Te=Qe=>Qe==null?"":Qe<0?`前${-Qe}`:String(Qe),De=Q.birth_year!=null||Q.death_year!=null?`${Te(Q.birth_year)||"?"}—${Te(Q.death_year)||"?"}`:"";return{title:A(Q.primary_name||Q.title),subtitle:[Q.dynasty?`〔${A(Q.dynasty)}〕`:"",De].filter(Boolean).join(" ")||void 0,aside:Ie?B.status.draft:void 0,secondLine:void 0}}const Ae=A(at(E,B.unit.juan));return{title:A(E.title),subtitle:[Ae,je].filter(Boolean).join(" · ")||void 0,aside:[yx(B,E.subtype),Ie?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,A,B]),Je=E?E.type==="work"?(((Ki=se==null?void 0:se.juan_files)==null?void 0:Ki.length)??0)>0?"collated":oe.length>0?"fulltext":null:E.type==="book"&&(((ve==null?void 0:ve.chapters.length)??0)>0||E.has_full_text&&n.getBookFullTextIndex&&O!==E.id)?"fulltext":null:null,ct=oe.find(Y=>Y.primary)??oe[0],nn=()=>{var Y;Je==="collated"&&((Y=se==null?void 0:se.juan_files)!=null&&Y.length)?(ye(se.juan_files[0]),l("collated")):Je==="fulltext"&&((E==null?void 0:E.type)==="work"&&ct&&D(ct.key),ye(null),l("fulltext"))};let dt=null;if(E&&$){const Y=$({detail:E,kind:Je,fullTextKey:E.type==="work"?ct==null?void 0:ct.key:void 0});Y&&(dt=t.jsx(Kn,{href:Y}))}else Je&&(dt=t.jsx(Kn,{onClick:nn}));const on=Y=>{if(!E)return null;const je=Y.replace(/\.[^.]+$/,"");if($){const Ie=$({detail:E,kind:"fulltext",juan:je});return Ie?{href:Ie}:null}return{onClick:()=>{ye(je),l("fulltext")}}},rn=new Set(_.map(Y=>Y.key)),_e=xe.filter(Y=>Y.key.startsWith("catalog:")&&Y.key!=="catalog:loading"||rn.has(Y.key)).map(Y=>({key:Y.key,label:Y.label,onClick:()=>l(Y.key)})),Ze=()=>{var Y;return E?E.type==="work"?t.jsx(tl,{data:E,transport:n,onNavigate:b,renderLink:y,readAction:dt,railTop:v,railLinks:_e}):E.type==="book"?t.jsx(rl,{data:E,transport:n,onNavigate:b,renderLink:y,readAction:dt,fullText:ve,fullTextPending:!!E.has_full_text&&!!n.getBookFullTextIndex&&O!==E.id,chapterLink:on,railTop:v,railLinks:_e}):E.type==="collection"?t.jsx(sl,{data:E,catalog:(Y=X[0])==null?void 0:Y.data,transport:n,onNavigate:b,renderLink:y,readAction:dt,railTop:v,railLinks:_e,catalogAction:X.length>0?t.jsxs("a",{href:"#catalog",onClick:je=>{je.preventDefault(),l(`catalog:${X[0].resource_id}`)},children:[A(B.detailTab.collectionCatalog)," →"]}):null}):t.jsx(ll,{data:E,transport:n,onNavigate:b,renderLink:y,railTop:v,railLinks:_e}):null},Re=()=>{var je,Ie,Ae,Xe;if(!V||!E)return null;if(s==="basic"||s==="emendated")return Ze();if(typeof s=="string"&&s.startsWith("catalog:")){const Q=(je=X.find(Te=>`catalog:${Te.resource_id}`===s))==null?void 0:je.data;return t.jsx(gi,{data:Q,onNavigate:b,renderLink:y})}if(s==="collated")return t.jsx(Fi,{index:se||void 0,workId:e,transport:n,onNavigate:b,activeJuan:Se,onJuanChange:ye});if(s==="fulltext"&&E.type==="work"){const Q=I??((Ie=oe[0])==null?void 0:Ie.key);return Q?t.jsx(ni,{bookId:e,workKey:Q,versions:oe,onVersionChange:Te=>{D(Te),ye(null)},transport:n,activeChapter:Se,onChapterChange:ye},Q):t.jsx("div",{style:{padding:24,color:o("desc-fg")},children:Z?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(ni,{index:ve||void 0,bookId:e,transport:n,activeChapter:Se,onChapterChange:ye});if(s==="lineage"){if(!M)return t.jsx("div",{style:{color:o("label-fg"),padding:"24px 0"},children:R?"加載中…":"暫無版本圖數據"});const Q=E.type==="work"?E:null;return t.jsx(Hi,{graph:M,renderLink:y,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:d,selectedNodeId:m,collection:u??((Ae=Q==null?void 0:Q.version_graph)==null?void 0:Ae.default_collection),onCollectionChange:g,collectionsAvailable:(Xe=Q==null?void 0:Q.version_graph)==null?void 0:Xe.collections,collectionCounts:(()=>{var Ji,Zi,Xi,Qi,eo,to,no;if(!Q)return;const Te={},De=((Ji=H.current)==null?void 0:Ji.books)??[];Te.all=(((Zi=Q.books)==null?void 0:Zi.length)??0)-(((Qi=(Xi=Q.version_graph)==null?void 0:Xi.excluded_books)==null?void 0:Qi.length)??0);const Qe=(eo=Q.version_graph)==null?void 0:eo.collections;if(Qe)for(const io of Object.keys(Qe))Te[io]=xn(Q,De,io).nodes.filter(oo=>oo.kind==="book"&&!oo.bridge).length;return Te.core==null&&((no=(to=Q.version_graph)==null?void 0:to.core_books)!=null&&no.length)&&(Te.core=Q.version_graph.core_books.length),Te})()})}if(s==="feedback"&&w)return t.jsx(Zs,{resourceId:e,apiUrl:z});const Y=_.find(Q=>Q.key===s);return Y?Y.render({detail:E,entry:V,transport:n,onNavigate:b}):null};if(G)return t.jsx(Ht,{style:{minHeight:N,...P},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((Y,je)=>t.jsx("div",{style:{height:je===1?40:16,width:Y,opacity:.35,background:o("rule")}},je))})});if(pe||!E||!V||!Oe)return t.jsx(Ht,{style:{minHeight:N,...P},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:o("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const kt=s==="basic"||s==="emendated",sn=[{label:h??B.detailTab.backToIndex,onClick:S}];if(E.type==="book"&&E.work_id){const Y=E.work_id;sn.push({label:B.indexType.work,id:Y,onClick:()=>b==null?void 0:b(Y)})}sn.push({label:B.indexType[E.type]});const ln=s==="collated"||s==="fulltext",Yi=typeof T=="string"?B.status[T.trim()]??T:T,qi=t.jsx(ds,{left:t.jsxs(t.Fragment,{children:[Yi,Yi?" · ":"",t.jsx(bx,{id:E.id,label:B.label.id,copied:B.action.copied,copyLabel:B.action.copy})]}),right:t.jsxs(t.Fragment,{children:[w&&!kt&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:B.detailTab.submitVersion}),Ce&&t.jsx("a",{href:Ce.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:o("meta-fg")},children:B.detailTab.dataLicense})]})});return kt?t.jsx("div",{className:C,children:t.jsxs(Ht,{grid:!0,style:{minHeight:N,...P},children:[t.jsx(Jn,{breadcrumb:t.jsx(Zn,{items:sn}),actions:t.jsxs(t.Fragment,{children:[t.jsx(li,{style:{border:"none",background:"transparent"}}),Ce&&t.jsx(ai,{...Ce})]})}),Ze(),qi]})}):t.jsx("div",{className:C,children:t.jsxs(Ht,{wide:ln,style:{minHeight:N,...P},children:[t.jsx(Jn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(ki,{char:"籍"}),t.jsx(Zn,{items:sn})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(li,{}),w&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:B.detailTab.feedback}),Ce&&t.jsx(ai,{...Ce})]})}),t.jsx(ts,{...Oe,aside:ln?t.jsxs("button",{type:"button",onClick:()=>l("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("accent"),borderBottom:`1px solid ${o("rule")}`},children:[A("作品信息")," →"]}):Oe.aside}),!ln&&xe.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:xe.map(Y=>t.jsx(ns,{label:Y.label,active:Y.key===s||kt&&Y.key==="basic",onClick:()=>l(Y.key)},Y.key))}),t.jsx("div",{style:{marginTop:!ln&&xe.length>1?8:0},children:Re()}),qi]})})};function bx({id:e,label:n,copied:i,copyLabel:r}){const[s,l]=f.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var a;(a=navigator.clipboard)==null||a.writeText(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?i:r,"aria-label":s?i:r,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:o("aux-fg")},children:s?"✓":"⧉"})]})}function yx(e,n){return n?e.workSubtype[n]??n:""}const hl=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛藍"}],Cn="zhusha",In="bim-theme";function bl(e){return e==="zhusha"||e==="indigo"}function Tn(e){return bl(e)?e:Cn}function jx(){try{return Tn(window.localStorage.getItem(In))}catch{return Cn}}function yl(e){try{window.localStorage.setItem(In,e)}catch{}}function jl(e){const n=Tn(e);return document.documentElement.setAttribute("data-theme",n),n}function vl(){return Tn(document.documentElement.getAttribute("data-theme"))}const vx=`try{if(localStorage.getItem(${JSON.stringify(In)})==='indigo')document.documentElement.setAttribute('data-theme','indigo')}catch(e){}`,kx={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo"},Sx=({onChange:e,style:n})=>{const{convert:i}=q(),[r,s]=f.useState(Cn);f.useEffect(()=>{s(vl())},[]);const l=a=>{s(jl(a)),yl(a),e==null||e(a)};return t.jsx("div",{role:"radiogroup","aria-label":i("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:hl.map(a=>{const p=r===a.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":p,"aria-label":i(a.label),title:i(a.label),onClick:()=>l(a.name),style:{width:28,height:44,padding:0,border:0,background:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:t.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:"50%",boxSizing:"border-box",background:o(kx[a.name]),boxShadow:p?`0 0 0 2px ${o("page-bg")}, 0 0 0 3.5px ${o("aux-fg")}`:"none"}})},a.name)})})};exports.BidLink=we.BidLink;exports.BookIndexError=we.BookIndexError;exports.BookIndexManager=we.BookIndexManager;exports.BookIndexStorage=we.BookIndexStorage;exports.BundleStorage=we.BundleStorage;exports.ConfigError=we.ConfigError;exports.GithubStorage=we.GithubStorage;exports.IdGenerationError=we.IdGenerationError;exports.IdGenerator=we.IdGenerator;exports.LocalStorage=we.LocalStorage;exports.MigrationError=we.MigrationError;exports.StorageError=we.StorageError;exports.base36Decode=we.base36Decode;exports.base36Encode=we.base36Encode;exports.base58Decode=we.base58Decode;exports.buildId=we.buildId;exports.buildPromotionMap=we.buildPromotionMap;exports.cleanName=we.cleanName;exports.decodeId=we.decodeId;exports.decodeIdString=we.decodeIdString;exports.encodeId=we.encodeId;exports.extractIdFromUrl=we.extractIdFromUrl;exports.extractStatus=we.extractStatus;exports.extractType=we.extractType;exports.normalizeCatalog=we.normalizeCatalog;exports.parseId=we.parseId;exports.shardOf=we.shardOf;exports.smartDecode=we.smartDecode;exports.validateResource=we.validateResource;exports.Badge=hn;exports.BidUrlProvider=Rl;exports.BookDetailLayout=hx;exports.BookFullText=ni;exports.BookPage=rl;exports.Breadcrumb=Zn;exports.CATALOG_ALL_ID=rt;exports.CATALOG_CSS=al;exports.CATALOG_NARROW_QUERY=Gi;exports.CATALOG_PAGE_SIZE=Ui;exports.CATALOG_UNCLASSIFIED_ID=qt;exports.CardFoot=Qt;exports.CatalogPage=gx;exports.CatalogPager=gl;exports.CatalogTree=dl;exports.CheckFilter=Qr;exports.Chip=is;exports.ChipWall=wc;exports.CollatedEdition=Fi;exports.CollectionCatalog=gi;exports.CollectionPage=sl;exports.CreateEntityDialog=Hs;exports.DEFAULT_READER_PREFS=_i;exports.DEFAULT_THEME=Cn;exports.DETAIL_CSS=es;exports.Dash=Tc;exports.DataTable=$c;exports.DetailFooter=ds;exports.DetailGrid=Zt;exports.DetailHeader=ts;exports.EmendatedBySection=Br;exports.EmptyNote=Wc;exports.EntityDetail=Ir;exports.EntityPage=ll;exports.EntityPickerDialog=Us;exports.EntitySelector=Ds;exports.ExpandRow=Ec;exports.ExtLink=Mc;exports.FEEDBACK_FAB_OFFSET_VAR=oi;exports.FONT_SIZE_STEPS=$t;exports.FactList=jc;exports.FeedbackButton=su;exports.FeedbackDialog=Ks;exports.FeedbackForm=Js;exports.FeedbackList=Pi;exports.FeedbackTab=Zs;exports.FilterChip=ns;exports.FormInput=Ge;exports.FormTextArea=bt;exports.GUJI_MARKDOWN_FIELD=sc;exports.GUJI_TABLE_NOTATION=vs;exports.GlyphBadge=ki;exports.GujiTable=Ii;exports.HomePage=ti;exports.ImagePanel=ms;exports.IndexApp=pp;exports.IndexBrowser=Un;exports.IndexDetail=fi;exports.IndexEditor=Vs;exports.IndexView=Yp;exports.IntroGrid=yc;exports.LocaleContext=Rt;exports.LocaleProvider=Vl;exports.LocaleToggle=li;exports.MetaLine=Me;exports.ModeIndicator=$r;exports.MoreButton=Sc;exports.MoreLink=Bt;exports.PAGE_MAX_WIDTH=pn;exports.PageFrame=Ht;exports.Quote=Nc;exports.READER_CSS=xs;exports.RECENT_IDS_STORAGE_KEY=Ct;exports.ROLE_CLASS_ORDER=Dr;exports.ReadButton=Kn;exports.ReaderMdText=Ni;exports.ReaderShell=zi;exports.ReaderToc=gs;exports.RelationPanel=Ps;exports.RepoSourceLink=ai;exports.ResourceEditor=Gn;exports.ResourceGroup=Lc;exports.ResourceLine=Bc;exports.ResourceList=xi;exports.ResourceRow=as;exports.SNIPPET_MARK_END=yr;exports.SNIPPET_MARK_START=br;exports.SearchInput=zr;exports.Sec=Fe;exports.Section=qe;exports.SectionHead=vc;exports.SideList=ht;exports.SmartBidInput=un;exports.SourceEditor=Ws;exports.SummaryCard=Xt;exports.THEMES=hl;exports.THEME_INIT_SCRIPT=vx;exports.THEME_STORAGE_KEY=In;exports.TabFilter=_n;exports.TableHead=zc;exports.TableRow=Cc;exports.TagRow=cs;exports.TagRows=Ac;exports.TextButton=kc;exports.ThemeToggle=Sx;exports.TopStrip=Jn;exports.VersionLineageGraph=ol;exports.VersionLineageList=il;exports.VersionLineageView=Hi;exports.VolumeChips=_c;exports.VolumeLinks=Si;exports.WorkCard=xl;exports.WorkCardGrid=ml;exports.WorkCatalog=up;exports.WorkPage=tl;exports.WorkRow=fl;exports.applyTheme=jl;exports.bucketResources=bi;exports.buildCatalogTree=sx;exports.buildCollectionTable=Gr;exports.buildLineageGraph=xn;exports.buildPageUrl=ui;exports.buildParagraphBlocks=Is;exports.buildVersionRow=Pr;exports.buildVersionTable=Or;exports.canParagraphize=zn;exports.catalogNodeIdOf=ox;exports.catalogNodeIdsOf=rx;exports.catalogPageCount=dx;exports.catalogTotal=Vi;exports.classificationPath=tn;exports.compareCatalogCards=cx;exports.computeVersionPartition=nc;exports.currentTheme=vl;exports.defaultWorkLink=pl;exports.deriveDating=Qa;exports.deriveEditionType=Vr;exports.deriveEra=Jt;exports.deriveYear=kn;exports.deriveYearRange=hi;exports.detailToEditor=qs;exports.detectGenre=$n;exports.displayAuthorRole=ji;exports.editorToDetail=Vp;exports.eraRank=Yn;exports.findCatalogPath=zt;exports.flattenTitles=Xn;exports.flattenToc=js;exports.formatTemplate=Kt;exports.formatVolumeRange=wn;exports.getDisplayNameFromUrl=Nt;exports.getStartPage=pi;exports.getTypeGroupKey=ci;exports.groupRelatedWorks=ec;exports.gujiInlineToPlain=Jr;exports.hasGujiMarkdownV02=qn;exports.hasGujiTableNotation=ks;exports.isThemeName=bl;exports.measureText=at;exports.mergeVolumeResources=di;exports.normalizeEra=We;exports.normalizeRole=yi;exports.normalizeTheme=Tn;exports.normalizeVolumeIndex=Ut;exports.normalizeVolumes=_r;exports.numberToChinese=Ur;exports.paginationItems=cl;exports.parseChineseNumber=fn;exports.parseGujiInline=Kr;exports.parseGujiTable=ws;exports.parseSourceString=Ms;exports.pickReaderVersion=ys;exports.readStoredTheme=jx;exports.readerVersionOptionLabel=ei;exports.readerVersionsFromFullText=bs;exports.renderFullTextBody=ld;exports.renderProperNames=Es;exports.renderReaderInline=Ri;exports.resourceHref=Lt;exports.resourceNote=Sn;exports.roleFacets=Hr;exports.rowNo=Ic;exports.sortYear=gn;exports.splitFullTextTables=Ci;exports.splitHighlightSnippet=jr;exports.splitTableRow=Ss;exports.storeTheme=yl;exports.stringifySources=Fs;exports.toCatalogWorkCard=ax;exports.useBidUrl=Pe;exports.useConvert=q;exports.useReaderPrefs=$i;exports.useT=ue;exports.validateLineageGraph=zu;exports.volumeStats=bn;