book-index-ui 0.10.3 → 0.10.5

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.
Files changed (3) hide show
  1. package/dist/index.cjs +56 -42
  2. package/dist/index.js +2901 -2840
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -1,18 +1,18 @@
1
- "use strict";var il=Object.create;var Vi=Object.defineProperty;var ol=Object.getOwnPropertyDescriptor;var rl=Object.getOwnPropertyNames;var sl=Object.getPrototypeOf,ll=Object.prototype.hasOwnProperty;var al=(e,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of rl(n))!ll.call(e,s)&&s!==i&&Vi(e,s,{get:()=>n[s],enumerable:!(r=ol(n,s))||r.enumerable});return e};var Rt=(e,n,i)=>(i=e!=null?il(sl(e)):{},al(n||!e||!e.__esModule?Vi(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const be=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),g=require("react"),cl=require("react-markdown"),dl=require("remark-gfm"),pl=e=>`/book-index?id=${e}`,nr=g.createContext(pl);function ul({buildUrl:e,children:n}){const i=g.useMemo(()=>e,[e]);return t.jsx(nr.Provider,{value:i,children:n})}function Re(){return g.useContext(nr)}const ir="",or="";function rr(e){const n=[];let i=!1,r=e;for(;r.length;){const s=i?or:ir,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 Yi='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',xl=[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:Yi,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:Yi,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],fl=Object.assign({},...xl.map(e=>e.tokens)),sr={};for(const[e,n]of Object.entries(fl))sr[e]=`var(--bim-${e}, ${n.value})`;function o(e){const n=sr[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function xt(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function gl(e,n){return xt(e).includes(n)}const Rn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},ml={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};o("quality-published"),o("quality-fine"),o("quality-rough"),o("quality-ocr");const _t=g.createContext(null),lr={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:"圖片資源"}},hl={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:"图片资源"}},bl={"zh-Hant":lr,"zh-Hans":hl},ar="bim-locale";function yl(){try{const e=localStorage.getItem(ar);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function jl(e){try{localStorage.setItem(ar,e)}catch{}}const vl="zh-Hans",kl=({locale:e,onLocaleChange:n,children:i})=>{const[r,s]=g.useState(e??vl),l=e??r;g.useEffect(()=>{if(e)return;const u=yl();u&&u!==r&&s(u)},[]);const[c,p]=g.useState(null);g.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(u=>{const f=u.Converter({from:"tw",to:"cn"});p(()=>f)}).catch(()=>{p(()=>u=>u)}):p(null)},[l]);const a=g.useCallback(u=>{s(u),jl(u),n==null||n(u)},[n]),d=g.useMemo(()=>({locale:l,setLocale:a,messages:bl[l],converter:c}),[l,a,c]);return t.jsx(_t.Provider,{value:d,children:i})};function ce(){const e=g.useContext(_t);return(e==null?void 0:e.messages)??lr}const Sl=2e3;function U(){const e=g.useContext(_t),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,r=g.useRef(new Map),s=g.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const l=g.useCallback(c=>{if(!c)return"";if(!i)return c;const p=r.current.get(c);if(p!==void 0)return p;const a=i(c);if(r.current.size>=Sl){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(c,a),a},[i]);return g.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Ht(e,n){return e.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function wl(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 _l(){return{id:"",name:"",url:"",type:"text",details:""}}const En=({items:e,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const l=ce(),[c,p]=g.useState(null),a=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],d=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=y=>{if(!s)return!0;const k=xt(y);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},f=e.map((y,k)=>({item:y,originalIndex:k})).filter(({item:y})=>u(y)),x=()=>{const y=_l();s&&(y.type=s),n([...e,y]),p(e.length)},m=y=>{n(e.filter((k,$)=>$!==y)),p(null)},h=(y,k,$)=>{const S=[...e];if(S[y]={...S[y],[k]:$},k==="url"&&!S[y].id){const _=wl($);_&&(S[y].id=_)}n(S)},v=(y,k,$)=>{const _={...e[y].metadata||{}};$?_[k]=$:delete _[k],h(y,"metadata",Object.keys(_).length>0?_:void 0)},b=(y,k)=>{const $=k.trim()?k.split(/[,,、]/).map(S=>S.trim()).filter(Boolean):void 0;h(y,"structure",$)},j=(y,k,$)=>{const _=e[y].coverage||{level:1,ranges:""};k==="level"?_.level=parseInt($)||1:_.ranges=$,h(y,"coverage",_.ranges?_:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[f.map(({item:y,originalIndex:k})=>{var $,S,_;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(c===k?null:k),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:c===k?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:$l(y.type??"text"),color:o("on-color-fg")},children:(()=>{var z,T;const w=xt(y);return w.length===0?y.type??"text":w.length===1?((z=a.find(R=>R.value===w[0]))==null?void 0:z.label)??w[0]:w.includes("text")&&w.includes("image")?((T=a.find(R=>R.value==="text+image"))==null?void 0:T.label)??"text+image":w.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${l.editor.resourcePlaceholder} ${k+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&&zl(k,r==null?void 0:r[k],i,l),t.jsx("button",{onClick:w=>{w.stopPropagation(),m(k)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),c===k&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:[gl(y,"image")&&y.url&&Cl(y,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Et,children:[t.jsx("span",{style:Nt,children:l.label.type}),t.jsx("select",{value:y.type,onChange:w=>h(k,"type",w.target.value),style:{...Ve,flex:1},children:a.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]}),t.jsxs("label",{style:Et,children:[t.jsx("span",{style:Nt,children:l.label.rootType}),t.jsx("select",{value:y.root_type||"catalog",onChange:w=>h(k,"root_type",w.target.value),style:{...Ve,flex:1},children:d.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:y.id,onChange:w=>h(k,"id",w.target.value),placeholder:l.editor.idAutoExtract,style:{...Ve,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:y.name,onChange:w=>h(k,"name",w.target.value),placeholder:l.editor.resourceName,style:{...Ve,flex:1}})]}),t.jsx("input",{type:"text",value:y.url,onChange:w=>h(k,"url",w.target.value),placeholder:l.editor.resourceUrl,style:Ve}),t.jsx("input",{type:"text",value:(($=y.structure)==null?void 0:$.join("、"))||"",onChange:w=>b(k,w.target.value),placeholder:l.editor.structurePlaceholder,style:Ve}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Et,children:[t.jsx("span",{style:Nt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((S=y.coverage)==null?void 0:S.level)??"",onChange:w=>j(k,"level",w.target.value),placeholder:"1",style:{...Ve,width:"60px"}})]}),t.jsxs("label",{style:{...Et,flex:1},children:[t.jsx("span",{style:Nt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:((_=y.coverage)==null?void 0:_.ranges)||"",onChange:w=>j(k,"ranges",w.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...Ve,flex:1}})]})]}),t.jsx("textarea",{value:y.details||"",onChange:w=>h(k,"details",w.target.value),placeholder:l.editor.detailsPlaceholder,style:{...Ve,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 T;return t.jsxs("label",{style:{...Et,gap:"4px"},children:[t.jsx("span",{style:{...Nt,minWidth:"56px"},children:z}),t.jsx("input",{type:"text",value:((T=y.metadata)==null?void 0:T[w])||"",onChange:R=>v(k,w,R.target.value),placeholder:z,style:{...Ve,flex:1}})]},w)})})]})]})]})]},k)}),t.jsxs("button",{onClick:x,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:l.action.addResource})]})]})};function $l(e){switch(e){case"text":return o("restype-text");case"image":return o("restype-image");case"text+image":return o("restype-text-image");case"physical":return o("restype-physical")}}function zl(e,n,i,r){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:c=>{c.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 Cl(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 Ve={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"},Et={display:"flex",alignItems:"center",gap:"6px"},Nt={fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap"},Il={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function $t(e){try{return Il[new URL(e).hostname]}catch{return}}const Ki={text:0,image:1,physical:2};function Jn(e){return e.length===0?"physical":[...e].sort((n,i)=>(Ki[n]??99)-(Ki[i]??99)).join("+")}function Zn(e){var c;const n=p=>{const a=p.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const d=p.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},i=new Map;for(let p=0;p<e.length;p++){const a=e[p];if(a.volumes&&a.volumes.length>0)continue;const d=n(a.name);if(!d)continue;const[u,f]=d,x=`${u}|${Jn(xt(a))}`;i.has(x)||i.set(x,{base:{...a,name:u,url:"",volumes:[]},volumes:[],indices:[]});const m=i.get(x);m.volumes.push({volume:f,url:a.url||void 0,status:"found"}),m.indices.push(p)}const r=[],s=new Set;for(const p of i.values())if(!(p.volumes.length<2)){p.volumes.sort((a,d)=>a.volume-d.volume),p.base.volumes=p.volumes,p.base.expected_volumes=p.volumes.length,p.base.url||(p.base.url=((c=p.volumes.find(a=>a.url))==null?void 0:c.url)??""),r.push(p.base);for(const a of p.indices)s.add(a)}const l=[...r];for(let p=0;p<e.length;p++)s.has(p)||l.push(e[p]);return l}function cr(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 dr(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||cr(n)}))}function cn(e){const n=dr(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 Xn(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 Qn(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 zt(e){if(!e.url)return;const n=Xn(e.metadata);return n?Qn(e.url,n):e.url}const qi={text:o("restype-text"),image:o("restype-image"),"text+image":o("restype-text-image"),physical:o("restype-physical")};function Tl(e){return e.includes("text")&&e.includes("image")?qi["text+image"]:qi[e[0]||"physical"]}const ei=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const l=ce(),{convert:c}=U(),p=g.useMemo(()=>Zn(e||[]),[e]),{mirrorGroups:a,ungroupedItems:d}=g.useMemo(()=>{const b=new Map,j=[];for(const y of p){const k=y.group;k?(b.has(k)||b.set(k,[]),b.get(k).push(y)):j.push(y)}for(const y of b.values())y.sort((k,$)=>{const S=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return S(k)-S($)});return{mirrorGroups:b,ungroupedItems:j}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},f=b=>u[b]?u[b]:b.split("+").map(j=>u[j]||j).join("+");if(!p||p.length===0)return t.jsx("div",{style:{padding:"16px",color:o("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((b,j)=>t.jsx(bn,{item:b},b.id||j))});const x=(b,j)=>{const y=i==null?void 0:i[b],k=(y==null?void 0:y.label)||b,$=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:c(k)}),$&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.5},children:c($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((S,_)=>t.jsx(bn,{item:S,onNavigate:r,renderLink:s},S.id||_))})]},`group-${b}`)},m=new Map;for(const b of d){const j=Jn(xt(b));m.has(j)||m.set(j,[]),m.get(j).push(b)}const h=["text","image","text+image","physical"],v=[...h.filter(b=>m.has(b)),...[...m.keys()].filter(b=>!h.includes(b)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([b,j])=>x(b,j)),v.map(b=>{const j=m.get(b),y=Tl(b.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:f(b)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((k,$)=>t.jsx(bn,{item:k,onNavigate:r,renderLink:s},k.id||$))})]},b)})]})},Rl={bw:{label:"",bg:o("colormode-bw-bg"),fg:o("colormode-bw-fg")},color:{label:"",bg:o("colormode-color-bg"),fg:o("colormode-color-fg")}},bn=({item:e})=>{const n=ce(),{convert:i}=U(),[r,s]=g.useState(!1),l=g.useMemo(()=>(e.url?$t(e.url):void 0)||i(e.name),[e.url,e.name,i]),c=g.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(h=>({...h,url:h.url||cr(h)})),[e.volumes]),p=c&&c.length>0,a=p?new Set(c.filter(h=>h.status!=="missing").map(h=>h.volume)).size:0,d=p?new Set(c.filter(h=>h.status==="missing").map(h=>h.volume)).size:0,u=e.expected_volumes??(p?a+d:0),f=e.color_mode?{...Rl[e.color_mode],label:n.colorMode[e.color_mode]}:null,x=e.details&&!p?i(e.details):null,m={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",background:o("input-bg"),fontSize:"12px",color:o("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:m,children:[t.jsx("span",{style:{fontWeight:500},children:l}),f&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:f.bg,color:f.fg},children:f.label}),x&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:x}),p&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[a,"/",u,n.unit.volume,d>0&&t.jsxs("span",{style:{color:o("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),e.url&&t.jsx("a",{href:(()=>{const h=Xn(e.metadata);return h?Qn(e.url,h):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:o("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),p&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),p&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:c.map(h=>{const v=h.status==="missing";return h.url&&!v?t.jsx("a",{href:h.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:h.volume},h.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:o(v?"missing-fg":"desc-fg"),textDecoration:v?"line-through":"none",opacity:v?.6:1},children:h.volume},h.volume)})})]})},pr=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:c})=>{const p=ce(),a=e==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",f=u?u.split(/[/\\]/).pop()||u:"",x={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:o("primary-soft"),color:o("primary")},m={onMouseOver:v=>v.currentTarget.style.opacity="0.8",onMouseOut:v=>v.currentTarget.style.opacity="1"},h=t.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...x,background:o(d?"warning":"success"),color:o("on-color-fg")},...m,children:[t.jsx("span",{children:d?"📝":"📚"}),t.jsx("span",{children:d?"draft":"official"})]});return i==="index-browser"?a?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[h,t.jsxs("div",{onClick:r,title:p.mode.switchToSync,style:x,...m,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:p.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:c,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px"},...m,children:[t.jsx("span",{children:"📂"}),f&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:p.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:f||p.mode.configurePath,style:{...x,background:"transparent",padding:"6px",fontSize:"12px"},...m,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:a?p.mode.switchToGithub:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:a?"📁":"🌐"}),t.jsx("span",{children:a?p.mode.localMode:p.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&t.jsxs("div",{onClick:c,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...m,children:[t.jsx("span",{children:"📂"}),f&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]}),!a&&f&&t.jsxs("div",{style:{...x,background:o("mode-active-bg"),color:o("on-color-fg"),cursor:"default"},title:u,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:f})]})]})},dn="bim-search-history",Ji=10,Zi=8;function Ft(){try{const e=localStorage.getItem(dn);return e?JSON.parse(e):[]}catch{return[]}}function El(e){try{const n=Ft().filter(i=>i!==e);n.unshift(e),n.length>Ji&&(n.length=Ji),localStorage.setItem(dn,JSON.stringify(n))}catch{}}function Nl(e){try{const n=Ft().filter(i=>i!==e);localStorage.setItem(dn,JSON.stringify(n))}catch{}}function Ll(){try{localStorage.removeItem(dn)}catch{}}const ur=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:l})=>{const c=ce(),p=l??c.search.placeholder,a={work:c.indexType.work,book:c.indexType.book,collection:c.indexType.collection,entity:c.indexType.entity},[d,u]=g.useState(!1),[f,x]=g.useState([]),[m,h]=g.useState(-1),[v,b]=g.useState(Ft),j=g.useRef(null),y=g.useRef(null),k=g.useRef(null),$=g.useRef(!1);g.useEffect(()=>{h(-1);const C=n.trim();if(!C){x(v.map(A=>({type:"history",text:A})));return}if(!e.searchAll){x([]);return}let P=!1;const M=setTimeout(()=>{e.searchAll(C,Zi).then(A=>{if(P)return;const F=[...A.works,...A.books,...A.collections,...A.entities??[]];x(F.slice(0,Zi).map(G=>({type:"entry",text:G.title||G.id,entry:G})))}).catch(()=>{P||x([])})},80);return()=>{P=!0,clearTimeout(M)}},[n,v,e]),g.useEffect(()=>{const C=P=>{k.current&&!k.current.contains(P.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),g.useEffect(()=>{const C=P=>{var M,A;if(P.key==="/"&&document.activeElement!==j.current){const F=(M=document.activeElement)==null?void 0:M.tagName;if(F==="INPUT"||F==="TEXTAREA"||F==="SELECT")return;P.preventDefault(),(A=j.current)==null||A.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const S=g.useCallback(C=>{C.trim()&&(El(C.trim()),b(Ft())),r(C),u(!1)},[r]),_=g.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=g.useCallback(C=>{if(!d||f.length===0){C.key==="Enter"&&S(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),h(P=>(P+1)%f.length);break;case"ArrowUp":C.preventDefault(),h(P=>(P-1+f.length)%f.length);break;case"Enter":C.preventDefault(),m>=0&&m<f.length?_(f[m]):S(n);break;case"Escape":C.preventDefault(),u(!1);break}},[d,f,m,n,S,_]),z=g.useCallback((C,P)=>{P.stopPropagation(),Nl(C),b(Ft()),x(M=>M.filter(A=>!(A.type==="history"&&A.text===C)))},[]),T=g.useCallback(C=>{C.stopPropagation(),Ll(),b([]),x([])},[]);g.useEffect(()=>{if(m>=0&&y.current){const C=y.current.children;C[m]&&C[m].scrollIntoView({block:"nearest"})}},[m]);const R=!n.trim()&&v.length>0;return t.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:j,type:"text",placeholder:p,value:n,onChange:C=>{i(C.target.value),u(!0)},onCompositionStart:()=>{$.current=!0},onCompositionEnd:()=>{$.current=!1},onFocus:()=>{u(!0)},onKeyDown:w,style:{width:"100%",padding:"8px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),d&&f.length>0&&t.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:o("input-bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"6px",boxShadow:o("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[R&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:o("desc-fg"),borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("span",{children:c.search.history}),t.jsx("button",{onClick:T,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:c.search.clearAll})]}),f.map((C,P)=>t.jsxs("div",{onClick:()=>_(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:o("fg"),background:P===m?o("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:[a[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&t.jsx("button",{onClick:M=>z(C.text,M),style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:c.action.remove,children:"×"})]},`${C.type}-${C.text}-${P}`))]})]})},vt="bim-recent-ids",Xi="bim-recent-entries",Qi=50,yn=5,Bl=50,Al=200;function bt(){try{const e=localStorage.getItem(vt);if(e)return JSON.parse(e);const n=localStorage.getItem(Xi);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(vt,JSON.stringify(i)),localStorage.removeItem(Xi),i}return[]}catch{return[]}}function eo(e){try{const n=bt().filter(i=>i!==e);n.unshift(e),n.length>Qi&&(n.length=Qi),localStorage.setItem(vt,JSON.stringify(n))}catch{}}function Wl(e){try{const n=bt().filter(i=>i!==e);localStorage.setItem(vt,JSON.stringify(n))}catch{}}function Ml(){try{localStorage.removeItem(vt)}catch{}}const Fl={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Nn=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a,hideModeIndicator:d,resultVariant:u="compact",renderEntry:f,initialQuery:x,onQueryChange:m,headerRight:h})=>{const v=ce(),b=[{type:"work",icon:"✍️",name:v.indexType.work,key:"works"},{type:"book",icon:"📖",name:v.indexType.book,key:"books"},{type:"collection",icon:"📚",name:v.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:v.indexType.entity,key:"entities"}],[j,y]=g.useState(x??""),[k,$]=g.useState(null),[S,_]=g.useState(null),[w,z]=g.useState(!1),[T,R]=g.useState(null),[C,P]=g.useState(""),[M,A]=g.useState(!x),[F,G]=g.useState(bt),[D,E]=g.useState([]),[le,W]=g.useState(!1),[Y,re]=g.useState(!1),[te,J]=g.useState(null),[ee,ge]=g.useState(null),se=g.useRef(void 0),ie=g.useRef(!1),O=g.useCallback(async(Q,V)=>{if(!Q.trim()){A(!0),$(null),_(null);return}A(!1),z(!0),P("");try{if(e.searchAll){const B=await e.searchAll(Q,V??yn);$(B)}else{const B=["work","book","collection","entity"],oe=await Promise.all(B.map(de=>e.search(Q,de,{page:1,pageSize:V??yn})));$({works:oe[0].entries,books:oe[1].entries,collections:oe[2].entries,entities:oe[3].entries,totalWorks:oe[0].total,totalBooks:oe[1].total,totalCollections:oe[2].total,totalEntities:oe[3].total})}}catch(B){P(B instanceof Error?B.message:String(B)),$(null)}finally{z(!1)}},[e]);g.useEffect(()=>{let Q=!1;const V=()=>{var pe,Be;const B=["work","book","collection","entity"],oe=Promise.all(B.map(Ee=>e.loadEntries(Ee,{page:1,pageSize:1}).catch(()=>({total:0})))),de=((pe=e.getResourceCounts)==null?void 0:pe.call(e).catch(()=>null))??Promise.resolve(null),_e=((Be=e.getSubtypeStats)==null?void 0:Be.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([oe,de,_e]).then(([Ee,we,Je])=>{Q||(J({works:Ee[0].total,books:Ee[1].total,collections:Ee[2].total,entities:Ee[3].total,hasText:we==null?void 0:we.hasText,hasImage:we==null?void 0:we.hasImage}),Je&&ge(Je))})};return e.getCounts?e.getCounts().then(B=>{var oe,de;Q||(J({works:B.works,books:B.books,collections:B.collections,entities:B.entities,hasText:(oe=B.resourceCounts)==null?void 0:oe.hasText,hasImage:(de=B.resourceCounts)==null?void 0:de.hasImage}),B.subtypeStats&&ge(B.subtypeStats))}).catch(()=>{Q||V()}):V(),()=>{Q=!0}},[e]),g.useEffect(()=>{ie.current||!(x!=null&&x.trim())||(ie.current=!0,O(x))},[x,O]);const Z=g.useCallback(Q=>{if(y(Q),!Q.trim()){m==null||m(Q),A(!0),$(null),_(null);return}se.current&&clearTimeout(se.current),se.current=setTimeout(()=>{_(null),m==null||m(Q),O(Q)},Al)},[O,m]),ne=g.useCallback(Q=>{se.current&&clearTimeout(se.current),m==null||m(Q),O(Q)},[O,m]),N=g.useCallback(Q=>{_(Q),O(j,Bl)},[j,O]);g.useEffect(()=>{if(!F.length){E([]);return}let Q=!1;return W(!0),Promise.all(F.slice(0,10).map(async V=>{var B,oe,de;try{if(e.getEntry){const pe=await e.getEntry(V);if(pe)return pe}const _e=await e.getItem(V);if(_e){const pe=_e.authors;return{id:V,title:_e.title||V,type:_e.type||"work",author:(B=pe==null?void 0:pe[0])==null?void 0:B.name,dynasty:(oe=pe==null?void 0:pe[0])==null?void 0:oe.dynasty,role:(de=pe==null?void 0:pe[0])==null?void 0:de.role,edition:_e.edition||void 0}}}catch{}return{id:V,title:V,type:"work",notFound:!0}})).then(V=>{Q||(E(V),W(!1))}),()=>{Q=!0}},[F,e]);const I=Q=>{R(Q.id),eo(Q.id),G(bt()),r==null||r(Q)},K=(Q,V)=>{if(r&&Pl(V)){V.preventDefault(),I(Q);return}eo(Q.id),G(bt())},X=Q=>{Wl(Q),G(bt())},xe=()=>{Ml(),G([])},fe=Q=>b.find(V=>V.type===Q),ke=k&&(k.works.length>0||k.books.length>0||k.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:v.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!d&&t.jsx(pr,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(ur,{transport:e,value:j,onChange:Z,onSearch:ne,onEntrySelect:I}),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:v.action.newEntry})]}),te&&M&&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:te.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:te.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[v.indexType.work," ",t.jsx("strong",{style:{color:o("fg")},children:te.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.book," ",t.jsx("strong",{style:{color:o("fg")},children:te.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.collection," ",t.jsx("strong",{style:{color:o("fg")},children:te.collections.toLocaleString()}),te.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.entity," ",t.jsx("strong",{style:{color:o("fg")},children:te.entities.toLocaleString()})]})]})}),te.hasImage!=null&&te.hasText!=null&&t.jsxs("span",{children:[v.resourceType.image," ",t.jsx("strong",{style:{color:o("fg")},children:te.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.resourceType.text," ",t.jsx("strong",{style:{color:o("fg")},children:te.hasText.toLocaleString()})]})]}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:w?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:v.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})]}):M?t.jsx("div",{style:{flex:1},children:le?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:v.search.loading}):D.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:v.search.recentBrowse}),t.jsx("button",{onClick:xe,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:v.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:D.slice(0,Y?10:3).map(Q=>Q.notFound?t.jsx(Gl,{id:Q.id,onRemove:X,t:v},Q.id):t.jsx(to,{entry:Q,selected:T===Q.id,onClick:K,getConfig:fe,onRemove:X},Q.id))}),!Y&&D.length>3&&t.jsx("button",{onClick:()=>re(!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:v.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:v.search.searchTitle}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:v.search.searchSubtitle})]})}):ke?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:Ol}),b.map(({type:Q,icon:V,name:B,key:oe})=>{const de=k[oe]??[],_e=Fl[oe],pe=k[_e]??0;if(de.length===0)return null;const Ee=!(S===Q)&&pe>yn;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:[V," ",B,t.jsxs("span",{style:{fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[pe," ",v.unit.items]})]}),Ee&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>N(Q),style:{border:"none",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"12px"},children:v.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:de.map(we=>{if(f)return t.jsx(g.Fragment,{children:f(we)},we.id);const Je=u==="card"?Hl:to;return t.jsx(Je,{entry:we,selected:T===we.id,onClick:K,getConfig:fe,query:j},we.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:Ht(v.search.noResultsFor,{query:j})}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:v.search.tryOther})]})})]})};function Pl(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const Ol=`
1
+ "use strict";var rl=Object.create;var Vi=Object.defineProperty;var sl=Object.getOwnPropertyDescriptor;var ll=Object.getOwnPropertyNames;var al=Object.getPrototypeOf,cl=Object.prototype.hasOwnProperty;var dl=(e,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of ll(n))!cl.call(e,s)&&s!==i&&Vi(e,s,{get:()=>n[s],enumerable:!(r=sl(n,s))||r.enumerable});return e};var Et=(e,n,i)=>(i=e!=null?rl(al(e)):{},dl(n||!e||!e.__esModule?Vi(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const he=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),g=require("react"),pl=require("react-markdown"),ul=require("remark-gfm"),xl=e=>`/book-index?id=${e}`,ir=g.createContext(xl);function fl({buildUrl:e,children:n}){const i=g.useMemo(()=>e,[e]);return t.jsx(ir.Provider,{value:i,children:n})}function Ne(){return g.useContext(ir)}const or="",rr="";function sr(e){const n=[];let i=!1,r=e;for(;r.length;){const s=i?rr:or,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 Yi='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',gl=[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:Yi,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:Yi,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],ml=Object.assign({},...gl.map(e=>e.tokens)),lr={};for(const[e,n]of Object.entries(ml))lr[e]=`var(--bim-${e}, ${n.value})`;function o(e){const n=lr[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function ft(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function hl(e,n){return ft(e).includes(n)}const Rn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},bl={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};o("quality-published"),o("quality-fine"),o("quality-rough"),o("quality-ocr");const $t=g.createContext(null),ar={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:"圖片資源"}},yl={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:"图片资源"}},jl=["曹霑"];function vl(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function kl(e,n=jl){const i=[...new Set(n.filter(Boolean))].sort((l,c)=>c.length-l.length);if(!i.length)return e;const r=new RegExp(`(${i.map(vl).join("|")})`,"g"),s=new Set(i);return l=>{if(!l)return e(l);const c=l.split(r);return c.length===1?e(l):c.map((p,a)=>a%2===1&&s.has(p)?p:p&&e(p)).join("")}}const Sl={"zh-Hant":ar,"zh-Hans":yl},cr="bim-locale";function wl(){try{const e=localStorage.getItem(cr);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function _l(e){try{localStorage.setItem(cr,e)}catch{}}const $l="zh-Hans",zl=({locale:e,onLocaleChange:n,children:i})=>{const[r,s]=g.useState(e??$l),l=e??r;g.useEffect(()=>{if(e)return;const u=wl();u&&u!==r&&s(u)},[]);const[c,p]=g.useState(null);g.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(u=>{const f=u.Converter({from:"tw",to:"cn"});p(()=>kl(f))}).catch(()=>{p(()=>u=>u)}):p(null)},[l]);const a=g.useCallback(u=>{s(u),_l(u),n==null||n(u)},[n]),d=g.useMemo(()=>({locale:l,setLocale:a,messages:Sl[l],converter:c}),[l,a,c]);return t.jsx($t.Provider,{value:d,children:i})};function ae(){const e=g.useContext($t);return(e==null?void 0:e.messages)??ar}const Cl=2e3;function Y(){const e=g.useContext($t),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,r=g.useRef(new Map),s=g.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const l=g.useCallback(c=>{if(!c)return"";if(!i)return c;const p=r.current.get(c);if(p!==void 0)return p;const a=i(c);if(r.current.size>=Cl){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(c,a),a},[i]);return g.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Gt(e,n){return e.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function Il(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 Tl(){return{id:"",name:"",url:"",type:"text",details:""}}const En=({items:e,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const l=ae(),[c,p]=g.useState(null),a=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],d=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=y=>{if(!s)return!0;const v=ft(y);return s==="text"?v.includes("text"):s==="image"?v.includes("image")||v.includes("physical"):s==="physical"?v.includes("physical"):v.includes(s)},f=e.map((y,v)=>({item:y,originalIndex:v})).filter(({item:y})=>u(y)),x=()=>{const y=Tl();s&&(y.type=s),n([...e,y]),p(e.length)},m=y=>{n(e.filter((v,$)=>$!==y)),p(null)},h=(y,v,$)=>{const S=[...e];if(S[y]={...S[y],[v]:$},v==="url"&&!S[y].id){const _=Il($);_&&(S[y].id=_)}n(S)},k=(y,v,$)=>{const _={...e[y].metadata||{}};$?_[v]=$:delete _[v],h(y,"metadata",Object.keys(_).length>0?_:void 0)},b=(y,v)=>{const $=v.trim()?v.split(/[,,、]/).map(S=>S.trim()).filter(Boolean):void 0;h(y,"structure",$)},j=(y,v,$)=>{const _=e[y].coverage||{level:1,ranges:""};v==="level"?_.level=parseInt($)||1:_.ranges=$,h(y,"coverage",_.ranges?_:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[f.map(({item:y,originalIndex:v})=>{var $,S,_;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(c===v?null:v),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:c===v?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Rl(y.type??"text"),color:o("on-color-fg")},children:(()=>{var z,T;const w=ft(y);return w.length===0?y.type??"text":w.length===1?((z=a.find(R=>R.value===w[0]))==null?void 0:z.label)??w[0]:w.includes("text")&&w.includes("image")?((T=a.find(R=>R.value==="text+image"))==null?void 0:T.label)??"text+image":w.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${l.editor.resourcePlaceholder} ${v+1}`}),y.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:y.id}),y.url&&t.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:w=>w.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&y.url&&El(v,r==null?void 0:r[v],i,l),t.jsx("button",{onClick:w=>{w.stopPropagation(),m(v)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),c===v&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:[hl(y,"image")&&y.url&&Nl(y,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Nt,children:[t.jsx("span",{style:Lt,children:l.label.type}),t.jsx("select",{value:y.type,onChange:w=>h(v,"type",w.target.value),style:{...Ve,flex:1},children:a.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]}),t.jsxs("label",{style:Nt,children:[t.jsx("span",{style:Lt,children:l.label.rootType}),t.jsx("select",{value:y.root_type||"catalog",onChange:w=>h(v,"root_type",w.target.value),style:{...Ve,flex:1},children:d.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:y.id,onChange:w=>h(v,"id",w.target.value),placeholder:l.editor.idAutoExtract,style:{...Ve,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:y.name,onChange:w=>h(v,"name",w.target.value),placeholder:l.editor.resourceName,style:{...Ve,flex:1}})]}),t.jsx("input",{type:"text",value:y.url,onChange:w=>h(v,"url",w.target.value),placeholder:l.editor.resourceUrl,style:Ve}),t.jsx("input",{type:"text",value:(($=y.structure)==null?void 0:$.join("、"))||"",onChange:w=>b(v,w.target.value),placeholder:l.editor.structurePlaceholder,style:Ve}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Nt,children:[t.jsx("span",{style:Lt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((S=y.coverage)==null?void 0:S.level)??"",onChange:w=>j(v,"level",w.target.value),placeholder:"1",style:{...Ve,width:"60px"}})]}),t.jsxs("label",{style:{...Nt,flex:1},children:[t.jsx("span",{style:Lt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:((_=y.coverage)==null?void 0:_.ranges)||"",onChange:w=>j(v,"ranges",w.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...Ve,flex:1}})]})]}),t.jsx("textarea",{value:y.details||"",onChange:w=>h(v,"details",w.target.value),placeholder:l.editor.detailsPlaceholder,style:{...Ve,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 T;return t.jsxs("label",{style:{...Nt,gap:"4px"},children:[t.jsx("span",{style:{...Lt,minWidth:"56px"},children:z}),t.jsx("input",{type:"text",value:((T=y.metadata)==null?void 0:T[w])||"",onChange:R=>k(v,w,R.target.value),placeholder:z,style:{...Ve,flex:1}})]},w)})})]})]})]})]},v)}),t.jsxs("button",{onClick:x,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:l.action.addResource})]})]})};function Rl(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 El(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:c=>{c.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 Nl(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 Ve={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"},Nt={display:"flex",alignItems:"center",gap:"6px"},Lt={fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap"},Ll={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function zt(e){try{return Ll[new URL(e).hostname]}catch{return}}const Ki={text:0,image:1,physical:2};function Jn(e){return e.length===0?"physical":[...e].sort((n,i)=>(Ki[n]??99)-(Ki[i]??99)).join("+")}function Zn(e){var c;const n=p=>{const a=p.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const d=p.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},i=new Map;for(let p=0;p<e.length;p++){const a=e[p];if(a.volumes&&a.volumes.length>0)continue;const d=n(a.name);if(!d)continue;const[u,f]=d,x=`${u}|${Jn(ft(a))}`;i.has(x)||i.set(x,{base:{...a,name:u,url:"",volumes:[]},volumes:[],indices:[]});const m=i.get(x);m.volumes.push({volume:f,url:a.url||void 0,status:"found"}),m.indices.push(p)}const r=[],s=new Set;for(const p of i.values())if(!(p.volumes.length<2)){p.volumes.sort((a,d)=>a.volume-d.volume),p.base.volumes=p.volumes,p.base.expected_volumes=p.volumes.length,p.base.url||(p.base.url=((c=p.volumes.find(a=>a.url))==null?void 0:c.url)??""),r.push(p.base);for(const a of p.indices)s.add(a)}const l=[...r];for(let p=0;p<e.length;p++)s.has(p)||l.push(e[p]);return l}function dr(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 pr(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||dr(n)}))}function cn(e){const n=pr(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 Xn(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 Qn(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 Ct(e){if(!e.url)return;const n=Xn(e.metadata);return n?Qn(e.url,n):e.url}const qi={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")?qi["text+image"]:qi[e[0]||"physical"]}const ei=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const l=ae(),{convert:c}=Y(),p=g.useMemo(()=>Zn(e||[]),[e]),{mirrorGroups:a,ungroupedItems:d}=g.useMemo(()=>{const b=new Map,j=[];for(const y of p){const v=y.group;v?(b.has(v)||b.set(v,[]),b.get(v).push(y)):j.push(y)}for(const y of b.values())y.sort((v,$)=>{const S=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return S(v)-S($)});return{mirrorGroups:b,ungroupedItems:j}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},f=b=>u[b]?u[b]:b.split("+").map(j=>u[j]||j).join("+");if(!p||p.length===0)return t.jsx("div",{style:{padding:"16px",color:o("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((b,j)=>t.jsx(bn,{item:b},b.id||j))});const x=(b,j)=>{const y=i==null?void 0:i[b],v=(y==null?void 0:y.label)||b,$=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:c(v)}),$&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.5},children:c($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((S,_)=>t.jsx(bn,{item:S,onNavigate:r,renderLink:s},S.id||_))})]},`group-${b}`)},m=new Map;for(const b of d){const j=Jn(ft(b));m.has(j)||m.set(j,[]),m.get(j).push(b)}const h=["text","image","text+image","physical"],k=[...h.filter(b=>m.has(b)),...[...m.keys()].filter(b=>!h.includes(b)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([b,j])=>x(b,j)),k.map(b=>{const j=m.get(b),y=Bl(b.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:f(b)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((v,$)=>t.jsx(bn,{item:v,onNavigate:r,renderLink:s},v.id||$))})]},b)})]})},Al={bw:{label:"",bg:o("colormode-bw-bg"),fg:o("colormode-bw-fg")},color:{label:"",bg:o("colormode-color-bg"),fg:o("colormode-color-fg")}},bn=({item:e})=>{const n=ae(),{convert:i}=Y(),[r,s]=g.useState(!1),l=g.useMemo(()=>(e.url?zt(e.url):void 0)||i(e.name),[e.url,e.name,i]),c=g.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(h=>({...h,url:h.url||dr(h)})),[e.volumes]),p=c&&c.length>0,a=p?new Set(c.filter(h=>h.status!=="missing").map(h=>h.volume)).size:0,d=p?new Set(c.filter(h=>h.status==="missing").map(h=>h.volume)).size:0,u=e.expected_volumes??(p?a+d:0),f=e.color_mode?{...Al[e.color_mode],label:n.colorMode[e.color_mode]}:null,x=e.details&&!p?i(e.details):null,m={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",background:o("input-bg"),fontSize:"12px",color:o("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:m,children:[t.jsx("span",{style:{fontWeight:500},children:l}),f&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:f.bg,color:f.fg},children:f.label}),x&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:x}),p&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[a,"/",u,n.unit.volume,d>0&&t.jsxs("span",{style:{color:o("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),e.url&&t.jsx("a",{href:(()=>{const h=Xn(e.metadata);return h?Qn(e.url,h):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:o("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),p&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),p&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:c.map(h=>{const k=h.status==="missing";return h.url&&!k?t.jsx("a",{href:h.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:h.volume},h.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:h.volume},h.volume)})})]})},ur=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:c})=>{const p=ae(),a=e==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",f=u?u.split(/[/\\]/).pop()||u:"",x={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:o("primary-soft"),color:o("primary")},m={onMouseOver:k=>k.currentTarget.style.opacity="0.8",onMouseOut:k=>k.currentTarget.style.opacity="1"},h=t.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...x,background:o(d?"warning":"success"),color:o("on-color-fg")},...m,children:[t.jsx("span",{children:d?"📝":"📚"}),t.jsx("span",{children:d?"draft":"official"})]});return i==="index-browser"?a?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[h,t.jsxs("div",{onClick:r,title:p.mode.switchToSync,style:x,...m,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:p.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:c,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px"},...m,children:[t.jsx("span",{children:"📂"}),f&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:p.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:f||p.mode.configurePath,style:{...x,background:"transparent",padding:"6px",fontSize:"12px"},...m,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:a?p.mode.switchToGithub:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:a?"📁":"🌐"}),t.jsx("span",{children:a?p.mode.localMode:p.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&t.jsxs("div",{onClick:c,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...m,children:[t.jsx("span",{children:"📂"}),f&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]}),!a&&f&&t.jsxs("div",{style:{...x,background:o("mode-active-bg"),color:o("on-color-fg"),cursor:"default"},title:u,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:f})]})]})},dn="bim-search-history",Ji=10,Zi=8;function Pt(){try{const e=localStorage.getItem(dn);return e?JSON.parse(e):[]}catch{return[]}}function Wl(e){try{const n=Pt().filter(i=>i!==e);n.unshift(e),n.length>Ji&&(n.length=Ji),localStorage.setItem(dn,JSON.stringify(n))}catch{}}function Ml(e){try{const n=Pt().filter(i=>i!==e);localStorage.setItem(dn,JSON.stringify(n))}catch{}}function Fl(){try{localStorage.removeItem(dn)}catch{}}const xr=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:l})=>{const c=ae(),p=l??c.search.placeholder,a={work:c.indexType.work,book:c.indexType.book,collection:c.indexType.collection,entity:c.indexType.entity},[d,u]=g.useState(!1),[f,x]=g.useState([]),[m,h]=g.useState(-1),[k,b]=g.useState(Pt),j=g.useRef(null),y=g.useRef(null),v=g.useRef(null),$=g.useRef(!1);g.useEffect(()=>{h(-1);const C=n.trim();if(!C){x(k.map(A=>({type:"history",text:A})));return}if(!e.searchAll){x([]);return}let O=!1;const M=setTimeout(()=>{e.searchAll(C,Zi).then(A=>{if(O)return;const F=[...A.works,...A.books,...A.collections,...A.entities??[]];x(F.slice(0,Zi).map(G=>({type:"entry",text:G.title||G.id,entry:G})))}).catch(()=>{O||x([])})},80);return()=>{O=!0,clearTimeout(M)}},[n,k,e]),g.useEffect(()=>{const C=O=>{v.current&&!v.current.contains(O.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),g.useEffect(()=>{const C=O=>{var M,A;if(O.key==="/"&&document.activeElement!==j.current){const F=(M=document.activeElement)==null?void 0:M.tagName;if(F==="INPUT"||F==="TEXTAREA"||F==="SELECT")return;O.preventDefault(),(A=j.current)==null||A.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const S=g.useCallback(C=>{C.trim()&&(Wl(C.trim()),b(Pt())),r(C),u(!1)},[r]),_=g.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=g.useCallback(C=>{if(!d||f.length===0){C.key==="Enter"&&S(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),h(O=>(O+1)%f.length);break;case"ArrowUp":C.preventDefault(),h(O=>(O-1+f.length)%f.length);break;case"Enter":C.preventDefault(),m>=0&&m<f.length?_(f[m]):S(n);break;case"Escape":C.preventDefault(),u(!1);break}},[d,f,m,n,S,_]),z=g.useCallback((C,O)=>{O.stopPropagation(),Ml(C),b(Pt()),x(M=>M.filter(A=>!(A.type==="history"&&A.text===C)))},[]),T=g.useCallback(C=>{C.stopPropagation(),Fl(),b([]),x([])},[]);g.useEffect(()=>{if(m>=0&&y.current){const C=y.current.children;C[m]&&C[m].scrollIntoView({block:"nearest"})}},[m]);const R=!n.trim()&&k.length>0;return t.jsxs("div",{ref:v,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:j,type:"text",placeholder:p,value:n,onChange:C=>{i(C.target.value),u(!0)},onCompositionStart:()=>{$.current=!0},onCompositionEnd:()=>{$.current=!1},onFocus:()=>{u(!0)},onKeyDown:w,style:{width:"100%",padding:"8px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),d&&f.length>0&&t.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:o("input-bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"6px",boxShadow:o("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[R&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:o("desc-fg"),borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("span",{children:c.search.history}),t.jsx("button",{onClick:T,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:c.search.clearAll})]}),f.map((C,O)=>t.jsxs("div",{onClick:()=>_(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:o("fg"),background:O===m?o("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children: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:[a[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&t.jsx("button",{onClick:M=>z(C.text,M),style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:c.action.remove,children:"×"})]},`${C.type}-${C.text}-${O}`))]})]})},kt="bim-recent-ids",Xi="bim-recent-entries",Qi=50,yn=5,Pl=50,Ol=200;function yt(){try{const e=localStorage.getItem(kt);if(e)return JSON.parse(e);const n=localStorage.getItem(Xi);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(kt,JSON.stringify(i)),localStorage.removeItem(Xi),i}return[]}catch{return[]}}function eo(e){try{const n=yt().filter(i=>i!==e);n.unshift(e),n.length>Qi&&(n.length=Qi),localStorage.setItem(kt,JSON.stringify(n))}catch{}}function Dl(e){try{const n=yt().filter(i=>i!==e);localStorage.setItem(kt,JSON.stringify(n))}catch{}}function Hl(){try{localStorage.removeItem(kt)}catch{}}const Gl={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Nn=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a,hideModeIndicator:d,resultVariant:u="compact",renderEntry:f,initialQuery:x,onQueryChange:m,headerRight:h})=>{const k=ae(),b=[{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"}],[j,y]=g.useState(x??""),[v,$]=g.useState(null),[S,_]=g.useState(null),[w,z]=g.useState(!1),[T,R]=g.useState(null),[C,O]=g.useState(""),[M,A]=g.useState(!(x!=null&&x.trim())),[F,G]=g.useState(yt),[U,E]=g.useState([]),[ie,P]=g.useState(!1),[re,ce]=g.useState(!1),[K,V]=g.useState(null),[q,xe]=g.useState(null),oe=g.useRef(void 0),ne=g.useRef(!1),D=g.useCallback(async(W,B)=>{if(!W.trim()){A(!0),$(null),_(null);return}A(!1),z(!0),O("");try{if(e.searchAll){const te=await e.searchAll(W,B??yn);$(te)}else{const te=["work","book","collection","entity"],se=await Promise.all(te.map(Se=>e.search(W,Se,{page:1,pageSize:B??yn})));$({works:se[0].entries,books:se[1].entries,collections:se[2].entries,entities:se[3].entries,totalWorks:se[0].total,totalBooks:se[1].total,totalCollections:se[2].total,totalEntities:se[3].total})}}catch(te){O(te instanceof Error?te.message:String(te)),$(null)}finally{z(!1)}},[e]);g.useEffect(()=>{let W=!1;const B=()=>{var je,Je;const te=["work","book","collection","entity"],se=Promise.all(te.map($e=>e.loadEntries($e,{page:1,pageSize:1}).catch(()=>({total:0})))),Se=((je=e.getResourceCounts)==null?void 0:je.call(e).catch(()=>null))??Promise.resolve(null),me=((Je=e.getSubtypeStats)==null?void 0:Je.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([se,Se,me]).then(([$e,ze,Ze])=>{W||(V({works:$e[0].total,books:$e[1].total,collections:$e[2].total,entities:$e[3].total,hasText:ze==null?void 0:ze.hasText,hasImage:ze==null?void 0:ze.hasImage}),Ze&&xe(Ze))})};return e.getCounts?e.getCounts().then(te=>{var se,Se;W||(V({works:te.works,books:te.books,collections:te.collections,entities:te.entities,hasText:(se=te.resourceCounts)==null?void 0:se.hasText,hasImage:(Se=te.resourceCounts)==null?void 0:Se.hasImage}),te.subtypeStats&&xe(te.subtypeStats))}).catch(()=>{W||B()}):B(),()=>{W=!0}},[e]),g.useEffect(()=>{ne.current||!(x!=null&&x.trim())||(ne.current=!0,D(x))},[x,D]);const X=g.useCallback(W=>{if(y(W),!W.trim()){m==null||m(W),A(!0),$(null),_(null);return}oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{_(null),m==null||m(W),D(W)},Ol)},[D,m]),ee=g.useCallback(W=>{oe.current&&clearTimeout(oe.current),m==null||m(W),D(W)},[D,m]),N=g.useCallback(W=>{_(W),D(j,Pl)},[j,D]);g.useEffect(()=>{if(!F.length){E([]);return}let W=!1;return P(!0),Promise.all(F.slice(0,10).map(async B=>{var te,se,Se;try{if(e.getEntry){const je=await e.getEntry(B);if(je)return je}const me=await e.getItem(B);if(me){const je=me.authors;return{id:B,title:me.title||B,type:me.type||"work",author:(te=je==null?void 0:je[0])==null?void 0:te.name,dynasty:(se=je==null?void 0:je[0])==null?void 0:se.dynasty,role:(Se=je==null?void 0:je[0])==null?void 0:Se.role,edition:me.edition||void 0}}}catch{}return{id:B,title:B,type:"work",notFound:!0}})).then(B=>{W||(E(B),P(!1))}),()=>{W=!0}},[F,e]);const I=W=>{R(W.id),eo(W.id),G(yt()),r==null||r(W)},J=(W,B)=>{if(r&&Vl(B)){B.preventDefault(),I(W);return}eo(W.id),G(yt())},Q=W=>{Dl(W),G(yt())},pe=()=>{Hl(),G([])},ue=W=>b.find(B=>B.type===W),ke=!M&&!v&&!C,_e=v&&(v.works.length>0||v.books.length>0||v.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:[h,!d&&t.jsx(ur,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(xr,{transport:e,value:j,onChange:X,onSearch:ee,onEntrySelect:I}),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})]}),K&&M&&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:q?t.jsxs(t.Fragment,{children:[(q.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:o("fg")},children:q.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:o("fg")},children:K.books.toLocaleString()})," 本"]}),q.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:o("fg")},children:q.article.toLocaleString()})," 篇"]}):null,q.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:o("fg")},children:q.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:o("fg")},children:K.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[k.indexType.work," ",t.jsx("strong",{style:{color:o("fg")},children:K.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.indexType.book," ",t.jsx("strong",{style:{color:o("fg")},children:K.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.indexType.collection," ",t.jsx("strong",{style:{color:o("fg")},children:K.collections.toLocaleString()}),K.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:K.entities.toLocaleString()})]})]})}),K.hasImage!=null&&K.hasText!=null&&t.jsxs("span",{children:[k.resourceType.image," ",t.jsx("strong",{style:{color:o("fg")},children:K.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.resourceType.text," ",t.jsx("strong",{style:{color:o("fg")},children:K.hasText.toLocaleString()})]})]}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:w||ke?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg"),minHeight:Ul,boxSizing:"border-box"},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})]}):M?t.jsx("div",{style:{flex:1},children:ie?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:k.search.loading}):U.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:pe,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:U.slice(0,re?10:3).map(W=>W.notFound?t.jsx(Jl,{id:W.id,onRemove:Q,t:k},W.id):t.jsx(to,{entry:W,selected:T===W.id,onClick:J,getConfig:ue,onRemove:Q},W.id))}),!re&&U.length>3&&t.jsx("button",{onClick:()=>ce(!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("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:k.search.searchTitle}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:k.search.searchSubtitle})]})}):_e?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:Yl}),b.map(({type:W,icon:B,name:te,key:se})=>{const Se=v[se]??[],me=Gl[se],je=v[me]??0;if(Se.length===0)return null;const $e=!(S===W)&&je>yn;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:[B," ",te,t.jsxs("span",{style:{fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[je," ",k.unit.items]})]}),$e&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>N(W),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:Se.map(ze=>{if(f)return t.jsx(g.Fragment,{children:f(ze)},ze.id);const Ze=u==="card"?ql:to;return t.jsx(Ze,{entry:ze,selected:T===ze.id,onClick:J,getConfig:ue,query:j},ze.id)})})]},W)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:Gt(k.search.noResultsFor,{query:j})}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:k.search.tryOther})]})})]})},Ul=240;function Vl(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const Yl=`
2
2
  @media (max-width: 719px), (pointer: coarse) {
3
3
  .bim-ib-viewall { position: relative; }
4
4
  .bim-ib-viewall::after {
5
5
  content: ""; position: absolute; left: 50%; top: 50%;
6
6
  width: max(calc(100% + 8px), 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
7
7
  }
8
- }`,xr={color:"inherit",textDecoration:"none"},Dl=({snippet:e})=>{const{convert:n}=U();return t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.6},children:rr(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(g.Fragment,{children:n(i.text)},r))})},Hl=({entry:e,selected:n,onClick:i,getConfig:r,query:s})=>{const l=ce(),{convert:c}=U(),p=c(e.title||e.primary_name||e.id),a=e.measure_info?c(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",d=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&d.length?d.find(m=>{const h=typeof m=="string"?m:m==null?void 0:m.book_title;return h==null?void 0:h.toLowerCase().includes(s.toLowerCase())}):void 0,f=o("cover-accent"),x=Re();return t.jsxs("a",{href:x(e.id),onClick:m=>i(e,m),className:"bim-result-card",style:{...xr,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, ${f} 50%, ${o("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${f} 14%, ${o("bg")}), color-mix(in srgb, ${f} 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, ${f} 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:f},children:Array.from(p).map((m,h)=>t.jsx("span",{children:m},h))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:o("fg")},children:p}),a&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:a})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",c(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:c(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",c(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",c(e.era),"〕"]}),e.edition&&t.jsx("span",{children:c(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[l.search.alias,":",c(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(Dl,{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]})]})]})]})},to=({entry:e,selected:n,onClick:i,getConfig:r,query:s,onRemove:l})=>{const c=ce(),{convert:p}=U(),a=[...e.additional_titles||[],...e.attached_texts||[]],d=s&&a.length?a.find(f=>{const x=typeof f=="string"?f:f==null?void 0:f.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,u=Re();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:f=>i(e,f),className:"bim-result-card",style:{...xr,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx("span",{style:{fontSize:"16px"},children:r(e.type).icon}),t.jsx("span",{style:{fontSize:"9px",color:o("desc-fg"),lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:p(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{title:c.misc.textResource,children:"📝"}),e.has_image&&t.jsx("span",{title:c.misc.imageResource,children:"🖼️"})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",p(e.era),"〕"]}),e.edition&&p(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:p(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.juan_count,c.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",p(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:p(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",p(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),d&&t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:[c.search.alias,":",p(d)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:c.search.removeFromRecent,"aria-label":c.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:"×"})]})},Gl=({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 Ul(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 Vl({data:e}){const{convert:n}=U(),{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 Yl({alt_names:e}){const{convert:n}=U(),i=new Map;for(const l of e){const c=l.type||"別名";i.has(c)||i.set(c,[]),i.get(c).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((l,c)=>{const p=r.indexOf(l),a=r.indexOf(c);return p===-1&&a===-1?0:p===-1?1:a===-1?-1:p-a});return t.jsx("div",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const c=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:c.map((p,a)=>t.jsxs("span",{children:[a>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},a))})]},l)})})}function Kl({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 ql({works:e,transport:n,onNavigate:i,renderLink:r}){const s=ce(),{convert:l}=U(),c=Re(),[p,a]=g.useState(new Map);g.useEffect(()=>{if(!n)return;let x=!1;const m=e.map(v=>v.work_id);return(async()=>{const v=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(m);let $=!0;for(let S=0;S<m.length;S++){const _=k[S];_!=null&&_.title?v.set(m[S],_.title):_!=null&&_.primary_name?v.set(m[S],_.primary_name):$=!1}if($)return v}catch{}const b=[...m],j=8,y=new Array(j).fill(0).map(async()=>{for(;b.length;){const k=b.shift();if(!k)break;if(!v.has(k))try{if(n.getEntry){const _=await n.getEntry(k);if(_!=null&&_.title){v.set(k,_.title);continue}}const $=await n.getItem(k),S=$&&($.title||$.primary_name)||k;v.set(k,S)}catch{v.set(k,k)}}});return await Promise.all(y),v})().then(v=>{x||a(v)}),()=>{x=!0}},[e,n]);const d=new Map;for(const x of e){const m=x.role||"";d.has(m)||d.set(m,[]),d.get(m).push(x)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],f=[...d.keys()].sort((x,m)=>{const h=u.indexOf(x),v=u.indexOf(m);return h===-1&&v===-1?x.localeCompare(m):h===-1?1:v===-1?-1:h-v});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,")"]})]}),f.map(x=>{const m=d.get(x);return t.jsxs("div",{style:{marginBottom:"8px"},children:[x&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"2px"},children:[l(x)," ",t.jsxs("span",{style:{color:o("desc-fg")},children:["(",m.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:x?"16px":"0",listStyle:x?"disc":"none",fontSize:"14px",lineHeight:1.8},children:m.map((h,v)=>{const b=l(p.get(h.work_id)||h.work_id);return r?t.jsx("li",{children:r(h.work_id,b)},v):i?t.jsx("li",{children:t.jsx("a",{href:c(h.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),i(h.work_id))},style:{color:o("link-fg"),textDecoration:"underline",cursor:"pointer"},children:b})},v):t.jsx("li",{children:b},v)})})]},x)})]})}const fr=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:l})=>{var f;const c=ce(),{convert:p}=U();let a=!1;try{a=be.extractStatus(e.id)==="draft"}catch{}const d=Ul(e),u=e.subtype==="people"?"人物":e.subtype==="place"?"地名":e.subtype==="dynasty"?"朝代":e.subtype==="anonymous"?"佚名":e.subtype==="collective"?"集体":e.subtype;return t.jsxs("div",{children:[!l&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:o("fg")},children:[p(e.primary_name),t.jsx(Vl,{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:c.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),a&&t.jsx("span",{style:{padding:"1px 6px",background:o("warn-bg"),border:`1px solid ${o("warn-border")}`,borderRadius:"2px",color:o("warn-fg")},children:c.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),d&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:o("widget-bg"),border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(Yl,{alt_names:e.alt_names}),t.jsx(Kl,{data:e}),((f=e.description)==null?void 0:f.text)&&t.jsx("p",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(e.description.text)}),e.works&&e.works.length>0&&t.jsx(ql,{works:e.works,transport:n,onNavigate:i,renderLink:r})]})},gr={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})},Jl={...gr,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},tt=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:s}=U(),l=n?Jl:gr;return t.jsx("div",{className:r,style:i,children:t.jsx(cl,{remarkPlugins:[dl],components:l,children:s(e)})})},Zl=["〇","一","二","三","四","五","六","七","八","九"],no=["","十","百","千"];function mr(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 c=parseInt(n[l]),p=i-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=no[p]:r+=Zl[c]+no[p])}return r}function hr(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 Xl={book:o("type-book"),work:o("type-work"),collection:o("type-collection"),entity:o("type-entity")};function Ql({type:e}){const n=ce();return t.jsx("span",{style:hr(Xl[e]),children:n.indexType[e]})}function ea({isDraft:e}){const n=ce(),i=o(e?"status-draft":"status-official");return t.jsx("span",{style:hr(i),children:e?n.status.draft:n.status.official})}function ta({id:e}){const n=ce(),[i,r]=g.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 Pe({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 Ye({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 br({authors:e,type:n,onNavigate:i,renderLink:r}){const{convert:s}=U();return t.jsx("span",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.6},children:e.map((l,c)=>{const p=s(l.name),a=l.entity_id?t.jsx(De,{id:l.entity_id,label:p,onNavigate:i,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:p});return t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),a,l.role&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},c)})})}function De({id:e,label:n,onNavigate:i,renderLink:r}){const s=Re();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 na({id:e,title:n,edition:i,type:r,isDraft:s,authors:l,volumeText:c,meta:p,headerExtra:a,onNavigate:d,renderLink:u}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:o("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:i}),c&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:c})]}),a&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(Ql,{type:r}),t.jsx(ea,{isDraft:s}),t.jsx(ta,{id:e})]}),((l==null?void 0:l.length)||p.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(br,{authors:l,type:r,onNavigate:d,renderLink:u}),p]})]})}function yr({items:e,label:n,showMeta:i,onNavigate:r,renderLink:s}){const l=ce(),{convert:c}=U();if(!e.length)return null;const[p,a]=g.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(Pe,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((d,u)=>{const f=p===u;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...f?{boxShadow:o("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>a(f?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:f?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:c(d.source)}),!f&&i&&d.title_info&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c(d.title_info)}),d.source_bid&&t.jsx("span",{onClick:x=>x.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(De,{id:d.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),f&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${o("widget-border")}`},children:[i&&(d.title_info||d.author_info||d.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&t.jsx(Ye,{label:l.label.titleInfo,children:c(d.title_info)}),d.author_info&&t.jsx(Ye,{label:l.label.authorInfo,children:c(d.author_info)}),d.edition&&t.jsx(Ye,{label:l.label.edition,children:c(d.edition)})]}),d.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:c(d.summary)})]}),d.comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(d.comment)})]}),d.additional_comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(d.additional_comment)})]})]})]},u)})})]})}function ia({items:e,onNavigate:n,renderLink:i}){const r=ce();return t.jsx(yr,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function jr({items:e,onNavigate:n,renderLink:i}){const r=ce();return t.jsx(yr,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function vr({label:e,items:n}){const{convert:i}=U();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(Pe,{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 oa({items:e}){const n=ce();return t.jsx(vr,{label:n.section.aliases,items:e})}function ra({items:e}){const n=ce();return t.jsx(vr,{label:n.section.attachedTexts,items:e})}function sa({items:e}){const n=ce(),{convert:i}=U();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Pe,{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 la({items:e}){const n=ce(),{convert:i}=U();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Pe,{children:n.section.locationHistory}),t.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[t.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:o("widget-border")}}),e.map((r,s)=>t.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[t.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:o("primary"),border:`1.5px solid ${o("input-bg")}`}}),t.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:o("fg")},children:i(r.name)}),r.description&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),marginLeft:"8px"},children:i(r.description)})]},s))]})]}):null}function aa({items:e}){const n=ce(),{convert:i}=U();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Pe,{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 io({title:e,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:l}=U(),[c,p]=g.useState([]);return g.useEffect(()=>{if(!n.length){p([]);return}if(!i){p(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>i.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{a||p(d)}),()=>{a=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(Pe,{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:(c.length?c:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${l(a.title)||a.id}(${l(a.edition)})`:l(a.title)||void 0;return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),transition:"border-color 0.15s"},children:t.jsx(De,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function jn({book:e,onNavigate:n,renderLink:i}){const r=ce(),{convert:s}=U(),[l,c]=g.useState(!1),p=e.resources&&e.resources.length>0,a=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:o("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(De,{id:e.id,label:a,onNavigate:n,renderLink:i})}),p&&t.jsx("span",{onClick:()=>c(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:o("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),p&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(ei,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function ca({ids:e,workData:n,transport:i,onNavigate:r,renderLink:s,footer:l}){const c=ce(),{convert:p}=U(),[a,d]=g.useState([]);if(g.useEffect(()=>{if(!e.length){d([]);return}if(!i){d(e.map(v=>({id:v})));return}let h=!1;return Promise.all(e.map(v=>i.getItem(v).then(b=>({id:v,title:b?b.title:void 0,edition:b?b.edition:void 0,resources:b?b.resources:void 0,resource_groups:b?b.resource_groups:void 0})).catch(()=>({id:v})))).then(v=>{h||d(v)}),()=>{h=!0}},[e,i]),!e.length)return null;const u=a.length?a:e.map(h=>({id:h})),f=new Map(u.map(h=>[h.id,h])),x=n==null?void 0:n.version_graph,m=da(e,x);return t.jsxs(t.Fragment,{children:[t.jsxs(Pe,{children:[c.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,m.useGrouping?t.jsxs(t.Fragment,{children:[m.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:m.coreIds.map(h=>{const v=f.get(h);return v?t.jsx(jn,{book:v,onNavigate:r,renderLink:s},h):null})}),m.groupedIds.map(h=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${o("widget-border")}`,borderRadius:6,background:o("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:o("fg"),userSelect:"none"},children:[p(h.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:o("desc-fg"),fontWeight:400},children:["(",h.ids.length,")"]}),h.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:o("desc-fg"),fontWeight:400},children:p(h.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:h.ids.map(v=>{const b=f.get(v);return b?t.jsx(jn,{book:b,onNavigate:r,renderLink:s},v):null})})]},h.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(h=>t.jsx(jn,{book:h,onNavigate:r,renderLink:s},h.id))})]})}function da(e,n){var b,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(b=n.collections)==null?void 0:b[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,c=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&c.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...c]),d=y=>{if(a.has(y))return!0;const k=n.node_groups[y];return k!=null&&p.has(k)},u=[],f=new Map,x=[];for(const y of e)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))u.push(y);else{const k=n.node_groups[y];k?(f.has(k)||f.set(k,[]),f.get(k).push(y)):x.push(y)}if(x.length+[...f.values()].reduce((y,k)=>y+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const h=new Map((n.groups??[]).map(y=>[y.id,y])),v=[...f.entries()].map(([y,k])=>{const $=h.get(y);return{id:y,label:($==null?void 0:$.label)??y,description:$==null?void 0:$.description,ids:k}});return x.length>0&&v.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:v}}function pa({workData:e,onNavigate:n,renderLink:i}){var c,p,a,d;const r=ce(),{convert:s}=U(),l=!!((c=e.description)!=null&&c.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(De,{id:e.id,label:s(e.title),onNavigate:n,renderLink:i})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:s(e.measure_info)}):((p=e.juan_count)==null?void 0:p.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[mr(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(br,{authors:e.authors,type:"work",onNavigate:n,renderLink:i})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((a=e.description)==null?void 0:a.text)&&t.jsx(tt,{text:e.description.text,style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(d=e.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:t.jsx(Ye,{label:r.label.parentWork,children:t.jsx(De,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function ua({items:e,onNavigate:n,renderLink:i}){const r=ce(),{convert:s}=U();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(De,{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:Ht(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const ti=({data:e,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:c,className:p,style:a})=>{var P,M,A,F,G,D,E,le;const d=ce(),{convert:u}=U(),[f,x]=g.useState(null),[m,h]=g.useState(!1),[v,b]=g.useState(null),[j,y]=g.useState(null),[k,$]=g.useState([]),S=e||f;if(g.useEffect(()=>{if(e||!n||!i)return;let W=!1;return h(!0),b(null),i.getItem(n).then(Y=>{W||(Y?x(Y):b(d.misc.notFoundEntry))}).catch(Y=>{W||b(Y instanceof Error?Y.message:d.misc.loadFailed)}).finally(()=>{W||h(!1)}),()=>{W=!0}},[e,n,i]),g.useEffect(()=>{if(!S||!i){y(null),$([]);return}let W=!1;const Y=S.type==="book"||S.type==="collection"?S.work_id:void 0;if(Y?i.getItem(Y).then(re=>{!W&&re&&re.type==="work"&&y(re)}).catch(()=>{}):y(null),S.type==="book"){const re=S;re.contained_in&&re.contained_in.length>0?Promise.all(re.contained_in.map(te=>{const J=typeof te=="string"?te:te.id,ee=typeof te=="string"?void 0:te.volume_index;return i.getItem(J).then(ge=>({id:J,title:ge&&ge.title||J,volume_index:ee})).catch(()=>({id:J,title:J,volume_index:ee}))})).then(te=>{W||$(te)}):$([])}else $([]);return()=>{W=!0}},[S,i]),m)return t.jsx("div",{className:p,style:{...a,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((W,Y)=>t.jsx("div",{style:{height:Y===1?"32px":"16px",width:`${W}px`,background:o("widget-border"),borderRadius:"4px",opacity:.4}},Y))})});if(v)return t.jsx("div",{className:p,style:{...a,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:v});if(!S)return null;if(S.type==="entity")return t.jsx("div",{className:p,style:a,children:t.jsx(fr,{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 T=!1;try{T=be.extractStatus(S.id)==="draft"}catch{}let R="";S.measure_info?R=u(S.measure_info):(P=S.juan_count)!=null&&P.number?R=mr(S.juan_count.number)+d.unit.juan:(M=S.juan_count)!=null&&M.description&&(R=u(S.juan_count.description));const C=[];return(A=S.publication_info)!=null&&A.year&&C.push(t.jsx(Ye,{label:d.label.year,children:S.publication_info.year},"year")),(F=S.current_location)!=null&&F.name&&C.push(t.jsx(Ye,{label:d.label.currentLocation,children:u(S.current_location.name)},"loc")),(G=S.page_count)!=null&&G.description&&C.push(t.jsx(Ye,{label:d.label.pageCount,children:S.page_count.description},"page")),_!=null&&_.edition&&C.push(t.jsx(Ye,{label:d.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&C.push(t.jsx(Ye,{label:d.label.parentWork,children:t.jsx(De,{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(Ye,{label:d.label.parentWork,children:z.parent_works.map((W,Y)=>t.jsxs("span",{children:[Y>0&&"、",t.jsx(De,{id:W,onNavigate:r,renderLink:s})]},W))},"pws")),t.jsxs("div",{className:p,style:a,children:[t.jsx(na,{id:S.id,title:u(S.title),edition:S.edition?u(S.edition):void 0,type:S.type,isDraft:T,authors:S.authors,volumeText:R,meta:C,headerExtra:l,onNavigate:r,renderLink:s}),((D=S.description)==null?void 0:D.text)&&t.jsx(tt,{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((W,Y)=>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(W.title)}),t.jsx(tt,{text:W.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:o("fg")}})]},Y))}),k.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Pe,{children:d.section.containedIn}),t.jsx(ua,{items:k,onNavigate:r,renderLink:s})]}),j&&t.jsxs(t.Fragment,{children:[t.jsx(Pe,{children:d.section.belongsToWork}),t.jsx(pa,{workData:j,onNavigate:r,renderLink:s})]}),S.additional_works&&S.additional_works.length>0&&t.jsx(sa,{items:S.additional_works}),S.additional_titles&&S.additional_titles.length>0&&t.jsx(oa,{items:S.additional_titles}),S.attached_texts&&S.attached_texts.length>0&&t.jsx(ra,{items:S.attached_texts}),S.indexed_by&&S.indexed_by.length>0&&t.jsx(ia,{items:S.indexed_by,onNavigate:r,renderLink:s}),S.emendated_by&&S.emendated_by.length>0&&t.jsx(jr,{items:S.emendated_by,onNavigate:r,renderLink:s}),S.resources&&S.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Pe,{children:d.section.resources}),t.jsx(ei,{items:S.resources,resourceGroups:S.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&t.jsx(la,{items:_.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&t.jsx(aa,{items:w.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&t.jsx(io,{title:d.section.relatedVersions,ids:_.related_books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.books)&&w.books.length>0&&t.jsx(io,{title:d.section.containedBooks,ids:w.books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.contained_works)&&w.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(Pe,{children:[d.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",w.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.contained_works.map(W=>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(De,{id:W.id,label:u(W.title),onNavigate:r,renderLink:s})},W.id))})]}),(((E=z==null?void 0:z.books)==null?void 0:E.length)||0)+(((le=z==null?void 0:z.collections)==null?void 0:le.length)||0)>0&&t.jsx(ca,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z,transport:i,onNavigate:r,renderLink:s,footer:c}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const W=[],Y=z.related_works.filter(se=>se.relation==="part_of"),re=z.related_works.filter(se=>se.relation==="has_part"),te=z.related_works.filter(se=>se.relation==="has_adaptation"),J=z.related_works.filter(se=>se.relation==="text_carried_by"),ee=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ge=z.related_works.filter(se=>!se.relation||!ee.has(se.relation));return Y.length>0&&W.push({label:d.section.belongsToWork,items:Y}),re.length>0&&W.push({label:d.section.containedWorks,items:re}),te.length>0&&W.push({label:d.section.adaptations,items:te}),J.length>0&&W.push({label:d.section.derivativeWorks,items:J}),ge.length>0&&W.push({label:d.section.relatedWorks,items:ge}),W.map(se=>t.jsxs("div",{children:[t.jsxs(Pe,{children:[se.label,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",se.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:se.items.map(ie=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:t.jsx(De,{id:ie.id,label:u(ie.title),onNavigate:r,renderLink:s})},ie.id))})]},se.label))})()]})};function xa({data:e}){const n=ce(),{convert:i}=U(),{stats:r}=e,s=r.processed_volumes??r.total_found_volumes,l=s!=null&&e.total_volumes>0?Math.round(s/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:i(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"6px"},children:i(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:o("desc-fg")},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:o("fg")},children:e.total_volumes})," ",n.unit.volume]}),l!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:o("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:o("fg")},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&t.jsxs("span",{children:[n.catalog.matched," ",t.jsx("strong",{style:{color:o("fg")},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&t.jsxs("span",{children:[n.catalog.unmatched," ",t.jsx("strong",{style:{color:o("missing-fg")},children:r.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:o("desc-fg")},children:[n.catalog.source," ",e.source]})]})}function fa({sections:e,activeSection:n,onSelect:i}){const r=ce();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:oo(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:oo(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 oo(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 ga({id:e,label:n,onNavigate:i,renderLink:r}){const s=Re();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 ma(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 ro({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const s=ce(),{convert:l}=U(),c=e.book_id||e.work_id,p=r&&e.volumes.length>0?ma(e.volumes,s.unit.volume):null,a=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${o("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:o("desc-fg"),textAlign:"right"},children:p}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:o("fg")},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(d=>l(d)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:o(a?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),c&&t.jsx(ga,{id:c,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!c&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const ni=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:l,style:c})=>{const p=ce(),[a,d]=g.useState(null),[u,f]=g.useState(!1),[x,m]=g.useState(null),[h,v]=g.useState(null),[b,j]=g.useState(""),y=e||a;g.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let w=!1;return f(!0),m(null),i.getCollectionCatalog(n).then(z=>{w||(z?d(z):m(p.catalog.notFound))}).catch(z=>{w||m(z instanceof Error?z.message:p.catalog.loadFailed)}).finally(()=>{w||f(!1)}),()=>{w=!0}},[e,n,i,p]);const k=(y==null?void 0:y.sections)&&y.sections.length>0,$=g.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const w=y.books.map(T=>T.volumes[0]).filter(T=>T!=null);return new Set(w).size<w.length},[y]),S=g.useMemo(()=>{if(!y)return[];let w=y.books;if(h&&(w=w.filter(z=>z.section===h)),b.trim()){const z=b.trim().toLowerCase();w=w.filter(T=>T.title.toLowerCase().includes(z)||T.sub_items&&T.sub_items.some(R=>R.toLowerCase().includes(z))||T.edition&&T.edition.toLowerCase().includes(z))}return w},[y,h,b]),_=g.useMemo(()=>{if(!$)return null;const w=[],z=new Map;for(const R of S){if(!R.volumes||R.volumes.length===0)continue;const C=R.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(R)}const T=[...z.keys()].sort((R,C)=>R-C);for(const R of T)w.push({volume:R,books:z.get(R)});return w},[S,$]);return u?t.jsx("div",{className:l,style:{...c,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):x?t.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:x}):y?t.jsxs("div",{className:l,style:c,children:[t.jsx(xa,{data:y}),k&&t.jsx(fa,{sections:y.sections,activeSection:h,onSelect:v}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:b,onChange:w=>j(w.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:o("desc-fg")},children:[S.length," ",p.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[_?_.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:Ht(p.catalog.volume,{n:w.volume})}),w.books.map((T,R)=>t.jsx(ro,{book:T,onNavigate:r,renderLink:s,showVolumes:T.volumes.length>1},`${w.volume}-${R}`))]},`${w.volume}-${z}`)):S.map((w,z)=>t.jsx(ro,{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:p.catalog.noMatch})]})]}):null},ft=()=>{const[e,n]=g.useState(1);return g.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)})},kr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],ha={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Ce(e){return ha[e]??e}const kt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],St={熹平: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},Sr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function pn(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 ba(e){return e>=1950?"":e>=1912?"民國":e>=1645?"清":e>=1368?"明":e>=1279?"元":e>=960?"宋":e>=907?"五代":e>=618?"唐":e>=581?"隋":e>=420?"南北朝":e>=265?"晉":e>=220?"三國":e>=-202?"漢":""}const ya=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,so={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function ii(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(so))if(n.startsWith(s))return so[s];const i=Ce(n);if(ct[i]!=null)return i;const r=et(n);if(r&&n.length<=r.length+1)return Ce(r)}function at(e,n){if(n){const i=Sr[`${n}|${e}`];if(i!=null)return i}return St[e]}const ja=1911;function va(e){const n=St[e];if(n==null)return;const i=Ke[e];let r;for(const[s,l]of Object.entries(St))Ke[s]===i&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const ka={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function rn(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 c=ka[l];if(c===void 0)return;r=!0,l==="十"?i=(i||1)*10:l==="廿"||l==="卅"?(n+=c,i=0):i>=10?(n+=i+c,i=0):i=i*10+c}const s=n+i;return r&&s>0?s:void 0}function et(e){for(const n of kr)if(e.startsWith(n))return n}const Ke={};{const e=(n,i)=>{for(const r of i)Ke[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function dt(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(St))if(e.includes(r)&&!(i&&Ke[r]&&Ke[r]!==i&&Sr[`${i}|${r}`]==null))return r}function Gt(e){var c,p,a;const n={era:"",reign:"",source:"none"},i=e.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const d=et(r)??"";return{era:Ce(d),reign:dt(r,d)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const d=pn(s);if(d)return{era:ba(d.from),reign:"",source:"publication"};const u=et(s)??ii(s)??((a=kt.find(m=>m.pattern.test(s)))==null?void 0:a.era)??"",f=dt(s,u)??"",x=u||(f?Ke[f]??"":"");if(x||f)return{era:Ce(x),reign:f,source:"publication"}}const l=e.edition||e.title||"";if(l){const d=et(l);if(d)return{era:Ce(d),reign:dt(l,d)??"",source:"edition"};const u=kt.find(f=>f.pattern.test(l));if(u)return{era:Ce(u.era),reign:dt(l,u.era)??u.reign??"",source:"edition"}}return n}function un(e){var r,s,l,c,p,a,d,u,f;if(((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;if(typeof((s=e.lineage)==null?void 0:s.year)=="number")return e.lineage.year;const n=(l=e.publication_info)==null?void 0:l.year;if(n){const x=pn(n);if(x)return x.from}const i=[(c=e.lineage)==null?void 0:c.year_text,(p=e.publication_info)==null?void 0:p.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const x of i){const m=((a=e.publication_info)==null?void 0:a.year)||((d=e.lineage)==null?void 0:d.year_text);if(m&&x!==m&&(et(m)||ii(m)))break;const h=x.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??x.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(h){const k=parseInt(h[1],10);if(k>=100&&k<=2100)return k}const v=x.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(v){const k=et(x);if(!k||Ce(k)==="民國"){const S=rn(v[1]);if(S!=null&&S>=1&&S<=120)return ja+S}}const b=et(x)??((u=kt.find(k=>k.pattern.test(x)))==null?void 0:u.era),j=b?Ce(b):void 0,y=dt(x,j)??(et(x)||(f=kt.find(k=>k.pattern.test(x)))==null?void 0:f.reign);if(y){const k=at(y,j);if(k==null)continue;const $=x.indexOf(y),S=$>=0?x.slice($+y.length):"",_=S.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??S.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),w=_?rn(_[1]):void 0;return k+(w?w-1:0)}}}function oi(e){var c,p,a,d,u,f;const n=(c=e.dating)==null?void 0:c.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(p=e.lineage)==null?void 0:p.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(a=e.lineage)==null?void 0:a.year_text;if(r){const x=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(x){const m=Ln[Ce(x[1])],h=ct[Ce(x[2])];if(m!=null&&h!=null)return{from:Math.min(m,h)-20,to:Math.max(m,h)+40}}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const x=pn(s);if((x==null?void 0:x.to)!=null)return{from:x.from,to:x.to};const m=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(m){const h=Ln[Ce(m[1])],v=ct[Ce(m[2])];if(h!=null&&v!=null)return{from:Math.min(h,v)-20,to:Math.max(h,v)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const x of l){if(!/[間间]/.test(x))continue;const m=et(x)??ii(x)??((f=kt.find(b=>b.pattern.test(x)))==null?void 0:f.era),h=m?Ce(m):void 0,v=[];for(const b of Object.keys(St))x.includes(b)&&(h&&Ke[b]&&Ke[b]!==h||at(b,h)!=null&&v.push(b));if(v.length===0){const b=x.match(/([一-鿿])([一-鿿])[間间]/);if(b&&h){for(const j of[b[1],b[2]])for(const y of Object.keys(St))if(Ke[y]===h&&!(y[0]!==j&&y[y.length-1]!==j)&&at(y,h)!=null){v.push(y);break}}}if(v.length>0){const b=v.map($=>at($,h)).filter($=>$!=null),j=Math.min(...b),y=v.reduce(($,S)=>at($,h)>=at(S,h)?$:S),k=va(y)??vn(h??"")??Math.max(...b);return{from:j,to:k>j?k:vn(h??Ke[y]??"")??j}}if(h&&ct[h]!=null)return{from:ct[h],to:vn(h)??ct[h]}}}const ct={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Sa=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],wa=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,lo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function ao(e,n){for(const i of kr){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const a=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(a)&&!dt(e.slice(r),Ce(i)))continue}const s=Ce(i);if(s===n)continue;const l=e.slice(r),c=dt(l,s)??"";let p;if(c){const a=at(c,s);if(a!=null){const u=l.slice(l.indexOf(c)+c.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),f=u?rn(u[1]):void 0;p=a+(f?f-1:0)}}return{era:s,reign:c,year:p}}for(const i of kt)if(i.pattern.test(e))return{era:Ce(i.era),reign:i.reign??""}}function _a(e){var j,y,k,$,S;const n=Gt(e),i=((j=e.publication_info)==null?void 0:j.year)??"",r=i?pn(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),c=((y=e.lineage)==null?void 0:y.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(c),a=n.source==="publication"&&ya.test(i),d=n.source==="publication"&&/[間间]/.test(i),u=c.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let f;l||p||a||d?f=void 0:u?f=parseInt(u[2],10):f=un(e);const x=f==null?oi(e):void 0;let m;n.source==="publication"&&(a||lo.test(i))?m="uncertain":n.source==="lineage"||n.source==="publication"?m="attested":lo.test(s)||!n.reign&&f==null?m="uncertain":m="inferred";const h=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((k=e.lineage)==null?void 0:k.year_text)??(($=e.lineage)==null?void 0:$.year)??""}」`:`出版著錄「${((S=e.publication_info)==null?void 0:S.year)??""}」`,v={era:n.era,reign:n.reign,year:f,yearRange:x,certainty:m,source:n.source==="edition"?"edition":"catalog",basis:h};if(u){const _=c.match(/[、,,]\s*([宋元明清])/);_&&_[1]!==v.era&&(v.laterRepair={era:_[1]})}if(!v.laterRepair&&wa.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(v.laterRepair={era:_[1]})}const b=Sa.find(_=>_.re.test(s));if(b){const _=s.search(b.re),w=s.slice(_),z=ao(w,n.era)??ao(s,n.era);z&&(v.basedOn={era:z.era,reign:z.reign,year:z.year,relation:b.relation})}return v}const Ln={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function vn(e){return Ln[e]}function sn(e){const n=un(e);if(n!=null)return n;const i=oi(e);if(i)return i.from;const r=Gt(e).era;return r?ct[r]:void 0}const co=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Bn(e){const n=co.indexOf(e);return n===-1?co.length:n}function $a(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 ri(e,n){const i=Zn(e||[]),r=new Map,s=[];for(const d of i)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((u,f)=>{const x=m=>m.group_role==="origin"?0:m.group_role==="mirror"?1:2;return x(u)-x(f)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=xt(d),f=u.includes("text"),x=u.includes("image");f&&x?l.textImage.push(d):f?l.text.push(d):x?l.image.push(d):l.physical.push(d)}const p=["text","image","textImage","physical"].filter(d=>l[d].length>0).map(d=>({key:d,items:l[d]})),a=[...r.entries()].map(([d,u])=>{var f,x;return{key:d,label:((f=n==null?void 0:n[d])==null?void 0:f.label)||d,description:(x=n==null?void 0:n[d])==null?void 0:x.description,items:u}});return{buckets:p,mirrors:a,total:i.length}}function xn(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=cn(e);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),i.version&&n.push(String(i.version)),n.join(" · ")}function wr(e,n){if(xn(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 _r(e,n){var l,c;const i=e.resources||[],r=[],s=[];for(const p of i){const a=xt(p);a.includes("image")&&r.push(p),a.includes("physical")&&s.push(p)}return{id:e.id,name:e.edition||e.title||e.id,era:Gt(e),year:un(e),sortYear:sn(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:za(e.id,n),group:(c=n==null?void 0:n.node_groups)==null?void 0:c[e.id],hasImage:r.length>0}}function za(e,n){var p,a;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(p=n.collections)==null?void 0:p[i];if(((r==null?void 0:r.book_ids)??(i==="core"?n.core_books??[]:[])).includes(e))return!0;const l=(r==null?void 0:r.groups)??[],c=(a=n.node_groups)==null?void 0:a[e];return!!c&&l.includes(c)}function $r(e,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(a=>!r.has(a.id)).map(a=>_r(a,n));let l=s;i.era&&(l=l.filter(a=>a.era.era===i.era)),i.scanOnly&&(l=l.filter(a=>a.hasImage)),i.sort==="year"?l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=a.r.sortYear,f=d.r.sortYear;return u!=null&&f!=null?u-f||a.i-d.i:u!=null?-1:f!=null?1:a.i-d.i}).map(a=>a.r):l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=f=>(f.important?0:1)*2+(f.hasImage?0:1);return u(a.r)-u(d.r)||a.i-d.i}).map(a=>a.r);const p=[...new Set(s.map(a=>a.era.era).filter(Boolean))].sort((a,d)=>Bn(a)-Bn(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(a=>a.era.source==="edition")}}function Ca(e,n){var b,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(b=n.collections)==null?void 0:b[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,c=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&c.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...c]),d=y=>{if(a.has(y))return!0;const k=n.node_groups[y];return k!=null&&p.has(k)},u=[],f=new Map,x=[];for(const y of e)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))u.push(y);else{const k=n.node_groups[y];k?(f.has(k)||f.set(k,[]),f.get(k).push(y)):x.push(y)}if(x.length+[...f.values()].reduce((y,k)=>y+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const h=new Map((n.groups??[]).map(y=>[y.id,y])),v=[...f.entries()].map(([y,k])=>{const $=h.get(y);return{id:y,label:($==null?void 0:$.label)??y,description:$==null?void 0:$.description,ids:k}});return x.length>0&&v.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:v}}const zr=["撰","編","注","校","譯","繪","其他"],Ia=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function si(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of Ia)if(r.test(n))return i;return"其他"}function li(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Cr(e){const n=new Map;for(const r of e){const s=si(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:e.length}];for(const r of zr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function Ir(e,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(c=>({id:c.work_id||c.book_id||void 0,title:c.title,section:c.section,volumes:c.volumes||[],subItems:c.sub_items,edition:c.edition,found:c.found_volumes,expected:c.expected_volumes})),l=[...new Set(s.map(c=>c.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:Pt(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,c;return{id:s,title:((l=i==null?void 0:i.get(s))==null?void 0:l.title)||s,edition:(c=i==null?void 0:i.get(s))==null?void 0:c.edition,volumes:[]}}),source:"books",sections:[]}}function Pt(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 fn(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((l,c)=>l-c),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 Ta=["〇","一","二","三","四","五","六","七","八","九"],po=["","十","百","千"];function Tr(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 c=parseInt(n[l]),p=i-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=po[p]:r+=Ta[c]+po[p])}return r}function Ra(e){return e==null?"":typeof e=="string"?e:e.title??""}function nt(e,n="卷"){var r,s;const i=e;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?Tr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Rr(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 Ea="guji_markdown";function An(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 Na=/^□\{guess=([^\s{}]+)\}/;function La(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function Er(e,n){let i=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
9
- `)return-1;if(s==="\\"){r++;continue}if(s==="[")i++;else if(s==="]"&&(i--,i===0))return r}return-1}function Ba(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function Aa(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(`
10
- `)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const r=Er(e,n+3);return r>n+4?{node:{type:"zi",label:Ba(e.slice(n+4,r))},end:r+1}:null}if(i==="□"&&e[n+1]==="{"){const r=Na.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function Nr(e,n,i,r){const s=[];let l="";const c=()=>{if(!l)return;const p=r?l.replace(/\\?\|/g,""):l;p&&s.push({type:"text",text:p}),l=""};for(;n<e.length;){const p=e[n];if(i!==null){if(p===i)return c(),{nodes:s,end:n};if(p===`
11
- `)return null}const a=Aa(e,n);if(a){c(),s.push(a.node),n=a.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&La(e,n)&&(d=">"),d){const u=Nr(e,n+1,d,!0);if(u){c(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return i!==null?null:(c(),{nodes:s,end:n})}function Lr(e){return Nr(e,0,null,!1).nodes}function Wa(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function Br(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Br(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const Ma=216,uo="clamp(280px, 23vw, 360px)",Fa=1440,Ar="(max-width: 719px)",Pa=`${Ar}, (pointer: coarse)`,Oa=`
12
- .bim-d-main.bim-d-main-grid { max-width: ${Fa}px; padding: 16px 32px 0; }
8
+ }`,fr={color:"inherit",textDecoration:"none"},Kl=({snippet:e})=>{const{convert:n}=Y();return t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.6},children:sr(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(g.Fragment,{children:n(i.text)},r))})},ql=({entry:e,selected:n,onClick:i,getConfig:r,query:s})=>{const l=ae(),{convert:c}=Y(),p=c(e.title||e.primary_name||e.id),a=e.measure_info?c(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",d=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&d.length?d.find(m=>{const h=typeof m=="string"?m:m==null?void 0:m.book_title;return h==null?void 0:h.toLowerCase().includes(s.toLowerCase())}):void 0,f=o("cover-accent"),x=Ne();return t.jsxs("a",{href:x(e.id),onClick:m=>i(e,m),className:"bim-result-card",style:{...fr,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, ${f} 50%, ${o("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${f} 14%, ${o("bg")}), color-mix(in srgb, ${f} 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, ${f} 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:f},children:Array.from(p).map((m,h)=>t.jsx("span",{children:m},h))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:o("fg")},children:p}),a&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:a})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",c(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:c(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",c(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",c(e.era),"〕"]}),e.edition&&t.jsx("span",{children:c(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[l.search.alias,":",c(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(Kl,{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]})]})]})]})},to=({entry:e,selected:n,onClick:i,getConfig:r,query:s,onRemove:l})=>{const c=ae(),{convert:p}=Y(),a=[...e.additional_titles||[],...e.attached_texts||[]],d=s&&a.length?a.find(f=>{const x=typeof f=="string"?f:f==null?void 0:f.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,u=Ne();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:f=>i(e,f),className:"bim-result-card",style:{...fr,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx("span",{style:{fontSize:"16px"},children:r(e.type).icon}),t.jsx("span",{style:{fontSize:"9px",color:o("desc-fg"),lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:p(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{title:c.misc.textResource,children:"📝"}),e.has_image&&t.jsx("span",{title:c.misc.imageResource,children:"🖼️"})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",p(e.era),"〕"]}),e.edition&&p(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:p(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.juan_count,c.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",p(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:p(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",p(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),d&&t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:[c.search.alias,":",p(d)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:c.search.removeFromRecent,"aria-label":c.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:"×"})]})},Jl=({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 Zl(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 Xl({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 Ql({alt_names:e}){const{convert:n}=Y(),i=new Map;for(const l of e){const c=l.type||"別名";i.has(c)||i.set(c,[]),i.get(c).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((l,c)=>{const p=r.indexOf(l),a=r.indexOf(c);return p===-1&&a===-1?0:p===-1?1:a===-1?-1:p-a});return t.jsx("div",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const c=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:c.map((p,a)=>t.jsxs("span",{children:[a>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},a))})]},l)})})}function ea({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 ta({works:e,transport:n,onNavigate:i,renderLink:r}){const s=ae(),{convert:l}=Y(),c=Ne(),[p,a]=g.useState(new Map);g.useEffect(()=>{if(!n)return;let x=!1;const m=e.map(k=>k.work_id);return(async()=>{const k=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(m);let $=!0;for(let S=0;S<m.length;S++){const _=v[S];_!=null&&_.title?k.set(m[S],_.title):_!=null&&_.primary_name?k.set(m[S],_.primary_name):$=!1}if($)return k}catch{}const b=[...m],j=8,y=new Array(j).fill(0).map(async()=>{for(;b.length;){const v=b.shift();if(!v)break;if(!k.has(v))try{if(n.getEntry){const _=await n.getEntry(v);if(_!=null&&_.title){k.set(v,_.title);continue}}const $=await n.getItem(v),S=$&&($.title||$.primary_name)||v;k.set(v,S)}catch{k.set(v,v)}}});return await Promise.all(y),k})().then(k=>{x||a(k)}),()=>{x=!0}},[e,n]);const d=new Map;for(const x of e){const m=x.role||"";d.has(m)||d.set(m,[]),d.get(m).push(x)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],f=[...d.keys()].sort((x,m)=>{const h=u.indexOf(x),k=u.indexOf(m);return h===-1&&k===-1?x.localeCompare(m):h===-1?1:k===-1?-1:h-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,")"]})]}),f.map(x=>{const m=d.get(x);return t.jsxs("div",{style:{marginBottom:"8px"},children:[x&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"2px"},children:[l(x)," ",t.jsxs("span",{style:{color:o("desc-fg")},children:["(",m.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:x?"16px":"0",listStyle:x?"disc":"none",fontSize:"14px",lineHeight:1.8},children:m.map((h,k)=>{const b=l(p.get(h.work_id)||h.work_id);return r?t.jsx("li",{children:r(h.work_id,b)},k):i?t.jsx("li",{children:t.jsx("a",{href:c(h.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),i(h.work_id))},style:{color:o("link-fg"),textDecoration:"underline",cursor:"pointer"},children:b})},k):t.jsx("li",{children:b},k)})})]},x)})]})}const gr=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:l})=>{var f;const c=ae(),{convert:p}=Y();let a=!1;try{a=he.extractStatus(e.id)==="draft"}catch{}const d=Zl(e),u=e.subtype==="people"?"人物":e.subtype==="place"?"地名":e.subtype==="dynasty"?"朝代":e.subtype==="anonymous"?"佚名":e.subtype==="collective"?"集体":e.subtype;return t.jsxs("div",{children:[!l&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:o("fg")},children:[p(e.primary_name),t.jsx(Xl,{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:c.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),a&&t.jsx("span",{style:{padding:"1px 6px",background:o("warn-bg"),border:`1px solid ${o("warn-border")}`,borderRadius:"2px",color:o("warn-fg")},children:c.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),d&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:o("widget-bg"),border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(Ql,{alt_names:e.alt_names}),t.jsx(ea,{data:e}),((f=e.description)==null?void 0:f.text)&&t.jsx("p",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(e.description.text)}),e.works&&e.works.length>0&&t.jsx(ta,{works:e.works,transport:n,onNavigate:i,renderLink:r})]})},na=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function ia(e){const n=e.search(na);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const mr={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>{let i=e,r="",s=n;if(e&&typeof n=="string"&&(n===e||n===oa(e))){const[l,c]=ia(n);c&&(i=encodeURI(l),s=l,r=c)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:i,target:i!=null&&i.startsWith("http")?"_blank":void 0,rel:i!=null&&i.startsWith("http")?"noopener noreferrer":void 0,style:{color:o("link")},children:s}),r]})},code:({children:e})=>t.jsx("code",{style:{background:o("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function oa(e){try{return decodeURI(e)}catch{return e}}const ra={...mr,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},nt=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:s}=Y(),l=n?ra:mr;return t.jsx("div",{className:r,style:i,children:t.jsx(pl,{remarkPlugins:[ul],components:l,children:s(e)})})},sa=["〇","一","二","三","四","五","六","七","八","九"],no=["","十","百","千"];function hr(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const c=parseInt(n[l]),p=i-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=no[p]:r+=sa[c]+no[p])}return r}function br(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 la={book:o("type-book"),work:o("type-work"),collection:o("type-collection"),entity:o("type-entity")};function aa({type:e}){const n=ae();return t.jsx("span",{style:br(la[e]),children:n.indexType[e]})}function ca({isDraft:e}){const n=ae(),i=o(e?"status-draft":"status-official");return t.jsx("span",{style:br(i),children:e?n.status.draft:n.status.official})}function da({id:e}){const n=ae(),[i,r]=g.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 Pe({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 Ye({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 yr({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,c)=>{const p=s(l.name),a=l.entity_id?t.jsx(De,{id:l.entity_id,label:p,onNavigate:i,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:p});return t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),a,l.role&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},c)})})}function De({id:e,label:n,onNavigate:i,renderLink:r}){const s=Ne();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 pa({id:e,title:n,edition:i,type:r,isDraft:s,authors:l,volumeText:c,meta:p,headerExtra:a,onNavigate:d,renderLink:u}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:o("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:i}),c&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:c})]}),a&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(aa,{type:r}),t.jsx(ca,{isDraft:s}),t.jsx(da,{id:e})]}),((l==null?void 0:l.length)||p.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(yr,{authors:l,type:r,onNavigate:d,renderLink:u}),p]})]})}function jr({items:e,label:n,showMeta:i,onNavigate:r,renderLink:s}){const l=ae(),{convert:c}=Y();if(!e.length)return null;const[p,a]=g.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(Pe,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((d,u)=>{const f=p===u;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...f?{boxShadow:o("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>a(f?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:f?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:c(d.source)}),!f&&i&&d.title_info&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c(d.title_info)}),d.source_bid&&t.jsx("span",{onClick:x=>x.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(De,{id:d.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),f&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${o("widget-border")}`},children:[i&&(d.title_info||d.author_info||d.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&t.jsx(Ye,{label:l.label.titleInfo,children:c(d.title_info)}),d.author_info&&t.jsx(Ye,{label:l.label.authorInfo,children:c(d.author_info)}),d.edition&&t.jsx(Ye,{label:l.label.edition,children:c(d.edition)})]}),d.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:c(d.summary)})]}),d.comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(d.comment)})]}),d.additional_comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(d.additional_comment)})]})]})]},u)})})]})}function ua({items:e,onNavigate:n,renderLink:i}){const r=ae();return t.jsx(jr,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function vr({items:e,onNavigate:n,renderLink:i}){const r=ae();return t.jsx(jr,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function kr({label:e,items:n}){const{convert:i}=Y();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(Pe,{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 xa({items:e}){const n=ae();return t.jsx(kr,{label:n.section.aliases,items:e})}function fa({items:e}){const n=ae();return t.jsx(kr,{label:n.section.attachedTexts,items:e})}function ga({items:e}){const n=ae(),{convert:i}=Y();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Pe,{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 ma({items:e}){const n=ae(),{convert:i}=Y();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Pe,{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 ha({items:e}){const n=ae(),{convert:i}=Y();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Pe,{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 io({title:e,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:l}=Y(),[c,p]=g.useState([]);return g.useEffect(()=>{if(!n.length){p([]);return}if(!i){p(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>i.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{a||p(d)}),()=>{a=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(Pe,{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:(c.length?c:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${l(a.title)||a.id}(${l(a.edition)})`:l(a.title)||void 0;return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),transition:"border-color 0.15s"},children:t.jsx(De,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function jn({book:e,onNavigate:n,renderLink:i}){const r=ae(),{convert:s}=Y(),[l,c]=g.useState(!1),p=e.resources&&e.resources.length>0,a=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:o("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(De,{id:e.id,label:a,onNavigate:n,renderLink:i})}),p&&t.jsx("span",{onClick:()=>c(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:o("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),p&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(ei,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function ba({ids:e,workData:n,transport:i,onNavigate:r,renderLink:s,footer:l}){const c=ae(),{convert:p}=Y(),[a,d]=g.useState([]);if(g.useEffect(()=>{if(!e.length){d([]);return}if(!i){d(e.map(k=>({id:k})));return}let h=!1;return Promise.all(e.map(k=>i.getItem(k).then(b=>({id:k,title:b?b.title:void 0,edition:b?b.edition:void 0,resources:b?b.resources:void 0,resource_groups:b?b.resource_groups:void 0})).catch(()=>({id:k})))).then(k=>{h||d(k)}),()=>{h=!0}},[e,i]),!e.length)return null;const u=a.length?a:e.map(h=>({id:h})),f=new Map(u.map(h=>[h.id,h])),x=n==null?void 0:n.version_graph,m=ya(e,x);return t.jsxs(t.Fragment,{children:[t.jsxs(Pe,{children:[c.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,m.useGrouping?t.jsxs(t.Fragment,{children:[m.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:m.coreIds.map(h=>{const k=f.get(h);return k?t.jsx(jn,{book:k,onNavigate:r,renderLink:s},h):null})}),m.groupedIds.map(h=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${o("widget-border")}`,borderRadius:6,background:o("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:o("fg"),userSelect:"none"},children:[p(h.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:o("desc-fg"),fontWeight:400},children:["(",h.ids.length,")"]}),h.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:o("desc-fg"),fontWeight:400},children:p(h.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:h.ids.map(k=>{const b=f.get(k);return b?t.jsx(jn,{book:b,onNavigate:r,renderLink:s},k):null})})]},h.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(h=>t.jsx(jn,{book:h,onNavigate:r,renderLink:s},h.id))})]})}function ya(e,n){var b,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(b=n.collections)==null?void 0:b[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,c=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&c.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...c]),d=y=>{if(a.has(y))return!0;const v=n.node_groups[y];return v!=null&&p.has(v)},u=[],f=new Map,x=[];for(const y of e)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))u.push(y);else{const v=n.node_groups[y];v?(f.has(v)||f.set(v,[]),f.get(v).push(y)):x.push(y)}if(x.length+[...f.values()].reduce((y,v)=>y+v.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const h=new Map((n.groups??[]).map(y=>[y.id,y])),k=[...f.entries()].map(([y,v])=>{const $=h.get(y);return{id:y,label:($==null?void 0:$.label)??y,description:$==null?void 0:$.description,ids:v}});return x.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:k}}function ja({workData:e,onNavigate:n,renderLink:i}){var c,p,a,d;const r=ae(),{convert:s}=Y(),l=!!((c=e.description)!=null&&c.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(De,{id:e.id,label:s(e.title),onNavigate:n,renderLink:i})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:s(e.measure_info)}):((p=e.juan_count)==null?void 0:p.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[hr(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(yr,{authors:e.authors,type:"work",onNavigate:n,renderLink:i})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((a=e.description)==null?void 0:a.text)&&t.jsx(nt,{text:e.description.text,style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(d=e.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:t.jsx(Ye,{label:r.label.parentWork,children:t.jsx(De,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function va({items:e,onNavigate:n,renderLink:i}){const r=ae(),{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(De,{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:Gt(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const ti=({data:e,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:c,className:p,style:a})=>{var O,M,A,F,G,U,E,ie;const d=ae(),{convert:u}=Y(),[f,x]=g.useState(null),[m,h]=g.useState(!1),[k,b]=g.useState(null),[j,y]=g.useState(null),[v,$]=g.useState([]),S=e||f;if(g.useEffect(()=>{if(e||!n||!i)return;let P=!1;return h(!0),b(null),i.getItem(n).then(re=>{P||(re?x(re):b(d.misc.notFoundEntry))}).catch(re=>{P||b(re instanceof Error?re.message:d.misc.loadFailed)}).finally(()=>{P||h(!1)}),()=>{P=!0}},[e,n,i]),g.useEffect(()=>{if(!S||!i){y(null),$([]);return}let P=!1;const re=S.type==="book"||S.type==="collection"?S.work_id:void 0;if(re?i.getItem(re).then(ce=>{!P&&ce&&ce.type==="work"&&y(ce)}).catch(()=>{}):y(null),S.type==="book"){const ce=S;ce.contained_in&&ce.contained_in.length>0?Promise.all(ce.contained_in.map(K=>{const V=typeof K=="string"?K:K.id,q=typeof K=="string"?void 0:K.volume_index;return i.getItem(V).then(xe=>({id:V,title:xe&&xe.title||V,volume_index:q})).catch(()=>({id:V,title:V,volume_index:q}))})).then(K=>{P||$(K)}):$([])}else $([]);return()=>{P=!0}},[S,i]),m)return t.jsx("div",{className:p,style:{...a,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((P,re)=>t.jsx("div",{style:{height:re===1?"32px":"16px",width:`${P}px`,background:o("widget-border"),borderRadius:"4px",opacity:.4}},re))})});if(k)return t.jsx("div",{className:p,style:{...a,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:k});if(!S)return null;if(S.type==="entity")return t.jsx("div",{className:p,style:a,children:t.jsx(gr,{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 T=!1;try{T=he.extractStatus(S.id)==="draft"}catch{}let R="";S.measure_info?R=u(S.measure_info):(O=S.juan_count)!=null&&O.number?R=hr(S.juan_count.number)+d.unit.juan:(M=S.juan_count)!=null&&M.description&&(R=u(S.juan_count.description));const C=[];return(A=S.publication_info)!=null&&A.year&&C.push(t.jsx(Ye,{label:d.label.year,children:S.publication_info.year},"year")),(F=S.current_location)!=null&&F.name&&C.push(t.jsx(Ye,{label:d.label.currentLocation,children:u(S.current_location.name)},"loc")),(G=S.page_count)!=null&&G.description&&C.push(t.jsx(Ye,{label:d.label.pageCount,children:S.page_count.description},"page")),_!=null&&_.edition&&C.push(t.jsx(Ye,{label:d.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&C.push(t.jsx(Ye,{label:d.label.parentWork,children:t.jsx(De,{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(Ye,{label:d.label.parentWork,children:z.parent_works.map((P,re)=>t.jsxs("span",{children:[re>0&&"、",t.jsx(De,{id:P,onNavigate:r,renderLink:s})]},P))},"pws")),t.jsxs("div",{className:p,style:a,children:[t.jsx(pa,{id:S.id,title:u(S.title),edition:S.edition?u(S.edition):void 0,type:S.type,isDraft:T,authors:S.authors,volumeText:R,meta:C,headerExtra:l,onNavigate:r,renderLink:s}),((U=S.description)==null?void 0:U.text)&&t.jsx(nt,{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((P,re)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:o("bg-subtle"),borderRadius:4,border:`1px solid ${o("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:o("muted")},children:u(P.title)}),t.jsx(nt,{text:P.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:o("fg")}})]},re))}),v.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Pe,{children:d.section.containedIn}),t.jsx(va,{items:v,onNavigate:r,renderLink:s})]}),j&&t.jsxs(t.Fragment,{children:[t.jsx(Pe,{children:d.section.belongsToWork}),t.jsx(ja,{workData:j,onNavigate:r,renderLink:s})]}),S.additional_works&&S.additional_works.length>0&&t.jsx(ga,{items:S.additional_works}),S.additional_titles&&S.additional_titles.length>0&&t.jsx(xa,{items:S.additional_titles}),S.attached_texts&&S.attached_texts.length>0&&t.jsx(fa,{items:S.attached_texts}),S.indexed_by&&S.indexed_by.length>0&&t.jsx(ua,{items:S.indexed_by,onNavigate:r,renderLink:s}),S.emendated_by&&S.emendated_by.length>0&&t.jsx(vr,{items:S.emendated_by,onNavigate:r,renderLink:s}),S.resources&&S.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Pe,{children:d.section.resources}),t.jsx(ei,{items:S.resources,resourceGroups:S.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&t.jsx(ma,{items:_.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&t.jsx(ha,{items:w.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&t.jsx(io,{title:d.section.relatedVersions,ids:_.related_books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.books)&&w.books.length>0&&t.jsx(io,{title:d.section.containedBooks,ids:w.books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.contained_works)&&w.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(Pe,{children:[d.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",w.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.contained_works.map(P=>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(De,{id:P.id,label:u(P.title),onNavigate:r,renderLink:s})},P.id))})]}),(((E=z==null?void 0:z.books)==null?void 0:E.length)||0)+(((ie=z==null?void 0:z.collections)==null?void 0:ie.length)||0)>0&&t.jsx(ba,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z??void 0,transport:i,onNavigate:r,renderLink:s,footer:c}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const P=[],re=z.related_works.filter(oe=>oe.relation==="part_of"),ce=z.related_works.filter(oe=>oe.relation==="has_part"),K=z.related_works.filter(oe=>oe.relation==="has_adaptation"),V=z.related_works.filter(oe=>oe.relation==="text_carried_by"),q=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),xe=z.related_works.filter(oe=>!oe.relation||!q.has(oe.relation));return re.length>0&&P.push({label:d.section.belongsToWork,items:re}),ce.length>0&&P.push({label:d.section.containedWorks,items:ce}),K.length>0&&P.push({label:d.section.adaptations,items:K}),V.length>0&&P.push({label:d.section.derivativeWorks,items:V}),xe.length>0&&P.push({label:d.section.relatedWorks,items:xe}),P.map(oe=>t.jsxs("div",{children:[t.jsxs(Pe,{children:[oe.label,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",oe.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:oe.items.map(ne=>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(De,{id:ne.id,label:u(ne.title),onNavigate:r,renderLink:s})},ne.id))})]},oe.label))})()]})};function ka({data:e}){const n=ae(),{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 Sa({sections:e,activeSection:n,onSelect:i}){const r=ae();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:oo(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:oo(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 oo(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 wa({id:e,label:n,onNavigate:i,renderLink:r}){const s=Ne();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 _a(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 ro({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const s=ae(),{convert:l}=Y(),c=e.book_id||e.work_id,p=r&&e.volumes.length>0?_a(e.volumes,s.unit.volume):null,a=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${o("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:o("desc-fg"),textAlign:"right"},children:p}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:o("fg")},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(d=>l(d)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:o(a?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),c&&t.jsx(wa,{id:c,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!c&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const ni=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:l,style:c})=>{const p=ae(),[a,d]=g.useState(null),[u,f]=g.useState(!1),[x,m]=g.useState(null),[h,k]=g.useState(null),[b,j]=g.useState(""),y=e||a;g.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let w=!1;return f(!0),m(null),i.getCollectionCatalog(n).then(z=>{w||(z?d(z):m(p.catalog.notFound))}).catch(z=>{w||m(z instanceof Error?z.message:p.catalog.loadFailed)}).finally(()=>{w||f(!1)}),()=>{w=!0}},[e,n,i,p]);const v=(y==null?void 0:y.sections)&&y.sections.length>0,$=g.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const w=y.books.map(T=>T.volumes[0]).filter(T=>T!=null);return new Set(w).size<w.length},[y]),S=g.useMemo(()=>{if(!y)return[];let w=y.books;if(h&&(w=w.filter(z=>z.section===h)),b.trim()){const z=b.trim().toLowerCase();w=w.filter(T=>T.title.toLowerCase().includes(z)||T.sub_items&&T.sub_items.some(R=>R.toLowerCase().includes(z))||T.edition&&T.edition.toLowerCase().includes(z))}return w},[y,h,b]),_=g.useMemo(()=>{if(!$)return null;const w=[],z=new Map;for(const R of S){if(!R.volumes||R.volumes.length===0)continue;const C=R.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(R)}const T=[...z.keys()].sort((R,C)=>R-C);for(const R of T)w.push({volume:R,books:z.get(R)});return w},[S,$]);return u?t.jsx("div",{className:l,style:{...c,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):x?t.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:x}):y?t.jsxs("div",{className:l,style:c,children:[t.jsx(ka,{data:y}),v&&t.jsx(Sa,{sections:y.sections,activeSection:h,onSelect:k}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:b,onChange:w=>j(w.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:o("desc-fg")},children:[S.length," ",p.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[_?_.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:Gt(p.catalog.volume,{n:w.volume})}),w.books.map((T,R)=>t.jsx(ro,{book:T,onNavigate:r,renderLink:s,showVolumes:T.volumes.length>1},`${w.volume}-${R}`))]},`${w.volume}-${z}`)):S.map((w,z)=>t.jsx(ro,{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:p.catalog.noMatch})]})]}):null},gt=()=>{const[e,n]=g.useState(1);return g.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)})},Sr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],$a={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Te(e){return $a[e]??e}const St=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],wt={熹平: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},wr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function pn(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 za(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 Ca=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,so={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function ii(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(so))if(n.startsWith(s))return so[s];const i=Te(n);if(dt[i]!=null)return i;const r=tt(n);if(r&&n.length<=r.length+1)return Te(r)}function ct(e,n){if(n){const i=wr[`${n}|${e}`];if(i!=null)return i}return wt[e]}const Ia=1911;function Ta(e){const n=wt[e];if(n==null)return;const i=Ke[e];let r;for(const[s,l]of Object.entries(wt))Ke[s]===i&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const Ra={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function rn(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 c=Ra[l];if(c===void 0)return;r=!0,l==="十"?i=(i||1)*10:l==="廿"||l==="卅"?(n+=c,i=0):i>=10?(n+=i+c,i=0):i=i*10+c}const s=n+i;return r&&s>0?s:void 0}function tt(e){for(const n of Sr)if(e.startsWith(n))return n}const Ke={};{const e=(n,i)=>{for(const r of i)Ke[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function pt(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(wt))if(e.includes(r)&&!(i&&Ke[r]&&Ke[r]!==i&&wr[`${i}|${r}`]==null))return r}function Ut(e){var c,p,a;const n={era:"",reign:"",source:"none"},i=e.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const d=tt(r)??"";return{era:Te(d),reign:pt(r,d)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const d=pn(s);if(d)return{era:za(d.from),reign:"",source:"publication"};const u=tt(s)??ii(s)??((a=St.find(m=>m.pattern.test(s)))==null?void 0:a.era)??"",f=pt(s,u)??"",x=u||(f?Ke[f]??"":"");if(x||f)return{era:Te(x),reign:f,source:"publication"}}const l=e.edition||e.title||"";if(l){const d=tt(l);if(d)return{era:Te(d),reign:pt(l,d)??"",source:"edition"};const u=St.find(f=>f.pattern.test(l));if(u)return{era:Te(u.era),reign:pt(l,u.era)??u.reign??"",source:"edition"}}return n}function un(e){var r,s,l,c,p,a,d,u,f;if(((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;if(typeof((s=e.lineage)==null?void 0:s.year)=="number")return e.lineage.year;const n=(l=e.publication_info)==null?void 0:l.year;if(n){const x=pn(n);if(x)return x.from}const i=[(c=e.lineage)==null?void 0:c.year_text,(p=e.publication_info)==null?void 0:p.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const x of i){const m=((a=e.publication_info)==null?void 0:a.year)||((d=e.lineage)==null?void 0:d.year_text);if(m&&x!==m&&(tt(m)||ii(m)))break;const h=x.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??x.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(h){const v=parseInt(h[1],10);if(v>=100&&v<=2100)return v}const k=x.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(k){const v=tt(x);if(!v||Te(v)==="民國"){const S=rn(k[1]);if(S!=null&&S>=1&&S<=120)return Ia+S}}const b=tt(x)??((u=St.find(v=>v.pattern.test(x)))==null?void 0:u.era),j=b?Te(b):void 0,y=pt(x,j)??(tt(x)||(f=St.find(v=>v.pattern.test(x)))==null?void 0:f.reign);if(y){const v=ct(y,j);if(v==null)continue;const $=x.indexOf(y),S=$>=0?x.slice($+y.length):"",_=S.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??S.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),w=_?rn(_[1]):void 0;return v+(w?w-1:0)}}}function oi(e){var c,p,a,d,u,f;const n=(c=e.dating)==null?void 0:c.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(p=e.lineage)==null?void 0:p.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(a=e.lineage)==null?void 0:a.year_text;if(r){const x=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(x){const m=Ln[Te(x[1])],h=dt[Te(x[2])];if(m!=null&&h!=null)return{from:Math.min(m,h)-20,to:Math.max(m,h)+40}}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const x=pn(s);if((x==null?void 0:x.to)!=null)return{from:x.from,to:x.to};const m=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(m){const h=Ln[Te(m[1])],k=dt[Te(m[2])];if(h!=null&&k!=null)return{from:Math.min(h,k)-20,to:Math.max(h,k)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const x of l){if(!/[間间]/.test(x))continue;const m=tt(x)??ii(x)??((f=St.find(b=>b.pattern.test(x)))==null?void 0:f.era),h=m?Te(m):void 0,k=[];for(const b of Object.keys(wt))x.includes(b)&&(h&&Ke[b]&&Ke[b]!==h||ct(b,h)!=null&&k.push(b));if(k.length===0){const b=x.match(/([一-鿿])([一-鿿])[間间]/);if(b&&h){for(const j of[b[1],b[2]])for(const y of Object.keys(wt))if(Ke[y]===h&&!(y[0]!==j&&y[y.length-1]!==j)&&ct(y,h)!=null){k.push(y);break}}}if(k.length>0){const b=k.map($=>ct($,h)).filter($=>$!=null),j=Math.min(...b),y=k.reduce(($,S)=>ct($,h)>=ct(S,h)?$:S),v=Ta(y)??vn(h??"")??Math.max(...b);return{from:j,to:v>j?v:vn(h??Ke[y]??"")??j}}if(h&&dt[h]!=null)return{from:dt[h],to:vn(h)??dt[h]}}}const dt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Ea=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Na=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,lo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function ao(e,n){for(const i of Sr){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const a=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(a)&&!pt(e.slice(r),Te(i)))continue}const s=Te(i);if(s===n)continue;const l=e.slice(r),c=pt(l,s)??"";let p;if(c){const a=ct(c,s);if(a!=null){const u=l.slice(l.indexOf(c)+c.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),f=u?rn(u[1]):void 0;p=a+(f?f-1:0)}}return{era:s,reign:c,year:p}}for(const i of St)if(i.pattern.test(e))return{era:Te(i.era),reign:i.reign??""}}function La(e){var j,y,v,$,S;const n=Ut(e),i=((j=e.publication_info)==null?void 0:j.year)??"",r=i?pn(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),c=((y=e.lineage)==null?void 0:y.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(c),a=n.source==="publication"&&Ca.test(i),d=n.source==="publication"&&/[間间]/.test(i),u=c.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let f;l||p||a||d?f=void 0:u?f=parseInt(u[2],10):f=un(e);const x=f==null?oi(e):void 0;let m;n.source==="publication"&&(a||lo.test(i))?m="uncertain":n.source==="lineage"||n.source==="publication"?m="attested":lo.test(s)||!n.reign&&f==null?m="uncertain":m="inferred";const h=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((v=e.lineage)==null?void 0:v.year_text)??(($=e.lineage)==null?void 0:$.year)??""}」`:`出版著錄「${((S=e.publication_info)==null?void 0:S.year)??""}」`,k={era:n.era,reign:n.reign,year:f,yearRange:x,certainty:m,source:n.source==="edition"?"edition":"catalog",basis:h};if(u){const _=c.match(/[、,,]\s*([宋元明清])/);_&&_[1]!==k.era&&(k.laterRepair={era:_[1]})}if(!k.laterRepair&&Na.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(k.laterRepair={era:_[1]})}const b=Ea.find(_=>_.re.test(s));if(b){const _=s.search(b.re),w=s.slice(_),z=ao(w,n.era)??ao(s,n.era);z&&(k.basedOn={era:z.era,reign:z.reign,year:z.year,relation:b.relation})}return k}const Ln={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function vn(e){return Ln[e]}function sn(e){const n=un(e);if(n!=null)return n;const i=oi(e);if(i)return i.from;const r=Ut(e).era;return r?dt[r]:void 0}const co=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Bn(e){const n=co.indexOf(e);return n===-1?co.length:n}function Ba(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 ri(e,n){const i=Zn(e||[]),r=new Map,s=[];for(const d of i)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((u,f)=>{const x=m=>m.group_role==="origin"?0:m.group_role==="mirror"?1:2;return x(u)-x(f)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=ft(d),f=u.includes("text"),x=u.includes("image");f&&x?l.textImage.push(d):f?l.text.push(d):x?l.image.push(d):l.physical.push(d)}const p=["text","image","textImage","physical"].filter(d=>l[d].length>0).map(d=>({key:d,items:l[d]})),a=[...r.entries()].map(([d,u])=>{var f,x;return{key:d,label:((f=n==null?void 0:n[d])==null?void 0:f.label)||d,description:(x=n==null?void 0:n[d])==null?void 0:x.description,items:u}});return{buckets:p,mirrors:a,total:i.length}}function xn(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=cn(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 _r(e,n){if(xn(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 $r(e,n){var l,c;const i=e.resources||[],r=[],s=[];for(const p of i){const a=ft(p);a.includes("image")&&r.push(p),a.includes("physical")&&s.push(p)}return{id:e.id,name:e.edition||e.title||e.id,era:Ut(e),year:un(e),sortYear:sn(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:Aa(e.id,n),group:(c=n==null?void 0:n.node_groups)==null?void 0:c[e.id],hasImage:r.length>0}}function Aa(e,n){var p,a;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(p=n.collections)==null?void 0:p[i];if(((r==null?void 0:r.book_ids)??(i==="core"?n.core_books??[]:[])).includes(e))return!0;const l=(r==null?void 0:r.groups)??[],c=(a=n.node_groups)==null?void 0:a[e];return!!c&&l.includes(c)}function zr(e,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(a=>!r.has(a.id)).map(a=>$r(a,n));let l=s;i.era&&(l=l.filter(a=>a.era.era===i.era)),i.scanOnly&&(l=l.filter(a=>a.hasImage)),i.sort==="year"?l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=a.r.sortYear,f=d.r.sortYear;return u!=null&&f!=null?u-f||a.i-d.i:u!=null?-1:f!=null?1:a.i-d.i}).map(a=>a.r):l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=f=>(f.important?0:1)*2+(f.hasImage?0:1);return u(a.r)-u(d.r)||a.i-d.i}).map(a=>a.r);const p=[...new Set(s.map(a=>a.era.era).filter(Boolean))].sort((a,d)=>Bn(a)-Bn(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(a=>a.era.source==="edition")}}function Wa(e,n){var b,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(b=n.collections)==null?void 0:b[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,c=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&c.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...c]),d=y=>{if(a.has(y))return!0;const v=n.node_groups[y];return v!=null&&p.has(v)},u=[],f=new Map,x=[];for(const y of e)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))u.push(y);else{const v=n.node_groups[y];v?(f.has(v)||f.set(v,[]),f.get(v).push(y)):x.push(y)}if(x.length+[...f.values()].reduce((y,v)=>y+v.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const h=new Map((n.groups??[]).map(y=>[y.id,y])),k=[...f.entries()].map(([y,v])=>{const $=h.get(y);return{id:y,label:($==null?void 0:$.label)??y,description:$==null?void 0:$.description,ids:v}});return x.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:k}}const Cr=["撰","編","注","校","譯","繪","其他"],Ma=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function si(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of Ma)if(r.test(n))return i;return"其他"}function li(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Ir(e){const n=new Map;for(const r of e){const s=si(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:e.length}];for(const r of Cr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function Tr(e,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(c=>({id:c.work_id||c.book_id||void 0,title:c.title,section:c.section,volumes:c.volumes||[],subItems:c.sub_items,edition:c.edition,found:c.found_volumes,expected:c.expected_volumes})),l=[...new Set(s.map(c=>c.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:Ot(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,c;return{id:s,title:((l=i==null?void 0:i.get(s))==null?void 0:l.title)||s,edition:(c=i==null?void 0:i.get(s))==null?void 0:c.edition,volumes:[]}}),source:"books",sections:[]}}function Ot(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 fn(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((l,c)=>l-c),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 Fa=["〇","一","二","三","四","五","六","七","八","九"],po=["","十","百","千"];function Rr(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 c=parseInt(n[l]),p=i-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=po[p]:r+=Fa[c]+po[p])}return r}function Pa(e){return e==null?"":typeof e=="string"?e:e.title??""}function it(e,n="卷"){var r,s;const i=e;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?Rr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Er(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 Oa="guji_markdown";function An(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 Da=/^□\{guess=([^\s{}]+)\}/;function Ha(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function Nr(e,n){let i=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
9
+ `)return-1;if(s==="\\"){r++;continue}if(s==="[")i++;else if(s==="]"&&(i--,i===0))return r}return-1}function Ga(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function Ua(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(`
10
+ `)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const r=Nr(e,n+3);return r>n+4?{node:{type:"zi",label:Ga(e.slice(n+4,r))},end:r+1}:null}if(i==="□"&&e[n+1]==="{"){const r=Da.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function Lr(e,n,i,r){const s=[];let l="";const c=()=>{if(!l)return;const p=r?l.replace(/\\?\|/g,""):l;p&&s.push({type:"text",text:p}),l=""};for(;n<e.length;){const p=e[n];if(i!==null){if(p===i)return c(),{nodes:s,end:n};if(p===`
11
+ `)return null}const a=Ua(e,n);if(a){c(),s.push(a.node),n=a.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&Ha(e,n)&&(d=">"),d){const u=Lr(e,n+1,d,!0);if(u){c(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return i!==null?null:(c(),{nodes:s,end:n})}function Br(e){return Lr(e,0,null,!1).nodes}function Va(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function Ar(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Ar(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const Ya=216,uo="clamp(280px, 23vw, 360px)",Ka=1440,Wr="(max-width: 719px)",qa=`${Wr}, (pointer: coarse)`,Ja=`
12
+ .bim-d-main.bim-d-main-grid { max-width: ${Ka}px; padding: 16px 32px 0; }
13
13
  .bim-d-grid {
14
14
  display: grid;
15
- grid-template-columns: ${Ma}px minmax(0, 1fr) ${uo};
15
+ grid-template-columns: ${Ya}px minmax(0, 1fr) ${uo};
16
16
  grid-template-rows: auto 1fr;
17
17
  grid-template-areas: "rail main card" "rail main side";
18
18
  column-gap: 32px; row-gap: 28px; align-items: start;
@@ -79,6 +79,9 @@
79
79
  .bim-d-zt .bim-d-zt-empty { color: ${o("aux-fg")}; }
80
80
  /* 版本表:行高先按「有影印」色块那一行的高度占好,解析到的年代、馆藏、色块进来时行不再长高(INT Q3) */
81
81
  .bim-d-zt-ver tbody tr { height: 42px; }
82
+ /* 版本行的卷帙小字(measure_info)随次级数据晚到,会把行撑高、把「展开」按钮整体下推(P2-8,CLS 0.11):
83
+ 解析前就按「版本名 + 一行小字」占高 */
84
+ .bim-d-zt-ver tbody tr[data-loading] { height: 62px; }
82
85
 
83
86
  .bim-d-flag {
84
87
  display: inline-block; padding: 1px 8px; border-radius: 4px;
@@ -228,7 +231,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
228
231
  .bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
229
232
 
230
233
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
231
- @media ${Pa} {
234
+ @media ${qa} {
232
235
  .bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
233
236
  .bim-d-card-foot summary, .bim-d-card-toggle, .bim-d-card details.bim-d-more-names summary,
234
237
  .bim-d-tl summary, .bim-d-chap a { min-height: 44px; }
@@ -249,6 +252,12 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
249
252
  content: ""; position: absolute; left: 50%; top: 50%;
250
253
  width: max(calc(100% + 8px), 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
251
254
  }
255
+ /* 影印「鏡像」链接:一行里并排几个,只上下外扩到 44,左右各扩 6px(间距 14px,不叠) */
256
+ .bim-d-rg-mir a { position: relative; }
257
+ .bim-d-rg-mir a::after {
258
+ content: ""; position: absolute; left: -6px; right: -6px; top: 50%;
259
+ height: 44px; transform: translateY(-50%);
260
+ }
252
261
  /*
253
262
  * 相邻热区不能叠:两字页签(26px)两边各扩 9px,间距 18px 正好贴边,放宽到 20px;
254
263
  * 单字页签(13px)两边各扩 15.5px,再左右各多留 7px
@@ -274,7 +283,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
274
283
  }
275
284
 
276
285
  /* 手机:左栏收起,提要卡 → 正文 → 旁栏 */
277
- @media ${Ar} {
286
+ @media ${Wr} {
278
287
  .bim-d-main.bim-d-main-grid { padding: 8px 16px 0; }
279
288
  .bim-d-grid {
280
289
  grid-template-columns: minmax(0, 1fr);
@@ -315,7 +324,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
315
324
  .bim-d-pick-n { margin: 0; grid-column: 2; grid-row: 1 / span 2; }
316
325
  .bim-d-find { flex-basis: 100%; min-height: 40px; }
317
326
  }
318
- `;function Ut({railTop:e,back:n,up:i,nav:r,railLinks:s,main:l,card:c,side:p}){const{convert:a}=U(),d=(r||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,n&&t.jsx("div",{style:{marginTop:e?12:0},children:n}),i,d.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":a("本頁導航"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:a("本頁")}),t.jsx("ul",{className:"bim-d-rail-nav",children:d.map(u=>t.jsx("li",{children:t.jsxs("a",{href:`#${u.id}`,children:[t.jsx("span",{children:a(u.label)}),u.count!=null&&t.jsx("span",{className:"bim-d-meta",children:u.count})]})},u.id))})]}),s&&s.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":a("更多"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:a("更多")}),t.jsx("ul",{className:"bim-d-rail-nav",children:s.map(u=>t.jsx("li",{children:t.jsxs("a",{href:u.href??"#",onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),u.onClick())},children:[t.jsx("span",{children:a(u.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},u.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:l}),t.jsx("div",{className:"bim-d-g-card",children:c}),t.jsx("div",{className:"bim-d-g-side",children:p})]})}function Wr({caption:e,children:n}){const{convert:i}=U();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:i(e)}),n]})}function Te({id:e,title:n,meta:i,action:r,children:s}){const{convert:l}=U();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 Ie({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(g.Fragment,{children:[l>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},l))}):null}function ai({items:e,value:n,onChange:i}){const{convert:r}=U();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 Mr({label:e,checked:n,onChange:i}){const{convert:r}=U();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 Ct({label:e,onClick:n}){const{convert:i}=U();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:i(e)})}function Vt({kind:e,title:n,subtitle:i,byline:r,meta:s,description:l,clampDescription:c,facts:p,readAction:a,secondaryAction:d,children:u,foot:f}){const{convert:x}=U(),m=(p||[]).filter(j=>j.value!=null&&j.value!==""),[h,v]=g.useState(!1),b=!!c&&!h;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:x(e)}),t.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),i&&t.jsx("div",{className:"bim-d-card-sub",children:i}),r&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:r}),s&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),l&&t.jsx("div",{className:b?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:b?{"--detail-clamp":c}:void 0,children:l}),l&&!!c&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":h,onClick:()=>v(j=>!j),children:x(h?"收起":"展開")}),m.length>0&&t.jsx("dl",{className:"bim-d-ui",children:m.map((j,y)=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:x(j.label)}),t.jsx("dd",{title:j.title,children:j.value})]},y))}),u,a,d,f&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:f})]})}function ci(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function Wn({href:e,onClick:n,label:i="閱讀全文"}){const{convert:r}=U();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 pt({id:e,title:n,meta:i,items:r,metas:s,currentIndex:l,cap:c=8,moreLabel:p}){const{convert:a}=U(),[d,u]=g.useState(!1);if(!r.length)return null;const f=d?r:r.slice(0,c),x=r.length-f.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:[a(n),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i})]}),t.jsx("ul",{children:f.map((m,h)=>t.jsxs("li",{className:h===l?"bim-d-side-cur":void 0,"aria-current":h===l?"page":void 0,children:[m,s!=null&&s[h]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[h]}):null]},h))}),x>0&&t.jsx(Ct,{label:p?p(x):`顯示更多(${x})`,onClick:()=>u(!0)})]})}const Da={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核"};function Yt({revision:e,revisedAt:n,review:i,todo:r}){const{convert:s}=U(),l=i&&i.status!=="unreviewed"?[Da[i.status]??i.status,i.by,i.date].filter(Boolean).join(" "):"",c=[e!=null&&e!==""?`${s("數據版本")} ${e}`:"",n??"",s(l)].filter(Boolean),p=(r||[]).filter(a=>a&&a.what);return!c.length&&!p.length?null:t.jsxs(t.Fragment,{children:[c.length>0&&t.jsx(Ie,{items:c,style:{fontSize:12}}),p.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s(`待核 ${p.length} 項`)}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:p.map((a,d)=>t.jsxs("li",{children:[s(a.what),(a.by||a.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[a.by&&s(a.by),a.date].filter(Boolean).join(" · "),")"]})]},d))})]})]})}const Wt=1e3,kn=208,Ha="(max-width: 719px)",Fr=`
327
+ `;function Vt({railTop:e,back:n,up:i,nav:r,railLinks:s,main:l,card:c,side:p}){const{convert:a}=Y(),d=(r||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,n&&t.jsx("div",{style:{marginTop:e?12:0},children:n}),i,d.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":a("本頁導航"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:a("本頁")}),t.jsx("ul",{className:"bim-d-rail-nav",children:d.map(u=>t.jsx("li",{children:t.jsxs("a",{href:`#${u.id}`,children:[t.jsx("span",{children:a(u.label)}),u.count!=null&&t.jsx("span",{className:"bim-d-meta",children:u.count})]})},u.id))})]}),s&&s.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":a("更多"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:a("更多")}),t.jsx("ul",{className:"bim-d-rail-nav",children:s.map(u=>t.jsx("li",{children:t.jsxs("a",{href:u.href??"#",onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),u.onClick())},children:[t.jsx("span",{children:a(u.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},u.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:l}),t.jsx("div",{className:"bim-d-g-card",children:c}),t.jsx("div",{className:"bim-d-g-side",children:p})]})}function Mr({caption:e,children:n}){const{convert:i}=Y();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:i(e)}),n]})}function Ee({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 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(g.Fragment,{children:[l>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},l))}):null}function ai({items:e,value:n,onChange:i}){const{convert:r}=Y();return t.jsx(t.Fragment,{children:e.map(s=>t.jsx("button",{type:"button",className:[...r(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>i(s.key),children:r(s.label)},s.key))})}function Fr({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 It({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 Yt({kind:e,title:n,subtitle:i,byline:r,meta:s,description:l,clampDescription:c,facts:p,readAction:a,secondaryAction:d,children:u,foot:f}){const{convert:x}=Y(),m=(p||[]).filter(j=>j.value!=null&&j.value!==""),[h,k]=g.useState(!1),b=!!c&&!h;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:x(e)}),t.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),i&&t.jsx("div",{className:"bim-d-card-sub",children:i}),r&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:r}),s&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),l&&t.jsx("div",{className:b?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:b?{"--detail-clamp":c}:void 0,children:l}),l&&!!c&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":h,onClick:()=>k(j=>!j),children:x(h?"收起":"展開")}),m.length>0&&t.jsx("dl",{className:"bim-d-ui",children:m.map((j,y)=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:x(j.label)}),t.jsx("dd",{title:j.title,children:j.value})]},y))}),u,a,d,f&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:f})]})}function ci(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function Wn({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 ut({id:e,title:n,meta:i,items:r,metas:s,currentIndex:l,cap:c=8,moreLabel:p}){const{convert:a}=Y(),[d,u]=g.useState(!1);if(!r.length)return null;const f=d?r:r.slice(0,c),x=r.length-f.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:[a(n),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i})]}),t.jsx("ul",{children:f.map((m,h)=>t.jsxs("li",{className:h===l?"bim-d-side-cur":void 0,"aria-current":h===l?"page":void 0,children:[m,s!=null&&s[h]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[h]}):null]},h))}),x>0&&t.jsx(It,{label:p?p(x):`顯示更多(${x})`,onClick:()=>u(!0)})]})}const Za={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function Kt({revision:e,revisedAt:n,review:i,todo:r}){const{convert:s}=Y(),l=i?Za[i.status]:void 0,c=i&&i.status!=="unreviewed"&&l?[l,i.by,i.date].filter(Boolean).join(" "):"",p=[e!=null&&e!==""?`${s("數據版本")} ${e}`:"",n??"",s(c)].filter(Boolean),a=(r||[]).filter(d=>d&&d.what);return!p.length&&!a.length?null:t.jsxs(t.Fragment,{children:[p.length>0&&t.jsx(Re,{items:p,style:{fontSize:12}}),a.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s(`待核 ${a.length} 項`)}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:a.map((d,u)=>t.jsxs("li",{children:[s(d.what),(d.by||d.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[d.by&&s(d.by),d.date].filter(Boolean).join(" · "),")"]})]},u))})]})]})}const Mt=1e3,kn=208,Xa="(max-width: 719px)",Pr=`
319
328
  .bim-d-page {
320
329
  background: ${o("page-bg")};
321
330
  color: ${o("ink")};
@@ -324,7 +333,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
324
333
  padding-bottom: 64px;
325
334
  }
326
335
  .bim-d-main {
327
- max-width: ${Wt}px;
336
+ max-width: ${Mt}px;
328
337
  margin: 0 auto;
329
338
  padding: 24px clamp(16px, 4vw, 28px) 0;
330
339
  }
@@ -335,7 +344,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
335
344
  * PAGE_MAX_WIDTH,读者的行宽体验不变。
336
345
  */
337
346
  .bim-d-main.bim-d-main-wide {
338
- max-width: ${kn+Wt+32}px;
347
+ max-width: ${kn+Mt+32}px;
339
348
  }
340
349
  .bim-d-ui { font-family: var(--bim-font-ui, system-ui, sans-serif); }
341
350
 
@@ -367,9 +376,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
367
376
  */
368
377
  .bim-d-reader {
369
378
  display: grid;
370
- grid-template-columns: ${kn}px minmax(0, ${Wt}px);
379
+ grid-template-columns: ${kn}px minmax(0, ${Mt}px);
371
380
  gap: 32px;
372
- max-width: ${kn+Wt+32}px;
381
+ max-width: ${kn+Mt+32}px;
373
382
  margin: 0 auto;
374
383
  align-items: start;
375
384
  }
@@ -392,7 +401,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
392
401
  align-items: start; margin-bottom: 48px; }
393
402
  .bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
394
403
 
395
- @media ${Ha} {
404
+ @media ${Xa} {
396
405
  .bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
397
406
  .bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
398
407
  /* 表格:meta 列折到第二行,表头隐藏 */
@@ -410,14 +419,14 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
410
419
  padding-right: 0; padding-bottom: 12px;
411
420
  }
412
421
  }
413
- ${Oa}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Fr}),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 Mn({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 di({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 Fn({items:e}){const n=Re();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}`),c=i.id?n(i.id):i.href,p=s||!i.onClick&&!c?t.jsx("span",{style:{color:o("ink")},children:i.label},r):t.jsx("a",{href:c??"#",onClick:i.onClick?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i.onClick())}:void 0,style:{color:o("meta-fg")},children:i.label},r);return t.jsxs(g.Fragment,{children:[l,p]},r)})})}function Pr({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 Ga({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 Ua({items:e,horizontal:n}){const{convert:i}=U();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 Va({glyph:e,tone:n,title:i,count:r,actions:s,id:l}){const{convert:c}=U();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(di,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:c(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 Or({label:e,active:n,onClick:i,dashed:r}){const{convert:s}=U();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 Ya({label:e,onClick:n}){const{convert:i}=U();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 Ka({label:e,onClick:n,inline:i}){const{convert:r}=U();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 Dr({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 qa({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function Ja({volumes:e,unit:n="冊",max:i=60}){const[r,s]=g.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(c=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${o("rule")}`,color:o("meta-fg")},children:c},c)),!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 Za({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${o("rule-strong")}`},children:e})}function Xa({spec:e}){const{convert:n}=U();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 Qa({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 ec(e){return String(e+1).padStart(2,"0")}function tc(){return t.jsx("span",{style:{color:o("hint-fg")},children:"—"})}function nc({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 Hr(e){const n=[];for(let i=0;i<e.length;i++){const r=e[i];let s;if(r==="⟨")s="⟩";else if(r==="<"){const p=e[i+1];if(p===void 0||/[A-Za-z/!?>\s]/.test(p))continue;s=">"}else continue;const l=e.indexOf(s,i+1);if(l<0)continue;const c=e.slice(i+1,l);c.includes(`
414
- `)||(n.push({start:i,end:l+1,inner:c}),i=l)}return n}function Gr(e,n){if(e.length<=n)return e;let i=n;for(const r of Hr(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 Ur={fontSize:".78em",color:o("meta-fg"),lineHeight:1.55},ic={display:"inline-block",fontSize:"1em",lineHeight:1.15,padding:"0 .12em",margin:"0 .05em",border:"1px solid color-mix(in srgb, currentColor 40%, transparent)",borderRadius:2,verticalAlign:"baseline",whiteSpace:"nowrap"};function Vr(e,n,i){return e.map((r,s)=>{switch(r.type){case"text":return t.jsx(g.Fragment,{children:n(r.text)},s);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:i===0?Ur:void 0,children:Vr(r.children,n,i+1)},s);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:r.label?`闕文:${r.label}`:"闕文",children:"□"},s);case"qz":return t.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":r.guess,children:"□"},s);case"zi":return t.jsx("span",{className:"bim-zi guji-zi",title:`組字:${r.label}`,style:ic,children:r.label},s)}})}function Fe(e,n=r=>r,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return Wa(e)?Vr(Lr(e),n,0):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let s=0,l=0;for(const c of Hr(e))c.start>s&&r.push(t.jsx(g.Fragment,{children:n(e.slice(s,c.start))},l++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:Ur,children:n(c.inner)},l++)),s=c.end;return s<e.length&&r.push(t.jsx(g.Fragment,{children:n(e.slice(s))},l++)),r}function oc({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 rc({title:e,tag:n,children:i}){const{convert:r}=U();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 Yr({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 sc({item:e,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=U(),[l,c]=g.useState(!1),p=cn(e),a=i&&!!p&&p.expected>0,d=(e.url?$t(e.url):void 0)||s(e.name),u=n?wr(e,n):"",f=u?`${d}(${u})`:d;return t.jsx(Yr,{name:f,note:xn(e)||r,href:zt(e),extra:a?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>c(x=>!x),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:o("meta-fg"),borderBottom:`1px solid ${o("rule")}`},children:l?"收起分冊":`展開 ${p.expected} 冊`}),l&&t.jsx(pi,{item:e})]}):void 0})}function pi({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 Kr({label:e,items:n}){const{convert:i}=U();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(Dr,{children:i(r)},s))]}):null}function lc({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(Kr,{label:i.label,items:i.items},i.label))}):null}function Pn(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function qr({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 ac({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 ze({id:e,label:n,onNavigate:i,renderLink:r,style:s,dense:l}){const c=Re();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:l})}):t.jsx("a",{href:c(e),onClick:i?p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(e))}:void 0,style:s,children:n??e})}function cc({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 Jr="(min-width: 1100px)",Zr="(max-width: 719px)",dc=`${Zr}, (pointer: coarse)`,ot=o("reader-top"),pc="48px",Xr=`
422
+ ${Ja}`;function Ft({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Pr}),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 Mn({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 di({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 Fn({items:e}){const n=Ne();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}`),c=i.id?n(i.id):i.href,p=s||!i.onClick&&!c?t.jsx("span",{style:{color:o("ink")},children:i.label},r):t.jsx("a",{href:c??"#",onClick:i.onClick?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i.onClick())}:void 0,style:{color:o("meta-fg")},children:i.label},r);return t.jsxs(g.Fragment,{children:[l,p]},r)})})}function Or({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 Qa({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 ec({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 tc({glyph:e,tone:n,title:i,count:r,actions:s,id:l}){const{convert:c}=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(di,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:c(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 Dr({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 nc({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 ic({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 Hr({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 oc({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function rc({volumes:e,unit:n="冊",max:i=60}){const[r,s]=g.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(c=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${o("rule")}`,color:o("meta-fg")},children:c},c)),!r&&e.length>i&&t.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${o("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:o("meta-fg")},children:["+",e.length-i]}),t.jsx("span",{style:{padding:"2px 6px",color:o("hint-fg")},children:n})]})}function sc({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${o("rule-strong")}`},children:e})}function lc({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 ac({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 cc(e){return String(e+1).padStart(2,"0")}function dc(){return t.jsx("span",{style:{color:o("hint-fg")},children:"—"})}function pc({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 Gr(e){const n=[];for(let i=0;i<e.length;i++){const r=e[i];let s;if(r==="⟨")s="⟩";else if(r==="<"){const p=e[i+1];if(p===void 0||/[A-Za-z/!?>\s]/.test(p))continue;s=">"}else continue;const l=e.indexOf(s,i+1);if(l<0)continue;const c=e.slice(i+1,l);c.includes(`
423
+ `)||(n.push({start:i,end:l+1,inner:c}),i=l)}return n}function Ur(e,n){if(e.length<=n)return e;let i=n;for(const r of Gr(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 Vr={fontSize:".78em",color:o("meta-fg"),lineHeight:1.55},uc={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 Yr(e,n,i){return e.map((r,s)=>{switch(r.type){case"text":return t.jsx(g.Fragment,{children:n(r.text)},s);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:i===0?Vr:void 0,children:Yr(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:uc,children:r.label},s)}})}function Fe(e,n=r=>r,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return Va(e)?Yr(Br(e),n,0):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let s=0,l=0;for(const c of Gr(e))c.start>s&&r.push(t.jsx(g.Fragment,{children:n(e.slice(s,c.start))},l++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:Vr,children:n(c.inner)},l++)),s=c.end;return s<e.length&&r.push(t.jsx(g.Fragment,{children:n(e.slice(s))},l++)),r}function xc({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 fc({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 Kr({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 gc({item:e,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=Y(),[l,c]=g.useState(!1),p=cn(e),a=i&&!!p&&p.expected>0,d=(e.url?zt(e.url):void 0)||s(e.name),u=n?_r(e,n):"",f=u?`${d}(${u})`:d;return t.jsx(Kr,{name:f,note:xn(e)||r,href:Ct(e),extra:a?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>c(x=>!x),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:o("meta-fg"),borderBottom:`1px solid ${o("rule")}`},children:l?"收起分冊":`展開 ${p.expected} 冊`}),l&&t.jsx(pi,{item:e})]}):void 0})}function pi({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 qr({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(Hr,{children:i(r)},s))]}):null}function mc({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(qr,{label:i.label,items:i.items},i.label))}):null}function Pn(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Jr({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 hc({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 Ie({id:e,label:n,onNavigate:i,renderLink:r,style:s,dense:l}){const c=Ne();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:l})}):t.jsx("a",{href:c(e),onClick:i?p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(e))}:void 0,style:s,children:n??e})}function bc({href:e,children:n}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[n," ",t.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const Zr="(min-width: 1100px)",Xr="(max-width: 719px)",yc=`${Xr}, (pointer: coarse)`,rt=o("reader-top"),jc="48px",Qr=`
415
424
  .bim-rd {
416
425
  position: relative;
417
426
  background: ${o("page-bg")};
418
427
  color: ${o("ink")};
419
428
  font-family: ${o("font-ui")};
420
- --bimrd-bar-h: ${pc};
429
+ --bimrd-bar-h: ${jc};
421
430
  }
422
431
  .bim-rd *, .bim-rd *::before, .bim-rd *::after { box-sizing: border-box; }
423
432
 
@@ -443,7 +452,7 @@ ${Oa}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
443
452
 
444
453
  /* ── 工具条:文字 + 图标,不画按钮外框 ── */
445
454
  .bim-rd-bar {
446
- position: sticky; top: ${ot}; z-index: 30;
455
+ position: sticky; top: ${rt}; z-index: 30;
447
456
  height: var(--bimrd-bar-h);
448
457
  display: flex; align-items: center; gap: 16px;
449
458
  padding: 0 20px;
@@ -480,14 +489,14 @@ ${Oa}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
480
489
  display: grid;
481
490
  grid-template-columns: auto auto minmax(0, 1fr);
482
491
  align-items: start;
483
- min-height: calc(100vh - ${ot} - var(--bimrd-bar-h));
492
+ min-height: calc(100vh - ${rt} - var(--bimrd-bar-h));
484
493
  }
485
494
 
486
495
  /* 目录:宽屏是侧栏 */
487
496
  .bim-rd-toc {
488
497
  grid-column: 1;
489
- position: sticky; top: calc(${ot} + var(--bimrd-bar-h));
490
- width: 248px; height: calc(100vh - ${ot} - var(--bimrd-bar-h));
498
+ position: sticky; top: calc(${rt} + var(--bimrd-bar-h));
499
+ width: 248px; height: calc(100vh - ${rt} - var(--bimrd-bar-h));
491
500
  overflow-y: auto; overscroll-behavior: contain;
492
501
  padding: 0 10px 40px;
493
502
  background: ${o("sidebar-bg")};
@@ -524,8 +533,8 @@ ${Oa}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
524
533
  /* 书影:正文左侧 */
525
534
  .bim-rd-img {
526
535
  grid-column: 2;
527
- position: sticky; top: calc(${ot} + var(--bimrd-bar-h));
528
- width: clamp(300px, 32vw, 560px); height: calc(100vh - ${ot} - var(--bimrd-bar-h));
536
+ position: sticky; top: calc(${rt} + var(--bimrd-bar-h));
537
+ width: clamp(300px, 32vw, 560px); height: calc(100vh - ${rt} - var(--bimrd-bar-h));
529
538
  padding: 16px 0 16px 20px;
530
539
  display: flex; flex-direction: column; gap: 8px;
531
540
  }
@@ -536,7 +545,7 @@ ${Oa}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
536
545
  display: flex; align-items: center; justify-content: center; overflow: hidden;
537
546
  }
538
547
  .bim-rd-img-fig { position: relative; margin: 0; max-width: 100%; max-height: 100%; }
539
- .bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${ot} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
548
+ .bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${rt} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
540
549
  .bim-rd-img-fig svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
541
550
  .bim-rd-img-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 24px; text-align: center; font-size: 13px; color: ${o("meta-fg")}; }
542
551
  .bim-rd-img-empty b { font-size: 15px; font-weight: 500; color: ${o("quiet-fg")}; }
@@ -600,21 +609,25 @@ ${Oa}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
600
609
 
601
610
  /* 竖排(预留):只在宿主打开 allowVertical 时可切换 */
602
611
  .bim-rd-vertical .bim-rd-prose {
603
- writing-mode: vertical-rl; max-height: calc(100vh - ${ot} - var(--bimrd-bar-h) - 120px);
612
+ writing-mode: vertical-rl; max-height: calc(100vh - ${rt} - var(--bimrd-bar-h) - 120px);
604
613
  overflow-x: auto; text-align: start;
605
614
  }
606
615
 
607
616
  .bim-rd-src { margin: 48px 0 0; font-size: 12px; line-height: 1.8; color: ${o("meta-fg")}; font-family: ${o("font-ui")}; }
608
617
  .bim-rd-src .bim-rd-dot::before { content: "·"; margin: 0 0.5em; }
609
618
  .bim-rd-pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 56px; font-size: 14px; font-family: ${o("font-ui")}; }
610
- .bim-rd-pager .bim-rd-t { color: ${o("quiet-fg")}; }
619
+ .bim-rd-pager .bim-rd-t { color: ${o("quiet-fg")}; max-width: 100%; min-width: 0; }
620
+ /* 长回目不能撑宽页面:两侧各占不超过一半,标题省略号截断(390 宽 scrollWidth 曾到 648) */
621
+ .bim-rd-pager > span { display: flex; min-width: 0; max-width: calc(50% - 8px); }
622
+ .bim-rd-pager > span:last-child { margin-left: auto; justify-content: flex-end; }
623
+ .bim-rd-pglabel { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
611
624
  .bim-rd-refs { margin-top: 48px; font-size: 12px; line-height: 1.8; color: ${o("meta-fg")}; font-family: ${o("font-ui")}; }
612
625
  .bim-rd-refs h2 { font-size: 12px; font-weight: 600; letter-spacing: 0.2em; margin: 0 0 6px; color: ${o("meta-fg")}; }
613
626
  .bim-rd-refs ol { margin: 0; padding-left: 1.6em; }
614
627
 
615
628
  /* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
616
629
  A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
617
- @media ${dc} {
630
+ @media ${yc} {
618
631
  .bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
619
632
  .bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
620
633
  content: ""; position: absolute; left: 50%; top: 50%;
@@ -622,10 +635,11 @@ ${Oa}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
622
635
  }
623
636
  .bim-rd-tools .bim-rd-fs + .bim-rd-fs { margin-left: 12px; }
624
637
  .bim-rd-ver select { min-height: 44px; }
638
+ .bim-rd-pager .bim-rd-t { min-height: 44px; }
625
639
  }
626
640
 
627
641
  /* ── 中屏以下:目录改抽屉 ── */
628
- @media not all and ${Jr} {
642
+ @media not all and ${Zr} {
629
643
  .bim-rd-toc {
630
644
  position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto;
631
645
  width: min(86vw, 320px);
@@ -639,7 +653,7 @@ ${Oa}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
639
653
  }
640
654
 
641
655
  /* ── 窄屏:书影收起,只留正文 ── */
642
- @media ${Zr} {
656
+ @media ${Xr} {
643
657
  .bim-rd-bar { padding: 0 12px; gap: 10px; }
644
658
  .bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
645
659
  .bim-rd-ttl { flex: 1 1 auto; }
@@ -655,19 +669,19 @@ ${Oa}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
655
669
  .bim-rd-h1 { font-size: 20px; letter-spacing: 0.06em; }
656
670
  .bim-rd-prose { margin-top: 20px; }
657
671
  }
658
- `;function ui(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(r=>ui(r,n))):!1}const uc=()=>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 xc({item:e,activeKey:n,onSelect:i,tabKey:r}){const s=ui(e,n),[l,c]=g.useState(s||!!e.defaultExpanded);return g.useEffect(()=>{s&&c(!0)},[s]),g.useEffect(()=>{e.defaultExpanded&&c(!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:()=>c(p=>!p),children:[t.jsx(uc,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Qr,{items:e.children,activeKey:n,onSelect:i,tabKey:r})]})}function Qr({items:e,activeKey:n,onSelect:i,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(xc,{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 xo(e,n){var i;for(const r of e)if(r.key===n||ui(r,n))return r.key;return((i=e[0])==null?void 0:i.key)??null}function es({items:e,activeKey:n,onSelect:i,label:r="目录"}){const s=g.useRef(null),[l,c]=g.useState(null);g.useEffect(()=>{c(null)},[n]);const p=g.useMemo(()=>l||(n??xo(e,n)),[l,n,e]);g.useEffect(()=>{const d=s.current;if(!d)return;const u=Array.from(d.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const f=u.find(x=>x.dataset.rdTocKey===p)??u.find(x=>x.dataset.rdTocKey===xo(e,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===f?0:-1}),g.useEffect(()=>{const d=s.current,u=d==null?void 0:d.closest(".bim-rd-toc");if(!d||!u||!n)return;const f=Array.from(d.querySelectorAll("[data-rd-toc-key]")).find(m=>m.dataset.rdTocKey===n);if(!f)return;const x=f.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(x<u.scrollTop+80||x>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,x-u.clientHeight/3))},[n]);const a=g.useCallback(d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const f=s.current;if(!f)return;const x=Array.from(f.querySelectorAll("[data-rd-toc-key]")).filter(b=>!b.disabled),m=x.indexOf(document.activeElement);let h=m;if(d.key==="ArrowDown"?h=Math.min(x.length-1,m+1):d.key==="ArrowUp"?h=Math.max(0,m-1):d.key==="Home"?h=0:d.key==="End"&&(h=x.length-1),h<0||h===m)return;d.preventDefault();const v=x[h];for(const b of x)b.tabIndex=-1;v.tabIndex=0,v.focus(),c(v.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:a,children:t.jsx(Qr,{items:e,activeKey:n,onSelect:i,tabKey:p})})}function fc({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 ts({pages:e,loading:n,page:i,onPageChange:r,renderOverlay:s}){const[l,c]=g.useState(0),p=i??l,a=x=>{r?r(x):c(x)};if(g.useEffect(()=>{i===void 0&&c(0)},[e,i]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:"加载书影…"})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:"暂无书影"}),t.jsx("span",{children:"这一卷还没有配上影像;接入后在此与正文逐页对看"})]})});const d=Math.max(0,Math.min(e.length-1,p)),u=e[d],f=u.label??`${d+1}`;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${f} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(fc,{page:u}),s==null?void 0:s(u,d)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:d===0,onClick:()=>a(d-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${d+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:d===e.length-1,onClick:()=>a(d+1),children:"›"})]})]})}const xi={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal"},yt=[15,16,17,18,20,22,24],On=18,ns="bim-reader-prefs",gc="bim-reading-mode";function mc(){const e={...xi};try{const n=localStorage.getItem(ns),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&yt.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(gc))==="paragraph"&&(e.readingMode="paragraph"),i.properNames===!0&&(e.properNames=!0),i.writingMode==="vertical"&&(e.writingMode="vertical")}catch{}return e}function hc(e){try{localStorage.setItem(ns,JSON.stringify(e))}catch{}}function fo(e,n){const i=e??On,r=yt;let s=r.indexOf(i);return s<0&&(s=r.indexOf(On)),r[Math.max(0,Math.min(r.length-1,s+n))]}function fi(){const[e,n]=g.useState(xi);g.useEffect(()=>{n(mc())},[]);const i=g.useCallback(r=>{n(s=>{const l={...s,...r};return hc(l),l})},[]);return[e,i]}function bc(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 Dn(e){const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function is(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 os(e){const n=[],i=r=>{for(const s of r)s.children&&s.children.length>0?i(s.children):n.push(s)};return i(e),n}const yc=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),jc=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),t.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function vc(e,n){if(!n)return;const i=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(c=>c.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 kc(e,n){const[i,r]=g.useState(n);return g.useEffect(()=>{var c;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(s.matches);return(c=s.addEventListener)==null||c.call(s,"change",l),()=>{var p;return(p=s.removeEventListener)==null?void 0:p.call(s,"change",l)}},[e]),i}function Sc(){const e=g.useContext(_t);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 gi({title:e,subtitle:n,toc:i,activeKey:r,onSelect:s,tocHeader:l,tocCaption:c,images:p,imagesLoading:a,renderImageOverlay:d,imagePanel:u="auto",prefs:f,onPrefsChange:x,paragraphToggle:m,properNameToggle:h=!0,allowVertical:v,pager:b=!0,versions:j,currentVersionKey:y,onVersionChange:k,versionSource:$=!0,children:S,className:_,style:w}){const z=g.useId().replace(/:/g,""),T=`bim-rd-toc-${z}`,R=`bim-rd-text-${z}`,C=g.useRef(null),P=g.useRef(null),M=g.useRef(null),A=g.useRef(null),F=kc(Jr,!0),[G,D]=g.useState("auto"),E=G==="auto"?F:G==="open",le=!F,W=!!p&&p.length>0,[Y,re]=g.useState(u);g.useEffect(()=>{re(u)},[u]);const te=Y==="auto"?W||!!a:Y==="open",J=g.useCallback(V=>{var B;D("auto"),V&&((B=A.current)==null||B.focus())},[]),ee=()=>D(E?"closed":"open");g.useEffect(()=>{if(!le||G!=="open")return;const V=M.current,B=V==null?void 0:V.querySelector('input, [data-rd-toc-key][tabindex="0"]');B==null||B.focus()},[le,G]);const ge=g.useCallback(V=>{s(V),le&&J(!1);const B=P.current,oe=C.current;if(B&&oe&&typeof window<"u"){const de=B.getBoundingClientRect().top-oe.getBoundingClientRect().bottom;de<0&&window.scrollBy({top:de})}},[s,le,J]),se=g.useMemo(()=>os(i),[i]),[ie,O]=g.useState(null),Z=is(j,y!==void 0?y:ie),ne=(Z==null?void 0:Z.key)??null,N=g.useMemo(()=>se.map(V=>V.key).join(`
659
- `),[se]),I=g.useRef(null),K=V=>{V!==ne&&(I.current={key:V,sig:N,done:!1},y===void 0&&O(V),k==null||k(V))};g.useEffect(()=>{const V=I.current;if(!V||V.key!==ne)return;const B=se.find(de=>!de.disabled);if(!B)return;const oe=N!==V.sig;!oe&&V.done||(oe?I.current=null:V.done=!0,B.key!==r&&ge(B.key))},[ne,N,se,r,ge]);const X=se.findIndex(V=>V.key===r),xe=X>0?se.slice(0,X).reverse().find(V=>!V.disabled):void 0,fe=X>=0?se.slice(X+1).find(V=>!V.disabled):void 0,ke=f.fontSize??On,Q={...w,...f.fontSize?{"--bimrd-fs":`${f.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",f.writingMode==="vertical"&&v?"bim-rd-vertical":"",_].filter(Boolean).join(" "),"data-toc":G,"data-img":te?"open":"closed",style:Q,children:[t.jsx("style",{children:Xr}),t.jsx("a",{className:"bim-rd-skip",href:`#${R}`,onClick:V=>{var B,oe,de;V.preventDefault(),(B=P.current)==null||B.focus(),(de=(oe=P.current)==null?void 0:oe.scrollIntoView)==null||de.call(oe,{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:[j&&j.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:Z?Dn(Z):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:ne??"",onChange:V=>K(V.target.value),children:j.map(V=>t.jsx("option",{value:V.key,children:Dn(V)},V.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),t.jsxs("button",{ref:A,type:"button",className:"bim-rd-t","aria-expanded":E,"aria-controls":T,onClick:ee,children:[t.jsx(yc,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":te,onClick:()=>re(te?"closed":"open"),children:[t.jsx(jc,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Sc,{}),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:ke<=yt[0],onClick:()=>x({fontSize:fo(f.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"放大字号",disabled:ke>=yt[yt.length-1],onClick:()=>x({fontSize:fo(f.fontSize,1)}),children:"A+"}),(m||h||v)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),m&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":f.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>x({readingMode:f.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),h&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":f.properNames,title:"书名加波浪线",onClick:()=>x({properNames:!f.properNames}),children:"专名线"}),v&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":f.writingMode==="vertical",onClick:()=>x({writingMode:f.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:T,ref:M,role:le&&E?"dialog":void 0,"aria-modal":le&&E?!0:void 0,"aria-label":le&&E?"目录":void 0,onKeyDown:V=>{if(!(!le||!E)){if(V.key==="Escape"){V.stopPropagation(),J(!0);return}V.key==="Tab"&&vc(V,M.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:c??"目录"}),le&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>J(!0),children:"✕"})]}),l]}),t.jsx(es,{items:i,activeKey:r,onSelect:ge})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>J(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:te&&t.jsx(ts,{pages:p??null,loading:a,renderOverlay:d})}),t.jsx("div",{className:"bim-rd-text",id:R,ref:P,tabIndex:-1,children:t.jsxs("div",{className:"bim-rd-col",children:[S,$&&Z&&(Z.sourceName||Z.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":Z.key,children:[Z.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",Z.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:Z.sourceUrl,target:"_blank",rel:"noreferrer",children:Z.sourceName}):Z.sourceName]}),Z.sourceName&&Z.license&&t.jsx("span",{className:"bim-rd-dot"}),Z.license&&t.jsxs(t.Fragment,{children:["授权 ",Z.license]})]}),b&&(xe||fe)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[t.jsx("span",{children:xe&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>ge(xe.key),children:["‹ ",xe.label]})}),t.jsx("span",{children:fe&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>ge(fe.key),children:[fe.label," ›"]})})]})]})})]})]})}const rs="guji-table-v1";function ss(e){return!!e&&e.table_notation===rs}const wc=/^:::table(?:\{[^}]*\})?[ \t]*$/,_c=/^:::[ \t]*$/;function ls(e){const n=[];let i="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const c=Er(e,r+3);if(c>r+4){i+=e.slice(r,c+1),r=c;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const c=e[r+1];c!==void 0&&!/[A-Za-z/!?>\s]/.test(c)&&(l=">")}if(l){const c=e.indexOf(l,r+1);if(c>0){i+=e.slice(r,c+1),r=c;continue}}s==="|"?(n.push(i),i=""):i+=s}return n.push(i),n.map(r=>r.trim())}const $c=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function zc(e){if(e==="^")return{cont:!0};const n=$c.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 as(e,n=1){const i=[],r=[],s=[];let l=[];e.forEach((p,a)=>{const d=a+n+1;let u=p.trim();if(!u)return;let f=!1;u.startsWith("!")&&(f=!0,u=u.slice(1));const x=ls(u).map(zc),m=l.map(j=>j>0),h=l.map(j=>j>0?j-1:0),v=[];let b=0;for(const j of x){if(j.cont){m[b]||i.push(`第 ${d} 行第 ${b+1} 列:续格 ^ 上方没有跨行格`),b+=1;continue}const{cell:y}=j;for(let k=b;k<b+y.colspan;k++)if(m[k]){i.push(`第 ${d} 行第 ${k+1} 列:此处被上方跨行格占住,应写 ^`);break}if(y.rowspan>1)for(let k=b;k<b+y.colspan;k++)h[k]=y.rowspan-1;v.push(y),b+=y.colspan}for(let j=b;j<m.length;j++)m[j]&&i.push(`第 ${d} 行第 ${j+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let j=0;j<h.length;j++)h[j]===void 0&&(h[j]=0);l=h,r.push({header:f,cells:v}),s.push({width:b,line:d})});const c=s.reduce((p,a)=>Math.max(p,a.width),0);for(const p of s)p.width!==c&&i.push(`第 ${p.line} 行:占 ${p.width} 列,与总列数 ${c} 不符`);return l.some(p=>p>0)&&i.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&i.push("空表"),{rows:r,columns:c,warnings:i}}function mi(e){const n=e.split(`
672
+ `;function ui(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(r=>ui(r,n))):!1}const vc=()=>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 kc({item:e,activeKey:n,onSelect:i,tabKey:r}){const s=ui(e,n),[l,c]=g.useState(s||!!e.defaultExpanded);return g.useEffect(()=>{s&&c(!0)},[s]),g.useEffect(()=>{e.defaultExpanded&&c(!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:()=>c(p=>!p),children:[t.jsx(vc,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(es,{items:e.children,activeKey:n,onSelect:i,tabKey:r})]})}function es({items:e,activeKey:n,onSelect:i,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(kc,{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 xo(e,n){var i;for(const r of e)if(r.key===n||ui(r,n))return r.key;return((i=e[0])==null?void 0:i.key)??null}function ts({items:e,activeKey:n,onSelect:i,label:r="目录"}){const s=g.useRef(null),[l,c]=g.useState(null);g.useEffect(()=>{c(null)},[n]);const p=g.useMemo(()=>l||(n??xo(e,n)),[l,n,e]);g.useEffect(()=>{const d=s.current;if(!d)return;const u=Array.from(d.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const f=u.find(x=>x.dataset.rdTocKey===p)??u.find(x=>x.dataset.rdTocKey===xo(e,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===f?0:-1}),g.useEffect(()=>{const d=s.current,u=d==null?void 0:d.closest(".bim-rd-toc");if(!d||!u||!n)return;const f=Array.from(d.querySelectorAll("[data-rd-toc-key]")).find(m=>m.dataset.rdTocKey===n);if(!f)return;const x=f.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(x<u.scrollTop+80||x>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,x-u.clientHeight/3))},[n]);const a=g.useCallback(d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const f=s.current;if(!f)return;const x=Array.from(f.querySelectorAll("[data-rd-toc-key]")).filter(b=>!b.disabled),m=x.indexOf(document.activeElement);let h=m;if(d.key==="ArrowDown"?h=Math.min(x.length-1,m+1):d.key==="ArrowUp"?h=Math.max(0,m-1):d.key==="Home"?h=0:d.key==="End"&&(h=x.length-1),h<0||h===m)return;d.preventDefault();const k=x[h];for(const b of x)b.tabIndex=-1;k.tabIndex=0,k.focus(),c(k.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:a,children:t.jsx(es,{items:e,activeKey:n,onSelect:i,tabKey:p})})}function Sc({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 ns({pages:e,loading:n,page:i,onPageChange:r,renderOverlay:s}){const[l,c]=g.useState(0),p=i??l,a=x=>{r?r(x):c(x)};if(g.useEffect(()=>{i===void 0&&c(0)},[e,i]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:"加载书影…"})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:"暂无书影"}),t.jsx("span",{children:"这一卷还没有配上影像;接入后在此与正文逐页对看"})]})});const d=Math.max(0,Math.min(e.length-1,p)),u=e[d],f=u.label??`${d+1}`;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${f} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(Sc,{page:u}),s==null?void 0:s(u,d)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:d===0,onClick:()=>a(d-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${d+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:d===e.length-1,onClick:()=>a(d+1),children:"›"})]})]})}const xi={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal"},jt=[15,16,17,18,20,22,24],On=18,is="bim-reader-prefs",wc="bim-reading-mode";function _c(){const e={...xi};try{const n=localStorage.getItem(is),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&jt.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(wc))==="paragraph"&&(e.readingMode="paragraph"),i.properNames===!0&&(e.properNames=!0),i.writingMode==="vertical"&&(e.writingMode="vertical")}catch{}return e}function $c(e){try{localStorage.setItem(is,JSON.stringify(e))}catch{}}function fo(e,n){const i=e??On,r=jt;let s=r.indexOf(i);return s<0&&(s=r.indexOf(On)),r[Math.max(0,Math.min(r.length-1,s+n))]}function fi(){const[e,n]=g.useState(xi);g.useEffect(()=>{n(_c())},[]);const i=g.useCallback(r=>{n(s=>{const l={...s,...r};return $c(l),l})},[]);return[e,i]}function os(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 Dn(e){const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function rs(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 ss(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 zc=()=>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"})}),Cc=()=>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 Ic(e,n){if(!n)return;const i=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(c=>c.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 Tc(e,n){const[i,r]=g.useState(n);return g.useEffect(()=>{var c;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(s.matches);return(c=s.addEventListener)==null||c.call(s,"change",l),()=>{var p;return(p=s.removeEventListener)==null?void 0:p.call(s,"change",l)}},[e]),i}function Rc(){const e=g.useContext($t);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 gi({title:e,subtitle:n,toc:i,activeKey:r,onSelect:s,tocHeader:l,tocCaption:c,images:p,imagesLoading:a,renderImageOverlay:d,imagePanel:u="auto",prefs:f,onPrefsChange:x,paragraphToggle:m,properNameToggle:h=!0,allowVertical:k,pager:b=!0,versions:j,currentVersionKey:y,onVersionChange:v,versionSource:$=!0,children:S,className:_,style:w}){const z=g.useId().replace(/:/g,""),T=`bim-rd-toc-${z}`,R=`bim-rd-text-${z}`,C=g.useRef(null),O=g.useRef(null),M=g.useRef(null),A=g.useRef(null),F=Tc(Zr,!0),[G,U]=g.useState("auto"),E=G==="auto"?F:G==="open",ie=!F,P=!!p&&p.length>0,[re,ce]=g.useState(u);g.useEffect(()=>{ce(u)},[u]);const K=re==="auto"?P||!!a:re==="open",V=g.useCallback(W=>{var B;U("auto"),W&&((B=A.current)==null||B.focus())},[]),q=()=>U(E?"closed":"open");g.useEffect(()=>{if(!ie||G!=="open")return;const W=M.current,B=W==null?void 0:W.querySelector('input, [data-rd-toc-key][tabindex="0"]');B==null||B.focus()},[ie,G]);const xe=g.useCallback(W=>{s(W),ie&&V(!1);const B=O.current,te=C.current;if(B&&te&&typeof window<"u"){const se=B.getBoundingClientRect().top-te.getBoundingClientRect().bottom;se<0&&window.scrollBy({top:se})}},[s,ie,V]),oe=g.useMemo(()=>ss(i),[i]),[ne,D]=g.useState(null),X=rs(j,y!==void 0?y:ne),ee=(X==null?void 0:X.key)??null,N=g.useMemo(()=>oe.map(W=>W.key).join(`
673
+ `),[oe]),I=g.useRef(null),J=W=>{W!==ee&&(I.current={key:W,sig:N,done:!1},y===void 0&&D(W),v==null||v(W))};g.useEffect(()=>{const W=I.current;if(!W||W.key!==ee)return;const B=oe.find(se=>!se.disabled);if(!B)return;const te=N!==W.sig;!te&&W.done||(te?I.current=null:W.done=!0,B.key!==r&&xe(B.key))},[ee,N,oe,r,xe]);const Q=oe.findIndex(W=>W.key===r),pe=Q>0?oe.slice(0,Q).reverse().find(W=>!W.disabled):void 0,ue=Q>=0?oe.slice(Q+1).find(W=>!W.disabled):void 0,ke=f.fontSize??On,_e={...w,...f.fontSize?{"--bimrd-fs":`${f.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",f.writingMode==="vertical"&&k?"bim-rd-vertical":"",_].filter(Boolean).join(" "),"data-toc":G,"data-img":K?"open":"closed",style:_e,children:[t.jsx("style",{children:Qr}),t.jsx("a",{className:"bim-rd-skip",href:`#${R}`,onClick:W=>{var B,te,se;W.preventDefault(),(B=O.current)==null||B.focus(),(se=(te=O.current)==null?void 0:te.scrollIntoView)==null||se.call(te,{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:[j&&j.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:X?Dn(X):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:ee??"",onChange:W=>J(W.target.value),children:j.map(W=>t.jsx("option",{value:W.key,children:Dn(W)},W.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),t.jsxs("button",{ref:A,type:"button",className:"bim-rd-t","aria-expanded":E,"aria-controls":T,onClick:q,children:[t.jsx(zc,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":K,onClick:()=>ce(K?"closed":"open"),children:[t.jsx(Cc,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Rc,{}),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:ke<=jt[0],onClick:()=>x({fontSize:fo(f.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"放大字号",disabled:ke>=jt[jt.length-1],onClick:()=>x({fontSize:fo(f.fontSize,1)}),children:"A+"}),(m||h||k)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),m&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":f.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>x({readingMode:f.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),h&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":f.properNames,title:"书名加波浪线",onClick:()=>x({properNames:!f.properNames}),children:"专名线"}),k&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":f.writingMode==="vertical",onClick:()=>x({writingMode:f.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:T,ref:M,role:ie&&E?"dialog":void 0,"aria-modal":ie&&E?!0:void 0,"aria-label":ie&&E?"目录":void 0,onKeyDown:W=>{if(!(!ie||!E)){if(W.key==="Escape"){W.stopPropagation(),V(!0);return}W.key==="Tab"&&Ic(W,M.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:c??"目录"}),ie&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>V(!0),children:"✕"})]}),l]}),t.jsx(ts,{items:i,activeKey:r,onSelect:xe})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>V(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:K&&t.jsx(ns,{pages:p??null,loading:a,renderOverlay:d})}),t.jsx("div",{className:"bim-rd-text",id:R,ref:O,tabIndex:-1,children:t.jsxs("div",{className:"bim-rd-col",children:[S,$&&X&&(X.sourceName||X.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":X.key,children:[X.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",X.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:X.sourceUrl,target:"_blank",rel:"noreferrer",children:X.sourceName}):X.sourceName]}),X.sourceName&&X.license&&t.jsx("span",{className:"bim-rd-dot"}),X.license&&t.jsxs(t.Fragment,{children:["授权 ",X.license]})]}),b&&(pe||ue)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[t.jsx("span",{children:pe&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>xe(pe.key),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-pglabel",children:pe.label})]})}),t.jsx("span",{children:ue&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>xe(ue.key),children:[t.jsx("span",{className:"bim-rd-pglabel",children:ue.label}),t.jsx("span",{"aria-hidden":"true",children:"›"})]})})]})]})})]})]})}const ls="guji-table-v1";function as(e){return!!e&&e.table_notation===ls}const Ec=/^:::table(?:\{[^}]*\})?[ \t]*$/,Nc=/^:::[ \t]*$/;function cs(e){const n=[];let i="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const c=Nr(e,r+3);if(c>r+4){i+=e.slice(r,c+1),r=c;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const c=e[r+1];c!==void 0&&!/[A-Za-z/!?>\s]/.test(c)&&(l=">")}if(l){const c=e.indexOf(l,r+1);if(c>0){i+=e.slice(r,c+1),r=c;continue}}s==="|"?(n.push(i),i=""):i+=s}return n.push(i),n.map(r=>r.trim())}const Lc=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function Bc(e){if(e==="^")return{cont:!0};const n=Lc.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 ds(e,n=1){const i=[],r=[],s=[];let l=[];e.forEach((p,a)=>{const d=a+n+1;let u=p.trim();if(!u)return;let f=!1;u.startsWith("!")&&(f=!0,u=u.slice(1));const x=cs(u).map(Bc),m=l.map(j=>j>0),h=l.map(j=>j>0?j-1:0),k=[];let b=0;for(const j of x){if(j.cont){m[b]||i.push(`第 ${d} 行第 ${b+1} 列:续格 ^ 上方没有跨行格`),b+=1;continue}const{cell:y}=j;for(let v=b;v<b+y.colspan;v++)if(m[v]){i.push(`第 ${d} 行第 ${v+1} 列:此处被上方跨行格占住,应写 ^`);break}if(y.rowspan>1)for(let v=b;v<b+y.colspan;v++)h[v]=y.rowspan-1;k.push(y),b+=y.colspan}for(let j=b;j<m.length;j++)m[j]&&i.push(`第 ${d} 行第 ${j+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let j=0;j<h.length;j++)h[j]===void 0&&(h[j]=0);l=h,r.push({header:f,cells:k}),s.push({width:b,line:d})});const c=s.reduce((p,a)=>Math.max(p,a.width),0);for(const p of s)p.width!==c&&i.push(`第 ${p.line} 行:占 ${p.width} 列,与总列数 ${c} 不符`);return l.some(p=>p>0)&&i.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&i.push("空表"),{rows:r,columns:c,warnings:i}}function mi(e){const n=e.split(`
660
674
  `),i=[];let r=[];const s=()=>{if(r.length===0)return;const c=r.join(`
661
- `);r=[],i.push({type:"text",text:c})};let l=0;for(;l<n.length;){if(wc.test(n[l].trim())){let c=l+1;for(;c<n.length&&!_c.test(n[c].trim());)c++;if(c<n.length){s();const p=n.slice(l+1,c);i.push({type:"table",table:as(p,l+1),source:n.slice(l,c+1).join(`
662
- `)}),l=c+1;continue}}r.push(n[l]),l++}return s(),i.map((c,p)=>{var d,u;if(c.type!=="text")return c;let a=c.text;return((d=i[p-1])==null?void 0:d.type)==="table"&&(a=a.replace(/^\n+/,"")),((u=i[p+1])==null?void 0:u.type)==="table"&&(a=a.replace(/\n+$/,"")),{type:"text",text:a}}).filter(c=>c.type!=="text"||c.text!=="")}const Cc={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},Ic={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},Tc=`1px solid ${o("table-border")}`,cs={border:Tc,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},Rc={...cs,background:o("table-head-bg"),fontWeight:600};function hi({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:Cc,children:t.jsx("table",{className:"bim-guji-table",style:Ic,children:t.jsx("tbody",{children:e.rows.map((i,r)=>t.jsx("tr",{children:i.cells.map((s,l)=>{const c=i.header?"th":"td";return t.jsx(c,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:i.header?Rc:cs,children:s.empty?null:Fe(s.text,void 0,n)},l)})},r))})})})}function Ec(e,n){return e.indexOf("**")<0?Fe(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:Fe(r.trim().slice(2,-2),void 0,n)},s):t.jsx(g.Fragment,{children:Fe(r,void 0,n)},s))}function Nc(e,n,i=!1){const r=i?{gujiMarkdown:!0}:void 0;return n?mi(e).map((s,l)=>s.type==="table"?t.jsx(hi,{table:s.table,opts:r},l):t.jsx(g.Fragment,{children:Ec(s.text,r)},l)):Fe(e,void 0,r)}const Lc=/^(#{1,6})\s+(.*)$/,Bc=/^\*\*([^*\n]+)\*\*\s*$/;function bi(e){const n=e.match(Lc);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(Bc);return i?{level:3,text:i[1].trim()}:null}const yi=/^<!--.*-->$/;function ds(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function ps(e){return e.split(`
663
- `).map(n=>n.trim()).filter(n=>n&&!yi.test(n))}const Ac=60;function us(e){let n=0,i=0;for(const r of e.split(`
664
- `)){const s=r.trim();if(!s||yi.test(s)||bi(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>Ac&&(i+=l)}return n>0&&i*2>=n}function Wc(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function gn(e){if(e=Wc(e),us(e))return"unknown";const n=ds(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>ps(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 Mc(e){const n=e.split(`
675
+ `);r=[],i.push({type:"text",text:c})};let l=0;for(;l<n.length;){if(Ec.test(n[l].trim())){let c=l+1;for(;c<n.length&&!Nc.test(n[c].trim());)c++;if(c<n.length){s();const p=n.slice(l+1,c);i.push({type:"table",table:ds(p,l+1),source:n.slice(l,c+1).join(`
676
+ `)}),l=c+1;continue}}r.push(n[l]),l++}return s(),i.map((c,p)=>{var d,u;if(c.type!=="text")return c;let a=c.text;return((d=i[p-1])==null?void 0:d.type)==="table"&&(a=a.replace(/^\n+/,"")),((u=i[p+1])==null?void 0:u.type)==="table"&&(a=a.replace(/\n+$/,"")),{type:"text",text:a}}).filter(c=>c.type!=="text"||c.text!=="")}const Ac={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},Wc={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},Mc=`1px solid ${o("table-border")}`,ps={border:Mc,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},Fc={...ps,background:o("table-head-bg"),fontWeight:600};function hi({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:Ac,children:t.jsx("table",{className:"bim-guji-table",style:Wc,children:t.jsx("tbody",{children:e.rows.map((i,r)=>t.jsx("tr",{children:i.cells.map((s,l)=>{const c=i.header?"th":"td";return t.jsx(c,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:i.header?Fc:ps,children:s.empty?null:Fe(s.text,void 0,n)},l)})},r))})})})}function Pc(e,n){return e.indexOf("**")<0?Fe(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:Fe(r.trim().slice(2,-2),void 0,n)},s):t.jsx(g.Fragment,{children:Fe(r,void 0,n)},s))}function Oc(e,n,i=!1){const r=i?{gujiMarkdown:!0}:void 0;return n?mi(e).map((s,l)=>s.type==="table"?t.jsx(hi,{table:s.table,opts:r},l):t.jsx(g.Fragment,{children:Pc(s.text,r)},l)):Fe(e,void 0,r)}const Dc=/^(#{1,6})\s+(.*)$/,Hc=/^\*\*([^*\n]+)\*\*\s*$/;function bi(e){const n=e.match(Dc);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(Hc);return i?{level:3,text:i[1].trim()}:null}const yi=/^<!--.*-->$/;function us(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function xs(e){return e.split(`
677
+ `).map(n=>n.trim()).filter(n=>n&&!yi.test(n))}const Gc=60;function fs(e){let n=0,i=0;for(const r of e.split(`
678
+ `)){const s=r.trim();if(!s||yi.test(s)||bi(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>Gc&&(i+=l)}return n>0&&i*2>=n}function Uc(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function gn(e){if(e=Uc(e),fs(e))return"unknown";const n=us(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>xs(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 Vc(e){const n=e.split(`
665
679
  `),i=[];let r=null,s=[];const l=()=>{i.push({heading:r,body:s.join(`
666
680
  `)}),s=[]};for(const c of n){const p=bi(c);if(p){l(),r={kind:"heading",level:p.level,text:p.text};continue}s.push(c)}return l(),i}function go(e){const n=[];for(const i of e.split(`
667
- `)){const r=bi(i);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=i.trim();!s||yi.test(s)||n.push({kind:"body",text:i})}return n}function xs(e){if(!e)return[];const n=gn(e);if(n==="unknown")return go(e);const i=[];for(const{heading:r,body:s}of Mc(e)){r&&i.push(r);const l=ds(s);if(l.length!==0){if(us(s)){i.push(...go(s));continue}if(n==="record"){const c=l.join(" ");c&&i.push({kind:"body",text:c})}else for(const c of l){const p=ps(c);p.length&&i.push({kind:"body",text:p.join(" ")})}}}return i}const fs=e=>e;function gs(e,n=fs){if(e.indexOf("《")<0)return n(e);const i=[],r=/《([^《》\n]+)》/g;let s=0,l=0,c;for(;c=r.exec(e);)c.index>s&&i.push(t.jsx(g.Fragment,{children:n(e.slice(s,c.index))},l++)),i.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(c[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=c.index+c[0].length;return s===0?n(e):(s<e.length&&i.push(t.jsx(g.Fragment,{children:n(e.slice(s))},l++)),i)}function ji(e,n={}){const i=n.renderText??fs,r=n.properNames?l=>gs(l,i):i,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Fe(e,r,s)}function mo(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(g.Fragment,{children:n(s)},`${i}-${l}`))}const Sn=/^(#{1,6})\s+(.*)$/,Fc=/^\s*<!--.*-->\s*$/;function ms(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
668
- `)?"":n)}function Pc(e){return e<=1?2:e===2?3:4}function Oc(){let e=1;return n=>{const i=Pc(n),r=Math.min(i,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${i}`}}}function mn(e){return e?gn(ms(e))!=="unknown":!1}function ho({text:e,mode:n,inline:i,dropTitle:r}){const s=ms(e),l=(d,u,f)=>!!r&&f<=1&&d<=2&&u.trim()===r.trim(),c=Oc();if(n==="paragraph"&&gn(s)!=="unknown"){const d=xs(s);return t.jsx(t.Fragment,{children:d.map((u,f)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,f))return null;const{Tag:x,className:m}=c(u.level??1);return t.jsx(x,{className:m,children:i(u.text)},f)}return t.jsx("p",{children:mo(u.text,i,f)},f)})})}const p=s.split(`
669
- `);let a=0;return t.jsx(t.Fragment,{children:p.map((d,u)=>{const f=d.match(Sn);if(f){const m=a++;if(l(f[1].length,f[2],m))return null;const{Tag:h,className:v}=c(f[1].length);return t.jsx(h,{className:v,children:i(f[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Sn.test(p[u-1])&&!Sn.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(Fc.test(d))return null;if(a++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:m,className:h}=c(3);return t.jsx(m,{className:h,children:i(d.trim().slice(2,-2))},u)}return t.jsx("p",{children:mo(d,i,u)},u)})})}function Dc(e){const{convert:n}=U();return g.useMemo(()=>e?n(e):"",[e,n])}function vi({text:e,mode:n,tables:i=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:c}){const p=Dc(e),{convert:a}=U(),d=x=>ji(x,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,f=c?a(c):void 0;return!i||p.indexOf(":::")<0?t.jsx(ho,{text:p,mode:n,inline:d,dropTitle:f}):t.jsx(t.Fragment,{children:mi(p).map((x,m)=>x.type==="table"?t.jsx(hi,{table:x.table,opts:u},m):t.jsx(ho,{text:x.text,mode:n,inline:d,dropTitle:m===0?f:void 0},m))})}function hs(e,n){const[i,r]=g.useState(null),[s,l]=g.useState(!1),c=g.useRef(0);return g.useEffect(()=>{const p=++c.current;if(!e||!n){r(null),l(!1);return}let a;try{a=e(n)}catch{r(null),l(!1);return}if(!a||typeof a.then!="function"){r(a??null),l(!1);return}l(!0),a.then(d=>{p===c.current&&r(d??null)}).catch(()=>{p===c.current&&r(null)}).finally(()=>{p===c.current&&l(!1)})},[e,n]),{images:i,loading:s}}const bo={A:"fine",B:"rough",C:"rough",D:"ocr"};function Hc(e){return typeof e!="string"?null:e in Rn?e:e in bo?bo[e]:null}const Gc={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Uc={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function qe(e){return typeof e!="string"?"":Gc[e]??Uc[e]??e}const Vc=["〇","一","二","三","四","五","六","七","八","九"],yo=["","十","百","千"],Yc=["","萬","億"];function ki(e){if(e===0)return"〇";if(e<0)return`負${ki(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(Kc(s,r>0)+Yc[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Kc(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 c=i[l],p=i.length-1-l;c===0?s&&!s.endsWith("〇")&&(s+="〇"):c===1&&p===1&&l===0&&!n?s+=yo[p]:s+=Vc[c]+yo[p]}return s.replace(/〇$/,"")}let Ot=null,en=null;const ln=new Set;function qc(){return Ot?Promise.resolve():en||(en=import("opencc-js/t2cn").then(e=>{Ot=e.Converter({from:"tw",to:"cn"}),ln.forEach(n=>n())}).catch(()=>{Ot=e=>e,ln.forEach(e=>e())}),en)}const Jc=e=>e;function gt(){const[,e]=g.useState(0);return g.useEffect(()=>{if(Ot)return;const n=()=>e(i=>i+1);return ln.add(n),qc(),()=>{ln.delete(n)}},[]),Ot??Jc}function wt(e,n){return n(e).toLowerCase()}const Zc=o("highlight-bg");function Kt(e,n,i){if(!n)return e;const r=wt(n,i);if(!r)return e;const s=wt(e,i);if(s.length!==e.length)return e;const l=[];let c=0,p=0;for(;c<e.length;){const a=s.indexOf(r,c);if(a===-1){l.push(e.slice(c));break}a>c&&l.push(e.slice(c,a)),l.push(t.jsx("mark",{style:{background:Zc,padding:0,color:"inherit"},children:e.slice(a,a+r.length)},p++)),c=a+r.length}return t.jsx(t.Fragment,{children:l})}function Si(e,n,i,r){if(!n)return!0;const s=wt(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(c=>typeof c=="string"&&wt(c,r).includes(s))}function Xc(e,n,i){return n?wt(e,i).includes(wt(n,i)):!0}const wi={类:o("section-lei"),书:o("section-shu"),序:o("section-xu"),结语:o("section-jieyu"),注释:o("section-zhushi")},Qc={考证:o("section-kaozhen")};function ed(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 bs(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((s,l)=>s+bs(l),0))||0;return n+i}function td(e,n){const i=[],r=c=>{var p;i.push(...c.files),(p=c.children)==null||p.forEach(r)};if(r(e),i.length===0)return;const s=i.map(c=>n[c]);if(s.every(c=>c===void 0))return;if(s.some(c=>c==="loading"))return"loading";let l=0;for(const c of s)typeof c=="number"&&(l+=c);return l}const nd={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function _i({enabled:e,expanded:n,onClick:i,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...nd,...r},children:s}):t.jsx("span",{style:r,children:s})}function id({type:e}){const n=qe(e),i=wi[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 od({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=U(),s=Re(),l=gt(),c=v=>v?Fe(r(v),b=>i?Kt(b,i,l):b):"",[p,a]=g.useState(!1),d=!!e.summary,u=!!e.comment,f=!!e.additional_comment,x=!!(e.content&&e.content.length>60),m=d||u||f||x;g.useEffect(()=>{i&&a(!0)},[i]);const h=!p&&x?Gr(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[t.jsxs("div",{onClick:()=>m&&a(!p),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:m?"pointer":"default",userSelect:"none",background:o("input-bg")},children:[t.jsxs(_i,{enabled:m,expanded:p,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",c(e.book_title),"》"]}):c(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[ki(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:c(e.author_info||e.author)})]}),!p&&h&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:c(h)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:c(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:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),p&&m&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${o("widget-border")}`,background:o("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"8px"},children:c(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:c(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:c(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:c(e.additional_comment)})]}),x&&!d&&!u&&!f&&t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(e.content)})]})]})}function rd({section:e,highlightQuery:n=""}){const{convert:i}=U(),r=gt(),s=a=>a?Fe(i(a),d=>n?Kt(d,n,r):d):"",[l,c]=g.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(_i,{enabled:p,expanded:l,onClick:()=>c(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(id,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:s(e.title)}),p&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&p&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${wi[qe(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 sd=100;function $i(e){return qe(e.type)!=="page_header"?!1:(e.content||"").length>=sd}function ld({section:e,highlightQuery:n=""}){const{convert:i}=U(),r=gt();if(qe(e.type)==="page_header"&&!$i(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
670
- `)),l=Fe(s,d=>n?Kt(d,n,r):d),c=qe(e.type),p=wi[c]||o("desc-fg"),a=c==="序"||c==="结语"||c==="注释";return t.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:o("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${p}40`:void 0,background:a?o("bg"):void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:c}),l]})}function ad(e,n,i){const[r,s]=g.useState({});return g.useEffect(()=>{var d;if(!n||e.length===0)return;let l=!1;const c=e.filter(u=>{var f;return!((f=i==null?void 0:i.current)!=null&&f.has(u))}),p={};for(const u of e)(d=i==null?void 0:i.current)!=null&&d.has(u)&&(p[u]=i.current.get(u));if(Object.keys(p).length>0&&s(p),c.length===0)return;const a=async u=>{var f;try{if(n.getEntry){const b=await n.getEntry(u);if(b)return{title:b.title,author:b.author}}const x=await n.getItem(u);if(!x)return null;const m=x.title||u,h=x.authors,v=(f=h==null?void 0:h[0])==null?void 0:f.name;return{title:m,author:v}}catch{return null}};return Promise.all(c.map(async u=>{var x;const f=await a(u);return(x=i==null?void 0:i.current)==null||x.set(u,f),[u,f]})).then(u=>{l||s(f=>{const x={...f};for(const[m,h]of u)x[m]=h;return x})}),()=>{l=!0}},[e.join(","),n]),r}function cd({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=U(),c=Re(),p=gt(),a=y=>y?Fe(l(y),k=>s?Kt(k,s,p):k):"",[d,u]=g.useState(!1);g.useEffect(()=>{s&&u(!0)},[s]);const f=qe(e.type),x=Qc[f]||o("desc-fg"),m=!!e.content,h=e.work_ids||[],v=h.length>1,b=ad(v?h:[],i,r),j=m&&!d&&e.content.length>80?Gr(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${o("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>m&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:m?"pointer":"default",userSelect:"none"},children:[t.jsxs(_i,{enabled:m,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg"),lineHeight:1.6},children:e.header_line?a(e.header_line):a(e.title)}),!d&&j&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:a(j)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[h.length===1&&n&&t.jsx("a",{href:c(h[0]),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(h[0]))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),v&&t.jsxs("span",{style:{fontSize:"11px",color:o("link-fg"),flexShrink:0},children:[h.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:f})]})]}),v&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:h.map(y=>{const k=b[y],$=k?`${l(k.title)}${k.author?`(${l(k.author)})`:""}`:y.slice(0,8)+"…";return t.jsxs("a",{href:c(y),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(y))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",$]},y)})}),d&&m&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:o("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${o("widget-border")}`,fontSize:"12px",color:o("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:a(e.comment)})]})]})}function dd({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=gt(),c=n.trim(),p=g.useMemo(()=>c?e.sections.filter(a=>Si(a,c,!0,l)):e.sections,[e.sections,c,l]);return t.jsxs("div",{children:[t.jsx("div",{children:p.map((a,d)=>t.jsx(cd,{section:a,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:c},d))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function pd(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function ud({sections:e,onNavigate:n,inline:i}){const r=Re(),{convert:s}=U(),l=pd();return t.jsx(t.Fragment,{children:e.map((c,p)=>{const a=qe(c.type);if(a==="page_header"&&!$i(c))return null;if(a==="类")return t.jsxs(g.Fragment,{children:[g.createElement(l("类"),null,i(s(c.title))),c.content&&t.jsx("p",{children:i(s(c.content))})]},p);if(a==="书"||a==="诗"||a==="考证"||a==="注释"){const d=c.book_title?`《${c.book_title}》${c.n_juan!=null?ki(c.n_juan)+"卷":""}`:c.title,u=i(s(d));return t.jsxs("section",{className:"bim-rd-entry",children:[g.createElement(l("条目"),{className:"bim-rd-entry-h"},c.work_id&&n?t.jsx("a",{href:r(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(c.work_id))},title:"查看作品",children:u}):u),c.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(c.author_info))}),c.content&&c.content.split(/\n+/).map((f,x)=>t.jsx("p",{children:i(s(f))},x)),c.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(c.summary))]}),c.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(c.comment))]}),c.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(c.additional_comment))]})]},p)}return c.content?t.jsx("p",{children:i(s(c.content))},p):null})})}function xd(e){return e.some(n=>{const i=qe(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&$i(n)})}function fd({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:c,workLabelCache:p,prefs:a}){var M;const{convert:d}=U(),u=gt(),[f,x]=g.useState("text"),m=s.trim(),h=(r==null?void 0:r.type)==="kaozhen",v=g.useCallback(A=>m?Kt(A,m,u):A,[m,u]),b=A=>ji(A,{renderText:v,properNames:a.properNames}),j=g.useMemo(()=>m?e.sections.filter(A=>Si(A,m,h,u)):e.sections,[e.sections,m,h,u]),y=(A,F)=>F.filter(G=>qe(G.type)===A).length,k=y("书",e.sections),$=y("诗",e.sections),S=y("考证",e.sections);let _="";h?_=m?`${y("考证",j)} / ${S} ${d("條")}`:`${S} ${d("條")}`:$>0?_=m?`${y("诗",j)} / ${$} 首`:`${$} 首`:k>0&&(_=m?`${y("书",j)} / ${k} ${d("部書")}`:`${k} ${d("部書")}`);const w=r!=null&&r.text_quality?Hc(r.text_quality.grade):null,z=[];i&&z.push(i),_&&z.push(_),h&&(r!=null&&r.target_source)&&z.push(t.jsxs(t.Fragment,{children:[d("考證對象")," ",d(r.target_source)]})),w&&z.push(t.jsx("span",{title:ml[w],children:(M=r==null?void 0:r.text_quality)!=null&&M.source_note?t.jsxs(t.Fragment,{children:["底本 ",d(r.text_quality.source_note),"(",d(Rn[w]),")"]}):t.jsxs(t.Fragment,{children:[d("文本質量")," ",d(Rn[w])]})})),e.source_url&&z.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:d("原文來源")}));const T=!h&&xd(e.sections),R=!!n&&(!T||a.readingMode==="paragraph"&&mn(n)),C=!h&&(T||!!n),P=h||!C?"entries":f;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:d(e.title)}),z.length>0&&t.jsx("p",{className:"bim-rd-meta",children:z.map((A,F)=>t.jsxs(g.Fragment,{children:[F>0&&t.jsx("span",{className:"bim-rd-dot"}),A]},F))}),C&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":"看法",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":P==="text",onClick:()=>x("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":P==="entries",onClick:()=>x("entries"),children:d("條目")})]})]}),P==="text"&&t.jsx("article",{className:"bim-rd-prose",children:R?t.jsx(vi,{text:n,mode:a.readingMode,properNames:a.properNames,renderText:v,dropTitle:e.title}):t.jsx(ud,{sections:e.sections,onNavigate:l,inline:b})}),P==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:h?t.jsx(dd,{juan:e,searchQuery:s,onNavigate:l,transport:c,workLabelCache:p}):t.jsxs(t.Fragment,{children:[j.map((A,F)=>{const G=qe(A.type);return G==="书"||G==="诗"||G==="考证"?t.jsx(od,{section:A,onNavigate:l,highlightQuery:m},F):G==="类"?t.jsx(rd,{section:A,highlightQuery:m},F):t.jsx(ld,{section:A,highlightQuery:m},F)}),j.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function ys(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 gd(e){const n=ys(e);return n.length>0?n[0]:null}function md(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:c,query:p,isKaozhen:a}=e,d=gt(),u=g.useRef(new Map),[f,x]=g.useState({}),[m,h]=g.useState({}),v=g.useCallback((j,y)=>{const k=y==null?void 0:y.title;k&&h($=>$[j]===k?$:{...$,[j]:k})},[]);g.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:c}),v(s,l))},[s,l,c,v]),g.useEffect(()=>{u.current.clear(),x({}),h({})},[n]);const b=g.useCallback((j,y)=>{let k=0;if(j.juan)for(const $ of j.juan.sections)Si($,y,a,d)&&k++;return k===0&&j.rawText&&Xc(j.rawText,y,d)&&(k=1),k},[a,d]);return g.useEffect(()=>{const j=p.trim();if(!j){x({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let y=!1;const k={},$=[];for(const T of r){const R=u.current.get(T);R?k[T]=b(R,j):(k[T]="loading",$.push(T))}x(k);const S=8;let _=0;const w=async()=>{var T;for(;_<$.length;){if(y)return;const R=_++,C=$[R];try{const[P,M]=await Promise.all([i.getCollatedJuan(n,C),((T=i.getCollatedJuanText)==null?void 0:T.call(i,n,C))??Promise.resolve(null)]),A={juan:P,rawText:M};if(u.current.set(C,A),v(C,P),y)return;x(F=>({...F,[C]:b(A,j)}))}catch{if(y)return;x(P=>({...P,[C]:0}))}}},z=Array.from({length:Math.min(S,$.length)},()=>w());return Promise.all(z),()=>{y=!0}},[p,n,i,r.join(","),b,d,v]),{matchStates:f,titles:m}}const zi=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:c,style:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m})=>{const[h,v]=g.useState(null),[b,j]=g.useState(!1),[y,k]=g.useState(null),[$,S]=g.useState(null),[_,w]=g.useState(null),[z,T]=g.useState(!1),[R,C]=g.useState(null),[P,M]=g.useState(""),A=g.useRef(new Map),F=g.useRef(0),G=s??$,D=g.useCallback(J=>{S(J),l==null||l(J)},[l]),E=e||h;g.useEffect(()=>{e&&(j(!1),k(null))},[e]),g.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let J=!1;return j(!0),k(null),i.getCollatedEditionIndex(n).then(ee=>{J||(ee?v(ee):k("未找到整理本数据"))}).catch(ee=>{J||k(ee instanceof Error?ee.message:"加载失败")}).finally(()=>{J||j(!1)}),()=>{J=!0}},[e,n,i]),g.useEffect(()=>{if(E&&!G){const J=gd(E);J&&D(J)}},[E,G,D]);const le=n||(E==null?void 0:E.work_id),W=g.useCallback(async J=>{var ge;if(!le||!(i!=null&&i.getCollatedJuan))return;const ee=++F.current;T(!0),w(null),C(null);try{const[se,ie]=await Promise.all([i.getCollatedJuan(le,J),((ge=i.getCollatedJuanText)==null?void 0:ge.call(i,le,J))??Promise.resolve(null)]);if(ee!==F.current)return;w(se),C(ie)}catch{if(ee!==F.current)return;w(null),C(null)}finally{ee===F.current&&T(!1)}},[le,i]);g.useEffect(()=>{G&&W(G)},[G,W]);const Y=J=>{D(J)};if(b)return t.jsx("div",{className:c,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(y)return t.jsx("div",{className:c,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:y});if(!E)return null;const re=E.type==="kaozhen",te=ys(E);return t.jsx(bd,{className:c,style:p,index:E,allFiles:te,isKaozhen:re,effectiveWorkId:le,transport:i,activeFile:G,handleSelectFile:Y,juanData:_,juanRawText:R,juanLoading:z,searchQuery:P,setSearchQuery:M,onNavigate:r,workLabelCacheRef:A,reader:{title:a,subtitle:d,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m}})};function js(e,n,i,r){var d,u,f,x;const s=(u=(d=n.juan_metadata)==null?void 0:d[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:ed(e)),p=((x=(f=n.files)==null?void 0:f.find(m=>m.filename===e))==null?void 0:x.title)??i[e];if(!p)return{position:l,label:l};const a=r(p);return{position:l,label:l===p||l===a?a:`${l} ${a}`}}function hd(e,n,i,r,s){const l=a=>a==="loading"?"…":typeof a=="number"&&a>0?a:void 0,c=(a,d)=>({key:a,label:d??js(a,e,r,s).label,hint:l(i[a]),disabled:i[a]===0}),p=(a,d)=>{var f;if(a.files.length===1&&!((f=a.children)!=null&&f.length))return c(a.files[0],s(a.label));const u=td(a,i);return{key:`group:${d}`,label:s(a.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:bs(a),defaultExpanded:typeof u=="number"&&u>0,children:[...a.files.map(x=>c(x)),...(a.children??[]).map((x,m)=>p(x,`${d}.${m}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((a,d)=>p(a,`${d}`)):n.map(a=>c(a))}const bd=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:c,activeFile:p,handleSelectFile:a,juanData:d,juanRawText:u,juanLoading:f,searchQuery:x,setSearchQuery:m,onNavigate:h,workLabelCacheRef:v,reader:b})=>{const{convert:j}=U(),[y,k]=fi(),{matchStates:$,titles:S}=md({workId:l,transport:c,files:r,activeFile:p,activeJuan:d,activeRawText:u,query:x,isKaozhen:s}),_=hs(b.resolveImages,p),w=g.useMemo(()=>hd(i,r,$,S,j),[i,r,$,S,j]),z=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:C=>m(C.target.value)}),T=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(C=>C.vol_label)?"冊":"卷",R=p?js(p,i,S,j).position:void 0;return t.jsxs(gi,{className:e,style:n,title:b.title??(i.title?j(i.title):void 0),subtitle:b.subtitle??j(s?"考證":"整理本"),toc:w,tocCaption:`目录 · ${r.length} ${j(T)}`,tocHeader:z,activeKey:p,onSelect:a,images:_.images,imagesLoading:_.loading,renderImageOverlay:b.renderImageOverlay,imagePanel:b.imagePanel,prefs:y,onPrefsChange:k,paragraphToggle:!s&&mn(u),allowVertical:b.allowVertical,children:[f?t.jsx(ft,{}):d?t.jsx(fd,{juan:d,rawText:u,positionLabel:R,index:i,searchQuery:x,onNavigate:h,transport:c,workLabelCache:v,prefs:y},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,i.references&&i.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:j("參考文獻")}),t.jsx("ol",{children:i.references.map((C,P)=>t.jsxs("li",{children:[C.url?t.jsx("a",{className:"bim-rd-link",href:C.url,target:"_blank",rel:"noopener noreferrer",children:C.title}):t.jsx("span",{children:C.title}),C.author&&t.jsxs("span",{children:[",",C.author]}),C.note&&t.jsxs("span",{children:["。",C.note]})]},P))})]})]})},yd={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},jd={label:"其他",color:o("desc-fg")},vd={pending:{label:"待处理",color:o("warning")},in_progress:{label:"处理中",color:o("primary")},resolved:{label:"已处理",color:o("success")},wontfix:{label:"不采纳",color:o("desc-fg")},duplicate:{label:"重复",color:o("desc-fg")}},kd={label:"待处理",color:o("warning")};function Sd(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 wd(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 Ci=({items:e,loading:n})=>{const i=Re();return n?t.jsx(ft,{}):e.length===0?t.jsx("div",{style:_d,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=yd[r.type]||jd,l=vd[r.status]||kd,c=typeof window<"u"&&wd(r.pageUrl,window.location.href);return t.jsxs("div",{style:$d,children:[t.jsxs("div",{style:zd,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...jo,background:s.color},children:s.label}),t.jsx("span",{style:{...jo,background:l.color},children:l.label})]}),t.jsx("span",{style:Cd,children:Sd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:Id,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:wn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(c?t.jsx("a",{href:r.pageUrl,style:wn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:wn,children:r.pageUrl}))]}),t.jsx("div",{style:Td,children:r.content}),r.reply&&t.jsxs("div",{style:Rd,children:[t.jsx("div",{style:Ed,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},_d={textAlign:"center",padding:"40px 0",color:o("desc-fg"),fontSize:"14px"},$d={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"16px"},zd={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},jo={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Cd={fontSize:"12px",color:o("desc-fg")},Id={fontSize:"12px",marginBottom:"6px"},wn={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},Td={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},Rd={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},Ed={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},Hn=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const c=ce(),[p,a]=g.useState(null),[d,u]=g.useState([]),[f,x]=g.useState("recommend"),[m,h]=g.useState([]),[v,b]=g.useState(!1),j=r??f,y=F=>{x(F),s==null||s(F)},[k,$]=g.useState(!0),[S,_]=g.useState(null),[w,z]=g.useState(null),[T,R]=g.useState(null);g.useEffect(()=>{let F=!1;if(e.getCounts)return e.getCounts().then(G=>{F||a({works:G.works,books:G.books,collections:G.collections})}).catch(()=>{}),()=>{F=!0}},[e]),g.useEffect(()=>{let F=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const D=await e.getRecommended();if(D!=null&&D.groups)return D.groups.flatMap(E=>E.items.map(le=>({...le,group:E.name})))}catch{}return[]})().then(async D=>{if(F)return;const E=D.filter(W=>W.id);if(E.length===0){$(!1);return}const le=await Promise.all(E.map(async W=>{if(W.type)return{id:W.id,title:W.title,type:W.type,author:W.author,dynasty:W.dynasty,role:W.role,edition:W.edition,has_text:W.has_text,has_image:W.has_image,has_collated:W.has_collated,subtype:W.subtype,primary_name:W.primary_name,group:W.group,fallbackDescription:W.description};try{let Y=null;if(e.getEntry)Y=await e.getEntry(W.id);else{const re=await e.getItem(W.id);re&&(Y={id:W.id,title:re.title||W.id,type:re.type||"work"})}if(Y)return{...Y,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:be.extractType(W.id),group:W.group,fallbackDescription:W.description}}));F||(u(le.filter(W=>W!==null)),$(!1))}),()=>{F=!0}},[e,i]);const C=g.useRef(!1),P=g.useRef(!1),M=g.useRef(!1);g.useEffect(()=>{if(j!=="catalog"||C.current)return;const F=e.getCatalogProgress??e.getResourceProgress;if(!F)return;C.current=!0;let G=!1;return F.call(e).then(D=>{G||_(D)}).catch(()=>{C.current=!1}),()=>{G=!0}},[e,j]),g.useEffect(()=>{if(j!=="collection"||P.current||!e.getCollectionProgress)return;P.current=!0;let F=!1;return e.getCollectionProgress().then(G=>{F||z(G)}).catch(()=>{P.current=!1}),()=>{F=!0}},[e,j]),g.useEffect(()=>{if(j!=="site"||M.current||!e.getSiteProgress)return;M.current=!0;let F=!1;return e.getSiteProgress().then(G=>{F||R(G)}).catch(()=>{M.current=!1}),()=>{F=!0}},[e,j]),g.useEffect(()=>{if(!l||j!=="feedback")return;let F=!1;return b(!0),fetch(l).then(G=>G.json()).then(G=>{!F&&G.success&&h(G.items||[])}).catch(()=>{}).finally(()=>{F||b(!1)}),()=>{F=!0}},[l,j]);const A=F=>{switch(F){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(Lt,{label:c.home.recommendTab,active:j==="recommend",onClick:()=>y("recommend")}),t.jsx(Lt,{label:c.home.catalogTab,active:j==="catalog",onClick:()=>y("catalog")}),t.jsx(Lt,{label:c.home.collectionTab,active:j==="collection",onClick:()=>y("collection")}),t.jsx(Lt,{label:c.home.siteTab,active:j==="site",onClick:()=>y("site")}),l&&t.jsx(Lt,{label:c.home.feedbackTab,active:j==="feedback",onClick:()=>y("feedback")})]}),j==="recommend"&&t.jsx(Nd,{recommended:d,loading:k,onNavigate:n,getIcon:A,t:c}),j==="catalog"&&t.jsx(vo,{progress:S,t:c,onNavigate:n}),j==="collection"&&t.jsx(vo,{progress:w,t:c,onNavigate:n}),j==="site"&&t.jsx(Bd,{progress:T,t:c,totalWorks:(p==null?void 0:p.works)??0}),j==="feedback"&&l&&t.jsx(Ci,{items:m,loading:v})]})})},Lt=({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}),Nd=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=Re();if(n)return t.jsx(ft,{});if(e.length===0)return null;const c=new Map;for(const p of e){const a=p.group||s.home.recommendedBrowse;c.has(a)||c.set(a,[]),c.get(a).push(p)}return t.jsx(t.Fragment,{children:Array.from(c.entries()).map(([p,a])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:p}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return t.jsxs("a",{href:l(d.id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),i==null||i(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,cursor:"pointer",background:o("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},vo=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(ft,{});const r=[...e.resources].sort((p,a)=>p.priority-a.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},c={in_progress:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(p=>{const a=r.filter(d=>d.status===p);return a.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:c[p]}}),l[p]," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>t.jsx(Ld,{item:d,t:n,statusColor:c[p],onNavigate:i},d.id))})]},p)})})},Ld=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=Re(),l=e.total>0?Math.round(e.imported/e.total*100):0,c=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=e.edition?`${e.name}·${e.edition}`:e.name,a=e.collection_id||e.work_id;return a&&r?t.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:p}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:o("widget-border"),color:o("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:c})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Ht(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})]})},Bd=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(ft,{});const r=[...e.resources].sort((a,d)=>a.priority-d.priority),s=r.filter(a=>a.imported>0),l=r.filter(a=>a.imported===0),c=s.reduce((a,d)=>Math.max(a,d.imported),0),p=i>0?Math.round(c/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:c.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>t.jsx(ko,{item:a,t:n,totalWorks:i},a.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(a=>t.jsx(ko,{item:a,t:n,totalWorks:i},a.id))})]})]})},ko=({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})]})},So="(max-width: 768px)";function Ad(){const[e,n]=g.useState(()=>typeof window>"u"?!1:window.matchMedia(So).matches);return g.useEffect(()=>{const i=window.matchMedia(So),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),e}const Wd=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var G;const l=ce(),{convert:c}=U(),p=Ad(),[a,d]=g.useState(null),[u,f]=g.useState(null),[x,m]=g.useState(!1),[h,v]=g.useState("detail"),[b,j]=g.useState([]),[y,k]=g.useState(!1),[$,S]=g.useState(null),[_,w]=g.useState(!1),z=g.useCallback(async D=>{if(!e.getCollatedEditionIndex){S(null);return}w(!0);try{const E=await e.getCollatedEditionIndex(D);S(E)}catch{S(null)}finally{w(!1)}},[e]),T=g.useCallback(async D=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){j([]);return}k(!0);try{if(e.getCollectionCatalogs){const E=await e.getCollectionCatalogs(D);j(E||[])}else if(e.getCollectionCatalog){const E=await e.getCollectionCatalog(D);j(E?[{resource_id:"",data:E}]:[])}}catch{j([])}finally{k(!1)}},[e]),R=g.useCallback(async D=>{if(i){i(D);return}d(D),f(null),j([]),S(null),v("detail"),m(!0);try{const E=await e.getItem(D.id);E&&(f(E),E.type==="collection"?T(D.id):E.type==="work"&&E.has_collated&&z(D.id))}catch(E){console.error("加载详情失败:",E)}finally{m(!1)}},[e,i,T,z]),C=g.useCallback(async D=>{f(null),j([]),S(null),v("detail"),m(!0);try{const E=await e.getItem(D);E&&(f(E),d({id:D,title:E.title||D,type:E.type||"book"}),E.type==="collection"?T(D):E.type==="work"&&E.has_collated&&z(D))}catch(E){console.error("导航失败:",E)}finally{m(!1)}},[e,T,z]),P=(u==null?void 0:u.type)==="collection"&&(b.length>0||y)||(u==null?void 0:u.type)==="work"&&($||_),M=p&&(x||u),A=g.useCallback(()=>{d(null),f(null),j([]),S(null),v("detail")},[]),F=t.jsx(t.Fragment,{children:x?t.jsx(ft,{}):u?t.jsxs(t.Fragment,{children:[(P||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${o("widget-border")}`,padding:p?"0 12px":"0 48px",background:o("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[P&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>v("detail"),style:tn(h==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&y&&b.length===0&&t.jsxs("button",{onClick:()=>{},style:tn(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&b.map(D=>t.jsx("button",{onClick:()=>v(`catalog:${D.resource_id}`),style:tn(h===`catalog:${D.resource_id}`),children:D.short_name?`${c(D.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},D.resource_id)),u.type==="work"&&($||_)&&t.jsxs("button",{onClick:()=>v("collated"),style:tn(h==="collated"),children:[l.detailTab.collatedEdition,_&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:h==="detail"?t.jsx(ti,{data:u,transport:e,onNavigate:C}):h.startsWith("catalog:")?t.jsx(ni,{data:(G=b.find(D=>`catalog:${D.resource_id}`===h))==null?void 0:G.data,onNavigate:C}):h==="collated"?t.jsx(zi,{index:$||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(Hn,{transport:e,onNavigate:C,recommendedIds:r})});return p?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:M?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${o("widget-border")}`,background:o("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:A,style:{padding:"4px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:F})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Nn,{transport:e,onEntryClick:R,hideModeIndicator:n}),!u&&t.jsx(Hn,{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(Nn,{transport:e,onEntryClick:R,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:F})]})};function tn(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 rt(e){return e.replace(/\.md$/,"")}function Md(e){let n="";if(e.source_url)try{const r=new URL(e.source_url).pathname.split("/").filter(Boolean).pop()??"";n=decodeURIComponent(r).replace(/_/g," ")}catch{}return[e.source_name,n||e.version_label].filter(Boolean).join(" · ")||e.key}const wo={padding:24,color:o("desc-fg")},Gn=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:c,onVersionChange:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m,className:h,style:v})=>{const[b,j]=g.useState(e??null),[y,k]=g.useState(!1),[$,S]=g.useState(null),_=r!==void 0?r:$,w=g.useCallback(Y=>{s?s(Y):S(Y)},[s]),[z,T]=g.useState(null),[R,C]=g.useState(!1);g.useEffect(()=>{e&&j(e)},[e]),g.useEffect(()=>{if(e)return;j(null),k(!1);const Y=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!Y){k(!0);return}let re=!1;return Promise.resolve().then(Y).then(te=>{re||(te?j(te):k(!0))}).catch(()=>{re||k(!0)}),()=>{re=!0}},[n,i,e,l]),g.useEffect(()=>{if(!b||b.chapters.length===0)return;const Y=rt(b.chapters[0].file);if(!_){w(Y);return}const re=rt(_);b.chapters.some(J=>rt(J.file)===re)||w(Y)},[b,_,w]);const P=g.useMemo(()=>{if(!b||!_)return null;const Y=rt(_);return b.chapters.find(re=>rt(re.file)===Y)??null},[b,_]);g.useEffect(()=>{if(!n||!P)return;const Y=l!==void 0?i.getWorkFullTextChapter?te=>i.getWorkFullTextChapter(n,l,te):null:i.getBookFullTextChapter?te=>i.getBookFullTextChapter(n,te):null;if(!Y)return;let re=!1;return C(!0),T(null),Promise.resolve(P.file).then(Y).then(te=>{re||T(te)}).catch(()=>{re||T(null)}).finally(()=>{re||C(!1)}),()=>{re=!0}},[n,P,i,l]);const M=hs(u,P?rt(P.file):null),[A,F]=fi(),{convert:G}=U(),D=c&&c.length>1&&p?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:Y=>p(Y.target.value),children:c.map(Y=>t.jsx("option",{value:Y.key,children:Md(Y)},Y.key))})]}):null;if(!b)return t.jsxs("div",{style:wo,children:[D&&t.jsx("div",{style:{marginBottom:12},children:D}),y?"无法加载全文目录":"加载全文目录…"]});if(b.chapters.length===0)return t.jsxs("div",{style:wo,children:[D&&t.jsx("div",{style:{marginBottom:12},children:D}),"全文目录为空"]});const E=b.chapters.map(Y=>({key:rt(Y.file),label:G(Y.title)})),le=ss(b)||An(b),W=z?z.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(gi,{title:a??G(b.version_label),subtitle:d??"全文",toc:E,tocCaption:`目录 · ${b.chapters.length} ${b.chapters.length>1?"卷":"篇"}`,activeKey:_?rt(_):null,onSelect:w,images:M.images,imagesLoading:M.loading,renderImageOverlay:f,imagePanel:x,prefs:A,onPrefsChange:F,paragraphToggle:mn(W),allowVertical:m,className:h,style:v,children:[P&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:G(P.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:b.source.url,target:"_blank",rel:"noreferrer",children:G(b.source.name)}),b.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),b.source.license]}),D&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),D]})]})]}),R&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!R&&W!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(vi,{text:W,mode:A.readingMode,tables:le,gujiMarkdown:An(b),properNames:A.properNames})}),!R&&!z&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},Fd=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=ce(),{convert:l}=U(),[c,p]=g.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[a,d]=g.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(f=>t.jsx(Pd,{division:f,expanded:c===f.name,onToggle:()=>p(c===f.name?null:f.name),expandedCat:a,onCatToggle:x=>d(a===x?null:x),onNavigate:n},f.name))})]})},Pd=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:c}=U(),p=e.categories.reduce((a,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return a+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${o("primary")} 6%, transparent)`:o("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:o("fg"),textAlign:"left"},children:[t.jsx("span",{children:c(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg")},children:[e.categories.length," 類 · ",p," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(a=>{const d=`${e.name}/${a.name}`;return t.jsx(Od,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:l},a.name)})})]})},Od=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var a,d,u,f;const{convert:s}=U(),l=((a=e.books)==null?void 0:a.zhulu)||[],c=((d=e.books)==null?void 0:d.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((f=e.stats)==null?void 0:f.cunmu)||c.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?o("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:o("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||c.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(_o,{label:"著錄",books:l,onNavigate:r}),c.length>0&&t.jsx(_o,{label:"存目",books:c,onNavigate:r})]})]})},_o=({label:e,books:n,onNavigate:i})=>{const{convert:r}=U(),s=Re(),[l,c]=g.useState(n.length<=20),p=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((a,d)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:o("fg")},children:a.work_id&&i?t.jsx("a",{href:s(a.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},children:r(a.title)}):r(a.title)}),a.volumes&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.volumes)}),a.author&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.author).slice(0,20)})]},d))}),!l&&t.jsxs("button",{onClick:()=>c(!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," 條"]})]})},Oe=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=ce();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:o("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&t.jsx("button",{onClick:i,style:Hd,children:"AI"}),n&&t.jsx("button",{onClick:n,style:Dd,children:l.action.save})]})]}),s]})},Dd={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Hd={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Me=({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"}})]}),ut=({value:e,onChange:n,placeholder:i})=>{const r=g.useRef(null);return g.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"}})},an=({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 Gd(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const nn=({value:e,onChange:n,label:i})=>{const[r,s]=g.useState(!1),l=g.useRef(null),c=Gd(e||"");return g.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&c?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:$o,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:c.name}),t.jsx(an,{children:c.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:$o,children:i}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},$o={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function Ud(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function Vd(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const vs=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=ce(),[s,l]=g.useState(null),c=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},p=f=>{n(e.filter((x,m)=>m!==f)),s===f&&l(null)},a=(f,x,m)=>{const h=[...e];h[f]={...h[f],[x]:m},n(h)},d=(f,x)=>{const m=[...e];m[f]={...m[f],type:x,id:"",name:""},n(m),x==="bookID"&&i&&i(h=>{const v=[...e];v[f]={...v[f],id:h.id,name:h.title,type:"bookID"},n(v)})},u=f=>{i&&i(x=>{const m=[...e];m[f]={...m[f],id:x.id,name:x.title,type:"bookID"},n(m)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((f,x)=>t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===x?null:x),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===x?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:o("fg")},children:f.name||`${r.editor.sourcePlaceholder} ${x+1}`}),f.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Ud(f.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:Vd(f.type)}),t.jsx("button",{onClick:m=>{m.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===x&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!f.type&&t.jsxs("div",{children:[t.jsx("label",{style:Xe,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>d(x,"bookID"),style:{...zo,borderColor:o("source-bookid"),color:o("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>d(x,"url"),style:{...zo,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})]})]})]}),f.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:Xe,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Co,children:r.action.changeType})]}),f.id&&f.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:f.name}),t.jsx("code",{style:{fontSize:"11px",background:o("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:f.id})]}),t.jsx("button",{onClick:()=>u(x),style:{background:"transparent",border:`1px solid ${o("widget-border")}`,color:o("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(x),style:{width:"100%",padding:"14px",border:`2px dashed ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),f.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:Xe,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Co,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:f.name,onChange:m=>a(x,"name",m.target.value),placeholder:r.editor.sourceNamePlaceholder,style:mt})]}),t.jsxs("div",{children:[t.jsx("label",{style:Xe,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:f.id,onChange:m=>a(x,"id",m.target.value),placeholder:"https://...",style:mt})]})]}),f.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:{...Xe,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:Xe,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:f.details,onChange:m=>a(x,"details",m.target.value),placeholder:r.editor.detailsPlaceholder,style:mt})]}),t.jsxs("div",{children:[t.jsx("label",{style:Xe,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:f.position,onChange:m=>a(x,"position",m.target.value),placeholder:"如: 卷三, p.52",style:mt})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:Xe,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:f.version,onChange:m=>a(x,"version",m.target.value),placeholder:"如: v1.0, 2024-01",style:mt})]}),t.jsxs("div",{children:[t.jsx("label",{style:Xe,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:f.processor_version,onChange:m=>a(x,"processor_version",m.target.value),placeholder:"如: v0.1",style:mt})]})]})]})]})})]},x)),t.jsxs("button",{onClick:c,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})]})]})},Xe={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},mt={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"},zo={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"},Co={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function ks(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 Ss(e){return!e||e.length===0?"":JSON.stringify(e)}const ws=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:c,childWorks:p,childCollections:a,containedBooks:d,siblingBooks:u,onLinkEntity:f,onUnlinkEntity:x,onViewEntity:m,onCreateAndLink:h,onSaveRelations:v})=>{const b=ce();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:b.section.relations})]}),v&&t.jsx("button",{onClick:v,style:Yd,children:b.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Bt,{direction:"up",title:b.relation.belongsToWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>f("workId","work"),onCreate:()=>h("workId","work",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),t.jsx(Bt,{direction:"up",title:b.relation.containedInCollection,entity:c,onView:m,onUnlink:()=>x("collectionId"),onLink:()=>f("collectionId","collection"),onCreate:()=>h("collectionId","collection",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),l&&u&&u.length>0&&t.jsx(ht,{direction:"horizontal",title:`${b.relation.siblingVersions} (${u.length})`,entities:u,onView:m,onAdd:()=>h("siblingBook","book",{workId:l.id}),addLabel:b.relation.addVersionForWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Bt,{direction:"up",title:b.relation.parentWork,entity:r,onView:m,onUnlink:()=>x("parentWorkId"),onLink:()=>f("parentWorkId","work"),onCreate:()=>h("parentWorkId","work"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),p&&p.length>0&&t.jsx(ht,{direction:"down",title:`${b.relation.childWorks} (${p.length})`,entities:p,onView:m,onAdd:()=>h("childWork","work",{parentWorkId:n}),addLabel:b.action.addSubWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),a&&a.length>0&&t.jsx(ht,{direction:"down",title:`${b.relation.collectionImpl} (${a.length})`,entities:a,onView:m,onAdd:()=>h("childCollection","collection",{workId:n}),addLabel:b.action.addCollectionImpl,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),t.jsx(ht,{direction:"down",title:`${b.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>h("childBook","book",{workId:n}),addLabel:b.action.addVersion,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Bt,{direction:"up",title:b.relation.correspondingWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>f("workId","work"),onCreate:()=>h("workId","work",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),t.jsx(Bt,{direction:"up",title:b.relation.parentCollection,entity:s,onView:m,onUnlink:()=>x("parentCollectionId"),onLink:()=>f("parentCollectionId","collection"),onCreate:()=>h("parentCollectionId","collection"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),t.jsx(ht,{direction:"down",title:`${b.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:m,onAdd:()=>h("childCollection","collection",{parentCollectionId:n}),addLabel:b.action.addSubCollection,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),t.jsx(ht,{direction:"down",title:`${b.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>h("childBook","book",{collectionId:n}),addLabel:b.action.addBook,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]})]})]})},Bt=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:c,linkLabel:p,createLabel:a,notLinkedLabel:d,viewLabel:u,unlinkLabel:f})=>{const x=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:o("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:_s(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(Io,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(Io,{onClick:s,title:f,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(Un,{onClick:l,children:p}),t.jsx(Un,{onClick:c,primary:!0,children:a})]})]})},ht=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:c,expandMoreLabel:p})=>{const[a,d]=g.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),f=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=a?i:i.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:f}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[x.map(m=>t.jsxs("div",{onClick:()=>r(m),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:o("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:_s(m.type)}),t.jsx("span",{children:m.title})]},m.id)),i.length>5&&!a&&t.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:o("link-fg"),cursor:"pointer"},children:[p," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:c}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(Un,{onClick:s,primary:!0,children:["+ ",l]})})]})},Io=({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}),Un=({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 _s(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Yd={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},$s=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:c,onSearch:p,isLoading:a,excludeId:d})=>{const[u,f]=g.useState(""),x=d?c.filter(b=>b.id!==d):c;g.useEffect(()=>{e&&(f(""),p(""))},[e]);const m=b=>{f(b),p(b)};if(!e)return null;const h=n==="work"?"作品":n==="book"?"书籍":"丛编",v=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:Kd,children:t.jsxs("div",{style:qd,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:Jd,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:b=>m(b.target.value),placeholder:`搜索${h}名称或 ID...`,autoFocus:!0,style:Zd})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?t.jsx("div",{style:_n,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(b=>t.jsxs("div",{onClick:()=>r(b),style:Xd,children:[t.jsx("span",{style:{fontSize:"16px"},children:v}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[b.title,b.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:b.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[b.id,b.author&&` · ${b.author}`,b.dynasty&&` · ${b.dynasty}`]})]})]},b.id))}):u?t.jsxs("div",{style:_n,children:["未找到匹配的",h]}):t.jsxs("div",{style:_n,children:["输入关键词搜索",h]})}),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:Qd,children:["创建新",h,"并关联"]})]})]})})},Kd={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},qd={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")},Jd={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Zd={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"},Xd={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:o("primary-soft")},_n={padding:"20px",textAlign:"center",color:o("desc-fg")},Qd={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},To={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},ep={work:"📜",book:"📖",collection:"📚",entity:"👤"},zs=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[c,p]=g.useState(""),a=g.useRef(null);g.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,m;(x=a.current)==null||x.focus(),(m=a.current)==null||m.select()},100))},[e,r==null?void 0:r.title]);const d=x=>{x.key==="Enter"&&c.trim()?u():x.key==="Escape"&&l()},u=()=>{c.trim()&&s(c.trim(),{...r,title:c.trim()})};if(!e)return null;const f=()=>{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`创建新${To[n]}`}};return t.jsx("div",{style:tp,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:np,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:ep[n]}),t.jsx("span",{children:f()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:o("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:o("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:a,type:"text",value:c,onChange:x=>p(x.target.value),onKeyDown:d,placeholder:`请输入${To[n]}名称...`,style:ip})]}),((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:op,children:"取消"}),t.jsx("button",{onClick:u,disabled:!c.trim(),style:{...rp,opacity:c.trim()?1:.6,cursor:c.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},tp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},np={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")},ip={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"},op={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},rp={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function sp(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Cs(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function lp(e){switch(e){case"work":return o("editor-type-work");case"collection":return o("editor-type-collection");case"book":return o("editor-type-book");default:return o("desc-fg")}}const Is=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:c,onSelect:p,onCancel:a,onCreate:d,onSearch:u})=>{const[f,x]=g.useState(""),[m,h]=g.useState([]),[v,b]=g.useState(!1),[j,y]=g.useState("recent");g.useEffect(()=>{e&&(x(""),h([]),y(r.length>0?"recent":"search"))},[e,r.length]),g.useEffect(()=>{if(!f.trim()){h([]);return}const z=setTimeout(async()=>{b(!0);try{h(await u(f,i))}catch{h([])}finally{b(!1)}},300);return()=>clearTimeout(z)},[f,i,u]);const k=g.useCallback(z=>{x(z.target.value),z.target.value.trim()&&y("search")},[]),$=g.useCallback(z=>s?z.filter(T=>T.id!==s):z,[s]);if(!e)return null;const S=n||(i==="all"?"选择实体":`选择${Cs(i)}`),_=$(r),w=$(m);return t.jsx("div",{style:cp,children:t.jsxs("div",{style:dp,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:a,style:pp,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:f,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:up}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),v&&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(Ro,{active:j==="recent",onClick:()=>y("recent"),children:["最近使用 (",_.length,")"]}),t.jsxs(Ro,{active:j==="search",onClick:()=>y("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&_.length>0?t.jsx(Eo,{entities:_,onSelect:p}):f.trim()?v?t.jsx($n,{message:"搜索中..."}):w.length>0?t.jsx(Eo,{entities:w,onSelect:p}):t.jsx($n,{message:"未找到匹配的结果"}):t.jsx($n,{message:"输入关键词开始搜索"})}),l&&d&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:d,style:xp,children:c||"创建新实体"})]})]})})},Ro=({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}),Eo=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(ap,{entity:i,onClick:()=>n(i)},i.id))}),ap=({entity:e,onClick:n})=>{const[i,r]=g.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:sp(e.type)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:e.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[t.jsx("code",{style:{fontSize:"10px",background:o("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&t.jsx("span",{children:e.author}),e.dynasty&&t.jsx("span",{children:e.dynasty})]})]}),t.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:lp(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Cs(e.type)})]})},$n=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),cp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},dp={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")},pp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},up={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"},xp={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},fp={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},gp={work:"📜",collection:"📚",book:"📖",entity:"👤"},Ts=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:c,onAskAI:p,renderSectionActions:a,onDownloadResource:d,downloadStatuses:u,relations:f,onRelationsChange:x})=>{var V;const m=ce(),[h,v]=g.useState(!1),[b,j]=g.useState("work"),[y,k]=g.useState(""),[$,S]=g.useState(""),[_,w]=g.useState([]),[z,T]=g.useState(!1),[R,C]=g.useState(!1),[P,M]=g.useState("work"),[A,F]=g.useState(""),[G,D]=g.useState(),[E,le]=g.useState(!1),[W,Y]=g.useState(null),[re,te]=g.useState([]);g.useRef(null);const J=e.type,ee=J==="work",ge=J==="collection",se=J==="book",ie=g.useCallback((B,oe)=>{n({...e,[B]:oe})},[e,n]),O=g.useCallback((B,oe)=>{k(B),j(oe),S(m.editor.selectToLink+m.indexType[oe]),w([]),v(!0)},[m]),Z=g.useCallback(B=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,B)},[r,e.id]),ne=g.useCallback(B=>{s==null||s(B.id,B.type)},[s]),N=g.useCallback((B,oe,de)=>{const _e={...de,author:(de==null?void 0:de.author)||e.author,dynasty:de==null?void 0:de.dynasty};M(oe),F(B),D(_e),C(!0)},[e.author]),I=g.useCallback((B,oe)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,A,{type:P,title:B,inheritData:oe}),C(!1)},[r,e.id,A,P]),K=g.useCallback(B=>{if(!B.trim()){w([]);return}T(!0),r!=null&&r.searchEntities&&r.searchEntities(B,b).then(oe=>{w(oe),T(!1)}).catch(()=>{w([]),T(!1)})},[r,b]),X=g.useCallback(B=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,y,B.id),v(!1)},[r,e.id,y]),xe=g.useCallback(()=>{i()},[i]),fe=g.useCallback(B=>{Y(()=>B),le(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(te).catch(()=>{})},[r]),ke=g.useCallback((B,oe)=>r!=null&&r.searchEntities?r.searchEntities(B,oe==="all"?void 0:oe):Promise.resolve([]),[r]),Q=g.useCallback(B=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(B),te(oe=>[B,...oe.filter(de=>de.id!==B.id)].slice(0,10)),W==null||W(B),le(!1),Y(null)},[r,W]);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:gp[J]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(an,{children:e.id}),t.jsx(an,{color:fp[J],children:m.indexType[J]})]})}),t.jsx(Oe,{title:m.section.basicInfo,onSave:i,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(nn,{label:ee?m.editor.workTitle:ge?m.editor.collectionTitle:m.editor.bookTitle,value:e.title,onChange:B=>ie("title",B)}),se&&t.jsx(nn,{label:m.editor.belongsToWork,value:e.workName||"",onChange:B=>ie("workName",B)}),t.jsx(Me,{label:m.editor.authorLabel,value:e.author||"",onChange:B=>ie("author",B)}),t.jsx(Me,{label:m.editor.publicationYearLabel,value:e.publicationYear||"",onChange:B=>ie("publicationYear",B)}),(se||ge)&&t.jsx(nn,{label:m.editor.containedIn,value:e.collection||"",onChange:B=>ie("collection",B)}),(se||ge)&&t.jsx(Me,{label:m.editor.holderLabel,value:e.holder||"",onChange:B=>ie("holder",B)}),(se||ge)&&t.jsx(Me,{label:se?m.editor.pageLabel:m.editor.volumeLabel,value:e.pages||"",onChange:B=>ie("pages",B)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(Me,{label:m.editor.firstImageLabel,value:e.firstImage||"",onChange:B=>ie("firstImage",B)})})]})}),t.jsx(Oe,{title:m.section.description,onSave:i,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(ut,{value:e.description||"",onChange:B=>ie("description",B),placeholder:m.editor.descriptionPlaceholder})}),(((V=e.additional_works)==null?void 0:V.length)||0)>0&&t.jsx(Oe,{title:m.section.additionalWorks,onSave:i,children:t.jsx(mp,{items:e.additional_works||[],onChange:B=>ie("additional_works",B)})}),t.jsx(Oe,{title:m.section.indexedBy,onSave:i,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(hp,{items:e.indexed_by||[],onChange:B=>ie("indexed_by",B)})}),t.jsx(Oe,{title:m.section.emendatedBy,onSave:i,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(bp,{items:e.emendated_by||[],onChange:B=>ie("emendated_by",B)})}),t.jsx(Oe,{title:m.section.textResources,onSave:i,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(En,{items:e.resources||[],onChange:B=>ie("resources",B),onDownload:d,downloadStatuses:u,filterType:"text"})}),t.jsx(Oe,{title:m.section.imageResources,onSave:i,children:t.jsx(En,{items:e.resources||[],onChange:B=>ie("resources",B),onDownload:d,downloadStatuses:u,filterType:"image"})}),t.jsx(Oe,{title:m.section.sources,onSave:i,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(vs,{items:ks(e.sources||""),onChange:B=>ie("sources",Ss(B)),onOpenEntityPicker:fe})}),(se||ge)&&t.jsx(Oe,{title:m.section.provenance,onSave:i,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(ut,{value:e.provenance||"",onChange:B=>ie("provenance",B),placeholder:m.editor.provenancePlaceholder})}),se&&t.jsx(Oe,{title:m.section.otherEditions,onSave:i,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(ut,{value:e.otherEditions||"",onChange:B=>ie("otherEditions",B),placeholder:m.editor.otherEditionsPlaceholder})}),t.jsx(ws,{entityType:J,entityId:e.id,entityTitle:e.title,parentWork:f==null?void 0:f.parentWork,parentCollection:f==null?void 0:f.parentCollection,belongsToWork:f==null?void 0:f.belongsToWork,belongsToCollection:f==null?void 0:f.belongsToCollection,childWorks:f==null?void 0:f.childWorks,childCollections:f==null?void 0:f.childCollections,containedBooks:f==null?void 0:f.containedBooks,siblingBooks:f==null?void 0:f.siblingBooks,onLinkEntity:O,onUnlinkEntity:Z,onViewEntity:ne,onCreateAndLink:N,onSaveRelations:xe}),l&&c&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${o("danger-soft-border")}`,background:o("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:o("danger"),fontWeight:600,marginBottom:"8px"},children:m.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"12px"},children:m.editor.dangerZoneDesc}),t.jsx("button",{onClick:c,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("danger")}`,borderRadius:"4px",background:"transparent",color:o("danger"),cursor:"pointer"},children:m.editor.deleteEntity})]}),t.jsx($s,{isOpen:h,entityType:b,title:$,onSelect:X,onCancel:()=>v(!1),onCreate:()=>{v(!1),N(y,b)},searchResults:_,onSearch:K,isLoading:z,excludeId:e.id}),t.jsx(zs,{isOpen:R,entityType:P,relationField:A,inheritData:G,onConfirm:I,onCancel:()=>C(!1)}),t.jsx(Is,{isOpen:E,title:m.action.selectBookOrWork,filterType:"all",recentEntities:re,excludeId:e.id,onSelect:Q,onCancel:()=>{le(!1),Y(null)},onSearch:ke})]})};function mp({items:e,onChange:n}){const i=ce(),r=(c,p,a)=>{const d=e.map((u,f)=>f===c?{...u,[p]:a}:u);n(d)},s=c=>n(e.filter((p,a)=>a!==c)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((c,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(Me,{label:i.editor.bookNameLabel,value:c.book_title,onChange:a=>r(p,"book_title",a)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(Me,{label:i.label.juanCount,value:c.n_juan!=null?String(c.n_juan):"",onChange:a=>r(p,"n_juan",a&&parseInt(a,10)||void 0)})}),t.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Rs({items:e,onChange:n,showMeta:i,addLabel:r}){const s=ce(),[l,c]=g.useState(null),p=(u,f,x)=>{const m=e.map((h,v)=>v===u?{...h,[f]:x||void 0}:h);n(m)},a=u=>{n(e.filter((f,x)=>x!==u)),l===u&&c(null)},d=()=>{n([...e,{source:""}]),c(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,f)=>{const x=l===f;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:x?`color-mix(in srgb, ${o("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>c(x?null:f),children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.2s",transform:x?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:m=>{m.stopPropagation(),a(f)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${o("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:o("muted")},children:"✕"})]}),!x&&i&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:o("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),x&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Me,{label:s.label.sourceName,value:u.source,onChange:m=>p(f,"source",m)}),t.jsx(Me,{label:s.label.sourceBid,value:u.source_bid||"",onChange:m=>p(f,"source_bid",m)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Me,{label:s.label.titleInfo,value:u.title_info||"",onChange:m=>p(f,"title_info",m)}),t.jsx(Me,{label:s.label.authorInfo,value:u.author_info||"",onChange:m=>p(f,"author_info",m)})]}),t.jsx(Me,{label:s.label.edition,value:u.edition||"",onChange:m=>p(f,"edition",m)})]}),t.jsx(ut,{value:u.summary||"",onChange:m=>p(f,"summary",m),placeholder:s.editor.summaryPlaceholder}),t.jsx(ut,{value:u.comment||"",onChange:m=>p(f,"comment",m),placeholder:s.editor.commentPlaceholder}),t.jsx(ut,{value:u.additional_comment||"",onChange:m=>p(f,"additional_comment",m),placeholder:s.editor.additionalCommentPlaceholder})]})]},f)}),t.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:r})]})}function hp({items:e,onChange:n}){const i=ce();return t.jsx(Rs,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function bp({items:e,onChange:n}){const i=ce();return t.jsx(Rs,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function Es(e){var p,a,d,u,f,x,m;const n=((a=(p=e.authors)==null?void 0:p[0])==null?void 0:a.name)||"",i=((d=e.publication_info)==null?void 0:d.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(f=e.page_count)!=null&&f.number?String(e.page_count.number):((x=e.page_count)==null?void 0:x.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",c={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 h=e;if(Array.isArray(h.related_works)){const v=h.related_works.find(b=>b.relation==="part_of");v&&(c.parentWorkId=v.id,c.parentWorkName=v.title)}}if(e.type==="book"){const h=e;c.workId=h.work_id,Array.isArray(h.contained_in)&&h.contained_in.length>0&&(c.collectionId=(m=h.contained_in[0])==null?void 0:m.id)}return c}function yp(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 jp=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:c,onSave:p,onDelete:a,onNavigate:d,renderLink:u,onAskAI:f,renderSectionActions:x,onDownloadResource:m,downloadStatuses:h,relations:v,onRelationsChange:b,headerExtra:j,className:y,style:k}=e;ce();const[$,S]=g.useState(s),_=l?s:$;g.useEffect(()=>{s!==$&&S(s)},[s]);const w=g.useCallback(()=>{const A=_==="view"?"edit":"view";l?l(A):S(A)},[_,l]),[z,T]=g.useState(null);g.useEffect(()=>{i&&r&&r.getItem(i).then(A=>{A&&T(A)})},[i,r]);const R=n||z,C=g.useMemo(()=>R?Es(R):null,[R]),P=l||!n?t.jsx("button",{onClick:w,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:_==="edit"?o("accent-bg"):"transparent",color:o(_==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?"切换到编辑模式":"切换到查看模式",children:_==="view"?"✏️ 编辑":"👁 查看"}):null,M=t.jsxs(t.Fragment,{children:[P,j]});return!R&&!C?t.jsx(ft,{}):_==="view"?t.jsx(ti,{data:R,transport:r,onNavigate:d?A=>d(A):void 0,renderLink:u,headerExtra:M,className:y,style:k}):C?t.jsxs("div",{className:y,style:k,children:[M&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:M}),t.jsx(Ts,{data:C,onChange:c||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:f,renderSectionActions:x,onDownloadResource:m,downloadStatuses:h,relations:v,onRelationsChange:b})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},No=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ns=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,l]=g.useState(null),[c,p]=g.useState(""),[a,d]=g.useState(""),[u,f]=g.useState("idle"),[x,m]=g.useState(""),h=g.useRef(null);g.useEffect(()=>{e&&(l(null),p(""),d(""),f("idle"),m(""))},[e]),g.useEffect(()=>{s&&setTimeout(()=>{var y;return(y=h.current)==null?void 0:y.focus()},100)},[s]),g.useEffect(()=>{if(u==="success"){const y=setTimeout(n,2e3);return()=>clearTimeout(y)}},[u,n]),g.useEffect(()=>{if(!e)return;const y=k=>{k.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[e,n]);const v=async()=>{if(!(!s||!c.trim())){f("submitting"),m("");try{await i({type:s,content:c.trim(),...a.trim()?{contact:a.trim()}:{}}),f("success")}catch(y){f("error"),m(y instanceof Error?y.message:"提交失败,请稍后重试")}}};if(!e)return null;const b=s&&c.trim()&&u!=="submitting",j=No.find(y=>y.value===s);return t.jsx("div",{style:vp,onClick:y=>{y.target===y.currentTarget&&n()},children:t.jsxs("div",{style:kp,onClick:y=>y.stopPropagation(),children:[t.jsxs("div",{style:Sp,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:wp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:Ip,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:No.map(y=>t.jsxs("button",{onClick:()=>l(y.value),style:{..._p,...s===y.value?$p:{}},children:[t.jsx("span",{children:y.icon})," ",y.label]},y.value))}),t.jsx("textarea",{ref:h,value:c,onChange:y=>p(y.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...zp,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:a,onChange:y=>d(y.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:Rp}),t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[c.length," / 2000"]}),u==="error"&&t.jsx("div",{style:Tp,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:v,disabled:!b,style:{...Cp,opacity:b?1:.6,cursor:b?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},vp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},kp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},Sp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},wp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:o("desc-fg"),padding:"4px 8px",borderRadius:"4px"},_p={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"},$p={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},zp={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Cp={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},Ip={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},Tp={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Rp={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"},Vn="--bim-feedback-fab-offset",Yn=48,Ep=16,Np=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,c]=g.useState(!1),p=n.bottom??24;return g.useEffect(()=>{if(r||typeof document>"u")return;const a=document.documentElement;return a.style.setProperty(Vn,`calc(${p+Yn+Ep}px + env(safe-area-inset-bottom, 0px))`),()=>{a.style.removeProperty(Vn)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>c(!0),style:{...Lp,zIndex:s??o("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(Ns,{isOpen:l,onClose:()=>c(!1),onSubmit:e,feedbackListUrl:i})]})},Lp={position:"fixed",width:`${Yn}px`,height:`${Yn}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"},Lo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ls=({onSubmit:e})=>{const[n,i]=g.useState("bug"),[r,s]=g.useState(""),[l,c]=g.useState(""),[p,a]=g.useState("idle"),[d,u]=g.useState(""),f=g.useRef(null);g.useEffect(()=>{n&&setTimeout(()=>{var v;return(v=f.current)==null?void 0:v.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){a("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),a("success"),s(""),c(""),i("bug")}catch(v){a("error"),u(v instanceof Error?v.message:"提交失败,请稍后重试")}}},m=n&&r.trim()&&p!=="submitting",h=Lo.find(v=>v.value===n);return p==="success"?t.jsx("div",{style:Bo,children:t.jsxs("div",{style:Fp,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>a("idle"),style:Pp,children:"继续提交"})]})}):t.jsxs("div",{style:Bo,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Lo.map(v=>t.jsxs("button",{onClick:()=>i(v.value),style:{...Bp,...n===v.value?Ap:{}},children:[t.jsx("span",{children:v.icon})," ",v.label]},v.value))}),t.jsx("textarea",{ref:f,value:r,onChange:v=>s(v.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...Wp}}),t.jsx("input",{type:"text",value:l,onChange:v=>c(v.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:Dp}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:x,disabled:!m,style:{...Mp,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:Op,children:d})]})},Bo={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},Bp={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"},Ap={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},Wp={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"},Mp={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},Fp={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},Pp={background:"none",border:"none",color:o("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Op={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginTop:"8px"},Dp={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 Ao(e){return typeof e=="function"?e():e??"/api/feedback"}const Bs=({resourceId:e,apiUrl:n})=>{const[i,r]=g.useState([]),[s,l]=g.useState(!0),c=g.useCallback(async()=>{const a=Ao(n);l(!0);try{const u=await(await fetch(`${a}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);g.useEffect(()=>{c()},[c]);const p=async a=>{const d=Ao(n),u=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const f=await u.json().catch(()=>null);throw new Error((f==null?void 0:f.error)||"提交失败")}setTimeout(()=>c(),500)};return t.jsxs("div",{children:[t.jsx(Ci,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Ls,{onSubmit:p})})]})},Wo={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 Hp(e){return e?Wo[e]??e:Wo.related}const Gp={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function Up(e){return Gp[e]??e}const Vp={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function Yp(e){return Vp[e]??""}function Ii({authors:e,onNavigate:n,renderLink:i}){const{convert:r}=U(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,c)=>{const p=li(l.role);return t.jsxs(g.Fragment,{children:[c>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(ze,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:i,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},c)})}):null}function As(e,n){var p,a;const i=ri(e,n),r=i.mirrors.map(d=>({key:d.key,label:d.label,description:d.description,rows:d.items.filter(u=>u.group_role!=="mirror"),mirrors:d.items.filter(u=>u.group_role==="mirror")})),s=i.buckets.filter(d=>d.key==="image"||d.key==="textImage").flatMap(d=>d.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=i.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((a=i.buckets.find(d=>d.key==="text"))==null?void 0:a.items)??[],groups:r}}function Ws(e,n){const i=(e.url?$t(e.url):void 0)||e.name,r=wr(e,n);return r?`${i}(${r})`:i}function Ti({item:e,siblings:n,listedVolumeCounts:i}){const{convert:r}=U(),[s,l]=g.useState(!1),c=cn(e),p=!!c&&c.expected>0&&!(i!=null&&i.has(c.expected)),a=r(Ws(e,n)),d=zt(e),u=xn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[a," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:a}),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(pi,{item:e})})]}),t.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(f=>!f),children:r(s?"收起分冊":`展開 ${c.expected} 冊`)})})]})}function Ms({groups:e,listedVolumeCounts:n}){const{convert:i}=U();return t.jsx(t.Fragment,{children:e.map(r=>t.jsxs("div",{className:"bim-d-rg",children:[r.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:i(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:i(r.description)}),r.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:r.rows.map((s,l)=>t.jsx(Ti,{item:s,siblings:r.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),r.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[r.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:i("鏡像")}),r.mirrors.map((s,l)=>{const c=zt(s),p=i(Ws(s,r.mirrors));return c?t.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",title:s.details?i(s.details):void 0,children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:p},l)})]})]},r.key))})}const Mo=12,Kp=60,Fs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:c,railLinks:p})=>{var Z,ne,N;const a=ce(),{convert:d}=U(),u=g.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[f,x]=g.useState(new Map),[m,h]=g.useState(!1),[v,b]=g.useState(""),[j,y]=g.useState(!1),k=u.length<=Kp,$=k||m||!!v||j,S=g.useMemo(()=>$?u:u.slice(0,Mo),[u,$]);g.useEffect(()=>{if(!n||S.length===0)return;const I=S.filter(X=>!f.has(X));if(I.length===0)return;let K=!1;return Promise.all(I.map(X=>n.getItem(X).then(xe=>{const fe=xe??{};return[X,{id:X,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(()=>[X,{id:X}]))).then(X=>{K||x(xe=>{const fe=new Map(xe);for(const[ke,Q]of X)fe.set(ke,Q);return fe})}),()=>{K=!0}},[n,S,f]);const _=g.useMemo(()=>u.map(I=>f.get(I)??{id:I}),[u,f]),w=u.length>0&&u.every(I=>f.has(I)),z=!!n&&S.some(I=>!f.has(I)),T=k||$,R=g.useMemo(()=>$r(_,e.version_graph,{era:v,scanOnly:j,sort:T?"year":"default"}),[_,e.version_graph,v,j,T]),C=m?R.rows:R.rows.slice(0,Mo),P=R.allRows.filter(I=>I.hasImage).length,M=e.related_works||[],A=M.filter(I=>I.relation==="collected_in"),F=g.useMemo(()=>{const I=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],K=X=>{const xe=I.indexOf(X??"");return xe<0?I.length:xe};return M.filter(X=>X.relation!=="collected_in").map((X,xe)=>({r:X,i:xe})).sort((X,xe)=>K(X.r.relation)-K(xe.r.relation)||X.i-xe.i).map(X=>X.r)},[M]),G=g.useMemo(()=>{const I=ri(e.resources,e.resource_groups);return[...I.mirrors.flatMap(K=>K.items.map(X=>({r:X,kind:d(K.label)}))),...I.buckets.flatMap(K=>K.items.map(X=>({r:X,kind:d(Yp(K.key))})))]},[e.resources,e.resource_groups,d]),D=e.indexed_by||[],E=e.emendated_by||[],le=g.useMemo(()=>{var oe,de,_e;const I=[],K=(de=(oe=e.authors)==null?void 0:oe[0])==null?void 0:de.dynasty;K&&I.push({label:"成書",value:d(K)});const X=nt(e,a.unit.juan);if(X){const pe=(_e=e.juan_count)==null?void 0:_e.description;I.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[d(X),pe&&pe!==X?t.jsxs("span",{className:"bim-d-meta",children:["(",d(pe),")"]}):null]})})}e.loss_status&&I.push({label:"存佚",value:d(Up(e.loss_status))});const xe=e._edition_count??u.length;xe&&I.push({label:"版本",value:t.jsxs(t.Fragment,{children:[xe," ",d("種"),w&&P?t.jsxs("span",{className:"bim-d-meta",children:[" ",d(`${P} 種有影印`)]}):null]})});const fe=R.allRows.filter(pe=>pe.sortYear!=null),ke=fe.length>0?fe.reduce((pe,Be)=>pe.sortYear<=Be.sortYear?pe:Be):null;ke!=null&&ke.era.era?I.push({label:"最早存世",value:d([ke.era.era,ke.era.reign].filter(Boolean).join(" ")),title:ke.era.source==="edition"?d("據版本題名推斷"):void 0}):z&&I.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),(D.length||E.length)&&I.push({label:"著錄",value:t.jsxs(t.Fragment,{children:[D.length?`${D.length} ${d("家")}`:"—",E.length?t.jsxs("span",{className:"bim-d-meta",children:[" ",d(`考證 ${E.length} 條`)]}):null]})});const Q=Fo(e.additional_titles);Q.length&&I.push({label:"又名",value:Q.map(d).join("、")});const V=Fo(e.attached_texts);V.length&&I.push({label:"附載",value:V.map(d).join("、")});const B=(e.additional_works||[]).map(pe=>d(pe.book_title)+(pe.n_juan!=null?` ${pe.n_juan}${d(a.unit.juan)}`:""));return B.length&&I.push({label:"附錄",value:B.join("、")}),I},[e,d,a,u.length,w,z,P,R.allRows,D.length,E.length]),W=e.classification,Y=W?[W.l1,W.l2,W.l3,W.l4].filter(Boolean).map(I=>d(I)):[],re=e.subtype?d(a.workSubtype[e.subtype]??e.subtype):"",te=t.jsx(Vt,{title:d(e.title),byline:t.jsx(Ii,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(Ie,{items:[...Y,W!=null&&W.source?d(`據《${W.source.split("/")[0]}》`):"",re]}),description:(Z=e.description)!=null&&Z.text?t.jsxs(t.Fragment,{children:[t.jsx(tt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(ne=e.description.sources)!=null&&ne.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(I=>d(Ra(I))).filter(Boolean).join(" · ")}):null]}):void 0,facts:le,readAction:s,foot:t.jsx(Yt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(N=e.appendix)==null?void 0:N.map((I,K)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(I.title)}),t.jsx(tt,{text:I.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},K))}),J=R.eras.length>=2?[{key:"",label:a.catalog.all},...R.eras.map(I=>({key:I,label:I}))]:[],ee=[];u.length&&ee.push({id:"versions",label:"版本",count:u.length}),D.length&&ee.push({id:"catalogs",label:"著錄",count:D.length}),A.length&&ee.push({id:"collected",label:"收入叢編",count:A.length}),F.length&&ee.push({id:"related",label:"相關書目",count:F.length}),G.length&&ee.push({id:"resources",label:"在線資源",count:G.length});const ge=u.length===0&&D.length===0,se=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Te,{id:"versions",title:"版本",meta:t.jsx(Ie,{items:[d(`共 ${u.length} 種`),w&&P?d(`${P} 種有影印`):"",R.rows.length!==R.allRows.length?d(`當前 ${R.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&J.length===0&&u.length>1?"":void 0,children:[J.length>0&&t.jsx(ai,{items:J,value:v,onChange:I=>{b(I),h(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Mr,{label:"只看有影印",checked:j,onChange:I=>{y(I),h(!1)}}),t.jsx("span",{className:"bim-d-meta",children:d(T?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("版本")}),t.jsx("th",{children:d("年代")}),t.jsx("th",{children:d("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:d("影印")})})]})}),t.jsx("tbody",{children:C.map(I=>{var K;return t.jsx(qp,{row:I,measure:(K=f.get(I.id))==null?void 0:K.measure_info,loaded:f.has(I.id),onNavigate:i,renderLink:r},I.id)})})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(v||j?"當前篩選下沒有版本":"暫無版本著錄")}),R.rows.length>C.length&&t.jsx(Ct,{label:`展開其餘 ${R.rows.length-C.length} 種版本`,onClick:()=>h(!0)}),R.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:d("部分年代據版本題名推斷,非著錄原文")})]}),D.length>0&&t.jsx(Jp,{items:D,onNavigate:i,renderLink:r}),ge&&t.jsx(Te,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),ie=(I,K)=>t.jsx(ze,{id:I,label:d(K),onNavigate:i,renderLink:r,dense:!0}),O=t.jsxs(t.Fragment,{children:[t.jsx(pt,{id:"collected",title:"收入叢編",items:A.map(I=>ie(I.id,I.title))}),t.jsx(pt,{id:"related",title:"相關書目",meta:d(`${F.length} 部`),items:F.map(I=>t.jsxs(t.Fragment,{children:[ie(I.id,I.title),t.jsx("span",{className:"bim-d-meta",title:I.note?d(I.note):void 0,children:d(Hp(I.relation))})]}))}),t.jsx(pt,{id:"resources",title:"在線資源",cap:6,items:G.map(({r:I,kind:K})=>{const X=d((I.url?$t(I.url):void 0)||I.name),xe=zt(I);return t.jsxs(t.Fragment,{children:[xe?t.jsxs("a",{href:xe,target:"_blank",rel:"noopener noreferrer",children:[X," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:X}),K&&t.jsx("span",{className:"bim-d-meta",children:K})]})})})]});return t.jsx(Ut,{railTop:l,back:c,nav:ee,railLinks:p,main:se,card:te,side:O})};function Fo(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Po(e,n){return n((e.url?$t(e.url):void 0)||e.name)}function qp({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=U(),c=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",a=e.holders[0],d=a?Po(a,l):e.locationName?l(e.locationName):"",u=e.images[0],f=u?zt(u):void 0,x=e.images.map(m=>Po(m,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(ze,{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${c?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:c?l(c):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${d?"":" bim-d-zt-blank"}`,children:[d||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(f?t.jsx("a",{className:"bim-d-flag",href:f,target:"_blank",rel:"noopener noreferrer",title:x,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:x,children:l("有影印")}))})]})}function Jp({items:e,onNavigate:n,renderLink:i}){const r=ce(),{convert:s}=U(),[l,c]=g.useState(0),p=e[Math.min(l,e.length-1)];return t.jsx(Te,{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((a,d)=>t.jsx("li",{role:"presentation",children:t.jsx("button",{type:"button",role:"tab","aria-selected":d===l,onClick:()=>c(d),children:s(a.source)})},d))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[p.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:s(p.title_info)}),t.jsx(Ie,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[p.source_bid?t.jsx(ze,{id:p.source_bid,label:s(p.source),onNavigate:n,renderLink:i,dense:!0}):s(p.source),p.section?s(p.section):"",p.author_info?`${s(r.label.authorInfo)} ${s(p.author_info)}`:"",p.edition?`${s(r.label.edition)} ${s(p.edition)}`:"",p.page??""]}),p.summary&&t.jsx("p",{className:"bim-d-quote",children:Fe(s(p.summary))}),p.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:Fe(s(p.comment))})]}),p.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:Fe(s(p.additional_comment))})]}),!p.summary&&!p.comment&&!p.additional_comment&&!p.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:s("僅著錄書名,無提要。")})]})]})})}const Oo=40,Do=2,Zp=9,Ho={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function zn(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Ps=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,fullText:l,fullTextPending:c,chapterLink:p,railTop:a,back:d,railLinks:u})=>{var V,B,oe,de,_e,pe,Be,Ee,we,Je,Jt,st,He,It;const f=ce(),{convert:x}=U(),[m,h]=g.useState(null),[v,b]=g.useState(new Map),[j,y]=g.useState([]),[k,$]=g.useState(new Map),[S,_]=g.useState(!1);g.useEffect(()=>{if(!n||!e.work_id){h(null);return}let L=!1;return n.getItem(e.work_id).then(ae=>{!L&&ae&&ae.type==="work"&&h(ae)}).catch(()=>{}),()=>{L=!0}},[n,e.work_id]),g.useEffect(()=>{const L=e.contained_in||[];if(!n||L.length===0){b(new Map);return}let ae=!1;return Promise.all(L.map(ue=>{const ye=typeof ue=="string"?ue:ue.id;return n.getItem(ye).then(je=>[ye,je]).catch(()=>[ye,null])})).then(ue=>{if(ae)return;const ye=new Map;for(const[je,he]of ue)he&&ye.set(je,he);b(ye)}),()=>{ae=!0}},[n,e.contained_in]);const w=g.useMemo(()=>{const L=new Set([...(m==null?void 0:m.books)||[],...e.related_books||[]]);return L.add(e.id),[...L]},[m==null?void 0:m.books,e.related_books,e.id]),z=w.length-1;g.useEffect(()=>{if(!n||z<=0){y([]);return}const L=w.length<=Oo,ae=L?w:w.slice(0,8);let ue=!1;return Promise.all(ae.map(ye=>ye===e.id?Promise.resolve({id:ye,title:e.title,edition:e.edition,year:sn(e)}):n.getItem(ye).then(je=>{const he=je??{};return{id:ye,title:he.title,edition:he.edition,year:je?sn(he):void 0}}).catch(()=>({id:ye})))).then(ye=>{if(ue)return;const je=ye.filter(he=>he.id===e.id||he.title||he.edition);L&&je.sort((he,Ne)=>(he.year??1/0)-(Ne.year??1/0)),y(je)}),()=>{ue=!0}},[n,w,z,e]);const T=e.lineage,R=g.useMemo(()=>[...((T==null?void 0:T.derived_from)||[]).filter(L=>L.ref_type==="book").map(L=>L.ref),...((T==null?void 0:T.related_to)||[]).map(L=>L.book_id)].filter(Boolean),[T]);g.useEffect(()=>{if(!n||R.length===0){$(new Map);return}let L=!1;return Promise.all(R.map(ae=>n.getItem(ae).then(ue=>[ae,{id:ae,title:ue==null?void 0:ue.title,edition:ue==null?void 0:ue.edition}]).catch(()=>[ae,{id:ae}]))).then(ae=>{L||$(new Map(ae))}),()=>{L=!0}},[n,R]);const C=g.useMemo(()=>As(e.resources,e.resource_groups),[e.resources,e.resource_groups]),P=C.groups.reduce((L,ae)=>L+ae.rows.length+ae.mirrors.length,0),M=C.groups.length>0&&C.groups.every(L=>L.key==="_physical"),A=Gt(e),F=Rr(e),G=nt(e,f.unit.juan),D=new Set((e.contained_in||[]).map(L=>typeof L=="string"?0:Pt(L.volume_index).length).filter(L=>L>0)),E=L=>{var ye;const ae=(ye=e.base_edition)==null?void 0:ye.find(je=>je.book_id===L&&je.name);if(ae!=null&&ae.name)return ae.name;const ue=k.get(L);return(ue==null?void 0:ue.edition)||(ue==null?void 0:ue.title)||""},le=g.useMemo(()=>{var he,Ne,Ze,lt,it;const L=[];F&&L.push({label:"版本類型",value:x(F),title:(he=e.lineage)!=null&&he.category?void 0:x("據版本題名推斷")}),(Ne=e.publication_info)!=null&&Ne.details?L.push({label:"刊印",value:x(e.publication_info.details)}):(A.era||A.reign)&&L.push({label:"刊寫年代",value:x([A.era,A.reign].filter(Boolean).join(" ")),title:A.source==="edition"?x("據版本題名推斷"):void 0}),G&&L.push({label:"卷帙",value:x(G)});const ae=(e.contained_in||[]).flatMap(Ae=>typeof Ae=="string"?[]:Pt(Ae.volume_index));ae.length&&L.push({label:"冊次",value:x(`第 ${fn(ae,f.unit.volume)} ${f.unit.volume}(${ae.length} ${f.unit.volume})`)});const ue=(((Ze=e.lineage)==null?void 0:Ze.derived_from)||[]).find(Ae=>Ae.relation==="底本"&&Ae.ref_type==="book");ue&&E(ue.ref)&&L.push({label:"底本",value:t.jsx(ze,{id:ue.ref,label:x(E(ue.ref)),onNavigate:i,renderLink:r,dense:!0})});const ye=(e.resources||[]).filter(Ae=>(Ae.types||(Ae.type?[Ae.type]:[])).includes("physical"));ye.length?L.push({label:"存藏",value:ye.slice(0,2).map(Ae=>x(Ae.name)).join("、")+(ye.length>2?x(` 等 ${ye.length} 處`):"")}):(lt=e.current_location)!=null&&lt.name&&L.push({label:"存藏",value:x(e.current_location.name)}),(it=e.page_count)!=null&&it.description&&L.push({label:f.label.pageCount,value:x(e.page_count.description)});const je=[...Pn(e.additional_titles),...Pn(e.attached_texts)];return je.length&&L.push({label:"又名",value:je.map(x).join("、")}),L},[e,x,f,A,F,G,k,i,r]),W=x(e.title),Y=e.edition?x(e.edition):void 0,re=((V=e.lineage)==null?void 0:V.year_text)||"",te=t.jsx(Vt,{kind:"版本",title:W,subtitle:Y,byline:t.jsx(Ii,{authors:e.authors??(m==null?void 0:m.authors),onNavigate:i,renderLink:r}),meta:t.jsx(Ie,{items:[F?x(F):"",A.era?x([A.era,A.reign].filter(Boolean).join("")):"",G?x(G):""]}),description:(B=e.description)!=null&&B.text?t.jsx(tt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ci((oe=e.description)==null?void 0:oe.text)?6:void 0,facts:le,readAction:s,secondaryAction:s&&P>0&&!M?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(Yt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),J=e.contained_in||[],ee=(l==null?void 0:l.chapters)||[],ge=ee[0]&&zn(ee[0].title)[0].slice(-1)||"章",se=!!((de=T==null?void 0:T.derived_from)!=null&&de.length||(_e=T==null?void 0:T.related_to)!=null&&_e.length||(pe=e.appendix)!=null&&pe.length),ie=[];(ee.length||C.text.length||c)&&ie.push({id:"fulltext",label:"全文",count:ee.length?x(`${ee.length} ${ge}`):void 0}),C.groups.length&&ie.push({id:"images",label:M?"館藏":"影印",count:P}),se&&ie.push({id:"lineage",label:"版本源流"}),J.length&&ie.push({id:"collections",label:"收入叢編",count:J.length}),(Be=e.location_history)!=null&&Be.length&&ie.push({id:"provenance",label:"流轉歷史"});const O=L=>(p==null?void 0:p(L))??null,Z=ee[0],ne=Z?O(Z.file):null,N=S?ee:ee.slice(0,Zp),I=(L,ae,ue)=>L?t.jsx("a",{className:ue,href:L.href??"#",onClick:L.onClick?ye=>{ye.metaKey||ye.ctrlKey||(ye.preventDefault(),L.onClick())}:void 0,children:ae}):t.jsx("span",{className:ue,children:ae}),K=t.jsxs(t.Fragment,{children:[(ee.length>0||C.text.length>0||c)&&t.jsxs(Te,{id:"fulltext",title:"全文",meta:ee.length>0?t.jsx(Ie,{items:[x(`${ee.length} ${ge}`),(Ee=l==null?void 0:l.source)!=null&&Ee.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[c&&!Z&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),Z&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${zn(Z.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((Z.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),I(ne,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),ee.length>1&&t.jsx("ul",{className:"bim-d-chap",children:N.map(L=>{const[ae,ue]=zn(L.title);return t.jsx("li",{children:I(O(L.file),t.jsxs(t.Fragment,{children:[ae&&t.jsx("b",{children:x(ae)}),x(ue||L.file)]}))},L.file)})}),ee.length>N.length&&t.jsx(Ct,{label:`展開其餘 ${ee.length-N.length} ${ge}`,onClick:()=>_(!0)}),C.text.length>0&&t.jsxs(t.Fragment,{children:[(ee.length>0||c)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:C.text.map((L,ae)=>t.jsx(Ti,{item:L,siblings:C.text,listedVolumeCounts:D},`${L.id||L.url||L.name}-${ae}`))})})]})]}),C.groups.length>0&&t.jsx(Te,{id:"images",title:M?"館藏":"影印",meta:t.jsx(Ie,{items:[C.groups.length>1?x(`${C.groups.length} 組`):"",x(`${P} 處`)]}),children:t.jsx(Ms,{groups:C.groups,listedVolumeCounts:D})}),se&&t.jsxs(Te,{id:"lineage",title:"版本源流",meta:(we=T==null?void 0:T.derived_from)!=null&&we.length?x("據版本傳承著錄"):void 0,children:[t.jsxs("ul",{className:"bim-d-tl",children:[((T==null?void 0:T.derived_from)||[]).map((L,ae)=>{const ue=L.ref_type==="book"?E(L.ref):"";return t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(L.relation)}),L.ref_type==="book"?t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(ze,{id:L.ref,label:x(ue||L.ref),onNavigate:i,renderLink:r,dense:!0})}):t.jsx("span",{className:"bim-d-tl-t",children:x("擬構祖本")}),(L.evidence||L.confidence)&&t.jsxs("span",{className:"bim-d-tl-ev",children:[L.evidence?x(L.evidence):"",L.confidence&&Ho[L.confidence]?x(`(${Ho[L.confidence]})`):""]})]},`d-${ae}`)}),(Je=T==null?void 0:T.derived_from)!=null&&Je.length||(Jt=T==null?void 0:T.related_to)!=null&&Jt.length?t.jsxs("li",{className:"bim-d-tl-cur",children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("本版")}),t.jsx("span",{className:"bim-d-tl-t",children:Y||W}),re&&t.jsxs("span",{className:"bim-d-meta",children:[t.jsx("span",{className:"bim-d-dot"}),x(re)]})]}):null,((T==null?void 0:T.related_to)||[]).map((L,ae)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(L.relation)}),t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(ze,{id:L.book_id,label:x(E(L.book_id)||L.book_id),onNavigate:i,renderLink:r,dense:!0})}),L.evidence&&t.jsx("span",{className:"bim-d-tl-ev",children:x(L.evidence)})]},`r-${ae}`)),(st=e.appendix)==null?void 0:st.map((L,ae)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("附記")}),t.jsx("span",{className:"bim-d-tl-t",children:x(L.title)}),t.jsxs("details",{children:[t.jsx("summary",{className:"bim-d-ui",children:x("展開")}),t.jsx(tt,{text:L.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]})]},`a-${ae}`))]}),(T==null?void 0:T.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"10px 0 0",maxWidth:"46em"},children:x(T.note)})]}),J.length>0&&t.jsx(Te,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:J.map((L,ae)=>{var Ne,Ze;const ue=typeof L=="string"?L:L.id,ye=typeof L=="string"?[]:Pt(L.volume_index),je=v.get(ue),he=(je==null?void 0:je._member_count)||((Ne=je==null?void 0:je.books)==null?void 0:Ne.length)||((Ze=je==null?void 0:je.contained_works)==null?void 0:Ze.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(ze,{id:ue,label:je?x(je.title):ue,onNavigate:i,renderLink:r,dense:!0}),ye.length>0&&t.jsx(Xp,{volumes:ye,unit:f.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${he?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:he>0&&x(`全 ${he} ${f.unit.bu}`)})]},`${ue}-${ae}`)})})})}),(He=e.location_history)!=null&&He.length?t.jsx(Te,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((L,ae)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(L.name)}),([L.start_date,L.end_date].filter(Boolean).join("—")||L.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(Ie,{items:[[L.start_date,L.end_date].filter(Boolean).join("—"),L.description?x(L.description):""]})})]},ae))})}):null,ie.length===0&&t.jsx(Te,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),X=j.findIndex(L=>L.id===e.id),xe=w.length<=Oo,fe=xe&&X>=0?j.slice(Math.max(0,X-Do),X+Do+1):j.filter(L=>L.id!==e.id),ke=t.jsxs(t.Fragment,{children:[m&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:x(f.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(ze,{id:m.id,label:x(m.title),onNavigate:i,renderLink:r})}),t.jsx(Ie,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(m.authors||[]).slice(0,2).map(L=>`${L.dynasty?`〔${x(L.dynasty)}〕`:""}${x(L.name)}`),x(nt(m,f.unit.juan)),m._edition_count?x(`${m._edition_count} 種版本`):""]}),((It=m.description)==null?void 0:It.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:x(m.description.text.replace(/[#*_>`[\]]/g,""))})]}),z>0&&fe.length>0&&t.jsxs("div",{children:[t.jsx(pt,{id:"siblings",title:xe?"同作品版本":f.relation.siblingVersions,meta:x(xe?"按年代":`${z} 種`),cap:fe.length,items:fe.map(L=>L.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(L.edition||L.title||L.id)}):t.jsx(ze,{id:L.id,label:x(L.edition||L.title||L.id),onNavigate:i,renderLink:r,dense:!0})),metas:fe.map(L=>[L.year!=null?L.year<0?`前${-L.year}`:String(L.year):"",L.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:fe.findIndex(L=>L.id===e.id)}),m&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(ze,{id:m.id,label:x(`在作品頁看全部 ${w.length} 種 →`),onNavigate:i,renderLink:r,dense:!0})})]})]}),Q=e.work_id?t.jsx(Wr,{caption:f.section.belongsToWork,children:t.jsx(ze,{id:e.work_id,label:m?x(m.title):" ",onNavigate:i,renderLink:r,dense:!0})}):void 0;return t.jsx(Ut,{railTop:a,back:d,up:Q,nav:ie,railLinks:u,main:K,card:te,side:ke})};function Xp({volumes:e,unit:n}){const{convert:i}=U();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${fn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}const Go=16,Os=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,railTop:c,back:p,railLinks:a})=>{var te,J,ee,ge,se,ie;const d=ce(),{convert:u}=U(),[f,x]=g.useState(""),[m,h]=g.useState(!1),[v,b]=g.useState(null),j=g.useMemo(()=>Ir(e,n),[e,n]),[y,k]=g.useState(new Map),$=g.useMemo(()=>{const O=f.trim();if(!O)return j.rows;const Z=u(O);return j.rows.filter(ne=>{var I;const N=ne.id&&((I=y.get(ne.id))==null?void 0:I.title)||ne.title;return u(N).includes(Z)||(ne.subItems||[]).some(K=>u(K).includes(Z))})},[j.rows,f,y,u]),S=m?$:$.slice(0,Go),_=g.useMemo(()=>S.filter(O=>O.id&&!y.has(O.id)).map(O=>O.id),[S,y]);g.useEffect(()=>{if(!i||_.length===0)return;let O=!1;return Promise.all(_.map(Z=>i.getItem(Z).then(ne=>{var K;const N=ne??{},I={title:N.title,edition:N.edition,authors:N.authors,measure:ne?nt(ne,d.unit.juan):void 0,versionCount:N._edition_count??((K=N.books)==null?void 0:K.length)};return[Z,I]}).catch(()=>[Z,{}]))).then(Z=>{O||k(ne=>{const N=new Map(ne);for(const[I,K]of Z)N.set(I,K);return N})}),()=>{O=!0}},[i,_,d.unit.juan]);const w=(e.contained_in||[])[0];g.useEffect(()=>{if(!w){b(null);return}if(b({id:w}),!i)return;let O=!1;return i.getItem(w).then(Z=>{O||b({id:w,title:Z==null?void 0:Z.title})}).catch(()=>{}),()=>{O=!0}},[i,w]);const z=g.useMemo(()=>As(e.resources,e.resource_groups),[e.resources,e.resource_groups]),T=z.text.length+z.groups.reduce((O,Z)=>O+Z.rows.length+Z.mirrors.length,0),R=e.contained_works||[],C=new Set(j.rows.map(O=>O.id).filter(Boolean)),P=R.length>0&&!R.every(O=>C.has(O.id)),M=(()=>{const O=j.rows.map(Z=>Z.edition).filter(Boolean);return O.length>1&&new Set(O).size===1})(),A=j.rows.some(O=>O.volumes.length>0||O.expected!=null),F=e._member_count||((te=e.books)==null?void 0:te.length)||R.length,G=g.useMemo(()=>{var N,I,K;const O=[];j.rows.length&&O.push({label:"子目",value:`${j.rows.length} ${u(d.unit.items)}`}),F&&F!==j.rows.length&&O.push({label:"成員",value:`${F} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")});const Z=nt(e,d.unit.juan),ne=j.totalVolumes?`${j.totalVolumes} ${u(d.unit.volume)}`:"";return(Z||ne)&&O.push({label:"卷帙",value:[Z?u(Z):"",ne].filter(Boolean).join(" "),title:(N=e.juan_count)!=null&&N.description?u(e.juan_count.description):void 0}),(I=e.publication_info)!=null&&I.details&&O.push({label:"刊印",value:u(e.publication_info.details)}),(K=e.publication_info)!=null&&K.year&&O.push({label:"年代",value:u(e.publication_info.year)}),O},[e,F,j.rows.length,j.totalVolumes,u,d]),D=(J=e.description)==null?void 0:J.text,E=t.jsx(Vt,{kind:"叢編",title:u(e.title),byline:t.jsx(Ii,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Ie,{items:[e.subtype==="work_collection"?u("作品集"):"",(ee=e.publication_info)!=null&&ee.year?u(e.publication_info.year):""]}),description:D||(ge=e.history)!=null&&ge.length?t.jsxs(t.Fragment,{children:[D&&t.jsx(tt,{text:D,style:{fontSize:15,lineHeight:1.85}}),(se=e.history)!=null&&se.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((O,Z)=>t.jsx("li",{children:u(O)},Z))}):null]}):void 0,clampDescription:ci(D)||(((ie=e.history)==null?void 0:ie.length)??0)>2?6:void 0,facts:G,foot:t.jsx(Yt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),le=[];j.rows.length&&le.push({id:"titles",label:"子目",count:j.rows.length}),T&&le.push({id:"resources",label:"影印與全文",count:T}),P&&le.push({id:"works",label:d.section.containedWorks,count:R.length});const W=t.jsxs(t.Fragment,{children:[j.rows.length>0&&t.jsxs(Te,{id:"titles",title:"子目",meta:t.jsx(Ie,{items:[u(`${j.rows.length} ${d.unit.items}`),j.totalVolumes?u(`全帙 ${j.totalVolumes} ${d.unit.volume}`):"",$.length!==j.rows.length?u(`當前 ${$.length} ${d.unit.items}`):""]}),action:l,children:[j.rows.length>Go&&t.jsx("div",{className:"bim-d-filters bim-d-ui",children:t.jsx("input",{type:"search",className:"bim-d-find",value:f,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:O=>{x(O.target.value),h(!1)}})}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[A&&t.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),t.jsx("th",{children:u("書名")}),t.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),t.jsx("tbody",{children:S.map((O,Z)=>{var xe;const ne=O.id?y.get(O.id):void 0,N=ne!=null&&ne.title&&O.title===O.id?ne.title:O.title,I=((ne==null?void 0:ne.authors)||[]).find(fe=>fe&&fe.name),K=[I?`${I.dynasty?`〔${u(I.dynasty)}〕`:""}${u(I.name)}${I.role?` ${u(I.role)}`:""}`:"",ne!=null&&ne.measure?u(ne.measure):"",(xe=O.subItems)!=null&&xe.length?O.subItems.map(fe=>u(fe)).join("、"):"",(ne!=null&&ne.edition||O.edition)&&!M?u((ne==null?void 0:ne.edition)||O.edition||""):""].filter(Boolean),X=O.volumes.length>0?u(`第 ${fn(O.volumes,d.unit.volume)} ${d.unit.volume}`):O.expected!=null?u(`${O.found??0}/${O.expected} ${d.unit.volume}`):"";return t.jsxs("tr",{children:[A&&t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${X?"":" bim-d-zt-blank"}`,children:X||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsxs("td",{className:"bim-d-zt-main",children:[O.id?t.jsx(ze,{id:O.id,label:u(N),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(N)}),K.length>0?t.jsx(Ie,{items:K}):O.id&&!ne&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ne!=null&&ne.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ne!=null&&ne.versionCount?u(`${ne.versionCount} 種`):""})]},`${O.id??O.title}-${Z}`)})})]}),S.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),$.length>S.length&&t.jsx(Ct,{label:`展開其餘 ${$.length-S.length} ${d.unit.items}`,onClick:()=>h(!0)})]}),T>0&&t.jsxs(Te,{id:"resources",title:"影印與全文",meta:u(`${T} 處`),children:[z.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[z.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:z.text.map((O,Z)=>t.jsx(Ti,{item:O,siblings:z.text},`${O.id||O.url||O.name}-${Z}`))})})]}),t.jsx(Ms,{groups:z.groups})]}),j.rows.length===0&&T===0&&t.jsx(Te,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),Y=P?t.jsx(pt,{id:"works",title:d.section.containedWorks,meta:u(`${R.length} 種`),cap:12,items:R.map(O=>t.jsx(ze,{id:O.id,label:u(O.title),onNavigate:r,renderLink:s,dense:!0}))}):null,re=v?t.jsx(Wr,{caption:"上級叢編",children:t.jsx(ze,{id:v.id,label:u(v.title||v.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(Ut,{railTop:c,back:p,up:re,nav:le,railLinks:a,main:W,card:E,side:Y})},Qp=16,Cn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Uo(e){if(!e)return Cn.length;const n=Cn.indexOf(e);return n===-1?Cn.length:n}const eu={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function Vo(e){return e==null?"":e<0?`前${-e}`:String(e)}const Ds=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:c})=>{var Z,ne;const p=ce(),{convert:a}=U(),[d,u]=g.useState("全部"),[f,x]=g.useState(!1),[m,h]=g.useState("default"),[v,b]=g.useState(new Map),j=g.useMemo(()=>(e.works||[]).map(N=>{const I=v.get(N.work_id);return{id:N.work_id,title:(I==null?void 0:I.title)??N.title??N.work_id,role:N.role||"",cls:si(N.role),versionCount:I==null?void 0:I.versionCount,section:I==null?void 0:I.cls,measure:I==null?void 0:I.measure,hasImage:I==null?void 0:I.hasImage,loaded:!!(I!=null&&I.loaded)}}),[e.works,v]),y=g.useMemo(()=>Cr((e.works||[]).map(N=>N.role)),[e.works]),k=g.useMemo(()=>{const N=d==="全部"?j:j.filter(I=>I.cls===d);return m==="versions"?[...N].sort((I,K)=>(K.versionCount??-1)-(I.versionCount??-1)):N},[j,d,m]),$=f?k:k.slice(0,Qp),S=g.useMemo(()=>$.filter(N=>!v.has(N.id)).map(N=>N.id),[$,v]);g.useEffect(()=>{if(!n||S.length===0)return;let N=!1;return Promise.all(S.map(I=>n.getItem(I).then(K=>{var ke,Q,V,B;const X=K??{},xe=X._edition_count??(((ke=X.books)==null?void 0:ke.length)??0)+(((Q=X.collections)==null?void 0:Q.length)??0),fe=[(V=X.classification)==null?void 0:V.l1,(B=X.classification)==null?void 0:B.l2].filter(Boolean).join(" ");return[I,{id:I,title:X.title,versionCount:xe,loaded:!0,cls:fe||void 0,measure:K&&nt(K,p.unit.juan)||void 0,hasImage:!!(X.has_image??X._has_image)}]}).catch(()=>[I,{id:I,loaded:!0}]))).then(I=>{N||b(K=>{const X=new Map(K);for(const[xe,fe]of I)X.set(xe,fe);return X})}),()=>{N=!0}},[n,S,p.unit.juan]);const _=g.useMemo(()=>{const N=new Map;for(const I of e.alt_names||[]){const K=I.type||p.section.aliases;N.has(K)||N.set(K,[]),N.get(K).push(I.name)}return[...N.entries()].sort((I,K)=>Uo(I[0])-Uo(K[0])).map(([I,K])=>({label:I,names:K}))},[e.alt_names,p]),w=e.birth_year!=null||e.death_year!=null?`${Vo(e.birth_year)||"?"}—${Vo(e.death_year)||"?"}`:"",z=new Set(["本名","字","號","号"]),T=_.filter(N=>z.has(N.label)),R=_.filter(N=>!z.has(N.label)),C=R.reduce((N,I)=>N+I.names.length,0),P=g.useMemo(()=>{const N=[];for(const K of T)N.push({label:K.label,value:K.names.map(X=>a(X)).join("、")});const I=(e.works||[]).length;return I&&N.push({label:"著作",value:`${I} ${a("種")}`}),N},[e.works,T,a]),M=N=>{var I;return(I=_.find(K=>N.includes(K.label)))==null?void 0:I.names[0]},A=M(["字"]),F=M(["號","号"]),G=[A?`字${A}`:"",F?`號${F}`:""].filter(Boolean).join(","),D=e.native_place,E=t.jsx(Vt,{kind:eu[e.subtype]??"人物",title:a(e.primary_name||e.title),subtitle:G?a(G):void 0,meta:t.jsx(Ie,{items:[e.dynasty?a(e.dynasty):"",w,D?a(`${D}人`):""]}),description:(Z=e.description)!=null&&Z.text?t.jsx(tt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ci((ne=e.description)==null?void 0:ne.text)?6:void 0,facts:P,foot:t.jsx(Yt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:C>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:a(`更多別名(${C})`)}),t.jsx("dl",{children:R.map(N=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:a(N.label)}),t.jsx("dd",{children:N.names.map(I=>a(I)).join("、")})]},N.label))})]})}),le=g.useMemo(()=>j.filter(N=>N.loaded&&(N.versionCount??0)>0).sort((N,I)=>(I.versionCount??0)-(N.versionCount??0)).slice(0,3),[j]),W=!!n&&j.length>=3&&$.some(N=>!N.loaded),Y=d==="全部"&&(W||le.length>=2),re=e.external_ids||{},te=[];re.cbdb_id!=null&&te.push({label:"CBDB",id:String(re.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${re.cbdb_id}`,note:re.cbdb_match==="auto"?"自動匹配":void 0});const J=re.wikidata_id;J&&te.push({label:"Wikidata",id:J,href:`https://www.wikidata.org/wiki/${J}`});const ee=re.viaf_id;ee&&te.push({label:"VIAF",id:ee,href:`https://viaf.org/viaf/${ee}`});const ge=y.map(N=>({key:N.cls,label:`${N.label} ${N.count}`})),se=j.length?[{id:"works",label:"著作",count:j.length}]:[],ie=j.length===0?t.jsx(Te,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該人物的關聯作品。")})}):t.jsxs(Te,{id:"works",title:"著作",meta:t.jsx(Ie,{items:[a(`共 ${j.length} 種`),k.length!==j.length?a(`當前 ${k.length} 種`):""]}),children:[Y&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"-6px 0 10px",fontSize:14},children:a("著作舉要")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":W||void 0,children:[W&&[0,1,2].map(N=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},N)),!W&&le.map(N=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(ze,{id:N.id,label:a(N.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx(Ie,{items:[N.section?a(N.section):"",N.measure?a(N.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[a(`${N.versionCount} 種版本`),N.hasImage&&t.jsx("span",{className:"bim-d-flag",children:a("有影印")})]})]},N.id))]})]}),t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ge.length>1&&t.jsx(ai,{items:ge,value:d,onChange:N=>{u(N),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":m==="versions",onClick:()=>{m==="default"&&x(!0),h(N=>N==="default"?"versions":"default")},children:a(m==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("作品")}),t.jsx("th",{children:a("職任")}),t.jsx("th",{children:a("存世版本")}),t.jsx("th",{"aria-label":a("影印")})]})}),t.jsx("tbody",{children:$.map(N=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(ze,{id:N.id,label:a(N.title),onNavigate:i,renderLink:r,dense:!0}),N.section||N.measure?t.jsx(Ie,{items:[N.section?a(N.section):"",N.measure?a(N.measure):""]}):!N.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${N.role?"":" bim-d-zt-blank"}`,children:N.role?a(N.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${N.loaded?"":" bim-d-zt-blank"}`,children:N.loaded?N.versionCount?a(`${N.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:a("未著錄")}):""}),t.jsx("td",{className:N.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:N.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:a("有影印")})})]},N.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a("該職任下的著作尚未著錄。")}),k.length>$.length&&t.jsx(Ct,{label:`展開其餘 ${k.length-$.length} 種著作`,onClick:()=>x(!0)})]}),O=te.length>0?t.jsx(pt,{id:"external",title:"站外資料",items:te.map(N=>t.jsxs("a",{href:N.href,target:"_blank",rel:"noopener noreferrer",children:[N.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:te.map(N=>[N.id,N.note?a(N.note):""].filter(Boolean).join(" · "))}):null;return t.jsx(Ut,{railTop:s,back:l,nav:se,railLinks:c,main:ie,card:E,side:O})},Ri="(max-width: 719px)",tu=`${Ri}, (pointer: coarse)`,Hs=`
681
+ `)){const r=bi(i);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=i.trim();!s||yi.test(s)||n.push({kind:"body",text:i})}return n}function gs(e){if(!e)return[];const n=gn(e);if(n==="unknown")return go(e);const i=[];for(const{heading:r,body:s}of Vc(e)){r&&i.push(r);const l=us(s);if(l.length!==0){if(fs(s)){i.push(...go(s));continue}if(n==="record"){const c=l.join(" ");c&&i.push({kind:"body",text:c})}else for(const c of l){const p=xs(c);p.length&&i.push({kind:"body",text:p.join(" ")})}}}return i}const ms=e=>e;function hs(e,n=ms){if(e.indexOf("《")<0)return n(e);const i=[],r=/《([^《》\n]+)》/g;let s=0,l=0,c;for(;c=r.exec(e);)c.index>s&&i.push(t.jsx(g.Fragment,{children:n(e.slice(s,c.index))},l++)),i.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(c[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=c.index+c[0].length;return s===0?n(e):(s<e.length&&i.push(t.jsx(g.Fragment,{children:n(e.slice(s))},l++)),i)}function ji(e,n={}){const i=n.renderText??ms,r=n.properNames?l=>hs(l,i):i,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Fe(e,r,s)}function mo(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(g.Fragment,{children:n(s)},`${i}-${l}`))}const Sn=/^(#{1,6})\s+(.*)$/,Yc=/^\s*<!--.*-->\s*$/;function bs(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
682
+ `)?"":n)}function Kc(e){return e<=1?2:e===2?3:4}function qc(){let e=1;return n=>{const i=Kc(n),r=Math.min(i,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${i}`}}}function mn(e){return e?gn(bs(e))!=="unknown":!1}function ho({text:e,mode:n,inline:i,dropTitle:r}){const s=bs(e),l=(d,u,f)=>!!r&&f<=1&&d<=2&&u.trim()===r.trim(),c=qc();if(n==="paragraph"&&gn(s)!=="unknown"){const d=gs(s);return t.jsx(t.Fragment,{children:d.map((u,f)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,f))return null;const{Tag:x,className:m}=c(u.level??1);return t.jsx(x,{className:m,children:i(u.text)},f)}return t.jsx("p",{children:mo(u.text,i,f)},f)})})}const p=s.split(`
683
+ `);let a=0;return t.jsx(t.Fragment,{children:p.map((d,u)=>{const f=d.match(Sn);if(f){const m=a++;if(l(f[1].length,f[2],m))return null;const{Tag:h,className:k}=c(f[1].length);return t.jsx(h,{className:k,children:i(f[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Sn.test(p[u-1])&&!Sn.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(Yc.test(d))return null;if(a++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:m,className:h}=c(3);return t.jsx(m,{className:h,children:i(d.trim().slice(2,-2))},u)}return t.jsx("p",{children:mo(d,i,u)},u)})})}function Jc(e){const{convert:n}=Y();return g.useMemo(()=>e?n(e):"",[e,n])}function vi({text:e,mode:n,tables:i=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:c}){const p=Jc(e),{convert:a}=Y(),d=x=>ji(x,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,f=c?a(c):void 0;return!i||p.indexOf(":::")<0?t.jsx(ho,{text:p,mode:n,inline:d,dropTitle:f}):t.jsx(t.Fragment,{children:mi(p).map((x,m)=>x.type==="table"?t.jsx(hi,{table:x.table,opts:u},m):t.jsx(ho,{text:x.text,mode:n,inline:d,dropTitle:m===0?f:void 0},m))})}function ys(e,n){const[i,r]=g.useState(null),[s,l]=g.useState(!1),c=g.useRef(0);return g.useEffect(()=>{const p=++c.current;if(!e||!n){r(null),l(!1);return}let a;try{a=e(n)}catch{r(null),l(!1);return}if(!a||typeof a.then!="function"){r(a??null),l(!1);return}l(!0),a.then(d=>{p===c.current&&r(d??null)}).catch(()=>{p===c.current&&r(null)}).finally(()=>{p===c.current&&l(!1)})},[e,n]),{images:i,loading:s}}const bo={A:"fine",B:"rough",C:"rough",D:"ocr"};function Zc(e){return typeof e!="string"?null:e in Rn?e:e in bo?bo[e]:null}const Xc={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Qc={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function qe(e){return typeof e!="string"?"":Xc[e]??Qc[e]??e}const ed=["〇","一","二","三","四","五","六","七","八","九"],yo=["","十","百","千"],td=["","萬","億"];function ki(e){if(e===0)return"〇";if(e<0)return`負${ki(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(nd(s,r>0)+td[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function nd(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 c=i[l],p=i.length-1-l;c===0?s&&!s.endsWith("〇")&&(s+="〇"):c===1&&p===1&&l===0&&!n?s+=yo[p]:s+=ed[c]+yo[p]}return s.replace(/〇$/,"")}let Dt=null,en=null;const ln=new Set;function id(){return Dt?Promise.resolve():en||(en=import("opencc-js/t2cn").then(e=>{Dt=e.Converter({from:"tw",to:"cn"}),ln.forEach(n=>n())}).catch(()=>{Dt=e=>e,ln.forEach(e=>e())}),en)}const od=e=>e;function mt(){const[,e]=g.useState(0);return g.useEffect(()=>{if(Dt)return;const n=()=>e(i=>i+1);return ln.add(n),id(),()=>{ln.delete(n)}},[]),Dt??od}function _t(e,n){return n(e).toLowerCase()}const rd=o("highlight-bg");function qt(e,n,i){if(!n)return e;const r=_t(n,i);if(!r)return e;const s=_t(e,i);if(s.length!==e.length)return e;const l=[];let c=0,p=0;for(;c<e.length;){const a=s.indexOf(r,c);if(a===-1){l.push(e.slice(c));break}a>c&&l.push(e.slice(c,a)),l.push(t.jsx("mark",{style:{background:rd,padding:0,color:"inherit"},children:e.slice(a,a+r.length)},p++)),c=a+r.length}return t.jsx(t.Fragment,{children:l})}function Si(e,n,i,r){if(!n)return!0;const s=_t(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(c=>typeof c=="string"&&_t(c,r).includes(s))}function sd(e,n,i){return n?_t(e,i).includes(_t(n,i)):!0}const wi={类:o("section-lei"),书:o("section-shu"),序:o("section-xu"),结语:o("section-jieyu"),注释:o("section-zhushi")},ld={考证:o("section-kaozhen")};function ad(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 js(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((s,l)=>s+js(l),0))||0;return n+i}function cd(e,n){const i=[],r=c=>{var p;i.push(...c.files),(p=c.children)==null||p.forEach(r)};if(r(e),i.length===0)return;const s=i.map(c=>n[c]);if(s.every(c=>c===void 0))return;if(s.some(c=>c==="loading"))return"loading";let l=0;for(const c of s)typeof c=="number"&&(l+=c);return l}const dd={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function _i({enabled:e,expanded:n,onClick:i,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...dd,...r},children:s}):t.jsx("span",{style:r,children:s})}function pd({type:e}){const n=qe(e),i=wi[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 ud({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=Y(),s=Ne(),l=mt(),c=k=>k?Fe(r(k),b=>i?qt(b,i,l):b):"",[p,a]=g.useState(!1),d=!!e.summary,u=!!e.comment,f=!!e.additional_comment,x=!!(e.content&&e.content.length>60),m=d||u||f||x;g.useEffect(()=>{i&&a(!0)},[i]);const h=!p&&x?Ur(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[t.jsxs("div",{onClick:()=>m&&a(!p),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:m?"pointer":"default",userSelect:"none",background:o("input-bg")},children:[t.jsxs(_i,{enabled:m,expanded:p,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",c(e.book_title),"》"]}):c(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[ki(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:c(e.author_info||e.author)})]}),!p&&h&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:c(h)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:c(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:o("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:s(e.work_id),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),p&&m&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${o("widget-border")}`,background:o("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"8px"},children:c(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:c(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:c(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:c(e.additional_comment)})]}),x&&!d&&!u&&!f&&t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(e.content)})]})]})}function xd({section:e,highlightQuery:n=""}){const{convert:i}=Y(),r=mt(),s=a=>a?Fe(i(a),d=>n?qt(d,n,r):d):"",[l,c]=g.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(_i,{enabled:p,expanded:l,onClick:()=>c(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(pd,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:s(e.title)}),p&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&p&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${wi[qe(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 fd=100;function $i(e){return qe(e.type)!=="page_header"?!1:(e.content||"").length>=fd}function gd({section:e,highlightQuery:n=""}){const{convert:i}=Y(),r=mt();if(qe(e.type)==="page_header"&&!$i(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
684
+ `)),l=Fe(s,d=>n?qt(d,n,r):d),c=qe(e.type),p=wi[c]||o("desc-fg"),a=c==="序"||c==="结语"||c==="注释";return t.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:o("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${p}40`:void 0,background:a?o("bg"):void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:c}),l]})}function md(e,n,i){const[r,s]=g.useState({});return g.useEffect(()=>{var d;if(!n||e.length===0)return;let l=!1;const c=e.filter(u=>{var f;return!((f=i==null?void 0:i.current)!=null&&f.has(u))}),p={};for(const u of e)(d=i==null?void 0:i.current)!=null&&d.has(u)&&(p[u]=i.current.get(u));if(Object.keys(p).length>0&&s(p),c.length===0)return;const a=async u=>{var f;try{if(n.getEntry){const b=await n.getEntry(u);if(b)return{title:b.title,author:b.author}}const x=await n.getItem(u);if(!x)return null;const m=x.title||u,h=x.authors,k=(f=h==null?void 0:h[0])==null?void 0:f.name;return{title:m,author:k}}catch{return null}};return Promise.all(c.map(async u=>{var x;const f=await a(u);return(x=i==null?void 0:i.current)==null||x.set(u,f),[u,f]})).then(u=>{l||s(f=>{const x={...f};for(const[m,h]of u)x[m]=h;return x})}),()=>{l=!0}},[e.join(","),n]),r}function hd({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=Y(),c=Ne(),p=mt(),a=y=>y?Fe(l(y),v=>s?qt(v,s,p):v):"",[d,u]=g.useState(!1);g.useEffect(()=>{s&&u(!0)},[s]);const f=qe(e.type),x=ld[f]||o("desc-fg"),m=!!e.content,h=e.work_ids||[],k=h.length>1,b=md(k?h:[],i,r),j=m&&!d&&e.content.length>80?Ur(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${o("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>m&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:m?"pointer":"default",userSelect:"none"},children:[t.jsxs(_i,{enabled:m,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg"),lineHeight:1.6},children:e.header_line?a(e.header_line):a(e.title)}),!d&&j&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:a(j)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[h.length===1&&n&&t.jsx("a",{href:c(h[0]),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(h[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:[h.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:f})]})]}),k&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:h.map(y=>{const v=b[y],$=v?`${l(v.title)}${v.author?`(${l(v.author)})`:""}`:y.slice(0,8)+"…";return t.jsxs("a",{href:c(y),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(y))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",$]},y)})}),d&&m&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:o("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${o("widget-border")}`,fontSize:"12px",color:o("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:a(e.comment)})]})]})}function bd({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=mt(),c=n.trim(),p=g.useMemo(()=>c?e.sections.filter(a=>Si(a,c,!0,l)):e.sections,[e.sections,c,l]);return t.jsxs("div",{children:[t.jsx("div",{children:p.map((a,d)=>t.jsx(hd,{section:a,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:c},d))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function yd(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function jd({sections:e,onNavigate:n,inline:i}){const r=Ne(),{convert:s}=Y(),l=yd();return t.jsx(t.Fragment,{children:e.map((c,p)=>{const a=qe(c.type);if(a==="page_header"&&!$i(c))return null;if(a==="类")return t.jsxs(g.Fragment,{children:[g.createElement(l("类"),null,i(s(c.title))),c.content&&t.jsx("p",{children:i(s(c.content))})]},p);if(a==="书"||a==="诗"||a==="考证"||a==="注释"){const d=c.book_title?`《${c.book_title}》${c.n_juan!=null?ki(c.n_juan)+"卷":""}`:c.title,u=i(s(d));return t.jsxs("section",{className:"bim-rd-entry",children:[g.createElement(l("条目"),{className:"bim-rd-entry-h"},c.work_id&&n?t.jsx("a",{href:r(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(c.work_id))},title:"查看作品",children:u}):u),c.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(c.author_info))}),c.content&&c.content.split(/\n+/).map((f,x)=>t.jsx("p",{children:i(s(f))},x)),c.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(c.summary))]}),c.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(c.comment))]}),c.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(c.additional_comment))]})]},p)}return c.content?t.jsx("p",{children:i(s(c.content))},p):null})})}function vd(e){return e.some(n=>{const i=qe(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&$i(n)})}function kd({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:c,workLabelCache:p,prefs:a}){var M;const{convert:d}=Y(),u=mt(),[f,x]=g.useState("text"),m=s.trim(),h=(r==null?void 0:r.type)==="kaozhen",k=g.useCallback(A=>m?qt(A,m,u):A,[m,u]),b=A=>ji(A,{renderText:k,properNames:a.properNames}),j=g.useMemo(()=>m?e.sections.filter(A=>Si(A,m,h,u)):e.sections,[e.sections,m,h,u]),y=(A,F)=>F.filter(G=>qe(G.type)===A).length,v=y("书",e.sections),$=y("诗",e.sections),S=y("考证",e.sections);let _="";h?_=m?`${y("考证",j)} / ${S} ${d("條")}`:`${S} ${d("條")}`:$>0?_=m?`${y("诗",j)} / ${$} 首`:`${$} 首`:v>0&&(_=m?`${y("书",j)} / ${v} ${d("部書")}`:`${v} ${d("部書")}`);const w=r!=null&&r.text_quality?Zc(r.text_quality.grade):null,z=[];i&&z.push(i),_&&z.push(_),h&&(r!=null&&r.target_source)&&z.push(t.jsxs(t.Fragment,{children:[d("考證對象")," ",d(r.target_source)]})),w&&z.push(t.jsx("span",{title:bl[w],children:(M=r==null?void 0:r.text_quality)!=null&&M.source_note?t.jsxs(t.Fragment,{children:["底本 ",d(r.text_quality.source_note),"(",d(Rn[w]),")"]}):t.jsxs(t.Fragment,{children:[d("文本質量")," ",d(Rn[w])]})})),e.source_url&&z.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:d("原文來源")}));const T=!h&&vd(e.sections),R=!!n&&(!T||a.readingMode==="paragraph"&&mn(n)),C=!h&&(T||!!n),O=h||!C?"entries":f;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:d(e.title)}),z.length>0&&t.jsx("p",{className:"bim-rd-meta",children:z.map((A,F)=>t.jsxs(g.Fragment,{children:[F>0&&t.jsx("span",{className:"bim-rd-dot"}),A]},F))}),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":O==="text",onClick:()=>x("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":O==="entries",onClick:()=>x("entries"),children:d("條目")})]})]}),O==="text"&&t.jsx("article",{className:"bim-rd-prose",children:R?t.jsx(vi,{text:n,mode:a.readingMode,properNames:a.properNames,renderText:k,dropTitle:e.title}):t.jsx(jd,{sections:e.sections,onNavigate:l,inline:b})}),O==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:h?t.jsx(bd,{juan:e,searchQuery:s,onNavigate:l,transport:c,workLabelCache:p}):t.jsxs(t.Fragment,{children:[j.map((A,F)=>{const G=qe(A.type);return G==="书"||G==="诗"||G==="考证"?t.jsx(ud,{section:A,onNavigate:l,highlightQuery:m},F):G==="类"?t.jsx(xd,{section:A,highlightQuery:m},F):t.jsx(gd,{section:A,highlightQuery:m},F)}),j.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function vs(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 Sd(e){const n=vs(e);return n.length>0?n[0]:null}function wd(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:c,query:p,isKaozhen:a}=e,d=mt(),u=g.useRef(new Map),[f,x]=g.useState({}),[m,h]=g.useState({}),k=g.useCallback((j,y)=>{const v=y==null?void 0:y.title;v&&h($=>$[j]===v?$:{...$,[j]:v})},[]);g.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:c}),k(s,l))},[s,l,c,k]),g.useEffect(()=>{u.current.clear(),x({}),h({})},[n]);const b=g.useCallback((j,y)=>{let v=0;if(j.juan)for(const $ of j.juan.sections)Si($,y,a,d)&&v++;return v===0&&j.rawText&&sd(j.rawText,y,d)&&(v=1),v},[a,d]);return g.useEffect(()=>{const j=p.trim();if(!j){x({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let y=!1;const v={},$=[];for(const T of r){const R=u.current.get(T);R?v[T]=b(R,j):(v[T]="loading",$.push(T))}x(v);const S=8;let _=0;const w=async()=>{var T;for(;_<$.length;){if(y)return;const R=_++,C=$[R];try{const[O,M]=await Promise.all([i.getCollatedJuan(n,C),((T=i.getCollatedJuanText)==null?void 0:T.call(i,n,C))??Promise.resolve(null)]),A={juan:O,rawText:M};if(u.current.set(C,A),k(C,O),y)return;x(F=>({...F,[C]:b(A,j)}))}catch{if(y)return;x(O=>({...O,[C]:0}))}}},z=Array.from({length:Math.min(S,$.length)},()=>w());return Promise.all(z),()=>{y=!0}},[p,n,i,r.join(","),b,d,k]),{matchStates:f,titles:m}}const zi=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:c,style:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m})=>{const[h,k]=g.useState(null),[b,j]=g.useState(!1),[y,v]=g.useState(null),[$,S]=g.useState(null),[_,w]=g.useState(null),[z,T]=g.useState(!1),[R,C]=g.useState(null),[O,M]=g.useState(""),A=g.useRef(new Map),F=g.useRef(0),G=s??$,U=g.useCallback(V=>{S(V),l==null||l(V)},[l]),E=e||h;g.useEffect(()=>{e&&(j(!1),v(null))},[e]),g.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let V=!1;return j(!0),v(null),i.getCollatedEditionIndex(n).then(q=>{V||(q?k(q):v("未找到整理本数据"))}).catch(q=>{V||v(q instanceof Error?q.message:"加载失败")}).finally(()=>{V||j(!1)}),()=>{V=!0}},[e,n,i]),g.useEffect(()=>{if(E&&!G){const V=Sd(E);V&&U(V)}},[E,G,U]);const ie=n||(E==null?void 0:E.work_id),P=g.useCallback(async V=>{var xe;if(!ie||!(i!=null&&i.getCollatedJuan))return;const q=++F.current;T(!0),w(null),C(null);try{const[oe,ne]=await Promise.all([i.getCollatedJuan(ie,V),((xe=i.getCollatedJuanText)==null?void 0:xe.call(i,ie,V))??Promise.resolve(null)]);if(q!==F.current)return;w(oe),C(ne)}catch{if(q!==F.current)return;w(null),C(null)}finally{q===F.current&&T(!1)}},[ie,i]);g.useEffect(()=>{G&&P(G)},[G,P]);const re=V=>{U(V)};if(b)return t.jsx("div",{className:c,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(y)return t.jsx("div",{className:c,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:y});if(!E)return null;const ce=E.type==="kaozhen",K=vs(E);return t.jsx($d,{className:c,style:p,index:E,allFiles:K,isKaozhen:ce,effectiveWorkId:ie,transport:i,activeFile:G,handleSelectFile:re,juanData:_,juanRawText:R,juanLoading:z,searchQuery:O,setSearchQuery:M,onNavigate:r,workLabelCacheRef:A,reader:{title:a,subtitle:d,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m}})};function ks(e,n,i,r){var d,u,f,x;const s=(u=(d=n.juan_metadata)==null?void 0:d[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:ad(e)),p=((x=(f=n.files)==null?void 0:f.find(m=>m.filename===e))==null?void 0:x.title)??i[e];if(!p)return{position:l,label:l};const a=r(p);return{position:l,label:l===p||l===a?a:`${l} ${a}`}}function _d(e,n,i,r,s){const l=a=>a==="loading"?"…":typeof a=="number"&&a>0?a:void 0,c=(a,d)=>({key:a,label:d??ks(a,e,r,s).label,hint:l(i[a]),disabled:i[a]===0}),p=(a,d)=>{var f;if(a.files.length===1&&!((f=a.children)!=null&&f.length))return c(a.files[0],s(a.label));const u=cd(a,i);return{key:`group:${d}`,label:s(a.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:js(a),defaultExpanded:typeof u=="number"&&u>0,children:[...a.files.map(x=>c(x)),...(a.children??[]).map((x,m)=>p(x,`${d}.${m}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((a,d)=>p(a,`${d}`)):n.map(a=>c(a))}const $d=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:c,activeFile:p,handleSelectFile:a,juanData:d,juanRawText:u,juanLoading:f,searchQuery:x,setSearchQuery:m,onNavigate:h,workLabelCacheRef:k,reader:b})=>{const{convert:j}=Y(),[y,v]=fi(),{matchStates:$,titles:S}=wd({workId:l,transport:c,files:r,activeFile:p,activeJuan:d,activeRawText:u,query:x,isKaozhen:s}),_=ys(b.resolveImages,p),w=g.useMemo(()=>_d(i,r,$,S,j),[i,r,$,S,j]),z=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:C=>m(C.target.value)}),T=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(C=>C.vol_label)?"冊":"卷",R=p?ks(p,i,S,j).position:void 0;return t.jsxs(gi,{className:e,style:n,title:b.title??(i.title?j(i.title):void 0),subtitle:b.subtitle??j(s?"考證":"整理本"),toc:w,tocCaption:`目录 · ${r.length} ${j(T)}`,tocHeader:z,activeKey:p,onSelect:a,images:_.images,imagesLoading:_.loading,renderImageOverlay:b.renderImageOverlay,imagePanel:b.imagePanel,prefs:y,onPrefsChange:v,paragraphToggle:!s&&mn(u),allowVertical:b.allowVertical,children:[f?t.jsx(gt,{}):d?t.jsx(kd,{juan:d,rawText:u,positionLabel:R,index:i,searchQuery:x,onNavigate:h,transport:c,workLabelCache:k,prefs:y},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,i.references&&i.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:j("參考文獻")}),t.jsx("ol",{children:i.references.map((C,O)=>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]})]},O))})]})]})},zd={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},Cd={label:"其他",color:o("desc-fg")},Id={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")}},Td={label:"待处理",color:o("warning")};function Rd(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 Ed(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 Ci=({items:e,loading:n})=>{const i=Ne();return n?t.jsx(gt,{}):e.length===0?t.jsx("div",{style:Nd,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=zd[r.type]||Cd,l=Id[r.status]||Td,c=typeof window<"u"&&Ed(r.pageUrl,window.location.href);return t.jsxs("div",{style:Ld,children:[t.jsxs("div",{style:Bd,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...jo,background:s.color},children:s.label}),t.jsx("span",{style:{...jo,background:l.color},children:l.label})]}),t.jsx("span",{style:Ad,children:Rd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:Wd,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:wn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(c?t.jsx("a",{href:r.pageUrl,style:wn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:wn,children:r.pageUrl}))]}),t.jsx("div",{style:Md,children:r.content}),r.reply&&t.jsxs("div",{style:Fd,children:[t.jsx("div",{style:Pd,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Nd={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"},Bd={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},jo={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Ad={fontSize:"12px",color:o("desc-fg")},Wd={fontSize:"12px",marginBottom:"6px"},wn={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},Md={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},Fd={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},Pd={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},Hn=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const c=ae(),[p,a]=g.useState(null),[d,u]=g.useState([]),[f,x]=g.useState("recommend"),[m,h]=g.useState([]),[k,b]=g.useState(!1),j=r??f,y=F=>{x(F),s==null||s(F)},[v,$]=g.useState(!0),[S,_]=g.useState(null),[w,z]=g.useState(null),[T,R]=g.useState(null);g.useEffect(()=>{let F=!1;if(e.getCounts)return e.getCounts().then(G=>{F||a({works:G.works,books:G.books,collections:G.collections})}).catch(()=>{}),()=>{F=!0}},[e]),g.useEffect(()=>{let F=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const U=await e.getRecommended();if(U!=null&&U.groups)return U.groups.flatMap(E=>E.items.map(ie=>({...ie,group:E.name})))}catch{}return[]})().then(async U=>{if(F)return;const E=U.filter(P=>P.id);if(E.length===0){$(!1);return}const ie=await Promise.all(E.map(async P=>{if(P.type)return{id:P.id,title:P.title,type:P.type,author:P.author,dynasty:P.dynasty,role:P.role,edition:P.edition,has_text:P.has_text,has_image:P.has_image,has_collated:P.has_collated,subtype:P.subtype,primary_name:P.primary_name,group:P.group,fallbackDescription:P.description};try{let re=null;if(e.getEntry)re=await e.getEntry(P.id);else{const ce=await e.getItem(P.id);ce&&(re={id:P.id,title:ce.title||P.id,type:ce.type||"work"})}if(re)return{...re,group:P.group,fallbackDescription:P.description}}catch{}return{id:P.id,title:P.title,type:he.extractType(P.id),group:P.group,fallbackDescription:P.description}}));F||(u(ie.filter(P=>P!==null)),$(!1))}),()=>{F=!0}},[e,i]);const C=g.useRef(!1),O=g.useRef(!1),M=g.useRef(!1);g.useEffect(()=>{if(j!=="catalog"||C.current)return;const F=e.getCatalogProgress??e.getResourceProgress;if(!F)return;C.current=!0;let G=!1;return F.call(e).then(U=>{G||_(U)}).catch(()=>{C.current=!1}),()=>{G=!0}},[e,j]),g.useEffect(()=>{if(j!=="collection"||O.current||!e.getCollectionProgress)return;O.current=!0;let F=!1;return e.getCollectionProgress().then(G=>{F||z(G)}).catch(()=>{O.current=!1}),()=>{F=!0}},[e,j]),g.useEffect(()=>{if(j!=="site"||M.current||!e.getSiteProgress)return;M.current=!0;let F=!1;return e.getSiteProgress().then(G=>{F||R(G)}).catch(()=>{M.current=!1}),()=>{F=!0}},[e,j]),g.useEffect(()=>{if(!l||j!=="feedback")return;let F=!1;return b(!0),fetch(l).then(G=>G.json()).then(G=>{!F&&G.success&&h(G.items||[])}).catch(()=>{}).finally(()=>{F||b(!1)}),()=>{F=!0}},[l,j]);const A=F=>{switch(F){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(Bt,{label:c.home.recommendTab,active:j==="recommend",onClick:()=>y("recommend")}),t.jsx(Bt,{label:c.home.catalogTab,active:j==="catalog",onClick:()=>y("catalog")}),t.jsx(Bt,{label:c.home.collectionTab,active:j==="collection",onClick:()=>y("collection")}),t.jsx(Bt,{label:c.home.siteTab,active:j==="site",onClick:()=>y("site")}),l&&t.jsx(Bt,{label:c.home.feedbackTab,active:j==="feedback",onClick:()=>y("feedback")})]}),j==="recommend"&&t.jsx(Od,{recommended:d,loading:v,onNavigate:n,getIcon:A,t:c}),j==="catalog"&&t.jsx(vo,{progress:S,t:c,onNavigate:n}),j==="collection"&&t.jsx(vo,{progress:w,t:c,onNavigate:n}),j==="site"&&t.jsx(Hd,{progress:T,t:c,totalWorks:(p==null?void 0:p.works)??0}),j==="feedback"&&l&&t.jsx(Ci,{items:m,loading:k})]})})},Bt=({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}),Od=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=Ne();if(n)return t.jsx(gt,{});if(e.length===0)return null;const c=new Map;for(const p of e){const a=p.group||s.home.recommendedBrowse;c.has(a)||c.set(a,[]),c.get(a).push(p)}return t.jsx(t.Fragment,{children:Array.from(c.entries()).map(([p,a])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:p}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return t.jsxs("a",{href:l(d.id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),i==null||i(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,cursor:"pointer",background:o("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},vo=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(gt,{});const r=[...e.resources].sort((p,a)=>p.priority-a.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},c={in_progress:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(p=>{const a=r.filter(d=>d.status===p);return a.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:c[p]}}),l[p]," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>t.jsx(Dd,{item:d,t:n,statusColor:c[p],onNavigate:i},d.id))})]},p)})})},Dd=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=Ne(),l=e.total>0?Math.round(e.imported/e.total*100):0,c=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=e.edition?`${e.name}·${e.edition}`:e.name,a=e.collection_id||e.work_id;return a&&r?t.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:p}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:o("widget-border"),color:o("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:c})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Gt(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(gt,{});const r=[...e.resources].sort((a,d)=>a.priority-d.priority),s=r.filter(a=>a.imported>0),l=r.filter(a=>a.imported===0),c=s.reduce((a,d)=>Math.max(a,d.imported),0),p=i>0?Math.round(c/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:c.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>t.jsx(ko,{item:a,t:n,totalWorks:i},a.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(a=>t.jsx(ko,{item:a,t:n,totalWorks:i},a.id))})]})]})},ko=({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})]})},So="(max-width: 768px)";function Gd(){const[e,n]=g.useState(()=>typeof window>"u"?!1:window.matchMedia(So).matches);return g.useEffect(()=>{const i=window.matchMedia(So),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),e}const Ud=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var G;const l=ae(),{convert:c}=Y(),p=Gd(),[a,d]=g.useState(null),[u,f]=g.useState(null),[x,m]=g.useState(!1),[h,k]=g.useState("detail"),[b,j]=g.useState([]),[y,v]=g.useState(!1),[$,S]=g.useState(null),[_,w]=g.useState(!1),z=g.useCallback(async U=>{if(!e.getCollatedEditionIndex){S(null);return}w(!0);try{const E=await e.getCollatedEditionIndex(U);S(E)}catch{S(null)}finally{w(!1)}},[e]),T=g.useCallback(async U=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){j([]);return}v(!0);try{if(e.getCollectionCatalogs){const E=await e.getCollectionCatalogs(U);j(E||[])}else if(e.getCollectionCatalog){const E=await e.getCollectionCatalog(U);j(E?[{resource_id:"",data:E}]:[])}}catch{j([])}finally{v(!1)}},[e]),R=g.useCallback(async U=>{if(i){i(U);return}d(U),f(null),j([]),S(null),k("detail"),m(!0);try{const E=await e.getItem(U.id);E&&(f(E),E.type==="collection"?T(U.id):E.type==="work"&&E.has_collated&&z(U.id))}catch(E){console.error("加载详情失败:",E)}finally{m(!1)}},[e,i,T,z]),C=g.useCallback(async U=>{f(null),j([]),S(null),k("detail"),m(!0);try{const E=await e.getItem(U);E&&(f(E),d({id:U,title:E.title||U,type:E.type||"book"}),E.type==="collection"?T(U):E.type==="work"&&E.has_collated&&z(U))}catch(E){console.error("导航失败:",E)}finally{m(!1)}},[e,T,z]),O=(u==null?void 0:u.type)==="collection"&&(b.length>0||y)||(u==null?void 0:u.type)==="work"&&($||_),M=p&&(x||u),A=g.useCallback(()=>{d(null),f(null),j([]),S(null),k("detail")},[]),F=t.jsx(t.Fragment,{children:x?t.jsx(gt,{}):u?t.jsxs(t.Fragment,{children:[(O||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${o("widget-border")}`,padding:p?"0 12px":"0 48px",background:o("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[O&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>k("detail"),style:tn(h==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&y&&b.length===0&&t.jsxs("button",{onClick:()=>{},style:tn(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&b.map(U=>t.jsx("button",{onClick:()=>k(`catalog:${U.resource_id}`),style:tn(h===`catalog:${U.resource_id}`),children:U.short_name?`${c(U.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},U.resource_id)),u.type==="work"&&($||_)&&t.jsxs("button",{onClick:()=>k("collated"),style:tn(h==="collated"),children:[l.detailTab.collatedEdition,_&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:h==="detail"?t.jsx(ti,{data:u,transport:e,onNavigate:C}):h.startsWith("catalog:")?t.jsx(ni,{data:(G=b.find(U=>`catalog:${U.resource_id}`===h))==null?void 0:G.data,onNavigate:C}):h==="collated"?t.jsx(zi,{index:$||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(Hn,{transport:e,onNavigate:C,recommendedIds:r})});return p?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:M?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${o("widget-border")}`,background:o("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:A,style:{padding:"4px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:F})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Nn,{transport:e,onEntryClick:R,hideModeIndicator:n}),!u&&t.jsx(Hn,{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(Nn,{transport:e,onEntryClick:R,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:F})]})};function tn(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 st(e){return e.replace(/\.md$/,"")}function wo(e){let n="";if(e.source_url)try{const r=new URL(e.source_url).pathname.split("/").filter(Boolean).pop()??"";n=decodeURIComponent(r).replace(/_/g," ")}catch{}return[e.source_name,n||e.version_label].filter(Boolean).join(" · ")||e.key}const _o={padding:24,color:o("desc-fg")},Gn=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:c,onVersionChange:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m,className:h,style:k})=>{const[b,j]=g.useState(e??null),[y,v]=g.useState(!1),[$,S]=g.useState(null),_=r!==void 0?r:$,w=g.useCallback(K=>{s?s(K):S(K)},[s]),[z,T]=g.useState(null),[R,C]=g.useState(!1);g.useEffect(()=>{e&&j(e)},[e]),g.useEffect(()=>{if(e)return;j(null),v(!1);const K=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!K){v(!0);return}let V=!1;return Promise.resolve().then(K).then(q=>{V||(q?j(q):v(!0))}).catch(()=>{V||v(!0)}),()=>{V=!0}},[n,i,e,l]),g.useEffect(()=>{if(!b||b.chapters.length===0)return;const K=st(b.chapters[0].file);if(!_){w(K);return}const V=st(_);b.chapters.some(xe=>st(xe.file)===V)||w(K)},[b,_,w]);const O=g.useMemo(()=>{if(!b||!_)return null;const K=st(_);return b.chapters.find(V=>st(V.file)===K)??null},[b,_]);g.useEffect(()=>{if(!n||!O)return;const K=l!==void 0?i.getWorkFullTextChapter?q=>i.getWorkFullTextChapter(n,l,q):null:i.getBookFullTextChapter?q=>i.getBookFullTextChapter(n,q):null;if(!K)return;let V=!1;return C(!0),T(null),Promise.resolve(O.file).then(K).then(q=>{V||T(q)}).catch(()=>{V||T(null)}).finally(()=>{V||C(!1)}),()=>{V=!0}},[n,O,i,l]);const M=ys(u,O?st(O.file):null),[A,F]=fi(),{convert:G}=Y(),U=!!(c&&c.length>1&&p),E=g.useMemo(()=>U?os(c).map((K,V)=>({...K,label:wo(c[V])})):void 0,[U,c]),ie=U?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:K=>p(K.target.value),children:c.map(K=>t.jsx("option",{value:K.key,children:wo(K)},K.key))})]}):null;if(!b)return t.jsxs("div",{style:_o,children:[ie&&t.jsx("div",{style:{marginBottom:12},children:ie}),y?"无法加载全文目录":"加载全文目录…"]});if(b.chapters.length===0)return t.jsxs("div",{style:_o,children:[ie&&t.jsx("div",{style:{marginBottom:12},children:ie}),"全文目录为空"]});const P=b.chapters.map(K=>({key:st(K.file),label:G(K.title)})),re=as(b)||An(b),ce=z?z.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(gi,{title:a??G(b.version_label),subtitle:d??"全文",toc:P,tocCaption:`目录 · ${b.chapters.length} ${b.chapters.length>1?"卷":"篇"}`,activeKey:_?st(_):null,onSelect:w,images:M.images,imagesLoading:M.loading,renderImageOverlay:f,imagePanel:x,prefs:A,onPrefsChange:F,versions:E,currentVersionKey:E?l??null:void 0,onVersionChange:E?p:void 0,versionSource:!1,paragraphToggle:mn(ce),allowVertical:m,className:h,style:k,children:[O&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:G(O.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:b.source.url,target:"_blank",rel:"noreferrer",children:G(b.source.name)}),b.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),b.source.license]})]})]}),R&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!R&&ce!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(vi,{text:ce,mode:A.readingMode,tables:re,gujiMarkdown:An(b),properNames:A.properNames})}),!R&&!z&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},Vd=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=ae(),{convert:l}=Y(),[c,p]=g.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[a,d]=g.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(f=>t.jsx(Yd,{division:f,expanded:c===f.name,onToggle:()=>p(c===f.name?null:f.name),expandedCat:a,onCatToggle:x=>d(a===x?null:x),onNavigate:n},f.name))})]})},Yd=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:c}=Y(),p=e.categories.reduce((a,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return a+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${o("primary")} 6%, transparent)`:o("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:o("fg"),textAlign:"left"},children:[t.jsx("span",{children:c(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg")},children:[e.categories.length," 類 · ",p," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(a=>{const d=`${e.name}/${a.name}`;return t.jsx(Kd,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:l},a.name)})})]})},Kd=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var a,d,u,f;const{convert:s}=Y(),l=((a=e.books)==null?void 0:a.zhulu)||[],c=((d=e.books)==null?void 0:d.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((f=e.stats)==null?void 0:f.cunmu)||c.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?o("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:o("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||c.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx($o,{label:"著錄",books:l,onNavigate:r}),c.length>0&&t.jsx($o,{label:"存目",books:c,onNavigate:r})]})]})},$o=({label:e,books:n,onNavigate:i})=>{const{convert:r}=Y(),s=Ne(),[l,c]=g.useState(n.length<=20),p=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((a,d)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:o("fg")},children:a.work_id&&i?t.jsx("a",{href:s(a.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},children:r(a.title)}):r(a.title)}),a.volumes&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.volumes)}),a.author&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.author).slice(0,20)})]},d))}),!l&&t.jsxs("button",{onClick:()=>c(!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," 條"]})]})},Oe=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=ae();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:Jd,children:"AI"}),n&&t.jsx("button",{onClick:n,style:qd,children:l.action.save})]})]}),s]})},qd={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Jd={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Me=({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"}})]}),xt=({value:e,onChange:n,placeholder:i})=>{const r=g.useRef(null);return g.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"}})},an=({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 Zd(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const nn=({value:e,onChange:n,label:i})=>{const[r,s]=g.useState(!1),l=g.useRef(null),c=Zd(e||"");return g.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&c?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:zo,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:c.name}),t.jsx(an,{children:c.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:zo,children:i}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},zo={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function Xd(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function Qd(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ss=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=ae(),[s,l]=g.useState(null),c=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},p=f=>{n(e.filter((x,m)=>m!==f)),s===f&&l(null)},a=(f,x,m)=>{const h=[...e];h[f]={...h[f],[x]:m},n(h)},d=(f,x)=>{const m=[...e];m[f]={...m[f],type:x,id:"",name:""},n(m),x==="bookID"&&i&&i(h=>{const k=[...e];k[f]={...k[f],id:h.id,name:h.title,type:"bookID"},n(k)})},u=f=>{i&&i(x=>{const m=[...e];m[f]={...m[f],id:x.id,name:x.title,type:"bookID"},n(m)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((f,x)=>t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===x?null:x),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===x?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:o("fg")},children:f.name||`${r.editor.sourcePlaceholder} ${x+1}`}),f.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Xd(f.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:Qd(f.type)}),t.jsx("button",{onClick:m=>{m.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===x&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!f.type&&t.jsxs("div",{children:[t.jsx("label",{style:Qe,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>d(x,"bookID"),style:{...Co,borderColor:o("source-bookid"),color:o("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>d(x,"url"),style:{...Co,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})]})]})]}),f.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:Qe,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Io,children:r.action.changeType})]}),f.id&&f.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:f.name}),t.jsx("code",{style:{fontSize:"11px",background:o("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:f.id})]}),t.jsx("button",{onClick:()=>u(x),style:{background:"transparent",border:`1px solid ${o("widget-border")}`,color:o("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(x),style:{width:"100%",padding:"14px",border:`2px dashed ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),f.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:Qe,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Io,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:f.name,onChange:m=>a(x,"name",m.target.value),placeholder:r.editor.sourceNamePlaceholder,style:ht})]}),t.jsxs("div",{children:[t.jsx("label",{style:Qe,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:f.id,onChange:m=>a(x,"id",m.target.value),placeholder:"https://...",style:ht})]})]}),f.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:{...Qe,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:Qe,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:f.details,onChange:m=>a(x,"details",m.target.value),placeholder:r.editor.detailsPlaceholder,style:ht})]}),t.jsxs("div",{children:[t.jsx("label",{style:Qe,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:f.position,onChange:m=>a(x,"position",m.target.value),placeholder:"如: 卷三, p.52",style:ht})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:Qe,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:f.version,onChange:m=>a(x,"version",m.target.value),placeholder:"如: v1.0, 2024-01",style:ht})]}),t.jsxs("div",{children:[t.jsx("label",{style:Qe,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:f.processor_version,onChange:m=>a(x,"processor_version",m.target.value),placeholder:"如: v0.1",style:ht})]})]})]})]})})]},x)),t.jsxs("button",{onClick:c,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})]})]})},Qe={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},ht={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"},Co={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"},Io={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function ws(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 _s(e){return!e||e.length===0?"":JSON.stringify(e)}const $s=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:c,childWorks:p,childCollections:a,containedBooks:d,siblingBooks:u,onLinkEntity:f,onUnlinkEntity:x,onViewEntity:m,onCreateAndLink:h,onSaveRelations:k})=>{const b=ae();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:b.section.relations})]}),k&&t.jsx("button",{onClick:k,style:ep,children:b.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(At,{direction:"up",title:b.relation.belongsToWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>f("workId","work"),onCreate:()=>h("workId","work",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),t.jsx(At,{direction:"up",title:b.relation.containedInCollection,entity:c,onView:m,onUnlink:()=>x("collectionId"),onLink:()=>f("collectionId","collection"),onCreate:()=>h("collectionId","collection",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),l&&u&&u.length>0&&t.jsx(bt,{direction:"horizontal",title:`${b.relation.siblingVersions} (${u.length})`,entities:u,onView:m,onAdd:()=>h("siblingBook","book",{workId:l.id}),addLabel:b.relation.addVersionForWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(At,{direction:"up",title:b.relation.parentWork,entity:r,onView:m,onUnlink:()=>x("parentWorkId"),onLink:()=>f("parentWorkId","work"),onCreate:()=>h("parentWorkId","work"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),p&&p.length>0&&t.jsx(bt,{direction:"down",title:`${b.relation.childWorks} (${p.length})`,entities:p,onView:m,onAdd:()=>h("childWork","work",{parentWorkId:n}),addLabel:b.action.addSubWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),a&&a.length>0&&t.jsx(bt,{direction:"down",title:`${b.relation.collectionImpl} (${a.length})`,entities:a,onView:m,onAdd:()=>h("childCollection","collection",{workId:n}),addLabel:b.action.addCollectionImpl,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),t.jsx(bt,{direction:"down",title:`${b.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>h("childBook","book",{workId:n}),addLabel:b.action.addVersion,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(At,{direction:"up",title:b.relation.correspondingWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>f("workId","work"),onCreate:()=>h("workId","work",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),t.jsx(At,{direction:"up",title:b.relation.parentCollection,entity:s,onView:m,onUnlink:()=>x("parentCollectionId"),onLink:()=>f("parentCollectionId","collection"),onCreate:()=>h("parentCollectionId","collection"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),t.jsx(bt,{direction:"down",title:`${b.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:m,onAdd:()=>h("childCollection","collection",{parentCollectionId:n}),addLabel:b.action.addSubCollection,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),t.jsx(bt,{direction:"down",title:`${b.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>h("childBook","book",{collectionId:n}),addLabel:b.action.addBook,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]})]})]})},At=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:c,linkLabel:p,createLabel:a,notLinkedLabel:d,viewLabel:u,unlinkLabel:f})=>{const x=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:o("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:zs(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(To,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(To,{onClick:s,title:f,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(Un,{onClick:l,children:p}),t.jsx(Un,{onClick:c,primary:!0,children:a})]})]})},bt=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:c,expandMoreLabel:p})=>{const[a,d]=g.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),f=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=a?i:i.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:f}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[x.map(m=>t.jsxs("div",{onClick:()=>r(m),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:o("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:zs(m.type)}),t.jsx("span",{children:m.title})]},m.id)),i.length>5&&!a&&t.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:o("link-fg"),cursor:"pointer"},children:[p," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:c}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(Un,{onClick:s,primary:!0,children:["+ ",l]})})]})},To=({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}),Un=({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 zs(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const ep={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Cs=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:c,onSearch:p,isLoading:a,excludeId:d})=>{const[u,f]=g.useState(""),x=d?c.filter(b=>b.id!==d):c;g.useEffect(()=>{e&&(f(""),p(""))},[e]);const m=b=>{f(b),p(b)};if(!e)return null;const h=n==="work"?"作品":n==="book"?"书籍":"丛编",k=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:tp,children:t.jsxs("div",{style:np,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:ip,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:b=>m(b.target.value),placeholder:`搜索${h}名称或 ID...`,autoFocus:!0,style:op})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?t.jsx("div",{style:_n,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(b=>t.jsxs("div",{onClick:()=>r(b),style:rp,children:[t.jsx("span",{style:{fontSize:"16px"},children:k}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[b.title,b.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:b.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[b.id,b.author&&` · ${b.author}`,b.dynasty&&` · ${b.dynasty}`]})]})]},b.id))}):u?t.jsxs("div",{style:_n,children:["未找到匹配的",h]}):t.jsxs("div",{style:_n,children:["输入关键词搜索",h]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:l,style:sp,children:["创建新",h,"并关联"]})]})]})})},tp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},np={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")},ip={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},op={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"},rp={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:o("primary-soft")},_n={padding:"20px",textAlign:"center",color:o("desc-fg")},sp={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Ro={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},lp={work:"📜",book:"📖",collection:"📚",entity:"👤"},Is=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[c,p]=g.useState(""),a=g.useRef(null);g.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,m;(x=a.current)==null||x.focus(),(m=a.current)==null||m.select()},100))},[e,r==null?void 0:r.title]);const d=x=>{x.key==="Enter"&&c.trim()?u():x.key==="Escape"&&l()},u=()=>{c.trim()&&s(c.trim(),{...r,title:c.trim()})};if(!e)return null;const f=()=>{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`创建新${Ro[n]}`}};return t.jsx("div",{style:ap,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:cp,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:lp[n]}),t.jsx("span",{children:f()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:o("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:o("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:a,type:"text",value:c,onChange:x=>p(x.target.value),onKeyDown:d,placeholder:`请输入${Ro[n]}名称...`,style:dp})]}),((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:pp,children:"取消"}),t.jsx("button",{onClick:u,disabled:!c.trim(),style:{...up,opacity:c.trim()?1:.6,cursor:c.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},ap={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},cp={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")},dp={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"},pp={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},up={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function xp(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Ts(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function fp(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 Rs=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:c,onSelect:p,onCancel:a,onCreate:d,onSearch:u})=>{const[f,x]=g.useState(""),[m,h]=g.useState([]),[k,b]=g.useState(!1),[j,y]=g.useState("recent");g.useEffect(()=>{e&&(x(""),h([]),y(r.length>0?"recent":"search"))},[e,r.length]),g.useEffect(()=>{if(!f.trim()){h([]);return}const z=setTimeout(async()=>{b(!0);try{h(await u(f,i))}catch{h([])}finally{b(!1)}},300);return()=>clearTimeout(z)},[f,i,u]);const v=g.useCallback(z=>{x(z.target.value),z.target.value.trim()&&y("search")},[]),$=g.useCallback(z=>s?z.filter(T=>T.id!==s):z,[s]);if(!e)return null;const S=n||(i==="all"?"选择实体":`选择${Ts(i)}`),_=$(r),w=$(m);return t.jsx("div",{style:mp,children:t.jsxs("div",{style:hp,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:a,style:bp,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:f,onChange:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:yp}),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(Eo,{active:j==="recent",onClick:()=>y("recent"),children:["最近使用 (",_.length,")"]}),t.jsxs(Eo,{active:j==="search",onClick:()=>y("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&_.length>0?t.jsx(No,{entities:_,onSelect:p}):f.trim()?k?t.jsx($n,{message:"搜索中..."}):w.length>0?t.jsx(No,{entities:w,onSelect:p}):t.jsx($n,{message:"未找到匹配的结果"}):t.jsx($n,{message:"输入关键词开始搜索"})}),l&&d&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:d,style:jp,children:c||"创建新实体"})]})]})})},Eo=({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}),No=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(gp,{entity:i,onClick:()=>n(i)},i.id))}),gp=({entity:e,onClick:n})=>{const[i,r]=g.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:xp(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:fp(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Ts(e.type)})]})},$n=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),mp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},hp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},bp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},yp={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"},jp={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},vp={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},kp={work:"📜",collection:"📚",book:"📖",entity:"👤"},Es=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:c,onAskAI:p,renderSectionActions:a,onDownloadResource:d,downloadStatuses:u,relations:f,onRelationsChange:x})=>{var W;const m=ae(),[h,k]=g.useState(!1),[b,j]=g.useState("work"),[y,v]=g.useState(""),[$,S]=g.useState(""),[_,w]=g.useState([]),[z,T]=g.useState(!1),[R,C]=g.useState(!1),[O,M]=g.useState("work"),[A,F]=g.useState(""),[G,U]=g.useState(),[E,ie]=g.useState(!1),[P,re]=g.useState(null),[ce,K]=g.useState([]);g.useRef(null);const V=e.type,q=V==="work",xe=V==="collection",oe=V==="book",ne=g.useCallback((B,te)=>{n({...e,[B]:te})},[e,n]),D=g.useCallback((B,te)=>{v(B),j(te),S(m.editor.selectToLink+m.indexType[te]),w([]),k(!0)},[m]),X=g.useCallback(B=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,B)},[r,e.id]),ee=g.useCallback(B=>{s==null||s(B.id,B.type)},[s]),N=g.useCallback((B,te,se)=>{const Se={...se,author:(se==null?void 0:se.author)||e.author,dynasty:se==null?void 0:se.dynasty};M(te),F(B),U(Se),C(!0)},[e.author]),I=g.useCallback((B,te)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,A,{type:O,title:B,inheritData:te}),C(!1)},[r,e.id,A,O]),J=g.useCallback(B=>{if(!B.trim()){w([]);return}T(!0),r!=null&&r.searchEntities&&r.searchEntities(B,b).then(te=>{w(te),T(!1)}).catch(()=>{w([]),T(!1)})},[r,b]),Q=g.useCallback(B=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,y,B.id),k(!1)},[r,e.id,y]),pe=g.useCallback(()=>{i()},[i]),ue=g.useCallback(B=>{re(()=>B),ie(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(K).catch(()=>{})},[r]),ke=g.useCallback((B,te)=>r!=null&&r.searchEntities?r.searchEntities(B,te==="all"?void 0:te):Promise.resolve([]),[r]),_e=g.useCallback(B=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(B),K(te=>[B,...te.filter(se=>se.id!==B.id)].slice(0,10)),P==null||P(B),ie(!1),re(null)},[r,P]);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:kp[V]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(an,{children:e.id}),t.jsx(an,{color:vp[V],children:m.indexType[V]})]})}),t.jsx(Oe,{title:m.section.basicInfo,onSave:i,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(nn,{label:q?m.editor.workTitle:xe?m.editor.collectionTitle:m.editor.bookTitle,value:e.title,onChange:B=>ne("title",B)}),oe&&t.jsx(nn,{label:m.editor.belongsToWork,value:e.workName||"",onChange:B=>ne("workName",B)}),t.jsx(Me,{label:m.editor.authorLabel,value:e.author||"",onChange:B=>ne("author",B)}),t.jsx(Me,{label:m.editor.publicationYearLabel,value:e.publicationYear||"",onChange:B=>ne("publicationYear",B)}),(oe||xe)&&t.jsx(nn,{label:m.editor.containedIn,value:e.collection||"",onChange:B=>ne("collection",B)}),(oe||xe)&&t.jsx(Me,{label:m.editor.holderLabel,value:e.holder||"",onChange:B=>ne("holder",B)}),(oe||xe)&&t.jsx(Me,{label:oe?m.editor.pageLabel:m.editor.volumeLabel,value:e.pages||"",onChange:B=>ne("pages",B)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(Me,{label:m.editor.firstImageLabel,value:e.firstImage||"",onChange:B=>ne("firstImage",B)})})]})}),t.jsx(Oe,{title:m.section.description,onSave:i,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(xt,{value:e.description||"",onChange:B=>ne("description",B),placeholder:m.editor.descriptionPlaceholder})}),(((W=e.additional_works)==null?void 0:W.length)||0)>0&&t.jsx(Oe,{title:m.section.additionalWorks,onSave:i,children:t.jsx(Sp,{items:e.additional_works||[],onChange:B=>ne("additional_works",B)})}),t.jsx(Oe,{title:m.section.indexedBy,onSave:i,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(wp,{items:e.indexed_by||[],onChange:B=>ne("indexed_by",B)})}),t.jsx(Oe,{title:m.section.emendatedBy,onSave:i,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(_p,{items:e.emendated_by||[],onChange:B=>ne("emendated_by",B)})}),t.jsx(Oe,{title:m.section.textResources,onSave:i,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(En,{items:e.resources||[],onChange:B=>ne("resources",B),onDownload:d,downloadStatuses:u,filterType:"text"})}),t.jsx(Oe,{title:m.section.imageResources,onSave:i,children:t.jsx(En,{items:e.resources||[],onChange:B=>ne("resources",B),onDownload:d,downloadStatuses:u,filterType:"image"})}),t.jsx(Oe,{title:m.section.sources,onSave:i,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(Ss,{items:ws(e.sources||""),onChange:B=>ne("sources",_s(B)),onOpenEntityPicker:ue})}),(oe||xe)&&t.jsx(Oe,{title:m.section.provenance,onSave:i,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(xt,{value:e.provenance||"",onChange:B=>ne("provenance",B),placeholder:m.editor.provenancePlaceholder})}),oe&&t.jsx(Oe,{title:m.section.otherEditions,onSave:i,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(xt,{value:e.otherEditions||"",onChange:B=>ne("otherEditions",B),placeholder:m.editor.otherEditionsPlaceholder})}),t.jsx($s,{entityType:V,entityId:e.id,entityTitle:e.title,parentWork:f==null?void 0:f.parentWork,parentCollection:f==null?void 0:f.parentCollection,belongsToWork:f==null?void 0:f.belongsToWork,belongsToCollection:f==null?void 0:f.belongsToCollection,childWorks:f==null?void 0:f.childWorks,childCollections:f==null?void 0:f.childCollections,containedBooks:f==null?void 0:f.containedBooks,siblingBooks:f==null?void 0:f.siblingBooks,onLinkEntity:D,onUnlinkEntity:X,onViewEntity:ee,onCreateAndLink:N,onSaveRelations:pe}),l&&c&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${o("danger-soft-border")}`,background:o("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:o("danger"),fontWeight:600,marginBottom:"8px"},children:m.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"12px"},children:m.editor.dangerZoneDesc}),t.jsx("button",{onClick:c,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("danger")}`,borderRadius:"4px",background:"transparent",color:o("danger"),cursor:"pointer"},children:m.editor.deleteEntity})]}),t.jsx(Cs,{isOpen:h,entityType:b,title:$,onSelect:Q,onCancel:()=>k(!1),onCreate:()=>{k(!1),N(y,b)},searchResults:_,onSearch:J,isLoading:z,excludeId:e.id}),t.jsx(Is,{isOpen:R,entityType:O,relationField:A,inheritData:G,onConfirm:I,onCancel:()=>C(!1)}),t.jsx(Rs,{isOpen:E,title:m.action.selectBookOrWork,filterType:"all",recentEntities:ce,excludeId:e.id,onSelect:_e,onCancel:()=>{ie(!1),re(null)},onSearch:ke})]})};function Sp({items:e,onChange:n}){const i=ae(),r=(c,p,a)=>{const d=e.map((u,f)=>f===c?{...u,[p]:a}:u);n(d)},s=c=>n(e.filter((p,a)=>a!==c)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((c,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(Me,{label:i.editor.bookNameLabel,value:c.book_title,onChange:a=>r(p,"book_title",a)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(Me,{label:i.label.juanCount,value:c.n_juan!=null?String(c.n_juan):"",onChange:a=>r(p,"n_juan",a&&parseInt(a,10)||void 0)})}),t.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Ns({items:e,onChange:n,showMeta:i,addLabel:r}){const s=ae(),[l,c]=g.useState(null),p=(u,f,x)=>{const m=e.map((h,k)=>k===u?{...h,[f]:x||void 0}:h);n(m)},a=u=>{n(e.filter((f,x)=>x!==u)),l===u&&c(null)},d=()=>{n([...e,{source:""}]),c(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,f)=>{const x=l===f;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:x?`color-mix(in srgb, ${o("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>c(x?null:f),children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.2s",transform:x?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:m=>{m.stopPropagation(),a(f)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${o("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:o("muted")},children:"✕"})]}),!x&&i&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:o("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),x&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Me,{label:s.label.sourceName,value:u.source,onChange:m=>p(f,"source",m)}),t.jsx(Me,{label:s.label.sourceBid,value:u.source_bid||"",onChange:m=>p(f,"source_bid",m)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Me,{label:s.label.titleInfo,value:u.title_info||"",onChange:m=>p(f,"title_info",m)}),t.jsx(Me,{label:s.label.authorInfo,value:u.author_info||"",onChange:m=>p(f,"author_info",m)})]}),t.jsx(Me,{label:s.label.edition,value:u.edition||"",onChange:m=>p(f,"edition",m)})]}),t.jsx(xt,{value:u.summary||"",onChange:m=>p(f,"summary",m),placeholder:s.editor.summaryPlaceholder}),t.jsx(xt,{value:u.comment||"",onChange:m=>p(f,"comment",m),placeholder:s.editor.commentPlaceholder}),t.jsx(xt,{value:u.additional_comment||"",onChange:m=>p(f,"additional_comment",m),placeholder:s.editor.additionalCommentPlaceholder})]})]},f)}),t.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:r})]})}function wp({items:e,onChange:n}){const i=ae();return t.jsx(Ns,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function _p({items:e,onChange:n}){const i=ae();return t.jsx(Ns,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function Ls(e){var p,a,d,u,f,x,m;const n=((a=(p=e.authors)==null?void 0:p[0])==null?void 0:a.name)||"",i=((d=e.publication_info)==null?void 0:d.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(f=e.page_count)!=null&&f.number?String(e.page_count.number):((x=e.page_count)==null?void 0:x.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",c={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 h=e;if(Array.isArray(h.related_works)){const k=h.related_works.find(b=>b.relation==="part_of");k&&(c.parentWorkId=k.id,c.parentWorkName=k.title)}}if(e.type==="book"){const h=e;c.workId=h.work_id,Array.isArray(h.contained_in)&&h.contained_in.length>0&&(c.collectionId=(m=h.contained_in[0])==null?void 0:m.id)}return c}function $p(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 zp=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:c,onSave:p,onDelete:a,onNavigate:d,renderLink:u,onAskAI:f,renderSectionActions:x,onDownloadResource:m,downloadStatuses:h,relations:k,onRelationsChange:b,headerExtra:j,className:y,style:v}=e;ae();const[$,S]=g.useState(s),_=l?s:$;g.useEffect(()=>{s!==$&&S(s)},[s]);const w=g.useCallback(()=>{const A=_==="view"?"edit":"view";l?l(A):S(A)},[_,l]),[z,T]=g.useState(null);g.useEffect(()=>{i&&r&&r.getItem(i).then(A=>{A&&T(A)})},[i,r]);const R=n||z,C=g.useMemo(()=>R?Ls(R):null,[R]),O=l||!n?t.jsx("button",{onClick:w,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:_==="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,M=t.jsxs(t.Fragment,{children:[O,j]});return!R&&!C?t.jsx(gt,{}):_==="view"?t.jsx(ti,{data:R,transport:r,onNavigate:d?A=>d(A):void 0,renderLink:u,headerExtra:M,className:y,style:v}):C?t.jsxs("div",{className:y,style:v,children:[M&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:M}),t.jsx(Es,{data:C,onChange:c||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:f,renderSectionActions:x,onDownloadResource:m,downloadStatuses:h,relations:k,onRelationsChange:b})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},Lo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Bs=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,l]=g.useState(null),[c,p]=g.useState(""),[a,d]=g.useState(""),[u,f]=g.useState("idle"),[x,m]=g.useState(""),h=g.useRef(null);g.useEffect(()=>{e&&(l(null),p(""),d(""),f("idle"),m(""))},[e]),g.useEffect(()=>{s&&setTimeout(()=>{var y;return(y=h.current)==null?void 0:y.focus()},100)},[s]),g.useEffect(()=>{if(u==="success"){const y=setTimeout(n,2e3);return()=>clearTimeout(y)}},[u,n]),g.useEffect(()=>{if(!e)return;const y=v=>{v.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[e,n]);const k=async()=>{if(!(!s||!c.trim())){f("submitting"),m("");try{await i({type:s,content:c.trim(),...a.trim()?{contact:a.trim()}:{}}),f("success")}catch(y){f("error"),m(y instanceof Error?y.message:"提交失败,请稍后重试")}}};if(!e)return null;const b=s&&c.trim()&&u!=="submitting",j=Lo.find(y=>y.value===s);return t.jsx("div",{style:Cp,onClick:y=>{y.target===y.currentTarget&&n()},children:t.jsxs("div",{style:Ip,onClick:y=>y.stopPropagation(),children:[t.jsxs("div",{style:Tp,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:Ap,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:Lo.map(y=>t.jsxs("button",{onClick:()=>l(y.value),style:{...Ep,...s===y.value?Np:{}},children:[t.jsx("span",{children:y.icon})," ",y.label]},y.value))}),t.jsx("textarea",{ref:h,value:c,onChange:y=>p(y.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...Lp,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:a,onChange:y=>d(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:[c.length," / 2000"]}),u==="error"&&t.jsx("div",{style:Wp,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:k,disabled:!b,style:{...Bp,opacity:b?1:.6,cursor:b?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},Cp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ip={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},Tp={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"},Ep={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"},Np={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},Lp={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"},Bp={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},Ap={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},Wp={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"},Vn="--bim-feedback-fab-offset",Yn=48,Fp=16,Pp=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,c]=g.useState(!1),p=n.bottom??24;return g.useEffect(()=>{if(r||typeof document>"u")return;const a=document.documentElement;return a.style.setProperty(Vn,`calc(${p+Yn+Fp}px + env(safe-area-inset-bottom, 0px))`),()=>{a.style.removeProperty(Vn)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>c(!0),style:{...Op,zIndex:s??o("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(Bs,{isOpen:l,onClose:()=>c(!1),onSubmit:e,feedbackListUrl:i})]})},Op={position:"fixed",width:`${Yn}px`,height:`${Yn}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"},Bo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],As=({onSubmit:e})=>{const[n,i]=g.useState("bug"),[r,s]=g.useState(""),[l,c]=g.useState(""),[p,a]=g.useState("idle"),[d,u]=g.useState(""),f=g.useRef(null);g.useEffect(()=>{n&&setTimeout(()=>{var k;return(k=f.current)==null?void 0:k.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){a("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),a("success"),s(""),c(""),i("bug")}catch(k){a("error"),u(k instanceof Error?k.message:"提交失败,请稍后重试")}}},m=n&&r.trim()&&p!=="submitting",h=Bo.find(k=>k.value===n);return p==="success"?t.jsx("div",{style:Ao,children:t.jsxs("div",{style:Vp,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>a("idle"),style:Yp,children:"继续提交"})]})}):t.jsxs("div",{style:Ao,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Bo.map(k=>t.jsxs("button",{onClick:()=>i(k.value),style:{...Dp,...n===k.value?Hp:{}},children:[t.jsx("span",{children:k.icon})," ",k.label]},k.value))}),t.jsx("textarea",{ref:f,value:r,onChange:k=>s(k.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...Gp}}),t.jsx("input",{type:"text",value:l,onChange:k=>c(k.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:qp}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:x,disabled:!m,style:{...Up,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:Kp,children:d})]})},Ao={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},Dp={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"},Hp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},Gp={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"},Up={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},Vp={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},Yp={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"},qp={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 Wo(e){return typeof e=="function"?e():e??"/api/feedback"}const Ws=({resourceId:e,apiUrl:n})=>{const[i,r]=g.useState([]),[s,l]=g.useState(!0),c=g.useCallback(async()=>{const a=Wo(n);l(!0);try{const u=await(await fetch(`${a}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);g.useEffect(()=>{c()},[c]);const p=async a=>{const d=Wo(n),u=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const f=await u.json().catch(()=>null);throw new Error((f==null?void 0:f.error)||"提交失败")}setTimeout(()=>c(),500)};return t.jsxs("div",{children:[t.jsx(Ci,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(As,{onSubmit:p})})]})},Mo={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 Jp(e){return e?Mo[e]??e:Mo.related}const Zp={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function Xp(e){return Zp[e]??e}const Qp={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function eu(e){return Qp[e]??""}function Ii({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,c)=>{const p=li(l.role);return t.jsxs(g.Fragment,{children:[c>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Ie,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:i,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},c)})}):null}function Ms(e,n){var p,a;const i=ri(e,n),r=i.mirrors.map(d=>({key:d.key,label:d.label,description:d.description,rows:d.items.filter(u=>u.group_role!=="mirror"),mirrors:d.items.filter(u=>u.group_role==="mirror")})),s=i.buckets.filter(d=>d.key==="image"||d.key==="textImage").flatMap(d=>d.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=i.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((a=i.buckets.find(d=>d.key==="text"))==null?void 0:a.items)??[],groups:r}}function Fs(e,n){const i=(e.url?zt(e.url):void 0)||e.name,r=_r(e,n);return r?`${i}(${r})`:i}function Ti({item:e,siblings:n,listedVolumeCounts:i}){const{convert:r}=Y(),[s,l]=g.useState(!1),c=cn(e),p=!!c&&c.expected>0&&!(i!=null&&i.has(c.expected)),a=r(Fs(e,n)),d=Ct(e),u=xn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[a," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:a}),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(pi,{item:e})})]}),t.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(f=>!f),children:r(s?"收起分冊":`展開 ${c.expected} 冊`)})})]})}function Ps({groups:e,listedVolumeCounts:n}){const{convert:i}=Y();return t.jsx(t.Fragment,{children:e.map(r=>t.jsxs("div",{className:"bim-d-rg",children:[r.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:i(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:i(r.description)}),r.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:r.rows.map((s,l)=>t.jsx(Ti,{item:s,siblings:r.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),r.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[r.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:i("鏡像")}),r.mirrors.map((s,l)=>{const c=Ct(s),p=i(Fs(s,r.mirrors));return c?t.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",title:s.details?i(s.details):void 0,children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:p},l)})]})]},r.key))})}const Fo=12,tu=60,Os=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:c,railLinks:p})=>{var X,ee,N;const a=ae(),{convert:d}=Y(),u=g.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[f,x]=g.useState(new Map),[m,h]=g.useState(!1),[k,b]=g.useState(""),[j,y]=g.useState(!1),v=u.length<=tu,$=v||m||!!k||j,S=g.useMemo(()=>$?u:u.slice(0,Fo),[u,$]);g.useEffect(()=>{if(!n||S.length===0)return;const I=S.filter(Q=>!f.has(Q));if(I.length===0)return;let J=!1;return Promise.all(I.map(Q=>n.getItem(Q).then(pe=>{const ue=pe??{};return[Q,{id:Q,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(()=>[Q,{id:Q}]))).then(Q=>{J||x(pe=>{const ue=new Map(pe);for(const[ke,_e]of Q)ue.set(ke,_e);return ue})}),()=>{J=!0}},[n,S,f]);const _=g.useMemo(()=>u.map(I=>f.get(I)??{id:I}),[u,f]),w=u.length>0&&u.every(I=>f.has(I)),z=!!n&&S.some(I=>!f.has(I)),T=v||$,R=g.useMemo(()=>zr(_,e.version_graph,{era:k,scanOnly:j,sort:T?"year":"default"}),[_,e.version_graph,k,j,T]),C=m?R.rows:R.rows.slice(0,Fo),O=R.allRows.filter(I=>I.hasImage).length,M=e.related_works||[],A=M.filter(I=>I.relation==="collected_in"),F=g.useMemo(()=>{const I=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],J=Q=>{const pe=I.indexOf(Q??"");return pe<0?I.length:pe};return M.filter(Q=>Q.relation!=="collected_in").map((Q,pe)=>({r:Q,i:pe})).sort((Q,pe)=>J(Q.r.relation)-J(pe.r.relation)||Q.i-pe.i).map(Q=>Q.r)},[M]),G=g.useMemo(()=>{const I=ri(e.resources,e.resource_groups);return[...I.mirrors.flatMap(J=>J.items.map(Q=>({r:Q,kind:d(J.label)}))),...I.buckets.flatMap(J=>J.items.map(Q=>({r:Q,kind:d(eu(J.key))})))]},[e.resources,e.resource_groups,d]),U=e.indexed_by||[],E=e.emendated_by||[],ie=g.useMemo(()=>{var te,se,Se;const I=[],J=(se=(te=e.authors)==null?void 0:te[0])==null?void 0:se.dynasty;J&&I.push({label:"成書",value:d(J)});const Q=it(e,a.unit.juan);if(Q){const me=(Se=e.juan_count)==null?void 0:Se.description;I.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[d(Q),me&&me!==Q?t.jsxs("span",{className:"bim-d-meta",children:["(",d(me),")"]}):null]})})}e.loss_status&&I.push({label:"存佚",value:d(Xp(e.loss_status))});const pe=e._edition_count??u.length;pe&&I.push({label:"版本",value:t.jsxs(t.Fragment,{children:[pe," ",d("種"),w&&O?t.jsxs("span",{className:"bim-d-meta",children:[" ",d(`${O} 種有影印`)]}):null]})});const ue=R.allRows.filter(me=>me.sortYear!=null),ke=ue.length>0?ue.reduce((me,je)=>me.sortYear<=je.sortYear?me:je):null;ke!=null&&ke.era.era?I.push({label:"最早存世",value:d([ke.era.era,ke.era.reign].filter(Boolean).join(" ")),title:ke.era.source==="edition"?d("據版本題名推斷"):void 0}):z&&I.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),(U.length||E.length)&&I.push({label:"著錄",value:t.jsxs(t.Fragment,{children:[U.length?`${U.length} ${d("家")}`:"—",E.length?t.jsxs("span",{className:"bim-d-meta",children:[" ",d(`考證 ${E.length} 條`)]}):null]})});const _e=Po(e.additional_titles);_e.length&&I.push({label:"又名",value:_e.map(d).join("、")});const W=Po(e.attached_texts);W.length&&I.push({label:"附載",value:W.map(d).join("、")});const B=(e.additional_works||[]).map(me=>d(me.book_title)+(me.n_juan!=null?` ${me.n_juan}${d(a.unit.juan)}`:""));return B.length&&I.push({label:"附錄",value:B.join("、")}),I},[e,d,a,u.length,w,z,O,R.allRows,U.length,E.length]),P=e.classification,re=P?[P.l1,P.l2,P.l3,P.l4].filter(Boolean).map(I=>d(I)):[],ce=e.subtype?d(a.workSubtype[e.subtype]??e.subtype):"",K=t.jsx(Yt,{title:d(e.title),byline:t.jsx(Ii,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(Re,{items:[...re,P!=null&&P.source?d(`據《${P.source.split("/")[0]}》`):"",ce]}),description:(X=e.description)!=null&&X.text?t.jsxs(t.Fragment,{children:[t.jsx(nt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(ee=e.description.sources)!=null&&ee.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(I=>d(Pa(I))).filter(Boolean).join(" · ")}):null]}):void 0,facts:ie,readAction:s,foot:t.jsx(Kt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(N=e.appendix)==null?void 0:N.map((I,J)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(I.title)}),t.jsx(nt,{text:I.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},J))}),V=R.eras.length>=2?[{key:"",label:a.catalog.all},...R.eras.map(I=>({key:I,label:I}))]:[],q=[];u.length&&q.push({id:"versions",label:"版本",count:u.length}),U.length&&q.push({id:"catalogs",label:"著錄",count:U.length}),A.length&&q.push({id:"collected",label:"收入叢編",count:A.length}),F.length&&q.push({id:"related",label:"相關書目",count:F.length}),G.length&&q.push({id:"resources",label:"在線資源",count:G.length});const xe=u.length===0&&U.length===0,oe=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Ee,{id:"versions",title:"版本",meta:t.jsx(Re,{items:[d(`共 ${u.length} 種`),w&&O?d(`${O} 種有影印`):"",R.rows.length!==R.allRows.length?d(`當前 ${R.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&V.length===0&&u.length>1?"":void 0,children:[V.length>0&&t.jsx(ai,{items:V,value:k,onChange:I=>{b(I),h(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Fr,{label:"只看有影印",checked:j,onChange:I=>{y(I),h(!1)}}),t.jsx("span",{className:"bim-d-meta",children:d(T?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("版本")}),t.jsx("th",{children:d("年代")}),t.jsx("th",{children:d("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:d("影印")})})]})}),t.jsx("tbody",{children:C.map(I=>{var J;return t.jsx(nu,{row:I,measure:(J=f.get(I.id))==null?void 0:J.measure_info,loaded:f.has(I.id),onNavigate:i,renderLink:r},I.id)})})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(k||j?"當前篩選下沒有版本":"暫無版本著錄")}),R.rows.length>C.length&&t.jsx(It,{label:`展開其餘 ${R.rows.length-C.length} 種版本`,onClick:()=>h(!0)}),R.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:d("部分年代據版本題名推斷,非著錄原文")})]}),U.length>0&&t.jsx(iu,{items:U,onNavigate:i,renderLink:r}),xe&&t.jsx(Ee,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),ne=(I,J)=>t.jsx(Ie,{id:I,label:d(J),onNavigate:i,renderLink:r,dense:!0}),D=t.jsxs(t.Fragment,{children:[t.jsx(ut,{id:"collected",title:"收入叢編",items:A.map(I=>ne(I.id,I.title))}),t.jsx(ut,{id:"related",title:"相關書目",meta:d(`${F.length} 部`),items:F.map(I=>t.jsxs(t.Fragment,{children:[ne(I.id,I.title),t.jsx("span",{className:"bim-d-meta",title:I.note?d(I.note):void 0,children:d(Jp(I.relation))})]}))}),t.jsx(ut,{id:"resources",title:"在線資源",cap:6,items:G.map(({r:I,kind:J})=>{const Q=d((I.url?zt(I.url):void 0)||I.name),pe=Ct(I);return t.jsxs(t.Fragment,{children:[pe?t.jsxs("a",{href:pe,target:"_blank",rel:"noopener noreferrer",children:[Q," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:Q}),J&&t.jsx("span",{className:"bim-d-meta",children:J})]})})})]});return t.jsx(Vt,{railTop:l,back:c,nav:q,railLinks:p,main:oe,card:K,side:D})};function Po(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Oo(e,n){return n((e.url?zt(e.url):void 0)||e.name)}function nu({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=Y(),c=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",a=e.holders[0],d=a?Oo(a,l):e.locationName?l(e.locationName):"",u=e.images[0],f=u?Ct(u):void 0,x=e.images.map(m=>Oo(m,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Ie,{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${c?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:c?l(c):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${d?"":" bim-d-zt-blank"}`,children:[d||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(f?t.jsx("a",{className:"bim-d-flag",href:f,target:"_blank",rel:"noopener noreferrer",title:x,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:x,children:l("有影印")}))})]})}function iu({items:e,onNavigate:n,renderLink:i}){const r=ae(),{convert:s}=Y(),[l,c]=g.useState(0),p=e[Math.min(l,e.length-1)];return t.jsx(Ee,{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((a,d)=>t.jsx("li",{role:"presentation",children:t.jsx("button",{type:"button",role:"tab","aria-selected":d===l,onClick:()=>c(d),children:s(a.source)})},d))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[p.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:s(p.title_info)}),t.jsx(Re,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[p.source_bid?t.jsx(Ie,{id:p.source_bid,label:s(p.source),onNavigate:n,renderLink:i,dense:!0}):s(p.source),p.section?s(p.section):"",p.author_info?`${s(r.label.authorInfo)} ${s(p.author_info)}`:"",p.edition?`${s(r.label.edition)} ${s(p.edition)}`:"",p.page??""]}),p.summary&&t.jsx("p",{className:"bim-d-quote",children:Fe(s(p.summary))}),p.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:Fe(s(p.comment))})]}),p.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:Fe(s(p.additional_comment))})]}),!p.summary&&!p.comment&&!p.additional_comment&&!p.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:s("僅著錄書名,無提要。")})]})]})})}const Do=40,Ho=2,ou=9,Go={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function zn(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Ds=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,fullText:l,fullTextPending:c,chapterLink:p,railTop:a,back:d,railLinks:u})=>{var W,B,te,se,Se,me,je,Je,$e,ze,Ze,lt,He,Tt;const f=ae(),{convert:x}=Y(),[m,h]=g.useState(null),[k,b]=g.useState(new Map),[j,y]=g.useState([]),[v,$]=g.useState(new Map),[S,_]=g.useState(!1);g.useEffect(()=>{if(!n||!e.work_id){h(null);return}let L=!1;return n.getItem(e.work_id).then(le=>{!L&&le&&le.type==="work"&&h(le)}).catch(()=>{}),()=>{L=!0}},[n,e.work_id]),g.useEffect(()=>{const L=e.contained_in||[];if(!n||L.length===0){b(new Map);return}let le=!1;return Promise.all(L.map(de=>{const be=typeof de=="string"?de:de.id;return n.getItem(be).then(ye=>[be,ye]).catch(()=>[be,null])})).then(de=>{if(le)return;const be=new Map;for(const[ye,ge]of de)ge&&be.set(ye,ge);b(be)}),()=>{le=!0}},[n,e.contained_in]);const w=g.useMemo(()=>{const L=new Set([...(m==null?void 0:m.books)||[],...e.related_books||[]]);return L.add(e.id),[...L]},[m==null?void 0:m.books,e.related_books,e.id]),z=w.length-1;g.useEffect(()=>{if(!n||z<=0){y([]);return}const L=w.length<=Do,le=L?w:w.slice(0,8);let de=!1;return Promise.all(le.map(be=>be===e.id?Promise.resolve({id:be,title:e.title,edition:e.edition,year:sn(e)}):n.getItem(be).then(ye=>{const ge=ye??{};return{id:be,title:ge.title,edition:ge.edition,year:ye?sn(ge):void 0}}).catch(()=>({id:be})))).then(be=>{if(de)return;const ye=be.filter(ge=>ge.id===e.id||ge.title||ge.edition);L&&ye.sort((ge,Le)=>(ge.year??1/0)-(Le.year??1/0)),y(ye)}),()=>{de=!0}},[n,w,z,e]);const T=e.lineage,R=g.useMemo(()=>[...((T==null?void 0:T.derived_from)||[]).filter(L=>L.ref_type==="book").map(L=>L.ref),...((T==null?void 0:T.related_to)||[]).map(L=>L.book_id)].filter(Boolean),[T]);g.useEffect(()=>{if(!n||R.length===0){$(new Map);return}let L=!1;return Promise.all(R.map(le=>n.getItem(le).then(de=>[le,{id:le,title:de==null?void 0:de.title,edition:de==null?void 0:de.edition}]).catch(()=>[le,{id:le}]))).then(le=>{L||$(new Map(le))}),()=>{L=!0}},[n,R]);const C=g.useMemo(()=>Ms(e.resources,e.resource_groups),[e.resources,e.resource_groups]),O=C.groups.reduce((L,le)=>L+le.rows.length+le.mirrors.length,0),M=C.groups.length>0&&C.groups.every(L=>L.key==="_physical"),A=Ut(e),F=Er(e),G=it(e,f.unit.juan),U=new Set((e.contained_in||[]).map(L=>typeof L=="string"?0:Ot(L.volume_index).length).filter(L=>L>0)),E=L=>{var be;const le=(be=e.base_edition)==null?void 0:be.find(ye=>ye.book_id===L&&ye.name);if(le!=null&&le.name)return le.name;const de=v.get(L);return(de==null?void 0:de.edition)||(de==null?void 0:de.title)||""},ie=g.useMemo(()=>{var ge,Le,Xe,at,ot;const L=[];F&&L.push({label:"版本類型",value:x(F),title:(ge=e.lineage)!=null&&ge.category?void 0:x("據版本題名推斷")}),(Le=e.publication_info)!=null&&Le.details?L.push({label:"刊印",value:x(e.publication_info.details)}):(A.era||A.reign)&&L.push({label:"刊寫年代",value:x([A.era,A.reign].filter(Boolean).join(" ")),title:A.source==="edition"?x("據版本題名推斷"):void 0}),G&&L.push({label:"卷帙",value:x(G)});const le=(e.contained_in||[]).flatMap(Ae=>typeof Ae=="string"?[]:Ot(Ae.volume_index));le.length&&L.push({label:"冊次",value:x(`第 ${fn(le,f.unit.volume)} ${f.unit.volume}(${le.length} ${f.unit.volume})`)});const de=(((Xe=e.lineage)==null?void 0:Xe.derived_from)||[]).find(Ae=>Ae.relation==="底本"&&Ae.ref_type==="book");de&&E(de.ref)&&L.push({label:"底本",value:t.jsx(Ie,{id:de.ref,label:x(E(de.ref)),onNavigate:i,renderLink:r,dense:!0})});const be=(e.resources||[]).filter(Ae=>(Ae.types||(Ae.type?[Ae.type]:[])).includes("physical"));be.length?L.push({label:"存藏",value:be.slice(0,2).map(Ae=>x(Ae.name)).join("、")+(be.length>2?x(` 等 ${be.length} 處`):"")}):(at=e.current_location)!=null&&at.name&&L.push({label:"存藏",value:x(e.current_location.name)}),(ot=e.page_count)!=null&&ot.description&&L.push({label:f.label.pageCount,value:x(e.page_count.description)});const ye=[...Pn(e.additional_titles),...Pn(e.attached_texts)];return ye.length&&L.push({label:"又名",value:ye.map(x).join("、")}),L},[e,x,f,A,F,G,v,i,r]),P=x(e.title),re=e.edition?x(e.edition):void 0,ce=((W=e.lineage)==null?void 0:W.year_text)||"",K=t.jsx(Yt,{kind:"版本",title:P,subtitle:re,byline:t.jsx(Ii,{authors:e.authors??(m==null?void 0:m.authors),onNavigate:i,renderLink:r}),meta:t.jsx(Re,{items:[F?x(F):"",A.era?x([A.era,A.reign].filter(Boolean).join("")):"",G?x(G):""]}),description:(B=e.description)!=null&&B.text?t.jsx(nt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ci((te=e.description)==null?void 0:te.text)?6:void 0,facts:ie,readAction:s,secondaryAction:s&&O>0&&!M?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(Kt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),V=e.contained_in||[],q=(l==null?void 0:l.chapters)||[],xe=q[0]&&zn(q[0].title)[0].slice(-1)||"章",oe=!!((se=T==null?void 0:T.derived_from)!=null&&se.length||(Se=T==null?void 0:T.related_to)!=null&&Se.length||(me=e.appendix)!=null&&me.length),ne=[];(q.length||C.text.length||c)&&ne.push({id:"fulltext",label:"全文",count:q.length?x(`${q.length} ${xe}`):void 0}),C.groups.length&&ne.push({id:"images",label:M?"館藏":"影印",count:O}),oe&&ne.push({id:"lineage",label:"版本源流"}),V.length&&ne.push({id:"collections",label:"收入叢編",count:V.length}),(je=e.location_history)!=null&&je.length&&ne.push({id:"provenance",label:"流轉歷史"});const D=L=>(p==null?void 0:p(L))??null,X=q[0],ee=X?D(X.file):null,N=S?q:q.slice(0,ou),I=(L,le,de)=>L?t.jsx("a",{className:de,href:L.href??"#",onClick:L.onClick?be=>{be.metaKey||be.ctrlKey||(be.preventDefault(),L.onClick())}:void 0,children:le}):t.jsx("span",{className:de,children:le}),J=t.jsxs(t.Fragment,{children:[(q.length>0||C.text.length>0||c)&&t.jsxs(Ee,{id:"fulltext",title:"全文",meta:q.length>0?t.jsx(Re,{items:[x(`${q.length} ${xe}`),(Je=l==null?void 0:l.source)!=null&&Je.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[c&&!X&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),X&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${zn(X.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((X.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),I(ee,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),q.length>1&&t.jsx("ul",{className:"bim-d-chap",children:N.map(L=>{const[le,de]=zn(L.title);return t.jsx("li",{children:I(D(L.file),t.jsxs(t.Fragment,{children:[le&&t.jsx("b",{children:x(le)}),x(de||L.file)]}))},L.file)})}),q.length>N.length&&t.jsx(It,{label:`展開其餘 ${q.length-N.length} ${xe}`,onClick:()=>_(!0)}),C.text.length>0&&t.jsxs(t.Fragment,{children:[(q.length>0||c)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:C.text.map((L,le)=>t.jsx(Ti,{item:L,siblings:C.text,listedVolumeCounts:U},`${L.id||L.url||L.name}-${le}`))})})]})]}),C.groups.length>0&&t.jsx(Ee,{id:"images",title:M?"館藏":"影印",meta:t.jsx(Re,{items:[C.groups.length>1?x(`${C.groups.length} 組`):"",x(`${O} 處`)]}),children:t.jsx(Ps,{groups:C.groups,listedVolumeCounts:U})}),oe&&t.jsxs(Ee,{id:"lineage",title:"版本源流",meta:($e=T==null?void 0:T.derived_from)!=null&&$e.length?x("據版本傳承著錄"):void 0,children:[t.jsxs("ul",{className:"bim-d-tl",children:[((T==null?void 0:T.derived_from)||[]).map((L,le)=>{const de=L.ref_type==="book"?E(L.ref):"";return t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(L.relation)}),L.ref_type==="book"?t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(Ie,{id:L.ref,label:x(de||L.ref),onNavigate:i,renderLink:r,dense:!0})}):t.jsx("span",{className:"bim-d-tl-t",children:x("擬構祖本")}),(L.evidence||L.confidence)&&t.jsxs("span",{className:"bim-d-tl-ev",children:[L.evidence?x(L.evidence):"",L.confidence&&Go[L.confidence]?x(`(${Go[L.confidence]})`):""]})]},`d-${le}`)}),(ze=T==null?void 0:T.derived_from)!=null&&ze.length||(Ze=T==null?void 0:T.related_to)!=null&&Ze.length?t.jsxs("li",{className:"bim-d-tl-cur",children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("本版")}),t.jsx("span",{className:"bim-d-tl-t",children:re||P}),ce&&t.jsxs("span",{className:"bim-d-meta",children:[t.jsx("span",{className:"bim-d-dot"}),x(ce)]})]}):null,((T==null?void 0:T.related_to)||[]).map((L,le)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(L.relation)}),t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(Ie,{id:L.book_id,label:x(E(L.book_id)||L.book_id),onNavigate:i,renderLink:r,dense:!0})}),L.evidence&&t.jsx("span",{className:"bim-d-tl-ev",children:x(L.evidence)})]},`r-${le}`)),(lt=e.appendix)==null?void 0:lt.map((L,le)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("附記")}),t.jsx("span",{className:"bim-d-tl-t",children:x(L.title)}),t.jsxs("details",{children:[t.jsx("summary",{className:"bim-d-ui",children:x("展開")}),t.jsx(nt,{text:L.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]})]},`a-${le}`))]}),(T==null?void 0:T.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"10px 0 0",maxWidth:"46em"},children:x(T.note)})]}),V.length>0&&t.jsx(Ee,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:V.map((L,le)=>{var Le,Xe;const de=typeof L=="string"?L:L.id,be=typeof L=="string"?[]:Ot(L.volume_index),ye=k.get(de),ge=(ye==null?void 0:ye._member_count)||((Le=ye==null?void 0:ye.books)==null?void 0:Le.length)||((Xe=ye==null?void 0:ye.contained_works)==null?void 0:Xe.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Ie,{id:de,label:ye?x(ye.title):de,onNavigate:i,renderLink:r,dense:!0}),be.length>0&&t.jsx(ru,{volumes:be,unit:f.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ge?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ge>0&&x(`全 ${ge} ${f.unit.bu}`)})]},`${de}-${le}`)})})})}),(He=e.location_history)!=null&&He.length?t.jsx(Ee,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((L,le)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(L.name)}),([L.start_date,L.end_date].filter(Boolean).join("—")||L.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(Re,{items:[[L.start_date,L.end_date].filter(Boolean).join("—"),L.description?x(L.description):""]})})]},le))})}):null,ne.length===0&&t.jsx(Ee,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),Q=j.findIndex(L=>L.id===e.id),pe=w.length<=Do,ue=pe&&Q>=0?j.slice(Math.max(0,Q-Ho),Q+Ho+1):j.filter(L=>L.id!==e.id),ke=t.jsxs(t.Fragment,{children:[m&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:x(f.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Ie,{id:m.id,label:x(m.title),onNavigate:i,renderLink:r})}),t.jsx(Re,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(m.authors||[]).slice(0,2).map(L=>`${L.dynasty?`〔${x(L.dynasty)}〕`:""}${x(L.name)}`),x(it(m,f.unit.juan)),m._edition_count?x(`${m._edition_count} 種版本`):""]}),((Tt=m.description)==null?void 0:Tt.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:x(m.description.text.replace(/[#*_>`[\]]/g,""))})]}),z>0&&ue.length>0&&t.jsxs("div",{children:[t.jsx(ut,{id:"siblings",title:pe?"同作品版本":f.relation.siblingVersions,meta:x(pe?"按年代":`${z} 種`),cap:ue.length,items:ue.map(L=>L.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(L.edition||L.title||L.id)}):t.jsx(Ie,{id:L.id,label:x(L.edition||L.title||L.id),onNavigate:i,renderLink:r,dense:!0})),metas:ue.map(L=>[L.year!=null?L.year<0?`前${-L.year}`:String(L.year):"",L.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:ue.findIndex(L=>L.id===e.id)}),m&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Ie,{id:m.id,label:x(`在作品頁看全部 ${w.length} 種 →`),onNavigate:i,renderLink:r,dense:!0})})]})]}),_e=e.work_id?t.jsx(Mr,{caption:f.section.belongsToWork,children:t.jsx(Ie,{id:e.work_id,label:m?x(m.title):" ",onNavigate:i,renderLink:r,dense:!0})}):void 0;return t.jsx(Vt,{railTop:a,back:d,up:_e,nav:ne,railLinks:u,main:J,card:K,side:ke})};function ru({volumes:e,unit:n}){const{convert:i}=Y();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${fn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}const Uo=16,Hs=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,railTop:c,back:p,railLinks:a})=>{var K,V,q,xe,oe,ne;const d=ae(),{convert:u}=Y(),[f,x]=g.useState(""),[m,h]=g.useState(!1),[k,b]=g.useState(null),j=g.useMemo(()=>Tr(e,n),[e,n]),[y,v]=g.useState(new Map),$=g.useMemo(()=>{const D=f.trim();if(!D)return j.rows;const X=u(D);return j.rows.filter(ee=>{var I;const N=ee.id&&((I=y.get(ee.id))==null?void 0:I.title)||ee.title;return u(N).includes(X)||(ee.subItems||[]).some(J=>u(J).includes(X))})},[j.rows,f,y,u]),S=m?$:$.slice(0,Uo),_=g.useMemo(()=>S.filter(D=>D.id&&!y.has(D.id)).map(D=>D.id),[S,y]);g.useEffect(()=>{if(!i||_.length===0)return;let D=!1;return Promise.all(_.map(X=>i.getItem(X).then(ee=>{var J;const N=ee??{},I={title:N.title,edition:N.edition,authors:N.authors,measure:ee?it(ee,d.unit.juan):void 0,versionCount:N._edition_count??((J=N.books)==null?void 0:J.length)};return[X,I]}).catch(()=>[X,{}]))).then(X=>{D||v(ee=>{const N=new Map(ee);for(const[I,J]of X)N.set(I,J);return N})}),()=>{D=!0}},[i,_,d.unit.juan]);const w=(e.contained_in||[])[0];g.useEffect(()=>{if(!w){b(null);return}if(b({id:w}),!i)return;let D=!1;return i.getItem(w).then(X=>{D||b({id:w,title:X==null?void 0:X.title})}).catch(()=>{}),()=>{D=!0}},[i,w]);const z=g.useMemo(()=>Ms(e.resources,e.resource_groups),[e.resources,e.resource_groups]),T=z.text.length+z.groups.reduce((D,X)=>D+X.rows.length+X.mirrors.length,0),R=e.contained_works||[],C=new Set(j.rows.map(D=>D.id).filter(Boolean)),O=R.length>0&&!R.every(D=>C.has(D.id)),M=(()=>{const D=j.rows.map(X=>X.edition).filter(Boolean);return D.length>1&&new Set(D).size===1})(),A=j.rows.some(D=>D.volumes.length>0||D.expected!=null),F=e._member_count||((K=e.books)==null?void 0:K.length)||R.length,G=g.useMemo(()=>{var N,I,J;const D=[];j.rows.length&&D.push({label:"子目",value:`${j.rows.length} ${u(d.unit.items)}`}),F&&F!==j.rows.length&&D.push({label:"成員",value:`${F} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")});const X=it(e,d.unit.juan),ee=j.totalVolumes?`${j.totalVolumes} ${u(d.unit.volume)}`:"";return(X||ee)&&D.push({label:"卷帙",value:[X?u(X):"",ee].filter(Boolean).join(" "),title:(N=e.juan_count)!=null&&N.description?u(e.juan_count.description):void 0}),(I=e.publication_info)!=null&&I.details&&D.push({label:"刊印",value:u(e.publication_info.details)}),(J=e.publication_info)!=null&&J.year&&D.push({label:"年代",value:u(e.publication_info.year)}),D},[e,F,j.rows.length,j.totalVolumes,u,d]),U=(V=e.description)==null?void 0:V.text,E=t.jsx(Yt,{kind:"叢編",title:u(e.title),byline:t.jsx(Ii,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Re,{items:[e.subtype==="work_collection"?u("作品集"):"",(q=e.publication_info)!=null&&q.year?u(e.publication_info.year):""]}),description:U||(xe=e.history)!=null&&xe.length?t.jsxs(t.Fragment,{children:[U&&t.jsx(nt,{text:U,style:{fontSize:15,lineHeight:1.85}}),(oe=e.history)!=null&&oe.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((D,X)=>t.jsx("li",{children:u(D)},X))}):null]}):void 0,clampDescription:ci(U)||(((ne=e.history)==null?void 0:ne.length)??0)>2?6:void 0,facts:G,foot:t.jsx(Kt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),ie=[];j.rows.length&&ie.push({id:"titles",label:"子目",count:j.rows.length}),T&&ie.push({id:"resources",label:"影印與全文",count:T}),O&&ie.push({id:"works",label:d.section.containedWorks,count:R.length});const P=t.jsxs(t.Fragment,{children:[j.rows.length>0&&t.jsxs(Ee,{id:"titles",title:"子目",meta:t.jsx(Re,{items:[u(`${j.rows.length} ${d.unit.items}`),j.totalVolumes?u(`全帙 ${j.totalVolumes} ${d.unit.volume}`):"",$.length!==j.rows.length?u(`當前 ${$.length} ${d.unit.items}`):""]}),action:l,children:[j.rows.length>Uo&&t.jsx("div",{className:"bim-d-filters bim-d-ui",children:t.jsx("input",{type:"search",className:"bim-d-find",value:f,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:D=>{x(D.target.value),h(!1)}})}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[A&&t.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),t.jsx("th",{children:u("書名")}),t.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),t.jsx("tbody",{children:S.map((D,X)=>{var pe;const ee=D.id?y.get(D.id):void 0,N=ee!=null&&ee.title&&D.title===D.id?ee.title:D.title,I=((ee==null?void 0:ee.authors)||[]).find(ue=>ue&&ue.name),J=[I?`${I.dynasty?`〔${u(I.dynasty)}〕`:""}${u(I.name)}${I.role?` ${u(I.role)}`:""}`:"",ee!=null&&ee.measure?u(ee.measure):"",(pe=D.subItems)!=null&&pe.length?D.subItems.map(ue=>u(ue)).join("、"):"",(ee!=null&&ee.edition||D.edition)&&!M?u((ee==null?void 0:ee.edition)||D.edition||""):""].filter(Boolean),Q=D.volumes.length>0?u(`第 ${fn(D.volumes,d.unit.volume)} ${d.unit.volume}`):D.expected!=null?u(`${D.found??0}/${D.expected} ${d.unit.volume}`):"";return t.jsxs("tr",{children:[A&&t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Q?"":" bim-d-zt-blank"}`,children:Q||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsxs("td",{className:"bim-d-zt-main",children:[D.id?t.jsx(Ie,{id:D.id,label:u(N),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(N)}),J.length>0?t.jsx(Re,{items:J}):D.id&&!ee&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ee!=null&&ee.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ee!=null&&ee.versionCount?u(`${ee.versionCount} 種`):""})]},`${D.id??D.title}-${X}`)})})]}),S.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),$.length>S.length&&t.jsx(It,{label:`展開其餘 ${$.length-S.length} ${d.unit.items}`,onClick:()=>h(!0)})]}),T>0&&t.jsxs(Ee,{id:"resources",title:"影印與全文",meta:u(`${T} 處`),children:[z.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[z.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:z.text.map((D,X)=>t.jsx(Ti,{item:D,siblings:z.text},`${D.id||D.url||D.name}-${X}`))})})]}),t.jsx(Ps,{groups:z.groups})]}),j.rows.length===0&&T===0&&t.jsx(Ee,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),re=O?t.jsx(ut,{id:"works",title:d.section.containedWorks,meta:u(`${R.length} 種`),cap:12,items:R.map(D=>t.jsx(Ie,{id:D.id,label:u(D.title),onNavigate:r,renderLink:s,dense:!0}))}):null,ce=k?t.jsx(Mr,{caption:"上級叢編",children:t.jsx(Ie,{id:k.id,label:u(k.title||k.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(Vt,{railTop:c,back:p,up:ce,nav:ie,railLinks:a,main:P,card:E,side:re})},su=16,Cn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Vo(e){if(!e)return Cn.length;const n=Cn.indexOf(e);return n===-1?Cn.length:n}const lu={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function Yo(e){return e==null?"":e<0?`前${-e}`:String(e)}const Gs=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:c})=>{var X,ee;const p=ae(),{convert:a}=Y(),[d,u]=g.useState("全部"),[f,x]=g.useState(!1),[m,h]=g.useState("default"),[k,b]=g.useState(new Map),j=g.useMemo(()=>(e.works||[]).map(N=>{const I=k.get(N.work_id);return{id:N.work_id,title:(I==null?void 0:I.title)??N.title??N.work_id,role:N.role||"",cls:si(N.role),versionCount:I==null?void 0:I.versionCount,section:I==null?void 0:I.cls,measure:I==null?void 0:I.measure,hasImage:I==null?void 0:I.hasImage,loaded:!!(I!=null&&I.loaded)}}),[e.works,k]),y=g.useMemo(()=>Ir((e.works||[]).map(N=>N.role)),[e.works]),v=g.useMemo(()=>{const N=d==="全部"?j:j.filter(I=>I.cls===d);return m==="versions"?[...N].sort((I,J)=>(J.versionCount??-1)-(I.versionCount??-1)):N},[j,d,m]),$=f?v:v.slice(0,su),S=g.useMemo(()=>$.filter(N=>!k.has(N.id)).map(N=>N.id),[$,k]);g.useEffect(()=>{if(!n||S.length===0)return;let N=!1;return Promise.all(S.map(I=>n.getItem(I).then(J=>{var ke,_e,W,B;const Q=J??{},pe=Q._edition_count??(((ke=Q.books)==null?void 0:ke.length)??0)+(((_e=Q.collections)==null?void 0:_e.length)??0),ue=[(W=Q.classification)==null?void 0:W.l1,(B=Q.classification)==null?void 0:B.l2].filter(Boolean).join(" ");return[I,{id:I,title:Q.title,versionCount:pe,loaded:!0,cls:ue||void 0,measure:J&&it(J,p.unit.juan)||void 0,hasImage:!!(Q.has_image??Q._has_image)}]}).catch(()=>[I,{id:I,loaded:!0}]))).then(I=>{N||b(J=>{const Q=new Map(J);for(const[pe,ue]of I)Q.set(pe,ue);return Q})}),()=>{N=!0}},[n,S,p.unit.juan]);const _=g.useMemo(()=>{const N=new Map;for(const I of e.alt_names||[]){const J=I.type||p.section.aliases;N.has(J)||N.set(J,[]),N.get(J).push(I.name)}return[...N.entries()].sort((I,J)=>Vo(I[0])-Vo(J[0])).map(([I,J])=>({label:I,names:J}))},[e.alt_names,p]),w=e.birth_year!=null||e.death_year!=null?`${Yo(e.birth_year)||"?"}—${Yo(e.death_year)||"?"}`:"",z=new Set(["本名","字","號","号"]),T=_.filter(N=>z.has(N.label)),R=_.filter(N=>!z.has(N.label)),C=R.reduce((N,I)=>N+I.names.length,0),O=g.useMemo(()=>{const N=[];for(const J of T)N.push({label:J.label,value:J.names.map(Q=>a(Q)).join("、")});const I=(e.works||[]).length;return I&&N.push({label:"著作",value:`${I} ${a("種")}`}),N},[e.works,T,a]),M=N=>{var I;return(I=_.find(J=>N.includes(J.label)))==null?void 0:I.names[0]},A=M(["字"]),F=M(["號","号"]),G=[A?`字${A}`:"",F?`號${F}`:""].filter(Boolean).join(","),U=e.native_place,E=t.jsx(Yt,{kind:lu[e.subtype]??"人物",title:a(e.primary_name||e.title),subtitle:G?a(G):void 0,meta:t.jsx(Re,{items:[e.dynasty?a(e.dynasty):"",w,U?a(`${U}人`):""]}),description:(X=e.description)!=null&&X.text?t.jsx(nt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ci((ee=e.description)==null?void 0:ee.text)?6:void 0,facts:O,foot:t.jsx(Kt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:C>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:a(`更多別名(${C})`)}),t.jsx("dl",{children:R.map(N=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:a(N.label)}),t.jsx("dd",{children:N.names.map(I=>a(I)).join("、")})]},N.label))})]})}),ie=g.useMemo(()=>j.filter(N=>N.loaded&&(N.versionCount??0)>0).sort((N,I)=>(I.versionCount??0)-(N.versionCount??0)).slice(0,3),[j]),P=!!n&&j.length>=3&&$.some(N=>!N.loaded),re=d==="全部"&&(P||ie.length>=2),ce=e.external_ids||{},K=[];ce.cbdb_id!=null&&K.push({label:"CBDB",id:String(ce.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${ce.cbdb_id}`,note:ce.cbdb_match==="auto"?"自動匹配":void 0});const V=ce.wikidata_id;V&&K.push({label:"Wikidata",id:V,href:`https://www.wikidata.org/wiki/${V}`});const q=ce.viaf_id;q&&K.push({label:"VIAF",id:q,href:`https://viaf.org/viaf/${q}`});const xe=y.map(N=>({key:N.cls,label:`${N.label} ${N.count}`})),oe=j.length?[{id:"works",label:"著作",count:j.length}]:[],ne=j.length===0?t.jsx(Ee,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該人物的關聯作品。")})}):t.jsxs(Ee,{id:"works",title:"著作",meta:t.jsx(Re,{items:[a(`共 ${j.length} 種`),v.length!==j.length?a(`當前 ${v.length} 種`):""]}),children:[re&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"-6px 0 10px",fontSize:14},children:a("著作舉要")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":P||void 0,children:[P&&[0,1,2].map(N=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},N)),!P&&ie.map(N=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Ie,{id:N.id,label:a(N.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx(Re,{items:[N.section?a(N.section):"",N.measure?a(N.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[a(`${N.versionCount} 種版本`),N.hasImage&&t.jsx("span",{className:"bim-d-flag",children:a("有影印")})]})]},N.id))]})]}),t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[xe.length>1&&t.jsx(ai,{items:xe,value:d,onChange:N=>{u(N),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":m==="versions",onClick:()=>{m==="default"&&x(!0),h(N=>N==="default"?"versions":"default")},children:a(m==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("作品")}),t.jsx("th",{children:a("職任")}),t.jsx("th",{children:a("存世版本")}),t.jsx("th",{"aria-label":a("影印")})]})}),t.jsx("tbody",{children:$.map(N=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Ie,{id:N.id,label:a(N.title),onNavigate:i,renderLink:r,dense:!0}),N.section||N.measure?t.jsx(Re,{items:[N.section?a(N.section):"",N.measure?a(N.measure):""]}):!N.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${N.role?"":" bim-d-zt-blank"}`,children:N.role?a(N.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${N.loaded?"":" bim-d-zt-blank"}`,children:N.loaded?N.versionCount?a(`${N.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:a("未著錄")}):""}),t.jsx("td",{className:N.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:N.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:a("有影印")})})]},N.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a("該職任下的著作尚未著錄。")}),v.length>$.length&&t.jsx(It,{label:`展開其餘 ${v.length-$.length} 種著作`,onClick:()=>x(!0)})]}),D=K.length>0?t.jsx(ut,{id:"external",title:"站外資料",items:K.map(N=>t.jsxs("a",{href:N.href,target:"_blank",rel:"noopener noreferrer",children:[N.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:K.map(N=>[N.id,N.note?a(N.note):""].filter(Boolean).join(" · "))}):null;return t.jsx(Vt,{railTop:s,back:l,nav:oe,railLinks:c,main:ne,card:E,side:D})},Ri="(max-width: 719px)",au=`${Ri}, (pointer: coarse)`,Us=`
671
685
  .bim-ct {
672
686
  display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
673
687
  max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
@@ -780,9 +794,9 @@ ${Oa}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
780
794
  }
781
795
 
782
796
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
783
- @media ${tu} {
797
+ @media ${au} {
784
798
  .bim-ct-row { min-height: 44px; }
785
799
  .bim-ct-tw { width: 44px; }
786
800
  .bim-ct-pg { min-width: 44px; height: 44px; }
787
801
  }
788
- `,Dt="未分類",Qe="all",Ei=20;function qt(e){if(!e)return[];const n=[];for(const i of[e.l1,e.l2,e.l3,e.l4]){const r=(i??"").trim();if(!r)break;n.push(r)}return n}function nu(e){const n=qt(e);return n.length?n.join("/"):Dt}function iu(e){const n=qt(e);return n.length?n.map((i,r)=>n.slice(0,r+1).join("/")):[Dt]}function ou(e,n=[]){const i=new Map;n.forEach((p,a)=>{const d=[p.cata_l1,p.cata_l2,p.cata_l3,p.cata_l4].filter(u=>!!u);d.forEach((u,f)=>{const x=d.slice(0,f+1).join("/");i.has(x)||i.set(x,a)})});const r=new Map;let s=0;for(const p of e){const a=qt(p.classification);if(!a.length){s++;continue}let d=r;a.forEach((u,f)=>{const x=a.slice(0,f+1).join("/");let m=d.get(u);m||(m={id:x,label:u,count:0,children:new Map},d.set(u,m)),m.count++,d=m.children})}const l=p=>[...p.values()].sort((a,d)=>{const u=i.get(a.id)??1/0,f=i.get(d.id)??1/0;return u!==f?u-f:a.label.localeCompare(d.label,"zh")}).map(a=>{const d={id:a.id,label:a.label,count:a.count};return a.children.size&&(d.children=l(a.children)),d}),c=l(r);return s>0&&c.push({id:Dt,label:Dt,count:s}),c}function jt(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const r=jt(i.children,n);if(r.length)return[i,...r]}}return[]}function Ni(e){return e.reduce((n,i)=>n+i.count,0)}function ru(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function su(e){var p;const n={id:e.id,title:e.title||e.id},i=e.juan_count,r=typeof i=="number"?i:i==null?void 0:i.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(a=>a==null?void 0:a.name).map(a=>{const d=a.dynasty||(e.authors.length===1?e.dynasty:void 0);return d?{name:a.name,dynasty:d}:{name:a.name}});s.length&&(n.authors=s);const l=ru(typeof e.description=="string"?e.description:(p=e.description)==null?void 0:p.text);l&&(n.summary=l);const c=qt(e.classification);return c.length&&(n.classification=c),n}function lu(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 au(e,n=Ei){return Math.max(1,Math.ceil(e/n))}function Gs(e,n,i=2){if(n<=1)return[1];const r=new Set([1,n]);for(let c=e-i;c<=e+i;c++)c>=1&&c<=n&&r.add(c);const s=[...r].sort((c,p)=>c-p),l=[];return s.forEach((c,p)=>{if(p>0){const a=c-s[p-1];a===2?l.push(c-1):a>2&&l.push(null)}l.push(c)}),l}const cu=()=>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 du(e,n,i){const r=[];i&&r.push({id:Qe,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,c)=>{var p;for(const a of l){const d=(p=a.children)!=null&&p.length?a.children:null;r.push({id:a.id,parentId:c,hasChildren:!!d,firstChildId:d?d[0].id:null}),d&&n.has(a.id)&&s(d,a.id)}};return s(e,null),r}function Us({tree:e,selectedId:n,onSelect:i,allLabel:r="全部",label:s="分類"}){const{convert:l}=U(),c=g.useRef(null),p=n&&n!==Qe?n:null,a=r!==null,[d,u]=g.useState(()=>{const S=new Set;for(const _ of jt(e,p))S.add(_.id);return S});g.useEffect(()=>{const S=jt(e,p);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,p]);const f=g.useMemo(()=>du(e,d,a),[e,d,a]),[x,m]=g.useState(null);g.useEffect(()=>{m(null)},[n]);const h=p??(a?Qe:null),v=g.useMemo(()=>{var w;const S=new Set(f.map(z=>z.id));if(x&&S.has(x))return x;if(h&&S.has(h))return h;const _=jt(e,p).map(z=>z.id).filter(z=>S.has(z));return _.length?_[_.length-1]:((w=f[0])==null?void 0:w.id)??null},[f,x,h,e,p]),b=g.useCallback((S,_)=>{u(w=>{const z=w.has(S),T=_??!z;if(T===z)return w;const R=new Set(w);return T?R.add(S):R.delete(S),R})},[]),j=g.useCallback(S=>{m(S),requestAnimationFrame(()=>{var w;const _=Array.from(((w=c.current)==null?void 0:w.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===S);_==null||_.focus()})},[]),y=g.useCallback((S,_)=>{_&&b(S,!0),i(S)},[i,b]),k=g.useCallback(S=>{const _=S.target.closest("[data-ct-id]");if(!_)return;const w=_.dataset.ctId,z=f.findIndex(C=>C.id===w);if(z<0)return;const T=f[z];let R=null;switch(S.key){case"ArrowDown":R=f[Math.min(f.length-1,z+1)].id;break;case"ArrowUp":R=f[Math.max(0,z-1)].id;break;case"Home":R=f[0].id;break;case"End":R=f[f.length-1].id;break;case"ArrowRight":if(!T.hasChildren)break;d.has(w)?R=T.firstChildId:b(w,!0);break;case"ArrowLeft":T.hasChildren&&d.has(w)?b(w,!1):R=T.parentId;break;case"Enter":case" ":S.preventDefault(),y(w,T.hasChildren);return;default:return}S.preventDefault(),R&&R!==w&&j(R)},[f,d,b,j,y]),$=(S,_)=>S.map((w,z)=>{var M;const T=(M=w.children)!=null&&M.length?w.children:null,R=!!T&&d.has(w.id),C=w.id===p,P=_===1&&S.length>1&&z===S.length-1;return t.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":T?R:void 0,"aria-selected":C,tabIndex:v===w.id?0:-1,"data-ct-id":w.id,className:P?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{m(w.id),y(w.id,!!T)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:T?A=>{A.stopPropagation(),m(w.id),b(w.id)}:void 0,children:T?t.jsx(cu,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(w.label)}),t.jsx("span",{className:"bim-ct-n",children:w.count.toLocaleString("en-US")})]}),R&&t.jsx("ul",{role:"group",children:$(T,_+1)})]},w.id)});return t.jsxs("ul",{ref:c,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:k,children:[a&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:v===Qe?0:-1,"data-ct-id":Qe,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{m(Qe),i(Qe)},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:Ni(e).toLocaleString("en-US")})]})}),$(e,1)]})}const Vs=e=>`/item/${encodeURIComponent(e)}`;function pu(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function uu(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function Ys({work:e,href:n}){var c,p;const{convert:i}=U(),r=uu(e.juan),s=((c=e.authors)==null?void 0:c.filter(a=>a.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:n,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:i(e.title)}),r&&t.jsx("span",{className:"bim-ct-juan",children:i(r)})]}),s.length>0&&t.jsx("span",{className:"bim-ct-by",children:s.map((a,d)=>t.jsxs(g.Fragment,{children:[d>0&&"、",a.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(a.dynasty),"〕"]}),i(a.name)]},d))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:i(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(a=>i(a)).join(" · ")})]})})}function Ks({page:e,pageCount:n,onPage:i,pageHref:r,label:s="分頁"}){const{convert:l}=U();if(n<=1)return null;const c=a=>d=>{i&&(r&&!pu(d)||(d.preventDefault(),i(a)))},p=(a,d,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const f={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...f,href:r(a),onClick:c(a),children:d}):t.jsx("button",{type:"button",...f,onClick:u.current?void 0:c(a),children:d})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:Gs(e,n).map((a,d)=>t.jsx("li",{style:{display:"contents"},children:a===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(a,a,{current:a===e,aria:l(`第 ${a} 頁`)})},a??`gap${d}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),p(e+1,l("下一頁"),{disabled:e>=n})]})}function qs({works:e,workLink:n=Vs,emptyText:i="此類暫無作品",...r}){const{convert:s}=U();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(Ys,{work:l,href:n(l.id)},l.id))}),t.jsx(Ks,{...r})]})}const xu=()=>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 fu({tree:e,selectedId:n,page:i,pageCount:r,works:s,onSelect:l,onPage:c,searchSlot:p,workLink:a,pageHref:d,allLabel:u="全部",allTitle:f="全部典籍",pageSize:x=Ei,className:m}){const{convert:h}=U(),b=`bim-ct-drawer-${g.useId().replace(/:/g,"")}`,[j,y]=g.useState(!1),k=jt(e,n&&n!==Qe?n:null),$=k.length?k[k.length-1]:null,S=$?$.label:f,_=$?$.count:Ni(e),w=g.useCallback(z=>{y(!1),l(z)},[l]);return t.jsxs("div",{className:m?`bim-ct ${m}`:"bim-ct","data-drawer":j?"open":"closed",children:[t.jsx("style",{children:Hs}),t.jsxs("aside",{className:"bim-ct-side","aria-label":h("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":j,"aria-controls":b,onClick:()=>y(z=>!z),children:[t.jsxs("span",{children:[h("分類"),":",h(k.length?k.map(z=>z.label).join(" › "):u??f)]}),t.jsx(xu,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:b,children:[t.jsx("h2",{className:"bim-ct-side-h",children:h("分類")}),t.jsx(Us,{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:h(S)}),k.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:h(k.slice(0,-1).map(z=>z.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[h(`共 ${_.toLocaleString("en-US")} 種 · 每頁 ${x} 條`),r>1&&h(` · 第 ${i} / ${r} 頁`)]})]}),p&&t.jsx("div",{className:"bim-ct-search",children:p}),t.jsx(qs,{works:s,workLink:a,page:i,pageCount:r,onPage:c,pageHref:d})]})]})}function gu(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 mu(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 Yo(e,n,i){return{id:`derive:${n.ref}->${e}:${i}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function hu(e,n,i){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${i}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function bu(e,n){var d;if(n==="all")return null;const i=(d=e.collections)==null?void 0:d[n],r=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,l=r||s||!!(i!=null&&i.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!i||!l)return null;const c=r?new Set(i.groups):null,p=new Set(i.book_ids??[]);if(c&&e.node_groups)for(const[u,f]of Object.entries(e.node_groups))c.has(f)&&p.add(u);let a=null;if(i.hypothetical_ids&&(a=new Set(i.hypothetical_ids)),c){a||(a=new Set);for(const u of e.hypothetical_nodes??[])u.group&&c.has(u.group)&&a.add(u.id)}return{books:p,hypos:a}}function on(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??[]),c=r.node_groups??{},p=bu(r,i??r.default_collection??"all"),a=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,f=new Set,x=new Set;if(a){const $=new Map(n.map(R=>[R.id,R])),S=new Map((r.hypothetical_nodes??[]).map(R=>[R.id,R])),_=R=>{const C=$.get(R);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(M=>M.ref);const P=S.get(R);return P?(P.derived_from??[]).map(M=>M.ref):[]},w=R=>S.has(R)?!u||u.has(R):!d||d.has(R),z=new Set,T=R=>{if(!z.has(R)){z.add(R);for(const C of _(R))l.has(C)||(w(C)||(S.has(C)?x.add(C):$.has(C)&&f.add(C)),T(C))}};for(const R of n)d&&d.has(R.id)&&!l.has(R.id)&&T(R.id);for(const R of r.hypothetical_nodes??[])u&&u.has(R.id)&&T(R.id)}const m=n.filter($=>!l.has($.id)).filter($=>!d||d.has($.id)||f.has($.id)).map($=>{const S=mu($,c);return S&&f.has($.id)&&(S.bridge=!0),S}).filter($=>$!==null),h=(r.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||x.has($.id)).map($=>{const S=gu($);return x.has($.id)&&(S.bridge=!0),S}),v=[...m,...h],b=new Set(v.map($=>$.id)),j=new Set,y=[],k=$=>{j.has($.id)||!b.has($.source)||!b.has($.target)||(j.add($.id),y.push($))};for(const $ of n)l.has($.id)||!$.lineage||d&&!d.has($.id)&&!f.has($.id)||(($.lineage.derived_from??[]).forEach((S,_)=>{k(Yo($.id,S,_))}),($.lineage.related_to??[]).forEach((S,_)=>{k(hu($.id,S,_))}));for(const $ of r.hypothetical_nodes??[])u&&!u.has($.id)&&!x.has($.id)||($.derived_from??[]).forEach((S,_)=>{k(Yo($.id,S,_))});return{nodes:v,edges:y,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function Js(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function yu(e,n){const i=[],r=e.version_graph;if(!r)return i;const s=new Set(n.map(a=>a.id)),l=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),c=new Set([...s,...l]),p=(a,d)=>{c.has(d.ref)||i.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(u=>p(d,u)),(a.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||i.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(u=>p(d,u))}return i}const Zs=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:s}=U();if(!e.nodes.length)return t.jsx("div",{style:{...Nu,...r},className:i,children:"暂无版本图数据"});const l=new Map,c=new Map;for(const x of e.edges)if(x.kind==="derive"){const m=l.get(x.target)??[];m.push(x),l.set(x.target,m)}else for(const m of[x.source,x.target]){const h=c.get(m)??[];h.push(x),c.set(m,h)}const p=new Map(e.nodes.map(x=>[x.id,x])),a=new Map,d=[];for(const x of e.nodes)if(x.group){const m=a.get(x.group)??[];m.push(x),a.set(x.group,m)}else d.push(x);const u=(x,m)=>(x.year??9999)-(m.year??9999);a.forEach(x=>x.sort(u)),d.sort(u);const f=e.groups.filter(x=>a.has(x.id));return t.jsxs("div",{className:i,style:{...vu,...r},children:[e.title&&t.jsx("div",{style:ku,children:s(e.title)}),e.description&&t.jsx("div",{style:Su,children:s(e.description)}),f.map(x=>t.jsx(Ko,{label:x.label,color:x.color,nodes:a.get(x.id),incomingMap:l,siblingMap:c,nodeMap:p,renderLink:n},x.id)),d.length>0&&t.jsx(Ko,{label:"其他",nodes:d,incomingMap:l,siblingMap:c,nodeMap:p,renderLink:n})]})},Ko=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:c})=>{const{convert:p}=U();return t.jsxs("div",{style:wu,children:[t.jsx("div",{style:{..._u,borderLeftColor:n??o("widget-border")},children:p(e)}),i.map(a=>t.jsx(ju,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:l,renderLink:c},a.id))]})},ju=({node:e,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",c=e.bridge,{convert:p}=U();return t.jsxs("div",{style:{...$u,borderStyle:l||c?"dashed":"solid",opacity:c?.55:e.status==="lost"?.7:1,background:c?o("bg-subtle"):void 0},title:c?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:zu,children:[t.jsx("span",{style:Cu,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Iu,children:Js(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Tu,children:[e.category&&t.jsx(At,{children:p(e.category)}),e.status==="lost"&&t.jsx(At,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(At,{tone:"warn",children:"残本"}),l&&t.jsx(At,{tone:"info",children:"假想祖本"}),c&&t.jsx(At,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Ru,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:Eu,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:Jo,children:[t.jsx("div",{style:Zo,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return t.jsxs("div",{style:Xo(a.confidence),children:[t.jsx("span",{style:Qo,children:p(a.relation)}),t.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,p(d.label)):p((d==null?void 0:d.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&t.jsx(qo,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:er,children:["· ",p(a.evidence)]})]},a.id)})]}),i.length>0&&t.jsxs("div",{style:Jo,children:[t.jsx("div",{style:Zo,children:"关联:"}),i.map(a=>{const d=a.source===e.id?a.target:a.source,u=r.get(d);return t.jsxs("div",{style:Xo(a.confidence),children:[t.jsx("span",{style:Qo,children:p(a.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,p(u.label)):p((u==null?void 0:u.label)??d)}),t.jsx(qo,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:er,children:["· ",p(a.evidence)]})]},a.id)})]})]})},At=({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})},qo=({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},vu={fontSize:"14px",color:o("fg")},ku={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Su={fontSize:"13px",color:o("muted"),marginBottom:"16px",lineHeight:1.6},wu={marginBottom:"16px"},_u={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:o("fg")},$u={border:`1px solid ${o("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:o("bg")},zu={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Cu={fontSize:"15px",fontWeight:600},Iu={fontSize:"12px",color:o("muted")},Tu={marginBottom:"6px"},Ru={fontSize:"12px",color:o("muted"),margin:"2px 0"},Eu={fontSize:"12px",color:o("muted"),fontStyle:"italic",margin:"4px 0"},Jo={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${o("widget-border")}`},Zo={fontSize:"11px",color:o("muted"),marginBottom:"2px"},Xo=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Qo={display:"inline-block",padding:"0 6px",fontSize:"11px",background:o("tag-bg"),color:o("fg"),borderRadius:"3px",marginRight:"6px"},er={fontSize:"11px",color:o("muted")},Nu={padding:"20px",textAlign:"center",color:o("muted"),fontSize:"13px"},Xs=({selectedNodeId:e,...n})=>{const[i,r]=g.useState("loading"),[s,l]=g.useState(null);return g.useEffect(()=>{let c=!1;return Lu().then(p=>{c||(p?(l(p),r("ready")):r("missing"))}),()=>{c=!0}},[]),i==="loading"?t.jsx("div",{style:tr,children:"加载图组件中…"}):i==="missing"||!s?t.jsxs("div",{style:tr,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(Bu,{modules:s,selectedNodeId:e,...n})};async function Lu(){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 Bu=({graph:e,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:l,modules:c})=>{const{ReactFlow:p,Background:a,Controls:d,Handle:u,Position:f,BaseEdge:x,EdgeLabelRenderer:m,getSmoothStepPath:h,dagre:v}=c,b=g.useMemo(()=>({lineage:_=>{var G,D,E,le;const w=((G=_.data)==null?void 0:G.stepPosition)??.85,[z,T,R]=h({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:w,borderRadius:5}),C=!!((D=_.data)!=null&&D.isSibling),P=C?T:_.targetX-18,M=C?R:_.targetY-12,A=(E=_.data)==null?void 0:E.labelStyle,F=(le=_.data)==null?void 0:le.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(x,{id:_.id,path:z,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&t.jsx(m,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${P}px,${M}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:o("bg"),border:`0.5px solid ${o("widget-border")}`,...F,...A},children:_.label})})]})}}),[x,m,h]),j=g.useMemo(()=>({version:_=>{const w=_.data,z=w.kind==="hypothetical",T=w.status==="lost",R=w.isSelected,C=w.bridge,P=w.borderColor??o("muted"),M=C||z?"dashed":"solid",A=C?.5:T?.6:1;return t.jsxs("div",{style:{background:o(C?"bg-subtle":"bg"),border:`2px ${M} ${R?o("primary"):P}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:A,boxShadow:R?o("shadow-node-selected"):z||C?"none":o("shadow-node")},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:f.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:Js(w.yearText,void 0,w.uncertain)}),T&&t.jsx("div",{style:{fontSize:9,color:o("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:f.Right,style:{visibility:"hidden"}})]})}}),[u,f]),{convert:y}=U(),{rfNodes:k,rfEdges:$}=g.useMemo(()=>Au(e,v,n,l,y),[e,v,n,l,y]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:t.jsxs(p,{nodes:k,edges:$,nodeTypes:j,edgeTypes:b,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(a,{gap:16}),t.jsx(d,{showInteractive:!1})]})})};function Au(e,n,i,r,s=l=>l??""){const p=e.layout==="LR"||!e.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:p?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(e.groups.map(j=>[j.id,j.color??o("muted")]));for(const j of e.nodes)a.setNode(j.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of e.edges)j.kind==="derive"&&(u.has(j.relation)||a.setEdge(j.source,j.target));n.layout(a);const f=e.nodes.map(j=>{const y=a.node(j.id),k=r&&j.id===r,$={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??Mu(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:i,isSelected:k,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:y.x-160/2,y:y.y-90/2},data:$,draggable:!1,selected:k}}),x=.78,m=.06,h=new Map;for(const j of e.edges)j.kind==="derive"&&(h.has(j.source)||h.set(j.source,[]),h.get(j.source).push(j));const v=new Map;for(const[j,y]of h){if(y.length<=1)continue;const k=[...y].sort((S,_)=>{var T,R;const w=((T=a.node(S.target))==null?void 0:T.y)??0,z=((R=a.node(_.target))==null?void 0:R.y)??0;return w-z}),$=k.length;k.forEach((S,_)=>{const w=(_-($-1)/2)*m;v.set(S.id,x+w)})}const b=e.edges.map(j=>Wu(j,v.get(j.id),s));return{rfNodes:f,rfEdges:b}}function Wu(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Fu(e.confidence),c={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:c,markerStart:s?c:void 0,zIndex:1e3}}function Mu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Fu(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 tr={padding:"40px 20px",textAlign:"center",color:o("muted"),fontSize:"13px",border:`1px dashed ${o("widget-border")}`,borderRadius:8,background:o("bg")},Qs=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:c,onCollectionChange:p,collectionsAvailable:a,collectionCounts:d,className:u,style:f})=>{var y;const[x,m]=g.useState(n),h=k=>{m(k),l==null||l(k)},v=(()=>{if(!a)return[];const k=Object.entries(a);return k.length===0||a.all?k:[...k,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),b=!!(p&&v.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:o("muted"),textAlign:"center"},children:"暂无版本传承数据"});const j=c?(y=a==null?void 0:a[c])==null?void 0:y.description:void 0;return t.jsxs("div",{className:u,style:f,children:[t.jsxs("div",{style:Pu,children:[t.jsx("button",{onClick:()=>h("list"),style:In(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>h("graph"),style:In(x==="graph"),children:"关系图"}),b&&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:"集合:"}),v.map(([k,$])=>{const S=d==null?void 0:d[k];return t.jsxs("button",{onClick:()=>p==null?void 0:p(k),style:In(c===k),title:$.description,children:[$.label,S!=null?` ${S}`:""]},k)})]})]}),b&&j&&t.jsx("div",{style:{fontSize:12,color:o("muted"),marginBottom:8,padding:"4px 8px",background:o("bg-subtle"),borderRadius:4},children:j}),x==="list"?t.jsx(Zs,{graph:e,renderLink:i}):t.jsx(Xs,{graph:e,renderLink:i,height:r,selectedNodeId:s})]})},Pu={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},In=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"}),Kn=({style:e})=>{const n=g.useContext(_t);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:"简"})]})},qn=({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 Tn(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function Ou(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const Du=({id:e,transport:n,initialDetail:i,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:c,onJuanChange:p,lineageMode:a="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:f,initialPage:x=1,selectedLineageNodeId:m,onNavigate:h,onBack:v,backLabel:b,renderLink:j,enrichDetail:y,getSourceLink:k,readLink:$,railTop:S,extraTabs:_=[],showFeedbackTab:w=!0,feedbackApiUrl:z,height:T,footerExtra:R,className:C,style:P})=>{var Ai;const M=ce(),{convert:A}=U(),[F]=g.useState(()=>{if(!Ou(e,i))return null;const H={...i},me=r??Tn(e,H);return y&&y(me,H),{id:e,entry:me,detail:H}}),[G,D]=g.useState((F==null?void 0:F.entry)??null),[E,le]=g.useState((F==null?void 0:F.detail)??null),[W,Y]=g.useState(!F),[re,te]=g.useState(!1),[J,ee]=g.useState([]),[ge,se]=g.useState(!1),[ie,O]=g.useState(null),[Z,ne]=g.useState(!1),[N,I]=g.useState(null),[K,X]=g.useState(!1),[xe,fe]=g.useState(null),[ke,Q]=g.useState([]),[V,B]=g.useState(!1),[oe,de]=g.useState(null),[_e,pe]=g.useState(null),[Be,Ee]=g.useState(!1),we=g.useRef(null),[Je,Jt]=g.useState(null),st=c!==void 0?c:Je,He=g.useCallback(H=>{p?p(H):Jt(H)},[p]),It=g.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){ee([]);return}se(!0);try{if(n.getCollectionCatalogs)ee(await n.getCollectionCatalogs(H)||[]);else if(n.getCollectionCatalog){const me=await n.getCollectionCatalog(H);ee(me?[{resource_id:"",data:me}]:[])}}catch{ee([])}finally{se(!1)}},[n]),L=g.useCallback(async H=>{if(!n.getCollatedEditionIndex){O(null);return}ne(!0);try{O(await n.getCollatedEditionIndex(H))}catch{O(null)}finally{ne(!1)}},[n]),ae=g.useCallback(async H=>{if(!n.getBookFullTextIndex){I(null);return}X(!0);try{I(await n.getBookFullTextIndex(H))}catch{I(null)}finally{X(!1),fe(H)}},[n]),ue=g.useCallback(async H=>{var me;if(!n.getWorkFullTextList){Q([]);return}B(!0);try{const ve=(await n.getWorkFullTextList(H)??[]).filter($e=>$e.owner_type!=="Book");Q(ve),de(((me=ve.find($e=>$e.primary)??ve[0])==null?void 0:me.key)??null)}catch{Q([])}finally{B(!1)}},[n]),ye=g.useCallback(async(H,me)=>{Ee(!0);try{if(n.getLineageGraph){const Le=await n.getLineageGraph(H);Le&&pe(Le)}const ve=me.version_graph;if(!ve||!ve.enabled){_e||pe(null),we.current=null;return}const $e=me.books??[],Ge=[];for(const Le of $e)try{const Ue=await n.getItem(Le);Ue&&Ge.push(Ue)}catch{}we.current={work:me,books:Ge};const q=u??ve.default_collection??(ve.core_books&&ve.core_books.length>0?"core":"all"),Se=q==="core"&&Array.isArray(ve.core_books)&&ve.core_books.length>0?"core":q??"all";pe(on(me,Ge,Se))}catch{pe(null),we.current=null}finally{Ee(!1)}},[n]),je=g.useRef({initialDetail:i,initialEntry:r});je.current={initialDetail:i,initialEntry:r},g.useEffect(()=>{let H=!1;const me=q=>{q.type==="collection"?It(e):q.type==="work"?((q.has_collated||n.getCollatedEditionIndex)&&L(e),(q.version_graph||n.getLineageGraph)&&ye(e,q),n.getWorkFullTextList&&ue(e)):q.type==="book"&&q.has_full_text&&n.getBookFullTextIndex&&ae(e)},ve=je.current;let $e=null;if(F&&F.id===e)$e=F;else if(ve.initialDetail&&ve.initialDetail.id===e){const q={...ve.initialDetail},Se=ve.initialEntry??Tn(e,q);y&&y(Se,q),$e={entry:Se,detail:q}}return $e?(te(!1),ee(q=>q.length?[]:q),O(null),I(null),Q(q=>q.length?[]:q),de(null),pe(null),we.current=null,D($e.entry),le($e.detail),Y(!1),me($e.detail),()=>{H=!0}):((async()=>{Y(!0),te(!1),D(null),le(null),ee([]),O(null),I(null),Q([]),de(null),pe(null),we.current=null;try{const q=await n.getItem(e);if(H)return;if(!q){te(!0);return}const Se=q;let Le=null;if(n.getEntry&&(Le=await n.getEntry(e),H))return;Le||(Le=Tn(e,Se)),y&&y(Le,Se),D(Le),le(Se),me(Se)}catch{H||te(!0)}finally{H||Y(!1)}})(),()=>{H=!0})},[e,n,F,y,It,L,ye,ae,ue]),g.useEffect(()=>{const H=we.current;!H||!u||pe(on(H.work,H.books,u))},[u]);const he=[];if(E){if(he.push({key:"basic",label:M.detailTab.basicInfo}),E.type==="collection"){ge&&J.length===0&&he.push({key:"catalog:loading",label:`${M.detailTab.catalog}…`});for(const H of J)he.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${A(H.short_name)}${M.detailTab.catalogSuffix}`:M.detailTab.collectionCatalog})}E.type==="work"&&(ie||Z)&&s==="collated"&&he.push({key:"collated",label:Z?`${M.detailTab.collatedEdition}…`:M.detailTab.collatedEdition}),E.type==="book"&&(N||K)&&s==="fulltext"&&he.push({key:"fulltext",label:K?`${M.detailTab.fullText}…`:M.detailTab.fullText}),E.type==="work"&&(ke.length>0||V)&&s==="fulltext"&&he.push({key:"fulltext",label:V?`${M.detailTab.fullText}…`:M.detailTab.fullText}),E.type==="work"&&(_e||Be)&&he.push({key:"lineage",label:Be?`${M.detailTab.lineage}…`:M.detailTab.lineage});for(const H of _)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(E)&&he.push({key:H.key,label:H.label});w&&s==="feedback"&&he.push({key:"feedback",label:M.detailTab.feedback});for(const H of _)H.position==="after-feedback"&&H.shouldShow(E)&&he.push({key:H.key,label:H.label})}g.useEffect(()=>{if(s!=="emendated"||!E)return;l("basic");const H=setTimeout(()=>{var me;(me=document.getElementById("studies"))==null||me.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[s,E,l]);const Ne=G&&E&&k?k({activeTab:s,activeJuan:st,entry:G,detail:E}):null,Ze=g.useMemo(()=>{var Ge;if(!E)return null;const me=(E.authors??[]).map(q=>{const Se=li(q.role);return`${q.dynasty?`〔${A(q.dynasty)}〕`:""}${A(q.name)}${Se?` ${A(Se)}`:""}`}).join(" · ");let ve=!1;try{ve=be.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const q=E;return{title:A(q.title),subtitle:q.edition?A(q.edition):me||void 0,aside:[ve?M.status.draft:"",me&&q.edition?me:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const q=E;return{title:A(q.title),subtitle:A(nt(q,M.unit.juan))||void 0,aside:[(Ge=q.publication_info)==null?void 0:Ge.year,ve?M.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:me||void 0}}if(E.type==="entity"){const q=E,Se=Ue=>Ue==null?"":Ue<0?`前${-Ue}`:String(Ue),Le=q.birth_year!=null||q.death_year!=null?`${Se(q.birth_year)||"?"}—${Se(q.death_year)||"?"}`:"";return{title:A(q.primary_name||q.title),subtitle:[q.dynasty?`〔${A(q.dynasty)}〕`:"",Le].filter(Boolean).join(" ")||void 0,aside:ve?M.status.draft:void 0,secondLine:void 0}}const $e=A(nt(E,M.unit.juan));return{title:A(E.title),subtitle:[$e,me].filter(Boolean).join(" · ")||void 0,aside:[Gu(M,E.subtype),ve?M.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,A,M]),lt=E?E.type==="work"?(((Ai=ie==null?void 0:ie.juan_files)==null?void 0:Ai.length)??0)>0?"collated":ke.length>0?"fulltext":null:E.type==="book"&&(((N==null?void 0:N.chapters.length)??0)>0||E.has_full_text&&n.getBookFullTextIndex&&xe!==E.id)?"fulltext":null:null,it=ke.find(H=>H.primary)??ke[0],Ae=()=>{var H;lt==="collated"&&((H=ie==null?void 0:ie.juan_files)!=null&&H.length)?(He(ie.juan_files[0]),l("collated")):lt==="fulltext"&&((E==null?void 0:E.type)==="work"&&it&&de(it.key),He(null),l("fulltext"))};let Tt=null;if(E&&$){const H=$({detail:E,kind:lt,fullTextKey:E.type==="work"?it==null?void 0:it.key:void 0});H&&(Tt=t.jsx(Wn,{href:H}))}else lt&&(Tt=t.jsx(Wn,{onClick:Ae}));const el=H=>{if(!E)return null;const me=H.replace(/\.[^.]+$/,"");if($){const ve=$({detail:E,kind:"fulltext",juan:me});return ve?{href:ve}:null}return{onClick:()=>{He(me),l("fulltext")}}},tl=new Set(_.map(H=>H.key)),Zt=he.filter(H=>H.key.startsWith("catalog:")&&H.key!=="catalog:loading"||tl.has(H.key)).map(H=>({key:H.key,label:H.label,onClick:()=>l(H.key)})),Li=()=>{var H;return E?E.type==="work"?t.jsx(Fs,{data:E,transport:n,onNavigate:h,renderLink:j,readAction:Tt,railTop:S,railLinks:Zt}):E.type==="book"?t.jsx(Ps,{data:E,transport:n,onNavigate:h,renderLink:j,readAction:Tt,fullText:N,fullTextPending:!!E.has_full_text&&!!n.getBookFullTextIndex&&xe!==E.id,chapterLink:el,railTop:S,railLinks:Zt}):E.type==="collection"?t.jsx(Os,{data:E,catalog:(H=J[0])==null?void 0:H.data,transport:n,onNavigate:h,renderLink:j,readAction:Tt,railTop:S,railLinks:Zt,catalogAction:J.length>0?t.jsxs("a",{href:"#catalog",onClick:me=>{me.preventDefault(),l(`catalog:${J[0].resource_id}`)},children:[A(M.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Ds,{data:E,transport:n,onNavigate:h,renderLink:j,railTop:S,railLinks:Zt}):null},nl=()=>{var me,ve,$e,Ge;if(!G||!E)return null;if(s==="basic"||s==="emendated")return Li();if(typeof s=="string"&&s.startsWith("catalog:")){const q=(me=J.find(Se=>`catalog:${Se.resource_id}`===s))==null?void 0:me.data;return t.jsx(ni,{data:q,onNavigate:h,renderLink:j})}if(s==="collated")return t.jsx(zi,{index:ie||void 0,workId:e,transport:n,onNavigate:h,activeJuan:st,onJuanChange:He});if(s==="fulltext"&&E.type==="work"){const q=oe??((ve=ke[0])==null?void 0:ve.key);return q?t.jsx(Gn,{bookId:e,workKey:q,versions:ke,onVersionChange:Se=>{de(Se),He(null)},transport:n,activeChapter:st,onChapterChange:He},q):t.jsx("div",{style:{padding:24,color:o("desc-fg")},children:V?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(Gn,{index:N||void 0,bookId:e,transport:n,activeChapter:st,onChapterChange:He});if(s==="lineage"){if(!_e)return t.jsx("div",{style:{color:o("label-fg"),padding:"24px 0"},children:Be?"加載中…":"暫無版本圖數據"});const q=E.type==="work"?E:null;return t.jsx(Qs,{graph:_e,renderLink:j,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:a,onModeChange:d,selectedNodeId:m,collection:u??(($e=q==null?void 0:q.version_graph)==null?void 0:$e.default_collection),onCollectionChange:f,collectionsAvailable:(Ge=q==null?void 0:q.version_graph)==null?void 0:Ge.collections,collectionCounts:(()=>{var Wi,Mi,Fi,Pi,Oi,Di,Hi;if(!q)return;const Se={},Le=((Wi=we.current)==null?void 0:Wi.books)??[];Se.all=(((Mi=q.books)==null?void 0:Mi.length)??0)-(((Pi=(Fi=q.version_graph)==null?void 0:Fi.excluded_books)==null?void 0:Pi.length)??0);const Ue=(Oi=q.version_graph)==null?void 0:Oi.collections;if(Ue)for(const Gi of Object.keys(Ue))Se[Gi]=on(q,Le,Gi).nodes.filter(Ui=>Ui.kind==="book"&&!Ui.bridge).length;return Se.core==null&&((Hi=(Di=q.version_graph)==null?void 0:Di.core_books)!=null&&Hi.length)&&(Se.core=q.version_graph.core_books.length),Se})()})}if(s==="feedback"&&w)return t.jsx(Bs,{resourceId:e,apiUrl:z});const H=_.find(q=>q.key===s);return H?H.render({detail:E,entry:G,transport:n,onNavigate:h}):null};if(W)return t.jsx(Mt,{style:{minHeight:T,...P},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((H,me)=>t.jsx("div",{style:{height:me===1?40:16,width:H,opacity:.35,background:o("rule")}},me))})});if(re||!E||!G||!Ze)return t.jsx(Mt,{style:{minHeight:T,...P},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:o("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const hn=s==="basic"||s==="emendated",Xt=[{label:b??M.detailTab.backToIndex,onClick:v}];if(E.type==="book"&&E.work_id){const H=E.work_id;Xt.push({label:M.indexType.work,id:H,onClick:()=>h==null?void 0:h(H)})}Xt.push({label:M.indexType[E.type]});const Qt=s==="collated"||s==="fulltext",Bi=t.jsx(qr,{left:t.jsxs(t.Fragment,{children:[R,R?" · ":"",t.jsx(Hu,{id:E.id,label:M.label.id,copied:M.action.copied,copyLabel:M.action.copy})]}),right:t.jsxs(t.Fragment,{children:[w&&!hn&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:M.detailTab.submitVersion}),Ne&&t.jsx("a",{href:Ne.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:o("meta-fg")},children:M.detailTab.dataLicense})]})});return hn?t.jsx("div",{className:C,children:t.jsxs(Mt,{grid:!0,style:{minHeight:T,...P},children:[t.jsx(Mn,{breadcrumb:t.jsx(Fn,{items:Xt}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Kn,{style:{border:"none",background:"transparent"}}),Ne&&t.jsx(qn,{...Ne})]})}),Li(),Bi]})}):t.jsx("div",{className:C,children:t.jsxs(Mt,{wide:Qt,style:{minHeight:T,...P},children:[t.jsx(Mn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(di,{char:"籍"}),t.jsx(Fn,{items:Xt})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Kn,{}),w&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:M.detailTab.feedback}),Ne&&t.jsx(qn,{...Ne})]})}),t.jsx(Pr,{...Ze,aside:Qt?t.jsxs("button",{type:"button",onClick:()=>l("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("accent"),borderBottom:`1px solid ${o("rule")}`},children:[A("作品信息")," →"]}):Ze.aside}),!Qt&&he.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:he.map(H=>t.jsx(Or,{label:H.label,active:H.key===s||hn&&H.key==="basic",onClick:()=>l(H.key)},H.key))}),t.jsx("div",{style:{marginTop:!Qt&&he.length>1?8:0},children:nl()}),Bi]})})};function Hu({id:e,label:n,copied:i,copyLabel:r}){const[s,l]=g.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 c;(c=navigator.clipboard)==null||c.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 Gu(e,n){return n?e.workSubtype[n]??n:""}exports.BidLink=be.BidLink;exports.BookIndexError=be.BookIndexError;exports.BookIndexManager=be.BookIndexManager;exports.BookIndexStorage=be.BookIndexStorage;exports.BundleStorage=be.BundleStorage;exports.ConfigError=be.ConfigError;exports.GithubStorage=be.GithubStorage;exports.IdGenerationError=be.IdGenerationError;exports.IdGenerator=be.IdGenerator;exports.LocalStorage=be.LocalStorage;exports.MigrationError=be.MigrationError;exports.StorageError=be.StorageError;exports.base36Decode=be.base36Decode;exports.base36Encode=be.base36Encode;exports.base58Decode=be.base58Decode;exports.buildId=be.buildId;exports.buildPromotionMap=be.buildPromotionMap;exports.cleanName=be.cleanName;exports.decodeId=be.decodeId;exports.decodeIdString=be.decodeIdString;exports.encodeId=be.encodeId;exports.extractIdFromUrl=be.extractIdFromUrl;exports.extractStatus=be.extractStatus;exports.extractType=be.extractType;exports.normalizeCatalog=be.normalizeCatalog;exports.parseId=be.parseId;exports.shardOf=be.shardOf;exports.smartDecode=be.smartDecode;exports.validateResource=be.validateResource;exports.Badge=an;exports.BidUrlProvider=ul;exports.BookDetailLayout=Du;exports.BookFullText=Gn;exports.BookPage=Ps;exports.Breadcrumb=Fn;exports.CATALOG_ALL_ID=Qe;exports.CATALOG_CSS=Hs;exports.CATALOG_NARROW_QUERY=Ri;exports.CATALOG_PAGE_SIZE=Ei;exports.CATALOG_UNCLASSIFIED_ID=Dt;exports.CardFoot=Yt;exports.CatalogPage=fu;exports.CatalogPager=Ks;exports.CatalogTree=Us;exports.CheckFilter=Mr;exports.Chip=Dr;exports.ChipWall=qa;exports.CollatedEdition=zi;exports.CollectionCatalog=ni;exports.CollectionPage=Os;exports.CreateEntityDialog=zs;exports.DEFAULT_READER_PREFS=xi;exports.DETAIL_CSS=Fr;exports.Dash=tc;exports.DataTable=Za;exports.DetailFooter=qr;exports.DetailGrid=Ut;exports.DetailHeader=Pr;exports.EmendatedBySection=jr;exports.EmptyNote=ac;exports.EntityDetail=fr;exports.EntityPage=Ds;exports.EntityPickerDialog=Is;exports.EntitySelector=$s;exports.ExpandRow=nc;exports.ExtLink=cc;exports.FEEDBACK_FAB_OFFSET_VAR=Vn;exports.FONT_SIZE_STEPS=yt;exports.FactList=Ua;exports.FeedbackButton=Np;exports.FeedbackDialog=Ns;exports.FeedbackForm=Ls;exports.FeedbackList=Ci;exports.FeedbackTab=Bs;exports.FilterChip=Or;exports.FormInput=Me;exports.FormTextArea=ut;exports.GUJI_MARKDOWN_FIELD=Ea;exports.GUJI_TABLE_NOTATION=rs;exports.GlyphBadge=di;exports.GujiTable=hi;exports.HomePage=Hn;exports.ImagePanel=ts;exports.IndexApp=Wd;exports.IndexBrowser=Nn;exports.IndexDetail=ti;exports.IndexEditor=Ts;exports.IndexView=jp;exports.IntroGrid=Ga;exports.LocaleContext=_t;exports.LocaleProvider=kl;exports.LocaleToggle=Kn;exports.MetaLine=Ie;exports.ModeIndicator=pr;exports.MoreButton=Ka;exports.MoreLink=Ct;exports.PAGE_MAX_WIDTH=Wt;exports.PageFrame=Mt;exports.Quote=oc;exports.READER_CSS=Xr;exports.RECENT_IDS_STORAGE_KEY=vt;exports.ROLE_CLASS_ORDER=zr;exports.ReadButton=Wn;exports.ReaderMdText=vi;exports.ReaderShell=gi;exports.ReaderToc=es;exports.RelationPanel=ws;exports.RepoSourceLink=qn;exports.ResourceEditor=En;exports.ResourceGroup=rc;exports.ResourceLine=sc;exports.ResourceList=ei;exports.ResourceRow=Yr;exports.SNIPPET_MARK_END=or;exports.SNIPPET_MARK_START=ir;exports.SearchInput=ur;exports.Sec=Te;exports.Section=Oe;exports.SectionHead=Va;exports.SideList=pt;exports.SmartBidInput=nn;exports.SourceEditor=vs;exports.SummaryCard=Vt;exports.TabFilter=ai;exports.TableHead=Xa;exports.TableRow=Qa;exports.TagRow=Kr;exports.TagRows=lc;exports.TextButton=Ya;exports.TopStrip=Mn;exports.VersionLineageGraph=Xs;exports.VersionLineageList=Zs;exports.VersionLineageView=Qs;exports.VolumeChips=Ja;exports.VolumeLinks=pi;exports.WorkCard=Ys;exports.WorkCardGrid=qs;exports.WorkCatalog=Fd;exports.WorkPage=Fs;exports.bucketResources=ri;exports.buildCatalogTree=ou;exports.buildCollectionTable=Ir;exports.buildLineageGraph=on;exports.buildPageUrl=Qn;exports.buildParagraphBlocks=xs;exports.buildVersionRow=_r;exports.buildVersionTable=$r;exports.canParagraphize=mn;exports.catalogNodeIdOf=nu;exports.catalogNodeIdsOf=iu;exports.catalogPageCount=au;exports.catalogTotal=Ni;exports.classificationPath=qt;exports.compareCatalogCards=lu;exports.computeVersionPartition=Ca;exports.defaultWorkLink=Vs;exports.deriveDating=_a;exports.deriveEditionType=Rr;exports.deriveEra=Gt;exports.deriveYear=un;exports.deriveYearRange=oi;exports.detailToEditor=Es;exports.detectGenre=gn;exports.displayAuthorRole=li;exports.editorToDetail=yp;exports.eraRank=Bn;exports.findCatalogPath=jt;exports.flattenTitles=Pn;exports.flattenToc=os;exports.formatTemplate=Ht;exports.formatVolumeRange=fn;exports.getDisplayNameFromUrl=$t;exports.getStartPage=Xn;exports.getTypeGroupKey=Jn;exports.groupRelatedWorks=$a;exports.gujiInlineToPlain=Br;exports.hasGujiMarkdownV02=An;exports.hasGujiTableNotation=ss;exports.measureText=nt;exports.mergeVolumeResources=Zn;exports.normalizeEra=Ce;exports.normalizeRole=si;exports.normalizeVolumeIndex=Pt;exports.normalizeVolumes=dr;exports.numberToChinese=Tr;exports.paginationItems=Gs;exports.parseChineseNumber=rn;exports.parseGujiInline=Lr;exports.parseGujiTable=as;exports.parseSourceString=ks;exports.pickReaderVersion=is;exports.readerVersionOptionLabel=Dn;exports.readerVersionsFromFullText=bc;exports.renderFullTextBody=Nc;exports.renderProperNames=gs;exports.renderReaderInline=ji;exports.resourceHref=zt;exports.resourceNote=xn;exports.roleFacets=Cr;exports.rowNo=ec;exports.sortYear=sn;exports.splitFullTextTables=mi;exports.splitHighlightSnippet=rr;exports.splitTableRow=ls;exports.stringifySources=Ss;exports.toCatalogWorkCard=su;exports.useBidUrl=Re;exports.useConvert=U;exports.useReaderPrefs=fi;exports.useT=ce;exports.validateLineageGraph=yu;exports.volumeStats=cn;
802
+ `,Ht="未分類",et="all",Ei=20;function Jt(e){if(!e)return[];const n=[];for(const i of[e.l1,e.l2,e.l3,e.l4]){const r=(i??"").trim();if(!r)break;n.push(r)}return n}function cu(e){const n=Jt(e);return n.length?n.join("/"):Ht}function du(e){const n=Jt(e);return n.length?n.map((i,r)=>n.slice(0,r+1).join("/")):[Ht]}function pu(e,n=[]){const i=new Map;n.forEach((p,a)=>{const d=[p.cata_l1,p.cata_l2,p.cata_l3,p.cata_l4].filter(u=>!!u);d.forEach((u,f)=>{const x=d.slice(0,f+1).join("/");i.has(x)||i.set(x,a)})});const r=new Map;let s=0;for(const p of e){const a=Jt(p.classification);if(!a.length){s++;continue}let d=r;a.forEach((u,f)=>{const x=a.slice(0,f+1).join("/");let m=d.get(u);m||(m={id:x,label:u,count:0,children:new Map},d.set(u,m)),m.count++,d=m.children})}const l=p=>[...p.values()].sort((a,d)=>{const u=i.get(a.id)??1/0,f=i.get(d.id)??1/0;return u!==f?u-f:a.label.localeCompare(d.label,"zh")}).map(a=>{const d={id:a.id,label:a.label,count:a.count};return a.children.size&&(d.children=l(a.children)),d}),c=l(r);return s>0&&c.push({id:Ht,label:Ht,count:s}),c}function vt(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const r=vt(i.children,n);if(r.length)return[i,...r]}}return[]}function Ni(e){return e.reduce((n,i)=>n+i.count,0)}function uu(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function xu(e){var p;const n={id:e.id,title:e.title||e.id},i=e.juan_count,r=typeof i=="number"?i:i==null?void 0:i.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(a=>a==null?void 0:a.name).map(a=>{const d=a.dynasty||(e.authors.length===1?e.dynasty:void 0);return d?{name:a.name,dynasty:d}:{name:a.name}});s.length&&(n.authors=s);const l=uu(typeof e.description=="string"?e.description:(p=e.description)==null?void 0:p.text);l&&(n.summary=l);const c=Jt(e.classification);return c.length&&(n.classification=c),n}function fu(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 gu(e,n=Ei){return Math.max(1,Math.ceil(e/n))}function Vs(e,n,i=2){if(n<=1)return[1];const r=new Set([1,n]);for(let c=e-i;c<=e+i;c++)c>=1&&c<=n&&r.add(c);const s=[...r].sort((c,p)=>c-p),l=[];return s.forEach((c,p)=>{if(p>0){const a=c-s[p-1];a===2?l.push(c-1):a>2&&l.push(null)}l.push(c)}),l}const mu=()=>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 hu(e,n,i){const r=[];i&&r.push({id:et,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,c)=>{var p;for(const a of l){const d=(p=a.children)!=null&&p.length?a.children:null;r.push({id:a.id,parentId:c,hasChildren:!!d,firstChildId:d?d[0].id:null}),d&&n.has(a.id)&&s(d,a.id)}};return s(e,null),r}function Ys({tree:e,selectedId:n,onSelect:i,allLabel:r="全部",label:s="分類"}){const{convert:l}=Y(),c=g.useRef(null),p=n&&n!==et?n:null,a=r!==null,[d,u]=g.useState(()=>{const S=new Set;for(const _ of vt(e,p))S.add(_.id);return S});g.useEffect(()=>{const S=vt(e,p);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,p]);const f=g.useMemo(()=>hu(e,d,a),[e,d,a]),[x,m]=g.useState(null);g.useEffect(()=>{m(null)},[n]);const h=p??(a?et:null),k=g.useMemo(()=>{var w;const S=new Set(f.map(z=>z.id));if(x&&S.has(x))return x;if(h&&S.has(h))return h;const _=vt(e,p).map(z=>z.id).filter(z=>S.has(z));return _.length?_[_.length-1]:((w=f[0])==null?void 0:w.id)??null},[f,x,h,e,p]),b=g.useCallback((S,_)=>{u(w=>{const z=w.has(S),T=_??!z;if(T===z)return w;const R=new Set(w);return T?R.add(S):R.delete(S),R})},[]),j=g.useCallback(S=>{m(S),requestAnimationFrame(()=>{var w;const _=Array.from(((w=c.current)==null?void 0:w.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===S);_==null||_.focus()})},[]),y=g.useCallback((S,_)=>{_&&b(S,!0),i(S)},[i,b]),v=g.useCallback(S=>{const _=S.target.closest("[data-ct-id]");if(!_)return;const w=_.dataset.ctId,z=f.findIndex(C=>C.id===w);if(z<0)return;const T=f[z];let R=null;switch(S.key){case"ArrowDown":R=f[Math.min(f.length-1,z+1)].id;break;case"ArrowUp":R=f[Math.max(0,z-1)].id;break;case"Home":R=f[0].id;break;case"End":R=f[f.length-1].id;break;case"ArrowRight":if(!T.hasChildren)break;d.has(w)?R=T.firstChildId:b(w,!0);break;case"ArrowLeft":T.hasChildren&&d.has(w)?b(w,!1):R=T.parentId;break;case"Enter":case" ":S.preventDefault(),y(w,T.hasChildren);return;default:return}S.preventDefault(),R&&R!==w&&j(R)},[f,d,b,j,y]),$=(S,_)=>S.map((w,z)=>{var M;const T=(M=w.children)!=null&&M.length?w.children:null,R=!!T&&d.has(w.id),C=w.id===p,O=_===1&&S.length>1&&z===S.length-1;return t.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":T?R:void 0,"aria-selected":C,tabIndex:k===w.id?0:-1,"data-ct-id":w.id,className:O?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{m(w.id),y(w.id,!!T)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:T?A=>{A.stopPropagation(),m(w.id),b(w.id)}:void 0,children:T?t.jsx(mu,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(w.label)}),t.jsx("span",{className:"bim-ct-n",children:w.count.toLocaleString("en-US")})]}),R&&t.jsx("ul",{role:"group",children:$(T,_+1)})]},w.id)});return t.jsxs("ul",{ref:c,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:v,children:[a&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:k===et?0:-1,"data-ct-id":et,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{m(et),i(et)},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:Ni(e).toLocaleString("en-US")})]})}),$(e,1)]})}const Ks=e=>`/item/${encodeURIComponent(e)}`;function bu(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function yu(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function qs({work:e,href:n}){var c,p;const{convert:i}=Y(),r=yu(e.juan),s=((c=e.authors)==null?void 0:c.filter(a=>a.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:n,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:i(e.title)}),r&&t.jsx("span",{className:"bim-ct-juan",children:i(r)})]}),s.length>0&&t.jsx("span",{className:"bim-ct-by",children:s.map((a,d)=>t.jsxs(g.Fragment,{children:[d>0&&"、",a.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(a.dynasty),"〕"]}),i(a.name)]},d))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:i(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(a=>i(a)).join(" · ")})]})})}function Js({page:e,pageCount:n,onPage:i,pageHref:r,label:s="分頁"}){const{convert:l}=Y();if(n<=1)return null;const c=a=>d=>{i&&(r&&!bu(d)||(d.preventDefault(),i(a)))},p=(a,d,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const f={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...f,href:r(a),onClick:c(a),children:d}):t.jsx("button",{type:"button",...f,onClick:u.current?void 0:c(a),children:d})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:Vs(e,n).map((a,d)=>t.jsx("li",{style:{display:"contents"},children:a===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(a,a,{current:a===e,aria:l(`第 ${a} 頁`)})},a??`gap${d}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),p(e+1,l("下一頁"),{disabled:e>=n})]})}function Zs({works:e,workLink:n=Ks,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(qs,{work:l,href:n(l.id)},l.id))}),t.jsx(Js,{...r})]})}const ju=()=>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 vu({tree:e,selectedId:n,page:i,pageCount:r,works:s,onSelect:l,onPage:c,searchSlot:p,workLink:a,pageHref:d,allLabel:u="全部",allTitle:f="全部典籍",pageSize:x=Ei,className:m}){const{convert:h}=Y(),b=`bim-ct-drawer-${g.useId().replace(/:/g,"")}`,[j,y]=g.useState(!1),v=vt(e,n&&n!==et?n:null),$=v.length?v[v.length-1]:null,S=$?$.label:f,_=$?$.count:Ni(e),w=g.useCallback(z=>{y(!1),l(z)},[l]);return t.jsxs("div",{className:m?`bim-ct ${m}`:"bim-ct","data-drawer":j?"open":"closed",children:[t.jsx("style",{children:Us}),t.jsxs("aside",{className:"bim-ct-side","aria-label":h("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":j,"aria-controls":b,onClick:()=>y(z=>!z),children:[t.jsxs("span",{children:[h("分類"),":",h(v.length?v.map(z=>z.label).join(" › "):u??f)]}),t.jsx(ju,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:b,children:[t.jsx("h2",{className:"bim-ct-side-h",children:h("分類")}),t.jsx(Ys,{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:h(S)}),v.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:h(v.slice(0,-1).map(z=>z.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[h(`共 ${_.toLocaleString("en-US")} 種 · 每頁 ${x} 條`),r>1&&h(` · 第 ${i} / ${r} 頁`)]})]}),p&&t.jsx("div",{className:"bim-ct-search",children:p}),t.jsx(Zs,{works:s,workLink:a,page:i,pageCount:r,onPage:c,pageHref:d})]})]})}function ku(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 Su(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 Ko(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 wu(e,n,i){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${i}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function _u(e,n){var d;if(n==="all")return null;const i=(d=e.collections)==null?void 0:d[n],r=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,l=r||s||!!(i!=null&&i.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!i||!l)return null;const c=r?new Set(i.groups):null,p=new Set(i.book_ids??[]);if(c&&e.node_groups)for(const[u,f]of Object.entries(e.node_groups))c.has(f)&&p.add(u);let a=null;if(i.hypothetical_ids&&(a=new Set(i.hypothetical_ids)),c){a||(a=new Set);for(const u of e.hypothetical_nodes??[])u.group&&c.has(u.group)&&a.add(u.id)}return{books:p,hypos:a}}function on(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??[]),c=r.node_groups??{},p=_u(r,i??r.default_collection??"all"),a=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,f=new Set,x=new Set;if(a){const $=new Map(n.map(R=>[R.id,R])),S=new Map((r.hypothetical_nodes??[]).map(R=>[R.id,R])),_=R=>{const C=$.get(R);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(M=>M.ref);const O=S.get(R);return O?(O.derived_from??[]).map(M=>M.ref):[]},w=R=>S.has(R)?!u||u.has(R):!d||d.has(R),z=new Set,T=R=>{if(!z.has(R)){z.add(R);for(const C of _(R))l.has(C)||(w(C)||(S.has(C)?x.add(C):$.has(C)&&f.add(C)),T(C))}};for(const R of n)d&&d.has(R.id)&&!l.has(R.id)&&T(R.id);for(const R of r.hypothetical_nodes??[])u&&u.has(R.id)&&T(R.id)}const m=n.filter($=>!l.has($.id)).filter($=>!d||d.has($.id)||f.has($.id)).map($=>{const S=Su($,c);return S&&f.has($.id)&&(S.bridge=!0),S}).filter($=>$!==null),h=(r.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||x.has($.id)).map($=>{const S=ku($);return x.has($.id)&&(S.bridge=!0),S}),k=[...m,...h],b=new Set(k.map($=>$.id)),j=new Set,y=[],v=$=>{j.has($.id)||!b.has($.source)||!b.has($.target)||(j.add($.id),y.push($))};for(const $ of n)l.has($.id)||!$.lineage||d&&!d.has($.id)&&!f.has($.id)||(($.lineage.derived_from??[]).forEach((S,_)=>{v(Ko($.id,S,_))}),($.lineage.related_to??[]).forEach((S,_)=>{v(wu($.id,S,_))}));for(const $ of r.hypothetical_nodes??[])u&&!u.has($.id)&&!x.has($.id)||($.derived_from??[]).forEach((S,_)=>{v(Ko($.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 Xs(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function $u(e,n){const i=[],r=e.version_graph;if(!r)return i;const s=new Set(n.map(a=>a.id)),l=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),c=new Set([...s,...l]),p=(a,d)=>{c.has(d.ref)||i.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(u=>p(d,u)),(a.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||i.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(u=>p(d,u))}return i}const Qs=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:s}=Y();if(!e.nodes.length)return t.jsx("div",{style:{...Pu,...r},className:i,children:"暂无版本图数据"});const l=new Map,c=new Map;for(const x of e.edges)if(x.kind==="derive"){const m=l.get(x.target)??[];m.push(x),l.set(x.target,m)}else for(const m of[x.source,x.target]){const h=c.get(m)??[];h.push(x),c.set(m,h)}const p=new Map(e.nodes.map(x=>[x.id,x])),a=new Map,d=[];for(const x of e.nodes)if(x.group){const m=a.get(x.group)??[];m.push(x),a.set(x.group,m)}else d.push(x);const u=(x,m)=>(x.year??9999)-(m.year??9999);a.forEach(x=>x.sort(u)),d.sort(u);const f=e.groups.filter(x=>a.has(x.id));return t.jsxs("div",{className:i,style:{...Cu,...r},children:[e.title&&t.jsx("div",{style:Iu,children:s(e.title)}),e.description&&t.jsx("div",{style:Tu,children:s(e.description)}),f.map(x=>t.jsx(qo,{label:x.label,color:x.color,nodes:a.get(x.id),incomingMap:l,siblingMap:c,nodeMap:p,renderLink:n},x.id)),d.length>0&&t.jsx(qo,{label:"其他",nodes:d,incomingMap:l,siblingMap:c,nodeMap:p,renderLink:n})]})},qo=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:c})=>{const{convert:p}=Y();return t.jsxs("div",{style:Ru,children:[t.jsx("div",{style:{...Eu,borderLeftColor:n??o("widget-border")},children:p(e)}),i.map(a=>t.jsx(zu,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:l,renderLink:c},a.id))]})},zu=({node:e,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",c=e.bridge,{convert:p}=Y();return t.jsxs("div",{style:{...Nu,borderStyle:l||c?"dashed":"solid",opacity:c?.55:e.status==="lost"?.7:1,background:c?o("bg-subtle"):void 0},title:c?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:Lu,children:[t.jsx("span",{style:Bu,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Au,children:Xs(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Wu,children:[e.category&&t.jsx(Wt,{children:p(e.category)}),e.status==="lost"&&t.jsx(Wt,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(Wt,{tone:"warn",children:"残本"}),l&&t.jsx(Wt,{tone:"info",children:"假想祖本"}),c&&t.jsx(Wt,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Mu,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:Fu,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:Zo,children:[t.jsx("div",{style:Xo,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return t.jsxs("div",{style:Qo(a.confidence),children:[t.jsx("span",{style:er,children:p(a.relation)}),t.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,p(d.label)):p((d==null?void 0:d.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&t.jsx(Jo,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:tr,children:["· ",p(a.evidence)]})]},a.id)})]}),i.length>0&&t.jsxs("div",{style:Zo,children:[t.jsx("div",{style:Xo,children:"关联:"}),i.map(a=>{const d=a.source===e.id?a.target:a.source,u=r.get(d);return t.jsxs("div",{style:Qo(a.confidence),children:[t.jsx("span",{style:er,children:p(a.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,p(u.label)):p((u==null?void 0:u.label)??d)}),t.jsx(Jo,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:tr,children:["· ",p(a.evidence)]})]},a.id)})]})]})},Wt=({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})},Jo=({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},Cu={fontSize:"14px",color:o("fg")},Iu={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Tu={fontSize:"13px",color:o("muted"),marginBottom:"16px",lineHeight:1.6},Ru={marginBottom:"16px"},Eu={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:o("fg")},Nu={border:`1px solid ${o("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:o("bg")},Lu={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Bu={fontSize:"15px",fontWeight:600},Au={fontSize:"12px",color:o("muted")},Wu={marginBottom:"6px"},Mu={fontSize:"12px",color:o("muted"),margin:"2px 0"},Fu={fontSize:"12px",color:o("muted"),fontStyle:"italic",margin:"4px 0"},Zo={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${o("widget-border")}`},Xo={fontSize:"11px",color:o("muted"),marginBottom:"2px"},Qo=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),er={display:"inline-block",padding:"0 6px",fontSize:"11px",background:o("tag-bg"),color:o("fg"),borderRadius:"3px",marginRight:"6px"},tr={fontSize:"11px",color:o("muted")},Pu={padding:"20px",textAlign:"center",color:o("muted"),fontSize:"13px"},el=({selectedNodeId:e,...n})=>{const[i,r]=g.useState("loading"),[s,l]=g.useState(null);return g.useEffect(()=>{let c=!1;return Ou().then(p=>{c||(p?(l(p),r("ready")):r("missing"))}),()=>{c=!0}},[]),i==="loading"?t.jsx("div",{style:nr,children:"加载图组件中…"}):i==="missing"||!s?t.jsxs("div",{style:nr,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(Du,{modules:s,selectedNodeId:e,...n})};async function Ou(){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 Du=({graph:e,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:l,modules:c})=>{const{ReactFlow:p,Background:a,Controls:d,Handle:u,Position:f,BaseEdge:x,EdgeLabelRenderer:m,getSmoothStepPath:h,dagre:k}=c,b=g.useMemo(()=>({lineage:_=>{var G,U,E,ie;const w=((G=_.data)==null?void 0:G.stepPosition)??.85,[z,T,R]=h({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:w,borderRadius:5}),C=!!((U=_.data)!=null&&U.isSibling),O=C?T:_.targetX-18,M=C?R:_.targetY-12,A=(E=_.data)==null?void 0:E.labelStyle,F=(ie=_.data)==null?void 0:ie.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(x,{id:_.id,path:z,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&t.jsx(m,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${O}px,${M}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:o("bg"),border:`0.5px solid ${o("widget-border")}`,...F,...A},children:_.label})})]})}}),[x,m,h]),j=g.useMemo(()=>({version:_=>{const w=_.data,z=w.kind==="hypothetical",T=w.status==="lost",R=w.isSelected,C=w.bridge,O=w.borderColor??o("muted"),M=C||z?"dashed":"solid",A=C?.5:T?.6:1;return t.jsxs("div",{style:{background:o(C?"bg-subtle":"bg"),border:`2px ${M} ${R?o("primary"):O}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:A,boxShadow:R?o("shadow-node-selected"):z||C?"none":o("shadow-node")},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:f.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:Xs(w.yearText,void 0,w.uncertain)}),T&&t.jsx("div",{style:{fontSize:9,color:o("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:f.Right,style:{visibility:"hidden"}})]})}}),[u,f]),{convert:y}=Y(),{rfNodes:v,rfEdges:$}=g.useMemo(()=>Hu(e,k,n,l,y),[e,k,n,l,y]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:t.jsxs(p,{nodes:v,edges:$,nodeTypes:j,edgeTypes:b,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(a,{gap:16}),t.jsx(d,{showInteractive:!1})]})})};function Hu(e,n,i,r,s=l=>l??""){const p=e.layout==="LR"||!e.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:p?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(e.groups.map(j=>[j.id,j.color??o("muted")]));for(const j of e.nodes)a.setNode(j.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of e.edges)j.kind==="derive"&&(u.has(j.relation)||a.setEdge(j.source,j.target));n.layout(a);const f=e.nodes.map(j=>{const y=a.node(j.id),v=r?j.id===r:void 0,$={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??Uu(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:i,isSelected:v,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:y.x-160/2,y:y.y-90/2},data:$,draggable:!1,selected:v}}),x=.78,m=.06,h=new Map;for(const j of e.edges)j.kind==="derive"&&(h.has(j.source)||h.set(j.source,[]),h.get(j.source).push(j));const k=new Map;for(const[j,y]of h){if(y.length<=1)continue;const v=[...y].sort((S,_)=>{var T,R;const w=((T=a.node(S.target))==null?void 0:T.y)??0,z=((R=a.node(_.target))==null?void 0:R.y)??0;return w-z}),$=v.length;v.forEach((S,_)=>{const w=(_-($-1)/2)*m;k.set(S.id,x+w)})}const b=e.edges.map(j=>Gu(j,k.get(j.id),s));return{rfNodes:f,rfEdges:b}}function Gu(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Vu(e.confidence),c={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:c,markerStart:s?c:void 0,zIndex:1e3}}function Uu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Vu(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 nr={padding:"40px 20px",textAlign:"center",color:o("muted"),fontSize:"13px",border:`1px dashed ${o("widget-border")}`,borderRadius:8,background:o("bg")},tl=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:c,onCollectionChange:p,collectionsAvailable:a,collectionCounts:d,className:u,style:f})=>{var y;const[x,m]=g.useState(n),h=v=>{m(v),l==null||l(v)},k=(()=>{if(!a)return[];const v=Object.entries(a);return v.length===0||a.all?v:[...v,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),b=!!(p&&k.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:o("muted"),textAlign:"center"},children:"暂无版本传承数据"});const j=c?(y=a==null?void 0:a[c])==null?void 0:y.description:void 0;return t.jsxs("div",{className:u,style:f,children:[t.jsxs("div",{style:Yu,children:[t.jsx("button",{onClick:()=>h("list"),style:In(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>h("graph"),style:In(x==="graph"),children:"关系图"}),b&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:o("muted"),marginRight:4},children:"集合:"}),k.map(([v,$])=>{const S=d==null?void 0:d[v];return t.jsxs("button",{onClick:()=>p==null?void 0:p(v),style:In(c===v),title:$.description,children:[$.label,S!=null?` ${S}`:""]},v)})]})]}),b&&j&&t.jsx("div",{style:{fontSize:12,color:o("muted"),marginBottom:8,padding:"4px 8px",background:o("bg-subtle"),borderRadius:4},children:j}),x==="list"?t.jsx(Qs,{graph:e,renderLink:i}):t.jsx(el,{graph:e,renderLink:i,height:r,selectedNodeId:s})]})},Yu={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},In=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"}),Kn=({style:e})=>{const n=g.useContext($t);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:"简"})]})},qn=({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 Tn(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 qu=({id:e,transport:n,initialDetail:i,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:c,onJuanChange:p,lineageMode:a="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:f,initialPage:x=1,selectedLineageNodeId:m,onNavigate:h,onBack:k,backLabel:b,renderLink:j,enrichDetail:y,getSourceLink:v,readLink:$,railTop:S,extraTabs:_=[],showFeedbackTab:w=!0,feedbackApiUrl:z,height:T,footerExtra:R,className:C,style:O})=>{var Ai;const M=ae(),{convert:A}=Y(),[F]=g.useState(()=>{if(!Ku(e,i))return null;const H={...i},fe=r??Tn(e,H);return y&&y(fe,H),{id:e,entry:fe,detail:H}}),[G,U]=g.useState((F==null?void 0:F.entry)??null),[E,ie]=g.useState((F==null?void 0:F.detail)??null),[P,re]=g.useState(!F),[ce,K]=g.useState(!1),[V,q]=g.useState([]),[xe,oe]=g.useState(!1),[ne,D]=g.useState(null),[X,ee]=g.useState(!1),[N,I]=g.useState(null),[J,Q]=g.useState(!1),[pe,ue]=g.useState(null),[ke,_e]=g.useState([]),[W,B]=g.useState(!1),[te,se]=g.useState(null),[Se,me]=g.useState(null),[je,Je]=g.useState(!1),$e=g.useRef(null),[ze,Ze]=g.useState(null),lt=c!==void 0?c:ze,He=g.useCallback(H=>{p?p(H):Ze(H)},[p]),Tt=g.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){q([]);return}oe(!0);try{if(n.getCollectionCatalogs)q(await n.getCollectionCatalogs(H)||[]);else if(n.getCollectionCatalog){const fe=await n.getCollectionCatalog(H);q(fe?[{resource_id:"",data:fe}]:[])}}catch{q([])}finally{oe(!1)}},[n]),L=g.useCallback(async H=>{if(!n.getCollatedEditionIndex){D(null);return}ee(!0);try{D(await n.getCollatedEditionIndex(H))}catch{D(null)}finally{ee(!1)}},[n]),le=g.useCallback(async H=>{if(!n.getBookFullTextIndex){I(null);return}Q(!0);try{I(await n.getBookFullTextIndex(H))}catch{I(null)}finally{Q(!1),ue(H)}},[n]),de=g.useCallback(async H=>{var fe;if(!n.getWorkFullTextList){_e([]);return}B(!0);try{const ve=(await n.getWorkFullTextList(H)??[]).filter(Ce=>Ce.owner_type!=="Book");_e(ve),se(((fe=ve.find(Ce=>Ce.primary)??ve[0])==null?void 0:fe.key)??null)}catch{_e([])}finally{B(!1)}},[n]),be=g.useCallback(async(H,fe)=>{Je(!0);try{if(n.getLineageGraph){const Be=await n.getLineageGraph(H);Be&&me(Be)}const ve=fe.version_graph;if(!ve||!ve.enabled){Se||me(null),$e.current=null;return}const Ce=fe.books??[],Ge=[];for(const Be of Ce)try{const Ue=await n.getItem(Be);Ue&&Ge.push(Ue)}catch{}$e.current={work:fe,books:Ge};const Z=u??ve.default_collection??(ve.core_books&&ve.core_books.length>0?"core":"all"),we=Z==="core"&&Array.isArray(ve.core_books)&&ve.core_books.length>0?"core":Z??"all";me(on(fe,Ge,we))}catch{me(null),$e.current=null}finally{Je(!1)}},[n]),ye=g.useRef({initialDetail:i,initialEntry:r});ye.current={initialDetail:i,initialEntry:r},g.useEffect(()=>{let H=!1;const fe=Z=>{Z.type==="collection"?Tt(e):Z.type==="work"?(Z.has_collated&&L(e),(Z.version_graph||n.getLineageGraph)&&be(e,Z),n.getWorkFullTextList&&de(e)):Z.type==="book"&&Z.has_full_text&&n.getBookFullTextIndex&&le(e)},ve=ye.current;let Ce=null;if(F&&F.id===e)Ce=F;else if(ve.initialDetail&&ve.initialDetail.id===e){const Z={...ve.initialDetail},we=ve.initialEntry??Tn(e,Z);y&&y(we,Z),Ce={entry:we,detail:Z}}return Ce?(K(!1),q(Z=>Z.length?[]:Z),D(null),I(null),_e(Z=>Z.length?[]:Z),se(null),me(null),$e.current=null,U(Ce.entry),ie(Ce.detail),re(!1),fe(Ce.detail),()=>{H=!0}):((async()=>{re(!0),K(!1),U(null),ie(null),q([]),D(null),I(null),_e([]),se(null),me(null),$e.current=null;try{const Z=await n.getItem(e);if(H)return;if(!Z){K(!0);return}const we=Z;let Be=null;if(n.getEntry&&(Be=await n.getEntry(e),H))return;Be||(Be=Tn(e,we)),y&&y(Be,we),U(Be),ie(we),fe(we)}catch{H||K(!0)}finally{H||re(!1)}})(),()=>{H=!0})},[e,n,F,y,Tt,L,be,le,de]),g.useEffect(()=>{const H=$e.current;!H||!u||me(on(H.work,H.books,u))},[u]);const ge=[];if(E){if(ge.push({key:"basic",label:M.detailTab.basicInfo}),E.type==="collection"){xe&&V.length===0&&ge.push({key:"catalog:loading",label:`${M.detailTab.catalog}…`});for(const H of V)ge.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${A(H.short_name)}${M.detailTab.catalogSuffix}`:M.detailTab.collectionCatalog})}E.type==="work"&&(ne||X)&&s==="collated"&&ge.push({key:"collated",label:X?`${M.detailTab.collatedEdition}…`:M.detailTab.collatedEdition}),E.type==="book"&&(N||J)&&s==="fulltext"&&ge.push({key:"fulltext",label:J?`${M.detailTab.fullText}…`:M.detailTab.fullText}),E.type==="work"&&(ke.length>0||W)&&s==="fulltext"&&ge.push({key:"fulltext",label:W?`${M.detailTab.fullText}…`:M.detailTab.fullText}),E.type==="work"&&(Se||je)&&ge.push({key:"lineage",label:je?`${M.detailTab.lineage}…`:M.detailTab.lineage});for(const H of _)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(E)&&ge.push({key:H.key,label:H.label});w&&s==="feedback"&&ge.push({key:"feedback",label:M.detailTab.feedback});for(const H of _)H.position==="after-feedback"&&H.shouldShow(E)&&ge.push({key:H.key,label:H.label})}g.useEffect(()=>{if(s!=="emendated"||!E)return;l("basic");const H=setTimeout(()=>{var fe;(fe=document.getElementById("studies"))==null||fe.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[s,E,l]);const Le=G&&E&&v?v({activeTab:s,activeJuan:lt,entry:G,detail:E}):null,Xe=g.useMemo(()=>{var Ge;if(!E)return null;const fe=(E.authors??[]).map(Z=>{const we=li(Z.role);return`${Z.dynasty?`〔${A(Z.dynasty)}〕`:""}${A(Z.name)}${we?` ${A(we)}`:""}`}).join(" · ");let ve=!1;try{ve=he.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const Z=E;return{title:A(Z.title),subtitle:Z.edition?A(Z.edition):fe||void 0,aside:[ve?M.status.draft:"",fe&&Z.edition?fe:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const Z=E;return{title:A(Z.title),subtitle:A(it(Z,M.unit.juan))||void 0,aside:[(Ge=Z.publication_info)==null?void 0:Ge.year,ve?M.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:fe||void 0}}if(E.type==="entity"){const Z=E,we=Ue=>Ue==null?"":Ue<0?`前${-Ue}`:String(Ue),Be=Z.birth_year!=null||Z.death_year!=null?`${we(Z.birth_year)||"?"}—${we(Z.death_year)||"?"}`:"";return{title:A(Z.primary_name||Z.title),subtitle:[Z.dynasty?`〔${A(Z.dynasty)}〕`:"",Be].filter(Boolean).join(" ")||void 0,aside:ve?M.status.draft:void 0,secondLine:void 0}}const Ce=A(it(E,M.unit.juan));return{title:A(E.title),subtitle:[Ce,fe].filter(Boolean).join(" · ")||void 0,aside:[Zu(M,E.subtype),ve?M.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,A,M]),at=E?E.type==="work"?(((Ai=ne==null?void 0:ne.juan_files)==null?void 0:Ai.length)??0)>0?"collated":ke.length>0?"fulltext":null:E.type==="book"&&(((N==null?void 0:N.chapters.length)??0)>0||E.has_full_text&&n.getBookFullTextIndex&&pe!==E.id)?"fulltext":null:null,ot=ke.find(H=>H.primary)??ke[0],Ae=()=>{var H;at==="collated"&&((H=ne==null?void 0:ne.juan_files)!=null&&H.length)?(He(ne.juan_files[0]),l("collated")):at==="fulltext"&&((E==null?void 0:E.type)==="work"&&ot&&se(ot.key),He(null),l("fulltext"))};let Rt=null;if(E&&$){const H=$({detail:E,kind:at,fullTextKey:E.type==="work"?ot==null?void 0:ot.key:void 0});H&&(Rt=t.jsx(Wn,{href:H}))}else at&&(Rt=t.jsx(Wn,{onClick:Ae}));const nl=H=>{if(!E)return null;const fe=H.replace(/\.[^.]+$/,"");if($){const ve=$({detail:E,kind:"fulltext",juan:fe});return ve?{href:ve}:null}return{onClick:()=>{He(fe),l("fulltext")}}},il=new Set(_.map(H=>H.key)),Zt=ge.filter(H=>H.key.startsWith("catalog:")&&H.key!=="catalog:loading"||il.has(H.key)).map(H=>({key:H.key,label:H.label,onClick:()=>l(H.key)})),Li=()=>{var H;return E?E.type==="work"?t.jsx(Os,{data:E,transport:n,onNavigate:h,renderLink:j,readAction:Rt,railTop:S,railLinks:Zt}):E.type==="book"?t.jsx(Ds,{data:E,transport:n,onNavigate:h,renderLink:j,readAction:Rt,fullText:N,fullTextPending:!!E.has_full_text&&!!n.getBookFullTextIndex&&pe!==E.id,chapterLink:nl,railTop:S,railLinks:Zt}):E.type==="collection"?t.jsx(Hs,{data:E,catalog:(H=V[0])==null?void 0:H.data,transport:n,onNavigate:h,renderLink:j,readAction:Rt,railTop:S,railLinks:Zt,catalogAction:V.length>0?t.jsxs("a",{href:"#catalog",onClick:fe=>{fe.preventDefault(),l(`catalog:${V[0].resource_id}`)},children:[A(M.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Gs,{data:E,transport:n,onNavigate:h,renderLink:j,railTop:S,railLinks:Zt}):null},ol=()=>{var fe,ve,Ce,Ge;if(!G||!E)return null;if(s==="basic"||s==="emendated")return Li();if(typeof s=="string"&&s.startsWith("catalog:")){const Z=(fe=V.find(we=>`catalog:${we.resource_id}`===s))==null?void 0:fe.data;return t.jsx(ni,{data:Z,onNavigate:h,renderLink:j})}if(s==="collated")return t.jsx(zi,{index:ne||void 0,workId:e,transport:n,onNavigate:h,activeJuan:lt,onJuanChange:He});if(s==="fulltext"&&E.type==="work"){const Z=te??((ve=ke[0])==null?void 0:ve.key);return Z?t.jsx(Gn,{bookId:e,workKey:Z,versions:ke,onVersionChange:we=>{se(we),He(null)},transport:n,activeChapter:lt,onChapterChange:He},Z):t.jsx("div",{style:{padding:24,color:o("desc-fg")},children:W?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(Gn,{index:N||void 0,bookId:e,transport:n,activeChapter:lt,onChapterChange:He});if(s==="lineage"){if(!Se)return t.jsx("div",{style:{color:o("label-fg"),padding:"24px 0"},children:je?"加載中…":"暫無版本圖數據"});const Z=E.type==="work"?E:null;return t.jsx(tl,{graph:Se,renderLink:j,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:a,onModeChange:d,selectedNodeId:m,collection:u??((Ce=Z==null?void 0:Z.version_graph)==null?void 0:Ce.default_collection),onCollectionChange:f,collectionsAvailable:(Ge=Z==null?void 0:Z.version_graph)==null?void 0:Ge.collections,collectionCounts:(()=>{var Wi,Mi,Fi,Pi,Oi,Di,Hi;if(!Z)return;const we={},Be=((Wi=$e.current)==null?void 0:Wi.books)??[];we.all=(((Mi=Z.books)==null?void 0:Mi.length)??0)-(((Pi=(Fi=Z.version_graph)==null?void 0:Fi.excluded_books)==null?void 0:Pi.length)??0);const Ue=(Oi=Z.version_graph)==null?void 0:Oi.collections;if(Ue)for(const Gi of Object.keys(Ue))we[Gi]=on(Z,Be,Gi).nodes.filter(Ui=>Ui.kind==="book"&&!Ui.bridge).length;return we.core==null&&((Hi=(Di=Z.version_graph)==null?void 0:Di.core_books)!=null&&Hi.length)&&(we.core=Z.version_graph.core_books.length),we})()})}if(s==="feedback"&&w)return t.jsx(Ws,{resourceId:e,apiUrl:z});const H=_.find(Z=>Z.key===s);return H?H.render({detail:E,entry:G,transport:n,onNavigate:h}):null};if(P)return t.jsx(Ft,{style:{minHeight:T,...O},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((H,fe)=>t.jsx("div",{style:{height:fe===1?40:16,width:H,opacity:.35,background:o("rule")}},fe))})});if(ce||!E||!G||!Xe)return t.jsx(Ft,{style:{minHeight:T,...O},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:o("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const hn=s==="basic"||s==="emendated",Xt=[{label:b??M.detailTab.backToIndex,onClick:k}];if(E.type==="book"&&E.work_id){const H=E.work_id;Xt.push({label:M.indexType.work,id:H,onClick:()=>h==null?void 0:h(H)})}Xt.push({label:M.indexType[E.type]});const Qt=s==="collated"||s==="fulltext",Bi=t.jsx(Jr,{left:t.jsxs(t.Fragment,{children:[R,R?" · ":"",t.jsx(Ju,{id:E.id,label:M.label.id,copied:M.action.copied,copyLabel:M.action.copy})]}),right:t.jsxs(t.Fragment,{children:[w&&!hn&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:M.detailTab.submitVersion}),Le&&t.jsx("a",{href:Le.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:o("meta-fg")},children:M.detailTab.dataLicense})]})});return hn?t.jsx("div",{className:C,children:t.jsxs(Ft,{grid:!0,style:{minHeight:T,...O},children:[t.jsx(Mn,{breadcrumb:t.jsx(Fn,{items:Xt}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Kn,{style:{border:"none",background:"transparent"}}),Le&&t.jsx(qn,{...Le})]})}),Li(),Bi]})}):t.jsx("div",{className:C,children:t.jsxs(Ft,{wide:Qt,style:{minHeight:T,...O},children:[t.jsx(Mn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(di,{char:"籍"}),t.jsx(Fn,{items:Xt})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Kn,{}),w&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:M.detailTab.feedback}),Le&&t.jsx(qn,{...Le})]})}),t.jsx(Or,{...Xe,aside:Qt?t.jsxs("button",{type:"button",onClick:()=>l("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("accent"),borderBottom:`1px solid ${o("rule")}`},children:[A("作品信息")," →"]}):Xe.aside}),!Qt&&ge.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:ge.map(H=>t.jsx(Dr,{label:H.label,active:H.key===s||hn&&H.key==="basic",onClick:()=>l(H.key)},H.key))}),t.jsx("div",{style:{marginTop:!Qt&&ge.length>1?8:0},children:ol()}),Bi]})})};function Ju({id:e,label:n,copied:i,copyLabel:r}){const[s,l]=g.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 c;(c=navigator.clipboard)==null||c.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 Zu(e,n){return n?e.workSubtype[n]??n:""}exports.BidLink=he.BidLink;exports.BookIndexError=he.BookIndexError;exports.BookIndexManager=he.BookIndexManager;exports.BookIndexStorage=he.BookIndexStorage;exports.BundleStorage=he.BundleStorage;exports.ConfigError=he.ConfigError;exports.GithubStorage=he.GithubStorage;exports.IdGenerationError=he.IdGenerationError;exports.IdGenerator=he.IdGenerator;exports.LocalStorage=he.LocalStorage;exports.MigrationError=he.MigrationError;exports.StorageError=he.StorageError;exports.base36Decode=he.base36Decode;exports.base36Encode=he.base36Encode;exports.base58Decode=he.base58Decode;exports.buildId=he.buildId;exports.buildPromotionMap=he.buildPromotionMap;exports.cleanName=he.cleanName;exports.decodeId=he.decodeId;exports.decodeIdString=he.decodeIdString;exports.encodeId=he.encodeId;exports.extractIdFromUrl=he.extractIdFromUrl;exports.extractStatus=he.extractStatus;exports.extractType=he.extractType;exports.normalizeCatalog=he.normalizeCatalog;exports.parseId=he.parseId;exports.shardOf=he.shardOf;exports.smartDecode=he.smartDecode;exports.validateResource=he.validateResource;exports.Badge=an;exports.BidUrlProvider=fl;exports.BookDetailLayout=qu;exports.BookFullText=Gn;exports.BookPage=Ds;exports.Breadcrumb=Fn;exports.CATALOG_ALL_ID=et;exports.CATALOG_CSS=Us;exports.CATALOG_NARROW_QUERY=Ri;exports.CATALOG_PAGE_SIZE=Ei;exports.CATALOG_UNCLASSIFIED_ID=Ht;exports.CardFoot=Kt;exports.CatalogPage=vu;exports.CatalogPager=Js;exports.CatalogTree=Ys;exports.CheckFilter=Fr;exports.Chip=Hr;exports.ChipWall=oc;exports.CollatedEdition=zi;exports.CollectionCatalog=ni;exports.CollectionPage=Hs;exports.CreateEntityDialog=Is;exports.DEFAULT_READER_PREFS=xi;exports.DETAIL_CSS=Pr;exports.Dash=dc;exports.DataTable=sc;exports.DetailFooter=Jr;exports.DetailGrid=Vt;exports.DetailHeader=Or;exports.EmendatedBySection=vr;exports.EmptyNote=hc;exports.EntityDetail=gr;exports.EntityPage=Gs;exports.EntityPickerDialog=Rs;exports.EntitySelector=Cs;exports.ExpandRow=pc;exports.ExtLink=bc;exports.FEEDBACK_FAB_OFFSET_VAR=Vn;exports.FONT_SIZE_STEPS=jt;exports.FactList=ec;exports.FeedbackButton=Pp;exports.FeedbackDialog=Bs;exports.FeedbackForm=As;exports.FeedbackList=Ci;exports.FeedbackTab=Ws;exports.FilterChip=Dr;exports.FormInput=Me;exports.FormTextArea=xt;exports.GUJI_MARKDOWN_FIELD=Oa;exports.GUJI_TABLE_NOTATION=ls;exports.GlyphBadge=di;exports.GujiTable=hi;exports.HomePage=Hn;exports.ImagePanel=ns;exports.IndexApp=Ud;exports.IndexBrowser=Nn;exports.IndexDetail=ti;exports.IndexEditor=Es;exports.IndexView=zp;exports.IntroGrid=Qa;exports.LocaleContext=$t;exports.LocaleProvider=zl;exports.LocaleToggle=Kn;exports.MetaLine=Re;exports.ModeIndicator=ur;exports.MoreButton=ic;exports.MoreLink=It;exports.PAGE_MAX_WIDTH=Mt;exports.PageFrame=Ft;exports.Quote=xc;exports.READER_CSS=Qr;exports.RECENT_IDS_STORAGE_KEY=kt;exports.ROLE_CLASS_ORDER=Cr;exports.ReadButton=Wn;exports.ReaderMdText=vi;exports.ReaderShell=gi;exports.ReaderToc=ts;exports.RelationPanel=$s;exports.RepoSourceLink=qn;exports.ResourceEditor=En;exports.ResourceGroup=fc;exports.ResourceLine=gc;exports.ResourceList=ei;exports.ResourceRow=Kr;exports.SNIPPET_MARK_END=rr;exports.SNIPPET_MARK_START=or;exports.SearchInput=xr;exports.Sec=Ee;exports.Section=Oe;exports.SectionHead=tc;exports.SideList=ut;exports.SmartBidInput=nn;exports.SourceEditor=Ss;exports.SummaryCard=Yt;exports.TabFilter=ai;exports.TableHead=lc;exports.TableRow=ac;exports.TagRow=qr;exports.TagRows=mc;exports.TextButton=nc;exports.TopStrip=Mn;exports.VersionLineageGraph=el;exports.VersionLineageList=Qs;exports.VersionLineageView=tl;exports.VolumeChips=rc;exports.VolumeLinks=pi;exports.WorkCard=qs;exports.WorkCardGrid=Zs;exports.WorkCatalog=Vd;exports.WorkPage=Os;exports.bucketResources=ri;exports.buildCatalogTree=pu;exports.buildCollectionTable=Tr;exports.buildLineageGraph=on;exports.buildPageUrl=Qn;exports.buildParagraphBlocks=gs;exports.buildVersionRow=$r;exports.buildVersionTable=zr;exports.canParagraphize=mn;exports.catalogNodeIdOf=cu;exports.catalogNodeIdsOf=du;exports.catalogPageCount=gu;exports.catalogTotal=Ni;exports.classificationPath=Jt;exports.compareCatalogCards=fu;exports.computeVersionPartition=Wa;exports.defaultWorkLink=Ks;exports.deriveDating=La;exports.deriveEditionType=Er;exports.deriveEra=Ut;exports.deriveYear=un;exports.deriveYearRange=oi;exports.detailToEditor=Ls;exports.detectGenre=gn;exports.displayAuthorRole=li;exports.editorToDetail=$p;exports.eraRank=Bn;exports.findCatalogPath=vt;exports.flattenTitles=Pn;exports.flattenToc=ss;exports.formatTemplate=Gt;exports.formatVolumeRange=fn;exports.getDisplayNameFromUrl=zt;exports.getStartPage=Xn;exports.getTypeGroupKey=Jn;exports.groupRelatedWorks=Ba;exports.gujiInlineToPlain=Ar;exports.hasGujiMarkdownV02=An;exports.hasGujiTableNotation=as;exports.measureText=it;exports.mergeVolumeResources=Zn;exports.normalizeEra=Te;exports.normalizeRole=si;exports.normalizeVolumeIndex=Ot;exports.normalizeVolumes=pr;exports.numberToChinese=Rr;exports.paginationItems=Vs;exports.parseChineseNumber=rn;exports.parseGujiInline=Br;exports.parseGujiTable=ds;exports.parseSourceString=ws;exports.pickReaderVersion=rs;exports.readerVersionOptionLabel=Dn;exports.readerVersionsFromFullText=os;exports.renderFullTextBody=Oc;exports.renderProperNames=hs;exports.renderReaderInline=ji;exports.resourceHref=Ct;exports.resourceNote=xn;exports.roleFacets=Ir;exports.rowNo=cc;exports.sortYear=sn;exports.splitFullTextTables=mi;exports.splitHighlightSnippet=sr;exports.splitTableRow=cs;exports.stringifySources=_s;exports.toCatalogWorkCard=xu;exports.useBidUrl=Ne;exports.useConvert=Y;exports.useReaderPrefs=fi;exports.useT=ae;exports.validateLineageGraph=$u;exports.volumeStats=cn;