book-index-ui 0.10.1 → 0.10.2

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,11 +1,11 @@
1
- "use strict";var Hs=Object.create;var Pi=Object.defineProperty;var Gs=Object.getOwnPropertyDescriptor;var Us=Object.getOwnPropertyNames;var Vs=Object.getPrototypeOf,Ys=Object.prototype.hasOwnProperty;var Ks=(e,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Us(n))!Ys.call(e,s)&&s!==i&&Pi(e,s,{get:()=>n[s],enumerable:!(r=Gs(n,s))||r.enumerable});return e};var kt=(e,n,i)=>(i=e!=null?Hs(Vs(e)):{},Ks(n||!e||!e.__esModule?Pi(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ae=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),f=require("react"),qs=require("react-markdown"),Js=require("remark-gfm"),Zs=e=>`/book-index?id=${e}`,Yo=f.createContext(Zs);function Xs({buildUrl:e,children:n}){const i=f.useMemo(()=>e,[e]);return t.jsx(Yo.Provider,{value:i,children:n})}function je(){return f.useContext(Yo)}const Ko="",qo="";function Jo(e){const n=[];let i=!1,r=e;for(;r.length;){const s=i?qo:Ko,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 we(e,n){return{title:e,tokens:n}}const Oi='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Qs=[we("基础(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"}}),we("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),we("提示与警告",{"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)"}}),we("遮罩与阴影",{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)"}}),we("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),we("资源",{"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"}}),we("整理本(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"}}),we("版本传承(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"}}),we("编辑器视图(主要在 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")'}}),we("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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:"唯一的状态色块「有影印」"},"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}}),we("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),we("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),we("字体(全站无衬线,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:Oi,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:Oi,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],el=Object.assign({},...Qs.map(e=>e.tokens)),Zo={};for(const[e,n]of Object.entries(el))Zo[e]=`var(--bim-${e}, ${n.value})`;function o(e){const n=Zo[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function Qe(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function tl(e,n){return Qe(e).includes(n)}const Sn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},nl={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};o("quality-published"),o("quality-fine"),o("quality-rough"),o("quality-ocr");const mt=f.createContext(null),Xo={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:"圖片資源"}},il={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:"图片资源"}},ol={"zh-Hant":Xo,"zh-Hans":il},Qo="bim-locale";function rl(){try{const e=localStorage.getItem(Qo);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function sl(e){try{localStorage.setItem(Qo,e)}catch{}}const ll="zh-Hans",al=({locale:e,onLocaleChange:n,children:i})=>{const[r,s]=f.useState(e??ll),l=e??r;f.useEffect(()=>{if(e)return;const u=rl();u&&u!==r&&s(u)},[]);const[p,d]=f.useState(null);f.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(u=>{const x=u.Converter({from:"tw",to:"cn"});d(()=>x)}).catch(()=>{d(()=>u=>u)}):d(null)},[l]);const c=f.useCallback(u=>{s(u),sl(u),n==null||n(u)},[n]),a=f.useMemo(()=>({locale:l,setLocale:c,messages:ol[l],converter:p}),[l,c,p]);return t.jsx(mt.Provider,{value:a,children:i})};function te(){const e=f.useContext(mt);return(e==null?void 0:e.messages)??Xo}const cl=2e3;function Y(){const e=f.useContext(mt),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(p=>{if(!p)return"";if(!i)return p;const d=r.current.get(p);if(d!==void 0)return d;const c=i(p);if(r.current.size>=cl){const a=r.current.keys().next().value;a!==void 0&&r.current.delete(a)}return r.current.set(p,c),c},[i]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Lt(e,n){return e.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function dl(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 pl(){return{id:"",name:"",url:"",type:"text",details:""}}const wn=({items:e,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const l=te(),[p,d]=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}],a=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=b=>{if(!s)return!0;const j=Qe(b);return s==="text"?j.includes("text"):s==="image"?j.includes("image")||j.includes("physical"):s==="physical"?j.includes("physical"):j.includes(s)},x=e.map((b,j)=>({item:b,originalIndex:j})).filter(({item:b})=>u(b)),g=()=>{const b=pl();s&&(b.type=s),n([...e,b]),d(e.length)},h=b=>{n(e.filter((j,$)=>$!==b)),d(null)},y=(b,j,$)=>{const S=[...e];if(S[b]={...S[b],[j]:$},j==="url"&&!S[b].id){const _=dl($);_&&(S[b].id=_)}n(S)},k=(b,j,$)=>{const _={...e[b].metadata||{}};$?_[j]=$:delete _[j],y(b,"metadata",Object.keys(_).length>0?_:void 0)},m=(b,j)=>{const $=j.trim()?j.split(/[,,、]/).map(S=>S.trim()).filter(Boolean):void 0;y(b,"structure",$)},v=(b,j,$)=>{const _=e[b].coverage||{level:1,ranges:""};j==="level"?_.level=parseInt($)||1:_.ranges=$,y(b,"coverage",_.ranges?_:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:b,originalIndex:j})=>{var $,S,_;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>d(p===j?null:j),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:p===j?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:ul(b.type??"text"),color:o("on-color-fg")},children:(()=>{var z,B;const w=Qe(b);return w.length===0?b.type??"text":w.length===1?((z=c.find(L=>L.value===w[0]))==null?void 0:z.label)??w[0]:w.includes("text")&&w.includes("image")?((B=c.find(L=>L.value==="text+image"))==null?void 0:B.label)??"text+image":w.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:b.name||`${l.editor.resourcePlaceholder} ${j+1}`}),b.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:b.id}),b.url&&t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",onClick:w=>w.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&b.url&&xl(j,r==null?void 0:r[j],i,l),t.jsx("button",{onClick:w=>{w.stopPropagation(),h(j)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),p===j&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:[tl(b,"image")&&b.url&&fl(b,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:St,children:[t.jsx("span",{style:wt,children:l.label.type}),t.jsx("select",{value:b.type,onChange:w=>y(j,"type",w.target.value),style:{...Ae,flex:1},children:c.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]}),t.jsxs("label",{style:St,children:[t.jsx("span",{style:wt,children:l.label.rootType}),t.jsx("select",{value:b.root_type||"catalog",onChange:w=>y(j,"root_type",w.target.value),style:{...Ae,flex:1},children:a.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:b.id,onChange:w=>y(j,"id",w.target.value),placeholder:l.editor.idAutoExtract,style:{...Ae,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:b.name,onChange:w=>y(j,"name",w.target.value),placeholder:l.editor.resourceName,style:{...Ae,flex:1}})]}),t.jsx("input",{type:"text",value:b.url,onChange:w=>y(j,"url",w.target.value),placeholder:l.editor.resourceUrl,style:Ae}),t.jsx("input",{type:"text",value:(($=b.structure)==null?void 0:$.join("、"))||"",onChange:w=>m(j,w.target.value),placeholder:l.editor.structurePlaceholder,style:Ae}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:St,children:[t.jsx("span",{style:wt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((S=b.coverage)==null?void 0:S.level)??"",onChange:w=>v(j,"level",w.target.value),placeholder:"1",style:{...Ae,width:"60px"}})]}),t.jsxs("label",{style:{...St,flex:1},children:[t.jsx("span",{style:wt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:((_=b.coverage)==null?void 0:_.ranges)||"",onChange:w=>v(j,"ranges",w.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...Ae,flex:1}})]})]}),t.jsx("textarea",{value:b.details||"",onChange:w=>y(j,"details",w.target.value),placeholder:l.editor.detailsPlaceholder,style:{...Ae,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 B;return t.jsxs("label",{style:{...St,gap:"4px"},children:[t.jsx("span",{style:{...wt,minWidth:"56px"},children:z}),t.jsx("input",{type:"text",value:((B=b.metadata)==null?void 0:B[w])||"",onChange:L=>k(j,w,L.target.value),placeholder:z,style:{...Ae,flex:1}})]},w)})})]})]})]})]},j)}),t.jsxs("button",{onClick:g,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 ul(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 xl(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:p=>{p.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 fl(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 Ae={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"},St={display:"flex",alignItems:"center",gap:"6px"},wt={fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap"},gl={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function tt(e){try{return gl[new URL(e).hostname]}catch{return}}const Di={text:0,image:1,physical:2};function On(e){return e.length===0?"physical":[...e].sort((n,i)=>(Di[n]??99)-(Di[i]??99)).join("+")}function Dn(e){var p;const n=d=>{const c=d.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const a=d.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},i=new Map;for(let d=0;d<e.length;d++){const c=e[d];if(c.volumes&&c.volumes.length>0)continue;const a=n(c.name);if(!a)continue;const[u,x]=a,g=`${u}|${On(Qe(c))}`;i.has(g)||i.set(g,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const h=i.get(g);h.volumes.push({volume:x,url:c.url||void 0,status:"found"}),h.indices.push(d)}const r=[],s=new Set;for(const d of i.values())if(!(d.volumes.length<2)){d.volumes.sort((c,a)=>c.volume-a.volume),d.base.volumes=d.volumes,d.base.expected_volumes=d.volumes.length,d.base.url||(d.base.url=((p=d.volumes.find(c=>c.url))==null?void 0:p.url)??""),r.push(d.base);for(const c of d.indices)s.add(c)}const l=[...r];for(let d=0;d<e.length;d++)s.has(d)||l.push(e[d]);return l}function er(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 tr(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||er(n)}))}function Xt(e){const n=tr(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 Hn(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 Gn(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 bt(e){if(!e.url)return;const n=Hn(e.metadata);return n?Gn(e.url,n):e.url}const Hi={text:o("restype-text"),image:o("restype-image"),"text+image":o("restype-text-image"),physical:o("restype-physical")};function hl(e){return e.includes("text")&&e.includes("image")?Hi["text+image"]:Hi[e[0]||"physical"]}const Un=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const l=te(),{convert:p}=Y(),d=f.useMemo(()=>Dn(e||[]),[e]),{mirrorGroups:c,ungroupedItems:a}=f.useMemo(()=>{const m=new Map,v=[];for(const b of d){const j=b.group;j?(m.has(j)||m.set(j,[]),m.get(j).push(b)):v.push(b)}for(const b of m.values())b.sort((j,$)=>{const S=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return S(j)-S($)});return{mirrorGroups:m,ungroupedItems:v}},[d]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},x=m=>u[m]?u[m]:m.split("+").map(v=>u[v]||v).join("+");if(!d||d.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:d.map((m,v)=>t.jsx(dn,{item:m},m.id||v))});const g=(m,v)=>{const b=i==null?void 0:i[m],j=(b==null?void 0:b.label)||m,$=b==null?void 0:b.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:p(j)}),$&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.5},children:p($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((S,_)=>t.jsx(dn,{item:S,onNavigate:r,renderLink:s},S.id||_))})]},`group-${m}`)},h=new Map;for(const m of a){const v=On(Qe(m));h.has(v)||h.set(v,[]),h.get(v).push(m)}const y=["text","image","text+image","physical"],k=[...y.filter(m=>h.has(m)),...[...h.keys()].filter(m=>!y.includes(m)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([m,v])=>g(m,v)),k.map(m=>{const v=h.get(m),b=hl(m.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:b,whiteSpace:"nowrap",flexShrink:0},children:x(m)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((j,$)=>t.jsx(dn,{item:j,onNavigate:r,renderLink:s},j.id||$))})]},m)})]})},ml={bw:{label:"",bg:o("colormode-bw-bg"),fg:o("colormode-bw-fg")},color:{label:"",bg:o("colormode-color-bg"),fg:o("colormode-color-fg")}},dn=({item:e})=>{const n=te(),{convert:i}=Y(),[r,s]=f.useState(!1),l=f.useMemo(()=>(e.url?tt(e.url):void 0)||i(e.name),[e.url,e.name,i]),p=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(y=>({...y,url:y.url||er(y)})),[e.volumes]),d=p&&p.length>0,c=d?new Set(p.filter(y=>y.status!=="missing").map(y=>y.volume)).size:0,a=d?new Set(p.filter(y=>y.status==="missing").map(y=>y.volume)).size:0,u=e.expected_volumes??(d?c+a:0),x=e.color_mode?{...ml[e.color_mode],label:n.colorMode[e.color_mode]}:null,g=e.details&&!d?i(e.details):null,h={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:h,children:[t.jsx("span",{style:{fontWeight:500},children:l}),x&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),g&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:g}),d&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[c,"/",u,n.unit.volume,a>0&&t.jsxs("span",{style:{color:o("missing-fg"),marginLeft:"3px"},children:["缺",a]})]}),e.url&&t.jsx("a",{href:(()=>{const y=Hn(e.metadata);return y?Gn(e.url,y):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:o("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),d&&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?"▲":"▼"})]}),d&&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:p.map(y=>{const k=y.status==="missing";return y.url&&!k?t.jsx("a",{href:y.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:y.volume},y.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:y.volume},y.volume)})})]})},nr=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:p})=>{const d=te(),c=e==="local",a=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",x=u?u.split(/[/\\]/).pop()||u:"",g={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")},h={onMouseOver:k=>k.currentTarget.style.opacity="0.8",onMouseOut:k=>k.currentTarget.style.opacity="1"},y=t.jsxs("div",{onClick:s,title:a?d.mode.switchToOfficial:d.mode.switchToDraft,style:{...g,background:o(a?"warning":"success"),color:o("on-color-fg")},...h,children:[t.jsx("span",{children:a?"📝":"📚"}),t.jsx("span",{children:a?"draft":"official"})]});return i==="index-browser"?c?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[y,t.jsxs("div",{onClick:r,title:d.mode.switchToSync,style:g,...h,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:d.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:p,title:u||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...h,children:[t.jsx("span",{children:"📂"}),x&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[y,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:d.mode.switchToLocal,style:g,...h,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:d.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:x||d.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...h,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:c?d.mode.switchToGithub:d.mode.switchToLocal,style:g,...h,children:[t.jsx("span",{children:c?"📁":"🌐"}),t.jsx("span",{children:c?d.mode.localMode:d.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&t.jsxs("div",{onClick:p,title:u||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...h,children:[t.jsx("span",{children:"📂"}),x&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!c&&x&&t.jsxs("div",{style:{...g,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:x})]})]})},Qt="bim-search-history",Gi=10,Ui=8;function Tt(){try{const e=localStorage.getItem(Qt);return e?JSON.parse(e):[]}catch{return[]}}function bl(e){try{const n=Tt().filter(i=>i!==e);n.unshift(e),n.length>Gi&&(n.length=Gi),localStorage.setItem(Qt,JSON.stringify(n))}catch{}}function yl(e){try{const n=Tt().filter(i=>i!==e);localStorage.setItem(Qt,JSON.stringify(n))}catch{}}function jl(){try{localStorage.removeItem(Qt)}catch{}}const ir=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:l})=>{const p=te(),d=l??p.search.placeholder,c={work:p.indexType.work,book:p.indexType.book,collection:p.indexType.collection,entity:p.indexType.entity},[a,u]=f.useState(!1),[x,g]=f.useState([]),[h,y]=f.useState(-1),[k,m]=f.useState(Tt),v=f.useRef(null),b=f.useRef(null),j=f.useRef(null),$=f.useRef(!1);f.useEffect(()=>{y(-1);const C=n.trim();if(!C){g(k.map(T=>({type:"history",text:T})));return}if(!e.searchAll){g([]);return}let A=!1;const W=setTimeout(()=>{e.searchAll(C,Ui).then(T=>{if(A)return;const R=[...T.works,...T.books,...T.collections,...T.entities??[]];g(R.slice(0,Ui).map(N=>({type:"entry",text:N.title||N.id,entry:N})))}).catch(()=>{A||g([])})},80);return()=>{A=!0,clearTimeout(W)}},[n,k,e]),f.useEffect(()=>{const C=A=>{j.current&&!j.current.contains(A.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=A=>{var W,T;if(A.key==="/"&&document.activeElement!==v.current){const R=(W=document.activeElement)==null?void 0:W.tagName;if(R==="INPUT"||R==="TEXTAREA"||R==="SELECT")return;A.preventDefault(),(T=v.current)==null||T.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const S=f.useCallback(C=>{C.trim()&&(bl(C.trim()),m(Tt())),r(C),u(!1)},[r]),_=f.useCallback(C=>{C.type==="history"?(i(C.text),S(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(i(C.text),S(C.text)))},[i,S,s]),w=f.useCallback(C=>{if(!a||x.length===0){C.key==="Enter"&&S(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),y(A=>(A+1)%x.length);break;case"ArrowUp":C.preventDefault(),y(A=>(A-1+x.length)%x.length);break;case"Enter":C.preventDefault(),h>=0&&h<x.length?_(x[h]):S(n);break;case"Escape":C.preventDefault(),u(!1);break}},[a,x,h,n,S,_]),z=f.useCallback((C,A)=>{A.stopPropagation(),yl(C),m(Tt()),g(W=>W.filter(T=>!(T.type==="history"&&T.text===C)))},[]),B=f.useCallback(C=>{C.stopPropagation(),jl(),m([]),g([])},[]);f.useEffect(()=>{if(h>=0&&b.current){const C=b.current.children;C[h]&&C[h].scrollIntoView({block:"nearest"})}},[h]);const L=!n.trim()&&k.length>0;return t.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:v,type:"text",placeholder:d,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"}}),a&&x.length>0&&t.jsxs("div",{ref:b,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:[L&&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:p.search.history}),t.jsx("button",{onClick:B,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:p.search.clearAll})]}),x.map((C,A)=>t.jsxs("div",{onClick:()=>_(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:o("fg"),background:A===h?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:W=>z(C.text,W),style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:p.action.remove,children:"×"})]},`${C.type}-${C.text}-${A}`))]})]})},ut="bim-recent-ids",Vi="bim-recent-entries",Yi=50,pn=5,vl=50,kl=200;function at(){try{const e=localStorage.getItem(ut);if(e)return JSON.parse(e);const n=localStorage.getItem(Vi);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(ut,JSON.stringify(i)),localStorage.removeItem(Vi),i}return[]}catch{return[]}}function Ki(e){try{const n=at().filter(i=>i!==e);n.unshift(e),n.length>Yi&&(n.length=Yi),localStorage.setItem(ut,JSON.stringify(n))}catch{}}function Sl(e){try{const n=at().filter(i=>i!==e);localStorage.setItem(ut,JSON.stringify(n))}catch{}}function wl(){try{localStorage.removeItem(ut)}catch{}}const _l={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},_n=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:p,onConfigurePath:d,onSelectFolder:c,hideModeIndicator:a,resultVariant:u="compact",renderEntry:x,initialQuery:g,onQueryChange:h,headerRight:y})=>{const k=te(),m=[{type:"work",icon:"✍️",name:k.indexType.work,key:"works"},{type:"book",icon:"📖",name:k.indexType.book,key:"books"},{type:"collection",icon:"📚",name:k.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:k.indexType.entity,key:"entities"}],[v,b]=f.useState(g??""),[j,$]=f.useState(null),[S,_]=f.useState(null),[w,z]=f.useState(!1),[B,L]=f.useState(null),[C,A]=f.useState(""),[W,T]=f.useState(!g),[R,N]=f.useState(at),[O,E]=f.useState([]),[X,I]=f.useState(!1),[M,K]=f.useState(!1),[V,G]=f.useState(null),[ee,P]=f.useState(null),q=f.useRef(void 0),Z=f.useRef(!1),U=f.useCallback(async(Q,ce)=>{if(!Q.trim()){T(!0),$(null),_(null);return}T(!1),z(!0),A("");try{if(e.searchAll){const F=await e.searchAll(Q,ce??pn);$(F)}else{const F=["work","book","collection","entity"],ie=await Promise.all(F.map(ne=>e.search(Q,ne,{page:1,pageSize:ce??pn})));$({works:ie[0].entries,books:ie[1].entries,collections:ie[2].entries,entities:ie[3].entries,totalWorks:ie[0].total,totalBooks:ie[1].total,totalCollections:ie[2].total,totalEntities:ie[3].total})}}catch(F){A(F instanceof Error?F.message:String(F)),$(null)}finally{z(!1)}},[e]);f.useEffect(()=>{let Q=!1;const ce=()=>{var ge,Re;const F=["work","book","collection","entity"],ie=Promise.all(F.map(Be=>e.loadEntries(Be,{page:1,pageSize:1}).catch(()=>({total:0})))),ne=((ge=e.getResourceCounts)==null?void 0:ge.call(e).catch(()=>null))??Promise.resolve(null),he=((Re=e.getSubtypeStats)==null?void 0:Re.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([ie,ne,he]).then(([Be,ve,De])=>{Q||(G({works:Be[0].total,books:Be[1].total,collections:Be[2].total,entities:Be[3].total,hasText:ve==null?void 0:ve.hasText,hasImage:ve==null?void 0:ve.hasImage}),De&&P(De))})};return e.getCounts?e.getCounts().then(F=>{var ie,ne;Q||(G({works:F.works,books:F.books,collections:F.collections,entities:F.entities,hasText:(ie=F.resourceCounts)==null?void 0:ie.hasText,hasImage:(ne=F.resourceCounts)==null?void 0:ne.hasImage}),F.subtypeStats&&P(F.subtypeStats))}).catch(()=>{Q||ce()}):ce(),()=>{Q=!0}},[e]),f.useEffect(()=>{Z.current||!(g!=null&&g.trim())||(Z.current=!0,U(g))},[g,U]);const se=f.useCallback(Q=>{if(b(Q),!Q.trim()){h==null||h(Q),T(!0),$(null),_(null);return}q.current&&clearTimeout(q.current),q.current=setTimeout(()=>{_(null),h==null||h(Q),U(Q)},kl)},[U,h]),de=f.useCallback(Q=>{q.current&&clearTimeout(q.current),h==null||h(Q),U(Q)},[U,h]),D=f.useCallback(Q=>{_(Q),U(v,vl)},[v,U]);f.useEffect(()=>{if(!R.length){E([]);return}let Q=!1;return I(!0),Promise.all(R.slice(0,10).map(async ce=>{var F,ie,ne;try{if(e.getEntry){const ge=await e.getEntry(ce);if(ge)return ge}const he=await e.getItem(ce);if(he){const ge=he.authors;return{id:ce,title:he.title||ce,type:he.type||"work",author:(F=ge==null?void 0:ge[0])==null?void 0:F.name,dynasty:(ie=ge==null?void 0:ge[0])==null?void 0:ie.dynasty,role:(ne=ge==null?void 0:ge[0])==null?void 0:ne.role,edition:he.edition||void 0}}}catch{}return{id:ce,title:ce,type:"work",notFound:!0}})).then(ce=>{Q||(E(ce),I(!1))}),()=>{Q=!0}},[R,e]);const re=Q=>{L(Q.id),Ki(Q.id),N(at()),r==null||r(Q)},oe=(Q,ce)=>{if(r&&$l(ce)){ce.preventDefault(),re(Q);return}Ki(Q.id),N(at())},pe=Q=>{Sl(Q),N(at())},fe=()=>{wl(),N([])},ye=Q=>m.find(ce=>ce.type===Q),Ce=j&&(j.works.length>0||j.books.length>0||j.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",children:[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:k.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[y,!a&&t.jsx(nr,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:l,onToggleDraft:p,onConfigurePath:d,onSelectFolder:c})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(ir,{transport:e,value:v,onChange:se,onSearch:de,onEntrySelect:re}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${o("primary")}`,borderRadius:"6px",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"13px"},children:k.action.newEntry})]}),V&&W&&t.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[t.jsx("span",{children:ee?t.jsxs(t.Fragment,{children:[(ee.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:o("fg")},children:ee.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:o("fg")},children:V.books.toLocaleString()})," 本"]}),ee.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:o("fg")},children:ee.article.toLocaleString()})," 篇"]}):null,ee.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:o("fg")},children:ee.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:o("fg")},children:V.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[k.indexType.work," ",t.jsx("strong",{style:{color:o("fg")},children:V.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.indexType.book," ",t.jsx("strong",{style:{color:o("fg")},children:V.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.indexType.collection," ",t.jsx("strong",{style:{color:o("fg")},children:V.collections.toLocaleString()}),V.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.indexType.entity," ",t.jsx("strong",{style:{color:o("fg")},children:V.entities.toLocaleString()})]})]})}),V.hasImage!=null&&V.hasText!=null&&t.jsxs("span",{children:[k.resourceType.image," ",t.jsx("strong",{style:{color:o("fg")},children:V.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.resourceType.text," ",t.jsx("strong",{style:{color:o("fg")},children:V.hasText.toLocaleString()})]})]}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:w?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:k.search.searching}):C?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:C})]}):W?t.jsx("div",{style:{flex:1},children:X?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:k.search.loading}):O.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:k.search.recentBrowse}),t.jsx("button",{onClick:fe,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:k.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:O.slice(0,M?10:3).map(Q=>Q.notFound?t.jsx(Il,{id:Q.id,onRemove:pe,t:k},Q.id):t.jsx(qi,{entry:Q,selected:B===Q.id,onClick:oe,getConfig:ye,onRemove:pe},Q.id))}),!M&&O.length>3&&t.jsx("button",{onClick:()=>K(!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:k.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h3",{style:{margin:"0 0 8px",color:o("fg")},children:k.search.searchTitle}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:k.search.searchSubtitle})]})}):Ce?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:m.map(({type:Q,icon:ce,name:F,key:ie})=>{const ne=j[ie]??[],he=_l[ie],ge=j[he]??0;if(ne.length===0)return null;const Be=!(S===Q)&&ge>pn;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:[ce," ",F,t.jsxs("span",{style:{fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[ge," ",k.unit.items]})]}),Be&&t.jsx("button",{onClick:()=>D(Q),style:{border:"none",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"12px"},children:k.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:ne.map(ve=>{if(x)return t.jsx(f.Fragment,{children:x(ve)},ve.id);const De=u==="card"?Cl:qi;return t.jsx(De,{entry:ve,selected:B===ve.id,onClick:oe,getConfig:ye,query:v},ve.id)})})]},Q)})}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h3",{style:{margin:"0 0 8px",color:o("fg")},children:Lt(k.search.noResultsFor,{query:v})}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:k.search.tryOther})]})})]})};function $l(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const or={color:"inherit",textDecoration:"none"},zl=({snippet:e})=>{const{convert:n}=Y();return t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.6},children:Jo(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))})},Cl=({entry:e,selected:n,onClick:i,getConfig:r,query:s})=>{const l=te(),{convert:p}=Y(),d=p(e.title||e.primary_name||e.id),c=e.measure_info?p(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",a=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&a.length?a.find(h=>{const y=typeof h=="string"?h:h==null?void 0:h.book_title;return y==null?void 0:y.toLowerCase().includes(s.toLowerCase())}):void 0,x=o("cover-accent"),g=je();return t.jsxs("a",{href:g(e.id),onClick:h=>i(e,h),className:"bim-result-card",style:{...or,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, ${x} 50%, ${o("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${x} 14%, ${o("bg")}), color-mix(in srgb, ${x} 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, ${x} 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:x},children:Array.from(d).map((h,y)=>t.jsx("span",{children:h},y))})]}),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:d}),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:["〔",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.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",p(e.era),"〕"]}),e.edition&&t.jsx("span",{children:p(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[l.search.alias,":",p(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(zl,{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]})]})]})]})},qi=({entry:e,selected:n,onClick:i,getConfig:r,query:s,onRemove:l})=>{const p=te(),{convert:d}=Y(),c=[...e.additional_titles||[],...e.attached_texts||[]],a=s&&c.length?c.find(x=>{const g=typeof x=="string"?x:x==null?void 0:x.book_title;return g==null?void 0:g.toLowerCase().includes(s.toLowerCase())}):void 0,u=je();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:x=>i(e,x),className:"bim-result-card",style:{...or,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:d(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:p.misc.textResource,children:"📝"}),e.has_image&&t.jsx("span",{title:p.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:["〔",d(e.era),"〕"]}),e.edition&&d(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:d(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,p.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:["〔",d(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:d(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",d(e.role)]}),e.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??"?"]})]}),a&&t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:[p.search.alias,":",d(a)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:p.search.removeFromRecent,"aria-label":p.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:"×"})]})},Il=({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 Tl(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 Rl({data:e}){const{convert:n}=Y(),{dynasty:i,birth_year:r,death_year:s}=e,l=[];return i&&l.push(`〔${n(i)}〕`),r!==void 0&&s!==void 0?l.push(`${r}—${s}`):r!==void 0?l.push(`${r}—?`):s!==void 0&&l.push(`?—${s}`),l.length===0?null:t.jsx("span",{style:{fontSize:"14px",color:o("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function El({alt_names:e}){const{convert:n}=Y(),i=new Map;for(const l of e){const p=l.type||"別名";i.has(p)||i.set(p,[]),i.get(p).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((l,p)=>{const d=r.indexOf(l),c=r.indexOf(p);return d===-1&&c===-1?0:d===-1?1:c===-1?-1:d-c});return t.jsx("div",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const p=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:p.map((d,c)=>t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),n(d)]},c))})]},l)})})}function Ll({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 Bl({works:e,transport:n,onNavigate:i,renderLink:r}){const s=te(),{convert:l}=Y(),p=je(),[d,c]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let g=!1;const h=e.map(k=>k.work_id);return(async()=>{const k=new Map;if(n.getEntriesByIds)try{const j=await n.getEntriesByIds(h);let $=!0;for(let S=0;S<h.length;S++){const _=j[S];_!=null&&_.title?k.set(h[S],_.title):_!=null&&_.primary_name?k.set(h[S],_.primary_name):$=!1}if($)return k}catch{}const m=[...h],v=8,b=new Array(v).fill(0).map(async()=>{for(;m.length;){const j=m.shift();if(!j)break;if(!k.has(j))try{if(n.getEntry){const _=await n.getEntry(j);if(_!=null&&_.title){k.set(j,_.title);continue}}const $=await n.getItem(j),S=$&&($.title||$.primary_name)||j;k.set(j,S)}catch{k.set(j,j)}}});return await Promise.all(b),k})().then(k=>{g||c(k)}),()=>{g=!0}},[e,n]);const a=new Map;for(const g of e){const h=g.role||"";a.has(h)||a.set(h,[]),a.get(h).push(g)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...a.keys()].sort((g,h)=>{const y=u.indexOf(g),k=u.indexOf(h);return y===-1&&k===-1?g.localeCompare(h):y===-1?1:k===-1?-1:y-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,")"]})]}),x.map(g=>{const h=a.get(g);return t.jsxs("div",{style:{marginBottom:"8px"},children:[g&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"2px"},children:[l(g)," ",t.jsxs("span",{style:{color:o("desc-fg")},children:["(",h.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:h.map((y,k)=>{const m=l(d.get(y.work_id)||y.work_id);return r?t.jsx("li",{children:r(y.work_id,m)},k):i?t.jsx("li",{children:t.jsx("a",{href:p(y.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),i(y.work_id))},style:{color:o("link-fg"),textDecoration:"underline",cursor:"pointer"},children:m})},k):t.jsx("li",{children:m},k)})})]},g)})]})}const rr=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:l})=>{var x;const p=te(),{convert:d}=Y();let c=!1;try{c=ae.extractStatus(e.id)==="draft"}catch{}const a=Tl(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:[d(e.primary_name),t.jsx(Rl,{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:p.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:p.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),a&&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(El,{alt_names:e.alt_names}),t.jsx(Ll,{data:e}),((x=e.description)==null?void 0:x.text)&&t.jsx("p",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:d(e.description.text)}),e.works&&e.works.length>0&&t.jsx(Bl,{works:e.works,transport:n,onNavigate:i,renderLink:r})]})},sr={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})=>t.jsx("a",{href:e,target:e!=null&&e.startsWith("http")?"_blank":void 0,rel:e!=null&&e.startsWith("http")?"noopener noreferrer":void 0,style:{color:o("link")},children:n}),code:({children:e})=>t.jsx("code",{style:{background:o("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})},Nl={...sr,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},Ke=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:s}=Y(),l=n?Nl:sr;return t.jsx("div",{className:r,style:i,children:t.jsx(qs,{remarkPlugins:[Js],components:l,children:s(e)})})},Wl=["〇","一","二","三","四","五","六","七","八","九"],Ji=["","十","百","千"];function lr(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 p=parseInt(n[l]),d=i-1-l;p===0?s=!0:(s&&r&&(r+="〇"),s=!1,p===1&&d===1&&l===0?r+=Ji[d]:r+=Wl[p]+Ji[d])}return r}function ar(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 Al={book:o("type-book"),work:o("type-work"),collection:o("type-collection"),entity:o("type-entity")};function Ml({type:e}){const n=te();return t.jsx("span",{style:ar(Al[e]),children:n.indexType[e]})}function Fl({isDraft:e}){const n=te(),i=o(e?"status-draft":"status-official");return t.jsx("span",{style:ar(i),children:e?n.status.draft:n.status.official})}function Pl({id:e}){const n=te(),[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 Ie({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 Me({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 cr({authors:e,type:n,onNavigate:i,renderLink:r}){const{convert:s}=Y();return t.jsx("span",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.6},children:e.map((l,p)=>{const d=s(l.name),c=l.entity_id?t.jsx(Le,{id:l.entity_id,label:d,onNavigate:i,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:d});return t.jsxs("span",{children:[p>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)]})]},p)})})}function Le({id:e,label:n,onNavigate:i,renderLink:r}){const s=je();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 Ol({id:e,title:n,edition:i,type:r,isDraft:s,authors:l,volumeText:p,meta:d,headerExtra:c,onNavigate:a,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}),p&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:p})]}),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(Ml,{type:r}),t.jsx(Fl,{isDraft:s}),t.jsx(Pl,{id:e})]}),((l==null?void 0:l.length)||d.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(cr,{authors:l,type:r,onNavigate:a,renderLink:u}),d]})]})}function dr({items:e,label:n,showMeta:i,onNavigate:r,renderLink:s}){const l=te(),{convert:p}=Y();if(!e.length)return null;const[d,c]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(Ie,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((a,u)=>{const x=d===u;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:o("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>c(x?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:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:p(a.source)}),!x&&i&&a.title_info&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p(a.title_info)}),a.source_bid&&t.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Le,{id:a.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),x&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${o("widget-border")}`},children:[i&&(a.title_info||a.author_info||a.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[a.title_info&&t.jsx(Me,{label:l.label.titleInfo,children:p(a.title_info)}),a.author_info&&t.jsx(Me,{label:l.label.authorInfo,children:p(a.author_info)}),a.edition&&t.jsx(Me,{label:l.label.edition,children:p(a.edition)})]}),a.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:p(a.summary)})]}),a.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:p(a.comment)})]}),a.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:p(a.additional_comment)})]})]})]},u)})})]})}function Dl({items:e,onNavigate:n,renderLink:i}){const r=te();return t.jsx(dr,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function pr({items:e,onNavigate:n,renderLink:i}){const r=te();return t.jsx(dr,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function ur({label:e,items:n}){const{convert:i}=Y();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{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 Hl({items:e}){const n=te();return t.jsx(ur,{label:n.section.aliases,items:e})}function Gl({items:e}){const n=te();return t.jsx(ur,{label:n.section.attachedTexts,items:e})}function Ul({items:e}){const n=te(),{convert:i}=Y();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{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 Vl({items:e}){const n=te(),{convert:i}=Y();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{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 Yl({items:e}){const n=te(),{convert:i}=Y();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{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 Zi({title:e,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:l}=Y(),[p,d]=f.useState([]);return f.useEffect(()=>{if(!n.length){d([]);return}if(!i){d(n.map(a=>({id:a})));return}let c=!1;return Promise.all(n.map(a=>i.getItem(a).then(u=>({id:a,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:a})))).then(a=>{c||d(a)}),()=>{c=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(Ie,{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:(p.length?p:n.map(c=>({id:c}))).map(c=>{const a=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(Le,{id:c.id,label:a,onNavigate:r,renderLink:s})},c.id)})})]}):null}function un({book:e,onNavigate:n,renderLink:i}){const r=te(),{convert:s}=Y(),[l,p]=f.useState(!1),d=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:d&&!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(Le,{id:e.id,label:c,onNavigate:n,renderLink:i})}),d&&t.jsx("span",{onClick:()=>p(a=>!a),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:"▼"})]}),d&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(Un,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Kl({ids:e,workData:n,transport:i,onNavigate:r,renderLink:s,footer:l}){const p=te(),{convert:d}=Y(),[c,a]=f.useState([]);if(f.useEffect(()=>{if(!e.length){a([]);return}if(!i){a(e.map(k=>({id:k})));return}let y=!1;return Promise.all(e.map(k=>i.getItem(k).then(m=>({id:k,title:m?m.title:void 0,edition:m?m.edition:void 0,resources:m?m.resources:void 0,resource_groups:m?m.resource_groups:void 0})).catch(()=>({id:k})))).then(k=>{y||a(k)}),()=>{y=!0}},[e,i]),!e.length)return null;const u=c.length?c:e.map(y=>({id:y})),x=new Map(u.map(y=>[y.id,y])),g=n==null?void 0:n.version_graph,h=ql(e,g);return t.jsxs(t.Fragment,{children:[t.jsxs(Ie,{children:[p.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,h.useGrouping?t.jsxs(t.Fragment,{children:[h.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:h.coreIds.map(y=>{const k=x.get(y);return k?t.jsx(un,{book:k,onNavigate:r,renderLink:s},y):null})}),h.groupedIds.map(y=>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:[d(y.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:o("desc-fg"),fontWeight:400},children:["(",y.ids.length,")"]}),y.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:o("desc-fg"),fontWeight:400},children:d(y.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:y.ids.map(k=>{const m=x.get(k);return m?t.jsx(un,{book:m,onNavigate:r,renderLink:s},k):null})})]},y.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(y=>t.jsx(un,{book:y,onNavigate:r,renderLink:s},y.id))})]})}function ql(e,n){var m,v;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[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,p=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&p.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const d=new Set(r),c=new Set([...s,...p]),a=b=>{if(c.has(b))return!0;const j=n.node_groups[b];return j!=null&&d.has(j)},u=[],x=new Map,g=[];for(const b of e)if(!((v=n.excluded_books)!=null&&v.includes(b)))if(a(b))u.push(b);else{const j=n.node_groups[b];j?(x.has(j)||x.set(j,[]),x.get(j).push(b)):g.push(b)}if(g.length+[...x.values()].reduce((b,j)=>b+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const y=new Map((n.groups??[]).map(b=>[b.id,b])),k=[...x.entries()].map(([b,j])=>{const $=y.get(b);return{id:b,label:($==null?void 0:$.label)??b,description:$==null?void 0:$.description,ids:j}});return g.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:u,groupedIds:k}}function Jl({workData:e,onNavigate:n,renderLink:i}){var p,d,c,a;const r=te(),{convert:s}=Y(),l=!!((p=e.description)!=null&&p.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(Le,{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)}):((d=e.juan_count)==null?void 0:d.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[lr(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(cr,{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(Ke,{text:e.description.text,style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(a=e.description)!=null&&a.text?"8px":0,fontSize:"13px"},children:t.jsx(Me,{label:r.label.parentWork,children:t.jsx(Le,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Zl({items:e,onNavigate:n,renderLink:i}){const r=te(),{convert:s}=Y();return e.length?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(l=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid color-mix(in srgb, ${o("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${o("type-collection")} 3%, transparent)`},children:[t.jsx("span",{style:{fontSize:"11px",color:o("type-collection")},children:r.indexType.collection}),t.jsx(Le,{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:Lt(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Vn=({data:e,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:p,className:d,style:c})=>{var A,W,T,R,N,O,E,X;const a=te(),{convert:u}=Y(),[x,g]=f.useState(null),[h,y]=f.useState(!1),[k,m]=f.useState(null),[v,b]=f.useState(null),[j,$]=f.useState([]),S=e||x;if(f.useEffect(()=>{if(e||!n||!i)return;let I=!1;return y(!0),m(null),i.getItem(n).then(M=>{I||(M?g(M):m(a.misc.notFoundEntry))}).catch(M=>{I||m(M instanceof Error?M.message:a.misc.loadFailed)}).finally(()=>{I||y(!1)}),()=>{I=!0}},[e,n,i]),f.useEffect(()=>{if(!S||!i){b(null),$([]);return}let I=!1;const M=S.type==="book"||S.type==="collection"?S.work_id:void 0;if(M?i.getItem(M).then(K=>{!I&&K&&K.type==="work"&&b(K)}).catch(()=>{}):b(null),S.type==="book"){const K=S;K.contained_in&&K.contained_in.length>0?Promise.all(K.contained_in.map(V=>{const G=typeof V=="string"?V:V.id,ee=typeof V=="string"?void 0:V.volume_index;return i.getItem(G).then(P=>({id:G,title:P&&P.title||G,volume_index:ee})).catch(()=>({id:G,title:G,volume_index:ee}))})).then(V=>{I||$(V)}):$([])}else $([]);return()=>{I=!0}},[S,i]),h)return t.jsx("div",{className:d,style:{...c,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((I,M)=>t.jsx("div",{style:{height:M===1?"32px":"16px",width:`${I}px`,background:o("widget-border"),borderRadius:"4px",opacity:.4}},M))})});if(k)return t.jsx("div",{className:d,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:d,style:c,children:t.jsx(rr,{data:S,transport:i,onNavigate:r,renderLink:s,headerExtra:l})});const _=S.type==="book"?S:null,w=S.type==="collection"?S:null,z=S.type==="work"?S:null;let B=!1;try{B=ae.extractStatus(S.id)==="draft"}catch{}let L="";S.measure_info?L=u(S.measure_info):(A=S.juan_count)!=null&&A.number?L=lr(S.juan_count.number)+a.unit.juan:(W=S.juan_count)!=null&&W.description&&(L=u(S.juan_count.description));const C=[];return(T=S.publication_info)!=null&&T.year&&C.push(t.jsx(Me,{label:a.label.year,children:S.publication_info.year},"year")),(R=S.current_location)!=null&&R.name&&C.push(t.jsx(Me,{label:a.label.currentLocation,children:u(S.current_location.name)},"loc")),(N=S.page_count)!=null&&N.description&&C.push(t.jsx(Me,{label:a.label.pageCount,children:S.page_count.description},"page")),_!=null&&_.edition&&C.push(t.jsx(Me,{label:a.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&C.push(t.jsx(Me,{label:a.label.parentWork,children:t.jsx(Le,{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(Me,{label:a.label.parentWork,children:z.parent_works.map((I,M)=>t.jsxs("span",{children:[M>0&&"、",t.jsx(Le,{id:I,onNavigate:r,renderLink:s})]},I))},"pws")),t.jsxs("div",{className:d,style:c,children:[t.jsx(Ol,{id:S.id,title:u(S.title),edition:S.edition?u(S.edition):void 0,type:S.type,isDraft:B,authors:S.authors,volumeText:L,meta:C,headerExtra:l,onNavigate:r,renderLink:s}),((O=S.description)==null?void 0:O.text)&&t.jsx(Ke,{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((I,M)=>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(I.title)}),t.jsx(Ke,{text:I.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:o("fg")}})]},M))}),j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ie,{children:a.section.containedIn}),t.jsx(Zl,{items:j,onNavigate:r,renderLink:s})]}),v&&t.jsxs(t.Fragment,{children:[t.jsx(Ie,{children:a.section.belongsToWork}),t.jsx(Jl,{workData:v,onNavigate:r,renderLink:s})]}),S.additional_works&&S.additional_works.length>0&&t.jsx(Ul,{items:S.additional_works}),S.additional_titles&&S.additional_titles.length>0&&t.jsx(Hl,{items:S.additional_titles}),S.attached_texts&&S.attached_texts.length>0&&t.jsx(Gl,{items:S.attached_texts}),S.indexed_by&&S.indexed_by.length>0&&t.jsx(Dl,{items:S.indexed_by,onNavigate:r,renderLink:s}),S.emendated_by&&S.emendated_by.length>0&&t.jsx(pr,{items:S.emendated_by,onNavigate:r,renderLink:s}),S.resources&&S.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ie,{children:a.section.resources}),t.jsx(Un,{items:S.resources,resourceGroups:S.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&t.jsx(Vl,{items:_.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&t.jsx(Yl,{items:w.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&t.jsx(Zi,{title:a.section.relatedVersions,ids:_.related_books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.books)&&w.books.length>0&&t.jsx(Zi,{title:a.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(Ie,{children:[a.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(I=>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(Le,{id:I.id,label:u(I.title),onNavigate:r,renderLink:s})},I.id))})]}),(((E=z==null?void 0:z.books)==null?void 0:E.length)||0)+(((X=z==null?void 0:z.collections)==null?void 0:X.length)||0)>0&&t.jsx(Kl,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z,transport:i,onNavigate:r,renderLink:s,footer:p}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const I=[],M=z.related_works.filter(q=>q.relation==="part_of"),K=z.related_works.filter(q=>q.relation==="has_part"),V=z.related_works.filter(q=>q.relation==="has_adaptation"),G=z.related_works.filter(q=>q.relation==="text_carried_by"),ee=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),P=z.related_works.filter(q=>!q.relation||!ee.has(q.relation));return M.length>0&&I.push({label:a.section.belongsToWork,items:M}),K.length>0&&I.push({label:a.section.containedWorks,items:K}),V.length>0&&I.push({label:a.section.adaptations,items:V}),G.length>0&&I.push({label:a.section.derivativeWorks,items:G}),P.length>0&&I.push({label:a.section.relatedWorks,items:P}),I.map(q=>t.jsxs("div",{children:[t.jsxs(Ie,{children:[q.label,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",q.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:q.items.map(Z=>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(Le,{id:Z.id,label:u(Z.title),onNavigate:r,renderLink:s})},Z.id))})]},q.label))})()]})};function Xl({data:e}){const n=te(),{convert:i}=Y(),{stats:r}=e,s=r.processed_volumes??r.total_found_volumes,l=s!=null&&e.total_volumes>0?Math.round(s/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:i(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"6px"},children:i(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:o("desc-fg")},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:o("fg")},children:e.total_volumes})," ",n.unit.volume]}),l!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:o("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:o("fg")},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&t.jsxs("span",{children:[n.catalog.matched," ",t.jsx("strong",{style:{color:o("fg")},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&t.jsxs("span",{children:[n.catalog.unmatched," ",t.jsx("strong",{style:{color:o("missing-fg")},children:r.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:o("desc-fg")},children:[n.catalog.source," ",e.source]})]})}function Ql({sections:e,activeSection:n,onSelect:i}){const r=te();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:Xi(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:Xi(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 Xi(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 ea({id:e,label:n,onNavigate:i,renderLink:r}){const s=je();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 ta(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 Qi({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const s=te(),{convert:l}=Y(),p=e.book_id||e.work_id,d=r&&e.volumes.length>0?ta(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:d}),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(a=>l(a)).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]}),p&&t.jsx(ea,{id:p,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!p&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const Yn=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:l,style:p})=>{const d=te(),[c,a]=f.useState(null),[u,x]=f.useState(!1),[g,h]=f.useState(null),[y,k]=f.useState(null),[m,v]=f.useState(""),b=e||c;f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let w=!1;return x(!0),h(null),i.getCollectionCatalog(n).then(z=>{w||(z?a(z):h(d.catalog.notFound))}).catch(z=>{w||h(z instanceof Error?z.message:d.catalog.loadFailed)}).finally(()=>{w||x(!1)}),()=>{w=!0}},[e,n,i,d]);const j=(b==null?void 0:b.sections)&&b.sections.length>0,$=f.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const w=b.books.map(B=>B.volumes[0]).filter(B=>B!=null);return new Set(w).size<w.length},[b]),S=f.useMemo(()=>{if(!b)return[];let w=b.books;if(y&&(w=w.filter(z=>z.section===y)),m.trim()){const z=m.trim().toLowerCase();w=w.filter(B=>B.title.toLowerCase().includes(z)||B.sub_items&&B.sub_items.some(L=>L.toLowerCase().includes(z))||B.edition&&B.edition.toLowerCase().includes(z))}return w},[b,y,m]),_=f.useMemo(()=>{if(!$)return null;const w=[],z=new Map;for(const L of S){if(!L.volumes||L.volumes.length===0)continue;const C=L.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(L)}const B=[...z.keys()].sort((L,C)=>L-C);for(const L of B)w.push({volume:L,books:z.get(L)});return w},[S,$]);return u?t.jsx("div",{className:l,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):g?t.jsx("div",{className:l,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:g}):b?t.jsxs("div",{className:l,style:p,children:[t.jsx(Xl,{data:b}),j&&t.jsx(Ql,{sections:b.sections,activeSection:y,onSelect:k}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:m,onChange:w=>v(w.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:o("desc-fg")},children:[S.length," ",d.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:Lt(d.catalog.volume,{n:w.volume})}),w.books.map((B,L)=>t.jsx(Qi,{book:B,onNavigate:r,renderLink:s,showVolumes:B.volumes.length>1},`${w.volume}-${L}`))]},`${w.volume}-${z}`)):S.map((w,z)=>t.jsx(Qi,{book:w,onNavigate:r,renderLink:s,showVolumes:!0},z)),S.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},nt=()=>{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)})},xr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],na={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function be(e){return na[e]??e}const xt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],ft={熹平: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},fr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function en(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 ia(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 oa=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,eo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Kn(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(eo))if(n.startsWith(s))return eo[s];const i=be(n);if(Je[i]!=null)return i;const r=Ue(n);if(r&&n.length<=r.length+1)return be(r)}function qe(e,n){if(n){const i=fr[`${n}|${e}`];if(i!=null)return i}return ft[e]}const ra=1911;function sa(e){const n=ft[e];if(n==null)return;const i=Fe[e];let r;for(const[s,l]of Object.entries(ft))Fe[s]===i&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const la={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function qt(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 p=la[l];if(p===void 0)return;r=!0,l==="十"?i=(i||1)*10:l==="廿"||l==="卅"?(n+=p,i=0):i>=10?(n+=i+p,i=0):i=i*10+p}const s=n+i;return r&&s>0?s:void 0}function Ue(e){for(const n of xr)if(e.startsWith(n))return n}const Fe={};{const e=(n,i)=>{for(const r of i)Fe[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Ze(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(ft))if(e.includes(r)&&!(i&&Fe[r]&&Fe[r]!==i&&fr[`${i}|${r}`]==null))return r}function Bt(e){var p,d,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=(p=e.lineage)==null?void 0:p.year_text;if(r){const a=Ue(r)??"";return{era:be(a),reign:Ze(r,a)??"",source:"lineage"}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const a=en(s);if(a)return{era:ia(a.from),reign:"",source:"publication"};const u=Ue(s)??Kn(s)??((c=xt.find(h=>h.pattern.test(s)))==null?void 0:c.era)??"",x=Ze(s,u)??"",g=u||(x?Fe[x]??"":"");if(g||x)return{era:be(g),reign:x,source:"publication"}}const l=e.edition||e.title||"";if(l){const a=Ue(l);if(a)return{era:be(a),reign:Ze(l,a)??"",source:"edition"};const u=xt.find(x=>x.pattern.test(l));if(u)return{era:be(u.era),reign:Ze(l,u.era)??u.reign??"",source:"edition"}}return n}function tn(e){var r,s,l,p,d,c,a,u,x;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 g=en(n);if(g)return g.from}const i=[(p=e.lineage)==null?void 0:p.year_text,(d=e.publication_info)==null?void 0:d.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const g of i){const h=((c=e.publication_info)==null?void 0:c.year)||((a=e.lineage)==null?void 0:a.year_text);if(h&&g!==h&&(Ue(h)||Kn(h)))break;const y=g.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??g.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(y){const j=parseInt(y[1],10);if(j>=100&&j<=2100)return j}const k=g.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(k){const j=Ue(g);if(!j||be(j)==="民國"){const S=qt(k[1]);if(S!=null&&S>=1&&S<=120)return ra+S}}const m=Ue(g)??((u=xt.find(j=>j.pattern.test(g)))==null?void 0:u.era),v=m?be(m):void 0,b=Ze(g,v)??(Ue(g)||(x=xt.find(j=>j.pattern.test(g)))==null?void 0:x.reign);if(b){const j=qe(b,v);if(j==null)continue;const $=g.indexOf(b),S=$>=0?g.slice($+b.length):"",_=S.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??S.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),w=_?qt(_[1]):void 0;return j+(w?w-1:0)}}}function qn(e){var p,d,c,a,u,x;const n=(p=e.dating)==null?void 0:p.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(d=e.lineage)==null?void 0:d.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 g=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const h=$n[be(g[1])],y=Je[be(g[2])];if(h!=null&&y!=null)return{from:Math.min(h,y)-20,to:Math.max(h,y)+40}}}const s=(a=e.publication_info)==null?void 0:a.year;if(s){const g=en(s);if((g==null?void 0:g.to)!=null)return{from:g.from,to:g.to};const h=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(h){const y=$n[be(h[1])],k=Je[be(h[2])];if(y!=null&&k!=null)return{from:Math.min(y,k)-20,to:Math.max(y,k)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const g of l){if(!/[間间]/.test(g))continue;const h=Ue(g)??Kn(g)??((x=xt.find(m=>m.pattern.test(g)))==null?void 0:x.era),y=h?be(h):void 0,k=[];for(const m of Object.keys(ft))g.includes(m)&&(y&&Fe[m]&&Fe[m]!==y||qe(m,y)!=null&&k.push(m));if(k.length===0){const m=g.match(/([一-鿿])([一-鿿])[間间]/);if(m&&y){for(const v of[m[1],m[2]])for(const b of Object.keys(ft))if(Fe[b]===y&&!(b[0]!==v&&b[b.length-1]!==v)&&qe(b,y)!=null){k.push(b);break}}}if(k.length>0){const m=k.map($=>qe($,y)).filter($=>$!=null),v=Math.min(...m),b=k.reduce(($,S)=>qe($,y)>=qe(S,y)?$:S),j=sa(b)??xn(y??"")??Math.max(...m);return{from:v,to:j>v?j:xn(y??Fe[b]??"")??v}}if(y&&Je[y]!=null)return{from:Je[y],to:xn(y)??Je[y]}}}const Je={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},aa=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],ca=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,to=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function no(e,n){for(const i of xr){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!Ze(e.slice(r),be(i)))continue}const s=be(i);if(s===n)continue;const l=e.slice(r),p=Ze(l,s)??"";let d;if(p){const c=qe(p,s);if(c!=null){const u=l.slice(l.indexOf(p)+p.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),x=u?qt(u[1]):void 0;d=c+(x?x-1:0)}}return{era:s,reign:p,year:d}}for(const i of xt)if(i.pattern.test(e))return{era:be(i.era),reign:i.reign??""}}function da(e){var v,b,j,$,S;const n=Bt(e),i=((v=e.publication_info)==null?void 0:v.year)??"",r=i?en(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),p=((b=e.lineage)==null?void 0:b.year_text)??"",d=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(p),c=n.source==="publication"&&oa.test(i),a=n.source==="publication"&&/[間间]/.test(i),u=p.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let x;l||d||c||a?x=void 0:u?x=parseInt(u[2],10):x=tn(e);const g=x==null?qn(e):void 0;let h;n.source==="publication"&&(c||to.test(i))?h="uncertain":n.source==="lineage"||n.source==="publication"?h="attested":to.test(s)||!n.reign&&x==null?h="uncertain":h="inferred";const y=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((j=e.lineage)==null?void 0:j.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:x,yearRange:g,certainty:h,source:n.source==="edition"?"edition":"catalog",basis:y};if(u){const _=p.match(/[、,,]\s*([宋元明清])/);_&&_[1]!==k.era&&(k.laterRepair={era:_[1]})}if(!k.laterRepair&&ca.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(k.laterRepair={era:_[1]})}const m=aa.find(_=>_.re.test(s));if(m){const _=s.search(m.re),w=s.slice(_),z=no(w,n.era)??no(s,n.era);z&&(k.basedOn={era:z.era,reign:z.reign,year:z.year,relation:m.relation})}return k}const $n={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function xn(e){return $n[e]}function gr(e){const n=tn(e);if(n!=null)return n;const i=qn(e);if(i)return i.from;const r=Bt(e).era;return r?Je[r]:void 0}const io=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function zn(e){const n=io.indexOf(e);return n===-1?io.length:n}function pa(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 nn(e,n){const i=Dn(e||[]),r=new Map,s=[];for(const a of i)a.group?(r.has(a.group)||r.set(a.group,[]),r.get(a.group).push(a)):s.push(a);for(const a of r.values())a.sort((u,x)=>{const g=h=>h.group_role==="origin"?0:h.group_role==="mirror"?1:2;return g(u)-g(x)});const l={text:[],image:[],textImage:[],physical:[]};for(const a of s){const u=Qe(a),x=u.includes("text"),g=u.includes("image");x&&g?l.textImage.push(a):x?l.text.push(a):g?l.image.push(a):l.physical.push(a)}const d=["text","image","textImage","physical"].filter(a=>l[a].length>0).map(a=>({key:a,items:l[a]})),c=[...r.entries()].map(([a,u])=>{var x,g;return{key:a,label:((x=n==null?void 0:n[a])==null?void 0:x.label)||a,description:(g=n==null?void 0:n[a])==null?void 0:g.description,items:u}});return{buckets:d,mirrors:c,total:i.length}}function Nt(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=Xt(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 hr(e,n){if(Nt(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,p;const i=e.resources||[],r=[],s=[];for(const d of i){const c=Qe(d);c.includes("image")&&r.push(d),c.includes("physical")&&s.push(d)}return{id:e.id,name:e.edition||e.title||e.id,era:Bt(e),year:tn(e),sortYear:gr(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:ua(e.id,n),group:(p=n==null?void 0:n.node_groups)==null?void 0:p[e.id],hasImage:r.length>0}}function ua(e,n){var d,c;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(d=n.collections)==null?void 0:d[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)??[],p=(c=n.node_groups)==null?void 0:c[e];return!!p&&l.includes(p)}function br(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,a)=>({r:c,i:a})).sort((c,a)=>{const u=c.r.sortYear,x=a.r.sortYear;return u!=null&&x!=null?u-x||c.i-a.i:u!=null?-1:x!=null?1:c.i-a.i}).map(c=>c.r):l=l.map((c,a)=>({r:c,i:a})).sort((c,a)=>{const u=x=>(x.important?0:1)*2+(x.hasImage?0:1);return u(c.r)-u(a.r)||c.i-a.i}).map(c=>c.r);const d=[...new Set(s.map(c=>c.era.era).filter(Boolean))].sort((c,a)=>zn(c)-zn(a));return{rows:l,allRows:s,eras:d,hasInferredEra:s.some(c=>c.era.source==="edition")}}function xa(e,n){var m,v;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[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,p=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&p.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const d=new Set(r),c=new Set([...s,...p]),a=b=>{if(c.has(b))return!0;const j=n.node_groups[b];return j!=null&&d.has(j)},u=[],x=new Map,g=[];for(const b of e)if(!((v=n.excluded_books)!=null&&v.includes(b)))if(a(b))u.push(b);else{const j=n.node_groups[b];j?(x.has(j)||x.set(j,[]),x.get(j).push(b)):g.push(b)}if(g.length+[...x.values()].reduce((b,j)=>b+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const y=new Map((n.groups??[]).map(b=>[b.id,b])),k=[...x.entries()].map(([b,j])=>{const $=y.get(b);return{id:b,label:($==null?void 0:$.label)??b,description:$==null?void 0:$.description,ids:j}});return g.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:u,groupedIds:k}}const yr=["撰","編","注","校","譯","繪","其他"],fa=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function Jn(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of fa)if(r.test(n))return i;return"其他"}function Zn(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function jr(e){const n=new Map;for(const r of e){const s=Jn(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:e.length}];for(const r of yr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function vr(e,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(p=>({id:p.work_id||p.book_id||void 0,title:p.title,section:p.section,volumes:p.volumes||[],subItems:p.sub_items,edition:p.edition,found:p.found_volumes,expected:p.expected_volumes})),l=[...new Set(s.map(p=>p.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:Rt(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,p;return{id:s,title:((l=i==null?void 0:i.get(s))==null?void 0:l.title)||s,edition:(p=i==null?void 0:i.get(s))==null?void 0:p.edition,volumes:[]}}),source:"books",sections:[]}}function Rt(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 on(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((l,p)=>l-p),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 ga=["〇","一","二","三","四","五","六","七","八","九"],oo=["","十","百","千"];function kr(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 p=parseInt(n[l]),d=i-1-l;p===0?s=!0:(s&&r&&(r+="〇"),s=!1,p===1&&d===1&&l===0?r+=oo[d]:r+=ga[p]+oo[d])}return r}function ha(e){return e==null?"":typeof e=="string"?e:e.title??""}function et(e,n="卷"){var r,s;const i=e;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?kr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Sr(e){var r;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 ma="guji_markdown";function Cn(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 ba=/^□\{guess=([^\s{}]+)\}/;function ya(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function wr(e,n){let i=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
2
- `)return-1;if(s==="\\"){r++;continue}if(s==="[")i++;else if(s==="]"&&(i--,i===0))return r}return-1}function ja(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function va(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(`
3
- `)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const r=wr(e,n+3);return r>n+4?{node:{type:"zi",label:ja(e.slice(n+4,r))},end:r+1}:null}if(i==="□"&&e[n+1]==="{"){const r=ba.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function _r(e,n,i,r){const s=[];let l="";const p=()=>{if(!l)return;const d=r?l.replace(/\\?\|/g,""):l;d&&s.push({type:"text",text:d}),l=""};for(;n<e.length;){const d=e[n];if(i!==null){if(d===i)return p(),{nodes:s,end:n};if(d===`
4
- `)return null}const c=va(e,n);if(c){p(),s.push(c.node),n=c.end;continue}let a=null;if(d==="⟨"?a="⟩":d==="<"&&ya(e,n)&&(a=">"),a){const u=_r(e,n+1,a,!0);if(u){p(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=d,n++}return i!==null?null:(p(),{nodes:s,end:n})}function $r(e){return _r(e,0,null,!1).nodes}function ka(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function zr(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${zr(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const Sa=216,ro="clamp(280px, 23vw, 360px)",wa=1440,Cr="(max-width: 719px)",_a=`${Cr}, (pointer: coarse)`,$a=`
5
- .bim-d-main.bim-d-main-grid { max-width: ${wa}px; padding: 16px 32px 0; }
1
+ "use strict";var Us=Object.create;var Pi=Object.defineProperty;var Vs=Object.getOwnPropertyDescriptor;var Ys=Object.getOwnPropertyNames;var Ks=Object.getPrototypeOf,qs=Object.prototype.hasOwnProperty;var Js=(e,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Ys(n))!qs.call(e,s)&&s!==i&&Pi(e,s,{get:()=>n[s],enumerable:!(r=Vs(n,s))||r.enumerable});return e};var kt=(e,n,i)=>(i=e!=null?Us(Ks(e)):{},Js(n||!e||!e.__esModule?Pi(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const pe=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),f=require("react"),Zs=require("react-markdown"),Xs=require("remark-gfm"),Qs=e=>`/book-index?id=${e}`,Yo=f.createContext(Qs);function el({buildUrl:e,children:n}){const i=f.useMemo(()=>e,[e]);return t.jsx(Yo.Provider,{value:i,children:n})}function ve(){return f.useContext(Yo)}const Ko="",qo="";function Jo(e){const n=[];let i=!1,r=e;for(;r.length;){const s=i?qo:Ko,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 $e(e,n){return{title:e,tokens:n}}const Oi='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',tl=[$e("基础(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"}}),$e("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),$e("提示与警告",{"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)"}}),$e("遮罩与阴影",{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)"}}),$e("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),$e("资源",{"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"}}),$e("整理本(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"}}),$e("版本传承(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"}}),$e("编辑器视图(主要在 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")'}}),$e("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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:"唯一的状态色块「有影印」"},"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}}),$e("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),$e("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),$e("字体(全站无衬线,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:Oi,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:Oi,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],nl=Object.assign({},...tl.map(e=>e.tokens)),Zo={};for(const[e,n]of Object.entries(nl))Zo[e]=`var(--bim-${e}, ${n.value})`;function o(e){const n=Zo[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function Qe(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function il(e,n){return Qe(e).includes(n)}const kn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},ol={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};o("quality-published"),o("quality-fine"),o("quality-rough"),o("quality-ocr");const mt=f.createContext(null),Xo={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:"圖片資源"}},rl={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:"图片资源"}},sl={"zh-Hant":Xo,"zh-Hans":rl},Qo="bim-locale";function ll(){try{const e=localStorage.getItem(Qo);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function al(e){try{localStorage.setItem(Qo,e)}catch{}}const cl="zh-Hans",dl=({locale:e,onLocaleChange:n,children:i})=>{const[r,s]=f.useState(e??cl),l=e??r;f.useEffect(()=>{if(e)return;const u=ll();u&&u!==r&&s(u)},[]);const[p,d]=f.useState(null);f.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(u=>{const x=u.Converter({from:"tw",to:"cn"});d(()=>x)}).catch(()=>{d(()=>u=>u)}):d(null)},[l]);const c=f.useCallback(u=>{s(u),al(u),n==null||n(u)},[n]),a=f.useMemo(()=>({locale:l,setLocale:c,messages:sl[l],converter:p}),[l,c,p]);return t.jsx(mt.Provider,{value:a,children:i})};function ie(){const e=f.useContext(mt);return(e==null?void 0:e.messages)??Xo}const pl=2e3;function V(){const e=f.useContext(mt),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(p=>{if(!p)return"";if(!i)return p;const d=r.current.get(p);if(d!==void 0)return d;const c=i(p);if(r.current.size>=pl){const a=r.current.keys().next().value;a!==void 0&&r.current.delete(a)}return r.current.set(p,c),c},[i]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Lt(e,n){return e.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function ul(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 xl(){return{id:"",name:"",url:"",type:"text",details:""}}const Sn=({items:e,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const l=ie(),[p,d]=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}],a=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=y=>{if(!s)return!0;const j=Qe(y);return s==="text"?j.includes("text"):s==="image"?j.includes("image")||j.includes("physical"):s==="physical"?j.includes("physical"):j.includes(s)},x=e.map((y,j)=>({item:y,originalIndex:j})).filter(({item:y})=>u(y)),g=()=>{const y=xl();s&&(y.type=s),n([...e,y]),d(e.length)},h=y=>{n(e.filter((j,$)=>$!==y)),d(null)},b=(y,j,$)=>{const S=[...e];if(S[y]={...S[y],[j]:$},j==="url"&&!S[y].id){const _=ul($);_&&(S[y].id=_)}n(S)},k=(y,j,$)=>{const _={...e[y].metadata||{}};$?_[j]=$:delete _[j],b(y,"metadata",Object.keys(_).length>0?_:void 0)},m=(y,j)=>{const $=j.trim()?j.split(/[,,、]/).map(S=>S.trim()).filter(Boolean):void 0;b(y,"structure",$)},v=(y,j,$)=>{const _=e[y].coverage||{level:1,ranges:""};j==="level"?_.level=parseInt($)||1:_.ranges=$,b(y,"coverage",_.ranges?_:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:y,originalIndex:j})=>{var $,S,_;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>d(p===j?null:j),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:p===j?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:fl(y.type??"text"),color:o("on-color-fg")},children:(()=>{var z,B;const w=Qe(y);return w.length===0?y.type??"text":w.length===1?((z=c.find(E=>E.value===w[0]))==null?void 0:z.label)??w[0]:w.includes("text")&&w.includes("image")?((B=c.find(E=>E.value==="text+image"))==null?void 0:B.label)??"text+image":w.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${l.editor.resourcePlaceholder} ${j+1}`}),y.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:y.id}),y.url&&t.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:w=>w.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&y.url&&gl(j,r==null?void 0:r[j],i,l),t.jsx("button",{onClick:w=>{w.stopPropagation(),h(j)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),p===j&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:[il(y,"image")&&y.url&&hl(y,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:St,children:[t.jsx("span",{style:wt,children:l.label.type}),t.jsx("select",{value:y.type,onChange:w=>b(j,"type",w.target.value),style:{...Ae,flex:1},children:c.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]}),t.jsxs("label",{style:St,children:[t.jsx("span",{style:wt,children:l.label.rootType}),t.jsx("select",{value:y.root_type||"catalog",onChange:w=>b(j,"root_type",w.target.value),style:{...Ae,flex:1},children:a.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:y.id,onChange:w=>b(j,"id",w.target.value),placeholder:l.editor.idAutoExtract,style:{...Ae,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:y.name,onChange:w=>b(j,"name",w.target.value),placeholder:l.editor.resourceName,style:{...Ae,flex:1}})]}),t.jsx("input",{type:"text",value:y.url,onChange:w=>b(j,"url",w.target.value),placeholder:l.editor.resourceUrl,style:Ae}),t.jsx("input",{type:"text",value:(($=y.structure)==null?void 0:$.join("、"))||"",onChange:w=>m(j,w.target.value),placeholder:l.editor.structurePlaceholder,style:Ae}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:St,children:[t.jsx("span",{style:wt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((S=y.coverage)==null?void 0:S.level)??"",onChange:w=>v(j,"level",w.target.value),placeholder:"1",style:{...Ae,width:"60px"}})]}),t.jsxs("label",{style:{...St,flex:1},children:[t.jsx("span",{style:wt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:((_=y.coverage)==null?void 0:_.ranges)||"",onChange:w=>v(j,"ranges",w.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...Ae,flex:1}})]})]}),t.jsx("textarea",{value:y.details||"",onChange:w=>b(j,"details",w.target.value),placeholder:l.editor.detailsPlaceholder,style:{...Ae,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 B;return t.jsxs("label",{style:{...St,gap:"4px"},children:[t.jsx("span",{style:{...wt,minWidth:"56px"},children:z}),t.jsx("input",{type:"text",value:((B=y.metadata)==null?void 0:B[w])||"",onChange:E=>k(j,w,E.target.value),placeholder:z,style:{...Ae,flex:1}})]},w)})})]})]})]})]},j)}),t.jsxs("button",{onClick:g,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 fl(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 gl(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:p=>{p.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 hl(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 Ae={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"},St={display:"flex",alignItems:"center",gap:"6px"},wt={fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap"},ml={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function tt(e){try{return ml[new URL(e).hostname]}catch{return}}const Di={text:0,image:1,physical:2};function On(e){return e.length===0?"physical":[...e].sort((n,i)=>(Di[n]??99)-(Di[i]??99)).join("+")}function Dn(e){var p;const n=d=>{const c=d.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const a=d.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},i=new Map;for(let d=0;d<e.length;d++){const c=e[d];if(c.volumes&&c.volumes.length>0)continue;const a=n(c.name);if(!a)continue;const[u,x]=a,g=`${u}|${On(Qe(c))}`;i.has(g)||i.set(g,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const h=i.get(g);h.volumes.push({volume:x,url:c.url||void 0,status:"found"}),h.indices.push(d)}const r=[],s=new Set;for(const d of i.values())if(!(d.volumes.length<2)){d.volumes.sort((c,a)=>c.volume-a.volume),d.base.volumes=d.volumes,d.base.expected_volumes=d.volumes.length,d.base.url||(d.base.url=((p=d.volumes.find(c=>c.url))==null?void 0:p.url)??""),r.push(d.base);for(const c of d.indices)s.add(c)}const l=[...r];for(let d=0;d<e.length;d++)s.has(d)||l.push(e[d]);return l}function er(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 tr(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||er(n)}))}function Xt(e){const n=tr(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 Hn(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 Gn(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 bt(e){if(!e.url)return;const n=Hn(e.metadata);return n?Gn(e.url,n):e.url}const Hi={text:o("restype-text"),image:o("restype-image"),"text+image":o("restype-text-image"),physical:o("restype-physical")};function bl(e){return e.includes("text")&&e.includes("image")?Hi["text+image"]:Hi[e[0]||"physical"]}const Un=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const l=ie(),{convert:p}=V(),d=f.useMemo(()=>Dn(e||[]),[e]),{mirrorGroups:c,ungroupedItems:a}=f.useMemo(()=>{const m=new Map,v=[];for(const y of d){const j=y.group;j?(m.has(j)||m.set(j,[]),m.get(j).push(y)):v.push(y)}for(const y of m.values())y.sort((j,$)=>{const S=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return S(j)-S($)});return{mirrorGroups:m,ungroupedItems:v}},[d]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},x=m=>u[m]?u[m]:m.split("+").map(v=>u[v]||v).join("+");if(!d||d.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:d.map((m,v)=>t.jsx(dn,{item:m},m.id||v))});const g=(m,v)=>{const y=i==null?void 0:i[m],j=(y==null?void 0:y.label)||m,$=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:p(j)}),$&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.5},children:p($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((S,_)=>t.jsx(dn,{item:S,onNavigate:r,renderLink:s},S.id||_))})]},`group-${m}`)},h=new Map;for(const m of a){const v=On(Qe(m));h.has(v)||h.set(v,[]),h.get(v).push(m)}const b=["text","image","text+image","physical"],k=[...b.filter(m=>h.has(m)),...[...h.keys()].filter(m=>!b.includes(m)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([m,v])=>g(m,v)),k.map(m=>{const v=h.get(m),y=bl(m.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:x(m)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((j,$)=>t.jsx(dn,{item:j,onNavigate:r,renderLink:s},j.id||$))})]},m)})]})},yl={bw:{label:"",bg:o("colormode-bw-bg"),fg:o("colormode-bw-fg")},color:{label:"",bg:o("colormode-color-bg"),fg:o("colormode-color-fg")}},dn=({item:e})=>{const n=ie(),{convert:i}=V(),[r,s]=f.useState(!1),l=f.useMemo(()=>(e.url?tt(e.url):void 0)||i(e.name),[e.url,e.name,i]),p=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(b=>({...b,url:b.url||er(b)})),[e.volumes]),d=p&&p.length>0,c=d?new Set(p.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,a=d?new Set(p.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=e.expected_volumes??(d?c+a:0),x=e.color_mode?{...yl[e.color_mode],label:n.colorMode[e.color_mode]}:null,g=e.details&&!d?i(e.details):null,h={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:h,children:[t.jsx("span",{style:{fontWeight:500},children:l}),x&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),g&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:g}),d&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[c,"/",u,n.unit.volume,a>0&&t.jsxs("span",{style:{color:o("missing-fg"),marginLeft:"3px"},children:["缺",a]})]}),e.url&&t.jsx("a",{href:(()=>{const b=Hn(e.metadata);return b?Gn(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}),d&&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?"▲":"▼"})]}),d&&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:p.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)})})]})},nr=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:p})=>{const d=ie(),c=e==="local",a=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",x=u?u.split(/[/\\]/).pop()||u:"",g={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")},h={onMouseOver:k=>k.currentTarget.style.opacity="0.8",onMouseOut:k=>k.currentTarget.style.opacity="1"},b=t.jsxs("div",{onClick:s,title:a?d.mode.switchToOfficial:d.mode.switchToDraft,style:{...g,background:o(a?"warning":"success"),color:o("on-color-fg")},...h,children:[t.jsx("span",{children:a?"📝":"📚"}),t.jsx("span",{children:a?"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:d.mode.switchToSync,style:g,...h,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:d.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:p,title:u||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...h,children:[t.jsx("span",{children:"📂"}),x&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):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:d.mode.switchToLocal,style:g,...h,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:d.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:x||d.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...h,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:c?d.mode.switchToGithub:d.mode.switchToLocal,style:g,...h,children:[t.jsx("span",{children:c?"📁":"🌐"}),t.jsx("span",{children:c?d.mode.localMode:d.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&t.jsxs("div",{onClick:p,title:u||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...h,children:[t.jsx("span",{children:"📂"}),x&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!c&&x&&t.jsxs("div",{style:{...g,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:x})]})]})},Qt="bim-search-history",Gi=10,Ui=8;function Tt(){try{const e=localStorage.getItem(Qt);return e?JSON.parse(e):[]}catch{return[]}}function jl(e){try{const n=Tt().filter(i=>i!==e);n.unshift(e),n.length>Gi&&(n.length=Gi),localStorage.setItem(Qt,JSON.stringify(n))}catch{}}function vl(e){try{const n=Tt().filter(i=>i!==e);localStorage.setItem(Qt,JSON.stringify(n))}catch{}}function kl(){try{localStorage.removeItem(Qt)}catch{}}const ir=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:l})=>{const p=ie(),d=l??p.search.placeholder,c={work:p.indexType.work,book:p.indexType.book,collection:p.indexType.collection,entity:p.indexType.entity},[a,u]=f.useState(!1),[x,g]=f.useState([]),[h,b]=f.useState(-1),[k,m]=f.useState(Tt),v=f.useRef(null),y=f.useRef(null),j=f.useRef(null),$=f.useRef(!1);f.useEffect(()=>{b(-1);const C=n.trim();if(!C){g(k.map(T=>({type:"history",text:T})));return}if(!e.searchAll){g([]);return}let A=!1;const W=setTimeout(()=>{e.searchAll(C,Ui).then(T=>{if(A)return;const L=[...T.works,...T.books,...T.collections,...T.entities??[]];g(L.slice(0,Ui).map(M=>({type:"entry",text:M.title||M.id,entry:M})))}).catch(()=>{A||g([])})},80);return()=>{A=!0,clearTimeout(W)}},[n,k,e]),f.useEffect(()=>{const C=A=>{j.current&&!j.current.contains(A.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=A=>{var W,T;if(A.key==="/"&&document.activeElement!==v.current){const L=(W=document.activeElement)==null?void 0:W.tagName;if(L==="INPUT"||L==="TEXTAREA"||L==="SELECT")return;A.preventDefault(),(T=v.current)==null||T.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const S=f.useCallback(C=>{C.trim()&&(jl(C.trim()),m(Tt())),r(C),u(!1)},[r]),_=f.useCallback(C=>{C.type==="history"?(i(C.text),S(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(i(C.text),S(C.text)))},[i,S,s]),w=f.useCallback(C=>{if(!a||x.length===0){C.key==="Enter"&&S(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(A=>(A+1)%x.length);break;case"ArrowUp":C.preventDefault(),b(A=>(A-1+x.length)%x.length);break;case"Enter":C.preventDefault(),h>=0&&h<x.length?_(x[h]):S(n);break;case"Escape":C.preventDefault(),u(!1);break}},[a,x,h,n,S,_]),z=f.useCallback((C,A)=>{A.stopPropagation(),vl(C),m(Tt()),g(W=>W.filter(T=>!(T.type==="history"&&T.text===C)))},[]),B=f.useCallback(C=>{C.stopPropagation(),kl(),m([]),g([])},[]);f.useEffect(()=>{if(h>=0&&y.current){const C=y.current.children;C[h]&&C[h].scrollIntoView({block:"nearest"})}},[h]);const E=!n.trim()&&k.length>0;return t.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:v,type:"text",placeholder:d,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"}}),a&&x.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:p.search.history}),t.jsx("button",{onClick:B,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:p.search.clearAll})]}),x.map((C,A)=>t.jsxs("div",{onClick:()=>_(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:o("fg"),background:A===h?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:W=>z(C.text,W),style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:p.action.remove,children:"×"})]},`${C.type}-${C.text}-${A}`))]})]})},ut="bim-recent-ids",Vi="bim-recent-entries",Yi=50,pn=5,Sl=50,wl=200;function at(){try{const e=localStorage.getItem(ut);if(e)return JSON.parse(e);const n=localStorage.getItem(Vi);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(ut,JSON.stringify(i)),localStorage.removeItem(Vi),i}return[]}catch{return[]}}function Ki(e){try{const n=at().filter(i=>i!==e);n.unshift(e),n.length>Yi&&(n.length=Yi),localStorage.setItem(ut,JSON.stringify(n))}catch{}}function _l(e){try{const n=at().filter(i=>i!==e);localStorage.setItem(ut,JSON.stringify(n))}catch{}}function $l(){try{localStorage.removeItem(ut)}catch{}}const zl={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},wn=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:p,onConfigurePath:d,onSelectFolder:c,hideModeIndicator:a,resultVariant:u="compact",renderEntry:x,initialQuery:g,onQueryChange:h,headerRight:b})=>{const k=ie(),m=[{type:"work",icon:"✍️",name:k.indexType.work,key:"works"},{type:"book",icon:"📖",name:k.indexType.book,key:"books"},{type:"collection",icon:"📚",name:k.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:k.indexType.entity,key:"entities"}],[v,y]=f.useState(g??""),[j,$]=f.useState(null),[S,_]=f.useState(null),[w,z]=f.useState(!1),[B,E]=f.useState(null),[C,A]=f.useState(""),[W,T]=f.useState(!g),[L,M]=f.useState(at),[P,R]=f.useState([]),[ne,I]=f.useState(!1),[F,K]=f.useState(!1),[G,U]=f.useState(null),[te,O]=f.useState(null),Y=f.useRef(void 0),Z=f.useRef(!1),X=f.useCallback(async(Q,q)=>{if(!Q.trim()){T(!0),$(null),_(null);return}T(!1),z(!0),A("");try{if(e.searchAll){const N=await e.searchAll(Q,q??pn);$(N)}else{const N=["work","book","collection","entity"],ee=await Promise.all(N.map(re=>e.search(Q,re,{page:1,pageSize:q??pn})));$({works:ee[0].entries,books:ee[1].entries,collections:ee[2].entries,entities:ee[3].entries,totalWorks:ee[0].total,totalBooks:ee[1].total,totalCollections:ee[2].total,totalEntities:ee[3].total})}}catch(N){A(N instanceof Error?N.message:String(N)),$(null)}finally{z(!1)}},[e]);f.useEffect(()=>{let Q=!1;const q=()=>{var ae,ke;const N=["work","book","collection","entity"],ee=Promise.all(N.map(Ne=>e.loadEntries(Ne,{page:1,pageSize:1}).catch(()=>({total:0})))),re=((ae=e.getResourceCounts)==null?void 0:ae.call(e).catch(()=>null))??Promise.resolve(null),be=((ke=e.getSubtypeStats)==null?void 0:ke.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([ee,re,be]).then(([Ne,Se,De])=>{Q||(U({works:Ne[0].total,books:Ne[1].total,collections:Ne[2].total,entities:Ne[3].total,hasText:Se==null?void 0:Se.hasText,hasImage:Se==null?void 0:Se.hasImage}),De&&O(De))})};return e.getCounts?e.getCounts().then(N=>{var ee,re;Q||(U({works:N.works,books:N.books,collections:N.collections,entities:N.entities,hasText:(ee=N.resourceCounts)==null?void 0:ee.hasText,hasImage:(re=N.resourceCounts)==null?void 0:re.hasImage}),N.subtypeStats&&O(N.subtypeStats))}).catch(()=>{Q||q()}):q(),()=>{Q=!0}},[e]),f.useEffect(()=>{Z.current||!(g!=null&&g.trim())||(Z.current=!0,X(g))},[g,X]);const se=f.useCallback(Q=>{if(y(Q),!Q.trim()){h==null||h(Q),T(!0),$(null),_(null);return}Y.current&&clearTimeout(Y.current),Y.current=setTimeout(()=>{_(null),h==null||h(Q),X(Q)},wl)},[X,h]),ge=f.useCallback(Q=>{Y.current&&clearTimeout(Y.current),h==null||h(Q),X(Q)},[X,h]),he=f.useCallback(Q=>{_(Q),X(v,Sl)},[v,X]);f.useEffect(()=>{if(!L.length){R([]);return}let Q=!1;return I(!0),Promise.all(L.slice(0,10).map(async q=>{var N,ee,re;try{if(e.getEntry){const ae=await e.getEntry(q);if(ae)return ae}const be=await e.getItem(q);if(be){const ae=be.authors;return{id:q,title:be.title||q,type:be.type||"work",author:(N=ae==null?void 0:ae[0])==null?void 0:N.name,dynasty:(ee=ae==null?void 0:ae[0])==null?void 0:ee.dynasty,role:(re=ae==null?void 0:ae[0])==null?void 0:re.role,edition:be.edition||void 0}}}catch{}return{id:q,title:q,type:"work",notFound:!0}})).then(q=>{Q||(R(q),I(!1))}),()=>{Q=!0}},[L,e]);const D=Q=>{E(Q.id),Ki(Q.id),M(at()),r==null||r(Q)},le=(Q,q)=>{if(r&&Cl(q)){q.preventDefault(),D(Q);return}Ki(Q.id),M(at())},oe=Q=>{_l(Q),M(at())},ce=()=>{$l(),M([])},ue=Q=>m.find(q=>q.type===Q),me=j&&(j.works.length>0||j.books.length>0||j.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",children:[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:k.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!a&&t.jsx(nr,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:l,onToggleDraft:p,onConfigurePath:d,onSelectFolder:c})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(ir,{transport:e,value:v,onChange:se,onSearch:ge,onEntrySelect:D}),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:k.action.newEntry})]}),G&&W&&t.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[t.jsx("span",{children:te?t.jsxs(t.Fragment,{children:[(te.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:o("fg")},children:te.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:o("fg")},children:G.books.toLocaleString()})," 本"]}),te.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:o("fg")},children:te.article.toLocaleString()})," 篇"]}):null,te.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:o("fg")},children:te.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:[k.indexType.work," ",t.jsx("strong",{style:{color:o("fg")},children:G.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.indexType.book," ",t.jsx("strong",{style:{color:o("fg")},children:G.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.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:"·"}),k.indexType.entity," ",t.jsx("strong",{style:{color:o("fg")},children:G.entities.toLocaleString()})]})]})}),G.hasImage!=null&&G.hasText!=null&&t.jsxs("span",{children:[k.resourceType.image," ",t.jsx("strong",{style:{color:o("fg")},children:G.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.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:w?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:k.search.searching}):C?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:C})]}):W?t.jsx("div",{style:{flex:1},children:ne?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:k.search.loading}):P.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:k.search.recentBrowse}),t.jsx("button",{onClick:ce,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:k.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:P.slice(0,F?10:3).map(Q=>Q.notFound?t.jsx(Rl,{id:Q.id,onRemove:oe,t:k},Q.id):t.jsx(qi,{entry:Q,selected:B===Q.id,onClick:le,getConfig:ue,onRemove:oe},Q.id))}),!F&&P.length>3&&t.jsx("button",{onClick:()=>K(!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:k.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h3",{style:{margin:"0 0 8px",color:o("fg")},children:k.search.searchTitle}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:k.search.searchSubtitle})]})}):me?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:m.map(({type:Q,icon:q,name:N,key:ee})=>{const re=j[ee]??[],be=zl[ee],ae=j[be]??0;if(re.length===0)return null;const Ne=!(S===Q)&&ae>pn;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:[q," ",N,t.jsxs("span",{style:{fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[ae," ",k.unit.items]})]}),Ne&&t.jsx("button",{onClick:()=>he(Q),style:{border:"none",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"12px"},children:k.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:re.map(Se=>{if(x)return t.jsx(f.Fragment,{children:x(Se)},Se.id);const De=u==="card"?Tl:qi;return t.jsx(De,{entry:Se,selected:B===Se.id,onClick:le,getConfig:ue,query:v},Se.id)})})]},Q)})}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h3",{style:{margin:"0 0 8px",color:o("fg")},children:Lt(k.search.noResultsFor,{query:v})}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:k.search.tryOther})]})})]})};function Cl(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const or={color:"inherit",textDecoration:"none"},Il=({snippet:e})=>{const{convert:n}=V();return t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.6},children:Jo(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))})},Tl=({entry:e,selected:n,onClick:i,getConfig:r,query:s})=>{const l=ie(),{convert:p}=V(),d=p(e.title||e.primary_name||e.id),c=e.measure_info?p(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",a=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&a.length?a.find(h=>{const b=typeof h=="string"?h:h==null?void 0:h.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,x=o("cover-accent"),g=ve();return t.jsxs("a",{href:g(e.id),onClick:h=>i(e,h),className:"bim-result-card",style:{...or,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, ${x} 50%, ${o("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${x} 14%, ${o("bg")}), color-mix(in srgb, ${x} 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, ${x} 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:x},children:Array.from(d).map((h,b)=>t.jsx("span",{children:h},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:d}),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:["〔",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.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",p(e.era),"〕"]}),e.edition&&t.jsx("span",{children:p(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[l.search.alias,":",p(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(Il,{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]})]})]})]})},qi=({entry:e,selected:n,onClick:i,getConfig:r,query:s,onRemove:l})=>{const p=ie(),{convert:d}=V(),c=[...e.additional_titles||[],...e.attached_texts||[]],a=s&&c.length?c.find(x=>{const g=typeof x=="string"?x:x==null?void 0:x.book_title;return g==null?void 0:g.toLowerCase().includes(s.toLowerCase())}):void 0,u=ve();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:x=>i(e,x),className:"bim-result-card",style:{...or,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:d(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:p.misc.textResource,children:"📝"}),e.has_image&&t.jsx("span",{title:p.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:["〔",d(e.era),"〕"]}),e.edition&&d(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:d(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,p.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:["〔",d(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:d(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",d(e.role)]}),e.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??"?"]})]}),a&&t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:[p.search.alias,":",d(a)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:p.search.removeFromRecent,"aria-label":p.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:"×"})]})},Rl=({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 El(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 Ll({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 Nl({alt_names:e}){const{convert:n}=V(),i=new Map;for(const l of e){const p=l.type||"別名";i.has(p)||i.set(p,[]),i.get(p).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((l,p)=>{const d=r.indexOf(l),c=r.indexOf(p);return d===-1&&c===-1?0:d===-1?1:c===-1?-1:d-c});return t.jsx("div",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const p=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:p.map((d,c)=>t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),n(d)]},c))})]},l)})})}function Bl({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 Wl({works:e,transport:n,onNavigate:i,renderLink:r}){const s=ie(),{convert:l}=V(),p=ve(),[d,c]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let g=!1;const h=e.map(k=>k.work_id);return(async()=>{const k=new Map;if(n.getEntriesByIds)try{const j=await n.getEntriesByIds(h);let $=!0;for(let S=0;S<h.length;S++){const _=j[S];_!=null&&_.title?k.set(h[S],_.title):_!=null&&_.primary_name?k.set(h[S],_.primary_name):$=!1}if($)return k}catch{}const m=[...h],v=8,y=new Array(v).fill(0).map(async()=>{for(;m.length;){const j=m.shift();if(!j)break;if(!k.has(j))try{if(n.getEntry){const _=await n.getEntry(j);if(_!=null&&_.title){k.set(j,_.title);continue}}const $=await n.getItem(j),S=$&&($.title||$.primary_name)||j;k.set(j,S)}catch{k.set(j,j)}}});return await Promise.all(y),k})().then(k=>{g||c(k)}),()=>{g=!0}},[e,n]);const a=new Map;for(const g of e){const h=g.role||"";a.has(h)||a.set(h,[]),a.get(h).push(g)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...a.keys()].sort((g,h)=>{const b=u.indexOf(g),k=u.indexOf(h);return b===-1&&k===-1?g.localeCompare(h):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,")"]})]}),x.map(g=>{const h=a.get(g);return t.jsxs("div",{style:{marginBottom:"8px"},children:[g&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"2px"},children:[l(g)," ",t.jsxs("span",{style:{color:o("desc-fg")},children:["(",h.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:h.map((b,k)=>{const m=l(d.get(b.work_id)||b.work_id);return r?t.jsx("li",{children:r(b.work_id,m)},k):i?t.jsx("li",{children:t.jsx("a",{href:p(b.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),i(b.work_id))},style:{color:o("link-fg"),textDecoration:"underline",cursor:"pointer"},children:m})},k):t.jsx("li",{children:m},k)})})]},g)})]})}const rr=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:l})=>{var x;const p=ie(),{convert:d}=V();let c=!1;try{c=pe.extractStatus(e.id)==="draft"}catch{}const a=El(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:[d(e.primary_name),t.jsx(Ll,{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:p.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:p.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),a&&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(Nl,{alt_names:e.alt_names}),t.jsx(Bl,{data:e}),((x=e.description)==null?void 0:x.text)&&t.jsx("p",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:d(e.description.text)}),e.works&&e.works.length>0&&t.jsx(Wl,{works:e.works,transport:n,onNavigate:i,renderLink:r})]})},sr={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})=>t.jsx("a",{href:e,target:e!=null&&e.startsWith("http")?"_blank":void 0,rel:e!=null&&e.startsWith("http")?"noopener noreferrer":void 0,style:{color:o("link")},children:n}),code:({children:e})=>t.jsx("code",{style:{background:o("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})},Al={...sr,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},Ke=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:s}=V(),l=n?Al:sr;return t.jsx("div",{className:r,style:i,children:t.jsx(Zs,{remarkPlugins:[Xs],components:l,children:s(e)})})},Ml=["〇","一","二","三","四","五","六","七","八","九"],Ji=["","十","百","千"];function lr(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 p=parseInt(n[l]),d=i-1-l;p===0?s=!0:(s&&r&&(r+="〇"),s=!1,p===1&&d===1&&l===0?r+=Ji[d]:r+=Ml[p]+Ji[d])}return r}function ar(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 Fl={book:o("type-book"),work:o("type-work"),collection:o("type-collection"),entity:o("type-entity")};function Pl({type:e}){const n=ie();return t.jsx("span",{style:ar(Fl[e]),children:n.indexType[e]})}function Ol({isDraft:e}){const n=ie(),i=o(e?"status-draft":"status-official");return t.jsx("span",{style:ar(i),children:e?n.status.draft:n.status.official})}function Dl({id:e}){const n=ie(),[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 Te({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 Me({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 cr({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,p)=>{const d=s(l.name),c=l.entity_id?t.jsx(Le,{id:l.entity_id,label:d,onNavigate:i,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:d});return t.jsxs("span",{children:[p>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)]})]},p)})})}function Le({id:e,label:n,onNavigate:i,renderLink:r}){const s=ve();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 Hl({id:e,title:n,edition:i,type:r,isDraft:s,authors:l,volumeText:p,meta:d,headerExtra:c,onNavigate:a,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}),p&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:p})]}),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(Pl,{type:r}),t.jsx(Ol,{isDraft:s}),t.jsx(Dl,{id:e})]}),((l==null?void 0:l.length)||d.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(cr,{authors:l,type:r,onNavigate:a,renderLink:u}),d]})]})}function dr({items:e,label:n,showMeta:i,onNavigate:r,renderLink:s}){const l=ie(),{convert:p}=V();if(!e.length)return null;const[d,c]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(Te,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((a,u)=>{const x=d===u;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:o("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>c(x?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:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:p(a.source)}),!x&&i&&a.title_info&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p(a.title_info)}),a.source_bid&&t.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Le,{id:a.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),x&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${o("widget-border")}`},children:[i&&(a.title_info||a.author_info||a.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[a.title_info&&t.jsx(Me,{label:l.label.titleInfo,children:p(a.title_info)}),a.author_info&&t.jsx(Me,{label:l.label.authorInfo,children:p(a.author_info)}),a.edition&&t.jsx(Me,{label:l.label.edition,children:p(a.edition)})]}),a.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:p(a.summary)})]}),a.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:p(a.comment)})]}),a.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:p(a.additional_comment)})]})]})]},u)})})]})}function Gl({items:e,onNavigate:n,renderLink:i}){const r=ie();return t.jsx(dr,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function pr({items:e,onNavigate:n,renderLink:i}){const r=ie();return t.jsx(dr,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function ur({label:e,items:n}){const{convert:i}=V();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(Te,{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 Ul({items:e}){const n=ie();return t.jsx(ur,{label:n.section.aliases,items:e})}function Vl({items:e}){const n=ie();return t.jsx(ur,{label:n.section.attachedTexts,items:e})}function Yl({items:e}){const n=ie(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Te,{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 Kl({items:e}){const n=ie(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Te,{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 ql({items:e}){const n=ie(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Te,{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 Zi({title:e,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:l}=V(),[p,d]=f.useState([]);return f.useEffect(()=>{if(!n.length){d([]);return}if(!i){d(n.map(a=>({id:a})));return}let c=!1;return Promise.all(n.map(a=>i.getItem(a).then(u=>({id:a,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:a})))).then(a=>{c||d(a)}),()=>{c=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(Te,{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:(p.length?p:n.map(c=>({id:c}))).map(c=>{const a=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(Le,{id:c.id,label:a,onNavigate:r,renderLink:s})},c.id)})})]}):null}function un({book:e,onNavigate:n,renderLink:i}){const r=ie(),{convert:s}=V(),[l,p]=f.useState(!1),d=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:d&&!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(Le,{id:e.id,label:c,onNavigate:n,renderLink:i})}),d&&t.jsx("span",{onClick:()=>p(a=>!a),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:"▼"})]}),d&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(Un,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Jl({ids:e,workData:n,transport:i,onNavigate:r,renderLink:s,footer:l}){const p=ie(),{convert:d}=V(),[c,a]=f.useState([]);if(f.useEffect(()=>{if(!e.length){a([]);return}if(!i){a(e.map(k=>({id:k})));return}let b=!1;return Promise.all(e.map(k=>i.getItem(k).then(m=>({id:k,title:m?m.title:void 0,edition:m?m.edition:void 0,resources:m?m.resources:void 0,resource_groups:m?m.resource_groups:void 0})).catch(()=>({id:k})))).then(k=>{b||a(k)}),()=>{b=!0}},[e,i]),!e.length)return null;const u=c.length?c:e.map(b=>({id:b})),x=new Map(u.map(b=>[b.id,b])),g=n==null?void 0:n.version_graph,h=Zl(e,g);return t.jsxs(t.Fragment,{children:[t.jsxs(Te,{children:[p.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,h.useGrouping?t.jsxs(t.Fragment,{children:[h.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:h.coreIds.map(b=>{const k=x.get(b);return k?t.jsx(un,{book:k,onNavigate:r,renderLink:s},b):null})}),h.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:[d(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:d(b.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(k=>{const m=x.get(k);return m?t.jsx(un,{book:m,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(un,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Zl(e,n){var m,v;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[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,p=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&p.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const d=new Set(r),c=new Set([...s,...p]),a=y=>{if(c.has(y))return!0;const j=n.node_groups[y];return j!=null&&d.has(j)},u=[],x=new Map,g=[];for(const y of e)if(!((v=n.excluded_books)!=null&&v.includes(y)))if(a(y))u.push(y);else{const j=n.node_groups[y];j?(x.has(j)||x.set(j,[]),x.get(j).push(y)):g.push(y)}if(g.length+[...x.values()].reduce((y,j)=>y+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(y=>[y.id,y])),k=[...x.entries()].map(([y,j])=>{const $=b.get(y);return{id:y,label:($==null?void 0:$.label)??y,description:$==null?void 0:$.description,ids:j}});return g.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:u,groupedIds:k}}function Xl({workData:e,onNavigate:n,renderLink:i}){var p,d,c,a;const r=ie(),{convert:s}=V(),l=!!((p=e.description)!=null&&p.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(Le,{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)}):((d=e.juan_count)==null?void 0:d.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[lr(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(cr,{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(Ke,{text:e.description.text,style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(a=e.description)!=null&&a.text?"8px":0,fontSize:"13px"},children:t.jsx(Me,{label:r.label.parentWork,children:t.jsx(Le,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Ql({items:e,onNavigate:n,renderLink:i}){const r=ie(),{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(Le,{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:Lt(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Vn=({data:e,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:p,className:d,style:c})=>{var A,W,T,L,M,P,R,ne;const a=ie(),{convert:u}=V(),[x,g]=f.useState(null),[h,b]=f.useState(!1),[k,m]=f.useState(null),[v,y]=f.useState(null),[j,$]=f.useState([]),S=e||x;if(f.useEffect(()=>{if(e||!n||!i)return;let I=!1;return b(!0),m(null),i.getItem(n).then(F=>{I||(F?g(F):m(a.misc.notFoundEntry))}).catch(F=>{I||m(F instanceof Error?F.message:a.misc.loadFailed)}).finally(()=>{I||b(!1)}),()=>{I=!0}},[e,n,i]),f.useEffect(()=>{if(!S||!i){y(null),$([]);return}let I=!1;const F=S.type==="book"||S.type==="collection"?S.work_id:void 0;if(F?i.getItem(F).then(K=>{!I&&K&&K.type==="work"&&y(K)}).catch(()=>{}):y(null),S.type==="book"){const K=S;K.contained_in&&K.contained_in.length>0?Promise.all(K.contained_in.map(G=>{const U=typeof G=="string"?G:G.id,te=typeof G=="string"?void 0:G.volume_index;return i.getItem(U).then(O=>({id:U,title:O&&O.title||U,volume_index:te})).catch(()=>({id:U,title:U,volume_index:te}))})).then(G=>{I||$(G)}):$([])}else $([]);return()=>{I=!0}},[S,i]),h)return t.jsx("div",{className:d,style:{...c,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((I,F)=>t.jsx("div",{style:{height:F===1?"32px":"16px",width:`${I}px`,background:o("widget-border"),borderRadius:"4px",opacity:.4}},F))})});if(k)return t.jsx("div",{className:d,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:d,style:c,children:t.jsx(rr,{data:S,transport:i,onNavigate:r,renderLink:s,headerExtra:l})});const _=S.type==="book"?S:null,w=S.type==="collection"?S:null,z=S.type==="work"?S:null;let B=!1;try{B=pe.extractStatus(S.id)==="draft"}catch{}let E="";S.measure_info?E=u(S.measure_info):(A=S.juan_count)!=null&&A.number?E=lr(S.juan_count.number)+a.unit.juan:(W=S.juan_count)!=null&&W.description&&(E=u(S.juan_count.description));const C=[];return(T=S.publication_info)!=null&&T.year&&C.push(t.jsx(Me,{label:a.label.year,children:S.publication_info.year},"year")),(L=S.current_location)!=null&&L.name&&C.push(t.jsx(Me,{label:a.label.currentLocation,children:u(S.current_location.name)},"loc")),(M=S.page_count)!=null&&M.description&&C.push(t.jsx(Me,{label:a.label.pageCount,children:S.page_count.description},"page")),_!=null&&_.edition&&C.push(t.jsx(Me,{label:a.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&C.push(t.jsx(Me,{label:a.label.parentWork,children:t.jsx(Le,{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(Me,{label:a.label.parentWork,children:z.parent_works.map((I,F)=>t.jsxs("span",{children:[F>0&&"、",t.jsx(Le,{id:I,onNavigate:r,renderLink:s})]},I))},"pws")),t.jsxs("div",{className:d,style:c,children:[t.jsx(Hl,{id:S.id,title:u(S.title),edition:S.edition?u(S.edition):void 0,type:S.type,isDraft:B,authors:S.authors,volumeText:E,meta:C,headerExtra:l,onNavigate:r,renderLink:s}),((P=S.description)==null?void 0:P.text)&&t.jsx(Ke,{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((I,F)=>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(I.title)}),t.jsx(Ke,{text:I.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:o("fg")}})]},F))}),j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Te,{children:a.section.containedIn}),t.jsx(Ql,{items:j,onNavigate:r,renderLink:s})]}),v&&t.jsxs(t.Fragment,{children:[t.jsx(Te,{children:a.section.belongsToWork}),t.jsx(Xl,{workData:v,onNavigate:r,renderLink:s})]}),S.additional_works&&S.additional_works.length>0&&t.jsx(Yl,{items:S.additional_works}),S.additional_titles&&S.additional_titles.length>0&&t.jsx(Ul,{items:S.additional_titles}),S.attached_texts&&S.attached_texts.length>0&&t.jsx(Vl,{items:S.attached_texts}),S.indexed_by&&S.indexed_by.length>0&&t.jsx(Gl,{items:S.indexed_by,onNavigate:r,renderLink:s}),S.emendated_by&&S.emendated_by.length>0&&t.jsx(pr,{items:S.emendated_by,onNavigate:r,renderLink:s}),S.resources&&S.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Te,{children:a.section.resources}),t.jsx(Un,{items:S.resources,resourceGroups:S.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&t.jsx(Kl,{items:_.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&t.jsx(ql,{items:w.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&t.jsx(Zi,{title:a.section.relatedVersions,ids:_.related_books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.books)&&w.books.length>0&&t.jsx(Zi,{title:a.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(Te,{children:[a.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(I=>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(Le,{id:I.id,label:u(I.title),onNavigate:r,renderLink:s})},I.id))})]}),(((R=z==null?void 0:z.books)==null?void 0:R.length)||0)+(((ne=z==null?void 0:z.collections)==null?void 0:ne.length)||0)>0&&t.jsx(Jl,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z,transport:i,onNavigate:r,renderLink:s,footer:p}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const I=[],F=z.related_works.filter(Y=>Y.relation==="part_of"),K=z.related_works.filter(Y=>Y.relation==="has_part"),G=z.related_works.filter(Y=>Y.relation==="has_adaptation"),U=z.related_works.filter(Y=>Y.relation==="text_carried_by"),te=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),O=z.related_works.filter(Y=>!Y.relation||!te.has(Y.relation));return F.length>0&&I.push({label:a.section.belongsToWork,items:F}),K.length>0&&I.push({label:a.section.containedWorks,items:K}),G.length>0&&I.push({label:a.section.adaptations,items:G}),U.length>0&&I.push({label:a.section.derivativeWorks,items:U}),O.length>0&&I.push({label:a.section.relatedWorks,items:O}),I.map(Y=>t.jsxs("div",{children:[t.jsxs(Te,{children:[Y.label,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",Y.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:Y.items.map(Z=>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(Le,{id:Z.id,label:u(Z.title),onNavigate:r,renderLink:s})},Z.id))})]},Y.label))})()]})};function ea({data:e}){const n=ie(),{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 ta({sections:e,activeSection:n,onSelect:i}){const r=ie();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:Xi(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:Xi(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 Xi(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 na({id:e,label:n,onNavigate:i,renderLink:r}){const s=ve();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 ia(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 Qi({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const s=ie(),{convert:l}=V(),p=e.book_id||e.work_id,d=r&&e.volumes.length>0?ia(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:d}),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(a=>l(a)).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]}),p&&t.jsx(na,{id:p,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!p&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const Yn=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:l,style:p})=>{const d=ie(),[c,a]=f.useState(null),[u,x]=f.useState(!1),[g,h]=f.useState(null),[b,k]=f.useState(null),[m,v]=f.useState(""),y=e||c;f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let w=!1;return x(!0),h(null),i.getCollectionCatalog(n).then(z=>{w||(z?a(z):h(d.catalog.notFound))}).catch(z=>{w||h(z instanceof Error?z.message:d.catalog.loadFailed)}).finally(()=>{w||x(!1)}),()=>{w=!0}},[e,n,i,d]);const j=(y==null?void 0:y.sections)&&y.sections.length>0,$=f.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const w=y.books.map(B=>B.volumes[0]).filter(B=>B!=null);return new Set(w).size<w.length},[y]),S=f.useMemo(()=>{if(!y)return[];let w=y.books;if(b&&(w=w.filter(z=>z.section===b)),m.trim()){const z=m.trim().toLowerCase();w=w.filter(B=>B.title.toLowerCase().includes(z)||B.sub_items&&B.sub_items.some(E=>E.toLowerCase().includes(z))||B.edition&&B.edition.toLowerCase().includes(z))}return w},[y,b,m]),_=f.useMemo(()=>{if(!$)return null;const w=[],z=new Map;for(const E of S){if(!E.volumes||E.volumes.length===0)continue;const C=E.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(E)}const B=[...z.keys()].sort((E,C)=>E-C);for(const E of B)w.push({volume:E,books:z.get(E)});return w},[S,$]);return u?t.jsx("div",{className:l,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):g?t.jsx("div",{className:l,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:g}):y?t.jsxs("div",{className:l,style:p,children:[t.jsx(ea,{data:y}),j&&t.jsx(ta,{sections:y.sections,activeSection:b,onSelect:k}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:m,onChange:w=>v(w.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:o("desc-fg")},children:[S.length," ",d.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:Lt(d.catalog.volume,{n:w.volume})}),w.books.map((B,E)=>t.jsx(Qi,{book:B,onNavigate:r,renderLink:s,showVolumes:B.volumes.length>1},`${w.volume}-${E}`))]},`${w.volume}-${z}`)):S.map((w,z)=>t.jsx(Qi,{book:w,onNavigate:r,renderLink:s,showVolumes:!0},z)),S.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},nt=()=>{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)})},xr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],oa={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function je(e){return oa[e]??e}const xt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],ft={熹平: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},fr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function en(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 ra(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 sa=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,eo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Kn(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(eo))if(n.startsWith(s))return eo[s];const i=je(n);if(Je[i]!=null)return i;const r=Ue(n);if(r&&n.length<=r.length+1)return je(r)}function qe(e,n){if(n){const i=fr[`${n}|${e}`];if(i!=null)return i}return ft[e]}const la=1911;function aa(e){const n=ft[e];if(n==null)return;const i=Fe[e];let r;for(const[s,l]of Object.entries(ft))Fe[s]===i&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const ca={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function qt(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 p=ca[l];if(p===void 0)return;r=!0,l==="十"?i=(i||1)*10:l==="廿"||l==="卅"?(n+=p,i=0):i>=10?(n+=i+p,i=0):i=i*10+p}const s=n+i;return r&&s>0?s:void 0}function Ue(e){for(const n of xr)if(e.startsWith(n))return n}const Fe={};{const e=(n,i)=>{for(const r of i)Fe[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Ze(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(ft))if(e.includes(r)&&!(i&&Fe[r]&&Fe[r]!==i&&fr[`${i}|${r}`]==null))return r}function Nt(e){var p,d,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=(p=e.lineage)==null?void 0:p.year_text;if(r){const a=Ue(r)??"";return{era:je(a),reign:Ze(r,a)??"",source:"lineage"}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const a=en(s);if(a)return{era:ra(a.from),reign:"",source:"publication"};const u=Ue(s)??Kn(s)??((c=xt.find(h=>h.pattern.test(s)))==null?void 0:c.era)??"",x=Ze(s,u)??"",g=u||(x?Fe[x]??"":"");if(g||x)return{era:je(g),reign:x,source:"publication"}}const l=e.edition||e.title||"";if(l){const a=Ue(l);if(a)return{era:je(a),reign:Ze(l,a)??"",source:"edition"};const u=xt.find(x=>x.pattern.test(l));if(u)return{era:je(u.era),reign:Ze(l,u.era)??u.reign??"",source:"edition"}}return n}function tn(e){var r,s,l,p,d,c,a,u,x;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 g=en(n);if(g)return g.from}const i=[(p=e.lineage)==null?void 0:p.year_text,(d=e.publication_info)==null?void 0:d.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const g of i){const h=((c=e.publication_info)==null?void 0:c.year)||((a=e.lineage)==null?void 0:a.year_text);if(h&&g!==h&&(Ue(h)||Kn(h)))break;const b=g.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??g.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const j=parseInt(b[1],10);if(j>=100&&j<=2100)return j}const k=g.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(k){const j=Ue(g);if(!j||je(j)==="民國"){const S=qt(k[1]);if(S!=null&&S>=1&&S<=120)return la+S}}const m=Ue(g)??((u=xt.find(j=>j.pattern.test(g)))==null?void 0:u.era),v=m?je(m):void 0,y=Ze(g,v)??(Ue(g)||(x=xt.find(j=>j.pattern.test(g)))==null?void 0:x.reign);if(y){const j=qe(y,v);if(j==null)continue;const $=g.indexOf(y),S=$>=0?g.slice($+y.length):"",_=S.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??S.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),w=_?qt(_[1]):void 0;return j+(w?w-1:0)}}}function qn(e){var p,d,c,a,u,x;const n=(p=e.dating)==null?void 0:p.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(d=e.lineage)==null?void 0:d.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 g=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const h=_n[je(g[1])],b=Je[je(g[2])];if(h!=null&&b!=null)return{from:Math.min(h,b)-20,to:Math.max(h,b)+40}}}const s=(a=e.publication_info)==null?void 0:a.year;if(s){const g=en(s);if((g==null?void 0:g.to)!=null)return{from:g.from,to:g.to};const h=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(h){const b=_n[je(h[1])],k=Je[je(h[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 g of l){if(!/[間间]/.test(g))continue;const h=Ue(g)??Kn(g)??((x=xt.find(m=>m.pattern.test(g)))==null?void 0:x.era),b=h?je(h):void 0,k=[];for(const m of Object.keys(ft))g.includes(m)&&(b&&Fe[m]&&Fe[m]!==b||qe(m,b)!=null&&k.push(m));if(k.length===0){const m=g.match(/([一-鿿])([一-鿿])[間间]/);if(m&&b){for(const v of[m[1],m[2]])for(const y of Object.keys(ft))if(Fe[y]===b&&!(y[0]!==v&&y[y.length-1]!==v)&&qe(y,b)!=null){k.push(y);break}}}if(k.length>0){const m=k.map($=>qe($,b)).filter($=>$!=null),v=Math.min(...m),y=k.reduce(($,S)=>qe($,b)>=qe(S,b)?$:S),j=aa(y)??xn(b??"")??Math.max(...m);return{from:v,to:j>v?j:xn(b??Fe[y]??"")??v}}if(b&&Je[b]!=null)return{from:Je[b],to:xn(b)??Je[b]}}}const Je={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},da=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],pa=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,to=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function no(e,n){for(const i of xr){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!Ze(e.slice(r),je(i)))continue}const s=je(i);if(s===n)continue;const l=e.slice(r),p=Ze(l,s)??"";let d;if(p){const c=qe(p,s);if(c!=null){const u=l.slice(l.indexOf(p)+p.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),x=u?qt(u[1]):void 0;d=c+(x?x-1:0)}}return{era:s,reign:p,year:d}}for(const i of xt)if(i.pattern.test(e))return{era:je(i.era),reign:i.reign??""}}function ua(e){var v,y,j,$,S;const n=Nt(e),i=((v=e.publication_info)==null?void 0:v.year)??"",r=i?en(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),p=((y=e.lineage)==null?void 0:y.year_text)??"",d=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(p),c=n.source==="publication"&&sa.test(i),a=n.source==="publication"&&/[間间]/.test(i),u=p.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let x;l||d||c||a?x=void 0:u?x=parseInt(u[2],10):x=tn(e);const g=x==null?qn(e):void 0;let h;n.source==="publication"&&(c||to.test(i))?h="uncertain":n.source==="lineage"||n.source==="publication"?h="attested":to.test(s)||!n.reign&&x==null?h="uncertain":h="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((j=e.lineage)==null?void 0:j.year_text)??(($=e.lineage)==null?void 0:$.year)??""}」`:`出版著錄「${((S=e.publication_info)==null?void 0:S.year)??""}」`,k={era:n.era,reign:n.reign,year:x,yearRange:g,certainty:h,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const _=p.match(/[、,,]\s*([宋元明清])/);_&&_[1]!==k.era&&(k.laterRepair={era:_[1]})}if(!k.laterRepair&&pa.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(k.laterRepair={era:_[1]})}const m=da.find(_=>_.re.test(s));if(m){const _=s.search(m.re),w=s.slice(_),z=no(w,n.era)??no(s,n.era);z&&(k.basedOn={era:z.era,reign:z.reign,year:z.year,relation:m.relation})}return k}const _n={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function xn(e){return _n[e]}function gr(e){const n=tn(e);if(n!=null)return n;const i=qn(e);if(i)return i.from;const r=Nt(e).era;return r?Je[r]:void 0}const io=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function $n(e){const n=io.indexOf(e);return n===-1?io.length:n}function xa(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 nn(e,n){const i=Dn(e||[]),r=new Map,s=[];for(const a of i)a.group?(r.has(a.group)||r.set(a.group,[]),r.get(a.group).push(a)):s.push(a);for(const a of r.values())a.sort((u,x)=>{const g=h=>h.group_role==="origin"?0:h.group_role==="mirror"?1:2;return g(u)-g(x)});const l={text:[],image:[],textImage:[],physical:[]};for(const a of s){const u=Qe(a),x=u.includes("text"),g=u.includes("image");x&&g?l.textImage.push(a):x?l.text.push(a):g?l.image.push(a):l.physical.push(a)}const d=["text","image","textImage","physical"].filter(a=>l[a].length>0).map(a=>({key:a,items:l[a]})),c=[...r.entries()].map(([a,u])=>{var x,g;return{key:a,label:((x=n==null?void 0:n[a])==null?void 0:x.label)||a,description:(g=n==null?void 0:n[a])==null?void 0:g.description,items:u}});return{buckets:d,mirrors:c,total:i.length}}function Bt(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=Xt(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 hr(e,n){if(Bt(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,p;const i=e.resources||[],r=[],s=[];for(const d of i){const c=Qe(d);c.includes("image")&&r.push(d),c.includes("physical")&&s.push(d)}return{id:e.id,name:e.edition||e.title||e.id,era:Nt(e),year:tn(e),sortYear:gr(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:fa(e.id,n),group:(p=n==null?void 0:n.node_groups)==null?void 0:p[e.id],hasImage:r.length>0}}function fa(e,n){var d,c;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(d=n.collections)==null?void 0:d[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)??[],p=(c=n.node_groups)==null?void 0:c[e];return!!p&&l.includes(p)}function br(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,a)=>({r:c,i:a})).sort((c,a)=>{const u=c.r.sortYear,x=a.r.sortYear;return u!=null&&x!=null?u-x||c.i-a.i:u!=null?-1:x!=null?1:c.i-a.i}).map(c=>c.r):l=l.map((c,a)=>({r:c,i:a})).sort((c,a)=>{const u=x=>(x.important?0:1)*2+(x.hasImage?0:1);return u(c.r)-u(a.r)||c.i-a.i}).map(c=>c.r);const d=[...new Set(s.map(c=>c.era.era).filter(Boolean))].sort((c,a)=>$n(c)-$n(a));return{rows:l,allRows:s,eras:d,hasInferredEra:s.some(c=>c.era.source==="edition")}}function ga(e,n){var m,v;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[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,p=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&p.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const d=new Set(r),c=new Set([...s,...p]),a=y=>{if(c.has(y))return!0;const j=n.node_groups[y];return j!=null&&d.has(j)},u=[],x=new Map,g=[];for(const y of e)if(!((v=n.excluded_books)!=null&&v.includes(y)))if(a(y))u.push(y);else{const j=n.node_groups[y];j?(x.has(j)||x.set(j,[]),x.get(j).push(y)):g.push(y)}if(g.length+[...x.values()].reduce((y,j)=>y+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(y=>[y.id,y])),k=[...x.entries()].map(([y,j])=>{const $=b.get(y);return{id:y,label:($==null?void 0:$.label)??y,description:$==null?void 0:$.description,ids:j}});return g.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:u,groupedIds:k}}const yr=["撰","編","注","校","譯","繪","其他"],ha=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function Jn(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of ha)if(r.test(n))return i;return"其他"}function Zn(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function jr(e){const n=new Map;for(const r of e){const s=Jn(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:e.length}];for(const r of yr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function vr(e,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(p=>({id:p.work_id||p.book_id||void 0,title:p.title,section:p.section,volumes:p.volumes||[],subItems:p.sub_items,edition:p.edition,found:p.found_volumes,expected:p.expected_volumes})),l=[...new Set(s.map(p=>p.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:Rt(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,p;return{id:s,title:((l=i==null?void 0:i.get(s))==null?void 0:l.title)||s,edition:(p=i==null?void 0:i.get(s))==null?void 0:p.edition,volumes:[]}}),source:"books",sections:[]}}function Rt(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 on(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((l,p)=>l-p),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 ma=["〇","一","二","三","四","五","六","七","八","九"],oo=["","十","百","千"];function kr(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 p=parseInt(n[l]),d=i-1-l;p===0?s=!0:(s&&r&&(r+="〇"),s=!1,p===1&&d===1&&l===0?r+=oo[d]:r+=ma[p]+oo[d])}return r}function ba(e){return e==null?"":typeof e=="string"?e:e.title??""}function et(e,n="卷"){var r,s;const i=e;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?kr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Sr(e){var r;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 ya="guji_markdown";function zn(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 ja=/^□\{guess=([^\s{}]+)\}/;function va(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function wr(e,n){let i=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
2
+ `)return-1;if(s==="\\"){r++;continue}if(s==="[")i++;else if(s==="]"&&(i--,i===0))return r}return-1}function ka(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function Sa(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(`
3
+ `)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const r=wr(e,n+3);return r>n+4?{node:{type:"zi",label:ka(e.slice(n+4,r))},end:r+1}:null}if(i==="□"&&e[n+1]==="{"){const r=ja.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function _r(e,n,i,r){const s=[];let l="";const p=()=>{if(!l)return;const d=r?l.replace(/\\?\|/g,""):l;d&&s.push({type:"text",text:d}),l=""};for(;n<e.length;){const d=e[n];if(i!==null){if(d===i)return p(),{nodes:s,end:n};if(d===`
4
+ `)return null}const c=Sa(e,n);if(c){p(),s.push(c.node),n=c.end;continue}let a=null;if(d==="⟨"?a="⟩":d==="<"&&va(e,n)&&(a=">"),a){const u=_r(e,n+1,a,!0);if(u){p(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=d,n++}return i!==null?null:(p(),{nodes:s,end:n})}function $r(e){return _r(e,0,null,!1).nodes}function wa(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function zr(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${zr(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const _a=216,ro="clamp(280px, 23vw, 360px)",$a=1440,Cr="(max-width: 719px)",za=`${Cr}, (pointer: coarse)`,Ca=`
5
+ .bim-d-main.bim-d-main-grid { max-width: ${$a}px; padding: 16px 32px 0; }
6
6
  .bim-d-grid {
7
7
  display: grid;
8
- grid-template-columns: ${Sa}px minmax(0, 1fr) ${ro};
8
+ grid-template-columns: ${_a}px minmax(0, 1fr) ${ro};
9
9
  grid-template-rows: auto 1fr;
10
10
  grid-template-areas: "rail main card" "rail main side";
11
11
  column-gap: 32px; row-gap: 28px; align-items: start;
@@ -40,8 +40,8 @@
40
40
  .bim-d-sec-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .04em; color: ${o("ink")}; }
41
41
  .bim-d-sec-head .bim-d-sec-act { margin-left: auto; font-size: 13px; }
42
42
 
43
- /* 文字页签式筛选 */
44
- .bim-d-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; margin-bottom: 10px; font-size: 13px; }
43
+ /* 文字页签式筛选。min-height = 页签行高:朝代页签随次级数据晚到,行高先占好(INT Q3) */
44
+ .bim-d-filters { min-height: 26px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; margin-bottom: 10px; font-size: 13px; }
45
45
  .bim-d-tab {
46
46
  background: none; border: 0; padding: 4px 0; cursor: pointer; font: inherit;
47
47
  color: ${o("quiet-fg")};
@@ -70,6 +70,8 @@
70
70
  .bim-d-zt .bim-d-zt-sub { color: ${o("quiet-fg")}; font-size: 13px; }
71
71
  .bim-d-zt .bim-d-zt-nowrap { white-space: nowrap; }
72
72
  .bim-d-zt .bim-d-zt-empty { color: ${o("aux-fg")}; }
73
+ /* 版本表:行高先按「有影印」色块那一行的高度占好,解析到的年代、馆藏、色块进来时行不再长高(INT Q3) */
74
+ .bim-d-zt-ver tbody tr { height: 42px; }
73
75
 
74
76
  .bim-d-flag {
75
77
  display: inline-block; padding: 1px 8px; border-radius: 4px;
@@ -130,10 +132,10 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
130
132
  }
131
133
  .bim-d-btn:hover { background: ${o("accent-deep")}; }
132
134
 
133
- /* 旁栏清单 */
134
- .bim-d-side h3 { margin: 0 0 6px; font-size: 15px; font-weight: 700; color: ${o("ink")};
135
+ /* 旁栏清单:小标题是 h2(提要卡 h1 之下不跳级,INT Q5),外观仍是 15px 小标题 */
136
+ .bim-d-side h3, .bim-d-side .bim-d-side-h { margin: 0 0 6px; font-size: 15px; font-weight: 700; color: ${o("ink")};
135
137
  display: flex; align-items: baseline; gap: 8px; }
136
- .bim-d-side h3 .bim-d-meta { font-weight: 400; font-size: 12px; }
138
+ .bim-d-side h3 .bim-d-meta, .bim-d-side .bim-d-side-h .bim-d-meta { font-weight: 400; font-size: 12px; }
137
139
  .bim-d-side ul { list-style: none; margin: 0; padding: 0; }
138
140
  .bim-d-side li { display: flex; align-items: baseline; gap: 10px; padding: 5px 0; font-size: 15px; min-width: 0; }
139
141
  .bim-d-side li > a, .bim-d-side li > span:first-child { color: ${o("ink")}; min-width: 0; overflow-wrap: anywhere; }
@@ -141,7 +143,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
141
143
  .bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
142
144
 
143
145
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
144
- @media ${_a} {
146
+ @media ${za} {
145
147
  .bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
146
148
  .bim-d-card-foot summary { min-height: 44px; }
147
149
  .bim-d-side li { padding: 0; }
@@ -151,12 +153,21 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
151
153
  align-items: center; justify-content: center; }
152
154
  .bim-d-zt td.bim-d-zt-main > a, .bim-d-zt td.bim-d-zt-main > span.bim-d-zt-name {
153
155
  min-height: 44px; box-sizing: border-box; display: flex; align-items: center; }
154
- /* 视觉不变、热区外扩到 44px:「有影印」色块、顶条的面包屑 / 繁简 / GitHub */
155
- .bim-d-flag, .bim-d-top a, .bim-d-top button { position: relative; }
156
- .bim-d-flag::after, .bim-d-top a::after, .bim-d-top button::after {
157
- content: ""; position: absolute; left: -4px; right: -4px; top: 50%;
158
- height: 44px; transform: translateY(-50%);
156
+ /*
157
+ * 视觉不变、热区外扩到 44×44(INT Q4):「有影印」色块、顶条的面包屑(返回索引)/ 繁简 / GitHub 图标、
158
+ * 朝代页签(单字「宋」「元」只有 13px 宽)。伪元素居中外扩,宽高都至少 44px。
159
+ */
160
+ .bim-d-flag, .bim-d-top a, .bim-d-top button, .bim-d-tab { position: relative; }
161
+ .bim-d-flag::after, .bim-d-top a::after, .bim-d-top button::after, .bim-d-tab::after {
162
+ content: ""; position: absolute; left: 50%; top: 50%;
163
+ width: max(calc(100% + 8px), 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
159
164
  }
165
+ /*
166
+ * 相邻热区不能叠:两字页签(26px)两边各扩 9px,间距 18px 正好贴边,放宽到 20px;
167
+ * 单字页签(13px)两边各扩 15.5px,再左右各多留 7px
168
+ */
169
+ .bim-d-filters { column-gap: 20px; }
170
+ .bim-d-tab.bim-d-tab-1 { margin: 0 7px; }
160
171
  }
161
172
 
162
173
  /* 中等宽度:左栏折到顶部一行 */
@@ -196,11 +207,16 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
196
207
  color: ${o("aux-fg")}; }
197
208
  .bim-d-zt td.bim-d-zt-blank { display: none; }
198
209
  .bim-d-zt td.bim-d-zt-main .bim-d-meta { padding-bottom: 2px; }
210
+ /* 手机上版本行是块:解析前只有版本名一行,先按「名 + 一行年代馆藏」占高 */
211
+ .bim-d-zt-ver tbody tr { height: auto; }
212
+ /* 朝代页签晚到、在手机上自成一行:解析中先占两行(页签一行 + 复选框一行) */
213
+ .bim-d-filters[data-pending] { min-height: 92px; align-content: flex-end; }
214
+ .bim-d-zt-ver tbody tr[data-loading] { min-height: 64px; }
199
215
  .bim-d-lu { grid-template-columns: 1fr; gap: 12px; }
200
216
  .bim-d-lu-list { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
201
217
  .bim-d-lu-list button { white-space: nowrap; padding: 6px 12px; }
202
218
  }
203
- `;function Wt({railTop:e,back:n,nav:i,railLinks:r,main:s,card:l,side:p}){const{convert:d}=Y(),c=(i||[]).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}),c.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":d("本頁導航"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:d("本頁")}),t.jsx("ul",{className:"bim-d-rail-nav",children:c.map(a=>t.jsx("li",{children:t.jsxs("a",{href:`#${a.id}`,children:[t.jsx("span",{children:d(a.label)}),a.count!=null&&t.jsx("span",{className:"bim-d-meta",children:a.count})]})},a.id))})]}),r&&r.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":d("更多"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:d("更多")}),t.jsx("ul",{className:"bim-d-rail-nav",children:r.map(a=>t.jsx("li",{children:t.jsxs("a",{href:a.href??"#",onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),a.onClick())},children:[t.jsx("span",{children:d(a.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},a.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:s}),t.jsx("div",{className:"bim-d-g-card",children:l}),t.jsx("div",{className:"bim-d-g-side",children:p})]})}function $e({id:e,title:n,meta:i,action:r,children:s}){const{convert:l}=Y();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:l(n)}),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i}),r&&t.jsx("span",{className:"bim-d-sec-act",children:r})]}),s]})}function Te({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 rn({items:e,value:n,onChange:i}){const{convert:r}=Y();return t.jsx(t.Fragment,{children:e.map(s=>t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":s.key===n,onClick:()=>i(s.key),children:r(s.label)},s.key))})}function Ir({label:e,checked:n,onChange:i}){const{convert:r}=Y();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:s=>i(s.target.checked)}),r(e)]})}function yt({label:e,onClick:n}){const{convert:i}=Y();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:i(e)})}function At({title:e,subtitle:n,byline:i,meta:r,description:s,facts:l,readAction:p,children:d,foot:c}){const{convert:a}=Y(),u=(l||[]).filter(x=>x.value!=null&&x.value!=="");return t.jsxs("div",{className:"bim-d-card",children:[t.jsx("h1",{className:typeof e=="string"&&[...e].length>7?"bim-d-card-long":void 0,children:e}),n&&t.jsx("div",{className:"bim-d-card-sub",children:n}),i&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:i}),r&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:r}),s&&t.jsx("div",{className:"bim-d-card-desc",children:s}),u.length>0&&t.jsx("dl",{className:"bim-d-ui",children:u.map((x,g)=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:a(x.label)}),t.jsx("dd",{title:x.title,children:x.value})]},g))}),d,p,c&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:c})]})}function In({href:e,onClick:n,label:i="閱讀全文"}){const{convert:r}=Y();return e?t.jsx("a",{className:"bim-d-btn",href:e,onClick:n?s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),n())}:void 0,children:r(i)}):t.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:r(i)})}function ct({id:e,title:n,meta:i,items:r,cap:s=8,moreLabel:l}){const{convert:p}=Y(),[d,c]=f.useState(!1);if(!r.length)return null;const a=d?r:r.slice(0,s),u=r.length-a.length;return t.jsxs("div",{id:e,className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h3",{className:"bim-d-ui",children:[p(n),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i})]}),t.jsx("ul",{children:a.map((x,g)=>t.jsx("li",{children:x},g))}),u>0&&t.jsx(yt,{label:l?l(u):`顯示更多(${u})`,onClick:()=>c(!0)})]})}const za={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核"};function Mt({revision:e,revisedAt:n,review:i,todo:r}){const{convert:s}=Y(),l=i&&i.status!=="unreviewed"?[za[i.status]??i.status,i.by,i.date].filter(Boolean).join(" "):"",p=[e!=null&&e!==""?`${s("數據版本")} ${e}`:"",n??"",s(l)].filter(Boolean),d=(r||[]).filter(c=>c&&c.what);return!p.length&&!d.length?null:t.jsxs(t.Fragment,{children:[p.length>0&&t.jsx(Te,{items:p,style:{fontSize:12}}),d.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s(`待核 ${d.length} 項`)}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:d.map((c,a)=>t.jsxs("li",{children:[s(c.what),(c.by||c.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[c.by&&s(c.by),c.date].filter(Boolean).join(" · "),")"]})]},a))})]})]})}const Ct=1e3,fn=208,Ca="(max-width: 719px)",Tr=`
219
+ `;function Wt({railTop:e,back:n,nav:i,railLinks:r,main:s,card:l,side:p}){const{convert:d}=V(),c=(i||[]).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}),c.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":d("本頁導航"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:d("本頁")}),t.jsx("ul",{className:"bim-d-rail-nav",children:c.map(a=>t.jsx("li",{children:t.jsxs("a",{href:`#${a.id}`,children:[t.jsx("span",{children:d(a.label)}),a.count!=null&&t.jsx("span",{className:"bim-d-meta",children:a.count})]})},a.id))})]}),r&&r.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":d("更多"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:d("更多")}),t.jsx("ul",{className:"bim-d-rail-nav",children:r.map(a=>t.jsx("li",{children:t.jsxs("a",{href:a.href??"#",onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),a.onClick())},children:[t.jsx("span",{children:d(a.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},a.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:s}),t.jsx("div",{className:"bim-d-g-card",children:l}),t.jsx("div",{className:"bim-d-g-side",children:p})]})}function Ce({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 Re({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 rn({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 Ir({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 yt({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 At({title:e,subtitle:n,byline:i,meta:r,description:s,facts:l,readAction:p,children:d,foot:c}){const{convert:a}=V(),u=(l||[]).filter(x=>x.value!=null&&x.value!=="");return t.jsxs("div",{className:"bim-d-card",children:[t.jsx("h1",{className:typeof e=="string"&&[...e].length>7?"bim-d-card-long":void 0,children:e}),n&&t.jsx("div",{className:"bim-d-card-sub",children:n}),i&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:i}),r&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:r}),s&&t.jsx("div",{className:"bim-d-card-desc",children:s}),u.length>0&&t.jsx("dl",{className:"bim-d-ui",children:u.map((x,g)=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:a(x.label)}),t.jsx("dd",{title:x.title,children:x.value})]},g))}),d,p,c&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:c})]})}function Cn({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 ct({id:e,title:n,meta:i,items:r,cap:s=8,moreLabel:l}){const{convert:p}=V(),[d,c]=f.useState(!1);if(!r.length)return null;const a=d?r:r.slice(0,s),u=r.length-a.length;return t.jsxs("div",{id:e,className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[p(n),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i})]}),t.jsx("ul",{children:a.map((x,g)=>t.jsx("li",{children:x},g))}),u>0&&t.jsx(yt,{label:l?l(u):`顯示更多(${u})`,onClick:()=>c(!0)})]})}const Ia={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核"};function Mt({revision:e,revisedAt:n,review:i,todo:r}){const{convert:s}=V(),l=i&&i.status!=="unreviewed"?[Ia[i.status]??i.status,i.by,i.date].filter(Boolean).join(" "):"",p=[e!=null&&e!==""?`${s("數據版本")} ${e}`:"",n??"",s(l)].filter(Boolean),d=(r||[]).filter(c=>c&&c.what);return!p.length&&!d.length?null:t.jsxs(t.Fragment,{children:[p.length>0&&t.jsx(Re,{items:p,style:{fontSize:12}}),d.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s(`待核 ${d.length} 項`)}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:d.map((c,a)=>t.jsxs("li",{children:[s(c.what),(c.by||c.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[c.by&&s(c.by),c.date].filter(Boolean).join(" · "),")"]})]},a))})]})]})}const Ct=1e3,fn=208,Ta="(max-width: 719px)",Tr=`
204
220
  .bim-d-page {
205
221
  background: ${o("page-bg")};
206
222
  color: ${o("ink")};
@@ -277,7 +293,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
277
293
  align-items: start; margin-bottom: 48px; }
278
294
  .bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
279
295
 
280
- @media ${Ca} {
296
+ @media ${Ta} {
281
297
  .bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
282
298
  .bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
283
299
  /* 表格:meta 列折到第二行,表头隐藏 */
@@ -295,14 +311,14 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
295
311
  padding-right: 0; padding-bottom: 12px;
296
312
  }
297
313
  }
298
- ${$a}`;function It({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Tr}),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 Tn({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 Xn({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 Rn({items:e}){const n=je();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}`),p=i.id?n(i.id):i.href,d=s||!i.onClick&&!p?t.jsx("span",{style:{color:o("ink")},children:i.label},r):t.jsx("a",{href:p??"#",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,d]},r)})})}function Rr({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 Ia({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 Ta({items:e,horizontal:n}){const{convert:i}=Y();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${o("accent")}`,paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:e.map((r,s)=>t.jsxs("div",{title:r.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[t.jsx("span",{className:"bim-d-ui",style:{color:o("label-fg"),letterSpacing:".08em",flex:"none"},children:i(r.label)}),t.jsx("span",{style:{color:o("body-fg"),textAlign:n?"left":"right",minWidth:0},children:r.value})]},s))}):null}function Ra({glyph:e,tone:n,title:i,count:r,actions:s,id:l}){const{convert:p}=Y();return t.jsxs("div",{id:l,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(Xn,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:p(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 Er({label:e,active:n,onClick:i,dashed:r}){const{convert:s}=Y();return t.jsx("button",{type:"button",onClick:i,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!n?"dashed":"solid"} ${o(n?"accent":"rule")}`,background:n?o("accent"):"transparent",color:o(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(e)})}function Ea({label:e,onClick:n}){const{convert:i}=Y();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg"),borderBottom:`1px solid ${o("rule")}`},children:i(e)})}function La({label:e,onClick:n,inline:i}){const{convert:r}=Y();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:i?0:12,width:i?void 0:"100%",padding:i?"4px 12px":9,background:"none",border:`1px dashed ${o("rule-dashed")}`,cursor:"pointer",fontSize:12,color:o("meta-fg"),letterSpacing:i?void 0:".08em"},children:r(e)})}function Lr({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 Ba({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function Na({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(p=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${o("rule")}`,color:o("meta-fg")},children:p},p)),!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 Wa({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${o("rule-strong")}`},children:e})}function Aa({spec:e}){const{convert:n}=Y();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${o("rule-strong")}`,fontSize:11,color:o("label-fg"),letterSpacing:".1em"},children:[t.jsx("span",{}),t.jsx("span",{children:n(e.mainLabel)}),t.jsx("span",{style:{display:"grid",gridTemplateColumns:e.columns.map(i=>i.width).join(" "),gap:12},children:e.columns.map(i=>t.jsx("span",{children:n(i.label)},i.label))})]})}function Ma({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 Fa(e){return String(e+1).padStart(2,"0")}function Pa(){return t.jsx("span",{style:{color:o("hint-fg")},children:"—"})}function Oa({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 Br(e){const n=[];for(let i=0;i<e.length;i++){const r=e[i];let s;if(r==="⟨")s="⟩";else if(r==="<"){const d=e[i+1];if(d===void 0||/[A-Za-z/!?>\s]/.test(d))continue;s=">"}else continue;const l=e.indexOf(s,i+1);if(l<0)continue;const p=e.slice(i+1,l);p.includes(`
299
- `)||(n.push({start:i,end:l+1,inner:p}),i=l)}return n}function Nr(e,n){if(e.length<=n)return e;let i=n;for(const r of Br(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 Wr={fontSize:".78em",color:o("meta-fg"),lineHeight:1.55},Da={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 Ar(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?Wr:void 0,children:Ar(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:Da,children:r.label},s)}})}function ze(e,n=r=>r,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return ka(e)?Ar($r(e),n,0):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let s=0,l=0;for(const p of Br(e))p.start>s&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s,p.start))},l++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:Wr,children:n(p.inner)},l++)),s=p.end;return s<e.length&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),r}function Ha({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 Ga({title:e,tag:n,children:i}){const{convert:r}=Y();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${o("rule-strong")}`,marginBottom:2},children:[t.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:r(e)}),n&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:o("accent"),letterSpacing:".06em"},children:r(n)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function Mr({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 Ua({item:e,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=Y(),[l,p]=f.useState(!1),d=Xt(e),c=i&&!!d&&d.expected>0,a=(e.url?tt(e.url):void 0)||s(e.name),u=n?hr(e,n):"",x=u?`${a}(${u})`:a;return t.jsx(Mr,{name:x,note:Nt(e)||r,href:bt(e),extra:c?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>p(g=>!g),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?"收起分冊":`展開 ${d.expected} 冊`}),l&&t.jsx(Qn,{item:e})]}):void 0})}function Qn({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 Fr({label:e,items:n}){const{convert:i}=Y();return n.length?t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg"),letterSpacing:".08em"},children:e}),n.map((r,s)=>t.jsx(Lr,{children:i(r)},s))]}):null}function Va({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(Fr,{label:i.label,items:i.items},i.label))}):null}function En(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Pr({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 Ya({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 Pe({id:e,label:n,onNavigate:i,renderLink:r,style:s,dense:l}){const p=je();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:l})}):t.jsx("a",{href:p(e),onClick:i?d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),i(e))}:void 0,style:s,children:n??e})}function Ka({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 Or="(min-width: 1100px)",qa="(max-width: 719px)",Ve=o("reader-top"),Ja="48px",Dr=`
314
+ ${Ca}`;function It({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Tr}),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 In({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 Xn({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 Tn({items:e}){const n=ve();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}`),p=i.id?n(i.id):i.href,d=s||!i.onClick&&!p?t.jsx("span",{style:{color:o("ink")},children:i.label},r):t.jsx("a",{href:p??"#",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,d]},r)})})}function Rr({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 Ra({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 Ea({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 La({glyph:e,tone:n,title:i,count:r,actions:s,id:l}){const{convert:p}=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(Xn,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:p(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 Er({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 Na({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 Ba({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 Lr({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 Wa({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function Aa({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(p=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${o("rule")}`,color:o("meta-fg")},children:p},p)),!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 Ma({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${o("rule-strong")}`},children:e})}function Fa({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 Pa({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 Oa(e){return String(e+1).padStart(2,"0")}function Da(){return t.jsx("span",{style:{color:o("hint-fg")},children:"—"})}function Ha({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 Nr(e){const n=[];for(let i=0;i<e.length;i++){const r=e[i];let s;if(r==="⟨")s="⟩";else if(r==="<"){const d=e[i+1];if(d===void 0||/[A-Za-z/!?>\s]/.test(d))continue;s=">"}else continue;const l=e.indexOf(s,i+1);if(l<0)continue;const p=e.slice(i+1,l);p.includes(`
315
+ `)||(n.push({start:i,end:l+1,inner:p}),i=l)}return n}function Br(e,n){if(e.length<=n)return e;let i=n;for(const r of Nr(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 Wr={fontSize:".78em",color:o("meta-fg"),lineHeight:1.55},Ga={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 Ar(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?Wr:void 0,children:Ar(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:Ga,children:r.label},s)}})}function Ie(e,n=r=>r,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return wa(e)?Ar($r(e),n,0):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let s=0,l=0;for(const p of Nr(e))p.start>s&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s,p.start))},l++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:Wr,children:n(p.inner)},l++)),s=p.end;return s<e.length&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),r}function Ua({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 Va({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 Mr({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 Ya({item:e,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=V(),[l,p]=f.useState(!1),d=Xt(e),c=i&&!!d&&d.expected>0,a=(e.url?tt(e.url):void 0)||s(e.name),u=n?hr(e,n):"",x=u?`${a}(${u})`:a;return t.jsx(Mr,{name:x,note:Bt(e)||r,href:bt(e),extra:c?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>p(g=>!g),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?"收起分冊":`展開 ${d.expected} 冊`}),l&&t.jsx(Qn,{item:e})]}):void 0})}function Qn({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 Fr({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(Lr,{children:i(r)},s))]}):null}function Ka({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(Fr,{label:i.label,items:i.items},i.label))}):null}function Rn(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Pr({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 qa({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 Pe({id:e,label:n,onNavigate:i,renderLink:r,style:s,dense:l}){const p=ve();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:l})}):t.jsx("a",{href:p(e),onClick:i?d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),i(e))}:void 0,style:s,children:n??e})}function Ja({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 Or="(min-width: 1100px)",Dr="(max-width: 719px)",Za=`${Dr}, (pointer: coarse)`,Ve=o("reader-top"),Xa="48px",Hr=`
300
316
  .bim-rd {
301
317
  position: relative;
302
318
  background: ${o("page-bg")};
303
319
  color: ${o("ink")};
304
320
  font-family: ${o("font-ui")};
305
- --bimrd-bar-h: ${Ja};
321
+ --bimrd-bar-h: ${Xa};
306
322
  }
307
323
  .bim-rd *, .bim-rd *::before, .bim-rd *::after { box-sizing: border-box; }
308
324
 
@@ -351,6 +367,13 @@ ${$a}`;function It({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
351
367
  .bim-rd-t svg { flex: none; }
352
368
  .bim-rd-t .bim-rd-on { color: ${o("accent")}; font-weight: 700; }
353
369
  .bim-rd-t .bim-rd-off { opacity: 0.55; }
370
+ .bim-rd-ver { position: relative; display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
371
+ .bim-rd-ver-short { display: none; }
372
+ .bim-rd-ver select {
373
+ max-width: 16em; min-height: 32px; margin: 0; padding: 0 2px;
374
+ background: none; border: 0; font: inherit; color: ${o("ink")}; cursor: pointer;
375
+ text-overflow: ellipsis;
376
+ }
354
377
  .bim-rd :focus-visible { outline: 2px solid ${o("accent")}; outline-offset: 2px; border-radius: 3px; }
355
378
 
356
379
  /* ── 主体:目录 | 书影 | 正文 ── */
@@ -454,6 +477,11 @@ ${$a}`;function It({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
454
477
  .bim-rd-prose h3 { font-size: 1.06em; font-weight: 700; margin: 1.4em 0 0.3em; }
455
478
  .bim-rd-prose h4 { font-size: 1em; font-weight: 700; margin: 1.2em 0 0.2em; }
456
479
  .bim-rd-prose > :first-child { margin-top: 0; }
480
+ /* 标题标签按层级不跳级(h1 下先 h2,INT Q5),外观按 md 原层级走 class */
481
+ .bim-rd-prose .bim-rd-hl2 { font-size: 1.2em; font-weight: 700; margin: 1.6em 0 0.6em; }
482
+ .bim-rd-prose .bim-rd-hl3 { font-size: 1.06em; font-weight: 700; margin: 1.4em 0 0.3em; }
483
+ .bim-rd-prose .bim-rd-hl4 { font-size: 1em; font-weight: 700; margin: 1.2em 0 0.2em; }
484
+ .bim-rd-prose > .bim-rd-hl2:first-child, .bim-rd-prose > .bim-rd-hl3:first-child, .bim-rd-prose > .bim-rd-hl4:first-child { margin-top: 0; }
457
485
  .bim-rd-prose .bim-rd-gap { height: 0.6em; }
458
486
  .bim-rd-entry { margin-top: 1.6em; }
459
487
  .bim-rd-entry h3 { margin: 0 !important; }
@@ -477,12 +505,26 @@ ${$a}`;function It({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
477
505
  overflow-x: auto; text-align: start;
478
506
  }
479
507
 
508
+ .bim-rd-src { margin: 48px 0 0; font-size: 12px; line-height: 1.8; color: ${o("meta-fg")}; font-family: ${o("font-ui")}; }
509
+ .bim-rd-src .bim-rd-dot::before { content: "·"; margin: 0 0.5em; }
480
510
  .bim-rd-pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 56px; font-size: 14px; font-family: ${o("font-ui")}; }
481
511
  .bim-rd-pager .bim-rd-t { color: ${o("quiet-fg")}; }
482
512
  .bim-rd-refs { margin-top: 48px; font-size: 12px; line-height: 1.8; color: ${o("meta-fg")}; font-family: ${o("font-ui")}; }
483
513
  .bim-rd-refs h2 { font-size: 12px; font-weight: 600; letter-spacing: 0.2em; margin: 0 0 6px; color: ${o("meta-fg")}; }
484
514
  .bim-rd-refs ol { margin: 0; padding-left: 1.6em; }
485
515
 
516
+ /* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
517
+ A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
518
+ @media ${Za} {
519
+ .bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
520
+ .bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
521
+ content: ""; position: absolute; left: 50%; top: 50%;
522
+ width: max(100%, 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
523
+ }
524
+ .bim-rd-tools .bim-rd-fs + .bim-rd-fs { margin-left: 12px; }
525
+ .bim-rd-ver select { min-height: 44px; }
526
+ }
527
+
486
528
  /* ── 中屏以下:目录改抽屉 ── */
487
529
  @media not all and ${Or} {
488
530
  .bim-rd-toc {
@@ -498,11 +540,15 @@ ${$a}`;function It({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
498
540
  }
499
541
 
500
542
  /* ── 窄屏:书影收起,只留正文 ── */
501
- @media ${qa} {
543
+ @media ${Dr} {
502
544
  .bim-rd-bar { padding: 0 12px; gap: 10px; }
503
545
  .bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
504
546
  .bim-rd-ttl { flex: 1 1 auto; }
505
547
  .bim-rd-tools { gap: 10px; }
548
+ .bim-rd-ver { min-width: 44px; min-height: 44px; justify-content: center; }
549
+ .bim-rd-ver-short { display: inline; white-space: nowrap; }
550
+ .bim-rd-ver select { position: absolute; inset: 0; width: 100%; max-width: none; opacity: 0; }
551
+ .bim-rd-ver:focus-within { outline: 2px solid ${o("accent")}; outline-offset: 2px; border-radius: 3px; }
506
552
  .bim-rd-tlabel { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
507
553
  .bim-rd-img { display: none !important; }
508
554
  .bim-rd-body { grid-template-columns: minmax(0, 1fr); }
@@ -510,18 +556,19 @@ ${$a}`;function It({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
510
556
  .bim-rd-h1 { font-size: 20px; letter-spacing: 0.06em; }
511
557
  .bim-rd-prose { margin-top: 20px; }
512
558
  }
513
- `;function ei(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(r=>ei(r,n))):!1}const Za=()=>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 Xa({item:e,activeKey:n,onSelect:i,tabKey:r}){const s=ei(e,n),[l,p]=f.useState(s||!!e.defaultExpanded);return f.useEffect(()=>{s&&p(!0)},[s]),f.useEffect(()=>{e.defaultExpanded&&p(!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:()=>p(d=>!d),children:[t.jsx(Za,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Hr,{items:e.children,activeKey:n,onSelect:i,tabKey:r})]})}function Hr({items:e,activeKey:n,onSelect:i,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Xa,{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 so(e,n){var i;for(const r of e)if(r.key===n||ei(r,n))return r.key;return((i=e[0])==null?void 0:i.key)??null}function Gr({items:e,activeKey:n,onSelect:i,label:r="目录"}){const s=f.useRef(null),[l,p]=f.useState(null);f.useEffect(()=>{p(null)},[n]);const d=f.useMemo(()=>l||(n??so(e,n)),[l,n,e]);f.useEffect(()=>{const a=s.current;if(!a)return;const u=Array.from(a.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const x=u.find(g=>g.dataset.rdTocKey===d)??u.find(g=>g.dataset.rdTocKey===so(e,n))??u.find(g=>!g.disabled)??u[0];for(const g of u)g.tabIndex=g===x?0:-1}),f.useEffect(()=>{const a=s.current,u=a==null?void 0:a.closest(".bim-rd-toc");if(!a||!u||!n)return;const x=Array.from(a.querySelectorAll("[data-rd-toc-key]")).find(h=>h.dataset.rdTocKey===n);if(!x)return;const g=x.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(g<u.scrollTop+80||g>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,g-u.clientHeight/3))},[n]);const c=f.useCallback(a=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(a.key))return;const x=s.current;if(!x)return;const g=Array.from(x.querySelectorAll("[data-rd-toc-key]")).filter(m=>!m.disabled),h=g.indexOf(document.activeElement);let y=h;if(a.key==="ArrowDown"?y=Math.min(g.length-1,h+1):a.key==="ArrowUp"?y=Math.max(0,h-1):a.key==="Home"?y=0:a.key==="End"&&(y=g.length-1),y<0||y===h)return;a.preventDefault();const k=g[y];for(const m of g)m.tabIndex=-1;k.tabIndex=0,k.focus(),p(k.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:c,children:t.jsx(Hr,{items:e,activeKey:n,onSelect:i,tabKey:d})})}function Qa({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 Ur({pages:e,loading:n,page:i,onPageChange:r,renderOverlay:s}){const[l,p]=f.useState(0),d=i??l,c=g=>{r?r(g):p(g)};if(f.useEffect(()=>{i===void 0&&p(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 a=Math.max(0,Math.min(e.length-1,d)),u=e[a],x=u.label??`${a+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??`书影 第 ${x} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(Qa,{page:u}),s==null?void 0:s(u,a)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:a===0,onClick:()=>c(a-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${a+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:a===e.length-1,onClick:()=>c(a+1),children:"›"})]})]})}const ti={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal"},dt=[15,16,17,18,20,22,24],Ln=18,Vr="bim-reader-prefs",ec="bim-reading-mode";function tc(){const e={...ti};try{const n=localStorage.getItem(Vr),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&dt.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(ec))==="paragraph"&&(e.readingMode="paragraph"),i.properNames===!0&&(e.properNames=!0),i.writingMode==="vertical"&&(e.writingMode="vertical")}catch{}return e}function nc(e){try{localStorage.setItem(Vr,JSON.stringify(e))}catch{}}function lo(e,n){const i=e??Ln,r=dt;let s=r.indexOf(i);return s<0&&(s=r.indexOf(Ln)),r[Math.max(0,Math.min(r.length-1,s+n))]}function ni(){const[e,n]=f.useState(ti);f.useEffect(()=>{n(tc())},[]);const i=f.useCallback(r=>{n(s=>{const l={...s,...r};return nc(l),l})},[]);return[e,i]}function Yr(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 ic=()=>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"})}),oc=()=>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 rc(e,n){if(!n)return;const i=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(p=>p.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 sc(e,n){const[i,r]=f.useState(n);return f.useEffect(()=>{var p;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(s.matches);return(p=s.addEventListener)==null||p.call(s,"change",l),()=>{var d;return(d=s.removeEventListener)==null?void 0:d.call(s,"change",l)}},[e]),i}function lc(){const e=f.useContext(mt);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 ii({title:e,subtitle:n,toc:i,activeKey:r,onSelect:s,tocHeader:l,tocCaption:p,images:d,imagesLoading:c,renderImageOverlay:a,imagePanel:u="auto",prefs:x,onPrefsChange:g,paragraphToggle:h,properNameToggle:y=!0,allowVertical:k,pager:m=!0,children:v,className:b,style:j}){const $=f.useId().replace(/:/g,""),S=`bim-rd-toc-${$}`,_=`bim-rd-text-${$}`,w=f.useRef(null),z=f.useRef(null),B=f.useRef(null),L=f.useRef(null),C=sc(Or,!0),[A,W]=f.useState("auto"),T=A==="auto"?C:A==="open",R=!C,N=!!d&&d.length>0,[O,E]=f.useState(u);f.useEffect(()=>{E(u)},[u]);const X=O==="auto"?N||!!c:O==="open",I=f.useCallback(U=>{var se;W("auto"),U&&((se=L.current)==null||se.focus())},[]),M=()=>W(T?"closed":"open");f.useEffect(()=>{if(!R||A!=="open")return;const U=B.current,se=U==null?void 0:U.querySelector('input, [data-rd-toc-key][tabindex="0"]');se==null||se.focus()},[R,A]);const K=f.useCallback(U=>{s(U),R&&I(!1);const se=z.current,de=w.current;if(se&&de&&typeof window<"u"){const D=se.getBoundingClientRect().top-de.getBoundingClientRect().bottom;D<0&&window.scrollBy({top:D})}},[s,R,I]),V=f.useMemo(()=>Yr(i),[i]),G=V.findIndex(U=>U.key===r),ee=G>0?V.slice(0,G).reverse().find(U=>!U.disabled):void 0,P=G>=0?V.slice(G+1).find(U=>!U.disabled):void 0,q=x.fontSize??Ln,Z={...j,...x.fontSize?{"--bimrd-fs":`${x.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",x.writingMode==="vertical"&&k?"bim-rd-vertical":"",b].filter(Boolean).join(" "),"data-toc":A,"data-img":X?"open":"closed",style:Z,children:[t.jsx("style",{children:Dr}),t.jsx("a",{className:"bim-rd-skip",href:`#${_}`,onClick:U=>{var se,de,D;U.preventDefault(),(se=z.current)==null||se.focus(),(D=(de=z.current)==null?void 0:de.scrollIntoView)==null||D.call(de,{block:"start"})},children:"跳到正文"}),t.jsxs("div",{className:"bim-rd-bar",ref:w,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:[t.jsxs("button",{ref:L,type:"button",className:"bim-rd-t","aria-expanded":T,"aria-controls":S,onClick:M,children:[t.jsx(ic,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":X,onClick:()=>E(X?"closed":"open"),children:[t.jsx(oc,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(lc,{}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"缩小字号",disabled:q<=dt[0],onClick:()=>g({fontSize:lo(x.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大字号",disabled:q>=dt[dt.length-1],onClick:()=>g({fontSize:lo(x.fontSize,1)}),children:"A+"}),(h||y||k)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),h&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":x.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>g({readingMode:x.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),y&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":x.properNames,title:"书名加波浪线",onClick:()=>g({properNames:!x.properNames}),children:"专名线"}),k&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":x.writingMode==="vertical",onClick:()=>g({writingMode:x.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:S,ref:B,role:R&&T?"dialog":void 0,"aria-modal":R&&T?!0:void 0,"aria-label":R&&T?"目录":void 0,onKeyDown:U=>{if(!(!R||!T)){if(U.key==="Escape"){U.stopPropagation(),I(!0);return}U.key==="Tab"&&rc(U,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:p??"目录"}),R&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>I(!0),children:"✕"})]}),l]}),t.jsx(Gr,{items:i,activeKey:r,onSelect:K})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>I(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:X&&t.jsx(Ur,{pages:d??null,loading:c,renderOverlay:a})}),t.jsx("div",{className:"bim-rd-text",id:_,ref:z,tabIndex:-1,children:t.jsxs("div",{className:"bim-rd-col",children:[v,m&&(ee||P)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[t.jsx("span",{children:ee&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>K(ee.key),children:["‹ ",ee.label]})}),t.jsx("span",{children:P&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>K(P.key),children:[P.label," ›"]})})]})]})})]})]})}const Kr="guji-table-v1";function qr(e){return!!e&&e.table_notation===Kr}const ac=/^:::table(?:\{[^}]*\})?[ \t]*$/,cc=/^:::[ \t]*$/;function Jr(e){const n=[];let i="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const p=wr(e,r+3);if(p>r+4){i+=e.slice(r,p+1),r=p;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const p=e[r+1];p!==void 0&&!/[A-Za-z/!?>\s]/.test(p)&&(l=">")}if(l){const p=e.indexOf(l,r+1);if(p>0){i+=e.slice(r,p+1),r=p;continue}}s==="|"?(n.push(i),i=""):i+=s}return n.push(i),n.map(r=>r.trim())}const dc=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function pc(e){if(e==="^")return{cont:!0};const n=dc.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 Zr(e,n=1){const i=[],r=[],s=[];let l=[];e.forEach((d,c)=>{const a=c+n+1;let u=d.trim();if(!u)return;let x=!1;u.startsWith("!")&&(x=!0,u=u.slice(1));const g=Jr(u).map(pc),h=l.map(v=>v>0),y=l.map(v=>v>0?v-1:0),k=[];let m=0;for(const v of g){if(v.cont){h[m]||i.push(`第 ${a} 行第 ${m+1} 列:续格 ^ 上方没有跨行格`),m+=1;continue}const{cell:b}=v;for(let j=m;j<m+b.colspan;j++)if(h[j]){i.push(`第 ${a} 行第 ${j+1} 列:此处被上方跨行格占住,应写 ^`);break}if(b.rowspan>1)for(let j=m;j<m+b.colspan;j++)y[j]=b.rowspan-1;k.push(b),m+=b.colspan}for(let v=m;v<h.length;v++)h[v]&&i.push(`第 ${a} 行第 ${v+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let v=0;v<y.length;v++)y[v]===void 0&&(y[v]=0);l=y,r.push({header:x,cells:k}),s.push({width:m,line:a})});const p=s.reduce((d,c)=>Math.max(d,c.width),0);for(const d of s)d.width!==p&&i.push(`第 ${d.line} 行:占 ${d.width} 列,与总列数 ${p} 不符`);return l.some(d=>d>0)&&i.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&i.push("空表"),{rows:r,columns:p,warnings:i}}function oi(e){const n=e.split(`
559
+ `;function ei(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(r=>ei(r,n))):!1}const Qa=()=>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 ec({item:e,activeKey:n,onSelect:i,tabKey:r}){const s=ei(e,n),[l,p]=f.useState(s||!!e.defaultExpanded);return f.useEffect(()=>{s&&p(!0)},[s]),f.useEffect(()=>{e.defaultExpanded&&p(!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:()=>p(d=>!d),children:[t.jsx(Qa,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Gr,{items:e.children,activeKey:n,onSelect:i,tabKey:r})]})}function Gr({items:e,activeKey:n,onSelect:i,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(ec,{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 so(e,n){var i;for(const r of e)if(r.key===n||ei(r,n))return r.key;return((i=e[0])==null?void 0:i.key)??null}function Ur({items:e,activeKey:n,onSelect:i,label:r="目录"}){const s=f.useRef(null),[l,p]=f.useState(null);f.useEffect(()=>{p(null)},[n]);const d=f.useMemo(()=>l||(n??so(e,n)),[l,n,e]);f.useEffect(()=>{const a=s.current;if(!a)return;const u=Array.from(a.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const x=u.find(g=>g.dataset.rdTocKey===d)??u.find(g=>g.dataset.rdTocKey===so(e,n))??u.find(g=>!g.disabled)??u[0];for(const g of u)g.tabIndex=g===x?0:-1}),f.useEffect(()=>{const a=s.current,u=a==null?void 0:a.closest(".bim-rd-toc");if(!a||!u||!n)return;const x=Array.from(a.querySelectorAll("[data-rd-toc-key]")).find(h=>h.dataset.rdTocKey===n);if(!x)return;const g=x.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(g<u.scrollTop+80||g>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,g-u.clientHeight/3))},[n]);const c=f.useCallback(a=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(a.key))return;const x=s.current;if(!x)return;const g=Array.from(x.querySelectorAll("[data-rd-toc-key]")).filter(m=>!m.disabled),h=g.indexOf(document.activeElement);let b=h;if(a.key==="ArrowDown"?b=Math.min(g.length-1,h+1):a.key==="ArrowUp"?b=Math.max(0,h-1):a.key==="Home"?b=0:a.key==="End"&&(b=g.length-1),b<0||b===h)return;a.preventDefault();const k=g[b];for(const m of g)m.tabIndex=-1;k.tabIndex=0,k.focus(),p(k.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:c,children:t.jsx(Gr,{items:e,activeKey:n,onSelect:i,tabKey:d})})}function tc({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 Vr({pages:e,loading:n,page:i,onPageChange:r,renderOverlay:s}){const[l,p]=f.useState(0),d=i??l,c=g=>{r?r(g):p(g)};if(f.useEffect(()=>{i===void 0&&p(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 a=Math.max(0,Math.min(e.length-1,d)),u=e[a],x=u.label??`${a+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??`书影 第 ${x} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(tc,{page:u}),s==null?void 0:s(u,a)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:a===0,onClick:()=>c(a-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${a+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:a===e.length-1,onClick:()=>c(a+1),children:"›"})]})]})}const ti={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal"},dt=[15,16,17,18,20,22,24],En=18,Yr="bim-reader-prefs",nc="bim-reading-mode";function ic(){const e={...ti};try{const n=localStorage.getItem(Yr),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&dt.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(nc))==="paragraph"&&(e.readingMode="paragraph"),i.properNames===!0&&(e.properNames=!0),i.writingMode==="vertical"&&(e.writingMode="vertical")}catch{}return e}function oc(e){try{localStorage.setItem(Yr,JSON.stringify(e))}catch{}}function lo(e,n){const i=e??En,r=dt;let s=r.indexOf(i);return s<0&&(s=r.indexOf(En)),r[Math.max(0,Math.min(r.length-1,s+n))]}function ni(){const[e,n]=f.useState(ti);f.useEffect(()=>{n(ic())},[]);const i=f.useCallback(r=>{n(s=>{const l={...s,...r};return oc(l),l})},[]);return[e,i]}function rc(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 Ln(e){const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function Kr(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 qr(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 sc=()=>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"})}),lc=()=>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 ac(e,n){if(!n)return;const i=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(p=>p.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 cc(e,n){const[i,r]=f.useState(n);return f.useEffect(()=>{var p;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(s.matches);return(p=s.addEventListener)==null||p.call(s,"change",l),()=>{var d;return(d=s.removeEventListener)==null?void 0:d.call(s,"change",l)}},[e]),i}function dc(){const e=f.useContext(mt);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 ii({title:e,subtitle:n,toc:i,activeKey:r,onSelect:s,tocHeader:l,tocCaption:p,images:d,imagesLoading:c,renderImageOverlay:a,imagePanel:u="auto",prefs:x,onPrefsChange:g,paragraphToggle:h,properNameToggle:b=!0,allowVertical:k,pager:m=!0,versions:v,currentVersionKey:y,onVersionChange:j,versionSource:$=!0,children:S,className:_,style:w}){const z=f.useId().replace(/:/g,""),B=`bim-rd-toc-${z}`,E=`bim-rd-text-${z}`,C=f.useRef(null),A=f.useRef(null),W=f.useRef(null),T=f.useRef(null),L=cc(Or,!0),[M,P]=f.useState("auto"),R=M==="auto"?L:M==="open",ne=!L,I=!!d&&d.length>0,[F,K]=f.useState(u);f.useEffect(()=>{K(u)},[u]);const G=F==="auto"?I||!!c:F==="open",U=f.useCallback(q=>{var N;P("auto"),q&&((N=T.current)==null||N.focus())},[]),te=()=>P(R?"closed":"open");f.useEffect(()=>{if(!ne||M!=="open")return;const q=W.current,N=q==null?void 0:q.querySelector('input, [data-rd-toc-key][tabindex="0"]');N==null||N.focus()},[ne,M]);const O=f.useCallback(q=>{s(q),ne&&U(!1);const N=A.current,ee=C.current;if(N&&ee&&typeof window<"u"){const re=N.getBoundingClientRect().top-ee.getBoundingClientRect().bottom;re<0&&window.scrollBy({top:re})}},[s,ne,U]),Y=f.useMemo(()=>qr(i),[i]),[Z,X]=f.useState(null),se=Kr(v,y!==void 0?y:Z),ge=(se==null?void 0:se.key)??null,he=f.useMemo(()=>Y.map(q=>q.key).join(`
560
+ `),[Y]),D=f.useRef(null),le=q=>{q!==ge&&(D.current={key:q,sig:he,done:!1},y===void 0&&X(q),j==null||j(q))};f.useEffect(()=>{const q=D.current;if(!q||q.key!==ge)return;const N=Y.find(re=>!re.disabled);if(!N)return;const ee=he!==q.sig;!ee&&q.done||(ee?D.current=null:q.done=!0,N.key!==r&&O(N.key))},[ge,he,Y,r,O]);const oe=Y.findIndex(q=>q.key===r),ce=oe>0?Y.slice(0,oe).reverse().find(q=>!q.disabled):void 0,ue=oe>=0?Y.slice(oe+1).find(q=>!q.disabled):void 0,me=x.fontSize??En,Q={...w,...x.fontSize?{"--bimrd-fs":`${x.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",x.writingMode==="vertical"&&k?"bim-rd-vertical":"",_].filter(Boolean).join(" "),"data-toc":M,"data-img":G?"open":"closed",style:Q,children:[t.jsx("style",{children:Hr}),t.jsx("a",{className:"bim-rd-skip",href:`#${E}`,onClick:q=>{var N,ee,re;q.preventDefault(),(N=A.current)==null||N.focus(),(re=(ee=A.current)==null?void 0:ee.scrollIntoView)==null||re.call(ee,{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:[v&&v.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:se?Ln(se):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:ge??"",onChange:q=>le(q.target.value),children:v.map(q=>t.jsx("option",{value:q.key,children:Ln(q)},q.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),t.jsxs("button",{ref:T,type:"button",className:"bim-rd-t","aria-expanded":R,"aria-controls":B,onClick:te,children:[t.jsx(sc,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":G,onClick:()=>K(G?"closed":"open"),children:[t.jsx(lc,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(dc,{}),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:me<=dt[0],onClick:()=>g({fontSize:lo(x.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"放大字号",disabled:me>=dt[dt.length-1],onClick:()=>g({fontSize:lo(x.fontSize,1)}),children:"A+"}),(h||b||k)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),h&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":x.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>g({readingMode:x.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),b&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":x.properNames,title:"书名加波浪线",onClick:()=>g({properNames:!x.properNames}),children:"专名线"}),k&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":x.writingMode==="vertical",onClick:()=>g({writingMode:x.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:B,ref:W,role:ne&&R?"dialog":void 0,"aria-modal":ne&&R?!0:void 0,"aria-label":ne&&R?"目录":void 0,onKeyDown:q=>{if(!(!ne||!R)){if(q.key==="Escape"){q.stopPropagation(),U(!0);return}q.key==="Tab"&&ac(q,W.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:p??"目录"}),ne&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>U(!0),children:"✕"})]}),l]}),t.jsx(Ur,{items:i,activeKey:r,onSelect:O})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>U(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:G&&t.jsx(Vr,{pages:d??null,loading:c,renderOverlay:a})}),t.jsx("div",{className:"bim-rd-text",id:E,ref:A,tabIndex:-1,children:t.jsxs("div",{className:"bim-rd-col",children:[S,$&&se&&(se.sourceName||se.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":se.key,children:[se.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",se.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:se.sourceUrl,target:"_blank",rel:"noreferrer",children:se.sourceName}):se.sourceName]}),se.sourceName&&se.license&&t.jsx("span",{className:"bim-rd-dot"}),se.license&&t.jsxs(t.Fragment,{children:["授权 ",se.license]})]}),m&&(ce||ue)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[t.jsx("span",{children:ce&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>O(ce.key),children:["‹ ",ce.label]})}),t.jsx("span",{children:ue&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>O(ue.key),children:[ue.label," ›"]})})]})]})})]})]})}const Jr="guji-table-v1";function Zr(e){return!!e&&e.table_notation===Jr}const pc=/^:::table(?:\{[^}]*\})?[ \t]*$/,uc=/^:::[ \t]*$/;function Xr(e){const n=[];let i="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const p=wr(e,r+3);if(p>r+4){i+=e.slice(r,p+1),r=p;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const p=e[r+1];p!==void 0&&!/[A-Za-z/!?>\s]/.test(p)&&(l=">")}if(l){const p=e.indexOf(l,r+1);if(p>0){i+=e.slice(r,p+1),r=p;continue}}s==="|"?(n.push(i),i=""):i+=s}return n.push(i),n.map(r=>r.trim())}const xc=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function fc(e){if(e==="^")return{cont:!0};const n=xc.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 Qr(e,n=1){const i=[],r=[],s=[];let l=[];e.forEach((d,c)=>{const a=c+n+1;let u=d.trim();if(!u)return;let x=!1;u.startsWith("!")&&(x=!0,u=u.slice(1));const g=Xr(u).map(fc),h=l.map(v=>v>0),b=l.map(v=>v>0?v-1:0),k=[];let m=0;for(const v of g){if(v.cont){h[m]||i.push(`第 ${a} 行第 ${m+1} 列:续格 ^ 上方没有跨行格`),m+=1;continue}const{cell:y}=v;for(let j=m;j<m+y.colspan;j++)if(h[j]){i.push(`第 ${a} 行第 ${j+1} 列:此处被上方跨行格占住,应写 ^`);break}if(y.rowspan>1)for(let j=m;j<m+y.colspan;j++)b[j]=y.rowspan-1;k.push(y),m+=y.colspan}for(let v=m;v<h.length;v++)h[v]&&i.push(`第 ${a} 行第 ${v+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let v=0;v<b.length;v++)b[v]===void 0&&(b[v]=0);l=b,r.push({header:x,cells:k}),s.push({width:m,line:a})});const p=s.reduce((d,c)=>Math.max(d,c.width),0);for(const d of s)d.width!==p&&i.push(`第 ${d.line} 行:占 ${d.width} 列,与总列数 ${p} 不符`);return l.some(d=>d>0)&&i.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&i.push("空表"),{rows:r,columns:p,warnings:i}}function oi(e){const n=e.split(`
514
561
  `),i=[];let r=[];const s=()=>{if(r.length===0)return;const p=r.join(`
515
- `);r=[],i.push({type:"text",text:p})};let l=0;for(;l<n.length;){if(ac.test(n[l].trim())){let p=l+1;for(;p<n.length&&!cc.test(n[p].trim());)p++;if(p<n.length){s();const d=n.slice(l+1,p);i.push({type:"table",table:Zr(d,l+1),source:n.slice(l,p+1).join(`
516
- `)}),l=p+1;continue}}r.push(n[l]),l++}return s(),i.map((p,d)=>{var a,u;if(p.type!=="text")return p;let c=p.text;return((a=i[d-1])==null?void 0:a.type)==="table"&&(c=c.replace(/^\n+/,"")),((u=i[d+1])==null?void 0:u.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(p=>p.type!=="text"||p.text!=="")}const uc={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},xc={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},fc=`1px solid ${o("table-border")}`,Xr={border:fc,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},gc={...Xr,background:o("table-head-bg"),fontWeight:600};function ri({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:uc,children:t.jsx("table",{className:"bim-guji-table",style:xc,children:t.jsx("tbody",{children:e.rows.map((i,r)=>t.jsx("tr",{children:i.cells.map((s,l)=>{const p=i.header?"th":"td";return t.jsx(p,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:i.header?gc:Xr,children:s.empty?null:ze(s.text,void 0,n)},l)})},r))})})})}function hc(e,n){return e.indexOf("**")<0?ze(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:ze(r.trim().slice(2,-2),void 0,n)},s):t.jsx(f.Fragment,{children:ze(r,void 0,n)},s))}function mc(e,n,i=!1){const r=i?{gujiMarkdown:!0}:void 0;return n?oi(e).map((s,l)=>s.type==="table"?t.jsx(ri,{table:s.table,opts:r},l):t.jsx(f.Fragment,{children:hc(s.text,r)},l)):ze(e,void 0,r)}const bc=/^(#{1,6})\s+(.*)$/,yc=/^\*\*([^*\n]+)\*\*\s*$/;function si(e){const n=e.match(bc);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(yc);return i?{level:3,text:i[1].trim()}:null}const li=/^<!--.*-->$/;function Qr(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function es(e){return e.split(`
517
- `).map(n=>n.trim()).filter(n=>n&&!li.test(n))}const jc=60;function ts(e){let n=0,i=0;for(const r of e.split(`
518
- `)){const s=r.trim();if(!s||li.test(s)||si(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>jc&&(i+=l)}return n>0&&i*2>=n}function vc(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function sn(e){if(e=vc(e),ts(e))return"unknown";const n=Qr(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>es(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 kc(e){const n=e.split(`
562
+ `);r=[],i.push({type:"text",text:p})};let l=0;for(;l<n.length;){if(pc.test(n[l].trim())){let p=l+1;for(;p<n.length&&!uc.test(n[p].trim());)p++;if(p<n.length){s();const d=n.slice(l+1,p);i.push({type:"table",table:Qr(d,l+1),source:n.slice(l,p+1).join(`
563
+ `)}),l=p+1;continue}}r.push(n[l]),l++}return s(),i.map((p,d)=>{var a,u;if(p.type!=="text")return p;let c=p.text;return((a=i[d-1])==null?void 0:a.type)==="table"&&(c=c.replace(/^\n+/,"")),((u=i[d+1])==null?void 0:u.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(p=>p.type!=="text"||p.text!=="")}const gc={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},hc={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},mc=`1px solid ${o("table-border")}`,es={border:mc,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},bc={...es,background:o("table-head-bg"),fontWeight:600};function ri({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:gc,children:t.jsx("table",{className:"bim-guji-table",style:hc,children:t.jsx("tbody",{children:e.rows.map((i,r)=>t.jsx("tr",{children:i.cells.map((s,l)=>{const p=i.header?"th":"td";return t.jsx(p,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:i.header?bc:es,children:s.empty?null:Ie(s.text,void 0,n)},l)})},r))})})})}function yc(e,n){return e.indexOf("**")<0?Ie(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:Ie(r.trim().slice(2,-2),void 0,n)},s):t.jsx(f.Fragment,{children:Ie(r,void 0,n)},s))}function jc(e,n,i=!1){const r=i?{gujiMarkdown:!0}:void 0;return n?oi(e).map((s,l)=>s.type==="table"?t.jsx(ri,{table:s.table,opts:r},l):t.jsx(f.Fragment,{children:yc(s.text,r)},l)):Ie(e,void 0,r)}const vc=/^(#{1,6})\s+(.*)$/,kc=/^\*\*([^*\n]+)\*\*\s*$/;function si(e){const n=e.match(vc);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(kc);return i?{level:3,text:i[1].trim()}:null}const li=/^<!--.*-->$/;function ts(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function ns(e){return e.split(`
564
+ `).map(n=>n.trim()).filter(n=>n&&!li.test(n))}const Sc=60;function is(e){let n=0,i=0;for(const r of e.split(`
565
+ `)){const s=r.trim();if(!s||li.test(s)||si(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>Sc&&(i+=l)}return n>0&&i*2>=n}function wc(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function sn(e){if(e=wc(e),is(e))return"unknown";const n=ts(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>ns(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 _c(e){const n=e.split(`
519
566
  `),i=[];let r=null,s=[];const l=()=>{i.push({heading:r,body:s.join(`
520
567
  `)}),s=[]};for(const p of n){const d=si(p);if(d){l(),r={kind:"heading",level:d.level,text:d.text};continue}s.push(p)}return l(),i}function ao(e){const n=[];for(const i of e.split(`
521
- `)){const r=si(i);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=i.trim();!s||li.test(s)||n.push({kind:"body",text:i})}return n}function ns(e){if(!e)return[];const n=sn(e);if(n==="unknown")return ao(e);const i=[];for(const{heading:r,body:s}of kc(e)){r&&i.push(r);const l=Qr(s);if(l.length!==0){if(ts(s)){i.push(...ao(s));continue}if(n==="record"){const p=l.join(" ");p&&i.push({kind:"body",text:p})}else for(const p of l){const d=es(p);d.length&&i.push({kind:"body",text:d.join(" ")})}}}return i}const is=e=>e;function os(e,n=is){if(e.indexOf("《")<0)return n(e);const i=[],r=/《([^《》\n]+)》/g;let s=0,l=0,p;for(;p=r.exec(e);)p.index>s&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s,p.index))},l++)),i.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(p[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=p.index+p[0].length;return s===0?n(e):(s<e.length&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),i)}function ai(e,n={}){const i=n.renderText??is,r=n.properNames?l=>os(l,i):i,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return ze(e,r,s)}function co(e,n,i){return e.indexOf("**")<0?n(e):e.split(/(\*\*[^*]+\*\*)/g).map((s,l)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?t.jsx("strong",{children:n(s.slice(2,-2))},`${i}-${l}`):t.jsx(f.Fragment,{children:n(s)},`${i}-${l}`))}const gn=/^(#{1,6})\s+(.*)$/,Sc=/^\s*<!--.*-->\s*$/;function rs(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
522
- `)?"":n)}function hn(e){return e<=1?"h2":e===2?"h3":"h4"}function ln(e){return e?sn(rs(e))!=="unknown":!1}function po({text:e,mode:n,inline:i,dropTitle:r}){const s=rs(e),l=(c,a,u)=>!!r&&u<=1&&c<=2&&a.trim()===r.trim();if(n==="paragraph"&&sn(s)!=="unknown"){const c=ns(s);return t.jsx(t.Fragment,{children:c.map((a,u)=>{if(a.kind==="heading"){if(l(a.level??1,a.text,u))return null;const x=hn(a.level??1);return t.jsx(x,{children:i(a.text)},u)}return t.jsx("p",{children:co(a.text,i,u)},u)})})}const p=s.split(`
523
- `);let d=0;return t.jsx(t.Fragment,{children:p.map((c,a)=>{const u=c.match(gn);if(u){const g=d++;if(l(u[1].length,u[2],g))return null;const h=hn(u[1].length);return t.jsx(h,{children:i(u[2])},a)}if(!c.trim())return a>=2&&!!p[a-1].trim()&&!!p[a-2].trim()&&!gn.test(p[a-1])&&!gn.test(p[a-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},a):null;if(Sc.test(c))return null;if(d++,/^\*\*[^*]+\*\*\s*$/.test(c.trim())){const g=hn(3);return t.jsx(g,{children:i(c.trim().slice(2,-2))},a)}return t.jsx("p",{children:co(c,i,a)},a)})})}function wc(e){const{convert:n}=Y();return f.useMemo(()=>e?n(e):"",[e,n])}function ci({text:e,mode:n,tables:i=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:p}){const d=wc(e),{convert:c}=Y(),a=g=>ai(g,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,x=p?c(p):void 0;return!i||d.indexOf(":::")<0?t.jsx(po,{text:d,mode:n,inline:a,dropTitle:x}):t.jsx(t.Fragment,{children:oi(d).map((g,h)=>g.type==="table"?t.jsx(ri,{table:g.table,opts:u},h):t.jsx(po,{text:g.text,mode:n,inline:a,dropTitle:h===0?x:void 0},h))})}function ss(e,n){const[i,r]=f.useState(null),[s,l]=f.useState(!1),p=f.useRef(0);return f.useEffect(()=>{const d=++p.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(a=>{d===p.current&&r(a??null)}).catch(()=>{d===p.current&&r(null)}).finally(()=>{d===p.current&&l(!1)})},[e,n]),{images:i,loading:s}}const uo={A:"fine",B:"rough",C:"rough",D:"ocr"};function _c(e){return typeof e!="string"?null:e in Sn?e:e in uo?uo[e]:null}const $c={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},zc={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function Oe(e){return typeof e!="string"?"":$c[e]??zc[e]??e}const Cc=["〇","一","二","三","四","五","六","七","八","九"],xo=["","十","百","千"],Ic=["","萬","億"];function di(e){if(e===0)return"〇";if(e<0)return`負${di(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(Tc(s,r>0)+Ic[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Tc(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 p=i[l],d=i.length-1-l;p===0?s&&!s.endsWith("〇")&&(s+="〇"):p===1&&d===1&&l===0&&!n?s+=xo[d]:s+=Cc[p]+xo[d]}return s.replace(/〇$/,"")}let Et=null,Ut=null;const Jt=new Set;function Rc(){return Et?Promise.resolve():Ut||(Ut=import("opencc-js/t2cn").then(e=>{Et=e.Converter({from:"tw",to:"cn"}),Jt.forEach(n=>n())}).catch(()=>{Et=e=>e,Jt.forEach(e=>e())}),Ut)}const Ec=e=>e;function it(){const[,e]=f.useState(0);return f.useEffect(()=>{if(Et)return;const n=()=>e(i=>i+1);return Jt.add(n),Rc(),()=>{Jt.delete(n)}},[]),Et??Ec}function gt(e,n){return n(e).toLowerCase()}const Lc=o("highlight-bg");function Ft(e,n,i){if(!n)return e;const r=gt(n,i);if(!r)return e;const s=gt(e,i);if(s.length!==e.length)return e;const l=[];let p=0,d=0;for(;p<e.length;){const c=s.indexOf(r,p);if(c===-1){l.push(e.slice(p));break}c>p&&l.push(e.slice(p,c)),l.push(t.jsx("mark",{style:{background:Lc,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},d++)),p=c+r.length}return t.jsx(t.Fragment,{children:l})}function pi(e,n,i,r){if(!n)return!0;const s=gt(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(p=>typeof p=="string"&&gt(p,r).includes(s))}function Bc(e,n,i){return n?gt(e,i).includes(gt(n,i)):!0}const ui={类:o("section-lei"),书:o("section-shu"),序:o("section-xu"),结语:o("section-jieyu"),注释:o("section-zhushi")},Nc={考证:o("section-kaozhen")};function Wc(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 Ac(e,n){const i=[],r=p=>{var d;i.push(...p.files),(d=p.children)==null||d.forEach(r)};if(r(e),i.length===0)return;const s=i.map(p=>n[p]);if(s.every(p=>p===void 0))return;if(s.some(p=>p==="loading"))return"loading";let l=0;for(const p of s)typeof p=="number"&&(l+=p);return l}const Mc={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function xi({enabled:e,expanded:n,onClick:i,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...Mc,...r},children:s}):t.jsx("span",{style:r,children:s})}function Fc({type:e}){const n=Oe(e),i=ui[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 Pc({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=Y(),s=je(),l=it(),p=k=>k?ze(r(k),m=>i?Ft(m,i,l):m):"",[d,c]=f.useState(!1),a=!!e.summary,u=!!e.comment,x=!!e.additional_comment,g=!!(e.content&&e.content.length>60),h=a||u||x||g;f.useEffect(()=>{i&&c(!0)},[i]);const y=!d&&g?Nr(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:()=>h&&c(!d),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:h?"pointer":"default",userSelect:"none",background:o("input-bg")},children:[t.jsxs(xi,{enabled:h,expanded:d,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[h&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:d?"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:["《",p(e.book_title),"》"]}):p(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[di(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:p(e.author_info||e.author)})]}),!d&&y&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:p(y)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:p(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:"→作品"})]}),d&&h&&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:p(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:p(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:p(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:p(e.additional_comment)})]}),g&&!a&&!u&&!x&&t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:p(e.content)})]})]})}function Oc({section:e,highlightQuery:n=""}){const{convert:i}=Y(),r=it(),s=c=>c?ze(i(c),a=>n?Ft(a,n,r):a):"",[l,p]=f.useState(!1),d=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(xi,{enabled:d,expanded:l,onClick:()=>p(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:d?"pointer":"default",userSelect:"none"},children:[t.jsx(Fc,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:s(e.title)}),d&&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&&d&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${ui[Oe(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 Dc=100;function fi(e){return Oe(e.type)!=="page_header"?!1:(e.content||"").length>=Dc}function Hc({section:e,highlightQuery:n=""}){const{convert:i}=Y(),r=it();if(Oe(e.type)==="page_header"&&!fi(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
524
- `)),l=ze(s,a=>n?Ft(a,n,r):a),p=Oe(e.type),d=ui[p]||o("desc-fg"),c=p==="序"||p==="结语"||p==="注释";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 ${d}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:d,marginRight:"8px",padding:"1px 5px",border:`1px solid ${d}40`,borderRadius:"2px",background:`${d}08`,verticalAlign:"middle"},children:p}),l]})}function Gc(e,n,i){const[r,s]=f.useState({});return f.useEffect(()=>{var a;if(!n||e.length===0)return;let l=!1;const p=e.filter(u=>{var x;return!((x=i==null?void 0:i.current)!=null&&x.has(u))}),d={};for(const u of e)(a=i==null?void 0:i.current)!=null&&a.has(u)&&(d[u]=i.current.get(u));if(Object.keys(d).length>0&&s(d),p.length===0)return;const c=async u=>{var x;try{if(n.getEntry){const m=await n.getEntry(u);if(m)return{title:m.title,author:m.author}}const g=await n.getItem(u);if(!g)return null;const h=g.title||u,y=g.authors,k=(x=y==null?void 0:y[0])==null?void 0:x.name;return{title:h,author:k}}catch{return null}};return Promise.all(p.map(async u=>{var g;const x=await c(u);return(g=i==null?void 0:i.current)==null||g.set(u,x),[u,x]})).then(u=>{l||s(x=>{const g={...x};for(const[h,y]of u)g[h]=y;return g})}),()=>{l=!0}},[e.join(","),n]),r}function Uc({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=Y(),p=je(),d=it(),c=b=>b?ze(l(b),j=>s?Ft(j,s,d):j):"",[a,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const x=Oe(e.type),g=Nc[x]||o("desc-fg"),h=!!e.content,y=e.work_ids||[],k=y.length>1,m=Gc(k?y:[],i,r),v=h&&!a&&e.content.length>80?Nr(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${o("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>h&&u(!a),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:h?"pointer":"default",userSelect:"none"},children:[t.jsxs(xi,{enabled:h,expanded:a,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[h&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:a?"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)}),!a&&v&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:c(v)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[y.length===1&&n&&t.jsx("a",{href:p(y[0]),onClick:b=>{b.metaKey||b.ctrlKey||(b.preventDefault(),b.stopPropagation(),n(y[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:[y.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:g,border:`1px solid ${g}40`,borderRadius:"2px",background:`${g}08`},children:x})]})]}),k&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:y.map(b=>{const j=m[b],$=j?`${l(j.title)}${j.author?`(${l(j.author)})`:""}`:b.slice(0,8)+"…";return t.jsxs("a",{href:p(b),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(b))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:b,children:["→",$]},b)})}),a&&h&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}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 Vc({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=it(),p=n.trim(),d=f.useMemo(()=>p?e.sections.filter(c=>pi(c,p,!0,l)):e.sections,[e.sections,p,l]);return t.jsxs("div",{children:[t.jsx("div",{children:d.map((c,a)=>t.jsx(Uc,{section:c,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:p},a))}),d.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Yc({sections:e,onNavigate:n,inline:i}){const r=je(),{convert:s}=Y();return t.jsx(t.Fragment,{children:e.map((l,p)=>{const d=Oe(l.type);if(d==="page_header"&&!fi(l))return null;if(d==="类")return t.jsxs(f.Fragment,{children:[t.jsx("h2",{children:i(s(l.title))}),l.content&&t.jsx("p",{children:i(s(l.content))})]},p);if(d==="书"||d==="诗"||d==="考证"||d==="注释"){const c=l.book_title?`《${l.book_title}》${l.n_juan!=null?di(l.n_juan)+"卷":""}`:l.title,a=i(s(c));return t.jsxs("section",{className:"bim-rd-entry",children:[t.jsx("h3",{children:l.work_id&&n?t.jsx("a",{href:r(l.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),n(l.work_id))},title:"查看作品",children:a}):a}),l.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(l.author_info))}),l.content&&l.content.split(/\n+/).map((u,x)=>t.jsx("p",{children:i(s(u))},x)),l.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(l.summary))]}),l.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(l.comment))]}),l.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(l.additional_comment))]})]},p)}return l.content?t.jsx("p",{children:i(s(l.content))},p):null})})}function Kc(e){return e.some(n=>{const i=Oe(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&fi(n)})}function qc({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:p,workLabelCache:d,prefs:c}){var W;const{convert:a}=Y(),u=it(),[x,g]=f.useState("text"),h=s.trim(),y=(r==null?void 0:r.type)==="kaozhen",k=f.useCallback(T=>h?Ft(T,h,u):T,[h,u]),m=T=>ai(T,{renderText:k,properNames:c.properNames}),v=f.useMemo(()=>h?e.sections.filter(T=>pi(T,h,y,u)):e.sections,[e.sections,h,y,u]),b=(T,R)=>R.filter(N=>Oe(N.type)===T).length,j=b("书",e.sections),$=b("诗",e.sections),S=b("考证",e.sections);let _="";y?_=h?`${b("考证",v)} / ${S} ${a("條")}`:`${S} ${a("條")}`:$>0?_=h?`${b("诗",v)} / ${$} 首`:`${$} 首`:j>0&&(_=h?`${b("书",v)} / ${j} ${a("部書")}`:`${j} ${a("部書")}`);const w=r!=null&&r.text_quality?_c(r.text_quality.grade):null,z=[];i&&z.push(i),_&&z.push(_),y&&(r!=null&&r.target_source)&&z.push(t.jsxs(t.Fragment,{children:[a("考證對象")," ",a(r.target_source)]})),w&&z.push(t.jsx("span",{title:nl[w],children:(W=r==null?void 0:r.text_quality)!=null&&W.source_note?t.jsxs(t.Fragment,{children:["底本 ",a(r.text_quality.source_note),"(",a(Sn[w]),")"]}):t.jsxs(t.Fragment,{children:[a("文本質量")," ",a(Sn[w])]})})),e.source_url&&z.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:a("原文來源")}));const B=!y&&Kc(e.sections),L=!!n&&(!B||c.readingMode==="paragraph"&&ln(n)),C=!y&&(B||!!n),A=y||!C?"entries":x;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:a(e.title)}),z.length>0&&t.jsx("p",{className:"bim-rd-meta",children:z.map((T,R)=>t.jsxs(f.Fragment,{children:[R>0&&t.jsx("span",{className:"bim-rd-dot"}),T]},R))}),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":A==="text",onClick:()=>g("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":A==="entries",onClick:()=>g("entries"),children:a("條目")})]})]}),A==="text"&&t.jsx("article",{className:"bim-rd-prose",children:L?t.jsx(ci,{text:n,mode:c.readingMode,properNames:c.properNames,renderText:k,dropTitle:e.title}):t.jsx(Yc,{sections:e.sections,onNavigate:l,inline:m})}),A==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:y?t.jsx(Vc,{juan:e,searchQuery:s,onNavigate:l,transport:p,workLabelCache:d}):t.jsxs(t.Fragment,{children:[v.map((T,R)=>{const N=Oe(T.type);return N==="书"||N==="诗"||N==="考证"?t.jsx(Pc,{section:T,onNavigate:l,highlightQuery:h},R):N==="类"?t.jsx(Oc,{section:T,highlightQuery:h},R):t.jsx(Hc,{section:T,highlightQuery:h},R)}),v.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function as(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 Jc(e){const n=as(e);return n.length>0?n[0]:null}function Zc(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:p,query:d,isKaozhen:c}=e,a=it(),u=f.useRef(new Map),[x,g]=f.useState({}),[h,y]=f.useState({}),k=f.useCallback((v,b)=>{const j=b==null?void 0:b.title;j&&y($=>$[v]===j?$:{...$,[v]:j})},[]);f.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:p}),k(s,l))},[s,l,p,k]),f.useEffect(()=>{u.current.clear(),g({}),y({})},[n]);const m=f.useCallback((v,b)=>{let j=0;if(v.juan)for(const $ of v.juan.sections)pi($,b,c,a)&&j++;return j===0&&v.rawText&&Bc(v.rawText,b,a)&&(j=1),j},[c,a]);return f.useEffect(()=>{const v=d.trim();if(!v){g({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let b=!1;const j={},$=[];for(const B of r){const L=u.current.get(B);L?j[B]=m(L,v):(j[B]="loading",$.push(B))}g(j);const S=8;let _=0;const w=async()=>{var B;for(;_<$.length;){if(b)return;const L=_++,C=$[L];try{const[A,W]=await Promise.all([i.getCollatedJuan(n,C),((B=i.getCollatedJuanText)==null?void 0:B.call(i,n,C))??Promise.resolve(null)]),T={juan:A,rawText:W};if(u.current.set(C,T),k(C,A),b)return;g(R=>({...R,[C]:m(T,v)}))}catch{if(b)return;g(A=>({...A,[C]:0}))}}},z=Array.from({length:Math.min(S,$.length)},()=>w());return Promise.all(z),()=>{b=!0}},[d,n,i,r.join(","),m,a,k]),{matchStates:x,titles:h}}const gi=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:p,style:d,title:c,subtitle:a,resolveImages:u,renderImageOverlay:x,imagePanel:g,allowVertical:h})=>{const[y,k]=f.useState(null),[m,v]=f.useState(!1),[b,j]=f.useState(null),[$,S]=f.useState(null),[_,w]=f.useState(null),[z,B]=f.useState(!1),[L,C]=f.useState(null),[A,W]=f.useState(""),T=f.useRef(new Map),R=f.useRef(0),N=s??$,O=f.useCallback(G=>{S(G),l==null||l(G)},[l]),E=e||y;f.useEffect(()=>{e&&(v(!1),j(null))},[e]),f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let G=!1;return v(!0),j(null),i.getCollatedEditionIndex(n).then(ee=>{G||(ee?k(ee):j("未找到整理本数据"))}).catch(ee=>{G||j(ee instanceof Error?ee.message:"加载失败")}).finally(()=>{G||v(!1)}),()=>{G=!0}},[e,n,i]),f.useEffect(()=>{if(E&&!N){const G=Jc(E);G&&O(G)}},[E,N,O]);const X=n||(E==null?void 0:E.work_id),I=f.useCallback(async G=>{var P;if(!X||!(i!=null&&i.getCollatedJuan))return;const ee=++R.current;B(!0),w(null),C(null);try{const[q,Z]=await Promise.all([i.getCollatedJuan(X,G),((P=i.getCollatedJuanText)==null?void 0:P.call(i,X,G))??Promise.resolve(null)]);if(ee!==R.current)return;w(q),C(Z)}catch{if(ee!==R.current)return;w(null),C(null)}finally{ee===R.current&&B(!1)}},[X,i]);f.useEffect(()=>{N&&I(N)},[N,I]);const M=G=>{O(G)};if(m)return t.jsx("div",{className:p,style:{...d,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(b)return t.jsx("div",{className:p,style:{...d,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:b});if(!E)return null;const K=E.type==="kaozhen",V=as(E);return t.jsx(Qc,{className:p,style:d,index:E,allFiles:V,isKaozhen:K,effectiveWorkId:X,transport:i,activeFile:N,handleSelectFile:M,juanData:_,juanRawText:L,juanLoading:z,searchQuery:A,setSearchQuery:W,onNavigate:r,workLabelCacheRef:T,reader:{title:c,subtitle:a,resolveImages:u,renderImageOverlay:x,imagePanel:g,allowVertical:h}})};function cs(e,n,i,r){var a,u,x,g;const s=(u=(a=n.juan_metadata)==null?void 0:a[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:Wc(e)),d=((g=(x=n.files)==null?void 0:x.find(h=>h.filename===e))==null?void 0:g.title)??i[e];if(!d)return{position:l,label:l};const c=r(d);return{position:l,label:l===d||l===c?c:`${l} ${c}`}}function Xc(e,n,i,r,s){const l=c=>c==="loading"?"…":typeof c=="number"&&c>0?c:void 0,p=(c,a)=>({key:c,label:a??cs(c,e,r,s).label,hint:l(i[c]),disabled:i[c]===0}),d=(c,a)=>{var x;if(c.files.length===1&&!((x=c.children)!=null&&x.length))return p(c.files[0],s(c.label));const u=Ac(c,i);return{key:`group:${a}`,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(g=>p(g)),...(c.children??[]).map((g,h)=>d(g,`${a}.${h}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((c,a)=>d(c,`${a}`)):n.map(c=>p(c))}const Qc=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:p,activeFile:d,handleSelectFile:c,juanData:a,juanRawText:u,juanLoading:x,searchQuery:g,setSearchQuery:h,onNavigate:y,workLabelCacheRef:k,reader:m})=>{const{convert:v}=Y(),[b,j]=ni(),{matchStates:$,titles:S}=Zc({workId:l,transport:p,files:r,activeFile:d,activeJuan:a,activeRawText:u,query:g,isKaozhen:s}),_=ss(m.resolveImages,d),w=f.useMemo(()=>Xc(i,r,$,S,v),[i,r,$,S,v]),z=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:g,onChange:C=>h(C.target.value)}),B=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(C=>C.vol_label)?"冊":"卷",L=d?cs(d,i,S,v).position:void 0;return t.jsxs(ii,{className:e,style:n,title:m.title??(i.title?v(i.title):void 0),subtitle:m.subtitle??v(s?"考證":"整理本"),toc:w,tocCaption:`目录 · ${r.length} ${v(B)}`,tocHeader:z,activeKey:d,onSelect:c,images:_.images,imagesLoading:_.loading,renderImageOverlay:m.renderImageOverlay,imagePanel:m.imagePanel,prefs:b,onPrefsChange:j,paragraphToggle:!s&&ln(u),allowVertical:m.allowVertical,children:[x?t.jsx(nt,{}):a?t.jsx(qc,{juan:a,rawText:u,positionLabel:L,index:i,searchQuery:g,onNavigate:y,transport:p,workLabelCache:k,prefs:b},d??""):d?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,i.references&&i.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:v("參考文獻")}),t.jsx("ol",{children:i.references.map((C,A)=>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]})]},A))})]})]})},ed={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},td={label:"其他",color:o("desc-fg")},nd={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")}},id={label:"待处理",color:o("warning")};function od(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 rd(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 hi=({items:e,loading:n})=>{const i=je();return n?t.jsx(nt,{}):e.length===0?t.jsx("div",{style:sd,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=ed[r.type]||td,l=nd[r.status]||id,p=typeof window<"u"&&rd(r.pageUrl,window.location.href);return t.jsxs("div",{style:ld,children:[t.jsxs("div",{style:ad,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...fo,background:s.color},children:s.label}),t.jsx("span",{style:{...fo,background:l.color},children:l.label})]}),t.jsx("span",{style:cd,children:od(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:dd,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:mn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(p?t.jsx("a",{href:r.pageUrl,style:mn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:mn,children:r.pageUrl}))]}),t.jsx("div",{style:pd,children:r.content}),r.reply&&t.jsxs("div",{style:ud,children:[t.jsx("div",{style:xd,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},sd={textAlign:"center",padding:"40px 0",color:o("desc-fg"),fontSize:"14px"},ld={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"16px"},ad={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},fo={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},cd={fontSize:"12px",color:o("desc-fg")},dd={fontSize:"12px",marginBottom:"6px"},mn={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},pd={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},ud={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},xd={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},Bn=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const p=te(),[d,c]=f.useState(null),[a,u]=f.useState([]),[x,g]=f.useState("recommend"),[h,y]=f.useState([]),[k,m]=f.useState(!1),v=r??x,b=R=>{g(R),s==null||s(R)},[j,$]=f.useState(!0),[S,_]=f.useState(null),[w,z]=f.useState(null),[B,L]=f.useState(null);f.useEffect(()=>{let R=!1;if(e.getCounts)return e.getCounts().then(N=>{R||c({works:N.works,books:N.books,collections:N.collections})}).catch(()=>{}),()=>{R=!0}},[e]),f.useEffect(()=>{let R=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const O=await e.getRecommended();if(O!=null&&O.groups)return O.groups.flatMap(E=>E.items.map(X=>({...X,group:E.name})))}catch{}return[]})().then(async O=>{if(R)return;const E=O.filter(I=>I.id);if(E.length===0){$(!1);return}const X=await Promise.all(E.map(async I=>{if(I.type)return{id:I.id,title:I.title,type:I.type,author:I.author,dynasty:I.dynasty,role:I.role,edition:I.edition,has_text:I.has_text,has_image:I.has_image,has_collated:I.has_collated,subtype:I.subtype,primary_name:I.primary_name,group:I.group,fallbackDescription:I.description};try{let M=null;if(e.getEntry)M=await e.getEntry(I.id);else{const K=await e.getItem(I.id);K&&(M={id:I.id,title:K.title||I.id,type:K.type||"work"})}if(M)return{...M,group:I.group,fallbackDescription:I.description}}catch{}return{id:I.id,title:I.title,type:ae.extractType(I.id),group:I.group,fallbackDescription:I.description}}));R||(u(X.filter(I=>I!==null)),$(!1))}),()=>{R=!0}},[e,i]);const C=f.useRef(!1),A=f.useRef(!1),W=f.useRef(!1);f.useEffect(()=>{if(v!=="catalog"||C.current)return;const R=e.getCatalogProgress??e.getResourceProgress;if(!R)return;C.current=!0;let N=!1;return R.call(e).then(O=>{N||_(O)}).catch(()=>{C.current=!1}),()=>{N=!0}},[e,v]),f.useEffect(()=>{if(v!=="collection"||A.current||!e.getCollectionProgress)return;A.current=!0;let R=!1;return e.getCollectionProgress().then(N=>{R||z(N)}).catch(()=>{A.current=!1}),()=>{R=!0}},[e,v]),f.useEffect(()=>{if(v!=="site"||W.current||!e.getSiteProgress)return;W.current=!0;let R=!1;return e.getSiteProgress().then(N=>{R||L(N)}).catch(()=>{W.current=!1}),()=>{R=!0}},[e,v]),f.useEffect(()=>{if(!l||v!=="feedback")return;let R=!1;return m(!0),fetch(l).then(N=>N.json()).then(N=>{!R&&N.success&&y(N.items||[])}).catch(()=>{}).finally(()=>{R||m(!1)}),()=>{R=!0}},[l,v]);const T=R=>{switch(R){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(_t,{label:p.home.recommendTab,active:v==="recommend",onClick:()=>b("recommend")}),t.jsx(_t,{label:p.home.catalogTab,active:v==="catalog",onClick:()=>b("catalog")}),t.jsx(_t,{label:p.home.collectionTab,active:v==="collection",onClick:()=>b("collection")}),t.jsx(_t,{label:p.home.siteTab,active:v==="site",onClick:()=>b("site")}),l&&t.jsx(_t,{label:p.home.feedbackTab,active:v==="feedback",onClick:()=>b("feedback")})]}),v==="recommend"&&t.jsx(fd,{recommended:a,loading:j,onNavigate:n,getIcon:T,t:p}),v==="catalog"&&t.jsx(go,{progress:S,t:p,onNavigate:n}),v==="collection"&&t.jsx(go,{progress:w,t:p,onNavigate:n}),v==="site"&&t.jsx(hd,{progress:B,t:p,totalWorks:(d==null?void 0:d.works)??0}),v==="feedback"&&l&&t.jsx(hi,{items:h,loading:k})]})})},_t=({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}),fd=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=je();if(n)return t.jsx(nt,{});if(e.length===0)return null;const p=new Map;for(const d of e){const c=d.group||s.home.recommendedBrowse;p.has(c)||p.set(c,[]),p.get(c).push(d)}return t.jsx(t.Fragment,{children:Array.from(p.entries()).map(([d,c])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:d}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(a=>{const u=a.dynasty||a.author?`${a.dynasty?`〔${a.dynasty}〕`:""}${a.author||""}`:a.fallbackDescription;return t.jsxs("a",{href:l(a.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),i==null||i(a.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(a.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[a.title,a.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:a.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},a.id)})})]},d))})},go=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(nt,{});const r=[...e.resources].sort((d,c)=>d.priority-c.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},p={in_progress:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(d=>{const c=r.filter(a=>a.status===d);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:p[d]}}),l[d]," (",c.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(a=>t.jsx(gd,{item:a,t:n,statusColor:p[d],onNavigate:i},a.id))})]},d)})})},gd=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=je(),l=e.total>0?Math.round(e.imported/e.total*100):0,p=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 d=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:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:a=>a.currentTarget.style.borderBottomStyle="solid",onMouseLeave:a=>a.currentTarget.style.borderBottomStyle="dashed",children:d}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:d}):d})()}),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:p})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Lt(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})]})},hd=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(nt,{});const r=[...e.resources].sort((c,a)=>c.priority-a.priority),s=r.filter(c=>c.imported>0),l=r.filter(c=>c.imported===0),p=s.reduce((c,a)=>Math.max(c,a.imported),0),d=i>0?Math.round(p/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:p.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",d,"%)"]}),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(ho,{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(ho,{item:c,t:n,totalWorks:i},c.id))})]})]})},ho=({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 md(){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 bd=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var N;const l=te(),{convert:p}=Y(),d=md(),[c,a]=f.useState(null),[u,x]=f.useState(null),[g,h]=f.useState(!1),[y,k]=f.useState("detail"),[m,v]=f.useState([]),[b,j]=f.useState(!1),[$,S]=f.useState(null),[_,w]=f.useState(!1),z=f.useCallback(async O=>{if(!e.getCollatedEditionIndex){S(null);return}w(!0);try{const E=await e.getCollatedEditionIndex(O);S(E)}catch{S(null)}finally{w(!1)}},[e]),B=f.useCallback(async O=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){v([]);return}j(!0);try{if(e.getCollectionCatalogs){const E=await e.getCollectionCatalogs(O);v(E||[])}else if(e.getCollectionCatalog){const E=await e.getCollectionCatalog(O);v(E?[{resource_id:"",data:E}]:[])}}catch{v([])}finally{j(!1)}},[e]),L=f.useCallback(async O=>{if(i){i(O);return}a(O),x(null),v([]),S(null),k("detail"),h(!0);try{const E=await e.getItem(O.id);E&&(x(E),E.type==="collection"?B(O.id):E.type==="work"&&E.has_collated&&z(O.id))}catch(E){console.error("加载详情失败:",E)}finally{h(!1)}},[e,i,B,z]),C=f.useCallback(async O=>{x(null),v([]),S(null),k("detail"),h(!0);try{const E=await e.getItem(O);E&&(x(E),a({id:O,title:E.title||O,type:E.type||"book"}),E.type==="collection"?B(O):E.type==="work"&&E.has_collated&&z(O))}catch(E){console.error("导航失败:",E)}finally{h(!1)}},[e,B,z]),A=(u==null?void 0:u.type)==="collection"&&(m.length>0||b)||(u==null?void 0:u.type)==="work"&&($||_),W=d&&(g||u),T=f.useCallback(()=>{a(null),x(null),v([]),S(null),k("detail")},[]),R=t.jsx(t.Fragment,{children:g?t.jsx(nt,{}):u?t.jsxs(t.Fragment,{children:[(A||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${o("widget-border")}`,padding:d?"0 12px":"0 48px",background:o("input-bg"),flexShrink:0,overflowX:d?"auto":void 0},children:[A&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>k("detail"),style:Vt(y==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&b&&m.length===0&&t.jsxs("button",{onClick:()=>{},style:Vt(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&m.map(O=>t.jsx("button",{onClick:()=>k(`catalog:${O.resource_id}`),style:Vt(y===`catalog:${O.resource_id}`),children:O.short_name?`${p(O.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},O.resource_id)),u.type==="work"&&($||_)&&t.jsxs("button",{onClick:()=>k("collated"),style:Vt(y==="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:d?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:y==="detail"?t.jsx(Vn,{data:u,transport:e,onNavigate:C}):y.startsWith("catalog:")?t.jsx(Yn,{data:(N=m.find(O=>`catalog:${O.resource_id}`===y))==null?void 0:N.data,onNavigate:C}):y==="collated"?t.jsx(gi,{index:$||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(Bn,{transport:e,onNavigate:C,recommendedIds:r})});return d?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:W?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:T,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:R})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(_n,{transport:e,onEntryClick:L,hideModeIndicator:n}),!u&&t.jsx(Bn,{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(_n,{transport:e,onEntryClick:L,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:R})]})};function Vt(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 Ye(e){return e.replace(/\.md$/,"")}function yd(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 bo={padding:24,color:o("desc-fg")},Nn=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:p,onVersionChange:d,title:c,subtitle:a,resolveImages:u,renderImageOverlay:x,imagePanel:g,allowVertical:h,className:y,style:k})=>{const[m,v]=f.useState(e??null),[b,j]=f.useState(!1),[$,S]=f.useState(null),_=r!==void 0?r:$,w=f.useCallback(M=>{s?s(M):S(M)},[s]),[z,B]=f.useState(null),[L,C]=f.useState(!1);f.useEffect(()=>{e&&v(e)},[e]),f.useEffect(()=>{if(e)return;v(null),j(!1);const M=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!M){j(!0);return}let K=!1;return Promise.resolve().then(M).then(V=>{K||(V?v(V):j(!0))}).catch(()=>{K||j(!0)}),()=>{K=!0}},[n,i,e,l]),f.useEffect(()=>{if(!m||m.chapters.length===0)return;const M=Ye(m.chapters[0].file);if(!_){w(M);return}const K=Ye(_);m.chapters.some(G=>Ye(G.file)===K)||w(M)},[m,_,w]);const A=f.useMemo(()=>{if(!m||!_)return null;const M=Ye(_);return m.chapters.find(K=>Ye(K.file)===M)??null},[m,_]);f.useEffect(()=>{if(!n||!A)return;const M=l!==void 0?i.getWorkFullTextChapter?V=>i.getWorkFullTextChapter(n,l,V):null:i.getBookFullTextChapter?V=>i.getBookFullTextChapter(n,V):null;if(!M)return;let K=!1;return C(!0),B(null),Promise.resolve(A.file).then(M).then(V=>{K||B(V)}).catch(()=>{K||B(null)}).finally(()=>{K||C(!1)}),()=>{K=!0}},[n,A,i,l]);const W=ss(u,A?Ye(A.file):null),[T,R]=ni(),{convert:N}=Y(),O=p&&p.length>1&&d?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:M=>d(M.target.value),children:p.map(M=>t.jsx("option",{value:M.key,children:yd(M)},M.key))})]}):null;if(!m)return t.jsxs("div",{style:bo,children:[O&&t.jsx("div",{style:{marginBottom:12},children:O}),b?"无法加载全文目录":"加载全文目录…"]});if(m.chapters.length===0)return t.jsxs("div",{style:bo,children:[O&&t.jsx("div",{style:{marginBottom:12},children:O}),"全文目录为空"]});const E=m.chapters.map(M=>({key:Ye(M.file),label:N(M.title)})),X=qr(m)||Cn(m),I=z?z.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(ii,{title:c??N(m.version_label),subtitle:a??"全文",toc:E,tocCaption:`目录 · ${m.chapters.length} ${m.chapters.length>1?"卷":"篇"}`,activeKey:_?Ye(_):null,onSelect:w,images:W.images,imagesLoading:W.loading,renderImageOverlay:x,imagePanel:g,prefs:T,onPrefsChange:R,paragraphToggle:ln(I),allowVertical:h,className:y,style:k,children:[A&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:N(A.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:m.source.url,target:"_blank",rel:"noreferrer",children:N(m.source.name)}),m.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),m.source.license]}),O&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),O]})]})]}),L&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!L&&I!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(ci,{text:I,mode:T.readingMode,tables:X,gujiMarkdown:Cn(m),properNames:T.properNames})}),!L&&!z&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},jd=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=te(),{convert:l}=Y(),[p,d]=f.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[c,a]=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(x=>t.jsx(vd,{division:x,expanded:p===x.name,onToggle:()=>d(p===x.name?null:x.name),expandedCat:c,onCatToggle:g=>a(c===g?null:g),onNavigate:n},x.name))})]})},vd=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:p}=Y(),d=e.categories.reduce((c,a)=>{const u=a.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:p(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg")},children:[e.categories.length," 類 · ",d," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(c=>{const a=`${e.name}/${c.name}`;return t.jsx(kd,{category:c,expanded:r===a,onToggle:()=>s(a),onNavigate:l},c.name)})})]})},kd=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var c,a,u,x;const{convert:s}=Y(),l=((c=e.books)==null?void 0:c.zhulu)||[],p=((a=e.books)==null?void 0:a.cunmu)||[],d=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((x=e.stats)==null?void 0:x.cunmu)||p.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:[d," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||p.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(yo,{label:"著錄",books:l,onNavigate:r}),p.length>0&&t.jsx(yo,{label:"存目",books:p,onNavigate:r})]})]})},yo=({label:e,books:n,onNavigate:i})=>{const{convert:r}=Y(),s=je(),[l,p]=f.useState(n.length<=20),d=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:d.map((c,a)=>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)})]},a))}),!l&&t.jsxs("button",{onClick:()=>p(!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," 條"]})]})},Ee=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=te();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:wd,children:"AI"}),n&&t.jsx("button",{onClick:n,style:Sd,children:l.action.save})]})]}),s]})},Sd={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},wd={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},_e=({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"}})]}),Xe=({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"}})},Zt=({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 _d(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Yt=({value:e,onChange:n,label:i})=>{const[r,s]=f.useState(!1),l=f.useRef(null),p=_d(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&p?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:jo,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:p.name}),t.jsx(Zt,{children:p.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:jo,children:i}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:d=>n(d.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"}})]})},jo={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function $d(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function zd(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const ds=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=te(),[s,l]=f.useState(null),p=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},d=x=>{n(e.filter((g,h)=>h!==x)),s===x&&l(null)},c=(x,g,h)=>{const y=[...e];y[x]={...y[x],[g]:h},n(y)},a=(x,g)=>{const h=[...e];h[x]={...h[x],type:g,id:"",name:""},n(h),g==="bookID"&&i&&i(y=>{const k=[...e];k[x]={...k[x],id:y.id,name:y.title,type:"bookID"},n(k)})},u=x=>{i&&i(g=>{const h=[...e];h[x]={...h[x],id:g.id,name:g.title,type:"bookID"},n(h)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((x,g)=>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===g?null:g),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:o("fg")},children:x.name||`${r.editor.sourcePlaceholder} ${g+1}`}),x.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:$d(x.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:zd(x.type)}),t.jsx("button",{onClick:h=>{h.stopPropagation(),d(g)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===g&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>a(g,"bookID"),style:{...vo,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:()=>a(g,"url"),style:{...vo,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})]})]})]}),x.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:He,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const h=[...e];h[g]={...h[g],type:"",id:"",name:""},n(h)},style:ko,children:r.action.changeType})]}),x.id&&x.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:x.name}),t.jsx("code",{style:{fontSize:"11px",background:o("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),t.jsx("button",{onClick:()=>u(g),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(g),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})]})]})}),x.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:He,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const h=[...e];h[g]={...h[g],type:"",id:"",name:""},n(h)},style:ko,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:x.name,onChange:h=>c(g,"name",h.target.value),placeholder:r.editor.sourceNamePlaceholder,style:st})]}),t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:x.id,onChange:h=>c(g,"id",h.target.value),placeholder:"https://...",style:st})]})]}),x.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:{...He,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:He,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:x.details,onChange:h=>c(g,"details",h.target.value),placeholder:r.editor.detailsPlaceholder,style:st})]}),t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:x.position,onChange:h=>c(g,"position",h.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:He,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:x.version,onChange:h=>c(g,"version",h.target.value),placeholder:"如: v1.0, 2024-01",style:st})]}),t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:x.processor_version,onChange:h=>c(g,"processor_version",h.target.value),placeholder:"如: v0.1",style:st})]})]})]})]})})]},g)),t.jsxs("button",{onClick:p,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})]})]})},He={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"},vo={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"},ko={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function ps(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 us(e){return!e||e.length===0?"":JSON.stringify(e)}const xs=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:p,childWorks:d,childCollections:c,containedBooks:a,siblingBooks:u,onLinkEntity:x,onUnlinkEntity:g,onViewEntity:h,onCreateAndLink:y,onSaveRelations:k})=>{const m=te();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:m.section.relations})]}),k&&t.jsx("button",{onClick:k,style:Cd,children:m.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx($t,{direction:"up",title:m.relation.belongsToWork,entity:l,onView:h,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>y("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),t.jsx($t,{direction:"up",title:m.relation.containedInCollection,entity:p,onView:h,onUnlink:()=>g("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>y("collectionId","collection",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),l&&u&&u.length>0&&t.jsx(lt,{direction:"horizontal",title:`${m.relation.siblingVersions} (${u.length})`,entities:u,onView:h,onAdd:()=>y("siblingBook","book",{workId:l.id}),addLabel:m.relation.addVersionForWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx($t,{direction:"up",title:m.relation.parentWork,entity:r,onView:h,onUnlink:()=>g("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>y("parentWorkId","work"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),d&&d.length>0&&t.jsx(lt,{direction:"down",title:`${m.relation.childWorks} (${d.length})`,entities:d,onView:h,onAdd:()=>y("childWork","work",{parentWorkId:n}),addLabel:m.action.addSubWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),c&&c.length>0&&t.jsx(lt,{direction:"down",title:`${m.relation.collectionImpl} (${c.length})`,entities:c,onView:h,onAdd:()=>y("childCollection","collection",{workId:n}),addLabel:m.action.addCollectionImpl,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),t.jsx(lt,{direction:"down",title:`${m.relation.allVersions} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:h,onAdd:()=>y("childBook","book",{workId:n}),addLabel:m.action.addVersion,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx($t,{direction:"up",title:m.relation.correspondingWork,entity:l,onView:h,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>y("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),t.jsx($t,{direction:"up",title:m.relation.parentCollection,entity:s,onView:h,onUnlink:()=>g("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>y("parentCollectionId","collection"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),t.jsx(lt,{direction:"down",title:`${m.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:h,onAdd:()=>y("childCollection","collection",{parentCollectionId:n}),addLabel:m.action.addSubCollection,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),t.jsx(lt,{direction:"down",title:`${m.relation.containedBooks} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:h,onAdd:()=>y("childBook","book",{collectionId:n}),addLabel:m.action.addBook,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]})]})]})},$t=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:p,linkLabel:d,createLabel:c,notLinkedLabel:a,viewLabel:u,unlinkLabel:x})=>{const g=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),h=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:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:h}),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(So,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(So,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:a}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(Wn,{onClick:l,children:d}),t.jsx(Wn,{onClick:p,primary:!0,children:c})]})]})},lt=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:p,expandMoreLabel:d})=>{const[c,a]=f.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),x=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",g=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:x}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(h=>t.jsxs("div",{onClick:()=>r(h),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(h.type)}),t.jsx("span",{children:h.title})]},h.id)),i.length>5&&!c&&t.jsxs("div",{onClick:()=>a(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:o("link-fg"),cursor:"pointer"},children:[d," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:p}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(Wn,{onClick:s,primary:!0,children:["+ ",l]})})]})},So=({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}),Wn=({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"📚"}}const Cd={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},gs=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:p,onSearch:d,isLoading:c,excludeId:a})=>{const[u,x]=f.useState(""),g=a?p.filter(m=>m.id!==a):p;f.useEffect(()=>{e&&(x(""),d(""))},[e]);const h=m=>{x(m),d(m)};if(!e)return null;const y=n==="work"?"作品":n==="book"?"书籍":"丛编",k=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:Id,children:t.jsxs("div",{style:Td,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:Rd,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:m=>h(m.target.value),placeholder:`搜索${y}名称或 ID...`,autoFocus:!0,style:Ed})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:bn,children:"搜索中..."}):g.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(m=>t.jsxs("div",{onClick:()=>r(m),style:Ld,children:[t.jsx("span",{style:{fontSize:"16px"},children:k}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[m.title,m.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:m.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[m.id,m.author&&` · ${m.author}`,m.dynasty&&` · ${m.dynasty}`]})]})]},m.id))}):u?t.jsxs("div",{style:bn,children:["未找到匹配的",y]}):t.jsxs("div",{style:bn,children:["输入关键词搜索",y]})}),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:Bd,children:["创建新",y,"并关联"]})]})]})})},Id={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Td={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")},Rd={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Ed={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"},Ld={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")},Bd={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},wo={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Nd={work:"📜",book:"📖",collection:"📚",entity:"👤"},hs=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[p,d]=f.useState(""),c=f.useRef(null);f.useEffect(()=>{e&&(d((r==null?void 0:r.title)||""),setTimeout(()=>{var g,h;(g=c.current)==null||g.focus(),(h=c.current)==null||h.select()},100))},[e,r==null?void 0:r.title]);const a=g=>{g.key==="Enter"&&p.trim()?u():g.key==="Escape"&&l()},u=()=>{p.trim()&&s(p.trim(),{...r,title:p.trim()})};if(!e)return null;const x=()=>{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`创建新${wo[n]}`}};return t.jsx("div",{style:Wd,onClick:g=>{g.target===g.currentTarget&&l()},children:t.jsxs("div",{style:Ad,onClick:g=>g.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Nd[n]}),t.jsx("span",{children:x()})]}),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:p,onChange:g=>d(g.target.value),onKeyDown:a,placeholder:`请输入${wo[n]}名称...`,style:Md})]}),((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:Fd,children:"取消"}),t.jsx("button",{onClick:u,disabled:!p.trim(),style:{...Pd,opacity:p.trim()?1:.6,cursor:p.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Wd={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ad={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")},Md={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"},Fd={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Pd={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function Od(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function ms(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Dd(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 bs=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:p,onSelect:d,onCancel:c,onCreate:a,onSearch:u})=>{const[x,g]=f.useState(""),[h,y]=f.useState([]),[k,m]=f.useState(!1),[v,b]=f.useState("recent");f.useEffect(()=>{e&&(g(""),y([]),b(r.length>0?"recent":"search"))},[e,r.length]),f.useEffect(()=>{if(!x.trim()){y([]);return}const z=setTimeout(async()=>{m(!0);try{y(await u(x,i))}catch{y([])}finally{m(!1)}},300);return()=>clearTimeout(z)},[x,i,u]);const j=f.useCallback(z=>{g(z.target.value),z.target.value.trim()&&b("search")},[]),$=f.useCallback(z=>s?z.filter(B=>B.id!==s):z,[s]);if(!e)return null;const S=n||(i==="all"?"选择实体":`选择${ms(i)}`),_=$(r),w=$(h);return t.jsx("div",{style:Gd,children:t.jsxs("div",{style:Ud,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:Vd,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:x,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Yd}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),k&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),_.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs(_o,{active:v==="recent",onClick:()=>b("recent"),children:["最近使用 (",_.length,")"]}),t.jsxs(_o,{active:v==="search",onClick:()=>b("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:v==="recent"&&_.length>0?t.jsx($o,{entities:_,onSelect:d}):x.trim()?k?t.jsx(yn,{message:"搜索中..."}):w.length>0?t.jsx($o,{entities:w,onSelect:d}):t.jsx(yn,{message:"未找到匹配的结果"}):t.jsx(yn,{message:"输入关键词开始搜索"})}),l&&a&&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:a,style:Kd,children:p||"创建新实体"})]})]})})},_o=({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}),$o=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(Hd,{entity:i,onClick:()=>n(i)},i.id))}),Hd=({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:Od(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:Dd(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:ms(e.type)})]})},yn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),Gd={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ud={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")},Vd={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Yd={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"},Kd={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},qd={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},Jd={work:"📜",collection:"📚",book:"📖",entity:"👤"},ys=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:p,onAskAI:d,renderSectionActions:c,onDownloadResource:a,downloadStatuses:u,relations:x,onRelationsChange:g})=>{var ce;const h=te(),[y,k]=f.useState(!1),[m,v]=f.useState("work"),[b,j]=f.useState(""),[$,S]=f.useState(""),[_,w]=f.useState([]),[z,B]=f.useState(!1),[L,C]=f.useState(!1),[A,W]=f.useState("work"),[T,R]=f.useState(""),[N,O]=f.useState(),[E,X]=f.useState(!1),[I,M]=f.useState(null),[K,V]=f.useState([]);f.useRef(null);const G=e.type,ee=G==="work",P=G==="collection",q=G==="book",Z=f.useCallback((F,ie)=>{n({...e,[F]:ie})},[e,n]),U=f.useCallback((F,ie)=>{j(F),v(ie),S(h.editor.selectToLink+h.indexType[ie]),w([]),k(!0)},[h]),se=f.useCallback(F=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,F)},[r,e.id]),de=f.useCallback(F=>{s==null||s(F.id,F.type)},[s]),D=f.useCallback((F,ie,ne)=>{const he={...ne,author:(ne==null?void 0:ne.author)||e.author,dynasty:ne==null?void 0:ne.dynasty};W(ie),R(F),O(he),C(!0)},[e.author]),re=f.useCallback((F,ie)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,T,{type:A,title:F,inheritData:ie}),C(!1)},[r,e.id,T,A]),oe=f.useCallback(F=>{if(!F.trim()){w([]);return}B(!0),r!=null&&r.searchEntities&&r.searchEntities(F,m).then(ie=>{w(ie),B(!1)}).catch(()=>{w([]),B(!1)})},[r,m]),pe=f.useCallback(F=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,b,F.id),k(!1)},[r,e.id,b]),fe=f.useCallback(()=>{i()},[i]),ye=f.useCallback(F=>{M(()=>F),X(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(V).catch(()=>{})},[r]),Ce=f.useCallback((F,ie)=>r!=null&&r.searchEntities?r.searchEntities(F,ie==="all"?void 0:ie):Promise.resolve([]),[r]),Q=f.useCallback(F=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(F),V(ie=>[F,...ie.filter(ne=>ne.id!==F.id)].slice(0,10)),I==null||I(F),X(!1),M(null)},[r,I]);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:Jd[G]}),t.jsx("span",{children:e.title||h.editor.untitled}),t.jsx(Zt,{children:e.id}),t.jsx(Zt,{color:qd[G],children:h.indexType[G]})]})}),t.jsx(Ee,{title:h.section.basicInfo,onSave:i,onAskAI:d?()=>d("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(Yt,{label:ee?h.editor.workTitle:P?h.editor.collectionTitle:h.editor.bookTitle,value:e.title,onChange:F=>Z("title",F)}),q&&t.jsx(Yt,{label:h.editor.belongsToWork,value:e.workName||"",onChange:F=>Z("workName",F)}),t.jsx(_e,{label:h.editor.authorLabel,value:e.author||"",onChange:F=>Z("author",F)}),t.jsx(_e,{label:h.editor.publicationYearLabel,value:e.publicationYear||"",onChange:F=>Z("publicationYear",F)}),(q||P)&&t.jsx(Yt,{label:h.editor.containedIn,value:e.collection||"",onChange:F=>Z("collection",F)}),(q||P)&&t.jsx(_e,{label:h.editor.holderLabel,value:e.holder||"",onChange:F=>Z("holder",F)}),(q||P)&&t.jsx(_e,{label:q?h.editor.pageLabel:h.editor.volumeLabel,value:e.pages||"",onChange:F=>Z("pages",F)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(_e,{label:h.editor.firstImageLabel,value:e.firstImage||"",onChange:F=>Z("firstImage",F)})})]})}),t.jsx(Ee,{title:h.section.description,onSave:i,onAskAI:d?()=>d("介绍"):void 0,children:t.jsx(Xe,{value:e.description||"",onChange:F=>Z("description",F),placeholder:h.editor.descriptionPlaceholder})}),(((ce=e.additional_works)==null?void 0:ce.length)||0)>0&&t.jsx(Ee,{title:h.section.additionalWorks,onSave:i,children:t.jsx(Zd,{items:e.additional_works||[],onChange:F=>Z("additional_works",F)})}),t.jsx(Ee,{title:h.section.indexedBy,onSave:i,onAskAI:d?()=>d("收录于"):void 0,children:t.jsx(Xd,{items:e.indexed_by||[],onChange:F=>Z("indexed_by",F)})}),t.jsx(Ee,{title:h.section.emendatedBy,onSave:i,onAskAI:d?()=>d("考证"):void 0,children:t.jsx(Qd,{items:e.emendated_by||[],onChange:F=>Z("emendated_by",F)})}),t.jsx(Ee,{title:h.section.textResources,onSave:i,onAskAI:d?()=>d("资源"):void 0,children:t.jsx(wn,{items:e.resources||[],onChange:F=>Z("resources",F),onDownload:a,downloadStatuses:u,filterType:"text"})}),t.jsx(Ee,{title:h.section.imageResources,onSave:i,children:t.jsx(wn,{items:e.resources||[],onChange:F=>Z("resources",F),onDownload:a,downloadStatuses:u,filterType:"image"})}),t.jsx(Ee,{title:h.section.sources,onSave:i,onAskAI:d?()=>d("资料来源"):void 0,children:t.jsx(ds,{items:ps(e.sources||""),onChange:F=>Z("sources",us(F)),onOpenEntityPicker:ye})}),(q||P)&&t.jsx(Ee,{title:h.section.provenance,onSave:i,onAskAI:d?()=>d("收藏历史"):void 0,children:t.jsx(Xe,{value:e.provenance||"",onChange:F=>Z("provenance",F),placeholder:h.editor.provenancePlaceholder})}),q&&t.jsx(Ee,{title:h.section.otherEditions,onSave:i,onAskAI:d?()=>d("其他版本"):void 0,children:t.jsx(Xe,{value:e.otherEditions||"",onChange:F=>Z("otherEditions",F),placeholder:h.editor.otherEditionsPlaceholder})}),t.jsx(xs,{entityType:G,entityId:e.id,entityTitle:e.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:U,onUnlinkEntity:se,onViewEntity:de,onCreateAndLink:D,onSaveRelations:fe}),l&&p&&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:h.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"12px"},children:h.editor.dangerZoneDesc}),t.jsx("button",{onClick:p,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("danger")}`,borderRadius:"4px",background:"transparent",color:o("danger"),cursor:"pointer"},children:h.editor.deleteEntity})]}),t.jsx(gs,{isOpen:y,entityType:m,title:$,onSelect:pe,onCancel:()=>k(!1),onCreate:()=>{k(!1),D(b,m)},searchResults:_,onSearch:oe,isLoading:z,excludeId:e.id}),t.jsx(hs,{isOpen:L,entityType:A,relationField:T,inheritData:N,onConfirm:re,onCancel:()=>C(!1)}),t.jsx(bs,{isOpen:E,title:h.action.selectBookOrWork,filterType:"all",recentEntities:K,excludeId:e.id,onSelect:Q,onCancel:()=>{X(!1),M(null)},onSearch:Ce})]})};function Zd({items:e,onChange:n}){const i=te(),r=(p,d,c)=>{const a=e.map((u,x)=>x===p?{...u,[d]:c}:u);n(a)},s=p=>n(e.filter((d,c)=>c!==p)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((p,d)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(_e,{label:i.editor.bookNameLabel,value:p.book_title,onChange:c=>r(d,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(_e,{label:i.label.juanCount,value:p.n_juan!=null?String(p.n_juan):"",onChange:c=>r(d,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(d),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("muted"),marginTop:"18px"},children:"✕"})]},d)),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 js({items:e,onChange:n,showMeta:i,addLabel:r}){const s=te(),[l,p]=f.useState(null),d=(u,x,g)=>{const h=e.map((y,k)=>k===u?{...y,[x]:g||void 0}:y);n(h)},c=u=>{n(e.filter((x,g)=>g!==u)),l===u&&p(null)},a=()=>{n([...e,{source:""}]),p(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,x)=>{const g=l===x;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:g?`color-mix(in srgb, ${o("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>p(g?null:x),children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.2s",transform:g?"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:h=>{h.stopPropagation(),c(x)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${o("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:o("muted")},children:"✕"})]}),!g&&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]}),g&&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(_e,{label:s.label.sourceName,value:u.source,onChange:h=>d(x,"source",h)}),t.jsx(_e,{label:s.label.sourceBid,value:u.source_bid||"",onChange:h=>d(x,"source_bid",h)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(_e,{label:s.label.titleInfo,value:u.title_info||"",onChange:h=>d(x,"title_info",h)}),t.jsx(_e,{label:s.label.authorInfo,value:u.author_info||"",onChange:h=>d(x,"author_info",h)})]}),t.jsx(_e,{label:s.label.edition,value:u.edition||"",onChange:h=>d(x,"edition",h)})]}),t.jsx(Xe,{value:u.summary||"",onChange:h=>d(x,"summary",h),placeholder:s.editor.summaryPlaceholder}),t.jsx(Xe,{value:u.comment||"",onChange:h=>d(x,"comment",h),placeholder:s.editor.commentPlaceholder}),t.jsx(Xe,{value:u.additional_comment||"",onChange:h=>d(x,"additional_comment",h),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),t.jsx("button",{onClick:a,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 Xd({items:e,onChange:n}){const i=te();return t.jsx(js,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Qd({items:e,onChange:n}){const i=te();return t.jsx(js,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function vs(e){var d,c,a,u,x,g,h;const n=((c=(d=e.authors)==null?void 0:d[0])==null?void 0:c.name)||"",i=((a=e.publication_info)==null?void 0:a.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(x=e.page_count)!=null&&x.number?String(e.page_count.number):((g=e.page_count)==null?void 0:g.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",p={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 y=e;if(Array.isArray(y.related_works)){const k=y.related_works.find(m=>m.relation==="part_of");k&&(p.parentWorkId=k.id,p.parentWorkName=k.title)}}if(e.type==="book"){const y=e;p.workId=y.work_id,Array.isArray(y.contained_in)&&y.contained_in.length>0&&(p.collectionId=(h=y.contained_in[0])==null?void 0:h.id)}return p}function ep(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 tp=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:p,onSave:d,onDelete:c,onNavigate:a,renderLink:u,onAskAI:x,renderSectionActions:g,onDownloadResource:h,downloadStatuses:y,relations:k,onRelationsChange:m,headerExtra:v,className:b,style:j}=e;te();const[$,S]=f.useState(s),_=l?s:$;f.useEffect(()=>{s!==$&&S(s)},[s]);const w=f.useCallback(()=>{const T=_==="view"?"edit":"view";l?l(T):S(T)},[_,l]),[z,B]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(T=>{T&&B(T)})},[i,r]);const L=n||z,C=f.useMemo(()=>L?vs(L):null,[L]),A=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,W=t.jsxs(t.Fragment,{children:[A,v]});return!L&&!C?t.jsx(nt,{}):_==="view"?t.jsx(Vn,{data:L,transport:r,onNavigate:a?T=>a(T):void 0,renderLink:u,headerExtra:W,className:b,style:j}):C?t.jsxs("div",{className:b,style:j,children:[W&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:W}),t.jsx(ys,{data:C,onChange:p||(()=>{}),onSave:d||(()=>{}),transport:r,onNavigate:a,showDelete:!!c,onDelete:c,onAskAI:x,renderSectionActions:g,onDownloadResource:h,downloadStatuses:y,relations:k,onRelationsChange:m})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},zo=[{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),[p,d]=f.useState(""),[c,a]=f.useState(""),[u,x]=f.useState("idle"),[g,h]=f.useState(""),y=f.useRef(null);f.useEffect(()=>{e&&(l(null),d(""),a(""),x("idle"),h(""))},[e]),f.useEffect(()=>{s&&setTimeout(()=>{var b;return(b=y.current)==null?void 0:b.focus()},100)},[s]),f.useEffect(()=>{if(u==="success"){const b=setTimeout(n,2e3);return()=>clearTimeout(b)}},[u,n]),f.useEffect(()=>{if(!e)return;const b=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[e,n]);const k=async()=>{if(!(!s||!p.trim())){x("submitting"),h("");try{await i({type:s,content:p.trim(),...c.trim()?{contact:c.trim()}:{}}),x("success")}catch(b){x("error"),h(b instanceof Error?b.message:"提交失败,请稍后重试")}}};if(!e)return null;const m=s&&p.trim()&&u!=="submitting",v=zo.find(b=>b.value===s);return t.jsx("div",{style:np,onClick:b=>{b.target===b.currentTarget&&n()},children:t.jsxs("div",{style:ip,onClick:b=>b.stopPropagation(),children:[t.jsxs("div",{style:op,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:rp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:dp,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:zo.map(b=>t.jsxs("button",{onClick:()=>l(b.value),style:{...sp,...s===b.value?lp:{}},children:[t.jsx("span",{children:b.icon})," ",b.label]},b.value))}),t.jsx("textarea",{ref:y,value:p,onChange:b=>d(b.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...ap,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:c,onChange:b=>a(b.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:up}),t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[p.length," / 2000"]}),u==="error"&&t.jsx("div",{style:pp,children:g}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:k,disabled:!m,style:{...cp,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},np={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:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},op={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},rp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:o("desc-fg"),padding:"4px 8px",borderRadius:"4px"},sp={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"},lp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},ap={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"},cp={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},dp={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},pp={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginBottom:"12px"},up={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"},An="--bim-feedback-fab-offset",Mn=48,xp=16,fp=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,p]=f.useState(!1),d=n.bottom??24;return f.useEffect(()=>{if(r||typeof document>"u")return;const c=document.documentElement;return c.style.setProperty(An,`calc(${d+Mn+xp}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(An)}},[r,d]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>p(!0),style:{...gp,zIndex:s??o("feedback-fab-z"),bottom:`calc(${d}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:()=>p(!1),onSubmit:e,feedbackListUrl:i})]})},gp={position:"fixed",width:`${Mn}px`,height:`${Mn}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"},Co=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ss=({onSubmit:e})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[l,p]=f.useState(""),[d,c]=f.useState("idle"),[a,u]=f.useState(""),x=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var k;return(k=x.current)==null?void 0:k.focus()},100)},[n]);const g=async()=>{if(!(!n||!r.trim())){c("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),c("success"),s(""),p(""),i("bug")}catch(k){c("error"),u(k instanceof Error?k.message:"提交失败,请稍后重试")}}},h=n&&r.trim()&&d!=="submitting",y=Co.find(k=>k.value===n);return d==="success"?t.jsx("div",{style:Io,children:t.jsxs("div",{style:jp,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>c("idle"),style:vp,children:"继续提交"})]})}):t.jsxs("div",{style:Io,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Co.map(k=>t.jsxs("button",{onClick:()=>i(k.value),style:{...hp,...n===k.value?mp:{}},children:[t.jsx("span",{children:k.icon})," ",k.label]},k.value))}),t.jsx("textarea",{ref:x,value:r,onChange:k=>s(k.target.value),placeholder:(y==null?void 0:y.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:d==="submitting",style:{...bp}}),t.jsx("input",{type:"text",value:l,onChange:k=>p(k.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:d==="submitting","aria-label":"联系方式(选填)",style:Sp}),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:g,disabled:!h,style:{...yp,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:d==="submitting"?"提交中...":"提交"})]}),d==="error"&&t.jsx("div",{style:kp,children:a})]})},Io={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},hp={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"},mp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},bp={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"},yp={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},jp={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},vp={background:"none",border:"none",color:o("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},kp={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginTop:"8px"},Sp={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 To(e){return typeof e=="function"?e():e??"/api/feedback"}const ws=({resourceId:e,apiUrl:n})=>{const[i,r]=f.useState([]),[s,l]=f.useState(!0),p=f.useCallback(async()=>{const c=To(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(()=>{p()},[p]);const d=async c=>{const a=To(n),u=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...c,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const x=await u.json().catch(()=>null);throw new Error((x==null?void 0:x.error)||"提交失败")}setTimeout(()=>p(),500)};return t.jsxs("div",{children:[t.jsx(hi,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Ss,{onSubmit:d})})]})},Ro={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 wp(e){return e?Ro[e]??e:Ro.related}const _p={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function $p(e){return _p[e]??e}const zp={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function mi(e){return zp[e]??""}function bi({authors:e,onNavigate:n,renderLink:i}){const{convert:r}=Y(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,p)=>{const d=Zn(l.role);return t.jsxs(f.Fragment,{children:[p>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Pe,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:i,dense:!0}):r(l.name),d&&t.jsx("span",{style:{marginLeft:4},children:r(d)})]},p)})}):null}const Eo=12,Cp=60,_s=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:p,railLinks:d})=>{var U,se,de;const c=te(),{convert:a}=Y(),u=f.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[x,g]=f.useState(new Map),[h,y]=f.useState(!1),[k,m]=f.useState(""),[v,b]=f.useState(!1),j=u.length<=Cp,$=j||h||!!k||v,S=f.useMemo(()=>$?u:u.slice(0,Eo),[u,$]);f.useEffect(()=>{if(!n||S.length===0)return;const D=S.filter(oe=>!x.has(oe));if(D.length===0)return;let re=!1;return Promise.all(D.map(oe=>n.getItem(oe).then(pe=>{const fe=pe??{};return[oe,{id:oe,title:fe.title,edition:fe.edition,resources:fe.resources,publication_info:fe.publication_info,current_location:fe.current_location,lineage:fe.lineage,measure_info:fe.measure_info}]}).catch(()=>[oe,{id:oe}]))).then(oe=>{re||g(pe=>{const fe=new Map(pe);for(const[ye,Ce]of oe)fe.set(ye,Ce);return fe})}),()=>{re=!0}},[n,S,x]);const _=f.useMemo(()=>u.map(D=>x.get(D)??{id:D}),[u,x]),w=u.length>0&&u.every(D=>x.has(D)),z=j||$,B=f.useMemo(()=>br(_,e.version_graph,{era:k,scanOnly:v,sort:z?"year":"default"}),[_,e.version_graph,k,v,z]),L=h?B.rows:B.rows.slice(0,Eo),C=B.allRows.filter(D=>D.hasImage).length,A=e.related_works||[],W=A.filter(D=>D.relation==="collected_in"),T=f.useMemo(()=>{const D=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],re=oe=>{const pe=D.indexOf(oe??"");return pe<0?D.length:pe};return A.filter(oe=>oe.relation!=="collected_in").map((oe,pe)=>({r:oe,i:pe})).sort((oe,pe)=>re(oe.r.relation)-re(pe.r.relation)||oe.i-pe.i).map(oe=>oe.r)},[A]),R=f.useMemo(()=>{const D=nn(e.resources,e.resource_groups);return[...D.mirrors.flatMap(re=>re.items.map(oe=>({r:oe,kind:a(re.label)}))),...D.buckets.flatMap(re=>re.items.map(oe=>({r:oe,kind:a(mi(re.key))})))]},[e.resources,e.resource_groups,a]),N=e.indexed_by||[],O=e.emendated_by||[],E=f.useMemo(()=>{var ce,F,ie;const D=[],re=(F=(ce=e.authors)==null?void 0:ce[0])==null?void 0:F.dynasty;re&&D.push({label:"成書",value:a(re)});const oe=et(e,c.unit.juan);if(oe){const ne=(ie=e.juan_count)==null?void 0:ie.description;D.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[a(oe),ne&&ne!==oe?t.jsxs("span",{className:"bim-d-meta",children:["(",a(ne),")"]}):null]})})}e.loss_status&&D.push({label:"存佚",value:a($p(e.loss_status))});const pe=e._edition_count??u.length;pe&&D.push({label:"版本",value:t.jsxs(t.Fragment,{children:[pe," ",a("種"),w&&C?t.jsxs("span",{className:"bim-d-meta",children:[" ",a(`${C} 種有影印`)]}):null]})});const fe=B.allRows.filter(ne=>ne.sortYear!=null);if(fe.length>0){const ne=fe.reduce((he,ge)=>he.sortYear<=ge.sortYear?he:ge);ne.era.era&&D.push({label:"最早存世",value:a([ne.era.era,ne.era.reign].filter(Boolean).join(" ")),title:ne.era.source==="edition"?a("據版本題名推斷"):void 0})}(N.length||O.length)&&D.push({label:"著錄",value:t.jsxs(t.Fragment,{children:[N.length?`${N.length} ${a("家")}`:"—",O.length?t.jsxs("span",{className:"bim-d-meta",children:[" ",a(`考證 ${O.length} 條`)]}):null]})});const ye=Lo(e.additional_titles);ye.length&&D.push({label:"又名",value:ye.map(a).join("、")});const Ce=Lo(e.attached_texts);Ce.length&&D.push({label:"附載",value:Ce.map(a).join("、")});const Q=(e.additional_works||[]).map(ne=>a(ne.book_title)+(ne.n_juan!=null?` ${ne.n_juan}${a(c.unit.juan)}`:""));return Q.length&&D.push({label:"附錄",value:Q.join("、")}),D},[e,a,c,u.length,w,C,B.allRows,N.length,O.length]),X=e.classification,I=X?[X.l1,X.l2,X.l3,X.l4].filter(Boolean).map(D=>a(D)):[],M=e.subtype?a(c.workSubtype[e.subtype]??e.subtype):"",K=t.jsx(At,{title:a(e.title),byline:t.jsx(bi,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(Te,{items:[...I,X!=null&&X.source?a(`據《${X.source.split("/")[0]}》`):"",M]}),description:(U=e.description)!=null&&U.text?t.jsxs(t.Fragment,{children:[t.jsx(Ke,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(se=e.description.sources)!=null&&se.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(D=>a(ha(D))).filter(Boolean).join(" · ")}):null]}):void 0,facts:E,readAction:s,foot:t.jsx(Mt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(de=e.appendix)==null?void 0:de.map((D,re)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:a(D.title)}),t.jsx(Ke,{text:D.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},re))}),V=B.eras.length>=2?[{key:"",label:c.catalog.all},...B.eras.map(D=>({key:D,label:D}))]:[],G=[];u.length&&G.push({id:"versions",label:"版本",count:u.length}),N.length&&G.push({id:"catalogs",label:"著錄",count:N.length}),W.length&&G.push({id:"collected",label:"收入叢編",count:W.length}),T.length&&G.push({id:"related",label:"相關書目",count:T.length}),R.length&&G.push({id:"resources",label:"在線資源",count:R.length});const ee=u.length===0&&N.length===0,P=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs($e,{id:"versions",title:"版本",meta:t.jsx(Te,{items:[a(`共 ${u.length} 種`),w&&C?a(`${C} 種有影印`):"",B.rows.length!==B.allRows.length?a(`當前 ${B.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[V.length>0&&t.jsx(rn,{items:V,value:k,onChange:D=>{m(D),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Ir,{label:"只看有影印",checked:v,onChange:D=>{b(D),y(!1)}}),t.jsx("span",{className:"bim-d-meta",children:a(z?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("版本")}),t.jsx("th",{children:a("年代")}),t.jsx("th",{children:a("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:a("影印")})})]})}),t.jsx("tbody",{children:L.map(D=>{var re;return t.jsx(Ip,{row:D,measure:(re=x.get(D.id))==null?void 0:re.measure_info,loaded:x.has(D.id),onNavigate:i,renderLink:r},D.id)})})]}),L.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a(k||v?"當前篩選下沒有版本":"暫無版本著錄")}),B.rows.length>L.length&&t.jsx(yt,{label:`展開其餘 ${B.rows.length-L.length} 種版本`,onClick:()=>y(!0)}),B.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:a("部分年代據版本題名推斷,非著錄原文")})]}),N.length>0&&t.jsx(Tp,{items:N,onNavigate:i,renderLink:r}),ee&&t.jsx($e,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該作品的版本與書目收錄。")})})]}),q=(D,re)=>t.jsx(Pe,{id:D,label:a(re),onNavigate:i,renderLink:r,dense:!0}),Z=t.jsxs(t.Fragment,{children:[t.jsx(ct,{id:"collected",title:"收入叢編",items:W.map(D=>q(D.id,D.title))}),t.jsx(ct,{id:"related",title:"相關書目",meta:a(`${T.length} 部`),items:T.map(D=>t.jsxs(t.Fragment,{children:[q(D.id,D.title),t.jsx("span",{className:"bim-d-meta",title:D.note?a(D.note):void 0,children:a(wp(D.relation))})]}))}),t.jsx(ct,{id:"resources",title:"在線資源",cap:6,items:R.map(({r:D,kind:re})=>{const oe=a((D.url?tt(D.url):void 0)||D.name),pe=bt(D);return t.jsxs(t.Fragment,{children:[pe?t.jsxs("a",{href:pe,target:"_blank",rel:"noopener noreferrer",children:[oe," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:oe}),re&&t.jsx("span",{className:"bim-d-meta",children:re})]})})})]});return t.jsx(Wt,{railTop:l,back:p,nav:G,railLinks:d,main:P,card:K,side:Z})};function Lo(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Bo(e,n){return n((e.url?tt(e.url):void 0)||e.name)}function Ip({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=Y(),p=[e.era.era,e.era.reign].filter(Boolean).join(" "),d=e.era.source==="edition",c=e.holders[0],a=c?Bo(c,l):e.locationName?l(e.locationName):"",u=e.images[0],x=u?bt(u):void 0,g=e.images.map(h=>Bo(h,l)).join("、");return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Pe,{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("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${p?"":" bim-d-zt-blank"}`,title:d?l("據版本題名推斷"):void 0,children:p?l(p):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${a?"":" bim-d-zt-blank"}`,children:[a||(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&&(x?t.jsx("a",{className:"bim-d-flag",href:x,target:"_blank",rel:"noopener noreferrer",title:g,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:g,children:l("有影印")}))})]})}function Tp({items:e,onNavigate:n,renderLink:i}){const r=te(),{convert:s}=Y(),[l,p]=f.useState(0),d=e[Math.min(l,e.length-1)];return t.jsx($e,{id:"catalogs",title:"著錄",meta:s(`歷代書目 ${e.length} 家`),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-lu-list bim-d-ui",role:"tablist","aria-label":s("著錄書目"),children:e.map((c,a)=>t.jsx("li",{role:"presentation",children:t.jsx("button",{type:"button",role:"tab","aria-selected":a===l,onClick:()=>p(a),children:s(c.source)})},a))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:s(d.title_info)}),t.jsx(Te,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?t.jsx(Pe,{id:d.source_bid,label:s(d.source),onNavigate:n,renderLink:i,dense:!0}):s(d.source),d.section?s(d.section):"",d.author_info?`${s(r.label.authorInfo)} ${s(d.author_info)}`:"",d.edition?`${s(r.label.edition)} ${s(d.edition)}`:"",d.page??""]}),d.summary&&t.jsx("p",{className:"bim-d-quote",children:ze(s(d.summary))}),d.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s(r.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:ze(s(d.comment))})]}),d.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s(r.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:ze(s(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:s("僅著錄書名,無提要。")})]})]})})}const No=8,$s=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:p,railLinks:d})=>{var R,N,O,E,X;const c=te(),{convert:a}=Y(),[u,x]=f.useState(null),[g,h]=f.useState(new Map),[y,k]=f.useState([]),[m,v]=f.useState(!1);f.useEffect(()=>{if(!n||!e.work_id){x(null);return}let I=!1;return n.getItem(e.work_id).then(M=>{!I&&M&&M.type==="work"&&x(M)}).catch(()=>{}),()=>{I=!0}},[n,e.work_id]),f.useEffect(()=>{const I=e.contained_in||[];if(!n||I.length===0){h(new Map);return}let M=!1;return Promise.all(I.map(K=>{const V=typeof K=="string"?K:K.id;return n.getItem(V).then(G=>[V,G]).catch(()=>[V,null])})).then(K=>{if(M)return;const V=new Map;for(const[G,ee]of K)ee&&V.set(G,ee);h(V)}),()=>{M=!0}},[n,e.contained_in]);const b=f.useMemo(()=>{const I=new Set([...(u==null?void 0:u.books)||[],...e.related_books||[]]);return I.delete(e.id),[...I]},[u==null?void 0:u.books,e.related_books,e.id]);f.useEffect(()=>{if(!n||b.length===0){k([]);return}const I=m?b:b.slice(0,No);let M=!1;return Promise.all(I.map(K=>n.getItem(K).then(V=>({id:K,title:V==null?void 0:V.title,edition:V==null?void 0:V.edition})).catch(()=>({id:K})))).then(K=>{M||k(K)}),()=>{M=!0}},[n,b,m]);const j=f.useMemo(()=>{const I=nn(e.resources,e.resource_groups);return[...I.mirrors.flatMap(M=>M.items.map(K=>({r:K,kind:a(M.label),all:M.items}))),...I.buckets.flatMap(M=>M.items.map(K=>({r:K,kind:a(mi(M.key)),all:M.items})))]},[e.resources,e.resource_groups,a]),$=Bt(e),S=Sr(e),_=new Set((e.contained_in||[]).map(I=>typeof I=="string"?0:Rt(I.volume_index).length).filter(I=>I>0)),w=f.useMemo(()=>{var ee,P,q,Z;const I=[];S&&I.push({label:"版本類型",value:a(S),title:(ee=e.lineage)!=null&&ee.category?void 0:a("據版本題名推斷")}),($.era||$.reign)&&I.push({label:"刊寫年代",value:a([$.era,$.reign].filter(Boolean).join(" ")),title:$.source==="edition"?a("據版本題名推斷"):void 0});const M=et(e,c.unit.juan);M&&I.push({label:"卷帙",value:a(M)});const K=(e.contained_in||[]).flatMap(U=>typeof U=="string"?[]:Rt(U.volume_index));K.length&&I.push({label:"冊次",value:a(`第 ${on(K,c.unit.volume)} ${c.unit.volume}(${K.length} ${c.unit.volume})`)});const V=(e.resources||[]).filter(U=>(U.types||(U.type?[U.type]:[])).includes("physical"));V.length?I.push({label:"存藏",value:V.slice(0,2).map(U=>a(U.name)).join("、")+(V.length>2?a(` 等 ${V.length} 處`):"")}):(P=e.current_location)!=null&&P.name&&I.push({label:"存藏",value:a(e.current_location.name)}),(q=e.page_count)!=null&&q.description&&I.push({label:c.label.pageCount,value:a(e.page_count.description)}),(Z=e.publication_info)!=null&&Z.details&&I.push({label:"刊印",value:a(e.publication_info.details)});const G=[...En(e.additional_titles),...En(e.attached_texts)];return G.length&&I.push({label:"又名",value:G.map(a).join("、")}),I},[e,a,c,$,S]),z=a(e.title),B=e.edition?a(e.edition):void 0,L=t.jsx(At,{title:z,subtitle:B,byline:t.jsx(bi,{authors:e.authors??(u==null?void 0:u.authors),onNavigate:i,renderLink:r}),meta:t.jsx(Te,{items:[a("版本"),S?a(S):"",$.era?a($.era):""]}),description:(R=e.description)!=null&&R.text?t.jsx(Ke,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,facts:w,readAction:s,foot:t.jsx(Mt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),C=e.contained_in||[],A=[];j.length&&A.push({id:"resources",label:"影印與全文",count:j.length}),C.length&&A.push({id:"collections",label:"收入叢編",count:C.length}),(N=e.location_history)!=null&&N.length&&A.push({id:"provenance",label:"流轉歷史"}),u&&A.push({id:"work",label:"所屬作品"}),b.length&&A.push({id:"siblings",label:"其他版本",count:b.length});const W=t.jsxs(t.Fragment,{children:[j.length>0&&t.jsx($e,{id:"resources",title:"影印與全文",meta:a(`${j.length} 處`),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:j.map(({r:I,kind:M,all:K},V)=>t.jsx(Rp,{item:I,kind:M,siblings:K,listedVolumeCounts:_},`${I.id||I.url||I.name}-${V}`))})})}),C.length>0&&t.jsx($e,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:C.map((I,M)=>{var P,q;const K=typeof I=="string"?I:I.id,V=typeof I=="string"?[]:Rt(I.volume_index),G=g.get(K),ee=(G==null?void 0:G._member_count)||((P=G==null?void 0:G.books)==null?void 0:P.length)||((q=G==null?void 0:G.contained_works)==null?void 0:q.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Pe,{id:K,label:G?a(G.title):K,onNavigate:i,renderLink:r,dense:!0}),V.length>0&&t.jsx(Ep,{volumes:V,unit:c.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ee?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ee>0&&a(`全 ${ee} ${c.unit.bu}`)})]},`${K}-${M}`)})})})}),(O=e.location_history)!=null&&O.length?t.jsx($e,{id:"provenance",title:"流轉歷史",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:e.location_history.map((I,M)=>t.jsxs("tr",{children:[t.jsx("td",{className:"bim-d-zt-main",children:t.jsx("span",{className:"bim-d-zt-name",children:a(I.name)})}),t.jsx("td",{className:`bim-d-zt-sub${I.description||I.start_date?"":" bim-d-zt-blank"}`,children:t.jsx(Te,{items:[[I.start_date,I.end_date].filter(Boolean).join("—"),I.description?a(I.description):""]})})]},M))})})}):null,j.length===0&&C.length===0&&!((E=e.location_history)!=null&&E.length)&&t.jsx($e,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該版本的影印、全文與收藏信息。")})})]}),T=t.jsxs(t.Fragment,{children:[u&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h3",{className:"bim-d-ui",children:a(c.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Pe,{id:u.id,label:a(u.title),onNavigate:i,renderLink:r})}),t.jsx(Te,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[a(et(u,c.unit.juan)),...(u.authors||[]).slice(0,2).map(I=>`${I.dynasty?`〔${a(I.dynasty)}〕`:""}${a(I.name)}`),u._edition_count?a(`${u._edition_count} 種版本`):""]}),((X=u.description)==null?void 0:X.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:4,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:a(u.description.text.replace(/[#*_>`[\]]/g,""))})]}),b.length>0&&t.jsxs("div",{children:[t.jsx(ct,{id:"siblings",title:c.relation.siblingVersions,meta:a(`${b.length} 種`),cap:m?y.length:No,items:y.map(I=>t.jsx(Pe,{id:I.id,label:a(I.edition||I.title||I.id),onNavigate:i,renderLink:r,dense:!0}))}),!m&&b.length>y.length&&y.length>0&&t.jsx(yt,{label:`顯示更多(${b.length-y.length})`,onClick:()=>v(!0)})]})]});return t.jsx(Wt,{railTop:l,back:p,nav:A,railLinks:d,main:W,card:L,side:T})};function Rp({item:e,kind:n,siblings:i,listedVolumeCounts:r}){const{convert:s}=Y(),[l,p]=f.useState(!1),d=Xt(e),c=!!d&&d.expected>0&&!r.has(d.expected),a=(e.url?tt(e.url):void 0)||e.name,u=hr(e,i),x=s(u?`${a}(${u})`:a),g=bt(e),h=Nt(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[g?t.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",children:[x," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:x}),h&&t.jsx("span",{className:"bim-d-meta",children:s(h)}),c&&l&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(Qn,{item:e})})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${n?"":" bim-d-zt-blank"}`,children:n}),t.jsx("td",{className:c?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:c&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":l,onClick:()=>p(y=>!y),children:s(l?"收起分冊":`展開 ${d.expected} 冊`)})})]})}function Ep({volumes:e,unit:n}){const{convert:i}=Y();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${on(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}const Lp=16,zs=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,readAction:p,railTop:d,back:c,railLinks:a})=>{var I,M,K,V,G,ee;const u=te(),{convert:x}=Y(),[g,h]=f.useState(""),[y,k]=f.useState(!1),m=f.useMemo(()=>vr(e,n),[e,n]),v=f.useMemo(()=>g?m.rows.filter(P=>P.section===g):m.rows,[m.rows,g]),b=y?v:v.slice(0,Lp),[j,$]=f.useState(new Map),S=f.useMemo(()=>b.filter(P=>P.id&&P.title===P.id&&!j.has(P.id)).map(P=>P.id),[b,j]);f.useEffect(()=>{if(!i||S.length===0)return;let P=!1;return Promise.all(S.map(q=>i.getItem(q).then(Z=>[q,{title:Z==null?void 0:Z.title,edition:Z==null?void 0:Z.edition}]).catch(()=>[q,{}]))).then(q=>{P||$(Z=>{const U=new Map(Z);for(const[se,de]of q)U.set(se,de);return U})}),()=>{P=!0}},[i,S]);const _=f.useMemo(()=>{const P=nn(e.resources,e.resource_groups);return[...P.mirrors.flatMap(q=>q.items.map(Z=>({r:Z,kind:x(q.label)}))),...P.buckets.flatMap(q=>q.items.map(Z=>({r:Z,kind:x(mi(q.key))})))]},[e.resources,e.resource_groups,x]),w=e.contained_works||[],z=new Set(m.rows.map(P=>P.id).filter(Boolean)),B=w.length>0&&!w.every(P=>z.has(P.id)),L=(()=>{const P=m.rows.map(q=>q.edition).filter(Boolean);return P.length>1&&new Set(P).size===1})(),C=m.sections.length>0,A=m.rows.some(P=>P.volumes.length>0||P.expected!=null),W=e._member_count||((I=e.books)==null?void 0:I.length)||w.length,T=f.useMemo(()=>{var Z,U,se;const P=[];W&&P.push({label:"種數",value:`${W} ${x(u.unit.bu)}`});const q=et(e,u.unit.juan);return q&&P.push({label:"卷數",value:x(q),title:(Z=e.juan_count)!=null&&Z.description?x(e.juan_count.description):void 0}),m.totalVolumes&&P.push({label:"全帙冊數",value:`${m.totalVolumes} ${x(u.unit.volume)}`}),(U=e.publication_info)!=null&&U.details&&P.push({label:"刊印",value:x(e.publication_info.details)}),(se=e.publication_info)!=null&&se.year&&P.push({label:"年代",value:x(e.publication_info.year)}),P},[e,W,m.totalVolumes,x,u]),R=t.jsx(At,{title:x(e.title),byline:t.jsx(bi,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Te,{items:[x("叢編"),e.subtype==="work_collection"?x("作品集"):"",(M=e.publication_info)!=null&&M.year?x(e.publication_info.year):""]}),description:(K=e.description)!=null&&K.text||(V=e.history)!=null&&V.length?t.jsxs(t.Fragment,{children:[((G=e.description)==null?void 0:G.text)&&t.jsx(Ke,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(ee=e.history)!=null&&ee.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((P,q)=>t.jsx("li",{children:x(P)},q))}):null]}):void 0,facts:T,readAction:p,foot:t.jsx(Mt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),N=[];m.rows.length&&N.push({id:"titles",label:u.section.containedBooks,count:m.rows.length}),_.length&&N.push({id:"resources",label:"影印與全文",count:_.length}),B&&N.push({id:"works",label:u.section.containedWorks,count:w.length});const O=C?[{key:"",label:u.catalog.all},...m.sections.map(P=>({key:P,label:P}))]:[],E=t.jsxs(t.Fragment,{children:[m.rows.length>0&&t.jsxs($e,{id:"titles",title:u.section.containedBooks,meta:t.jsx(Te,{items:[x(`共 ${m.rows.length} ${u.unit.items}`),W&&W!==m.rows.length?x(`成員 ${W} ${u.unit.bu}`):"",v.length!==m.rows.length?x(`當前 ${v.length} ${u.unit.items}`):""]}),action:l,children:[O.length>0&&t.jsx("div",{className:"bim-d-filters bim-d-ui",children:t.jsx(rn,{items:O,value:g,onChange:P=>{h(P),k(!1)}})}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:x("書名")}),C&&t.jsx("th",{children:x("部類")}),A&&t.jsx("th",{children:x("全帙冊次")})]})}),t.jsx("tbody",{children:b.map((P,q)=>{var re;const Z=P.id?j.get(P.id):void 0,U=Z!=null&&Z.title?{...P,title:Z.title}:P,se=[(re=U.subItems)!=null&&re.length?U.subItems.map(oe=>x(oe)).join("、"):"",U.edition&&!L?x(U.edition):""].filter(Boolean).join(" · "),de=U.volumes.length>0?x(`第 ${on(U.volumes,u.unit.volume)} ${u.unit.volume}`):U.expected!=null?x(`${U.found??0}/${U.expected} ${u.unit.volume}`):"",D=U.section?x(U.section.endsWith("部")?U.section:`${U.section}部`):"";return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[U.id?t.jsx(Pe,{id:U.id,label:x(U.title),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:x(U.title)}),se&&t.jsx("span",{className:"bim-d-meta",children:se})]}),C&&t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${D?"":" bim-d-zt-blank"}`,children:D||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),A&&t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${de?"":" bim-d-zt-blank"}`,children:de||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})})]},`${U.id??U.title}-${q}`)})})]}),b.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:x(u.catalog.noMatch)}),v.length>b.length&&t.jsx(yt,{label:`展開其餘 ${v.length-b.length} ${u.unit.items}`,onClick:()=>k(!0)})]}),_.length>0&&t.jsx($e,{id:"resources",title:"影印與全文",meta:x(`${_.length} 處`),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:_.map(({r:P,kind:q},Z)=>{const U=x((P.url?tt(P.url):void 0)||P.name),se=bt(P),de=Nt(P)||P.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[se?t.jsxs("a",{href:se,target:"_blank",rel:"noopener noreferrer",children:[U," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:U}),de&&t.jsx("span",{className:"bim-d-meta",children:x(de)})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${q?"":" bim-d-zt-blank"}`,children:q})]},`${P.id||P.url||P.name}-${Z}`)})})})}),m.rows.length===0&&_.length===0&&t.jsx($e,{title:u.section.containedBooks,children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該叢編的子目。")})})]}),X=B?t.jsx(ct,{id:"works",title:u.section.containedWorks,meta:x(`${w.length} 種`),cap:12,items:w.map(P=>t.jsx(Pe,{id:P.id,label:x(P.title),onNavigate:r,renderLink:s,dense:!0}))}):null;return t.jsx(Wt,{railTop:d,back:c,nav:N,railLinks:a,main:E,card:R,side:X})},Bp=16,jn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Wo(e){if(!e)return jn.length;const n=jn.indexOf(e);return n===-1?jn.length:n}const Np={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function Ao(e){return e==null?"":e<0?`前${-e}`:String(e)}const Cs=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:p})=>{var W;const d=te(),{convert:c}=Y(),[a,u]=f.useState("全部"),[x,g]=f.useState(!1),[h,y]=f.useState("default"),[k,m]=f.useState(new Map),v=f.useMemo(()=>(e.works||[]).map(T=>{const R=k.get(T.work_id);return{id:T.work_id,title:(R==null?void 0:R.title)??T.title??T.work_id,role:T.role||"",cls:Jn(T.role),versionCount:R==null?void 0:R.versionCount,loaded:!!(R!=null&&R.loaded)}}),[e.works,k]),b=f.useMemo(()=>jr((e.works||[]).map(T=>T.role)),[e.works]),j=f.useMemo(()=>{const T=a==="全部"?v:v.filter(R=>R.cls===a);return h==="versions"?[...T].sort((R,N)=>(N.versionCount??-1)-(R.versionCount??-1)):T},[v,a,h]),$=x?j:j.slice(0,Bp),S=f.useMemo(()=>$.filter(T=>!k.has(T.id)).map(T=>T.id),[$,k]);f.useEffect(()=>{if(!n||S.length===0)return;let T=!1;return Promise.all(S.map(R=>n.getItem(R).then(N=>{var X,I;const O=N??{},E=O._edition_count??(((X=O.books)==null?void 0:X.length)??0)+(((I=O.collections)==null?void 0:I.length)??0);return[R,{id:R,title:O.title,versionCount:E,loaded:!0}]}).catch(()=>[R,{id:R,loaded:!0}]))).then(R=>{T||m(N=>{const O=new Map(N);for(const[E,X]of R)O.set(E,X);return O})}),()=>{T=!0}},[n,S]);const _=f.useMemo(()=>{const T=new Map;for(const R of e.alt_names||[]){const N=R.type||d.section.aliases;T.has(N)||T.set(N,[]),T.get(N).push(R.name)}return[...T.entries()].sort((R,N)=>Wo(R[0])-Wo(N[0])).map(([R,N])=>({label:R,names:N}))},[e.alt_names,d]),w=e.birth_year!=null||e.death_year!=null?`${Ao(e.birth_year)||"?"}—${Ao(e.death_year)||"?"}`:"",z=f.useMemo(()=>{var O,E;const T=[];for(const X of _)T.push({label:X.label,value:X.names.map(I=>c(I)).join("、")});e.dynasty&&T.push({label:"時代",value:c(e.dynasty)}),w&&T.push({label:"生卒",value:w});const R=(e.works||[]).length;R&&T.push({label:"著作",value:`${R} ${c("種")}`});const N=(O=e.external_ids)==null?void 0:O.cbdb_id;return N!=null&&T.push({label:"CBDB",value:t.jsxs(t.Fragment,{children:[N,((E=e.external_ids)==null?void 0:E.cbdb_match)==="auto"&&t.jsx("span",{className:"bim-d-meta",title:c("由姓名、朝代與著作重合度自動匹配,未經人工複核"),children:c("自動匹配")})]})}),T},[e,_,w,c]),B=t.jsx(At,{title:c(e.primary_name||e.title),meta:t.jsx(Te,{items:[c(Np[e.subtype]??""),w]}),description:(W=e.description)!=null&&W.text?t.jsx(Ke,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,facts:z,foot:t.jsx(Mt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),L=b.map(T=>({key:T.cls,label:`${T.label} ${T.count}`})),C=v.length?[{id:"works",label:"著作",count:v.length}]:[],A=v.length===0?t.jsx($e,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該人物的關聯作品。")})}):t.jsxs($e,{id:"works",title:"著作",meta:t.jsx(Te,{items:[c(`共 ${v.length} 種`),j.length!==v.length?c(`當前 ${j.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[L.length>1&&t.jsx(rn,{items:L,value:a,onChange:T=>{u(T),g(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":h==="versions",onClick:()=>{h==="default"&&g(!0),y(T=>T==="default"?"versions":"default")},children:c(h==="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("tbody",{children:$.map(T=>t.jsxs("tr",{children:[t.jsx("td",{className:"bim-d-zt-main",children:t.jsx(Pe,{id:T.id,label:c(T.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${T.role?"":" bim-d-zt-blank"}`,children:T.role?c(T.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${T.loaded?"":" bim-d-zt-blank"}`,children:T.loaded?T.versionCount?c(`${T.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:c("未著錄")}):""})]},T.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("該職任下的著作尚未著錄。")}),j.length>$.length&&t.jsx(yt,{label:`展開其餘 ${j.length-$.length} 種著作`,onClick:()=>g(!0)})]});return t.jsx(Wt,{railTop:s,back:l,nav:C,railLinks:p,main:A,card:B})},yi="(max-width: 719px)",Wp=`${yi}, (pointer: coarse)`,Is=`
568
+ `)){const r=si(i);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=i.trim();!s||li.test(s)||n.push({kind:"body",text:i})}return n}function os(e){if(!e)return[];const n=sn(e);if(n==="unknown")return ao(e);const i=[];for(const{heading:r,body:s}of _c(e)){r&&i.push(r);const l=ts(s);if(l.length!==0){if(is(s)){i.push(...ao(s));continue}if(n==="record"){const p=l.join(" ");p&&i.push({kind:"body",text:p})}else for(const p of l){const d=ns(p);d.length&&i.push({kind:"body",text:d.join(" ")})}}}return i}const rs=e=>e;function ss(e,n=rs){if(e.indexOf("《")<0)return n(e);const i=[],r=/《([^《》\n]+)》/g;let s=0,l=0,p;for(;p=r.exec(e);)p.index>s&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s,p.index))},l++)),i.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(p[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=p.index+p[0].length;return s===0?n(e):(s<e.length&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),i)}function ai(e,n={}){const i=n.renderText??rs,r=n.properNames?l=>ss(l,i):i,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Ie(e,r,s)}function co(e,n,i){return e.indexOf("**")<0?n(e):e.split(/(\*\*[^*]+\*\*)/g).map((s,l)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?t.jsx("strong",{children:n(s.slice(2,-2))},`${i}-${l}`):t.jsx(f.Fragment,{children:n(s)},`${i}-${l}`))}const gn=/^(#{1,6})\s+(.*)$/,$c=/^\s*<!--.*-->\s*$/;function ls(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
569
+ `)?"":n)}function zc(e){return e<=1?2:e===2?3:4}function Cc(){let e=1;return n=>{const i=zc(n),r=Math.min(i,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${i}`}}}function ln(e){return e?sn(ls(e))!=="unknown":!1}function po({text:e,mode:n,inline:i,dropTitle:r}){const s=ls(e),l=(a,u,x)=>!!r&&x<=1&&a<=2&&u.trim()===r.trim(),p=Cc();if(n==="paragraph"&&sn(s)!=="unknown"){const a=os(s);return t.jsx(t.Fragment,{children:a.map((u,x)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,x))return null;const{Tag:g,className:h}=p(u.level??1);return t.jsx(g,{className:h,children:i(u.text)},x)}return t.jsx("p",{children:co(u.text,i,x)},x)})})}const d=s.split(`
570
+ `);let c=0;return t.jsx(t.Fragment,{children:d.map((a,u)=>{const x=a.match(gn);if(x){const h=c++;if(l(x[1].length,x[2],h))return null;const{Tag:b,className:k}=p(x[1].length);return t.jsx(b,{className:k,children:i(x[2])},u)}if(!a.trim())return u>=2&&!!d[u-1].trim()&&!!d[u-2].trim()&&!gn.test(d[u-1])&&!gn.test(d[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if($c.test(a))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(a.trim())){const{Tag:h,className:b}=p(3);return t.jsx(h,{className:b,children:i(a.trim().slice(2,-2))},u)}return t.jsx("p",{children:co(a,i,u)},u)})})}function Ic(e){const{convert:n}=V();return f.useMemo(()=>e?n(e):"",[e,n])}function ci({text:e,mode:n,tables:i=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:p}){const d=Ic(e),{convert:c}=V(),a=g=>ai(g,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,x=p?c(p):void 0;return!i||d.indexOf(":::")<0?t.jsx(po,{text:d,mode:n,inline:a,dropTitle:x}):t.jsx(t.Fragment,{children:oi(d).map((g,h)=>g.type==="table"?t.jsx(ri,{table:g.table,opts:u},h):t.jsx(po,{text:g.text,mode:n,inline:a,dropTitle:h===0?x:void 0},h))})}function as(e,n){const[i,r]=f.useState(null),[s,l]=f.useState(!1),p=f.useRef(0);return f.useEffect(()=>{const d=++p.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(a=>{d===p.current&&r(a??null)}).catch(()=>{d===p.current&&r(null)}).finally(()=>{d===p.current&&l(!1)})},[e,n]),{images:i,loading:s}}const uo={A:"fine",B:"rough",C:"rough",D:"ocr"};function Tc(e){return typeof e!="string"?null:e in kn?e:e in uo?uo[e]:null}const Rc={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Ec={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function Oe(e){return typeof e!="string"?"":Rc[e]??Ec[e]??e}const Lc=["〇","一","二","三","四","五","六","七","八","九"],xo=["","十","百","千"],Nc=["","萬","億"];function di(e){if(e===0)return"〇";if(e<0)return`負${di(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(Bc(s,r>0)+Nc[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Bc(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 p=i[l],d=i.length-1-l;p===0?s&&!s.endsWith("〇")&&(s+="〇"):p===1&&d===1&&l===0&&!n?s+=xo[d]:s+=Lc[p]+xo[d]}return s.replace(/〇$/,"")}let Et=null,Ut=null;const Jt=new Set;function Wc(){return Et?Promise.resolve():Ut||(Ut=import("opencc-js/t2cn").then(e=>{Et=e.Converter({from:"tw",to:"cn"}),Jt.forEach(n=>n())}).catch(()=>{Et=e=>e,Jt.forEach(e=>e())}),Ut)}const Ac=e=>e;function it(){const[,e]=f.useState(0);return f.useEffect(()=>{if(Et)return;const n=()=>e(i=>i+1);return Jt.add(n),Wc(),()=>{Jt.delete(n)}},[]),Et??Ac}function gt(e,n){return n(e).toLowerCase()}const Mc=o("highlight-bg");function Ft(e,n,i){if(!n)return e;const r=gt(n,i);if(!r)return e;const s=gt(e,i);if(s.length!==e.length)return e;const l=[];let p=0,d=0;for(;p<e.length;){const c=s.indexOf(r,p);if(c===-1){l.push(e.slice(p));break}c>p&&l.push(e.slice(p,c)),l.push(t.jsx("mark",{style:{background:Mc,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},d++)),p=c+r.length}return t.jsx(t.Fragment,{children:l})}function pi(e,n,i,r){if(!n)return!0;const s=gt(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(p=>typeof p=="string"&&gt(p,r).includes(s))}function Fc(e,n,i){return n?gt(e,i).includes(gt(n,i)):!0}const ui={类:o("section-lei"),书:o("section-shu"),序:o("section-xu"),结语:o("section-jieyu"),注释:o("section-zhushi")},Pc={考证:o("section-kaozhen")};function Oc(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 cs(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((s,l)=>s+cs(l),0))||0;return n+i}function Dc(e,n){const i=[],r=p=>{var d;i.push(...p.files),(d=p.children)==null||d.forEach(r)};if(r(e),i.length===0)return;const s=i.map(p=>n[p]);if(s.every(p=>p===void 0))return;if(s.some(p=>p==="loading"))return"loading";let l=0;for(const p of s)typeof p=="number"&&(l+=p);return l}const Hc={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function xi({enabled:e,expanded:n,onClick:i,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...Hc,...r},children:s}):t.jsx("span",{style:r,children:s})}function Gc({type:e}){const n=Oe(e),i=ui[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 Uc({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=V(),s=ve(),l=it(),p=k=>k?Ie(r(k),m=>i?Ft(m,i,l):m):"",[d,c]=f.useState(!1),a=!!e.summary,u=!!e.comment,x=!!e.additional_comment,g=!!(e.content&&e.content.length>60),h=a||u||x||g;f.useEffect(()=>{i&&c(!0)},[i]);const b=!d&&g?Br(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:()=>h&&c(!d),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:h?"pointer":"default",userSelect:"none",background:o("input-bg")},children:[t.jsxs(xi,{enabled:h,expanded:d,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[h&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:d?"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:["《",p(e.book_title),"》"]}):p(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[di(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:p(e.author_info||e.author)})]}),!d&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:p(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:p(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:"→作品"})]}),d&&h&&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:p(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:p(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:p(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:p(e.additional_comment)})]}),g&&!a&&!u&&!x&&t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:p(e.content)})]})]})}function Vc({section:e,highlightQuery:n=""}){const{convert:i}=V(),r=it(),s=c=>c?Ie(i(c),a=>n?Ft(a,n,r):a):"",[l,p]=f.useState(!1),d=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(xi,{enabled:d,expanded:l,onClick:()=>p(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:d?"pointer":"default",userSelect:"none"},children:[t.jsx(Gc,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:s(e.title)}),d&&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&&d&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${ui[Oe(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 Yc=100;function fi(e){return Oe(e.type)!=="page_header"?!1:(e.content||"").length>=Yc}function Kc({section:e,highlightQuery:n=""}){const{convert:i}=V(),r=it();if(Oe(e.type)==="page_header"&&!fi(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
571
+ `)),l=Ie(s,a=>n?Ft(a,n,r):a),p=Oe(e.type),d=ui[p]||o("desc-fg"),c=p==="序"||p==="结语"||p==="注释";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 ${d}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:d,marginRight:"8px",padding:"1px 5px",border:`1px solid ${d}40`,borderRadius:"2px",background:`${d}08`,verticalAlign:"middle"},children:p}),l]})}function qc(e,n,i){const[r,s]=f.useState({});return f.useEffect(()=>{var a;if(!n||e.length===0)return;let l=!1;const p=e.filter(u=>{var x;return!((x=i==null?void 0:i.current)!=null&&x.has(u))}),d={};for(const u of e)(a=i==null?void 0:i.current)!=null&&a.has(u)&&(d[u]=i.current.get(u));if(Object.keys(d).length>0&&s(d),p.length===0)return;const c=async u=>{var x;try{if(n.getEntry){const m=await n.getEntry(u);if(m)return{title:m.title,author:m.author}}const g=await n.getItem(u);if(!g)return null;const h=g.title||u,b=g.authors,k=(x=b==null?void 0:b[0])==null?void 0:x.name;return{title:h,author:k}}catch{return null}};return Promise.all(p.map(async u=>{var g;const x=await c(u);return(g=i==null?void 0:i.current)==null||g.set(u,x),[u,x]})).then(u=>{l||s(x=>{const g={...x};for(const[h,b]of u)g[h]=b;return g})}),()=>{l=!0}},[e.join(","),n]),r}function Jc({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=V(),p=ve(),d=it(),c=y=>y?Ie(l(y),j=>s?Ft(j,s,d):j):"",[a,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const x=Oe(e.type),g=Pc[x]||o("desc-fg"),h=!!e.content,b=e.work_ids||[],k=b.length>1,m=qc(k?b:[],i,r),v=h&&!a&&e.content.length>80?Br(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${o("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>h&&u(!a),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:h?"pointer":"default",userSelect:"none"},children:[t.jsxs(xi,{enabled:h,expanded:a,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[h&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:a?"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)}),!a&&v&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:c(v)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:p(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:g,border:`1px solid ${g}40`,borderRadius:"2px",background:`${g}08`},children:x})]})]}),k&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(y=>{const j=m[y],$=j?`${l(j.title)}${j.author?`(${l(j.author)})`:""}`:y.slice(0,8)+"…";return t.jsxs("a",{href:p(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)})}),a&&h&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}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 Zc({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=it(),p=n.trim(),d=f.useMemo(()=>p?e.sections.filter(c=>pi(c,p,!0,l)):e.sections,[e.sections,p,l]);return t.jsxs("div",{children:[t.jsx("div",{children:d.map((c,a)=>t.jsx(Jc,{section:c,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:p},a))}),d.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Xc({sections:e,onNavigate:n,inline:i}){const r=ve(),{convert:s}=V();return t.jsx(t.Fragment,{children:e.map((l,p)=>{const d=Oe(l.type);if(d==="page_header"&&!fi(l))return null;if(d==="类")return t.jsxs(f.Fragment,{children:[t.jsx("h2",{children:i(s(l.title))}),l.content&&t.jsx("p",{children:i(s(l.content))})]},p);if(d==="书"||d==="诗"||d==="考证"||d==="注释"){const c=l.book_title?`《${l.book_title}》${l.n_juan!=null?di(l.n_juan)+"卷":""}`:l.title,a=i(s(c));return t.jsxs("section",{className:"bim-rd-entry",children:[t.jsx("h3",{children:l.work_id&&n?t.jsx("a",{href:r(l.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),n(l.work_id))},title:"查看作品",children:a}):a}),l.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(l.author_info))}),l.content&&l.content.split(/\n+/).map((u,x)=>t.jsx("p",{children:i(s(u))},x)),l.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(l.summary))]}),l.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(l.comment))]}),l.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(l.additional_comment))]})]},p)}return l.content?t.jsx("p",{children:i(s(l.content))},p):null})})}function Qc(e){return e.some(n=>{const i=Oe(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&fi(n)})}function ed({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:p,workLabelCache:d,prefs:c}){var W;const{convert:a}=V(),u=it(),[x,g]=f.useState("text"),h=s.trim(),b=(r==null?void 0:r.type)==="kaozhen",k=f.useCallback(T=>h?Ft(T,h,u):T,[h,u]),m=T=>ai(T,{renderText:k,properNames:c.properNames}),v=f.useMemo(()=>h?e.sections.filter(T=>pi(T,h,b,u)):e.sections,[e.sections,h,b,u]),y=(T,L)=>L.filter(M=>Oe(M.type)===T).length,j=y("书",e.sections),$=y("诗",e.sections),S=y("考证",e.sections);let _="";b?_=h?`${y("考证",v)} / ${S} ${a("條")}`:`${S} ${a("條")}`:$>0?_=h?`${y("诗",v)} / ${$} 首`:`${$} 首`:j>0&&(_=h?`${y("书",v)} / ${j} ${a("部書")}`:`${j} ${a("部書")}`);const w=r!=null&&r.text_quality?Tc(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:[a("考證對象")," ",a(r.target_source)]})),w&&z.push(t.jsx("span",{title:ol[w],children:(W=r==null?void 0:r.text_quality)!=null&&W.source_note?t.jsxs(t.Fragment,{children:["底本 ",a(r.text_quality.source_note),"(",a(kn[w]),")"]}):t.jsxs(t.Fragment,{children:[a("文本質量")," ",a(kn[w])]})})),e.source_url&&z.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:a("原文來源")}));const B=!b&&Qc(e.sections),E=!!n&&(!B||c.readingMode==="paragraph"&&ln(n)),C=!b&&(B||!!n),A=b||!C?"entries":x;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:a(e.title)}),z.length>0&&t.jsx("p",{className:"bim-rd-meta",children:z.map((T,L)=>t.jsxs(f.Fragment,{children:[L>0&&t.jsx("span",{className:"bim-rd-dot"}),T]},L))}),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":A==="text",onClick:()=>g("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":A==="entries",onClick:()=>g("entries"),children:a("條目")})]})]}),A==="text"&&t.jsx("article",{className:"bim-rd-prose",children:E?t.jsx(ci,{text:n,mode:c.readingMode,properNames:c.properNames,renderText:k,dropTitle:e.title}):t.jsx(Xc,{sections:e.sections,onNavigate:l,inline:m})}),A==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:b?t.jsx(Zc,{juan:e,searchQuery:s,onNavigate:l,transport:p,workLabelCache:d}):t.jsxs(t.Fragment,{children:[v.map((T,L)=>{const M=Oe(T.type);return M==="书"||M==="诗"||M==="考证"?t.jsx(Uc,{section:T,onNavigate:l,highlightQuery:h},L):M==="类"?t.jsx(Vc,{section:T,highlightQuery:h},L):t.jsx(Kc,{section:T,highlightQuery:h},L)}),v.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function ds(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 td(e){const n=ds(e);return n.length>0?n[0]:null}function nd(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:p,query:d,isKaozhen:c}=e,a=it(),u=f.useRef(new Map),[x,g]=f.useState({}),[h,b]=f.useState({}),k=f.useCallback((v,y)=>{const j=y==null?void 0:y.title;j&&b($=>$[v]===j?$:{...$,[v]:j})},[]);f.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:p}),k(s,l))},[s,l,p,k]),f.useEffect(()=>{u.current.clear(),g({}),b({})},[n]);const m=f.useCallback((v,y)=>{let j=0;if(v.juan)for(const $ of v.juan.sections)pi($,y,c,a)&&j++;return j===0&&v.rawText&&Fc(v.rawText,y,a)&&(j=1),j},[c,a]);return f.useEffect(()=>{const v=d.trim();if(!v){g({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let y=!1;const j={},$=[];for(const B of r){const E=u.current.get(B);E?j[B]=m(E,v):(j[B]="loading",$.push(B))}g(j);const S=8;let _=0;const w=async()=>{var B;for(;_<$.length;){if(y)return;const E=_++,C=$[E];try{const[A,W]=await Promise.all([i.getCollatedJuan(n,C),((B=i.getCollatedJuanText)==null?void 0:B.call(i,n,C))??Promise.resolve(null)]),T={juan:A,rawText:W};if(u.current.set(C,T),k(C,A),y)return;g(L=>({...L,[C]:m(T,v)}))}catch{if(y)return;g(A=>({...A,[C]:0}))}}},z=Array.from({length:Math.min(S,$.length)},()=>w());return Promise.all(z),()=>{y=!0}},[d,n,i,r.join(","),m,a,k]),{matchStates:x,titles:h}}const gi=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:p,style:d,title:c,subtitle:a,resolveImages:u,renderImageOverlay:x,imagePanel:g,allowVertical:h})=>{const[b,k]=f.useState(null),[m,v]=f.useState(!1),[y,j]=f.useState(null),[$,S]=f.useState(null),[_,w]=f.useState(null),[z,B]=f.useState(!1),[E,C]=f.useState(null),[A,W]=f.useState(""),T=f.useRef(new Map),L=f.useRef(0),M=s??$,P=f.useCallback(U=>{S(U),l==null||l(U)},[l]),R=e||b;f.useEffect(()=>{e&&(v(!1),j(null))},[e]),f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let U=!1;return v(!0),j(null),i.getCollatedEditionIndex(n).then(te=>{U||(te?k(te):j("未找到整理本数据"))}).catch(te=>{U||j(te instanceof Error?te.message:"加载失败")}).finally(()=>{U||v(!1)}),()=>{U=!0}},[e,n,i]),f.useEffect(()=>{if(R&&!M){const U=td(R);U&&P(U)}},[R,M,P]);const ne=n||(R==null?void 0:R.work_id),I=f.useCallback(async U=>{var O;if(!ne||!(i!=null&&i.getCollatedJuan))return;const te=++L.current;B(!0),w(null),C(null);try{const[Y,Z]=await Promise.all([i.getCollatedJuan(ne,U),((O=i.getCollatedJuanText)==null?void 0:O.call(i,ne,U))??Promise.resolve(null)]);if(te!==L.current)return;w(Y),C(Z)}catch{if(te!==L.current)return;w(null),C(null)}finally{te===L.current&&B(!1)}},[ne,i]);f.useEffect(()=>{M&&I(M)},[M,I]);const F=U=>{P(U)};if(m)return t.jsx("div",{className:p,style:{...d,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(y)return t.jsx("div",{className:p,style:{...d,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:y});if(!R)return null;const K=R.type==="kaozhen",G=ds(R);return t.jsx(od,{className:p,style:d,index:R,allFiles:G,isKaozhen:K,effectiveWorkId:ne,transport:i,activeFile:M,handleSelectFile:F,juanData:_,juanRawText:E,juanLoading:z,searchQuery:A,setSearchQuery:W,onNavigate:r,workLabelCacheRef:T,reader:{title:c,subtitle:a,resolveImages:u,renderImageOverlay:x,imagePanel:g,allowVertical:h}})};function ps(e,n,i,r){var a,u,x,g;const s=(u=(a=n.juan_metadata)==null?void 0:a[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:Oc(e)),d=((g=(x=n.files)==null?void 0:x.find(h=>h.filename===e))==null?void 0:g.title)??i[e];if(!d)return{position:l,label:l};const c=r(d);return{position:l,label:l===d||l===c?c:`${l} ${c}`}}function id(e,n,i,r,s){const l=c=>c==="loading"?"…":typeof c=="number"&&c>0?c:void 0,p=(c,a)=>({key:c,label:a??ps(c,e,r,s).label,hint:l(i[c]),disabled:i[c]===0}),d=(c,a)=>{var x;if(c.files.length===1&&!((x=c.children)!=null&&x.length))return p(c.files[0],s(c.label));const u=Dc(c,i);return{key:`group:${a}`,label:s(c.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:cs(c),defaultExpanded:typeof u=="number"&&u>0,children:[...c.files.map(g=>p(g)),...(c.children??[]).map((g,h)=>d(g,`${a}.${h}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((c,a)=>d(c,`${a}`)):n.map(c=>p(c))}const od=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:p,activeFile:d,handleSelectFile:c,juanData:a,juanRawText:u,juanLoading:x,searchQuery:g,setSearchQuery:h,onNavigate:b,workLabelCacheRef:k,reader:m})=>{const{convert:v}=V(),[y,j]=ni(),{matchStates:$,titles:S}=nd({workId:l,transport:p,files:r,activeFile:d,activeJuan:a,activeRawText:u,query:g,isKaozhen:s}),_=as(m.resolveImages,d),w=f.useMemo(()=>id(i,r,$,S,v),[i,r,$,S,v]),z=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:g,onChange:C=>h(C.target.value)}),B=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(C=>C.vol_label)?"冊":"卷",E=d?ps(d,i,S,v).position:void 0;return t.jsxs(ii,{className:e,style:n,title:m.title??(i.title?v(i.title):void 0),subtitle:m.subtitle??v(s?"考證":"整理本"),toc:w,tocCaption:`目录 · ${r.length} ${v(B)}`,tocHeader:z,activeKey:d,onSelect:c,images:_.images,imagesLoading:_.loading,renderImageOverlay:m.renderImageOverlay,imagePanel:m.imagePanel,prefs:y,onPrefsChange:j,paragraphToggle:!s&&ln(u),allowVertical:m.allowVertical,children:[x?t.jsx(nt,{}):a?t.jsx(ed,{juan:a,rawText:u,positionLabel:E,index:i,searchQuery:g,onNavigate:b,transport:p,workLabelCache:k,prefs:y},d??""):d?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,i.references&&i.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:v("參考文獻")}),t.jsx("ol",{children:i.references.map((C,A)=>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]})]},A))})]})]})},rd={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},sd={label:"其他",color:o("desc-fg")},ld={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")}},ad={label:"待处理",color:o("warning")};function cd(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 dd(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 hi=({items:e,loading:n})=>{const i=ve();return n?t.jsx(nt,{}):e.length===0?t.jsx("div",{style:pd,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=rd[r.type]||sd,l=ld[r.status]||ad,p=typeof window<"u"&&dd(r.pageUrl,window.location.href);return t.jsxs("div",{style:ud,children:[t.jsxs("div",{style:xd,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...fo,background:s.color},children:s.label}),t.jsx("span",{style:{...fo,background:l.color},children:l.label})]}),t.jsx("span",{style:fd,children:cd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:gd,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:hn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(p?t.jsx("a",{href:r.pageUrl,style:hn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:hn,children:r.pageUrl}))]}),t.jsx("div",{style:hd,children:r.content}),r.reply&&t.jsxs("div",{style:md,children:[t.jsx("div",{style:bd,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},pd={textAlign:"center",padding:"40px 0",color:o("desc-fg"),fontSize:"14px"},ud={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"},fo={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},fd={fontSize:"12px",color:o("desc-fg")},gd={fontSize:"12px",marginBottom:"6px"},hn={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},hd={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},md={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},bd={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},Nn=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const p=ie(),[d,c]=f.useState(null),[a,u]=f.useState([]),[x,g]=f.useState("recommend"),[h,b]=f.useState([]),[k,m]=f.useState(!1),v=r??x,y=L=>{g(L),s==null||s(L)},[j,$]=f.useState(!0),[S,_]=f.useState(null),[w,z]=f.useState(null),[B,E]=f.useState(null);f.useEffect(()=>{let L=!1;if(e.getCounts)return e.getCounts().then(M=>{L||c({works:M.works,books:M.books,collections:M.collections})}).catch(()=>{}),()=>{L=!0}},[e]),f.useEffect(()=>{let L=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const P=await e.getRecommended();if(P!=null&&P.groups)return P.groups.flatMap(R=>R.items.map(ne=>({...ne,group:R.name})))}catch{}return[]})().then(async P=>{if(L)return;const R=P.filter(I=>I.id);if(R.length===0){$(!1);return}const ne=await Promise.all(R.map(async I=>{if(I.type)return{id:I.id,title:I.title,type:I.type,author:I.author,dynasty:I.dynasty,role:I.role,edition:I.edition,has_text:I.has_text,has_image:I.has_image,has_collated:I.has_collated,subtype:I.subtype,primary_name:I.primary_name,group:I.group,fallbackDescription:I.description};try{let F=null;if(e.getEntry)F=await e.getEntry(I.id);else{const K=await e.getItem(I.id);K&&(F={id:I.id,title:K.title||I.id,type:K.type||"work"})}if(F)return{...F,group:I.group,fallbackDescription:I.description}}catch{}return{id:I.id,title:I.title,type:pe.extractType(I.id),group:I.group,fallbackDescription:I.description}}));L||(u(ne.filter(I=>I!==null)),$(!1))}),()=>{L=!0}},[e,i]);const C=f.useRef(!1),A=f.useRef(!1),W=f.useRef(!1);f.useEffect(()=>{if(v!=="catalog"||C.current)return;const L=e.getCatalogProgress??e.getResourceProgress;if(!L)return;C.current=!0;let M=!1;return L.call(e).then(P=>{M||_(P)}).catch(()=>{C.current=!1}),()=>{M=!0}},[e,v]),f.useEffect(()=>{if(v!=="collection"||A.current||!e.getCollectionProgress)return;A.current=!0;let L=!1;return e.getCollectionProgress().then(M=>{L||z(M)}).catch(()=>{A.current=!1}),()=>{L=!0}},[e,v]),f.useEffect(()=>{if(v!=="site"||W.current||!e.getSiteProgress)return;W.current=!0;let L=!1;return e.getSiteProgress().then(M=>{L||E(M)}).catch(()=>{W.current=!1}),()=>{L=!0}},[e,v]),f.useEffect(()=>{if(!l||v!=="feedback")return;let L=!1;return m(!0),fetch(l).then(M=>M.json()).then(M=>{!L&&M.success&&b(M.items||[])}).catch(()=>{}).finally(()=>{L||m(!1)}),()=>{L=!0}},[l,v]);const T=L=>{switch(L){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(_t,{label:p.home.recommendTab,active:v==="recommend",onClick:()=>y("recommend")}),t.jsx(_t,{label:p.home.catalogTab,active:v==="catalog",onClick:()=>y("catalog")}),t.jsx(_t,{label:p.home.collectionTab,active:v==="collection",onClick:()=>y("collection")}),t.jsx(_t,{label:p.home.siteTab,active:v==="site",onClick:()=>y("site")}),l&&t.jsx(_t,{label:p.home.feedbackTab,active:v==="feedback",onClick:()=>y("feedback")})]}),v==="recommend"&&t.jsx(yd,{recommended:a,loading:j,onNavigate:n,getIcon:T,t:p}),v==="catalog"&&t.jsx(go,{progress:S,t:p,onNavigate:n}),v==="collection"&&t.jsx(go,{progress:w,t:p,onNavigate:n}),v==="site"&&t.jsx(vd,{progress:B,t:p,totalWorks:(d==null?void 0:d.works)??0}),v==="feedback"&&l&&t.jsx(hi,{items:h,loading:k})]})})},_t=({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}),yd=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=ve();if(n)return t.jsx(nt,{});if(e.length===0)return null;const p=new Map;for(const d of e){const c=d.group||s.home.recommendedBrowse;p.has(c)||p.set(c,[]),p.get(c).push(d)}return t.jsx(t.Fragment,{children:Array.from(p.entries()).map(([d,c])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:d}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(a=>{const u=a.dynasty||a.author?`${a.dynasty?`〔${a.dynasty}〕`:""}${a.author||""}`:a.fallbackDescription;return t.jsxs("a",{href:l(a.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),i==null||i(a.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(a.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[a.title,a.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:a.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},a.id)})})]},d))})},go=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(nt,{});const r=[...e.resources].sort((d,c)=>d.priority-c.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},p={in_progress:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(d=>{const c=r.filter(a=>a.status===d);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:p[d]}}),l[d]," (",c.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(a=>t.jsx(jd,{item:a,t:n,statusColor:p[d],onNavigate:i},a.id))})]},d)})})},jd=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=ve(),l=e.total>0?Math.round(e.imported/e.total*100):0,p=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 d=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:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:a=>a.currentTarget.style.borderBottomStyle="solid",onMouseLeave:a=>a.currentTarget.style.borderBottomStyle="dashed",children:d}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:d}):d})()}),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:p})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Lt(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})]})},vd=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(nt,{});const r=[...e.resources].sort((c,a)=>c.priority-a.priority),s=r.filter(c=>c.imported>0),l=r.filter(c=>c.imported===0),p=s.reduce((c,a)=>Math.max(c,a.imported),0),d=i>0?Math.round(p/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:p.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",d,"%)"]}),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(ho,{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(ho,{item:c,t:n,totalWorks:i},c.id))})]})]})},ho=({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 kd(){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 Sd=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var M;const l=ie(),{convert:p}=V(),d=kd(),[c,a]=f.useState(null),[u,x]=f.useState(null),[g,h]=f.useState(!1),[b,k]=f.useState("detail"),[m,v]=f.useState([]),[y,j]=f.useState(!1),[$,S]=f.useState(null),[_,w]=f.useState(!1),z=f.useCallback(async P=>{if(!e.getCollatedEditionIndex){S(null);return}w(!0);try{const R=await e.getCollatedEditionIndex(P);S(R)}catch{S(null)}finally{w(!1)}},[e]),B=f.useCallback(async P=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){v([]);return}j(!0);try{if(e.getCollectionCatalogs){const R=await e.getCollectionCatalogs(P);v(R||[])}else if(e.getCollectionCatalog){const R=await e.getCollectionCatalog(P);v(R?[{resource_id:"",data:R}]:[])}}catch{v([])}finally{j(!1)}},[e]),E=f.useCallback(async P=>{if(i){i(P);return}a(P),x(null),v([]),S(null),k("detail"),h(!0);try{const R=await e.getItem(P.id);R&&(x(R),R.type==="collection"?B(P.id):R.type==="work"&&R.has_collated&&z(P.id))}catch(R){console.error("加载详情失败:",R)}finally{h(!1)}},[e,i,B,z]),C=f.useCallback(async P=>{x(null),v([]),S(null),k("detail"),h(!0);try{const R=await e.getItem(P);R&&(x(R),a({id:P,title:R.title||P,type:R.type||"book"}),R.type==="collection"?B(P):R.type==="work"&&R.has_collated&&z(P))}catch(R){console.error("导航失败:",R)}finally{h(!1)}},[e,B,z]),A=(u==null?void 0:u.type)==="collection"&&(m.length>0||y)||(u==null?void 0:u.type)==="work"&&($||_),W=d&&(g||u),T=f.useCallback(()=>{a(null),x(null),v([]),S(null),k("detail")},[]),L=t.jsx(t.Fragment,{children:g?t.jsx(nt,{}):u?t.jsxs(t.Fragment,{children:[(A||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${o("widget-border")}`,padding:d?"0 12px":"0 48px",background:o("input-bg"),flexShrink:0,overflowX:d?"auto":void 0},children:[A&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>k("detail"),style:Vt(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&y&&m.length===0&&t.jsxs("button",{onClick:()=>{},style:Vt(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&m.map(P=>t.jsx("button",{onClick:()=>k(`catalog:${P.resource_id}`),style:Vt(b===`catalog:${P.resource_id}`),children:P.short_name?`${p(P.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},P.resource_id)),u.type==="work"&&($||_)&&t.jsxs("button",{onClick:()=>k("collated"),style:Vt(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:d?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?t.jsx(Vn,{data:u,transport:e,onNavigate:C}):b.startsWith("catalog:")?t.jsx(Yn,{data:(M=m.find(P=>`catalog:${P.resource_id}`===b))==null?void 0:M.data,onNavigate:C}):b==="collated"?t.jsx(gi,{index:$||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(Nn,{transport:e,onNavigate:C,recommendedIds:r})});return d?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:W?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:T,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:L})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(wn,{transport:e,onEntryClick:E,hideModeIndicator:n}),!u&&t.jsx(Nn,{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(wn,{transport:e,onEntryClick:E,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:L})]})};function Vt(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 Ye(e){return e.replace(/\.md$/,"")}function wd(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 bo={padding:24,color:o("desc-fg")},Bn=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:p,onVersionChange:d,title:c,subtitle:a,resolveImages:u,renderImageOverlay:x,imagePanel:g,allowVertical:h,className:b,style:k})=>{const[m,v]=f.useState(e??null),[y,j]=f.useState(!1),[$,S]=f.useState(null),_=r!==void 0?r:$,w=f.useCallback(F=>{s?s(F):S(F)},[s]),[z,B]=f.useState(null),[E,C]=f.useState(!1);f.useEffect(()=>{e&&v(e)},[e]),f.useEffect(()=>{if(e)return;v(null),j(!1);const F=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!F){j(!0);return}let K=!1;return Promise.resolve().then(F).then(G=>{K||(G?v(G):j(!0))}).catch(()=>{K||j(!0)}),()=>{K=!0}},[n,i,e,l]),f.useEffect(()=>{if(!m||m.chapters.length===0)return;const F=Ye(m.chapters[0].file);if(!_){w(F);return}const K=Ye(_);m.chapters.some(U=>Ye(U.file)===K)||w(F)},[m,_,w]);const A=f.useMemo(()=>{if(!m||!_)return null;const F=Ye(_);return m.chapters.find(K=>Ye(K.file)===F)??null},[m,_]);f.useEffect(()=>{if(!n||!A)return;const F=l!==void 0?i.getWorkFullTextChapter?G=>i.getWorkFullTextChapter(n,l,G):null:i.getBookFullTextChapter?G=>i.getBookFullTextChapter(n,G):null;if(!F)return;let K=!1;return C(!0),B(null),Promise.resolve(A.file).then(F).then(G=>{K||B(G)}).catch(()=>{K||B(null)}).finally(()=>{K||C(!1)}),()=>{K=!0}},[n,A,i,l]);const W=as(u,A?Ye(A.file):null),[T,L]=ni(),{convert:M}=V(),P=p&&p.length>1&&d?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:F=>d(F.target.value),children:p.map(F=>t.jsx("option",{value:F.key,children:wd(F)},F.key))})]}):null;if(!m)return t.jsxs("div",{style:bo,children:[P&&t.jsx("div",{style:{marginBottom:12},children:P}),y?"无法加载全文目录":"加载全文目录…"]});if(m.chapters.length===0)return t.jsxs("div",{style:bo,children:[P&&t.jsx("div",{style:{marginBottom:12},children:P}),"全文目录为空"]});const R=m.chapters.map(F=>({key:Ye(F.file),label:M(F.title)})),ne=Zr(m)||zn(m),I=z?z.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(ii,{title:c??M(m.version_label),subtitle:a??"全文",toc:R,tocCaption:`目录 · ${m.chapters.length} ${m.chapters.length>1?"卷":"篇"}`,activeKey:_?Ye(_):null,onSelect:w,images:W.images,imagesLoading:W.loading,renderImageOverlay:x,imagePanel:g,prefs:T,onPrefsChange:L,paragraphToggle:ln(I),allowVertical:h,className:b,style:k,children:[A&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:M(A.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:m.source.url,target:"_blank",rel:"noreferrer",children:M(m.source.name)}),m.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),m.source.license]}),P&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),P]})]})]}),E&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!E&&I!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(ci,{text:I,mode:T.readingMode,tables:ne,gujiMarkdown:zn(m),properNames:T.properNames})}),!E&&!z&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},_d=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=ie(),{convert:l}=V(),[p,d]=f.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[c,a]=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(x=>t.jsx($d,{division:x,expanded:p===x.name,onToggle:()=>d(p===x.name?null:x.name),expandedCat:c,onCatToggle:g=>a(c===g?null:g),onNavigate:n},x.name))})]})},$d=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:p}=V(),d=e.categories.reduce((c,a)=>{const u=a.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:p(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg")},children:[e.categories.length," 類 · ",d," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(c=>{const a=`${e.name}/${c.name}`;return t.jsx(zd,{category:c,expanded:r===a,onToggle:()=>s(a),onNavigate:l},c.name)})})]})},zd=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var c,a,u,x;const{convert:s}=V(),l=((c=e.books)==null?void 0:c.zhulu)||[],p=((a=e.books)==null?void 0:a.cunmu)||[],d=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((x=e.stats)==null?void 0:x.cunmu)||p.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:[d," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||p.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(yo,{label:"著錄",books:l,onNavigate:r}),p.length>0&&t.jsx(yo,{label:"存目",books:p,onNavigate:r})]})]})},yo=({label:e,books:n,onNavigate:i})=>{const{convert:r}=V(),s=ve(),[l,p]=f.useState(n.length<=20),d=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:d.map((c,a)=>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)})]},a))}),!l&&t.jsxs("button",{onClick:()=>p(!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," 條"]})]})},Ee=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=ie();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:Id,children:"AI"}),n&&t.jsx("button",{onClick:n,style:Cd,children:l.action.save})]})]}),s]})},Cd={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Id={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},ze=({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"}})]}),Xe=({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"}})},Zt=({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 Td(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Yt=({value:e,onChange:n,label:i})=>{const[r,s]=f.useState(!1),l=f.useRef(null),p=Td(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&p?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:jo,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:p.name}),t.jsx(Zt,{children:p.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:jo,children:i}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:d=>n(d.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"}})]})},jo={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function Rd(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function Ed(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const us=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=ie(),[s,l]=f.useState(null),p=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},d=x=>{n(e.filter((g,h)=>h!==x)),s===x&&l(null)},c=(x,g,h)=>{const b=[...e];b[x]={...b[x],[g]:h},n(b)},a=(x,g)=>{const h=[...e];h[x]={...h[x],type:g,id:"",name:""},n(h),g==="bookID"&&i&&i(b=>{const k=[...e];k[x]={...k[x],id:b.id,name:b.title,type:"bookID"},n(k)})},u=x=>{i&&i(g=>{const h=[...e];h[x]={...h[x],id:g.id,name:g.title,type:"bookID"},n(h)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((x,g)=>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===g?null:g),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:o("fg")},children:x.name||`${r.editor.sourcePlaceholder} ${g+1}`}),x.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Rd(x.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:Ed(x.type)}),t.jsx("button",{onClick:h=>{h.stopPropagation(),d(g)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===g&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>a(g,"bookID"),style:{...vo,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:()=>a(g,"url"),style:{...vo,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})]})]})]}),x.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:He,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const h=[...e];h[g]={...h[g],type:"",id:"",name:""},n(h)},style:ko,children:r.action.changeType})]}),x.id&&x.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:x.name}),t.jsx("code",{style:{fontSize:"11px",background:o("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),t.jsx("button",{onClick:()=>u(g),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(g),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})]})]})}),x.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:He,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const h=[...e];h[g]={...h[g],type:"",id:"",name:""},n(h)},style:ko,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:x.name,onChange:h=>c(g,"name",h.target.value),placeholder:r.editor.sourceNamePlaceholder,style:st})]}),t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:x.id,onChange:h=>c(g,"id",h.target.value),placeholder:"https://...",style:st})]})]}),x.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:{...He,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:He,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:x.details,onChange:h=>c(g,"details",h.target.value),placeholder:r.editor.detailsPlaceholder,style:st})]}),t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:x.position,onChange:h=>c(g,"position",h.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:He,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:x.version,onChange:h=>c(g,"version",h.target.value),placeholder:"如: v1.0, 2024-01",style:st})]}),t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:x.processor_version,onChange:h=>c(g,"processor_version",h.target.value),placeholder:"如: v0.1",style:st})]})]})]})]})})]},g)),t.jsxs("button",{onClick:p,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})]})]})},He={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"},vo={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"},ko={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function xs(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 gs=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:p,childWorks:d,childCollections:c,containedBooks:a,siblingBooks:u,onLinkEntity:x,onUnlinkEntity:g,onViewEntity:h,onCreateAndLink:b,onSaveRelations:k})=>{const m=ie();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:m.section.relations})]}),k&&t.jsx("button",{onClick:k,style:Ld,children:m.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx($t,{direction:"up",title:m.relation.belongsToWork,entity:l,onView:h,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),t.jsx($t,{direction:"up",title:m.relation.containedInCollection,entity:p,onView:h,onUnlink:()=>g("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),l&&u&&u.length>0&&t.jsx(lt,{direction:"horizontal",title:`${m.relation.siblingVersions} (${u.length})`,entities:u,onView:h,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:m.relation.addVersionForWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx($t,{direction:"up",title:m.relation.parentWork,entity:r,onView:h,onUnlink:()=>g("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),d&&d.length>0&&t.jsx(lt,{direction:"down",title:`${m.relation.childWorks} (${d.length})`,entities:d,onView:h,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:m.action.addSubWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),c&&c.length>0&&t.jsx(lt,{direction:"down",title:`${m.relation.collectionImpl} (${c.length})`,entities:c,onView:h,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:m.action.addCollectionImpl,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),t.jsx(lt,{direction:"down",title:`${m.relation.allVersions} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:h,onAdd:()=>b("childBook","book",{workId:n}),addLabel:m.action.addVersion,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx($t,{direction:"up",title:m.relation.correspondingWork,entity:l,onView:h,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),t.jsx($t,{direction:"up",title:m.relation.parentCollection,entity:s,onView:h,onUnlink:()=>g("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),t.jsx(lt,{direction:"down",title:`${m.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:h,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:m.action.addSubCollection,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),t.jsx(lt,{direction:"down",title:`${m.relation.containedBooks} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:h,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:m.action.addBook,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]})]})]})},$t=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:p,linkLabel:d,createLabel:c,notLinkedLabel:a,viewLabel:u,unlinkLabel:x})=>{const g=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),h=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:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:h}),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:hs(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(So,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(So,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:a}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(Wn,{onClick:l,children:d}),t.jsx(Wn,{onClick:p,primary:!0,children:c})]})]})},lt=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:p,expandMoreLabel:d})=>{const[c,a]=f.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),x=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",g=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:x}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(h=>t.jsxs("div",{onClick:()=>r(h),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:o("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:hs(h.type)}),t.jsx("span",{children:h.title})]},h.id)),i.length>5&&!c&&t.jsxs("div",{onClick:()=>a(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:o("link-fg"),cursor:"pointer"},children:[d," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:p}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(Wn,{onClick:s,primary:!0,children:["+ ",l]})})]})},So=({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}),Wn=({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 hs(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Ld={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},ms=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:p,onSearch:d,isLoading:c,excludeId:a})=>{const[u,x]=f.useState(""),g=a?p.filter(m=>m.id!==a):p;f.useEffect(()=>{e&&(x(""),d(""))},[e]);const h=m=>{x(m),d(m)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",k=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:Nd,children:t.jsxs("div",{style:Bd,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:Wd,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:m=>h(m.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:Ad})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:mn,children:"搜索中..."}):g.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(m=>t.jsxs("div",{onClick:()=>r(m),style:Md,children:[t.jsx("span",{style:{fontSize:"16px"},children:k}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[m.title,m.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:m.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[m.id,m.author&&` · ${m.author}`,m.dynasty&&` · ${m.dynasty}`]})]})]},m.id))}):u?t.jsxs("div",{style:mn,children:["未找到匹配的",b]}):t.jsxs("div",{style:mn,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:Fd,children:["创建新",b,"并关联"]})]})]})})},Nd={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Bd={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")},Wd={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Ad={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"},Md={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:o("primary-soft")},mn={padding:"20px",textAlign:"center",color:o("desc-fg")},Fd={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},wo={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Pd={work:"📜",book:"📖",collection:"📚",entity:"👤"},bs=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[p,d]=f.useState(""),c=f.useRef(null);f.useEffect(()=>{e&&(d((r==null?void 0:r.title)||""),setTimeout(()=>{var g,h;(g=c.current)==null||g.focus(),(h=c.current)==null||h.select()},100))},[e,r==null?void 0:r.title]);const a=g=>{g.key==="Enter"&&p.trim()?u():g.key==="Escape"&&l()},u=()=>{p.trim()&&s(p.trim(),{...r,title:p.trim()})};if(!e)return null;const x=()=>{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`创建新${wo[n]}`}};return t.jsx("div",{style:Od,onClick:g=>{g.target===g.currentTarget&&l()},children:t.jsxs("div",{style:Dd,onClick:g=>g.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Pd[n]}),t.jsx("span",{children:x()})]}),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:p,onChange:g=>d(g.target.value),onKeyDown:a,placeholder:`请输入${wo[n]}名称...`,style:Hd})]}),((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:Gd,children:"取消"}),t.jsx("button",{onClick:u,disabled:!p.trim(),style:{...Ud,opacity:p.trim()?1:.6,cursor:p.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Od={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Dd={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")},Hd={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"},Gd={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Ud={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function Vd(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function ys(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Yd(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 js=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:p,onSelect:d,onCancel:c,onCreate:a,onSearch:u})=>{const[x,g]=f.useState(""),[h,b]=f.useState([]),[k,m]=f.useState(!1),[v,y]=f.useState("recent");f.useEffect(()=>{e&&(g(""),b([]),y(r.length>0?"recent":"search"))},[e,r.length]),f.useEffect(()=>{if(!x.trim()){b([]);return}const z=setTimeout(async()=>{m(!0);try{b(await u(x,i))}catch{b([])}finally{m(!1)}},300);return()=>clearTimeout(z)},[x,i,u]);const j=f.useCallback(z=>{g(z.target.value),z.target.value.trim()&&y("search")},[]),$=f.useCallback(z=>s?z.filter(B=>B.id!==s):z,[s]);if(!e)return null;const S=n||(i==="all"?"选择实体":`选择${ys(i)}`),_=$(r),w=$(h);return t.jsx("div",{style:qd,children:t.jsxs("div",{style:Jd,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:Zd,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:x,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Xd}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),k&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),_.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs(_o,{active:v==="recent",onClick:()=>y("recent"),children:["最近使用 (",_.length,")"]}),t.jsxs(_o,{active:v==="search",onClick:()=>y("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:v==="recent"&&_.length>0?t.jsx($o,{entities:_,onSelect:d}):x.trim()?k?t.jsx(bn,{message:"搜索中..."}):w.length>0?t.jsx($o,{entities:w,onSelect:d}):t.jsx(bn,{message:"未找到匹配的结果"}):t.jsx(bn,{message:"输入关键词开始搜索"})}),l&&a&&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:a,style:Qd,children:p||"创建新实体"})]})]})})},_o=({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}),$o=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(Kd,{entity:i,onClick:()=>n(i)},i.id))}),Kd=({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:Vd(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:Yd(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:ys(e.type)})]})},bn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),qd={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Jd={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")},Zd={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Xd={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"},Qd={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},ep={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},tp={work:"📜",collection:"📚",book:"📖",entity:"👤"},vs=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:p,onAskAI:d,renderSectionActions:c,onDownloadResource:a,downloadStatuses:u,relations:x,onRelationsChange:g})=>{var q;const h=ie(),[b,k]=f.useState(!1),[m,v]=f.useState("work"),[y,j]=f.useState(""),[$,S]=f.useState(""),[_,w]=f.useState([]),[z,B]=f.useState(!1),[E,C]=f.useState(!1),[A,W]=f.useState("work"),[T,L]=f.useState(""),[M,P]=f.useState(),[R,ne]=f.useState(!1),[I,F]=f.useState(null),[K,G]=f.useState([]);f.useRef(null);const U=e.type,te=U==="work",O=U==="collection",Y=U==="book",Z=f.useCallback((N,ee)=>{n({...e,[N]:ee})},[e,n]),X=f.useCallback((N,ee)=>{j(N),v(ee),S(h.editor.selectToLink+h.indexType[ee]),w([]),k(!0)},[h]),se=f.useCallback(N=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,N)},[r,e.id]),ge=f.useCallback(N=>{s==null||s(N.id,N.type)},[s]),he=f.useCallback((N,ee,re)=>{const be={...re,author:(re==null?void 0:re.author)||e.author,dynasty:re==null?void 0:re.dynasty};W(ee),L(N),P(be),C(!0)},[e.author]),D=f.useCallback((N,ee)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,T,{type:A,title:N,inheritData:ee}),C(!1)},[r,e.id,T,A]),le=f.useCallback(N=>{if(!N.trim()){w([]);return}B(!0),r!=null&&r.searchEntities&&r.searchEntities(N,m).then(ee=>{w(ee),B(!1)}).catch(()=>{w([]),B(!1)})},[r,m]),oe=f.useCallback(N=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,y,N.id),k(!1)},[r,e.id,y]),ce=f.useCallback(()=>{i()},[i]),ue=f.useCallback(N=>{F(()=>N),ne(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(G).catch(()=>{})},[r]),me=f.useCallback((N,ee)=>r!=null&&r.searchEntities?r.searchEntities(N,ee==="all"?void 0:ee):Promise.resolve([]),[r]),Q=f.useCallback(N=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(N),G(ee=>[N,...ee.filter(re=>re.id!==N.id)].slice(0,10)),I==null||I(N),ne(!1),F(null)},[r,I]);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:tp[U]}),t.jsx("span",{children:e.title||h.editor.untitled}),t.jsx(Zt,{children:e.id}),t.jsx(Zt,{color:ep[U],children:h.indexType[U]})]})}),t.jsx(Ee,{title:h.section.basicInfo,onSave:i,onAskAI:d?()=>d("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(Yt,{label:te?h.editor.workTitle:O?h.editor.collectionTitle:h.editor.bookTitle,value:e.title,onChange:N=>Z("title",N)}),Y&&t.jsx(Yt,{label:h.editor.belongsToWork,value:e.workName||"",onChange:N=>Z("workName",N)}),t.jsx(ze,{label:h.editor.authorLabel,value:e.author||"",onChange:N=>Z("author",N)}),t.jsx(ze,{label:h.editor.publicationYearLabel,value:e.publicationYear||"",onChange:N=>Z("publicationYear",N)}),(Y||O)&&t.jsx(Yt,{label:h.editor.containedIn,value:e.collection||"",onChange:N=>Z("collection",N)}),(Y||O)&&t.jsx(ze,{label:h.editor.holderLabel,value:e.holder||"",onChange:N=>Z("holder",N)}),(Y||O)&&t.jsx(ze,{label:Y?h.editor.pageLabel:h.editor.volumeLabel,value:e.pages||"",onChange:N=>Z("pages",N)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(ze,{label:h.editor.firstImageLabel,value:e.firstImage||"",onChange:N=>Z("firstImage",N)})})]})}),t.jsx(Ee,{title:h.section.description,onSave:i,onAskAI:d?()=>d("介绍"):void 0,children:t.jsx(Xe,{value:e.description||"",onChange:N=>Z("description",N),placeholder:h.editor.descriptionPlaceholder})}),(((q=e.additional_works)==null?void 0:q.length)||0)>0&&t.jsx(Ee,{title:h.section.additionalWorks,onSave:i,children:t.jsx(np,{items:e.additional_works||[],onChange:N=>Z("additional_works",N)})}),t.jsx(Ee,{title:h.section.indexedBy,onSave:i,onAskAI:d?()=>d("收录于"):void 0,children:t.jsx(ip,{items:e.indexed_by||[],onChange:N=>Z("indexed_by",N)})}),t.jsx(Ee,{title:h.section.emendatedBy,onSave:i,onAskAI:d?()=>d("考证"):void 0,children:t.jsx(op,{items:e.emendated_by||[],onChange:N=>Z("emendated_by",N)})}),t.jsx(Ee,{title:h.section.textResources,onSave:i,onAskAI:d?()=>d("资源"):void 0,children:t.jsx(Sn,{items:e.resources||[],onChange:N=>Z("resources",N),onDownload:a,downloadStatuses:u,filterType:"text"})}),t.jsx(Ee,{title:h.section.imageResources,onSave:i,children:t.jsx(Sn,{items:e.resources||[],onChange:N=>Z("resources",N),onDownload:a,downloadStatuses:u,filterType:"image"})}),t.jsx(Ee,{title:h.section.sources,onSave:i,onAskAI:d?()=>d("资料来源"):void 0,children:t.jsx(us,{items:xs(e.sources||""),onChange:N=>Z("sources",fs(N)),onOpenEntityPicker:ue})}),(Y||O)&&t.jsx(Ee,{title:h.section.provenance,onSave:i,onAskAI:d?()=>d("收藏历史"):void 0,children:t.jsx(Xe,{value:e.provenance||"",onChange:N=>Z("provenance",N),placeholder:h.editor.provenancePlaceholder})}),Y&&t.jsx(Ee,{title:h.section.otherEditions,onSave:i,onAskAI:d?()=>d("其他版本"):void 0,children:t.jsx(Xe,{value:e.otherEditions||"",onChange:N=>Z("otherEditions",N),placeholder:h.editor.otherEditionsPlaceholder})}),t.jsx(gs,{entityType:U,entityId:e.id,entityTitle:e.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:X,onUnlinkEntity:se,onViewEntity:ge,onCreateAndLink:he,onSaveRelations:ce}),l&&p&&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:h.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"12px"},children:h.editor.dangerZoneDesc}),t.jsx("button",{onClick:p,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("danger")}`,borderRadius:"4px",background:"transparent",color:o("danger"),cursor:"pointer"},children:h.editor.deleteEntity})]}),t.jsx(ms,{isOpen:b,entityType:m,title:$,onSelect:oe,onCancel:()=>k(!1),onCreate:()=>{k(!1),he(y,m)},searchResults:_,onSearch:le,isLoading:z,excludeId:e.id}),t.jsx(bs,{isOpen:E,entityType:A,relationField:T,inheritData:M,onConfirm:D,onCancel:()=>C(!1)}),t.jsx(js,{isOpen:R,title:h.action.selectBookOrWork,filterType:"all",recentEntities:K,excludeId:e.id,onSelect:Q,onCancel:()=>{ne(!1),F(null)},onSearch:me})]})};function np({items:e,onChange:n}){const i=ie(),r=(p,d,c)=>{const a=e.map((u,x)=>x===p?{...u,[d]:c}:u);n(a)},s=p=>n(e.filter((d,c)=>c!==p)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((p,d)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(ze,{label:i.editor.bookNameLabel,value:p.book_title,onChange:c=>r(d,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(ze,{label:i.label.juanCount,value:p.n_juan!=null?String(p.n_juan):"",onChange:c=>r(d,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(d),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("muted"),marginTop:"18px"},children:"✕"})]},d)),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 ks({items:e,onChange:n,showMeta:i,addLabel:r}){const s=ie(),[l,p]=f.useState(null),d=(u,x,g)=>{const h=e.map((b,k)=>k===u?{...b,[x]:g||void 0}:b);n(h)},c=u=>{n(e.filter((x,g)=>g!==u)),l===u&&p(null)},a=()=>{n([...e,{source:""}]),p(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,x)=>{const g=l===x;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:g?`color-mix(in srgb, ${o("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>p(g?null:x),children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.2s",transform:g?"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:h=>{h.stopPropagation(),c(x)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${o("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:o("muted")},children:"✕"})]}),!g&&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]}),g&&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(ze,{label:s.label.sourceName,value:u.source,onChange:h=>d(x,"source",h)}),t.jsx(ze,{label:s.label.sourceBid,value:u.source_bid||"",onChange:h=>d(x,"source_bid",h)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(ze,{label:s.label.titleInfo,value:u.title_info||"",onChange:h=>d(x,"title_info",h)}),t.jsx(ze,{label:s.label.authorInfo,value:u.author_info||"",onChange:h=>d(x,"author_info",h)})]}),t.jsx(ze,{label:s.label.edition,value:u.edition||"",onChange:h=>d(x,"edition",h)})]}),t.jsx(Xe,{value:u.summary||"",onChange:h=>d(x,"summary",h),placeholder:s.editor.summaryPlaceholder}),t.jsx(Xe,{value:u.comment||"",onChange:h=>d(x,"comment",h),placeholder:s.editor.commentPlaceholder}),t.jsx(Xe,{value:u.additional_comment||"",onChange:h=>d(x,"additional_comment",h),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),t.jsx("button",{onClick:a,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 ip({items:e,onChange:n}){const i=ie();return t.jsx(ks,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function op({items:e,onChange:n}){const i=ie();return t.jsx(ks,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function Ss(e){var d,c,a,u,x,g,h;const n=((c=(d=e.authors)==null?void 0:d[0])==null?void 0:c.name)||"",i=((a=e.publication_info)==null?void 0:a.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(x=e.page_count)!=null&&x.number?String(e.page_count.number):((g=e.page_count)==null?void 0:g.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",p={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(m=>m.relation==="part_of");k&&(p.parentWorkId=k.id,p.parentWorkName=k.title)}}if(e.type==="book"){const b=e;p.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(p.collectionId=(h=b.contained_in[0])==null?void 0:h.id)}return p}function rp(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 sp=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:p,onSave:d,onDelete:c,onNavigate:a,renderLink:u,onAskAI:x,renderSectionActions:g,onDownloadResource:h,downloadStatuses:b,relations:k,onRelationsChange:m,headerExtra:v,className:y,style:j}=e;ie();const[$,S]=f.useState(s),_=l?s:$;f.useEffect(()=>{s!==$&&S(s)},[s]);const w=f.useCallback(()=>{const T=_==="view"?"edit":"view";l?l(T):S(T)},[_,l]),[z,B]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(T=>{T&&B(T)})},[i,r]);const E=n||z,C=f.useMemo(()=>E?Ss(E):null,[E]),A=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,W=t.jsxs(t.Fragment,{children:[A,v]});return!E&&!C?t.jsx(nt,{}):_==="view"?t.jsx(Vn,{data:E,transport:r,onNavigate:a?T=>a(T):void 0,renderLink:u,headerExtra:W,className:y,style:j}):C?t.jsxs("div",{className:y,style:j,children:[W&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:W}),t.jsx(vs,{data:C,onChange:p||(()=>{}),onSave:d||(()=>{}),transport:r,onNavigate:a,showDelete:!!c,onDelete:c,onAskAI:x,renderSectionActions:g,onDownloadResource:h,downloadStatuses:b,relations:k,onRelationsChange:m})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},zo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],ws=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,l]=f.useState(null),[p,d]=f.useState(""),[c,a]=f.useState(""),[u,x]=f.useState("idle"),[g,h]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{e&&(l(null),d(""),a(""),x("idle"),h(""))},[e]),f.useEffect(()=>{s&&setTimeout(()=>{var y;return(y=b.current)==null?void 0:y.focus()},100)},[s]),f.useEffect(()=>{if(u==="success"){const y=setTimeout(n,2e3);return()=>clearTimeout(y)}},[u,n]),f.useEffect(()=>{if(!e)return;const y=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[e,n]);const k=async()=>{if(!(!s||!p.trim())){x("submitting"),h("");try{await i({type:s,content:p.trim(),...c.trim()?{contact:c.trim()}:{}}),x("success")}catch(y){x("error"),h(y instanceof Error?y.message:"提交失败,请稍后重试")}}};if(!e)return null;const m=s&&p.trim()&&u!=="submitting",v=zo.find(y=>y.value===s);return t.jsx("div",{style:lp,onClick:y=>{y.target===y.currentTarget&&n()},children:t.jsxs("div",{style:ap,onClick:y=>y.stopPropagation(),children:[t.jsxs("div",{style:cp,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:dp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:gp,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:zo.map(y=>t.jsxs("button",{onClick:()=>l(y.value),style:{...pp,...s===y.value?up:{}},children:[t.jsx("span",{children:y.icon})," ",y.label]},y.value))}),t.jsx("textarea",{ref:b,value:p,onChange:y=>d(y.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...xp,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:c,onChange:y=>a(y.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:mp}),t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[p.length," / 2000"]}),u==="error"&&t.jsx("div",{style:hp,children:g}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:k,disabled:!m,style:{...fp,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},lp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ap={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},cp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},dp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:o("desc-fg"),padding:"4px 8px",borderRadius:"4px"},pp={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"},up={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},xp={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"},fp={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},gp={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},hp={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginBottom:"12px"},mp={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"},An="--bim-feedback-fab-offset",Mn=48,bp=16,yp=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,p]=f.useState(!1),d=n.bottom??24;return f.useEffect(()=>{if(r||typeof document>"u")return;const c=document.documentElement;return c.style.setProperty(An,`calc(${d+Mn+bp}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(An)}},[r,d]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>p(!0),style:{...jp,zIndex:s??o("feedback-fab-z"),bottom:`calc(${d}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(ws,{isOpen:l,onClose:()=>p(!1),onSubmit:e,feedbackListUrl:i})]})},jp={position:"fixed",width:`${Mn}px`,height:`${Mn}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"},Co=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],_s=({onSubmit:e})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[l,p]=f.useState(""),[d,c]=f.useState("idle"),[a,u]=f.useState(""),x=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var k;return(k=x.current)==null?void 0:k.focus()},100)},[n]);const g=async()=>{if(!(!n||!r.trim())){c("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),c("success"),s(""),p(""),i("bug")}catch(k){c("error"),u(k instanceof Error?k.message:"提交失败,请稍后重试")}}},h=n&&r.trim()&&d!=="submitting",b=Co.find(k=>k.value===n);return d==="success"?t.jsx("div",{style:Io,children:t.jsxs("div",{style:_p,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>c("idle"),style:$p,children:"继续提交"})]})}):t.jsxs("div",{style:Io,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Co.map(k=>t.jsxs("button",{onClick:()=>i(k.value),style:{...vp,...n===k.value?kp:{}},children:[t.jsx("span",{children:k.icon})," ",k.label]},k.value))}),t.jsx("textarea",{ref:x,value:r,onChange:k=>s(k.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:d==="submitting",style:{...Sp}}),t.jsx("input",{type:"text",value:l,onChange:k=>p(k.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:d==="submitting","aria-label":"联系方式(选填)",style:Cp}),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:g,disabled:!h,style:{...wp,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:d==="submitting"?"提交中...":"提交"})]}),d==="error"&&t.jsx("div",{style:zp,children:a})]})},Io={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},vp={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"},kp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},Sp={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"},wp={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},_p={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},$p={background:"none",border:"none",color:o("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},zp={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginTop:"8px"},Cp={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 To(e){return typeof e=="function"?e():e??"/api/feedback"}const $s=({resourceId:e,apiUrl:n})=>{const[i,r]=f.useState([]),[s,l]=f.useState(!0),p=f.useCallback(async()=>{const c=To(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(()=>{p()},[p]);const d=async c=>{const a=To(n),u=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...c,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const x=await u.json().catch(()=>null);throw new Error((x==null?void 0:x.error)||"提交失败")}setTimeout(()=>p(),500)};return t.jsxs("div",{children:[t.jsx(hi,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(_s,{onSubmit:d})})]})},Ro={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 Ip(e){return e?Ro[e]??e:Ro.related}const Tp={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function Rp(e){return Tp[e]??e}const Ep={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function mi(e){return Ep[e]??""}function bi({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,p)=>{const d=Zn(l.role);return t.jsxs(f.Fragment,{children:[p>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Pe,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:i,dense:!0}):r(l.name),d&&t.jsx("span",{style:{marginLeft:4},children:r(d)})]},p)})}):null}const Eo=12,Lp=60,zs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:p,railLinks:d})=>{var se,ge,he;const c=ie(),{convert:a}=V(),u=f.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[x,g]=f.useState(new Map),[h,b]=f.useState(!1),[k,m]=f.useState(""),[v,y]=f.useState(!1),j=u.length<=Lp,$=j||h||!!k||v,S=f.useMemo(()=>$?u:u.slice(0,Eo),[u,$]);f.useEffect(()=>{if(!n||S.length===0)return;const D=S.filter(oe=>!x.has(oe));if(D.length===0)return;let le=!1;return Promise.all(D.map(oe=>n.getItem(oe).then(ce=>{const ue=ce??{};return[oe,{id:oe,title:ue.title,edition:ue.edition,resources:ue.resources,publication_info:ue.publication_info,current_location:ue.current_location,lineage:ue.lineage,measure_info:ue.measure_info}]}).catch(()=>[oe,{id:oe}]))).then(oe=>{le||g(ce=>{const ue=new Map(ce);for(const[me,Q]of oe)ue.set(me,Q);return ue})}),()=>{le=!0}},[n,S,x]);const _=f.useMemo(()=>u.map(D=>x.get(D)??{id:D}),[u,x]),w=u.length>0&&u.every(D=>x.has(D)),z=!!n&&S.some(D=>!x.has(D)),B=j||$,E=f.useMemo(()=>br(_,e.version_graph,{era:k,scanOnly:v,sort:B?"year":"default"}),[_,e.version_graph,k,v,B]),C=h?E.rows:E.rows.slice(0,Eo),A=E.allRows.filter(D=>D.hasImage).length,W=e.related_works||[],T=W.filter(D=>D.relation==="collected_in"),L=f.useMemo(()=>{const D=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],le=oe=>{const ce=D.indexOf(oe??"");return ce<0?D.length:ce};return W.filter(oe=>oe.relation!=="collected_in").map((oe,ce)=>({r:oe,i:ce})).sort((oe,ce)=>le(oe.r.relation)-le(ce.r.relation)||oe.i-ce.i).map(oe=>oe.r)},[W]),M=f.useMemo(()=>{const D=nn(e.resources,e.resource_groups);return[...D.mirrors.flatMap(le=>le.items.map(oe=>({r:oe,kind:a(le.label)}))),...D.buckets.flatMap(le=>le.items.map(oe=>({r:oe,kind:a(mi(le.key))})))]},[e.resources,e.resource_groups,a]),P=e.indexed_by||[],R=e.emendated_by||[],ne=f.useMemo(()=>{var ee,re,be;const D=[],le=(re=(ee=e.authors)==null?void 0:ee[0])==null?void 0:re.dynasty;le&&D.push({label:"成書",value:a(le)});const oe=et(e,c.unit.juan);if(oe){const ae=(be=e.juan_count)==null?void 0:be.description;D.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[a(oe),ae&&ae!==oe?t.jsxs("span",{className:"bim-d-meta",children:["(",a(ae),")"]}):null]})})}e.loss_status&&D.push({label:"存佚",value:a(Rp(e.loss_status))});const ce=e._edition_count??u.length;ce&&D.push({label:"版本",value:t.jsxs(t.Fragment,{children:[ce," ",a("種"),w&&A?t.jsxs("span",{className:"bim-d-meta",children:[" ",a(`${A} 種有影印`)]}):null]})});const ue=E.allRows.filter(ae=>ae.sortYear!=null),me=ue.length>0?ue.reduce((ae,ke)=>ae.sortYear<=ke.sortYear?ae:ke):null;me!=null&&me.era.era?D.push({label:"最早存世",value:a([me.era.era,me.era.reign].filter(Boolean).join(" ")),title:me.era.source==="edition"?a("據版本題名推斷"):void 0}):z&&D.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":a("載入中"),children:"…"})}),(P.length||R.length)&&D.push({label:"著錄",value:t.jsxs(t.Fragment,{children:[P.length?`${P.length} ${a("家")}`:"—",R.length?t.jsxs("span",{className:"bim-d-meta",children:[" ",a(`考證 ${R.length} 條`)]}):null]})});const Q=Lo(e.additional_titles);Q.length&&D.push({label:"又名",value:Q.map(a).join("、")});const q=Lo(e.attached_texts);q.length&&D.push({label:"附載",value:q.map(a).join("、")});const N=(e.additional_works||[]).map(ae=>a(ae.book_title)+(ae.n_juan!=null?` ${ae.n_juan}${a(c.unit.juan)}`:""));return N.length&&D.push({label:"附錄",value:N.join("、")}),D},[e,a,c,u.length,w,z,A,E.allRows,P.length,R.length]),I=e.classification,F=I?[I.l1,I.l2,I.l3,I.l4].filter(Boolean).map(D=>a(D)):[],K=e.subtype?a(c.workSubtype[e.subtype]??e.subtype):"",G=t.jsx(At,{title:a(e.title),byline:t.jsx(bi,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(Re,{items:[...F,I!=null&&I.source?a(`據《${I.source.split("/")[0]}》`):"",K]}),description:(se=e.description)!=null&&se.text?t.jsxs(t.Fragment,{children:[t.jsx(Ke,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(ge=e.description.sources)!=null&&ge.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(D=>a(ba(D))).filter(Boolean).join(" · ")}):null]}):void 0,facts:ne,readAction:s,foot:t.jsx(Mt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(he=e.appendix)==null?void 0:he.map((D,le)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:a(D.title)}),t.jsx(Ke,{text:D.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},le))}),U=E.eras.length>=2?[{key:"",label:c.catalog.all},...E.eras.map(D=>({key:D,label:D}))]:[],te=[];u.length&&te.push({id:"versions",label:"版本",count:u.length}),P.length&&te.push({id:"catalogs",label:"著錄",count:P.length}),T.length&&te.push({id:"collected",label:"收入叢編",count:T.length}),L.length&&te.push({id:"related",label:"相關書目",count:L.length}),M.length&&te.push({id:"resources",label:"在線資源",count:M.length});const O=u.length===0&&P.length===0,Y=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Ce,{id:"versions",title:"版本",meta:t.jsx(Re,{items:[a(`共 ${u.length} 種`),w&&A?a(`${A} 種有影印`):"",E.rows.length!==E.allRows.length?a(`當前 ${E.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&U.length===0&&u.length>1?"":void 0,children:[U.length>0&&t.jsx(rn,{items:U,value:k,onChange:D=>{m(D),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Ir,{label:"只看有影印",checked:v,onChange:D=>{y(D),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:a(B?"按年代排列":"按著錄順序")})]}),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:a("版本")}),t.jsx("th",{children:a("年代")}),t.jsx("th",{children:a("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:a("影印")})})]})}),t.jsx("tbody",{children:C.map(D=>{var le;return t.jsx(Np,{row:D,measure:(le=x.get(D.id))==null?void 0:le.measure_info,loaded:x.has(D.id),onNavigate:i,renderLink:r},D.id)})})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a(k||v?"當前篩選下沒有版本":"暫無版本著錄")}),E.rows.length>C.length&&t.jsx(yt,{label:`展開其餘 ${E.rows.length-C.length} 種版本`,onClick:()=>b(!0)}),E.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:a("部分年代據版本題名推斷,非著錄原文")})]}),P.length>0&&t.jsx(Bp,{items:P,onNavigate:i,renderLink:r}),O&&t.jsx(Ce,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該作品的版本與書目收錄。")})})]}),Z=(D,le)=>t.jsx(Pe,{id:D,label:a(le),onNavigate:i,renderLink:r,dense:!0}),X=t.jsxs(t.Fragment,{children:[t.jsx(ct,{id:"collected",title:"收入叢編",items:T.map(D=>Z(D.id,D.title))}),t.jsx(ct,{id:"related",title:"相關書目",meta:a(`${L.length} 部`),items:L.map(D=>t.jsxs(t.Fragment,{children:[Z(D.id,D.title),t.jsx("span",{className:"bim-d-meta",title:D.note?a(D.note):void 0,children:a(Ip(D.relation))})]}))}),t.jsx(ct,{id:"resources",title:"在線資源",cap:6,items:M.map(({r:D,kind:le})=>{const oe=a((D.url?tt(D.url):void 0)||D.name),ce=bt(D);return t.jsxs(t.Fragment,{children:[ce?t.jsxs("a",{href:ce,target:"_blank",rel:"noopener noreferrer",children:[oe," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:oe}),le&&t.jsx("span",{className:"bim-d-meta",children:le})]})})})]});return t.jsx(Wt,{railTop:l,back:p,nav:te,railLinks:d,main:Y,card:G,side:X})};function Lo(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function No(e,n){return n((e.url?tt(e.url):void 0)||e.name)}function Np({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=V(),p=[e.era.era,e.era.reign].filter(Boolean).join(" "),d=e.era.source==="edition",c=e.holders[0],a=c?No(c,l):e.locationName?l(e.locationName):"",u=e.images[0],x=u?bt(u):void 0,g=e.images.map(h=>No(h,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Pe,{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("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${p?"":" bim-d-zt-blank"}`,title:d?l("據版本題名推斷"):void 0,children:p?l(p):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${a?"":" bim-d-zt-blank"}`,children:[a||(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&&(x?t.jsx("a",{className:"bim-d-flag",href:x,target:"_blank",rel:"noopener noreferrer",title:g,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:g,children:l("有影印")}))})]})}function Bp({items:e,onNavigate:n,renderLink:i}){const r=ie(),{convert:s}=V(),[l,p]=f.useState(0),d=e[Math.min(l,e.length-1)];return t.jsx(Ce,{id:"catalogs",title:"著錄",meta:s(`歷代書目 ${e.length} 家`),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-lu-list bim-d-ui",role:"tablist","aria-label":s("著錄書目"),children:e.map((c,a)=>t.jsx("li",{role:"presentation",children:t.jsx("button",{type:"button",role:"tab","aria-selected":a===l,onClick:()=>p(a),children:s(c.source)})},a))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:s(d.title_info)}),t.jsx(Re,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?t.jsx(Pe,{id:d.source_bid,label:s(d.source),onNavigate:n,renderLink:i,dense:!0}):s(d.source),d.section?s(d.section):"",d.author_info?`${s(r.label.authorInfo)} ${s(d.author_info)}`:"",d.edition?`${s(r.label.edition)} ${s(d.edition)}`:"",d.page??""]}),d.summary&&t.jsx("p",{className:"bim-d-quote",children:Ie(s(d.summary))}),d.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s(r.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:Ie(s(d.comment))})]}),d.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s(r.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:Ie(s(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:s("僅著錄書名,無提要。")})]})]})})}const Bo=8,Cs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:p,railLinks:d})=>{var L,M,P,R,ne;const c=ie(),{convert:a}=V(),[u,x]=f.useState(null),[g,h]=f.useState(new Map),[b,k]=f.useState([]),[m,v]=f.useState(!1);f.useEffect(()=>{if(!n||!e.work_id){x(null);return}let I=!1;return n.getItem(e.work_id).then(F=>{!I&&F&&F.type==="work"&&x(F)}).catch(()=>{}),()=>{I=!0}},[n,e.work_id]),f.useEffect(()=>{const I=e.contained_in||[];if(!n||I.length===0){h(new Map);return}let F=!1;return Promise.all(I.map(K=>{const G=typeof K=="string"?K:K.id;return n.getItem(G).then(U=>[G,U]).catch(()=>[G,null])})).then(K=>{if(F)return;const G=new Map;for(const[U,te]of K)te&&G.set(U,te);h(G)}),()=>{F=!0}},[n,e.contained_in]);const y=f.useMemo(()=>{const I=new Set([...(u==null?void 0:u.books)||[],...e.related_books||[]]);return I.delete(e.id),[...I]},[u==null?void 0:u.books,e.related_books,e.id]);f.useEffect(()=>{if(!n||y.length===0){k([]);return}const I=m?y:y.slice(0,Bo);let F=!1;return Promise.all(I.map(K=>n.getItem(K).then(G=>({id:K,title:G==null?void 0:G.title,edition:G==null?void 0:G.edition})).catch(()=>({id:K})))).then(K=>{F||k(K)}),()=>{F=!0}},[n,y,m]);const j=f.useMemo(()=>{const I=nn(e.resources,e.resource_groups);return[...I.mirrors.flatMap(F=>F.items.map(K=>({r:K,kind:a(F.label),all:F.items}))),...I.buckets.flatMap(F=>F.items.map(K=>({r:K,kind:a(mi(F.key)),all:F.items})))]},[e.resources,e.resource_groups,a]),$=Nt(e),S=Sr(e),_=new Set((e.contained_in||[]).map(I=>typeof I=="string"?0:Rt(I.volume_index).length).filter(I=>I>0)),w=f.useMemo(()=>{var te,O,Y,Z;const I=[];S&&I.push({label:"版本類型",value:a(S),title:(te=e.lineage)!=null&&te.category?void 0:a("據版本題名推斷")}),($.era||$.reign)&&I.push({label:"刊寫年代",value:a([$.era,$.reign].filter(Boolean).join(" ")),title:$.source==="edition"?a("據版本題名推斷"):void 0});const F=et(e,c.unit.juan);F&&I.push({label:"卷帙",value:a(F)});const K=(e.contained_in||[]).flatMap(X=>typeof X=="string"?[]:Rt(X.volume_index));K.length&&I.push({label:"冊次",value:a(`第 ${on(K,c.unit.volume)} ${c.unit.volume}(${K.length} ${c.unit.volume})`)});const G=(e.resources||[]).filter(X=>(X.types||(X.type?[X.type]:[])).includes("physical"));G.length?I.push({label:"存藏",value:G.slice(0,2).map(X=>a(X.name)).join("、")+(G.length>2?a(` 等 ${G.length} 處`):"")}):(O=e.current_location)!=null&&O.name&&I.push({label:"存藏",value:a(e.current_location.name)}),(Y=e.page_count)!=null&&Y.description&&I.push({label:c.label.pageCount,value:a(e.page_count.description)}),(Z=e.publication_info)!=null&&Z.details&&I.push({label:"刊印",value:a(e.publication_info.details)});const U=[...Rn(e.additional_titles),...Rn(e.attached_texts)];return U.length&&I.push({label:"又名",value:U.map(a).join("、")}),I},[e,a,c,$,S]),z=a(e.title),B=e.edition?a(e.edition):void 0,E=t.jsx(At,{title:z,subtitle:B,byline:t.jsx(bi,{authors:e.authors??(u==null?void 0:u.authors),onNavigate:i,renderLink:r}),meta:t.jsx(Re,{items:[a("版本"),S?a(S):"",$.era?a($.era):""]}),description:(L=e.description)!=null&&L.text?t.jsx(Ke,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,facts:w,readAction:s,foot:t.jsx(Mt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),C=e.contained_in||[],A=[];j.length&&A.push({id:"resources",label:"影印與全文",count:j.length}),C.length&&A.push({id:"collections",label:"收入叢編",count:C.length}),(M=e.location_history)!=null&&M.length&&A.push({id:"provenance",label:"流轉歷史"}),u&&A.push({id:"work",label:"所屬作品"}),y.length&&A.push({id:"siblings",label:"其他版本",count:y.length});const W=t.jsxs(t.Fragment,{children:[j.length>0&&t.jsx(Ce,{id:"resources",title:"影印與全文",meta:a(`${j.length} 處`),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:j.map(({r:I,kind:F,all:K},G)=>t.jsx(Wp,{item:I,kind:F,siblings:K,listedVolumeCounts:_},`${I.id||I.url||I.name}-${G}`))})})}),C.length>0&&t.jsx(Ce,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:C.map((I,F)=>{var O,Y;const K=typeof I=="string"?I:I.id,G=typeof I=="string"?[]:Rt(I.volume_index),U=g.get(K),te=(U==null?void 0:U._member_count)||((O=U==null?void 0:U.books)==null?void 0:O.length)||((Y=U==null?void 0:U.contained_works)==null?void 0:Y.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Pe,{id:K,label:U?a(U.title):K,onNavigate:i,renderLink:r,dense:!0}),G.length>0&&t.jsx(Ap,{volumes:G,unit:c.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${te?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:te>0&&a(`全 ${te} ${c.unit.bu}`)})]},`${K}-${F}`)})})})}),(P=e.location_history)!=null&&P.length?t.jsx(Ce,{id:"provenance",title:"流轉歷史",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:e.location_history.map((I,F)=>t.jsxs("tr",{children:[t.jsx("td",{className:"bim-d-zt-main",children:t.jsx("span",{className:"bim-d-zt-name",children:a(I.name)})}),t.jsx("td",{className:`bim-d-zt-sub${I.description||I.start_date?"":" bim-d-zt-blank"}`,children:t.jsx(Re,{items:[[I.start_date,I.end_date].filter(Boolean).join("—"),I.description?a(I.description):""]})})]},F))})})}):null,j.length===0&&C.length===0&&!((R=e.location_history)!=null&&R.length)&&t.jsx(Ce,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該版本的影印、全文與收藏信息。")})})]}),T=t.jsxs(t.Fragment,{children:[u&&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:a(c.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Pe,{id:u.id,label:a(u.title),onNavigate:i,renderLink:r})}),t.jsx(Re,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[a(et(u,c.unit.juan)),...(u.authors||[]).slice(0,2).map(I=>`${I.dynasty?`〔${a(I.dynasty)}〕`:""}${a(I.name)}`),u._edition_count?a(`${u._edition_count} 種版本`):""]}),((ne=u.description)==null?void 0:ne.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:4,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:a(u.description.text.replace(/[#*_>`[\]]/g,""))})]}),y.length>0&&t.jsxs("div",{children:[t.jsx(ct,{id:"siblings",title:c.relation.siblingVersions,meta:a(`${y.length} 種`),cap:m?b.length:Bo,items:b.map(I=>t.jsx(Pe,{id:I.id,label:a(I.edition||I.title||I.id),onNavigate:i,renderLink:r,dense:!0}))}),!m&&y.length>b.length&&b.length>0&&t.jsx(yt,{label:`顯示更多(${y.length-b.length})`,onClick:()=>v(!0)})]})]});return t.jsx(Wt,{railTop:l,back:p,nav:A,railLinks:d,main:W,card:E,side:T})};function Wp({item:e,kind:n,siblings:i,listedVolumeCounts:r}){const{convert:s}=V(),[l,p]=f.useState(!1),d=Xt(e),c=!!d&&d.expected>0&&!r.has(d.expected),a=(e.url?tt(e.url):void 0)||e.name,u=hr(e,i),x=s(u?`${a}(${u})`:a),g=bt(e),h=Bt(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[g?t.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",children:[x," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:x}),h&&t.jsx("span",{className:"bim-d-meta",children:s(h)}),c&&l&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(Qn,{item:e})})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${n?"":" bim-d-zt-blank"}`,children:n}),t.jsx("td",{className:c?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:c&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":l,onClick:()=>p(b=>!b),children:s(l?"收起分冊":`展開 ${d.expected} 冊`)})})]})}function Ap({volumes:e,unit:n}){const{convert:i}=V();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${on(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}const Mp=16,Is=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,readAction:p,railTop:d,back:c,railLinks:a})=>{var I,F,K,G,U,te;const u=ie(),{convert:x}=V(),[g,h]=f.useState(""),[b,k]=f.useState(!1),m=f.useMemo(()=>vr(e,n),[e,n]),v=f.useMemo(()=>g?m.rows.filter(O=>O.section===g):m.rows,[m.rows,g]),y=b?v:v.slice(0,Mp),[j,$]=f.useState(new Map),S=f.useMemo(()=>y.filter(O=>O.id&&O.title===O.id&&!j.has(O.id)).map(O=>O.id),[y,j]);f.useEffect(()=>{if(!i||S.length===0)return;let O=!1;return Promise.all(S.map(Y=>i.getItem(Y).then(Z=>[Y,{title:Z==null?void 0:Z.title,edition:Z==null?void 0:Z.edition}]).catch(()=>[Y,{}]))).then(Y=>{O||$(Z=>{const X=new Map(Z);for(const[se,ge]of Y)X.set(se,ge);return X})}),()=>{O=!0}},[i,S]);const _=f.useMemo(()=>{const O=nn(e.resources,e.resource_groups);return[...O.mirrors.flatMap(Y=>Y.items.map(Z=>({r:Z,kind:x(Y.label)}))),...O.buckets.flatMap(Y=>Y.items.map(Z=>({r:Z,kind:x(mi(Y.key))})))]},[e.resources,e.resource_groups,x]),w=e.contained_works||[],z=new Set(m.rows.map(O=>O.id).filter(Boolean)),B=w.length>0&&!w.every(O=>z.has(O.id)),E=(()=>{const O=m.rows.map(Y=>Y.edition).filter(Boolean);return O.length>1&&new Set(O).size===1})(),C=m.sections.length>0,A=m.rows.some(O=>O.volumes.length>0||O.expected!=null),W=e._member_count||((I=e.books)==null?void 0:I.length)||w.length,T=f.useMemo(()=>{var Z,X,se;const O=[];W&&O.push({label:"種數",value:`${W} ${x(u.unit.bu)}`});const Y=et(e,u.unit.juan);return Y&&O.push({label:"卷數",value:x(Y),title:(Z=e.juan_count)!=null&&Z.description?x(e.juan_count.description):void 0}),m.totalVolumes&&O.push({label:"全帙冊數",value:`${m.totalVolumes} ${x(u.unit.volume)}`}),(X=e.publication_info)!=null&&X.details&&O.push({label:"刊印",value:x(e.publication_info.details)}),(se=e.publication_info)!=null&&se.year&&O.push({label:"年代",value:x(e.publication_info.year)}),O},[e,W,m.totalVolumes,x,u]),L=t.jsx(At,{title:x(e.title),byline:t.jsx(bi,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Re,{items:[x("叢編"),e.subtype==="work_collection"?x("作品集"):"",(F=e.publication_info)!=null&&F.year?x(e.publication_info.year):""]}),description:(K=e.description)!=null&&K.text||(G=e.history)!=null&&G.length?t.jsxs(t.Fragment,{children:[((U=e.description)==null?void 0:U.text)&&t.jsx(Ke,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(te=e.history)!=null&&te.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((O,Y)=>t.jsx("li",{children:x(O)},Y))}):null]}):void 0,facts:T,readAction:p,foot:t.jsx(Mt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),M=[];m.rows.length&&M.push({id:"titles",label:u.section.containedBooks,count:m.rows.length}),_.length&&M.push({id:"resources",label:"影印與全文",count:_.length}),B&&M.push({id:"works",label:u.section.containedWorks,count:w.length});const P=C?[{key:"",label:u.catalog.all},...m.sections.map(O=>({key:O,label:O}))]:[],R=t.jsxs(t.Fragment,{children:[m.rows.length>0&&t.jsxs(Ce,{id:"titles",title:u.section.containedBooks,meta:t.jsx(Re,{items:[x(`共 ${m.rows.length} ${u.unit.items}`),W&&W!==m.rows.length?x(`成員 ${W} ${u.unit.bu}`):"",v.length!==m.rows.length?x(`當前 ${v.length} ${u.unit.items}`):""]}),action:l,children:[P.length>0&&t.jsx("div",{className:"bim-d-filters bim-d-ui",children:t.jsx(rn,{items:P,value:g,onChange:O=>{h(O),k(!1)}})}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:x("書名")}),C&&t.jsx("th",{children:x("部類")}),A&&t.jsx("th",{children:x("全帙冊次")})]})}),t.jsx("tbody",{children:y.map((O,Y)=>{var D;const Z=O.id?j.get(O.id):void 0,X=Z!=null&&Z.title?{...O,title:Z.title}:O,se=[(D=X.subItems)!=null&&D.length?X.subItems.map(le=>x(le)).join("、"):"",X.edition&&!E?x(X.edition):""].filter(Boolean).join(" · "),ge=X.volumes.length>0?x(`第 ${on(X.volumes,u.unit.volume)} ${u.unit.volume}`):X.expected!=null?x(`${X.found??0}/${X.expected} ${u.unit.volume}`):"",he=X.section?x(X.section.endsWith("部")?X.section:`${X.section}部`):"";return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[X.id?t.jsx(Pe,{id:X.id,label:x(X.title),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:x(X.title)}),se&&t.jsx("span",{className:"bim-d-meta",children:se})]}),C&&t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${he?"":" bim-d-zt-blank"}`,children:he||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),A&&t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ge?"":" bim-d-zt-blank"}`,children:ge||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})})]},`${X.id??X.title}-${Y}`)})})]}),y.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:x(u.catalog.noMatch)}),v.length>y.length&&t.jsx(yt,{label:`展開其餘 ${v.length-y.length} ${u.unit.items}`,onClick:()=>k(!0)})]}),_.length>0&&t.jsx(Ce,{id:"resources",title:"影印與全文",meta:x(`${_.length} 處`),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:_.map(({r:O,kind:Y},Z)=>{const X=x((O.url?tt(O.url):void 0)||O.name),se=bt(O),ge=Bt(O)||O.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[se?t.jsxs("a",{href:se,target:"_blank",rel:"noopener noreferrer",children:[X," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:X}),ge&&t.jsx("span",{className:"bim-d-meta",children:x(ge)})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Y?"":" bim-d-zt-blank"}`,children:Y})]},`${O.id||O.url||O.name}-${Z}`)})})})}),m.rows.length===0&&_.length===0&&t.jsx(Ce,{title:u.section.containedBooks,children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該叢編的子目。")})})]}),ne=B?t.jsx(ct,{id:"works",title:u.section.containedWorks,meta:x(`${w.length} 種`),cap:12,items:w.map(O=>t.jsx(Pe,{id:O.id,label:x(O.title),onNavigate:r,renderLink:s,dense:!0}))}):null;return t.jsx(Wt,{railTop:d,back:c,nav:M,railLinks:a,main:R,card:L,side:ne})},Fp=16,yn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Wo(e){if(!e)return yn.length;const n=yn.indexOf(e);return n===-1?yn.length:n}const Pp={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function Ao(e){return e==null?"":e<0?`前${-e}`:String(e)}const Ts=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:p})=>{var W;const d=ie(),{convert:c}=V(),[a,u]=f.useState("全部"),[x,g]=f.useState(!1),[h,b]=f.useState("default"),[k,m]=f.useState(new Map),v=f.useMemo(()=>(e.works||[]).map(T=>{const L=k.get(T.work_id);return{id:T.work_id,title:(L==null?void 0:L.title)??T.title??T.work_id,role:T.role||"",cls:Jn(T.role),versionCount:L==null?void 0:L.versionCount,loaded:!!(L!=null&&L.loaded)}}),[e.works,k]),y=f.useMemo(()=>jr((e.works||[]).map(T=>T.role)),[e.works]),j=f.useMemo(()=>{const T=a==="全部"?v:v.filter(L=>L.cls===a);return h==="versions"?[...T].sort((L,M)=>(M.versionCount??-1)-(L.versionCount??-1)):T},[v,a,h]),$=x?j:j.slice(0,Fp),S=f.useMemo(()=>$.filter(T=>!k.has(T.id)).map(T=>T.id),[$,k]);f.useEffect(()=>{if(!n||S.length===0)return;let T=!1;return Promise.all(S.map(L=>n.getItem(L).then(M=>{var ne,I;const P=M??{},R=P._edition_count??(((ne=P.books)==null?void 0:ne.length)??0)+(((I=P.collections)==null?void 0:I.length)??0);return[L,{id:L,title:P.title,versionCount:R,loaded:!0}]}).catch(()=>[L,{id:L,loaded:!0}]))).then(L=>{T||m(M=>{const P=new Map(M);for(const[R,ne]of L)P.set(R,ne);return P})}),()=>{T=!0}},[n,S]);const _=f.useMemo(()=>{const T=new Map;for(const L of e.alt_names||[]){const M=L.type||d.section.aliases;T.has(M)||T.set(M,[]),T.get(M).push(L.name)}return[...T.entries()].sort((L,M)=>Wo(L[0])-Wo(M[0])).map(([L,M])=>({label:L,names:M}))},[e.alt_names,d]),w=e.birth_year!=null||e.death_year!=null?`${Ao(e.birth_year)||"?"}—${Ao(e.death_year)||"?"}`:"",z=f.useMemo(()=>{var P,R;const T=[];for(const ne of _)T.push({label:ne.label,value:ne.names.map(I=>c(I)).join("、")});e.dynasty&&T.push({label:"時代",value:c(e.dynasty)}),w&&T.push({label:"生卒",value:w});const L=(e.works||[]).length;L&&T.push({label:"著作",value:`${L} ${c("種")}`});const M=(P=e.external_ids)==null?void 0:P.cbdb_id;return M!=null&&T.push({label:"CBDB",value:t.jsxs(t.Fragment,{children:[M,((R=e.external_ids)==null?void 0:R.cbdb_match)==="auto"&&t.jsx("span",{className:"bim-d-meta",title:c("由姓名、朝代與著作重合度自動匹配,未經人工複核"),children:c("自動匹配")})]})}),T},[e,_,w,c]),B=t.jsx(At,{title:c(e.primary_name||e.title),meta:t.jsx(Re,{items:[c(Pp[e.subtype]??""),w]}),description:(W=e.description)!=null&&W.text?t.jsx(Ke,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,facts:z,foot:t.jsx(Mt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),E=y.map(T=>({key:T.cls,label:`${T.label} ${T.count}`})),C=v.length?[{id:"works",label:"著作",count:v.length}]:[],A=v.length===0?t.jsx(Ce,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該人物的關聯作品。")})}):t.jsxs(Ce,{id:"works",title:"著作",meta:t.jsx(Re,{items:[c(`共 ${v.length} 種`),j.length!==v.length?c(`當前 ${j.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[E.length>1&&t.jsx(rn,{items:E,value:a,onChange:T=>{u(T),g(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":h==="versions",onClick:()=>{h==="default"&&g(!0),b(T=>T==="default"?"versions":"default")},children:c(h==="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("tbody",{children:$.map(T=>t.jsxs("tr",{children:[t.jsx("td",{className:"bim-d-zt-main",children:t.jsx(Pe,{id:T.id,label:c(T.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${T.role?"":" bim-d-zt-blank"}`,children:T.role?c(T.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${T.loaded?"":" bim-d-zt-blank"}`,children:T.loaded?T.versionCount?c(`${T.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:c("未著錄")}):""})]},T.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("該職任下的著作尚未著錄。")}),j.length>$.length&&t.jsx(yt,{label:`展開其餘 ${j.length-$.length} 種著作`,onClick:()=>g(!0)})]});return t.jsx(Wt,{railTop:s,back:l,nav:C,railLinks:p,main:A,card:B})},yi="(max-width: 719px)",Op=`${yi}, (pointer: coarse)`,Rs=`
525
572
  .bim-ct {
526
573
  display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
527
574
  max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
@@ -634,9 +681,9 @@ ${$a}`;function It({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
634
681
  }
635
682
 
636
683
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
637
- @media ${Wp} {
684
+ @media ${Op} {
638
685
  .bim-ct-row { min-height: 44px; }
639
686
  .bim-ct-tw { width: 44px; }
640
687
  .bim-ct-pg { min-width: 44px; height: 44px; }
641
688
  }
642
- `,ht="未分類",Ge="all",ji=20;function Pt(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 Ap(e){const n=Pt(e);return n.length?n.join("/"):ht}function Mp(e){const n=Pt(e);return n.length?n.map((i,r)=>n.slice(0,r+1).join("/")):[ht]}function Fp(e,n=[]){const i=new Map;n.forEach((d,c)=>{const a=[d.cata_l1,d.cata_l2,d.cata_l3,d.cata_l4].filter(u=>!!u);a.forEach((u,x)=>{const g=a.slice(0,x+1).join("/");i.has(g)||i.set(g,c)})});const r=new Map;let s=0;for(const d of e){const c=Pt(d.classification);if(!c.length){s++;continue}let a=r;c.forEach((u,x)=>{const g=c.slice(0,x+1).join("/");let h=a.get(u);h||(h={id:g,label:u,count:0,children:new Map},a.set(u,h)),h.count++,a=h.children})}const l=d=>[...d.values()].sort((c,a)=>{const u=i.get(c.id)??1/0,x=i.get(a.id)??1/0;return u!==x?u-x:c.label.localeCompare(a.label,"zh")}).map(c=>{const a={id:c.id,label:c.label,count:c.count};return c.children.size&&(a.children=l(c.children)),a}),p=l(r);return s>0&&p.push({id:ht,label:ht,count:s}),p}function pt(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const r=pt(i.children,n);if(r.length)return[i,...r]}}return[]}function vi(e){return e.reduce((n,i)=>n+i.count,0)}function Pp(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function Op(e){var d;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 a=c.dynasty||(e.authors.length===1?e.dynasty:void 0);return a?{name:c.name,dynasty:a}:{name:c.name}});s.length&&(n.authors=s);const l=Pp(typeof e.description=="string"?e.description:(d=e.description)==null?void 0:d.text);l&&(n.summary=l);const p=Pt(e.classification);return p.length&&(n.classification=p),n}function Dp(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 Hp(e,n=ji){return Math.max(1,Math.ceil(e/n))}function Ts(e,n,i=2){if(n<=1)return[1];const r=new Set([1,n]);for(let p=e-i;p<=e+i;p++)p>=1&&p<=n&&r.add(p);const s=[...r].sort((p,d)=>p-d),l=[];return s.forEach((p,d)=>{if(d>0){const c=p-s[d-1];c===2?l.push(p-1):c>2&&l.push(null)}l.push(p)}),l}const Gp=()=>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 Up(e,n,i){const r=[];i&&r.push({id:Ge,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,p)=>{var d;for(const c of l){const a=(d=c.children)!=null&&d.length?c.children:null;r.push({id:c.id,parentId:p,hasChildren:!!a,firstChildId:a?a[0].id:null}),a&&n.has(c.id)&&s(a,c.id)}};return s(e,null),r}function Rs({tree:e,selectedId:n,onSelect:i,allLabel:r="全部",label:s="分類"}){const{convert:l}=Y(),p=f.useRef(null),d=n&&n!==Ge?n:null,c=r!==null,[a,u]=f.useState(()=>{const S=new Set;for(const _ of pt(e,d))S.add(_.id);return S});f.useEffect(()=>{const S=pt(e,d);S.length&&u(_=>{if(S.every(z=>_.has(z.id)))return _;const w=new Set(_);for(const z of S)w.add(z.id);return w})},[e,d]);const x=f.useMemo(()=>Up(e,a,c),[e,a,c]),[g,h]=f.useState(null);f.useEffect(()=>{h(null)},[n]);const y=d??(c?Ge:null),k=f.useMemo(()=>{var w;const S=new Set(x.map(z=>z.id));if(g&&S.has(g))return g;if(y&&S.has(y))return y;const _=pt(e,d).map(z=>z.id).filter(z=>S.has(z));return _.length?_[_.length-1]:((w=x[0])==null?void 0:w.id)??null},[x,g,y,e,d]),m=f.useCallback((S,_)=>{u(w=>{const z=w.has(S),B=_??!z;if(B===z)return w;const L=new Set(w);return B?L.add(S):L.delete(S),L})},[]),v=f.useCallback(S=>{h(S),requestAnimationFrame(()=>{var w;const _=Array.from(((w=p.current)==null?void 0:w.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===S);_==null||_.focus()})},[]),b=f.useCallback((S,_)=>{_&&m(S,!0),i(S)},[i,m]),j=f.useCallback(S=>{const _=S.target.closest("[data-ct-id]");if(!_)return;const w=_.dataset.ctId,z=x.findIndex(C=>C.id===w);if(z<0)return;const B=x[z];let L=null;switch(S.key){case"ArrowDown":L=x[Math.min(x.length-1,z+1)].id;break;case"ArrowUp":L=x[Math.max(0,z-1)].id;break;case"Home":L=x[0].id;break;case"End":L=x[x.length-1].id;break;case"ArrowRight":if(!B.hasChildren)break;a.has(w)?L=B.firstChildId:m(w,!0);break;case"ArrowLeft":B.hasChildren&&a.has(w)?m(w,!1):L=B.parentId;break;case"Enter":case" ":S.preventDefault(),b(w,B.hasChildren);return;default:return}S.preventDefault(),L&&L!==w&&v(L)},[x,a,m,v,b]),$=(S,_)=>S.map(w=>{var A;const z=(A=w.children)!=null&&A.length?w.children:null,B=!!z&&a.has(w.id),L=w.id===d,C=_===1&&w.id===ht;return t.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":z?B:void 0,"aria-selected":L,tabIndex:k===w.id?0:-1,"data-ct-id":w.id,className:C?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{h(w.id),b(w.id,!!z)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:z?W=>{W.stopPropagation(),h(w.id),m(w.id)}:void 0,children:z?t.jsx(Gp,{}):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")})]}),B&&t.jsx("ul",{role:"group",children:$(z,_+1)})]},w.id)});return t.jsxs("ul",{ref:p,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:j,children:[c&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!d,tabIndex:k===Ge?0:-1,"data-ct-id":Ge,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{h(Ge),i(Ge)},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 Es=e=>`/item/${encodeURIComponent(e)}`;function Vp(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Yp(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function Ls({work:e,href:n}){var p,d;const{convert:i}=Y(),r=Yp(e.juan),s=((p=e.authors)==null?void 0:p.filter(c=>c.name))??[],l=((d=e.classification)==null?void 0:d.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,a)=>t.jsxs(f.Fragment,{children:[a>0&&"、",c.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(c.dynasty),"〕"]}),i(c.name)]},a))}),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 Bs({page:e,pageCount:n,onPage:i,pageHref:r,label:s="分頁"}){const{convert:l}=Y();if(n<=1)return null;const p=c=>a=>{i&&(r&&!Vp(a)||(a.preventDefault(),i(c)))},d=(c,a,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:a});const x={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...x,href:r(c),onClick:p(c),children:a}):t.jsx("button",{type:"button",...x,onClick:u.current?void 0:p(c),children:a})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[d(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:Ts(e,n).map((c,a)=>t.jsx("li",{style:{display:"contents"},children:c===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):d(c,c,{current:c===e,aria:l(`第 ${c} 頁`)})},c??`gap${a}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),d(e+1,l("下一頁"),{disabled:e>=n})]})}function Ns({works:e,workLink:n=Es,emptyText:i="此類暫無作品",...r}){const{convert:s}=Y();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:typeof i=="string"?s(i):i}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(l=>t.jsx(Ls,{work:l,href:n(l.id)},l.id))}),t.jsx(Bs,{...r})]})}const Kp=()=>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 qp({tree:e,selectedId:n,page:i,pageCount:r,works:s,onSelect:l,onPage:p,searchSlot:d,workLink:c,pageHref:a,allLabel:u="全部",allTitle:x="全部典籍",pageSize:g=ji,className:h}){const{convert:y}=Y(),m=`bim-ct-drawer-${f.useId().replace(/:/g,"")}`,[v,b]=f.useState(!1),j=pt(e,n&&n!==Ge?n:null),$=j.length?j[j.length-1]:null,S=$?$.label:x,_=$?$.count:vi(e),w=f.useCallback(z=>{b(!1),l(z)},[l]);return t.jsxs("div",{className:h?`bim-ct ${h}`:"bim-ct","data-drawer":v?"open":"closed",children:[t.jsx("style",{children:Is}),t.jsxs("aside",{className:"bim-ct-side","aria-label":y("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":v,"aria-controls":m,onClick:()=>b(z=>!z),children:[t.jsxs("span",{children:[y("分類"),":",y(j.length?j.map(z=>z.label).join(" › "):u??x)]}),t.jsx(Kp,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:m,children:[t.jsx("h2",{className:"bim-ct-side-h",children:y("分類")}),t.jsx(Rs,{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:y(S)}),j.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:y(j.slice(0,-1).map(z=>z.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[y(`共 ${_.toLocaleString("en-US")} 種 · 每頁 ${g} 條`),r>1&&y(` · 第 ${i} / ${r} 頁`)]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(Ns,{works:s,workLink:c,page:i,pageCount:r,onPage:p,pageHref:a})]})]})}function Jp(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 Zp(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 Mo(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 Xp(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 Qp(e,n){var a;if(n==="all")return null;const i=(a=e.collections)==null?void 0:a[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 p=r?new Set(i.groups):null,d=new Set(i.book_ids??[]);if(p&&e.node_groups)for(const[u,x]of Object.entries(e.node_groups))p.has(x)&&d.add(u);let c=null;if(i.hypothetical_ids&&(c=new Set(i.hypothetical_ids)),p){c||(c=new Set);for(const u of e.hypothetical_nodes??[])u.group&&p.has(u.group)&&c.add(u.id)}return{books:d,hypos:c}}function Kt(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??[]),p=r.node_groups??{},d=Qp(r,i??r.default_collection??"all"),c=d!==null,a=(d==null?void 0:d.books)??null,u=(d==null?void 0:d.hypos)??null,x=new Set,g=new Set;if(c){const $=new Map(n.map(L=>[L.id,L])),S=new Map((r.hypothetical_nodes??[]).map(L=>[L.id,L])),_=L=>{const C=$.get(L);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(W=>W.ref);const A=S.get(L);return A?(A.derived_from??[]).map(W=>W.ref):[]},w=L=>S.has(L)?!u||u.has(L):!a||a.has(L),z=new Set,B=L=>{if(!z.has(L)){z.add(L);for(const C of _(L))l.has(C)||(w(C)||(S.has(C)?g.add(C):$.has(C)&&x.add(C)),B(C))}};for(const L of n)a&&a.has(L.id)&&!l.has(L.id)&&B(L.id);for(const L of r.hypothetical_nodes??[])u&&u.has(L.id)&&B(L.id)}const h=n.filter($=>!l.has($.id)).filter($=>!a||a.has($.id)||x.has($.id)).map($=>{const S=Zp($,p);return S&&x.has($.id)&&(S.bridge=!0),S}).filter($=>$!==null),y=(r.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||g.has($.id)).map($=>{const S=Jp($);return g.has($.id)&&(S.bridge=!0),S}),k=[...h,...y],m=new Set(k.map($=>$.id)),v=new Set,b=[],j=$=>{v.has($.id)||!m.has($.source)||!m.has($.target)||(v.add($.id),b.push($))};for(const $ of n)l.has($.id)||!$.lineage||a&&!a.has($.id)&&!x.has($.id)||(($.lineage.derived_from??[]).forEach((S,_)=>{j(Mo($.id,S,_))}),($.lineage.related_to??[]).forEach((S,_)=>{j(Xp($.id,S,_))}));for(const $ of r.hypothetical_nodes??[])u&&!u.has($.id)&&!g.has($.id)||($.derived_from??[]).forEach((S,_)=>{j(Mo($.id,S,_))});return{nodes:k,edges:b,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function Ws(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function eu(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)),p=new Set([...s,...l]),d=(c,a)=>{p.has(a.ref)||i.push(`${c}: derived_from.ref "${a.ref}" 未在 books 或 hypothetical_nodes 中找到`),a.ref_type==="book"&&!s.has(a.ref)&&i.push(`${c}: derived_from.ref "${a.ref}" 标记为 book 但不在 books 列表中`),a.ref_type==="hypothetical"&&!l.has(a.ref)&&i.push(`${c}: derived_from.ref "${a.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const a=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>d(a,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||i.push(`${a}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const a=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>d(a,u))}return i}const As=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:s}=Y();if(!e.nodes.length)return t.jsx("div",{style:{...fu,...r},className:i,children:"暂无版本图数据"});const l=new Map,p=new Map;for(const g of e.edges)if(g.kind==="derive"){const h=l.get(g.target)??[];h.push(g),l.set(g.target,h)}else for(const h of[g.source,g.target]){const y=p.get(h)??[];y.push(g),p.set(h,y)}const d=new Map(e.nodes.map(g=>[g.id,g])),c=new Map,a=[];for(const g of e.nodes)if(g.group){const h=c.get(g.group)??[];h.push(g),c.set(g.group,h)}else a.push(g);const u=(g,h)=>(g.year??9999)-(h.year??9999);c.forEach(g=>g.sort(u)),a.sort(u);const x=e.groups.filter(g=>c.has(g.id));return t.jsxs("div",{className:i,style:{...nu,...r},children:[e.title&&t.jsx("div",{style:iu,children:s(e.title)}),e.description&&t.jsx("div",{style:ou,children:s(e.description)}),x.map(g=>t.jsx(Fo,{label:g.label,color:g.color,nodes:c.get(g.id),incomingMap:l,siblingMap:p,nodeMap:d,renderLink:n},g.id)),a.length>0&&t.jsx(Fo,{label:"其他",nodes:a,incomingMap:l,siblingMap:p,nodeMap:d,renderLink:n})]})},Fo=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:p})=>{const{convert:d}=Y();return t.jsxs("div",{style:ru,children:[t.jsx("div",{style:{...su,borderLeftColor:n??o("widget-border")},children:d(e)}),i.map(c=>t.jsx(tu,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:p},c.id))]})},tu=({node:e,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",p=e.bridge,{convert:d}=Y();return t.jsxs("div",{style:{...lu,borderStyle:l||p?"dashed":"solid",opacity:p?.55:e.status==="lost"?.7:1,background:p?o("bg-subtle"):void 0},title:p?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:au,children:[t.jsx("span",{style:cu,children:l||!s?d(e.label):s(e.id,d(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:du,children:Ws(d(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:pu,children:[e.category&&t.jsx(zt,{children:d(e.category)}),e.status==="lost"&&t.jsx(zt,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(zt,{tone:"warn",children:"残本"}),l&&t.jsx(zt,{tone:"info",children:"假想祖本"}),p&&t.jsx(zt,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:uu,children:["现存:",d(e.extant_juan)]}),e.note&&t.jsx("div",{style:xu,children:d(e.note)}),n.length>0&&t.jsxs("div",{style:Oo,children:[t.jsx("div",{style:Do,children:"来源:"}),n.map(c=>{const a=r.get(c.source);return t.jsxs("div",{style:Ho(c.confidence),children:[t.jsx("span",{style:Go,children:d(c.relation)}),t.jsx("span",{children:(a==null?void 0:a.kind)==="book"&&s?s(a.id,d(a.label)):d((a==null?void 0:a.label)??c.source)}),c.confidence!=="consensus"&&c.confidence!=="certain"&&t.jsx(Po,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:Uo,children:["· ",d(c.evidence)]})]},c.id)})]}),i.length>0&&t.jsxs("div",{style:Oo,children:[t.jsx("div",{style:Do,children:"关联:"}),i.map(c=>{const a=c.source===e.id?c.target:c.source,u=r.get(a);return t.jsxs("div",{style:Ho(c.confidence),children:[t.jsx("span",{style:Go,children:d(c.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,d(u.label)):d((u==null?void 0:u.label)??a)}),t.jsx(Po,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:Uo,children:["· ",d(c.evidence)]})]},c.id)})]})]})},zt=({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})},Po=({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},nu={fontSize:"14px",color:o("fg")},iu={fontSize:"16px",fontWeight:600,marginBottom:"8px"},ou={fontSize:"13px",color:o("muted"),marginBottom:"16px",lineHeight:1.6},ru={marginBottom:"16px"},su={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")},au={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},cu={fontSize:"15px",fontWeight:600},du={fontSize:"12px",color:o("muted")},pu={marginBottom:"6px"},uu={fontSize:"12px",color:o("muted"),margin:"2px 0"},xu={fontSize:"12px",color:o("muted"),fontStyle:"italic",margin:"4px 0"},Oo={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${o("widget-border")}`},Do={fontSize:"11px",color:o("muted"),marginBottom:"2px"},Ho=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Go={display:"inline-block",padding:"0 6px",fontSize:"11px",background:o("tag-bg"),color:o("fg"),borderRadius:"3px",marginRight:"6px"},Uo={fontSize:"11px",color:o("muted")},fu={padding:"20px",textAlign:"center",color:o("muted"),fontSize:"13px"},Ms=({selectedNodeId:e,...n})=>{const[i,r]=f.useState("loading"),[s,l]=f.useState(null);return f.useEffect(()=>{let p=!1;return gu().then(d=>{p||(d?(l(d),r("ready")):r("missing"))}),()=>{p=!0}},[]),i==="loading"?t.jsx("div",{style:Vo,children:"加载图组件中…"}):i==="missing"||!s?t.jsxs("div",{style:Vo,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 gu(){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:p})=>{const{ReactFlow:d,Background:c,Controls:a,Handle:u,Position:x,BaseEdge:g,EdgeLabelRenderer:h,getSmoothStepPath:y,dagre:k}=p,m=f.useMemo(()=>({lineage:_=>{var N,O,E,X;const w=((N=_.data)==null?void 0:N.stepPosition)??.85,[z,B,L]=y({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:w,borderRadius:5}),C=!!((O=_.data)!=null&&O.isSibling),A=C?B:_.targetX-18,W=C?L:_.targetY-12,T=(E=_.data)==null?void 0:E.labelStyle,R=(X=_.data)==null?void 0:X.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(g,{id:_.id,path:z,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&t.jsx(h,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${A}px,${W}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:o("bg"),border:`0.5px solid ${o("widget-border")}`,...R,...T},children:_.label})})]})}}),[g,h,y]),v=f.useMemo(()=>({version:_=>{const w=_.data,z=w.kind==="hypothetical",B=w.status==="lost",L=w.isSelected,C=w.bridge,A=w.borderColor??o("muted"),W=C||z?"dashed":"solid",T=C?.5:B?.6:1;return t.jsxs("div",{style:{background:o(C?"bg-subtle":"bg"),border:`2px ${W} ${L?o("primary"):A}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:T,boxShadow:L?o("shadow-node-selected"):z||C?"none":o("shadow-node")},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:x.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("muted"),lineHeight:1.25,marginTop:1},children:w.description}),w.yearText&&t.jsx("div",{style:{fontSize:10,color:o("muted"),lineHeight:1.2},children:Ws(w.yearText,void 0,w.uncertain)}),B&&t.jsx("div",{style:{fontSize:9,color:o("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[u,x]),{convert:b}=Y(),{rfNodes:j,rfEdges:$}=f.useMemo(()=>mu(e,k,n,l,b),[e,k,n,l,b]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:t.jsxs(d,{nodes:j,edges:$,nodeTypes:v,edgeTypes:m,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(a,{showInteractive:!1})]})})};function mu(e,n,i,r,s=l=>l??""){const d=e.layout==="LR"||!e.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:d?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const a=new Map(e.groups.map(v=>[v.id,v.color??o("muted")]));for(const v of e.nodes)c.setNode(v.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const v of e.edges)v.kind==="derive"&&(u.has(v.relation)||c.setEdge(v.source,v.target));n.layout(c);const x=e.nodes.map(v=>{const b=c.node(v.id),j=r&&v.id===r,$={kind:v.kind,label:s(v.label),bookId:v.kind==="book"?v.id:void 0,yearText:s(v.year_text??yu(v)),uncertain:v.year_uncertain,category:v.category,status:v.status,borderColor:v.group?a.get(v.group):void 0,renderLink:i,isSelected:j,description:s(v.description),bridge:v.bridge};return{id:v.id,type:"version",position:{x:b.x-160/2,y:b.y-90/2},data:$,draggable:!1,selected:j}}),g=.78,h=.06,y=new Map;for(const v of e.edges)v.kind==="derive"&&(y.has(v.source)||y.set(v.source,[]),y.get(v.source).push(v));const k=new Map;for(const[v,b]of y){if(b.length<=1)continue;const j=[...b].sort((S,_)=>{var B,L;const w=((B=c.node(S.target))==null?void 0:B.y)??0,z=((L=c.node(_.target))==null?void 0:L.y)??0;return w-z}),$=j.length;j.forEach((S,_)=>{const w=(_-($-1)/2)*h;k.set(S.id,g+w)})}const m=e.edges.map(v=>bu(v,k.get(v.id),s));return{rfNodes:x,rfEdges:m}}function bu(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=ju(e.confidence),p={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:p,markerStart:s?p:void 0,zIndex:1e3}}function yu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function ju(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 Vo={padding:"40px 20px",textAlign:"center",color:o("muted"),fontSize:"13px",border:`1px dashed ${o("widget-border")}`,borderRadius:8,background:o("bg")},Fs=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:p,onCollectionChange:d,collectionsAvailable:c,collectionCounts:a,className:u,style:x})=>{var b;const[g,h]=f.useState(n),y=j=>{h(j),l==null||l(j)},k=(()=>{if(!c)return[];const j=Object.entries(c);return j.length===0||c.all?j:[...j,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),m=!!(d&&k.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:o("muted"),textAlign:"center"},children:"暂无版本传承数据"});const v=p?(b=c==null?void 0:c[p])==null?void 0:b.description:void 0;return t.jsxs("div",{className:u,style:x,children:[t.jsxs("div",{style:vu,children:[t.jsx("button",{onClick:()=>y("list"),style:vn(g==="list"),children:"列表"}),t.jsx("button",{onClick:()=>y("graph"),style:vn(g==="graph"),children:"关系图"}),m&&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(([j,$])=>{const S=a==null?void 0:a[j];return t.jsxs("button",{onClick:()=>d==null?void 0:d(j),style:vn(p===j),title:$.description,children:[$.label,S!=null?` ${S}`:""]},j)})]})]}),m&&v&&t.jsx("div",{style:{fontSize:12,color:o("muted"),marginBottom:8,padding:"4px 8px",background:o("bg-subtle"),borderRadius:4},children:v}),g==="list"?t.jsx(As,{graph:e,renderLink:i}):t.jsx(Ms,{graph:e,renderLink:i,height:r,selectedNodeId:s})]})},vu={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},vn=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"}),Fn=({style:e})=>{const n=f.useContext(mt);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:"简"})]})},Pn=({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 kn(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function ku(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const Su=({id:e,transport:n,initialDetail:i,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:p,onJuanChange:d,lineageMode:c="list",onLineageModeChange:a,lineageCollection:u,onLineageCollectionChange:x,initialPage:g=1,selectedLineageNodeId:h,onNavigate:y,onBack:k,backLabel:m,renderLink:v,enrichDetail:b,getSourceLink:j,readLink:$,railTop:S,extraTabs:_=[],showFeedbackTab:w=!0,feedbackApiUrl:z,height:B,footerExtra:L,className:C,style:A})=>{var Ti;const W=te(),{convert:T}=Y(),[R]=f.useState(()=>{if(!ku(e,i))return null;const H={...i},le=r??kn(e,H);return b&&b(le,H),{id:e,entry:le,detail:H}}),[N,O]=f.useState((R==null?void 0:R.entry)??null),[E,X]=f.useState((R==null?void 0:R.detail)??null),[I,M]=f.useState(!R),[K,V]=f.useState(!1),[G,ee]=f.useState([]),[P,q]=f.useState(!1),[Z,U]=f.useState(null),[se,de]=f.useState(!1),[D,re]=f.useState(null),[oe,pe]=f.useState(!1),[fe,ye]=f.useState([]),[Ce,Q]=f.useState(!1),[ce,F]=f.useState(null),[ie,ne]=f.useState(null),[he,ge]=f.useState(!1),Re=f.useRef(null),[Be,ve]=f.useState(null),De=p!==void 0?p:Be,ot=f.useCallback(H=>{d?d(H):ve(H)},[d]),ki=f.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){ee([]);return}q(!0);try{if(n.getCollectionCatalogs)ee(await n.getCollectionCatalogs(H)||[]);else if(n.getCollectionCatalog){const le=await n.getCollectionCatalog(H);ee(le?[{resource_id:"",data:le}]:[])}}catch{ee([])}finally{q(!1)}},[n]),Si=f.useCallback(async H=>{if(!n.getCollatedEditionIndex){U(null);return}de(!0);try{U(await n.getCollatedEditionIndex(H))}catch{U(null)}finally{de(!1)}},[n]),wi=f.useCallback(async H=>{if(!n.getBookFullTextIndex){re(null);return}pe(!0);try{re(await n.getBookFullTextIndex(H))}catch{re(null)}finally{pe(!1)}},[n]),_i=f.useCallback(async H=>{var le;if(!n.getWorkFullTextList){ye([]);return}Q(!0);try{const ue=(await n.getWorkFullTextList(H)??[]).filter(me=>me.owner_type!=="Book");ye(ue),F(((le=ue.find(me=>me.primary)??ue[0])==null?void 0:le.key)??null)}catch{ye([])}finally{Q(!1)}},[n]),$i=f.useCallback(async(H,le)=>{ge(!0);try{if(n.getLineageGraph){const Se=await n.getLineageGraph(H);Se&&ne(Se)}const ue=le.version_graph;if(!ue||!ue.enabled){ie||ne(null),Re.current=null;return}const me=le.books??[],Ne=[];for(const Se of me)try{const We=await n.getItem(Se);We&&Ne.push(We)}catch{}Re.current={work:le,books:Ne};const J=u??ue.default_collection??(ue.core_books&&ue.core_books.length>0?"core":"all"),xe=J==="core"&&Array.isArray(ue.core_books)&&ue.core_books.length>0?"core":J??"all";ne(Kt(le,Ne,xe))}catch{ne(null),Re.current=null}finally{ge(!1)}},[n]),zi=f.useRef({initialDetail:i,initialEntry:r});zi.current={initialDetail:i,initialEntry:r},f.useEffect(()=>{let H=!1;const le=J=>{J.type==="collection"?ki(e):J.type==="work"?((J.has_collated||n.getCollatedEditionIndex)&&Si(e),(J.version_graph||n.getLineageGraph)&&$i(e,J),n.getWorkFullTextList&&_i(e)):J.type==="book"&&J.has_full_text&&n.getBookFullTextIndex&&wi(e)},ue=zi.current;let me=null;if(R&&R.id===e)me=R;else if(ue.initialDetail&&ue.initialDetail.id===e){const J={...ue.initialDetail},xe=ue.initialEntry??kn(e,J);b&&b(xe,J),me={entry:xe,detail:J}}return me?(V(!1),ee(J=>J.length?[]:J),U(null),re(null),ye(J=>J.length?[]:J),F(null),ne(null),Re.current=null,O(me.entry),X(me.detail),M(!1),le(me.detail),()=>{H=!0}):((async()=>{M(!0),V(!1),O(null),X(null),ee([]),U(null),re(null),ye([]),F(null),ne(null),Re.current=null;try{const J=await n.getItem(e);if(H)return;if(!J){V(!0);return}const xe=J;let Se=null;if(n.getEntry&&(Se=await n.getEntry(e),H))return;Se||(Se=kn(e,xe)),b&&b(Se,xe),O(Se),X(xe),le(xe)}catch{H||V(!0)}finally{H||M(!1)}})(),()=>{H=!0})},[e,n,R,b,ki,Si,$i,wi,_i]),f.useEffect(()=>{const H=Re.current;!H||!u||ne(Kt(H.work,H.books,u))},[u]);const ke=[];if(E){if(ke.push({key:"basic",label:W.detailTab.basicInfo}),E.type==="collection"){P&&G.length===0&&ke.push({key:"catalog:loading",label:`${W.detailTab.catalog}…`});for(const H of G)ke.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${T(H.short_name)}${W.detailTab.catalogSuffix}`:W.detailTab.collectionCatalog})}E.type==="work"&&(Z||se)&&s==="collated"&&ke.push({key:"collated",label:se?`${W.detailTab.collatedEdition}…`:W.detailTab.collatedEdition}),E.type==="book"&&(D||oe)&&s==="fulltext"&&ke.push({key:"fulltext",label:oe?`${W.detailTab.fullText}…`:W.detailTab.fullText}),E.type==="work"&&(fe.length>0||Ce)&&s==="fulltext"&&ke.push({key:"fulltext",label:Ce?`${W.detailTab.fullText}…`:W.detailTab.fullText}),E.type==="work"&&(ie||he)&&ke.push({key:"lineage",label:he?`${W.detailTab.lineage}…`:W.detailTab.lineage});for(const H of _)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(E)&&ke.push({key:H.key,label:H.label});w&&s==="feedback"&&ke.push({key:"feedback",label:W.detailTab.feedback});for(const H of _)H.position==="after-feedback"&&H.shouldShow(E)&&ke.push({key:H.key,label:H.label})}f.useEffect(()=>{if(s!=="emendated"||!E)return;l("basic");const H=setTimeout(()=>{var le;(le=document.getElementById("studies"))==null||le.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[s,E,l]);const rt=N&&E&&j?j({activeTab:s,activeJuan:De,entry:N,detail:E}):null,an=f.useMemo(()=>{var Ne;if(!E)return null;const le=(E.authors??[]).map(J=>{const xe=Zn(J.role);return`${J.dynasty?`〔${T(J.dynasty)}〕`:""}${T(J.name)}${xe?` ${T(xe)}`:""}`}).join(" · ");let ue=!1;try{ue=ae.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const J=E;return{title:T(J.title),subtitle:J.edition?T(J.edition):le||void 0,aside:[ue?W.status.draft:"",le&&J.edition?le:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const J=E;return{title:T(J.title),subtitle:T(et(J,W.unit.juan))||void 0,aside:[(Ne=J.publication_info)==null?void 0:Ne.year,ue?W.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:le||void 0}}if(E.type==="entity"){const J=E,xe=We=>We==null?"":We<0?`前${-We}`:String(We),Se=J.birth_year!=null||J.death_year!=null?`${xe(J.birth_year)||"?"}—${xe(J.death_year)||"?"}`:"";return{title:T(J.primary_name||J.title),subtitle:[J.dynasty?`〔${T(J.dynasty)}〕`:"",Se].filter(Boolean).join(" ")||void 0,aside:ue?W.status.draft:void 0,secondLine:void 0}}const me=T(et(E,W.unit.juan));return{title:T(E.title),subtitle:[me,le].filter(Boolean).join(" · ")||void 0,aside:[_u(W,E.subtype),ue?W.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,T,W]),Ot=E?E.type==="work"?(((Ti=Z==null?void 0:Z.juan_files)==null?void 0:Ti.length)??0)>0?"collated":fe.length>0?"fulltext":null:E.type==="book"&&((D==null?void 0:D.chapters.length)??0)>0?"fulltext":null:null,jt=fe.find(H=>H.primary)??fe[0],Ps=()=>{var H;Ot==="collated"&&((H=Z==null?void 0:Z.juan_files)!=null&&H.length)?(ot(Z.juan_files[0]),l("collated")):Ot==="fulltext"&&((E==null?void 0:E.type)==="work"&&jt&&F(jt.key),ot(null),l("fulltext"))};let vt=null;if(E&&$){const H=$({detail:E,kind:Ot,fullTextKey:E.type==="work"?jt==null?void 0:jt.key:void 0});H&&(vt=t.jsx(In,{href:H}))}else Ot&&(vt=t.jsx(In,{onClick:Ps}));const Os=new Set(_.map(H=>H.key)),Dt=ke.filter(H=>H.key.startsWith("catalog:")&&H.key!=="catalog:loading"||Os.has(H.key)).map(H=>({key:H.key,label:H.label,onClick:()=>l(H.key)})),Ci=()=>{var H;return E?E.type==="work"?t.jsx(_s,{data:E,transport:n,onNavigate:y,renderLink:v,readAction:vt,railTop:S,railLinks:Dt}):E.type==="book"?t.jsx($s,{data:E,transport:n,onNavigate:y,renderLink:v,readAction:vt,railTop:S,railLinks:Dt}):E.type==="collection"?t.jsx(zs,{data:E,catalog:(H=G[0])==null?void 0:H.data,transport:n,onNavigate:y,renderLink:v,readAction:vt,railTop:S,railLinks:Dt,catalogAction:G.length>0?t.jsxs("a",{href:"#catalog",onClick:le=>{le.preventDefault(),l(`catalog:${G[0].resource_id}`)},children:[T(W.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Cs,{data:E,transport:n,onNavigate:y,renderLink:v,railTop:S,railLinks:Dt}):null},Ds=()=>{var le,ue,me,Ne;if(!N||!E)return null;if(s==="basic"||s==="emendated")return Ci();if(typeof s=="string"&&s.startsWith("catalog:")){const J=(le=G.find(xe=>`catalog:${xe.resource_id}`===s))==null?void 0:le.data;return t.jsx(Yn,{data:J,onNavigate:y,renderLink:v})}if(s==="collated")return t.jsx(gi,{index:Z||void 0,workId:e,transport:n,onNavigate:y,activeJuan:De,onJuanChange:ot});if(s==="fulltext"&&E.type==="work"){const J=ce??((ue=fe[0])==null?void 0:ue.key);return J?t.jsx(Nn,{bookId:e,workKey:J,versions:fe,onVersionChange:xe=>{F(xe),ot(null)},transport:n,activeChapter:De,onChapterChange:ot},J):t.jsx("div",{style:{padding:24,color:o("desc-fg")},children:Ce?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(Nn,{index:D||void 0,bookId:e,transport:n,activeChapter:De,onChapterChange:ot});if(s==="lineage"){if(!ie)return t.jsx("div",{style:{color:o("label-fg"),padding:"24px 0"},children:he?"加載中…":"暫無版本圖數據"});const J=E.type==="work"?E:null;return t.jsx(Fs,{graph:ie,renderLink:v,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:a,selectedNodeId:h,collection:u??((me=J==null?void 0:J.version_graph)==null?void 0:me.default_collection),onCollectionChange:x,collectionsAvailable:(Ne=J==null?void 0:J.version_graph)==null?void 0:Ne.collections,collectionCounts:(()=>{var Ri,Ei,Li,Bi,Ni,Wi,Ai;if(!J)return;const xe={},Se=((Ri=Re.current)==null?void 0:Ri.books)??[];xe.all=(((Ei=J.books)==null?void 0:Ei.length)??0)-(((Bi=(Li=J.version_graph)==null?void 0:Li.excluded_books)==null?void 0:Bi.length)??0);const We=(Ni=J.version_graph)==null?void 0:Ni.collections;if(We)for(const Mi of Object.keys(We))xe[Mi]=Kt(J,Se,Mi).nodes.filter(Fi=>Fi.kind==="book"&&!Fi.bridge).length;return xe.core==null&&((Ai=(Wi=J.version_graph)==null?void 0:Wi.core_books)!=null&&Ai.length)&&(xe.core=J.version_graph.core_books.length),xe})()})}if(s==="feedback"&&w)return t.jsx(ws,{resourceId:e,apiUrl:z});const H=_.find(J=>J.key===s);return H?H.render({detail:E,entry:N,transport:n,onNavigate:y}):null};if(I)return t.jsx(It,{style:{minHeight:B,...A},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((H,le)=>t.jsx("div",{style:{height:le===1?40:16,width:H,opacity:.35,background:o("rule")}},le))})});if(K||!E||!N||!an)return t.jsx(It,{style:{minHeight:B,...A},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:o("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const cn=s==="basic"||s==="emendated",Ht=[{label:m??W.detailTab.backToIndex,onClick:k}];if(E.type==="book"&&E.work_id){const H=E.work_id;Ht.push({label:W.indexType.work,id:H,onClick:()=>y==null?void 0:y(H)})}Ht.push({label:W.indexType[E.type]});const Gt=s==="collated"||s==="fulltext",Ii=t.jsx(Pr,{left:t.jsxs(t.Fragment,{children:[L,L?" · ":"",t.jsx(wu,{id:E.id,label:W.label.id,copied:W.action.copied,copyLabel:W.action.copy})]}),right:t.jsxs(t.Fragment,{children:[w&&!cn&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:W.detailTab.submitVersion}),rt&&t.jsx("a",{href:rt.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:o("meta-fg")},children:W.detailTab.dataLicense})]})});return cn?t.jsx("div",{className:C,children:t.jsxs(It,{grid:!0,style:{minHeight:B,...A},children:[t.jsx(Tn,{breadcrumb:t.jsx(Rn,{items:Ht}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Fn,{style:{border:"none",background:"transparent"}}),rt&&t.jsx(Pn,{...rt})]})}),Ci(),Ii]})}):t.jsx("div",{className:C,children:t.jsxs(It,{wide:Gt,style:{minHeight:B,...A},children:[t.jsx(Tn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Xn,{char:"籍"}),t.jsx(Rn,{items:Ht})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Fn,{}),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:W.detailTab.feedback}),rt&&t.jsx(Pn,{...rt})]})}),t.jsx(Rr,{...an,aside:Gt?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:[T("作品信息")," →"]}):an.aside}),!Gt&&ke.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:ke.map(H=>t.jsx(Er,{label:H.label,active:H.key===s||cn&&H.key==="basic",onClick:()=>l(H.key)},H.key))}),t.jsx("div",{style:{marginTop:!Gt&&ke.length>1?8:0},children:Ds()}),Ii]})})};function wu({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 p;(p=navigator.clipboard)==null||p.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 _u(e,n){return n?e.workSubtype[n]??n:""}exports.BidLink=ae.BidLink;exports.BookIndexError=ae.BookIndexError;exports.BookIndexManager=ae.BookIndexManager;exports.BookIndexStorage=ae.BookIndexStorage;exports.BundleStorage=ae.BundleStorage;exports.ConfigError=ae.ConfigError;exports.GithubStorage=ae.GithubStorage;exports.IdGenerationError=ae.IdGenerationError;exports.IdGenerator=ae.IdGenerator;exports.LocalStorage=ae.LocalStorage;exports.MigrationError=ae.MigrationError;exports.StorageError=ae.StorageError;exports.base36Decode=ae.base36Decode;exports.base36Encode=ae.base36Encode;exports.base58Decode=ae.base58Decode;exports.buildId=ae.buildId;exports.buildPromotionMap=ae.buildPromotionMap;exports.cleanName=ae.cleanName;exports.decodeId=ae.decodeId;exports.decodeIdString=ae.decodeIdString;exports.encodeId=ae.encodeId;exports.extractIdFromUrl=ae.extractIdFromUrl;exports.extractStatus=ae.extractStatus;exports.extractType=ae.extractType;exports.normalizeCatalog=ae.normalizeCatalog;exports.parseId=ae.parseId;exports.shardOf=ae.shardOf;exports.smartDecode=ae.smartDecode;exports.validateResource=ae.validateResource;exports.Badge=Zt;exports.BidUrlProvider=Xs;exports.BookDetailLayout=Su;exports.BookFullText=Nn;exports.BookPage=$s;exports.Breadcrumb=Rn;exports.CATALOG_ALL_ID=Ge;exports.CATALOG_CSS=Is;exports.CATALOG_NARROW_QUERY=yi;exports.CATALOG_PAGE_SIZE=ji;exports.CATALOG_UNCLASSIFIED_ID=ht;exports.CardFoot=Mt;exports.CatalogPage=qp;exports.CatalogPager=Bs;exports.CatalogTree=Rs;exports.CheckFilter=Ir;exports.Chip=Lr;exports.ChipWall=Ba;exports.CollatedEdition=gi;exports.CollectionCatalog=Yn;exports.CollectionPage=zs;exports.CreateEntityDialog=hs;exports.DEFAULT_READER_PREFS=ti;exports.DETAIL_CSS=Tr;exports.Dash=Pa;exports.DataTable=Wa;exports.DetailFooter=Pr;exports.DetailGrid=Wt;exports.DetailHeader=Rr;exports.EmendatedBySection=pr;exports.EmptyNote=Ya;exports.EntityDetail=rr;exports.EntityPage=Cs;exports.EntityPickerDialog=bs;exports.EntitySelector=gs;exports.ExpandRow=Oa;exports.ExtLink=Ka;exports.FEEDBACK_FAB_OFFSET_VAR=An;exports.FONT_SIZE_STEPS=dt;exports.FactList=Ta;exports.FeedbackButton=fp;exports.FeedbackDialog=ks;exports.FeedbackForm=Ss;exports.FeedbackList=hi;exports.FeedbackTab=ws;exports.FilterChip=Er;exports.FormInput=_e;exports.FormTextArea=Xe;exports.GUJI_MARKDOWN_FIELD=ma;exports.GUJI_TABLE_NOTATION=Kr;exports.GlyphBadge=Xn;exports.GujiTable=ri;exports.HomePage=Bn;exports.ImagePanel=Ur;exports.IndexApp=bd;exports.IndexBrowser=_n;exports.IndexDetail=Vn;exports.IndexEditor=ys;exports.IndexView=tp;exports.IntroGrid=Ia;exports.LocaleContext=mt;exports.LocaleProvider=al;exports.LocaleToggle=Fn;exports.MetaLine=Te;exports.ModeIndicator=nr;exports.MoreButton=La;exports.MoreLink=yt;exports.PAGE_MAX_WIDTH=Ct;exports.PageFrame=It;exports.Quote=Ha;exports.READER_CSS=Dr;exports.RECENT_IDS_STORAGE_KEY=ut;exports.ROLE_CLASS_ORDER=yr;exports.ReadButton=In;exports.ReaderMdText=ci;exports.ReaderShell=ii;exports.ReaderToc=Gr;exports.RelationPanel=xs;exports.RepoSourceLink=Pn;exports.ResourceEditor=wn;exports.ResourceGroup=Ga;exports.ResourceLine=Ua;exports.ResourceList=Un;exports.ResourceRow=Mr;exports.SNIPPET_MARK_END=qo;exports.SNIPPET_MARK_START=Ko;exports.SearchInput=ir;exports.Sec=$e;exports.Section=Ee;exports.SectionHead=Ra;exports.SideList=ct;exports.SmartBidInput=Yt;exports.SourceEditor=ds;exports.SummaryCard=At;exports.TabFilter=rn;exports.TableHead=Aa;exports.TableRow=Ma;exports.TagRow=Fr;exports.TagRows=Va;exports.TextButton=Ea;exports.TopStrip=Tn;exports.VersionLineageGraph=Ms;exports.VersionLineageList=As;exports.VersionLineageView=Fs;exports.VolumeChips=Na;exports.VolumeLinks=Qn;exports.WorkCard=Ls;exports.WorkCardGrid=Ns;exports.WorkCatalog=jd;exports.WorkPage=_s;exports.bucketResources=nn;exports.buildCatalogTree=Fp;exports.buildCollectionTable=vr;exports.buildLineageGraph=Kt;exports.buildPageUrl=Gn;exports.buildParagraphBlocks=ns;exports.buildVersionRow=mr;exports.buildVersionTable=br;exports.canParagraphize=ln;exports.catalogNodeIdOf=Ap;exports.catalogNodeIdsOf=Mp;exports.catalogPageCount=Hp;exports.catalogTotal=vi;exports.classificationPath=Pt;exports.compareCatalogCards=Dp;exports.computeVersionPartition=xa;exports.defaultWorkLink=Es;exports.deriveDating=da;exports.deriveEditionType=Sr;exports.deriveEra=Bt;exports.deriveYear=tn;exports.deriveYearRange=qn;exports.detailToEditor=vs;exports.detectGenre=sn;exports.displayAuthorRole=Zn;exports.editorToDetail=ep;exports.eraRank=zn;exports.findCatalogPath=pt;exports.flattenTitles=En;exports.flattenToc=Yr;exports.formatTemplate=Lt;exports.formatVolumeRange=on;exports.getDisplayNameFromUrl=tt;exports.getStartPage=Hn;exports.getTypeGroupKey=On;exports.groupRelatedWorks=pa;exports.gujiInlineToPlain=zr;exports.hasGujiMarkdownV02=Cn;exports.hasGujiTableNotation=qr;exports.measureText=et;exports.mergeVolumeResources=Dn;exports.normalizeEra=be;exports.normalizeRole=Jn;exports.normalizeVolumeIndex=Rt;exports.normalizeVolumes=tr;exports.numberToChinese=kr;exports.paginationItems=Ts;exports.parseChineseNumber=qt;exports.parseGujiInline=$r;exports.parseGujiTable=Zr;exports.parseSourceString=ps;exports.renderFullTextBody=mc;exports.renderProperNames=os;exports.renderReaderInline=ai;exports.resourceHref=bt;exports.resourceNote=Nt;exports.roleFacets=jr;exports.rowNo=Fa;exports.sortYear=gr;exports.splitFullTextTables=oi;exports.splitHighlightSnippet=Jo;exports.splitTableRow=Jr;exports.stringifySources=us;exports.toCatalogWorkCard=Op;exports.useBidUrl=je;exports.useConvert=Y;exports.useReaderPrefs=ni;exports.useT=te;exports.validateLineageGraph=eu;exports.volumeStats=Xt;
689
+ `,ht="未分類",Ge="all",ji=20;function Pt(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 Dp(e){const n=Pt(e);return n.length?n.join("/"):ht}function Hp(e){const n=Pt(e);return n.length?n.map((i,r)=>n.slice(0,r+1).join("/")):[ht]}function Gp(e,n=[]){const i=new Map;n.forEach((d,c)=>{const a=[d.cata_l1,d.cata_l2,d.cata_l3,d.cata_l4].filter(u=>!!u);a.forEach((u,x)=>{const g=a.slice(0,x+1).join("/");i.has(g)||i.set(g,c)})});const r=new Map;let s=0;for(const d of e){const c=Pt(d.classification);if(!c.length){s++;continue}let a=r;c.forEach((u,x)=>{const g=c.slice(0,x+1).join("/");let h=a.get(u);h||(h={id:g,label:u,count:0,children:new Map},a.set(u,h)),h.count++,a=h.children})}const l=d=>[...d.values()].sort((c,a)=>{const u=i.get(c.id)??1/0,x=i.get(a.id)??1/0;return u!==x?u-x:c.label.localeCompare(a.label,"zh")}).map(c=>{const a={id:c.id,label:c.label,count:c.count};return c.children.size&&(a.children=l(c.children)),a}),p=l(r);return s>0&&p.push({id:ht,label:ht,count:s}),p}function pt(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const r=pt(i.children,n);if(r.length)return[i,...r]}}return[]}function vi(e){return e.reduce((n,i)=>n+i.count,0)}function Up(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function Vp(e){var d;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 a=c.dynasty||(e.authors.length===1?e.dynasty:void 0);return a?{name:c.name,dynasty:a}:{name:c.name}});s.length&&(n.authors=s);const l=Up(typeof e.description=="string"?e.description:(d=e.description)==null?void 0:d.text);l&&(n.summary=l);const p=Pt(e.classification);return p.length&&(n.classification=p),n}function Yp(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 Kp(e,n=ji){return Math.max(1,Math.ceil(e/n))}function Es(e,n,i=2){if(n<=1)return[1];const r=new Set([1,n]);for(let p=e-i;p<=e+i;p++)p>=1&&p<=n&&r.add(p);const s=[...r].sort((p,d)=>p-d),l=[];return s.forEach((p,d)=>{if(d>0){const c=p-s[d-1];c===2?l.push(p-1):c>2&&l.push(null)}l.push(p)}),l}const qp=()=>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 Jp(e,n,i){const r=[];i&&r.push({id:Ge,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,p)=>{var d;for(const c of l){const a=(d=c.children)!=null&&d.length?c.children:null;r.push({id:c.id,parentId:p,hasChildren:!!a,firstChildId:a?a[0].id:null}),a&&n.has(c.id)&&s(a,c.id)}};return s(e,null),r}function Ls({tree:e,selectedId:n,onSelect:i,allLabel:r="全部",label:s="分類"}){const{convert:l}=V(),p=f.useRef(null),d=n&&n!==Ge?n:null,c=r!==null,[a,u]=f.useState(()=>{const S=new Set;for(const _ of pt(e,d))S.add(_.id);return S});f.useEffect(()=>{const S=pt(e,d);S.length&&u(_=>{if(S.every(z=>_.has(z.id)))return _;const w=new Set(_);for(const z of S)w.add(z.id);return w})},[e,d]);const x=f.useMemo(()=>Jp(e,a,c),[e,a,c]),[g,h]=f.useState(null);f.useEffect(()=>{h(null)},[n]);const b=d??(c?Ge:null),k=f.useMemo(()=>{var w;const S=new Set(x.map(z=>z.id));if(g&&S.has(g))return g;if(b&&S.has(b))return b;const _=pt(e,d).map(z=>z.id).filter(z=>S.has(z));return _.length?_[_.length-1]:((w=x[0])==null?void 0:w.id)??null},[x,g,b,e,d]),m=f.useCallback((S,_)=>{u(w=>{const z=w.has(S),B=_??!z;if(B===z)return w;const E=new Set(w);return B?E.add(S):E.delete(S),E})},[]),v=f.useCallback(S=>{h(S),requestAnimationFrame(()=>{var w;const _=Array.from(((w=p.current)==null?void 0:w.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===S);_==null||_.focus()})},[]),y=f.useCallback((S,_)=>{_&&m(S,!0),i(S)},[i,m]),j=f.useCallback(S=>{const _=S.target.closest("[data-ct-id]");if(!_)return;const w=_.dataset.ctId,z=x.findIndex(C=>C.id===w);if(z<0)return;const B=x[z];let E=null;switch(S.key){case"ArrowDown":E=x[Math.min(x.length-1,z+1)].id;break;case"ArrowUp":E=x[Math.max(0,z-1)].id;break;case"Home":E=x[0].id;break;case"End":E=x[x.length-1].id;break;case"ArrowRight":if(!B.hasChildren)break;a.has(w)?E=B.firstChildId:m(w,!0);break;case"ArrowLeft":B.hasChildren&&a.has(w)?m(w,!1):E=B.parentId;break;case"Enter":case" ":S.preventDefault(),y(w,B.hasChildren);return;default:return}S.preventDefault(),E&&E!==w&&v(E)},[x,a,m,v,y]),$=(S,_)=>S.map(w=>{var A;const z=(A=w.children)!=null&&A.length?w.children:null,B=!!z&&a.has(w.id),E=w.id===d,C=_===1&&w.id===ht;return t.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":z?B:void 0,"aria-selected":E,tabIndex:k===w.id?0:-1,"data-ct-id":w.id,className:C?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{h(w.id),y(w.id,!!z)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:z?W=>{W.stopPropagation(),h(w.id),m(w.id)}:void 0,children:z?t.jsx(qp,{}):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")})]}),B&&t.jsx("ul",{role:"group",children:$(z,_+1)})]},w.id)});return t.jsxs("ul",{ref:p,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:j,children:[c&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!d,tabIndex:k===Ge?0:-1,"data-ct-id":Ge,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{h(Ge),i(Ge)},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 Ns=e=>`/item/${encodeURIComponent(e)}`;function Zp(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Xp(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function Bs({work:e,href:n}){var p,d;const{convert:i}=V(),r=Xp(e.juan),s=((p=e.authors)==null?void 0:p.filter(c=>c.name))??[],l=((d=e.classification)==null?void 0:d.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,a)=>t.jsxs(f.Fragment,{children:[a>0&&"、",c.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(c.dynasty),"〕"]}),i(c.name)]},a))}),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 Ws({page:e,pageCount:n,onPage:i,pageHref:r,label:s="分頁"}){const{convert:l}=V();if(n<=1)return null;const p=c=>a=>{i&&(r&&!Zp(a)||(a.preventDefault(),i(c)))},d=(c,a,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:a});const x={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...x,href:r(c),onClick:p(c),children:a}):t.jsx("button",{type:"button",...x,onClick:u.current?void 0:p(c),children:a})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[d(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:Es(e,n).map((c,a)=>t.jsx("li",{style:{display:"contents"},children:c===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):d(c,c,{current:c===e,aria:l(`第 ${c} 頁`)})},c??`gap${a}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),d(e+1,l("下一頁"),{disabled:e>=n})]})}function As({works:e,workLink:n=Ns,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(Bs,{work:l,href:n(l.id)},l.id))}),t.jsx(Ws,{...r})]})}const Qp=()=>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 eu({tree:e,selectedId:n,page:i,pageCount:r,works:s,onSelect:l,onPage:p,searchSlot:d,workLink:c,pageHref:a,allLabel:u="全部",allTitle:x="全部典籍",pageSize:g=ji,className:h}){const{convert:b}=V(),m=`bim-ct-drawer-${f.useId().replace(/:/g,"")}`,[v,y]=f.useState(!1),j=pt(e,n&&n!==Ge?n:null),$=j.length?j[j.length-1]:null,S=$?$.label:x,_=$?$.count:vi(e),w=f.useCallback(z=>{y(!1),l(z)},[l]);return t.jsxs("div",{className:h?`bim-ct ${h}`:"bim-ct","data-drawer":v?"open":"closed",children:[t.jsx("style",{children:Rs}),t.jsxs("aside",{className:"bim-ct-side","aria-label":b("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":v,"aria-controls":m,onClick:()=>y(z=>!z),children:[t.jsxs("span",{children:[b("分類"),":",b(j.length?j.map(z=>z.label).join(" › "):u??x)]}),t.jsx(Qp,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:m,children:[t.jsx("h2",{className:"bim-ct-side-h",children:b("分類")}),t.jsx(Ls,{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)}),j.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:b(j.slice(0,-1).map(z=>z.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[b(`共 ${_.toLocaleString("en-US")} 種 · 每頁 ${g} 條`),r>1&&b(` · 第 ${i} / ${r} 頁`)]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(As,{works:s,workLink:c,page:i,pageCount:r,onPage:p,pageHref:a})]})]})}function tu(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 nu(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 Mo(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 iu(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 ou(e,n){var a;if(n==="all")return null;const i=(a=e.collections)==null?void 0:a[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 p=r?new Set(i.groups):null,d=new Set(i.book_ids??[]);if(p&&e.node_groups)for(const[u,x]of Object.entries(e.node_groups))p.has(x)&&d.add(u);let c=null;if(i.hypothetical_ids&&(c=new Set(i.hypothetical_ids)),p){c||(c=new Set);for(const u of e.hypothetical_nodes??[])u.group&&p.has(u.group)&&c.add(u.id)}return{books:d,hypos:c}}function Kt(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??[]),p=r.node_groups??{},d=ou(r,i??r.default_collection??"all"),c=d!==null,a=(d==null?void 0:d.books)??null,u=(d==null?void 0:d.hypos)??null,x=new Set,g=new Set;if(c){const $=new Map(n.map(E=>[E.id,E])),S=new Map((r.hypothetical_nodes??[]).map(E=>[E.id,E])),_=E=>{const C=$.get(E);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(W=>W.ref);const A=S.get(E);return A?(A.derived_from??[]).map(W=>W.ref):[]},w=E=>S.has(E)?!u||u.has(E):!a||a.has(E),z=new Set,B=E=>{if(!z.has(E)){z.add(E);for(const C of _(E))l.has(C)||(w(C)||(S.has(C)?g.add(C):$.has(C)&&x.add(C)),B(C))}};for(const E of n)a&&a.has(E.id)&&!l.has(E.id)&&B(E.id);for(const E of r.hypothetical_nodes??[])u&&u.has(E.id)&&B(E.id)}const h=n.filter($=>!l.has($.id)).filter($=>!a||a.has($.id)||x.has($.id)).map($=>{const S=nu($,p);return S&&x.has($.id)&&(S.bridge=!0),S}).filter($=>$!==null),b=(r.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||g.has($.id)).map($=>{const S=tu($);return g.has($.id)&&(S.bridge=!0),S}),k=[...h,...b],m=new Set(k.map($=>$.id)),v=new Set,y=[],j=$=>{v.has($.id)||!m.has($.source)||!m.has($.target)||(v.add($.id),y.push($))};for(const $ of n)l.has($.id)||!$.lineage||a&&!a.has($.id)&&!x.has($.id)||(($.lineage.derived_from??[]).forEach((S,_)=>{j(Mo($.id,S,_))}),($.lineage.related_to??[]).forEach((S,_)=>{j(iu($.id,S,_))}));for(const $ of r.hypothetical_nodes??[])u&&!u.has($.id)&&!g.has($.id)||($.derived_from??[]).forEach((S,_)=>{j(Mo($.id,S,_))});return{nodes:k,edges:y,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function Ms(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function ru(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)),p=new Set([...s,...l]),d=(c,a)=>{p.has(a.ref)||i.push(`${c}: derived_from.ref "${a.ref}" 未在 books 或 hypothetical_nodes 中找到`),a.ref_type==="book"&&!s.has(a.ref)&&i.push(`${c}: derived_from.ref "${a.ref}" 标记为 book 但不在 books 列表中`),a.ref_type==="hypothetical"&&!l.has(a.ref)&&i.push(`${c}: derived_from.ref "${a.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const a=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>d(a,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||i.push(`${a}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const a=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>d(a,u))}return i}const Fs=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:s}=V();if(!e.nodes.length)return t.jsx("div",{style:{...yu,...r},className:i,children:"暂无版本图数据"});const l=new Map,p=new Map;for(const g of e.edges)if(g.kind==="derive"){const h=l.get(g.target)??[];h.push(g),l.set(g.target,h)}else for(const h of[g.source,g.target]){const b=p.get(h)??[];b.push(g),p.set(h,b)}const d=new Map(e.nodes.map(g=>[g.id,g])),c=new Map,a=[];for(const g of e.nodes)if(g.group){const h=c.get(g.group)??[];h.push(g),c.set(g.group,h)}else a.push(g);const u=(g,h)=>(g.year??9999)-(h.year??9999);c.forEach(g=>g.sort(u)),a.sort(u);const x=e.groups.filter(g=>c.has(g.id));return t.jsxs("div",{className:i,style:{...lu,...r},children:[e.title&&t.jsx("div",{style:au,children:s(e.title)}),e.description&&t.jsx("div",{style:cu,children:s(e.description)}),x.map(g=>t.jsx(Fo,{label:g.label,color:g.color,nodes:c.get(g.id),incomingMap:l,siblingMap:p,nodeMap:d,renderLink:n},g.id)),a.length>0&&t.jsx(Fo,{label:"其他",nodes:a,incomingMap:l,siblingMap:p,nodeMap:d,renderLink:n})]})},Fo=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:p})=>{const{convert:d}=V();return t.jsxs("div",{style:du,children:[t.jsx("div",{style:{...pu,borderLeftColor:n??o("widget-border")},children:d(e)}),i.map(c=>t.jsx(su,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:p},c.id))]})},su=({node:e,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",p=e.bridge,{convert:d}=V();return t.jsxs("div",{style:{...uu,borderStyle:l||p?"dashed":"solid",opacity:p?.55:e.status==="lost"?.7:1,background:p?o("bg-subtle"):void 0},title:p?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:xu,children:[t.jsx("span",{style:fu,children:l||!s?d(e.label):s(e.id,d(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:gu,children:Ms(d(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:hu,children:[e.category&&t.jsx(zt,{children:d(e.category)}),e.status==="lost"&&t.jsx(zt,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(zt,{tone:"warn",children:"残本"}),l&&t.jsx(zt,{tone:"info",children:"假想祖本"}),p&&t.jsx(zt,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:mu,children:["现存:",d(e.extant_juan)]}),e.note&&t.jsx("div",{style:bu,children:d(e.note)}),n.length>0&&t.jsxs("div",{style:Oo,children:[t.jsx("div",{style:Do,children:"来源:"}),n.map(c=>{const a=r.get(c.source);return t.jsxs("div",{style:Ho(c.confidence),children:[t.jsx("span",{style:Go,children:d(c.relation)}),t.jsx("span",{children:(a==null?void 0:a.kind)==="book"&&s?s(a.id,d(a.label)):d((a==null?void 0:a.label)??c.source)}),c.confidence!=="consensus"&&c.confidence!=="certain"&&t.jsx(Po,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:Uo,children:["· ",d(c.evidence)]})]},c.id)})]}),i.length>0&&t.jsxs("div",{style:Oo,children:[t.jsx("div",{style:Do,children:"关联:"}),i.map(c=>{const a=c.source===e.id?c.target:c.source,u=r.get(a);return t.jsxs("div",{style:Ho(c.confidence),children:[t.jsx("span",{style:Go,children:d(c.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,d(u.label)):d((u==null?void 0:u.label)??a)}),t.jsx(Po,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:Uo,children:["· ",d(c.evidence)]})]},c.id)})]})]})},zt=({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})},Po=({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},lu={fontSize:"14px",color:o("fg")},au={fontSize:"16px",fontWeight:600,marginBottom:"8px"},cu={fontSize:"13px",color:o("muted"),marginBottom:"16px",lineHeight:1.6},du={marginBottom:"16px"},pu={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:o("fg")},uu={border:`1px solid ${o("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:o("bg")},xu={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},fu={fontSize:"15px",fontWeight:600},gu={fontSize:"12px",color:o("muted")},hu={marginBottom:"6px"},mu={fontSize:"12px",color:o("muted"),margin:"2px 0"},bu={fontSize:"12px",color:o("muted"),fontStyle:"italic",margin:"4px 0"},Oo={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${o("widget-border")}`},Do={fontSize:"11px",color:o("muted"),marginBottom:"2px"},Ho=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Go={display:"inline-block",padding:"0 6px",fontSize:"11px",background:o("tag-bg"),color:o("fg"),borderRadius:"3px",marginRight:"6px"},Uo={fontSize:"11px",color:o("muted")},yu={padding:"20px",textAlign:"center",color:o("muted"),fontSize:"13px"},Ps=({selectedNodeId:e,...n})=>{const[i,r]=f.useState("loading"),[s,l]=f.useState(null);return f.useEffect(()=>{let p=!1;return ju().then(d=>{p||(d?(l(d),r("ready")):r("missing"))}),()=>{p=!0}},[]),i==="loading"?t.jsx("div",{style:Vo,children:"加载图组件中…"}):i==="missing"||!s?t.jsxs("div",{style:Vo,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(vu,{modules:s,selectedNodeId:e,...n})};async function ju(){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 vu=({graph:e,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:l,modules:p})=>{const{ReactFlow:d,Background:c,Controls:a,Handle:u,Position:x,BaseEdge:g,EdgeLabelRenderer:h,getSmoothStepPath:b,dagre:k}=p,m=f.useMemo(()=>({lineage:_=>{var M,P,R,ne;const w=((M=_.data)==null?void 0:M.stepPosition)??.85,[z,B,E]=b({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:w,borderRadius:5}),C=!!((P=_.data)!=null&&P.isSibling),A=C?B:_.targetX-18,W=C?E:_.targetY-12,T=(R=_.data)==null?void 0:R.labelStyle,L=(ne=_.data)==null?void 0:ne.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(g,{id:_.id,path:z,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&t.jsx(h,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${A}px,${W}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:o("bg"),border:`0.5px solid ${o("widget-border")}`,...L,...T},children:_.label})})]})}}),[g,h,b]),v=f.useMemo(()=>({version:_=>{const w=_.data,z=w.kind==="hypothetical",B=w.status==="lost",E=w.isSelected,C=w.bridge,A=w.borderColor??o("muted"),W=C||z?"dashed":"solid",T=C?.5:B?.6:1;return t.jsxs("div",{style:{background:o(C?"bg-subtle":"bg"),border:`2px ${W} ${E?o("primary"):A}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:T,boxShadow:E?o("shadow-node-selected"):z||C?"none":o("shadow-node")},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:x.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("muted"),lineHeight:1.25,marginTop:1},children:w.description}),w.yearText&&t.jsx("div",{style:{fontSize:10,color:o("muted"),lineHeight:1.2},children:Ms(w.yearText,void 0,w.uncertain)}),B&&t.jsx("div",{style:{fontSize:9,color:o("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[u,x]),{convert:y}=V(),{rfNodes:j,rfEdges:$}=f.useMemo(()=>ku(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(d,{nodes:j,edges:$,nodeTypes:v,edgeTypes:m,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(a,{showInteractive:!1})]})})};function ku(e,n,i,r,s=l=>l??""){const d=e.layout==="LR"||!e.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:d?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const a=new Map(e.groups.map(v=>[v.id,v.color??o("muted")]));for(const v of e.nodes)c.setNode(v.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const v of e.edges)v.kind==="derive"&&(u.has(v.relation)||c.setEdge(v.source,v.target));n.layout(c);const x=e.nodes.map(v=>{const y=c.node(v.id),j=r&&v.id===r,$={kind:v.kind,label:s(v.label),bookId:v.kind==="book"?v.id:void 0,yearText:s(v.year_text??wu(v)),uncertain:v.year_uncertain,category:v.category,status:v.status,borderColor:v.group?a.get(v.group):void 0,renderLink:i,isSelected:j,description:s(v.description),bridge:v.bridge};return{id:v.id,type:"version",position:{x:y.x-160/2,y:y.y-90/2},data:$,draggable:!1,selected:j}}),g=.78,h=.06,b=new Map;for(const v of e.edges)v.kind==="derive"&&(b.has(v.source)||b.set(v.source,[]),b.get(v.source).push(v));const k=new Map;for(const[v,y]of b){if(y.length<=1)continue;const j=[...y].sort((S,_)=>{var B,E;const w=((B=c.node(S.target))==null?void 0:B.y)??0,z=((E=c.node(_.target))==null?void 0:E.y)??0;return w-z}),$=j.length;j.forEach((S,_)=>{const w=(_-($-1)/2)*h;k.set(S.id,g+w)})}const m=e.edges.map(v=>Su(v,k.get(v.id),s));return{rfNodes:x,rfEdges:m}}function Su(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=_u(e.confidence),p={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:p,markerStart:s?p:void 0,zIndex:1e3}}function wu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function _u(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 Vo={padding:"40px 20px",textAlign:"center",color:o("muted"),fontSize:"13px",border:`1px dashed ${o("widget-border")}`,borderRadius:8,background:o("bg")},Os=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:p,onCollectionChange:d,collectionsAvailable:c,collectionCounts:a,className:u,style:x})=>{var y;const[g,h]=f.useState(n),b=j=>{h(j),l==null||l(j)},k=(()=>{if(!c)return[];const j=Object.entries(c);return j.length===0||c.all?j:[...j,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),m=!!(d&&k.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:o("muted"),textAlign:"center"},children:"暂无版本传承数据"});const v=p?(y=c==null?void 0:c[p])==null?void 0:y.description:void 0;return t.jsxs("div",{className:u,style:x,children:[t.jsxs("div",{style:$u,children:[t.jsx("button",{onClick:()=>b("list"),style:jn(g==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:jn(g==="graph"),children:"关系图"}),m&&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(([j,$])=>{const S=a==null?void 0:a[j];return t.jsxs("button",{onClick:()=>d==null?void 0:d(j),style:jn(p===j),title:$.description,children:[$.label,S!=null?` ${S}`:""]},j)})]})]}),m&&v&&t.jsx("div",{style:{fontSize:12,color:o("muted"),marginBottom:8,padding:"4px 8px",background:o("bg-subtle"),borderRadius:4},children:v}),g==="list"?t.jsx(Fs,{graph:e,renderLink:i}):t.jsx(Ps,{graph:e,renderLink:i,height:r,selectedNodeId:s})]})},$u={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},jn=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"}),Fn=({style:e})=>{const n=f.useContext(mt);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:"简"})]})},Pn=({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 vn(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function zu(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const Cu=({id:e,transport:n,initialDetail:i,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:p,onJuanChange:d,lineageMode:c="list",onLineageModeChange:a,lineageCollection:u,onLineageCollectionChange:x,initialPage:g=1,selectedLineageNodeId:h,onNavigate:b,onBack:k,backLabel:m,renderLink:v,enrichDetail:y,getSourceLink:j,readLink:$,railTop:S,extraTabs:_=[],showFeedbackTab:w=!0,feedbackApiUrl:z,height:B,footerExtra:E,className:C,style:A})=>{var Ti;const W=ie(),{convert:T}=V(),[L]=f.useState(()=>{if(!zu(e,i))return null;const H={...i},de=r??vn(e,H);return y&&y(de,H),{id:e,entry:de,detail:H}}),[M,P]=f.useState((L==null?void 0:L.entry)??null),[R,ne]=f.useState((L==null?void 0:L.detail)??null),[I,F]=f.useState(!L),[K,G]=f.useState(!1),[U,te]=f.useState([]),[O,Y]=f.useState(!1),[Z,X]=f.useState(null),[se,ge]=f.useState(!1),[he,D]=f.useState(null),[le,oe]=f.useState(!1),[ce,ue]=f.useState([]),[me,Q]=f.useState(!1),[q,N]=f.useState(null),[ee,re]=f.useState(null),[be,ae]=f.useState(!1),ke=f.useRef(null),[Ne,Se]=f.useState(null),De=p!==void 0?p:Ne,ot=f.useCallback(H=>{d?d(H):Se(H)},[d]),ki=f.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){te([]);return}Y(!0);try{if(n.getCollectionCatalogs)te(await n.getCollectionCatalogs(H)||[]);else if(n.getCollectionCatalog){const de=await n.getCollectionCatalog(H);te(de?[{resource_id:"",data:de}]:[])}}catch{te([])}finally{Y(!1)}},[n]),Si=f.useCallback(async H=>{if(!n.getCollatedEditionIndex){X(null);return}ge(!0);try{X(await n.getCollatedEditionIndex(H))}catch{X(null)}finally{ge(!1)}},[n]),wi=f.useCallback(async H=>{if(!n.getBookFullTextIndex){D(null);return}oe(!0);try{D(await n.getBookFullTextIndex(H))}catch{D(null)}finally{oe(!1)}},[n]),_i=f.useCallback(async H=>{var de;if(!n.getWorkFullTextList){ue([]);return}Q(!0);try{const xe=(await n.getWorkFullTextList(H)??[]).filter(ye=>ye.owner_type!=="Book");ue(xe),N(((de=xe.find(ye=>ye.primary)??xe[0])==null?void 0:de.key)??null)}catch{ue([])}finally{Q(!1)}},[n]),$i=f.useCallback(async(H,de)=>{ae(!0);try{if(n.getLineageGraph){const _e=await n.getLineageGraph(H);_e&&re(_e)}const xe=de.version_graph;if(!xe||!xe.enabled){ee||re(null),ke.current=null;return}const ye=de.books??[],Be=[];for(const _e of ye)try{const We=await n.getItem(_e);We&&Be.push(We)}catch{}ke.current={work:de,books:Be};const J=u??xe.default_collection??(xe.core_books&&xe.core_books.length>0?"core":"all"),fe=J==="core"&&Array.isArray(xe.core_books)&&xe.core_books.length>0?"core":J??"all";re(Kt(de,Be,fe))}catch{re(null),ke.current=null}finally{ae(!1)}},[n]),zi=f.useRef({initialDetail:i,initialEntry:r});zi.current={initialDetail:i,initialEntry:r},f.useEffect(()=>{let H=!1;const de=J=>{J.type==="collection"?ki(e):J.type==="work"?((J.has_collated||n.getCollatedEditionIndex)&&Si(e),(J.version_graph||n.getLineageGraph)&&$i(e,J),n.getWorkFullTextList&&_i(e)):J.type==="book"&&J.has_full_text&&n.getBookFullTextIndex&&wi(e)},xe=zi.current;let ye=null;if(L&&L.id===e)ye=L;else if(xe.initialDetail&&xe.initialDetail.id===e){const J={...xe.initialDetail},fe=xe.initialEntry??vn(e,J);y&&y(fe,J),ye={entry:fe,detail:J}}return ye?(G(!1),te(J=>J.length?[]:J),X(null),D(null),ue(J=>J.length?[]:J),N(null),re(null),ke.current=null,P(ye.entry),ne(ye.detail),F(!1),de(ye.detail),()=>{H=!0}):((async()=>{F(!0),G(!1),P(null),ne(null),te([]),X(null),D(null),ue([]),N(null),re(null),ke.current=null;try{const J=await n.getItem(e);if(H)return;if(!J){G(!0);return}const fe=J;let _e=null;if(n.getEntry&&(_e=await n.getEntry(e),H))return;_e||(_e=vn(e,fe)),y&&y(_e,fe),P(_e),ne(fe),de(fe)}catch{H||G(!0)}finally{H||F(!1)}})(),()=>{H=!0})},[e,n,L,y,ki,Si,$i,wi,_i]),f.useEffect(()=>{const H=ke.current;!H||!u||re(Kt(H.work,H.books,u))},[u]);const we=[];if(R){if(we.push({key:"basic",label:W.detailTab.basicInfo}),R.type==="collection"){O&&U.length===0&&we.push({key:"catalog:loading",label:`${W.detailTab.catalog}…`});for(const H of U)we.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${T(H.short_name)}${W.detailTab.catalogSuffix}`:W.detailTab.collectionCatalog})}R.type==="work"&&(Z||se)&&s==="collated"&&we.push({key:"collated",label:se?`${W.detailTab.collatedEdition}…`:W.detailTab.collatedEdition}),R.type==="book"&&(he||le)&&s==="fulltext"&&we.push({key:"fulltext",label:le?`${W.detailTab.fullText}…`:W.detailTab.fullText}),R.type==="work"&&(ce.length>0||me)&&s==="fulltext"&&we.push({key:"fulltext",label:me?`${W.detailTab.fullText}…`:W.detailTab.fullText}),R.type==="work"&&(ee||be)&&we.push({key:"lineage",label:be?`${W.detailTab.lineage}…`:W.detailTab.lineage});for(const H of _)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(R)&&we.push({key:H.key,label:H.label});w&&s==="feedback"&&we.push({key:"feedback",label:W.detailTab.feedback});for(const H of _)H.position==="after-feedback"&&H.shouldShow(R)&&we.push({key:H.key,label:H.label})}f.useEffect(()=>{if(s!=="emendated"||!R)return;l("basic");const H=setTimeout(()=>{var de;(de=document.getElementById("studies"))==null||de.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[s,R,l]);const rt=M&&R&&j?j({activeTab:s,activeJuan:De,entry:M,detail:R}):null,an=f.useMemo(()=>{var Be;if(!R)return null;const de=(R.authors??[]).map(J=>{const fe=Zn(J.role);return`${J.dynasty?`〔${T(J.dynasty)}〕`:""}${T(J.name)}${fe?` ${T(fe)}`:""}`}).join(" · ");let xe=!1;try{xe=pe.extractStatus(R.id)==="draft"}catch{}if(R.type==="book"){const J=R;return{title:T(J.title),subtitle:J.edition?T(J.edition):de||void 0,aside:[xe?W.status.draft:"",de&&J.edition?de:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(R.type==="collection"){const J=R;return{title:T(J.title),subtitle:T(et(J,W.unit.juan))||void 0,aside:[(Be=J.publication_info)==null?void 0:Be.year,xe?W.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:de||void 0}}if(R.type==="entity"){const J=R,fe=We=>We==null?"":We<0?`前${-We}`:String(We),_e=J.birth_year!=null||J.death_year!=null?`${fe(J.birth_year)||"?"}—${fe(J.death_year)||"?"}`:"";return{title:T(J.primary_name||J.title),subtitle:[J.dynasty?`〔${T(J.dynasty)}〕`:"",_e].filter(Boolean).join(" ")||void 0,aside:xe?W.status.draft:void 0,secondLine:void 0}}const ye=T(et(R,W.unit.juan));return{title:T(R.title),subtitle:[ye,de].filter(Boolean).join(" · ")||void 0,aside:[Tu(W,R.subtype),xe?W.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[R,T,W]),Ot=R?R.type==="work"?(((Ti=Z==null?void 0:Z.juan_files)==null?void 0:Ti.length)??0)>0?"collated":ce.length>0?"fulltext":null:R.type==="book"&&((he==null?void 0:he.chapters.length)??0)>0?"fulltext":null:null,jt=ce.find(H=>H.primary)??ce[0],Ds=()=>{var H;Ot==="collated"&&((H=Z==null?void 0:Z.juan_files)!=null&&H.length)?(ot(Z.juan_files[0]),l("collated")):Ot==="fulltext"&&((R==null?void 0:R.type)==="work"&&jt&&N(jt.key),ot(null),l("fulltext"))};let vt=null;if(R&&$){const H=$({detail:R,kind:Ot,fullTextKey:R.type==="work"?jt==null?void 0:jt.key:void 0});H&&(vt=t.jsx(Cn,{href:H}))}else Ot&&(vt=t.jsx(Cn,{onClick:Ds}));const Hs=new Set(_.map(H=>H.key)),Dt=we.filter(H=>H.key.startsWith("catalog:")&&H.key!=="catalog:loading"||Hs.has(H.key)).map(H=>({key:H.key,label:H.label,onClick:()=>l(H.key)})),Ci=()=>{var H;return R?R.type==="work"?t.jsx(zs,{data:R,transport:n,onNavigate:b,renderLink:v,readAction:vt,railTop:S,railLinks:Dt}):R.type==="book"?t.jsx(Cs,{data:R,transport:n,onNavigate:b,renderLink:v,readAction:vt,railTop:S,railLinks:Dt}):R.type==="collection"?t.jsx(Is,{data:R,catalog:(H=U[0])==null?void 0:H.data,transport:n,onNavigate:b,renderLink:v,readAction:vt,railTop:S,railLinks:Dt,catalogAction:U.length>0?t.jsxs("a",{href:"#catalog",onClick:de=>{de.preventDefault(),l(`catalog:${U[0].resource_id}`)},children:[T(W.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Ts,{data:R,transport:n,onNavigate:b,renderLink:v,railTop:S,railLinks:Dt}):null},Gs=()=>{var de,xe,ye,Be;if(!M||!R)return null;if(s==="basic"||s==="emendated")return Ci();if(typeof s=="string"&&s.startsWith("catalog:")){const J=(de=U.find(fe=>`catalog:${fe.resource_id}`===s))==null?void 0:de.data;return t.jsx(Yn,{data:J,onNavigate:b,renderLink:v})}if(s==="collated")return t.jsx(gi,{index:Z||void 0,workId:e,transport:n,onNavigate:b,activeJuan:De,onJuanChange:ot});if(s==="fulltext"&&R.type==="work"){const J=q??((xe=ce[0])==null?void 0:xe.key);return J?t.jsx(Bn,{bookId:e,workKey:J,versions:ce,onVersionChange:fe=>{N(fe),ot(null)},transport:n,activeChapter:De,onChapterChange:ot},J):t.jsx("div",{style:{padding:24,color:o("desc-fg")},children:me?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(Bn,{index:he||void 0,bookId:e,transport:n,activeChapter:De,onChapterChange:ot});if(s==="lineage"){if(!ee)return t.jsx("div",{style:{color:o("label-fg"),padding:"24px 0"},children:be?"加載中…":"暫無版本圖數據"});const J=R.type==="work"?R:null;return t.jsx(Os,{graph:ee,renderLink:v,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:a,selectedNodeId:h,collection:u??((ye=J==null?void 0:J.version_graph)==null?void 0:ye.default_collection),onCollectionChange:x,collectionsAvailable:(Be=J==null?void 0:J.version_graph)==null?void 0:Be.collections,collectionCounts:(()=>{var Ri,Ei,Li,Ni,Bi,Wi,Ai;if(!J)return;const fe={},_e=((Ri=ke.current)==null?void 0:Ri.books)??[];fe.all=(((Ei=J.books)==null?void 0:Ei.length)??0)-(((Ni=(Li=J.version_graph)==null?void 0:Li.excluded_books)==null?void 0:Ni.length)??0);const We=(Bi=J.version_graph)==null?void 0:Bi.collections;if(We)for(const Mi of Object.keys(We))fe[Mi]=Kt(J,_e,Mi).nodes.filter(Fi=>Fi.kind==="book"&&!Fi.bridge).length;return fe.core==null&&((Ai=(Wi=J.version_graph)==null?void 0:Wi.core_books)!=null&&Ai.length)&&(fe.core=J.version_graph.core_books.length),fe})()})}if(s==="feedback"&&w)return t.jsx($s,{resourceId:e,apiUrl:z});const H=_.find(J=>J.key===s);return H?H.render({detail:R,entry:M,transport:n,onNavigate:b}):null};if(I)return t.jsx(It,{style:{minHeight:B,...A},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((H,de)=>t.jsx("div",{style:{height:de===1?40:16,width:H,opacity:.35,background:o("rule")}},de))})});if(K||!R||!M||!an)return t.jsx(It,{style:{minHeight:B,...A},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:o("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const cn=s==="basic"||s==="emendated",Ht=[{label:m??W.detailTab.backToIndex,onClick:k}];if(R.type==="book"&&R.work_id){const H=R.work_id;Ht.push({label:W.indexType.work,id:H,onClick:()=>b==null?void 0:b(H)})}Ht.push({label:W.indexType[R.type]});const Gt=s==="collated"||s==="fulltext",Ii=t.jsx(Pr,{left:t.jsxs(t.Fragment,{children:[E,E?" · ":"",t.jsx(Iu,{id:R.id,label:W.label.id,copied:W.action.copied,copyLabel:W.action.copy})]}),right:t.jsxs(t.Fragment,{children:[w&&!cn&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:W.detailTab.submitVersion}),rt&&t.jsx("a",{href:rt.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:o("meta-fg")},children:W.detailTab.dataLicense})]})});return cn?t.jsx("div",{className:C,children:t.jsxs(It,{grid:!0,style:{minHeight:B,...A},children:[t.jsx(In,{breadcrumb:t.jsx(Tn,{items:Ht}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Fn,{style:{border:"none",background:"transparent"}}),rt&&t.jsx(Pn,{...rt})]})}),Ci(),Ii]})}):t.jsx("div",{className:C,children:t.jsxs(It,{wide:Gt,style:{minHeight:B,...A},children:[t.jsx(In,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Xn,{char:"籍"}),t.jsx(Tn,{items:Ht})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Fn,{}),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:W.detailTab.feedback}),rt&&t.jsx(Pn,{...rt})]})}),t.jsx(Rr,{...an,aside:Gt?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:[T("作品信息")," →"]}):an.aside}),!Gt&&we.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:we.map(H=>t.jsx(Er,{label:H.label,active:H.key===s||cn&&H.key==="basic",onClick:()=>l(H.key)},H.key))}),t.jsx("div",{style:{marginTop:!Gt&&we.length>1?8:0},children:Gs()}),Ii]})})};function Iu({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 p;(p=navigator.clipboard)==null||p.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 Tu(e,n){return n?e.workSubtype[n]??n:""}exports.BidLink=pe.BidLink;exports.BookIndexError=pe.BookIndexError;exports.BookIndexManager=pe.BookIndexManager;exports.BookIndexStorage=pe.BookIndexStorage;exports.BundleStorage=pe.BundleStorage;exports.ConfigError=pe.ConfigError;exports.GithubStorage=pe.GithubStorage;exports.IdGenerationError=pe.IdGenerationError;exports.IdGenerator=pe.IdGenerator;exports.LocalStorage=pe.LocalStorage;exports.MigrationError=pe.MigrationError;exports.StorageError=pe.StorageError;exports.base36Decode=pe.base36Decode;exports.base36Encode=pe.base36Encode;exports.base58Decode=pe.base58Decode;exports.buildId=pe.buildId;exports.buildPromotionMap=pe.buildPromotionMap;exports.cleanName=pe.cleanName;exports.decodeId=pe.decodeId;exports.decodeIdString=pe.decodeIdString;exports.encodeId=pe.encodeId;exports.extractIdFromUrl=pe.extractIdFromUrl;exports.extractStatus=pe.extractStatus;exports.extractType=pe.extractType;exports.normalizeCatalog=pe.normalizeCatalog;exports.parseId=pe.parseId;exports.shardOf=pe.shardOf;exports.smartDecode=pe.smartDecode;exports.validateResource=pe.validateResource;exports.Badge=Zt;exports.BidUrlProvider=el;exports.BookDetailLayout=Cu;exports.BookFullText=Bn;exports.BookPage=Cs;exports.Breadcrumb=Tn;exports.CATALOG_ALL_ID=Ge;exports.CATALOG_CSS=Rs;exports.CATALOG_NARROW_QUERY=yi;exports.CATALOG_PAGE_SIZE=ji;exports.CATALOG_UNCLASSIFIED_ID=ht;exports.CardFoot=Mt;exports.CatalogPage=eu;exports.CatalogPager=Ws;exports.CatalogTree=Ls;exports.CheckFilter=Ir;exports.Chip=Lr;exports.ChipWall=Wa;exports.CollatedEdition=gi;exports.CollectionCatalog=Yn;exports.CollectionPage=Is;exports.CreateEntityDialog=bs;exports.DEFAULT_READER_PREFS=ti;exports.DETAIL_CSS=Tr;exports.Dash=Da;exports.DataTable=Ma;exports.DetailFooter=Pr;exports.DetailGrid=Wt;exports.DetailHeader=Rr;exports.EmendatedBySection=pr;exports.EmptyNote=qa;exports.EntityDetail=rr;exports.EntityPage=Ts;exports.EntityPickerDialog=js;exports.EntitySelector=ms;exports.ExpandRow=Ha;exports.ExtLink=Ja;exports.FEEDBACK_FAB_OFFSET_VAR=An;exports.FONT_SIZE_STEPS=dt;exports.FactList=Ea;exports.FeedbackButton=yp;exports.FeedbackDialog=ws;exports.FeedbackForm=_s;exports.FeedbackList=hi;exports.FeedbackTab=$s;exports.FilterChip=Er;exports.FormInput=ze;exports.FormTextArea=Xe;exports.GUJI_MARKDOWN_FIELD=ya;exports.GUJI_TABLE_NOTATION=Jr;exports.GlyphBadge=Xn;exports.GujiTable=ri;exports.HomePage=Nn;exports.ImagePanel=Vr;exports.IndexApp=Sd;exports.IndexBrowser=wn;exports.IndexDetail=Vn;exports.IndexEditor=vs;exports.IndexView=sp;exports.IntroGrid=Ra;exports.LocaleContext=mt;exports.LocaleProvider=dl;exports.LocaleToggle=Fn;exports.MetaLine=Re;exports.ModeIndicator=nr;exports.MoreButton=Ba;exports.MoreLink=yt;exports.PAGE_MAX_WIDTH=Ct;exports.PageFrame=It;exports.Quote=Ua;exports.READER_CSS=Hr;exports.RECENT_IDS_STORAGE_KEY=ut;exports.ROLE_CLASS_ORDER=yr;exports.ReadButton=Cn;exports.ReaderMdText=ci;exports.ReaderShell=ii;exports.ReaderToc=Ur;exports.RelationPanel=gs;exports.RepoSourceLink=Pn;exports.ResourceEditor=Sn;exports.ResourceGroup=Va;exports.ResourceLine=Ya;exports.ResourceList=Un;exports.ResourceRow=Mr;exports.SNIPPET_MARK_END=qo;exports.SNIPPET_MARK_START=Ko;exports.SearchInput=ir;exports.Sec=Ce;exports.Section=Ee;exports.SectionHead=La;exports.SideList=ct;exports.SmartBidInput=Yt;exports.SourceEditor=us;exports.SummaryCard=At;exports.TabFilter=rn;exports.TableHead=Fa;exports.TableRow=Pa;exports.TagRow=Fr;exports.TagRows=Ka;exports.TextButton=Na;exports.TopStrip=In;exports.VersionLineageGraph=Ps;exports.VersionLineageList=Fs;exports.VersionLineageView=Os;exports.VolumeChips=Aa;exports.VolumeLinks=Qn;exports.WorkCard=Bs;exports.WorkCardGrid=As;exports.WorkCatalog=_d;exports.WorkPage=zs;exports.bucketResources=nn;exports.buildCatalogTree=Gp;exports.buildCollectionTable=vr;exports.buildLineageGraph=Kt;exports.buildPageUrl=Gn;exports.buildParagraphBlocks=os;exports.buildVersionRow=mr;exports.buildVersionTable=br;exports.canParagraphize=ln;exports.catalogNodeIdOf=Dp;exports.catalogNodeIdsOf=Hp;exports.catalogPageCount=Kp;exports.catalogTotal=vi;exports.classificationPath=Pt;exports.compareCatalogCards=Yp;exports.computeVersionPartition=ga;exports.defaultWorkLink=Ns;exports.deriveDating=ua;exports.deriveEditionType=Sr;exports.deriveEra=Nt;exports.deriveYear=tn;exports.deriveYearRange=qn;exports.detailToEditor=Ss;exports.detectGenre=sn;exports.displayAuthorRole=Zn;exports.editorToDetail=rp;exports.eraRank=$n;exports.findCatalogPath=pt;exports.flattenTitles=Rn;exports.flattenToc=qr;exports.formatTemplate=Lt;exports.formatVolumeRange=on;exports.getDisplayNameFromUrl=tt;exports.getStartPage=Hn;exports.getTypeGroupKey=On;exports.groupRelatedWorks=xa;exports.gujiInlineToPlain=zr;exports.hasGujiMarkdownV02=zn;exports.hasGujiTableNotation=Zr;exports.measureText=et;exports.mergeVolumeResources=Dn;exports.normalizeEra=je;exports.normalizeRole=Jn;exports.normalizeVolumeIndex=Rt;exports.normalizeVolumes=tr;exports.numberToChinese=kr;exports.paginationItems=Es;exports.parseChineseNumber=qt;exports.parseGujiInline=$r;exports.parseGujiTable=Qr;exports.parseSourceString=xs;exports.pickReaderVersion=Kr;exports.readerVersionOptionLabel=Ln;exports.readerVersionsFromFullText=rc;exports.renderFullTextBody=jc;exports.renderProperNames=ss;exports.renderReaderInline=ai;exports.resourceHref=bt;exports.resourceNote=Bt;exports.roleFacets=jr;exports.rowNo=Oa;exports.sortYear=gr;exports.splitFullTextTables=oi;exports.splitHighlightSnippet=Jo;exports.splitTableRow=Xr;exports.stringifySources=fs;exports.toCatalogWorkCard=Vp;exports.useBidUrl=ve;exports.useConvert=V;exports.useReaderPrefs=ni;exports.useT=ie;exports.validateLineageGraph=ru;exports.volumeStats=Xt;