book-index-ui 0.27.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,21 +1,140 @@
1
- "use strict";var zl=Object.create;var po=Object.defineProperty;var Cl=Object.getOwnPropertyDescriptor;var Il=Object.getOwnPropertyNames;var Tl=Object.getPrototypeOf,El=Object.prototype.hasOwnProperty;var Rl=(e,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Il(n))!El.call(e,s)&&s!==o&&po(e,s,{get:()=>n[s],enumerable:!(r=Cl(n,s))||r.enumerable});return e};var cn=(e,n,o)=>(o=e!=null?zl(Tl(e)):{},Rl(n||!e||!e.__esModule?po(o,"default",{value:e,enumerable:!0}):o,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const we=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),g=require("react"),Nl=require("opencc-js/t2cn"),Ll=require("react-markdown"),Bl=require("remark-gfm"),Al=e=>`/book-index?id=${e}`,kr=g.createContext(Al);function Wl({buildUrl:e,children:n}){const o=g.useMemo(()=>e,[e]);return t.jsx(kr.Provider,{value:o,children:n})}function Pe(){return g.useContext(kr)}const wr="",Sr="";function _r(e){const n=[];let o=!1,r=e;for(;r.length;){const s=o?Sr:wr,l=r.indexOf(s);if(l===-1){n.push({text:r,marked:o});break}l>0&&n.push({text:r.slice(0,l),marked:o}),r=r.slice(l+1),o=!o}return n}function He(e,n){return{title:e,tokens:n}}const uo='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Ml=[He("基础(VS Code 环境下跟随 --vscode-*)",{bg:{value:"#ffffff",vscode:"--vscode-editor-background"},fg:{value:"#333333",vscode:"--vscode-foreground"},"input-bg":{value:"#ffffff",vscode:"--vscode-input-background"},"input-fg":{value:"#333333",vscode:"--vscode-input-foreground"},"input-border":{value:"#cccccc",vscode:"--vscode-input-border"},"widget-border":{value:"#e0e0e0",vscode:"--vscode-widget-border"},"link-fg":{value:"#0066cc",vscode:"--vscode-textLink-foreground"},"desc-fg":{value:"#717171",vscode:"--vscode-descriptionForeground"},primary:{value:"#0078d4",vscode:"--vscode-button-background"},"primary-fg":{value:"#ffffff",vscode:"--vscode-button-foreground"},"primary-soft":{value:"rgba(0, 120, 212, 0.15)",css:"color-mix(in srgb, var(--bim-primary) 15%, transparent)"},danger:{value:"#f44336"},warning:{value:"#ff9800"},success:{value:"#4caf50"},"sidebar-bg":{value:"#f3f3f3",vscode:"--vscode-sideBar-background"},"list-hover-bg":{value:"rgba(0, 0, 0, 0.04)",vscode:"--vscode-list-hoverBackground"},"list-active-bg":{value:"rgba(0, 120, 212, 0.1)",vscode:"--vscode-list-activeSelectionBackground"},"focus-border":{value:"#0078d4",vscode:"--vscode-focusBorder"}}),He("底色层次 / 文字与描边 / 链接",{"bg-subtle":{value:"#fafafa"},"widget-bg":{value:"#f8f8f8"},muted:{value:"#888888"},border:{value:"#e5e5e5"},"primary-bg":{value:"#fdf4f4"},link:{value:"#1976d2"},"tag-bg":{value:"#f0f0f0"},"accent-bg":{value:"#1976d2"},"on-color-fg":{value:"#ffffff",note:"彩色底(徽章、选中态按钮)上的文字"}}),He("提示与警告",{"info-fg":{value:"#0c5380"},"info-bg":{value:"#e7f3ff"},"info-border":{value:"#b3dbff"},"warn-fg":{value:"#856404"},"warn-bg":{value:"#fff3cd"},"warn-border":{value:"#ffc107"},"danger-bg":{value:"rgba(244, 67, 54, 0.08)",note:"错误提示条底色"},"danger-soft-bg":{value:"rgba(244, 67, 54, 0.03)",note:"编辑器危险区块"},"danger-soft-border":{value:"rgba(244, 67, 54, 0.13)"}}),He("遮罩与阴影",{backdrop:{value:"rgba(0, 0, 0, 0.5)",note:"对话框遮罩"},"overlay-bg":{value:"#00000010",note:"轻量遮罩底(图片占位等)"},"shadow-dialog":{value:"0 4px 20px rgba(0, 0, 0, 0.3)"},"shadow-dropdown":{value:"0 4px 12px rgba(0, 0, 0, 0.1)"},"shadow-tooltip":{value:"0 2px 8px rgba(0, 0, 0, 0.08)"},"shadow-fab":{value:"0 2px 8px rgba(0, 0, 0, 0.25)",note:"悬浮按钮(反馈)"},"shadow-card":{value:"0 1px 4px rgba(0, 0, 0, 0.06)",note:"展开的卡片"},"shadow-node":{value:"0 1px 3px rgba(0, 0, 0, 0.1)",note:"谱系图节点"},"shadow-node-selected":{value:"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)"}}),He("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),He("资源",{"restype-text":{value:"#2196f3"},"restype-image":{value:"#ff9800"},"restype-text-image":{value:"#9c27b0"},"restype-physical":{value:"#795548"},"missing-fg":{value:"#e67e22",note:"资源缺册提示"},"colormode-bw-bg":{value:"#f5f5f5",note:"影印件色彩模式标记(黑白 / 彩色)"},"colormode-bw-fg":{value:"#757575"},"colormode-color-bg":{value:"#fff8e1"},"colormode-color-fg":{value:"#f57f17"},"progress-active":{value:"#f59e0b",note:"资源导入进度"},"progress-done":{value:"#10b981"},"progress-todo":{value:"#9ca3af"},"check-fine-bg":{value:"#e8f5e9",note:"文字资源校对程度徽章(精校 / 粗校 / AI整理)"},"check-fine-fg":{value:"#2e7d32"},"check-rough-bg":{value:"#fff3e0"},"check-rough-fg":{value:"#e65100"},"check-ai-bg":{value:"#e3f2fd"},"check-ai-fg":{value:"#1565c0"}}),He("整理本(CollatedEdition)",{"highlight-bg":{value:"#fff59d",note:"搜索命中高亮底"},"highlight-fg":{value:"inherit",root:!1},"section-lei":{value:"#8e6f3e",note:"章节类型标记:类 / 书 / 序 / 结语 / 考证 / 注释"},"section-shu":{value:"#c0392b"},"section-xu":{value:"#1a5276"},"section-jieyu":{value:"#7d6608"},"section-kaozhen":{value:"#5d6d7e"},"section-zhushi":{value:"#6c5b7b"},"section-tag-fg":{value:"#e74c3c",note:"章节标记(△ 等)"},"matchstate-fg":{value:"#b78900",note:"与底本匹配状态提示"},"quality-published":{value:"#1b5e20",note:"文本质量等级(出版 / 精校 / 粗校 / OCR)"},"quality-fine":{value:"#2e7d32"},"quality-rough":{value:"#1565c0"},"quality-ocr":{value:"#e65100"}}),He("版本传承(VersionLineageGraph / List) / 关系方向(RelationPanel)",{"lost-fg":{value:"#c62828",note:"佚失标记"},"confidence-certain":{value:"#2e7d32",note:"关系置信度"},"confidence-consensus":{value:"#1976d2"},"confidence-probable":{value:"#ed6c02"},"confidence-disputed":{value:"#c62828"},"lineage-edge-consensus":{value:"#555555",note:"⚠️ 同为 consensus,List 徽章用 --bim-confidence-consensus(蓝),Graph 连线用这个(灰)。若要统一,覆盖成 var(--bim-confidence-consensus)"},"relation-up":{value:"#2196f3"},"relation-down":{value:"#4caf50"},"relation-flat":{value:"#ff9800"}}),He("编辑器视图(主要在 guji-platform 插件中可见)",{"editor-type-work":{value:"#4caf50",note:"⚠️ 与展示视图的 --bim-type-* 是两套配色(历史如此)。若要统一,覆盖成对应的 var(--bim-type-*)"},"editor-type-collection":{value:"#2196f3"},"editor-type-book":{value:"#ff9800"},"editor-type-entity":{value:"#9c27b0"},"source-url":{value:"#2196f3",note:"来源类型(SourceEditor)"},"source-bookid":{value:"#4caf50"},"mode-active-bg":{value:"#2196f3",note:"模式指示器当前态(ModeIndicator)"},"cover-accent":{value:"#8e6f3e",note:'书目卡片「封面」点缀(IndexBrowser resultVariant="card")'}}),He("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --bim-primary 等控件色",{"page-bg":{value:"#fbf9f3",note:"纸"},"row-hover-bg":{value:"#f5f1e5"},"selection-bg":{value:"#ecdcbc",note:"选区"},"band-bg":{value:"#f0e4cb",note:"全文入口横幅(暖沙)"},"band-bg-hover":{value:"#e6d5b4"},ink:{value:"#2a231c",note:"文字层次:墨 → 正文 → 提要 → meta → 标签 → 提示"},"body-fg":{value:"#3b3228"},"quiet-fg":{value:"#5b4f40"},"meta-fg":{value:"#7b6a54"},"label-fg":{value:"#6f6457",note:"标签 / 提示:2026-09 N3a 调深,纸底与斑马底上对比度均 ≥4.5(原 #a3937b 2.8、#b3a385 2.3)"},"hint-fg":{value:"#756a5e"},accent:{value:"#9c3a2c",note:"朱"},"accent-deep":{value:"#6f2a20",note:"链接 hover"},"rule-strong":{value:"#2a231c",note:"分隔线:强 → 常规 → 虚线 → 提要左线"},rule:{value:"#e4dbc9"},"rule-dashed":{value:"#d6c9ae"},"rule-accent-soft":{value:"#e0d3b6"},"aux-fg":{value:"#6f6457",note:"辅助字(元数据、注记、「·」分隔的浅色小字)。须在 page-bg / zebra-bg 上对比度 ≥4.5(Q5 巡检)"},"card-bg":{value:"#fffdf9",note:"提要卡:抬起的面"},"zebra-bg":{value:"#f6f2eb",note:"表格斑马纹 / 左栏分组底(不画格线,靠这一阶底色分行)"},"tint-bg":{value:"#f3eee6",note:"检索框、悬停"},"shadow-summary":{value:"0 10px 32px rgba(60, 50, 40, 0.07)",note:"提要卡投影"},"flag-bg":{value:"rgba(158, 42, 43, 0.08)",note:"唯一的状态色块「有影印」"},"theme-dot-zhusha":{value:"#9c3a2c",note:"主题切换控件的色点:朱砂(不随主题变,两套主题下都要认得出)"},"theme-dot-indigo":{value:"#2e5266",note:"主题切换控件的色点:靛青"},"theme-dot-ink":{value:"#222221",note:"主题切换控件的色点:墨"},"sect-jing":{value:"#2e5266",note:"四部分布条:經部(人物页提要卡;无别处使用)"},"sect-shi":{value:"#9a7a3b",note:"四部分布条:史部"},"sect-zi":{value:"#4f7a5c",note:"四部分布条:子部"},"sect-ji":{value:"#9fb3bc",note:"四部分布条:集部"},"table-border":{value:"color-mix(in srgb, currentColor 28%, transparent)",root:!1,note:"古籍表格(跟随当前文字色)"},"table-head-bg":{value:"color-mix(in srgb, currentColor 8%, transparent)",root:!1}}),He('版式(v4 外观系统,overview#291):疏朗=留白分区(默认,下列值即疏朗);界栏=框线分区(`<html data-layout="boxed">`)',{"fr-bd":{value:"0 solid transparent",note:"区块外框(border 简写)。疏朗无框;界栏 1px 实线"},"fr-bg":{value:"transparent",note:"区块底。界栏=卡面色"},"fr-hd-pad":{value:"0",note:"区块标题栏内边距(界栏:标题栏与正文之间有分隔线)"},"fr-hd-bd":{value:"0 solid transparent",note:"区块标题栏下沿线(border 简写)"},"fr-bd-pad":{value:"0",note:"区块正文内边距"},"fr-gap":{value:"56px",note:"区块之间的间距。界栏收紧到 24px(框线本身已分隔)"},"fr-side-gap":{value:"34px",note:"侧栏各块之间的间距;界栏 20px"},"fr-shadow":{value:"0 1px 0 var(--bim-rule), 0 12px 32px -18px rgba(40, 36, 31, 0.25)",note:"抬起的面(提要卡)的投影;界栏不用投影,靠框线"},"fr-tab-bd":{value:"transparent",note:"页签行下沿线颜色(疏朗不画,界栏画)"}}),He("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),He("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),He("字体(全站无衬线,2026-09-05 定)",{"font-ui":{value:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif'},"font-body":{value:"system-ui, sans-serif",css:"var(--bim-font-ui)"},"font-serif":{value:uo,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:uo,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Fl=Object.assign({},...Ml.map(e=>e.tokens)),$r={};for(const[e,n]of Object.entries(Fl))$r[e]=`var(--bim-${e}, ${n.value})`;function i(e){const n=$r[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function yt(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function Pl(e,n){return yt(e).includes(n)}const Un={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Ol={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};i("quality-published"),i("quality-fine"),i("quality-rough"),i("quality-ocr");const Rt=g.createContext(null),zr={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:i("check-fine-bg"),fg:i("check-fine-fg")},粗校:{label:"粗校",bg:i("check-rough-bg"),fg:i("check-rough-fg")},AI整理:{label:"AI整理",bg:i("check-ai-bg"),fg:i("check-ai-fg")}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入叢編",collectedIn:"收入叢編",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評註",studies:"所考典籍"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"結果分類",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"概覽",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄",fullText:"全文",lineage:"版本傳承",feedback:"勘誤反饋",dataSource:"數據源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"數據源與授權"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},workSubtype:{book:"書",article:"篇",poem:"詩",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},Dl={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:i("check-fine-bg"),fg:i("check-fine-fg")},粗校:{label:"粗校",bg:i("check-rough-bg"),fg:i("check-rough-fg")},AI整理:{label:"AI整理",bg:i("check-ai-bg"),fg:i("check-ai-fg")}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入丛编",collectedIn:"收入丛编",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评注",studies:"所考典籍"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"结果分类",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"概览",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录",fullText:"全文",lineage:"版本传承",feedback:"勘误反馈",dataSource:"数据源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"数据源与授权"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},workSubtype:{book:"书",article:"篇",poem:"诗",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},Hl=["曹霑"];function Gl(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ul(e,n=Hl){const o=[...new Set(n.filter(Boolean))].sort((l,d)=>d.length-l.length);if(!o.length)return e;const r=new RegExp(`(${o.map(Gl).join("|")})`,"g"),s=new Set(o);return l=>{if(!l)return e(l);const d=l.split(r);return d.length===1?e(l):d.map((p,c)=>c%2===1&&s.has(p)?p:p&&e(p)).join("")}}let At=null;function Vl(){if(At)return At;try{At=Ul(Nl.Converter({from:"tw",to:"cn"}))}catch{At=e=>e}return At}const Yl={"zh-Hant":zr,"zh-Hans":Dl},Cr="bim-locale";function Kl(){try{const e=localStorage.getItem(Cr);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function ql(e){try{localStorage.setItem(Cr,e)}catch{}}const Jl="zh-Hans",Zl=({locale:e,onLocaleChange:n,converter:o,children:r})=>{const[s,l]=g.useState(e??Jl),d=e??s;g.useEffect(()=>{if(e)return;const u=Kl();u&&u!==s&&l(u)},[]);const p=g.useMemo(()=>d==="zh-Hans"?o??Vl():null,[d,o]),c=g.useCallback(u=>{l(u),ql(u),n==null||n(u)},[n]),a=g.useMemo(()=>({locale:d,setLocale:c,messages:Yl[d],converter:p}),[d,c,p]);return t.jsx(Rt.Provider,{value:a,children:r})};function ue(){const e=g.useContext(Rt);return(e==null?void 0:e.messages)??zr}const Xl=2e3;function Z(){const e=g.useContext(Rt),n=(e==null?void 0:e.locale)??"zh-Hant",o=(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(d=>{if(!d)return"";if(!o)return d;const p=r.current.get(d);if(p!==void 0)return p;const c=o(d);if(r.current.size>=Xl){const a=r.current.keys().next().value;a!==void 0&&r.current.delete(a)}return r.current.set(d,c),c},[o]);return g.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Jt(e,n){return e.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function Ql(e){if(!e)return"";try{const n=new URL(e).hostname,o={"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(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function ea(){return{id:"",name:"",url:"",type:"text",details:""}}const Vn=({items:e,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const l=ue(),[d,p]=g.useState(null),c=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],a=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=y=>{if(!s)return!0;const k=yt(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=ea();s&&(y.type=s),n([...e,y]),p(e.length)},m=y=>{n(e.filter((k,$)=>$!==y)),p(null)},j=(y,k,$)=>{const v=[...e];if(v[y]={...v[y],[k]:$},k==="url"&&!v[y].id){const _=Ql($);_&&(v[y].id=_)}n(v)},w=(y,k,$)=>{const _={...e[y].metadata||{}};$?_[k]=$:delete _[k],j(y,"metadata",Object.keys(_).length>0?_:void 0)},h=(y,k)=>{const $=k.trim()?k.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;j(y,"structure",$)},b=(y,k,$)=>{const _=e[y].coverage||{level:1,ranges:""};k==="level"?_.level=parseInt($)||1:_.ranges=$,j(y,"coverage",_.ranges?_:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[f.map(({item:y,originalIndex:k})=>{var $,v,_;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(d===k?null:k),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:d===k?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:ta(y.type??"text"),color:i("on-color-fg")},children:(()=>{var z,N;const S=yt(y);return S.length===0?y.type??"text":S.length===1?((z=c.find(T=>T.value===S[0]))==null?void 0:z.label)??S[0]:S.includes("text")&&S.includes("image")?((N=c.find(T=>T.value==="text+image"))==null?void 0:N.label)??"text+image":S.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:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&y.url&&na(k,r==null?void 0:r[k],o,l),t.jsx("button",{onClick:S=>{S.stopPropagation(),m(k)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),d===k&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:[Pl(y,"image")&&y.url&&ia(y,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.type}),t.jsx("select",{value:y.type,onChange:S=>j(k,"type",S.target.value),style:{...tt,flex:1},children:c.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]}),t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.rootType}),t.jsx("select",{value:y.root_type||"catalog",onChange:S=>j(k,"root_type",S.target.value),style:{...tt,flex:1},children:a.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:y.id,onChange:S=>j(k,"id",S.target.value),placeholder:l.editor.idAutoExtract,style:{...tt,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:y.name,onChange:S=>j(k,"name",S.target.value),placeholder:l.editor.resourceName,style:{...tt,flex:1}})]}),t.jsx("input",{type:"text",value:y.url,onChange:S=>j(k,"url",S.target.value),placeholder:l.editor.resourceUrl,style:tt}),t.jsx("input",{type:"text",value:(($=y.structure)==null?void 0:$.join("、"))||"",onChange:S=>h(k,S.target.value),placeholder:l.editor.structurePlaceholder,style:tt}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((v=y.coverage)==null?void 0:v.level)??"",onChange:S=>b(k,"level",S.target.value),placeholder:"1",style:{...tt,width:"60px"}})]}),t.jsxs("label",{style:{...Wt,flex:1},children:[t.jsx("span",{style:Mt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:((_=y.coverage)==null?void 0:_.ranges)||"",onChange:S=>b(k,"ranges",S.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...tt,flex:1}})]})]}),t.jsx("textarea",{value:y.details||"",onChange:S=>j(k,"details",S.target.value),placeholder:l.editor.detailsPlaceholder,style:{...tt,minHeight:"60px",resize:"vertical"}}),t.jsxs("div",{style:{borderTop:`1px solid ${i("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[t.jsx("div",{style:{fontSize:"12px",color:i("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(([S,z])=>{var N;return t.jsxs("label",{style:{...Wt,gap:"4px"},children:[t.jsx("span",{style:{...Mt,minWidth:"56px"},children:z}),t.jsx("input",{type:"text",value:((N=y.metadata)==null?void 0:N[S])||"",onChange:T=>w(k,S,T.target.value),placeholder:z,style:{...tt,flex:1}})]},S)})})]})]})]})]},k)}),t.jsxs("button",{onClick:x,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:l.action.addResource})]})]})};function ta(e){switch(e){case"text":return i("restype-text");case"image":return i("restype-image");case"text+image":return i("restype-text-image");case"physical":return i("restype-physical")}}function na(e,n,o,r){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:d=>{d.stopPropagation(),s||o(e,"")},disabled:s,style:{background:"transparent",border:"none",color:i(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 ia(e,n){const o=/\.(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:o?t.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:i("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:i("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:i("desc-fg")},children:n.editor.imageResourceLink})})}const tt={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Wt={display:"flex",alignItems:"center",gap:"6px"},Mt={fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap"},oa={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive","www.shuge.org":"書格","shuge.org":"書格","pan.baidu.com":"百度網盤"};function Nt(e){try{return oa[new URL(e).hostname]}catch{return}}const xo={text:0,image:1,physical:2};function xi(e){return e.length===0?"physical":[...e].sort((n,o)=>(xo[n]??99)-(xo[o]??99)).join("+")}function fi(e){var d;const n=p=>{const c=p.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const a=p.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},o=new Map;for(let p=0;p<e.length;p++){const c=e[p];if(c.volumes&&c.volumes.length>0)continue;const a=n(c.name);if(!a)continue;const[u,f]=a,x=`${u}|${xi(yt(c))}`;o.has(x)||o.set(x,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const m=o.get(x);m.volumes.push({volume:f,url:c.url||void 0,status:"found"}),m.indices.push(p)}const r=[],s=new Set;for(const p of o.values())if(!(p.volumes.length<2)){p.volumes.sort((c,a)=>c.volume-a.volume),p.base.volumes=p.volumes,p.base.expected_volumes=p.volumes.length,p.base.url||(p.base.url=((d=p.volumes.find(c=>c.url))==null?void 0:d.url)??""),r.push(p.base);for(const c of p.indices)s.add(c)}const l=[...r];for(let p=0;p<e.length;p++)s.has(p)||l.push(e[p]);return l}function Ir(e){if(e.url)return e.url;for(const[n,o]of Object.entries(e))if(n.endsWith("_url")&&typeof o=="string")return o}function Tr(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||Ir(n)}))}function yn(e){const n=Tr(e);if(!n)return null;const o=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:o,missing:r,expected:e.expected_volumes??o+r}}function gi(e){if(!e)return;const n=e.file_page_range||e.page_range;if(!n||typeof n!="string")return;const o=n.match(/^(\d+)/);return o?parseInt(o[1],10):void 0}function mi(e,n){try{if(new URL(e).hostname.includes("wikimedia.org")){const r=e.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const s=new URL(e);return s.searchParams.set("page",String(n)),s.toString()}return e}catch{return e}}function Lt(e){if(!e.url)return;const n=gi(e.metadata);return n?mi(e.url,n):e.url}const fo={text:i("restype-text"),image:i("restype-image"),"text+image":i("restype-text-image"),physical:i("restype-physical")};function ra(e){return e.includes("text")&&e.includes("image")?fo["text+image"]:fo[e[0]||"physical"]}const hi=({items:e,groupByType:n=!0,resourceGroups:o,onNavigate:r,renderLink:s})=>{const l=ue(),{convert:d}=Z(),p=g.useMemo(()=>fi(e||[]),[e]),{mirrorGroups:c,ungroupedItems:a}=g.useMemo(()=>{const h=new Map,b=[];for(const y of p){const k=y.group;k?(h.has(k)||h.set(k,[]),h.get(k).push(y)):b.push(y)}for(const y of h.values())y.sort((k,$)=>{const v=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return v(k)-v($)});return{mirrorGroups:h,ungroupedItems:b}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},f=h=>u[h]?u[h]:h.split("+").map(b=>u[b]||b).join("+");if(!p||p.length===0)return t.jsx("div",{style:{padding:"16px",color:i("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((h,b)=>t.jsx(Nn,{item:h},h.id||b))});const x=(h,b)=>{const y=o==null?void 0:o[h],k=(y==null?void 0:y.label)||h,$=y==null?void 0:y.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:d(k)}),$&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.5},children:d($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:b.map((v,_)=>t.jsx(Nn,{item:v,onNavigate:r,renderLink:s},v.id||_))})]},`group-${h}`)},m=new Map;for(const h of a){const b=xi(yt(h));m.has(b)||m.set(b,[]),m.get(b).push(h)}const j=["text","image","text+image","physical"],w=[...j.filter(h=>m.has(h)),...[...m.keys()].filter(h=>!j.includes(h)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([h,b])=>x(h,b)),w.map(h=>{const b=m.get(h),y=ra(h.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:y,whiteSpace:"nowrap",flexShrink:0},children:f(h)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:b.map((k,$)=>t.jsx(Nn,{item:k,onNavigate:r,renderLink:s},k.id||$))})]},h)})]})},sa={bw:{label:"",bg:i("colormode-bw-bg"),fg:i("colormode-bw-fg")},color:{label:"",bg:i("colormode-color-bg"),fg:i("colormode-color-fg")}},Nn=({item:e})=>{const n=ue(),{convert:o}=Z(),[r,s]=g.useState(!1),l=g.useMemo(()=>(e.url?Nt(e.url):void 0)||o(e.name),[e.url,e.name,o]),d=g.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(j=>({...j,url:j.url||Ir(j)})),[e.volumes]),p=d&&d.length>0,c=p?new Set(d.filter(j=>j.status!=="missing").map(j=>j.volume)).size:0,a=p?new Set(d.filter(j=>j.status==="missing").map(j=>j.volume)).size:0,u=e.expected_volumes??(p?c+a:0),f=e.color_mode?{...sa[e.color_mode],label:n.colorMode[e.color_mode]}:null,x=e.details&&!p?o(e.details):null,m={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",background:i("input-bg"),fontSize:"12px",color:i("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:i("desc-fg")},children:x}),p&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[c,"/",u,n.unit.volume,a>0&&t.jsxs("span",{style:{color:i("missing-fg"),marginLeft:"3px"},children:["缺",a]})]}),e.url&&t.jsx("a",{href:(()=>{const j=gi(e.metadata);return j?mi(e.url,j):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:i("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:i("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),p&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:d.map(j=>{const w=j.status==="missing";return j.url&&!w?t.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${i("widget-border")}`,color:i("link-fg"),textDecoration:"none"},children:j.volume},j.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:i(w?"missing-fg":"desc-fg"),textDecoration:w?"line-through":"none",opacity:w?.6:1},children:j.volume},j.volume)})})]})},Er=({indexSource:e,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:d})=>{const p=ue(),c=e==="local",a=(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:i("primary-soft"),color:i("primary")},m={onMouseOver:w=>w.currentTarget.style.opacity="0.8",onMouseOut:w=>w.currentTarget.style.opacity="1"},j=t.jsxs("div",{onClick:s,title:a?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...x,background:i(a?"warning":"success"),color:i("on-color-fg")},...m,children:[t.jsx("span",{children:a?"📝":"📚"}),t.jsx("span",{children:a?"draft":"official"})]});return o==="index-browser"?c?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[j,t.jsxs("div",{onClick:r,title:p.mode.switchToSync,style:x,...m,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:p.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:d,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px"},...m,children:[t.jsx("span",{children:"📂"}),f&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[j,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:c?p.mode.switchToGithub:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:c?"📁":"🌐"}),t.jsx("span",{children:c?p.mode.localMode:p.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&t.jsxs("div",{onClick:d,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...m,children:[t.jsx("span",{children:"📂"}),f&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]}),!c&&f&&t.jsxs("div",{style:{...x,background:i("mode-active-bg"),color:i("on-color-fg"),cursor:"default"},title:u,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:f})]})]})},jn="bim-search-history",go=10,mo=8;function Gt(){try{const e=localStorage.getItem(jn);return e?JSON.parse(e):[]}catch{return[]}}function la(e){try{const n=Gt().filter(o=>o!==e);n.unshift(e),n.length>go&&(n.length=go),localStorage.setItem(jn,JSON.stringify(n))}catch{}}function aa(e){try{const n=Gt().filter(o=>o!==e);localStorage.setItem(jn,JSON.stringify(n))}catch{}}function ca(){try{localStorage.removeItem(jn)}catch{}}const Rr=({transport:e,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:l})=>{const d=ue(),p=l??d.search.placeholder,c={work:d.indexType.work,book:d.indexType.book,collection:d.indexType.collection,entity:d.indexType.entity},[a,u]=g.useState(!1),[f,x]=g.useState([]),[m,j]=g.useState(-1),[w,h]=g.useState(Gt),b=g.useRef(null),y=g.useRef(null),k=g.useRef(null),$=g.useRef(!1);g.useEffect(()=>{j(-1);const C=n.trim();if(!C){x(w.map(O=>({type:"history",text:O})));return}if(!e.searchAll){x([]);return}let D=!1;const B=setTimeout(()=>{e.searchAll(C,mo).then(O=>{if(D)return;const M=[...O.works,...O.books,...O.collections,...O.entities??[]];x(M.slice(0,mo).map(X=>({type:"entry",text:X.title||X.id,entry:X})))}).catch(()=>{D||x([])})},80);return()=>{D=!0,clearTimeout(B)}},[n,w,e]),g.useEffect(()=>{const C=D=>{k.current&&!k.current.contains(D.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),g.useEffect(()=>{const C=D=>{var B,O;if(D.key==="/"&&document.activeElement!==b.current){const M=(B=document.activeElement)==null?void 0:B.tagName;if(M==="INPUT"||M==="TEXTAREA"||M==="SELECT")return;D.preventDefault(),(O=b.current)==null||O.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const v=g.useCallback(C=>{C.trim()&&(la(C.trim()),h(Gt())),r(C),u(!1)},[r]),_=g.useCallback(C=>{C.type==="history"?(o(C.text),v(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(o(C.text),v(C.text)))},[o,v,s]),S=g.useCallback(C=>{if(!a||f.length===0){C.key==="Enter"&&v(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),j(D=>(D+1)%f.length);break;case"ArrowUp":C.preventDefault(),j(D=>(D-1+f.length)%f.length);break;case"Enter":C.preventDefault(),m>=0&&m<f.length?_(f[m]):v(n);break;case"Escape":C.preventDefault(),u(!1);break}},[a,f,m,n,v,_]),z=g.useCallback((C,D)=>{D.stopPropagation(),aa(C),h(Gt()),x(B=>B.filter(O=>!(O.type==="history"&&O.text===C)))},[]),N=g.useCallback(C=>{C.stopPropagation(),ca(),h([]),x([])},[]);g.useEffect(()=>{if(m>=0&&y.current){const C=y.current.children;C[m]&&C[m].scrollIntoView({block:"nearest"})}},[m]);const T=!n.trim()&&w.length>0;return t.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:b,type:"text",placeholder:p,value:n,onChange:C=>{o(C.target.value),u(!0)},onCompositionStart:()=>{$.current=!0},onCompositionEnd:()=>{$.current=!1},onFocus:()=>{u(!0)},onKeyDown:S,style:{width:"100%",padding:"8px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),a&&f.length>0&&t.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:i("input-bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"6px",boxShadow:i("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[T&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:i("desc-fg"),borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("span",{children:d.search.history}),t.jsx("button",{onClick:N,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:d.search.clearAll})]}),f.map((C,D)=>t.jsxs("div",{onClick:()=>_(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:i("fg"),background:D===m?i("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:i("desc-fg"),flexShrink:0},children:[c[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&t.jsx("button",{onClick:B=>z(C.text,B),style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:d.action.remove,children:"×"})]},`${C.type}-${C.text}-${D}`))]})]})},vn=({type:e,size:n=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:n,borderRadius:1,flex:"none",background:i(`type-${e}`),verticalAlign:"middle"}}),Ct="bim-recent-ids",ho="bim-recent-entries",bo=50,Ln=5,da=50,pa=200;function _t(){try{const e=localStorage.getItem(Ct);if(e)return JSON.parse(e);const n=localStorage.getItem(ho);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Ct,JSON.stringify(o)),localStorage.removeItem(ho),o}return[]}catch{return[]}}function yo(e){try{const n=_t().filter(o=>o!==e);n.unshift(e),n.length>bo&&(n.length=bo),localStorage.setItem(Ct,JSON.stringify(n))}catch{}}function ua(e){try{const n=_t().filter(o=>o!==e);localStorage.setItem(Ct,JSON.stringify(n))}catch{}}function xa(){try{localStorage.removeItem(Ct)}catch{}}const jo={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Yn=({transport:e,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:d,onConfigurePath:p,onSelectFolder:c,hideModeIndicator:a,resultVariant:u="compact",renderEntry:f,initialQuery:x,onQueryChange:m,headerRight:j,reserveViewportHeight:w=!1})=>{const h=ue(),b=[{type:"work",name:h.indexType.work,key:"works"},{type:"book",name:h.indexType.book,key:"books"},{type:"collection",name:h.indexType.collection,key:"collections"},{type:"entity",name:h.indexType.entity,key:"entities"}],y=["work","collection","book","entity"],[k,$]=g.useState(x??""),[v,_]=g.useState(null),[S,z]=g.useState(null),[N,T]=g.useState("all"),[C,D]=g.useState(!1),[B,O]=g.useState(null),[M,X]=g.useState(""),[Y,E]=g.useState(!(x!=null&&x.trim())),[ee,F]=g.useState(_t),[K,ae]=g.useState([]),[ne,Q]=g.useState(!1),[ie,ge]=g.useState(!1),[re,le]=g.useState(null),[pe,Re]=g.useState(null),$e=g.useRef(void 0),ye=g.useRef(!1),Se=g.useCallback(async(W,A)=>{if(!W.trim()){E(!0),_(null),z(null);return}E(!1),D(!0),X("");try{if(e.searchAll){const I=await e.searchAll(W,A??Ln);_(I)}else{const I=["work","book","collection","entity"],G=await Promise.all(I.map(P=>e.search(W,P,{page:1,pageSize:A??Ln})));_({works:G[0].entries,books:G[1].entries,collections:G[2].entries,entities:G[3].entries,totalWorks:G[0].total,totalBooks:G[1].total,totalCollections:G[2].total,totalEntities:G[3].total})}}catch(I){X(I instanceof Error?I.message:String(I)),_(null)}finally{D(!1)}},[e]);g.useEffect(()=>{let W=!1;const A=()=>{var se,ke;const I=["work","book","collection","entity"],G=Promise.all(I.map(be=>e.loadEntries(be,{page:1,pageSize:1}).catch(()=>({total:0})))),P=((se=e.getResourceCounts)==null?void 0:se.call(e).catch(()=>null))??Promise.resolve(null),q=((ke=e.getSubtypeStats)==null?void 0:ke.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([G,P,q]).then(([be,Le,Ke])=>{W||(le({works:be[0].total,books:be[1].total,collections:be[2].total,entities:be[3].total,hasText:Le==null?void 0:Le.hasText,hasImage:Le==null?void 0:Le.hasImage}),Ke&&Re(Ke))})};return e.getCounts?e.getCounts().then(I=>{var G,P;W||(le({works:I.works,books:I.books,collections:I.collections,entities:I.entities,hasText:(G=I.resourceCounts)==null?void 0:G.hasText,hasImage:(P=I.resourceCounts)==null?void 0:P.hasImage}),I.subtypeStats&&Re(I.subtypeStats))}).catch(()=>{W||A()}):A(),()=>{W=!0}},[e]),g.useEffect(()=>{ye.current||!(x!=null&&x.trim())||(ye.current=!0,Se(x))},[x,Se]);const Ne=g.useCallback(W=>{if($(W),!W.trim()){m==null||m(W),E(!0),_(null),z(null),T("all");return}$e.current&&clearTimeout($e.current),$e.current=setTimeout(()=>{z(null),T("all"),m==null||m(W),Se(W)},pa)},[Se,m]),je=g.useCallback(W=>{$e.current&&clearTimeout($e.current),T("all"),m==null||m(W),Se(W)},[Se,m]),H=g.useCallback(W=>{z(W),Se(k,da)},[k,Se]);g.useEffect(()=>{if(!ee.length){ae([]);return}let W=!1;return Q(!0),Promise.all(ee.slice(0,10).map(async A=>{var I,G,P;try{if(e.getEntry){const se=await e.getEntry(A);if(se)return se}const q=await e.getItem(A);if(q){const se=q.authors;return{id:A,title:q.title||A,type:q.type||"work",author:(I=se==null?void 0:se[0])==null?void 0:I.name,dynasty:(G=se==null?void 0:se[0])==null?void 0:G.dynasty,role:(P=se==null?void 0:se[0])==null?void 0:P.role,edition:q.edition||void 0}}}catch{}return{id:A,title:A,type:"work",notFound:!0}})).then(A=>{W||(ae(A),Q(!1))}),()=>{W=!0}},[ee,e]);const ce=W=>{O(W.id),yo(W.id),F(_t()),r==null||r(W)},oe=(W,A)=>{if(r&&ga(A)){A.preventDefault(),ce(W);return}yo(W.id),F(_t())},he=W=>{ua(W),F(_t())},me=()=>{xa(),F([])},U=W=>b.find(A=>A.type===W),R=!Y&&!v&&!M,V=v&&(v.works.length>0||v.books.length>0||v.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",style:w?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:ma}),t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("h1",{style:{margin:0,fontSize:"18px",color:i("fg")},children:h.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[j,!a&&t.jsx(Er,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:l,onToggleDraft:d,onConfigurePath:p,onSelectFolder:c})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(Rr,{transport:e,value:k,onChange:Ne,onSearch:je,onEntrySelect:ce}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${i("primary")}`,borderRadius:"6px",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"13px"},children:h.action.newEntry})]}),Y&&t.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:re&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:pe?t.jsxs(t.Fragment,{children:[(pe.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:i("fg")},children:pe.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:i("fg")},children:re.books.toLocaleString()})," 本"]}),pe.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:i("fg")},children:pe.article.toLocaleString()})," 篇"]}):null,pe.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:i("fg")},children:pe.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:i("fg")},children:re.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[h.indexType.work," ",t.jsx("strong",{style:{color:i("fg")},children:re.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.book," ",t.jsx("strong",{style:{color:i("fg")},children:re.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.collection," ",t.jsx("strong",{style:{color:i("fg")},children:re.collections.toLocaleString()}),re.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.entity," ",t.jsx("strong",{style:{color:i("fg")},children:re.entities.toLocaleString()})]})]})}),re.hasImage!=null&&re.hasText!=null&&t.jsxs("span",{children:[h.resourceType.image," ",t.jsx("strong",{style:{color:i("fg")},children:re.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.resourceType.text," ",t.jsx("strong",{style:{color:i("fg")},children:re.hasText.toLocaleString()})]})]})}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:C||R?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg"),minHeight:fa,boxSizing:"border-box"},children:h.search.searching}):M?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:i("desc-fg")},children:M})}):Y?t.jsx("div",{style:{flex:1},children:ne?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg")},children:h.search.loading}):K.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:h.search.recentBrowse}),t.jsx("button",{onClick:me,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:h.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:K.slice(0,ie?10:3).map(W=>W.notFound?t.jsx(ja,{id:W.id,onRemove:he,t:h},W.id):t.jsx(vo,{entry:W,selected:B===W.id,onClick:oe,getConfig:U,onRemove:he},W.id))}),!ie&&K.length>3&&t.jsx("button",{onClick:()=>ge(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:h.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:h.search.searchTitle}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:h.search.searchSubtitle})]})}):V?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:ha}),(()=>{const W=q=>v[jo[q]]??0,A=y.map(q=>b.find(se=>se.type===q)).filter(q=>W(q.key)>0);if(A.length<2)return null;const I=A.reduce((q,se)=>q+W(se.key),0),G=q=>{if(T(q),q!=="all"&&S!==q){const se=b.find(be=>be.type===q),ke=(v[se.key]??[]).length;W(se.key)>ke&&H(q)}},P=q=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:i(q?"fg":"desc-fg"),fontWeight:q?700:400,boxShadow:q?`inset 0 -2px 0 ${i("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":h.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":N==="all",style:P(N==="all"),onClick:()=>G("all"),children:[h.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:I.toLocaleString()})]}),A.map(q=>t.jsxs("button",{type:"button","aria-pressed":N===q.type,style:P(N===q.type),onClick:()=>G(q.type),children:[q.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:W(q.key).toLocaleString()})]},q.type))]})})(),b.map(({type:W,name:A,key:I})=>{const G=v[I]??[],P=jo[I],q=v[P]??0;if(G.length===0||N!=="all"&&N!==W)return null;const ke=N==="all"&&!(S===W)&&q>Ln;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:[t.jsx(vn,{type:W})," ",A,t.jsxs("span",{style:{fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[q," ",h.unit.items]})]}),ke&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>H(W),style:{border:"none",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"12px"},children:h.action.viewAll})]}),t.jsx("div",{style:u==="list"?{display:"flex",flexDirection:"column",gap:0}:u==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:G.map(be=>{if(f)return t.jsx(g.Fragment,{children:f(be)},be.id);const Le=u==="card"?ya:vo;return t.jsx(Le,{entry:be,selected:B===be.id,onClick:oe,getConfig:U,query:k},be.id)})})]},W)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:Jt(h.search.noResultsFor,{query:k})}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:h.search.tryOther})]})})]})},fa=240;function ga(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const ma=`
1
+ "use strict";var ea=Object.create;var So=Object.defineProperty;var ta=Object.getOwnPropertyDescriptor;var na=Object.getOwnPropertyNames;var ia=Object.getPrototypeOf,oa=Object.prototype.hasOwnProperty;var ra=(e,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of na(n))!oa.call(e,s)&&s!==o&&So(e,s,{get:()=>n[s],enumerable:!(r=ta(n,s))||r.enumerable});return e};var xn=(e,n,o)=>(o=e!=null?ea(ia(e)):{},ra(n||!e||!e.__esModule?So(o,"default",{value:e,enumerable:!0}):o,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $e=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),f=require("react"),sa=require("opencc-js/t2cn"),la=require("react-markdown"),aa=require("remark-gfm"),ca=e=>`/book-index?id=${e}`,Dr=f.createContext(ca);function da({buildUrl:e,children:n}){const o=f.useMemo(()=>e,[e]);return t.jsx(Dr.Provider,{value:o,children:n})}function Fe(){return f.useContext(Dr)}const Hr="",Gr="";function wi(e){const n=[];let o=!1,r=e;for(;r.length;){const s=o?Gr:Hr,l=r.indexOf(s);if(l===-1){n.push({text:r,marked:o});break}l>0&&n.push({text:r.slice(0,l),marked:o}),r=r.slice(l+1),o=!o}return n}function Ve(e,n){return{title:e,tokens:n}}const $o='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',pa=[Ve("基础(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"}}),Ve("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),Ve("提示与警告",{"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)"}}),Ve("遮罩与阴影",{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)"}}),Ve("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),Ve("资源",{"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"}}),Ve("整理本(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"}}),Ve("版本传承(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"}}),Ve("编辑器视图(主要在 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")'}}),Ve("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --bim-primary 等控件色",{"page-bg":{value:"#fbf9f3",note:"纸"},"row-hover-bg":{value:"#f5f1e5"},"selection-bg":{value:"#ecdcbc",note:"选区"},"band-bg":{value:"#f0e4cb",note:"全文入口横幅(暖沙)"},"band-bg-hover":{value:"#e6d5b4"},ink:{value:"#2a231c",note:"文字层次:墨 → 正文 → 提要 → meta → 标签 → 提示"},"body-fg":{value:"#3b3228"},"quiet-fg":{value:"#5b4f40"},"meta-fg":{value:"#7b6a54"},"label-fg":{value:"#6f6457",note:"标签 / 提示:2026-09 N3a 调深,纸底与斑马底上对比度均 ≥4.5(原 #a3937b 2.8、#b3a385 2.3)"},"hint-fg":{value:"#756a5e"},accent:{value:"#9c3a2c",note:"朱"},"accent-deep":{value:"#6f2a20",note:"链接 hover"},"rule-strong":{value:"#2a231c",note:"分隔线:强 → 常规 → 虚线 → 提要左线"},rule:{value:"#e4dbc9"},"rule-dashed":{value:"#d6c9ae"},"rule-accent-soft":{value:"#e0d3b6"},"aux-fg":{value:"#6f6457",note:"辅助字(元数据、注记、「·」分隔的浅色小字)。须在 page-bg / zebra-bg 上对比度 ≥4.5(Q5 巡检)"},"card-bg":{value:"#fffdf9",note:"提要卡:抬起的面"},"zebra-bg":{value:"#f6f2eb",note:"表格斑马纹 / 左栏分组底(不画格线,靠这一阶底色分行)"},"tint-bg":{value:"#f3eee6",note:"检索框、悬停"},"shadow-summary":{value:"0 10px 32px rgba(60, 50, 40, 0.07)",note:"提要卡投影"},"flag-bg":{value:"rgba(158, 42, 43, 0.08)",note:"唯一的状态色块「有影印」"},"theme-dot-zhusha":{value:"#9c3a2c",note:"主题切换控件的色点:朱砂(不随主题变,两套主题下都要认得出)"},"theme-dot-indigo":{value:"#2e5266",note:"主题切换控件的色点:靛青"},"theme-dot-ink":{value:"#222221",note:"主题切换控件的色点:墨"},"sect-jing":{value:"#2e5266",note:"四部分布条:經部(人物页提要卡;无别处使用)"},"sect-shi":{value:"#9a7a3b",note:"四部分布条:史部"},"sect-zi":{value:"#4f7a5c",note:"四部分布条:子部"},"sect-ji":{value:"#9fb3bc",note:"四部分布条:集部"},"table-border":{value:"color-mix(in srgb, currentColor 28%, transparent)",root:!1,note:"古籍表格(跟随当前文字色)"},"table-head-bg":{value:"color-mix(in srgb, currentColor 8%, transparent)",root:!1}}),Ve('版式(v4 外观系统,overview#291):疏朗=留白分区(默认,下列值即疏朗);界栏=框线分区(`<html data-layout="boxed">`)',{"fr-bd":{value:"0 solid transparent",note:"区块外框(border 简写)。疏朗无框;界栏 1px 实线"},"fr-bg":{value:"transparent",note:"区块底。界栏=卡面色"},"fr-hd-pad":{value:"0",note:"区块标题栏内边距(界栏:标题栏与正文之间有分隔线)"},"fr-hd-bd":{value:"0 solid transparent",note:"区块标题栏下沿线(border 简写)"},"fr-bd-pad":{value:"0",note:"区块正文内边距"},"fr-gap":{value:"56px",note:"区块之间的间距。界栏收紧到 24px(框线本身已分隔)"},"fr-side-gap":{value:"34px",note:"侧栏各块之间的间距;界栏 20px"},"fr-shadow":{value:"0 1px 0 var(--bim-rule), 0 12px 32px -18px rgba(40, 36, 31, 0.25)",note:"抬起的面(提要卡)的投影;界栏不用投影,靠框线"},"fr-tab-bd":{value:"transparent",note:"页签行下沿线颜色(疏朗不画,界栏画)"}}),Ve("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),Ve("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),Ve("字体(全站无衬线,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:$o,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:$o,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],ua=Object.assign({},...pa.map(e=>e.tokens)),Ur={};for(const[e,n]of Object.entries(ua))Ur[e]=`var(--bim-${e}, ${n.value})`;function i(e){const n=Ur[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function vt(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function xa(e,n){return vt(e).includes(n)}const ti={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},fa={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};i("quality-published"),i("quality-fine"),i("quality-rough"),i("quality-ocr");const Lt=f.createContext(null),Vr={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:i("check-fine-bg"),fg:i("check-fine-fg")},粗校:{label:"粗校",bg:i("check-rough-bg"),fg:i("check-rough-fg")},AI整理:{label:"AI整理",bg:i("check-ai-bg"),fg:i("check-ai-fg")}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入叢編",collectedIn:"收入叢編",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評註",studies:"所考典籍"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"結果分類",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},searchV4:{filterTitle:"篩選",dynasty:"朝代",classification:"部類",resources:"資源",extant:"存佚",clearAllFilters:"清除全部篩選",hasImage:"有影印",hasText:"有全文",hasCollated:"有整理本",filterButton:"篩選",filterSelected:"{n} 項已選",expand:"展開",collapse:"收起",filteredCount:"篩出 {n} 條",removeFilter:"取消篩選:{name}",viewLabel:"結果視圖",viewTable:"表格",viewCard:"卡片",colTitle:"題名",colType:"類型",colAuthor:"責任者",colEra:"年代",colClass:"部類",colResource:"資源",tagImage:"影印",tagText:"全文",tagCollated:"整理本",tagLost:"佚",pageInfo:"共 {total} 條 · 每頁 {size} 條 · 第 {page} / {pages} 頁",pagerLabel:"翻頁",prevPage:"上一頁",nextPage:"下一頁",emptyFiltered:"沒有找到匹配的條目。試試更短的書名、減少篩選,或切換繁 / 簡。",limitedNote:"各類只列前幾條,點上方分類頁籤看全部。",sortLabel:"排序",sortRelevance:"相關度",sortEra:"年代",sortTitle:"書名",sortEraAsc:"由早到晚",sortEraDesc:"由晚到早",sortTitleAsc:"拼音 A→Z",sortTitleDesc:"拼音 Z→A",onlyWorksNote:"部類、存佚只適用於作品;選了它們,版本、叢編、人物不參與。"},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:"圖片資源"}},ma={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:i("check-fine-bg"),fg:i("check-fine-fg")},粗校:{label:"粗校",bg:i("check-rough-bg"),fg:i("check-rough-fg")},AI整理:{label:"AI整理",bg:i("check-ai-bg"),fg:i("check-ai-fg")}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入丛编",collectedIn:"收入丛编",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评注",studies:"所考典籍"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"结果分类",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},searchV4:{filterTitle:"筛选",dynasty:"朝代",classification:"部类",resources:"资源",extant:"存佚",clearAllFilters:"清除全部筛选",hasImage:"有影印",hasText:"有全文",hasCollated:"有整理本",filterButton:"筛选",filterSelected:"{n} 项已选",expand:"展开",collapse:"收起",filteredCount:"筛出 {n} 条",removeFilter:"取消筛选:{name}",viewLabel:"结果视图",viewTable:"表格",viewCard:"卡片",colTitle:"题名",colType:"类型",colAuthor:"责任者",colEra:"年代",colClass:"部类",colResource:"资源",tagImage:"影印",tagText:"全文",tagCollated:"整理本",tagLost:"佚",pageInfo:"共 {total} 条 · 每页 {size} 条 · 第 {page} / {pages} 页",pagerLabel:"翻页",prevPage:"上一页",nextPage:"下一页",emptyFiltered:"没有找到匹配的条目。试试更短的书名、减少筛选,或切换繁 / 简。",limitedNote:"各类只列前几条,点上方分类页签看全部。",sortLabel:"排序",sortRelevance:"相关度",sortEra:"年代",sortTitle:"书名",sortEraAsc:"由早到晚",sortEraDesc:"由晚到早",sortTitleAsc:"拼音 A→Z",sortTitleDesc:"拼音 Z→A",onlyWorksNote:"部类、存佚只适用于作品;选了它们,版本、丛编、人物不参与。"},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:"图片资源"}},ga=["曹霑"];function ha(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ba(e,n=ga){const o=[...new Set(n.filter(Boolean))].sort((l,c)=>c.length-l.length);if(!o.length)return e;const r=new RegExp(`(${o.map(ha).join("|")})`,"g"),s=new Set(o);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("")}}let Ft=null;function ya(){if(Ft)return Ft;try{Ft=ba(sa.Converter({from:"tw",to:"cn"}))}catch{Ft=e=>e}return Ft}const ja={"zh-Hant":Vr,"zh-Hans":ma},Yr="bim-locale";function va(){try{const e=localStorage.getItem(Yr);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function ka(e){try{localStorage.setItem(Yr,e)}catch{}}const wa="zh-Hans",Sa=({locale:e,onLocaleChange:n,converter:o,children:r})=>{const[s,l]=f.useState(e??wa),c=e??s;f.useEffect(()=>{if(e)return;const u=va();u&&u!==s&&l(u)},[]);const p=f.useMemo(()=>c==="zh-Hans"?o??ya():null,[c,o]),a=f.useCallback(u=>{l(u),ka(u),n==null||n(u)},[n]),d=f.useMemo(()=>({locale:c,setLocale:a,messages:ja[c],converter:p}),[c,a,p]);return t.jsx(Lt.Provider,{value:d,children:r})};function me(){const e=f.useContext(Lt);return(e==null?void 0:e.messages)??Vr}const $a=2e3;function V(){const e=f.useContext(Lt),n=(e==null?void 0:e.locale)??"zh-Hant",o=(e==null?void 0:e.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const l=f.useCallback(c=>{if(!c)return"";if(!o)return c;const p=r.current.get(c);if(p!==void 0)return p;const a=o(c);if(r.current.size>=$a){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(c,a),a},[o]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Qe(e,n){return e.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function _a(e){if(!e)return"";try{const n=new URL(e).hostname,o={"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(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function za(){return{id:"",name:"",url:"",type:"text",details:""}}const ni=({items:e,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const l=me(),[c,p]=f.useState(null),a=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],d=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=h=>{if(!s)return!0;const v=vt(h);return s==="text"?v.includes("text"):s==="image"?v.includes("image")||v.includes("physical"):s==="physical"?v.includes("physical"):v.includes(s)},m=e.map((h,v)=>({item:h,originalIndex:v})).filter(({item:h})=>u(h)),x=()=>{const h=za();s&&(h.type=s),n([...e,h]),p(e.length)},g=h=>{n(e.filter((v,$)=>$!==h)),p(null)},b=(h,v,$)=>{const k=[...e];if(k[h]={...k[h],[v]:$},v==="url"&&!k[h].id){const _=_a($);_&&(k[h].id=_)}n(k)},w=(h,v,$)=>{const _={...e[h].metadata||{}};$?_[v]=$:delete _[v],b(h,"metadata",Object.keys(_).length>0?_:void 0)},y=(h,v)=>{const $=v.trim()?v.split(/[,,、]/).map(k=>k.trim()).filter(Boolean):void 0;b(h,"structure",$)},j=(h,v,$)=>{const _=e[h].coverage||{level:1,ranges:""};v==="level"?_.level=parseInt($)||1:_.ranges=$,b(h,"coverage",_.ranges?_:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[m.map(({item:h,originalIndex:v})=>{var $,k,_;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("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:Ca(h.type??"text"),color:i("on-color-fg")},children:(()=>{var z,N;const S=vt(h);return S.length===0?h.type??"text":S.length===1?((z=a.find(R=>R.value===S[0]))==null?void 0:z.label)??S[0]:S.includes("text")&&S.includes("image")?((N=a.find(R=>R.value==="text+image"))==null?void 0:N.label)??"text+image":S.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:h.name||`${l.editor.resourcePlaceholder} ${v+1}`}),h.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:h.id}),h.url&&t.jsx("a",{href:h.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&h.url&&Ta(v,r==null?void 0:r[v],o,l),t.jsx("button",{onClick:S=>{S.stopPropagation(),g(v)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),c===v&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:[xa(h,"image")&&h.url&&Ia(h,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Pt,children:[t.jsx("span",{style:Ot,children:l.label.type}),t.jsx("select",{value:h.type,onChange:S=>b(v,"type",S.target.value),style:{...ot,flex:1},children:a.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]}),t.jsxs("label",{style:Pt,children:[t.jsx("span",{style:Ot,children:l.label.rootType}),t.jsx("select",{value:h.root_type||"catalog",onChange:S=>b(v,"root_type",S.target.value),style:{...ot,flex:1},children:d.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:h.id,onChange:S=>b(v,"id",S.target.value),placeholder:l.editor.idAutoExtract,style:{...ot,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:h.name,onChange:S=>b(v,"name",S.target.value),placeholder:l.editor.resourceName,style:{...ot,flex:1}})]}),t.jsx("input",{type:"text",value:h.url,onChange:S=>b(v,"url",S.target.value),placeholder:l.editor.resourceUrl,style:ot}),t.jsx("input",{type:"text",value:(($=h.structure)==null?void 0:$.join("、"))||"",onChange:S=>y(v,S.target.value),placeholder:l.editor.structurePlaceholder,style:ot}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Pt,children:[t.jsx("span",{style:Ot,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((k=h.coverage)==null?void 0:k.level)??"",onChange:S=>j(v,"level",S.target.value),placeholder:"1",style:{...ot,width:"60px"}})]}),t.jsxs("label",{style:{...Pt,flex:1},children:[t.jsx("span",{style:Ot,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:((_=h.coverage)==null?void 0:_.ranges)||"",onChange:S=>j(v,"ranges",S.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...ot,flex:1}})]})]}),t.jsx("textarea",{value:h.details||"",onChange:S=>b(v,"details",S.target.value),placeholder:l.editor.detailsPlaceholder,style:{...ot,minHeight:"60px",resize:"vertical"}}),t.jsxs("div",{style:{borderTop:`1px solid ${i("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[t.jsx("div",{style:{fontSize:"12px",color:i("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(([S,z])=>{var N;return t.jsxs("label",{style:{...Pt,gap:"4px"},children:[t.jsx("span",{style:{...Ot,minWidth:"56px"},children:z}),t.jsx("input",{type:"text",value:((N=h.metadata)==null?void 0:N[S])||"",onChange:R=>w(v,S,R.target.value),placeholder:z,style:{...ot,flex:1}})]},S)})})]})]})]})]},v)}),t.jsxs("button",{onClick:x,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:l.action.addResource})]})]})};function Ca(e){switch(e){case"text":return i("restype-text");case"image":return i("restype-image");case"text+image":return i("restype-text-image");case"physical":return i("restype-physical")}}function Ta(e,n,o,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||o(e,"")},disabled:s,style:{background:"transparent",border:"none",color:i(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 Ia(e,n){const o=/\.(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:o?t.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:i("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:i("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:i("desc-fg")},children:n.editor.imageResourceLink})})}const ot={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Pt={display:"flex",alignItems:"center",gap:"6px"},Ot={fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap"},Ea={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive","www.shuge.org":"書格","shuge.org":"書格","pan.baidu.com":"百度網盤"};function Bt(e){try{return Ea[new URL(e).hostname]}catch{return}}const _o={text:0,image:1,physical:2};function Si(e){return e.length===0?"physical":[...e].sort((n,o)=>(_o[n]??99)-(_o[o]??99)).join("+")}function $i(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},o=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,m]=d,x=`${u}|${Si(vt(a))}`;o.has(x)||o.set(x,{base:{...a,name:u,url:"",volumes:[]},volumes:[],indices:[]});const g=o.get(x);g.volumes.push({volume:m,url:a.url||void 0,status:"found"}),g.indices.push(p)}const r=[],s=new Set;for(const p of o.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 Kr(e){if(e.url)return e.url;for(const[n,o]of Object.entries(e))if(n.endsWith("_url")&&typeof o=="string")return o}function qr(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||Kr(n)}))}function Sn(e){const n=qr(e);if(!n)return null;const o=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:o,missing:r,expected:e.expected_volumes??o+r}}function _i(e){if(!e)return;const n=e.file_page_range||e.page_range;if(!n||typeof n!="string")return;const o=n.match(/^(\d+)/);return o?parseInt(o[1],10):void 0}function zi(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 At(e){if(!e.url)return;const n=_i(e.metadata);return n?zi(e.url,n):e.url}const zo={text:i("restype-text"),image:i("restype-image"),"text+image":i("restype-text-image"),physical:i("restype-physical")};function Ra(e){return e.includes("text")&&e.includes("image")?zo["text+image"]:zo[e[0]||"physical"]}const Ci=({items:e,groupByType:n=!0,resourceGroups:o,onNavigate:r,renderLink:s})=>{const l=me(),{convert:c}=V(),p=f.useMemo(()=>$i(e||[]),[e]),{mirrorGroups:a,ungroupedItems:d}=f.useMemo(()=>{const y=new Map,j=[];for(const h of p){const v=h.group;v?(y.has(v)||y.set(v,[]),y.get(v).push(h)):j.push(h)}for(const h of y.values())h.sort((v,$)=>{const k=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return k(v)-k($)});return{mirrorGroups:y,ungroupedItems:j}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},m=y=>u[y]?u[y]:y.split("+").map(j=>u[j]||j).join("+");if(!p||p.length===0)return t.jsx("div",{style:{padding:"16px",color:i("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((y,j)=>t.jsx(On,{item:y},y.id||j))});const x=(y,j)=>{const h=o==null?void 0:o[y],v=(h==null?void 0:h.label)||y,$=h==null?void 0:h.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:c(v)}),$&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.5},children:c($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((k,_)=>t.jsx(On,{item:k,onNavigate:r,renderLink:s},k.id||_))})]},`group-${y}`)},g=new Map;for(const y of d){const j=Si(vt(y));g.has(j)||g.set(j,[]),g.get(j).push(y)}const b=["text","image","text+image","physical"],w=[...b.filter(y=>g.has(y)),...[...g.keys()].filter(y=>!b.includes(y)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([y,j])=>x(y,j)),w.map(y=>{const j=g.get(y),h=Ra(y.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:h,whiteSpace:"nowrap",flexShrink:0},children:m(y)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((v,$)=>t.jsx(On,{item:v,onNavigate:r,renderLink:s},v.id||$))})]},y)})]})},Na={bw:{label:"",bg:i("colormode-bw-bg"),fg:i("colormode-bw-fg")},color:{label:"",bg:i("colormode-color-bg"),fg:i("colormode-color-fg")}},On=({item:e})=>{const n=me(),{convert:o}=V(),[r,s]=f.useState(!1),l=f.useMemo(()=>(e.url?Bt(e.url):void 0)||o(e.name),[e.url,e.name,o]),c=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(b=>({...b,url:b.url||Kr(b)})),[e.volumes]),p=c&&c.length>0,a=p?new Set(c.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=p?new Set(c.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=e.expected_volumes??(p?a+d:0),m=e.color_mode?{...Na[e.color_mode],label:n.colorMode[e.color_mode]}:null,x=e.details&&!p?o(e.details):null,g={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",background:i("input-bg"),fontSize:"12px",color:i("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:g,children:[t.jsx("span",{style:{fontWeight:500},children:l}),m&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:m.bg,color:m.fg},children:m.label}),x&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:x}),p&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[a,"/",u,n.unit.volume,d>0&&t.jsxs("span",{style:{color:i("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),e.url&&t.jsx("a",{href:(()=>{const b=_i(e.metadata);return b?zi(e.url,b):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:i("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:i("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),p&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:c.map(b=>{const w=b.status==="missing";return b.url&&!w?t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${i("widget-border")}`,color:i("link-fg"),textDecoration:"none"},children:b.volume},b.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:i(w?"missing-fg":"desc-fg"),textDecoration:w?"line-through":"none",opacity:w?.6:1},children:b.volume},b.volume)})})]})},Jr=({indexSource:e,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:c})=>{const p=me(),a=e==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",m=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:i("primary-soft"),color:i("primary")},g={onMouseOver:w=>w.currentTarget.style.opacity="0.8",onMouseOut:w=>w.currentTarget.style.opacity="1"},b=t.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...x,background:i(d?"warning":"success"),color:i("on-color-fg")},...g,children:[t.jsx("span",{children:d?"📝":"📚"}),t.jsx("span",{children:d?"draft":"official"})]});return o==="index-browser"?a?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,t.jsxs("div",{onClick:r,title:p.mode.switchToSync,style:x,...g,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"},...g,children:[t.jsx("span",{children:"📂"}),m&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:m})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:p.mode.switchToLocal,style:x,...g,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:m||p.mode.configurePath,style:{...x,background:"transparent",padding:"6px",fontSize:"12px"},...g,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,...g,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"},...g,children:[t.jsx("span",{children:"📂"}),m&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:m})]}),!a&&m&&t.jsxs("div",{style:{...x,background:i("mode-active-bg"),color:i("on-color-fg"),cursor:"default"},title:u,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:m})]})]})},$n="bim-search-history",Co=10,To=8;function qt(){try{const e=localStorage.getItem($n);return e?JSON.parse(e):[]}catch{return[]}}function La(e){try{const n=qt().filter(o=>o!==e);n.unshift(e),n.length>Co&&(n.length=Co),localStorage.setItem($n,JSON.stringify(n))}catch{}}function Ba(e){try{const n=qt().filter(o=>o!==e);localStorage.setItem($n,JSON.stringify(n))}catch{}}function Aa(){try{localStorage.removeItem($n)}catch{}}const Zr=({transport:e,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:l})=>{const c=me(),p=l??c.search.placeholder,a={work:c.indexType.work,book:c.indexType.book,collection:c.indexType.collection,entity:c.indexType.entity},[d,u]=f.useState(!1),[m,x]=f.useState([]),[g,b]=f.useState(-1),[w,y]=f.useState(qt),j=f.useRef(null),h=f.useRef(null),v=f.useRef(null),$=f.useRef(!1);f.useEffect(()=>{b(-1);const C=n.trim();if(!C){x(w.map(M=>({type:"history",text:M})));return}if(!e.searchAll){x([]);return}let H=!1;const L=setTimeout(()=>{e.searchAll(C,To).then(M=>{if(H)return;const F=[...M.works,...M.books,...M.collections,...M.entities??[]];x(F.slice(0,To).map(X=>({type:"entry",text:X.title||X.id,entry:X})))}).catch(()=>{H||x([])})},80);return()=>{H=!0,clearTimeout(L)}},[n,w,e]),f.useEffect(()=>{const C=H=>{v.current&&!v.current.contains(H.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=H=>{var L,M;if(H.key==="/"&&document.activeElement!==j.current){const F=(L=document.activeElement)==null?void 0:L.tagName;if(F==="INPUT"||F==="TEXTAREA"||F==="SELECT")return;H.preventDefault(),(M=j.current)==null||M.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const k=f.useCallback(C=>{C.trim()&&(La(C.trim()),y(qt())),r(C),u(!1)},[r]),_=f.useCallback(C=>{C.type==="history"?(o(C.text),k(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(o(C.text),k(C.text)))},[o,k,s]),S=f.useCallback(C=>{if(!d||m.length===0){C.key==="Enter"&&k(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(H=>(H+1)%m.length);break;case"ArrowUp":C.preventDefault(),b(H=>(H-1+m.length)%m.length);break;case"Enter":C.preventDefault(),g>=0&&g<m.length?_(m[g]):k(n);break;case"Escape":C.preventDefault(),u(!1);break}},[d,m,g,n,k,_]),z=f.useCallback((C,H)=>{H.stopPropagation(),Ba(C),y(qt()),x(L=>L.filter(M=>!(M.type==="history"&&M.text===C)))},[]),N=f.useCallback(C=>{C.stopPropagation(),Aa(),y([]),x([])},[]);f.useEffect(()=>{if(g>=0&&h.current){const C=h.current.children;C[g]&&C[g].scrollIntoView({block:"nearest"})}},[g]);const R=!n.trim()&&w.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=>{o(C.target.value),u(!0)},onCompositionStart:()=>{$.current=!0},onCompositionEnd:()=>{$.current=!1},onFocus:()=>{u(!0)},onKeyDown:S,style:{width:"100%",padding:"8px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),d&&m.length>0&&t.jsxs("div",{ref:h,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:i("input-bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"6px",boxShadow:i("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:i("desc-fg"),borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("span",{children:c.search.history}),t.jsx("button",{onClick:N,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:c.search.clearAll})]}),m.map((C,H)=>t.jsxs("div",{onClick:()=>_(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:i("fg"),background:H===g?i("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:i("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:L=>z(C.text,L),style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:c.action.remove,children:"×"})]},`${C.type}-${C.text}-${H}`))]})]})},Wt=({type:e,size:n=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:n,borderRadius:1,flex:"none",background:i(`type-${e}`),verticalAlign:"middle"}}),_n={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},Xr=new Set(["work","book","entity"]);function Wa(e){return es(e)||!!e.sort}function Ma(e,n){return n.sort&&Xr.has(e)?n.sort:void 0}const zn=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Cn=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Ti=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],Qr={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function Tn(e){return e.dynasty.length+e.classification.length+(e.hasImage?1:0)+(e.hasText?1:0)+(e.hasCollated?1:0)+(e.loss?1:0)}function es(e){return Tn(e)>0}function Fa(e){const n=[];return e.dynasty.length&&n.push("dynasty"),e.classification.length&&n.push("classification"),e.hasImage&&n.push("hasImage"),e.hasText&&n.push("hasText"),e.hasCollated&&n.push("hasCollated"),e.loss&&n.push("loss"),n}function ts(e,n){const o=Qr[e];return Fa(n).every(r=>o.has(r))}const Dt=e=>JSON.stringify(e);function Pa(e,n){if(!ts(n,e))return null;const o=[];if(e.dynasty.length){const r=Array.from(new Set(e.dynasty.flatMap(s=>{var l;return((l=zn.find(c=>c.key===s))==null?void 0:l.values)??[]})));r.length===1?o.push(`dynasty = ${Dt(r[0])}`):r.length>1&&o.push(`dynasty IN [${r.map(Dt).join(", ")}]`)}return e.classification.length&&o.push(e.classification.length===1?`classification = ${Dt(e.classification[0])}`:`classification IN [${e.classification.map(Dt).join(", ")}]`),e.hasImage&&o.push("has_image = true"),e.hasText&&o.push("has_text = true"),e.hasCollated&&o.push("has_collated = true"),e.loss&&o.push(`loss_status = ${Dt(e.loss)}`),o.join(" AND ")}const Ge={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},ns="_";function yn(e,n=new URLSearchParams){for(const o of Object.values(Ge))n.delete(o);return e.dynasty.length&&n.set(Ge.dynasty,e.dynasty.join(",")),e.classification.length&&n.set(Ge.classification,e.classification.map(o=>o||ns).join(",")),e.hasImage&&n.set(Ge.hasImage,"1"),e.hasText&&n.set(Ge.hasText,"1"),e.hasCollated&&n.set(Ge.hasCollated,"1"),e.loss&&n.set(Ge.loss,e.loss),e.sort&&n.set(Ge.sort,e.sort),n}function Oa(e){const n=l=>(e.get(l)??"").split(",").map(c=>c.trim()).filter(Boolean),o=new Set(zn.map(l=>l.key)),r=new Set(Cn.map(l=>l.value)),s=e.get(Ge.loss);return{dynasty:Array.from(new Set(n(Ge.dynasty).filter(l=>o.has(l)))),classification:Array.from(new Set(n(Ge.classification).map(l=>l===ns?"":l).filter(l=>r.has(l)))),hasImage:e.get(Ge.hasImage)==="1",hasText:e.get(Ge.hasText)==="1",hasCollated:e.get(Ge.hasCollated)==="1",loss:s==="extant"||s==="partially_extant"||s==="lost"?s:"",sort:["era:asc","era:desc","title:asc","title:desc"].find(l=>l===e.get(Ge.sort))??""}}function Da(e,n){return JSON.stringify([e.dynasty.slice().sort(),e.classification.slice().sort(),e.hasImage,e.hasText,e.hasCollated,e.loss,e.sort])===JSON.stringify([n.dynasty.slice().sort(),n.classification.slice().sort(),n.hasImage,n.hasText,n.hasCollated,n.loss,n.sort])}function Io(e,n){return e.includes(n)?e.filter(o=>o!==n):[...e,n]}const Ha=({filters:e,onChange:n})=>{const o=me().searchV4,{convert:r}=V(),[s,l]=f.useState(!1),c=f.useId(),p=Tn(e),a=d=>n({...e,...d});return t.jsxs("aside",{className:"bim-sr-aside","aria-label":r(o.filterTitle),children:[t.jsxs("button",{type:"button",className:"bim-sr-fbtn","aria-expanded":s,"aria-controls":c,onClick:()=>l(d=>!d),children:[t.jsxs("span",{children:[r(o.filterButton),p>0&&t.jsx("span",{className:"bim-sr-fn",children:r(Qe(o.filterSelected,{n:p}))})]}),t.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[r(s?o.collapse:o.expand)," ",s?"▴":"▾"]})]}),t.jsxs("div",{className:"bim-sr-filters",id:c,"data-open":s?"true":"false",...s?{}:{"data-collapsed":"true"},children:[t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:r(o.dynasty)}),t.jsx("div",{className:"bim-sr-chips",children:zn.map(d=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(d.key),onClick:()=>a({dynasty:Io(e.dynasty,d.key)}),children:r(d.key)},d.key))})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:r(o.classification)}),Cn.map(d=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(d.value),onChange:()=>a({classification:Io(e.classification,d.value)})}),r(d.label)]},d.value||"_"))]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:r(o.resources)}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasImage,onChange:d=>a({hasImage:d.target.checked})}),r(o.hasImage)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasText,onChange:d=>a({hasText:d.target.checked})}),r(o.hasText)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasCollated,onChange:d=>a({hasCollated:d.target.checked})}),r(o.hasCollated)]})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{id:`${c}-loss`,children:r(o.extant)}),t.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${c}-loss`,children:Ti.map(d=>t.jsx("button",{type:"button","aria-pressed":e.loss===d.value,onClick:()=>a({loss:d.value}),children:r(d.label)},d.value||"all"))})]}),t.jsx("p",{className:"bim-sr-note",children:r(o.onlyWorksNote)}),p>0&&t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>n({..._n,sort:e.sort}),children:r(o.clearAllFilters)})]})]})};function is({text:e,query:n}){const o=(n??"").trim();if(!o||!e)return t.jsx(t.Fragment,{children:e});const r=e.toLowerCase(),s=o.toLowerCase(),l=[];let c=0,p=0;for(;c<e.length;){const a=r.indexOf(s,c);if(a<0){l.push(e.slice(c));break}a>c&&l.push(e.slice(c,a)),l.push(t.jsx("mark",{className:"bim-sr-hl",children:e.slice(a,a+s.length)},p++)),c=a+s.length}return t.jsx(t.Fragment,{children:l})}const Eo=({entries:e,query:n,onEntryLinkClick:o,typeName:r})=>{const s=me(),l=s.searchV4,{convert:c}=V(),p=Fe();return t.jsx("div",{className:"bim-sr-tablewrap",children:t.jsxs("table",{className:"bim-sr-table",children:[t.jsxs("colgroup",{children:[t.jsx("col",{style:{width:"34%"}}),t.jsx("col",{style:{width:"8%"}}),t.jsx("col",{style:{width:"19%"}}),t.jsx("col",{style:{width:"13%"}}),t.jsx("col",{style:{width:"12%"}}),t.jsx("col",{style:{width:"14%"}})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:c(l.colTitle)}),t.jsx("th",{scope:"col",children:c(l.colType)}),t.jsx("th",{scope:"col",children:c(l.colAuthor)}),t.jsx("th",{scope:"col",children:c(l.colEra)}),t.jsx("th",{scope:"col",children:c(l.colClass)}),t.jsx("th",{scope:"col",style:{textAlign:"right"},children:c(l.colResource)})]})}),t.jsx("tbody",{children:e.map(a=>{const d=c(a.title||a.primary_name||a.id),u=a.measure_info?c(a.measure_info):a.juan_count?`${a.juan_count}${s.unit.juan}`:"",m=a.type==="entity"?[a.birth_year!=null||a.death_year!=null?`${a.birth_year??"?"}—${a.death_year??"?"}`:""].filter(Boolean).join(""):a.author?`${c(a.author)}${a.role&&a.role!=="author"?` ${c(a.role)}`:""}`:"",x=a.type==="book"?a.era??a.dynasty:a.dynasty,g=x?c(x):"",b=a.classification?c(a.classification):"",w=[];a.has_image&&w.push({label:l.tagImage,cls:"bim-sr-tag--img"}),a.has_text&&w.push({label:l.tagText,cls:""}),a.has_collated&&w.push({label:l.tagCollated,cls:""}),a.loss_status==="lost"&&w.push({label:l.tagLost,cls:"bim-sr-tag--lost"});const y=[m,g,b].filter(Boolean).join(" · ");return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-sr-c-title",children:[t.jsxs("div",{className:"bim-sr-tl",children:[t.jsx("a",{href:p(a.id),onClick:j=>o(a,j),children:t.jsx(is,{text:d,query:n?c(n):void 0})}),u&&t.jsx("span",{className:"bim-sr-measure",children:u})]}),y&&t.jsx("span",{className:"bim-sr-sub",children:y})]}),t.jsxs("td",{className:"bim-sr-c-type",children:[t.jsx(Wt,{type:a.type,size:6})," ",r(a.type)]}),t.jsx("td",{className:"bim-sr-c-who",children:m||"—"}),t.jsx("td",{className:"bim-sr-c-era",children:g||"—"}),t.jsx("td",{className:"bim-sr-c-cls",children:b||"—"}),t.jsx("td",{className:"bim-sr-c-res",children:w.map(j=>t.jsx("span",{className:`bim-sr-tag ${j.cls}`,children:c(j.label)},j.label))})]},a.id)})})]})})},Ga=`
2
+ .bim-sc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 10px; }
3
+ .bim-sc { display: flex; flex-direction: column; min-width: 0; padding: 14px 16px 12px; border: 1px solid ${i("rule")}; background: ${i("card-bg")}; color: inherit; text-decoration: none; }
4
+ .bim-sc:hover { border-color: ${i("rule-dashed")}; box-shadow: ${i("fr-shadow")}; }
5
+ .bim-sc-t { font-size: 15.5px; font-weight: 500; letter-spacing: .04em; line-height: 1.5; color: ${i("ink")}; }
6
+ .bim-sc:hover .bim-sc-t { color: ${i("accent")}; }
7
+ .bim-sc-m { margin-top: 3px; font-size: 12.5px; color: ${i("meta-fg")}; }
8
+ .bim-sc-s { margin: 8px 0 0; font-size: 13px; line-height: 1.8; color: ${i("quiet-fg")}; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
9
+ .bim-sc-s mark { background: ${i("selection-bg")}; color: ${i("ink")}; padding: 0 1px; }
10
+ .bim-sc-sp { flex: 1; }
11
+ .bim-sc-f { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; padding-top: 8px; border-top: 1px solid ${i("rule")}; }
12
+ .bim-sc-fl { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: ${i("aux-fg")}; }
13
+ .bim-sc-tags { display: flex; gap: 4px; flex: none; }
14
+ :root[data-layout="boxed"] .bim-sc { box-shadow: none; }
15
+ `,Ro=({entries:e,query:n,onEntryLinkClick:o,typeName:r})=>{const s=me(),l=s.searchV4,{convert:c}=V(),p=Fe();return t.jsxs("div",{className:"bim-sc-grid",children:[t.jsx("style",{children:Ga}),e.map(a=>{const d=c(a.title||a.primary_name||a.id),u=a.measure_info?c(a.measure_info):a.juan_count?`${a.juan_count}${s.unit.juan}`:"",x=[a.type==="entity"?a.birth_year!=null||a.death_year!=null?`${a.birth_year??"?"}—${a.death_year??"?"}`:"":`${a.dynasty?`〔${c(a.dynasty)}〕`:""}${a.author?c(a.author):""}`,a.type==="book"&&a.edition?c(a.edition):"",u].filter(Boolean).join(" · "),g=[r(a.type),a.classification?c(a.classification):""].filter(Boolean).join(" · "),b=[];return a.has_image&&b.push({label:l.tagImage,cls:"bim-sr-tag--img"}),a.has_text&&b.push({label:l.tagText,cls:""}),a.has_collated&&b.push({label:l.tagCollated,cls:""}),a.loss_status==="lost"&&b.push({label:l.tagLost,cls:"bim-sr-tag--lost"}),t.jsxs("a",{className:"bim-sc",href:p(a.id),onClick:w=>o(a,w),children:[t.jsx("span",{className:"bim-sc-t",children:t.jsx(is,{text:d,query:n?c(n):void 0})}),x&&t.jsx("span",{className:"bim-sc-m",children:x}),a.descriptionSnippet&&t.jsx("p",{className:"bim-sc-s",children:wi(a.descriptionSnippet).map((w,y)=>w.marked?t.jsx("mark",{children:c(w.text)},y):t.jsx(f.Fragment,{children:c(w.text)},y))}),t.jsx("span",{className:"bim-sc-sp"}),t.jsxs("div",{className:"bim-sc-f",children:[t.jsx("span",{className:"bim-sc-fl",children:g}),t.jsx("span",{className:"bim-sc-tags",children:b.map(w=>t.jsx("span",{className:`bim-sr-tag ${w.cls}`,children:c(w.label)},w.label))})]})]},a.id)})]})};function Ua(e,n){const o=new Set([1,n,e-1,e,e+1].filter(l=>l>=1&&l<=n)),r=Array.from(o).sort((l,c)=>l-c),s=[];return r.forEach((l,c)=>{c>0&&l-r[c-1]>1&&s.push("gap"),s.push(l)}),s}function Va(e,n,o){const r=Math.max(1,Math.ceil(n/o));return Math.min(Math.max(1,e),r)}const Ya=({page:e,pageSize:n,total:o,onPage:r})=>{const s=me().searchV4,{convert:l}=V(),c=Math.max(1,Math.ceil(o/n));return o<=0?null:t.jsxs("nav",{className:"bim-sr-pager","aria-label":l(s.pagerLabel),children:[t.jsx("span",{className:"bim-sr-info",children:l(Qe(s.pageInfo,{total:o.toLocaleString(),size:n,page:e,pages:c}))}),c>1&&t.jsxs("ul",{children:[t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e<=1,onClick:()=>r(e-1),children:l(s.prevPage)})}),Ua(e,c).map((p,a)=>p==="gap"?t.jsx("li",{className:"bim-sr-gap","aria-hidden":"true",children:"…"},`g${a}`):t.jsx("li",{children:t.jsx("button",{type:"button","aria-current":p===e?"page":void 0,"aria-label":`${p}`,onClick:()=>r(p),children:p})},p)),t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e>=c,onClick:()=>r(e+1),children:l(s.nextPage)})})]})]})},os="(max-width: 719px)",Ka=`${os}, (pointer: coarse)`,qa=`
16
+ .bim-sr-layout { display: grid; grid-template-columns: 208px minmax(0, 1fr); column-gap: 40px; align-items: start; padding: 0 20px; }
17
+ .bim-sr-layout[data-nofilters] { grid-template-columns: minmax(0, 1fr); }
18
+ .bim-sr-aside { position: sticky; top: calc(${i("reader-top")} + 16px); padding-top: 2px; }
19
+ .bim-sr-main { min-width: 0; }
20
+ .bim-sr-fbtn { display: none; }
21
+ .bim-sr-filters { display: flex; flex-direction: column; gap: 22px; border: ${i("fr-bd")}; background: ${i("fr-bg")}; padding: ${i("fr-bd-pad")}; }
22
+ .bim-sr-fg > h3 { margin: 0 0 8px; font-size: 11.5px; font-weight: 400; letter-spacing: .2em; color: ${i("aux-fg")}; }
23
+ .bim-sr-chips { display: flex; flex-wrap: wrap; gap: 4px; }
24
+ .bim-sr-chip {
25
+ padding: 3px 9px; border: 1px solid ${i("rule")}; background: ${i("card-bg")}; color: ${i("quiet-fg")};
26
+ cursor: pointer; font: inherit; font-size: 12.5px; white-space: nowrap;
27
+ }
28
+ .bim-sr-chip:hover { border-color: ${i("rule-dashed")}; color: ${i("ink")}; }
29
+ .bim-sr-chip[aria-pressed="true"] { background: ${i("accent")}; border-color: ${i("accent")}; color: ${i("page-bg")}; font-weight: 600; }
30
+ .bim-sr-chip[aria-pressed="true"]::before { content: "✓ " / ""; font-size: 10px; }
31
+ .bim-sr-opt { display: flex; align-items: center; gap: 8px; padding: 5px 2px; font-size: 13.5px; color: ${i("quiet-fg")}; cursor: pointer; }
32
+ .bim-sr-opt input { margin: 0; width: 14px; height: 14px; accent-color: ${i("accent")}; cursor: pointer; }
33
+ .bim-sr-opt:has(input:checked) { color: ${i("ink")}; font-weight: 600; }
34
+ .bim-sr-seg { display: flex; border: 1px solid ${i("rule")}; }
35
+ .bim-sr-seg button { flex: 1; padding: 5px 0; border: 0; background: ${i("card-bg")}; color: ${i("meta-fg")}; cursor: pointer; font: inherit; font-size: 12.5px; }
36
+ .bim-sr-seg button + button { border-left: 1px solid ${i("rule")}; }
37
+ .bim-sr-seg button[aria-pressed="true"] { background: ${i("flag-bg")}; color: ${i("accent")}; font-weight: 700; box-shadow: inset 0 -2px 0 ${i("accent")}; }
38
+ .bim-sr-clear { align-self: flex-start; padding: 0; border: 0; background: none; cursor: pointer; font: inherit; font-size: 12.5px; color: ${i("accent")}; text-decoration: underline; text-underline-offset: 3px; }
39
+ .bim-sr-note { margin: 0; font-size: 11.5px; line-height: 1.6; color: ${i("aux-fg")}; }
40
+ .bim-sr-chips-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 12px 0 0; }
41
+ .bim-sr-chips-row .bim-sr-count { font-size: 12px; color: ${i("meta-fg")}; margin-right: 4px; }
42
+ .bim-sr-tag-x { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border: 0; background: ${i("flag-bg")}; color: ${i("accent")}; cursor: pointer; font: inherit; font-size: 12px; }
43
+ .bim-sr-tag-x span { font-size: 13px; opacity: .7; }
44
+ .bim-sr-tools { display: flex; justify-content: flex-end; align-items: center; gap: 14px; margin: 10px 0 0; font-size: 12.5px; }
45
+ .bim-sr-sorts { display: flex; align-items: center; gap: 14px; }
46
+ .bim-sr-sorts button { padding: 0; border: 0; background: none; cursor: pointer; font: inherit; font-size: 12.5px; color: ${i("meta-fg")}; }
47
+ .bim-sr-sorts button[aria-pressed="true"] { color: ${i("ink")}; font-weight: 700; text-decoration: underline; text-underline-offset: 4px; }
48
+ .bim-sr-vsep { width: 1px; height: 14px; background: ${i("rule")}; }
49
+ .bim-sr-view { display: inline-flex; border: 1px solid ${i("rule")}; }
50
+ .bim-sr-view button { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border: 0; background: transparent; color: ${i("meta-fg")}; cursor: pointer; font: inherit; font-size: 12px; }
51
+ .bim-sr-view button + button { border-left: 1px solid ${i("rule")}; }
52
+ .bim-sr-view button[aria-pressed="true"] { background: ${i("flag-bg")}; color: ${i("accent")}; font-weight: 700; }
53
+
54
+ /* 表格 */
55
+ .bim-sr-tablewrap { margin-top: 14px; border: ${i("fr-bd")}; background: ${i("fr-bg")}; overflow-x: auto; }
56
+ .bim-sr-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 13.5px; line-height: 1.5; }
57
+ .bim-sr-table th { padding: 7px 12px; border-bottom: 1px solid ${i("rule-strong")}; font-size: 11.5px; font-weight: 400; letter-spacing: .12em; text-align: left; white-space: nowrap; color: ${i("meta-fg")}; }
58
+ .bim-sr-table td { padding: 8px 12px; border-bottom: 1px solid ${i("rule")}; vertical-align: baseline; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: ${i("meta-fg")}; }
59
+ .bim-sr-table tbody tr:hover td { background: ${i("row-hover-bg")}; }
60
+ .bim-sr-table td.bim-sr-c-title { font-size: 13.5px; font-weight: 500; }
61
+ .bim-sr-table td.bim-sr-c-title a { color: ${i("ink")}; text-decoration: none; }
62
+ .bim-sr-table td.bim-sr-c-title a:hover { color: ${i("accent")}; text-decoration: underline; text-underline-offset: 3px; }
63
+ .bim-sr-table .bim-sr-sub { display: none; }
64
+ .bim-sr-tl { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
65
+ .bim-sr-tl a { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
66
+ .bim-sr-table .bim-sr-measure { flex: none; font-size: 11.5px; font-weight: 400; color: ${i("aux-fg")}; }
67
+ .bim-sr-c-type { display: table-cell; }
68
+ .bim-sr-c-res { text-align: right; }
69
+ .bim-sr-tag { display: inline-block; margin-left: 4px; padding: 0 6px; font-size: 10.5px; line-height: 18px; white-space: nowrap; background: ${i("zebra-bg")}; color: ${i("quiet-fg")}; }
70
+ .bim-sr-tag--img { background: ${i("flag-bg")}; color: ${i("accent")}; }
71
+ .bim-sr-tag--lost { background: none; box-shadow: inset 0 0 0 1px ${i("rule")}; color: ${i("aux-fg")}; }
72
+ .bim-sr-hl { background: ${i("selection-bg")}; color: ${i("ink")}; padding: 0 1px; }
73
+
74
+ /* 翻页 */
75
+ .bim-sr-pager { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin: 22px 0 0; font-size: 13px; }
76
+ .bim-sr-pager .bim-sr-info { font-size: 12px; color: ${i("aux-fg")}; }
77
+ .bim-sr-pager ul { display: flex; align-items: center; gap: 4px; list-style: none; margin: 0; padding: 0; }
78
+ .bim-sr-pager button { min-width: 32px; padding: 5px 10px; border: 0; background: none; cursor: pointer; font: inherit; color: ${i("quiet-fg")}; }
79
+ .bim-sr-pager button[aria-current="page"] { background: ${i("flag-bg")}; color: ${i("accent")}; font-weight: 700; box-shadow: inset 0 -2px 0 ${i("accent")}; }
80
+ .bim-sr-pager button:disabled { color: ${i("label-fg")}; cursor: default; opacity: .6; }
81
+ .bim-sr-pager .bim-sr-gap { color: ${i("aux-fg")}; padding: 0 2px; }
82
+ .bim-sr-empty { padding: 60px 0; text-align: center; font-size: 14px; color: ${i("meta-fg")}; }
83
+
84
+ @media ${os} {
85
+ .bim-sr-layout { grid-template-columns: minmax(0, 1fr); row-gap: 16px; padding: 0 16px; }
86
+ .bim-sr-aside { position: static; }
87
+ .bim-sr-fbtn {
88
+ display: flex; width: 100%; justify-content: space-between; align-items: center; padding: 11px 14px;
89
+ border: 1px solid ${i("rule")}; background: ${i("card-bg")}; cursor: pointer; font: inherit; font-size: 14px; color: ${i("ink")};
90
+ }
91
+ .bim-sr-fbtn .bim-sr-fn { margin-left: 8px; font-size: 12px; color: ${i("accent")}; }
92
+ .bim-sr-fbtn .bim-sr-fa { font-size: 11px; color: ${i("aux-fg")}; }
93
+ .bim-sr-filters[data-collapsed] { display: none; }
94
+ .bim-sr-filters { margin-top: 8px; padding: 14px; border: 1px solid ${i("rule")}; background: ${i("card-bg")}; }
95
+ .bim-sr-table thead { display: none; }
96
+ .bim-sr-table, .bim-sr-table tbody, .bim-sr-table tr, .bim-sr-table td { display: block; width: 100%; box-sizing: border-box; }
97
+ .bim-sr-table td { padding: 0 12px; border-bottom: 0; white-space: normal; }
98
+ .bim-sr-table tr { padding: 8px 0; border-bottom: 1px solid ${i("rule")}; }
99
+ .bim-sr-table td.bim-sr-c-title { padding-top: 2px; }
100
+ .bim-sr-table td.bim-sr-c-type, .bim-sr-table td.bim-sr-c-who, .bim-sr-table td.bim-sr-c-era, .bim-sr-table td.bim-sr-c-cls { display: none; }
101
+ .bim-sr-table .bim-sr-sub { display: block; margin-top: 2px; font-size: 12px; font-weight: 400; color: ${i("meta-fg")}; }
102
+ .bim-sr-table td.bim-sr-c-res { text-align: left; padding-bottom: 2px; }
103
+ .bim-sr-table td.bim-sr-c-res:empty { display: none; }
104
+ }
105
+ @media ${Ka} {
106
+ .bim-sr-chip { min-height: 36px; }
107
+ .bim-sr-opt { min-height: 44px; }
108
+ .bim-sr-seg button { min-height: 44px; }
109
+ .bim-sr-view button { min-height: 44px; }
110
+ .bim-sr-sorts button { min-height: 44px; padding: 0 4px; }
111
+ .bim-sr-pager button { min-height: 44px; min-width: 44px; }
112
+ .bim-sr-clear, .bim-sr-tag-x { min-height: 44px; }
113
+ }
114
+
115
+ /* 界栏:结果表格、筛选、翻页条读 --bim-fr-* 令牌(疏朗=无框,下面不生效) */
116
+ :root[data-layout="boxed"] .bim-sr-filters { border: ${i("fr-bd")}; }
117
+ :root[data-layout="boxed"] .bim-sr-table th { background: ${i("fr-bg")}; }
118
+ /* 墨:强调色≈正文色,标题链接另加下划线 */
119
+ :root[data-theme="ink"] .bim-sr-table td.bim-sr-c-title a { text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); text-underline-offset: 3px; }
120
+ `,Ii="bim-search-view",Dn=50,No=5,Lo=1e3,Bo=["work","collection","book","entity"],Ja={work:"works",collection:"collections",book:"books",entity:"entities"},Za={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function Xa(){try{return window.localStorage.getItem(Ii)==="card"?"card":"table"}catch{return"table"}}function Qa(e){try{window.localStorage.setItem(Ii,e)}catch{}}const Ht=(e,n)=>(e==null?void 0:e[Za[n]])??0,Hn=(e,n)=>(e==null?void 0:e[Ja[n]])??[],rs=({transport:e,query:n,filters:o,onFiltersChange:r,onEntryLinkClick:s,typeName:l})=>{const c=me(),p=c.searchV4,{convert:a}=V(),d=!!e.supportsSearchFilters,u=f.useMemo(()=>d?o:_n,[d,o]),[m,x]=f.useState("table");f.useEffect(()=>{x(Xa())},[]);const g=A=>{x(A),Qa(A)},[b,w]=f.useState("all"),[y,j]=f.useState(1),[h,v]=f.useState(null),[$,k]=f.useState(null),[_,S]=f.useState(!1),[z,N]=f.useState(""),R=yn(u).toString(),C=Tn(u)>0,H=yn({...u,sort:""}).toString(),L=f.useRef({query:n,filterOnlyKey:H,sort:u.sort});f.useEffect(()=>{const A=L.current;A.query!==n||A.filterOnlyKey!==H?(w("all"),j(1)):A.sort!==u.sort&&j(1),L.current={query:n,filterOnlyKey:H,sort:u.sort}},[n,H,u.sort]),f.useEffect(()=>{let A=!1;return S(!0),N(""),(async()=>{try{let ee;if(e.searchAll)ee=await e.searchAll(n,No,u);else{const de=["work","book","collection","entity"],G=await Promise.all(de.map(q=>e.search(n,q,{page:1,pageSize:No,filters:u})));ee={works:G[0].entries,books:G[1].entries,collections:G[2].entries,entities:G[3].entries,totalWorks:G[0].total,totalBooks:G[1].total,totalCollections:G[2].total,totalEntities:G[3].total}}A||v(ee)}catch(ee){A||(N(ee instanceof Error?ee.message:String(ee)),v(null))}finally{A||S(!1)}})(),()=>{A=!0}},[e,n,R]),f.useEffect(()=>{if(b==="all"){k(null);return}let A=!1;return S(!0),(async()=>{try{const ee=await e.search(n,b,{page:y,pageSize:Dn,filters:u});A||k({entries:ee.entries,total:ee.total})}catch(ee){A||(N(ee instanceof Error?ee.message:String(ee)),k(null))}finally{A||S(!1)}})(),()=>{A=!0}},[e,n,R,b,y]),f.useEffect(()=>{if(b==="all"||!$||_)return;const A=Math.min($.total,Lo),ee=Va(y,A,Dn);$.entries.length===0&&A>0&&ee!==y&&j(ee)},[b,$,_,y]);const M=f.useMemo(()=>Bo.filter(A=>Ht(h,A)>0),[h]),F=M.reduce((A,ee)=>A+Ht(h,ee),0),X=!_&&!z&&h!==null&&F===0,U=f.useCallback(A=>{w(A),j(1)},[]),T=f.useMemo(()=>{var ee;const A=[];return u.dynasty.forEach(de=>A.push({name:de,remove:()=>r({...u,dynasty:u.dynasty.filter(G=>G!==de)})})),u.classification.forEach(de=>{var G;return A.push({name:((G=Cn.find(q=>q.value===de))==null?void 0:G.label)??de,remove:()=>r({...u,classification:u.classification.filter(q=>q!==de)})})}),u.hasImage&&A.push({name:p.hasImage,remove:()=>r({...u,hasImage:!1})}),u.hasText&&A.push({name:p.hasText,remove:()=>r({...u,hasText:!1})}),u.hasCollated&&A.push({name:p.hasCollated,remove:()=>r({...u,hasCollated:!1})}),u.loss&&A.push({name:`${p.extant}:${((ee=Ti.find(de=>de.value===u.loss))==null?void 0:ee.label)??""}`,remove:()=>r({...u,loss:""})}),A},[u,r,p]),ce={query:n,onEntryLinkClick:s,typeName:l},B=A=>m==="table"?t.jsx(Eo,{entries:A,...ce}):t.jsx(Ro,{entries:A,...ce}),D=Bo.flatMap(A=>Hn(h,A));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":d?void 0:"true",children:[t.jsx("style",{children:qa}),d&&t.jsx(Ha,{filters:u,onChange:r}),t.jsxs("div",{className:"bim-sr-main","aria-busy":_,children:[M.length>0&&t.jsxs("div",{className:"bim-sr-tabs",role:"group","aria-label":c.search.resultTabs,style:{display:"flex",flexWrap:"wrap",gap:"0 4px",borderBottom:`1px solid ${i("rule")}`},children:[t.jsxs(Ao,{on:b==="all",onClick:()=>U("all"),children:[c.search.allTab," ",t.jsx("small",{children:F.toLocaleString()})]}),M.map(A=>t.jsxs(Ao,{on:b===A,onClick:()=>U(A),children:[l(A)," ",t.jsx("small",{children:Ht(h,A).toLocaleString()})]},A))]}),t.jsxs("div",{className:"bim-sr-tools",children:[d&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":a(p.sortLabel),children:[t.jsx("button",{type:"button","aria-pressed":!u.sort,onClick:()=>r({...u,sort:""}),children:a(p.sortRelevance)}),["era","title"].map(A=>{const ee=u.sort.startsWith(`${A}:`)?u.sort.endsWith("desc")?"desc":"asc":null,de=A==="era"?p.sortEra:p.sortTitle,G=A==="era"?ee==="desc"?p.sortEraDesc:p.sortEraAsc:ee==="desc"?p.sortTitleDesc:p.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":ee!==null,title:a(G),onClick:()=>r({...u,sort:`${A}:${ee==="asc"?"desc":"asc"}`}),children:[a(de),ee?t.jsxs("span",{"aria-hidden":"true",children:[" ",ee==="asc"?"↑":"↓"]}):null]},A)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":a(p.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":m==="table",onClick:()=>g("table"),children:a(p.viewTable)}),t.jsx("button",{type:"button","aria-pressed":m==="card",onClick:()=>g("card"),children:a(p.viewCard)})]})]}),C&&t.jsxs("div",{className:"bim-sr-chips-row",children:[t.jsx("span",{className:"bim-sr-count",role:"status",children:a(Qe(p.filteredCount,{n:F.toLocaleString()}))}),T.map(A=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":a(Qe(p.removeFilter,{name:A.name})),onClick:A.remove,children:[a(A.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},A.name))]}),z&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:z}),X&&t.jsx("div",{className:"bim-sr-empty",children:a(C?p.emptyFiltered:Qe(c.search.noResultsFor,{query:n}))}),!z&&!X&&b==="all"&&h&&(m==="table"?t.jsxs(t.Fragment,{children:[t.jsx(Eo,{entries:D,...ce}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:a(p.limitedNote)})]}):t.jsx(t.Fragment,{children:M.map(A=>t.jsxs("section",{style:{marginTop:22},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[t.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[t.jsx(Wt,{type:A,size:8}),l(A),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:i("meta-fg")},children:[Ht(h,A).toLocaleString()," ",c.unit.items]})]}),Ht(h,A)>Hn(h,A).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>U(A),children:c.action.viewAll})]}),t.jsx(Ro,{entries:Hn(h,A),...ce})]},A))})),!z&&b!=="all"&&$&&$.entries.length>0&&t.jsxs(t.Fragment,{children:[B($.entries),t.jsx(Ya,{page:y,pageSize:Dn,total:Math.min($.total,Lo),onPage:j})]}),!z&&b!=="all"&&$&&$.entries.length===0&&!_&&t.jsxs("div",{className:"bim-sr-empty",children:[a(C?p.emptyFiltered:Qe(c.search.noResultsFor,{query:n})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>U("all"),children:c.search.allTab})})]})]})]})};function Ao({on:e,onClick:n,children:o}){return t.jsx("button",{type:"button","aria-pressed":e,onClick:n,style:{border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:14.5,minHeight:44,padding:"8px 12px",letterSpacing:".06em",color:i(e?"ink":"meta-fg"),fontWeight:e?700:400,boxShadow:e?`inset 0 -2px 0 ${i("accent")}`:"none"},children:o})}const It="bim-recent-ids",Wo="bim-recent-entries",Mo=50,Gn=5,ec=50,tc=200;function zt(){try{const e=localStorage.getItem(It);if(e)return JSON.parse(e);const n=localStorage.getItem(Wo);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(It,JSON.stringify(o)),localStorage.removeItem(Wo),o}return[]}catch{return[]}}function Fo(e){try{const n=zt().filter(o=>o!==e);n.unshift(e),n.length>Mo&&(n.length=Mo),localStorage.setItem(It,JSON.stringify(n))}catch{}}function nc(e){try{const n=zt().filter(o=>o!==e);localStorage.setItem(It,JSON.stringify(n))}catch{}}function ic(){try{localStorage.removeItem(It)}catch{}}const Po={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},ii=({transport:e,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a,hideModeIndicator:d,resultVariant:u="compact",renderEntry:m,initialQuery:x,onQueryChange:g,headerRight:b,reserveViewportHeight:w=!1,filtersEnabled:y=!1,filters:j=_n,onFiltersChange:h})=>{const v=me(),$=[{type:"work",name:v.indexType.work,key:"works"},{type:"book",name:v.indexType.book,key:"books"},{type:"collection",name:v.indexType.collection,key:"collections"},{type:"entity",name:v.indexType.entity,key:"entities"}],k=["work","collection","book","entity"],[_,S]=f.useState(x??""),[z,N]=f.useState(null),[R,C]=f.useState(x??""),H=yn(j).toString(),[L,M]=f.useState(j);f.useEffect(()=>{M(j)},[H]);const F=ne=>{M(ne),h==null||h(ne)},[X,U]=f.useState(null),[T,ce]=f.useState("all"),[B,D]=f.useState(!1),[A,ee]=f.useState(null),[de,G]=f.useState(""),[q,ie]=f.useState(!(x!=null&&x.trim())),[pe,ge]=f.useState(zt),[Ee,Ne]=f.useState([]),[ze,Te]=f.useState(!1),[Ce,Ae]=f.useState(!1),[P,se]=f.useState(null),[re,ye]=f.useState(null),be=f.useRef(void 0),K=f.useRef(!1),I=f.useCallback(async(ne,we)=>{if(!ne.trim()){ie(!0),N(null),U(null);return}if(ie(!1),y){C(ne);return}D(!0),G("");try{if(e.searchAll){const E=await e.searchAll(ne,we??Gn);N(E)}else{const E=["work","book","collection","entity"],Q=await Promise.all(E.map(ue=>e.search(ne,ue,{page:1,pageSize:we??Gn})));N({works:Q[0].entries,books:Q[1].entries,collections:Q[2].entries,entities:Q[3].entries,totalWorks:Q[0].total,totalBooks:Q[1].total,totalCollections:Q[2].total,totalEntities:Q[3].total})}}catch(E){G(E instanceof Error?E.message:String(E)),N(null)}finally{D(!1)}},[e,y]);f.useEffect(()=>{let ne=!1;const we=()=>{var te,ke;const E=["work","book","collection","entity"],Q=Promise.all(E.map(Ie=>e.loadEntries(Ie,{page:1,pageSize:1}).catch(()=>({total:0})))),ue=((te=e.getResourceCounts)==null?void 0:te.call(e).catch(()=>null))??Promise.resolve(null),le=((ke=e.getSubtypeStats)==null?void 0:ke.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([Q,ue,le]).then(([Ie,We,Ze])=>{ne||(se({works:Ie[0].total,books:Ie[1].total,collections:Ie[2].total,entities:Ie[3].total,hasText:We==null?void 0:We.hasText,hasImage:We==null?void 0:We.hasImage}),Ze&&ye(Ze))})};return e.getCounts?e.getCounts().then(E=>{var Q,ue;ne||(se({works:E.works,books:E.books,collections:E.collections,entities:E.entities,hasText:(Q=E.resourceCounts)==null?void 0:Q.hasText,hasImage:(ue=E.resourceCounts)==null?void 0:ue.hasImage}),E.subtypeStats&&ye(E.subtypeStats))}).catch(()=>{ne||we()}):we(),()=>{ne=!0}},[e]),f.useEffect(()=>{K.current||!(x!=null&&x.trim())||(K.current=!0,I(x))},[x,I]);const Y=f.useCallback(ne=>{if(S(ne),!ne.trim()){g==null||g(ne),ie(!0),N(null),U(null),ce("all");return}be.current&&clearTimeout(be.current),be.current=setTimeout(()=>{U(null),ce("all"),g==null||g(ne),I(ne)},tc)},[I,g]),fe=f.useCallback(ne=>{be.current&&clearTimeout(be.current),ce("all"),g==null||g(ne),I(ne)},[I,g]),he=f.useCallback(ne=>{U(ne),I(_,ec)},[_,I]);f.useEffect(()=>{if(!pe.length){Ne([]);return}let ne=!1;return Te(!0),Promise.all(pe.slice(0,10).map(async we=>{var E,Q,ue;try{if(e.getEntry){const te=await e.getEntry(we);if(te)return te}const le=await e.getItem(we);if(le){const te=le.authors;return{id:we,title:le.title||we,type:le.type||"work",author:(E=te==null?void 0:te[0])==null?void 0:E.name,dynasty:(Q=te==null?void 0:te[0])==null?void 0:Q.dynasty,role:(ue=te==null?void 0:te[0])==null?void 0:ue.role,edition:le.edition||void 0}}}catch{}return{id:we,title:we,type:"work",notFound:!0}})).then(we=>{ne||(Ne(we),Te(!1))}),()=>{ne=!0}},[pe,e]);const W=ne=>{ee(ne.id),Fo(ne.id),ge(zt()),r==null||r(ne)},ae=(ne,we)=>{if(r&&rc(we)){we.preventDefault(),W(ne);return}Fo(ne.id),ge(zt())},J=ne=>{nc(ne),ge(zt())},O=()=>{ic(),ge([])},xe=ne=>$.find(we=>we.type===ne),je=!q&&!z&&!de,Se=z&&(z.works.length>0||z.books.length>0||z.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",style:w?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:sc}),t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("h1",{style:{margin:0,fontSize:"18px",color:i("fg")},children:v.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&t.jsx(Jr,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(Zr,{transport:e,value:_,onChange:Y,onSearch:fe,onEntrySelect:W}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${i("primary")}`,borderRadius:"6px",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"13px"},children:v.action.newEntry})]}),q&&t.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:P&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:re?t.jsxs(t.Fragment,{children:[(re.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:i("fg")},children:re.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:i("fg")},children:P.books.toLocaleString()})," 本"]}),re.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:i("fg")},children:re.article.toLocaleString()})," 篇"]}):null,re.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:i("fg")},children:re.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:i("fg")},children:P.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[v.indexType.work," ",t.jsx("strong",{style:{color:i("fg")},children:P.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.book," ",t.jsx("strong",{style:{color:i("fg")},children:P.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.collection," ",t.jsx("strong",{style:{color:i("fg")},children:P.collections.toLocaleString()}),P.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.entity," ",t.jsx("strong",{style:{color:i("fg")},children:P.entities.toLocaleString()})]})]})}),P.hasImage!=null&&P.hasText!=null&&t.jsxs("span",{children:[v.resourceType.image," ",t.jsx("strong",{style:{color:i("fg")},children:P.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.resourceType.text," ",t.jsx("strong",{style:{color:i("fg")},children:P.hasText.toLocaleString()})]})]})}),y&&!q&&t.jsx(rs,{transport:e,query:R,filters:L,onFiltersChange:F,onEntryLinkClick:ae,typeName:ne=>xe(ne).name}),!(y&&!q)&&t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:B||je?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg"),minHeight:oc,boxSizing:"border-box"},children:v.search.searching}):de?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:i("desc-fg")},children:de})}):q?t.jsx("div",{style:{flex:1},children:ze?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg")},children:v.search.loading}):Ee.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:v.search.recentBrowse}),t.jsx("button",{onClick:O,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:v.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:Ee.slice(0,Ce?10:3).map(ne=>ne.notFound?t.jsx(dc,{id:ne.id,onRemove:J,t:v},ne.id):t.jsx(Oo,{entry:ne,selected:A===ne.id,onClick:ae,getConfig:xe,onRemove:J},ne.id))}),!Ce&&Ee.length>3&&t.jsx("button",{onClick:()=>Ae(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:v.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:v.search.searchTitle}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:v.search.searchSubtitle})]})}):Se?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:lc}),(()=>{const ne=le=>z[Po[le]]??0,we=k.map(le=>$.find(te=>te.type===le)).filter(le=>ne(le.key)>0);if(we.length<2)return null;const E=we.reduce((le,te)=>le+ne(te.key),0),Q=le=>{if(ce(le),le!=="all"&&X!==le){const te=$.find(Ie=>Ie.type===le),ke=(z[te.key]??[]).length;ne(te.key)>ke&&he(le)}},ue=le=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:i(le?"fg":"desc-fg"),fontWeight:le?700:400,boxShadow:le?`inset 0 -2px 0 ${i("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":v.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":T==="all",style:ue(T==="all"),onClick:()=>Q("all"),children:[v.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:E.toLocaleString()})]}),we.map(le=>t.jsxs("button",{type:"button","aria-pressed":T===le.type,style:ue(T===le.type),onClick:()=>Q(le.type),children:[le.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:ne(le.key).toLocaleString()})]},le.type))]})})(),$.map(({type:ne,name:we,key:E})=>{const Q=z[E]??[],ue=Po[E],le=z[ue]??0;if(Q.length===0||T!=="all"&&T!==ne)return null;const ke=T==="all"&&!(X===ne)&&le>Gn;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:[t.jsx(Wt,{type:ne})," ",we,t.jsxs("span",{style:{fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[le," ",v.unit.items]})]}),ke&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>he(ne),style:{border:"none",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"12px"},children:v.action.viewAll})]}),t.jsx("div",{style:u==="list"?{display:"flex",flexDirection:"column",gap:0}:u==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:Q.map(Ie=>{if(m)return t.jsx(f.Fragment,{children:m(Ie)},Ie.id);const We=u==="card"?cc:Oo;return t.jsx(We,{entry:Ie,selected:A===Ie.id,onClick:ae,getConfig:xe,query:_},Ie.id)})})]},ne)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:Qe(v.search.noResultsFor,{query:_})}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:v.search.tryOther})]})})]})},oc=240;function rc(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const sc=`
2
121
  .bim-ib-stats { min-height: 25px; box-sizing: content-box; }
3
122
  @media (max-width: 719px) { .bim-ib-stats { min-height: 46px; } }
4
- `,ha=`
123
+ `,lc=`
5
124
  @media (max-width: 719px), (pointer: coarse) {
6
125
  .bim-ib-viewall { position: relative; }
7
126
  .bim-ib-viewall::after {
8
127
  content: ""; position: absolute; left: 50%; top: 50%;
9
128
  width: max(calc(100% + 8px), 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
10
129
  }
11
- }`,Nr={color:"inherit",textDecoration:"none"},ba=({snippet:e})=>{const{convert:n}=Z();return t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.6},children:_r(e).map((o,r)=>o.marked?t.jsx("mark",{style:{background:i("highlight-bg"),color:i("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(o.text)},r):t.jsx(g.Fragment,{children:n(o.text)},r))})},ya=({entry:e,selected:n,onClick:o,getConfig:r,query:s})=>{const l=ue(),{convert:d}=Z(),p=d(e.title||e.primary_name||e.id),c=e.measure_info?d(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",a=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&a.length?a.find(m=>{const j=typeof m=="string"?m:m==null?void 0:m.book_title;return j==null?void 0:j.toLowerCase().includes(s.toLowerCase())}):void 0,f=i("cover-accent"),x=Pe();return t.jsxs("a",{href:x(e.id),onClick:m=>o(e,m),className:"bim-result-card",style:{...Nr,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:i("bg"),border:n?`1px solid ${i("primary")}`:`1px solid ${i("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%, ${i("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${f} 14%, ${i("bg")}), color-mix(in srgb, ${f} 7%, ${i("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,j)=>t.jsx("span",{children:m},j))})]}),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:i("fg")},children:p}),c&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",d(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:d(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",d(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",d(e.era),"〕"]}),e.edition&&t.jsx("span",{children:d(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[l.search.alias,":",d(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(ba,{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:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:[t.jsx(vn,{type:e.type,size:8})," ",r(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.imageResource})]})]})]})},vo=({entry:e,selected:n,onClick:o,getConfig:r,query:s,onRemove:l})=>{const d=ue(),{convert:p}=Z(),c=[...e.additional_titles||[],...e.attached_texts||[]],a=s&&c.length?c.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=Pe();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("a",{href:u(e.id),onClick:f=>o(e,f),className:"bim-result-card",style:{...Nr,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(vn,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:i("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:i("fg")},children:p(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{children:d.misc.textResource}),e.has_image&&t.jsx("span",{children:d.misc.imageResource})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:i("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:i("desc-fg")},children:p(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[e.juan_count,d.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:i("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??"?"]})]}),a&&t.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:[d.search.alias,":",p(a)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:d.search.removeFromRecent,"aria-label":d.search.removeFromRecent,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},ja=({id:e,onRemove:n,t:o})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${i("widget-border")}`,background:i("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:i("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:o.search.itemNotFound})]}),t.jsx("button",{onClick:()=>n(e),title:o.search.removeFromRecent,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function va(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 ka({data:e}){const{convert:n}=Z(),{dynasty:o,birth_year:r,death_year:s}=e,l=[];return o&&l.push(`〔${n(o)}〕`),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:i("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function wa({alt_names:e}){const{convert:n}=Z(),o=new Map;for(const l of e){const d=l.type||"別名";o.has(d)||o.set(d,[]),o.get(d).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((l,d)=>{const p=r.indexOf(l),c=r.indexOf(d);return p===-1&&c===-1?0:p===-1?1:c===-1?-1:p-c});return t.jsx("div",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const d=o.get(l);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),t.jsx("span",{children:d.map((p,c)=>t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},c))})]},l)})})}function Sa({data:e}){const n=e.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.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:i("link-fg"),border:`1px solid ${i("link-fg")}40`,borderRadius:"3px",textDecoration:"none",background:`${i("link-fg")}08`},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),o.length===0?null:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function _a({works:e,transport:n,onNavigate:o,renderLink:r}){const s=ue(),{convert:l}=Z(),d=Pe(),[p,c]=g.useState(new Map);g.useEffect(()=>{if(!n)return;let x=!1;const m=e.map(w=>w.work_id);return(async()=>{const w=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(m);let $=!0;for(let v=0;v<m.length;v++){const _=k[v];_!=null&&_.title?w.set(m[v],_.title):_!=null&&_.primary_name?w.set(m[v],_.primary_name):$=!1}if($)return w}catch{}const h=[...m],b=8,y=new Array(b).fill(0).map(async()=>{for(;h.length;){const k=h.shift();if(!k)break;if(!w.has(k))try{if(n.getEntry){const _=await n.getEntry(k);if(_!=null&&_.title){w.set(k,_.title);continue}}const $=await n.getItem(k),v=$&&($.title||$.primary_name)||k;w.set(k,v)}catch{w.set(k,k)}}});return await Promise.all(y),w})().then(w=>{x||c(w)}),()=>{x=!0}},[e,n]);const a=new Map;for(const x of e){const m=x.role||"";a.has(m)||a.set(m,[]),a.get(m).push(x)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],f=[...a.keys()].sort((x,m)=>{const j=u.indexOf(x),w=u.indexOf(m);return j===-1&&w===-1?x.localeCompare(m):j===-1?1:w===-1?-1:j-w});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:i("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:i("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),f.map(x=>{const m=a.get(x);return t.jsxs("div",{style:{marginBottom:"8px"},children:[x&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"2px"},children:[l(x)," ",t.jsxs("span",{style:{color:i("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((j,w)=>{const h=l(p.get(j.work_id)||j.work_id);return r?t.jsx("li",{children:r(j.work_id,h)},w):o?t.jsx("li",{children:t.jsx("a",{href:d(j.work_id),onClick:b=>{b.metaKey||b.ctrlKey||(b.preventDefault(),o(j.work_id))},style:{color:i("link-fg"),textDecoration:"underline",cursor:"pointer"},children:h})},w):t.jsx("li",{children:h},w)})})]},x)})]})}const Lr=({data:e,transport:n,onNavigate:o,renderLink:r,headerExtra:s,hideHeader:l})=>{var f;const d=ue(),{convert:p}=Z();let c=!1;try{c=we.extractStatus(e.id)==="draft"}catch{}const a=va(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:i("fg")},children:[p(e.primary_name),t.jsx(ka,{data:e})]}),s]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:i("type-entity"),border:`1px solid color-mix(in srgb, ${i("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${i("type-entity")} 3%, transparent)`},children:d.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),c&&t.jsx("span",{style:{padding:"1px 6px",background:i("warn-bg"),border:`1px solid ${i("warn-border")}`,borderRadius:"2px",color:i("warn-fg")},children:d.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),a&&t.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:i("widget-bg"),border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(wa,{alt_names:e.alt_names}),t.jsx(Sa,{data:e}),((f=e.description)==null?void 0:f.text)&&t.jsx("p",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(e.description.text)}),e.works&&e.works.length>0&&t.jsx(_a,{works:e.works,transport:n,onNavigate:o,renderLink:r})]})},$a=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function za(e){const n=e.search($a);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const Br={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 o=e,r="",s=n;if(e&&typeof n=="string"&&(n===e||n===Ca(e))){const[l,d]=za(n);d&&(o=encodeURI(l),s=l,r=d)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:o,target:o!=null&&o.startsWith("http")?"_blank":void 0,rel:o!=null&&o.startsWith("http")?"noopener noreferrer":void 0,style:{color:i("link")},children:s}),r]})},code:({children:e})=>t.jsx("code",{style:{background:i("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function Ca(e){try{return decodeURI(e)}catch{return e}}const Ia={...Br,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},lt=({text:e,plainStrong:n,style:o,className:r})=>{const{convert:s}=Z(),l=n?Ia:Br;return t.jsx("div",{className:r,style:o,children:t.jsx(Ll,{remarkPlugins:[Bl],components:l,children:s(e)})})},Ta=["〇","一","二","三","四","五","六","七","八","九"],ko=["","十","百","千"];function Ar(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),o=n.length;let r="",s=!1;for(let l=0;l<o;l++){const d=parseInt(n[l]),p=o-1-l;d===0?s=!0:(s&&r&&(r+="〇"),s=!1,d===1&&p===1&&l===0?r+=ko[p]:r+=Ta[d]+ko[p])}return r}function Wr(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 Ea={book:i("type-book"),work:i("type-work"),collection:i("type-collection"),entity:i("type-entity")};function Ra({type:e}){const n=ue();return t.jsx("span",{style:Wr(Ea[e]),children:n.indexType[e]})}function Na({isDraft:e}){const n=ue(),o=i(e?"status-draft":"status-official");return t.jsx("span",{style:Wr(o),children:e?n.status.draft:n.status.official})}function La({id:e}){const n=ue(),[o,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:i("desc-fg"),background:i("bg-subtle"),border:`1px solid ${i("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:i("fg")},children:e}),t.jsx("span",{onClick:s,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function Ve({children:e,extra:n}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("desc-fg"),letterSpacing:"1px"},children:e}),t.jsx("span",{style:{flex:1}}),n]})}function nt({label:e,children:n}){return t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[t.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:e}),t.jsx("span",{style:{color:i("fg")},children:n})]})}function Mr({authors:e,type:n,onNavigate:o,renderLink:r}){const{convert:s}=Z();return t.jsx("span",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.6},children:e.map((l,d)=>{const p=s(l.name),c=l.entity_id?t.jsx(Je,{id:l.entity_id,label:p,onNavigate:o,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:p});return t.jsxs("span",{children:[d>0&&t.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),c,l.role&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},d)})})}function Je({id:e,label:n,onNavigate:o,renderLink:r}){const s=Pe();return r?t.jsx(t.Fragment,{children:r(e,n)}):o?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(e))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("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 Ba({id:e,title:n,edition:o,type:r,isDraft:s,authors:l,volumeText:d,meta:p,headerExtra:c,onNavigate:a,renderLink:u}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:i("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,o&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:o}),d&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:d})]}),c&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(Ra,{type:r}),t.jsx(Na,{isDraft:s}),t.jsx(La,{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(Mr,{authors:l,type:r,onNavigate:a,renderLink:u}),p]})]})}function Fr({items:e,label:n,showMeta:o,onNavigate:r,renderLink:s}){const l=ue(),{convert:d}=Z();if(!e.length)return null;const[p,c]=g.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((a,u)=>{const f=p===u;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...f?{boxShadow:i("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>c(f?null:u),style:{padding:"8px 12px",background:i("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.jsx("span",{style:{fontSize:"10px",color:i("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:i("fg")},children:d(a.source)}),!f&&o&&a.title_info&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d(a.title_info)}),a.source_bid&&t.jsx("span",{onClick:x=>x.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Je,{id:a.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),f&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${i("widget-border")}`},children:[o&&(a.title_info||a.author_info||a.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[a.title_info&&t.jsx(nt,{label:l.label.titleInfo,children:d(a.title_info)}),a.author_info&&t.jsx(nt,{label:l.label.authorInfo,children:d(a.author_info)}),a.edition&&t.jsx(nt,{label:l.label.edition,children:d(a.edition)})]}),a.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${i("primary")}`,background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:d(a.summary)})]}),a.comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(a.comment)})]}),a.additional_comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(a.additional_comment)})]})]})]},u)})})]})}function Aa({items:e,onNavigate:n,renderLink:o}){const r=ue();return t.jsx(Fr,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function Pr({items:e,onNavigate:n,renderLink:o}){const r=ue();return t.jsx(Fr,{items:e,label:r.section.emendated,onNavigate:n,renderLink:o})}function Or({label:e,items:n}){const{convert:o}=Z();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const l=typeof r=="string"?r:r.book_title;return t.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:i("fg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:o(l)},s)})})]}):null}function Wa({items:e}){const n=ue();return t.jsx(Or,{label:n.section.aliases,items:e})}function Ma({items:e}){const n=ue();return t.jsx(Or,{label:n.section.attachedTexts,items:e})}function Fa({items:e}){const n=ue(),{convert:o}=Z();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.appendix}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:e.map((r,s)=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:i("fg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:["《",o(r.book_title),"》",r.n_juan!=null&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function Pa({items:e}){const n=ue(),{convert:o}=Z();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.locationHistory}),t.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[t.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:i("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:i("primary"),border:`1.5px solid ${i("input-bg")}`}}),t.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:i("fg")},children:o(r.name)}),r.description&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),marginLeft:"8px"},children:o(r.description)})]},s))]})]}):null}function Oa({items:e}){const n=ue(),{convert:o}=Z();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.historyOverview}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map((r,s)=>t.jsxs("div",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[t.jsx("span",{style:{position:"absolute",left:0,top:0,color:i("desc-fg")},children:"·"}),o(r)]},s))})]}):null}function wo({title:e,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:l}=Z(),[d,p]=g.useState([]);return g.useEffect(()=>{if(!n.length){p([]);return}if(!o){p(n.map(a=>({id:a})));return}let c=!1;return Promise.all(n.map(a=>o.getItem(a).then(u=>({id:a,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:a})))).then(a=>{c||p(a)}),()=>{c=!0}},[n,o]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(Ve,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",n.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(d.length?d:n.map(c=>({id:c}))).map(c=>{const a=c.edition?`${l(c.title)||c.id}(${l(c.edition)})`:l(c.title)||void 0;return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),transition:"border-color 0.15s"},children:t.jsx(Je,{id:c.id,label:a,onNavigate:r,renderLink:s})},c.id)})})]}):null}function Bn({book:e,onNavigate:n,renderLink:o}){const r=ue(),{convert:s}=Z(),[l,d]=g.useState(!1),p=e.resources&&e.resources.length>0,c=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:i("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${i("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(Je,{id:e.id,label:c,onNavigate:n,renderLink:o})}),p&&t.jsx("span",{onClick:()=>d(a=>!a),style:{cursor:"pointer",fontSize:"10px",color:i("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(hi,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Da({ids:e,workData:n,transport:o,onNavigate:r,renderLink:s,footer:l}){const d=ue(),{convert:p}=Z(),[c,a]=g.useState([]);if(g.useEffect(()=>{if(!e.length){a([]);return}if(!o){a(e.map(w=>({id:w})));return}let j=!1;return Promise.all(e.map(w=>o.getItem(w).then(h=>({id:w,title:h?h.title:void 0,edition:h?h.edition:void 0,resources:h?h.resources:void 0,resource_groups:h?h.resource_groups:void 0})).catch(()=>({id:w})))).then(w=>{j||a(w)}),()=>{j=!0}},[e,o]),!e.length)return null;const u=c.length?c:e.map(j=>({id:j})),f=new Map(u.map(j=>[j.id,j])),x=n==null?void 0:n.version_graph,m=Ha(e,x);return t.jsxs(t.Fragment,{children:[t.jsxs(Ve,{children:[d.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:i("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(j=>{const w=f.get(j);return w?t.jsx(Bn,{book:w,onNavigate:r,renderLink:s},j):null})}),m.groupedIds.map(j=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${i("widget-border")}`,borderRadius:6,background:i("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:i("fg"),userSelect:"none"},children:[p(j.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:i("desc-fg"),fontWeight:400},children:["(",j.ids.length,")"]}),j.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:i("desc-fg"),fontWeight:400},children:p(j.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:j.ids.map(w=>{const h=f.get(w);return h?t.jsx(Bn,{book:h,onNavigate:r,renderLink:s},w):null})})]},j.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(j=>t.jsx(Bn,{book:j,onNavigate:r,renderLink:s},j.id))})]})}function Ha(e,n){var h,b;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const o=(h=n.collections)==null?void 0:h[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.book_ids)??[],l=r.length>0||s.length>0,d=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&d.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),c=new Set([...s,...d]),a=y=>{if(c.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(!((b=n.excluded_books)!=null&&b.includes(y)))if(a(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 j=new Map((n.groups??[]).map(y=>[y.id,y])),w=[...f.entries()].map(([y,k])=>{const $=j.get(y);return{id:y,label:($==null?void 0:$.label)??y,description:$==null?void 0:$.description,ids:k}});return x.length>0&&w.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:w}}function Ga({workData:e,onNavigate:n,renderLink:o}){var d,p,c,a;const r=ue(),{convert:s}=Z(),l=!!((d=e.description)!=null&&d.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:i("input-bg"),marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?`1px solid ${i("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`},children:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:t.jsx(Je,{id:e.id,label:s(e.title),onNavigate:n,renderLink:o})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:i("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:i("desc-fg")},children:[Ar(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(Mr,{authors:e.authors,type:"work",onNavigate:n,renderLink:o})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((c=e.description)==null?void 0:c.text)&&t.jsx(lt,{text:e.description.text,style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(a=e.description)!=null&&a.text?"8px":0,fontSize:"13px"},children:t.jsx(nt,{label:r.label.parentWork,children:t.jsx(Je,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Ua({items:e,onNavigate:n,renderLink:o}){const r=ue(),{convert:s}=Z();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, ${i("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${i("type-collection")} 3%, transparent)`},children:[t.jsx("span",{style:{fontSize:"11px",color:i("type-collection")},children:r.indexType.collection}),t.jsx(Je,{id:l.id,label:s(l.title)||l.id,onNavigate:n,renderLink:o}),l.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"2px"},children:Jt(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const bi=({data:e,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:d,className:p,style:c})=>{var D,B,O,M,X,Y,E,ee;const a=ue(),{convert:u}=Z(),[f,x]=g.useState(null),[m,j]=g.useState(!1),[w,h]=g.useState(null),[b,y]=g.useState(null),[k,$]=g.useState([]),v=e||f;if(g.useEffect(()=>{if(e||!n||!o)return;let F=!1;return j(!0),h(null),o.getItem(n).then(K=>{F||(K?x(K):h(a.misc.notFoundEntry))}).catch(K=>{F||h(K instanceof Error?K.message:a.misc.loadFailed)}).finally(()=>{F||j(!1)}),()=>{F=!0}},[e,n,o]),g.useEffect(()=>{if(!v||!o){y(null),$([]);return}let F=!1;const K=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(K?o.getItem(K).then(ae=>{!F&&ae&&ae.type==="work"&&y(ae)}).catch(()=>{}):y(null),v.type==="book"){const ae=v;ae.contained_in&&ae.contained_in.length>0?Promise.all(ae.contained_in.map(ne=>{const Q=typeof ne=="string"?ne:ne.id,ie=typeof ne=="string"?void 0:ne.volume_index;return o.getItem(Q).then(ge=>({id:Q,title:ge&&ge.title||Q,volume_index:ie})).catch(()=>({id:Q,title:Q,volume_index:ie}))})).then(ne=>{F||$(ne)}):$([])}else $([]);return()=>{F=!0}},[v,o]),m)return t.jsx("div",{className:p,style:{...c,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((F,K)=>t.jsx("div",{style:{height:K===1?"32px":"16px",width:`${F}px`,background:i("widget-border"),borderRadius:"4px",opacity:.4}},K))})});if(w)return t.jsx("div",{className:p,style:{...c,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:w});if(!v)return null;if(v.type==="entity")return t.jsx("div",{className:p,style:c,children:t.jsx(Lr,{data:v,transport:o,onNavigate:r,renderLink:s,headerExtra:l})});const _=v.type==="book"?v:null,S=v.type==="collection"?v:null,z=v.type==="work"?v:null;let N=!1;try{N=we.extractStatus(v.id)==="draft"}catch{}let T="";v.measure_info?T=u(v.measure_info):(D=v.juan_count)!=null&&D.number?T=Ar(v.juan_count.number)+a.unit.juan:(B=v.juan_count)!=null&&B.description&&(T=u(v.juan_count.description));const C=[];return(O=v.publication_info)!=null&&O.year&&C.push(t.jsx(nt,{label:a.label.year,children:v.publication_info.year},"year")),(M=v.current_location)!=null&&M.name&&C.push(t.jsx(nt,{label:a.label.currentLocation,children:u(v.current_location.name)},"loc")),(X=v.page_count)!=null&&X.description&&C.push(t.jsx(nt,{label:a.label.pageCount,children:v.page_count.description},"page")),_!=null&&_.edition&&C.push(t.jsx(nt,{label:a.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&C.push(t.jsx(nt,{label:a.label.parentWork,children:t.jsx(Je,{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(nt,{label:a.label.parentWork,children:z.parent_works.map((F,K)=>t.jsxs("span",{children:[K>0&&"、",t.jsx(Je,{id:F,onNavigate:r,renderLink:s})]},F))},"pws")),t.jsxs("div",{className:p,style:c,children:[t.jsx(Ba,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:N,authors:v.authors,volumeText:T,meta:C,headerExtra:l,onNavigate:r,renderLink:s}),((Y=v.description)==null?void 0:Y.text)&&t.jsx(lt,{text:v.description.text,style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((F,K)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:i("bg-subtle"),borderRadius:4,border:`1px solid ${i("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:i("muted")},children:u(F.title)}),t.jsx(lt,{text:F.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:i("fg")}})]},K))}),k.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:a.section.containedIn}),t.jsx(Ua,{items:k,onNavigate:r,renderLink:s})]}),b&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:a.section.belongsToWork}),t.jsx(Ga,{workData:b,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&t.jsx(Fa,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&t.jsx(Wa,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&t.jsx(Ma,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&t.jsx(Aa,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&t.jsx(Pr,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:a.section.resources}),t.jsx(hi,{items:v.resources,resourceGroups:v.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&t.jsx(Pa,{items:_.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&t.jsx(Oa,{items:S.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&t.jsx(wo,{title:a.section.relatedVersions,ids:_.related_books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&t.jsx(wo,{title:a.section.containedBooks,ids:S.books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(Ve,{children:[a.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",S.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(F=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:t.jsx(Je,{id:F.id,label:u(F.title),onNavigate:r,renderLink:s})},F.id))})]}),(((E=z==null?void 0:z.books)==null?void 0:E.length)||0)+(((ee=z==null?void 0:z.collections)==null?void 0:ee.length)||0)>0&&t.jsx(Da,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z??void 0,transport:o,onNavigate:r,renderLink:s,footer:d}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const F=[],K=z.related_works.filter(re=>re.relation==="part_of"),ae=z.related_works.filter(re=>re.relation==="has_part"),ne=z.related_works.filter(re=>re.relation==="has_adaptation"),Q=z.related_works.filter(re=>re.relation==="text_carried_by"),ie=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ge=z.related_works.filter(re=>!re.relation||!ie.has(re.relation));return K.length>0&&F.push({label:a.section.belongsToWork,items:K}),ae.length>0&&F.push({label:a.section.containedWorks,items:ae}),ne.length>0&&F.push({label:a.section.adaptations,items:ne}),Q.length>0&&F.push({label:a.section.derivativeWorks,items:Q}),ge.length>0&&F.push({label:a.section.relatedWorks,items:ge}),F.map(re=>t.jsxs("div",{children:[t.jsxs(Ve,{children:[re.label,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",re.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:re.items.map(le=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:t.jsx(Je,{id:le.id,label:u(le.title),onNavigate:r,renderLink:s})},le.id))})]},re.label))})()]})};function Va({data:e}){const n=ue(),{convert:o}=Z(),{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:i("fg"),margin:"0 0 8px"},children:o(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"6px"},children:o(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:i("desc-fg")},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:i("fg")},children:e.total_volumes})," ",n.unit.volume]}),l!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:i("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:i("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:i("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:i("missing-fg")},children:r.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:i("desc-fg")},children:[n.catalog.source," ",e.source]})]})}function Ya({sections:e,activeSection:n,onSelect:o}){const r=ue();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>o(null),style:So(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>o(s.name),style:So(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 So(e){return{padding:"4px 12px",border:e?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${i("primary")} 8%, transparent)`:"transparent",color:i(e?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Ka({id:e,label:n,onNavigate:o,renderLink:r}){const s=Pe();return r?t.jsx(t.Fragment,{children:r(e,n)}):o?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(e))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("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:i("desc-fg")},children:n||e})}function qa(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const o=e[0],r=e[e.length-1];return r-o+1===e.length?`${o}–${r}`:e.length<=3?e.join(", "):`${o}–${r} (${e.length}${n})`}function _o({book:e,onNavigate:n,renderLink:o,showVolumes:r}){const s=ue(),{convert:l}=Z(),d=e.book_id||e.work_id,p=r&&e.volumes.length>0?qa(e.volumes,s.unit.volume):null,c=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${i("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:i("desc-fg"),textAlign:"right"},children:p}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:i("fg")},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(a=>l(a)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:i(c?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),d&&t.jsx(Ka,{id:d,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!d&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const yi=({data:e,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:l,style:d})=>{const p=ue(),[c,a]=g.useState(null),[u,f]=g.useState(!1),[x,m]=g.useState(null),[j,w]=g.useState(null),[h,b]=g.useState(""),y=e||c;g.useEffect(()=>{if(e||!n||!(o!=null&&o.getCollectionCatalog))return;let S=!1;return f(!0),m(null),o.getCollectionCatalog(n).then(z=>{S||(z?a(z):m(p.catalog.notFound))}).catch(z=>{S||m(z instanceof Error?z.message:p.catalog.loadFailed)}).finally(()=>{S||f(!1)}),()=>{S=!0}},[e,n,o,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 S=y.books.map(N=>N.volumes[0]).filter(N=>N!=null);return new Set(S).size<S.length},[y]),v=g.useMemo(()=>{if(!y)return[];let S=y.books;if(j&&(S=S.filter(z=>z.section===j)),h.trim()){const z=h.trim().toLowerCase();S=S.filter(N=>N.title.toLowerCase().includes(z)||N.sub_items&&N.sub_items.some(T=>T.toLowerCase().includes(z))||N.edition&&N.edition.toLowerCase().includes(z))}return S},[y,j,h]),_=g.useMemo(()=>{if(!$)return null;const S=[],z=new Map;for(const T of v){if(!T.volumes||T.volumes.length===0)continue;const C=T.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(T)}const N=[...z.keys()].sort((T,C)=>T-C);for(const T of N)S.push({volume:T,books:z.get(T)});return S},[v,$]);return u?t.jsx("div",{className:l,style:{...d,padding:"24px"},children:t.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):x?t.jsx("div",{className:l,style:{...d,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:x}):y?t.jsxs("div",{className:l,style:d,children:[t.jsx(Va,{data:y}),k&&t.jsx(Ya,{sections:y.sections,activeSection:j,onSelect:w}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:h,onChange:S=>b(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:i("desc-fg")},children:[v.length," ",p.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[_?_.map((S,z)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:i("bg"),borderBottom:`1px solid ${i("widget-border")}`,fontSize:"12px",fontWeight:600,color:i("desc-fg"),position:"sticky",top:0,zIndex:1},children:Jt(p.catalog.volume,{n:S.volume})}),S.books.map((N,T)=>t.jsx(_o,{book:N,onNavigate:r,renderLink:s,showVolumes:N.volumes.length>1},`${S.volume}-${T}`))]},`${S.volume}-${z}`)):v.map((S,z)=>t.jsx(_o,{book:S,onNavigate:r,renderLink:s,showVolumes:!0},z)),v.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},jt=()=>{const[e,n]=g.useState(1);return g.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:i("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(e)})},Dr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Ja={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function We(e){return Ja[e]??e}const It=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],Tt={熹平:172,建安:196,黃初:220,正始:240,廣政:938,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,開成:836,會昌:841,咸通:860,建隆:960,太平興國:976,咸平:998,天禧:1017,慶曆:1041,皇祐:1049,嘉祐:1056,治平:1064,熙寧:1068,元豐:1078,元祐:1086,紹聖:1094,崇寧:1102,大觀:1107,政和:1111,宣和:1119,建炎:1127,紹興:1131,隆興:1163,乾道:1165,淳熙:1174,紹熙:1190,慶元:1195,嘉泰:1201,開禧:1205,嘉定:1208,寶慶:1225,紹定:1228,端平:1234,嘉熙:1237,淳祐:1241,寶祐:1253,開慶:1259,景定:1260,咸淳:1265,大定:1161,明昌:1190,至元:1264,大德:1297,皇慶:1312,延祐:1314,泰定:1324,天曆:1328,至順:1330,至正:1341,洪武:1368,永樂:1403,宣德:1426,正統:1436,景泰:1450,天順:1457,成化:1465,弘治:1488,正德:1506,嘉靖:1522,隆慶:1567,萬曆:1573,泰昌:1620,天啟:1621,崇禎:1628,弘光:1645,隆武:1645,紹武:1646,永曆:1647,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,正保:1644,慶安:1648,承應:1652,明曆:1655,萬治:1658,寬文:1661,延寶:1673,天和:1681,貞享:1684,元祿:1688,寶永:1704,享保:1716,元文:1736,寬保:1741,延享:1744,寬延:1748,寶曆:1751,明和:1764,安永:1772,天明:1781,寬政:1789,享和:1801,文化:1804,文政:1818,天保:1830,弘化:1844,嘉永:1848,安政:1854,萬延:1860,文久:1861,元治:1864,慶應:1865,明治:1868,大正:1912,昭和:1926,天正:1573,文祿:1592,永祿:1558,天文:1532},Hr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function kn(e){const n=e.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const o=parseInt(n[1],10);if(o<100||o>2100)return;const r=n[2]?parseInt(n[2],10):void 0;return{from:o,to:r!=null&&r>=o&&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 Xa=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,$o={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function ji(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys($o))if(n.startsWith(s))return $o[s];const o=We(n);if(gt[o]!=null)return o;const r=st(n);if(r&&n.length<=r.length+1)return We(r)}function ft(e,n){if(n){const o=Hr[`${n}|${e}`];if(o!=null)return o}return Tt[e]}const Qa=1911;function ec(e){const n=Tt[e];if(n==null)return;const o=it[e];let r;for(const[s,l]of Object.entries(Tt))it[s]===o&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const tc={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function gn(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,o=0,r=!1;for(const l of e){const d=tc[l];if(d===void 0)return;r=!0,l==="十"?o=(o||1)*10:l==="廿"||l==="卅"?(n+=d,o=0):o>=10?(n+=o+d,o=0):o=o*10+d}const s=n+o;return r&&s>0?s:void 0}function st(e){for(const n of Dr)if(e.startsWith(n))return n}const it={};{const e=(n,o)=>{for(const r of o)it[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function mt(e,n){const o=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(Tt))if(e.includes(r)&&!(o&&it[r]&&it[r]!==o&&Hr[`${o}|${r}`]==null))return r}function Zt(e){var d,p,c;const n={era:"",reign:"",source:"none"},o=e.dating;if(o!=null&&o.era||o!=null&&o.reign)return{era:o.era??"",reign:o.reign??"",source:o.certainty==="attested"?"catalog":"edition"};const r=(d=e.lineage)==null?void 0:d.year_text;if(r){const a=st(r)??"";return{era:We(a),reign:mt(r,a)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const a=kn(s);if(a)return{era:Za(a.from),reign:"",source:"publication"};const u=st(s)??ji(s)??((c=It.find(m=>m.pattern.test(s)))==null?void 0:c.era)??"",f=mt(s,u)??"",x=u||(f?it[f]??"":"");if(x||f)return{era:We(x),reign:f,source:"publication"}}const l=e.edition||e.title||"";if(l){const a=st(l);if(a)return{era:We(a),reign:mt(l,a)??"",source:"edition"};const u=It.find(f=>f.pattern.test(l));if(u)return{era:We(u.era),reign:mt(l,u.era)??u.reign??"",source:"edition"}}return n}function wn(e){var r,s,l,d,p,c,a,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=kn(n);if(x)return x.from}const o=[(d=e.lineage)==null?void 0:d.year_text,(p=e.publication_info)==null?void 0:p.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const x of o){const m=((c=e.publication_info)==null?void 0:c.year)||((a=e.lineage)==null?void 0:a.year_text);if(m&&x!==m&&(st(m)||ji(m)))break;const j=x.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??x.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(j){const k=parseInt(j[1],10);if(k>=100&&k<=2100)return k}const w=x.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(w){const k=st(x);if(!k||We(k)==="民國"){const v=gn(w[1]);if(v!=null&&v>=1&&v<=120)return Qa+v}}const h=st(x)??((u=It.find(k=>k.pattern.test(x)))==null?void 0:u.era),b=h?We(h):void 0,y=mt(x,b)??(st(x)||(f=It.find(k=>k.pattern.test(x)))==null?void 0:f.reign);if(y){const k=ft(y,b);if(k==null)continue;const $=x.indexOf(y),v=$>=0?x.slice($+y.length):"",_=v.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??v.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=_?gn(_[1]):void 0;return k+(S?S-1:0)}}}function vi(e){var d,p,c,a,u,f;const n=(d=e.dating)==null?void 0:d.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const o=(p=e.lineage)==null?void 0:p.year_range;if(o&&o.length===2)return{from:o[0],to:o[1]};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const x=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(x){const m=Kn[We(x[1])],j=gt[We(x[2])];if(m!=null&&j!=null)return{from:Math.min(m,j)-20,to:Math.max(m,j)+40}}}const s=(a=e.publication_info)==null?void 0:a.year;if(s){const x=kn(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 j=Kn[We(m[1])],w=gt[We(m[2])];if(j!=null&&w!=null)return{from:Math.min(j,w)-20,to:Math.max(j,w)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const x of l){if(!/[間间]/.test(x))continue;const m=st(x)??ji(x)??((f=It.find(h=>h.pattern.test(x)))==null?void 0:f.era),j=m?We(m):void 0,w=[];for(const h of Object.keys(Tt))x.includes(h)&&(j&&it[h]&&it[h]!==j||ft(h,j)!=null&&w.push(h));if(w.length===0){const h=x.match(/([一-鿿])([一-鿿])[間间]/);if(h&&j){for(const b of[h[1],h[2]])for(const y of Object.keys(Tt))if(it[y]===j&&!(y[0]!==b&&y[y.length-1]!==b)&&ft(y,j)!=null){w.push(y);break}}}if(w.length>0){const h=w.map($=>ft($,j)).filter($=>$!=null),b=Math.min(...h),y=w.reduce(($,v)=>ft($,j)>=ft(v,j)?$:v),k=ec(y)??An(j??"")??Math.max(...h);return{from:b,to:k>b?k:An(j??it[y]??"")??b}}if(j&&gt[j]!=null)return{from:gt[j],to:An(j)??gt[j]}}}const gt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},nc=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],ic=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,zo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Co(e,n){for(const o of Dr){const r=e.indexOf(o);if(r<0)continue;if(o.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!mt(e.slice(r),We(o)))continue}const s=We(o);if(s===n)continue;const l=e.slice(r),d=mt(l,s)??"";let p;if(d){const c=ft(d,s);if(c!=null){const u=l.slice(l.indexOf(d)+d.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),f=u?gn(u[1]):void 0;p=c+(f?f-1:0)}}return{era:s,reign:d,year:p}}for(const o of It)if(o.pattern.test(e))return{era:We(o.era),reign:o.reign??""}}function oc(e){var b,y,k,$,v;const n=Zt(e),o=((b=e.publication_info)==null?void 0:b.year)??"",r=o?kn(o):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),d=((y=e.lineage)==null?void 0:y.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(d),c=n.source==="publication"&&Xa.test(o),a=n.source==="publication"&&/[間间]/.test(o),u=d.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let f;l||p||c||a?f=void 0:u?f=parseInt(u[2],10):f=wn(e);const x=f==null?vi(e):void 0;let m;n.source==="publication"&&(c||zo.test(o))?m="uncertain":n.source==="lineage"||n.source==="publication"?m="attested":zo.test(s)||!n.reign&&f==null?m="uncertain":m="inferred";const j=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((k=e.lineage)==null?void 0:k.year_text)??(($=e.lineage)==null?void 0:$.year)??""}」`:`出版著錄「${((v=e.publication_info)==null?void 0:v.year)??""}」`,w={era:n.era,reign:n.reign,year:f,yearRange:x,certainty:m,source:n.source==="edition"?"edition":"catalog",basis:j};if(u){const _=d.match(/[、,,]\s*([宋元明清])/);_&&_[1]!==w.era&&(w.laterRepair={era:_[1]})}if(!w.laterRepair&&ic.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(w.laterRepair={era:_[1]})}const h=nc.find(_=>_.re.test(s));if(h){const _=s.search(h.re),S=s.slice(_),z=Co(S,n.era)??Co(s,n.era);z&&(w.basedOn={era:z.era,reign:z.reign,year:z.year,relation:h.relation})}return w}const Kn={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function An(e){return Kn[e]}function mn(e){const n=wn(e);if(n!=null)return n;const o=vi(e);if(o)return o.from;const r=Zt(e).era;return r?gt[r]:void 0}const Io=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function qn(e){const n=Io.indexOf(e);return n===-1?Io.length:n}function rc(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 o=[],r=(s,l)=>{n[s].length&&o.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"),o}function ki(e,n){const o=fi(e||[]),r=new Map,s=[];for(const a of o)a.group?(r.has(a.group)||r.set(a.group,[]),r.get(a.group).push(a)):s.push(a);for(const a of r.values())a.sort((u,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 a of s){const u=yt(a),f=u.includes("text"),x=u.includes("image");f&&x?l.textImage.push(a):f?l.text.push(a):x?l.image.push(a):l.physical.push(a)}const p=["text","image","textImage","physical"].filter(a=>l[a].length>0).map(a=>({key:a,items:l[a]})),c=[...r.entries()].map(([a,u])=>{var f,x;return{key:a,label:((f=n==null?void 0:n[a])==null?void 0:f.label)||a,description:(x=n==null?void 0:n[a])==null?void 0:x.description,items:u}});return{buckets:p,mirrors:c,total:o.length}}function Sn(e){const n=[],o=e.metadata||{};o.edition&&n.push(String(o.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const r=yn(e);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),o.version&&n.push(String(o.version)),n.join(" · ")}function Gr(e,n){if(Sn(e)||n.filter(r=>r.name===e.name).length<2)return"";try{const r=new URL(e.url),s=r.searchParams.get("res")||r.searchParams.get("id");if(s)return s;const l=r.pathname.split("/").filter(Boolean).pop();if(l)return decodeURIComponent(l)}catch{}return""}function Ur(e,n){var l,d;const o=e.resources||[],r=[],s=[];for(const p of o){const c=yt(p);c.includes("image")&&r.push(p),c.includes("physical")&&s.push(p)}return{id:e.id,name:e.edition||e.title||e.id,era:Zt(e),year:wn(e),sortYear:mn(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:sc(e.id,n),group:(d=n==null?void 0:n.node_groups)==null?void 0:d[e.id],hasImage:r.length>0}}function sc(e,n){var p,c;if(!n)return!1;const o=n.default_collection;if(!o)return!1;const r=(p=n.collections)==null?void 0:p[o];if(((r==null?void 0:r.book_ids)??(o==="core"?n.core_books??[]:[])).includes(e))return!0;const l=(r==null?void 0:r.groups)??[],d=(c=n.node_groups)==null?void 0:c[e];return!!d&&l.includes(d)}function Vr(e,n,o={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!r.has(c.id)).map(c=>Ur(c,n));let l=s;o.era&&(l=l.filter(c=>c.era.era===o.era)),o.scanOnly&&(l=l.filter(c=>c.hasImage)),o.sort==="year"?l=l.map((c,a)=>({r:c,i:a})).sort((c,a)=>{const u=c.r.sortYear,f=a.r.sortYear;return u!=null&&f!=null?u-f||c.i-a.i:u!=null?-1:f!=null?1:c.i-a.i}).map(c=>c.r):l=l.map((c,a)=>({r:c,i:a})).sort((c,a)=>{const u=f=>(f.important?0:1)*2+(f.hasImage?0:1);return u(c.r)-u(a.r)||c.i-a.i}).map(c=>c.r);const p=[...new Set(s.map(c=>c.era.era).filter(Boolean))].sort((c,a)=>qn(c)-qn(a));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(c=>c.era.source==="edition")}}function lc(e,n){var h,b;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const o=(h=n.collections)==null?void 0:h[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.book_ids)??[],l=r.length>0||s.length>0,d=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&d.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),c=new Set([...s,...d]),a=y=>{if(c.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(!((b=n.excluded_books)!=null&&b.includes(y)))if(a(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 j=new Map((n.groups??[]).map(y=>[y.id,y])),w=[...f.entries()].map(([y,k])=>{const $=j.get(y);return{id:y,label:($==null?void 0:$.label)??y,description:$==null?void 0:$.description,ids:k}});return x.length>0&&w.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:w}}const Yr=["撰","編","注","校","譯","繪","其他"],ac=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function wi(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:o,re:r}of ac)if(r.test(n))return o;return"其他"}function Si(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Kr(e){const n=new Map;for(const r of e){const s=wi(r);n.set(s,(n.get(s)??0)+1)}const o=[{cls:"全部",label:"全部",count:e.length}];for(const r of Yr){const s=n.get(r);s&&o.push({cls:r,label:r,count:s})}return o.length>2?o:[]}function qr(e,n,o){if(n&&n.books&&n.books.length>0){const s=n.books.map(d=>({id:d.work_id||d.book_id||void 0,title:d.title,section:d.section,volumes:d.volumes||[],subItems:d.sub_items,edition:d.edition,found:d.found_volumes,expected:d.expected_volumes})),l=[...new Set(s.map(d=>d.section).filter(Boolean))];return{rows:s,source:"catalog",sections:l,totalVolumes:n.total_volumes}}return e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(l=>({id:l.id,title:l.title,volumes:Ut(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,d;return{id:s,title:((l=o==null?void 0:o.get(s))==null?void 0:l.title)||s,edition:(d=o==null?void 0:o.get(s))==null?void 0:d.edition,volumes:[]}}),source:"books",sections:[]}}function Ut(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(n=>typeof n=="number");if(typeof e=="string"){const n=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[o,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-o+1)},(s,l)=>o+l)}return e.split(/[,、]/).map(o=>parseInt(o.trim())).filter(o=>!isNaN(o))}return[]}function _n(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const o=[...e].sort((l,d)=>l-d),r=o[0],s=o[o.length-1];return s-r+1===o.length?`${r}–${s}`:o.length<=3?o.join(", "):`${r}–${s} (${o.length}${n})`}const cc=["〇","一","二","三","四","五","六","七","八","九"],To=["","十","百","千"];function Jr(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),o=n.length;let r="",s=!1;for(let l=0;l<o;l++){const d=parseInt(n[l]),p=o-1-l;d===0?s=!0:(s&&r&&(r+="〇"),s=!1,d===1&&p===1&&l===0?r+=To[p]:r+=cc[d]+To[p])}return r}function dc(e){return e==null?"":typeof e=="string"?e:e.title??""}function at(e,n="卷"){var r,s;const o=e;return o.measure_info?o.measure_info:(r=o.juan_count)!=null&&r.number?Jr(o.juan_count.number)+n:(s=o.juan_count)!=null&&s.description?o.juan_count.description:""}function Zr(e){var r;if(e.edition_type)return e.edition_type;if((r=e.lineage)!=null&&r.category)return e.lineage.category;const n=e.edition||e.title||"",o=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,l]of o)if(s.test(n))return l;return""}const pc="guji_markdown";function Jn(e){const n=e==null?void 0:e.guji_markdown;if(typeof n!="string")return!1;const o=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!o)return!1;const r=parseInt(o[1],10),s=parseInt(o[2],10);return r>0||s>=2}const uc=/^□\{guess=([^\s{}]+)\}/;function xc(e,n){const o=e[n+1];return o!==void 0&&!/[A-Za-z/!?>\s]/.test(o)}function Xr(e,n){let o=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
12
- `)return-1;if(s==="\\"){r++;continue}if(s==="[")o++;else if(s==="]"&&(o--,o===0))return r}return-1}function fc(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function gc(e,n){const o=e[n];if(o==="["&&e[n+1]==="["){const r=e.indexOf("]]",n+2);return r>=0&&e.slice(n+2,r).indexOf(`
13
- `)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(o===":"&&e.startsWith(":zi[",n)){const r=Xr(e,n+3);return r>n+4?{node:{type:"zi",label:fc(e.slice(n+4,r))},end:r+1}:null}if(o==="□"&&e[n+1]==="{"){const r=uc.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function Qr(e,n,o,r){const s=[];let l="";const d=()=>{if(!l)return;const p=r?l.replace(/\\?\|/g,""):l;p&&s.push({type:"text",text:p}),l=""};for(;n<e.length;){const p=e[n];if(o!==null){if(p===o)return d(),{nodes:s,end:n};if(p===`
14
- `)return null}const c=gc(e,n);if(c){d(),s.push(c.node),n=c.end;continue}let a=null;if(p==="⟨"?a="⟩":p==="<"&&xc(e,n)&&(a=">"),a){const u=Qr(e,n+1,a,!0);if(u){d(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return o!==null?null:(d(),{nodes:s,end:n})}function es(e){return Qr(e,0,null,!1).nodes}function mc(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function ts(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${ts(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const hc=216,Eo="clamp(280px, 23vw, 360px)",bc=1440,Zn="(max-width: 719px)",yc=`${Zn}, (pointer: coarse)`,jc=`
15
- .bim-d-main.bim-d-main-grid { max-width: ${bc}px; padding: 16px 32px 0; }
130
+ }`,ss={color:"inherit",textDecoration:"none"},ac=({snippet:e})=>{const{convert:n}=V();return t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.6},children:wi(e).map((o,r)=>o.marked?t.jsx("mark",{style:{background:i("highlight-bg"),color:i("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(o.text)},r):t.jsx(f.Fragment,{children:n(o.text)},r))})},cc=({entry:e,selected:n,onClick:o,getConfig:r,query:s})=>{const l=me(),{convert:c}=V(),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(g=>{const b=typeof g=="string"?g:g==null?void 0:g.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,m=i("cover-accent"),x=Fe();return t.jsxs("a",{href:x(e.id),onClick:g=>o(e,g),className:"bim-result-card",style:{...ss,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:i("bg"),border:n?`1px solid ${i("primary")}`:`1px solid ${i("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, ${m} 50%, ${i("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${m} 14%, ${i("bg")}), color-mix(in srgb, ${m} 7%, ${i("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, ${m} 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:m},children:Array.from(p).map((g,b)=>t.jsx("span",{children:g},b))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:i("fg")},children:p}),a&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:a})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:i("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:i("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:i("desc-fg")},children:[l.search.alias,":",c(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(ac,{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:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:[t.jsx(Wt,{type:e.type,size:8})," ",r(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.imageResource})]})]})]})},Oo=({entry:e,selected:n,onClick:o,getConfig:r,query:s,onRemove:l})=>{const c=me(),{convert:p}=V(),a=[...e.additional_titles||[],...e.attached_texts||[]],d=s&&a.length?a.find(m=>{const x=typeof m=="string"?m:m==null?void 0:m.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,u=Fe();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("a",{href:u(e.id),onClick:m=>o(e,m),className:"bim-result-card",style:{...ss,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(Wt,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:i("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:i("fg")},children:p(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{children:c.misc.textResource}),e.has_image&&t.jsx("span",{children:c.misc.imageResource})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:i("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:i("desc-fg")},children:p(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[e.juan_count,c.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:i("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:i("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:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},dc=({id:e,onRemove:n,t:o})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${i("widget-border")}`,background:i("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:i("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:o.search.itemNotFound})]}),t.jsx("button",{onClick:()=>n(e),title:o.search.removeFromRecent,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function pc(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 uc({data:e}){const{convert:n}=V(),{dynasty:o,birth_year:r,death_year:s}=e,l=[];return o&&l.push(`〔${n(o)}〕`),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:i("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function xc({alt_names:e}){const{convert:n}=V(),o=new Map;for(const l of e){const c=l.type||"別名";o.has(c)||o.set(c,[]),o.get(c).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.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:i("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const c=o.get(l);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:i("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:i("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},a))})]},l)})})}function fc({data:e}){const n=e.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.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:i("link-fg"),border:`1px solid ${i("link-fg")}40`,borderRadius:"3px",textDecoration:"none",background:`${i("link-fg")}08`},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),o.length===0?null:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function mc({works:e,transport:n,onNavigate:o,renderLink:r}){const s=me(),{convert:l}=V(),c=Fe(),[p,a]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let x=!1;const g=e.map(w=>w.work_id);return(async()=>{const w=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(g);let $=!0;for(let k=0;k<g.length;k++){const _=v[k];_!=null&&_.title?w.set(g[k],_.title):_!=null&&_.primary_name?w.set(g[k],_.primary_name):$=!1}if($)return w}catch{}const y=[...g],j=8,h=new Array(j).fill(0).map(async()=>{for(;y.length;){const v=y.shift();if(!v)break;if(!w.has(v))try{if(n.getEntry){const _=await n.getEntry(v);if(_!=null&&_.title){w.set(v,_.title);continue}}const $=await n.getItem(v),k=$&&($.title||$.primary_name)||v;w.set(v,k)}catch{w.set(v,v)}}});return await Promise.all(h),w})().then(w=>{x||a(w)}),()=>{x=!0}},[e,n]);const d=new Map;for(const x of e){const g=x.role||"";d.has(g)||d.set(g,[]),d.get(g).push(x)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],m=[...d.keys()].sort((x,g)=>{const b=u.indexOf(x),w=u.indexOf(g);return b===-1&&w===-1?x.localeCompare(g):b===-1?1:w===-1?-1:b-w});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:i("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:i("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),m.map(x=>{const g=d.get(x);return t.jsxs("div",{style:{marginBottom:"8px"},children:[x&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"2px"},children:[l(x)," ",t.jsxs("span",{style:{color:i("desc-fg")},children:["(",g.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:x?"16px":"0",listStyle:x?"disc":"none",fontSize:"14px",lineHeight:1.8},children:g.map((b,w)=>{const y=l(p.get(b.work_id)||b.work_id);return r?t.jsx("li",{children:r(b.work_id,y)},w):o?t.jsx("li",{children:t.jsx("a",{href:c(b.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),o(b.work_id))},style:{color:i("link-fg"),textDecoration:"underline",cursor:"pointer"},children:y})},w):t.jsx("li",{children:y},w)})})]},x)})]})}const ls=({data:e,transport:n,onNavigate:o,renderLink:r,headerExtra:s,hideHeader:l})=>{var m;const c=me(),{convert:p}=V();let a=!1;try{a=$e.extractStatus(e.id)==="draft"}catch{}const d=pc(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:i("fg")},children:[p(e.primary_name),t.jsx(uc,{data:e})]}),s]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:i("type-entity"),border:`1px solid color-mix(in srgb, ${i("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${i("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:i("warn-bg"),border:`1px solid ${i("warn-border")}`,borderRadius:"2px",color:i("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:i("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:i("widget-bg"),border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(xc,{alt_names:e.alt_names}),t.jsx(fc,{data:e}),((m=e.description)==null?void 0:m.text)&&t.jsx("p",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(e.description.text)}),e.works&&e.works.length>0&&t.jsx(mc,{works:e.works,transport:n,onNavigate:o,renderLink:r})]})},gc=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function hc(e){const n=e.search(gc);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const as={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 o=e,r="",s=n;if(e&&typeof n=="string"&&(n===e||n===bc(e))){const[l,c]=hc(n);c&&(o=encodeURI(l),s=l,r=c)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:o,target:o!=null&&o.startsWith("http")?"_blank":void 0,rel:o!=null&&o.startsWith("http")?"noopener noreferrer":void 0,style:{color:i("link")},children:s}),r]})},code:({children:e})=>t.jsx("code",{style:{background:i("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function bc(e){try{return decodeURI(e)}catch{return e}}const yc={...as,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},dt=({text:e,plainStrong:n,style:o,className:r})=>{const{convert:s}=V(),l=n?yc:as;return t.jsx("div",{className:r,style:o,children:t.jsx(la,{remarkPlugins:[aa],components:l,children:s(e)})})},jc=["〇","一","二","三","四","五","六","七","八","九"],Do=["","十","百","千"];function cs(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),o=n.length;let r="",s=!1;for(let l=0;l<o;l++){const c=parseInt(n[l]),p=o-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=Do[p]:r+=jc[c]+Do[p])}return r}function ds(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 vc={book:i("type-book"),work:i("type-work"),collection:i("type-collection"),entity:i("type-entity")};function kc({type:e}){const n=me();return t.jsx("span",{style:ds(vc[e]),children:n.indexType[e]})}function wc({isDraft:e}){const n=me(),o=i(e?"status-draft":"status-official");return t.jsx("span",{style:ds(o),children:e?n.status.draft:n.status.official})}function Sc({id:e}){const n=me(),[o,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:i("desc-fg"),background:i("bg-subtle"),border:`1px solid ${i("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:i("fg")},children:e}),t.jsx("span",{onClick:s,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function qe({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:i("desc-fg"),letterSpacing:"1px"},children:e}),t.jsx("span",{style:{flex:1}}),n]})}function rt({label:e,children:n}){return t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[t.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:e}),t.jsx("span",{style:{color:i("fg")},children:n})]})}function ps({authors:e,type:n,onNavigate:o,renderLink:r}){const{convert:s}=V();return t.jsx("span",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.6},children:e.map((l,c)=>{const p=s(l.name),a=l.entity_id?t.jsx(et,{id:l.entity_id,label:p,onNavigate:o,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:p});return t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),a,l.role&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},c)})})}function et({id:e,label:n,onNavigate:o,renderLink:r}){const s=Fe();return r?t.jsx(t.Fragment,{children:r(e,n)}):o?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(e))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("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 $c({id:e,title:n,edition:o,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:i("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,o&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:o}),c&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:i("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(kc,{type:r}),t.jsx(wc,{isDraft:s}),t.jsx(Sc,{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(ps,{authors:l,type:r,onNavigate:d,renderLink:u}),p]})]})}function us({items:e,label:n,showMeta:o,onNavigate:r,renderLink:s}){const l=me(),{convert:c}=V();if(!e.length)return null;const[p,a]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(qe,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((d,u)=>{const m=p===u;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...m?{boxShadow:i("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>a(m?null:u),style:{padding:"8px 12px",background:i("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.15s",transform:m?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:c(d.source)}),!m&&o&&d.title_info&&t.jsx("span",{style:{fontSize:"12px",color:i("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(et,{id:d.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),m&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${i("widget-border")}`},children:[o&&(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(rt,{label:l.label.titleInfo,children:c(d.title_info)}),d.author_info&&t.jsx(rt,{label:l.label.authorInfo,children:c(d.author_info)}),d.edition&&t.jsx(rt,{label:l.label.edition,children:c(d.edition)})]}),d.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${i("primary")}`,background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:i("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 ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:i("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 ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(d.additional_comment)})]})]})]},u)})})]})}function _c({items:e,onNavigate:n,renderLink:o}){const r=me();return t.jsx(us,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function xs({items:e,onNavigate:n,renderLink:o}){const r=me();return t.jsx(us,{items:e,label:r.section.emendated,onNavigate:n,renderLink:o})}function fs({label:e,items:n}){const{convert:o}=V();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(qe,{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:i("fg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:o(l)},s)})})]}):null}function zc({items:e}){const n=me();return t.jsx(fs,{label:n.section.aliases,items:e})}function Cc({items:e}){const n=me();return t.jsx(fs,{label:n.section.attachedTexts,items:e})}function Tc({items:e}){const n=me(),{convert:o}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(qe,{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:i("fg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:["《",o(r.book_title),"》",r.n_juan!=null&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function Ic({items:e}){const n=me(),{convert:o}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(qe,{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:i("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:i("primary"),border:`1.5px solid ${i("input-bg")}`}}),t.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:i("fg")},children:o(r.name)}),r.description&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),marginLeft:"8px"},children:o(r.description)})]},s))]})]}):null}function Ec({items:e}){const n=me(),{convert:o}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(qe,{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:i("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[t.jsx("span",{style:{position:"absolute",left:0,top:0,color:i("desc-fg")},children:"·"}),o(r)]},s))})]}):null}function Ho({title:e,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:l}=V(),[c,p]=f.useState([]);return f.useEffect(()=>{if(!n.length){p([]);return}if(!o){p(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>o.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,o]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(qe,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:i("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 ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),transition:"border-color 0.15s"},children:t.jsx(et,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function Un({book:e,onNavigate:n,renderLink:o}){const r=me(),{convert:s}=V(),[l,c]=f.useState(!1),p=e.resources&&e.resources.length>0,a=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:i("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${i("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(et,{id:e.id,label:a,onNavigate:n,renderLink:o})}),p&&t.jsx("span",{onClick:()=>c(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:i("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(Ci,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Rc({ids:e,workData:n,transport:o,onNavigate:r,renderLink:s,footer:l}){const c=me(),{convert:p}=V(),[a,d]=f.useState([]);if(f.useEffect(()=>{if(!e.length){d([]);return}if(!o){d(e.map(w=>({id:w})));return}let b=!1;return Promise.all(e.map(w=>o.getItem(w).then(y=>({id:w,title:y?y.title:void 0,edition:y?y.edition:void 0,resources:y?y.resources:void 0,resource_groups:y?y.resource_groups:void 0})).catch(()=>({id:w})))).then(w=>{b||d(w)}),()=>{b=!0}},[e,o]),!e.length)return null;const u=a.length?a:e.map(b=>({id:b})),m=new Map(u.map(b=>[b.id,b])),x=n==null?void 0:n.version_graph,g=Nc(e,x);return t.jsxs(t.Fragment,{children:[t.jsxs(qe,{children:[c.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,g.useGrouping?t.jsxs(t.Fragment,{children:[g.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:g.coreIds.map(b=>{const w=m.get(b);return w?t.jsx(Un,{book:w,onNavigate:r,renderLink:s},b):null})}),g.groupedIds.map(b=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${i("widget-border")}`,borderRadius:6,background:i("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:i("fg"),userSelect:"none"},children:[p(b.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:i("desc-fg"),fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:i("desc-fg"),fontWeight:400},children:p(b.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(w=>{const y=m.get(w);return y?t.jsx(Un,{book:y,onNavigate:r,renderLink:s},w):null})})]},b.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(b=>t.jsx(Un,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Nc(e,n){var y,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const o=(y=n.collections)==null?void 0:y[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.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=h=>{if(a.has(h))return!0;const v=n.node_groups[h];return v!=null&&p.has(v)},u=[],m=new Map,x=[];for(const h of e)if(!((j=n.excluded_books)!=null&&j.includes(h)))if(d(h))u.push(h);else{const v=n.node_groups[h];v?(m.has(v)||m.set(v,[]),m.get(v).push(h)):x.push(h)}if(x.length+[...m.values()].reduce((h,v)=>h+v.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(h=>[h.id,h])),w=[...m.entries()].map(([h,v])=>{const $=b.get(h);return{id:h,label:($==null?void 0:$.label)??h,description:$==null?void 0:$.description,ids:v}});return x.length>0&&w.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:w}}function Lc({workData:e,onNavigate:n,renderLink:o}){var c,p,a,d;const r=me(),{convert:s}=V(),l=!!((c=e.description)!=null&&c.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:i("input-bg"),marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?`1px solid ${i("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`},children:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:t.jsx(et,{id:e.id,label:s(e.title),onNavigate:n,renderLink:o})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:i("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:i("desc-fg")},children:[cs(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(ps,{authors:e.authors,type:"work",onNavigate:n,renderLink:o})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((a=e.description)==null?void 0:a.text)&&t.jsx(dt,{text:e.description.text,style:{fontSize:"13px",color:i("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(rt,{label:r.label.parentWork,children:t.jsx(et,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Bc({items:e,onNavigate:n,renderLink:o}){const r=me(),{convert:s}=V();return e.length?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(l=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid color-mix(in srgb, ${i("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${i("type-collection")} 3%, transparent)`},children:[t.jsx("span",{style:{fontSize:"11px",color:i("type-collection")},children:r.indexType.collection}),t.jsx(et,{id:l.id,label:s(l.title)||l.id,onNavigate:n,renderLink:o}),l.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"2px"},children:Qe(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Ei=({data:e,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:c,className:p,style:a})=>{var H,L,M,F,X,U,T,ce;const d=me(),{convert:u}=V(),[m,x]=f.useState(null),[g,b]=f.useState(!1),[w,y]=f.useState(null),[j,h]=f.useState(null),[v,$]=f.useState([]),k=e||m;if(f.useEffect(()=>{if(e||!n||!o)return;let B=!1;return b(!0),y(null),o.getItem(n).then(D=>{B||(D?x(D):y(d.misc.notFoundEntry))}).catch(D=>{B||y(D instanceof Error?D.message:d.misc.loadFailed)}).finally(()=>{B||b(!1)}),()=>{B=!0}},[e,n,o]),f.useEffect(()=>{if(!k||!o){h(null),$([]);return}let B=!1;const D=k.type==="book"||k.type==="collection"?k.work_id:void 0;if(D?o.getItem(D).then(A=>{!B&&A&&A.type==="work"&&h(A)}).catch(()=>{}):h(null),k.type==="book"){const A=k;A.contained_in&&A.contained_in.length>0?Promise.all(A.contained_in.map(ee=>{const de=typeof ee=="string"?ee:ee.id,G=typeof ee=="string"?void 0:ee.volume_index;return o.getItem(de).then(q=>({id:de,title:q&&q.title||de,volume_index:G})).catch(()=>({id:de,title:de,volume_index:G}))})).then(ee=>{B||$(ee)}):$([])}else $([]);return()=>{B=!0}},[k,o]),g)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((B,D)=>t.jsx("div",{style:{height:D===1?"32px":"16px",width:`${B}px`,background:i("widget-border"),borderRadius:"4px",opacity:.4}},D))})});if(w)return t.jsx("div",{className:p,style:{...a,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:w});if(!k)return null;if(k.type==="entity")return t.jsx("div",{className:p,style:a,children:t.jsx(ls,{data:k,transport:o,onNavigate:r,renderLink:s,headerExtra:l})});const _=k.type==="book"?k:null,S=k.type==="collection"?k:null,z=k.type==="work"?k:null;let N=!1;try{N=$e.extractStatus(k.id)==="draft"}catch{}let R="";k.measure_info?R=u(k.measure_info):(H=k.juan_count)!=null&&H.number?R=cs(k.juan_count.number)+d.unit.juan:(L=k.juan_count)!=null&&L.description&&(R=u(k.juan_count.description));const C=[];return(M=k.publication_info)!=null&&M.year&&C.push(t.jsx(rt,{label:d.label.year,children:k.publication_info.year},"year")),(F=k.current_location)!=null&&F.name&&C.push(t.jsx(rt,{label:d.label.currentLocation,children:u(k.current_location.name)},"loc")),(X=k.page_count)!=null&&X.description&&C.push(t.jsx(rt,{label:d.label.pageCount,children:k.page_count.description},"page")),_!=null&&_.edition&&C.push(t.jsx(rt,{label:d.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&C.push(t.jsx(rt,{label:d.label.parentWork,children:t.jsx(et,{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(rt,{label:d.label.parentWork,children:z.parent_works.map((B,D)=>t.jsxs("span",{children:[D>0&&"、",t.jsx(et,{id:B,onNavigate:r,renderLink:s})]},B))},"pws")),t.jsxs("div",{className:p,style:a,children:[t.jsx($c,{id:k.id,title:u(k.title),edition:k.edition?u(k.edition):void 0,type:k.type,isDraft:N,authors:k.authors,volumeText:R,meta:C,headerExtra:l,onNavigate:r,renderLink:s}),((U=k.description)==null?void 0:U.text)&&t.jsx(dt,{text:k.description.text,style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),k.appendix&&k.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:k.appendix.map((B,D)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:i("bg-subtle"),borderRadius:4,border:`1px solid ${i("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:i("muted")},children:u(B.title)}),t.jsx(dt,{text:B.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:i("fg")}})]},D))}),v.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(qe,{children:d.section.containedIn}),t.jsx(Bc,{items:v,onNavigate:r,renderLink:s})]}),j&&t.jsxs(t.Fragment,{children:[t.jsx(qe,{children:d.section.belongsToWork}),t.jsx(Lc,{workData:j,onNavigate:r,renderLink:s})]}),k.additional_works&&k.additional_works.length>0&&t.jsx(Tc,{items:k.additional_works}),k.additional_titles&&k.additional_titles.length>0&&t.jsx(zc,{items:k.additional_titles}),k.attached_texts&&k.attached_texts.length>0&&t.jsx(Cc,{items:k.attached_texts}),k.indexed_by&&k.indexed_by.length>0&&t.jsx(_c,{items:k.indexed_by,onNavigate:r,renderLink:s}),k.emendated_by&&k.emendated_by.length>0&&t.jsx(xs,{items:k.emendated_by,onNavigate:r,renderLink:s}),k.resources&&k.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(qe,{children:d.section.resources}),t.jsx(Ci,{items:k.resources,resourceGroups:k.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&t.jsx(Ic,{items:_.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&t.jsx(Ec,{items:S.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&t.jsx(Ho,{title:d.section.relatedVersions,ids:_.related_books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&t.jsx(Ho,{title:d.section.containedBooks,ids:S.books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(qe,{children:[d.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",S.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(B=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:t.jsx(et,{id:B.id,label:u(B.title),onNavigate:r,renderLink:s})},B.id))})]}),(((T=z==null?void 0:z.books)==null?void 0:T.length)||0)+(((ce=z==null?void 0:z.collections)==null?void 0:ce.length)||0)>0&&t.jsx(Rc,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z??void 0,transport:o,onNavigate:r,renderLink:s,footer:c}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const B=[],D=z.related_works.filter(ie=>ie.relation==="part_of"),A=z.related_works.filter(ie=>ie.relation==="has_part"),ee=z.related_works.filter(ie=>ie.relation==="has_adaptation"),de=z.related_works.filter(ie=>ie.relation==="text_carried_by"),G=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),q=z.related_works.filter(ie=>!ie.relation||!G.has(ie.relation));return D.length>0&&B.push({label:d.section.belongsToWork,items:D}),A.length>0&&B.push({label:d.section.containedWorks,items:A}),ee.length>0&&B.push({label:d.section.adaptations,items:ee}),de.length>0&&B.push({label:d.section.derivativeWorks,items:de}),q.length>0&&B.push({label:d.section.relatedWorks,items:q}),B.map(ie=>t.jsxs("div",{children:[t.jsxs(qe,{children:[ie.label,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",ie.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:ie.items.map(pe=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:t.jsx(et,{id:pe.id,label:u(pe.title),onNavigate:r,renderLink:s})},pe.id))})]},ie.label))})()]})};function Ac({data:e}){const n=me(),{convert:o}=V(),{stats:r}=e,s=r.processed_volumes??r.total_found_volumes,l=s!=null&&e.total_volumes>0?Math.round(s/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:o(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"6px"},children:o(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:i("desc-fg")},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:i("fg")},children:e.total_volumes})," ",n.unit.volume]}),l!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:i("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:i("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:i("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:i("missing-fg")},children:r.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:i("desc-fg")},children:[n.catalog.source," ",e.source]})]})}function Wc({sections:e,activeSection:n,onSelect:o}){const r=me();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>o(null),style:Go(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>o(s.name),style:Go(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 Go(e){return{padding:"4px 12px",border:e?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${i("primary")} 8%, transparent)`:"transparent",color:i(e?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Mc({id:e,label:n,onNavigate:o,renderLink:r}){const s=Fe();return r?t.jsx(t.Fragment,{children:r(e,n)}):o?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(e))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("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:i("desc-fg")},children:n||e})}function Fc(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const o=e[0],r=e[e.length-1];return r-o+1===e.length?`${o}–${r}`:e.length<=3?e.join(", "):`${o}–${r} (${e.length}${n})`}function Uo({book:e,onNavigate:n,renderLink:o,showVolumes:r}){const s=me(),{convert:l}=V(),c=e.book_id||e.work_id,p=r&&e.volumes.length>0?Fc(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 ${i("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:i("desc-fg"),textAlign:"right"},children:p}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:i("fg")},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(d=>l(d)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:i(a?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),c&&t.jsx(Mc,{id:c,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!c&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const Ri=({data:e,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:l,style:c})=>{const p=me(),[a,d]=f.useState(null),[u,m]=f.useState(!1),[x,g]=f.useState(null),[b,w]=f.useState(null),[y,j]=f.useState(""),h=e||a;f.useEffect(()=>{if(e||!n||!(o!=null&&o.getCollectionCatalog))return;let S=!1;return m(!0),g(null),o.getCollectionCatalog(n).then(z=>{S||(z?d(z):g(p.catalog.notFound))}).catch(z=>{S||g(z instanceof Error?z.message:p.catalog.loadFailed)}).finally(()=>{S||m(!1)}),()=>{S=!0}},[e,n,o,p]);const v=(h==null?void 0:h.sections)&&h.sections.length>0,$=f.useMemo(()=>{if(!h)return!1;if(h.volume_index&&Object.keys(h.volume_index).length>0)return!0;const S=h.books.map(N=>N.volumes[0]).filter(N=>N!=null);return new Set(S).size<S.length},[h]),k=f.useMemo(()=>{if(!h)return[];let S=h.books;if(b&&(S=S.filter(z=>z.section===b)),y.trim()){const z=y.trim().toLowerCase();S=S.filter(N=>N.title.toLowerCase().includes(z)||N.sub_items&&N.sub_items.some(R=>R.toLowerCase().includes(z))||N.edition&&N.edition.toLowerCase().includes(z))}return S},[h,b,y]),_=f.useMemo(()=>{if(!$)return null;const S=[],z=new Map;for(const R of k){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 N=[...z.keys()].sort((R,C)=>R-C);for(const R of N)S.push({volume:R,books:z.get(R)});return S},[k,$]);return u?t.jsx("div",{className:l,style:{...c,padding:"24px"},children:t.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):x?t.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:x}):h?t.jsxs("div",{className:l,style:c,children:[t.jsx(Ac,{data:h}),v&&t.jsx(Wc,{sections:h.sections,activeSection:b,onSelect:w}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:y,onChange:S=>j(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:i("desc-fg")},children:[k.length," ",p.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[_?_.map((S,z)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:i("bg"),borderBottom:`1px solid ${i("widget-border")}`,fontSize:"12px",fontWeight:600,color:i("desc-fg"),position:"sticky",top:0,zIndex:1},children:Qe(p.catalog.volume,{n:S.volume})}),S.books.map((N,R)=>t.jsx(Uo,{book:N,onNavigate:r,renderLink:s,showVolumes:N.volumes.length>1},`${S.volume}-${R}`))]},`${S.volume}-${z}`)):k.map((S,z)=>t.jsx(Uo,{book:S,onNavigate:r,renderLink:s,showVolumes:!0},z)),k.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},kt=()=>{const[e,n]=f.useState(1);return f.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:i("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(e)})},ms=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Pc={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Oe(e){return Pc[e]??e}const Et=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],Rt={熹平: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},gs={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function In(e){const n=e.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const o=parseInt(n[1],10);if(o<100||o>2100)return;const r=n[2]?parseInt(n[2],10):void 0;return{from:o,to:r!=null&&r>=o&&r<=2100?r:void 0}}function Oc(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 Dc=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Vo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Ni(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(Vo))if(n.startsWith(s))return Vo[s];const o=Oe(n);if(ht[o]!=null)return o;const r=ct(n);if(r&&n.length<=r.length+1)return Oe(r)}function gt(e,n){if(n){const o=gs[`${n}|${e}`];if(o!=null)return o}return Rt[e]}const Hc=1911;function Gc(e){const n=Rt[e];if(n==null)return;const o=st[e];let r;for(const[s,l]of Object.entries(Rt))st[s]===o&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const Uc={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function jn(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,o=0,r=!1;for(const l of e){const c=Uc[l];if(c===void 0)return;r=!0,l==="十"?o=(o||1)*10:l==="廿"||l==="卅"?(n+=c,o=0):o>=10?(n+=o+c,o=0):o=o*10+c}const s=n+o;return r&&s>0?s:void 0}function ct(e){for(const n of ms)if(e.startsWith(n))return n}const st={};{const e=(n,o)=>{for(const r of o)st[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function bt(e,n){const o=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(Rt))if(e.includes(r)&&!(o&&st[r]&&st[r]!==o&&gs[`${o}|${r}`]==null))return r}function tn(e){var c,p,a;const n={era:"",reign:"",source:"none"},o=e.dating;if(o!=null&&o.era||o!=null&&o.reign)return{era:o.era??"",reign:o.reign??"",source:o.certainty==="attested"?"catalog":"edition"};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const d=ct(r)??"";return{era:Oe(d),reign:bt(r,d)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const d=In(s);if(d)return{era:Oc(d.from),reign:"",source:"publication"};const u=ct(s)??Ni(s)??((a=Et.find(g=>g.pattern.test(s)))==null?void 0:a.era)??"",m=bt(s,u)??"",x=u||(m?st[m]??"":"");if(x||m)return{era:Oe(x),reign:m,source:"publication"}}const l=e.edition||e.title||"";if(l){const d=ct(l);if(d)return{era:Oe(d),reign:bt(l,d)??"",source:"edition"};const u=Et.find(m=>m.pattern.test(l));if(u)return{era:Oe(u.era),reign:bt(l,u.era)??u.reign??"",source:"edition"}}return n}function En(e){var r,s,l,c,p,a,d,u,m;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=In(n);if(x)return x.from}const o=[(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 o){const g=((a=e.publication_info)==null?void 0:a.year)||((d=e.lineage)==null?void 0:d.year_text);if(g&&x!==g&&(ct(g)||Ni(g)))break;const b=x.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??x.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const v=parseInt(b[1],10);if(v>=100&&v<=2100)return v}const w=x.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(w){const v=ct(x);if(!v||Oe(v)==="民國"){const k=jn(w[1]);if(k!=null&&k>=1&&k<=120)return Hc+k}}const y=ct(x)??((u=Et.find(v=>v.pattern.test(x)))==null?void 0:u.era),j=y?Oe(y):void 0,h=bt(x,j)??(ct(x)||(m=Et.find(v=>v.pattern.test(x)))==null?void 0:m.reign);if(h){const v=gt(h,j);if(v==null)continue;const $=x.indexOf(h),k=$>=0?x.slice($+h.length):"",_=k.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??k.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=_?jn(_[1]):void 0;return v+(S?S-1:0)}}}function Li(e){var c,p,a,d,u,m;const n=(c=e.dating)==null?void 0:c.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const o=(p=e.lineage)==null?void 0:p.year_range;if(o&&o.length===2)return{from:o[0],to:o[1]};const r=(a=e.lineage)==null?void 0:a.year_text;if(r){const x=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(x){const g=oi[Oe(x[1])],b=ht[Oe(x[2])];if(g!=null&&b!=null)return{from:Math.min(g,b)-20,to:Math.max(g,b)+40}}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const x=In(s);if((x==null?void 0:x.to)!=null)return{from:x.from,to:x.to};const g=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const b=oi[Oe(g[1])],w=ht[Oe(g[2])];if(b!=null&&w!=null)return{from:Math.min(b,w)-20,to:Math.max(b,w)+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 g=ct(x)??Ni(x)??((m=Et.find(y=>y.pattern.test(x)))==null?void 0:m.era),b=g?Oe(g):void 0,w=[];for(const y of Object.keys(Rt))x.includes(y)&&(b&&st[y]&&st[y]!==b||gt(y,b)!=null&&w.push(y));if(w.length===0){const y=x.match(/([一-鿿])([一-鿿])[間间]/);if(y&&b){for(const j of[y[1],y[2]])for(const h of Object.keys(Rt))if(st[h]===b&&!(h[0]!==j&&h[h.length-1]!==j)&&gt(h,b)!=null){w.push(h);break}}}if(w.length>0){const y=w.map($=>gt($,b)).filter($=>$!=null),j=Math.min(...y),h=w.reduce(($,k)=>gt($,b)>=gt(k,b)?$:k),v=Gc(h)??Vn(b??"")??Math.max(...y);return{from:j,to:v>j?v:Vn(b??st[h]??"")??j}}if(b&&ht[b]!=null)return{from:ht[b],to:Vn(b)??ht[b]}}}const ht={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Vc=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Yc=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,Yo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Ko(e,n){for(const o of ms){const r=e.indexOf(o);if(r<0)continue;if(o.length===1){const a=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(a)&&!bt(e.slice(r),Oe(o)))continue}const s=Oe(o);if(s===n)continue;const l=e.slice(r),c=bt(l,s)??"";let p;if(c){const a=gt(c,s);if(a!=null){const u=l.slice(l.indexOf(c)+c.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),m=u?jn(u[1]):void 0;p=a+(m?m-1:0)}}return{era:s,reign:c,year:p}}for(const o of Et)if(o.pattern.test(e))return{era:Oe(o.era),reign:o.reign??""}}function Kc(e){var j,h,v,$,k;const n=tn(e),o=((j=e.publication_info)==null?void 0:j.year)??"",r=o?In(o):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),c=((h=e.lineage)==null?void 0:h.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(c),a=n.source==="publication"&&Dc.test(o),d=n.source==="publication"&&/[間间]/.test(o),u=c.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let m;l||p||a||d?m=void 0:u?m=parseInt(u[2],10):m=En(e);const x=m==null?Li(e):void 0;let g;n.source==="publication"&&(a||Yo.test(o))?g="uncertain":n.source==="lineage"||n.source==="publication"?g="attested":Yo.test(s)||!n.reign&&m==null?g="uncertain":g="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((v=e.lineage)==null?void 0:v.year_text)??(($=e.lineage)==null?void 0:$.year)??""}」`:`出版著錄「${((k=e.publication_info)==null?void 0:k.year)??""}」`,w={era:n.era,reign:n.reign,year:m,yearRange:x,certainty:g,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const _=c.match(/[、,,]\s*([宋元明清])/);_&&_[1]!==w.era&&(w.laterRepair={era:_[1]})}if(!w.laterRepair&&Yc.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(w.laterRepair={era:_[1]})}const y=Vc.find(_=>_.re.test(s));if(y){const _=s.search(y.re),S=s.slice(_),z=Ko(S,n.era)??Ko(s,n.era);z&&(w.basedOn={era:z.era,reign:z.reign,year:z.year,relation:y.relation})}return w}const oi={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Vn(e){return oi[e]}function vn(e){const n=En(e);if(n!=null)return n;const o=Li(e);if(o)return o.from;const r=tn(e).era;return r?ht[r]:void 0}const qo=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function ri(e){const n=qo.indexOf(e);return n===-1?qo.length:n}function qc(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 o=[],r=(s,l)=>{n[s].length&&o.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"),o}function Bi(e,n){const o=$i(e||[]),r=new Map,s=[];for(const d of o)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,m)=>{const x=g=>g.group_role==="origin"?0:g.group_role==="mirror"?1:2;return x(u)-x(m)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=vt(d),m=u.includes("text"),x=u.includes("image");m&&x?l.textImage.push(d):m?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 m,x;return{key:d,label:((m=n==null?void 0:n[d])==null?void 0:m.label)||d,description:(x=n==null?void 0:n[d])==null?void 0:x.description,items:u}});return{buckets:p,mirrors:a,total:o.length}}function Rn(e){const n=[],o=e.metadata||{};o.edition&&n.push(String(o.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const r=Sn(e);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),o.version&&n.push(String(o.version)),n.join(" · ")}function hs(e,n){if(Rn(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 bs(e,n){var l,c;const o=e.resources||[],r=[],s=[];for(const p of o){const a=vt(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:tn(e),year:En(e),sortYear:vn(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:Jc(e.id,n),group:(c=n==null?void 0:n.node_groups)==null?void 0:c[e.id],hasImage:r.length>0}}function Jc(e,n){var p,a;if(!n)return!1;const o=n.default_collection;if(!o)return!1;const r=(p=n.collections)==null?void 0:p[o];if(((r==null?void 0:r.book_ids)??(o==="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 ys(e,n,o={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(a=>!r.has(a.id)).map(a=>bs(a,n));let l=s;o.era&&(l=l.filter(a=>a.era.era===o.era)),o.scanOnly&&(l=l.filter(a=>a.hasImage)),o.sort==="year"?l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=a.r.sortYear,m=d.r.sortYear;return u!=null&&m!=null?u-m||a.i-d.i:u!=null?-1:m!=null?1:a.i-d.i}).map(a=>a.r):l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=m=>(m.important?0:1)*2+(m.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)=>ri(a)-ri(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(a=>a.era.source==="edition")}}function Zc(e,n){var y,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const o=(y=n.collections)==null?void 0:y[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.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=h=>{if(a.has(h))return!0;const v=n.node_groups[h];return v!=null&&p.has(v)},u=[],m=new Map,x=[];for(const h of e)if(!((j=n.excluded_books)!=null&&j.includes(h)))if(d(h))u.push(h);else{const v=n.node_groups[h];v?(m.has(v)||m.set(v,[]),m.get(v).push(h)):x.push(h)}if(x.length+[...m.values()].reduce((h,v)=>h+v.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(h=>[h.id,h])),w=[...m.entries()].map(([h,v])=>{const $=b.get(h);return{id:h,label:($==null?void 0:$.label)??h,description:$==null?void 0:$.description,ids:v}});return x.length>0&&w.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:w}}const js=["撰","編","注","校","譯","繪","其他"],Xc=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function Ai(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:o,re:r}of Xc)if(r.test(n))return o;return"其他"}function Wi(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function vs(e){const n=new Map;for(const r of e){const s=Ai(r);n.set(s,(n.get(s)??0)+1)}const o=[{cls:"全部",label:"全部",count:e.length}];for(const r of js){const s=n.get(r);s&&o.push({cls:r,label:r,count:s})}return o.length>2?o:[]}function ks(e,n,o){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:Jt(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,c;return{id:s,title:((l=o==null?void 0:o.get(s))==null?void 0:l.title)||s,edition:(c=o==null?void 0:o.get(s))==null?void 0:c.edition,volumes:[]}}),source:"books",sections:[]}}function Jt(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[o,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-o+1)},(s,l)=>o+l)}return e.split(/[,、]/).map(o=>parseInt(o.trim())).filter(o=>!isNaN(o))}return[]}function Nn(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const o=[...e].sort((l,c)=>l-c),r=o[0],s=o[o.length-1];return s-r+1===o.length?`${r}–${s}`:o.length<=3?o.join(", "):`${r}–${s} (${o.length}${n})`}const Qc=["〇","一","二","三","四","五","六","七","八","九"],Jo=["","十","百","千"];function ws(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),o=n.length;let r="",s=!1;for(let l=0;l<o;l++){const c=parseInt(n[l]),p=o-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=Jo[p]:r+=Qc[c]+Jo[p])}return r}function ed(e){return e==null?"":typeof e=="string"?e:e.title??""}function pt(e,n="卷"){var r,s;const o=e;return o.measure_info?o.measure_info:(r=o.juan_count)!=null&&r.number?ws(o.juan_count.number)+n:(s=o.juan_count)!=null&&s.description?o.juan_count.description:""}function Ss(e){var r;if(e.edition_type)return e.edition_type;if((r=e.lineage)!=null&&r.category)return e.lineage.category;const n=e.edition||e.title||"",o=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,l]of o)if(s.test(n))return l;return""}const td="guji_markdown";function si(e){const n=e==null?void 0:e.guji_markdown;if(typeof n!="string")return!1;const o=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!o)return!1;const r=parseInt(o[1],10),s=parseInt(o[2],10);return r>0||s>=2}const nd=/^□\{guess=([^\s{}]+)\}/;function id(e,n){const o=e[n+1];return o!==void 0&&!/[A-Za-z/!?>\s]/.test(o)}function $s(e,n){let o=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
131
+ `)return-1;if(s==="\\"){r++;continue}if(s==="[")o++;else if(s==="]"&&(o--,o===0))return r}return-1}function od(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function rd(e,n){const o=e[n];if(o==="["&&e[n+1]==="["){const r=e.indexOf("]]",n+2);return r>=0&&e.slice(n+2,r).indexOf(`
132
+ `)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(o===":"&&e.startsWith(":zi[",n)){const r=$s(e,n+3);return r>n+4?{node:{type:"zi",label:od(e.slice(n+4,r))},end:r+1}:null}if(o==="□"&&e[n+1]==="{"){const r=nd.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function _s(e,n,o,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(o!==null){if(p===o)return c(),{nodes:s,end:n};if(p===`
133
+ `)return null}const a=rd(e,n);if(a){c(),s.push(a.node),n=a.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&id(e,n)&&(d=">"),d){const u=_s(e,n+1,d,!0);if(u){c(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return o!==null?null:(c(),{nodes:s,end:n})}function zs(e){return _s(e,0,null,!1).nodes}function sd(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function Cs(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Cs(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const ld=216,Zo="clamp(280px, 23vw, 360px)",ad=1440,li="(max-width: 719px)",cd=`${li}, (pointer: coarse)`,dd=`
134
+ .bim-d-main.bim-d-main-grid { max-width: ${ad}px; padding: 16px 32px 0; }
16
135
  .bim-d-grid {
17
136
  display: grid;
18
- grid-template-columns: ${hc}px minmax(0, 1fr) ${Eo};
137
+ grid-template-columns: ${ld}px minmax(0, 1fr) ${Zo};
19
138
  grid-template-rows: auto 1fr;
20
139
  grid-template-areas: "rail main card" "rail main side";
21
140
  column-gap: 32px; row-gap: 28px; align-items: start;
@@ -340,7 +459,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
340
459
  .bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
341
460
 
342
461
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
343
- @media ${yc} {
462
+ @media ${cd} {
344
463
  .bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
345
464
  .bim-d-card-foot summary, .bim-d-card-toggle, .bim-d-card details.bim-d-more-names summary,
346
465
  .bim-d-tl summary, .bim-d-chap a { min-height: 44px; }
@@ -378,7 +497,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
378
497
  /* 中等宽度:左栏折到顶部一行 */
379
498
  @media (max-width: 1100px) {
380
499
  .bim-d-grid {
381
- grid-template-columns: minmax(0, 1fr) ${Eo};
500
+ grid-template-columns: minmax(0, 1fr) ${Zo};
382
501
  grid-template-rows: auto auto 1fr;
383
502
  grid-template-areas: "rail rail" "main card" "main side";
384
503
  }
@@ -392,7 +511,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
392
511
  }
393
512
 
394
513
  /* 手机:左栏收起,提要卡 → 正文 → 旁栏 */
395
- @media ${Zn} {
514
+ @media ${li} {
396
515
  .bim-d-main.bim-d-main-grid { padding: 8px 16px 0; }
397
516
  .bim-d-grid {
398
517
  grid-template-columns: minmax(0, 1fr);
@@ -454,7 +573,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
454
573
  :root[data-layout="boxed"] .bim-d-g-rail { border: ${i("fr-bd")}; background: ${i("fr-bg")}; padding: 14px 8px; }
455
574
  :root[data-layout="boxed"] .bim-d-filters { border-bottom: 1px solid ${i("fr-tab-bd")}; }
456
575
  :root[data-layout="boxed"] .bim-d-filters .bim-d-tab { margin-bottom: -1px; }
457
- @media ${Zn} {
576
+ @media ${li} {
458
577
  :root[data-layout="boxed"] .bim-d-card { padding: 16px; }
459
578
  :root[data-layout="boxed"] .bim-d-g-rail { border: 0; background: transparent; padding: 0; }
460
579
  }
@@ -469,7 +588,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
469
588
  :root[data-theme="ink"] :is(.bim-d-zt, .bim-d-side li, .bim-d-card-desc, .bim-d-desc, .bim-d-lf-card) a:hover {
470
589
  text-decoration-color: currentColor; text-decoration-thickness: 2px;
471
590
  }
472
- `;function Xt({railTop:e,back:n,up:o,nav:r,railLinks:s,main:l,card:d,side:p}){const{convert:c}=Z(),a=(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}),o,a.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":c("本頁導航"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:c("本頁")}),t.jsx("ul",{className:"bim-d-rail-nav",children:a.map(u=>t.jsx("li",{children:t.jsxs("a",{href:`#${u.id}`,children:[t.jsx("span",{children:c(u.label)}),u.count!=null&&t.jsx("span",{className:"bim-d-meta",children:u.count})]})},u.id))})]}),s&&s.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("更多"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:c("更多")}),t.jsx("ul",{className:"bim-d-rail-nav",children:s.map(u=>t.jsx("li",{children:t.jsxs("a",{href:u.href??"#",onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),u.onClick())},children:[t.jsx("span",{children:c(u.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},u.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:l}),t.jsx("div",{className:"bim-d-g-card",children:d}),t.jsx("div",{className:"bim-d-g-side",children:p})]})}function ns({caption:e,children:n}){const{convert:o}=Z();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:o(e)}),n]})}function Fe({id:e,title:n,meta:o,action:r,children:s}){const{convert:l}=Z();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)}),o!=null&&o!==""&&t.jsx("span",{className:"bim-d-meta",children:o}),r&&t.jsx("span",{className:"bim-d-sec-act",children:r})]}),t.jsx("div",{className:"bim-d-sec-body",children:s})]})}function Me({items:e,className:n,style:o}){const r=e.filter(s=>s!=null&&s!==""&&s!==!1);return r.length?t.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:o,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 $n({items:e,value:n,onChange:o}){const{convert:r}=Z();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:()=>o(s.key),children:r(s.label)},s.key))})}function is({label:e,checked:n,onChange:o}){const{convert:r}=Z();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:s=>o(s.target.checked)}),r(e)]})}function Bt({label:e,onClick:n}){const{convert:o}=Z();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:o(e)})}function Qt({kind:e,title:n,subtitle:o,byline:r,meta:s,description:l,clampDescription:d,facts:p,stats:c,readAction:a,secondaryAction:u,children:f,foot:x}){const{convert:m}=Z(),j=(p||[]).filter(k=>k.value!=null&&k.value!==""),w=(c||[]).filter(k=>k.value!=null&&k.value!==""&&k.value!==0),[h,b]=g.useState(!1),y=!!d&&!h;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:m(e)}),t.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),o&&t.jsx("div",{className:"bim-d-card-sub",children:o}),r&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:r}),s&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),l&&t.jsx("div",{className:y?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:y?{"--detail-clamp":d}:void 0,children:l}),l&&!!d&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":h,onClick:()=>b(k=>!k),children:m(h?"收起":"展開")}),w.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:w.map((k,$)=>t.jsxs("div",{children:[t.jsx("b",{children:k.value}),t.jsx("span",{children:m(k.label)})]},$))}),j.length>0&&t.jsx("dl",{className:"bim-d-ui",children:j.map((k,$)=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:m(k.label)}),t.jsx("dd",{title:k.title,children:k.value})]},$))}),f,a,u,x&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:x})]})}function _i(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function Xn({href:e,onClick:n,label:o="閱讀全文"}){const{convert:r}=Z();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(o)}):t.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:r(o)})}function ht({id:e,title:n,meta:o,items:r,metas:s,currentIndex:l,cap:d=8,moreLabel:p,foot:c,sub:a,timeline:u}){const{convert:f}=Z(),[x,m]=g.useState(!1);if(!r.length)return null;const j=x?r:r.slice(0,d),w=r.length-j.length;return t.jsxs("div",{id:e,className:u?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[f(n),o!=null&&o!==""&&t.jsx("span",{className:"bim-d-meta",children:o})]}),a&&t.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:a}),t.jsx("ul",{children:j.map((h,b)=>t.jsxs("li",{className:b===l?"bim-d-side-cur":void 0,"aria-current":b===l?"page":void 0,children:[h,s!=null&&s[b]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[b]}):null]},b))}),w>0&&t.jsx(Bt,{label:p?p(w):`顯示更多(${w})`,onClick:()=>m(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const vc={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function en({revision:e,revisedAt:n,review:o,todo:r}){const{convert:s}=Z(),l=o?vc[o.status]:void 0,d=o&&o.status!=="unreviewed"&&l?[l,o.by,o.date].filter(Boolean).join(" "):"",p=[e!=null&&e!==""?`${s("數據版本")} ${e}`:"",n??"",s(d)].filter(Boolean),c=(r||[]).filter(a=>a&&a.what);return!p.length&&!c.length?null:t.jsxs(t.Fragment,{children:[p.length>0&&t.jsx(Me,{items:p,style:{fontSize:12}}),c.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s(`待核 ${c.length} 項`)}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:c.map((a,u)=>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(" · "),")"]})]},u))})]})]})}const un=1e3,Ro=208,kc=1440,wc="(max-width: 719px)",os=`
591
+ `;function nn({railTop:e,back:n,up:o,nav:r,railLinks:s,main:l,card:c,side:p}){const{convert:a}=V(),d=(r||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,n&&t.jsx("div",{style:{marginTop:e?12:0},children:n}),o,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:m=>{m.metaKey||m.ctrlKey||(m.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 Ts({caption:e,children:n}){const{convert:o}=V();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:o(e)}),n]})}function He({id:e,title:n,meta:o,action:r,children:s}){const{convert:l}=V();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:l(n)}),o!=null&&o!==""&&t.jsx("span",{className:"bim-d-meta",children:o}),r&&t.jsx("span",{className:"bim-d-sec-act",children:r})]}),t.jsx("div",{className:"bim-d-sec-body",children:s})]})}function De({items:e,className:n,style:o}){const r=e.filter(s=>s!=null&&s!==""&&s!==!1);return r.length?t.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:o,children:r.map((s,l)=>t.jsxs(f.Fragment,{children:[l>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},l))}):null}function Ln({items:e,value:n,onChange:o}){const{convert:r}=V();return t.jsx(t.Fragment,{children:e.map(s=>t.jsx("button",{type:"button",className:[...r(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>o(s.key),children:r(s.label)},s.key))})}function Is({label:e,checked:n,onChange:o}){const{convert:r}=V();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:s=>o(s.target.checked)}),r(e)]})}function Mt({label:e,onClick:n}){const{convert:o}=V();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:o(e)})}function on({kind:e,title:n,subtitle:o,byline:r,meta:s,description:l,clampDescription:c,facts:p,stats:a,readAction:d,secondaryAction:u,children:m,foot:x}){const{convert:g}=V(),b=(p||[]).filter(v=>v.value!=null&&v.value!==""),w=(a||[]).filter(v=>v.value!=null&&v.value!==""&&v.value!==0),[y,j]=f.useState(!1),h=!!c&&!y;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:g(e)}),t.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),o&&t.jsx("div",{className:"bim-d-card-sub",children:o}),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:h?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:h?{"--detail-clamp":c}:void 0,children:l}),l&&!!c&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":y,onClick:()=>j(v=>!v),children:g(y?"收起":"展開")}),w.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:w.map((v,$)=>t.jsxs("div",{children:[t.jsx("b",{children:v.value}),t.jsx("span",{children:g(v.label)})]},$))}),b.length>0&&t.jsx("dl",{className:"bim-d-ui",children:b.map((v,$)=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:g(v.label)}),t.jsx("dd",{title:v.title,children:v.value})]},$))}),m,d,u,x&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:x})]})}function Mi(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function ai({href:e,onClick:n,label:o="閱讀全文"}){const{convert:r}=V();return e?t.jsx("a",{className:"bim-d-btn",href:e,onClick:n?s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),n())}:void 0,children:r(o)}):t.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:r(o)})}function yt({id:e,title:n,meta:o,items:r,metas:s,currentIndex:l,cap:c=8,moreLabel:p,foot:a,sub:d,timeline:u}){const{convert:m}=V(),[x,g]=f.useState(!1);if(!r.length)return null;const b=x?r:r.slice(0,c),w=r.length-b.length;return t.jsxs("div",{id:e,className:u?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[m(n),o!=null&&o!==""&&t.jsx("span",{className:"bim-d-meta",children:o})]}),d&&t.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:d}),t.jsx("ul",{children:b.map((y,j)=>t.jsxs("li",{className:j===l?"bim-d-side-cur":void 0,"aria-current":j===l?"page":void 0,children:[y,s!=null&&s[j]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[j]}):null]},j))}),w>0&&t.jsx(Mt,{label:p?p(w):`顯示更多(${w})`,onClick:()=>g(!0)}),a&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:a})]})}const pd={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function rn({revision:e,revisedAt:n,review:o,todo:r}){const{convert:s}=V(),l=o?pd[o.status]:void 0,c=o&&o.status!=="unreviewed"&&l?[l,o.by,o.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(De,{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 gn=1e3,Xo=208,ud=1440,xd="(max-width: 719px)",Es=`
473
592
  .bim-d-page {
474
593
  background: ${i("page-bg")};
475
594
  color: ${i("ink")};
@@ -478,7 +597,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
478
597
  padding-bottom: 64px;
479
598
  }
480
599
  .bim-d-main {
481
- max-width: ${un}px;
600
+ max-width: ${gn}px;
482
601
  margin: 0 auto;
483
602
  padding: 24px clamp(16px, 4vw, 28px) 0;
484
603
  }
@@ -489,7 +608,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
489
608
  * PAGE_MAX_WIDTH,读者的行宽体验不变。
490
609
  */
491
610
  .bim-d-main.bim-d-main-wide {
492
- max-width: ${kc}px;
611
+ max-width: ${ud}px;
493
612
  }
494
613
  .bim-d-ui { font-family: var(--bim-font-ui, system-ui, sans-serif); }
495
614
 
@@ -521,9 +640,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
521
640
  */
522
641
  .bim-d-reader {
523
642
  display: grid;
524
- grid-template-columns: ${Ro}px minmax(0, ${un}px);
643
+ grid-template-columns: ${Xo}px minmax(0, ${gn}px);
525
644
  gap: 32px;
526
- max-width: ${Ro+un+32}px;
645
+ max-width: ${Xo+gn+32}px;
527
646
  margin: 0 auto;
528
647
  align-items: start;
529
648
  }
@@ -546,7 +665,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
546
665
  align-items: start; margin-bottom: 48px; }
547
666
  .bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
548
667
 
549
- @media ${wc} {
668
+ @media ${xd} {
550
669
  .bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
551
670
  .bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
552
671
  /* 表格:meta 列折到第二行,表头隐藏 */
@@ -564,14 +683,14 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
564
683
  padding-right: 0; padding-bottom: 12px;
565
684
  }
566
685
  }
567
- ${jc}`;function Ht({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:os}),t.jsx("div",{className:r?"bim-d-main bim-d-main-grid":o?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function Qn({breadcrumb:e,actions:n}){return t.jsxs("div",{className:"bim-d-ui bim-d-top",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:i("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 $i({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:i(n==="accent"?"accent":"ink"),color:i("page-bg")},children:e})}function ei({items:e}){const n=Pe();return t.jsx(t.Fragment,{children:e.map((o,r)=>{const s=r===e.length-1,l=r>0&&t.jsx("span",{style:{color:i("hint-fg")},children:"/"},`s${r}`),d=o.id?n(o.id):o.href,p=s||!o.onClick&&!d?t.jsx("span",{style:{color:i("ink")},children:o.label},r):t.jsx("a",{href:d??"#",onClick:o.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),o.onClick())}:void 0,style:{color:i("meta-fg")},children:o.label},r);return t.jsxs(g.Fragment,{children:[l,p]},r)})})}function rs({title:e,subtitle:n,aside:o,secondLine:r}){return t.jsxs("header",{style:{borderBottom:`2px solid ${i("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:i("meta-fg"),letterSpacing:".06em"},children:n})]}),o&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".06em"},children:o})]}),r&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:i("quiet-fg")},children:r})]})}function Sc({children:e,facts:n}){return!e&&n?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${i("rule")}`,marginBottom:40},children:n}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),n]})}function _c({items:e,horizontal:n}){const{convert:o}=Z();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${i("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:i("label-fg"),letterSpacing:".08em",flex:"none"},children:o(r.label)}),t.jsx("span",{style:{color:i("body-fg"),textAlign:n?"left":"right",minWidth:0},children:r.value})]},s))}):null}function $c({glyph:e,tone:n,title:o,count:r,actions:s,id:l}){const{convert:d}=Z();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($i,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:d(o)}),r!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg")},children:r})]}),s&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function ss({label:e,active:n,onClick:o,dashed:r}){const{convert:s}=Z();return t.jsx("button",{type:"button",onClick:o,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!n?"dashed":"solid"} ${i(n?"accent":"rule")}`,background:n?i("accent"):"transparent",color:i(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(e)})}function zc({label:e,onClick:n}){const{convert:o}=Z();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:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:o(e)})}function Cc({label:e,onClick:n,inline:o}){const{convert:r}=Z();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:o?0:12,width:o?void 0:"100%",padding:o?"4px 12px":9,background:"none",border:`1px dashed ${i("rule-dashed")}`,cursor:"pointer",fontSize:12,color:i("meta-fg"),letterSpacing:o?void 0:".08em"},children:r(e)})}function ls({children:e,href:n,onClick:o,title:r}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${i("rule")}`,fontSize:13,color:i("body-fg"),lineHeight:1.5};return n||o?t.jsx("a",{href:n??"#",title:r,onClick:o?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o())}:void 0,style:s,children:e}):t.jsx("span",{title:r,style:s,children:e})}function Ic({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function Tc({volumes:e,unit:n="冊",max:o=60}){const[r,s]=g.useState(!1);if(!e.length)return null;const l=r?e:e.slice(0,o);return t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[l.map(d=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${i("rule")}`,color:i("meta-fg")},children:d},d)),!r&&e.length>o&&t.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${i("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:i("meta-fg")},children:["+",e.length-o]}),t.jsx("span",{style:{padding:"2px 6px",color:i("hint-fg")},children:n})]})}function Ec({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${i("rule-strong")}`},children:e})}function Rc({spec:e}){const{convert:n}=Z();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 ${i("rule-strong")}`,fontSize:11,color:i("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(o=>o.width).join(" "),gap:12},children:e.columns.map(o=>t.jsx("span",{children:n(o.label)},o.label))})]})}function Nc({no:e,main:n,meta:o,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:i("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:o})]})}function Lc(e){return String(e+1).padStart(2,"0")}function Bc(){return t.jsx("span",{style:{color:i("hint-fg")},children:"—"})}function Ac({open:e,onToggle:n,main:o,action:r,children:s}){return t.jsxs("div",{style:{borderBottom:`1px solid ${i("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 ${i(e?"accent":"rule-dashed")}`,background:e?i("accent"):"transparent",color:i(e?"page-bg":"accent")},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:o}),r]}),e&&s&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${i("rule-accent-soft")}`,marginLeft:12},children:s})]})}function as(e){const n=[];for(let o=0;o<e.length;o++){const r=e[o];let s;if(r==="⟨")s="⟩";else if(r==="<"){const p=e[o+1];if(p===void 0||/[A-Za-z/!?>\s]/.test(p))continue;s=">"}else continue;const l=e.indexOf(s,o+1);if(l<0)continue;const d=e.slice(o+1,l);d.includes(`
568
- `)||(n.push({start:o,end:l+1,inner:d}),o=l)}return n}function cs(e,n){if(e.length<=n)return e;let o=n;for(const r of as(e)){if(r.start>=o)break;if(r.end>o){o=r.start>0?r.start:r.end;break}}return e.slice(0,o)}const ds={fontSize:".78em",color:i("meta-fg"),lineHeight:1.55},Wc={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 ps(e,n,o){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:o===0?ds:void 0,children:ps(r.children,n,o+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:Wc,children:r.label},s)}})}function Ue(e,n=r=>r,o){if(!e)return"";if(o!=null&&o.gujiMarkdown)return mc(e)?ps(es(e),n,0):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let s=0,l=0;for(const d of as(e))d.start>s&&r.push(t.jsx(g.Fragment,{children:n(e.slice(s,d.start))},l++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:ds,children:n(d.inner)},l++)),s=d.end;return s<e.length&&r.push(t.jsx(g.Fragment,{children:n(e.slice(s))},l++)),r}function Mc({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:i("label-fg"),marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:i("quiet-fg"),textAlign:"justify"},children:n})]})}function Fc({title:e,tag:n,children:o}){const{convert:r}=Z();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${i("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:i("accent"),letterSpacing:".06em"},children:r(n)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:o})]})}function us({name:e,note:n,href:o,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:i("hint-fg"),flex:"none"},children:o?"↗":""}),n&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:i("label-fg")},children:n})]}),l={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${i("rule")}`,color:i("body-fg"),alignItems:"baseline"};return t.jsxs(t.Fragment,{children:[o?t.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",style:l,children:s}):t.jsx("div",{style:l,children:s}),r]})}function Pc({item:e,siblings:n,showVolumes:o=!0,fallbackNote:r}){const{convert:s}=Z(),[l,d]=g.useState(!1),p=yn(e),c=o&&!!p&&p.expected>0,a=(e.url?Nt(e.url):void 0)||s(e.name),u=n?Gr(e,n):"",f=u?`${a}(${u})`:a;return t.jsx(us,{name:f,note:Sn(e)||r,href:Lt(e),extra:c?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>d(x=>!x),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:l?"收起分冊":`展開 ${p.expected} 冊`}),l&&t.jsx(zi,{item:e})]}):void 0})}function zi({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,o)=>{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:i("zebra-bg")},children:n.volume},o):t.jsx("span",{style:{padding:"1px 5px",color:i(r?"missing-fg":"hint-fg"),textDecoration:r?"line-through":void 0},children:n.volume},o)})})}function xs({label:e,items:n}){const{convert:o}=Z();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:i("label-fg"),letterSpacing:".08em"},children:e}),n.map((r,s)=>t.jsx(ls,{children:o(r)},s))]}):null}function Oc({rows:e}){const n=e.filter(o=>o.items.length>0);return n.length?t.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(o=>t.jsx(xs,{label:o.label,items:o.items},o.label))}):null}function ti(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function fs({left:e,right:n}){return t.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:i("aux-fg")},children:[t.jsx("span",{children:e}),n&&t.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function Dc({children:e,action:n}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:i("aux-fg"),borderBottom:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),n]})}function Be({id:e,label:n,onNavigate:o,renderLink:r,style:s,dense:l}){const d=Pe();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:l})}):t.jsx("a",{href:d(e),onClick:o?p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),o(e))}:void 0,style:s,children:n??e})}function Hc({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 gs="(min-width: 1100px)",ms="(max-width: 719px)",Gc=`${ms}, (pointer: coarse)`,pt=i("reader-top"),Uc="48px",hs=`
686
+ ${dd}`;function Kt({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Es}),t.jsx("div",{className:r?"bim-d-main bim-d-main-grid":o?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function ci({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:i("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 Fi({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:i(n==="accent"?"accent":"ink"),color:i("page-bg")},children:e})}function di({items:e}){const n=Fe();return t.jsx(t.Fragment,{children:e.map((o,r)=>{const s=r===e.length-1,l=r>0&&t.jsx("span",{style:{color:i("hint-fg")},children:"/"},`s${r}`),c=o.id?n(o.id):o.href,p=s||!o.onClick&&!c?t.jsx("span",{style:{color:i("ink")},children:o.label},r):t.jsx("a",{href:c??"#",onClick:o.onClick?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),o.onClick())}:void 0,style:{color:i("meta-fg")},children:o.label},r);return t.jsxs(f.Fragment,{children:[l,p]},r)})})}function Rs({title:e,subtitle:n,aside:o,secondLine:r}){return t.jsxs("header",{style:{borderBottom:`2px solid ${i("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:i("meta-fg"),letterSpacing:".06em"},children:n})]}),o&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".06em"},children:o})]}),r&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:i("quiet-fg")},children:r})]})}function fd({children:e,facts:n}){return!e&&n?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${i("rule")}`,marginBottom:40},children:n}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),n]})}function md({items:e,horizontal:n}){const{convert:o}=V();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${i("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:i("label-fg"),letterSpacing:".08em",flex:"none"},children:o(r.label)}),t.jsx("span",{style:{color:i("body-fg"),textAlign:n?"left":"right",minWidth:0},children:r.value})]},s))}):null}function gd({glyph:e,tone:n,title:o,count:r,actions:s,id:l}){const{convert:c}=V();return t.jsxs("div",{id:l,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(Fi,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:c(o)}),r!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg")},children:r})]}),s&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function Ns({label:e,active:n,onClick:o,dashed:r}){const{convert:s}=V();return t.jsx("button",{type:"button",onClick:o,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!n?"dashed":"solid"} ${i(n?"accent":"rule")}`,background:n?i("accent"):"transparent",color:i(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(e)})}function hd({label:e,onClick:n}){const{convert:o}=V();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:o(e)})}function bd({label:e,onClick:n,inline:o}){const{convert:r}=V();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:o?0:12,width:o?void 0:"100%",padding:o?"4px 12px":9,background:"none",border:`1px dashed ${i("rule-dashed")}`,cursor:"pointer",fontSize:12,color:i("meta-fg"),letterSpacing:o?void 0:".08em"},children:r(e)})}function Ls({children:e,href:n,onClick:o,title:r}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${i("rule")}`,fontSize:13,color:i("body-fg"),lineHeight:1.5};return n||o?t.jsx("a",{href:n??"#",title:r,onClick:o?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o())}:void 0,style:s,children:e}):t.jsx("span",{title:r,style:s,children:e})}function yd({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function jd({volumes:e,unit:n="冊",max:o=60}){const[r,s]=f.useState(!1);if(!e.length)return null;const l=r?e:e.slice(0,o);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 ${i("rule")}`,color:i("meta-fg")},children:c},c)),!r&&e.length>o&&t.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${i("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:i("meta-fg")},children:["+",e.length-o]}),t.jsx("span",{style:{padding:"2px 6px",color:i("hint-fg")},children:n})]})}function vd({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${i("rule-strong")}`},children:e})}function kd({spec:e}){const{convert:n}=V();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${i("rule-strong")}`,fontSize:11,color:i("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(o=>o.width).join(" "),gap:12},children:e.columns.map(o=>t.jsx("span",{children:n(o.label)},o.label))})]})}function wd({no:e,main:n,meta:o,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:i("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:o})]})}function Sd(e){return String(e+1).padStart(2,"0")}function $d(){return t.jsx("span",{style:{color:i("hint-fg")},children:"—"})}function _d({open:e,onToggle:n,main:o,action:r,children:s}){return t.jsxs("div",{style:{borderBottom:`1px solid ${i("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 ${i(e?"accent":"rule-dashed")}`,background:e?i("accent"):"transparent",color:i(e?"page-bg":"accent")},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:o}),r]}),e&&s&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${i("rule-accent-soft")}`,marginLeft:12},children:s})]})}function Bs(e){const n=[];for(let o=0;o<e.length;o++){const r=e[o];let s;if(r==="⟨")s="⟩";else if(r==="<"){const p=e[o+1];if(p===void 0||/[A-Za-z/!?>\s]/.test(p))continue;s=">"}else continue;const l=e.indexOf(s,o+1);if(l<0)continue;const c=e.slice(o+1,l);c.includes(`
687
+ `)||(n.push({start:o,end:l+1,inner:c}),o=l)}return n}function As(e,n){if(e.length<=n)return e;let o=n;for(const r of Bs(e)){if(r.start>=o)break;if(r.end>o){o=r.start>0?r.start:r.end;break}}return e.slice(0,o)}const Ws={fontSize:".78em",color:i("meta-fg"),lineHeight:1.55},zd={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 Ms(e,n,o){return e.map((r,s)=>{switch(r.type){case"text":return t.jsx(f.Fragment,{children:n(r.text)},s);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:o===0?Ws:void 0,children:Ms(r.children,n,o+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:zd,children:r.label},s)}})}function Ke(e,n=r=>r,o){if(!e)return"";if(o!=null&&o.gujiMarkdown)return sd(e)?Ms(zs(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 Bs(e))c.start>s&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s,c.start))},l++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:Ws,children:n(c.inner)},l++)),s=c.end;return s<e.length&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),r}function Cd({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:i("label-fg"),marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:i("quiet-fg"),textAlign:"justify"},children:n})]})}function Td({title:e,tag:n,children:o}){const{convert:r}=V();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${i("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:i("accent"),letterSpacing:".06em"},children:r(n)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:o})]})}function Fs({name:e,note:n,href:o,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:i("hint-fg"),flex:"none"},children:o?"↗":""}),n&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:i("label-fg")},children:n})]}),l={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${i("rule")}`,color:i("body-fg"),alignItems:"baseline"};return t.jsxs(t.Fragment,{children:[o?t.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",style:l,children:s}):t.jsx("div",{style:l,children:s}),r]})}function Id({item:e,siblings:n,showVolumes:o=!0,fallbackNote:r}){const{convert:s}=V(),[l,c]=f.useState(!1),p=Sn(e),a=o&&!!p&&p.expected>0,d=(e.url?Bt(e.url):void 0)||s(e.name),u=n?hs(e,n):"",m=u?`${d}(${u})`:d;return t.jsx(Fs,{name:m,note:Rn(e)||r,href:At(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:i("meta-fg"),borderBottom:`1px solid ${i("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,o)=>{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:i("zebra-bg")},children:n.volume},o):t.jsx("span",{style:{padding:"1px 5px",color:i(r?"missing-fg":"hint-fg"),textDecoration:r?"line-through":void 0},children:n.volume},o)})})}function Ps({label:e,items:n}){const{convert:o}=V();return n.length?t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".08em"},children:e}),n.map((r,s)=>t.jsx(Ls,{children:o(r)},s))]}):null}function Ed({rows:e}){const n=e.filter(o=>o.items.length>0);return n.length?t.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(o=>t.jsx(Ps,{label:o.label,items:o.items},o.label))}):null}function pi(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Os({left:e,right:n}){return t.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:i("aux-fg")},children:[t.jsx("span",{children:e}),n&&t.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function Rd({children:e,action:n}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:i("aux-fg"),borderBottom:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),n]})}function Me({id:e,label:n,onNavigate:o,renderLink:r,style:s,dense:l}){const c=Fe();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:l})}):t.jsx("a",{href:c(e),onClick:o?p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),o(e))}:void 0,style:s,children:n??e})}function Nd({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 Ds="(min-width: 1100px)",Hs="(max-width: 719px)",Ld=`${Hs}, (pointer: coarse)`,xt=i("reader-top"),Bd="48px",Gs=`
569
688
  .bim-rd {
570
689
  position: relative;
571
690
  background: ${i("page-bg")};
572
691
  color: ${i("ink")};
573
692
  font-family: ${i("font-ui")};
574
- --bimrd-bar-h: ${Uc};
693
+ --bimrd-bar-h: ${Bd};
575
694
  }
576
695
  .bim-rd *, .bim-rd *::before, .bim-rd *::after { box-sizing: border-box; }
577
696
 
@@ -597,7 +716,7 @@ ${jc}`;function Ht({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
597
716
 
598
717
  /* ── 工具条:文字 + 图标,不画按钮外框 ── */
599
718
  .bim-rd-bar {
600
- position: sticky; top: ${pt}; z-index: 30;
719
+ position: sticky; top: ${xt}; z-index: 30;
601
720
  height: var(--bimrd-bar-h);
602
721
  display: flex; align-items: center; gap: 16px;
603
722
  padding: 0 20px;
@@ -651,14 +770,14 @@ ${jc}`;function Ht({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
651
770
  display: grid;
652
771
  grid-template-columns: auto auto minmax(0, 1fr);
653
772
  align-items: start;
654
- min-height: calc(100vh - ${pt} - var(--bimrd-bar-h));
773
+ min-height: calc(100vh - ${xt} - var(--bimrd-bar-h));
655
774
  }
656
775
 
657
776
  /* 目录:宽屏是侧栏 */
658
777
  .bim-rd-toc {
659
778
  grid-column: 1;
660
- position: sticky; top: calc(${pt} + var(--bimrd-bar-h));
661
- width: 248px; height: calc(100vh - ${pt} - var(--bimrd-bar-h));
779
+ position: sticky; top: calc(${xt} + var(--bimrd-bar-h));
780
+ width: 248px; height: calc(100vh - ${xt} - var(--bimrd-bar-h));
662
781
  overflow-y: auto; overscroll-behavior: contain;
663
782
  padding: 0 10px 40px;
664
783
  background: ${i("sidebar-bg")};
@@ -695,8 +814,8 @@ ${jc}`;function Ht({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
695
814
  /* 书影:正文左侧 */
696
815
  .bim-rd-img {
697
816
  grid-column: 2;
698
- position: sticky; top: calc(${pt} + var(--bimrd-bar-h));
699
- width: clamp(300px, 32vw, 560px); height: calc(100vh - ${pt} - var(--bimrd-bar-h));
817
+ position: sticky; top: calc(${xt} + var(--bimrd-bar-h));
818
+ width: clamp(300px, 32vw, 560px); height: calc(100vh - ${xt} - var(--bimrd-bar-h));
700
819
  padding: 16px 0 16px 20px;
701
820
  display: flex; flex-direction: column; gap: 8px;
702
821
  }
@@ -707,7 +826,7 @@ ${jc}`;function Ht({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
707
826
  display: flex; align-items: center; justify-content: center; overflow: hidden;
708
827
  }
709
828
  .bim-rd-img-fig { position: relative; margin: 0; max-width: 100%; max-height: 100%; }
710
- .bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${pt} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
829
+ .bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${xt} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
711
830
  .bim-rd-img-fig svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
712
831
  .bim-rd-img-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 24px; text-align: center; font-size: 13px; color: ${i("meta-fg")}; }
713
832
  .bim-rd-img-empty b { font-size: 15px; font-weight: 500; color: ${i("quiet-fg")}; }
@@ -736,6 +855,9 @@ ${jc}`;function Ht({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
736
855
  .bim-rd-rail-list a { display: flex; align-items: baseline; gap: 8px; padding: 5px 12px; border-left: 2px solid ${i("rule")}; font-size: 13px; color: ${i("quiet-fg")}; text-decoration: none; }
737
856
  .bim-rd-rail-list a > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
738
857
  .bim-rd-rail-list a:hover { border-left-color: ${i("accent")}; color: ${i("ink")}; }
858
+ .bim-rd-rail-acts { margin-top: 18px; padding-top: 14px; border-top: 1px solid ${i("rule")}; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; font-size: 12.5px; }
859
+ .bim-rd-rail-report { padding: 0; border: none; background: none; font: inherit; color: ${i("accent")}; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
860
+ .bim-rd-rail-report:hover { color: ${i("ink")}; }
739
861
  .bim-rd-rail-dot { flex: none; align-self: center; width: 5px; height: 5px; background: ${i("rule")}; }
740
862
  .bim-rd-rail-dot.on { background: ${i("accent")}; }
741
863
 
@@ -743,6 +865,8 @@ ${jc}`;function Ht({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
743
865
  .bim-rd-text { grid-column: 3; min-width: 0; padding: 32px 48px 96px 40px; outline: none; }
744
866
  /* 正文列靠左紧贴目录栏(原来居中,两边各留 ~150px 空隙),并加宽 38em → 50em */
745
867
  .bim-rd-col { max-width: 50em; margin: 0 auto 0 0; font-size: var(--bimrd-fs, 18px); }
868
+ .bim-rd-kicker { margin: 0 0 8px; font-size: 12px; letter-spacing: 0.2em; color: ${i("label-fg")}; font-family: ${i("font-ui")}; }
869
+ .bim-rd-kicker .bim-rd-dot::before { content: "·"; margin: 0 0.6em; }
746
870
  .bim-rd-h1 { font-family: ${i("font-ui")}; font-size: 28px; font-weight: 700; letter-spacing: 0.12em; margin: 0; color: ${i("ink")}; line-height: 1.4; }
747
871
  .bim-rd-meta { margin: 6px 0 0; font-size: 13px; line-height: 1.8; color: ${i("meta-fg")}; font-family: ${i("font-ui")}; }
748
872
  .bim-rd-meta .bim-rd-dot::before { content: "·"; margin: 0 0.5em; }
@@ -795,12 +919,13 @@ ${jc}`;function Ht({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
795
919
 
796
920
  /* 竖排(预留):只在宿主打开 allowVertical 时可切换 */
797
921
  .bim-rd-vertical .bim-rd-prose {
798
- writing-mode: vertical-rl; max-height: calc(100vh - ${pt} - var(--bimrd-bar-h) - 120px);
922
+ writing-mode: vertical-rl; max-height: calc(100vh - ${xt} - var(--bimrd-bar-h) - 120px);
799
923
  overflow-x: auto; text-align: start;
800
924
  }
801
925
 
802
926
  .bim-rd-src { margin: 48px 0 0; font-size: 12px; line-height: 1.8; color: ${i("meta-fg")}; font-family: ${i("font-ui")}; }
803
927
  .bim-rd-src .bim-rd-dot::before { content: "·"; margin: 0 0.5em; }
928
+ .bim-rd-src + .bim-rd-rev { margin-top: 4px; }
804
929
  .bim-rd-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 48px; font-size: 14px; font-family: ${i("font-ui")}; }
805
930
  .bim-rd-pg {
806
931
  display: block; min-width: 0; margin: 0; padding: 14px 16px; text-align: left; font: inherit;
@@ -819,7 +944,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
819
944
 
820
945
  /* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
821
946
  A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
822
- @media ${Gc} {
947
+ @media ${Ld} {
823
948
  .bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
824
949
  .bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
825
950
  content: ""; position: absolute; left: 50%; top: 50%;
@@ -831,7 +956,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
831
956
  }
832
957
 
833
958
  /* ── 中屏以下:目录改抽屉 ── */
834
- @media not all and ${gs} {
959
+ @media not all and ${Ds} {
835
960
  .bim-rd-toc {
836
961
  position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto;
837
962
  width: min(86vw, 320px);
@@ -845,7 +970,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
845
970
  }
846
971
 
847
972
  /* ── 窄屏:书影收起,只留正文 ── */
848
- @media ${ms} {
973
+ @media ${Hs} {
849
974
  .bim-rd-bar { padding: 0 12px; gap: 10px; }
850
975
  .bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
851
976
  .bim-rd-ttl { flex: 1 1 auto; }
@@ -873,19 +998,23 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
873
998
  :root[data-theme="ink"] :is(.bim-rd-entry-h a, .bim-rd-link, .bim-rd-prose a, .bim-rd-meta a) {
874
999
  text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); text-underline-offset: 3px;
875
1000
  }
876
- `;function Ci(e,n){var o;return n?e.key===n?!0:!!((o=e.children)!=null&&o.some(r=>Ci(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 Yc({item:e,activeKey:n,onSelect:o,tabKey:r}){const s=Ci(e,n),[l,d]=g.useState(s||!!e.defaultExpanded);return g.useEffect(()=>{s&&d(!0)},[s]),g.useEffect(()=>{e.defaultExpanded&&d(!0)},[e.defaultExpanded]),t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>d(p=>!p),children:[t.jsx(Vc,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(bs,{items:e.children,activeKey:n,onSelect:o,tabKey:r})]})}function bs({items:e,activeKey:n,onSelect:o,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Yc,{item:s,activeKey:n,onSelect:o,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:()=>o(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 No(e,n){var o;for(const r of e)if(r.key===n||Ci(r,n))return r.key;return((o=e[0])==null?void 0:o.key)??null}function ys({items:e,activeKey:n,onSelect:o,label:r="目录"}){const s=g.useRef(null),[l,d]=g.useState(null);g.useEffect(()=>{d(null)},[n]);const p=g.useMemo(()=>l||(n??No(e,n)),[l,n,e]);g.useEffect(()=>{const a=s.current;if(!a)return;const u=Array.from(a.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===No(e,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===f?0:-1}),g.useEffect(()=>{const a=s.current,u=a==null?void 0:a.closest(".bim-rd-toc");if(!a||!u||!n)return;const f=Array.from(a.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 c=g.useCallback(a=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(a.key))return;const f=s.current;if(!f)return;const x=Array.from(f.querySelectorAll("[data-rd-toc-key]")).filter(h=>!h.disabled),m=x.indexOf(document.activeElement);let j=m;if(a.key==="ArrowDown"?j=Math.min(x.length-1,m+1):a.key==="ArrowUp"?j=Math.max(0,m-1):a.key==="Home"?j=0:a.key==="End"&&(j=x.length-1),j<0||j===m)return;a.preventDefault();const w=x[j];for(const h of x)h.tabIndex=-1;w.tabIndex=0,w.focus(),d(w.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:c,children:t.jsx(bs,{items:e,activeKey:n,onSelect:o,tabKey:p})})}function Kc({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((o,r)=>t.jsx("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:"none",stroke:i("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},r))})}function js({pages:e,loading:n,page:o,onPageChange:r,renderOverlay:s}){const[l,d]=g.useState(0),p=o??l,c=x=>{r?r(x):d(x)};if(g.useEffect(()=>{o===void 0&&d(0)},[e,o]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:"加载书影…"})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:"暂无书影"}),t.jsx("span",{children:"这一卷还没有配上影像;接入后在此与正文逐页对看"})]})});const a=Math.max(0,Math.min(e.length-1,p)),u=e[a],f=u.label??`${a+1}`;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${f} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(Kc,{page:u}),s==null?void 0:s(u,a)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:a===0,onClick:()=>c(a-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${a+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:a===e.length-1,onClick:()=>c(a+1),children:"›"})]})]})}const Ii={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal",workLinks:!0},$t=[15,16,17,18,20,22,24],ni=18,vs="bim-reader-prefs",qc="bim-reading-mode";function Jc(){const e={...Ii};try{const n=localStorage.getItem(vs),o=n?JSON.parse(n):{};typeof o.fontSize=="number"&&$t.includes(o.fontSize)&&(e.fontSize=o.fontSize),(o.readingMode??localStorage.getItem(qc))==="paragraph"&&(e.readingMode="paragraph"),o.properNames===!0&&(e.properNames=!0),o.writingMode==="vertical"&&(e.writingMode="vertical"),o.workLinks===!1&&(e.workLinks=!1)}catch{}return e}function Zc(e){try{localStorage.setItem(vs,JSON.stringify(e))}catch{}}function Lo(e,n){const o=e??ni,r=$t;let s=r.indexOf(o);return s<0&&(s=r.indexOf(ni)),r[Math.max(0,Math.min(r.length-1,s+n))]}function Ti(){const[e,n]=g.useState(Ii);g.useEffect(()=>{n(Jc())},[]);const o=g.useCallback(r=>{n(s=>{const l={...s,...r};return Zc(l),l})},[]);return[e,o]}function ks(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 ii(e){const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function ws(e,n){if(!(!e||e.length===0))return(n!=null?e.find(o=>o.key===n):void 0)??e.find(o=>o.primary)??e[0]}function Ss(e){const n=[],o=r=>{for(const s of r)s.children&&s.children.length>0?o(s.children):n.push(s)};return o(e),n}const Xc=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),Qc=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),t.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function ed(e,n){if(!n)return;const o=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(d=>d.tabIndex>=0);if(o.length===0)return;const r=o[0],s=o[o.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 td(e,n){const[o,r]=g.useState(n);return g.useEffect(()=>{var d;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(s.matches);return(d=s.addEventListener)==null||d.call(s,"change",l),()=>{var p;return(p=s.removeEventListener)==null?void 0:p.call(s,"change",l)}},[e]),o}function nd(){const e=g.useContext(Rt);if(!e)return null;const n=e.locale==="zh-Hant";return t.jsxs("button",{type:"button",className:"bim-rd-t",title:n?"切换为简体":"切換為繁體","aria-label":n?"切换为简体":"切換為繁體",onClick:()=>e.setLocale(n?"zh-Hans":"zh-Hant"),children:[t.jsx("span",{className:n?"bim-rd-on":"bim-rd-off",children:"繁"}),t.jsx("span",{className:"bim-rd-off",children:"|"}),t.jsx("span",{className:n?"bim-rd-off":"bim-rd-on",children:"简"})]})}function Ei({title:e,subtitle:n,toc:o,activeKey:r,onSelect:s,tocHeader:l,tocCaption:d,images:p,imagesLoading:c,renderImageOverlay:a,imagePanel:u="auto",prefs:f,onPrefsChange:x,paragraphToggle:m,properNameToggle:j=!0,allowVertical:w,byline:h,current:b,workLinkToggle:y,rail:k,pager:$=!0,pagerUnit:v="卷",versions:_,currentVersionKey:S,onVersionChange:z,versionSource:N=!0,children:T,className:C,style:D}){const B=g.useId().replace(/:/g,""),O=`bim-rd-toc-${B}`,M=`bim-rd-text-${B}`,X=g.useRef(null),Y=g.useRef(null),E=g.useRef(null),ee=g.useRef(null),F=td(gs,!0),[K,ae]=g.useState("auto"),ne=K==="auto"?F:K==="open",Q=!F,ie=!!p&&p.length>0,[ge,re]=g.useState(u);g.useEffect(()=>{re(u)},[u]);const le=ge==="auto"?ie||!!c:ge==="open",pe=g.useCallback(A=>{var I;ae("auto"),A&&((I=ee.current)==null||I.focus())},[]),Re=()=>ae(ne?"closed":"open");g.useEffect(()=>{if(!Q||K!=="open")return;const A=E.current,I=A==null?void 0:A.querySelector('input, [data-rd-toc-key][tabindex="0"]');I==null||I.focus()},[Q,K]);const $e=g.useCallback(A=>{s(A),Q&&pe(!1);const I=Y.current,G=X.current;if(I&&G&&typeof window<"u"){const P=I.getBoundingClientRect().top-G.getBoundingClientRect().bottom;P<0&&window.scrollBy({top:P})}},[s,Q,pe]),ye=g.useMemo(()=>Ss(o),[o]),[Se,Ne]=g.useState(null),je=ws(_,S!==void 0?S:Se),H=(je==null?void 0:je.key)??null,ce=g.useMemo(()=>ye.map(A=>A.key).join(`
877
- `),[ye]),oe=g.useRef(null),he=A=>{A!==H&&(oe.current={key:A,sig:ce,done:!1},S===void 0&&Ne(A),z==null||z(A))};g.useEffect(()=>{const A=oe.current;if(!A||A.key!==H)return;const I=ye.find(P=>!P.disabled);if(!I)return;const G=ce!==A.sig;!G&&A.done||(G?oe.current=null:A.done=!0,I.key!==r&&$e(I.key))},[H,ce,ye,r,$e]);const me=ye.findIndex(A=>A.key===r),U=me>0?ye.slice(0,me).reverse().find(A=>!A.disabled):void 0,R=me>=0?ye.slice(me+1).find(A=>!A.disabled):void 0,V=f.fontSize??ni,W={...D,...f.fontSize?{"--bimrd-fs":`${f.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",f.writingMode==="vertical"&&w?"bim-rd-vertical":"",C].filter(Boolean).join(" "),"data-toc":K,"data-img":le?"open":"closed",style:W,children:[t.jsx("style",{children:hs}),t.jsx("a",{className:"bim-rd-skip",href:`#${M}`,onClick:A=>{var I,G,P;A.preventDefault(),(I=Y.current)==null||I.focus(),(P=(G=Y.current)==null?void 0:G.scrollIntoView)==null||P.call(G,{block:"start"})},children:"跳到正文"}),t.jsxs("div",{className:"bim-rd-bar",ref:X,children:[(e||n||h||b)&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),h&&t.jsx("span",{className:"bim-rd-by",children:h}),b&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:b})]}),n&&t.jsx("span",{children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":"阅读设置",children:[_&&_.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:je?ii(je):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:H??"",onChange:A=>he(A.target.value),children:_.map(A=>t.jsx("option",{value:A.key,children:ii(A)},A.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),t.jsxs("button",{ref:ee,type:"button",className:"bim-rd-t","aria-expanded":ne,"aria-controls":O,onClick:Re,children:[t.jsx(Xc,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":le,onClick:()=>re(le?"closed":"open"),children:[t.jsx(Qc,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(nd,{}),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:V<=$t[0],onClick:()=>x({fontSize:Lo(f.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"放大字号",disabled:V>=$t[$t.length-1],onClick:()=>x({fontSize:Lo(f.fontSize,1)}),children:"A+"}),(m||j||w)&&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:"自然段"}),y&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk",children:[t.jsx("input",{type:"checkbox",checked:f.workLinks,onChange:A=>x({workLinks:A.target.checked})}),t.jsx("span",{children:"标出作品链接"})]}),j&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":f.properNames,title:"书名加波浪线",onClick:()=>x({properNames:!f.properNames}),children:"专名线"}),w&&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:O,ref:E,role:Q&&ne?"dialog":void 0,"aria-modal":Q&&ne?!0:void 0,"aria-label":Q&&ne?"目录":void 0,onKeyDown:A=>{if(!(!Q||!ne)){if(A.key==="Escape"){A.stopPropagation(),pe(!0);return}A.key==="Tab"&&ed(A,E.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:d??"目录"}),Q&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>pe(!0),children:"✕"})]}),l]}),t.jsx(ys,{items:o,activeKey:r,onSelect:$e})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>pe(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:le&&t.jsx(js,{pages:p??null,loading:c,renderOverlay:a})}),t.jsxs("div",{className:"bim-rd-text",id:M,ref:Y,tabIndex:-1,"data-rail":k?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[T,N&&je&&(je.sourceName||je.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":je.key,children:[je.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",je.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:je.sourceUrl,target:"_blank",rel:"noreferrer",children:je.sourceName}):je.sourceName]}),je.sourceName&&je.license&&t.jsx("span",{className:"bim-rd-dot"}),je.license&&t.jsxs(t.Fragment,{children:["授权 ",je.license]})]}),$&&(U||R)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[U?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>$e(U.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),"上一",v]}),t.jsx("span",{className:"bim-rd-pglabel",children:U.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← 已是第一",v]}),R?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>$e(R.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:["下一",v,t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:R.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:["已是最后一",v," →"]})]})]}),k&&t.jsx("aside",{className:"bim-rd-rail","aria-label":"本卷",children:k})]})]})]})}const _s="guji-table-v1";function $s(e){return!!e&&e.table_notation===_s}const id=/^:::table(?:\{[^}]*\})?[ \t]*$/,od=/^:::[ \t]*$/;function zs(e){const n=[];let o="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const d=Xr(e,r+3);if(d>r+4){o+=e.slice(r,d+1),r=d;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const d=e[r+1];d!==void 0&&!/[A-Za-z/!?>\s]/.test(d)&&(l=">")}if(l){const d=e.indexOf(l,r+1);if(d>0){o+=e.slice(r,d+1),r=d;continue}}s==="|"?(n.push(o),o=""):o+=s}return n.push(o),n.map(r=>r.trim())}const rd=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function sd(e){if(e==="^")return{cont:!0};const n=rd.exec(e),o=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=o==="_";return{cont:!1,cell:{text:l?"":o,empty:l,colspan:r,rowspan:s}}}function Cs(e,n=1){const o=[],r=[],s=[];let l=[];e.forEach((p,c)=>{const a=c+n+1;let u=p.trim();if(!u)return;let f=!1;u.startsWith("!")&&(f=!0,u=u.slice(1));const x=zs(u).map(sd),m=l.map(b=>b>0),j=l.map(b=>b>0?b-1:0),w=[];let h=0;for(const b of x){if(b.cont){m[h]||o.push(`第 ${a} 行第 ${h+1} 列:续格 ^ 上方没有跨行格`),h+=1;continue}const{cell:y}=b;for(let k=h;k<h+y.colspan;k++)if(m[k]){o.push(`第 ${a} 行第 ${k+1} 列:此处被上方跨行格占住,应写 ^`);break}if(y.rowspan>1)for(let k=h;k<h+y.colspan;k++)j[k]=y.rowspan-1;w.push(y),h+=y.colspan}for(let b=h;b<m.length;b++)m[b]&&o.push(`第 ${a} 行第 ${b+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let b=0;b<j.length;b++)j[b]===void 0&&(j[b]=0);l=j,r.push({header:f,cells:w}),s.push({width:h,line:a})});const d=s.reduce((p,c)=>Math.max(p,c.width),0);for(const p of s)p.width!==d&&o.push(`第 ${p.line} 行:占 ${p.width} 列,与总列数 ${d} 不符`);return l.some(p=>p>0)&&o.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&o.push("空表"),{rows:r,columns:d,warnings:o}}function Ri(e){const n=e.split(`
878
- `),o=[];let r=[];const s=()=>{if(r.length===0)return;const d=r.join(`
879
- `);r=[],o.push({type:"text",text:d})};let l=0;for(;l<n.length;){if(id.test(n[l].trim())){let d=l+1;for(;d<n.length&&!od.test(n[d].trim());)d++;if(d<n.length){s();const p=n.slice(l+1,d);o.push({type:"table",table:Cs(p,l+1),source:n.slice(l,d+1).join(`
880
- `)}),l=d+1;continue}}r.push(n[l]),l++}return s(),o.map((d,p)=>{var a,u;if(d.type!=="text")return d;let c=d.text;return((a=o[p-1])==null?void 0:a.type)==="table"&&(c=c.replace(/^\n+/,"")),((u=o[p+1])==null?void 0:u.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(d=>d.type!=="text"||d.text!=="")}const ld={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},ad={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},cd=`1px solid ${i("table-border")}`,Is={border:cd,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},dd={...Is,background:i("table-head-bg"),fontWeight:600};function Ni({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:ld,children:t.jsx("table",{className:"bim-guji-table",style:ad,children:t.jsx("tbody",{children:e.rows.map((o,r)=>t.jsx("tr",{children:o.cells.map((s,l)=>{const d=o.header?"th":"td";return t.jsx(d,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:o.header?dd:Is,children:s.empty?null:Ue(s.text,void 0,n)},l)})},r))})})})}function pd(e,n){return e.indexOf("**")<0?Ue(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:Ue(r.trim().slice(2,-2),void 0,n)},s):t.jsx(g.Fragment,{children:Ue(r,void 0,n)},s))}function ud(e,n,o=!1){const r=o?{gujiMarkdown:!0}:void 0;return n?Ri(e).map((s,l)=>s.type==="table"?t.jsx(Ni,{table:s.table,opts:r},l):t.jsx(g.Fragment,{children:pd(s.text,r)},l)):Ue(e,void 0,r)}const xd=/^(#{1,6})\s+(.*)$/,fd=/^\*\*([^*\n]+)\*\*\s*$/;function Li(e){const n=e.match(xd);if(n)return{level:n[1].length,text:n[2].trim()};const o=e.trim().match(fd);return o?{level:3,text:o[1].trim()}:null}const Bi=/^<!--.*-->$/;function Ts(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function Es(e){return e.split(`
881
- `).map(n=>n.trim()).filter(n=>n&&!Bi.test(n))}const gd=60;function Rs(e){let n=0,o=0;for(const r of e.split(`
882
- `)){const s=r.trim();if(!s||Bi.test(s)||Li(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>gd&&(o+=l)}return n>0&&o*2>=n}function md(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function zn(e){if(e=md(e),Rs(e))return"unknown";const n=Ts(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const o=n.map(s=>Es(s).length).filter(s=>s>0);if(o.length===0)return"unknown";const r=o.reduce((s,l)=>s+l,0)/o.length;return r<=4?"record":r>=8?"catalog":"unknown"}function hd(e){const n=e.split(`
1001
+ /* 墨下「已开启」的工具条按钮(自然段、专名线、书影、当前语言)不能只靠颜色:加下划线 */
1002
+ :root[data-theme="ink"] .bim-rd-t[aria-pressed="true"], :root[data-theme="ink"] .bim-rd-t[aria-current="true"] {
1003
+ text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px;
1004
+ }
1005
+ `;function Oi(e,n){var o;return n?e.key===n?!0:!!((o=e.children)!=null&&o.some(r=>Oi(r,n))):!1}const Ad=()=>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 Wd({item:e,activeKey:n,onSelect:o,tabKey:r}){const s=Oi(e,n),[l,c]=f.useState(s||!!e.defaultExpanded);return f.useEffect(()=>{s&&c(!0)},[s]),f.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(Ad,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Us,{items:e.children,activeKey:n,onSelect:o,tabKey:r})]})}function Us({items:e,activeKey:n,onSelect:o,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Wd,{item:s,activeKey:n,onSelect:o,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:()=>o(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 Qo(e,n){var o;for(const r of e)if(r.key===n||Oi(r,n))return r.key;return((o=e[0])==null?void 0:o.key)??null}function Vs({items:e,activeKey:n,onSelect:o,label:r="目录"}){const s=f.useRef(null),[l,c]=f.useState(null);f.useEffect(()=>{c(null)},[n]);const p=f.useMemo(()=>l||(n??Qo(e,n)),[l,n,e]);f.useEffect(()=>{const d=s.current;if(!d)return;const u=Array.from(d.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const m=u.find(x=>x.dataset.rdTocKey===p)??u.find(x=>x.dataset.rdTocKey===Qo(e,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===m?0:-1}),f.useEffect(()=>{const d=s.current,u=d==null?void 0:d.closest(".bim-rd-toc");if(!d||!u||!n)return;const m=Array.from(d.querySelectorAll("[data-rd-toc-key]")).find(g=>g.dataset.rdTocKey===n);if(!m)return;const x=m.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(x<u.scrollTop+80||x>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,x-u.clientHeight/3))},[n]);const a=f.useCallback(d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const m=s.current;if(!m)return;const x=Array.from(m.querySelectorAll("[data-rd-toc-key]")).filter(y=>!y.disabled),g=x.indexOf(document.activeElement);let b=g;if(d.key==="ArrowDown"?b=Math.min(x.length-1,g+1):d.key==="ArrowUp"?b=Math.max(0,g-1):d.key==="Home"?b=0:d.key==="End"&&(b=x.length-1),b<0||b===g)return;d.preventDefault();const w=x[b];for(const y of x)y.tabIndex=-1;w.tabIndex=0,w.focus(),c(w.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:a,children:t.jsx(Us,{items:e,activeKey:n,onSelect:o,tabKey:p})})}function Md({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((o,r)=>t.jsx("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:"none",stroke:i("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},r))})}function Ys({pages:e,loading:n,page:o,onPageChange:r,renderOverlay:s}){const[l,c]=f.useState(0),p=o??l,a=x=>{r?r(x):c(x)};if(f.useEffect(()=>{o===void 0&&c(0)},[e,o]),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],m=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??`书影 第 ${m} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(Md,{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 Di={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal",workLinks:!0},Ct=[15,16,17,18,20,22,24],ui=18,Ks="bim-reader-prefs",Fd="bim-reading-mode";function Pd(){const e={...Di};try{const n=localStorage.getItem(Ks),o=n?JSON.parse(n):{};typeof o.fontSize=="number"&&Ct.includes(o.fontSize)&&(e.fontSize=o.fontSize),(o.readingMode??localStorage.getItem(Fd))==="paragraph"&&(e.readingMode="paragraph"),o.properNames===!0&&(e.properNames=!0),o.writingMode==="vertical"&&(e.writingMode="vertical"),o.workLinks===!1&&(e.workLinks=!1)}catch{}return e}function Od(e){try{localStorage.setItem(Ks,JSON.stringify(e))}catch{}}function er(e,n){const o=e??ui,r=Ct;let s=r.indexOf(o);return s<0&&(s=r.indexOf(ui)),r[Math.max(0,Math.min(r.length-1,s+n))]}function Hi(){const[e,n]=f.useState(Di);f.useEffect(()=>{n(Pd())},[]);const o=f.useCallback(r=>{n(s=>{const l={...s,...r};return Od(l),l})},[]);return[e,o]}function qs(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 xi(e){const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function Js(e,n){if(!(!e||e.length===0))return(n!=null?e.find(o=>o.key===n):void 0)??e.find(o=>o.primary)??e[0]}function Zs(e){const n=[],o=r=>{for(const s of r)s.children&&s.children.length>0?o(s.children):n.push(s)};return o(e),n}const Dd=()=>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"})}),Hd=()=>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 Gd(e,n){if(!n)return;const o=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(c=>c.tabIndex>=0);if(o.length===0)return;const r=o[0],s=o[o.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 Ud(e,n){const[o,r]=f.useState(n);return f.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]),o}function Vd(){const e=f.useContext(Lt);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 Yd(e,n){if(!e)return;let o;for(const r of Array.from(e.querySelectorAll('[id^="rd-e-"]')))if(r.getBoundingClientRect().top<=n+8)o=r.id;else break;return o}function Kd(e){var l;if(typeof window>"u"||!e)return;const n=(l=window.getSelection)==null?void 0:l.call(window);if(!n||n.isCollapsed||n.rangeCount===0)return;const o=e.querySelector(".bim-rd-col"),r=c=>{const p=(c==null?void 0:c.nodeType)===1?c:c==null?void 0:c.parentElement;return!!c&&!!(o!=null&&o.contains(c))&&!(p!=null&&p.closest(".bim-rd-src, .bim-rd-pager"))};if(!r(n.anchorNode)||!r(n.focusNode))return;const s=n.toString().replace(/\s+/g," ").trim();return s?s.slice(0,500):void 0}function Gi({title:e,subtitle:n,toc:o,activeKey:r,onSelect:s,tocHeader:l,tocCaption:c,images:p,imagesLoading:a,renderImageOverlay:d,imagePanel:u="auto",prefs:m,onPrefsChange:x,paragraphToggle:g,properNameToggle:b=!0,allowVertical:w,byline:y,current:j,workLinkToggle:h,rail:v,onReportError:$,revisedAt:k,pager:_=!0,pagerUnit:S="卷",versions:z,currentVersionKey:N,onVersionChange:R,versionSource:C=!0,children:H,className:L,style:M}){const F=f.useId().replace(/:/g,""),X=`bim-rd-toc-${F}`,U=`bim-rd-text-${F}`,T=f.useRef(null),ce=f.useRef(null),B=f.useRef(null),D=f.useRef(null),A=Ud(Ds,!0),[ee,de]=f.useState("auto"),G=ee==="auto"?A:ee==="open",q=!A,ie=!!p&&p.length>0,[pe,ge]=f.useState(u);f.useEffect(()=>{ge(u)},[u]);const Ee=pe==="auto"?ie||!!a:pe==="open",Ne=f.useCallback(O=>{var xe;de("auto"),O&&((xe=D.current)==null||xe.focus())},[]),ze=()=>de(G?"closed":"open");f.useEffect(()=>{if(!q||ee!=="open")return;const O=B.current,xe=O==null?void 0:O.querySelector('input, [data-rd-toc-key][tabindex="0"]');xe==null||xe.focus()},[q,ee]);const Te=f.useCallback(O=>{s(O),q&&Ne(!1);const xe=ce.current,je=T.current;if(xe&&je&&typeof window<"u"){const Se=xe.getBoundingClientRect().top-je.getBoundingClientRect().bottom;Se<0&&window.scrollBy({top:Se})}},[s,q,Ne]),Ce=f.useMemo(()=>Zs(o),[o]),[Ae,P]=f.useState(null),se=Js(z,N!==void 0?N:Ae),re=(se==null?void 0:se.key)??null,ye=f.useMemo(()=>Ce.map(O=>O.key).join(`
1006
+ `),[Ce]),be=f.useRef(null),K=O=>{O!==re&&(be.current={key:O,sig:ye,done:!1},N===void 0&&P(O),R==null||R(O))};f.useEffect(()=>{const O=be.current;if(!O||O.key!==re)return;const xe=Ce.find(Se=>!Se.disabled);if(!xe)return;const je=ye!==O.sig;!je&&O.done||(je?be.current=null:O.done=!0,xe.key!==r&&Te(xe.key))},[re,ye,Ce,r,Te]);const I=Ce.find(O=>O.key===r),Y=()=>{var O;$==null||$({chapterKey:r,chapterLabel:typeof(I==null?void 0:I.label)=="string"?I.label:void 0,anchor:Yd(ce.current,((O=T.current)==null?void 0:O.getBoundingClientRect().bottom)??0),selectedText:Kd(ce.current)})},fe=Ce.findIndex(O=>O.key===r),he=fe>0?Ce.slice(0,fe).reverse().find(O=>!O.disabled):void 0,W=fe>=0?Ce.slice(fe+1).find(O=>!O.disabled):void 0,ae=m.fontSize??ui,J={...M,...m.fontSize?{"--bimrd-fs":`${m.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",m.writingMode==="vertical"&&w?"bim-rd-vertical":"",L].filter(Boolean).join(" "),"data-toc":ee,"data-img":Ee?"open":"closed",style:J,children:[t.jsx("style",{children:Gs}),t.jsx("a",{className:"bim-rd-skip",href:`#${U}`,onClick:O=>{var xe,je,Se;O.preventDefault(),(xe=ce.current)==null||xe.focus(),(Se=(je=ce.current)==null?void 0:je.scrollIntoView)==null||Se.call(je,{block:"start"})},children:"跳到正文"}),t.jsxs("div",{className:"bim-rd-bar",ref:T,children:[(e||n||y||j)&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),y&&t.jsx("span",{className:"bim-rd-by",children:y}),j&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:j})]}),n&&t.jsx("span",{children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":"阅读设置",children:[z&&z.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:se?xi(se):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:"版本"}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:"版本▾"}),t.jsx("select",{"aria-label":"版本",value:re??"",onChange:O=>K(O.target.value),children:z.map(O=>t.jsx("option",{value:O.key,children:xi(O)},O.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),t.jsxs("button",{ref:D,type:"button",className:"bim-rd-t","aria-expanded":G,"aria-controls":X,onClick:ze,children:[t.jsx(Dd,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":Ee,onClick:()=>ge(Ee?"closed":"open"),children:[t.jsx(Hd,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Vd,{}),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:ae<=Ct[0],onClick:()=>x({fontSize:er(m.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"放大字号",disabled:ae>=Ct[Ct.length-1],onClick:()=>x({fontSize:er(m.fontSize,1)}),children:"A+"}),(g||b||w)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),g&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":m.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>x({readingMode:m.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),h&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk",children:[t.jsx("input",{type:"checkbox",checked:m.workLinks,onChange:O=>x({workLinks:O.target.checked})}),t.jsx("span",{children:"标出作品链接"})]}),b&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":m.properNames,title:"书名加波浪线",onClick:()=>x({properNames:!m.properNames}),children:"专名线"}),w&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":m.writingMode==="vertical",onClick:()=>x({writingMode:m.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:X,ref:B,role:q&&G?"dialog":void 0,"aria-modal":q&&G?!0:void 0,"aria-label":q&&G?"目录":void 0,onKeyDown:O=>{if(!(!q||!G)){if(O.key==="Escape"){O.stopPropagation(),Ne(!0);return}O.key==="Tab"&&Gd(O,B.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:c??"目录"}),q&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>Ne(!0),children:"✕"})]}),l]}),t.jsx(Vs,{items:o,activeKey:r,onSelect:Te})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>Ne(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:Ee&&t.jsx(Ys,{pages:p??null,loading:a,renderOverlay:d})}),t.jsxs("div",{className:"bim-rd-text",id:U,ref:ce,tabIndex:-1,"data-rail":v||$?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[H,C&&se&&(se.sourceName||se.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":se.key,children:[se.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",se.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:se.sourceUrl,target:"_blank",rel:"noreferrer",children:se.sourceName}):se.sourceName]}),se.sourceName&&se.license&&t.jsx("span",{className:"bim-rd-dot"}),se.license&&t.jsxs(t.Fragment,{children:["授权 ",se.license]})]}),k&&t.jsxs("p",{className:"bim-rd-src bim-rd-rev",children:["最近校订 ",k]}),_&&(he||W)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[he?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>Te(he.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),"上一",S]}),t.jsx("span",{className:"bim-rd-pglabel",children:he.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← 已是第一",S]}),W?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>Te(W.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:["下一",S,t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:W.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:["已是最后一",S," →"]})]})]}),(v||$)&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":"本卷",children:[v,$&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:O=>O.preventDefault(),onClick:Y,children:"报告错字"})})]})]})]})]})}const Xs="guji-table-v1";function Qs(e){return!!e&&e.table_notation===Xs}const qd=/^:::table(?:\{[^}]*\})?[ \t]*$/,Jd=/^:::[ \t]*$/;function el(e){const n=[];let o="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const c=$s(e,r+3);if(c>r+4){o+=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){o+=e.slice(r,c+1),r=c;continue}}s==="|"?(n.push(o),o=""):o+=s}return n.push(o),n.map(r=>r.trim())}const Zd=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function Xd(e){if(e==="^")return{cont:!0};const n=Zd.exec(e),o=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=o==="_";return{cont:!1,cell:{text:l?"":o,empty:l,colspan:r,rowspan:s}}}function tl(e,n=1){const o=[],r=[],s=[];let l=[];e.forEach((p,a)=>{const d=a+n+1;let u=p.trim();if(!u)return;let m=!1;u.startsWith("!")&&(m=!0,u=u.slice(1));const x=el(u).map(Xd),g=l.map(j=>j>0),b=l.map(j=>j>0?j-1:0),w=[];let y=0;for(const j of x){if(j.cont){g[y]||o.push(`第 ${d} 行第 ${y+1} 列:续格 ^ 上方没有跨行格`),y+=1;continue}const{cell:h}=j;for(let v=y;v<y+h.colspan;v++)if(g[v]){o.push(`第 ${d} 行第 ${v+1} 列:此处被上方跨行格占住,应写 ^`);break}if(h.rowspan>1)for(let v=y;v<y+h.colspan;v++)b[v]=h.rowspan-1;w.push(h),y+=h.colspan}for(let j=y;j<g.length;j++)g[j]&&o.push(`第 ${d} 行第 ${j+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let j=0;j<b.length;j++)b[j]===void 0&&(b[j]=0);l=b,r.push({header:m,cells:w}),s.push({width:y,line:d})});const c=s.reduce((p,a)=>Math.max(p,a.width),0);for(const p of s)p.width!==c&&o.push(`第 ${p.line} 行:占 ${p.width} 列,与总列数 ${c} 不符`);return l.some(p=>p>0)&&o.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&o.push("空表"),{rows:r,columns:c,warnings:o}}function Ui(e){const n=e.split(`
1007
+ `),o=[];let r=[];const s=()=>{if(r.length===0)return;const c=r.join(`
1008
+ `);r=[],o.push({type:"text",text:c})};let l=0;for(;l<n.length;){if(qd.test(n[l].trim())){let c=l+1;for(;c<n.length&&!Jd.test(n[c].trim());)c++;if(c<n.length){s();const p=n.slice(l+1,c);o.push({type:"table",table:tl(p,l+1),source:n.slice(l,c+1).join(`
1009
+ `)}),l=c+1;continue}}r.push(n[l]),l++}return s(),o.map((c,p)=>{var d,u;if(c.type!=="text")return c;let a=c.text;return((d=o[p-1])==null?void 0:d.type)==="table"&&(a=a.replace(/^\n+/,"")),((u=o[p+1])==null?void 0:u.type)==="table"&&(a=a.replace(/\n+$/,"")),{type:"text",text:a}}).filter(c=>c.type!=="text"||c.text!=="")}const Qd={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},ep={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},tp=`1px solid ${i("table-border")}`,nl={border:tp,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},np={...nl,background:i("table-head-bg"),fontWeight:600};function Vi({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:Qd,children:t.jsx("table",{className:"bim-guji-table",style:ep,children:t.jsx("tbody",{children:e.rows.map((o,r)=>t.jsx("tr",{children:o.cells.map((s,l)=>{const c=o.header?"th":"td";return t.jsx(c,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:o.header?np:nl,children:s.empty?null:Ke(s.text,void 0,n)},l)})},r))})})})}function ip(e,n){return e.indexOf("**")<0?Ke(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:Ke(r.trim().slice(2,-2),void 0,n)},s):t.jsx(f.Fragment,{children:Ke(r,void 0,n)},s))}function op(e,n,o=!1){const r=o?{gujiMarkdown:!0}:void 0;return n?Ui(e).map((s,l)=>s.type==="table"?t.jsx(Vi,{table:s.table,opts:r},l):t.jsx(f.Fragment,{children:ip(s.text,r)},l)):Ke(e,void 0,r)}const rp=/^(#{1,6})\s+(.*)$/,sp=/^\*\*([^*\n]+)\*\*\s*$/;function Yi(e){const n=e.match(rp);if(n)return{level:n[1].length,text:n[2].trim()};const o=e.trim().match(sp);return o?{level:3,text:o[1].trim()}:null}const Ki=/^<!--.*-->$/;function il(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function ol(e){return e.split(`
1010
+ `).map(n=>n.trim()).filter(n=>n&&!Ki.test(n))}const lp=60;function rl(e){let n=0,o=0;for(const r of e.split(`
1011
+ `)){const s=r.trim();if(!s||Ki.test(s)||Yi(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>lp&&(o+=l)}return n>0&&o*2>=n}function ap(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function Bn(e){if(e=ap(e),rl(e))return"unknown";const n=il(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const o=n.map(s=>ol(s).length).filter(s=>s>0);if(o.length===0)return"unknown";const r=o.reduce((s,l)=>s+l,0)/o.length;return r<=4?"record":r>=8?"catalog":"unknown"}function cp(e){const n=e.split(`
883
1012
  `),o=[];let r=null,s=[];const l=()=>{o.push({heading:r,body:s.join(`
884
- `)}),s=[]};for(const d of n){const p=Li(d);if(p){l(),r={kind:"heading",level:p.level,text:p.text};continue}s.push(d)}return l(),o}function Bo(e){const n=[];for(const o of e.split(`
885
- `)){const r=Li(o);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=o.trim();!s||Bi.test(s)||n.push({kind:"body",text:o})}return n}function Ns(e){if(!e)return[];const n=zn(e);if(n==="unknown")return Bo(e);const o=[];for(const{heading:r,body:s}of hd(e)){r&&o.push(r);const l=Ts(s);if(l.length!==0){if(Rs(s)){o.push(...Bo(s));continue}if(n==="record"){const d=l.join(" ");d&&o.push({kind:"body",text:d})}else for(const d of l){const p=Es(d);p.length&&o.push({kind:"body",text:p.join(" ")})}}}return o}const Ls=e=>e;function Bs(e,n=Ls){if(e.indexOf("《")<0)return n(e);const o=[],r=/《([^《》\n]+)》/g;let s=0,l=0,d;for(;d=r.exec(e);)d.index>s&&o.push(t.jsx(g.Fragment,{children:n(e.slice(s,d.index))},l++)),o.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(d[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=d.index+d[0].length;return s===0?n(e):(s<e.length&&o.push(t.jsx(g.Fragment,{children:n(e.slice(s))},l++)),o)}function Ai(e,n={}){const o=n.renderText??Ls,r=n.properNames?l=>Bs(l,o):o,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Ue(e,r,s)}function Ao(e,n,o){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))},`${o}-${l}`):t.jsx(g.Fragment,{children:n(s)},`${o}-${l}`))}const Wn=/^(#{1,6})\s+(.*)$/,bd=/^\s*<!--.*-->\s*$/;function As(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
886
- `)?"":n)}function yd(e){return e<=1?2:e===2?3:4}function jd(){let e=1;return n=>{const o=yd(n),r=Math.min(o,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${o}`}}}function Kt(e){return e?zn(As(e))!=="unknown":!1}function Wo({text:e,mode:n,inline:o,dropTitle:r}){const s=As(e),l=(a,u,f)=>!!r&&f<=1&&a<=2&&u.trim()===r.trim(),d=jd();if(n==="paragraph"&&zn(s)!=="unknown"){const a=Ns(s);return t.jsx(t.Fragment,{children:a.map((u,f)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,f))return null;const{Tag:x,className:m}=d(u.level??1);return t.jsx(x,{className:m,children:o(u.text)},f)}return t.jsx("p",{children:Ao(u.text,o,f)},f)})})}const p=s.split(`
887
- `);let c=0;return t.jsx(t.Fragment,{children:p.map((a,u)=>{const f=a.match(Wn);if(f){const m=c++;if(l(f[1].length,f[2],m))return null;const{Tag:j,className:w}=d(f[1].length);return t.jsx(j,{className:w,children:o(f[2])},u)}if(!a.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Wn.test(p[u-1])&&!Wn.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(bd.test(a))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(a.trim())){const{Tag:m,className:j}=d(3);return t.jsx(m,{className:j,children:o(a.trim().slice(2,-2))},u)}return t.jsx("p",{children:Ao(a,o,u)},u)})})}function vd(e){const{convert:n}=Z();return g.useMemo(()=>e?n(e):"",[e,n])}function Wi({text:e,mode:n,tables:o=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:d}){const p=vd(e),{convert:c}=Z(),a=x=>Ai(x,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,f=d?c(d):void 0;return!o||p.indexOf(":::")<0?t.jsx(Wo,{text:p,mode:n,inline:a,dropTitle:f}):t.jsx(t.Fragment,{children:Ri(p).map((x,m)=>x.type==="table"?t.jsx(Ni,{table:x.table,opts:u},m):t.jsx(Wo,{text:x.text,mode:n,inline:a,dropTitle:m===0?f:void 0},m))})}function Ws(e,n){const[o,r]=g.useState(null),[s,l]=g.useState(!1),d=g.useRef(0);return g.useEffect(()=>{const p=++d.current;if(!e||!n){r(null),l(!1);return}let c;try{c=e(n)}catch{r(null),l(!1);return}if(!c||typeof c.then!="function"){r(c??null),l(!1);return}l(!0),c.then(a=>{p===d.current&&r(a??null)}).catch(()=>{p===d.current&&r(null)}).finally(()=>{p===d.current&&l(!1)})},[e,n]),{images:o,loading:s}}const Mo={A:"fine",B:"rough",C:"rough",D:"ocr"};function kd(e){return typeof e!="string"?null:e in Un?e:e in Mo?Mo[e]:null}const wd={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Sd={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function Ye(e){return typeof e!="string"?"":wd[e]??Sd[e]??e}const _d=["〇","一","二","三","四","五","六","七","八","九"],Fo=["","十","百","千"],$d=["","萬","億"];function Mi(e){if(e===0)return"〇";if(e<0)return`負${Mi(-e)}`;const n=[];let o=e,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(zd(s,r>0)+$d[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function zd(e,n){const o=[];let r=e;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let s="";for(let l=0;l<o.length;l++){const d=o[l],p=o.length-1-l;d===0?s&&!s.endsWith("〇")&&(s+="〇"):d===1&&p===1&&l===0&&!n?s+=Fo[p]:s+=_d[d]+Fo[p]}return s.replace(/〇$/,"")}let Vt=null,dn=null;const hn=new Set;function Cd(){return Vt?Promise.resolve():dn||(dn=import("opencc-js/t2cn").then(e=>{Vt=e.Converter({from:"tw",to:"cn"}),hn.forEach(n=>n())}).catch(()=>{Vt=e=>e,hn.forEach(e=>e())}),dn)}const Id=e=>e;function vt(){const[,e]=g.useState(0);return g.useEffect(()=>{if(Vt)return;const n=()=>e(o=>o+1);return hn.add(n),Cd(),()=>{hn.delete(n)}},[]),Vt??Id}function Et(e,n){return n(e).toLowerCase()}const Td=i("highlight-bg");function tn(e,n,o){if(!n)return e;const r=Et(n,o);if(!r)return e;const s=Et(e,o);if(s.length!==e.length)return e;const l=[];let d=0,p=0;for(;d<e.length;){const c=s.indexOf(r,d);if(c===-1){l.push(e.slice(d));break}c>d&&l.push(e.slice(d,c)),l.push(t.jsx("mark",{style:{background:Td,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},p++)),d=c+r.length}return t.jsx(t.Fragment,{children:l})}function Fi(e,n,o,r){if(!n)return!0;const s=Et(n,r);return(o?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(d=>typeof d=="string"&&Et(d,r).includes(s))}function Ed(e,n,o){return n?Et(e,o).includes(Et(n,o)):!0}const Pi={类:i("section-lei"),书:i("section-shu"),序:i("section-xu"),结语:i("section-jieyu"),注释:i("section-zhushi")},Rd={考证:i("section-kaozhen")};function Nd(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 Ms(e){var r;const n=e.files.length,o=((r=e.children)==null?void 0:r.reduce((s,l)=>s+Ms(l),0))||0;return n+o}function Ld(e,n){const o=[],r=d=>{var p;o.push(...d.files),(p=d.children)==null||p.forEach(r)};if(r(e),o.length===0)return;const s=o.map(d=>n[d]);if(s.every(d=>d===void 0))return;if(s.some(d=>d==="loading"))return"loading";let l=0;for(const d of s)typeof d=="number"&&(l+=d);return l}const Bd={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Oi({enabled:e,expanded:n,onClick:o,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:o,style:{...Bd,...r},children:s}):t.jsx("span",{style:r,children:s})}function Ad({type:e}){const n=Ye(e),o=Pi[n]||i("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:o,border:`1px solid ${o}40`,borderRadius:"2px",background:`${o}08`,flexShrink:0},children:n})}function Wd({section:e,onNavigate:n,highlightQuery:o="",no:r,showUnlinked:s=!1,domId:l}){const{convert:d}=Z(),p=Pe(),c=vt(),a=y=>y?Ue(d(y),k=>o?tn(k,o,c):k):"",[u,f]=g.useState(!1),x=!!e.summary,m=!!e.comment,j=!!e.additional_comment,w=!!(e.content&&e.content.length>60),h=x||m||j||w;g.useEffect(()=>{o&&f(!0)},[o]);const b=!u&&w?cs(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{className:"bim-rd-row",id:l,style:{borderBottom:`1px solid ${i("rule")}`,overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>h&&f(!u),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:h?"pointer":"default",userSelect:"none"},children:[r!=null&&t.jsx("span",{className:"bim-rd-no",style:{flex:"none",width:28,fontSize:12,color:i("label-fg")},children:r}),t.jsxs(Oi,{enabled:h,expanded:u,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[h&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),transition:"transform 0.15s",transform:u?"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:i("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",a(e.book_title),"》"]}):a(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[Mi(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:a(e.author_info||e.author)})]}),!u&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:a(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:a(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:i("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:p(e.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品","aria-label":`查看作品:${e.book_title||e.title}`,children:"作品 →"}),s&&!e.work_id&&t.jsx("span",{style:{fontSize:"11px",color:i("label-fg"),flexShrink:0},children:"未关联"})]}),u&&h&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${i("widget-border")}`,background:i("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"8px"},children:a(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${i("primary")}`,background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:a(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(e.additional_comment)})]}),w&&!x&&!m&&!j&&t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)})]})]})}function Md({section:e,highlightQuery:n=""}){const{convert:o}=Z(),r=vt(),s=c=>c?Ue(o(c),a=>n?tn(a,n,r):a):"",[l,d]=g.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(Oi,{enabled:p,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(Ad,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:s(e.title)}),p&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("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, ${Pi[Ye(e.type)]||i("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:i("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(e.content)})})]})}const Fd=100;function Di(e){return Ye(e.type)!=="page_header"?!1:(e.content||"").length>=Fd}function Pd({section:e,highlightQuery:n=""}){const{convert:o}=Z(),r=vt();if(Ye(e.type)==="page_header"&&!Di(e)||!e.content&&!e.title)return null;const s=o((e.content||e.title||"").replace(/\n{2,}/g,`
888
- `)),l=Ue(s,a=>n?tn(a,n,r):a),d=Ye(e.type),p=Pi[d]||i("desc-fg"),c=d==="序"||d==="结语"||d==="注释";return t.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:i("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${p}40`:void 0,background:c?i("bg"):void 0,borderRadius:c?"0 4px 4px 0":void 0,position:"relative"},children:[c&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:d}),l]})}function Od(e,n,o){const[r,s]=g.useState({});return g.useEffect(()=>{var a;if(!n||e.length===0)return;let l=!1;const d=e.filter(u=>{var f;return!((f=o==null?void 0:o.current)!=null&&f.has(u))}),p={};for(const u of e)(a=o==null?void 0:o.current)!=null&&a.has(u)&&(p[u]=o.current.get(u));if(Object.keys(p).length>0&&s(p),d.length===0)return;const c=async u=>{var f;try{if(n.getEntry){const h=await n.getEntry(u);if(h)return{title:h.title,author:h.author}}const x=await n.getItem(u);if(!x)return null;const m=x.title||u,j=x.authors,w=(f=j==null?void 0:j[0])==null?void 0:f.name;return{title:m,author:w}}catch{return null}};return Promise.all(d.map(async u=>{var x;const f=await c(u);return(x=o==null?void 0:o.current)==null||x.set(u,f),[u,f]})).then(u=>{l||s(f=>{const x={...f};for(const[m,j]of u)x[m]=j;return x})}),()=>{l=!0}},[e.join(","),n]),r}function Dd({section:e,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=Z(),d=Pe(),p=vt(),c=y=>y?Ue(l(y),k=>s?tn(k,s,p):k):"",[a,u]=g.useState(!1);g.useEffect(()=>{s&&u(!0)},[s]);const f=Ye(e.type),x=Rd[f]||i("desc-fg"),m=!!e.content,j=e.work_ids||[],w=j.length>1,h=Od(w?j:[],o,r),b=m&&!a&&e.content.length>80?cs(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${i("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>m&&u(!a),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:m?"pointer":"default",userSelect:"none"},children:[t.jsxs(Oi,{enabled:m,expanded:a,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:a?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg"),lineHeight:1.6},children:e.header_line?c(e.header_line):c(e.title)}),!a&&b&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:i("desc-fg"),lineHeight:1.7},children:c(b)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[j.length===1&&n&&t.jsx("a",{href:d(j[0]),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(j[0]))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),w&&t.jsxs("span",{style:{fontSize:"11px",color:i("link-fg"),flexShrink:0},children:[j.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})]})]}),w&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:j.map(y=>{const k=h[y],$=k?`${l(k.title)}${k.author?`(${l(k.author)})`:""}`:y.slice(0,8)+"…";return t.jsxs("a",{href:d(y),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(y))},style:{fontSize:"12px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",$]},y)})}),a&&m&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:i("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${i("widget-border")}`,fontSize:"12px",color:i("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:c(e.comment)})]})]})}function Hd({juan:e,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const l=vt(),d=n.trim(),p=g.useMemo(()=>d?e.sections.filter(c=>Fi(c,d,!0,l)):e.sections,[e.sections,d,l]);return t.jsxs("div",{children:[t.jsx("div",{children:p.map((c,a)=>t.jsx(Dd,{section:c,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:d},a))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Gd(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Ud({sections:e,onNavigate:n,inline:o,workLinks:r=!0}){const s=Pe(),{convert:l}=Z(),d=Gd();return t.jsx(t.Fragment,{children:e.map((p,c)=>{const a=Ye(p.type);if(a==="page_header"&&!Di(p))return null;if(a==="类")return t.jsxs(g.Fragment,{children:[g.createElement(d("类"),null,o(l(p.title))),p.content&&t.jsx("p",{children:o(l(p.content))})]},c);if(a==="书"||a==="诗"||a==="考证"||a==="注释"){const u=p.book_title?`《${p.book_title}》${p.n_juan!=null?Mi(p.n_juan)+"卷":""}`:p.title,f=o(l(u));return t.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${c}`,children:[g.createElement(d("条目"),{className:"bim-rd-entry-h"},p.work_id&&n&&r?t.jsxs(t.Fragment,{children:[t.jsx("a",{href:s(p.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),n(p.work_id))},title:"查看作品",children:f}),t.jsx("a",{className:"bim-rd-wl",href:s(p.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),n(p.work_id))},"aria-label":`查看作品:${u}`,children:"作品 →"})]}):f),p.author_info&&t.jsx("p",{className:"bim-rd-sub",children:o(l(p.author_info))}),p.content&&p.content.split(/\n+/).map((x,m)=>t.jsx("p",{children:o(l(x))},m)),p.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),o(l(p.summary))]}),p.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),o(l(p.comment))]}),p.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),o(l(p.additional_comment))]})]},c)}return p.content?t.jsx("p",{children:o(l(p.content))},c):null})})}function Fs(e){return e.some(n=>{const o=Ye(n.type);return o==="书"||o==="诗"||o==="考证"||o==="注释"||o==="类"||(o==="序"||o==="结语")&&!!n.content||o==="page_header"&&Di(n)})}function Vd({juan:e,rawText:n,positionLabel:o,index:r,searchQuery:s,onNavigate:l,transport:d,workLabelCache:p,prefs:c,view:a,onViewChange:u}){var E;const{convert:f}=Z(),x=vt(),[m,j]=g.useState("text"),w=a??m,h=ee=>{j(ee),u==null||u(ee)},b=s.trim(),y=(r==null?void 0:r.type)==="kaozhen",k=g.useCallback(ee=>b?tn(ee,b,x):ee,[b,x]),$=ee=>Ai(ee,{renderText:k,properNames:c.properNames}),v=g.useMemo(()=>b?e.sections.filter(ee=>Fi(ee,b,y,x)):e.sections,[e.sections,b,y,x]),_=(ee,F)=>F.filter(K=>Ye(K.type)===ee).length,S=_("书",e.sections),z=_("诗",e.sections),N=_("考证",e.sections);let T="";y?T=b?`${_("考证",v)} / ${N} ${f("條")}`:`${N} ${f("條")}`:z>0?T=b?`${_("诗",v)} / ${z} 首`:`${z} 首`:S>0&&(T=b?`${_("书",v)} / ${S} ${f("部書")}`:`${S} ${f("部書")}`);const C=r!=null&&r.text_quality?kd(r.text_quality.grade):null,D=[];o&&D.push(o),T&&D.push(T),y&&(r!=null&&r.target_source)&&D.push(t.jsxs(t.Fragment,{children:[f("考證對象")," ",f(r.target_source)]})),C&&D.push(t.jsx("span",{title:Ol[C],children:(E=r==null?void 0:r.text_quality)!=null&&E.source_note?t.jsxs(t.Fragment,{children:["底本 ",f(r.text_quality.source_note),t.jsx("span",{className:"bim-rd-grade",children:f(Un[C])})]}):t.jsxs(t.Fragment,{children:[f("文本質量"),t.jsx("span",{className:"bim-rd-grade",children:f(Un[C])})]})})),e.source_url&&D.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:f("原文來源")}));const B=!y&&Fs(e.sections),O=!!n&&(!B||c.readingMode==="paragraph"&&Kt(n)),M=!y&&(B||!!n),X=y||!M?"entries":w;let Y=0;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:f(e.title)}),D.length>0&&t.jsx("p",{className:"bim-rd-meta",children:D.map((ee,F)=>t.jsxs(g.Fragment,{children:[F>0&&t.jsx("span",{className:"bim-rd-dot"}),ee]},F))}),M&&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":X==="text",onClick:()=>h("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":X==="entries",onClick:()=>h("entries"),children:f("條目")})]})]}),X==="text"&&t.jsx("article",{className:"bim-rd-prose",children:O?t.jsx(Wi,{text:n,mode:c.readingMode,properNames:c.properNames,renderText:k,dropTitle:e.title}):t.jsx(Ud,{sections:e.sections,onNavigate:l,inline:$,workLinks:c.workLinks})}),X==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:y?t.jsx(Hd,{juan:e,searchQuery:s,onNavigate:l,transport:d,workLabelCache:p}):t.jsxs(t.Fragment,{children:[v.some(ee=>["书","诗","考证"].includes(Ye(ee.type)))&&t.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[t.jsx("span",{style:{width:28},children:"序"}),t.jsx("span",{style:{flex:1},children:"书名"}),t.jsx("span",{children:"作品"})]}),v.map((ee,F)=>{const K=Ye(ee.type);return K==="书"||K==="诗"||K==="考证"?(Y+=1,t.jsx(Wd,{domId:`rd-e-${e.sections.indexOf(ee)}`,section:ee,onNavigate:c.workLinks?l:void 0,highlightQuery:b,no:Y,showUnlinked:c.workLinks&&!!l},F)):K==="类"?t.jsx(Md,{section:ee,highlightQuery:b},F):t.jsx(Pd,{section:ee,highlightQuery:b},F)}),v.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function Ps(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 Yd(e){const n=Ps(e);return n.length>0?n[0]:null}function Kd(e){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:l,activeRawText:d,query:p,isKaozhen:c}=e,a=vt(),u=g.useRef(new Map),[f,x]=g.useState({}),[m,j]=g.useState({}),w=g.useCallback((b,y)=>{const k=y==null?void 0:y.title;k&&j($=>$[b]===k?$:{...$,[b]:k})},[]);g.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:d}),w(s,l))},[s,l,d,w]),g.useEffect(()=>{u.current.clear(),x({}),j({})},[n]);const h=g.useCallback((b,y)=>{let k=0;if(b.juan)for(const $ of b.juan.sections)Fi($,y,c,a)&&k++;return k===0&&b.rawText&&Ed(b.rawText,y,a)&&(k=1),k},[c,a]);return g.useEffect(()=>{const b=p.trim();if(!b){x({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let y=!1;const k={},$=[];for(const N of r){const T=u.current.get(N);T?k[N]=h(T,b):(k[N]="loading",$.push(N))}x(k);const v=8;let _=0;const S=async()=>{var N;for(;_<$.length;){if(y)return;const T=_++,C=$[T];try{const[D,B]=await Promise.all([o.getCollatedJuan(n,C),((N=o.getCollatedJuanText)==null?void 0:N.call(o,n,C))??Promise.resolve(null)]),O={juan:D,rawText:B};if(u.current.set(C,O),w(C,D),y)return;x(M=>({...M,[C]:h(O,b)}))}catch{if(y)return;x(D=>({...D,[C]:0}))}}},z=Array.from({length:Math.min(v,$.length)},()=>S());return Promise.all(z),()=>{y=!0}},[p,n,o,r.join(","),h,a,w]),{matchStates:f,titles:m}}function qd({juan:e,view:n,onView:o,textHasEntries:r}){const{convert:s}=Z(),l=e.sections.map((a,u)=>({s:a,i:u,t:Ye(a.type)})).filter(a=>a.t==="书"||a.t==="诗");if(l.length===0)return null;const d=l.filter(a=>!!a.s.work_id).length,p=l.every(a=>a.t==="诗")?"首":"部书",c=a=>{const u=()=>{var f,x;return(x=(f=document.getElementById(`rd-e-${a}`))==null?void 0:f.scrollIntoView)==null?void 0:x.call(f,{block:"start",behavior:"smooth"})};n==="text"&&!r&&o("entries"),n==="text"&&!r?setTimeout(u,0):u()};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-rd-rail-card",children:[t.jsx("div",{className:"bim-rd-rail-cap",children:"本卷"}),t.jsxs("div",{className:"bim-rd-rail-n",children:[t.jsx("b",{children:l.length}),t.jsx("span",{children:s(p)}),t.jsxs("span",{className:"bim-rd-rail-linked",children:["已关联 ",d]})]}),t.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":`已关联 ${d} / ${l.length}`,children:t.jsx("span",{style:{width:`${Math.round(d/l.length*100)}%`}})})]}),t.jsxs("nav",{"aria-label":"本卷条目",children:[t.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:s("條目")}),t.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:a,i:u})=>t.jsx("li",{children:t.jsxs("a",{href:`#rd-e-${u}`,onClick:f=>{f.preventDefault(),c(u)},children:[t.jsx("span",{className:`bim-rd-rail-dot${a.work_id?" on":""}`,"aria-hidden":"true"}),t.jsx("span",{children:s(a.book_title||a.title)})]})},u))})]})]})}function Jd(e,n){const[o,r]=g.useState([]);return g.useEffect(()=>{if(r([]),!e||typeof(n==null?void 0:n.getItem)!="function")return;let s=!1;return Promise.resolve(n.getItem(e)).then(l=>{if(s||!l)return;const d=l.authors??[];r(d.filter(p=>p&&p.name))}).catch(()=>{}),()=>{s=!0}},[e,n]),o}const Hi=({index:e,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:l,className:d,style:p,title:c,subtitle:a,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m})=>{const[j,w]=g.useState(null),[h,b]=g.useState(!1),[y,k]=g.useState(null),[$,v]=g.useState(null),[_,S]=g.useState(null),[z,N]=g.useState(!1),[T,C]=g.useState(null),[D,B]=g.useState(""),O=g.useRef(new Map),M=g.useRef(0),X=s??$,Y=g.useCallback(Q=>{v(Q),l==null||l(Q)},[l]),E=e||j;g.useEffect(()=>{e&&(b(!1),k(null))},[e]),g.useEffect(()=>{if(e||!n||!(o!=null&&o.getCollatedEditionIndex))return;let Q=!1;return b(!0),k(null),o.getCollatedEditionIndex(n).then(ie=>{Q||(ie?w(ie):k("未找到整理本数据"))}).catch(ie=>{Q||k(ie instanceof Error?ie.message:"加载失败")}).finally(()=>{Q||b(!1)}),()=>{Q=!0}},[e,n,o]),g.useEffect(()=>{if(E&&!X){const Q=Yd(E);Q&&Y(Q)}},[E,X,Y]);const ee=n||(E==null?void 0:E.work_id),F=g.useCallback(async Q=>{var ge;if(!ee||!(o!=null&&o.getCollatedJuan))return;const ie=++M.current;N(!0),S(null),C(null);try{const[re,le]=await Promise.all([o.getCollatedJuan(ee,Q),((ge=o.getCollatedJuanText)==null?void 0:ge.call(o,ee,Q))??Promise.resolve(null)]);if(ie!==M.current)return;S(re),C(le)}catch{if(ie!==M.current)return;S(null),C(null)}finally{ie===M.current&&N(!1)}},[ee,o]);g.useEffect(()=>{X&&F(X)},[X,F]);const K=Q=>{Y(Q)};if(h)return t.jsx("div",{className:d,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(y)return t.jsx("div",{className:d,style:{...p,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:y});if(!E)return null;const ae=E.type==="kaozhen",ne=Ps(E);return t.jsx(Xd,{className:d,style:p,index:E,allFiles:ne,isKaozhen:ae,effectiveWorkId:ee,transport:o,activeFile:X,handleSelectFile:K,juanData:_,juanRawText:T,juanLoading:z,searchQuery:D,setSearchQuery:B,onNavigate:r,workLabelCacheRef:O,reader:{title:c,subtitle:a,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m}})};function oi(e,n,o,r){var a,u,f,x;const s=(u=(a=n.juan_metadata)==null?void 0:a[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:Nd(e)),p=((x=(f=n.files)==null?void 0:f.find(m=>m.filename===e))==null?void 0:x.title)??o[e];if(!p)return{position:l,label:l};const c=r(p);return{position:l,label:l===p||l===c?c:`${l} ${c}`}}function Zd(e,n,o,r,s){const l=c=>c==="loading"?"…":typeof c=="number"&&c>0?c:void 0,d=(c,a)=>({key:c,label:a??oi(c,e,r,s).label,hint:l(o[c]),disabled:o[c]===0}),p=(c,a)=>{var f;if(c.files.length===1&&!((f=c.children)!=null&&f.length))return d(c.files[0],s(c.label));const u=Ld(c,o);return{key:`group:${a}`,label:s(c.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:Ms(c),defaultExpanded:typeof u=="number"&&u>0,children:[...c.files.map(x=>d(x)),...(c.children??[]).map((x,m)=>p(x,`${a}.${m}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((c,a)=>p(c,`${a}`)):n.map(c=>d(c))}const Xd=({className:e,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:d,activeFile:p,handleSelectFile:c,juanData:a,juanRawText:u,juanLoading:f,searchQuery:x,setSearchQuery:m,onNavigate:j,workLabelCacheRef:w,reader:h})=>{const{convert:b}=Z(),[y,k]=Ti(),[$,v]=g.useState("text");g.useEffect(()=>{v("text")},[p]);const{matchStates:_,titles:S}=Kd({workId:l,transport:d,files:r,activeFile:p,activeJuan:a,activeRawText:u,query:x,isKaozhen:s}),z=Ws(h.resolveImages,p),N=g.useMemo(()=>Zd(o,r,_,S,b),[o,r,_,S,b]),T=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:K=>m(K.target.value)}),C=s?"章":o.juan_metadata&&Object.values(o.juan_metadata).some(K=>K.vol_label)?"冊":"卷",D=p?oi(p,o,S,b).position:void 0,B=Pe(),O=h.title??(o.title?b(o.title):void 0),M=O&&l&&j?t.jsx("a",{href:B(l),onClick:K=>{K.metaKey||K.ctrlKey||(K.preventDefault(),j(l))},title:"查看作品",children:O}):O,X=!!a&&!s&&Fs(a.sections),Y=X&&!(u&&y.readingMode==="paragraph"&&Kt(u)),E=a&&!s&&X?t.jsx(qd,{juan:a,view:$,onView:v,textHasEntries:Y}):void 0,ee=Jd(l,d),F=ee.length>0?b(ee.slice(0,2).map(K=>`${K.dynasty?`〔${K.dynasty}〕`:""}${K.name}${K.role?` ${K.role}`:" 撰"}`).join("、")):void 0;return t.jsxs(Ei,{className:e,style:n,title:M,subtitle:h.subtitle??b(s?"考證":"整理本"),byline:F,pagerUnit:C,rail:E,current:p?oi(p,o,S,b).label:void 0,workLinkToggle:!s&&!!j&&!!(a!=null&&a.sections.some(K=>K.work_id)),toc:N,tocCaption:`目录 · ${r.length} ${b(C)}`,tocHeader:T,activeKey:p,onSelect:c,images:z.images,imagesLoading:z.loading,renderImageOverlay:h.renderImageOverlay,imagePanel:h.imagePanel,prefs:y,onPrefsChange:k,paragraphToggle:!s&&Kt(u),allowVertical:h.allowVertical,children:[f?t.jsx(jt,{}):a?t.jsx(Vd,{juan:a,rawText:u,positionLabel:D,index:o,searchQuery:x,onNavigate:j,transport:d,workLabelCache:w,prefs:y,view:$,onViewChange:v},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,o.references&&o.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:b("參考文獻")}),t.jsx("ol",{children:o.references.map((K,ae)=>t.jsxs("li",{children:[K.url?t.jsx("a",{className:"bim-rd-link",href:K.url,target:"_blank",rel:"noopener noreferrer",children:K.title}):t.jsx("span",{children:K.title}),K.author&&t.jsxs("span",{children:[",",K.author]}),K.note&&t.jsxs("span",{children:["。",K.note]})]},ae))})]})]})},Qd={bug:{label:"错误反馈",color:i("danger")},resource:{label:"资源建议",color:i("primary")},suggestion:{label:"功能建议",color:i("primary")},other:{label:"其他",color:i("desc-fg")}},ep={label:"其他",color:i("desc-fg")},tp={pending:{label:"待处理",color:i("warning")},in_progress:{label:"处理中",color:i("primary")},resolved:{label:"已处理",color:i("success")},wontfix:{label:"不采纳",color:i("desc-fg")},duplicate:{label:"重复",color:i("desc-fg")}},np={label:"待处理",color:i("warning")};function ip(e){try{const n=new Date(e),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return e}}function op(e,n){if(!e)return!1;try{const o=new URL(e,n);if(o.protocol!=="http:"&&o.protocol!=="https:")return!1;const r=new URL(n);return o.hostname===r.hostname}catch{return!1}}const Gi=({items:e,loading:n})=>{const o=Pe();return n?t.jsx(jt,{}):e.length===0?t.jsx("div",{style:rp,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Qd[r.type]||ep,l=tp[r.status]||np,d=typeof window<"u"&&op(r.pageUrl,window.location.href);return t.jsxs("div",{style:sp,children:[t.jsxs("div",{style:lp,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Po,background:s.color},children:s.label}),t.jsx("span",{style:{...Po,background:l.color},children:l.label})]}),t.jsx("span",{style:ap,children:ip(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:cp,children:[r.resourceId&&t.jsx("a",{href:o(r.resourceId),style:Mn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(d?t.jsx("a",{href:r.pageUrl,style:Mn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Mn,children:r.pageUrl}))]}),t.jsx("div",{style:dp,children:r.content}),r.reply&&t.jsxs("div",{style:pp,children:[t.jsx("div",{style:up,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},rp={textAlign:"center",padding:"40px 0",color:i("desc-fg"),fontSize:"14px"},sp={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"16px"},lp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Po={fontSize:"12px",color:i("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},ap={fontSize:"12px",color:i("desc-fg")},cp={fontSize:"12px",marginBottom:"6px"},Mn={color:i("primary"),textDecoration:"none",borderBottom:`1px dashed ${i("primary")}`},dp={fontSize:"14px",lineHeight:"1.6",color:i("fg"),whiteSpace:"pre-wrap"},pp={marginTop:"12px",padding:"10px 12px",background:i("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:i("fg")},up={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:i("primary")},ri=({transport:e,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const d=ue(),[p,c]=g.useState(null),[a,u]=g.useState([]),[f,x]=g.useState("recommend"),[m,j]=g.useState([]),[w,h]=g.useState(!1),b=r??f,y=M=>{x(M),s==null||s(M)},[k,$]=g.useState(!0),[v,_]=g.useState(null),[S,z]=g.useState(null),[N,T]=g.useState(null);g.useEffect(()=>{let M=!1;if(e.getCounts)return e.getCounts().then(X=>{M||c({works:X.works,books:X.books,collections:X.collections})}).catch(()=>{}),()=>{M=!0}},[e]),g.useEffect(()=>{let M=!1;return(async()=>{if(o)return o;if(e.getRecommended)try{const Y=await e.getRecommended();if(Y!=null&&Y.groups)return Y.groups.flatMap(E=>E.items.map(ee=>({...ee,group:E.name})))}catch{}return[]})().then(async Y=>{if(M)return;const E=Y.filter(F=>F.id);if(E.length===0){$(!1);return}const ee=await Promise.all(E.map(async F=>{if(F.type)return{id:F.id,title:F.title,type:F.type,author:F.author,dynasty:F.dynasty,role:F.role,edition:F.edition,has_text:F.has_text,has_image:F.has_image,has_collated:F.has_collated,subtype:F.subtype,primary_name:F.primary_name,group:F.group,fallbackDescription:F.description};try{let K=null;if(e.getEntry)K=await e.getEntry(F.id);else{const ae=await e.getItem(F.id);ae&&(K={id:F.id,title:ae.title||F.id,type:ae.type||"work"})}if(K)return{...K,group:F.group,fallbackDescription:F.description}}catch{}return{id:F.id,title:F.title,type:we.extractType(F.id),group:F.group,fallbackDescription:F.description}}));M||(u(ee.filter(F=>F!==null)),$(!1))}),()=>{M=!0}},[e,o]);const C=g.useRef(!1),D=g.useRef(!1),B=g.useRef(!1);g.useEffect(()=>{if(b!=="catalog"||C.current)return;const M=e.getCatalogProgress??e.getResourceProgress;if(!M)return;C.current=!0;let X=!1;return M.call(e).then(Y=>{X||_(Y)}).catch(()=>{C.current=!1}),()=>{X=!0}},[e,b]),g.useEffect(()=>{if(b!=="collection"||D.current||!e.getCollectionProgress)return;D.current=!0;let M=!1;return e.getCollectionProgress().then(X=>{M||z(X)}).catch(()=>{D.current=!1}),()=>{M=!0}},[e,b]),g.useEffect(()=>{if(b!=="site"||B.current||!e.getSiteProgress)return;B.current=!0;let M=!1;return e.getSiteProgress().then(X=>{M||T(X)}).catch(()=>{B.current=!1}),()=>{M=!0}},[e,b]),g.useEffect(()=>{if(!l||b!=="feedback")return;let M=!1;return h(!0),fetch(l).then(X=>X.json()).then(X=>{!M&&X.success&&j(X.items||[])}).catch(()=>{}).finally(()=>{M||h(!1)}),()=>{M=!0}},[l,b]);const O=M=>t.jsx(vn,{type:M,size:12});return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:i("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"16px"},children:[t.jsx(Ft,{label:d.home.recommendTab,active:b==="recommend",onClick:()=>y("recommend")}),t.jsx(Ft,{label:d.home.catalogTab,active:b==="catalog",onClick:()=>y("catalog")}),t.jsx(Ft,{label:d.home.collectionTab,active:b==="collection",onClick:()=>y("collection")}),t.jsx(Ft,{label:d.home.siteTab,active:b==="site",onClick:()=>y("site")}),l&&t.jsx(Ft,{label:d.home.feedbackTab,active:b==="feedback",onClick:()=>y("feedback")})]}),b==="recommend"&&t.jsx(xp,{recommended:a,loading:k,onNavigate:n,getIcon:O,t:d}),b==="catalog"&&t.jsx(Oo,{progress:v,t:d,onNavigate:n}),b==="collection"&&t.jsx(Oo,{progress:S,t:d,onNavigate:n}),b==="site"&&t.jsx(gp,{progress:N,t:d,totalWorks:(p==null?void 0:p.works)??0}),b==="feedback"&&l&&t.jsx(Gi,{items:m,loading:w})]})})},Ft=({label:e,active:n,onClick:o})=>t.jsx("button",{onClick:o,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:i(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${i("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),xp=({recommended:e,loading:n,onNavigate:o,getIcon:r,t:s})=>{const l=Pe();if(n)return t.jsx(jt,{});if(e.length===0)return null;const d=new Map;for(const p of e){const c=p.group||s.home.recommendedBrowse;d.has(c)||d.set(c,[]),d.get(c).push(p)}return t.jsx(t.Fragment,{children:Array.from(d.entries()).map(([p,c])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:p}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(a=>{const u=a.dynasty||a.author?`${a.dynasty?`〔${a.dynasty}〕`:""}${a.author||""}`:a.fallbackDescription;return t.jsxs("a",{href:l(a.id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),o==null||o(a.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,cursor:"pointer",background:i("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(a.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[a.title,a.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:a.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},a.id)})})]},p))})},Oo=({progress:e,t:n,onNavigate:o})=>{if(!e)return t.jsx(jt,{});const r=[...e.resources].sort((p,c)=>p.priority-c.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},d={in_progress:i("progress-active"),done:i("progress-done"),todo:i("progress-todo")};return t.jsx("div",{children:s.map(p=>{const c=r.filter(a=>a.status===p);return c.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:d[p]}}),l[p]," (",c.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(a=>t.jsx(fp,{item:a,t:n,statusColor:d[p],onNavigate:o},a.id))})]},p)})})},fp=({item:e,t:n,statusColor:o,onNavigate:r})=>{const s=Pe(),l=e.total>0?Math.round(e.imported/e.total*100):0,d=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=e.edition?`${e.name}·${e.edition}`:e.name,c=e.collection_id||e.work_id;return c&&r?t.jsx("a",{href:s(c),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},onMouseEnter:a=>a.currentTarget.style.borderBottomStyle="solid",onMouseLeave:a=>a.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:i("widget-border"),color:i("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:d})]}),t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Jt(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:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:o,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:e.description})]})},gp=({progress:e,t:n,totalWorks:o})=>{if(!e)return t.jsx(jt,{});const r=[...e.resources].sort((c,a)=>c.priority-a.priority),s=r.filter(c=>c.imported>0),l=r.filter(c=>c.imported===0),d=s.reduce((c,a)=>Math.max(c,a.imported),0),p=o>0?Math.round(d/o*100):0;return t.jsxs("div",{children:[o>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${i("primary")} 6%, transparent)`,fontSize:"13px",color:i("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:d.toLocaleString()})," / ",o.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:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>t.jsx(Do,{item:c,t:n,totalWorks:o},c.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(c=>t.jsx(Do,{item:c,t:n,totalWorks:o},c.id))})]})]})},Do=({item:e,t:n,totalWorks:o})=>{const r=o>0?Math.round(e.imported/o*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("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:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&o>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:i("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:e.description})]})},Ho="(max-width: 768px)";function mp(){const[e,n]=g.useState(()=>typeof window>"u"?!1:window.matchMedia(Ho).matches);return g.useEffect(()=>{const o=window.matchMedia(Ho),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),e}const hp=({transport:e,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var X;const l=ue(),{convert:d}=Z(),p=mp(),[c,a]=g.useState(null),[u,f]=g.useState(null),[x,m]=g.useState(!1),[j,w]=g.useState("detail"),[h,b]=g.useState([]),[y,k]=g.useState(!1),[$,v]=g.useState(null),[_,S]=g.useState(!1),z=g.useCallback(async Y=>{if(!e.getCollatedEditionIndex){v(null);return}S(!0);try{const E=await e.getCollatedEditionIndex(Y);v(E)}catch{v(null)}finally{S(!1)}},[e]),N=g.useCallback(async Y=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){b([]);return}k(!0);try{if(e.getCollectionCatalogs){const E=await e.getCollectionCatalogs(Y);b(E||[])}else if(e.getCollectionCatalog){const E=await e.getCollectionCatalog(Y);b(E?[{resource_id:"",data:E}]:[])}}catch{b([])}finally{k(!1)}},[e]),T=g.useCallback(async Y=>{if(o){o(Y);return}a(Y),f(null),b([]),v(null),w("detail"),m(!0);try{const E=await e.getItem(Y.id);E&&(f(E),E.type==="collection"?N(Y.id):E.type==="work"&&E.has_collated&&z(Y.id))}catch(E){console.error("加载详情失败:",E)}finally{m(!1)}},[e,o,N,z]),C=g.useCallback(async Y=>{f(null),b([]),v(null),w("detail"),m(!0);try{const E=await e.getItem(Y);E&&(f(E),a({id:Y,title:E.title||Y,type:E.type||"book"}),E.type==="collection"?N(Y):E.type==="work"&&E.has_collated&&z(Y))}catch(E){console.error("导航失败:",E)}finally{m(!1)}},[e,N,z]),D=(u==null?void 0:u.type)==="collection"&&(h.length>0||y)||(u==null?void 0:u.type)==="work"&&($||_),B=p&&(x||u),O=g.useCallback(()=>{a(null),f(null),b([]),v(null),w("detail")},[]),M=t.jsx(t.Fragment,{children:x?t.jsx(jt,{}):u?t.jsxs(t.Fragment,{children:[(D||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${i("widget-border")}`,padding:p?"0 12px":"0 48px",background:i("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[D&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>w("detail"),style:pn(j==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&y&&h.length===0&&t.jsxs("button",{onClick:()=>{},style:pn(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&h.map(Y=>t.jsx("button",{onClick:()=>w(`catalog:${Y.resource_id}`),style:pn(j===`catalog:${Y.resource_id}`),children:Y.short_name?`${d(Y.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},Y.resource_id)),u.type==="work"&&($||_)&&t.jsxs("button",{onClick:()=>w("collated"),style:pn(j==="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:j==="detail"?t.jsx(bi,{data:u,transport:e,onNavigate:C}):j.startsWith("catalog:")?t.jsx(yi,{data:(X=h.find(Y=>`catalog:${Y.resource_id}`===j))==null?void 0:X.data,onNavigate:C}):j==="collated"?t.jsx(Hi,{index:$||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(ri,{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:i("bg"),color:i("fg")},children:B?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${i("widget-border")}`,background:i("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:O,style:{padding:"4px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:M})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Yn,{transport:e,onEntryClick:T,hideModeIndicator:n}),!u&&t.jsx(ri,{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:i("bg"),color:i("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${i("widget-border")}`,display:"flex",flexDirection:"column",background:i("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(Yn,{transport:e,onEntryClick:T,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:i("bg"),display:"flex",flexDirection:"column"},children:M})]})};function pn(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function ut(e){return e.replace(/\.md$/,"")}function Go(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 Uo={padding:24,color:i("desc-fg")},si=({index:e,bookId:n,transport:o,activeChapter:r,onChapterChange:s,workKey:l,versions:d,onVersionChange:p,title:c,subtitle:a,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m,className:j,style:w})=>{const[h,b]=g.useState(e??null),[y,k]=g.useState(!1),[$,v]=g.useState(null),_=r!==void 0?r:$,S=g.useCallback(ne=>{s?s(ne):v(ne)},[s]),[z,N]=g.useState(null),[T,C]=g.useState(!1);g.useEffect(()=>{e&&b(e)},[e]),g.useEffect(()=>{if(e)return;b(null),k(!1);const ne=l!==void 0?o.getWorkFullTextIndex?()=>o.getWorkFullTextIndex(n,l):null:o.getBookFullTextIndex?()=>o.getBookFullTextIndex(n):null;if(!n||!ne){k(!0);return}let Q=!1;return Promise.resolve().then(ne).then(ie=>{Q||(ie?b(ie):k(!0))}).catch(()=>{Q||k(!0)}),()=>{Q=!0}},[n,o,e,l]),g.useEffect(()=>{if(!h||h.chapters.length===0)return;const ne=ut(h.chapters[0].file);if(!_){S(ne);return}const Q=ut(_);h.chapters.some(ge=>ut(ge.file)===Q)||S(ne)},[h,_,S]);const D=g.useMemo(()=>{if(!h||!_)return null;const ne=ut(_);return h.chapters.find(Q=>ut(Q.file)===ne)??null},[h,_]);g.useEffect(()=>{if(!n||!D)return;const ne=l!==void 0?o.getWorkFullTextChapter?ie=>o.getWorkFullTextChapter(n,l,ie):null:o.getBookFullTextChapter?ie=>o.getBookFullTextChapter(n,ie):null;if(!ne)return;let Q=!1;return C(!0),N(null),Promise.resolve(D.file).then(ne).then(ie=>{Q||N(ie)}).catch(()=>{Q||N(null)}).finally(()=>{Q||C(!1)}),()=>{Q=!0}},[n,D,o,l]);const B=Ws(u,D?ut(D.file):null),[O,M]=Ti(),{convert:X}=Z(),Y=!!(d&&d.length>1&&p),E=g.useMemo(()=>Y?ks(d).map((ne,Q)=>({...ne,label:Go(d[Q])})):void 0,[Y,d]),ee=Y?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:ne=>p(ne.target.value),children:d.map(ne=>t.jsx("option",{value:ne.key,children:Go(ne)},ne.key))})]}):null;if(!h)return t.jsxs("div",{style:Uo,children:[ee&&t.jsx("div",{style:{marginBottom:12},children:ee}),y?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:Uo,children:[ee&&t.jsx("div",{style:{marginBottom:12},children:ee}),"全文目录为空"]});const F=h.chapters.map(ne=>({key:ut(ne.file),label:X(ne.title)})),K=$s(h)||Jn(h),ae=z?z.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(Ei,{title:c??X(h.version_label),subtitle:a??"全文",toc:F,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:_?ut(_):null,onSelect:S,images:B.images,imagesLoading:B.loading,renderImageOverlay:f,imagePanel:x,prefs:O,onPrefsChange:M,versions:E,currentVersionKey:E?l??null:void 0,onVersionChange:E?p:void 0,versionSource:!1,paragraphToggle:Kt(ae),allowVertical:m,className:j,style:w,children:[D&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:X(D.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:h.source.url,target:"_blank",rel:"noreferrer",children:X(h.source.name)}),h.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),h.source.license]})]})]}),T&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!T&&ae!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Wi,{text:ae,mode:O.readingMode,tables:K,gujiMarkdown:Jn(h),properNames:O.properNames})}),!T&&!z&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},bp=({data:e,onNavigate:n,className:o,style:r})=>{var u;const s=ue(),{convert:l}=Z(),[d,p]=g.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[c,a]=g.useState(null);return t.jsxs("div",{className:o,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:l(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:i("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(yp,{division:f,expanded:d===f.name,onToggle:()=>p(d===f.name?null:f.name),expandedCat:c,onCatToggle:x=>a(c===x?null:x),onNavigate:n},f.name))})]})},yp=({division:e,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:d}=Z(),p=e.categories.reduce((c,a)=>{const u=a.stats||{zhulu:0,cunmu:0};return c+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${i("primary")} 6%, transparent)`:i("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:i("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg")},children:[e.categories.length," 類 · ",p," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(c=>{const a=`${e.name}/${c.name}`;return t.jsx(jp,{category:c,expanded:r===a,onToggle:()=>s(a),onNavigate:l},c.name)})})]})},jp=({category:e,expanded:n,onToggle:o,onNavigate:r})=>{var c,a,u,f;const{convert:s}=Z(),l=((c=e.books)==null?void 0:c.zhulu)||[],d=((a=e.books)==null?void 0:a.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((f=e.stats)==null?void 0:f.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?i("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:i("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||d.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Vo,{label:"著錄",books:l,onNavigate:r}),d.length>0&&t.jsx(Vo,{label:"存目",books:d,onNavigate:r})]})]})},Vo=({label:e,books:n,onNavigate:o})=>{const{convert:r}=Z(),s=Pe(),[l,d]=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:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((c,a)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:i("fg")},children:c.work_id&&o?t.jsx("a",{href:s(c.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),o(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},children:r(c.title)}):r(c.title)}),c.volumes&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:r(c.volumes)}),c.author&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:r(c.author).slice(0,20)})]},a))}),!l&&t.jsxs("button",{onClick:()=>d(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},qe=({title:e,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const l=ue();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("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 ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:i("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&t.jsx("button",{onClick:o,style:kp,children:"AI"}),n&&t.jsx("button",{onClick:n,style:vp,children:l.action.save})]})]}),s]})},vp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},kp={padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Ge=({label:e,value:n,onChange:o,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:l=>o(l.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),bt=({value:e,onChange:n,placeholder:o})=>{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:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},bn=({children:e,color:n,style:o})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||i("primary-soft"),color:i(n?"on-color-fg":"fg"),...o},children:e});function wp(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const xn=({value:e,onChange:n,label:o})=>{const[r,s]=g.useState(!1),l=g.useRef(null),d=wp(e||"");return g.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&d?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Yo,children:o}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${i("input-border")}`,borderRadius:"2px",background:i("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:i("fg")},children:d.name}),t.jsx(bn,{children:d.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Yo,children:o}),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:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Yo={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500};function Sp(e){switch(e){case"url":return i("source-url");case"bookID":return i("source-bookid");default:return i("desc-fg")}}function _p(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Os=({items:e,onChange:n,onOpenEntityPicker:o})=>{const r=ue(),[s,l]=g.useState(null),d=()=>{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)},c=(f,x,m)=>{const j=[...e];j[f]={...j[f],[x]:m},n(j)},a=(f,x)=>{const m=[...e];m[f]={...m[f],type:x,id:"",name:""},n(m),x==="bookID"&&o&&o(j=>{const w=[...e];w[f]={...w[f],id:j.id,name:j.title,type:"bookID"},n(w)})},u=f=>{o&&o(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 ${i("widget-border")}`,borderRadius:"4px",background:i("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:i("fg")},children:f.name||`${r.editor.sourcePlaceholder} ${x+1}`}),f.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Sp(f.type),color:i("on-color-fg"),borderRadius:"3px",fontWeight:500},children:_p(f.type)}),t.jsx("button",{onClick:m=>{m.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===x&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!f.type&&t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>a(x,"bookID"),style:{...Ko,borderColor:i("source-bookid"),color:i("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>a(x,"url"),style:{...Ko,borderColor:i("source-url"),color:i("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:ot,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:qo,children:r.action.changeType})]}),f.id&&f.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:i("bg"),border:`1px solid ${i("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:i("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:i("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:f.id})]}),t.jsx("button",{onClick:()=>u(x),style:{background:"transparent",border:`1px solid ${i("widget-border")}`,color:i("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 ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("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:ot,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:qo,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:f.name,onChange:m=>c(x,"name",m.target.value),placeholder:r.editor.sourceNamePlaceholder,style:wt})]}),t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:f.id,onChange:m=>c(x,"id",m.target.value),placeholder:"https://...",style:wt})]})]}),f.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${i("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...ot,opacity:.7},children:r.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:f.details,onChange:m=>c(x,"details",m.target.value),placeholder:r.editor.detailsPlaceholder,style:wt})]}),t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:f.position,onChange:m=>c(x,"position",m.target.value),placeholder:"如: 卷三, p.52",style:wt})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:f.version,onChange:m=>c(x,"version",m.target.value),placeholder:"如: v1.0, 2024-01",style:wt})]}),t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:f.processor_version,onChange:m=>c(x,"processor_version",m.target.value),placeholder:"如: v0.1",style:wt})]})]})]})]})})]},x)),t.jsxs("button",{onClick:d,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},ot={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},wt={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Ko={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:i("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},qo={background:"transparent",border:"none",color:i("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Ds(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(o=>({id:o.id||"",name:o.name||"",type:o.type||"",details:o.details||"",position:o.position||"",version:o.version||"",processor_version:o.processor_version||""}))}catch{}return[]}function Hs(e){return!e||e.length===0?"":JSON.stringify(e)}const Gs=({entityType:e,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:d,childWorks:p,childCollections:c,containedBooks:a,siblingBooks:u,onLinkEntity:f,onUnlinkEntity:x,onViewEntity:m,onCreateAndLink:j,onSaveRelations:w})=>{const h=ue();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:h.section.relations})]}),w&&t.jsx("button",{onClick:w,style:$p,children:h.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.belongsToWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>f("workId","work"),onCreate:()=>j("workId","work",{title:o}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Pt,{direction:"up",title:h.relation.containedInCollection,entity:d,onView:m,onUnlink:()=>x("collectionId"),onLink:()=>f("collectionId","collection"),onCreate:()=>j("collectionId","collection",{title:o}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),l&&u&&u.length>0&&t.jsx(St,{direction:"horizontal",title:`${h.relation.siblingVersions} (${u.length})`,entities:u,onView:m,onAdd:()=>j("siblingBook","book",{workId:l.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.parentWork,entity:r,onView:m,onUnlink:()=>x("parentWorkId"),onLink:()=>f("parentWorkId","work"),onCreate:()=>j("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),p&&p.length>0&&t.jsx(St,{direction:"down",title:`${h.relation.childWorks} (${p.length})`,entities:p,onView:m,onAdd:()=>j("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),c&&c.length>0&&t.jsx(St,{direction:"down",title:`${h.relation.collectionImpl} (${c.length})`,entities:c,onView:m,onAdd:()=>j("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(St,{direction:"down",title:`${h.relation.allVersions} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:m,onAdd:()=>j("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.correspondingWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>f("workId","work"),onCreate:()=>j("workId","work",{title:o}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Pt,{direction:"up",title:h.relation.parentCollection,entity:s,onView:m,onUnlink:()=>x("parentCollectionId"),onLink:()=>f("parentCollectionId","collection"),onCreate:()=>j("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(St,{direction:"down",title:`${h.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:m,onAdd:()=>j("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(St,{direction:"down",title:`${h.relation.containedBooks} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:m,onAdd:()=>j("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},Pt=({direction:e,title:n,entity:o,onView:r,onUnlink:s,onLink:l,onCreate:d,linkLabel:p,createLabel:c,notLinkedLabel:a,viewLabel:u,unlinkLabel:f})=>{const x=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("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})]}),o?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:i("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Us(o.type)}),t.jsx("span",{style:{fontWeight:500},children:o.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(Jo,{onClick:()=>r(o),title:u,children:"👁️"}),t.jsx(Jo,{onClick:s,title:f,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:a}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(li,{onClick:l,children:p}),t.jsx(li,{onClick:d,primary:!0,children:c})]})]})},St=({direction:e,title:n,entities:o,onView:r,onAdd:s,addLabel:l,noneLabel:d,expandMoreLabel:p})=>{const[c,a]=g.useState(!1),u=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),f=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=c?o:o.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("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})]}),o.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:i("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:Us(m.type)}),t.jsx("span",{children:m.title})]},m.id)),o.length>5&&!c&&t.jsxs("div",{onClick:()=>a(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:i("link-fg"),cursor:"pointer"},children:[p," (",o.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(li,{onClick:s,primary:!0,children:["+ ",l]})})]})},Jo=({onClick:e,title:n,danger:o,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:o?i("danger"):"inherit",opacity:.7},children:r}),li=({onClick:e,primary:n,children:o})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${i("widget-border")}`,borderRadius:"4px",background:n?i("primary"):"transparent",color:n?i("primary-fg"):"inherit",cursor:"pointer"},children:o});function Us(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const $p={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Vs=({isOpen:e,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:l,searchResults:d,onSearch:p,isLoading:c,excludeId:a})=>{const[u,f]=g.useState(""),x=a?d.filter(h=>h.id!==a):d;g.useEffect(()=>{e&&(f(""),p(""))},[e]);const m=h=>{f(h),p(h)};if(!e)return null;const j=n==="work"?"作品":n==="book"?"书籍":"丛编",w=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:zp,children:t.jsxs("div",{style:Cp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),t.jsx("button",{onClick:s,style:Ip,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:h=>m(h.target.value),placeholder:`搜索${j}名称或 ID...`,autoFocus:!0,style:Tp})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:Fn,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(h=>t.jsxs("div",{onClick:()=>r(h),style:Ep,children:[t.jsx("span",{style:{fontSize:"16px"},children:w}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):u?t.jsxs("div",{style:Fn,children:["未找到匹配的",j]}):t.jsxs("div",{style:Fn,children:["输入关键词搜索",j]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:l,style:Rp,children:["创建新",j,"并关联"]})]})]})})},zp={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Cp={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},Ip={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Tp={width:"100%",padding:"10px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},Ep={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:i("primary-soft")},Fn={padding:"20px",textAlign:"center",color:i("desc-fg")},Rp={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Zo={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Np={work:"📜",book:"📖",collection:"📚",entity:"👤"},Ys=({isOpen:e,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:l})=>{const[d,p]=g.useState(""),c=g.useRef(null);g.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,m;(x=c.current)==null||x.focus(),(m=c.current)==null||m.select()},100))},[e,r==null?void 0:r.title]);const a=x=>{x.key==="Enter"&&d.trim()?u():x.key==="Escape"&&l()},u=()=>{d.trim()&&s(d.trim(),{...r,title:d.trim()})};if(!e)return null;const f=()=>{switch(o){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`创建新${Zo[n]}`}};return t.jsx("div",{style:Lp,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:Bp,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:Np[n]}),t.jsx("span",{children:f()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:i("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:i("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:c,type:"text",value:d,onChange:x=>p(x.target.value),onKeyDown:a,placeholder:`请输入${Zo[n]}名称...`,style:Ap})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),background:i("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:Wp,children:"取消"}),t.jsx("button",{onClick:u,disabled:!d.trim(),style:{...Mp,opacity:d.trim()?1:.6,cursor:d.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Lp={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Bp={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:i("shadow-dialog")},Ap={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box"},Wp={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Mp={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg")};function Fp(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Ks(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Pp(e){switch(e){case"work":return i("editor-type-work");case"collection":return i("editor-type-collection");case"book":return i("editor-type-book");default:return i("desc-fg")}}const qs=({isOpen:e,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:d,onSelect:p,onCancel:c,onCreate:a,onSearch:u})=>{const[f,x]=g.useState(""),[m,j]=g.useState([]),[w,h]=g.useState(!1),[b,y]=g.useState("recent");g.useEffect(()=>{e&&(x(""),j([]),y(r.length>0?"recent":"search"))},[e,r.length]),g.useEffect(()=>{if(!f.trim()){j([]);return}const z=setTimeout(async()=>{h(!0);try{j(await u(f,o))}catch{j([])}finally{h(!1)}},300);return()=>clearTimeout(z)},[f,o,u]);const k=g.useCallback(z=>{x(z.target.value),z.target.value.trim()&&y("search")},[]),$=g.useCallback(z=>s?z.filter(N=>N.id!==s):z,[s]);if(!e)return null;const v=n||(o==="all"?"选择实体":`选择${Ks(o)}`),_=$(r),S=$(m);return t.jsx("div",{style:Dp,children:t.jsxs("div",{style:Hp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:v}),t.jsx("button",{onClick:c,style:Gp,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:"🔍"}),w&&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 ${i("widget-border")}`},children:[t.jsxs(Xo,{active:b==="recent",onClick:()=>y("recent"),children:["最近使用 (",_.length,")"]}),t.jsxs(Xo,{active:b==="search",onClick:()=>y("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:b==="recent"&&_.length>0?t.jsx(Qo,{entities:_,onSelect:p}):f.trim()?w?t.jsx(Pn,{message:"搜索中..."}):S.length>0?t.jsx(Qo,{entities:S,onSelect:p}):t.jsx(Pn,{message:"未找到匹配的结果"}):t.jsx(Pn,{message:"输入关键词开始搜索"})}),l&&a&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:a,style:Vp,children:d||"创建新实体"})]})]})})},Xo=({active:e,onClick:n,children:o})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:o}),Qo=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(o=>t.jsx(Op,{entity:o,onClick:()=>n(o)},o.id))}),Op=({entity:e,onClick:n})=>{const[o,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:i("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Fp(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:i("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:i("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:Pp(e.type),color:i("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Ks(e.type)})]})},Pn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:e}),Dp={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Hp={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},Gp={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 ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},Vp={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Yp={work:i("editor-type-work"),collection:i("editor-type-collection"),book:i("editor-type-book"),entity:i("editor-type-entity")},Kp={work:"📜",collection:"📚",book:"📖",entity:"👤"},Js=({data:e,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:l,onDelete:d,onAskAI:p,renderSectionActions:c,onDownloadResource:a,downloadStatuses:u,relations:f,onRelationsChange:x})=>{var me;const m=ue(),[j,w]=g.useState(!1),[h,b]=g.useState("work"),[y,k]=g.useState(""),[$,v]=g.useState(""),[_,S]=g.useState([]),[z,N]=g.useState(!1),[T,C]=g.useState(!1),[D,B]=g.useState("work"),[O,M]=g.useState(""),[X,Y]=g.useState(),[E,ee]=g.useState(!1),[F,K]=g.useState(null),[ae,ne]=g.useState([]);g.useRef(null);const Q=e.type,ie=Q==="work",ge=Q==="collection",re=Q==="book",le=g.useCallback((U,R)=>{n({...e,[U]:R})},[e,n]),pe=g.useCallback((U,R)=>{k(U),b(R),v(m.editor.selectToLink+m.indexType[R]),S([]),w(!0)},[m]),Re=g.useCallback(U=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,U)},[r,e.id]),$e=g.useCallback(U=>{s==null||s(U.id,U.type)},[s]),ye=g.useCallback((U,R,V)=>{const W={...V,author:(V==null?void 0:V.author)||e.author,dynasty:V==null?void 0:V.dynasty};B(R),M(U),Y(W),C(!0)},[e.author]),Se=g.useCallback((U,R)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,O,{type:D,title:U,inheritData:R}),C(!1)},[r,e.id,O,D]),Ne=g.useCallback(U=>{if(!U.trim()){S([]);return}N(!0),r!=null&&r.searchEntities&&r.searchEntities(U,h).then(R=>{S(R),N(!1)}).catch(()=>{S([]),N(!1)})},[r,h]),je=g.useCallback(U=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,y,U.id),w(!1)},[r,e.id,y]),H=g.useCallback(()=>{o()},[o]),ce=g.useCallback(U=>{K(()=>U),ee(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(ne).catch(()=>{})},[r]),oe=g.useCallback((U,R)=>r!=null&&r.searchEntities?r.searchEntities(U,R==="all"?void 0:R):Promise.resolve([]),[r]),he=g.useCallback(U=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(U),ne(R=>[U,...R.filter(V=>V.id!==U.id)].slice(0,10)),F==null||F(U),ee(!1),K(null)},[r,F]);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 ${i("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[Q]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(bn,{children:e.id}),t.jsx(bn,{color:Yp[Q],children:m.indexType[Q]})]})}),t.jsx(qe,{title:m.section.basicInfo,onSave:o,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(xn,{label:ie?m.editor.workTitle:ge?m.editor.collectionTitle:m.editor.bookTitle,value:e.title,onChange:U=>le("title",U)}),re&&t.jsx(xn,{label:m.editor.belongsToWork,value:e.workName||"",onChange:U=>le("workName",U)}),t.jsx(Ge,{label:m.editor.authorLabel,value:e.author||"",onChange:U=>le("author",U)}),t.jsx(Ge,{label:m.editor.publicationYearLabel,value:e.publicationYear||"",onChange:U=>le("publicationYear",U)}),(re||ge)&&t.jsx(xn,{label:m.editor.containedIn,value:e.collection||"",onChange:U=>le("collection",U)}),(re||ge)&&t.jsx(Ge,{label:m.editor.holderLabel,value:e.holder||"",onChange:U=>le("holder",U)}),(re||ge)&&t.jsx(Ge,{label:re?m.editor.pageLabel:m.editor.volumeLabel,value:e.pages||"",onChange:U=>le("pages",U)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(Ge,{label:m.editor.firstImageLabel,value:e.firstImage||"",onChange:U=>le("firstImage",U)})})]})}),t.jsx(qe,{title:m.section.description,onSave:o,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(bt,{value:e.description||"",onChange:U=>le("description",U),placeholder:m.editor.descriptionPlaceholder})}),(((me=e.additional_works)==null?void 0:me.length)||0)>0&&t.jsx(qe,{title:m.section.additionalWorks,onSave:o,children:t.jsx(qp,{items:e.additional_works||[],onChange:U=>le("additional_works",U)})}),t.jsx(qe,{title:m.section.indexedBy,onSave:o,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Jp,{items:e.indexed_by||[],onChange:U=>le("indexed_by",U)})}),t.jsx(qe,{title:m.section.emendatedBy,onSave:o,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Zp,{items:e.emendated_by||[],onChange:U=>le("emendated_by",U)})}),t.jsx(qe,{title:m.section.textResources,onSave:o,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(Vn,{items:e.resources||[],onChange:U=>le("resources",U),onDownload:a,downloadStatuses:u,filterType:"text"})}),t.jsx(qe,{title:m.section.imageResources,onSave:o,children:t.jsx(Vn,{items:e.resources||[],onChange:U=>le("resources",U),onDownload:a,downloadStatuses:u,filterType:"image"})}),t.jsx(qe,{title:m.section.sources,onSave:o,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(Os,{items:Ds(e.sources||""),onChange:U=>le("sources",Hs(U)),onOpenEntityPicker:ce})}),(re||ge)&&t.jsx(qe,{title:m.section.provenance,onSave:o,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(bt,{value:e.provenance||"",onChange:U=>le("provenance",U),placeholder:m.editor.provenancePlaceholder})}),re&&t.jsx(qe,{title:m.section.otherEditions,onSave:o,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(bt,{value:e.otherEditions||"",onChange:U=>le("otherEditions",U),placeholder:m.editor.otherEditionsPlaceholder})}),t.jsx(Gs,{entityType:Q,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:pe,onUnlinkEntity:Re,onViewEntity:$e,onCreateAndLink:ye,onSaveRelations:H}),l&&d&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${i("danger-soft-border")}`,background:i("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:i("danger"),fontWeight:600,marginBottom:"8px"},children:m.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"12px"},children:m.editor.dangerZoneDesc}),t.jsx("button",{onClick:d,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("danger")}`,borderRadius:"4px",background:"transparent",color:i("danger"),cursor:"pointer"},children:m.editor.deleteEntity})]}),t.jsx(Vs,{isOpen:j,entityType:h,title:$,onSelect:je,onCancel:()=>w(!1),onCreate:()=>{w(!1),ye(y,h)},searchResults:_,onSearch:Ne,isLoading:z,excludeId:e.id}),t.jsx(Ys,{isOpen:T,entityType:D,relationField:O,inheritData:X,onConfirm:Se,onCancel:()=>C(!1)}),t.jsx(qs,{isOpen:E,title:m.action.selectBookOrWork,filterType:"all",recentEntities:ae,excludeId:e.id,onSelect:he,onCancel:()=>{ee(!1),K(null)},onSearch:oe})]})};function qp({items:e,onChange:n}){const o=ue(),r=(d,p,c)=>{const a=e.map((u,f)=>f===d?{...u,[p]:c}:u);n(a)},s=d=>n(e.filter((p,c)=>c!==d)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((d,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(Ge,{label:o.editor.bookNameLabel,value:d.book_title,onChange:c=>r(p,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(Ge,{label:o.label.juanCount,value:d.n_juan!=null?String(d.n_juan):"",onChange:c=>r(p,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function Zs({items:e,onChange:n,showMeta:o,addLabel:r}){const s=ue(),[l,d]=g.useState(null),p=(u,f,x)=>{const m=e.map((j,w)=>w===u?{...j,[f]:x||void 0}:j);n(m)},c=u=>{n(e.filter((f,x)=>x!==u)),l===u&&d(null)},a=()=>{n([...e,{source:""}]),d(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 ${i("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, ${i("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>d(x?null:f),children:[t.jsx("span",{style:{fontSize:"10px",color:i("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:i("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:m=>{m.stopPropagation(),c(f)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${i("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:i("muted")},children:"✕"})]}),!x&&o&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:i("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),x&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ge,{label:s.label.sourceName,value:u.source,onChange:m=>p(f,"source",m)}),t.jsx(Ge,{label:s.label.sourceBid,value:u.source_bid||"",onChange:m=>p(f,"source_bid",m)})]}),o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ge,{label:s.label.titleInfo,value:u.title_info||"",onChange:m=>p(f,"title_info",m)}),t.jsx(Ge,{label:s.label.authorInfo,value:u.author_info||"",onChange:m=>p(f,"author_info",m)})]}),t.jsx(Ge,{label:s.label.edition,value:u.edition||"",onChange:m=>p(f,"edition",m)})]}),t.jsx(bt,{value:u.summary||"",onChange:m=>p(f,"summary",m),placeholder:s.editor.summaryPlaceholder}),t.jsx(bt,{value:u.comment||"",onChange:m=>p(f,"comment",m),placeholder:s.editor.commentPlaceholder}),t.jsx(bt,{value:u.additional_comment||"",onChange:m=>p(f,"additional_comment",m),placeholder:s.editor.additionalCommentPlaceholder})]})]},f)}),t.jsx("button",{onClick:a,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Jp({items:e,onChange:n}){const o=ue();return t.jsx(Zs,{items:e,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function Zp({items:e,onChange:n}){const o=ue();return t.jsx(Zs,{items:e,onChange:n,addLabel:o.action.addEmendatedBy})}function Xs(e){var p,c,a,u,f,x,m;const n=((c=(p=e.authors)==null?void 0:p[0])==null?void 0:c.name)||"",o=((a=e.publication_info)==null?void 0:a.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||"",d={id:e.id,title:e.title,type:e.type,author:n,publicationYear:o,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 j=e;if(Array.isArray(j.related_works)){const w=j.related_works.find(h=>h.relation==="part_of");w&&(d.parentWorkId=w.id,d.parentWorkName=w.title)}}if(e.type==="book"){const j=e;d.workId=j.work_id,Array.isArray(j.contained_in)&&j.contained_in.length>0&&(d.collectionId=(m=j.contained_in[0])==null?void 0:m.id)}return d}function Xp(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 Qp=e=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:l,onChange:d,onSave:p,onDelete:c,onNavigate:a,renderLink:u,onAskAI:f,renderSectionActions:x,onDownloadResource:m,downloadStatuses:j,relations:w,onRelationsChange:h,headerExtra:b,className:y,style:k}=e;ue();const[$,v]=g.useState(s),_=l?s:$;g.useEffect(()=>{s!==$&&v(s)},[s]);const S=g.useCallback(()=>{const O=_==="view"?"edit":"view";l?l(O):v(O)},[_,l]),[z,N]=g.useState(null);g.useEffect(()=>{o&&r&&r.getItem(o).then(O=>{O&&N(O)})},[o,r]);const T=n||z,C=g.useMemo(()=>T?Xs(T):null,[T]),D=l||!n?t.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:_==="edit"?i("accent-bg"):"transparent",color:i(_==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?"切换到编辑模式":"切换到查看模式",children:_==="view"?"✏️ 编辑":"👁 查看"}):null,B=t.jsxs(t.Fragment,{children:[D,b]});return!T&&!C?t.jsx(jt,{}):_==="view"?t.jsx(bi,{data:T,transport:r,onNavigate:a?O=>a(O):void 0,renderLink:u,headerExtra:B,className:y,style:k}):C?t.jsxs("div",{className:y,style:k,children:[B&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:B}),t.jsx(Js,{data:C,onChange:d||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:a,showDelete:!!c,onDelete:c,onAskAI:f,renderSectionActions:x,onDownloadResource:m,downloadStatuses:j,relations:w,onRelationsChange:h})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:i("muted")},children:"无数据"})},er=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Qs=({isOpen:e,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,l]=g.useState(null),[d,p]=g.useState(""),[c,a]=g.useState(""),[u,f]=g.useState("idle"),[x,m]=g.useState(""),j=g.useRef(null);g.useEffect(()=>{e&&(l(null),p(""),a(""),f("idle"),m(""))},[e]),g.useEffect(()=>{s&&setTimeout(()=>{var y;return(y=j.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 w=async()=>{if(!(!s||!d.trim())){f("submitting"),m("");try{await o({type:s,content:d.trim(),...c.trim()?{contact:c.trim()}:{}}),f("success")}catch(y){f("error"),m(y instanceof Error?y.message:"提交失败,请稍后重试")}}};if(!e)return null;const h=s&&d.trim()&&u!=="submitting",b=er.find(y=>y.value===s);return t.jsx("div",{style:eu,onClick:y=>{y.target===y.currentTarget&&n()},children:t.jsxs("div",{style:tu,onClick:y=>y.stopPropagation(),children:[t.jsxs("div",{style:nu,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:iu,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:au,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:i("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:er.map(y=>t.jsxs("button",{onClick:()=>l(y.value),style:{...ou,...s===y.value?ru:{}},children:[t.jsx("span",{children:y.icon})," ",y.label]},y.value))}),t.jsx("textarea",{ref:j,value:d,onChange:y=>p(y.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...su,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:c,onChange:y=>a(y.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:du}),t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),u==="error"&&t.jsx("div",{style:cu,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:w,disabled:!h,style:{...lu,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},eu={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},tu={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:i("shadow-dialog")},nu={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},iu={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:i("desc-fg"),padding:"4px 8px",borderRadius:"4px"},ou={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ru={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},su={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},lu={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},au={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:i("success")},cu={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginBottom:"12px"},du={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},ai="--bim-feedback-fab-offset",ci=48,pu=16,uu=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:o,hidden:r=!1,zIndex:s})=>{const[l,d]=g.useState(!1),p=n.bottom??24;return g.useEffect(()=>{if(r||typeof document>"u")return;const c=document.documentElement;return c.style.setProperty(ai,`calc(${p+ci+pu}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(ai)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...xu,zIndex:s??i("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(Qs,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:o})]})},xu={position:"fixed",width:`${ci}px`,height:`${ci}px`,borderRadius:"50%",border:"none",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:i("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},tr=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],el=({onSubmit:e})=>{const[n,o]=g.useState("bug"),[r,s]=g.useState(""),[l,d]=g.useState(""),[p,c]=g.useState("idle"),[a,u]=g.useState(""),f=g.useRef(null);g.useEffect(()=>{n&&setTimeout(()=>{var w;return(w=f.current)==null?void 0:w.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){c("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),c("success"),s(""),d(""),o("bug")}catch(w){c("error"),u(w instanceof Error?w.message:"提交失败,请稍后重试")}}},m=n&&r.trim()&&p!=="submitting",j=tr.find(w=>w.value===n);return p==="success"?t.jsx("div",{style:nr,children:t.jsxs("div",{style:bu,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>c("idle"),style:yu,children:"继续提交"})]})}):t.jsxs("div",{style:nr,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:tr.map(w=>t.jsxs("button",{onClick:()=>o(w.value),style:{...fu,...n===w.value?gu:{}},children:[t.jsx("span",{children:w.icon})," ",w.label]},w.value))}),t.jsx("textarea",{ref:f,value:r,onChange:w=>s(w.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...mu}}),t.jsx("input",{type:"text",value:l,onChange:w=>d(w.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:vu}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:x,disabled:!m,style:{...hu,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:ju,children:a})]})},nr={padding:"16px",border:`1px solid ${i("widget-border")}`,borderRadius:"8px",background:i("input-bg")},fu={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},gu={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},mu={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},hu={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},bu={display:"flex",alignItems:"center",gap:"12px",color:i("success"),fontSize:"14px"},yu={background:"none",border:"none",color:i("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ju={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginTop:"8px"},vu={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function ir(e){return typeof e=="function"?e():e??"/api/feedback"}const tl=({resourceId:e,apiUrl:n})=>{const[o,r]=g.useState([]),[s,l]=g.useState(!0),d=g.useCallback(async()=>{const c=ir(n);l(!0);try{const u=await(await fetch(`${c}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);g.useEffect(()=>{d()},[d]);const p=async c=>{const a=ir(n),u=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...c,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const f=await u.json().catch(()=>null);throw new Error((f==null?void 0:f.error)||"提交失败")}setTimeout(()=>d(),500)};return t.jsxs("div",{children:[t.jsx(Gi,{items:o,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(el,{onSubmit:p})})]})},or={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 rr(e){return e?or[e]??e:or.related}const ku={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function wu(e){return ku[e]??e}const Su={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function _u(e){return Su[e]??""}function Ui({authors:e,onNavigate:n,renderLink:o}){const{convert:r}=Z(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,d)=>{const p=Si(l.role);return t.jsxs(g.Fragment,{children:[d>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Be,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:o,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},d)})}):null}function nl(e,n){var p,c;const o=ki(e,n),r=o.mirrors.map(a=>({key:a.key,label:a.label,description:a.description,rows:a.items.filter(u=>u.group_role!=="mirror"),mirrors:a.items.filter(u=>u.group_role==="mirror")})),s=o.buckets.filter(a=>a.key==="image"||a.key==="textImage").flatMap(a=>a.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=o.buckets.find(a=>a.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((c=o.buckets.find(a=>a.key==="text"))==null?void 0:c.items)??[],groups:r}}function il(e,n){const o=(e.url?Nt(e.url):void 0)||e.name,r=Gr(e,n);return r?`${o}(${r})`:o}function Vi({item:e,siblings:n,listedVolumeCounts:o}){const{convert:r}=Z(),[s,l]=g.useState(!1),d=yn(e),p=!!d&&d.expected>0&&!(o!=null&&o.has(d.expected)),c=r(il(e,n)),a=Lt(e),u=Sn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var x,m;const f=(x=e.metadata)!=null&&x.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((m=e.metadata)==null?void 0:m.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("殘片")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:r(e.color_mode==="color"?"彩色":"黑白")})]}):null;return a?t.jsxs("a",{href:a,target:"_blank",rel:"noopener noreferrer",children:[c," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),f]}):t.jsxs("span",{className:"bim-d-zt-name",children:[c,f]})})(),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(zi,{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?"收起分冊":`展開 ${d.expected} 冊`)})})]})}function ol({groups:e,listedVolumeCounts:n}){const{convert:o}=Z();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:o(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:o(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(Vi,{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:o("鏡像")}),r.mirrors.map((s,l)=>{const d=Lt(s),p=o(il(s,r.mirrors));return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",title:s.details?o(s.details):void 0,children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:p},l)})]})]},r.key))})}const Yt=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function di(e){var o;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(o=Yt.find(r=>n.startsWith(r.key[0])))==null?void 0:o.key}const sr=12,$u=60,rl=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,railTop:l,back:d,railLinks:p})=>{var Se,Ne,je;const c=ue(),{convert:a}=Z(),u=g.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[f,x]=g.useState(new Map),[m,j]=g.useState(!1),[w,h]=g.useState(""),[b,y]=g.useState(!1),k=u.length<=$u,$=k||m||!!w||b,v=g.useMemo(()=>$?u:u.slice(0,sr),[u,$]);g.useEffect(()=>{if(!n||v.length===0)return;const H=v.filter(oe=>!f.has(oe));if(H.length===0)return;let ce=!1;return Promise.all(H.map(oe=>n.getItem(oe).then(he=>{const me=he??{};return[oe,{id:oe,title:me.title,edition:me.edition,resources:me.resources,publication_info:me.publication_info,current_location:me.current_location,lineage:me.lineage,measure_info:me.measure_info}]}).catch(()=>[oe,{id:oe}]))).then(oe=>{ce||x(he=>{const me=new Map(he);for(const[U,R]of oe)me.set(U,R);return me})}),()=>{ce=!0}},[n,v,f]);const _=g.useMemo(()=>u.map(H=>f.get(H)??{id:H}),[u,f]),S=u.length>0&&u.every(H=>f.has(H)),z=!!n&&v.some(H=>!f.has(H)),N=k||$,T=g.useMemo(()=>Vr(_,e.version_graph,{era:w,scanOnly:b,sort:N?"year":"default"}),[_,e.version_graph,w,b,N]),C=m?T.rows:T.rows.slice(0,sr),D=T.allRows.filter(H=>H.hasImage).length,B=e.related_works||[],O=B.filter(H=>H.relation==="collected_in"),M=g.useMemo(()=>{const H=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],ce=oe=>{const he=H.indexOf(oe??"");return he<0?H.length:he};return B.filter(oe=>oe.relation!=="collected_in").map((oe,he)=>({r:oe,i:he})).sort((oe,he)=>ce(oe.r.relation)-ce(he.r.relation)||oe.i-he.i).map(oe=>oe.r)},[B]),X=g.useMemo(()=>{const H=ki(e.resources,e.resource_groups);return[...H.mirrors.flatMap(ce=>ce.items.map(oe=>({r:oe,kind:a(ce.label)}))),...H.buckets.flatMap(ce=>ce.items.map(oe=>({r:oe,kind:a(_u(ce.key))})))]},[e.resources,e.resource_groups,a]),Y=e.indexed_by||[],E=e.emendated_by||[],ee=g.useMemo(()=>{var W,A,I;const H=[],ce=(A=(W=e.authors)==null?void 0:W[0])==null?void 0:A.dynasty;ce&&H.push({label:"成書",value:a(ce)});const oe=at(e,c.unit.juan);if(oe){const G=(I=e.juan_count)==null?void 0:I.description;H.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[a(oe),G&&G!==oe?t.jsxs("span",{className:"bim-d-meta",children:["(",a(G),")"]}):null]})})}e.loss_status&&H.push({label:"存佚",value:a(wu(e.loss_status))});const he=T.allRows.filter(G=>G.sortYear!=null),me=he.length>0?he.reduce((G,P)=>G.sortYear<=P.sortYear?G:P):null;me!=null&&me.era.era?H.push({label:"最早存世",value:a([me.era.era,me.era.reign].filter(Boolean).join(" ")),title:me.era.source==="edition"?a("據版本題名推斷"):void 0}):z&&H.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":a("載入中"),children:"…"})}),E.length&&H.push({label:"考證",value:`${E.length} ${a("條")}`});const U=lr(e.additional_titles);U.length&&H.push({label:"又名",value:U.map(a).join("、")});const R=lr(e.attached_texts);R.length&&H.push({label:"附載",value:R.map(a).join("、")});const V=(e.additional_works||[]).map(G=>a(G.book_title)+(G.n_juan!=null?` ${G.n_juan}${a(c.unit.juan)}`:""));return V.length&&H.push({label:"附錄",value:V.join("、")}),H},[e,a,c,z,T.allRows,E.length]),K=[{value:e._edition_count??u.length,label:"版本"},{value:S?D:0,label:"有影印"},{value:Y.length,label:"家著錄"}],ae=e.classification,ne=ae?[ae.l1,ae.l2,ae.l3,ae.l4].filter(Boolean).map(H=>a(H)):[],Q=e.subtype?a(c.workSubtype[e.subtype]??e.subtype):"",ie=t.jsx(Qt,{title:a(e.title),byline:t.jsx(Ui,{authors:e.authors,onNavigate:o,renderLink:r}),meta:t.jsx(Me,{items:[...ne,ae!=null&&ae.source?a(`據《${ae.source.split("/")[0]}》`):"",Q]}),description:(Se=e.description)!=null&&Se.text?t.jsxs(t.Fragment,{children:[t.jsx(lt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Ne=e.description.sources)!=null&&Ne.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(H=>a(dc(H))).filter(Boolean).join(" · ")}):null]}):void 0,stats:K,facts:ee,readAction:s,foot:t.jsx(en,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(je=e.appendix)==null?void 0:je.map((H,ce)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:a(H.title)}),t.jsx(lt,{text:H.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},ce))}),ge=T.eras.length>=2?[{key:"",label:c.catalog.all},...T.eras.map(H=>({key:H,label:`${H} ${T.allRows.filter(ce=>ce.era.era===H).length}`}))]:[],re=[];u.length&&re.push({id:"versions",label:"版本",count:u.length}),Y.length&&re.push({id:"catalogs",label:"著錄",count:Y.length}),O.length&&re.push({id:"collected",label:"收入叢編",count:O.length}),M.length&&re.push({id:"related",label:"相關書目",count:M.length}),X.length&&re.push({id:"resources",label:"在線資源",count:X.length});const le=u.length===0&&Y.length===0,pe=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Fe,{id:"versions",title:"版本",meta:t.jsx(Me,{items:[a(`共 ${u.length} 種`),S&&D?a(`${D} 種有影印`):"",T.rows.length!==T.allRows.length?a(`當前 ${T.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&ge.length===0&&u.length>1?"":void 0,children:[ge.length>0&&t.jsx($n,{items:ge,value:w,onChange:H=>{h(H),j(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(is,{label:"只看有影印",checked:b,onChange:H=>{y(H),j(!1)}}),t.jsx("span",{className:"bim-d-meta",children:a(N?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("版本")}),t.jsx("th",{children:a("年代")}),t.jsx("th",{children:a("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:a("影印")})})]})}),t.jsx("tbody",{children:C.map(H=>{var ce;return t.jsx(zu,{row:H,measure:(ce=f.get(H.id))==null?void 0:ce.measure_info,loaded:f.has(H.id),onNavigate:o,renderLink:r},`${H.id}:${f.has(H.id)?"r":"p"}`)})})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a(w||b?"當前篩選下沒有版本":"暫無版本著錄")}),T.rows.length>C.length&&t.jsx(Bt,{label:`展開其餘 ${T.rows.length-C.length} 種版本`,onClick:()=>j(!0)}),T.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:a("部分年代據版本題名推斷,非著錄原文")})]}),Y.length>0&&t.jsx(Cu,{items:Y,transport:n,onNavigate:o,renderLink:r}),le&&t.jsx(Fe,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該作品的版本與書目收錄。")})})]}),Re=(H,ce)=>t.jsx(Be,{id:H,label:a(ce),onNavigate:o,renderLink:r,dense:!0}),$e=g.useMemo(()=>{const H=new Map;for(const ce of M){const oe=rr(ce.relation);H.set(oe,(H.get(oe)??0)+1)}return H.size>1?[...H.entries()].sort((ce,oe)=>oe[1]-ce[1]).slice(0,4).map(([ce,oe])=>`${a(ce)} ${oe}`).join(" · "):void 0},[M,a]),ye=t.jsxs(t.Fragment,{children:[t.jsx(ht,{id:"collected",title:"收入叢編",items:O.map(H=>Re(H.id,H.title))}),t.jsx(ht,{id:"related",title:"相關書目",meta:a(`${M.length} 部`),sub:$e,items:M.map(H=>t.jsxs(t.Fragment,{children:[Re(H.id,H.title),t.jsx("span",{className:"bim-d-meta",title:H.note?a(H.note):void 0,children:a(rr(H.relation))})]}))}),t.jsx(ht,{id:"resources",title:"在線資源",cap:6,items:X.map(({r:H,kind:ce})=>{const oe=a((H.url?Nt(H.url):void 0)||H.name),he=Lt(H);return t.jsxs(t.Fragment,{children:[he?t.jsxs("a",{href:he,target:"_blank",rel:"noopener noreferrer",children:[oe," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:oe}),ce&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:ce})]})})})]});return t.jsx(Xt,{railTop:l,back:d,nav:re,railLinks:p,main:pe,card:ie,side:ye})};function lr(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ar(e,n){return n((e.url?Nt(e.url):void 0)||e.name)}function zu({row:e,measure:n,loaded:o,onNavigate:r,renderLink:s}){const{convert:l}=Z(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",c=e.holders[0],a=c?ar(c,l):e.locationName?l(e.locationName):"",u=e.images[0],f=u?Lt(u):void 0,x=e.images.map(m=>ar(m,l)).join("、");return t.jsxs("tr",{"data-loading":o?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Be,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${d?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:d?l(d):o?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${a?"":" bim-d-zt-blank"}`,children:[a||(o?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 Cu({items:e,transport:n,onNavigate:o,renderLink:r}){const s=ue(),{convert:l}=Z(),[d,p]=g.useState(0),c=Math.min(d,e.length-1),a=e[c],[u,f]=g.useState(new Map);return g.useEffect(()=>{if(!n)return;const x=[...new Set(e.map(j=>j.source_bid).filter(j=>!!j))];if(x.length===0)return;let m=!1;return Promise.all(x.map(j=>n.getItem(j).then(w=>{var h,b;return[j,((b=(h=w==null?void 0:w.authors)==null?void 0:h[0])==null?void 0:b.dynasty)??""]}).catch(()=>[j,""]))).then(j=>{m||f(new Map(j.filter(([,w])=>w)))}),()=>{m=!0}},[n,e]),t.jsx(Fe,{id:"catalogs",title:"著錄",meta:t.jsx(Me,{items:[l(`歷代書目 ${e.length} 家`),l("按著錄順序")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":l("著錄書目"),children:e.map((x,m)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":m===c,"aria-label":l(x.source),onClick:()=>p(m),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(x.source_bid??"")?l(u.get(x.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...l(x.source)].slice(0,9).map((j,w)=>t.jsx("span",{children:j},w))})]})},m))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[a.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:l(a.title_info)}),t.jsx(Me,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[a.source_bid?t.jsx(Be,{id:a.source_bid,label:l(a.source),onNavigate:o,renderLink:r,dense:!0}):l(a.source),a.section?l(a.section):"",a.author_info?`${l(s.label.authorInfo)} ${l(a.author_info)}`:"",a.edition?`${l(s.label.edition)} ${l(a.edition)}`:"",a.page??""]}),a.summary&&t.jsx("p",{className:"bim-d-quote",children:Ue(l(a.summary))}),a.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:Ue(l(a.comment))})]}),a.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:Ue(l(a.additional_comment))})]}),!a.summary&&!a.comment&&!a.additional_comment&&!a.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:l("僅著錄書名,無提要。")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?t.jsx("button",{type:"button","aria-label":l(`上一家:${e[c-1].source}`),onClick:()=>p(c-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",l(e[c-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",e.length]}),c<e.length-1?t.jsx("button",{type:"button","aria-label":l(`下一家:${e[c+1].source}`),onClick:()=>p(c+1),children:t.jsxs("span",{"aria-hidden":"true",children:[l(e[c+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function Iu(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 Tu(e,n){if(!e.lineage)return null;const o=e.lineage;return{id:e.id,kind:"book",label:e.title,year:o.year,year_text:o.year_text,year_uncertain:o.year_uncertain,category:o.category,status:o.status,extant_juan:o.extant_juan,group:n[e.id],note:o.note}}function cr(e,n,o){return{id:`derive:${n.ref}->${e}:${o}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Eu(e,n,o){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${o}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Ru(e,n){var a;if(n==="all")return null;const o=(a=e.collections)==null?void 0:a[n],r=Array.isArray(o==null?void 0:o.groups)&&o.groups.length>0,s=Array.isArray(o==null?void 0:o.book_ids)&&o.book_ids.length>0,l=r||s||!!(o!=null&&o.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(!o||!l)return null;const d=r?new Set(o.groups):null,p=new Set(o.book_ids??[]);if(d&&e.node_groups)for(const[u,f]of Object.entries(e.node_groups))d.has(f)&&p.add(u);let c=null;if(o.hypothetical_ids&&(c=new Set(o.hypothetical_ids)),d){c||(c=new Set);for(const u of e.hypothetical_nodes??[])u.group&&d.has(u.group)&&c.add(u.id)}return{books:p,hypos:c}}function fn(e,n,o){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const l=new Set(r.excluded_books??[]),d=r.node_groups??{},p=Ru(r,o??r.default_collection??"all"),c=p!==null,a=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,f=new Set,x=new Set;if(c){const $=new Map(n.map(T=>[T.id,T])),v=new Map((r.hypothetical_nodes??[]).map(T=>[T.id,T])),_=T=>{const C=$.get(T);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(B=>B.ref);const D=v.get(T);return D?(D.derived_from??[]).map(B=>B.ref):[]},S=T=>v.has(T)?!u||u.has(T):!a||a.has(T),z=new Set,N=T=>{if(!z.has(T)){z.add(T);for(const C of _(T))l.has(C)||(S(C)||(v.has(C)?x.add(C):$.has(C)&&f.add(C)),N(C))}};for(const T of n)a&&a.has(T.id)&&!l.has(T.id)&&N(T.id);for(const T of r.hypothetical_nodes??[])u&&u.has(T.id)&&N(T.id)}const m=n.filter($=>!l.has($.id)).filter($=>!a||a.has($.id)||f.has($.id)).map($=>{const v=Tu($,d);return v&&f.has($.id)&&(v.bridge=!0),v}).filter($=>$!==null),j=(r.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||x.has($.id)).map($=>{const v=Iu($);return x.has($.id)&&(v.bridge=!0),v}),w=[...m,...j],h=new Set(w.map($=>$.id)),b=new Set,y=[],k=$=>{b.has($.id)||!h.has($.source)||!h.has($.target)||(b.add($.id),y.push($))};for(const $ of n)l.has($.id)||!$.lineage||a&&!a.has($.id)&&!f.has($.id)||(($.lineage.derived_from??[]).forEach((v,_)=>{k(cr($.id,v,_))}),($.lineage.related_to??[]).forEach((v,_)=>{k(Eu($.id,v,_))}));for(const $ of r.hypothetical_nodes??[])u&&!u.has($.id)&&!x.has($.id)||($.derived_from??[]).forEach((v,_)=>{k(cr($.id,v,_))});return{nodes:w,edges:y,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function sl(e,n,o){const r=(e??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Nu(e,n){const o=[],r=e.version_graph;if(!r)return o;const s=new Set(n.map(c=>c.id)),l=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),d=new Set([...s,...l]),p=(c,a)=>{d.has(a.ref)||o.push(`${c}: derived_from.ref "${a.ref}" 未在 books 或 hypothetical_nodes 中找到`),a.ref_type==="book"&&!s.has(a.ref)&&o.push(`${c}: derived_from.ref "${a.ref}" 标记为 book 但不在 books 列表中`),a.ref_type==="hypothetical"&&!l.has(a.ref)&&o.push(`${c}: derived_from.ref "${a.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const a=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>p(a,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||o.push(`${a}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const a=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>p(a,u))}return o}const ll=({graph:e,renderLink:n,className:o,style:r})=>{const{convert:s}=Z();if(!e.nodes.length)return t.jsx("div",{style:{...Yu,...r},className:o,children:"暂无版本图数据"});const l=new Map,d=new Map;for(const x of e.edges)if(x.kind==="derive"){const m=l.get(x.target)??[];m.push(x),l.set(x.target,m)}else for(const m of[x.source,x.target]){const j=d.get(m)??[];j.push(x),d.set(m,j)}const p=new Map(e.nodes.map(x=>[x.id,x])),c=new Map,a=[];for(const x of e.nodes)if(x.group){const m=c.get(x.group)??[];m.push(x),c.set(x.group,m)}else a.push(x);const u=(x,m)=>(x.year??9999)-(m.year??9999);c.forEach(x=>x.sort(u)),a.sort(u);const f=e.groups.filter(x=>c.has(x.id));return t.jsxs("div",{className:o,style:{...Bu,...r},children:[e.title&&t.jsx("div",{style:Au,children:s(e.title)}),e.description&&t.jsx("div",{style:Wu,children:s(e.description)}),f.map(x=>t.jsx(dr,{label:x.label,color:x.color,nodes:c.get(x.id),incomingMap:l,siblingMap:d,nodeMap:p,renderLink:n},x.id)),a.length>0&&t.jsx(dr,{label:"其他",nodes:a,incomingMap:l,siblingMap:d,nodeMap:p,renderLink:n})]})},dr=({label:e,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:d})=>{const{convert:p}=Z();return t.jsxs("div",{style:Mu,children:[t.jsx("div",{style:{...Fu,borderLeftColor:n??i("widget-border")},children:p(e)}),o.map(c=>t.jsx(Lu,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:d},c.id))]})},Lu=({node:e,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",d=e.bridge,{convert:p}=Z();return t.jsxs("div",{style:{...Pu,borderStyle:l||d?"dashed":"solid",opacity:d?.55:e.status==="lost"?.7:1,background:d?i("bg-subtle"):void 0},title:d?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:Ou,children:[t.jsx("span",{style:Du,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Hu,children:sl(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Gu,children:[e.category&&t.jsx(Ot,{children:p(e.category)}),e.status==="lost"&&t.jsx(Ot,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(Ot,{tone:"warn",children:"残本"}),l&&t.jsx(Ot,{tone:"info",children:"假想祖本"}),d&&t.jsx(Ot,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Uu,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:Vu,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:ur,children:[t.jsx("div",{style:xr,children:"来源:"}),n.map(c=>{const a=r.get(c.source);return t.jsxs("div",{style:fr(c.confidence),children:[t.jsx("span",{style:gr,children:p(c.relation)}),t.jsx("span",{children:(a==null?void 0:a.kind)==="book"&&s?s(a.id,p(a.label)):p((a==null?void 0:a.label)??c.source)}),c.confidence!=="consensus"&&c.confidence!=="certain"&&t.jsx(pr,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:mr,children:["· ",p(c.evidence)]})]},c.id)})]}),o.length>0&&t.jsxs("div",{style:ur,children:[t.jsx("div",{style:xr,children:"关联:"}),o.map(c=>{const a=c.source===e.id?c.target:c.source,u=r.get(a);return t.jsxs("div",{style:fr(c.confidence),children:[t.jsx("span",{style:gr,children:p(c.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,p(u.label)):p((u==null?void 0:u.label)??a)}),t.jsx(pr,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:mr,children:["· ",p(c.evidence)]})]},c.id)})]})]})},Ot=({children:e,tone:n="default"})=>{const r={default:{bg:i("tag-bg"),fg:i("fg")},warn:{bg:i("warn-bg"),fg:i("warn-fg")},info:{bg:i("info-bg"),fg:i("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})},pr=({level:e})=>{const o={certain:{label:"确定",color:i("confidence-certain")},consensus:{label:"共识",color:i("confidence-consensus")},probable:{label:"推测",color:i("confidence-probable")},disputed:{label:"有争议",color:i("confidence-disputed")}}[e];return o?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${o.color}`,color:o.color,borderRadius:"8px",marginLeft:"4px"},children:o.label}):null},Bu={fontSize:"14px",color:i("fg")},Au={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Wu={fontSize:"13px",color:i("muted"),marginBottom:"16px",lineHeight:1.6},Mu={marginBottom:"16px"},Fu={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:i("fg")},Pu={border:`1px solid ${i("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:i("bg")},Ou={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Du={fontSize:"15px",fontWeight:600},Hu={fontSize:"12px",color:i("muted")},Gu={marginBottom:"6px"},Uu={fontSize:"12px",color:i("muted"),margin:"2px 0"},Vu={fontSize:"12px",color:i("muted"),fontStyle:"italic",margin:"4px 0"},ur={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${i("widget-border")}`},xr={fontSize:"11px",color:i("muted"),marginBottom:"2px"},fr=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),gr={display:"inline-block",padding:"0 6px",fontSize:"11px",background:i("tag-bg"),color:i("fg"),borderRadius:"3px",marginRight:"6px"},mr={fontSize:"11px",color:i("muted")},Yu={padding:"20px",textAlign:"center",color:i("muted"),fontSize:"13px"},al=({selectedNodeId:e,...n})=>{const[o,r]=g.useState("loading"),[s,l]=g.useState(null);return g.useEffect(()=>{let d=!1;return Ku().then(p=>{d||(p?(l(p),r("ready")):r("missing"))}),()=>{d=!0}},[]),o==="loading"?t.jsx("div",{style:hr,children:"加载图组件中…"}):o==="missing"||!s?t.jsxs("div",{style:hr,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(qu,{modules:s,selectedNodeId:e,...n})};async function Ku(){try{const[e,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let o=!1;try{await import("@xyflow/react/dist/style.css"),o=!0}catch{o=!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:o}}catch{return null}}const qu=({graph:e,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:l,modules:d})=>{const{ReactFlow:p,Background:c,Controls:a,Handle:u,Position:f,BaseEdge:x,EdgeLabelRenderer:m,getSmoothStepPath:j,dagre:w}=d,h=g.useMemo(()=>({lineage:_=>{var X,Y,E,ee;const S=((X=_.data)==null?void 0:X.stepPosition)??.85,[z,N,T]=j({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:S,borderRadius:5}),C=!!((Y=_.data)!=null&&Y.isSibling),D=C?N:_.targetX-18,B=C?T:_.targetY-12,O=(E=_.data)==null?void 0:E.labelStyle,M=(ee=_.data)==null?void 0:ee.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(${D}px,${B}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:i("bg"),border:`0.5px solid ${i("widget-border")}`,...M,...O},children:_.label})})]})}}),[x,m,j]),b=g.useMemo(()=>({version:_=>{const S=_.data,z=S.kind==="hypothetical",N=S.status==="lost",T=S.isSelected,C=S.bridge,D=S.borderColor??i("muted"),B=C||z?"dashed":"solid",O=C?.5:N?.6:1;return t.jsxs("div",{style:{background:i(C?"bg-subtle":"bg"),border:`2px ${B} ${T?i("primary"):D}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:O,boxShadow:T?i("shadow-node-selected"):z||C?"none":i("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||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.2},children:sl(S.yearText,void 0,S.uncertain)}),N&&t.jsx("div",{style:{fontSize:9,color:i("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:f.Right,style:{visibility:"hidden"}})]})}}),[u,f]),{convert:y}=Z(),{rfNodes:k,rfEdges:$}=g.useMemo(()=>Ju(e,w,n,l,y),[e,w,n,l,y]);return t.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:t.jsxs(p,{nodes:k,edges:$,nodeTypes:b,edgeTypes:h,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(a,{showInteractive:!1})]})})};function Ju(e,n,o,r,s=l=>l??""){const p=e.layout==="LR"||!e.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:p?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const a=new Map(e.groups.map(b=>[b.id,b.color??i("muted")]));for(const b of e.nodes)c.setNode(b.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const b of e.edges)b.kind==="derive"&&(u.has(b.relation)||c.setEdge(b.source,b.target));n.layout(c);const f=e.nodes.map(b=>{const y=c.node(b.id),k=r?b.id===r:void 0,$={kind:b.kind,label:s(b.label),bookId:b.kind==="book"?b.id:void 0,yearText:s(b.year_text??Xu(b)),uncertain:b.year_uncertain,category:b.category,status:b.status,borderColor:b.group?a.get(b.group):void 0,renderLink:o,isSelected:k,description:s(b.description),bridge:b.bridge};return{id:b.id,type:"version",position:{x:y.x-160/2,y:y.y-90/2},data:$,draggable:!1,selected:k}}),x=.78,m=.06,j=new Map;for(const b of e.edges)b.kind==="derive"&&(j.has(b.source)||j.set(b.source,[]),j.get(b.source).push(b));const w=new Map;for(const[b,y]of j){if(y.length<=1)continue;const k=[...y].sort((v,_)=>{var N,T;const S=((N=c.node(v.target))==null?void 0:N.y)??0,z=((T=c.node(_.target))==null?void 0:T.y)??0;return S-z}),$=k.length;k.forEach((v,_)=>{const S=(_-($-1)/2)*m;w.set(v.id,x+S)})}const h=e.edges.map(b=>Zu(b,w.get(b.id),s));return{rfNodes:f,rfEdges:h}}function Zu(e,n,o=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Qu(e.confidence),d={type:"arrowclosed",color:l,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:o(e.relation),data:{labelStyle:{color:i("fg")},isSibling:s,stepPosition:n},style:{stroke:l,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:d,markerStart:s?d:void 0,zIndex:1e3}}function Xu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Qu(e){switch(e){case"certain":return i("confidence-certain");case"consensus":return i("lineage-edge-consensus");case"probable":return i("confidence-probable");case"disputed":return i("confidence-disputed");default:return i("muted")}}const hr={padding:"40px 20px",textAlign:"center",color:i("muted"),fontSize:"13px",border:`1px dashed ${i("widget-border")}`,borderRadius:8,background:i("bg")},Yi=({graph:e,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:d,onCollectionChange:p,collectionsAvailable:c,collectionCounts:a,className:u,style:f})=>{var y;const[x,m]=g.useState(n),j=k=>{m(k),l==null||l(k)},w=(()=>{if(!c)return[];const k=Object.entries(c);return k.length===0||c.all?k:[...k,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),h=!!(p&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:i("muted"),textAlign:"center"},children:"暂无版本传承数据"});const b=d?(y=c==null?void 0:c[d])==null?void 0:y.description:void 0;return t.jsxs("div",{className:u,style:f,children:[t.jsxs("div",{style:ex,children:[t.jsx("button",{onClick:()=>j("list"),style:On(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>j("graph"),style:On(x==="graph"),children:"关系图"}),h&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:i("muted"),marginRight:4},children:"集合:"}),w.map(([k,$])=>{const v=a==null?void 0:a[k];return t.jsxs("button",{onClick:()=>p==null?void 0:p(k),style:On(d===k),title:$.description,children:[$.label,v!=null?` ${v}`:""]},k)})]})]}),h&&b&&t.jsx("div",{style:{fontSize:12,color:i("muted"),marginBottom:8,padding:"4px 8px",background:i("bg-subtle"),borderRadius:4},children:b}),x==="list"?t.jsx(ll,{graph:e,renderLink:o}):t.jsx(al,{graph:e,renderLink:o,height:r,selectedNodeId:s})]})},ex={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},On=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${i("widget-border")}`,borderRadius:4,background:e?i("primary"):"transparent",color:i(e?"primary-fg":"fg"),cursor:"pointer"}),br=40,yr=2,tx=9,jr={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function Dn(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const cl=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,fullText:l,fullTextPending:d,chapterLink:p,railTop:c,back:a,railLinks:u})=>{var W,A,I,G,P,q,se,ke,be,Le,Ke;const f=ue(),{convert:x}=Z(),[m,j]=g.useState(null),[w,h]=g.useState(new Map),[b,y]=g.useState([]),[k,$]=g.useState(new Map),[v,_]=g.useState(!1),[S,z]=g.useState("flow"),[N,T]=g.useState(null);g.useEffect(()=>{if(!n||!e.work_id){j(null);return}let L=!1;return n.getItem(e.work_id).then(de=>{!L&&de&&de.type==="work"&&j(de)}).catch(()=>{}),()=>{L=!0}},[n,e.work_id]),g.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){T(null);return}let L=!1;return n.getLineageGraph(e.work_id).then(de=>{L||T(de&&de.nodes.length>1?de:null)}).catch(()=>{L||T(null)}),()=>{L=!0}},[n,e.work_id]),g.useEffect(()=>{const L=e.contained_in||[];if(!n||L.length===0){h(new Map);return}let de=!1;return Promise.all(L.map(fe=>{const ze=typeof fe=="string"?fe:fe.id;return n.getItem(ze).then(xe=>[ze,xe]).catch(()=>[ze,null])})).then(fe=>{if(de)return;const ze=new Map;for(const[xe,Ce]of fe)Ce&&ze.set(xe,Ce);h(ze)}),()=>{de=!0}},[n,e.contained_in]);const C=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]),D=C.length-1;g.useEffect(()=>{if(!n||D<=0){y([]);return}const L=C.length<=br,de=L?C:C.slice(0,8);let fe=!1;return Promise.all(de.map(ze=>ze===e.id?Promise.resolve({id:ze,title:e.title,edition:e.edition,year:mn(e)}):n.getItem(ze).then(xe=>{const Ce=xe??{};return{id:ze,title:Ce.title,edition:Ce.edition,year:xe?mn(Ce):void 0}}).catch(()=>({id:ze})))).then(ze=>{if(fe)return;const xe=ze.filter(Ce=>Ce.id===e.id||Ce.title||Ce.edition);L&&xe.sort((Ce,Oe)=>(Ce.year??1/0)-(Oe.year??1/0)),y(xe)}),()=>{fe=!0}},[n,C,D,e]);const B=e.lineage,O=g.useMemo(()=>[...((B==null?void 0:B.derived_from)||[]).filter(L=>L.ref_type==="book").map(L=>L.ref),...((B==null?void 0:B.related_to)||[]).map(L=>L.book_id)].filter(Boolean),[B]);g.useEffect(()=>{if(!n||O.length===0){$(new Map);return}let L=!1;return Promise.all(O.map(de=>n.getItem(de).then(fe=>[de,{id:de,title:fe==null?void 0:fe.title,edition:fe==null?void 0:fe.edition}]).catch(()=>[de,{id:de}]))).then(de=>{L||$(new Map(de))}),()=>{L=!0}},[n,O]);const M=g.useMemo(()=>nl(e.resources,e.resource_groups),[e.resources,e.resource_groups]),X=M.groups.reduce((L,de)=>L+de.rows.length+de.mirrors.length,0),Y=M.groups.length>0&&M.groups.every(L=>L.key==="_physical"),E=Zt(e),ee=Zr(e),F=at(e,f.unit.juan),K=new Set((e.contained_in||[]).map(L=>typeof L=="string"?0:Ut(L.volume_index).length).filter(L=>L>0)),ae=L=>{var ze;const de=(ze=e.base_edition)==null?void 0:ze.find(xe=>xe.book_id===L&&xe.name);if(de!=null&&de.name)return de.name;const fe=k.get(L);return(fe==null?void 0:fe.edition)||(fe==null?void 0:fe.title)||""},ne=g.useMemo(()=>{var ct,on,dt,rn,sn;const L=[];ee&&L.push({label:"版本類型",value:x(ee),title:e.edition_type||(ct=e.lineage)!=null&&ct.category?void 0:x("據版本題名推斷")}),(on=e.publication_info)!=null&&on.details?L.push({label:"刊印",value:x(e.publication_info.details)}):(E.era||E.reign)&&L.push({label:"刊寫年代",value:x([E.era,E.reign].filter(Boolean).join(" ")),title:E.source==="edition"?x("據版本題名推斷"):void 0}),F&&L.push({label:"卷帙",value:x(F)});const de=(e.contained_in||[]).flatMap(_e=>typeof _e=="string"?[]:Ut(_e.volume_index));de.length&&L.push({label:"冊次",value:x(`第 ${_n(de,f.unit.volume)} ${f.unit.volume}(${de.length} ${f.unit.volume})`)});const fe=(((dt=e.lineage)==null?void 0:dt.derived_from)||[]).find(_e=>_e.relation==="底本"&&_e.ref_type==="book");fe&&ae(fe.ref)&&L.push({label:"底本",value:t.jsx(Be,{id:fe.ref,label:x(ae(fe.ref)),onNavigate:o,renderLink:r,dense:!0})});const ze=(e.base_edition||[]).filter(_e=>_e&&_e.name);for(const _e of["底本","配補","參校"]){if(_e==="底本"&&fe&&ae(fe.ref))continue;const Xe=ze.filter(Ee=>Ee.role===_e);Xe.length&&L.push({label:_e,value:Xe.map((Ee,kt)=>t.jsxs(g.Fragment,{children:[kt>0&&"、",Ee.book_id?t.jsx(Be,{id:Ee.book_id,label:x(Ee.name),onNavigate:o,renderLink:r,dense:!0}):x(Ee.name)]},kt))})}const xe=(e.provenance||[]).filter(_e=>_e&&_e.institution),Ce=(e.resources||[]).filter(_e=>(_e.types||(_e.type?[_e.type]:[])).includes("physical"));if(xe.length){L.push({label:"存藏",value:xe.slice(0,2).map(Ee=>x(Ee.institution)).join("、")+(xe.length>2?x(` 等 ${xe.length} 處`):"")});const _e=xe.filter(Ee=>Ee.call_number).slice(0,2).map(Ee=>`${x(Ee.institution)} ${Ee.call_number}`);_e.length&&L.push({label:"索書號",value:_e.join(";")+(xe.filter(Ee=>Ee.call_number).length>2?"…":"")});const Xe=xe.flatMap(Ee=>Ee.seals||[]).filter(Boolean);Xe.length&&L.push({label:"藏印",value:x(Xe.join("、"))})}else Ce.length?L.push({label:"存藏",value:Ce.slice(0,2).map(_e=>x(_e.name)).join("、")+(Ce.length>2?x(` 等 ${Ce.length} 處`):"")}):(rn=e.current_location)!=null&&rn.name&&L.push({label:"存藏",value:x(e.current_location.name)});const Oe=e.physical_description;if(Oe){const _e=[["行款",Oe.leaf_style],["裝幀",Oe.binding],["尺寸",Oe.dimensions],["品相",Oe.condition]];for(const[Xe,Ee]of _e)Ee&&Ee.trim()&&L.push({label:Xe,value:x(Ee)})}(sn=e.page_count)!=null&&sn.description&&L.push({label:f.label.pageCount,value:x(e.page_count.description)});const Ze=[...ti(e.additional_titles),...ti(e.attached_texts)];return Ze.length&&L.push({label:"又名",value:Ze.map(x).join("、")}),L},[e,x,f,E,ee,F,k,o,r]),Q=x(e.title),ie=e.edition?x(e.edition):void 0,ge=((W=e.lineage)==null?void 0:W.year_text)||"",re=t.jsx(Qt,{kind:"版本",title:Q,subtitle:ie,byline:t.jsx(Ui,{authors:e.authors??(m==null?void 0:m.authors),onNavigate:o,renderLink:r}),meta:(()=>{const L=[ee?x(ee):"",E.era?x([E.era,E.reign].filter(Boolean).join("")):"",F?x(F):""].filter(Boolean);return L.length?t.jsx("span",{className:"bim-d-tags",children:L.map((de,fe)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(fe,2)}`,children:de},fe))}):null})(),description:(A=e.description)!=null&&A.text?t.jsx(lt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:_i((I=e.description)==null?void 0:I.text)?6:void 0,facts:ne,readAction:s,secondaryAction:s&&X>0&&!Y?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(en,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),le=e.contained_in||[],pe=(l==null?void 0:l.chapters)||[],Re=pe[0]&&Dn(pe[0].title)[0].slice(-1)||"章",$e=!!((G=B==null?void 0:B.derived_from)!=null&&G.length||(P=B==null?void 0:B.related_to)!=null&&P.length||(q=e.appendix)!=null&&q.length),ye=[];(pe.length||M.text.length||d)&&ye.push({id:"fulltext",label:"全文",count:pe.length?x(`${pe.length} ${Re}`):void 0}),M.groups.length&&ye.push({id:"images",label:Y?"館藏":"影印",count:X}),$e&&ye.push({id:"lineage",label:"版本源流"}),le.length&&ye.push({id:"collections",label:"收入叢編",count:le.length}),(se=e.location_history)!=null&&se.length&&ye.push({id:"provenance",label:"流轉歷史"});const Se=L=>(p==null?void 0:p(L))??null,Ne=pe[0],je=Ne?Se(Ne.file):null,H=v?pe:pe.slice(0,tx),ce=(L,de,fe)=>L?t.jsx("a",{className:fe,href:L.href??"#",onClick:L.onClick?ze=>{ze.metaKey||ze.ctrlKey||(ze.preventDefault(),L.onClick())}:void 0,children:de}):t.jsx("span",{className:fe,children:de}),oe=t.jsxs(t.Fragment,{children:[(pe.length>0||M.text.length>0||d)&&t.jsxs(Fe,{id:"fulltext",title:"全文",meta:pe.length>0?t.jsx(Me,{items:[x(`${pe.length} ${Re}`),(ke=l==null?void 0:l.source)!=null&&ke.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[d&&!Ne&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),Ne&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${Dn(Ne.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((Ne.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),ce(je,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),pe.length>1&&t.jsx("ul",{className:"bim-d-chap",children:H.map(L=>{const[de,fe]=Dn(L.title);return t.jsx("li",{children:ce(Se(L.file),t.jsxs(t.Fragment,{children:[de&&t.jsx("b",{children:x(de)}),x(fe||L.file)]}))},L.file)})}),pe.length>H.length&&t.jsx(Bt,{label:`展開其餘 ${pe.length-H.length} ${Re}`,onClick:()=>_(!0)}),M.text.length>0&&t.jsxs(t.Fragment,{children:[(pe.length>0||d)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:M.text.map((L,de)=>t.jsx(Vi,{item:L,siblings:M.text,listedVolumeCounts:K},`${L.id||L.url||L.name}-${de}`))})})]})]}),M.groups.length>0&&t.jsx(Fe,{id:"images",title:Y?"館藏":"影印",meta:t.jsx(Me,{items:[M.groups.length>1?x(`${M.groups.length} 組`):"",x(`${X} 處`)]}),children:t.jsx(ol,{groups:M.groups,listedVolumeCounts:K})}),$e&&t.jsx(Fe,{id:"lineage",title:"版本源流",meta:(be=B==null?void 0:B.derived_from)!=null&&be.length?x("據版本傳承著錄"):void 0,action:N?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":x("源流視圖"),children:[t.jsx("button",{type:"button","aria-pressed":S==="flow",onClick:()=>z("flow"),children:x("卡片")}),t.jsx("button",{type:"button","aria-pressed":S==="graph",onClick:()=>z("graph"),children:x("關係圖")})]}):void 0,children:S==="graph"&&N?t.jsx(Yi,{graph:N,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(L,de)=>t.jsx(Be,{id:L,label:x(de),onNavigate:o,renderLink:r,dense:!0})}):t.jsx(ix,{data:e,heading:ie||Q,yearText:ge,refName:ae,onNavigate:o,renderLink:r})}),le.length>0&&t.jsx(Fe,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:le.map((L,de)=>{var Oe,Ze;const fe=typeof L=="string"?L:L.id,ze=typeof L=="string"?[]:Ut(L.volume_index),xe=w.get(fe),Ce=(xe==null?void 0:xe._member_count)||((Oe=xe==null?void 0:xe.books)==null?void 0:Oe.length)||((Ze=xe==null?void 0:xe.contained_works)==null?void 0:Ze.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Be,{id:fe,label:xe?x(xe.title):fe,onNavigate:o,renderLink:r,dense:!0}),ze.length>0&&t.jsx(nx,{volumes:ze,unit:f.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Ce?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Ce>0&&x(`全 ${Ce} ${f.unit.bu}`)})]},`${fe}-${de}`)})})})}),(Le=e.location_history)!=null&&Le.length?t.jsx(Fe,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((L,de)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(L.name)}),([L.start_date,L.end_date].filter(Boolean).join("—")||L.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(Me,{items:[[L.start_date,L.end_date].filter(Boolean).join("—"),L.description?x(L.description):""]})})]},de))})}):null,ye.length===0&&t.jsx(Fe,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),he=b.findIndex(L=>L.id===e.id),me=C.length<=br,U=me&&he>=0?b.slice(Math.max(0,he-yr),he+yr+1):b.filter(L=>L.id!==e.id),R=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(Be,{id:m.id,label:x(m.title),onNavigate:o,renderLink:r})}),t.jsx(Me,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(m.authors||[]).slice(0,2).map(L=>`${L.dynasty?`〔${x(L.dynasty)}〕`:""}${x(L.name)}`),x(at(m,f.unit.juan)),m._edition_count?x(`${m._edition_count} 種版本`):""]}),((Ke=m.description)==null?void 0:Ke.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,""))})]}),D>0&&U.length>0&&t.jsxs("div",{children:[t.jsx(ht,{id:"siblings",timeline:!0,title:me?"同作品版本":f.relation.siblingVersions,meta:x(me?"按年代":`${D} 種`),cap:U.length,items:U.map(L=>L.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(L.edition||L.title||L.id)}):t.jsx(Be,{id:L.id,label:x(L.edition||L.title||L.id),onNavigate:o,renderLink:r,dense:!0})),metas:U.map(L=>[L.year!=null?L.year<0?`前${-L.year}`:String(L.year):"",L.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:U.findIndex(L=>L.id===e.id)}),m&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Be,{id:m.id,label:x(`在作品頁看全部 ${C.length} 種 →`),onNavigate:o,renderLink:r,dense:!0})})]})]}),V=e.work_id?t.jsx(ns,{caption:f.section.belongsToWork,children:t.jsx(Be,{id:e.work_id,label:m?x(m.title):" ",onNavigate:o,renderLink:r,dense:!0})}):void 0;return t.jsx(Xt,{railTop:c,back:a,up:V,nav:ye,railLinks:u,main:oe,card:re,side:R})};function nx({volumes:e,unit:n}){const{convert:o}=Z();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[o(`第 ${_n(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),o(`${e.length} ${n}`)]})]})}function ix({data:e,heading:n,yearText:o,refName:r,onNavigate:s,renderLink:l}){var h;const{convert:d}=Z(),p=e.lineage,c=(p==null?void 0:p.derived_from)||[],a=c.filter(b=>b.ref_type!=="book"),u=c.filter(b=>b.ref_type==="book"&&b.relation==="底本"),f=c.filter(b=>b.ref_type==="book"&&b.relation!=="底本"),x=(p==null?void 0:p.related_to)||[],m=c.length>0||x.length>0,j=b=>b&&jr[b]?d(`(${jr[b]})`):"",w=(b,y)=>t.jsx(Be,{id:b,label:d(y||b),onNavigate:s,renderLink:l,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[m&&t.jsxs("ol",{className:"bim-d-lf-list",children:[a.map((b,y)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(b.relation||"祖本")}),t.jsx("span",{className:"bim-d-lf-name",children:d("擬構祖本")}),b.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[d(b.evidence),j(b.confidence)]})]})},`a-${y}`)),u.map((b,y)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(b.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:w(b.ref,r(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),j(b.confidence)]})]})},`b-${y}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d("本版")}),t.jsx("span",{className:"bim-d-lf-name",children:n}),o&&t.jsx("span",{className:"bim-d-lf-yr",children:d(o)})]}),f.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:f.map((b,y)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(b.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:w(b.ref,r(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),j(b.confidence)]})]},y))})]}),x.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:d("翻刻 · 衍生")}),t.jsx("span",{className:"bim-d-lf-chips",children:x.map((b,y)=>t.jsxs("span",{className:"bim-d-lf-chip",title:b.evidence?d(b.evidence):void 0,children:[w(b.book_id,r(b.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(b.relation)})]},y))})]})]}),(h=e.appendix)==null?void 0:h.map((b,y)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:d("附記")})," ",d(b.title)]}),t.jsx(lt,{text:b.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${y}`)),(p==null?void 0:p.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:d(p.note)})]})}const Dt=16,ox=200,rx=16,dl=({data:e,catalog:n,transport:o,onNavigate:r,renderLink:s,catalogAction:l,railTop:d,back:p,railLinks:c})=>{var he,me,U,R,V,W,A;const a=ue(),{convert:u}=Z(),[f,x]=g.useState(""),[m,j]=g.useState(!1),[w,h]=g.useState(null),[b,y]=g.useState(""),[k,$]=g.useState(!1),v=g.useMemo(()=>qr(e,n),[e,n]),[_,S]=g.useState(new Map),z=!!o&&v.rows.length>0&&v.rows.length<=ox,N=z&&(v.rows.length<=Dt||k),T=N&&v.rows.every(I=>!I.id||_.has(I.id)),C=I=>{var G;return di(I?(G=_.get(I))==null?void 0:G.l1:void 0)},D=g.useMemo(()=>{const I=f.trim(),G=I?u(I):"";return v.rows.filter(P=>{var se,ke;if(b&&di(P.id?(se=_.get(P.id))==null?void 0:se.l1:void 0)!==b)return!1;if(!G)return!0;const q=P.id&&((ke=_.get(P.id))==null?void 0:ke.title)||P.title;return u(q).includes(G)||(P.subItems||[]).some(be=>u(be).includes(G))})},[v.rows,f,b,_,u]),B=m?D:D.slice(0,Dt),O=g.useMemo(()=>(N?v.rows:B).filter(I=>I.id&&!_.has(I.id)).map(I=>I.id),[N,v.rows,B,_]);g.useEffect(()=>{if(!o||O.length===0)return;let I=!1;const G=O.slice(0,rx);return Promise.all(G.map(P=>o.getItem(P).then(q=>{var be,Le;const se=q??{},ke={title:se.title,edition:se.edition,authors:se.authors,measure:q?at(q,a.unit.juan):void 0,versionCount:se._edition_count??((be=se.books)==null?void 0:be.length),l1:((Le=se.classification)==null?void 0:Le.l1)||void 0};return[P,ke]}).catch(()=>[P,{}]))).then(P=>{I||S(q=>{const se=new Map(q);for(const[ke,be]of P)se.set(ke,be);return se})}),()=>{I=!0}},[o,O,a.unit.juan]);const M=(e.contained_in||[])[0];g.useEffect(()=>{if(!M){h(null);return}if(h({id:M}),!o)return;let I=!1;return o.getItem(M).then(G=>{I||h({id:M,title:G==null?void 0:G.title})}).catch(()=>{}),()=>{I=!0}},[o,M]);const X=g.useMemo(()=>nl(e.resources,e.resource_groups),[e.resources,e.resource_groups]),Y=X.text.length+X.groups.reduce((I,G)=>I+G.rows.length+G.mirrors.length,0),E=e.contained_works||[],ee=new Set(v.rows.map(I=>I.id).filter(Boolean)),F=E.length>0&&!E.every(I=>ee.has(I.id)),K=(()=>{const I=v.rows.map(G=>G.edition).filter(Boolean);return I.length>1&&new Set(I).size===1})(),ae=v.rows.some(I=>I.volumes.length>0||I.expected!=null),ne=e._member_count||((he=e.books)==null?void 0:he.length)||E.length,Q=at(e,a.unit.juan),ie=e.count,ge=I=>typeof I=="number"&&Number.isFinite(I)?I:null,re=ge(ie==null?void 0:ie.juan)??ge((me=e.juan_count)==null?void 0:me.number),le=ge(ie==null?void 0:ie.ce)??(v.totalVolumes||null),pe=[{value:v.rows.length,label:"子目"},{value:re??0,label:a.unit.juan},{value:le??0,label:a.unit.volume}],Re=g.useMemo(()=>{var P,q;const I=[];if((P=e.publication_info)!=null&&P.details&&I.push({label:"刊印",value:u(e.publication_info.details)}),ne&&ne!==v.rows.length){const se=e._member_type==="Book"?"所收版本":e._member_type==="Work"?"所收作品":"成員";I.push({label:u(se),value:`${ne} ${u(a.unit.bu)}`,title:u("子目與其各版本合計")})}const G=[ge(ie==null?void 0:ie.zhong)!=null?`${ie.zhong} 種`:"",ge(ie==null?void 0:ie.han)!=null?`${ie.han} 函`:""].filter(Boolean);return G.length&&I.push({label:"應收",value:u(G.join(" "))}),re==null&&Q&&I.push({label:"卷帙",value:u(Q),title:(q=e.juan_count)!=null&&q.description?u(e.juan_count.description):void 0}),I},[e,ne,v.rows.length,re,Q,ie,u,a]),$e=g.useMemo(()=>{if(!T)return[];const I=new Map;for(const P of v.rows){const q=C(P.id);q&&I.set(q,(I.get(q)??0)+1)}const G=Yt.filter(P=>(I.get(P.key)??0)>0);return G.length<2?[]:[{key:"",label:`${a.catalog.all} ${v.rows.length}`},...G.map(P=>({key:P.key,label:`${P.label} ${I.get(P.key)}`}))]},[T,v.rows,_,a]),ye=g.useMemo(()=>{if(!T||!v.rows.some(q=>q.volumes.length>0))return null;const I=[],G=v.rows.filter(q=>q.volumes.length>0).map(q=>({k:C(q.id)??"",from:Math.min(...q.volumes),to:Math.max(...q.volumes)})).sort((q,se)=>q.from-se.from);for(const q of G){const se=q.to-q.from+1,ke=I[I.length-1];ke&&ke.key===q.k?(ke.to=Math.max(ke.to,q.to),ke.n+=se):I.push({key:q.k,from:q.from,to:q.to,n:se})}const P=G.reduce((q,se)=>Math.max(q,se.to),0);return I.length>1&&I.some(q=>q.key)?{segs:I,last:P}:null},[T,v.rows,_]),Se=(U=e.description)==null?void 0:U.text,Ne=t.jsx(Qt,{kind:"叢編",title:u(e.title),byline:t.jsx(Ui,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Me,{items:[e.subtype==="work_collection"?u("作品集"):"",(R=e.publication_info)!=null&&R.year?u(e.publication_info.year):""]}),description:Se||(V=e.history)!=null&&V.length?t.jsxs(t.Fragment,{children:[Se&&t.jsx(lt,{text:Se,style:{fontSize:15,lineHeight:1.85}}),(W=e.history)!=null&&W.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((I,G)=>t.jsx("li",{children:u(I)},G))}):null]}):void 0,clampDescription:_i(Se)||(((A=e.history)==null?void 0:A.length)??0)>2?6:void 0,stats:pe,facts:Re,foot:t.jsx(en,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ye&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:u("全帙冊次分佈")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":u("全帙冊次分佈"),children:ye.segs.map((I,G)=>{const P=Yt.find(q=>q.key===I.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!P,title:P?u(`${P.label} 第 ${I.from}–${I.to} 冊`):void 0,"aria-label":u(P?`只看${P.label}`:"未分類"),"aria-pressed":!!P&&b===I.key,style:{flexGrow:I.n,background:i(P?P.token:"rule")},onClick:()=>{P&&(y(b===I.key?"":I.key),j(!1))}},G)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:u(`第 1 ${a.unit.volume}`)}),t.jsx("span",{children:u("點色段篩選部類")}),t.jsx("span",{children:u(`第 ${ye.last} ${a.unit.volume}`)})]})]})}),je=[];v.rows.length&&je.push({id:"titles",label:"子目",count:v.rows.length}),Y&&je.push({id:"resources",label:"影印與全文",count:Y}),F&&je.push({id:"works",label:a.section.containedWorks,count:E.length});const H=t.jsxs(t.Fragment,{children:[v.rows.length>0&&t.jsxs(Fe,{id:"titles",title:"子目",meta:t.jsx(Me,{items:[u(`${v.rows.length} ${a.unit.items}`),v.totalVolumes?u(`全帙 ${v.totalVolumes} ${a.unit.volume}`):"",D.length!==v.rows.length?u(`當前 ${D.length} ${a.unit.items}`):""]}),action:l,children:[(v.rows.length>Dt||$e.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[$e.length>0&&t.jsx($n,{items:$e,value:b,onChange:I=>{y(I),j(!1)}}),z&&v.rows.length>Dt&&!T&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:k,onClick:()=>$(!0),title:u(`將載入全部 ${v.rows.length} ${a.unit.items}`),children:u(k?"正在按部類分組…":"按部類分組")}),t.jsx("span",{className:"bim-d-spacer"}),v.rows.length>Dt&&t.jsx("input",{type:"search",className:"bim-d-find",value:f,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:I=>{x(I.target.value),j(!1)}})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[ae&&t.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),t.jsx("th",{children:u("書名")}),t.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),t.jsx("tbody",{children:B.map((I,G)=>{var Ke;const P=I.id?_.get(I.id):void 0,q=P!=null&&P.title&&I.title===I.id?P.title:I.title,se=((P==null?void 0:P.authors)||[]).find(L=>L&&L.name),ke=[se?`${se.dynasty?`〔${u(se.dynasty)}〕`:""}${u(se.name)}${se.role?` ${u(se.role)}`:""}`:"",P!=null&&P.measure?u(P.measure):"",(Ke=I.subItems)!=null&&Ke.length?I.subItems.map(L=>u(L)).join("、"):"",(P!=null&&P.edition||I.edition)&&!K?u((P==null?void 0:P.edition)||I.edition||""):""].filter(Boolean),be=Yt.find(L=>L.key===C(I.id)),Le=I.volumes.length>0?u(`第 ${_n(I.volumes,a.unit.volume)} ${a.unit.volume}`):I.expected!=null?u(`${I.found??0}/${I.expected} ${a.unit.volume}`):"";return t.jsxs("tr",{children:[ae&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Le?"":" bim-d-zt-blank"}`,children:[be&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:i(be.token)}}),Le||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[I.id?t.jsx(Be,{id:I.id,label:u(q),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(q)}),ke.length>0?t.jsx(Me,{items:ke}):I.id&&!P&&o?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${P!=null&&P.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:P!=null&&P.versionCount?u(`${P.versionCount} 種`):""})]},`${I.id??I.title}-${G}`)})})]}),B.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(a.catalog.noMatch)}),D.length>B.length&&t.jsx(Bt,{label:`展開其餘 ${D.length-B.length} ${a.unit.items}`,onClick:()=>j(!0)})]}),Y>0&&t.jsxs(Fe,{id:"resources",title:"影印與全文",meta:u(`${Y} 處`),children:[X.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[X.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:X.text.map((I,G)=>t.jsx(Vi,{item:I,siblings:X.text},`${I.id||I.url||I.name}-${G}`))})})]}),t.jsx(ol,{groups:X.groups})]}),v.rows.length===0&&Y===0&&t.jsx(Fe,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),ce=F?t.jsx(ht,{id:"works",title:a.section.containedWorks,meta:u(`${E.length} 種`),cap:12,items:E.map(I=>t.jsx(Be,{id:I.id,label:u(I.title),onNavigate:r,renderLink:s,dense:!0}))}):null,oe=w?t.jsx(ns,{caption:"上級叢編",children:t.jsx(Be,{id:w.id,label:u(w.title||w.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(Xt,{railTop:d,back:p,up:oe,nav:je,railLinks:c,main:H,card:Ne,side:ce})},sx=16,Hn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function vr(e){if(!e)return Hn.length;const n=Hn.indexOf(e);return n===-1?Hn.length:n}const lx={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function xt(e){return e==null?"":e<0?`前${-e}`:String(e)}const ax={秦:[-221,-207],西漢:[-202,8],西汉:[-202,8],東漢:[25,220],东汉:[25,220],漢:[-202,220],汉:[-202,220],三國:[220,280],三国:[220,280],西晉:[265,316],西晋:[265,316],東晉:[317,420],东晋:[317,420],隋:[581,618],唐:[618,907],五代:[907,960],北宋:[960,1127],南宋:[1127,1279],宋:[960,1279],遼:[916,1125],辽:[916,1125],金:[1115,1234],元:[1271,1368],明:[1368,1644],清:[1636,1912]},pl=({data:e,transport:n,onNavigate:o,renderLink:r,railTop:s,back:l,railLinks:d})=>{var ce,oe,he,me,U;const p=ue(),{convert:c}=Z(),[a,u]=g.useState("全部"),[f,x]=g.useState(!1),[m,j]=g.useState("default"),[w,h]=g.useState(new Map),b=g.useMemo(()=>(e.works||[]).map(R=>{const V=w.get(R.work_id);return{id:R.work_id,title:(V==null?void 0:V.title)??R.title??R.work_id,role:R.role||"",cls:wi(R.role),versionCount:V==null?void 0:V.versionCount,section:V==null?void 0:V.cls,l1:V==null?void 0:V.l1,measure:V==null?void 0:V.measure,hasImage:V==null?void 0:V.hasImage,loaded:!!(V!=null&&V.loaded)}}),[e.works,w]),y=g.useMemo(()=>Kr((e.works||[]).map(R=>R.role)),[e.works]),k=g.useMemo(()=>{const R=a==="全部"?b:b.filter(V=>V.cls===a);return m==="versions"?[...R].sort((V,W)=>(W.versionCount??-1)-(V.versionCount??-1)):R},[b,a,m]),$=f?k:k.slice(0,sx),v=g.useMemo(()=>$.filter(R=>!w.has(R.id)).map(R=>R.id),[$,w]);g.useEffect(()=>{if(!n||v.length===0)return;let R=!1;return Promise.all(v.map(V=>n.getItem(V).then(W=>{var P,q,se,ke,be;const A=W??{},I=A._edition_count??(((P=A.books)==null?void 0:P.length)??0)+(((q=A.collections)==null?void 0:q.length)??0),G=[(se=A.classification)==null?void 0:se.l1,(ke=A.classification)==null?void 0:ke.l2].filter(Boolean).join(" ");return[V,{id:V,title:A.title,versionCount:I,loaded:!0,cls:G||void 0,l1:((be=A.classification)==null?void 0:be.l1)||void 0,measure:W&&at(W,p.unit.juan)||void 0,hasImage:!!(A.has_image??A._has_image)}]}).catch(()=>[V,{id:V,loaded:!0}]))).then(V=>{R||h(W=>{const A=new Map(W);for(const[I,G]of V)A.set(I,G);return A})}),()=>{R=!0}},[n,v,p.unit.juan]);const _=g.useMemo(()=>{const R=new Map;for(const V of e.alt_names||[]){const W=V.type||p.section.aliases;R.has(W)||R.set(W,[]),R.get(W).push(V.name)}return[...R.entries()].sort((V,W)=>vr(V[0])-vr(W[0])).map(([V,W])=>({label:V,names:W}))},[e.alt_names,p]),S=e.birth_year??((ce=e.dates)==null?void 0:ce.birth)??void 0,z=e.death_year??((oe=e.dates)==null?void 0:oe.death)??void 0,N=(he=e.dates)==null?void 0:he.floruit,T=S!=null||z!=null?`${xt(S)||"?"}—${xt(z)||"?"}`:Array.isArray(N)&&N.length===2&&N.every(R=>Number.isFinite(R))?`活躍於 ${xt(N[0])}—${xt(N[1])}`:"",C=new Set(["本名","字","號","号"]),D=_.filter(R=>C.has(R.label)),B=_.filter(R=>!C.has(R.label)),O=B.reduce((R,V)=>R+V.names.length,0),M=g.useMemo(()=>{const R=[];for(const W of D)R.push({label:W.label,value:W.names.map(A=>c(A)).join("、")});const V=(e.works||[]).length;return V&&R.push({label:"著作",value:`${V} ${c("種")}`}),R},[e.works,D,c]),X=R=>{var V;return(V=_.find(W=>R.includes(W.label)))==null?void 0:V.names[0]},Y=X(["字"]),E=X(["號","号"]),ee=[Y?`字${Y}`:"",E?`號${E}`:""].filter(Boolean).join(","),F=e.native_place,K=e.dynasty?ax[e.dynasty]:void 0,ae=(()=>{if(!K||S==null||z==null||z<S)return null;const[R,V]=K,W=Math.max(S,R),A=Math.min(z,V);if(A<=W)return null;const I=V-R;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":c(`${xt(S)}—${xt(z)},一生 ${z-S+1} 年`),children:t.jsx("i",{style:{left:`${(W-R)/I*100}%`,width:`${(A-W)/I*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:c(`${xt(R)} ${e.dynasty}`)}),t.jsx("span",{children:c(`一生 ${z-S+1} 年`)}),t.jsx("span",{children:xt(V)})]})]})})(),ne=g.useMemo(()=>{if(!n||b.length===0||b.some(W=>!W.loaded))return null;const R=new Map;for(const W of b){const A=di(W.l1);A&&R.set(A,(R.get(A)??0)+1)}const V=Yt.map(W=>({...W,n:R.get(W.key)??0})).filter(W=>W.n>0);return V.length?V:null},[b,n]),Q=t.jsxs(Qt,{kind:lx[e.subtype]??"人物",title:c(e.primary_name||e.title),subtitle:ee?c(ee):void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(Me,{items:[e.dynasty?c(e.dynasty):"",T?c(T):"",F?c(`${F}人`):""]}),ae]}),description:(me=e.description)!=null&&me.text?t.jsx(lt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:_i((U=e.description)==null?void 0:U.text)?6:void 0,facts:M,foot:t.jsx(en,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[O>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c(`更多別名(${O})`)}),t.jsx("dl",{children:B.map(R=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:c(R.label)}),t.jsx("dd",{children:R.names.map(V=>c(V)).join("、")})]},R.label))})]}),ne&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:c("著作分佈")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:ne.map(R=>t.jsx("i",{style:{flexGrow:R.n,background:i(R.token)}},R.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ne.map(R=>t.jsxs("span",{children:[t.jsx("i",{style:{background:i(R.token)}}),c(R.label)," ",R.n]},R.key))})]})]}),ie=g.useMemo(()=>b.filter(R=>R.loaded&&(R.versionCount??0)>0).sort((R,V)=>(V.versionCount??0)-(R.versionCount??0)).slice(0,3),[b]),ge=!!n&&b.length>=3&&$.some(R=>!R.loaded),re=a==="全部"&&(ge||ie.length>=2),le=e.external_ids||{},pe=[];le.cbdb_id!=null&&pe.push({label:"CBDB",id:String(le.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${le.cbdb_id}`,note:le.cbdb_match==="auto"?"自動匹配":void 0});const Re=le.wikidata_id;Re&&pe.push({label:"Wikidata",id:Re,href:`https://www.wikidata.org/wiki/${Re}`});const $e=le.viaf_id;$e&&pe.push({label:"VIAF",id:$e,href:`https://viaf.org/viaf/${$e}`});const ye=y.map(R=>({key:R.cls,label:`${R.label} ${R.count}`})),Se=[...re&&!ge?[{id:"featured",label:"著作舉要",count:ie.length}]:[],...b.length?[{id:"works",label:"全部著作",count:b.length}]:[],...pe.length?[{id:"external",label:"站外資料",count:pe.length}]:[]],Ne=re?t.jsxs(Fe,{id:"featured",title:"著作舉要",children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:c("存世版本最多的三部")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":ge||void 0,children:[ge&&[0,1,2].map(R=>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:" "})]},R)),!ge&&ie.map(R=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Be,{id:R.id,label:c(R.title),onNavigate:o,renderLink:r,dense:!0})}),t.jsx(Me,{items:[R.section?c(R.section):"",R.measure?c(R.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:R.versionCount}),t.jsx("span",{children:c("種版本")}),R.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("有影印")})]})]},R.id))]})]}):null,je=b.length===0?t.jsx(Fe,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該人物的關聯作品。")})}):t.jsxs(t.Fragment,{children:[Ne,t.jsxs(Fe,{id:"works",title:"著作",meta:t.jsx(Me,{items:[c(`共 ${b.length} 種`),k.length!==b.length?c(`當前 ${k.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ye.length>1&&t.jsx($n,{items:ye,value:a,onChange:R=>{u(R),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),j(R=>R==="default"?"versions":"default")},children:c(m==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("作品")}),t.jsx("th",{children:c("部類")}),t.jsx("th",{children:c("職任")}),t.jsx("th",{children:c("存世版本")}),t.jsx("th",{"aria-label":c("影印")})]})}),t.jsx("tbody",{children:$.map(R=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Be,{id:R.id,label:c(R.title),onNavigate:o,renderLink:r,dense:!0}),R.measure?t.jsx(Me,{items:[c(R.measure)]}):!R.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${R.section||R.loaded?"":" bim-d-zt-blank"}`,children:R.section?c(R.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${R.role?"":" bim-d-zt-blank"}`,children:R.role?c(R.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${R.loaded?"":" bim-d-zt-blank"}`,children:R.loaded?R.versionCount?c(`${R.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:c("未著錄")}):""}),t.jsx("td",{className:R.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:R.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("有影印")})})]},R.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("該職任下的著作尚未著錄。")}),k.length>$.length&&t.jsx(Bt,{label:`展開其餘 ${k.length-$.length} 種著作`,onClick:()=>x(!0)})]})]}),H=pe.length>0?t.jsx(ht,{id:"external",title:"站外資料",items:pe.map(R=>t.jsxs("a",{href:R.href,target:"_blank",rel:"noopener noreferrer",children:[R.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:pe.map(R=>R.id),foot:le.cbdb_id!=null&&le.cbdb_match==="auto"?c("CBDB 為自動匹配,未經人工核對"):void 0}):null;return t.jsx(Xt,{railTop:s,back:l,nav:Se,railLinks:d,main:je,card:Q,side:H})},Ki="(max-width: 719px)",cx=`${Ki}, (pointer: coarse)`,ul=`
1013
+ `)}),s=[]};for(const c of n){const p=Yi(c);if(p){l(),r={kind:"heading",level:p.level,text:p.text};continue}s.push(c)}return l(),o}function tr(e){const n=[];for(const o of e.split(`
1014
+ `)){const r=Yi(o);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=o.trim();!s||Ki.test(s)||n.push({kind:"body",text:o})}return n}function sl(e){if(!e)return[];const n=Bn(e);if(n==="unknown")return tr(e);const o=[];for(const{heading:r,body:s}of cp(e)){r&&o.push(r);const l=il(s);if(l.length!==0){if(rl(s)){o.push(...tr(s));continue}if(n==="record"){const c=l.join(" ");c&&o.push({kind:"body",text:c})}else for(const c of l){const p=ol(c);p.length&&o.push({kind:"body",text:p.join(" ")})}}}return o}const ll=e=>e;function al(e,n=ll){if(e.indexOf("《")<0)return n(e);const o=[],r=/《([^《》\n]+)》/g;let s=0,l=0,c;for(;c=r.exec(e);)c.index>s&&o.push(t.jsx(f.Fragment,{children:n(e.slice(s,c.index))},l++)),o.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&&o.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),o)}function qi(e,n={}){const o=n.renderText??ll,r=n.properNames?l=>al(l,o):o,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Ke(e,r,s)}function nr(e,n,o){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))},`${o}-${l}`):t.jsx(f.Fragment,{children:n(s)},`${o}-${l}`))}const Yn=/^(#{1,6})\s+(.*)$/,dp=/^\s*<!--.*-->\s*$/;function cl(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
1015
+ `)?"":n)}function pp(e){return e<=1?2:e===2?3:4}function up(){let e=1;return n=>{const o=pp(n),r=Math.min(o,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${o}`}}}function Qt(e){return e?Bn(cl(e))!=="unknown":!1}function ir({text:e,mode:n,inline:o,dropTitle:r}){const s=cl(e),l=(d,u,m)=>!!r&&m<=1&&d<=2&&u.trim()===r.trim(),c=up();if(n==="paragraph"&&Bn(s)!=="unknown"){const d=sl(s);return t.jsx(t.Fragment,{children:d.map((u,m)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,m))return null;const{Tag:x,className:g}=c(u.level??1);return t.jsx(x,{className:g,children:o(u.text)},m)}return t.jsx("p",{children:nr(u.text,o,m)},m)})})}const p=s.split(`
1016
+ `);let a=0;return t.jsx(t.Fragment,{children:p.map((d,u)=>{const m=d.match(Yn);if(m){const g=a++;if(l(m[1].length,m[2],g))return null;const{Tag:b,className:w}=c(m[1].length);return t.jsx(b,{className:w,children:o(m[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Yn.test(p[u-1])&&!Yn.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(dp.test(d))return null;if(a++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:g,className:b}=c(3);return t.jsx(g,{className:b,children:o(d.trim().slice(2,-2))},u)}return t.jsx("p",{children:nr(d,o,u)},u)})})}function xp(e){const{convert:n}=V();return f.useMemo(()=>e?n(e):"",[e,n])}function Ji({text:e,mode:n,tables:o=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:c}){const p=xp(e),{convert:a}=V(),d=x=>qi(x,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,m=c?a(c):void 0;return!o||p.indexOf(":::")<0?t.jsx(ir,{text:p,mode:n,inline:d,dropTitle:m}):t.jsx(t.Fragment,{children:Ui(p).map((x,g)=>x.type==="table"?t.jsx(Vi,{table:x.table,opts:u},g):t.jsx(ir,{text:x.text,mode:n,inline:d,dropTitle:g===0?m:void 0},g))})}function dl(e,n){const[o,r]=f.useState(null),[s,l]=f.useState(!1),c=f.useRef(0);return f.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:o,loading:s}}const or={A:"fine",B:"rough",C:"rough",D:"ocr"};function fp(e){return typeof e!="string"?null:e in ti?e:e in or?or[e]:null}const mp={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},gp={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function Je(e){return typeof e!="string"?"":mp[e]??gp[e]??e}const hp=["〇","一","二","三","四","五","六","七","八","九"],rr=["","十","百","千"],bp=["","萬","億"];function Zi(e){if(e===0)return"〇";if(e<0)return`負${Zi(-e)}`;const n=[];let o=e,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(yp(s,r>0)+bp[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function yp(e,n){const o=[];let r=e;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let s="";for(let l=0;l<o.length;l++){const c=o[l],p=o.length-1-l;c===0?s&&!s.endsWith("〇")&&(s+="〇"):c===1&&p===1&&l===0&&!n?s+=rr[p]:s+=hp[c]+rr[p]}return s.replace(/〇$/,"")}let Zt=null,fn=null;const kn=new Set;function jp(){return Zt?Promise.resolve():fn||(fn=import("opencc-js/t2cn").then(e=>{Zt=e.Converter({from:"tw",to:"cn"}),kn.forEach(n=>n())}).catch(()=>{Zt=e=>e,kn.forEach(e=>e())}),fn)}const vp=e=>e;function wt(){const[,e]=f.useState(0);return f.useEffect(()=>{if(Zt)return;const n=()=>e(o=>o+1);return kn.add(n),jp(),()=>{kn.delete(n)}},[]),Zt??vp}function Nt(e,n){return n(e).toLowerCase()}const kp=i("highlight-bg");function sn(e,n,o){if(!n)return e;const r=Nt(n,o);if(!r)return e;const s=Nt(e,o);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:kp,padding:0,color:"inherit"},children:e.slice(a,a+r.length)},p++)),c=a+r.length}return t.jsx(t.Fragment,{children:l})}function Xi(e,n,o,r){if(!n)return!0;const s=Nt(n,r);return(o?[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"&&Nt(c,r).includes(s))}function wp(e,n,o){return n?Nt(e,o).includes(Nt(n,o)):!0}const Qi={类:i("section-lei"),书:i("section-shu"),序:i("section-xu"),结语:i("section-jieyu"),注释:i("section-zhushi")},Sp={考证:i("section-kaozhen")};function $p(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 pl(e){var r;const n=e.files.length,o=((r=e.children)==null?void 0:r.reduce((s,l)=>s+pl(l),0))||0;return n+o}function _p(e,n){const o=[],r=c=>{var p;o.push(...c.files),(p=c.children)==null||p.forEach(r)};if(r(e),o.length===0)return;const s=o.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 zp={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function eo({enabled:e,expanded:n,onClick:o,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:o,style:{...zp,...r},children:s}):t.jsx("span",{style:r,children:s})}function Cp({type:e}){const n=Je(e),o=Qi[n]||i("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:o,border:`1px solid ${o}40`,borderRadius:"2px",background:`${o}08`,flexShrink:0},children:n})}function Tp({section:e,onNavigate:n,highlightQuery:o="",no:r,showUnlinked:s=!1,domId:l}){const{convert:c}=V(),p=Fe(),a=wt(),d=h=>h?Ke(c(h),v=>o?sn(v,o,a):v):"",[u,m]=f.useState(!1),x=!!e.summary,g=!!e.comment,b=!!e.additional_comment,w=!!(e.content&&e.content.length>60),y=x||g||b||w;f.useEffect(()=>{o&&m(!0)},[o]);const j=!u&&w?As(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{className:"bim-rd-row",id:l,style:{borderBottom:`1px solid ${i("rule")}`,overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>y&&m(!u),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:y?"pointer":"default",userSelect:"none"},children:[r!=null&&t.jsx("span",{className:"bim-rd-no",style:{flex:"none",width:28,fontSize:12,color:i("label-fg")},children:r}),t.jsxs(eo,{enabled:y,expanded:u,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[y&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),transition:"transform 0.15s",transform:u?"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:i("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",d(e.book_title),"》"]}):d(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[Zi(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:d(e.author_info||e.author)})]}),!u&&j&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:d(j)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:d(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:i("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:p(e.work_id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),h.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品","aria-label":`查看作品:${e.book_title||e.title}`,children:"作品 →"}),s&&!e.work_id&&t.jsx("span",{style:{fontSize:"11px",color:i("label-fg"),flexShrink:0},children:"未关联"})]}),u&&y&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${i("widget-border")}`,background:i("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"8px"},children:d(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${i("primary")}`,background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:d(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(e.additional_comment)})]}),w&&!x&&!g&&!b&&t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:d(e.content)})]})]})}function Ip({section:e,highlightQuery:n=""}){const{convert:o}=V(),r=wt(),s=a=>a?Ke(o(a),d=>n?sn(d,n,r):d):"",[l,c]=f.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(eo,{enabled:p,expanded:l,onClick:()=>c(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(Cp,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:s(e.title)}),p&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("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, ${Qi[Je(e.type)]||i("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:i("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(e.content)})})]})}const Ep=100;function to(e){return Je(e.type)!=="page_header"?!1:(e.content||"").length>=Ep}function Rp({section:e,highlightQuery:n=""}){const{convert:o}=V(),r=wt();if(Je(e.type)==="page_header"&&!to(e)||!e.content&&!e.title)return null;const s=o((e.content||e.title||"").replace(/\n{2,}/g,`
1017
+ `)),l=Ke(s,d=>n?sn(d,n,r):d),c=Je(e.type),p=Qi[c]||i("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:i("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${p}40`:void 0,background:a?i("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 Np(e,n,o){const[r,s]=f.useState({});return f.useEffect(()=>{var d;if(!n||e.length===0)return;let l=!1;const c=e.filter(u=>{var m;return!((m=o==null?void 0:o.current)!=null&&m.has(u))}),p={};for(const u of e)(d=o==null?void 0:o.current)!=null&&d.has(u)&&(p[u]=o.current.get(u));if(Object.keys(p).length>0&&s(p),c.length===0)return;const a=async u=>{var m;try{if(n.getEntry){const y=await n.getEntry(u);if(y)return{title:y.title,author:y.author}}const x=await n.getItem(u);if(!x)return null;const g=x.title||u,b=x.authors,w=(m=b==null?void 0:b[0])==null?void 0:m.name;return{title:g,author:w}}catch{return null}};return Promise.all(c.map(async u=>{var x;const m=await a(u);return(x=o==null?void 0:o.current)==null||x.set(u,m),[u,m]})).then(u=>{l||s(m=>{const x={...m};for(const[g,b]of u)x[g]=b;return x})}),()=>{l=!0}},[e.join(","),n]),r}function Lp({section:e,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=V(),c=Fe(),p=wt(),a=h=>h?Ke(l(h),v=>s?sn(v,s,p):v):"",[d,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const m=Je(e.type),x=Sp[m]||i("desc-fg"),g=!!e.content,b=e.work_ids||[],w=b.length>1,y=Np(w?b:[],o,r),j=g&&!d&&e.content.length>80?As(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${i("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>g&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:g?"pointer":"default",userSelect:"none"},children:[t.jsxs(eo,{enabled:g,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[g&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("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:i("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:i("desc-fg"),lineHeight:1.7},children:a(j)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:c(b[0]),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),h.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),w&&t.jsxs("span",{style:{fontSize:"11px",color:i("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:m})]})]}),w&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(h=>{const v=y[h],$=v?`${l(v.title)}${v.author?`(${l(v.author)})`:""}`:h.slice(0,8)+"…";return t.jsxs("a",{href:c(h),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),n(h))},style:{fontSize:"12px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:h,children:["→",$]},h)})}),d&&g&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:i("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:i("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 ${i("widget-border")}`,fontSize:"12px",color:i("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:a(e.comment)})]})]})}function Bp({juan:e,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const l=wt(),c=n.trim(),p=f.useMemo(()=>c?e.sections.filter(a=>Xi(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(Lp,{section:a,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:c},d))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Ap(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Wp({sections:e,onNavigate:n,inline:o,workLinks:r=!0}){const s=Fe(),{convert:l}=V(),c=Ap();return t.jsx(t.Fragment,{children:e.map((p,a)=>{const d=Je(p.type);if(d==="page_header"&&!to(p))return null;if(d==="类")return t.jsxs(f.Fragment,{children:[f.createElement(c("类"),null,o(l(p.title))),p.content&&t.jsx("p",{children:o(l(p.content))})]},a);if(d==="书"||d==="诗"||d==="考证"||d==="注释"){const u=p.book_title?`《${p.book_title}》${p.n_juan!=null?Zi(p.n_juan)+"卷":""}`:p.title,m=o(l(u));return t.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${a}`,children:[f.createElement(c("条目"),{className:"bim-rd-entry-h"},p.work_id&&n&&r?t.jsxs(t.Fragment,{children:[t.jsx("a",{href:s(p.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),n(p.work_id))},title:"查看作品",children:m}),t.jsx("a",{className:"bim-rd-wl",href:s(p.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),n(p.work_id))},"aria-label":`查看作品:${u}`,children:"作品 →"})]}):m),p.author_info&&t.jsx("p",{className:"bim-rd-sub",children:o(l(p.author_info))}),p.content&&p.content.split(/\n+/).map((x,g)=>t.jsx("p",{children:o(l(x))},g)),p.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),o(l(p.summary))]}),p.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),o(l(p.comment))]}),p.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),o(l(p.additional_comment))]})]},a)}return p.content?t.jsx("p",{children:o(l(p.content))},a):null})})}function ul(e){return e.some(n=>{const o=Je(n.type);return o==="书"||o==="诗"||o==="考证"||o==="注释"||o==="类"||(o==="序"||o==="结语")&&!!n.content||o==="page_header"&&to(n)})}function Mp({juan:e,rawText:n,positionLabel:o,groupLabel:r,index:s,searchQuery:l,onNavigate:c,transport:p,workLabelCache:a,prefs:d,view:u,onViewChange:m}){var ce;const{convert:x}=V(),g=wt(),[b,w]=f.useState("text"),y=u??b,j=B=>{w(B),m==null||m(B)},h=l.trim(),v=(s==null?void 0:s.type)==="kaozhen",$=f.useCallback(B=>h?sn(B,h,g):B,[h,g]),k=B=>qi(B,{renderText:$,properNames:d.properNames}),_=f.useMemo(()=>h?e.sections.filter(B=>Xi(B,h,v,g)):e.sections,[e.sections,h,v,g]),S=(B,D)=>D.filter(A=>Je(A.type)===B).length,z=S("书",e.sections),N=S("诗",e.sections),R=S("考证",e.sections);let C="";v?C=h?`${S("考证",_)} / ${R} ${x("條")}`:`${R} ${x("條")}`:N>0?C=h?`${S("诗",_)} / ${N} 首`:`${N} 首`:z>0&&(C=h?`${S("书",_)} / ${z} ${x("部書")}`:`${z} ${x("部書")}`);const H=s!=null&&s.text_quality?fp(s.text_quality.grade):null,L=[];C&&L.push(C),v&&(s!=null&&s.target_source)&&L.push(t.jsxs(t.Fragment,{children:[x("考證對象")," ",x(s.target_source)]})),H&&L.push(t.jsx("span",{title:fa[H],children:(ce=s==null?void 0:s.text_quality)!=null&&ce.source_note?t.jsxs(t.Fragment,{children:["底本 ",x(s.text_quality.source_note),t.jsx("span",{className:"bim-rd-grade",children:x(ti[H])})]}):t.jsxs(t.Fragment,{children:[x("文本質量"),t.jsx("span",{className:"bim-rd-grade",children:x(ti[H])})]})})),e.source_url&&L.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:x("原文來源")}));const M=!v&&ul(e.sections),F=!!n&&(!M||d.readingMode==="paragraph"&&Qt(n)),X=!v&&(M||!!n),U=v||!X?"entries":y;let T=0;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[(o||r)&&t.jsxs("p",{className:"bim-rd-kicker",children:[o,o&&r&&t.jsx("span",{className:"bim-rd-dot"}),r&&x(r)]}),t.jsx("h1",{className:"bim-rd-h1",children:x(e.title)}),L.length>0&&t.jsx("p",{className:"bim-rd-meta",children:L.map((B,D)=>t.jsxs(f.Fragment,{children:[D>0&&t.jsx("span",{className:"bim-rd-dot"}),B]},D))}),X&&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":U==="text",onClick:()=>j("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":U==="entries",onClick:()=>j("entries"),children:x("條目")})]})]}),U==="text"&&t.jsx("article",{className:"bim-rd-prose",children:F?t.jsx(Ji,{text:n,mode:d.readingMode,properNames:d.properNames,renderText:$,dropTitle:e.title}):t.jsx(Wp,{sections:e.sections,onNavigate:c,inline:k,workLinks:d.workLinks})}),U==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:v?t.jsx(Bp,{juan:e,searchQuery:l,onNavigate:c,transport:p,workLabelCache:a}):t.jsxs(t.Fragment,{children:[_.some(B=>["书","诗","考证"].includes(Je(B.type)))&&t.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[t.jsx("span",{style:{width:28},children:"序"}),t.jsx("span",{style:{flex:1},children:"书名"}),t.jsx("span",{children:"作品"})]}),_.map((B,D)=>{const A=Je(B.type);return A==="书"||A==="诗"||A==="考证"?(T+=1,t.jsx(Tp,{domId:`rd-e-${e.sections.indexOf(B)}`,section:B,onNavigate:d.workLinks?c:void 0,highlightQuery:h,no:T,showUnlinked:d.workLinks&&!!c},D)):A==="类"?t.jsx(Ip,{section:B,highlightQuery:h},D):t.jsx(Rp,{section:B,highlightQuery:h},D)}),_.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function xl(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 Fp(e){const n=xl(e);return n.length>0?n[0]:null}function Pp(e){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:l,activeRawText:c,query:p,isKaozhen:a}=e,d=wt(),u=f.useRef(new Map),[m,x]=f.useState({}),[g,b]=f.useState({}),w=f.useCallback((j,h)=>{const v=h==null?void 0:h.title;v&&b($=>$[j]===v?$:{...$,[j]:v})},[]);f.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:c}),w(s,l))},[s,l,c,w]),f.useEffect(()=>{u.current.clear(),x({}),b({})},[n]);const y=f.useCallback((j,h)=>{let v=0;if(j.juan)for(const $ of j.juan.sections)Xi($,h,a,d)&&v++;return v===0&&j.rawText&&wp(j.rawText,h,d)&&(v=1),v},[a,d]);return f.useEffect(()=>{const j=p.trim();if(!j){x({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let h=!1;const v={},$=[];for(const N of r){const R=u.current.get(N);R?v[N]=y(R,j):(v[N]="loading",$.push(N))}x(v);const k=8;let _=0;const S=async()=>{var N;for(;_<$.length;){if(h)return;const R=_++,C=$[R];try{const[H,L]=await Promise.all([o.getCollatedJuan(n,C),((N=o.getCollatedJuanText)==null?void 0:N.call(o,n,C))??Promise.resolve(null)]),M={juan:H,rawText:L};if(u.current.set(C,M),w(C,H),h)return;x(F=>({...F,[C]:y(M,j)}))}catch{if(h)return;x(H=>({...H,[C]:0}))}}},z=Array.from({length:Math.min(k,$.length)},()=>S());return Promise.all(z),()=>{h=!0}},[p,n,o,r.join(","),y,d,w]),{matchStates:m,titles:g}}function Op({juan:e,view:n,onView:o,textHasEntries:r}){const{convert:s}=V(),l=e.sections.map((d,u)=>({s:d,i:u,t:Je(d.type)})).filter(d=>d.t==="书"||d.t==="诗");if(l.length===0)return null;const c=l.filter(d=>!!d.s.work_id).length,p=l.every(d=>d.t==="诗")?"首":"部书",a=d=>{const u=()=>{var m,x;return(x=(m=document.getElementById(`rd-e-${d}`))==null?void 0:m.scrollIntoView)==null?void 0:x.call(m,{block:"start",behavior:"smooth"})};n==="text"&&!r&&o("entries"),n==="text"&&!r?setTimeout(u,0):u()};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-rd-rail-card",children:[t.jsx("div",{className:"bim-rd-rail-cap",children:"本卷"}),t.jsxs("div",{className:"bim-rd-rail-n",children:[t.jsx("b",{children:l.length}),t.jsx("span",{children:s(p)}),t.jsxs("span",{className:"bim-rd-rail-linked",children:["已关联 ",c]})]}),t.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":`已关联 ${c} / ${l.length}`,children:t.jsx("span",{style:{width:`${Math.round(c/l.length*100)}%`}})})]}),t.jsxs("nav",{"aria-label":"本卷条目",children:[t.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:s("條目")}),t.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:d,i:u})=>t.jsx("li",{children:t.jsxs("a",{href:`#rd-e-${u}`,onClick:m=>{m.preventDefault(),a(u)},children:[t.jsx("span",{className:`bim-rd-rail-dot${d.work_id?" on":""}`,"aria-hidden":"true"}),t.jsx("span",{children:s(d.book_title||d.title)})]})},u))})]})]})}function Dp(e,n){const[o,r]=f.useState([]);return f.useEffect(()=>{if(r([]),!e||typeof(n==null?void 0:n.getItem)!="function")return;let s=!1;return Promise.resolve(n.getItem(e)).then(l=>{if(s||!l)return;const c=l.authors??[];r(c.filter(p=>p&&p.name))}).catch(()=>{}),()=>{s=!0}},[e,n]),o}const no=({index:e,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:l,className:c,style:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:m,imagePanel:x,allowVertical:g,onReportError:b,revisedAt:w})=>{const[y,j]=f.useState(null),[h,v]=f.useState(!1),[$,k]=f.useState(null),[_,S]=f.useState(null),[z,N]=f.useState(null),[R,C]=f.useState(!1),[H,L]=f.useState(null),[M,F]=f.useState(""),X=f.useRef(new Map),U=f.useRef(0),T=s??_,ce=f.useCallback(q=>{S(q),l==null||l(q)},[l]),B=e||y;f.useEffect(()=>{e&&(v(!1),k(null))},[e]),f.useEffect(()=>{if(e||!n||!(o!=null&&o.getCollatedEditionIndex))return;let q=!1;return v(!0),k(null),o.getCollatedEditionIndex(n).then(ie=>{q||(ie?j(ie):k("未找到整理本数据"))}).catch(ie=>{q||k(ie instanceof Error?ie.message:"加载失败")}).finally(()=>{q||v(!1)}),()=>{q=!0}},[e,n,o]),f.useEffect(()=>{if(B&&!T){const q=Fp(B);q&&ce(q)}},[B,T,ce]);const D=n||(B==null?void 0:B.work_id),A=f.useCallback(async q=>{var pe;if(!D||!(o!=null&&o.getCollatedJuan))return;const ie=++U.current;C(!0),N(null),L(null);try{const[ge,Ee]=await Promise.all([o.getCollatedJuan(D,q),((pe=o.getCollatedJuanText)==null?void 0:pe.call(o,D,q))??Promise.resolve(null)]);if(ie!==U.current)return;N(ge),L(Ee)}catch{if(ie!==U.current)return;N(null),L(null)}finally{ie===U.current&&C(!1)}},[D,o]);f.useEffect(()=>{T&&A(T)},[T,A]);const ee=q=>{ce(q)};if(h)return t.jsx("div",{className:c,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if($)return t.jsx("div",{className:c,style:{...p,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:$});if(!B)return null;const de=B.type==="kaozhen",G=xl(B);return t.jsx(Up,{className:c,style:p,index:B,allFiles:G,isKaozhen:de,effectiveWorkId:D,transport:o,activeFile:T,handleSelectFile:ee,juanData:z,juanRawText:H,juanLoading:R,searchQuery:M,setSearchQuery:F,onNavigate:r,workLabelCacheRef:X,reader:{title:a,subtitle:d,resolveImages:u,renderImageOverlay:m,imagePanel:x,allowVertical:g,onReportError:b,revisedAt:w}})};function fi(e,n,o,r){var d,u,m,x;const s=(u=(d=n.juan_metadata)==null?void 0:d[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:$p(e)),p=((x=(m=n.files)==null?void 0:m.find(g=>g.filename===e))==null?void 0:x.title)??o[e];if(!p)return{position:l,label:l};const a=r(p);return{position:l,label:l===p||l===a?a:`${l} ${a}`}}function Hp(e,n){if(!n)return;const o=r=>{var s;for(const l of r??[]){const c=o(l.children);if(c)return c;if((s=l.files)!=null&&s.includes(n))return l.label}};return o(e==null?void 0:e.juan_groups)}function Gp(e,n,o,r,s){const l=a=>a==="loading"?"…":typeof a=="number"&&a>0?a:void 0,c=(a,d)=>({key:a,label:d??fi(a,e,r,s).label,hint:l(o[a]),disabled:o[a]===0}),p=(a,d)=>{var m;if(a.files.length===1&&!((m=a.children)!=null&&m.length))return c(a.files[0],s(a.label));const u=_p(a,o);return{key:`group:${d}`,label:s(a.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:pl(a),defaultExpanded:typeof u=="number"&&u>0,children:[...a.files.map(x=>c(x)),...(a.children??[]).map((x,g)=>p(x,`${d}.${g}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((a,d)=>p(a,`${d}`)):n.map(a=>c(a))}const Up=({className:e,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:c,activeFile:p,handleSelectFile:a,juanData:d,juanRawText:u,juanLoading:m,searchQuery:x,setSearchQuery:g,onNavigate:b,workLabelCacheRef:w,reader:y})=>{const{convert:j}=V(),[h,v]=Hi(),[$,k]=f.useState("text");f.useEffect(()=>{k("text")},[p]);const{matchStates:_,titles:S}=Pp({workId:l,transport:c,files:r,activeFile:p,activeJuan:d,activeRawText:u,query:x,isKaozhen:s}),z=dl(y.resolveImages,p),N=f.useMemo(()=>Gp(o,r,_,S,j),[o,r,_,S,j]),R=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:D=>g(D.target.value)}),C=s?"章":o.juan_metadata&&Object.values(o.juan_metadata).some(D=>D.vol_label)?"冊":"卷",H=p?fi(p,o,S,j).position:void 0,L=Fe(),M=y.title??(o.title?j(o.title):void 0),F=M&&l&&b?t.jsx("a",{href:L(l),onClick:D=>{D.metaKey||D.ctrlKey||(D.preventDefault(),b(l))},title:"查看作品",children:M}):M,X=!!d&&!s&&ul(d.sections),U=X&&!(u&&h.readingMode==="paragraph"&&Qt(u)),T=d&&!s&&X?t.jsx(Op,{juan:d,view:$,onView:k,textHasEntries:U}):void 0,ce=Dp(l,c),B=ce.length>0?j(ce.slice(0,2).map(D=>`${D.dynasty?`〔${D.dynasty}〕`:""}${D.name}${D.role?` ${D.role}`:" 撰"}`).join("、")):void 0;return t.jsxs(Gi,{className:e,style:n,title:F,subtitle:y.subtitle??j(s?"考證":"整理本"),byline:B,pagerUnit:C,rail:T,revisedAt:y.revisedAt,onReportError:y.onReportError?D=>y.onReportError({...D,bookTitle:o.title??(typeof y.title=="string"?y.title:void 0),entryId:l}):void 0,current:p?fi(p,o,S,j).label:void 0,workLinkToggle:!s&&!!b&&!!(d!=null&&d.sections.some(D=>D.work_id)),toc:N,tocCaption:`目录 · ${r.length} ${j(C)}`,tocHeader:R,activeKey:p,onSelect:a,images:z.images,imagesLoading:z.loading,renderImageOverlay:y.renderImageOverlay,imagePanel:y.imagePanel,prefs:h,onPrefsChange:v,paragraphToggle:!s&&Qt(u),allowVertical:y.allowVertical,children:[m?t.jsx(kt,{}):d?t.jsx(Mp,{juan:d,rawText:u,positionLabel:H,groupLabel:Hp(o,p),index:o,searchQuery:x,onNavigate:b,transport:c,workLabelCache:w,prefs:h,view:$,onViewChange:k},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,o.references&&o.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:j("參考文獻")}),t.jsx("ol",{children:o.references.map((D,A)=>t.jsxs("li",{children:[D.url?t.jsx("a",{className:"bim-rd-link",href:D.url,target:"_blank",rel:"noopener noreferrer",children:D.title}):t.jsx("span",{children:D.title}),D.author&&t.jsxs("span",{children:[",",D.author]}),D.note&&t.jsxs("span",{children:["。",D.note]})]},A))})]})]})},Vp={bug:{label:"错误反馈",color:i("danger")},resource:{label:"资源建议",color:i("primary")},suggestion:{label:"功能建议",color:i("primary")},other:{label:"其他",color:i("desc-fg")}},Yp={label:"其他",color:i("desc-fg")},Kp={pending:{label:"待处理",color:i("warning")},in_progress:{label:"处理中",color:i("primary")},resolved:{label:"已处理",color:i("success")},wontfix:{label:"不采纳",color:i("desc-fg")},duplicate:{label:"重复",color:i("desc-fg")}},qp={label:"待处理",color:i("warning")};function Jp(e){try{const n=new Date(e),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return e}}function Zp(e,n){if(!e)return!1;try{const o=new URL(e,n);if(o.protocol!=="http:"&&o.protocol!=="https:")return!1;const r=new URL(n);return o.hostname===r.hostname}catch{return!1}}const io=({items:e,loading:n})=>{const o=Fe();return n?t.jsx(kt,{}):e.length===0?t.jsx("div",{style:Xp,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Vp[r.type]||Yp,l=Kp[r.status]||qp,c=typeof window<"u"&&Zp(r.pageUrl,window.location.href);return t.jsxs("div",{style:Qp,children:[t.jsxs("div",{style:eu,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...sr,background:s.color},children:s.label}),t.jsx("span",{style:{...sr,background:l.color},children:l.label})]}),t.jsx("span",{style:tu,children:Jp(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:nu,children:[r.resourceId&&t.jsx("a",{href:o(r.resourceId),style:Kn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(c?t.jsx("a",{href:r.pageUrl,style:Kn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Kn,children:r.pageUrl}))]}),t.jsx("div",{style:iu,children:r.content}),r.reply&&t.jsxs("div",{style:ou,children:[t.jsx("div",{style:ru,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Xp={textAlign:"center",padding:"40px 0",color:i("desc-fg"),fontSize:"14px"},Qp={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"16px"},eu={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},sr={fontSize:"12px",color:i("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},tu={fontSize:"12px",color:i("desc-fg")},nu={fontSize:"12px",marginBottom:"6px"},Kn={color:i("primary"),textDecoration:"none",borderBottom:`1px dashed ${i("primary")}`},iu={fontSize:"14px",lineHeight:"1.6",color:i("fg"),whiteSpace:"pre-wrap"},ou={marginTop:"12px",padding:"10px 12px",background:i("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:i("fg")},ru={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:i("primary")},mi=({transport:e,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const c=me(),[p,a]=f.useState(null),[d,u]=f.useState([]),[m,x]=f.useState("recommend"),[g,b]=f.useState([]),[w,y]=f.useState(!1),j=r??m,h=F=>{x(F),s==null||s(F)},[v,$]=f.useState(!0),[k,_]=f.useState(null),[S,z]=f.useState(null),[N,R]=f.useState(null);f.useEffect(()=>{let F=!1;if(e.getCounts)return e.getCounts().then(X=>{F||a({works:X.works,books:X.books,collections:X.collections})}).catch(()=>{}),()=>{F=!0}},[e]),f.useEffect(()=>{let F=!1;return(async()=>{if(o)return o;if(e.getRecommended)try{const U=await e.getRecommended();if(U!=null&&U.groups)return U.groups.flatMap(T=>T.items.map(ce=>({...ce,group:T.name})))}catch{}return[]})().then(async U=>{if(F)return;const T=U.filter(B=>B.id);if(T.length===0){$(!1);return}const ce=await Promise.all(T.map(async B=>{if(B.type)return{id:B.id,title:B.title,type:B.type,author:B.author,dynasty:B.dynasty,role:B.role,edition:B.edition,has_text:B.has_text,has_image:B.has_image,has_collated:B.has_collated,subtype:B.subtype,primary_name:B.primary_name,group:B.group,fallbackDescription:B.description};try{let D=null;if(e.getEntry)D=await e.getEntry(B.id);else{const A=await e.getItem(B.id);A&&(D={id:B.id,title:A.title||B.id,type:A.type||"work"})}if(D)return{...D,group:B.group,fallbackDescription:B.description}}catch{}return{id:B.id,title:B.title,type:$e.extractType(B.id),group:B.group,fallbackDescription:B.description}}));F||(u(ce.filter(B=>B!==null)),$(!1))}),()=>{F=!0}},[e,o]);const C=f.useRef(!1),H=f.useRef(!1),L=f.useRef(!1);f.useEffect(()=>{if(j!=="catalog"||C.current)return;const F=e.getCatalogProgress??e.getResourceProgress;if(!F)return;C.current=!0;let X=!1;return F.call(e).then(U=>{X||_(U)}).catch(()=>{C.current=!1}),()=>{X=!0}},[e,j]),f.useEffect(()=>{if(j!=="collection"||H.current||!e.getCollectionProgress)return;H.current=!0;let F=!1;return e.getCollectionProgress().then(X=>{F||z(X)}).catch(()=>{H.current=!1}),()=>{F=!0}},[e,j]),f.useEffect(()=>{if(j!=="site"||L.current||!e.getSiteProgress)return;L.current=!0;let F=!1;return e.getSiteProgress().then(X=>{F||R(X)}).catch(()=>{L.current=!1}),()=>{F=!0}},[e,j]),f.useEffect(()=>{if(!l||j!=="feedback")return;let F=!1;return y(!0),fetch(l).then(X=>X.json()).then(X=>{!F&&X.success&&b(X.items||[])}).catch(()=>{}).finally(()=>{F||y(!1)}),()=>{F=!0}},[l,j]);const M=F=>t.jsx(Wt,{type:F,size:12});return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:i("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"16px"},children:[t.jsx(Gt,{label:c.home.recommendTab,active:j==="recommend",onClick:()=>h("recommend")}),t.jsx(Gt,{label:c.home.catalogTab,active:j==="catalog",onClick:()=>h("catalog")}),t.jsx(Gt,{label:c.home.collectionTab,active:j==="collection",onClick:()=>h("collection")}),t.jsx(Gt,{label:c.home.siteTab,active:j==="site",onClick:()=>h("site")}),l&&t.jsx(Gt,{label:c.home.feedbackTab,active:j==="feedback",onClick:()=>h("feedback")})]}),j==="recommend"&&t.jsx(su,{recommended:d,loading:v,onNavigate:n,getIcon:M,t:c}),j==="catalog"&&t.jsx(lr,{progress:k,t:c,onNavigate:n}),j==="collection"&&t.jsx(lr,{progress:S,t:c,onNavigate:n}),j==="site"&&t.jsx(au,{progress:N,t:c,totalWorks:(p==null?void 0:p.works)??0}),j==="feedback"&&l&&t.jsx(io,{items:g,loading:w})]})})},Gt=({label:e,active:n,onClick:o})=>t.jsx("button",{onClick:o,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:i(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${i("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),su=({recommended:e,loading:n,onNavigate:o,getIcon:r,t:s})=>{const l=Fe();if(n)return t.jsx(kt,{});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:i("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:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),o==null||o(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,cursor:"pointer",background:i("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:i("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},lr=({progress:e,t:n,onNavigate:o})=>{if(!e)return t.jsx(kt,{});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:i("progress-active"),done:i("progress-done"),todo:i("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:i("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(lu,{item:d,t:n,statusColor:c[p],onNavigate:o},d.id))})]},p)})})},lu=({item:e,t:n,statusColor:o,onNavigate:r})=>{const s=Fe(),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 ${i("widget-border")}`,background:i("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 ${i("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:i("widget-border"),color:i("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:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Qe(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:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:o,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:e.description})]})},au=({progress:e,t:n,totalWorks:o})=>{if(!e)return t.jsx(kt,{});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=o>0?Math.round(c/o*100):0;return t.jsxs("div",{children:[o>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${i("primary")} 6%, transparent)`,fontSize:"13px",color:i("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:c.toLocaleString()})," / ",o.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:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>t.jsx(ar,{item:a,t:n,totalWorks:o},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:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(a=>t.jsx(ar,{item:a,t:n,totalWorks:o},a.id))})]})]})},ar=({item:e,t:n,totalWorks:o})=>{const r=o>0?Math.round(e.imported/o*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("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:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&o>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:i("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:e.description})]})},cr="(max-width: 768px)";function cu(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(cr).matches);return f.useEffect(()=>{const o=window.matchMedia(cr),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),e}const du=({transport:e,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var X;const l=me(),{convert:c}=V(),p=cu(),[a,d]=f.useState(null),[u,m]=f.useState(null),[x,g]=f.useState(!1),[b,w]=f.useState("detail"),[y,j]=f.useState([]),[h,v]=f.useState(!1),[$,k]=f.useState(null),[_,S]=f.useState(!1),z=f.useCallback(async U=>{if(!e.getCollatedEditionIndex){k(null);return}S(!0);try{const T=await e.getCollatedEditionIndex(U);k(T)}catch{k(null)}finally{S(!1)}},[e]),N=f.useCallback(async U=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){j([]);return}v(!0);try{if(e.getCollectionCatalogs){const T=await e.getCollectionCatalogs(U);j(T||[])}else if(e.getCollectionCatalog){const T=await e.getCollectionCatalog(U);j(T?[{resource_id:"",data:T}]:[])}}catch{j([])}finally{v(!1)}},[e]),R=f.useCallback(async U=>{if(o){o(U);return}d(U),m(null),j([]),k(null),w("detail"),g(!0);try{const T=await e.getItem(U.id);T&&(m(T),T.type==="collection"?N(U.id):T.type==="work"&&T.has_collated&&z(U.id))}catch(T){console.error("加载详情失败:",T)}finally{g(!1)}},[e,o,N,z]),C=f.useCallback(async U=>{m(null),j([]),k(null),w("detail"),g(!0);try{const T=await e.getItem(U);T&&(m(T),d({id:U,title:T.title||U,type:T.type||"book"}),T.type==="collection"?N(U):T.type==="work"&&T.has_collated&&z(U))}catch(T){console.error("导航失败:",T)}finally{g(!1)}},[e,N,z]),H=(u==null?void 0:u.type)==="collection"&&(y.length>0||h)||(u==null?void 0:u.type)==="work"&&($||_),L=p&&(x||u),M=f.useCallback(()=>{d(null),m(null),j([]),k(null),w("detail")},[]),F=t.jsx(t.Fragment,{children:x?t.jsx(kt,{}):u?t.jsxs(t.Fragment,{children:[(H||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${i("widget-border")}`,padding:p?"0 12px":"0 48px",background:i("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[H&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>w("detail"),style:mn(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&h&&y.length===0&&t.jsxs("button",{onClick:()=>{},style:mn(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&y.map(U=>t.jsx("button",{onClick:()=>w(`catalog:${U.resource_id}`),style:mn(b===`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:()=>w("collated"),style:mn(b==="collated"),children:[l.detailTab.collatedEdition,_&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?t.jsx(Ei,{data:u,transport:e,onNavigate:C}):b.startsWith("catalog:")?t.jsx(Ri,{data:(X=y.find(U=>`catalog:${U.resource_id}`===b))==null?void 0:X.data,onNavigate:C}):b==="collated"?t.jsx(no,{index:$||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(mi,{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:i("bg"),color:i("fg")},children:L?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${i("widget-border")}`,background:i("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:M,style:{padding:"4px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("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(ii,{transport:e,onEntryClick:R,hideModeIndicator:n}),!u&&t.jsx(mi,{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:i("bg"),color:i("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${i("widget-border")}`,display:"flex",flexDirection:"column",background:i("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(ii,{transport:e,onEntryClick:R,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:i("bg"),display:"flex",flexDirection:"column"},children:F})]})};function mn(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function ft(e){return e.replace(/\.md$/,"")}function dr(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 pr={padding:24,color:i("desc-fg")},gi=({index:e,bookId:n,transport:o,activeChapter:r,onChapterChange:s,workKey:l,versions:c,onVersionChange:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:m,imagePanel:x,allowVertical:g,onReportError:b,revisedAt:w,className:y,style:j})=>{const[h,v]=f.useState(e??null),[$,k]=f.useState(!1),[_,S]=f.useState(null),z=r!==void 0?r:_,N=f.useCallback(G=>{s?s(G):S(G)},[s]),[R,C]=f.useState(null),[H,L]=f.useState(!1);f.useEffect(()=>{e&&v(e)},[e]),f.useEffect(()=>{if(e)return;v(null),k(!1);const G=l!==void 0?o.getWorkFullTextIndex?()=>o.getWorkFullTextIndex(n,l):null:o.getBookFullTextIndex?()=>o.getBookFullTextIndex(n):null;if(!n||!G){k(!0);return}let q=!1;return Promise.resolve().then(G).then(ie=>{q||(ie?v(ie):k(!0))}).catch(()=>{q||k(!0)}),()=>{q=!0}},[n,o,e,l]),f.useEffect(()=>{if(!h||h.chapters.length===0)return;const G=ft(h.chapters[0].file);if(!z){N(G);return}const q=ft(z);h.chapters.some(pe=>ft(pe.file)===q)||N(G)},[h,z,N]);const M=f.useMemo(()=>{if(!h||!z)return null;const G=ft(z);return h.chapters.find(q=>ft(q.file)===G)??null},[h,z]);f.useEffect(()=>{if(!n||!M)return;const G=l!==void 0?o.getWorkFullTextChapter?ie=>o.getWorkFullTextChapter(n,l,ie):null:o.getBookFullTextChapter?ie=>o.getBookFullTextChapter(n,ie):null;if(!G)return;let q=!1;return L(!0),C(null),Promise.resolve(M.file).then(G).then(ie=>{q||C(ie)}).catch(()=>{q||C(null)}).finally(()=>{q||L(!1)}),()=>{q=!0}},[n,M,o,l]);const F=dl(u,M?ft(M.file):null),[X,U]=Hi(),{convert:T}=V(),ce=!!(c&&c.length>1&&p),B=f.useMemo(()=>ce?qs(c).map((G,q)=>({...G,label:dr(c[q])})):void 0,[ce,c]),D=ce?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:G=>p(G.target.value),children:c.map(G=>t.jsx("option",{value:G.key,children:dr(G)},G.key))})]}):null;if(!h)return t.jsxs("div",{style:pr,children:[D&&t.jsx("div",{style:{marginBottom:12},children:D}),$?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:pr,children:[D&&t.jsx("div",{style:{marginBottom:12},children:D}),"全文目录为空"]});const A=h.chapters.map(G=>({key:ft(G.file),label:T(G.title)})),ee=Qs(h)||si(h),de=R?R.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(Gi,{title:a??T(h.version_label),subtitle:d??"全文",toc:A,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:z?ft(z):null,onSelect:N,images:F.images,imagesLoading:F.loading,renderImageOverlay:m,imagePanel:x,prefs:X,onPrefsChange:U,versions:B,currentVersionKey:B?l??null:void 0,onVersionChange:B?p:void 0,versionSource:!1,paragraphToggle:Qt(de),allowVertical:g,revisedAt:w,onReportError:b?G=>b({...G,bookTitle:a===void 0?T(h.version_label):typeof a=="string"?a:void 0,entryId:n}):void 0,className:y,style:j,children:[M&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:T(M.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:h.source.url,target:"_blank",rel:"noreferrer",children:T(h.source.name)}),h.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),h.source.license]})]})]}),H&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!H&&de!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Ji,{text:de,mode:X.readingMode,tables:ee,gujiMarkdown:si(h),properNames:X.properNames})}),!H&&!R&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},pu=({data:e,onNavigate:n,className:o,style:r})=>{var u;const s=me(),{convert:l}=V(),[c,p]=f.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[a,d]=f.useState(null);return t.jsxs("div",{className:o,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:l(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:i("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(m=>t.jsx(uu,{division:m,expanded:c===m.name,onToggle:()=>p(c===m.name?null:m.name),expandedCat:a,onCatToggle:x=>d(a===x?null:x),onNavigate:n},m.name))})]})},uu=({division:e,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:c}=V(),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 ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${i("primary")} 6%, transparent)`:i("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:i("fg"),textAlign:"left"},children:[t.jsx("span",{children:c(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("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(xu,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:l},a.name)})})]})},xu=({category:e,expanded:n,onToggle:o,onNavigate:r})=>{var a,d,u,m;const{convert:s}=V(),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)+(((m=e.stats)==null?void 0:m.cunmu)||c.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?i("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:i("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:i("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(ur,{label:"著錄",books:l,onNavigate:r}),c.length>0&&t.jsx(ur,{label:"存目",books:c,onNavigate:r})]})]})},ur=({label:e,books:n,onNavigate:o})=>{const{convert:r}=V(),s=Fe(),[l,c]=f.useState(n.length<=20),p=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:i("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:i("fg")},children:a.work_id&&o?t.jsx("a",{href:s(a.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),o(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},children:r(a.title)}):r(a.title)}),a.volumes&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:r(a.volumes)}),a.author&&t.jsx("span",{style:{fontSize:"11px",color:i("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:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},Xe=({title:e,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const l=me();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("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 ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:i("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&t.jsx("button",{onClick:o,style:mu,children:"AI"}),n&&t.jsx("button",{onClick:n,style:fu,children:l.action.save})]})]}),s]})},fu={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},mu={padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Ye=({label:e,value:n,onChange:o,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:l=>o(l.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),jt=({value:e,onChange:n,placeholder:o})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},wn=({children:e,color:n,style:o})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||i("primary-soft"),color:i(n?"on-color-fg":"fg"),...o},children:e});function gu(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const hn=({value:e,onChange:n,label:o})=>{const[r,s]=f.useState(!1),l=f.useRef(null),c=gu(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&c?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:xr,children:o}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${i("input-border")}`,borderRadius:"2px",background:i("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:i("fg")},children:c.name}),t.jsx(wn,{children:c.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:xr,children:o}),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:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},xr={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500};function hu(e){switch(e){case"url":return i("source-url");case"bookID":return i("source-bookid");default:return i("desc-fg")}}function bu(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const fl=({items:e,onChange:n,onOpenEntityPicker:o})=>{const r=me(),[s,l]=f.useState(null),c=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},p=m=>{n(e.filter((x,g)=>g!==m)),s===m&&l(null)},a=(m,x,g)=>{const b=[...e];b[m]={...b[m],[x]:g},n(b)},d=(m,x)=>{const g=[...e];g[m]={...g[m],type:x,id:"",name:""},n(g),x==="bookID"&&o&&o(b=>{const w=[...e];w[m]={...w[m],id:b.id,name:b.title,type:"bookID"},n(w)})},u=m=>{o&&o(x=>{const g=[...e];g[m]={...g[m],id:x.id,name:x.title,type:"bookID"},n(g)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((m,x)=>t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("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:i("fg")},children:m.name||`${r.editor.sourcePlaceholder} ${x+1}`}),m.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:hu(m.type),color:i("on-color-fg"),borderRadius:"3px",fontWeight:500},children:bu(m.type)}),t.jsx("button",{onClick:g=>{g.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===x&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!m.type&&t.jsxs("div",{children:[t.jsx("label",{style:lt,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>d(x,"bookID"),style:{...fr,borderColor:i("source-bookid"),color:i("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:{...fr,borderColor:i("source-url"),color:i("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})]})]})]}),m.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:lt,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const g=[...e];g[x]={...g[x],type:"",id:"",name:""},n(g)},style:mr,children:r.action.changeType})]}),m.id&&m.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:i("bg"),border:`1px solid ${i("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:i("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:m.name}),t.jsx("code",{style:{fontSize:"11px",background:i("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:m.id})]}),t.jsx("button",{onClick:()=>u(x),style:{background:"transparent",border:`1px solid ${i("widget-border")}`,color:i("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 ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("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})]})]})}),m.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:lt,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const g=[...e];g[x]={...g[x],type:"",id:"",name:""},n(g)},style:mr,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:m.name,onChange:g=>a(x,"name",g.target.value),placeholder:r.editor.sourceNamePlaceholder,style:$t})]}),t.jsxs("div",{children:[t.jsx("label",{style:lt,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:m.id,onChange:g=>a(x,"id",g.target.value),placeholder:"https://...",style:$t})]})]}),m.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${i("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...lt,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:lt,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:m.details,onChange:g=>a(x,"details",g.target.value),placeholder:r.editor.detailsPlaceholder,style:$t})]}),t.jsxs("div",{children:[t.jsx("label",{style:lt,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:m.position,onChange:g=>a(x,"position",g.target.value),placeholder:"如: 卷三, p.52",style:$t})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:lt,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:m.version,onChange:g=>a(x,"version",g.target.value),placeholder:"如: v1.0, 2024-01",style:$t})]}),t.jsxs("div",{children:[t.jsx("label",{style:lt,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:m.processor_version,onChange:g=>a(x,"processor_version",g.target.value),placeholder:"如: v0.1",style:$t})]})]})]})]})})]},x)),t.jsxs("button",{onClick:c,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},lt={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},$t={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},fr={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:i("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},mr={background:"transparent",border:"none",color:i("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function ml(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(o=>({id:o.id||"",name:o.name||"",type:o.type||"",details:o.details||"",position:o.position||"",version:o.version||"",processor_version:o.processor_version||""}))}catch{}return[]}function gl(e){return!e||e.length===0?"":JSON.stringify(e)}const hl=({entityType:e,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:c,childWorks:p,childCollections:a,containedBooks:d,siblingBooks:u,onLinkEntity:m,onUnlinkEntity:x,onViewEntity:g,onCreateAndLink:b,onSaveRelations:w})=>{const y=me();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${i("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:y.section.relations})]}),w&&t.jsx("button",{onClick:w,style:yu,children:y.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Ut,{direction:"up",title:y.relation.belongsToWork,entity:l,onView:g,onUnlink:()=>x("workId"),onLink:()=>m("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(Ut,{direction:"up",title:y.relation.containedInCollection,entity:c,onView:g,onUnlink:()=>x("collectionId"),onLink:()=>m("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),l&&u&&u.length>0&&t.jsx(_t,{direction:"horizontal",title:`${y.relation.siblingVersions} (${u.length})`,entities:u,onView:g,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:y.relation.addVersionForWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Ut,{direction:"up",title:y.relation.parentWork,entity:r,onView:g,onUnlink:()=>x("parentWorkId"),onLink:()=>m("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),p&&p.length>0&&t.jsx(_t,{direction:"down",title:`${y.relation.childWorks} (${p.length})`,entities:p,onView:g,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:y.action.addSubWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),a&&a.length>0&&t.jsx(_t,{direction:"down",title:`${y.relation.collectionImpl} (${a.length})`,entities:a,onView:g,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:y.action.addCollectionImpl,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(_t,{direction:"down",title:`${y.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:g,onAdd:()=>b("childBook","book",{workId:n}),addLabel:y.action.addVersion,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Ut,{direction:"up",title:y.relation.correspondingWork,entity:l,onView:g,onUnlink:()=>x("workId"),onLink:()=>m("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(Ut,{direction:"up",title:y.relation.parentCollection,entity:s,onView:g,onUnlink:()=>x("parentCollectionId"),onLink:()=>m("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(_t,{direction:"down",title:`${y.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:g,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:y.action.addSubCollection,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(_t,{direction:"down",title:`${y.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:g,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:y.action.addBook,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]})]})]})},Ut=({direction:e,title:n,entity:o,onView:r,onUnlink:s,onLink:l,onCreate:c,linkLabel:p,createLabel:a,notLinkedLabel:d,viewLabel:u,unlinkLabel:m})=>{const x=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),g=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("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:g}),t.jsx("span",{children:n})]}),o?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:i("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:bl(o.type)}),t.jsx("span",{style:{fontWeight:500},children:o.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(gr,{onClick:()=>r(o),title:u,children:"👁️"}),t.jsx(gr,{onClick:s,title:m,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(hi,{onClick:l,children:p}),t.jsx(hi,{onClick:c,primary:!0,children:a})]})]})},_t=({direction:e,title:n,entities:o,onView:r,onAdd:s,addLabel:l,noneLabel:c,expandMoreLabel:p})=>{const[a,d]=f.useState(!1),u=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=a?o:o.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("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:m}),t.jsx("span",{children:n})]}),o.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[x.map(g=>t.jsxs("div",{onClick:()=>r(g),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:i("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:bl(g.type)}),t.jsx("span",{children:g.title})]},g.id)),o.length>5&&!a&&t.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:i("link-fg"),cursor:"pointer"},children:[p," (",o.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:c}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(hi,{onClick:s,primary:!0,children:["+ ",l]})})]})},gr=({onClick:e,title:n,danger:o,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:o?i("danger"):"inherit",opacity:.7},children:r}),hi=({onClick:e,primary:n,children:o})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${i("widget-border")}`,borderRadius:"4px",background:n?i("primary"):"transparent",color:n?i("primary-fg"):"inherit",cursor:"pointer"},children:o});function bl(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const yu={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},yl=({isOpen:e,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:l,searchResults:c,onSearch:p,isLoading:a,excludeId:d})=>{const[u,m]=f.useState(""),x=d?c.filter(y=>y.id!==d):c;f.useEffect(()=>{e&&(m(""),p(""))},[e]);const g=y=>{m(y),p(y)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",w=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:ju,children:t.jsxs("div",{style:vu,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),t.jsx("button",{onClick:s,style:ku,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:y=>g(y.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:wu})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?t.jsx("div",{style:qn,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(y=>t.jsxs("div",{onClick:()=>r(y),style:Su,children:[t.jsx("span",{style:{fontSize:"16px"},children:w}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[y.title,y.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:y.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[y.id,y.author&&` · ${y.author}`,y.dynasty&&` · ${y.dynasty}`]})]})]},y.id))}):u?t.jsxs("div",{style:qn,children:["未找到匹配的",b]}):t.jsxs("div",{style:qn,children:["输入关键词搜索",b]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:l,style:$u,children:["创建新",b,"并关联"]})]})]})})},ju={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},vu={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},ku={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},wu={width:"100%",padding:"10px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},Su={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:i("primary-soft")},qn={padding:"20px",textAlign:"center",color:i("desc-fg")},$u={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},hr={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},_u={work:"📜",book:"📖",collection:"📚",entity:"👤"},jl=({isOpen:e,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:l})=>{const[c,p]=f.useState(""),a=f.useRef(null);f.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,g;(x=a.current)==null||x.focus(),(g=a.current)==null||g.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 m=()=>{switch(o){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`创建新${hr[n]}`}};return t.jsx("div",{style:zu,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:Cu,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:_u[n]}),t.jsx("span",{children:m()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:i("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:i("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:a,type:"text",value:c,onChange:x=>p(x.target.value),onKeyDown:d,placeholder:`请输入${hr[n]}名称...`,style:Tu})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),background:i("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:Iu,children:"取消"}),t.jsx("button",{onClick:u,disabled:!c.trim(),style:{...Eu,opacity:c.trim()?1:.6,cursor:c.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},zu={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Cu={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:i("shadow-dialog")},Tu={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box"},Iu={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Eu={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg")};function Ru(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function vl(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Nu(e){switch(e){case"work":return i("editor-type-work");case"collection":return i("editor-type-collection");case"book":return i("editor-type-book");default:return i("desc-fg")}}const kl=({isOpen:e,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:c,onSelect:p,onCancel:a,onCreate:d,onSearch:u})=>{const[m,x]=f.useState(""),[g,b]=f.useState([]),[w,y]=f.useState(!1),[j,h]=f.useState("recent");f.useEffect(()=>{e&&(x(""),b([]),h(r.length>0?"recent":"search"))},[e,r.length]),f.useEffect(()=>{if(!m.trim()){b([]);return}const z=setTimeout(async()=>{y(!0);try{b(await u(m,o))}catch{b([])}finally{y(!1)}},300);return()=>clearTimeout(z)},[m,o,u]);const v=f.useCallback(z=>{x(z.target.value),z.target.value.trim()&&h("search")},[]),$=f.useCallback(z=>s?z.filter(N=>N.id!==s):z,[s]);if(!e)return null;const k=n||(o==="all"?"选择实体":`选择${vl(o)}`),_=$(r),S=$(g);return t.jsx("div",{style:Bu,children:t.jsxs("div",{style:Au,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:k}),t.jsx("button",{onClick:a,style:Wu,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:m,onChange:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Mu}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),w&&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 ${i("widget-border")}`},children:[t.jsxs(br,{active:j==="recent",onClick:()=>h("recent"),children:["最近使用 (",_.length,")"]}),t.jsxs(br,{active:j==="search",onClick:()=>h("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&_.length>0?t.jsx(yr,{entities:_,onSelect:p}):m.trim()?w?t.jsx(Jn,{message:"搜索中..."}):S.length>0?t.jsx(yr,{entities:S,onSelect:p}):t.jsx(Jn,{message:"未找到匹配的结果"}):t.jsx(Jn,{message:"输入关键词开始搜索"})}),l&&d&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:d,style:Fu,children:c||"创建新实体"})]})]})})},br=({active:e,onClick:n,children:o})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:o}),yr=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(o=>t.jsx(Lu,{entity:o,onClick:()=>n(o)},o.id))}),Lu=({entity:e,onClick:n})=>{const[o,r]=f.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Ru(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:i("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:i("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:Nu(e.type),color:i("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:vl(e.type)})]})},Jn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:e}),Bu={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Au={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},Wu={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Mu={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},Fu={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Pu={work:i("editor-type-work"),collection:i("editor-type-collection"),book:i("editor-type-book"),entity:i("editor-type-entity")},Ou={work:"📜",collection:"📚",book:"📖",entity:"👤"},wl=({data:e,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:l,onDelete:c,onAskAI:p,renderSectionActions:a,onDownloadResource:d,downloadStatuses:u,relations:m,onRelationsChange:x})=>{var be;const g=me(),[b,w]=f.useState(!1),[y,j]=f.useState("work"),[h,v]=f.useState(""),[$,k]=f.useState(""),[_,S]=f.useState([]),[z,N]=f.useState(!1),[R,C]=f.useState(!1),[H,L]=f.useState("work"),[M,F]=f.useState(""),[X,U]=f.useState(),[T,ce]=f.useState(!1),[B,D]=f.useState(null),[A,ee]=f.useState([]);f.useRef(null);const de=e.type,G=de==="work",q=de==="collection",ie=de==="book",pe=f.useCallback((K,I)=>{n({...e,[K]:I})},[e,n]),ge=f.useCallback((K,I)=>{v(K),j(I),k(g.editor.selectToLink+g.indexType[I]),S([]),w(!0)},[g]),Ee=f.useCallback(K=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,K)},[r,e.id]),Ne=f.useCallback(K=>{s==null||s(K.id,K.type)},[s]),ze=f.useCallback((K,I,Y)=>{const fe={...Y,author:(Y==null?void 0:Y.author)||e.author,dynasty:Y==null?void 0:Y.dynasty};L(I),F(K),U(fe),C(!0)},[e.author]),Te=f.useCallback((K,I)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,M,{type:H,title:K,inheritData:I}),C(!1)},[r,e.id,M,H]),Ce=f.useCallback(K=>{if(!K.trim()){S([]);return}N(!0),r!=null&&r.searchEntities&&r.searchEntities(K,y).then(I=>{S(I),N(!1)}).catch(()=>{S([]),N(!1)})},[r,y]),Ae=f.useCallback(K=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,h,K.id),w(!1)},[r,e.id,h]),P=f.useCallback(()=>{o()},[o]),se=f.useCallback(K=>{D(()=>K),ce(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(ee).catch(()=>{})},[r]),re=f.useCallback((K,I)=>r!=null&&r.searchEntities?r.searchEntities(K,I==="all"?void 0:I):Promise.resolve([]),[r]),ye=f.useCallback(K=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(K),ee(I=>[K,...I.filter(Y=>Y.id!==K.id)].slice(0,10)),B==null||B(K),ce(!1),D(null)},[r,B]);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 ${i("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:Ou[de]}),t.jsx("span",{children:e.title||g.editor.untitled}),t.jsx(wn,{children:e.id}),t.jsx(wn,{color:Pu[de],children:g.indexType[de]})]})}),t.jsx(Xe,{title:g.section.basicInfo,onSave:o,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(hn,{label:G?g.editor.workTitle:q?g.editor.collectionTitle:g.editor.bookTitle,value:e.title,onChange:K=>pe("title",K)}),ie&&t.jsx(hn,{label:g.editor.belongsToWork,value:e.workName||"",onChange:K=>pe("workName",K)}),t.jsx(Ye,{label:g.editor.authorLabel,value:e.author||"",onChange:K=>pe("author",K)}),t.jsx(Ye,{label:g.editor.publicationYearLabel,value:e.publicationYear||"",onChange:K=>pe("publicationYear",K)}),(ie||q)&&t.jsx(hn,{label:g.editor.containedIn,value:e.collection||"",onChange:K=>pe("collection",K)}),(ie||q)&&t.jsx(Ye,{label:g.editor.holderLabel,value:e.holder||"",onChange:K=>pe("holder",K)}),(ie||q)&&t.jsx(Ye,{label:ie?g.editor.pageLabel:g.editor.volumeLabel,value:e.pages||"",onChange:K=>pe("pages",K)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(Ye,{label:g.editor.firstImageLabel,value:e.firstImage||"",onChange:K=>pe("firstImage",K)})})]})}),t.jsx(Xe,{title:g.section.description,onSave:o,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(jt,{value:e.description||"",onChange:K=>pe("description",K),placeholder:g.editor.descriptionPlaceholder})}),(((be=e.additional_works)==null?void 0:be.length)||0)>0&&t.jsx(Xe,{title:g.section.additionalWorks,onSave:o,children:t.jsx(Du,{items:e.additional_works||[],onChange:K=>pe("additional_works",K)})}),t.jsx(Xe,{title:g.section.indexedBy,onSave:o,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Hu,{items:e.indexed_by||[],onChange:K=>pe("indexed_by",K)})}),t.jsx(Xe,{title:g.section.emendatedBy,onSave:o,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Gu,{items:e.emendated_by||[],onChange:K=>pe("emendated_by",K)})}),t.jsx(Xe,{title:g.section.textResources,onSave:o,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(ni,{items:e.resources||[],onChange:K=>pe("resources",K),onDownload:d,downloadStatuses:u,filterType:"text"})}),t.jsx(Xe,{title:g.section.imageResources,onSave:o,children:t.jsx(ni,{items:e.resources||[],onChange:K=>pe("resources",K),onDownload:d,downloadStatuses:u,filterType:"image"})}),t.jsx(Xe,{title:g.section.sources,onSave:o,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(fl,{items:ml(e.sources||""),onChange:K=>pe("sources",gl(K)),onOpenEntityPicker:se})}),(ie||q)&&t.jsx(Xe,{title:g.section.provenance,onSave:o,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(jt,{value:e.provenance||"",onChange:K=>pe("provenance",K),placeholder:g.editor.provenancePlaceholder})}),ie&&t.jsx(Xe,{title:g.section.otherEditions,onSave:o,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(jt,{value:e.otherEditions||"",onChange:K=>pe("otherEditions",K),placeholder:g.editor.otherEditionsPlaceholder})}),t.jsx(hl,{entityType:de,entityId:e.id,entityTitle:e.title,parentWork:m==null?void 0:m.parentWork,parentCollection:m==null?void 0:m.parentCollection,belongsToWork:m==null?void 0:m.belongsToWork,belongsToCollection:m==null?void 0:m.belongsToCollection,childWorks:m==null?void 0:m.childWorks,childCollections:m==null?void 0:m.childCollections,containedBooks:m==null?void 0:m.containedBooks,siblingBooks:m==null?void 0:m.siblingBooks,onLinkEntity:ge,onUnlinkEntity:Ee,onViewEntity:Ne,onCreateAndLink:ze,onSaveRelations:P}),l&&c&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${i("danger-soft-border")}`,background:i("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:i("danger"),fontWeight:600,marginBottom:"8px"},children:g.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"12px"},children:g.editor.dangerZoneDesc}),t.jsx("button",{onClick:c,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("danger")}`,borderRadius:"4px",background:"transparent",color:i("danger"),cursor:"pointer"},children:g.editor.deleteEntity})]}),t.jsx(yl,{isOpen:b,entityType:y,title:$,onSelect:Ae,onCancel:()=>w(!1),onCreate:()=>{w(!1),ze(h,y)},searchResults:_,onSearch:Ce,isLoading:z,excludeId:e.id}),t.jsx(jl,{isOpen:R,entityType:H,relationField:M,inheritData:X,onConfirm:Te,onCancel:()=>C(!1)}),t.jsx(kl,{isOpen:T,title:g.action.selectBookOrWork,filterType:"all",recentEntities:A,excludeId:e.id,onSelect:ye,onCancel:()=>{ce(!1),D(null)},onSearch:re})]})};function Du({items:e,onChange:n}){const o=me(),r=(c,p,a)=>{const d=e.map((u,m)=>m===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(Ye,{label:o.editor.bookNameLabel,value:c.book_title,onChange:a=>r(p,"book_title",a)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(Ye,{label:o.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 ${i("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function Sl({items:e,onChange:n,showMeta:o,addLabel:r}){const s=me(),[l,c]=f.useState(null),p=(u,m,x)=>{const g=e.map((b,w)=>w===u?{...b,[m]:x||void 0}:b);n(g)},a=u=>{n(e.filter((m,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,m)=>{const x=l===m;return t.jsxs("div",{style:{border:`1px solid ${i("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, ${i("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>c(x?null:m),children:[t.jsx("span",{style:{fontSize:"10px",color:i("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:i("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:g=>{g.stopPropagation(),a(m)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${i("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:i("muted")},children:"✕"})]}),!x&&o&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:i("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(Ye,{label:s.label.sourceName,value:u.source,onChange:g=>p(m,"source",g)}),t.jsx(Ye,{label:s.label.sourceBid,value:u.source_bid||"",onChange:g=>p(m,"source_bid",g)})]}),o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ye,{label:s.label.titleInfo,value:u.title_info||"",onChange:g=>p(m,"title_info",g)}),t.jsx(Ye,{label:s.label.authorInfo,value:u.author_info||"",onChange:g=>p(m,"author_info",g)})]}),t.jsx(Ye,{label:s.label.edition,value:u.edition||"",onChange:g=>p(m,"edition",g)})]}),t.jsx(jt,{value:u.summary||"",onChange:g=>p(m,"summary",g),placeholder:s.editor.summaryPlaceholder}),t.jsx(jt,{value:u.comment||"",onChange:g=>p(m,"comment",g),placeholder:s.editor.commentPlaceholder}),t.jsx(jt,{value:u.additional_comment||"",onChange:g=>p(m,"additional_comment",g),placeholder:s.editor.additionalCommentPlaceholder})]})]},m)}),t.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Hu({items:e,onChange:n}){const o=me();return t.jsx(Sl,{items:e,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function Gu({items:e,onChange:n}){const o=me();return t.jsx(Sl,{items:e,onChange:n,addLabel:o.action.addEmendatedBy})}function $l(e){var p,a,d,u,m,x,g;const n=((a=(p=e.authors)==null?void 0:p[0])==null?void 0:a.name)||"",o=((d=e.publication_info)==null?void 0:d.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(m=e.page_count)!=null&&m.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:o,holder:r,pages:s,description:l,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const b=e;if(Array.isArray(b.related_works)){const w=b.related_works.find(y=>y.relation==="part_of");w&&(c.parentWorkId=w.id,c.parentWorkName=w.title)}}if(e.type==="book"){const b=e;c.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(c.collectionId=(g=b.contained_in[0])==null?void 0:g.id)}return c}function Uu(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 Vu=e=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:l,onChange:c,onSave:p,onDelete:a,onNavigate:d,renderLink:u,onAskAI:m,renderSectionActions:x,onDownloadResource:g,downloadStatuses:b,relations:w,onRelationsChange:y,headerExtra:j,className:h,style:v}=e;me();const[$,k]=f.useState(s),_=l?s:$;f.useEffect(()=>{s!==$&&k(s)},[s]);const S=f.useCallback(()=>{const M=_==="view"?"edit":"view";l?l(M):k(M)},[_,l]),[z,N]=f.useState(null);f.useEffect(()=>{o&&r&&r.getItem(o).then(M=>{M&&N(M)})},[o,r]);const R=n||z,C=f.useMemo(()=>R?$l(R):null,[R]),H=l||!n?t.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:_==="edit"?i("accent-bg"):"transparent",color:i(_==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?"切换到编辑模式":"切换到查看模式",children:_==="view"?"✏️ 编辑":"👁 查看"}):null,L=t.jsxs(t.Fragment,{children:[H,j]});return!R&&!C?t.jsx(kt,{}):_==="view"?t.jsx(Ei,{data:R,transport:r,onNavigate:d?M=>d(M):void 0,renderLink:u,headerExtra:L,className:h,style:v}):C?t.jsxs("div",{className:h,style:v,children:[L&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:L}),t.jsx(wl,{data:C,onChange:c||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:m,renderSectionActions:x,onDownloadResource:g,downloadStatuses:b,relations:w,onRelationsChange:y})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:i("muted")},children:"无数据"})},jr=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],_l=({isOpen:e,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,l]=f.useState(null),[c,p]=f.useState(""),[a,d]=f.useState(""),[u,m]=f.useState("idle"),[x,g]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{e&&(l(null),p(""),d(""),m("idle"),g(""))},[e]),f.useEffect(()=>{s&&setTimeout(()=>{var h;return(h=b.current)==null?void 0:h.focus()},100)},[s]),f.useEffect(()=>{if(u==="success"){const h=setTimeout(n,2e3);return()=>clearTimeout(h)}},[u,n]),f.useEffect(()=>{if(!e)return;const h=v=>{v.key==="Escape"&&n()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[e,n]);const w=async()=>{if(!(!s||!c.trim())){m("submitting"),g("");try{await o({type:s,content:c.trim(),...a.trim()?{contact:a.trim()}:{}}),m("success")}catch(h){m("error"),g(h instanceof Error?h.message:"提交失败,请稍后重试")}}};if(!e)return null;const y=s&&c.trim()&&u!=="submitting",j=jr.find(h=>h.value===s);return t.jsx("div",{style:Yu,onClick:h=>{h.target===h.currentTarget&&n()},children:t.jsxs("div",{style:Ku,onClick:h=>h.stopPropagation(),children:[t.jsxs("div",{style:qu,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:Ju,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:tx,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:i("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:jr.map(h=>t.jsxs("button",{onClick:()=>l(h.value),style:{...Zu,...s===h.value?Xu:{}},children:[t.jsx("span",{children:h.icon})," ",h.label]},h.value))}),t.jsx("textarea",{ref:b,value:c,onChange:h=>p(h.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...Qu,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:a,onChange:h=>d(h.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:ix}),t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[c.length," / 2000"]}),u==="error"&&t.jsx("div",{style:nx,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:w,disabled:!y,style:{...ex,opacity:y?1:.6,cursor:y?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},Yu={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ku={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:i("shadow-dialog")},qu={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Ju={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:i("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Zu={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Xu={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Qu={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},ex={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},tx={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:i("success")},nx={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginBottom:"12px"},ix={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},bi="--bim-feedback-fab-offset",yi=48,ox=16,rx=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:o,hidden:r=!1,zIndex:s})=>{const[l,c]=f.useState(!1),p=n.bottom??24;return f.useEffect(()=>{if(r||typeof document>"u")return;const a=document.documentElement;return a.style.setProperty(bi,`calc(${p+yi+ox}px + env(safe-area-inset-bottom, 0px))`),()=>{a.style.removeProperty(bi)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>c(!0),style:{...sx,zIndex:s??i("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(_l,{isOpen:l,onClose:()=>c(!1),onSubmit:e,feedbackListUrl:o})]})},sx={position:"fixed",width:`${yi}px`,height:`${yi}px`,borderRadius:"50%",border:"none",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:i("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},vr=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],zl=({onSubmit:e})=>{const[n,o]=f.useState("bug"),[r,s]=f.useState(""),[l,c]=f.useState(""),[p,a]=f.useState("idle"),[d,u]=f.useState(""),m=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var w;return(w=m.current)==null?void 0:w.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(""),o("bug")}catch(w){a("error"),u(w instanceof Error?w.message:"提交失败,请稍后重试")}}},g=n&&r.trim()&&p!=="submitting",b=vr.find(w=>w.value===n);return p==="success"?t.jsx("div",{style:kr,children:t.jsxs("div",{style:px,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>a("idle"),style:ux,children:"继续提交"})]})}):t.jsxs("div",{style:kr,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:vr.map(w=>t.jsxs("button",{onClick:()=>o(w.value),style:{...lx,...n===w.value?ax:{}},children:[t.jsx("span",{children:w.icon})," ",w.label]},w.value))}),t.jsx("textarea",{ref:m,value:r,onChange:w=>s(w.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...cx}}),t.jsx("input",{type:"text",value:l,onChange:w=>c(w.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:fx}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:x,disabled:!g,style:{...dx,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:xx,children:d})]})},kr={padding:"16px",border:`1px solid ${i("widget-border")}`,borderRadius:"8px",background:i("input-bg")},lx={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ax={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},cx={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},dx={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},px={display:"flex",alignItems:"center",gap:"12px",color:i("success"),fontSize:"14px"},ux={background:"none",border:"none",color:i("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},xx={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginTop:"8px"},fx={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function wr(e){return typeof e=="function"?e():e??"/api/feedback"}const Cl=({resourceId:e,apiUrl:n})=>{const[o,r]=f.useState([]),[s,l]=f.useState(!0),c=f.useCallback(async()=>{const a=wr(n);l(!0);try{const u=await(await fetch(`${a}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);f.useEffect(()=>{c()},[c]);const p=async a=>{const d=wr(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 m=await u.json().catch(()=>null);throw new Error((m==null?void 0:m.error)||"提交失败")}setTimeout(()=>c(),500)};return t.jsxs("div",{children:[t.jsx(io,{items:o,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(zl,{onSubmit:p})})]})},Sr={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 $r(e){return e?Sr[e]??e:Sr.related}const mx={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function gx(e){return mx[e]??e}const hx={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function bx(e){return hx[e]??""}function oo({authors:e,onNavigate:n,renderLink:o}){const{convert:r}=V(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,c)=>{const p=Wi(l.role);return t.jsxs(f.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(Me,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:o,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},c)})}):null}function Tl(e,n){var p,a;const o=Bi(e,n),r=o.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=o.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=o.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((a=o.buckets.find(d=>d.key==="text"))==null?void 0:a.items)??[],groups:r}}function Il(e,n){const o=(e.url?Bt(e.url):void 0)||e.name,r=hs(e,n);return r?`${o}(${r})`:o}function ro({item:e,siblings:n,listedVolumeCounts:o}){const{convert:r}=V(),[s,l]=f.useState(!1),c=Sn(e),p=!!c&&c.expected>0&&!(o!=null&&o.has(c.expected)),a=r(Il(e,n)),d=At(e),u=Rn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var x,g;const m=(x=e.metadata)!=null&&x.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((g=e.metadata)==null?void 0:g.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("殘片")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:r(e.color_mode==="color"?"彩色":"黑白")})]}):null;return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[a," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),m]}):t.jsxs("span",{className:"bim-d-zt-name",children:[a,m]})})(),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(m=>!m),children:r(s?"收起分冊":`展開 ${c.expected} 冊`)})})]})}function El({groups:e,listedVolumeCounts:n}){const{convert:o}=V();return t.jsx(t.Fragment,{children:e.map(r=>t.jsxs("div",{className:"bim-d-rg",children:[r.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:o(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:o(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(ro,{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:o("鏡像")}),r.mirrors.map((s,l)=>{const c=At(s),p=o(Il(s,r.mirrors));return c?t.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",title:s.details?o(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 Xt=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function ji(e){var o;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(o=Xt.find(r=>n.startsWith(r.key[0])))==null?void 0:o.key}const _r=12,yx=60,Rl=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,railTop:l,back:c,railLinks:p})=>{var Te,Ce,Ae;const a=me(),{convert:d}=V(),u=f.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[m,x]=f.useState(new Map),[g,b]=f.useState(!1),[w,y]=f.useState(""),[j,h]=f.useState(!1),v=u.length<=yx,$=v||g||!!w||j,k=f.useMemo(()=>$?u:u.slice(0,_r),[u,$]);f.useEffect(()=>{if(!n||k.length===0)return;const P=k.filter(re=>!m.has(re));if(P.length===0)return;let se=!1;return Promise.all(P.map(re=>n.getItem(re).then(ye=>{const be=ye??{};return[re,{id:re,title:be.title,edition:be.edition,resources:be.resources,publication_info:be.publication_info,current_location:be.current_location,lineage:be.lineage,measure_info:be.measure_info}]}).catch(()=>[re,{id:re}]))).then(re=>{se||x(ye=>{const be=new Map(ye);for(const[K,I]of re)be.set(K,I);return be})}),()=>{se=!0}},[n,k,m]);const _=f.useMemo(()=>u.map(P=>m.get(P)??{id:P}),[u,m]),S=u.length>0&&u.every(P=>m.has(P)),z=!!n&&k.some(P=>!m.has(P)),N=v||$,R=f.useMemo(()=>ys(_,e.version_graph,{era:w,scanOnly:j,sort:N?"year":"default"}),[_,e.version_graph,w,j,N]),C=g?R.rows:R.rows.slice(0,_r),H=R.allRows.filter(P=>P.hasImage).length,L=e.related_works||[],M=L.filter(P=>P.relation==="collected_in"),F=f.useMemo(()=>{const P=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],se=re=>{const ye=P.indexOf(re??"");return ye<0?P.length:ye};return L.filter(re=>re.relation!=="collected_in").map((re,ye)=>({r:re,i:ye})).sort((re,ye)=>se(re.r.relation)-se(ye.r.relation)||re.i-ye.i).map(re=>re.r)},[L]),X=f.useMemo(()=>{const P=Bi(e.resources,e.resource_groups);return[...P.mirrors.flatMap(se=>se.items.map(re=>({r:re,kind:d(se.label)}))),...P.buckets.flatMap(se=>se.items.map(re=>({r:re,kind:d(bx(se.key))})))]},[e.resources,e.resource_groups,d]),U=e.indexed_by||[],T=e.emendated_by||[],ce=f.useMemo(()=>{var fe,he,W;const P=[],se=(he=(fe=e.authors)==null?void 0:fe[0])==null?void 0:he.dynasty;se&&P.push({label:"成書",value:d(se)});const re=pt(e,a.unit.juan);if(re){const ae=(W=e.juan_count)==null?void 0:W.description;P.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[d(re),ae&&ae!==re?t.jsxs("span",{className:"bim-d-meta",children:["(",d(ae),")"]}):null]})})}e.loss_status&&P.push({label:"存佚",value:d(gx(e.loss_status))});const ye=R.allRows.filter(ae=>ae.sortYear!=null),be=ye.length>0?ye.reduce((ae,J)=>ae.sortYear<=J.sortYear?ae:J):null;be!=null&&be.era.era?P.push({label:"最早存世",value:d([be.era.era,be.era.reign].filter(Boolean).join(" ")),title:be.era.source==="edition"?d("據版本題名推斷"):void 0}):z&&P.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),T.length&&P.push({label:"考證",value:`${T.length} ${d("條")}`});const K=zr(e.additional_titles);K.length&&P.push({label:"又名",value:K.map(d).join("、")});const I=zr(e.attached_texts);I.length&&P.push({label:"附載",value:I.map(d).join("、")});const Y=(e.additional_works||[]).map(ae=>d(ae.book_title)+(ae.n_juan!=null?` ${ae.n_juan}${d(a.unit.juan)}`:""));return Y.length&&P.push({label:"附錄",value:Y.join("、")}),P},[e,d,a,z,R.allRows,T.length]),D=[{value:e._edition_count??u.length,label:"版本"},{value:S?H:0,label:"有影印"},{value:U.length,label:"家著錄"}],A=e.classification,ee=A?[A.l1,A.l2,A.l3,A.l4].filter(Boolean).map(P=>d(P)):[],de=e.subtype?d(a.workSubtype[e.subtype]??e.subtype):"",G=t.jsx(on,{title:d(e.title),byline:t.jsx(oo,{authors:e.authors,onNavigate:o,renderLink:r}),meta:t.jsx(De,{items:[...ee,A!=null&&A.source?d(`據《${A.source.split("/")[0]}》`):"",de]}),description:(Te=e.description)!=null&&Te.text?t.jsxs(t.Fragment,{children:[t.jsx(dt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Ce=e.description.sources)!=null&&Ce.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(P=>d(ed(P))).filter(Boolean).join(" · ")}):null]}):void 0,stats:D,facts:ce,readAction:s,foot:t.jsx(rn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Ae=e.appendix)==null?void 0:Ae.map((P,se)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(P.title)}),t.jsx(dt,{text:P.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},se))}),q=R.eras.length>=2?[{key:"",label:a.catalog.all},...R.eras.map(P=>({key:P,label:`${P} ${R.allRows.filter(se=>se.era.era===P).length}`}))]:[],ie=[];u.length&&ie.push({id:"versions",label:"版本",count:u.length}),U.length&&ie.push({id:"catalogs",label:"著錄",count:U.length}),M.length&&ie.push({id:"collected",label:"收入叢編",count:M.length}),F.length&&ie.push({id:"related",label:"相關書目",count:F.length}),X.length&&ie.push({id:"resources",label:"在線資源",count:X.length});const pe=u.length===0&&U.length===0,ge=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(He,{id:"versions",title:"版本",meta:t.jsx(De,{items:[d(`共 ${u.length} 種`),S&&H?d(`${H} 種有影印`):"",R.rows.length!==R.allRows.length?d(`當前 ${R.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&q.length===0&&u.length>1?"":void 0,children:[q.length>0&&t.jsx(Ln,{items:q,value:w,onChange:P=>{y(P),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Is,{label:"只看有影印",checked:j,onChange:P=>{h(P),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:d(N?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("版本")}),t.jsx("th",{children:d("年代")}),t.jsx("th",{children:d("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:d("影印")})})]})}),t.jsx("tbody",{children:C.map(P=>{var se;return t.jsx(jx,{row:P,measure:(se=m.get(P.id))==null?void 0:se.measure_info,loaded:m.has(P.id),onNavigate:o,renderLink:r},`${P.id}:${m.has(P.id)?"r":"p"}`)})})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(w||j?"當前篩選下沒有版本":"暫無版本著錄")}),R.rows.length>C.length&&t.jsx(Mt,{label:`展開其餘 ${R.rows.length-C.length} 種版本`,onClick:()=>b(!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(vx,{items:U,transport:n,onNavigate:o,renderLink:r}),pe&&t.jsx(He,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),Ee=(P,se)=>t.jsx(Me,{id:P,label:d(se),onNavigate:o,renderLink:r,dense:!0}),Ne=f.useMemo(()=>{const P=new Map;for(const se of F){const re=$r(se.relation);P.set(re,(P.get(re)??0)+1)}return P.size>1?[...P.entries()].sort((se,re)=>re[1]-se[1]).slice(0,4).map(([se,re])=>`${d(se)} ${re}`).join(" · "):void 0},[F,d]),ze=t.jsxs(t.Fragment,{children:[t.jsx(yt,{id:"collected",title:"收入叢編",items:M.map(P=>Ee(P.id,P.title))}),t.jsx(yt,{id:"related",title:"相關書目",meta:d(`${F.length} 部`),sub:Ne,items:F.map(P=>t.jsxs(t.Fragment,{children:[Ee(P.id,P.title),t.jsx("span",{className:"bim-d-meta",title:P.note?d(P.note):void 0,children:d($r(P.relation))})]}))}),t.jsx(yt,{id:"resources",title:"在線資源",cap:6,items:X.map(({r:P,kind:se})=>{const re=d((P.url?Bt(P.url):void 0)||P.name),ye=At(P);return t.jsxs(t.Fragment,{children:[ye?t.jsxs("a",{href:ye,target:"_blank",rel:"noopener noreferrer",children:[re," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:re}),se&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:se})]})})})]});return t.jsx(nn,{railTop:l,back:c,nav:ie,railLinks:p,main:ge,card:G,side:ze})};function zr(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Cr(e,n){return n((e.url?Bt(e.url):void 0)||e.name)}function jx({row:e,measure:n,loaded:o,onNavigate:r,renderLink:s}){const{convert:l}=V(),c=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",a=e.holders[0],d=a?Cr(a,l):e.locationName?l(e.locationName):"",u=e.images[0],m=u?At(u):void 0,x=e.images.map(g=>Cr(g,l)).join("、");return t.jsxs("tr",{"data-loading":o?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Me,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${c?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:c?l(c):o?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||(o?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&&(m?t.jsx("a",{className:"bim-d-flag",href:m,target:"_blank",rel:"noopener noreferrer",title:x,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:x,children:l("有影印")}))})]})}function vx({items:e,transport:n,onNavigate:o,renderLink:r}){const s=me(),{convert:l}=V(),[c,p]=f.useState(0),a=Math.min(c,e.length-1),d=e[a],[u,m]=f.useState(new Map);return f.useEffect(()=>{if(!n)return;const x=[...new Set(e.map(b=>b.source_bid).filter(b=>!!b))];if(x.length===0)return;let g=!1;return Promise.all(x.map(b=>n.getItem(b).then(w=>{var y,j;return[b,((j=(y=w==null?void 0:w.authors)==null?void 0:y[0])==null?void 0:j.dynasty)??""]}).catch(()=>[b,""]))).then(b=>{g||m(new Map(b.filter(([,w])=>w)))}),()=>{g=!0}},[n,e]),t.jsx(He,{id:"catalogs",title:"著錄",meta:t.jsx(De,{items:[l(`歷代書目 ${e.length} 家`),l("按著錄順序")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":l("著錄書目"),children:e.map((x,g)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":g===a,"aria-label":l(x.source),onClick:()=>p(g),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(x.source_bid??"")?l(u.get(x.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...l(x.source)].slice(0,9).map((b,w)=>t.jsx("span",{children:b},w))})]})},g))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:l(d.title_info)}),t.jsx(De,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?t.jsx(Me,{id:d.source_bid,label:l(d.source),onNavigate:o,renderLink:r,dense:!0}):l(d.source),d.section?l(d.section):"",d.author_info?`${l(s.label.authorInfo)} ${l(d.author_info)}`:"",d.edition?`${l(s.label.edition)} ${l(d.edition)}`:"",d.page??""]}),d.summary&&t.jsx("p",{className:"bim-d-quote",children:Ke(l(d.summary))}),d.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:Ke(l(d.comment))})]}),d.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:Ke(l(d.additional_comment))})]}),!d.summary&&!d.comment&&!d.additional_comment&&!d.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:l("僅著錄書名,無提要。")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[a>0?t.jsx("button",{type:"button","aria-label":l(`上一家:${e[a-1].source}`),onClick:()=>p(a-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",l(e[a-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[a+1," / ",e.length]}),a<e.length-1?t.jsx("button",{type:"button","aria-label":l(`下一家:${e[a+1].source}`),onClick:()=>p(a+1),children:t.jsxs("span",{"aria-hidden":"true",children:[l(e[a+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function kx(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 wx(e,n){if(!e.lineage)return null;const o=e.lineage;return{id:e.id,kind:"book",label:e.title,year:o.year,year_text:o.year_text,year_uncertain:o.year_uncertain,category:o.category,status:o.status,extant_juan:o.extant_juan,group:n[e.id],note:o.note}}function Tr(e,n,o){return{id:`derive:${n.ref}->${e}:${o}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Sx(e,n,o){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${o}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function $x(e,n){var d;if(n==="all")return null;const o=(d=e.collections)==null?void 0:d[n],r=Array.isArray(o==null?void 0:o.groups)&&o.groups.length>0,s=Array.isArray(o==null?void 0:o.book_ids)&&o.book_ids.length>0,l=r||s||!!(o!=null&&o.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(!o||!l)return null;const c=r?new Set(o.groups):null,p=new Set(o.book_ids??[]);if(c&&e.node_groups)for(const[u,m]of Object.entries(e.node_groups))c.has(m)&&p.add(u);let a=null;if(o.hypothetical_ids&&(a=new Set(o.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 bn(e,n,o){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=$x(r,o??r.default_collection??"all"),a=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,m=new Set,x=new Set;if(a){const $=new Map(n.map(R=>[R.id,R])),k=new Map((r.hypothetical_nodes??[]).map(R=>[R.id,R])),_=R=>{const C=$.get(R);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(L=>L.ref);const H=k.get(R);return H?(H.derived_from??[]).map(L=>L.ref):[]},S=R=>k.has(R)?!u||u.has(R):!d||d.has(R),z=new Set,N=R=>{if(!z.has(R)){z.add(R);for(const C of _(R))l.has(C)||(S(C)||(k.has(C)?x.add(C):$.has(C)&&m.add(C)),N(C))}};for(const R of n)d&&d.has(R.id)&&!l.has(R.id)&&N(R.id);for(const R of r.hypothetical_nodes??[])u&&u.has(R.id)&&N(R.id)}const g=n.filter($=>!l.has($.id)).filter($=>!d||d.has($.id)||m.has($.id)).map($=>{const k=wx($,c);return k&&m.has($.id)&&(k.bridge=!0),k}).filter($=>$!==null),b=(r.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||x.has($.id)).map($=>{const k=kx($);return x.has($.id)&&(k.bridge=!0),k}),w=[...g,...b],y=new Set(w.map($=>$.id)),j=new Set,h=[],v=$=>{j.has($.id)||!y.has($.source)||!y.has($.target)||(j.add($.id),h.push($))};for(const $ of n)l.has($.id)||!$.lineage||d&&!d.has($.id)&&!m.has($.id)||(($.lineage.derived_from??[]).forEach((k,_)=>{v(Tr($.id,k,_))}),($.lineage.related_to??[]).forEach((k,_)=>{v(Sx($.id,k,_))}));for(const $ of r.hypothetical_nodes??[])u&&!u.has($.id)&&!x.has($.id)||($.derived_from??[]).forEach((k,_)=>{v(Tr($.id,k,_))});return{nodes:w,edges:h,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function Nl(e,n,o){const r=(e??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function _x(e,n){const o=[],r=e.version_graph;if(!r)return o;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)||o.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&o.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&o.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)||o.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 o}const Ll=({graph:e,renderLink:n,className:o,style:r})=>{const{convert:s}=V();if(!e.nodes.length)return t.jsx("div",{style:{...Px,...r},className:o,children:"暂无版本图数据"});const l=new Map,c=new Map;for(const x of e.edges)if(x.kind==="derive"){const g=l.get(x.target)??[];g.push(x),l.set(x.target,g)}else for(const g of[x.source,x.target]){const b=c.get(g)??[];b.push(x),c.set(g,b)}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 g=a.get(x.group)??[];g.push(x),a.set(x.group,g)}else d.push(x);const u=(x,g)=>(x.year??9999)-(g.year??9999);a.forEach(x=>x.sort(u)),d.sort(u);const m=e.groups.filter(x=>a.has(x.id));return t.jsxs("div",{className:o,style:{...Cx,...r},children:[e.title&&t.jsx("div",{style:Tx,children:s(e.title)}),e.description&&t.jsx("div",{style:Ix,children:s(e.description)}),m.map(x=>t.jsx(Ir,{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(Ir,{label:"其他",nodes:d,incomingMap:l,siblingMap:c,nodeMap:p,renderLink:n})]})},Ir=({label:e,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:c})=>{const{convert:p}=V();return t.jsxs("div",{style:Ex,children:[t.jsx("div",{style:{...Rx,borderLeftColor:n??i("widget-border")},children:p(e)}),o.map(a=>t.jsx(zx,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:l,renderLink:c},a.id))]})},zx=({node:e,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",c=e.bridge,{convert:p}=V();return t.jsxs("div",{style:{...Nx,borderStyle:l||c?"dashed":"solid",opacity:c?.55:e.status==="lost"?.7:1,background:c?i("bg-subtle"):void 0},title:c?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:Lx,children:[t.jsx("span",{style:Bx,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Ax,children:Nl(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Wx,children:[e.category&&t.jsx(Vt,{children:p(e.category)}),e.status==="lost"&&t.jsx(Vt,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(Vt,{tone:"warn",children:"残本"}),l&&t.jsx(Vt,{tone:"info",children:"假想祖本"}),c&&t.jsx(Vt,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Mx,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:Fx,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:Rr,children:[t.jsx("div",{style:Nr,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return t.jsxs("div",{style:Lr(a.confidence),children:[t.jsx("span",{style:Br,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(Er,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:Ar,children:["· ",p(a.evidence)]})]},a.id)})]}),o.length>0&&t.jsxs("div",{style:Rr,children:[t.jsx("div",{style:Nr,children:"关联:"}),o.map(a=>{const d=a.source===e.id?a.target:a.source,u=r.get(d);return t.jsxs("div",{style:Lr(a.confidence),children:[t.jsx("span",{style:Br,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(Er,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:Ar,children:["· ",p(a.evidence)]})]},a.id)})]})]})},Vt=({children:e,tone:n="default"})=>{const r={default:{bg:i("tag-bg"),fg:i("fg")},warn:{bg:i("warn-bg"),fg:i("warn-fg")},info:{bg:i("info-bg"),fg:i("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})},Er=({level:e})=>{const o={certain:{label:"确定",color:i("confidence-certain")},consensus:{label:"共识",color:i("confidence-consensus")},probable:{label:"推测",color:i("confidence-probable")},disputed:{label:"有争议",color:i("confidence-disputed")}}[e];return o?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${o.color}`,color:o.color,borderRadius:"8px",marginLeft:"4px"},children:o.label}):null},Cx={fontSize:"14px",color:i("fg")},Tx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ix={fontSize:"13px",color:i("muted"),marginBottom:"16px",lineHeight:1.6},Ex={marginBottom:"16px"},Rx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:i("fg")},Nx={border:`1px solid ${i("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:i("bg")},Lx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Bx={fontSize:"15px",fontWeight:600},Ax={fontSize:"12px",color:i("muted")},Wx={marginBottom:"6px"},Mx={fontSize:"12px",color:i("muted"),margin:"2px 0"},Fx={fontSize:"12px",color:i("muted"),fontStyle:"italic",margin:"4px 0"},Rr={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${i("widget-border")}`},Nr={fontSize:"11px",color:i("muted"),marginBottom:"2px"},Lr=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Br={display:"inline-block",padding:"0 6px",fontSize:"11px",background:i("tag-bg"),color:i("fg"),borderRadius:"3px",marginRight:"6px"},Ar={fontSize:"11px",color:i("muted")},Px={padding:"20px",textAlign:"center",color:i("muted"),fontSize:"13px"},Bl=({selectedNodeId:e,...n})=>{const[o,r]=f.useState("loading"),[s,l]=f.useState(null);return f.useEffect(()=>{let c=!1;return Ox().then(p=>{c||(p?(l(p),r("ready")):r("missing"))}),()=>{c=!0}},[]),o==="loading"?t.jsx("div",{style:Wr,children:"加载图组件中…"}):o==="missing"||!s?t.jsxs("div",{style:Wr,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(Dx,{modules:s,selectedNodeId:e,...n})};async function Ox(){try{const[e,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let o=!1;try{await import("@xyflow/react/dist/style.css"),o=!0}catch{o=!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:o}}catch{return null}}const Dx=({graph:e,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:l,modules:c})=>{const{ReactFlow:p,Background:a,Controls:d,Handle:u,Position:m,BaseEdge:x,EdgeLabelRenderer:g,getSmoothStepPath:b,dagre:w}=c,y=f.useMemo(()=>({lineage:_=>{var X,U,T,ce;const S=((X=_.data)==null?void 0:X.stepPosition)??.85,[z,N,R]=b({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:S,borderRadius:5}),C=!!((U=_.data)!=null&&U.isSibling),H=C?N:_.targetX-18,L=C?R:_.targetY-12,M=(T=_.data)==null?void 0:T.labelStyle,F=(ce=_.data)==null?void 0:ce.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(x,{id:_.id,path:z,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&t.jsx(g,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${H}px,${L}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:i("bg"),border:`0.5px solid ${i("widget-border")}`,...F,...M},children:_.label})})]})}}),[x,g,b]),j=f.useMemo(()=>({version:_=>{const S=_.data,z=S.kind==="hypothetical",N=S.status==="lost",R=S.isSelected,C=S.bridge,H=S.borderColor??i("muted"),L=C||z?"dashed":"solid",M=C?.5:N?.6:1;return t.jsxs("div",{style:{background:i(C?"bg-subtle":"bg"),border:`2px ${L} ${R?i("primary"):H}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:M,boxShadow:R?i("shadow-node-selected"):z||C?"none":i("shadow-node")},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:m.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.2},children:Nl(S.yearText,void 0,S.uncertain)}),N&&t.jsx("div",{style:{fontSize:9,color:i("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:m.Right,style:{visibility:"hidden"}})]})}}),[u,m]),{convert:h}=V(),{rfNodes:v,rfEdges:$}=f.useMemo(()=>Hx(e,w,n,l,h),[e,w,n,l,h]);return t.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:t.jsxs(p,{nodes:v,edges:$,nodeTypes:j,edgeTypes:y,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 Hx(e,n,o,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??i("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 m=e.nodes.map(j=>{const h=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??Ux(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:o,isSelected:v,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:h.x-160/2,y:h.y-90/2},data:$,draggable:!1,selected:v}}),x=.78,g=.06,b=new Map;for(const j of e.edges)j.kind==="derive"&&(b.has(j.source)||b.set(j.source,[]),b.get(j.source).push(j));const w=new Map;for(const[j,h]of b){if(h.length<=1)continue;const v=[...h].sort((k,_)=>{var N,R;const S=((N=a.node(k.target))==null?void 0:N.y)??0,z=((R=a.node(_.target))==null?void 0:R.y)??0;return S-z}),$=v.length;v.forEach((k,_)=>{const S=(_-($-1)/2)*g;w.set(k.id,x+S)})}const y=e.edges.map(j=>Gx(j,w.get(j.id),s));return{rfNodes:m,rfEdges:y}}function Gx(e,n,o=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Vx(e.confidence),c={type:"arrowclosed",color:l,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:o(e.relation),data:{labelStyle:{color:i("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 Ux(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Vx(e){switch(e){case"certain":return i("confidence-certain");case"consensus":return i("lineage-edge-consensus");case"probable":return i("confidence-probable");case"disputed":return i("confidence-disputed");default:return i("muted")}}const Wr={padding:"40px 20px",textAlign:"center",color:i("muted"),fontSize:"13px",border:`1px dashed ${i("widget-border")}`,borderRadius:8,background:i("bg")},so=({graph:e,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:c,onCollectionChange:p,collectionsAvailable:a,collectionCounts:d,className:u,style:m})=>{var h;const[x,g]=f.useState(n),b=v=>{g(v),l==null||l(v)},w=(()=>{if(!a)return[];const v=Object.entries(a);return v.length===0||a.all?v:[...v,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),y=!!(p&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:i("muted"),textAlign:"center"},children:"暂无版本传承数据"});const j=c?(h=a==null?void 0:a[c])==null?void 0:h.description:void 0;return t.jsxs("div",{className:u,style:m,children:[t.jsxs("div",{style:Yx,children:[t.jsx("button",{onClick:()=>b("list"),style:Zn(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:Zn(x==="graph"),children:"关系图"}),y&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:i("muted"),marginRight:4},children:"集合:"}),w.map(([v,$])=>{const k=d==null?void 0:d[v];return t.jsxs("button",{onClick:()=>p==null?void 0:p(v),style:Zn(c===v),title:$.description,children:[$.label,k!=null?` ${k}`:""]},v)})]})]}),y&&j&&t.jsx("div",{style:{fontSize:12,color:i("muted"),marginBottom:8,padding:"4px 8px",background:i("bg-subtle"),borderRadius:4},children:j}),x==="list"?t.jsx(Ll,{graph:e,renderLink:o}):t.jsx(Bl,{graph:e,renderLink:o,height:r,selectedNodeId:s})]})},Yx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Zn=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${i("widget-border")}`,borderRadius:4,background:e?i("primary"):"transparent",color:i(e?"primary-fg":"fg"),cursor:"pointer"}),Mr=40,Fr=2,Kx=9,Pr={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function Xn(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Al=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,fullText:l,fullTextPending:c,chapterLink:p,railTop:a,back:d,railLinks:u})=>{var fe,he,W,ae,J,O,xe,je,Se,ne,we;const m=me(),{convert:x}=V(),[g,b]=f.useState(null),[w,y]=f.useState(new Map),[j,h]=f.useState([]),[v,$]=f.useState(new Map),[k,_]=f.useState(!1),[S,z]=f.useState("flow"),[N,R]=f.useState(null);f.useEffect(()=>{if(!n||!e.work_id){b(null);return}let E=!1;return n.getItem(e.work_id).then(Q=>{!E&&Q&&Q.type==="work"&&b(Q)}).catch(()=>{}),()=>{E=!0}},[n,e.work_id]),f.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){R(null);return}let E=!1;return n.getLineageGraph(e.work_id).then(Q=>{E||R(Q&&Q.nodes.length>1?Q:null)}).catch(()=>{E||R(null)}),()=>{E=!0}},[n,e.work_id]),f.useEffect(()=>{const E=e.contained_in||[];if(!n||E.length===0){y(new Map);return}let Q=!1;return Promise.all(E.map(ue=>{const le=typeof ue=="string"?ue:ue.id;return n.getItem(le).then(te=>[le,te]).catch(()=>[le,null])})).then(ue=>{if(Q)return;const le=new Map;for(const[te,ke]of ue)ke&&le.set(te,ke);y(le)}),()=>{Q=!0}},[n,e.contained_in]);const C=f.useMemo(()=>{const E=new Set([...(g==null?void 0:g.books)||[],...e.related_books||[]]);return E.add(e.id),[...E]},[g==null?void 0:g.books,e.related_books,e.id]),H=C.length-1;f.useEffect(()=>{if(!n||H<=0){h([]);return}const E=C.length<=Mr,Q=E?C:C.slice(0,8);let ue=!1;return Promise.all(Q.map(le=>le===e.id?Promise.resolve({id:le,title:e.title,edition:e.edition,year:vn(e)}):n.getItem(le).then(te=>{const ke=te??{};return{id:le,title:ke.title,edition:ke.edition,year:te?vn(ke):void 0}}).catch(()=>({id:le})))).then(le=>{if(ue)return;const te=le.filter(ke=>ke.id===e.id||ke.title||ke.edition);E&&te.sort((ke,Ie)=>(ke.year??1/0)-(Ie.year??1/0)),h(te)}),()=>{ue=!0}},[n,C,H,e]);const L=e.lineage,M=f.useMemo(()=>[...((L==null?void 0:L.derived_from)||[]).filter(E=>E.ref_type==="book").map(E=>E.ref),...((L==null?void 0:L.related_to)||[]).map(E=>E.book_id)].filter(Boolean),[L]);f.useEffect(()=>{if(!n||M.length===0){$(new Map);return}let E=!1;return Promise.all(M.map(Q=>n.getItem(Q).then(ue=>[Q,{id:Q,title:ue==null?void 0:ue.title,edition:ue==null?void 0:ue.edition}]).catch(()=>[Q,{id:Q}]))).then(Q=>{E||$(new Map(Q))}),()=>{E=!0}},[n,M]);const F=f.useMemo(()=>Tl(e.resources,e.resource_groups),[e.resources,e.resource_groups]),X=F.groups.reduce((E,Q)=>E+Q.rows.length+Q.mirrors.length,0),U=F.groups.length>0&&F.groups.every(E=>E.key==="_physical"),T=tn(e),ce=Ss(e),B=pt(e,m.unit.juan),D=new Set((e.contained_in||[]).map(E=>typeof E=="string"?0:Jt(E.volume_index).length).filter(E=>E>0)),A=E=>{var le;const Q=(le=e.base_edition)==null?void 0:le.find(te=>te.book_id===E&&te.name);if(Q!=null&&Q.name)return Q.name;const ue=v.get(E);return(ue==null?void 0:ue.edition)||(ue==null?void 0:ue.title)||""},ee=f.useMemo(()=>{var Ze,an,ut,cn,dn;const E=[];ce&&E.push({label:"版本類型",value:x(ce),title:e.edition_type||(Ze=e.lineage)!=null&&Ze.category?void 0:x("據版本題名推斷")}),(an=e.publication_info)!=null&&an.details?E.push({label:"刊印",value:x(e.publication_info.details)}):(T.era||T.reign)&&E.push({label:"刊寫年代",value:x([T.era,T.reign].filter(Boolean).join(" ")),title:T.source==="edition"?x("據版本題名推斷"):void 0}),B&&E.push({label:"卷帙",value:x(B)});const Q=(e.contained_in||[]).flatMap(_e=>typeof _e=="string"?[]:Jt(_e.volume_index));Q.length&&E.push({label:"冊次",value:x(`第 ${Nn(Q,m.unit.volume)} ${m.unit.volume}(${Q.length} ${m.unit.volume})`)});const ue=(((ut=e.lineage)==null?void 0:ut.derived_from)||[]).find(_e=>_e.relation==="底本"&&_e.ref_type==="book");ue&&A(ue.ref)&&E.push({label:"底本",value:t.jsx(Me,{id:ue.ref,label:x(A(ue.ref)),onNavigate:o,renderLink:r,dense:!0})});const le=(e.base_edition||[]).filter(_e=>_e&&_e.name);for(const _e of["底本","配補","參校"]){if(_e==="底本"&&ue&&A(ue.ref))continue;const tt=le.filter(Be=>Be.role===_e);tt.length&&E.push({label:_e,value:tt.map((Be,St)=>t.jsxs(f.Fragment,{children:[St>0&&"、",Be.book_id?t.jsx(Me,{id:Be.book_id,label:x(Be.name),onNavigate:o,renderLink:r,dense:!0}):x(Be.name)]},St))})}const te=(e.provenance||[]).filter(_e=>_e&&_e.institution),ke=(e.resources||[]).filter(_e=>(_e.types||(_e.type?[_e.type]:[])).includes("physical"));if(te.length){E.push({label:"存藏",value:te.slice(0,2).map(Be=>x(Be.institution)).join("、")+(te.length>2?x(` 等 ${te.length} 處`):"")});const _e=te.filter(Be=>Be.call_number).slice(0,2).map(Be=>`${x(Be.institution)} ${Be.call_number}`);_e.length&&E.push({label:"索書號",value:_e.join(";")+(te.filter(Be=>Be.call_number).length>2?"…":"")});const tt=te.flatMap(Be=>Be.seals||[]).filter(Boolean);tt.length&&E.push({label:"藏印",value:x(tt.join("、"))})}else ke.length?E.push({label:"存藏",value:ke.slice(0,2).map(_e=>x(_e.name)).join("、")+(ke.length>2?x(` 等 ${ke.length} 處`):"")}):(cn=e.current_location)!=null&&cn.name&&E.push({label:"存藏",value:x(e.current_location.name)});const Ie=e.physical_description;if(Ie){const _e=[["行款",Ie.leaf_style],["裝幀",Ie.binding],["尺寸",Ie.dimensions],["品相",Ie.condition]];for(const[tt,Be]of _e)Be&&Be.trim()&&E.push({label:tt,value:x(Be)})}(dn=e.page_count)!=null&&dn.description&&E.push({label:m.label.pageCount,value:x(e.page_count.description)});const We=[...pi(e.additional_titles),...pi(e.attached_texts)];return We.length&&E.push({label:"又名",value:We.map(x).join("、")}),E},[e,x,m,T,ce,B,v,o,r]),de=x(e.title),G=e.edition?x(e.edition):void 0,q=((fe=e.lineage)==null?void 0:fe.year_text)||"",ie=t.jsx(on,{kind:"版本",title:de,subtitle:G,byline:t.jsx(oo,{authors:e.authors??(g==null?void 0:g.authors),onNavigate:o,renderLink:r}),meta:(()=>{const E=[ce?x(ce):"",T.era?x([T.era,T.reign].filter(Boolean).join("")):"",B?x(B):""].filter(Boolean);return E.length?t.jsx("span",{className:"bim-d-tags",children:E.map((Q,ue)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ue,2)}`,children:Q},ue))}):null})(),description:(he=e.description)!=null&&he.text?t.jsx(dt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Mi((W=e.description)==null?void 0:W.text)?6:void 0,facts:ee,readAction:s,secondaryAction:s&&X>0&&!U?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(rn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),pe=e.contained_in||[],ge=(l==null?void 0:l.chapters)||[],Ee=ge[0]&&Xn(ge[0].title)[0].slice(-1)||"章",Ne=!!((ae=L==null?void 0:L.derived_from)!=null&&ae.length||(J=L==null?void 0:L.related_to)!=null&&J.length||(O=e.appendix)!=null&&O.length),ze=[];(ge.length||F.text.length||c)&&ze.push({id:"fulltext",label:"全文",count:ge.length?x(`${ge.length} ${Ee}`):void 0}),F.groups.length&&ze.push({id:"images",label:U?"館藏":"影印",count:X}),Ne&&ze.push({id:"lineage",label:"版本源流"}),pe.length&&ze.push({id:"collections",label:"收入叢編",count:pe.length}),(xe=e.location_history)!=null&&xe.length&&ze.push({id:"provenance",label:"流轉歷史"});const Te=E=>(p==null?void 0:p(E))??null,Ce=ge[0],Ae=Ce?Te(Ce.file):null,P=k?ge:ge.slice(0,Kx),se=(E,Q,ue)=>E?t.jsx("a",{className:ue,href:E.href??"#",onClick:E.onClick?le=>{le.metaKey||le.ctrlKey||(le.preventDefault(),E.onClick())}:void 0,children:Q}):t.jsx("span",{className:ue,children:Q}),re=t.jsxs(t.Fragment,{children:[(ge.length>0||F.text.length>0||c)&&t.jsxs(He,{id:"fulltext",title:"全文",meta:ge.length>0?t.jsx(De,{items:[x(`${ge.length} ${Ee}`),(je=l==null?void 0:l.source)!=null&&je.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[c&&!Ce&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),Ce&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${Xn(Ce.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((Ce.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),se(Ae,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),ge.length>1&&t.jsx("ul",{className:"bim-d-chap",children:P.map(E=>{const[Q,ue]=Xn(E.title);return t.jsx("li",{children:se(Te(E.file),t.jsxs(t.Fragment,{children:[Q&&t.jsx("b",{children:x(Q)}),x(ue||E.file)]}))},E.file)})}),ge.length>P.length&&t.jsx(Mt,{label:`展開其餘 ${ge.length-P.length} ${Ee}`,onClick:()=>_(!0)}),F.text.length>0&&t.jsxs(t.Fragment,{children:[(ge.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:F.text.map((E,Q)=>t.jsx(ro,{item:E,siblings:F.text,listedVolumeCounts:D},`${E.id||E.url||E.name}-${Q}`))})})]})]}),F.groups.length>0&&t.jsx(He,{id:"images",title:U?"館藏":"影印",meta:t.jsx(De,{items:[F.groups.length>1?x(`${F.groups.length} 組`):"",x(`${X} 處`)]}),children:t.jsx(El,{groups:F.groups,listedVolumeCounts:D})}),Ne&&t.jsx(He,{id:"lineage",title:"版本源流",meta:(Se=L==null?void 0:L.derived_from)!=null&&Se.length?x("據版本傳承著錄"):void 0,action:N?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":x("源流視圖"),children:[t.jsx("button",{type:"button","aria-pressed":S==="flow",onClick:()=>z("flow"),children:x("卡片")}),t.jsx("button",{type:"button","aria-pressed":S==="graph",onClick:()=>z("graph"),children:x("關係圖")})]}):void 0,children:S==="graph"&&N?t.jsx(so,{graph:N,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(E,Q)=>t.jsx(Me,{id:E,label:x(Q),onNavigate:o,renderLink:r,dense:!0})}):t.jsx(Jx,{data:e,heading:G||de,yearText:q,refName:A,onNavigate:o,renderLink:r})}),pe.length>0&&t.jsx(He,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:pe.map((E,Q)=>{var Ie,We;const ue=typeof E=="string"?E:E.id,le=typeof E=="string"?[]:Jt(E.volume_index),te=w.get(ue),ke=(te==null?void 0:te._member_count)||((Ie=te==null?void 0:te.books)==null?void 0:Ie.length)||((We=te==null?void 0:te.contained_works)==null?void 0:We.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Me,{id:ue,label:te?x(te.title):ue,onNavigate:o,renderLink:r,dense:!0}),le.length>0&&t.jsx(qx,{volumes:le,unit:m.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ke?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ke>0&&x(`全 ${ke} ${m.unit.bu}`)})]},`${ue}-${Q}`)})})})}),(ne=e.location_history)!=null&&ne.length?t.jsx(He,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((E,Q)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(E.name)}),([E.start_date,E.end_date].filter(Boolean).join("—")||E.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(De,{items:[[E.start_date,E.end_date].filter(Boolean).join("—"),E.description?x(E.description):""]})})]},Q))})}):null,ze.length===0&&t.jsx(He,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),ye=j.findIndex(E=>E.id===e.id),be=C.length<=Mr,K=be&&ye>=0?j.slice(Math.max(0,ye-Fr),ye+Fr+1):j.filter(E=>E.id!==e.id),I=t.jsxs(t.Fragment,{children:[g&&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(m.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Me,{id:g.id,label:x(g.title),onNavigate:o,renderLink:r})}),t.jsx(De,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(g.authors||[]).slice(0,2).map(E=>`${E.dynasty?`〔${x(E.dynasty)}〕`:""}${x(E.name)}`),x(pt(g,m.unit.juan)),g._edition_count?x(`${g._edition_count} 種版本`):""]}),((we=g.description)==null?void 0:we.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(g.description.text.replace(/[#*_>`[\]]/g,""))})]}),H>0&&K.length>0&&t.jsxs("div",{children:[t.jsx(yt,{id:"siblings",timeline:!0,title:be?"同作品版本":m.relation.siblingVersions,meta:x(be?"按年代":`${H} 種`),cap:K.length,items:K.map(E=>E.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(E.edition||E.title||E.id)}):t.jsx(Me,{id:E.id,label:x(E.edition||E.title||E.id),onNavigate:o,renderLink:r,dense:!0})),metas:K.map(E=>[E.year!=null?E.year<0?`前${-E.year}`:String(E.year):"",E.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:K.findIndex(E=>E.id===e.id)}),g&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Me,{id:g.id,label:x(`在作品頁看全部 ${C.length} 種 →`),onNavigate:o,renderLink:r,dense:!0})})]})]}),Y=e.work_id?t.jsx(Ts,{caption:m.section.belongsToWork,children:t.jsx(Me,{id:e.work_id,label:g?x(g.title):" ",onNavigate:o,renderLink:r,dense:!0})}):void 0;return t.jsx(nn,{railTop:a,back:d,up:Y,nav:ze,railLinks:u,main:re,card:ie,side:I})};function qx({volumes:e,unit:n}){const{convert:o}=V();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[o(`第 ${Nn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),o(`${e.length} ${n}`)]})]})}function Jx({data:e,heading:n,yearText:o,refName:r,onNavigate:s,renderLink:l}){var y;const{convert:c}=V(),p=e.lineage,a=(p==null?void 0:p.derived_from)||[],d=a.filter(j=>j.ref_type!=="book"),u=a.filter(j=>j.ref_type==="book"&&j.relation==="底本"),m=a.filter(j=>j.ref_type==="book"&&j.relation!=="底本"),x=(p==null?void 0:p.related_to)||[],g=a.length>0||x.length>0,b=j=>j&&Pr[j]?c(`(${Pr[j]})`):"",w=(j,h)=>t.jsx(Me,{id:j,label:c(h||j),onNavigate:s,renderLink:l,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[g&&t.jsxs("ol",{className:"bim-d-lf-list",children:[d.map((j,h)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:c(j.relation||"祖本")}),t.jsx("span",{className:"bim-d-lf-name",children:c("擬構祖本")}),j.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[c(j.evidence),b(j.confidence)]})]})},`a-${h}`)),u.map((j,h)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:c(j.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:w(j.ref,r(j.ref))}),j.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[c(j.evidence),b(j.confidence)]})]})},`b-${h}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:c("本版")}),t.jsx("span",{className:"bim-d-lf-name",children:n}),o&&t.jsx("span",{className:"bim-d-lf-yr",children:c(o)})]}),m.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:m.map((j,h)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:c(j.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:w(j.ref,r(j.ref))}),j.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[c(j.evidence),b(j.confidence)]})]},h))})]}),x.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:c("翻刻 · 衍生")}),t.jsx("span",{className:"bim-d-lf-chips",children:x.map((j,h)=>t.jsxs("span",{className:"bim-d-lf-chip",title:j.evidence?c(j.evidence):void 0,children:[w(j.book_id,r(j.book_id)),t.jsx("span",{className:"bim-d-meta",children:c(j.relation)})]},h))})]})]}),(y=e.appendix)==null?void 0:y.map((j,h)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:c("附記")})," ",c(j.title)]}),t.jsx(dt,{text:j.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${h}`)),(p==null?void 0:p.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:c(p.note)})]})}const Yt=16,Zx=200,Xx=16,Wl=({data:e,catalog:n,transport:o,onNavigate:r,renderLink:s,catalogAction:l,railTop:c,back:p,railLinks:a})=>{var ye,be,K,I,Y,fe,he;const d=me(),{convert:u}=V(),[m,x]=f.useState(""),[g,b]=f.useState(!1),[w,y]=f.useState(null),[j,h]=f.useState(""),[v,$]=f.useState(!1),k=f.useMemo(()=>ks(e,n),[e,n]),[_,S]=f.useState(new Map),z=!!o&&k.rows.length>0&&k.rows.length<=Zx,N=z&&(k.rows.length<=Yt||v),R=N&&k.rows.every(W=>!W.id||_.has(W.id)),C=W=>{var ae;return ji(W?(ae=_.get(W))==null?void 0:ae.l1:void 0)},H=f.useMemo(()=>{const W=m.trim(),ae=W?u(W):"";return k.rows.filter(J=>{var xe,je;if(j&&ji(J.id?(xe=_.get(J.id))==null?void 0:xe.l1:void 0)!==j)return!1;if(!ae)return!0;const O=J.id&&((je=_.get(J.id))==null?void 0:je.title)||J.title;return u(O).includes(ae)||(J.subItems||[]).some(Se=>u(Se).includes(ae))})},[k.rows,m,j,_,u]),L=g?H:H.slice(0,Yt),M=f.useMemo(()=>(N?k.rows:L).filter(W=>W.id&&!_.has(W.id)).map(W=>W.id),[N,k.rows,L,_]);f.useEffect(()=>{if(!o||M.length===0)return;let W=!1;const ae=M.slice(0,Xx);return Promise.all(ae.map(J=>o.getItem(J).then(O=>{var Se,ne;const xe=O??{},je={title:xe.title,edition:xe.edition,authors:xe.authors,measure:O?pt(O,d.unit.juan):void 0,versionCount:xe._edition_count??((Se=xe.books)==null?void 0:Se.length),l1:((ne=xe.classification)==null?void 0:ne.l1)||void 0};return[J,je]}).catch(()=>[J,{}]))).then(J=>{W||S(O=>{const xe=new Map(O);for(const[je,Se]of J)xe.set(je,Se);return xe})}),()=>{W=!0}},[o,M,d.unit.juan]);const F=(e.contained_in||[])[0];f.useEffect(()=>{if(!F){y(null);return}if(y({id:F}),!o)return;let W=!1;return o.getItem(F).then(ae=>{W||y({id:F,title:ae==null?void 0:ae.title})}).catch(()=>{}),()=>{W=!0}},[o,F]);const X=f.useMemo(()=>Tl(e.resources,e.resource_groups),[e.resources,e.resource_groups]),U=X.text.length+X.groups.reduce((W,ae)=>W+ae.rows.length+ae.mirrors.length,0),T=e.contained_works||[],ce=new Set(k.rows.map(W=>W.id).filter(Boolean)),B=T.length>0&&!T.every(W=>ce.has(W.id)),D=(()=>{const W=k.rows.map(ae=>ae.edition).filter(Boolean);return W.length>1&&new Set(W).size===1})(),A=k.rows.some(W=>W.volumes.length>0||W.expected!=null),ee=e._member_count||((ye=e.books)==null?void 0:ye.length)||T.length,de=pt(e,d.unit.juan),G=e.count,q=W=>typeof W=="number"&&Number.isFinite(W)?W:null,ie=q(G==null?void 0:G.juan)??q((be=e.juan_count)==null?void 0:be.number),pe=q(G==null?void 0:G.ce)??(k.totalVolumes||null),ge=[{value:k.rows.length,label:"子目"},{value:ie??0,label:d.unit.juan},{value:pe??0,label:d.unit.volume}],Ee=f.useMemo(()=>{var J,O;const W=[];if((J=e.publication_info)!=null&&J.details&&W.push({label:"刊印",value:u(e.publication_info.details)}),ee&&ee!==k.rows.length){const xe=e._member_type==="Book"?"所收版本":e._member_type==="Work"?"所收作品":"成員";W.push({label:u(xe),value:`${ee} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")})}const ae=[q(G==null?void 0:G.zhong)!=null?`${G.zhong} 種`:"",q(G==null?void 0:G.han)!=null?`${G.han} 函`:""].filter(Boolean);return ae.length&&W.push({label:"應收",value:u(ae.join(" "))}),ie==null&&de&&W.push({label:"卷帙",value:u(de),title:(O=e.juan_count)!=null&&O.description?u(e.juan_count.description):void 0}),W},[e,ee,k.rows.length,ie,de,G,u,d]),Ne=f.useMemo(()=>{if(!R)return[];const W=new Map;for(const J of k.rows){const O=C(J.id);O&&W.set(O,(W.get(O)??0)+1)}const ae=Xt.filter(J=>(W.get(J.key)??0)>0);return ae.length<2?[]:[{key:"",label:`${d.catalog.all} ${k.rows.length}`},...ae.map(J=>({key:J.key,label:`${J.label} ${W.get(J.key)}`}))]},[R,k.rows,_,d]),ze=f.useMemo(()=>{if(!R||!k.rows.some(O=>O.volumes.length>0))return null;const W=[],ae=k.rows.filter(O=>O.volumes.length>0).map(O=>({k:C(O.id)??"",from:Math.min(...O.volumes),to:Math.max(...O.volumes)})).sort((O,xe)=>O.from-xe.from);for(const O of ae){const xe=O.to-O.from+1,je=W[W.length-1];je&&je.key===O.k?(je.to=Math.max(je.to,O.to),je.n+=xe):W.push({key:O.k,from:O.from,to:O.to,n:xe})}const J=ae.reduce((O,xe)=>Math.max(O,xe.to),0);return W.length>1&&W.some(O=>O.key)?{segs:W,last:J}:null},[R,k.rows,_]),Te=(K=e.description)==null?void 0:K.text,Ce=t.jsx(on,{kind:"叢編",title:u(e.title),byline:t.jsx(oo,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(De,{items:[e.subtype==="work_collection"?u("作品集"):"",(I=e.publication_info)!=null&&I.year?u(e.publication_info.year):""]}),description:Te||(Y=e.history)!=null&&Y.length?t.jsxs(t.Fragment,{children:[Te&&t.jsx(dt,{text:Te,style:{fontSize:15,lineHeight:1.85}}),(fe=e.history)!=null&&fe.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((W,ae)=>t.jsx("li",{children:u(W)},ae))}):null]}):void 0,clampDescription:Mi(Te)||(((he=e.history)==null?void 0:he.length)??0)>2?6:void 0,stats:ge,facts:Ee,foot:t.jsx(rn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ze&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:u("全帙冊次分佈")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":u("全帙冊次分佈"),children:ze.segs.map((W,ae)=>{const J=Xt.find(O=>O.key===W.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!J,title:J?u(`${J.label} 第 ${W.from}–${W.to} 冊`):void 0,"aria-label":u(J?`只看${J.label}`:"未分類"),"aria-pressed":!!J&&j===W.key,style:{flexGrow:W.n,background:i(J?J.token:"rule")},onClick:()=>{J&&(h(j===W.key?"":W.key),b(!1))}},ae)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:u(`第 1 ${d.unit.volume}`)}),t.jsx("span",{children:u("點色段篩選部類")}),t.jsx("span",{children:u(`第 ${ze.last} ${d.unit.volume}`)})]})]})}),Ae=[];k.rows.length&&Ae.push({id:"titles",label:"子目",count:k.rows.length}),U&&Ae.push({id:"resources",label:"影印與全文",count:U}),B&&Ae.push({id:"works",label:d.section.containedWorks,count:T.length});const P=t.jsxs(t.Fragment,{children:[k.rows.length>0&&t.jsxs(He,{id:"titles",title:"子目",meta:t.jsx(De,{items:[u(`${k.rows.length} ${d.unit.items}`),k.totalVolumes?u(`全帙 ${k.totalVolumes} ${d.unit.volume}`):"",H.length!==k.rows.length?u(`當前 ${H.length} ${d.unit.items}`):""]}),action:l,children:[(k.rows.length>Yt||Ne.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[Ne.length>0&&t.jsx(Ln,{items:Ne,value:j,onChange:W=>{h(W),b(!1)}}),z&&k.rows.length>Yt&&!R&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:v,onClick:()=>$(!0),title:u(`將載入全部 ${k.rows.length} ${d.unit.items}`),children:u(v?"正在按部類分組…":"按部類分組")}),t.jsx("span",{className:"bim-d-spacer"}),k.rows.length>Yt&&t.jsx("input",{type:"search",className:"bim-d-find",value:m,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:W=>{x(W.target.value),b(!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:L.map((W,ae)=>{var we;const J=W.id?_.get(W.id):void 0,O=J!=null&&J.title&&W.title===W.id?J.title:W.title,xe=((J==null?void 0:J.authors)||[]).find(E=>E&&E.name),je=[xe?`${xe.dynasty?`〔${u(xe.dynasty)}〕`:""}${u(xe.name)}${xe.role?` ${u(xe.role)}`:""}`:"",J!=null&&J.measure?u(J.measure):"",(we=W.subItems)!=null&&we.length?W.subItems.map(E=>u(E)).join("、"):"",(J!=null&&J.edition||W.edition)&&!D?u((J==null?void 0:J.edition)||W.edition||""):""].filter(Boolean),Se=Xt.find(E=>E.key===C(W.id)),ne=W.volumes.length>0?u(`第 ${Nn(W.volumes,d.unit.volume)} ${d.unit.volume}`):W.expected!=null?u(`${W.found??0}/${W.expected} ${d.unit.volume}`):"";return t.jsxs("tr",{children:[A&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ne?"":" bim-d-zt-blank"}`,children:[Se&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:i(Se.token)}}),ne||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[W.id?t.jsx(Me,{id:W.id,label:u(O),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(O)}),je.length>0?t.jsx(De,{items:je}):W.id&&!J&&o?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${J!=null&&J.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:J!=null&&J.versionCount?u(`${J.versionCount} 種`):""})]},`${W.id??W.title}-${ae}`)})})]}),L.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),H.length>L.length&&t.jsx(Mt,{label:`展開其餘 ${H.length-L.length} ${d.unit.items}`,onClick:()=>b(!0)})]}),U>0&&t.jsxs(He,{id:"resources",title:"影印與全文",meta:u(`${U} 處`),children:[X.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[X.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:X.text.map((W,ae)=>t.jsx(ro,{item:W,siblings:X.text},`${W.id||W.url||W.name}-${ae}`))})})]}),t.jsx(El,{groups:X.groups})]}),k.rows.length===0&&U===0&&t.jsx(He,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),se=B?t.jsx(yt,{id:"works",title:d.section.containedWorks,meta:u(`${T.length} 種`),cap:12,items:T.map(W=>t.jsx(Me,{id:W.id,label:u(W.title),onNavigate:r,renderLink:s,dense:!0}))}):null,re=w?t.jsx(Ts,{caption:"上級叢編",children:t.jsx(Me,{id:w.id,label:u(w.title||w.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(nn,{railTop:c,back:p,up:re,nav:Ae,railLinks:a,main:P,card:Ce,side:se})},Qx=16,Qn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Or(e){if(!e)return Qn.length;const n=Qn.indexOf(e);return n===-1?Qn.length:n}const ef={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function mt(e){return e==null?"":e<0?`前${-e}`:String(e)}const tf={秦:[-221,-207],西漢:[-202,8],西汉:[-202,8],東漢:[25,220],东汉:[25,220],漢:[-202,220],汉:[-202,220],三國:[220,280],三国:[220,280],西晉:[265,316],西晋:[265,316],東晉:[317,420],东晋:[317,420],隋:[581,618],唐:[618,907],五代:[907,960],北宋:[960,1127],南宋:[1127,1279],宋:[960,1279],遼:[916,1125],辽:[916,1125],金:[1115,1234],元:[1271,1368],明:[1368,1644],清:[1636,1912]},Ml=({data:e,transport:n,onNavigate:o,renderLink:r,railTop:s,back:l,railLinks:c})=>{var se,re,ye,be,K;const p=me(),{convert:a}=V(),[d,u]=f.useState("全部"),[m,x]=f.useState(!1),[g,b]=f.useState("default"),[w,y]=f.useState(new Map),j=f.useMemo(()=>(e.works||[]).map(I=>{const Y=w.get(I.work_id);return{id:I.work_id,title:(Y==null?void 0:Y.title)??I.title??I.work_id,role:I.role||"",cls:Ai(I.role),versionCount:Y==null?void 0:Y.versionCount,section:Y==null?void 0:Y.cls,l1:Y==null?void 0:Y.l1,measure:Y==null?void 0:Y.measure,hasImage:Y==null?void 0:Y.hasImage,loaded:!!(Y!=null&&Y.loaded)}}),[e.works,w]),h=f.useMemo(()=>vs((e.works||[]).map(I=>I.role)),[e.works]),v=f.useMemo(()=>{const I=d==="全部"?j:j.filter(Y=>Y.cls===d);return g==="versions"?[...I].sort((Y,fe)=>(fe.versionCount??-1)-(Y.versionCount??-1)):I},[j,d,g]),$=m?v:v.slice(0,Qx),k=f.useMemo(()=>$.filter(I=>!w.has(I.id)).map(I=>I.id),[$,w]);f.useEffect(()=>{if(!n||k.length===0)return;let I=!1;return Promise.all(k.map(Y=>n.getItem(Y).then(fe=>{var J,O,xe,je,Se;const he=fe??{},W=he._edition_count??(((J=he.books)==null?void 0:J.length)??0)+(((O=he.collections)==null?void 0:O.length)??0),ae=[(xe=he.classification)==null?void 0:xe.l1,(je=he.classification)==null?void 0:je.l2].filter(Boolean).join(" ");return[Y,{id:Y,title:he.title,versionCount:W,loaded:!0,cls:ae||void 0,l1:((Se=he.classification)==null?void 0:Se.l1)||void 0,measure:fe&&pt(fe,p.unit.juan)||void 0,hasImage:!!(he.has_image??he._has_image)}]}).catch(()=>[Y,{id:Y,loaded:!0}]))).then(Y=>{I||y(fe=>{const he=new Map(fe);for(const[W,ae]of Y)he.set(W,ae);return he})}),()=>{I=!0}},[n,k,p.unit.juan]);const _=f.useMemo(()=>{const I=new Map;for(const Y of e.alt_names||[]){const fe=Y.type||p.section.aliases;I.has(fe)||I.set(fe,[]),I.get(fe).push(Y.name)}return[...I.entries()].sort((Y,fe)=>Or(Y[0])-Or(fe[0])).map(([Y,fe])=>({label:Y,names:fe}))},[e.alt_names,p]),S=e.birth_year??((se=e.dates)==null?void 0:se.birth)??void 0,z=e.death_year??((re=e.dates)==null?void 0:re.death)??void 0,N=(ye=e.dates)==null?void 0:ye.floruit,R=S!=null||z!=null?`${mt(S)||"?"}—${mt(z)||"?"}`:Array.isArray(N)&&N.length===2&&N.every(I=>Number.isFinite(I))?`活躍於 ${mt(N[0])}—${mt(N[1])}`:"",C=new Set(["本名","字","號","号"]),H=_.filter(I=>C.has(I.label)),L=_.filter(I=>!C.has(I.label)),M=L.reduce((I,Y)=>I+Y.names.length,0),F=f.useMemo(()=>{const I=[];for(const fe of H)I.push({label:fe.label,value:fe.names.map(he=>a(he)).join("、")});const Y=(e.works||[]).length;return Y&&I.push({label:"著作",value:`${Y} ${a("種")}`}),I},[e.works,H,a]),X=I=>{var Y;return(Y=_.find(fe=>I.includes(fe.label)))==null?void 0:Y.names[0]},U=X(["字"]),T=X(["號","号"]),ce=[U?`字${U}`:"",T?`號${T}`:""].filter(Boolean).join(","),B=e.native_place,D=e.dynasty?tf[e.dynasty]:void 0,A=(()=>{if(!D||S==null||z==null||z<S)return null;const[I,Y]=D,fe=Math.max(S,I),he=Math.min(z,Y);if(he<=fe)return null;const W=Y-I;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":a(`${mt(S)}—${mt(z)},一生 ${z-S+1} 年`),children:t.jsx("i",{style:{left:`${(fe-I)/W*100}%`,width:`${(he-fe)/W*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:a(`${mt(I)} ${e.dynasty}`)}),t.jsx("span",{children:a(`一生 ${z-S+1} 年`)}),t.jsx("span",{children:mt(Y)})]})]})})(),ee=f.useMemo(()=>{if(!n||j.length===0||j.some(fe=>!fe.loaded))return null;const I=new Map;for(const fe of j){const he=ji(fe.l1);he&&I.set(he,(I.get(he)??0)+1)}const Y=Xt.map(fe=>({...fe,n:I.get(fe.key)??0})).filter(fe=>fe.n>0);return Y.length?Y:null},[j,n]),de=t.jsxs(on,{kind:ef[e.subtype]??"人物",title:a(e.primary_name||e.title),subtitle:ce?a(ce):void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(De,{items:[e.dynasty?a(e.dynasty):"",R?a(R):"",B?a(`${B}人`):""]}),A]}),description:(be=e.description)!=null&&be.text?t.jsx(dt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Mi((K=e.description)==null?void 0:K.text)?6:void 0,facts:F,foot:t.jsx(rn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[M>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:a(`更多別名(${M})`)}),t.jsx("dl",{children:L.map(I=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:a(I.label)}),t.jsx("dd",{children:I.names.map(Y=>a(Y)).join("、")})]},I.label))})]}),ee&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:a("著作分佈")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:ee.map(I=>t.jsx("i",{style:{flexGrow:I.n,background:i(I.token)}},I.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ee.map(I=>t.jsxs("span",{children:[t.jsx("i",{style:{background:i(I.token)}}),a(I.label)," ",I.n]},I.key))})]})]}),G=f.useMemo(()=>j.filter(I=>I.loaded&&(I.versionCount??0)>0).sort((I,Y)=>(Y.versionCount??0)-(I.versionCount??0)).slice(0,3),[j]),q=!!n&&j.length>=3&&$.some(I=>!I.loaded),ie=d==="全部"&&(q||G.length>=2),pe=e.external_ids||{},ge=[];pe.cbdb_id!=null&&ge.push({label:"CBDB",id:String(pe.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${pe.cbdb_id}`,note:pe.cbdb_match==="auto"?"自動匹配":void 0});const Ee=pe.wikidata_id;Ee&&ge.push({label:"Wikidata",id:Ee,href:`https://www.wikidata.org/wiki/${Ee}`});const Ne=pe.viaf_id;Ne&&ge.push({label:"VIAF",id:Ne,href:`https://viaf.org/viaf/${Ne}`});const ze=h.map(I=>({key:I.cls,label:`${I.label} ${I.count}`})),Te=[...ie&&!q?[{id:"featured",label:"著作舉要",count:G.length}]:[],...j.length?[{id:"works",label:"全部著作",count:j.length}]:[],...ge.length?[{id:"external",label:"站外資料",count:ge.length}]:[]],Ce=ie?t.jsxs(He,{id:"featured",title:"著作舉要",children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:a("存世版本最多的三部")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":q||void 0,children:[q&&[0,1,2].map(I=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},I)),!q&&G.map(I=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Me,{id:I.id,label:a(I.title),onNavigate:o,renderLink:r,dense:!0})}),t.jsx(De,{items:[I.section?a(I.section):"",I.measure?a(I.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:I.versionCount}),t.jsx("span",{children:a("種版本")}),I.hasImage&&t.jsx("span",{className:"bim-d-flag",children:a("有影印")})]})]},I.id))]})]}):null,Ae=j.length===0?t.jsx(He,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該人物的關聯作品。")})}):t.jsxs(t.Fragment,{children:[Ce,t.jsxs(He,{id:"works",title:"著作",meta:t.jsx(De,{items:[a(`共 ${j.length} 種`),v.length!==j.length?a(`當前 ${v.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ze.length>1&&t.jsx(Ln,{items:ze,value:d,onChange:I=>{u(I),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":g==="versions",onClick:()=>{g==="default"&&x(!0),b(I=>I==="default"?"versions":"default")},children:a(g==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("作品")}),t.jsx("th",{children:a("部類")}),t.jsx("th",{children:a("職任")}),t.jsx("th",{children:a("存世版本")}),t.jsx("th",{"aria-label":a("影印")})]})}),t.jsx("tbody",{children:$.map(I=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Me,{id:I.id,label:a(I.title),onNavigate:o,renderLink:r,dense:!0}),I.measure?t.jsx(De,{items:[a(I.measure)]}):!I.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.section||I.loaded?"":" bim-d-zt-blank"}`,children:I.section?a(I.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.role?"":" bim-d-zt-blank"}`,children:I.role?a(I.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.loaded?"":" bim-d-zt-blank"}`,children:I.loaded?I.versionCount?a(`${I.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:a("未著錄")}):""}),t.jsx("td",{className:I.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:I.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:a("有影印")})})]},I.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a("該職任下的著作尚未著錄。")}),v.length>$.length&&t.jsx(Mt,{label:`展開其餘 ${v.length-$.length} 種著作`,onClick:()=>x(!0)})]})]}),P=ge.length>0?t.jsx(yt,{id:"external",title:"站外資料",items:ge.map(I=>t.jsxs("a",{href:I.href,target:"_blank",rel:"noopener noreferrer",children:[I.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:ge.map(I=>I.id),foot:pe.cbdb_id!=null&&pe.cbdb_match==="auto"?a("CBDB 為自動匹配,未經人工核對"):void 0}):null;return t.jsx(nn,{railTop:s,back:l,nav:Te,railLinks:c,main:Ae,card:de,side:P})},lo="(max-width: 719px)",nf=`${lo}, (pointer: coarse)`,Fl=`
889
1018
  .bim-ct {
890
1019
  display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
891
1020
  max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
@@ -993,7 +1122,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
993
1122
  .bim-ct-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
994
1123
  }
995
1124
 
996
- @media ${Ki} {
1125
+ @media ${lo} {
997
1126
  .bim-ct { display: block; padding: 12px 16px 40px; }
998
1127
  .bim-ct-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
999
1128
  .bim-ct-lrow > a { grid-template-columns: minmax(0, 1fr); }
@@ -1018,7 +1147,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
1018
1147
  }
1019
1148
 
1020
1149
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
1021
- @media ${cx} {
1150
+ @media ${nf} {
1022
1151
  .bim-ct-row { min-height: 44px; }
1023
1152
  .bim-ct-tw { width: 44px; }
1024
1153
  .bim-ct-pg { min-width: 44px; height: 44px; }
@@ -1028,4 +1157,4 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
1028
1157
  :root[data-layout="boxed"] .bim-ct-side { border: ${i("fr-bd")}; background: ${i("fr-bg")}; padding: 14px 8px; }
1029
1158
  :root[data-layout="boxed"] .bim-ct-head { padding: ${i("fr-hd-pad")}; border: ${i("fr-bd")}; border-bottom: ${i("fr-hd-bd")}; background: ${i("fr-bg")}; margin: 0; }
1030
1159
  :root[data-layout="boxed"] .bim-ct-main > .bim-ct-search { margin-top: 14px; }
1031
- `,qt="未分類",rt="all",qi=20;function nn(e){if(!e)return[];const n=[];for(const o of[e.l1,e.l2,e.l3,e.l4]){const r=(o??"").trim();if(!r)break;n.push(r)}return n}function dx(e){const n=nn(e);return n.length?n.join("/"):qt}function px(e){const n=nn(e);return n.length?n.map((o,r)=>n.slice(0,r+1).join("/")):[qt]}function ux(e,n=[]){const o=new Map;n.forEach((p,c)=>{const a=[p.cata_l1,p.cata_l2,p.cata_l3,p.cata_l4].filter(u=>!!u);a.forEach((u,f)=>{const x=a.slice(0,f+1).join("/");o.has(x)||o.set(x,c)})});const r=new Map;let s=0;for(const p of e){const c=nn(p.classification);if(!c.length){s++;continue}let a=r;c.forEach((u,f)=>{const x=c.slice(0,f+1).join("/");let m=a.get(u);m||(m={id:x,label:u,count:0,children:new Map},a.set(u,m)),m.count++,a=m.children})}const l=p=>[...p.values()].sort((c,a)=>{const u=o.get(c.id)??1/0,f=o.get(a.id)??1/0;return u!==f?u-f:c.label.localeCompare(a.label,"zh")}).map(c=>{const a={id:c.id,label:c.label,count:c.count};return c.children.size&&(a.children=l(c.children)),a}),d=l(r);return s>0&&d.push({id:qt,label:qt,count:s}),d}function zt(e,n){if(!n)return[];for(const o of e){if(o.id===n)return[o];if(o.children){const r=zt(o.children,n);if(r.length)return[o,...r]}}return[]}function Ji(e){return e.reduce((n,o)=>n+o.count,0)}function xx(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function fx(e){var p;const n={id:e.id,title:e.title||e.id},o=e.juan_count,r=typeof o=="number"?o:o==null?void 0:o.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(c=>c==null?void 0:c.name).map(c=>{const a=c.dynasty||(e.authors.length===1?e.dynasty:void 0);return a?{name:c.name,dynasty:a}:{name:c.name}});s.length&&(n.authors=s);const l=xx(typeof e.description=="string"?e.description:(p=e.description)==null?void 0:p.text);l&&(n.summary=l);const d=nn(e.classification);return d.length&&(n.classification=d),n}function gx(e,n){const o=e.summary?0:1,r=n.summary?0:1;return o!==r?o-r:e.title.localeCompare(n.title,"zh")}function mx(e,n=qi){return Math.max(1,Math.ceil(e/n))}function xl(e,n,o=2){if(n<=1)return[1];const r=new Set([1,n]);for(let d=e-o;d<=e+o;d++)d>=1&&d<=n&&r.add(d);const s=[...r].sort((d,p)=>d-p),l=[];return s.forEach((d,p)=>{if(p>0){const c=d-s[p-1];c===2?l.push(d-1):c>2&&l.push(null)}l.push(d)}),l}const hx=()=>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 bx(e,n,o){const r=[];o&&r.push({id:rt,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,d)=>{var p;for(const c of l){const a=(p=c.children)!=null&&p.length?c.children:null;r.push({id:c.id,parentId:d,hasChildren:!!a,firstChildId:a?a[0].id:null}),a&&n.has(c.id)&&s(a,c.id)}};return s(e,null),r}function fl({tree:e,selectedId:n,onSelect:o,allLabel:r="全部",label:s="分類"}){const{convert:l}=Z(),d=g.useRef(null),p=n&&n!==rt?n:null,c=r!==null,[a,u]=g.useState(()=>{const v=new Set;for(const _ of zt(e,p))v.add(_.id);return v});g.useEffect(()=>{const v=zt(e,p);v.length&&u(_=>{if(v.every(z=>_.has(z.id)))return _;const S=new Set(_);for(const z of v)S.add(z.id);return S})},[e,p]);const f=g.useMemo(()=>bx(e,a,c),[e,a,c]),[x,m]=g.useState(null);g.useEffect(()=>{m(null)},[n]);const j=p??(c?rt:null),w=g.useMemo(()=>{var S;const v=new Set(f.map(z=>z.id));if(x&&v.has(x))return x;if(j&&v.has(j))return j;const _=zt(e,p).map(z=>z.id).filter(z=>v.has(z));return _.length?_[_.length-1]:((S=f[0])==null?void 0:S.id)??null},[f,x,j,e,p]),h=g.useCallback((v,_)=>{u(S=>{const z=S.has(v),N=_??!z;if(N===z)return S;const T=new Set(S);return N?T.add(v):T.delete(v),T})},[]),b=g.useCallback(v=>{m(v),requestAnimationFrame(()=>{var S;const _=Array.from(((S=d.current)==null?void 0:S.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===v);_==null||_.focus()})},[]),y=g.useCallback((v,_)=>{_&&h(v,!0),o(v)},[o,h]),k=g.useCallback(v=>{const _=v.target.closest("[data-ct-id]");if(!_)return;const S=_.dataset.ctId,z=f.findIndex(C=>C.id===S);if(z<0)return;const N=f[z];let T=null;switch(v.key){case"ArrowDown":T=f[Math.min(f.length-1,z+1)].id;break;case"ArrowUp":T=f[Math.max(0,z-1)].id;break;case"Home":T=f[0].id;break;case"End":T=f[f.length-1].id;break;case"ArrowRight":if(!N.hasChildren)break;a.has(S)?T=N.firstChildId:h(S,!0);break;case"ArrowLeft":N.hasChildren&&a.has(S)?h(S,!1):T=N.parentId;break;case"Enter":case" ":v.preventDefault(),y(S,N.hasChildren);return;default:return}v.preventDefault(),T&&T!==S&&b(T)},[f,a,h,b,y]),$=(v,_)=>v.map((S,z)=>{var B;const N=(B=S.children)!=null&&B.length?S.children:null,T=!!N&&a.has(S.id),C=S.id===p,D=_===1&&v.length>1&&z===v.length-1;return t.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":N?T:void 0,"aria-selected":C,tabIndex:w===S.id?0:-1,"data-ct-id":S.id,className:D?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{m(S.id),y(S.id,!!N)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:N?O=>{O.stopPropagation(),m(S.id),h(S.id)}:void 0,children:N?t.jsx(hx,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(S.label)}),t.jsx("span",{className:"bim-ct-n",children:S.count.toLocaleString("en-US")})]}),T&&t.jsx("ul",{role:"group",children:$(N,_+1)})]},S.id)});return t.jsxs("ul",{ref:d,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:k,children:[c&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:w===rt?0:-1,"data-ct-id":rt,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{m(rt),o(rt)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),t.jsx("span",{className:"bim-ct-lb",children:l(r)}),t.jsx("span",{className:"bim-ct-n",children:Ji(e).toLocaleString("en-US")})]})}),$(e,1)]})}const gl=e=>`/item/${encodeURIComponent(e)}`;function yx(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function ml(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function hl({work:e,href:n}){var d,p;const{convert:o}=Z(),r=ml(e.juan),s=((d=e.authors)==null?void 0:d.filter(c=>c.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:n,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:o(e.title)}),r&&t.jsx("span",{className:"bim-ct-juan",children:o(r)})]}),s.length>0&&t.jsx("span",{className:"bim-ct-by",children:s.map((c,a)=>t.jsxs(g.Fragment,{children:[a>0&&"、",c.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(c.dynasty),"〕"]}),o(c.name)]},a))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:o(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(c=>o(c)).join(" · ")})]})})}function bl({work:e,href:n}){var d,p;const{convert:o}=Z(),r=ml(e.juan),s=((d=e.authors)==null?void 0:d.filter(c=>c.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-lrow",children:t.jsxs("a",{href:n,children:[t.jsxs("span",{className:"bim-ct-lt",children:[o(e.title),r&&t.jsx("span",{className:"bim-ct-juan",children:o(r)})]}),t.jsx("span",{className:"bim-ct-by",children:s.map((c,a)=>t.jsxs(g.Fragment,{children:[a>0&&"、",c.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(c.dynasty),"〕"]}),o(c.name)]},a))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(c=>o(c)).join(" · ")})]})})}function yl({page:e,pageCount:n,onPage:o,pageHref:r,label:s="分頁"}){const{convert:l}=Z();if(n<=1)return null;const d=c=>a=>{o&&(r&&!yx(a)||(a.preventDefault(),o(c)))},p=(c,a,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:a});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(c),onClick:d(c),children:a}):t.jsx("button",{type:"button",...f,onClick:u.current?void 0:d(c),children:a})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:xl(e,n).map((c,a)=>t.jsx("li",{style:{display:"contents"},children:c===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(c,c,{current:c===e,aria:l(`第 ${c} 頁`)})},c??`gap${a}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),p(e+1,l("下一頁"),{disabled:e>=n})]})}function jl({works:e,workLink:n=gl,emptyText:o="此類暫無作品",view:r="card",...s}){const{convert:l}=Z();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:typeof o=="string"?l(o):o}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(d=>t.jsx(bl,{work:d,href:n(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(hl,{work:d,href:n(d.id)},d.id))}),t.jsx(yl,{...s})]})}const jx=()=>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 vx({tree:e,selectedId:n,page:o,pageCount:r,works:s,onSelect:l,onPage:d,searchSlot:p,workLink:c,pageHref:a,allLabel:u="全部",allTitle:f="全部典籍",pageSize:x=qi,className:m,view:j,onViewChange:w}){const{convert:h}=Z(),y=`bim-ct-drawer-${g.useId().replace(/:/g,"")}`,[k,$]=g.useState(!1),[v,_]=g.useState("card"),S=j??v,z=O=>{_(O),w==null||w(O)},N=zt(e,n&&n!==rt?n:null),T=N.length?N[N.length-1]:null,C=T?T.label:f,D=T?T.count:Ji(e),B=g.useCallback(O=>{$(!1),l(O)},[l]);return t.jsxs("div",{className:m?`bim-ct ${m}`:"bim-ct","data-drawer":k?"open":"closed",children:[t.jsx("style",{children:ul}),t.jsxs("aside",{className:"bim-ct-side","aria-label":h("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":k,"aria-controls":y,onClick:()=>$(O=>!O),children:[t.jsxs("span",{children:[h("分類"),":",h(N.length?N.map(O=>O.label).join(" › "):u??f)]}),t.jsx(jx,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:y,children:[t.jsx("h2",{className:"bim-ct-side-h",children:h("分類")}),t.jsx(fl,{tree:e,selectedId:n,onSelect:B,allLabel:u})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:h(C)}),N.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:h(N.slice(0,-1).map(O=>O.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[h(`共 ${D.toLocaleString("en-US")} 種 · 每頁 ${x} 條`),r>1&&h(` · 第 ${o} / ${r} 頁`)]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":h("呈現方式"),children:[t.jsx("button",{type:"button","aria-pressed":S==="card",onClick:()=>z("card"),children:h("卡片")}),t.jsx("button",{type:"button","aria-pressed":S==="list",onClick:()=>z("list"),children:h("列表")})]})]}),p&&t.jsx("div",{className:"bim-ct-search",children:p}),t.jsx(jl,{works:s,view:S,workLink:c,page:o,pageCount:r,onPage:d,pageHref:a})]})]})}const pi=({style:e})=>{const n=g.useContext(Rt);if(!n)return null;const{locale:o,setLocale:r}=n,s=o==="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 ${i("border")}`,borderRadius:"4px",background:i("bg"),color:i("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:s?i("primary"):void 0,fontWeight:s?700:400},children:"繁"}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:s?void 0:i("primary"),fontWeight:s?400:700},children:"简"})]})},ui=({href:e,label:n="在 GitHub 查看本条目源文件",size:o=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:o+8,height:o+8,borderRadius:4,color:i("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:l=>{l.currentTarget.style.color=i("fg")},onMouseLeave:l=>{l.currentTarget.style.color=i("desc-fg")},children:t.jsx("svg",{width:o,height:o,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 Gn(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function kx(e,n){if(!n)return!1;const o=n.id;return o===void 0||o===e}const wx=({id:e,transport:n,initialDetail:o,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:d,onJuanChange:p,lineageMode:c="list",onLineageModeChange:a,lineageCollection:u,onLineageCollectionChange:f,initialPage:x=1,selectedLineageNodeId:m,onNavigate:j,onBack:w,backLabel:h,renderLink:b,enrichDetail:y,getSourceLink:k,readLink:$,railTop:v,extraTabs:_=[],showFeedbackTab:S=!0,feedbackApiUrl:z,height:N,footerExtra:T,className:C,style:D})=>{var eo;const B=ue(),{convert:O}=Z(),[M]=g.useState(()=>{if(!kx(e,o))return null;const J={...o},ve=r??Gn(e,J);return y&&y(ve,J),{id:e,entry:ve,detail:J}}),[X,Y]=g.useState((M==null?void 0:M.entry)??null),[E,ee]=g.useState((M==null?void 0:M.detail)??null),[F,K]=g.useState(!M),[ae,ne]=g.useState(!1),[Q,ie]=g.useState([]),[ge,re]=g.useState(!1),[le,pe]=g.useState(null),[Re,$e]=g.useState(!1),[ye,Se]=g.useState(null),[Ne,je]=g.useState(!1),[H,ce]=g.useState(null),[oe,he]=g.useState([]),[me,U]=g.useState(!1),[R,V]=g.useState(null),[W,A]=g.useState(null),[I,G]=g.useState(!1),P=g.useRef(null),[q,se]=g.useState(null),ke=d!==void 0?d:q,be=g.useCallback(J=>{p?p(J):se(J)},[p]),Le=g.useCallback(async J=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){ie([]);return}re(!0);try{if(n.getCollectionCatalogs)ie(await n.getCollectionCatalogs(J)||[]);else if(n.getCollectionCatalog){const ve=await n.getCollectionCatalog(J);ie(ve?[{resource_id:"",data:ve}]:[])}}catch{ie([])}finally{re(!1)}},[n]),Ke=g.useCallback(async J=>{if(!n.getCollatedEditionIndex){pe(null);return}$e(!0);try{pe(await n.getCollatedEditionIndex(J))}catch{pe(null)}finally{$e(!1)}},[n]),L=g.useCallback(async J=>{if(!n.getBookFullTextIndex){Se(null);return}je(!0);try{Se(await n.getBookFullTextIndex(J))}catch{Se(null)}finally{je(!1),ce(J)}},[n]),de=g.useCallback(async J=>{var ve;if(!n.getWorkFullTextList){he([]);return}U(!0);try{const Ie=(await n.getWorkFullTextList(J)??[]).filter(Ae=>Ae.owner_type!=="Book");he(Ie),V(((ve=Ie.find(Ae=>Ae.primary)??Ie[0])==null?void 0:ve.key)??null)}catch{he([])}finally{U(!1)}},[n]),fe=g.useCallback(async(J,ve)=>{G(!0);try{if(n.getLineageGraph){const De=await n.getLineageGraph(J);De&&A(De)}const Ie=ve.version_graph;if(!Ie||!Ie.enabled){W||A(null),P.current=null;return}const Ae=ve.books??[],Qe=[];for(const De of Ae)try{const et=await n.getItem(De);et&&Qe.push(et)}catch{}P.current={work:ve,books:Qe};const te=u??Ie.default_collection??(Ie.core_books&&Ie.core_books.length>0?"core":"all"),Te=te==="core"&&Array.isArray(Ie.core_books)&&Ie.core_books.length>0?"core":te??"all";A(fn(ve,Qe,Te))}catch{A(null),P.current=null}finally{G(!1)}},[n]),ze=g.useRef({initialDetail:o,initialEntry:r});ze.current={initialDetail:o,initialEntry:r},g.useEffect(()=>{let J=!1;const ve=te=>{te.type==="collection"?Le(e):te.type==="work"?(te.has_collated&&Ke(e),(te.version_graph||n.getLineageGraph)&&fe(e,te),n.getWorkFullTextList&&de(e)):te.type==="book"&&te.has_full_text&&n.getBookFullTextIndex&&L(e)},Ie=ze.current;let Ae=null;if(M&&M.id===e)Ae=M;else if(Ie.initialDetail&&Ie.initialDetail.id===e){const te={...Ie.initialDetail},Te=Ie.initialEntry??Gn(e,te);y&&y(Te,te),Ae={entry:Te,detail:te}}return Ae?(ne(!1),ie(te=>te.length?[]:te),pe(null),Se(null),he(te=>te.length?[]:te),V(null),A(null),P.current=null,Y(Ae.entry),ee(Ae.detail),K(!1),ve(Ae.detail),()=>{J=!0}):((async()=>{K(!0),ne(!1),Y(null),ee(null),ie([]),pe(null),Se(null),he([]),V(null),A(null),P.current=null;try{const te=await n.getItem(e);if(J)return;if(!te){ne(!0);return}const Te=te;let De=null;if(n.getEntry&&(De=await n.getEntry(e),J))return;De||(De=Gn(e,Te)),y&&y(De,Te),Y(De),ee(Te),ve(Te)}catch{J||ne(!0)}finally{J||K(!1)}})(),()=>{J=!0})},[e,n,M,y,Le,Ke,fe,L,de]),g.useEffect(()=>{const J=P.current;!J||!u||A(fn(J.work,J.books,u))},[u]);const xe=[];if(E){if(xe.push({key:"basic",label:B.detailTab.basicInfo}),E.type==="collection"){ge&&Q.length===0&&xe.push({key:"catalog:loading",label:`${B.detailTab.catalog}…`});for(const J of Q)xe.push({key:`catalog:${J.resource_id}`,label:J.short_name?`${O(J.short_name)}${B.detailTab.catalogSuffix}`:B.detailTab.collectionCatalog})}E.type==="work"&&(le||Re)&&s==="collated"&&xe.push({key:"collated",label:Re?`${B.detailTab.collatedEdition}…`:B.detailTab.collatedEdition}),E.type==="book"&&(ye||Ne)&&s==="fulltext"&&xe.push({key:"fulltext",label:Ne?`${B.detailTab.fullText}…`:B.detailTab.fullText}),E.type==="work"&&(oe.length>0||me)&&s==="fulltext"&&xe.push({key:"fulltext",label:me?`${B.detailTab.fullText}…`:B.detailTab.fullText}),E.type==="work"&&(W||I)&&xe.push({key:"lineage",label:I?`${B.detailTab.lineage}…`:B.detailTab.lineage});for(const J of _)(J.position??"before-feedback")==="before-feedback"&&J.shouldShow(E)&&xe.push({key:J.key,label:J.label});S&&s==="feedback"&&xe.push({key:"feedback",label:B.detailTab.feedback});for(const J of _)J.position==="after-feedback"&&J.shouldShow(E)&&xe.push({key:J.key,label:J.label})}g.useEffect(()=>{if(s!=="emendated"||!E)return;l("basic");const J=setTimeout(()=>{var ve;(ve=document.getElementById("studies"))==null||ve.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(J)},[s,E,l]);const Ce=X&&E&&k?k({activeTab:s,activeJuan:ke,entry:X,detail:E}):null,Oe=g.useMemo(()=>{var Qe;if(!E)return null;const ve=(E.authors??[]).map(te=>{const Te=Si(te.role);return`${te.dynasty?`〔${O(te.dynasty)}〕`:""}${O(te.name)}${Te?` ${O(Te)}`:""}`}).join(" · ");let Ie=!1;try{Ie=we.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const te=E;return{title:O(te.title),subtitle:te.edition?O(te.edition):ve||void 0,aside:[Ie?B.status.draft:"",ve&&te.edition?ve:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const te=E;return{title:O(te.title),subtitle:O(at(te,B.unit.juan))||void 0,aside:[(Qe=te.publication_info)==null?void 0:Qe.year,Ie?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:ve||void 0}}if(E.type==="entity"){const te=E,Te=et=>et==null?"":et<0?`前${-et}`:String(et),De=te.birth_year!=null||te.death_year!=null?`${Te(te.birth_year)||"?"}—${Te(te.death_year)||"?"}`:"";return{title:O(te.primary_name||te.title),subtitle:[te.dynasty?`〔${O(te.dynasty)}〕`:"",De].filter(Boolean).join(" ")||void 0,aside:Ie?B.status.draft:void 0,secondLine:void 0}}const Ae=O(at(E,B.unit.juan));return{title:O(E.title),subtitle:[Ae,ve].filter(Boolean).join(" · ")||void 0,aside:[_x(B,E.subtype),Ie?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,O,B]),Ze=E?E.type==="work"?(((eo=le==null?void 0:le.juan_files)==null?void 0:eo.length)??0)>0?"collated":oe.length>0?"fulltext":null:E.type==="book"&&(((ye==null?void 0:ye.chapters.length)??0)>0||E.has_full_text&&n.getBookFullTextIndex&&H!==E.id)?"fulltext":null:null,ct=oe.find(J=>J.primary)??oe[0],on=()=>{var J;Ze==="collated"&&((J=le==null?void 0:le.juan_files)!=null&&J.length)?(be(le.juan_files[0]),l("collated")):Ze==="fulltext"&&((E==null?void 0:E.type)==="work"&&ct&&V(ct.key),be(null),l("fulltext"))};let dt=null;if(E&&$){const J=$({detail:E,kind:Ze,fullTextKey:E.type==="work"?ct==null?void 0:ct.key:void 0});J&&(dt=t.jsx(Xn,{href:J}))}else Ze&&(dt=t.jsx(Xn,{onClick:on}));const rn=J=>{if(!E)return null;const ve=J.replace(/\.[^.]+$/,"");if($){const Ie=$({detail:E,kind:"fulltext",juan:ve});return Ie?{href:Ie}:null}return{onClick:()=>{be(ve),l("fulltext")}}},sn=new Set(_.map(J=>J.key)),_e=xe.filter(J=>J.key.startsWith("catalog:")&&J.key!=="catalog:loading"||sn.has(J.key)).map(J=>({key:J.key,label:J.label,onClick:()=>l(J.key)})),Xe=()=>{var J;return E?E.type==="work"?t.jsx(rl,{data:E,transport:n,onNavigate:j,renderLink:b,readAction:dt,railTop:v,railLinks:_e}):E.type==="book"?t.jsx(cl,{data:E,transport:n,onNavigate:j,renderLink:b,readAction:dt,fullText:ye,fullTextPending:!!E.has_full_text&&!!n.getBookFullTextIndex&&H!==E.id,chapterLink:rn,railTop:v,railLinks:_e}):E.type==="collection"?t.jsx(dl,{data:E,catalog:(J=Q[0])==null?void 0:J.data,transport:n,onNavigate:j,renderLink:b,readAction:dt,railTop:v,railLinks:_e,catalogAction:Q.length>0?t.jsxs("a",{href:"#catalog",onClick:ve=>{ve.preventDefault(),l(`catalog:${Q[0].resource_id}`)},children:[O(B.detailTab.collectionCatalog)," →"]}):null}):t.jsx(pl,{data:E,transport:n,onNavigate:j,renderLink:b,railTop:v,railLinks:_e}):null},Ee=()=>{var ve,Ie,Ae,Qe;if(!X||!E)return null;if(s==="basic"||s==="emendated")return Xe();if(typeof s=="string"&&s.startsWith("catalog:")){const te=(ve=Q.find(Te=>`catalog:${Te.resource_id}`===s))==null?void 0:ve.data;return t.jsx(yi,{data:te,onNavigate:j,renderLink:b})}if(s==="collated")return t.jsx(Hi,{index:le||void 0,workId:e,transport:n,onNavigate:j,activeJuan:ke,onJuanChange:be});if(s==="fulltext"&&E.type==="work"){const te=R??((Ie=oe[0])==null?void 0:Ie.key);return te?t.jsx(si,{bookId:e,workKey:te,versions:oe,onVersionChange:Te=>{V(Te),be(null)},transport:n,activeChapter:ke,onChapterChange:be},te):t.jsx("div",{style:{padding:24,color:i("desc-fg")},children:me?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(si,{index:ye||void 0,bookId:e,transport:n,activeChapter:ke,onChapterChange:be});if(s==="lineage"){if(!W)return t.jsx("div",{style:{color:i("label-fg"),padding:"24px 0"},children:I?"加載中…":"暫無版本圖數據"});const te=E.type==="work"?E:null;return t.jsx(Yi,{graph:W,renderLink:b,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:a,selectedNodeId:m,collection:u??((Ae=te==null?void 0:te.version_graph)==null?void 0:Ae.default_collection),onCollectionChange:f,collectionsAvailable:(Qe=te==null?void 0:te.version_graph)==null?void 0:Qe.collections,collectionCounts:(()=>{var to,no,io,oo,ro,so,lo;if(!te)return;const Te={},De=((to=P.current)==null?void 0:to.books)??[];Te.all=(((no=te.books)==null?void 0:no.length)??0)-(((oo=(io=te.version_graph)==null?void 0:io.excluded_books)==null?void 0:oo.length)??0);const et=(ro=te.version_graph)==null?void 0:ro.collections;if(et)for(const ao of Object.keys(et))Te[ao]=fn(te,De,ao).nodes.filter(co=>co.kind==="book"&&!co.bridge).length;return Te.core==null&&((lo=(so=te.version_graph)==null?void 0:so.core_books)!=null&&lo.length)&&(Te.core=te.version_graph.core_books.length),Te})()})}if(s==="feedback"&&S)return t.jsx(tl,{resourceId:e,apiUrl:z});const J=_.find(te=>te.key===s);return J?J.render({detail:E,entry:X,transport:n,onNavigate:j}):null};if(F)return t.jsx(Ht,{style:{minHeight:N,...D},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((J,ve)=>t.jsx("div",{style:{height:ve===1?40:16,width:J,opacity:.35,background:i("rule")}},ve))})});if(ae||!E||!X||!Oe)return t.jsx(Ht,{style:{minHeight:N,...D},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:i("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const kt=s==="basic"||s==="emendated",ln=[{label:h??B.detailTab.backToIndex,onClick:w}];if(E.type==="book"&&E.work_id){const J=E.work_id;ln.push({label:B.indexType.work,id:J,onClick:()=>j==null?void 0:j(J)})}ln.push({label:B.indexType[E.type]});const an=s==="collated"||s==="fulltext",Xi=typeof T=="string"?B.status[T.trim()]??T:T,Qi=t.jsx(fs,{left:t.jsxs(t.Fragment,{children:[Xi,Xi?" · ":"",t.jsx(Sx,{id:E.id,label:B.label.id,copied:B.action.copied,copyLabel:B.action.copy})]}),right:t.jsxs(t.Fragment,{children:[S&&!kt&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:B.detailTab.submitVersion}),Ce&&t.jsx("a",{href:Ce.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:i("meta-fg")},children:B.detailTab.dataLicense})]})});return kt?t.jsx("div",{className:C,children:t.jsxs(Ht,{grid:!0,style:{minHeight:N,...D},children:[t.jsx(Qn,{breadcrumb:t.jsx(ei,{items:ln}),actions:t.jsxs(t.Fragment,{children:[t.jsx(pi,{style:{border:"none",background:"transparent"}}),Ce&&t.jsx(ui,{...Ce})]})}),Xe(),Qi]})}):t.jsx("div",{className:C,children:t.jsxs(Ht,{wide:an,style:{minHeight:N,...D},children:[t.jsx(Qn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx($i,{char:"籍"}),t.jsx(ei,{items:ln})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(pi,{}),S&&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:i("meta-fg")},children:B.detailTab.feedback}),Ce&&t.jsx(ui,{...Ce})]})}),t.jsx(rs,{...Oe,aside:an?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:i("accent"),borderBottom:`1px solid ${i("rule")}`},children:[O("作品信息")," →"]}):Oe.aside}),!an&&xe.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:xe.map(J=>t.jsx(ss,{label:J.label,active:J.key===s||kt&&J.key==="basic",onClick:()=>l(J.key)},J.key))}),t.jsx("div",{style:{marginTop:!an&&xe.length>1?8:0},children:Ee()}),Qi]})})};function Sx({id:e,label:n,copied:o,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 d;(d=navigator.clipboard)==null||d.writeText(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?o:r,"aria-label":s?o: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:i("aux-fg")},children:s?"✓":"⧉"})]})}function _x(e,n){return n?e.workSubtype[n]??n:""}const vl=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],Cn="zhusha",In="bim-theme";function kl(e){return e==="zhusha"||e==="indigo"||e==="ink"}function Tn(e){return kl(e)?e:Cn}function $x(){try{return Tn(window.localStorage.getItem(In))}catch{return Cn}}function wl(e){try{window.localStorage.setItem(In,e)}catch{}}function Sl(e){const n=Tn(e);return document.documentElement.setAttribute("data-theme",n),n}function _l(){return Tn(document.documentElement.getAttribute("data-theme"))}const zx=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],Zi="airy",En="bim-layout";function $l(e){return e==="airy"||e==="boxed"}function Rn(e){return $l(e)?e:Zi}function Cx(){try{return Rn(window.localStorage.getItem(En))}catch{return Zi}}function Ix(e){try{window.localStorage.setItem(En,e)}catch{}}function Tx(e){const n=Rn(e);return document.documentElement.setAttribute("data-layout",n),n}function Ex(){return Rn(document.documentElement.getAttribute("data-layout"))}const Rx=`try{var t=localStorage.getItem(${JSON.stringify(In)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(En)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,Nx={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},Lx=({onChange:e,style:n})=>{const{convert:o}=Z(),[r,s]=g.useState(Cn);g.useEffect(()=>{s(_l())},[]);const l=d=>{s(Sl(d)),wl(d),e==null||e(d)};return t.jsx("div",{role:"radiogroup","aria-label":o("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:vl.map(d=>{const p=r===d.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":p,"aria-label":o(d.label),title:o(d.label),onClick:()=>l(d.name),style:{width:28,height:44,padding:0,border:0,background:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:t.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:"50%",boxSizing:"border-box",background:i(Nx[d.name]),boxShadow:p?`0 0 0 2px ${i("page-bg")}, 0 0 0 3.5px ${i("aux-fg")}`:"none"}})},d.name)})})};exports.BidLink=we.BidLink;exports.BookIndexError=we.BookIndexError;exports.BookIndexManager=we.BookIndexManager;exports.BookIndexStorage=we.BookIndexStorage;exports.BundleStorage=we.BundleStorage;exports.ConfigError=we.ConfigError;exports.GithubStorage=we.GithubStorage;exports.IdGenerationError=we.IdGenerationError;exports.IdGenerator=we.IdGenerator;exports.LocalStorage=we.LocalStorage;exports.MigrationError=we.MigrationError;exports.StorageError=we.StorageError;exports.base36Decode=we.base36Decode;exports.base36Encode=we.base36Encode;exports.base58Decode=we.base58Decode;exports.buildId=we.buildId;exports.buildPromotionMap=we.buildPromotionMap;exports.cleanName=we.cleanName;exports.decodeId=we.decodeId;exports.decodeIdString=we.decodeIdString;exports.encodeId=we.encodeId;exports.extractIdFromUrl=we.extractIdFromUrl;exports.extractStatus=we.extractStatus;exports.extractType=we.extractType;exports.normalizeCatalog=we.normalizeCatalog;exports.parseId=we.parseId;exports.shardOf=we.shardOf;exports.smartDecode=we.smartDecode;exports.validateResource=we.validateResource;exports.Badge=bn;exports.BidUrlProvider=Wl;exports.BookDetailLayout=wx;exports.BookFullText=si;exports.BookPage=cl;exports.Breadcrumb=ei;exports.CATALOG_ALL_ID=rt;exports.CATALOG_CSS=ul;exports.CATALOG_NARROW_QUERY=Ki;exports.CATALOG_PAGE_SIZE=qi;exports.CATALOG_UNCLASSIFIED_ID=qt;exports.CardFoot=en;exports.CatalogPage=vx;exports.CatalogPager=yl;exports.CatalogTree=fl;exports.CheckFilter=is;exports.Chip=ls;exports.ChipWall=Ic;exports.CollatedEdition=Hi;exports.CollectionCatalog=yi;exports.CollectionPage=dl;exports.CreateEntityDialog=Ys;exports.DEFAULT_LAYOUT=Zi;exports.DEFAULT_READER_PREFS=Ii;exports.DEFAULT_THEME=Cn;exports.DETAIL_CSS=os;exports.Dash=Bc;exports.DataTable=Ec;exports.DetailFooter=fs;exports.DetailGrid=Xt;exports.DetailHeader=rs;exports.EmendatedBySection=Pr;exports.EmptyNote=Dc;exports.EntityDetail=Lr;exports.EntityPage=pl;exports.EntityPickerDialog=qs;exports.EntitySelector=Vs;exports.ExpandRow=Ac;exports.ExtLink=Hc;exports.FEEDBACK_FAB_OFFSET_VAR=ai;exports.FONT_SIZE_STEPS=$t;exports.FactList=_c;exports.FeedbackButton=uu;exports.FeedbackDialog=Qs;exports.FeedbackForm=el;exports.FeedbackList=Gi;exports.FeedbackTab=tl;exports.FilterChip=ss;exports.FormInput=Ge;exports.FormTextArea=bt;exports.GUJI_MARKDOWN_FIELD=pc;exports.GUJI_TABLE_NOTATION=_s;exports.GlyphBadge=$i;exports.GujiTable=Ni;exports.HomePage=ri;exports.ImagePanel=js;exports.IndexApp=hp;exports.IndexBrowser=Yn;exports.IndexDetail=bi;exports.IndexEditor=Js;exports.IndexView=Qp;exports.IntroGrid=Sc;exports.LAYOUTS=zx;exports.LAYOUT_STORAGE_KEY=En;exports.LocaleContext=Rt;exports.LocaleProvider=Zl;exports.LocaleToggle=pi;exports.MetaLine=Me;exports.ModeIndicator=Er;exports.MoreButton=Cc;exports.MoreLink=Bt;exports.PAGE_MAX_WIDTH=un;exports.PageFrame=Ht;exports.Quote=Mc;exports.READER_CSS=hs;exports.RECENT_IDS_STORAGE_KEY=Ct;exports.ROLE_CLASS_ORDER=Yr;exports.ReadButton=Xn;exports.ReaderMdText=Wi;exports.ReaderShell=Ei;exports.ReaderToc=ys;exports.RelationPanel=Gs;exports.RepoSourceLink=ui;exports.ResourceEditor=Vn;exports.ResourceGroup=Fc;exports.ResourceLine=Pc;exports.ResourceList=hi;exports.ResourceRow=us;exports.SNIPPET_MARK_END=Sr;exports.SNIPPET_MARK_START=wr;exports.SearchInput=Rr;exports.Sec=Fe;exports.Section=qe;exports.SectionHead=$c;exports.SideList=ht;exports.SmartBidInput=xn;exports.SourceEditor=Os;exports.SummaryCard=Qt;exports.THEMES=vl;exports.THEME_INIT_SCRIPT=Rx;exports.THEME_STORAGE_KEY=In;exports.TabFilter=$n;exports.TableHead=Rc;exports.TableRow=Nc;exports.TagRow=xs;exports.TagRows=Oc;exports.TextButton=zc;exports.ThemeToggle=Lx;exports.TopStrip=Qn;exports.VersionLineageGraph=al;exports.VersionLineageList=ll;exports.VersionLineageView=Yi;exports.VolumeChips=Tc;exports.VolumeLinks=zi;exports.WorkCard=hl;exports.WorkCardGrid=jl;exports.WorkCatalog=bp;exports.WorkPage=rl;exports.WorkRow=bl;exports.applyLayout=Tx;exports.applyTheme=Sl;exports.bucketResources=ki;exports.buildCatalogTree=ux;exports.buildCollectionTable=qr;exports.buildLineageGraph=fn;exports.buildPageUrl=mi;exports.buildParagraphBlocks=Ns;exports.buildVersionRow=Ur;exports.buildVersionTable=Vr;exports.canParagraphize=Kt;exports.catalogNodeIdOf=dx;exports.catalogNodeIdsOf=px;exports.catalogPageCount=mx;exports.catalogTotal=Ji;exports.classificationPath=nn;exports.compareCatalogCards=gx;exports.computeVersionPartition=lc;exports.currentLayout=Ex;exports.currentTheme=_l;exports.defaultWorkLink=gl;exports.deriveDating=oc;exports.deriveEditionType=Zr;exports.deriveEra=Zt;exports.deriveYear=wn;exports.deriveYearRange=vi;exports.detailToEditor=Xs;exports.detectGenre=zn;exports.displayAuthorRole=Si;exports.editorToDetail=Xp;exports.eraRank=qn;exports.findCatalogPath=zt;exports.flattenTitles=ti;exports.flattenToc=Ss;exports.formatTemplate=Jt;exports.formatVolumeRange=_n;exports.getDisplayNameFromUrl=Nt;exports.getStartPage=gi;exports.getTypeGroupKey=xi;exports.groupRelatedWorks=rc;exports.gujiInlineToPlain=ts;exports.hasGujiMarkdownV02=Jn;exports.hasGujiTableNotation=$s;exports.isLayoutName=$l;exports.isThemeName=kl;exports.measureText=at;exports.mergeVolumeResources=fi;exports.normalizeEra=We;exports.normalizeLayout=Rn;exports.normalizeRole=wi;exports.normalizeTheme=Tn;exports.normalizeVolumeIndex=Ut;exports.normalizeVolumes=Tr;exports.numberToChinese=Jr;exports.paginationItems=xl;exports.parseChineseNumber=gn;exports.parseGujiInline=es;exports.parseGujiTable=Cs;exports.parseSourceString=Ds;exports.pickReaderVersion=ws;exports.readStoredLayout=Cx;exports.readStoredTheme=$x;exports.readerVersionOptionLabel=ii;exports.readerVersionsFromFullText=ks;exports.renderFullTextBody=ud;exports.renderProperNames=Bs;exports.renderReaderInline=Ai;exports.resourceHref=Lt;exports.resourceNote=Sn;exports.roleFacets=Kr;exports.rowNo=Lc;exports.sortYear=mn;exports.splitFullTextTables=Ri;exports.splitHighlightSnippet=_r;exports.splitTableRow=zs;exports.storeLayout=Ix;exports.storeTheme=wl;exports.stringifySources=Hs;exports.toCatalogWorkCard=fx;exports.useBidUrl=Pe;exports.useConvert=Z;exports.useReaderPrefs=Ti;exports.useT=ue;exports.validateLineageGraph=Nu;exports.volumeStats=yn;
1160
+ `,en="未分類",at="all",ao=20;function ln(e){if(!e)return[];const n=[];for(const o of[e.l1,e.l2,e.l3,e.l4]){const r=(o??"").trim();if(!r)break;n.push(r)}return n}function of(e){const n=ln(e);return n.length?n.join("/"):en}function rf(e){const n=ln(e);return n.length?n.map((o,r)=>n.slice(0,r+1).join("/")):[en]}function sf(e,n=[]){const o=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,m)=>{const x=d.slice(0,m+1).join("/");o.has(x)||o.set(x,a)})});const r=new Map;let s=0;for(const p of e){const a=ln(p.classification);if(!a.length){s++;continue}let d=r;a.forEach((u,m)=>{const x=a.slice(0,m+1).join("/");let g=d.get(u);g||(g={id:x,label:u,count:0,children:new Map},d.set(u,g)),g.count++,d=g.children})}const l=p=>[...p.values()].sort((a,d)=>{const u=o.get(a.id)??1/0,m=o.get(d.id)??1/0;return u!==m?u-m: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:en,label:en,count:s}),c}function Tt(e,n){if(!n)return[];for(const o of e){if(o.id===n)return[o];if(o.children){const r=Tt(o.children,n);if(r.length)return[o,...r]}}return[]}function co(e){return e.reduce((n,o)=>n+o.count,0)}function lf(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function af(e){var p;const n={id:e.id,title:e.title||e.id},o=e.juan_count,r=typeof o=="number"?o:o==null?void 0:o.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=lf(typeof e.description=="string"?e.description:(p=e.description)==null?void 0:p.text);l&&(n.summary=l);const c=ln(e.classification);return c.length&&(n.classification=c),n}function cf(e,n){const o=e.summary?0:1,r=n.summary?0:1;return o!==r?o-r:e.title.localeCompare(n.title,"zh")}function df(e,n=ao){return Math.max(1,Math.ceil(e/n))}function Pl(e,n,o=2){if(n<=1)return[1];const r=new Set([1,n]);for(let c=e-o;c<=e+o;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 pf=()=>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 uf(e,n,o){const r=[];o&&r.push({id:at,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 Ol({tree:e,selectedId:n,onSelect:o,allLabel:r="全部",label:s="分類"}){const{convert:l}=V(),c=f.useRef(null),p=n&&n!==at?n:null,a=r!==null,[d,u]=f.useState(()=>{const k=new Set;for(const _ of Tt(e,p))k.add(_.id);return k});f.useEffect(()=>{const k=Tt(e,p);k.length&&u(_=>{if(k.every(z=>_.has(z.id)))return _;const S=new Set(_);for(const z of k)S.add(z.id);return S})},[e,p]);const m=f.useMemo(()=>uf(e,d,a),[e,d,a]),[x,g]=f.useState(null);f.useEffect(()=>{g(null)},[n]);const b=p??(a?at:null),w=f.useMemo(()=>{var S;const k=new Set(m.map(z=>z.id));if(x&&k.has(x))return x;if(b&&k.has(b))return b;const _=Tt(e,p).map(z=>z.id).filter(z=>k.has(z));return _.length?_[_.length-1]:((S=m[0])==null?void 0:S.id)??null},[m,x,b,e,p]),y=f.useCallback((k,_)=>{u(S=>{const z=S.has(k),N=_??!z;if(N===z)return S;const R=new Set(S);return N?R.add(k):R.delete(k),R})},[]),j=f.useCallback(k=>{g(k),requestAnimationFrame(()=>{var S;const _=Array.from(((S=c.current)==null?void 0:S.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===k);_==null||_.focus()})},[]),h=f.useCallback((k,_)=>{_&&y(k,!0),o(k)},[o,y]),v=f.useCallback(k=>{const _=k.target.closest("[data-ct-id]");if(!_)return;const S=_.dataset.ctId,z=m.findIndex(C=>C.id===S);if(z<0)return;const N=m[z];let R=null;switch(k.key){case"ArrowDown":R=m[Math.min(m.length-1,z+1)].id;break;case"ArrowUp":R=m[Math.max(0,z-1)].id;break;case"Home":R=m[0].id;break;case"End":R=m[m.length-1].id;break;case"ArrowRight":if(!N.hasChildren)break;d.has(S)?R=N.firstChildId:y(S,!0);break;case"ArrowLeft":N.hasChildren&&d.has(S)?y(S,!1):R=N.parentId;break;case"Enter":case" ":k.preventDefault(),h(S,N.hasChildren);return;default:return}k.preventDefault(),R&&R!==S&&j(R)},[m,d,y,j,h]),$=(k,_)=>k.map((S,z)=>{var L;const N=(L=S.children)!=null&&L.length?S.children:null,R=!!N&&d.has(S.id),C=S.id===p,H=_===1&&k.length>1&&z===k.length-1;return t.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":N?R:void 0,"aria-selected":C,tabIndex:w===S.id?0:-1,"data-ct-id":S.id,className:H?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{g(S.id),h(S.id,!!N)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:N?M=>{M.stopPropagation(),g(S.id),y(S.id)}:void 0,children:N?t.jsx(pf,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(S.label)}),t.jsx("span",{className:"bim-ct-n",children:S.count.toLocaleString("en-US")})]}),R&&t.jsx("ul",{role:"group",children:$(N,_+1)})]},S.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:w===at?0:-1,"data-ct-id":at,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{g(at),o(at)},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:co(e).toLocaleString("en-US")})]})}),$(e,1)]})}const Dl=e=>`/item/${encodeURIComponent(e)}`;function xf(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Hl(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function Gl({work:e,href:n}){var c,p;const{convert:o}=V(),r=Hl(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:o(e.title)}),r&&t.jsx("span",{className:"bim-ct-juan",children:o(r)})]}),s.length>0&&t.jsx("span",{className:"bim-ct-by",children:s.map((a,d)=>t.jsxs(f.Fragment,{children:[d>0&&"、",a.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(a.dynasty),"〕"]}),o(a.name)]},d))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:o(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(a=>o(a)).join(" · ")})]})})}function Ul({work:e,href:n}){var c,p;const{convert:o}=V(),r=Hl(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-lrow",children:t.jsxs("a",{href:n,children:[t.jsxs("span",{className:"bim-ct-lt",children:[o(e.title),r&&t.jsx("span",{className:"bim-ct-juan",children:o(r)})]}),t.jsx("span",{className:"bim-ct-by",children:s.map((a,d)=>t.jsxs(f.Fragment,{children:[d>0&&"、",a.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(a.dynasty),"〕"]}),o(a.name)]},d))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(a=>o(a)).join(" · ")})]})})}function Vl({page:e,pageCount:n,onPage:o,pageHref:r,label:s="分頁"}){const{convert:l}=V();if(n<=1)return null;const c=a=>d=>{o&&(r&&!xf(d)||(d.preventDefault(),o(a)))},p=(a,d,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const m={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...m,href:r(a),onClick:c(a),children:d}):t.jsx("button",{type:"button",...m,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:Pl(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 Yl({works:e,workLink:n=Dl,emptyText:o="此類暫無作品",view:r="card",...s}){const{convert:l}=V();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:typeof o=="string"?l(o):o}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(c=>t.jsx(Ul,{work:c,href:n(c.id)},c.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(c=>t.jsx(Gl,{work:c,href:n(c.id)},c.id))}),t.jsx(Vl,{...s})]})}const ff=()=>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 mf({tree:e,selectedId:n,page:o,pageCount:r,works:s,onSelect:l,onPage:c,searchSlot:p,workLink:a,pageHref:d,allLabel:u="全部",allTitle:m="全部典籍",pageSize:x=ao,className:g,view:b,onViewChange:w}){const{convert:y}=V(),h=`bim-ct-drawer-${f.useId().replace(/:/g,"")}`,[v,$]=f.useState(!1),[k,_]=f.useState("card"),S=b??k,z=M=>{_(M),w==null||w(M)},N=Tt(e,n&&n!==at?n:null),R=N.length?N[N.length-1]:null,C=R?R.label:m,H=R?R.count:co(e),L=f.useCallback(M=>{$(!1),l(M)},[l]);return t.jsxs("div",{className:g?`bim-ct ${g}`:"bim-ct","data-drawer":v?"open":"closed",children:[t.jsx("style",{children:Fl}),t.jsxs("aside",{className:"bim-ct-side","aria-label":y("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":v,"aria-controls":h,onClick:()=>$(M=>!M),children:[t.jsxs("span",{children:[y("分類"),":",y(N.length?N.map(M=>M.label).join(" › "):u??m)]}),t.jsx(ff,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:h,children:[t.jsx("h2",{className:"bim-ct-side-h",children:y("分類")}),t.jsx(Ol,{tree:e,selectedId:n,onSelect:L,allLabel:u})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:y(C)}),N.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:y(N.slice(0,-1).map(M=>M.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[y(`共 ${H.toLocaleString("en-US")} 種 · 每頁 ${x} 條`),r>1&&y(` · 第 ${o} / ${r} 頁`)]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":y("呈現方式"),children:[t.jsx("button",{type:"button","aria-pressed":S==="card",onClick:()=>z("card"),children:y("卡片")}),t.jsx("button",{type:"button","aria-pressed":S==="list",onClick:()=>z("list"),children:y("列表")})]})]}),p&&t.jsx("div",{className:"bim-ct-search",children:p}),t.jsx(Yl,{works:s,view:S,workLink:a,page:o,pageCount:r,onPage:c,pageHref:d})]})]})}const vi=({style:e})=>{const n=f.useContext(Lt);if(!n)return null;const{locale:o,setLocale:r}=n,s=o==="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 ${i("border")}`,borderRadius:"4px",background:i("bg"),color:i("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:s?i("primary"):void 0,fontWeight:s?700:400},children:"繁"}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:s?void 0:i("primary"),fontWeight:s?400:700},children:"简"})]})},ki=({href:e,label:n="在 GitHub 查看本条目源文件",size:o=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:o+8,height:o+8,borderRadius:4,color:i("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:l=>{l.currentTarget.style.color=i("fg")},onMouseLeave:l=>{l.currentTarget.style.color=i("desc-fg")},children:t.jsx("svg",{width:o,height:o,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 ei(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function gf(e,n){if(!n)return!1;const o=n.id;return o===void 0||o===e}const hf=({id:e,transport:n,initialDetail:o,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:c,onJuanChange:p,lineageMode:a="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:m,initialPage:x=1,selectedLineageNodeId:g,onNavigate:b,onBack:w,backLabel:y,renderLink:j,enrichDetail:h,getSourceLink:v,readLink:$,railTop:k,extraTabs:_=[],showFeedbackTab:S=!0,feedbackApiUrl:z,height:N,footerExtra:R,className:C,style:H})=>{var fo;const L=me(),{convert:M}=V(),[F]=f.useState(()=>{if(!gf(e,o))return null;const Z={...o},ve=r??ei(e,Z);return h&&h(ve,Z),{id:e,entry:ve,detail:Z}}),[X,U]=f.useState((F==null?void 0:F.entry)??null),[T,ce]=f.useState((F==null?void 0:F.detail)??null),[B,D]=f.useState(!F),[A,ee]=f.useState(!1),[de,G]=f.useState([]),[q,ie]=f.useState(!1),[pe,ge]=f.useState(null),[Ee,Ne]=f.useState(!1),[ze,Te]=f.useState(null),[Ce,Ae]=f.useState(!1),[P,se]=f.useState(null),[re,ye]=f.useState([]),[be,K]=f.useState(!1),[I,Y]=f.useState(null),[fe,he]=f.useState(null),[W,ae]=f.useState(!1),J=f.useRef(null),[O,xe]=f.useState(null),je=c!==void 0?c:O,Se=f.useCallback(Z=>{p?p(Z):xe(Z)},[p]),ne=f.useCallback(async Z=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){G([]);return}ie(!0);try{if(n.getCollectionCatalogs)G(await n.getCollectionCatalogs(Z)||[]);else if(n.getCollectionCatalog){const ve=await n.getCollectionCatalog(Z);G(ve?[{resource_id:"",data:ve}]:[])}}catch{G([])}finally{ie(!1)}},[n]),we=f.useCallback(async Z=>{if(!n.getCollatedEditionIndex){ge(null);return}Ne(!0);try{ge(await n.getCollatedEditionIndex(Z))}catch{ge(null)}finally{Ne(!1)}},[n]),E=f.useCallback(async Z=>{if(!n.getBookFullTextIndex){Te(null);return}Ae(!0);try{Te(await n.getBookFullTextIndex(Z))}catch{Te(null)}finally{Ae(!1),se(Z)}},[n]),Q=f.useCallback(async Z=>{var ve;if(!n.getWorkFullTextList){ye([]);return}K(!0);try{const Re=(await n.getWorkFullTextList(Z)??[]).filter(Pe=>Pe.owner_type!=="Book");ye(Re),Y(((ve=Re.find(Pe=>Pe.primary)??Re[0])==null?void 0:ve.key)??null)}catch{ye([])}finally{K(!1)}},[n]),ue=f.useCallback(async(Z,ve)=>{ae(!0);try{if(n.getLineageGraph){const Ue=await n.getLineageGraph(Z);Ue&&he(Ue)}const Re=ve.version_graph;if(!Re||!Re.enabled){fe||he(null),J.current=null;return}const Pe=ve.books??[],nt=[];for(const Ue of Pe)try{const it=await n.getItem(Ue);it&&nt.push(it)}catch{}J.current={work:ve,books:nt};const oe=u??Re.default_collection??(Re.core_books&&Re.core_books.length>0?"core":"all"),Le=oe==="core"&&Array.isArray(Re.core_books)&&Re.core_books.length>0?"core":oe??"all";he(bn(ve,nt,Le))}catch{he(null),J.current=null}finally{ae(!1)}},[n]),le=f.useRef({initialDetail:o,initialEntry:r});le.current={initialDetail:o,initialEntry:r},f.useEffect(()=>{let Z=!1;const ve=oe=>{oe.type==="collection"?ne(e):oe.type==="work"?(oe.has_collated&&we(e),(oe.version_graph||n.getLineageGraph)&&ue(e,oe),n.getWorkFullTextList&&Q(e)):oe.type==="book"&&oe.has_full_text&&n.getBookFullTextIndex&&E(e)},Re=le.current;let Pe=null;if(F&&F.id===e)Pe=F;else if(Re.initialDetail&&Re.initialDetail.id===e){const oe={...Re.initialDetail},Le=Re.initialEntry??ei(e,oe);h&&h(Le,oe),Pe={entry:Le,detail:oe}}return Pe?(ee(!1),G(oe=>oe.length?[]:oe),ge(null),Te(null),ye(oe=>oe.length?[]:oe),Y(null),he(null),J.current=null,U(Pe.entry),ce(Pe.detail),D(!1),ve(Pe.detail),()=>{Z=!0}):((async()=>{D(!0),ee(!1),U(null),ce(null),G([]),ge(null),Te(null),ye([]),Y(null),he(null),J.current=null;try{const oe=await n.getItem(e);if(Z)return;if(!oe){ee(!0);return}const Le=oe;let Ue=null;if(n.getEntry&&(Ue=await n.getEntry(e),Z))return;Ue||(Ue=ei(e,Le)),h&&h(Ue,Le),U(Ue),ce(Le),ve(Le)}catch{Z||ee(!0)}finally{Z||D(!1)}})(),()=>{Z=!0})},[e,n,F,h,ne,we,ue,E,Q]),f.useEffect(()=>{const Z=J.current;!Z||!u||he(bn(Z.work,Z.books,u))},[u]);const te=[];if(T){if(te.push({key:"basic",label:L.detailTab.basicInfo}),T.type==="collection"){q&&de.length===0&&te.push({key:"catalog:loading",label:`${L.detailTab.catalog}…`});for(const Z of de)te.push({key:`catalog:${Z.resource_id}`,label:Z.short_name?`${M(Z.short_name)}${L.detailTab.catalogSuffix}`:L.detailTab.collectionCatalog})}T.type==="work"&&(pe||Ee)&&s==="collated"&&te.push({key:"collated",label:Ee?`${L.detailTab.collatedEdition}…`:L.detailTab.collatedEdition}),T.type==="book"&&(ze||Ce)&&s==="fulltext"&&te.push({key:"fulltext",label:Ce?`${L.detailTab.fullText}…`:L.detailTab.fullText}),T.type==="work"&&(re.length>0||be)&&s==="fulltext"&&te.push({key:"fulltext",label:be?`${L.detailTab.fullText}…`:L.detailTab.fullText}),T.type==="work"&&(fe||W)&&te.push({key:"lineage",label:W?`${L.detailTab.lineage}…`:L.detailTab.lineage});for(const Z of _)(Z.position??"before-feedback")==="before-feedback"&&Z.shouldShow(T)&&te.push({key:Z.key,label:Z.label});S&&s==="feedback"&&te.push({key:"feedback",label:L.detailTab.feedback});for(const Z of _)Z.position==="after-feedback"&&Z.shouldShow(T)&&te.push({key:Z.key,label:Z.label})}f.useEffect(()=>{if(s!=="emendated"||!T)return;l("basic");const Z=setTimeout(()=>{var ve;(ve=document.getElementById("studies"))==null||ve.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(Z)},[s,T,l]);const ke=X&&T&&v?v({activeTab:s,activeJuan:je,entry:X,detail:T}):null,Ie=f.useMemo(()=>{var nt;if(!T)return null;const ve=(T.authors??[]).map(oe=>{const Le=Wi(oe.role);return`${oe.dynasty?`〔${M(oe.dynasty)}〕`:""}${M(oe.name)}${Le?` ${M(Le)}`:""}`}).join(" · ");let Re=!1;try{Re=$e.extractStatus(T.id)==="draft"}catch{}if(T.type==="book"){const oe=T;return{title:M(oe.title),subtitle:oe.edition?M(oe.edition):ve||void 0,aside:[Re?L.status.draft:"",ve&&oe.edition?ve:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(T.type==="collection"){const oe=T;return{title:M(oe.title),subtitle:M(pt(oe,L.unit.juan))||void 0,aside:[(nt=oe.publication_info)==null?void 0:nt.year,Re?L.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:ve||void 0}}if(T.type==="entity"){const oe=T,Le=it=>it==null?"":it<0?`前${-it}`:String(it),Ue=oe.birth_year!=null||oe.death_year!=null?`${Le(oe.birth_year)||"?"}—${Le(oe.death_year)||"?"}`:"";return{title:M(oe.primary_name||oe.title),subtitle:[oe.dynasty?`〔${M(oe.dynasty)}〕`:"",Ue].filter(Boolean).join(" ")||void 0,aside:Re?L.status.draft:void 0,secondLine:void 0}}const Pe=M(pt(T,L.unit.juan));return{title:M(T.title),subtitle:[Pe,ve].filter(Boolean).join(" · ")||void 0,aside:[yf(L,T.subtype),Re?L.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[T,M,L]),We=T?T.type==="work"?(((fo=pe==null?void 0:pe.juan_files)==null?void 0:fo.length)??0)>0?"collated":re.length>0?"fulltext":null:T.type==="book"&&(((ze==null?void 0:ze.chapters.length)??0)>0||T.has_full_text&&n.getBookFullTextIndex&&P!==T.id)?"fulltext":null:null,Ze=re.find(Z=>Z.primary)??re[0],an=()=>{var Z;We==="collated"&&((Z=pe==null?void 0:pe.juan_files)!=null&&Z.length)?(Se(pe.juan_files[0]),l("collated")):We==="fulltext"&&((T==null?void 0:T.type)==="work"&&Ze&&Y(Ze.key),Se(null),l("fulltext"))};let ut=null;if(T&&$){const Z=$({detail:T,kind:We,fullTextKey:T.type==="work"?Ze==null?void 0:Ze.key:void 0});Z&&(ut=t.jsx(ai,{href:Z}))}else We&&(ut=t.jsx(ai,{onClick:an}));const cn=Z=>{if(!T)return null;const ve=Z.replace(/\.[^.]+$/,"");if($){const Re=$({detail:T,kind:"fulltext",juan:ve});return Re?{href:Re}:null}return{onClick:()=>{Se(ve),l("fulltext")}}},dn=new Set(_.map(Z=>Z.key)),_e=te.filter(Z=>Z.key.startsWith("catalog:")&&Z.key!=="catalog:loading"||dn.has(Z.key)).map(Z=>({key:Z.key,label:Z.label,onClick:()=>l(Z.key)})),tt=()=>{var Z;return T?T.type==="work"?t.jsx(Rl,{data:T,transport:n,onNavigate:b,renderLink:j,readAction:ut,railTop:k,railLinks:_e}):T.type==="book"?t.jsx(Al,{data:T,transport:n,onNavigate:b,renderLink:j,readAction:ut,fullText:ze,fullTextPending:!!T.has_full_text&&!!n.getBookFullTextIndex&&P!==T.id,chapterLink:cn,railTop:k,railLinks:_e}):T.type==="collection"?t.jsx(Wl,{data:T,catalog:(Z=de[0])==null?void 0:Z.data,transport:n,onNavigate:b,renderLink:j,readAction:ut,railTop:k,railLinks:_e,catalogAction:de.length>0?t.jsxs("a",{href:"#catalog",onClick:ve=>{ve.preventDefault(),l(`catalog:${de[0].resource_id}`)},children:[M(L.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Ml,{data:T,transport:n,onNavigate:b,renderLink:j,railTop:k,railLinks:_e}):null},Be=()=>{var ve,Re,Pe,nt;if(!X||!T)return null;if(s==="basic"||s==="emendated")return tt();if(typeof s=="string"&&s.startsWith("catalog:")){const oe=(ve=de.find(Le=>`catalog:${Le.resource_id}`===s))==null?void 0:ve.data;return t.jsx(Ri,{data:oe,onNavigate:b,renderLink:j})}if(s==="collated")return t.jsx(no,{index:pe||void 0,workId:e,transport:n,onNavigate:b,activeJuan:je,onJuanChange:Se});if(s==="fulltext"&&T.type==="work"){const oe=I??((Re=re[0])==null?void 0:Re.key);return oe?t.jsx(gi,{bookId:e,workKey:oe,versions:re,onVersionChange:Le=>{Y(Le),Se(null)},transport:n,activeChapter:je,onChapterChange:Se},oe):t.jsx("div",{style:{padding:24,color:i("desc-fg")},children:be?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(gi,{index:ze||void 0,bookId:e,transport:n,activeChapter:je,onChapterChange:Se});if(s==="lineage"){if(!fe)return t.jsx("div",{style:{color:i("label-fg"),padding:"24px 0"},children:W?"加載中…":"暫無版本圖數據"});const oe=T.type==="work"?T:null;return t.jsx(so,{graph:fe,renderLink:j,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:a,onModeChange:d,selectedNodeId:g,collection:u??((Pe=oe==null?void 0:oe.version_graph)==null?void 0:Pe.default_collection),onCollectionChange:m,collectionsAvailable:(nt=oe==null?void 0:oe.version_graph)==null?void 0:nt.collections,collectionCounts:(()=>{var mo,go,ho,bo,yo,jo,vo;if(!oe)return;const Le={},Ue=((mo=J.current)==null?void 0:mo.books)??[];Le.all=(((go=oe.books)==null?void 0:go.length)??0)-(((bo=(ho=oe.version_graph)==null?void 0:ho.excluded_books)==null?void 0:bo.length)??0);const it=(yo=oe.version_graph)==null?void 0:yo.collections;if(it)for(const ko of Object.keys(it))Le[ko]=bn(oe,Ue,ko).nodes.filter(wo=>wo.kind==="book"&&!wo.bridge).length;return Le.core==null&&((vo=(jo=oe.version_graph)==null?void 0:jo.core_books)!=null&&vo.length)&&(Le.core=oe.version_graph.core_books.length),Le})()})}if(s==="feedback"&&S)return t.jsx(Cl,{resourceId:e,apiUrl:z});const Z=_.find(oe=>oe.key===s);return Z?Z.render({detail:T,entry:X,transport:n,onNavigate:b}):null};if(B)return t.jsx(Kt,{style:{minHeight:N,...H},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((Z,ve)=>t.jsx("div",{style:{height:ve===1?40:16,width:Z,opacity:.35,background:i("rule")}},ve))})});if(A||!T||!X||!Ie)return t.jsx(Kt,{style:{minHeight:N,...H},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:i("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const St=s==="basic"||s==="emendated",pn=[{label:y??L.detailTab.backToIndex,onClick:w}];if(T.type==="book"&&T.work_id){const Z=T.work_id;pn.push({label:L.indexType.work,id:Z,onClick:()=>b==null?void 0:b(Z)})}pn.push({label:L.indexType[T.type]});const un=s==="collated"||s==="fulltext",uo=typeof R=="string"?L.status[R.trim()]??R:R,xo=t.jsx(Os,{left:t.jsxs(t.Fragment,{children:[uo,uo?" · ":"",t.jsx(bf,{id:T.id,label:L.label.id,copied:L.action.copied,copyLabel:L.action.copy})]}),right:t.jsxs(t.Fragment,{children:[S&&!St&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:L.detailTab.submitVersion}),ke&&t.jsx("a",{href:ke.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:i("meta-fg")},children:L.detailTab.dataLicense})]})});return St?t.jsx("div",{className:C,children:t.jsxs(Kt,{grid:!0,style:{minHeight:N,...H},children:[t.jsx(ci,{breadcrumb:t.jsx(di,{items:pn}),actions:t.jsxs(t.Fragment,{children:[t.jsx(vi,{style:{border:"none",background:"transparent"}}),ke&&t.jsx(ki,{...ke})]})}),tt(),xo]})}):t.jsx("div",{className:C,children:t.jsxs(Kt,{wide:un,style:{minHeight:N,...H},children:[t.jsx(ci,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Fi,{char:"籍"}),t.jsx(di,{items:pn})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(vi,{}),S&&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:i("meta-fg")},children:L.detailTab.feedback}),ke&&t.jsx(ki,{...ke})]})}),t.jsx(Rs,{...Ie,aside:un?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:i("accent"),borderBottom:`1px solid ${i("rule")}`},children:[M("作品信息")," →"]}):Ie.aside}),!un&&te.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:te.map(Z=>t.jsx(Ns,{label:Z.label,active:Z.key===s||St&&Z.key==="basic",onClick:()=>l(Z.key)},Z.key))}),t.jsx("div",{style:{marginTop:!un&&te.length>1?8:0},children:Be()}),xo]})})};function bf({id:e,label:n,copied:o,copyLabel:r}){const[s,l]=f.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var c;(c=navigator.clipboard)==null||c.writeText(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?o:r,"aria-label":s?o: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:i("aux-fg")},children:s?"✓":"⧉"})]})}function yf(e,n){return n?e.workSubtype[n]??n:""}const Kl=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],An="zhusha",Wn="bim-theme";function ql(e){return e==="zhusha"||e==="indigo"||e==="ink"}function Mn(e){return ql(e)?e:An}function jf(){try{return Mn(window.localStorage.getItem(Wn))}catch{return An}}function Jl(e){try{window.localStorage.setItem(Wn,e)}catch{}}function Zl(e){const n=Mn(e);return document.documentElement.setAttribute("data-theme",n),n}function Xl(){return Mn(document.documentElement.getAttribute("data-theme"))}const vf=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],po="airy",Fn="bim-layout";function Ql(e){return e==="airy"||e==="boxed"}function Pn(e){return Ql(e)?e:po}function kf(){try{return Pn(window.localStorage.getItem(Fn))}catch{return po}}function wf(e){try{window.localStorage.setItem(Fn,e)}catch{}}function Sf(e){const n=Pn(e);return document.documentElement.setAttribute("data-layout",n),n}function $f(){return Pn(document.documentElement.getAttribute("data-layout"))}const _f=`try{var t=localStorage.getItem(${JSON.stringify(Wn)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(Fn)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,zf={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},Cf=({onChange:e,style:n})=>{const{convert:o}=V(),[r,s]=f.useState(An);f.useEffect(()=>{s(Xl())},[]);const l=c=>{s(Zl(c)),Jl(c),e==null||e(c)};return t.jsx("div",{role:"radiogroup","aria-label":o("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:Kl.map(c=>{const p=r===c.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":p,"aria-label":o(c.label),title:o(c.label),onClick:()=>l(c.name),style:{width:28,height:44,padding:0,border:0,background:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:t.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:"50%",boxSizing:"border-box",background:i(zf[c.name]),boxShadow:p?`0 0 0 2px ${i("page-bg")}, 0 0 0 3.5px ${i("aux-fg")}`:"none"}})},c.name)})})};exports.BidLink=$e.BidLink;exports.BookIndexError=$e.BookIndexError;exports.BookIndexManager=$e.BookIndexManager;exports.BookIndexStorage=$e.BookIndexStorage;exports.BundleStorage=$e.BundleStorage;exports.ConfigError=$e.ConfigError;exports.GithubStorage=$e.GithubStorage;exports.IdGenerationError=$e.IdGenerationError;exports.IdGenerator=$e.IdGenerator;exports.LocalStorage=$e.LocalStorage;exports.MigrationError=$e.MigrationError;exports.StorageError=$e.StorageError;exports.base36Decode=$e.base36Decode;exports.base36Encode=$e.base36Encode;exports.base58Decode=$e.base58Decode;exports.buildId=$e.buildId;exports.buildPromotionMap=$e.buildPromotionMap;exports.cleanName=$e.cleanName;exports.decodeId=$e.decodeId;exports.decodeIdString=$e.decodeIdString;exports.encodeId=$e.encodeId;exports.extractIdFromUrl=$e.extractIdFromUrl;exports.extractStatus=$e.extractStatus;exports.extractType=$e.extractType;exports.normalizeCatalog=$e.normalizeCatalog;exports.parseId=$e.parseId;exports.shardOf=$e.shardOf;exports.smartDecode=$e.smartDecode;exports.validateResource=$e.validateResource;exports.Badge=wn;exports.BidUrlProvider=da;exports.BookDetailLayout=hf;exports.BookFullText=gi;exports.BookPage=Al;exports.Breadcrumb=di;exports.CATALOG_ALL_ID=at;exports.CATALOG_CSS=Fl;exports.CATALOG_NARROW_QUERY=lo;exports.CATALOG_PAGE_SIZE=ao;exports.CATALOG_UNCLASSIFIED_ID=en;exports.CLASSIFICATIONS=Cn;exports.CardFoot=rn;exports.CatalogPage=mf;exports.CatalogPager=Vl;exports.CatalogTree=Ol;exports.CheckFilter=Is;exports.Chip=Ls;exports.ChipWall=yd;exports.CollatedEdition=no;exports.CollectionCatalog=Ri;exports.CollectionPage=Wl;exports.CreateEntityDialog=jl;exports.DEFAULT_LAYOUT=po;exports.DEFAULT_READER_PREFS=Di;exports.DEFAULT_THEME=An;exports.DETAIL_CSS=Es;exports.DYNASTY_GROUPS=zn;exports.Dash=$d;exports.DataTable=vd;exports.DetailFooter=Os;exports.DetailGrid=nn;exports.DetailHeader=Rs;exports.EMPTY_FILTERS=_n;exports.EmendatedBySection=xs;exports.EmptyNote=Rd;exports.EntityDetail=ls;exports.EntityPage=Ml;exports.EntityPickerDialog=kl;exports.EntitySelector=yl;exports.ExpandRow=_d;exports.ExtLink=Nd;exports.FEEDBACK_FAB_OFFSET_VAR=bi;exports.FILTER_SUPPORT=Qr;exports.FONT_SIZE_STEPS=Ct;exports.FactList=md;exports.FeedbackButton=rx;exports.FeedbackDialog=_l;exports.FeedbackForm=zl;exports.FeedbackList=io;exports.FeedbackTab=Cl;exports.FilterChip=Ns;exports.FormInput=Ye;exports.FormTextArea=jt;exports.GUJI_MARKDOWN_FIELD=td;exports.GUJI_TABLE_NOTATION=Xs;exports.GlyphBadge=Fi;exports.GujiTable=Vi;exports.HomePage=mi;exports.ImagePanel=Ys;exports.IndexApp=du;exports.IndexBrowser=ii;exports.IndexDetail=Ei;exports.IndexEditor=wl;exports.IndexView=Vu;exports.IntroGrid=fd;exports.LAYOUTS=vf;exports.LAYOUT_STORAGE_KEY=Fn;exports.LOSS_OPTIONS=Ti;exports.LocaleContext=Lt;exports.LocaleProvider=Sa;exports.LocaleToggle=vi;exports.MetaLine=De;exports.ModeIndicator=Jr;exports.MoreButton=bd;exports.MoreLink=Mt;exports.PAGE_MAX_WIDTH=gn;exports.PageFrame=Kt;exports.Quote=Cd;exports.READER_CSS=Gs;exports.RECENT_IDS_STORAGE_KEY=It;exports.ROLE_CLASS_ORDER=js;exports.ReadButton=ai;exports.ReaderMdText=Ji;exports.ReaderShell=Gi;exports.ReaderToc=Vs;exports.RelationPanel=hl;exports.RepoSourceLink=ki;exports.ResourceEditor=ni;exports.ResourceGroup=Td;exports.ResourceLine=Id;exports.ResourceList=Ci;exports.ResourceRow=Fs;exports.SEARCH_VIEW_STORAGE_KEY=Ii;exports.SNIPPET_MARK_END=Gr;exports.SNIPPET_MARK_START=Hr;exports.SORTABLE_TYPES=Xr;exports.SearchInput=Zr;exports.SearchResults=rs;exports.Sec=He;exports.Section=Xe;exports.SectionHead=gd;exports.SideList=yt;exports.SmartBidInput=hn;exports.SourceEditor=fl;exports.SummaryCard=on;exports.THEMES=Kl;exports.THEME_INIT_SCRIPT=_f;exports.THEME_STORAGE_KEY=Wn;exports.TabFilter=Ln;exports.TableHead=kd;exports.TableRow=wd;exports.TagRow=Ps;exports.TagRows=Ed;exports.TextButton=hd;exports.ThemeToggle=Cf;exports.TopStrip=ci;exports.VersionLineageGraph=Bl;exports.VersionLineageList=Ll;exports.VersionLineageView=so;exports.VolumeChips=jd;exports.VolumeLinks=Pi;exports.WorkCard=Gl;exports.WorkCardGrid=Yl;exports.WorkCatalog=pu;exports.WorkPage=Rl;exports.WorkRow=Ul;exports.applyLayout=Sf;exports.applyTheme=Zl;exports.bucketResources=Bi;exports.buildCatalogTree=sf;exports.buildCollectionTable=ks;exports.buildLineageGraph=bn;exports.buildMeiliFilter=Pa;exports.buildPageUrl=zi;exports.buildParagraphBlocks=sl;exports.buildVersionRow=bs;exports.buildVersionTable=ys;exports.canParagraphize=Qt;exports.catalogNodeIdOf=of;exports.catalogNodeIdsOf=rf;exports.catalogPageCount=df;exports.catalogTotal=co;exports.classificationPath=ln;exports.compareCatalogCards=cf;exports.computeVersionPartition=Zc;exports.countActiveFilters=Tn;exports.currentLayout=$f;exports.currentTheme=Xl;exports.defaultWorkLink=Dl;exports.deriveDating=Kc;exports.deriveEditionType=Ss;exports.deriveEra=tn;exports.deriveYear=En;exports.deriveYearRange=Li;exports.detailToEditor=$l;exports.detectGenre=Bn;exports.displayAuthorRole=Wi;exports.editorToDetail=Uu;exports.eraRank=ri;exports.filtersFromParams=Oa;exports.filtersToParams=yn;exports.findCatalogPath=Tt;exports.flattenTitles=pi;exports.flattenToc=Zs;exports.formatTemplate=Qe;exports.formatVolumeRange=Nn;exports.getDisplayNameFromUrl=Bt;exports.getStartPage=_i;exports.getTypeGroupKey=Si;exports.groupRelatedWorks=qc;exports.gujiInlineToPlain=Cs;exports.hasActiveFilters=es;exports.hasGujiMarkdownV02=si;exports.hasGujiTableNotation=Qs;exports.hasSearchOptions=Wa;exports.isLayoutName=Ql;exports.isThemeName=ql;exports.measureText=pt;exports.mergeVolumeResources=$i;exports.normalizeEra=Oe;exports.normalizeLayout=Pn;exports.normalizeRole=Ai;exports.normalizeTheme=Mn;exports.normalizeVolumeIndex=Jt;exports.normalizeVolumes=qr;exports.numberToChinese=ws;exports.paginationItems=Pl;exports.parseChineseNumber=jn;exports.parseGujiInline=zs;exports.parseGujiTable=tl;exports.parseSourceString=ml;exports.pickReaderVersion=Js;exports.readStoredLayout=kf;exports.readStoredTheme=jf;exports.readerVersionOptionLabel=xi;exports.readerVersionsFromFullText=qs;exports.renderFullTextBody=op;exports.renderProperNames=al;exports.renderReaderInline=qi;exports.resourceHref=At;exports.resourceNote=Rn;exports.roleFacets=vs;exports.rowNo=Sd;exports.sameFilters=Da;exports.sortFor=Ma;exports.sortYear=vn;exports.splitFullTextTables=Ui;exports.splitHighlightSnippet=wi;exports.splitTableRow=el;exports.storeLayout=wf;exports.storeTheme=Jl;exports.stringifySources=gl;exports.toCatalogWorkCard=af;exports.typeSupportsFilters=ts;exports.useBidUrl=Fe;exports.useConvert=V;exports.useReaderPrefs=Hi;exports.useT=me;exports.validateLineageGraph=_x;exports.volumeStats=Sn;