book-index-ui 0.22.1 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,21 +1,21 @@
1
- "use strict";var kl=Object.create;var ro=Object.defineProperty;var Sl=Object.getOwnPropertyDescriptor;var wl=Object.getOwnPropertyNames;var _l=Object.getPrototypeOf,$l=Object.prototype.hasOwnProperty;var zl=(e,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of wl(n))!$l.call(e,s)&&s!==i&&ro(e,s,{get:()=>n[s],enumerable:!(r=Sl(n,s))||r.enumerable});return e};var an=(e,n,i)=>(i=e!=null?kl(_l(e)):{},zl(n||!e||!e.__esModule?ro(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const we=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),f=require("react"),Cl=require("opencc-js/t2cn"),Il=require("react-markdown"),Tl=require("remark-gfm"),El=e=>`/book-index?id=${e}`,hr=f.createContext(El);function Rl({buildUrl:e,children:n}){const i=f.useMemo(()=>e,[e]);return t.jsx(hr.Provider,{value:i,children:n})}function Pe(){return f.useContext(hr)}const br="",yr="";function jr(e){const n=[];let i=!1,r=e;for(;r.length;){const s=i?yr:br,l=r.indexOf(s);if(l===-1){n.push({text:r,marked:i});break}l>0&&n.push({text:r.slice(0,l),marked:i}),r=r.slice(l+1),i=!i}return n}function He(e,n){return{title:e,tokens:n}}const so='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Nl=[He("基础(VS Code 环境下跟随 --vscode-*)",{bg:{value:"#ffffff",vscode:"--vscode-editor-background"},fg:{value:"#333333",vscode:"--vscode-foreground"},"input-bg":{value:"#ffffff",vscode:"--vscode-input-background"},"input-fg":{value:"#333333",vscode:"--vscode-input-foreground"},"input-border":{value:"#cccccc",vscode:"--vscode-input-border"},"widget-border":{value:"#e0e0e0",vscode:"--vscode-widget-border"},"link-fg":{value:"#0066cc",vscode:"--vscode-textLink-foreground"},"desc-fg":{value:"#717171",vscode:"--vscode-descriptionForeground"},primary:{value:"#0078d4",vscode:"--vscode-button-background"},"primary-fg":{value:"#ffffff",vscode:"--vscode-button-foreground"},"primary-soft":{value:"rgba(0, 120, 212, 0.15)",css:"color-mix(in srgb, var(--bim-primary) 15%, transparent)"},danger:{value:"#f44336"},warning:{value:"#ff9800"},success:{value:"#4caf50"},"sidebar-bg":{value:"#f3f3f3",vscode:"--vscode-sideBar-background"},"list-hover-bg":{value:"rgba(0, 0, 0, 0.04)",vscode:"--vscode-list-hoverBackground"},"list-active-bg":{value:"rgba(0, 120, 212, 0.1)",vscode:"--vscode-list-activeSelectionBackground"},"focus-border":{value:"#0078d4",vscode:"--vscode-focusBorder"}}),He("底色层次 / 文字与描边 / 链接",{"bg-subtle":{value:"#fafafa"},"widget-bg":{value:"#f8f8f8"},muted:{value:"#888888"},border:{value:"#e5e5e5"},"primary-bg":{value:"#fdf4f4"},link:{value:"#1976d2"},"tag-bg":{value:"#f0f0f0"},"accent-bg":{value:"#1976d2"},"on-color-fg":{value:"#ffffff",note:"彩色底(徽章、选中态按钮)上的文字"}}),He("提示与警告",{"info-fg":{value:"#0c5380"},"info-bg":{value:"#e7f3ff"},"info-border":{value:"#b3dbff"},"warn-fg":{value:"#856404"},"warn-bg":{value:"#fff3cd"},"warn-border":{value:"#ffc107"},"danger-bg":{value:"rgba(244, 67, 54, 0.08)",note:"错误提示条底色"},"danger-soft-bg":{value:"rgba(244, 67, 54, 0.03)",note:"编辑器危险区块"},"danger-soft-border":{value:"rgba(244, 67, 54, 0.13)"}}),He("遮罩与阴影",{backdrop:{value:"rgba(0, 0, 0, 0.5)",note:"对话框遮罩"},"overlay-bg":{value:"#00000010",note:"轻量遮罩底(图片占位等)"},"shadow-dialog":{value:"0 4px 20px rgba(0, 0, 0, 0.3)"},"shadow-dropdown":{value:"0 4px 12px rgba(0, 0, 0, 0.1)"},"shadow-tooltip":{value:"0 2px 8px rgba(0, 0, 0, 0.08)"},"shadow-fab":{value:"0 2px 8px rgba(0, 0, 0, 0.25)",note:"悬浮按钮(反馈)"},"shadow-card":{value:"0 1px 4px rgba(0, 0, 0, 0.06)",note:"展开的卡片"},"shadow-node":{value:"0 1px 3px rgba(0, 0, 0, 0.1)",note:"谱系图节点"},"shadow-node-selected":{value:"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)"}}),He("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),He("资源",{"restype-text":{value:"#2196f3"},"restype-image":{value:"#ff9800"},"restype-text-image":{value:"#9c27b0"},"restype-physical":{value:"#795548"},"missing-fg":{value:"#e67e22",note:"资源缺册提示"},"colormode-bw-bg":{value:"#f5f5f5",note:"影印件色彩模式标记(黑白 / 彩色)"},"colormode-bw-fg":{value:"#757575"},"colormode-color-bg":{value:"#fff8e1"},"colormode-color-fg":{value:"#f57f17"},"progress-active":{value:"#f59e0b",note:"资源导入进度"},"progress-done":{value:"#10b981"},"progress-todo":{value:"#9ca3af"},"check-fine-bg":{value:"#e8f5e9",note:"文字资源校对程度徽章(精校 / 粗校 / AI整理)"},"check-fine-fg":{value:"#2e7d32"},"check-rough-bg":{value:"#fff3e0"},"check-rough-fg":{value:"#e65100"},"check-ai-bg":{value:"#e3f2fd"},"check-ai-fg":{value:"#1565c0"}}),He("整理本(CollatedEdition)",{"highlight-bg":{value:"#fff59d",note:"搜索命中高亮底"},"highlight-fg":{value:"inherit",root:!1},"section-lei":{value:"#8e6f3e",note:"章节类型标记:类 / 书 / 序 / 结语 / 考证 / 注释"},"section-shu":{value:"#c0392b"},"section-xu":{value:"#1a5276"},"section-jieyu":{value:"#7d6608"},"section-kaozhen":{value:"#5d6d7e"},"section-zhushi":{value:"#6c5b7b"},"section-tag-fg":{value:"#e74c3c",note:"章节标记(△ 等)"},"matchstate-fg":{value:"#b78900",note:"与底本匹配状态提示"},"quality-published":{value:"#1b5e20",note:"文本质量等级(出版 / 精校 / 粗校 / OCR)"},"quality-fine":{value:"#2e7d32"},"quality-rough":{value:"#1565c0"},"quality-ocr":{value:"#e65100"}}),He("版本传承(VersionLineageGraph / List) / 关系方向(RelationPanel)",{"lost-fg":{value:"#c62828",note:"佚失标记"},"confidence-certain":{value:"#2e7d32",note:"关系置信度"},"confidence-consensus":{value:"#1976d2"},"confidence-probable":{value:"#ed6c02"},"confidence-disputed":{value:"#c62828"},"lineage-edge-consensus":{value:"#555555",note:"⚠️ 同为 consensus,List 徽章用 --bim-confidence-consensus(蓝),Graph 连线用这个(灰)。若要统一,覆盖成 var(--bim-confidence-consensus)"},"relation-up":{value:"#2196f3"},"relation-down":{value:"#4caf50"},"relation-flat":{value:"#ff9800"}}),He("编辑器视图(主要在 guji-platform 插件中可见)",{"editor-type-work":{value:"#4caf50",note:"⚠️ 与展示视图的 --bim-type-* 是两套配色(历史如此)。若要统一,覆盖成对应的 var(--bim-type-*)"},"editor-type-collection":{value:"#2196f3"},"editor-type-book":{value:"#ff9800"},"editor-type-entity":{value:"#9c27b0"},"source-url":{value:"#2196f3",note:"来源类型(SourceEditor)"},"source-bookid":{value:"#4caf50"},"mode-active-bg":{value:"#2196f3",note:"模式指示器当前态(ModeIndicator)"},"cover-accent":{value:"#8e6f3e",note:'书目卡片「封面」点缀(IndexBrowser resultVariant="card")'}}),He("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --bim-primary 等控件色",{"page-bg":{value:"#fbf9f3",note:"纸"},"row-hover-bg":{value:"#f5f1e5"},"selection-bg":{value:"#ecdcbc",note:"选区"},"band-bg":{value:"#f0e4cb",note:"全文入口横幅(暖沙)"},"band-bg-hover":{value:"#e6d5b4"},ink:{value:"#2a231c",note:"文字层次:墨 → 正文 → 提要 → meta → 标签 → 提示"},"body-fg":{value:"#3b3228"},"quiet-fg":{value:"#5b4f40"},"meta-fg":{value:"#7b6a54"},"label-fg":{value:"#6f6457",note:"标签 / 提示:2026-09 N3a 调深,纸底与斑马底上对比度均 ≥4.5(原 #a3937b 2.8、#b3a385 2.3)"},"hint-fg":{value:"#756a5e"},accent:{value:"#9c3a2c",note:"朱"},"accent-deep":{value:"#6f2a20",note:"链接 hover"},"rule-strong":{value:"#2a231c",note:"分隔线:强 → 常规 → 虚线 → 提要左线"},rule:{value:"#e4dbc9"},"rule-dashed":{value:"#d6c9ae"},"rule-accent-soft":{value:"#e0d3b6"},"aux-fg":{value:"#6f6457",note:"辅助字(元数据、注记、「·」分隔的浅色小字)。须在 page-bg / zebra-bg 上对比度 ≥4.5(Q5 巡检)"},"card-bg":{value:"#fffdf9",note:"提要卡:抬起的面"},"zebra-bg":{value:"#f6f2eb",note:"表格斑马纹 / 左栏分组底(不画格线,靠这一阶底色分行)"},"tint-bg":{value:"#f3eee6",note:"检索框、悬停"},"shadow-summary":{value:"0 10px 32px rgba(60, 50, 40, 0.07)",note:"提要卡投影"},"flag-bg":{value:"rgba(158, 42, 43, 0.08)",note:"唯一的状态色块「有影印」"},"theme-dot-zhusha":{value:"#9c3a2c",note:"主题切换控件的色点:朱砂(不随主题变,两套主题下都要认得出)"},"theme-dot-indigo":{value:"#2e5266",note:"主题切换控件的色点:靛蓝"},"sect-jing":{value:"#2e5266",note:"四部分布条:經部(人物页提要卡;无别处使用)"},"sect-shi":{value:"#9a7a3b",note:"四部分布条:史部"},"sect-zi":{value:"#4f7a5c",note:"四部分布条:子部"},"sect-ji":{value:"#9fb3bc",note:"四部分布条:集部"},"table-border":{value:"color-mix(in srgb, currentColor 28%, transparent)",root:!1,note:"古籍表格(跟随当前文字色)"},"table-head-bg":{value:"color-mix(in srgb, currentColor 8%, transparent)",root:!1}}),He("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),He("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),He("字体(全站无衬线,2026-09-05 定)",{"font-ui":{value:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif'},"font-body":{value:"system-ui, sans-serif",css:"var(--bim-font-ui)"},"font-serif":{value:so,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:so,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Ll=Object.assign({},...Nl.map(e=>e.tokens)),vr={};for(const[e,n]of Object.entries(Ll))vr[e]=`var(--bim-${e}, ${n.value})`;function o(e){const n=vr[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function yt(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function Bl(e,n){return yt(e).includes(n)}const Hn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Al={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};o("quality-published"),o("quality-fine"),o("quality-rough"),o("quality-ocr");const Rt=f.createContext(null),kr={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:o("check-fine-bg"),fg:o("check-fine-fg")},粗校:{label:"粗校",bg:o("check-rough-bg"),fg:o("check-rough-fg")},AI整理:{label:"AI整理",bg:o("check-ai-bg"),fg:o("check-ai-fg")}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入叢編",collectedIn:"收入叢編",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評註",studies:"所考典籍"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"結果分類",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"概覽",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄",fullText:"全文",lineage:"版本傳承",feedback:"勘誤反饋",dataSource:"數據源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"數據源與授權"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},workSubtype:{book:"書",article:"篇",poem:"詩",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},Wl={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:o("check-fine-bg"),fg:o("check-fine-fg")},粗校:{label:"粗校",bg:o("check-rough-bg"),fg:o("check-rough-fg")},AI整理:{label:"AI整理",bg:o("check-ai-bg"),fg:o("check-ai-fg")}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入丛编",collectedIn:"收入丛编",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评注",studies:"所考典籍"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"结果分类",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"概览",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录",fullText:"全文",lineage:"版本传承",feedback:"勘误反馈",dataSource:"数据源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"数据源与授权"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},workSubtype:{book:"书",article:"篇",poem:"诗",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},Ml=["曹霑"];function Fl(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Pl(e,n=Ml){const i=[...new Set(n.filter(Boolean))].sort((l,a)=>a.length-l.length);if(!i.length)return e;const r=new RegExp(`(${i.map(Fl).join("|")})`,"g"),s=new Set(i);return l=>{if(!l)return e(l);const a=l.split(r);return a.length===1?e(l):a.map((p,c)=>c%2===1&&s.has(p)?p:p&&e(p)).join("")}}let At=null;function Ol(){if(At)return At;try{At=Pl(Cl.Converter({from:"tw",to:"cn"}))}catch{At=e=>e}return At}const Dl={"zh-Hant":kr,"zh-Hans":Wl},Sr="bim-locale";function Hl(){try{const e=localStorage.getItem(Sr);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Gl(e){try{localStorage.setItem(Sr,e)}catch{}}const Ul="zh-Hans",Vl=({locale:e,onLocaleChange:n,converter:i,children:r})=>{const[s,l]=f.useState(e??Ul),a=e??s;f.useEffect(()=>{if(e)return;const u=Hl();u&&u!==s&&l(u)},[]);const p=f.useMemo(()=>a==="zh-Hans"?i??Ol():null,[a,i]),c=f.useCallback(u=>{l(u),Gl(u),n==null||n(u)},[n]),d=f.useMemo(()=>({locale:a,setLocale:c,messages:Dl[a],converter:p}),[a,c,p]);return t.jsx(Rt.Provider,{value:d,children:r})};function ue(){const e=f.useContext(Rt);return(e==null?void 0:e.messages)??kr}const Yl=2e3;function q(){const e=f.useContext(Rt),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const l=f.useCallback(a=>{if(!a)return"";if(!i)return a;const p=r.current.get(a);if(p!==void 0)return p;const c=i(a);if(r.current.size>=Yl){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(a,c),c},[i]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Kt(e,n){return e.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function ql(e){if(!e)return"";try{const n=new URL(e).hostname,i={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(i[n])return i[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function Kl(){return{id:"",name:"",url:"",type:"text",details:""}}const Gn=({items:e,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const l=ue(),[a,p]=f.useState(null),c=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],d=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=j=>{if(!s)return!0;const k=yt(j);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},g=e.map((j,k)=>({item:j,originalIndex:k})).filter(({item:j})=>u(j)),x=()=>{const j=Kl();s&&(j.type=s),n([...e,j]),p(e.length)},m=j=>{n(e.filter((k,$)=>$!==j)),p(null)},b=(j,k,$)=>{const v=[...e];if(v[j]={...v[j],[k]:$},k==="url"&&!v[j].id){const _=ql($);_&&(v[j].id=_)}n(v)},S=(j,k,$)=>{const _={...e[j].metadata||{}};$?_[k]=$:delete _[k],b(j,"metadata",Object.keys(_).length>0?_:void 0)},h=(j,k)=>{const $=k.trim()?k.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;b(j,"structure",$)},y=(j,k,$)=>{const _=e[j].coverage||{level:1,ranges:""};k==="level"?_.level=parseInt($)||1:_.ranges=$,b(j,"coverage",_.ranges?_:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[g.map(({item:j,originalIndex:k})=>{var $,v,_;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(a===k?null:k),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===k?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Jl(j.type??"text"),color:o("on-color-fg")},children:(()=>{var z,N;const w=yt(j);return w.length===0?j.type??"text":w.length===1?((z=c.find(T=>T.value===w[0]))==null?void 0:z.label)??w[0]:w.includes("text")&&w.includes("image")?((N=c.find(T=>T.value==="text+image"))==null?void 0:N.label)??"text+image":w.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:j.name||`${l.editor.resourcePlaceholder} ${k+1}`}),j.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:j.id}),j.url&&t.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",onClick:w=>w.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&j.url&&Zl(k,r==null?void 0:r[k],i,l),t.jsx("button",{onClick:w=>{w.stopPropagation(),m(k)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),a===k&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:[Bl(j,"image")&&j.url&&Xl(j,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.type}),t.jsx("select",{value:j.type,onChange:w=>b(k,"type",w.target.value),style:{...et,flex:1},children:c.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]}),t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.rootType}),t.jsx("select",{value:j.root_type||"catalog",onChange:w=>b(k,"root_type",w.target.value),style:{...et,flex:1},children:d.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:j.id,onChange:w=>b(k,"id",w.target.value),placeholder:l.editor.idAutoExtract,style:{...et,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:j.name,onChange:w=>b(k,"name",w.target.value),placeholder:l.editor.resourceName,style:{...et,flex:1}})]}),t.jsx("input",{type:"text",value:j.url,onChange:w=>b(k,"url",w.target.value),placeholder:l.editor.resourceUrl,style:et}),t.jsx("input",{type:"text",value:(($=j.structure)==null?void 0:$.join("、"))||"",onChange:w=>h(k,w.target.value),placeholder:l.editor.structurePlaceholder,style:et}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Wt,children:[t.jsx("span",{style:Mt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((v=j.coverage)==null?void 0:v.level)??"",onChange:w=>y(k,"level",w.target.value),placeholder:"1",style:{...et,width:"60px"}})]}),t.jsxs("label",{style:{...Wt,flex:1},children:[t.jsx("span",{style:Mt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:((_=j.coverage)==null?void 0:_.ranges)||"",onChange:w=>y(k,"ranges",w.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...et,flex:1}})]})]}),t.jsx("textarea",{value:j.details||"",onChange:w=>b(k,"details",w.target.value),placeholder:l.editor.detailsPlaceholder,style:{...et,minHeight:"60px",resize:"vertical"}}),t.jsxs("div",{style:{borderTop:`1px solid ${o("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"6px"},children:l.label.metadata}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([w,z])=>{var N;return t.jsxs("label",{style:{...Wt,gap:"4px"},children:[t.jsx("span",{style:{...Mt,minWidth:"56px"},children:z}),t.jsx("input",{type:"text",value:((N=j.metadata)==null?void 0:N[w])||"",onChange:T=>S(k,w,T.target.value),placeholder:z,style:{...et,flex:1}})]},w)})})]})]})]})]},k)}),t.jsxs("button",{onClick:x,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:l.action.addResource})]})]})};function Jl(e){switch(e){case"text":return o("restype-text");case"image":return o("restype-image");case"text+image":return o("restype-text-image");case"physical":return o("restype-physical")}}function Zl(e,n,i,r){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:a=>{a.stopPropagation(),s||i(e,"")},disabled:s,style:{background:"transparent",border:"none",color:o(l?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:l?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":s?"⏳":"⬇"})}function Xl(e,n){const i=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(e.url)||e.url.includes("iiif")||e.url.includes("image");return t.jsx("div",{style:{marginBottom:"12px"},children:i?t.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:o("overlay-bg")},children:t.jsx("img",{src:e.url,alt:e.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):t.jsx("div",{style:{padding:"12px",background:o("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:o("desc-fg")},children:n.editor.imageResourceLink})})}const et={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Wt={display:"flex",alignItems:"center",gap:"6px"},Mt={fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap"},Ql={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive","www.shuge.org":"書格","shuge.org":"書格","pan.baidu.com":"百度網盤"};function Nt(e){try{return Ql[new URL(e).hostname]}catch{return}}const lo={text:0,image:1,physical:2};function ci(e){return e.length===0?"physical":[...e].sort((n,i)=>(lo[n]??99)-(lo[i]??99)).join("+")}function di(e){var a;const n=p=>{const c=p.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const d=p.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},i=new Map;for(let p=0;p<e.length;p++){const c=e[p];if(c.volumes&&c.volumes.length>0)continue;const d=n(c.name);if(!d)continue;const[u,g]=d,x=`${u}|${ci(yt(c))}`;i.has(x)||i.set(x,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const m=i.get(x);m.volumes.push({volume:g,url:c.url||void 0,status:"found"}),m.indices.push(p)}const r=[],s=new Set;for(const p of i.values())if(!(p.volumes.length<2)){p.volumes.sort((c,d)=>c.volume-d.volume),p.base.volumes=p.volumes,p.base.expected_volumes=p.volumes.length,p.base.url||(p.base.url=((a=p.volumes.find(c=>c.url))==null?void 0:a.url)??""),r.push(p.base);for(const c of p.indices)s.add(c)}const l=[...r];for(let p=0;p<e.length;p++)s.has(p)||l.push(e[p]);return l}function wr(e){if(e.url)return e.url;for(const[n,i]of Object.entries(e))if(n.endsWith("_url")&&typeof i=="string")return i}function _r(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||wr(n)}))}function bn(e){const n=_r(e);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,r=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:r,expected:e.expected_volumes??i+r}}function pi(e){if(!e)return;const n=e.file_page_range||e.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function ui(e,n){try{if(new URL(e).hostname.includes("wikimedia.org")){const r=e.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const s=new URL(e);return s.searchParams.set("page",String(n)),s.toString()}return e}catch{return e}}function Lt(e){if(!e.url)return;const n=pi(e.metadata);return n?ui(e.url,n):e.url}const ao={text:o("restype-text"),image:o("restype-image"),"text+image":o("restype-text-image"),physical:o("restype-physical")};function ea(e){return e.includes("text")&&e.includes("image")?ao["text+image"]:ao[e[0]||"physical"]}const xi=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const l=ue(),{convert:a}=q(),p=f.useMemo(()=>di(e||[]),[e]),{mirrorGroups:c,ungroupedItems:d}=f.useMemo(()=>{const h=new Map,y=[];for(const j of p){const k=j.group;k?(h.has(k)||h.set(k,[]),h.get(k).push(j)):y.push(j)}for(const j of h.values())j.sort((k,$)=>{const v=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return v(k)-v($)});return{mirrorGroups:h,ungroupedItems:y}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},g=h=>u[h]?u[h]:h.split("+").map(y=>u[y]||y).join("+");if(!p||p.length===0)return t.jsx("div",{style:{padding:"16px",color:o("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((h,y)=>t.jsx(En,{item:h},h.id||y))});const x=(h,y)=>{const j=i==null?void 0:i[h],k=(j==null?void 0:j.label)||h,$=j==null?void 0:j.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:a(k)}),$&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.5},children:a($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:y.map((v,_)=>t.jsx(En,{item:v,onNavigate:r,renderLink:s},v.id||_))})]},`group-${h}`)},m=new Map;for(const h of d){const y=ci(yt(h));m.has(y)||m.set(y,[]),m.get(y).push(h)}const b=["text","image","text+image","physical"],S=[...b.filter(h=>m.has(h)),...[...m.keys()].filter(h=>!b.includes(h)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([h,y])=>x(h,y)),S.map(h=>{const y=m.get(h),j=ea(h.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:j,whiteSpace:"nowrap",flexShrink:0},children:g(h)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:y.map((k,$)=>t.jsx(En,{item:k,onNavigate:r,renderLink:s},k.id||$))})]},h)})]})},ta={bw:{label:"",bg:o("colormode-bw-bg"),fg:o("colormode-bw-fg")},color:{label:"",bg:o("colormode-color-bg"),fg:o("colormode-color-fg")}},En=({item:e})=>{const n=ue(),{convert:i}=q(),[r,s]=f.useState(!1),l=f.useMemo(()=>(e.url?Nt(e.url):void 0)||i(e.name),[e.url,e.name,i]),a=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(b=>({...b,url:b.url||wr(b)})),[e.volumes]),p=a&&a.length>0,c=p?new Set(a.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=p?new Set(a.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=e.expected_volumes??(p?c+d:0),g=e.color_mode?{...ta[e.color_mode],label:n.colorMode[e.color_mode]}:null,x=e.details&&!p?i(e.details):null,m={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",background:o("input-bg"),fontSize:"12px",color:o("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:m,children:[t.jsx("span",{style:{fontWeight:500},children:l}),g&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:g.bg,color:g.fg},children:g.label}),x&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:x}),p&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[c,"/",u,n.unit.volume,d>0&&t.jsxs("span",{style:{color:o("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),e.url&&t.jsx("a",{href:(()=>{const b=pi(e.metadata);return b?ui(e.url,b):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:o("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),p&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),p&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:a.map(b=>{const S=b.status==="missing";return b.url&&!S?t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${o("widget-border")}`,color:o("link-fg"),textDecoration:"none"},children:b.volume},b.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:o(S?"missing-fg":"desc-fg"),textDecoration:S?"line-through":"none",opacity:S?.6:1},children:b.volume},b.volume)})})]})},$r=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:a})=>{const p=ue(),c=e==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",g=u?u.split(/[/\\]/).pop()||u:"",x={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:o("primary-soft"),color:o("primary")},m={onMouseOver:S=>S.currentTarget.style.opacity="0.8",onMouseOut:S=>S.currentTarget.style.opacity="1"},b=t.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...x,background:o(d?"warning":"success"),color:o("on-color-fg")},...m,children:[t.jsx("span",{children:d?"📝":"📚"}),t.jsx("span",{children:d?"draft":"official"})]});return i==="index-browser"?c?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,t.jsxs("div",{onClick:r,title:p.mode.switchToSync,style:x,...m,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:p.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px"},...m,children:[t.jsx("span",{children:"📂"}),g&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:g})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:p.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:g||p.mode.configurePath,style:{...x,background:"transparent",padding:"6px",fontSize:"12px"},...m,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:c?p.mode.switchToGithub:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:c?"📁":"🌐"}),t.jsx("span",{children:c?p.mode.localMode:p.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&t.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...m,children:[t.jsx("span",{children:"📂"}),g&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:g})]}),!c&&g&&t.jsxs("div",{style:{...x,background:o("mode-active-bg"),color:o("on-color-fg"),cursor:"default"},title:u,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:g})]})]})},yn="bim-search-history",co=10,po=8;function Gt(){try{const e=localStorage.getItem(yn);return e?JSON.parse(e):[]}catch{return[]}}function na(e){try{const n=Gt().filter(i=>i!==e);n.unshift(e),n.length>co&&(n.length=co),localStorage.setItem(yn,JSON.stringify(n))}catch{}}function ia(e){try{const n=Gt().filter(i=>i!==e);localStorage.setItem(yn,JSON.stringify(n))}catch{}}function oa(){try{localStorage.removeItem(yn)}catch{}}const zr=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:l})=>{const a=ue(),p=l??a.search.placeholder,c={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,u]=f.useState(!1),[g,x]=f.useState([]),[m,b]=f.useState(-1),[S,h]=f.useState(Gt),y=f.useRef(null),j=f.useRef(null),k=f.useRef(null),$=f.useRef(!1);f.useEffect(()=>{b(-1);const C=n.trim();if(!C){x(S.map(A=>({type:"history",text:A})));return}if(!e.searchAll){x([]);return}let P=!1;const B=setTimeout(()=>{e.searchAll(C,po).then(A=>{if(P)return;const W=[...A.works,...A.books,...A.collections,...A.entities??[]];x(W.slice(0,po).map(V=>({type:"entry",text:V.title||V.id,entry:V})))}).catch(()=>{P||x([])})},80);return()=>{P=!0,clearTimeout(B)}},[n,S,e]),f.useEffect(()=>{const C=P=>{k.current&&!k.current.contains(P.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=P=>{var B,A;if(P.key==="/"&&document.activeElement!==y.current){const W=(B=document.activeElement)==null?void 0:B.tagName;if(W==="INPUT"||W==="TEXTAREA"||W==="SELECT")return;P.preventDefault(),(A=y.current)==null||A.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const v=f.useCallback(C=>{C.trim()&&(na(C.trim()),h(Gt())),r(C),u(!1)},[r]),_=f.useCallback(C=>{C.type==="history"?(i(C.text),v(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(i(C.text),v(C.text)))},[i,v,s]),w=f.useCallback(C=>{if(!d||g.length===0){C.key==="Enter"&&v(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(P=>(P+1)%g.length);break;case"ArrowUp":C.preventDefault(),b(P=>(P-1+g.length)%g.length);break;case"Enter":C.preventDefault(),m>=0&&m<g.length?_(g[m]):v(n);break;case"Escape":C.preventDefault(),u(!1);break}},[d,g,m,n,v,_]),z=f.useCallback((C,P)=>{P.stopPropagation(),ia(C),h(Gt()),x(B=>B.filter(A=>!(A.type==="history"&&A.text===C)))},[]),N=f.useCallback(C=>{C.stopPropagation(),oa(),h([]),x([])},[]);f.useEffect(()=>{if(m>=0&&j.current){const C=j.current.children;C[m]&&C[m].scrollIntoView({block:"nearest"})}},[m]);const T=!n.trim()&&S.length>0;return t.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:y,type:"text",placeholder:p,value:n,onChange:C=>{i(C.target.value),u(!0)},onCompositionStart:()=>{$.current=!0},onCompositionEnd:()=>{$.current=!1},onFocus:()=>{u(!0)},onKeyDown:w,style:{width:"100%",padding:"8px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),d&&g.length>0&&t.jsxs("div",{ref:j,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:o("input-bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"6px",boxShadow:o("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[T&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:o("desc-fg"),borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("span",{children:a.search.history}),t.jsx("button",{onClick:N,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),g.map((C,P)=>t.jsxs("div",{onClick:()=>_(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:o("fg"),background:P===m?o("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:[c[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&t.jsx("button",{onClick:B=>z(C.text,B),style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${C.type}-${C.text}-${P}`))]})]})},jn=({type:e,size:n=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:n,borderRadius:1,flex:"none",background:o(`type-${e}`),verticalAlign:"middle"}}),Ct="bim-recent-ids",uo="bim-recent-entries",xo=50,Rn=5,ra=50,sa=200;function _t(){try{const e=localStorage.getItem(Ct);if(e)return JSON.parse(e);const n=localStorage.getItem(uo);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Ct,JSON.stringify(i)),localStorage.removeItem(uo),i}return[]}catch{return[]}}function fo(e){try{const n=_t().filter(i=>i!==e);n.unshift(e),n.length>xo&&(n.length=xo),localStorage.setItem(Ct,JSON.stringify(n))}catch{}}function la(e){try{const n=_t().filter(i=>i!==e);localStorage.setItem(Ct,JSON.stringify(n))}catch{}}function aa(){try{localStorage.removeItem(Ct)}catch{}}const go={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Un=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c,hideModeIndicator:d,resultVariant:u="compact",renderEntry:g,initialQuery:x,onQueryChange:m,headerRight:b,reserveViewportHeight:S=!1})=>{const h=ue(),y=[{type:"work",name:h.indexType.work,key:"works"},{type:"book",name:h.indexType.book,key:"books"},{type:"collection",name:h.indexType.collection,key:"collections"},{type:"entity",name:h.indexType.entity,key:"entities"}],j=["work","collection","book","entity"],[k,$]=f.useState(x??""),[v,_]=f.useState(null),[w,z]=f.useState(null),[N,T]=f.useState("all"),[C,P]=f.useState(!1),[B,A]=f.useState(null),[W,V]=f.useState(""),[K,E]=f.useState(!(x!=null&&x.trim())),[le,G]=f.useState(_t),[ae,pe]=f.useState([]),[ee,X]=f.useState(!1),[ie,me]=f.useState(!1),[te,se]=f.useState(null),[fe,be]=f.useState(null),ze=f.useRef(void 0),ve=f.useRef(!1),ke=f.useCallback(async(M,ne)=>{if(!M.trim()){E(!0),_(null),z(null);return}E(!1),P(!0),V("");try{if(e.searchAll){const R=await e.searchAll(M,ne??Rn);_(R)}else{const R=["work","book","collection","entity"],J=await Promise.all(R.map(H=>e.search(M,H,{page:1,pageSize:ne??Rn})));_({works:J[0].entries,books:J[1].entries,collections:J[2].entries,entities:J[3].entries,totalWorks:J[0].total,totalBooks:J[1].total,totalCollections:J[2].total,totalEntities:J[3].total})}}catch(R){V(R instanceof Error?R.message:String(R)),_(null)}finally{P(!1)}},[e]);f.useEffect(()=>{let M=!1;const ne=()=>{var re,Se;const R=["work","book","collection","entity"],J=Promise.all(R.map(ye=>e.loadEntries(ye,{page:1,pageSize:1}).catch(()=>({total:0})))),H=((re=e.getResourceCounts)==null?void 0:re.call(e).catch(()=>null))??Promise.resolve(null),U=((Se=e.getSubtypeStats)==null?void 0:Se.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([J,H,U]).then(([ye,Le,Ye])=>{M||(se({works:ye[0].total,books:ye[1].total,collections:ye[2].total,entities:ye[3].total,hasText:Le==null?void 0:Le.hasText,hasImage:Le==null?void 0:Le.hasImage}),Ye&&be(Ye))})};return e.getCounts?e.getCounts().then(R=>{var J,H;M||(se({works:R.works,books:R.books,collections:R.collections,entities:R.entities,hasText:(J=R.resourceCounts)==null?void 0:J.hasText,hasImage:(H=R.resourceCounts)==null?void 0:H.hasImage}),R.subtypeStats&&be(R.subtypeStats))}).catch(()=>{M||ne()}):ne(),()=>{M=!0}},[e]),f.useEffect(()=>{ve.current||!(x!=null&&x.trim())||(ve.current=!0,ke(x))},[x,ke]);const Ne=f.useCallback(M=>{if($(M),!M.trim()){m==null||m(M),E(!0),_(null),z(null),T("all");return}ze.current&&clearTimeout(ze.current),ze.current=setTimeout(()=>{z(null),T("all"),m==null||m(M),ke(M)},sa)},[ke,m]),Ee=f.useCallback(M=>{ze.current&&clearTimeout(ze.current),T("all"),m==null||m(M),ke(M)},[ke,m]),O=f.useCallback(M=>{z(M),ke(k,ra)},[k,ke]);f.useEffect(()=>{if(!le.length){pe([]);return}let M=!1;return X(!0),Promise.all(le.slice(0,10).map(async ne=>{var R,J,H;try{if(e.getEntry){const re=await e.getEntry(ne);if(re)return re}const U=await e.getItem(ne);if(U){const re=U.authors;return{id:ne,title:U.title||ne,type:U.type||"work",author:(R=re==null?void 0:re[0])==null?void 0:R.name,dynasty:(J=re==null?void 0:re[0])==null?void 0:J.dynasty,role:(H=re==null?void 0:re[0])==null?void 0:H.role,edition:U.edition||void 0}}}catch{}return{id:ne,title:ne,type:"work",notFound:!0}})).then(ne=>{M||(pe(ne),X(!1))}),()=>{M=!0}},[le,e]);const ce=M=>{A(M.id),fo(M.id),G(_t()),r==null||r(M)},oe=(M,ne)=>{if(r&&da(ne)){ne.preventDefault(),ce(M);return}fo(M.id),G(_t())},he=M=>{la(M),G(_t())},Z=()=>{aa(),G([])},F=M=>y.find(ne=>ne.type===M),I=!K&&!v&&!W,D=v&&(v.works.length>0||v.books.length>0||v.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",style:S?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:pa}),t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("h1",{style:{margin:0,fontSize:"18px",color:o("fg")},children:h.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&t.jsx($r,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(zr,{transport:e,value:k,onChange:Ne,onSearch:Ee,onEntrySelect:ce}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${o("primary")}`,borderRadius:"6px",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"13px"},children:h.action.newEntry})]}),K&&t.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:te&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:fe?t.jsxs(t.Fragment,{children:[(fe.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:o("fg")},children:fe.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:o("fg")},children:te.books.toLocaleString()})," 本"]}),fe.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:o("fg")},children:fe.article.toLocaleString()})," 篇"]}):null,fe.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:o("fg")},children:fe.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:o("fg")},children:te.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[h.indexType.work," ",t.jsx("strong",{style:{color:o("fg")},children:te.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.book," ",t.jsx("strong",{style:{color:o("fg")},children:te.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.collection," ",t.jsx("strong",{style:{color:o("fg")},children:te.collections.toLocaleString()}),te.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.entity," ",t.jsx("strong",{style:{color:o("fg")},children:te.entities.toLocaleString()})]})]})}),te.hasImage!=null&&te.hasText!=null&&t.jsxs("span",{children:[h.resourceType.image," ",t.jsx("strong",{style:{color:o("fg")},children:te.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.resourceType.text," ",t.jsx("strong",{style:{color:o("fg")},children:te.hasText.toLocaleString()})]})]})}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:C||I?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg"),minHeight:ca,boxSizing:"border-box"},children:h.search.searching}):W?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:o("desc-fg")},children:W})}):K?t.jsx("div",{style:{flex:1},children:ee?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:h.search.loading}):ae.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:h.search.recentBrowse}),t.jsx("button",{onClick:Z,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:h.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:ae.slice(0,ie?10:3).map(M=>M.notFound?t.jsx(ga,{id:M.id,onRemove:he,t:h},M.id):t.jsx(mo,{entry:M,selected:B===M.id,onClick:oe,getConfig:F,onRemove:he},M.id))}),!ie&&ae.length>3&&t.jsx("button",{onClick:()=>me(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:h.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:h.search.searchTitle}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:h.search.searchSubtitle})]})}):D?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:ua}),(()=>{const M=U=>v[go[U]]??0,ne=j.map(U=>y.find(re=>re.type===U)).filter(U=>M(U.key)>0);if(ne.length<2)return null;const R=ne.reduce((U,re)=>U+M(re.key),0),J=U=>{if(T(U),U!=="all"&&w!==U){const re=y.find(ye=>ye.type===U),Se=(v[re.key]??[]).length;M(re.key)>Se&&O(U)}},H=U=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:o(U?"fg":"desc-fg"),fontWeight:U?700:400,boxShadow:U?`inset 0 -2px 0 ${o("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":h.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":N==="all",style:H(N==="all"),onClick:()=>J("all"),children:[h.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:R.toLocaleString()})]}),ne.map(U=>t.jsxs("button",{type:"button","aria-pressed":N===U.type,style:H(N===U.type),onClick:()=>J(U.type),children:[U.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:M(U.key).toLocaleString()})]},U.type))]})})(),y.map(({type:M,name:ne,key:R})=>{const J=v[R]??[],H=go[R],U=v[H]??0;if(J.length===0||N!=="all"&&N!==M)return null;const Se=N==="all"&&!(w===M)&&U>Rn;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${o("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:[t.jsx(jn,{type:M})," ",ne,t.jsxs("span",{style:{fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[U," ",h.unit.items]})]}),Se&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>O(M),style:{border:"none",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"12px"},children:h.action.viewAll})]}),t.jsx("div",{style:u==="list"?{display:"flex",flexDirection:"column",gap:0}:u==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:J.map(ye=>{if(g)return t.jsx(f.Fragment,{children:g(ye)},ye.id);const Le=u==="card"?fa:mo;return t.jsx(Le,{entry:ye,selected:B===ye.id,onClick:oe,getConfig:F,query:k},ye.id)})})]},M)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:Kt(h.search.noResultsFor,{query:k})}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:h.search.tryOther})]})})]})},ca=240;function da(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const pa=`
1
+ "use strict";var wl=Object.create;var so=Object.defineProperty;var Sl=Object.getOwnPropertyDescriptor;var _l=Object.getOwnPropertyNames;var $l=Object.getPrototypeOf,zl=Object.prototype.hasOwnProperty;var Cl=(e,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of _l(n))!zl.call(e,s)&&s!==o&&so(e,s,{get:()=>n[s],enumerable:!(r=Sl(n,s))||r.enumerable});return e};var cn=(e,n,o)=>(o=e!=null?wl($l(e)):{},Cl(n||!e||!e.__esModule?so(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"),Il=require("opencc-js/t2cn"),Tl=require("react-markdown"),El=require("remark-gfm"),Rl=e=>`/book-index?id=${e}`,br=g.createContext(Rl);function Nl({buildUrl:e,children:n}){const o=g.useMemo(()=>e,[e]);return t.jsx(br.Provider,{value:o,children:n})}function Pe(){return g.useContext(br)}const yr="",jr="";function vr(e){const n=[];let o=!1,r=e;for(;r.length;){const s=o?jr:yr,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 lo='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Ll=[He("基础(VS Code 环境下跟随 --vscode-*)",{bg:{value:"#ffffff",vscode:"--vscode-editor-background"},fg:{value:"#333333",vscode:"--vscode-foreground"},"input-bg":{value:"#ffffff",vscode:"--vscode-input-background"},"input-fg":{value:"#333333",vscode:"--vscode-input-foreground"},"input-border":{value:"#cccccc",vscode:"--vscode-input-border"},"widget-border":{value:"#e0e0e0",vscode:"--vscode-widget-border"},"link-fg":{value:"#0066cc",vscode:"--vscode-textLink-foreground"},"desc-fg":{value:"#717171",vscode:"--vscode-descriptionForeground"},primary:{value:"#0078d4",vscode:"--vscode-button-background"},"primary-fg":{value:"#ffffff",vscode:"--vscode-button-foreground"},"primary-soft":{value:"rgba(0, 120, 212, 0.15)",css:"color-mix(in srgb, var(--bim-primary) 15%, transparent)"},danger:{value:"#f44336"},warning:{value:"#ff9800"},success:{value:"#4caf50"},"sidebar-bg":{value:"#f3f3f3",vscode:"--vscode-sideBar-background"},"list-hover-bg":{value:"rgba(0, 0, 0, 0.04)",vscode:"--vscode-list-hoverBackground"},"list-active-bg":{value:"rgba(0, 120, 212, 0.1)",vscode:"--vscode-list-activeSelectionBackground"},"focus-border":{value:"#0078d4",vscode:"--vscode-focusBorder"}}),He("底色层次 / 文字与描边 / 链接",{"bg-subtle":{value:"#fafafa"},"widget-bg":{value:"#f8f8f8"},muted:{value:"#888888"},border:{value:"#e5e5e5"},"primary-bg":{value:"#fdf4f4"},link:{value:"#1976d2"},"tag-bg":{value:"#f0f0f0"},"accent-bg":{value:"#1976d2"},"on-color-fg":{value:"#ffffff",note:"彩色底(徽章、选中态按钮)上的文字"}}),He("提示与警告",{"info-fg":{value:"#0c5380"},"info-bg":{value:"#e7f3ff"},"info-border":{value:"#b3dbff"},"warn-fg":{value:"#856404"},"warn-bg":{value:"#fff3cd"},"warn-border":{value:"#ffc107"},"danger-bg":{value:"rgba(244, 67, 54, 0.08)",note:"错误提示条底色"},"danger-soft-bg":{value:"rgba(244, 67, 54, 0.03)",note:"编辑器危险区块"},"danger-soft-border":{value:"rgba(244, 67, 54, 0.13)"}}),He("遮罩与阴影",{backdrop:{value:"rgba(0, 0, 0, 0.5)",note:"对话框遮罩"},"overlay-bg":{value:"#00000010",note:"轻量遮罩底(图片占位等)"},"shadow-dialog":{value:"0 4px 20px rgba(0, 0, 0, 0.3)"},"shadow-dropdown":{value:"0 4px 12px rgba(0, 0, 0, 0.1)"},"shadow-tooltip":{value:"0 2px 8px rgba(0, 0, 0, 0.08)"},"shadow-fab":{value:"0 2px 8px rgba(0, 0, 0, 0.25)",note:"悬浮按钮(反馈)"},"shadow-card":{value:"0 1px 4px rgba(0, 0, 0, 0.06)",note:"展开的卡片"},"shadow-node":{value:"0 1px 3px rgba(0, 0, 0, 0.1)",note:"谱系图节点"},"shadow-node-selected":{value:"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)"}}),He("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),He("资源",{"restype-text":{value:"#2196f3"},"restype-image":{value:"#ff9800"},"restype-text-image":{value:"#9c27b0"},"restype-physical":{value:"#795548"},"missing-fg":{value:"#e67e22",note:"资源缺册提示"},"colormode-bw-bg":{value:"#f5f5f5",note:"影印件色彩模式标记(黑白 / 彩色)"},"colormode-bw-fg":{value:"#757575"},"colormode-color-bg":{value:"#fff8e1"},"colormode-color-fg":{value:"#f57f17"},"progress-active":{value:"#f59e0b",note:"资源导入进度"},"progress-done":{value:"#10b981"},"progress-todo":{value:"#9ca3af"},"check-fine-bg":{value:"#e8f5e9",note:"文字资源校对程度徽章(精校 / 粗校 / AI整理)"},"check-fine-fg":{value:"#2e7d32"},"check-rough-bg":{value:"#fff3e0"},"check-rough-fg":{value:"#e65100"},"check-ai-bg":{value:"#e3f2fd"},"check-ai-fg":{value:"#1565c0"}}),He("整理本(CollatedEdition)",{"highlight-bg":{value:"#fff59d",note:"搜索命中高亮底"},"highlight-fg":{value:"inherit",root:!1},"section-lei":{value:"#8e6f3e",note:"章节类型标记:类 / 书 / 序 / 结语 / 考证 / 注释"},"section-shu":{value:"#c0392b"},"section-xu":{value:"#1a5276"},"section-jieyu":{value:"#7d6608"},"section-kaozhen":{value:"#5d6d7e"},"section-zhushi":{value:"#6c5b7b"},"section-tag-fg":{value:"#e74c3c",note:"章节标记(△ 等)"},"matchstate-fg":{value:"#b78900",note:"与底本匹配状态提示"},"quality-published":{value:"#1b5e20",note:"文本质量等级(出版 / 精校 / 粗校 / OCR)"},"quality-fine":{value:"#2e7d32"},"quality-rough":{value:"#1565c0"},"quality-ocr":{value:"#e65100"}}),He("版本传承(VersionLineageGraph / List) / 关系方向(RelationPanel)",{"lost-fg":{value:"#c62828",note:"佚失标记"},"confidence-certain":{value:"#2e7d32",note:"关系置信度"},"confidence-consensus":{value:"#1976d2"},"confidence-probable":{value:"#ed6c02"},"confidence-disputed":{value:"#c62828"},"lineage-edge-consensus":{value:"#555555",note:"⚠️ 同为 consensus,List 徽章用 --bim-confidence-consensus(蓝),Graph 连线用这个(灰)。若要统一,覆盖成 var(--bim-confidence-consensus)"},"relation-up":{value:"#2196f3"},"relation-down":{value:"#4caf50"},"relation-flat":{value:"#ff9800"}}),He("编辑器视图(主要在 guji-platform 插件中可见)",{"editor-type-work":{value:"#4caf50",note:"⚠️ 与展示视图的 --bim-type-* 是两套配色(历史如此)。若要统一,覆盖成对应的 var(--bim-type-*)"},"editor-type-collection":{value:"#2196f3"},"editor-type-book":{value:"#ff9800"},"editor-type-entity":{value:"#9c27b0"},"source-url":{value:"#2196f3",note:"来源类型(SourceEditor)"},"source-bookid":{value:"#4caf50"},"mode-active-bg":{value:"#2196f3",note:"模式指示器当前态(ModeIndicator)"},"cover-accent":{value:"#8e6f3e",note:'书目卡片「封面」点缀(IndexBrowser resultVariant="card")'}}),He("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --bim-primary 等控件色",{"page-bg":{value:"#fbf9f3",note:"纸"},"row-hover-bg":{value:"#f5f1e5"},"selection-bg":{value:"#ecdcbc",note:"选区"},"band-bg":{value:"#f0e4cb",note:"全文入口横幅(暖沙)"},"band-bg-hover":{value:"#e6d5b4"},ink:{value:"#2a231c",note:"文字层次:墨 → 正文 → 提要 → meta → 标签 → 提示"},"body-fg":{value:"#3b3228"},"quiet-fg":{value:"#5b4f40"},"meta-fg":{value:"#7b6a54"},"label-fg":{value:"#6f6457",note:"标签 / 提示:2026-09 N3a 调深,纸底与斑马底上对比度均 ≥4.5(原 #a3937b 2.8、#b3a385 2.3)"},"hint-fg":{value:"#756a5e"},accent:{value:"#9c3a2c",note:"朱"},"accent-deep":{value:"#6f2a20",note:"链接 hover"},"rule-strong":{value:"#2a231c",note:"分隔线:强 → 常规 → 虚线 → 提要左线"},rule:{value:"#e4dbc9"},"rule-dashed":{value:"#d6c9ae"},"rule-accent-soft":{value:"#e0d3b6"},"aux-fg":{value:"#6f6457",note:"辅助字(元数据、注记、「·」分隔的浅色小字)。须在 page-bg / zebra-bg 上对比度 ≥4.5(Q5 巡检)"},"card-bg":{value:"#fffdf9",note:"提要卡:抬起的面"},"zebra-bg":{value:"#f6f2eb",note:"表格斑马纹 / 左栏分组底(不画格线,靠这一阶底色分行)"},"tint-bg":{value:"#f3eee6",note:"检索框、悬停"},"shadow-summary":{value:"0 10px 32px rgba(60, 50, 40, 0.07)",note:"提要卡投影"},"flag-bg":{value:"rgba(158, 42, 43, 0.08)",note:"唯一的状态色块「有影印」"},"theme-dot-zhusha":{value:"#9c3a2c",note:"主题切换控件的色点:朱砂(不随主题变,两套主题下都要认得出)"},"theme-dot-indigo":{value:"#2e5266",note:"主题切换控件的色点:靛蓝"},"sect-jing":{value:"#2e5266",note:"四部分布条:經部(人物页提要卡;无别处使用)"},"sect-shi":{value:"#9a7a3b",note:"四部分布条:史部"},"sect-zi":{value:"#4f7a5c",note:"四部分布条:子部"},"sect-ji":{value:"#9fb3bc",note:"四部分布条:集部"},"table-border":{value:"color-mix(in srgb, currentColor 28%, transparent)",root:!1,note:"古籍表格(跟随当前文字色)"},"table-head-bg":{value:"color-mix(in srgb, currentColor 8%, transparent)",root:!1}}),He("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),He("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),He("字体(全站无衬线,2026-09-05 定)",{"font-ui":{value:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif'},"font-body":{value:"system-ui, sans-serif",css:"var(--bim-font-ui)"},"font-serif":{value:lo,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:lo,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Bl=Object.assign({},...Ll.map(e=>e.tokens)),kr={};for(const[e,n]of Object.entries(Bl))kr[e]=`var(--bim-${e}, ${n.value})`;function i(e){const n=kr[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 Al(e,n){return yt(e).includes(n)}const Hn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Wl={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};i("quality-published"),i("quality-fine"),i("quality-rough"),i("quality-ocr");const Rt=g.createContext(null),wr={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:"圖片資源"}},Ml={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:"图片资源"}},Fl=["曹霑"];function Pl(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ol(e,n=Fl){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(Pl).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 Dl(){if(At)return At;try{At=Ol(Il.Converter({from:"tw",to:"cn"}))}catch{At=e=>e}return At}const Hl={"zh-Hant":wr,"zh-Hans":Ml},Sr="bim-locale";function Gl(){try{const e=localStorage.getItem(Sr);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Ul(e){try{localStorage.setItem(Sr,e)}catch{}}const Vl="zh-Hans",Yl=({locale:e,onLocaleChange:n,converter:o,children:r})=>{const[s,l]=g.useState(e??Vl),d=e??s;g.useEffect(()=>{if(e)return;const u=Gl();u&&u!==s&&l(u)},[]);const p=g.useMemo(()=>d==="zh-Hans"?o??Dl():null,[d,o]),c=g.useCallback(u=>{l(u),Ul(u),n==null||n(u)},[n]),a=g.useMemo(()=>({locale:d,setLocale:c,messages:Hl[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)??wr}const ql=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>=ql){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 Kl(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 Jl(){return{id:"",name:"",url:"",type:"text",details:""}}const Gn=({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=Jl();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 _=Kl($);_&&(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:Zl(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&&Xl(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:[Al(y,"image")&&y.url&&Ql(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 Zl(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 Xl(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 Ql(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"},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 Nt(e){try{return ea[new URL(e).hostname]}catch{return}}const ao={text:0,image:1,physical:2};function di(e){return e.length===0?"physical":[...e].sort((n,o)=>(ao[n]??99)-(ao[o]??99)).join("+")}function pi(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}|${di(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 _r(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 $r(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||_r(n)}))}function yn(e){const n=$r(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 ui(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 xi(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=ui(e.metadata);return n?xi(e.url,n):e.url}const co={text:i("restype-text"),image:i("restype-image"),"text+image":i("restype-text-image"),physical:i("restype-physical")};function ta(e){return e.includes("text")&&e.includes("image")?co["text+image"]:co[e[0]||"physical"]}const fi=({items:e,groupByType:n=!0,resourceGroups:o,onNavigate:r,renderLink:s})=>{const l=ue(),{convert:d}=Z(),p=g.useMemo(()=>pi(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(En,{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(En,{item:v,onNavigate:r,renderLink:s},v.id||_))})]},`group-${h}`)},m=new Map;for(const h of a){const b=di(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=ta(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(En,{item:k,onNavigate:r,renderLink:s},k.id||$))})]},h)})]})},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")}},En=({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||_r(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?{...na[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=ui(e.metadata);return j?xi(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)})})]})},zr=({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",po=10,uo=8;function Gt(){try{const e=localStorage.getItem(jn);return e?JSON.parse(e):[]}catch{return[]}}function ia(e){try{const n=Gt().filter(o=>o!==e);n.unshift(e),n.length>po&&(n.length=po),localStorage.setItem(jn,JSON.stringify(n))}catch{}}function oa(e){try{const n=Gt().filter(o=>o!==e);localStorage.setItem(jn,JSON.stringify(n))}catch{}}function ra(){try{localStorage.removeItem(jn)}catch{}}const Cr=({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,uo).then(O=>{if(D)return;const M=[...O.works,...O.books,...O.collections,...O.entities??[]];x(M.slice(0,uo).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()&&(ia(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(),oa(C),h(Gt()),x(B=>B.filter(O=>!(O.type==="history"&&O.text===C)))},[]),N=g.useCallback(C=>{C.stopPropagation(),ra(),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",xo="bim-recent-entries",fo=50,Rn=5,sa=50,la=200;function _t(){try{const e=localStorage.getItem(Ct);if(e)return JSON.parse(e);const n=localStorage.getItem(xo);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Ct,JSON.stringify(o)),localStorage.removeItem(xo),o}return[]}catch{return[]}}function go(e){try{const n=_t().filter(o=>o!==e);n.unshift(e),n.length>fo&&(n.length=fo),localStorage.setItem(Ct,JSON.stringify(n))}catch{}}function aa(e){try{const n=_t().filter(o=>o!==e);localStorage.setItem(Ct,JSON.stringify(n))}catch{}}function ca(){try{localStorage.removeItem(Ct)}catch{}}const mo={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Un=({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),[q,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??Rn);_(I)}else{const I=["work","book","collection","entity"],G=await Promise.all(I.map(P=>e.search(W,P,{page:1,pageSize:A??Rn})));_({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),K=((ke=e.getSubtypeStats)==null?void 0:ke.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([G,P,K]).then(([be,Le,qe])=>{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}),qe&&Re(qe))})};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)},la)},[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,sa)},[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 K=await e.getItem(A);if(K){const se=K.authors;return{id:A,title:K.title||A,type:K.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:K.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),go(W.id),F(_t()),r==null||r(W)},oe=(W,A)=>{if(r&&pa(A)){A.preventDefault(),ce(W);return}go(W.id),F(_t())},he=W=>{aa(W),F(_t())},me=()=>{ca(),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:ua}),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(zr,{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(Cr,{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:da,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}):q.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:q.slice(0,ie?10:3).map(W=>W.notFound?t.jsx(ma,{id:W.id,onRemove:he,t:h},W.id):t.jsx(ho,{entry:W,selected:B===W.id,onClick:oe,getConfig:U,onRemove:he},W.id))}),!ie&&q.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:xa}),(()=>{const W=K=>v[mo[K]]??0,A=y.map(K=>b.find(se=>se.type===K)).filter(K=>W(K.key)>0);if(A.length<2)return null;const I=A.reduce((K,se)=>K+W(se.key),0),G=K=>{if(T(K),K!=="all"&&S!==K){const se=b.find(be=>be.type===K),ke=(v[se.key]??[]).length;W(se.key)>ke&&H(K)}},P=K=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:i(K?"fg":"desc-fg"),fontWeight:K?700:400,boxShadow:K?`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(K=>t.jsxs("button",{type:"button","aria-pressed":N===K.type,style:P(N===K.type),onClick:()=>G(K.type),children:[K.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:W(K.key).toLocaleString()})]},K.type))]})})(),b.map(({type:W,name:A,key:I})=>{const G=v[I]??[],P=mo[I],K=v[P]??0;if(G.length===0||N!=="all"&&N!==W)return null;const ke=N==="all"&&!(S===W)&&K>Rn;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:[K," ",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"?ga:ho;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})]})})]})},da=240;function pa(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const ua=`
2
2
  .bim-ib-stats { min-height: 25px; box-sizing: content-box; }
3
3
  @media (max-width: 719px) { .bim-ib-stats { min-height: 46px; } }
4
- `,ua=`
4
+ `,xa=`
5
5
  @media (max-width: 719px), (pointer: coarse) {
6
6
  .bim-ib-viewall { position: relative; }
7
7
  .bim-ib-viewall::after {
8
8
  content: ""; position: absolute; left: 50%; top: 50%;
9
9
  width: max(calc(100% + 8px), 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
10
10
  }
11
- }`,Cr={color:"inherit",textDecoration:"none"},xa=({snippet:e})=>{const{convert:n}=q();return t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.6},children:jr(e).map((i,r)=>i.marked?t.jsx("mark",{style:{background:o("highlight-bg"),color:o("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(i.text)},r):t.jsx(f.Fragment,{children:n(i.text)},r))})},fa=({entry:e,selected:n,onClick:i,getConfig:r,query:s})=>{const l=ue(),{convert:a}=q(),p=a(e.title||e.primary_name||e.id),c=e.measure_info?a(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",d=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&d.length?d.find(m=>{const b=typeof m=="string"?m:m==null?void 0:m.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,g=o("cover-accent"),x=Pe();return t.jsxs("a",{href:x(e.id),onClick:m=>i(e,m),className:"bim-result-card",style:{...Cr,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:o("bg"),border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[t.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${g} 50%, ${o("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${g} 14%, ${o("bg")}), color-mix(in srgb, ${g} 7%, ${o("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[t.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${g} 45%, transparent)`}}),t.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:g},children:Array.from(p).map((m,b)=>t.jsx("span",{children:m},b))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:o("fg")},children:p}),c&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",a(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:a(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",a(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",a(e.era),"〕"]}),e.edition&&t.jsx("span",{children:a(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[l.search.alias,":",a(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(xa,{snippet:e.descriptionSnippet}),t.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[t.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:[t.jsx(jn,{type:e.type,size:8})," ",r(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:l.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:l.misc.imageResource})]})]})]})},mo=({entry:e,selected:n,onClick:i,getConfig:r,query:s,onRemove:l})=>{const a=ue(),{convert:p}=q(),c=[...e.additional_titles||[],...e.attached_texts||[]],d=s&&c.length?c.find(g=>{const x=typeof g=="string"?g:g==null?void 0:g.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,u=Pe();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("a",{href:u(e.id),onClick:g=>i(e,g),className:"bim-result-card",style:{...Cr,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx(jn,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:o("desc-fg"),lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:p(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{children:a.misc.textResource}),e.has_image&&t.jsx("span",{children:a.misc.imageResource})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",p(e.era),"〕"]}),e.edition&&p(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:p(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.juan_count,a.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",p(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:p(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",p(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),d&&t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:[a.search.alias,":",p(d)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:a.search.removeFromRecent,"aria-label":a.search.removeFromRecent,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},ga=({id:e,onRemove:n,t:i})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${o("widget-border")}`,background:o("input-bg"),opacity:.6},children:[t.jsx("span",{style:{fontSize:"16px"},children:"❓"}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:"13px",color:o("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:i.search.itemNotFound})]}),t.jsx("button",{onClick:()=>n(e),title:i.search.removeFromRecent,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function ma(e){var n;return!e.dynasty&&!e.birth_year&&!e.death_year&&(!e.alt_names||e.alt_names.length===0)&&!((n=e.description)!=null&&n.text)}function ha({data:e}){const{convert:n}=q(),{dynasty:i,birth_year:r,death_year:s}=e,l=[];return i&&l.push(`〔${n(i)}〕`),r!==void 0&&s!==void 0?l.push(`${r}—${s}`):r!==void 0?l.push(`${r}—?`):s!==void 0&&l.push(`?—${s}`),l.length===0?null:t.jsx("span",{style:{fontSize:"14px",color:o("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function ba({alt_names:e}){const{convert:n}=q(),i=new Map;for(const l of e){const a=l.type||"別名";i.has(a)||i.set(a,[]),i.get(a).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((l,a)=>{const p=r.indexOf(l),c=r.indexOf(a);return p===-1&&c===-1?0:p===-1?1:c===-1?-1:p-c});return t.jsx("div",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const a=i.get(l);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:o("desc-fg"),fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),t.jsx("span",{children:a.map((p,c)=>t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},c))})]},l)})})}function ya({data:e}){const n=e.external_ids;if(!n)return null;const i=[];return n.cbdb_id&&i.push(t.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:o("link-fg"),border:`1px solid ${o("link-fg")}40`,borderRadius:"3px",textDecoration:"none",background:`${o("link-fg")}08`},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),i.length===0?null:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:i})}function ja({works:e,transport:n,onNavigate:i,renderLink:r}){const s=ue(),{convert:l}=q(),a=Pe(),[p,c]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let x=!1;const m=e.map(S=>S.work_id);return(async()=>{const S=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(m);let $=!0;for(let v=0;v<m.length;v++){const _=k[v];_!=null&&_.title?S.set(m[v],_.title):_!=null&&_.primary_name?S.set(m[v],_.primary_name):$=!1}if($)return S}catch{}const h=[...m],y=8,j=new Array(y).fill(0).map(async()=>{for(;h.length;){const k=h.shift();if(!k)break;if(!S.has(k))try{if(n.getEntry){const _=await n.getEntry(k);if(_!=null&&_.title){S.set(k,_.title);continue}}const $=await n.getItem(k),v=$&&($.title||$.primary_name)||k;S.set(k,v)}catch{S.set(k,k)}}});return await Promise.all(j),S})().then(S=>{x||c(S)}),()=>{x=!0}},[e,n]);const d=new Map;for(const x of e){const m=x.role||"";d.has(m)||d.set(m,[]),d.get(m).push(x)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],g=[...d.keys()].sort((x,m)=>{const b=u.indexOf(x),S=u.indexOf(m);return b===-1&&S===-1?x.localeCompare(m):b===-1?1:S===-1?-1:b-S});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:o("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:o("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),g.map(x=>{const m=d.get(x);return t.jsxs("div",{style:{marginBottom:"8px"},children:[x&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"2px"},children:[l(x)," ",t.jsxs("span",{style:{color:o("desc-fg")},children:["(",m.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:x?"16px":"0",listStyle:x?"disc":"none",fontSize:"14px",lineHeight:1.8},children:m.map((b,S)=>{const h=l(p.get(b.work_id)||b.work_id);return r?t.jsx("li",{children:r(b.work_id,h)},S):i?t.jsx("li",{children:t.jsx("a",{href:a(b.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),i(b.work_id))},style:{color:o("link-fg"),textDecoration:"underline",cursor:"pointer"},children:h})},S):t.jsx("li",{children:h},S)})})]},x)})]})}const Ir=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:l})=>{var g;const a=ue(),{convert:p}=q();let c=!1;try{c=we.extractStatus(e.id)==="draft"}catch{}const d=ma(e),u=e.subtype==="people"?"人物":e.subtype==="place"?"地名":e.subtype==="dynasty"?"朝代":e.subtype==="anonymous"?"佚名":e.subtype==="collective"?"集体":e.subtype;return t.jsxs("div",{children:[!l&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:o("fg")},children:[p(e.primary_name),t.jsx(ha,{data:e})]}),s]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o("type-entity"),border:`1px solid color-mix(in srgb, ${o("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${o("type-entity")} 3%, transparent)`},children:a.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),c&&t.jsx("span",{style:{padding:"1px 6px",background:o("warn-bg"),border:`1px solid ${o("warn-border")}`,borderRadius:"2px",color:o("warn-fg")},children:a.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),d&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:o("widget-bg"),border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(ba,{alt_names:e.alt_names}),t.jsx(ya,{data:e}),((g=e.description)==null?void 0:g.text)&&t.jsx("p",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(e.description.text)}),e.works&&e.works.length>0&&t.jsx(ja,{works:e.works,transport:n,onNavigate:i,renderLink:r})]})},va=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function ka(e){const n=e.search(va);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const Tr={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>{let i=e,r="",s=n;if(e&&typeof n=="string"&&(n===e||n===Sa(e))){const[l,a]=ka(n);a&&(i=encodeURI(l),s=l,r=a)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:i,target:i!=null&&i.startsWith("http")?"_blank":void 0,rel:i!=null&&i.startsWith("http")?"noopener noreferrer":void 0,style:{color:o("link")},children:s}),r]})},code:({children:e})=>t.jsx("code",{style:{background:o("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function Sa(e){try{return decodeURI(e)}catch{return e}}const wa={...Tr,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},lt=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:s}=q(),l=n?wa:Tr;return t.jsx("div",{className:r,style:i,children:t.jsx(Il,{remarkPlugins:[Tl],components:l,children:s(e)})})},_a=["〇","一","二","三","四","五","六","七","八","九"],ho=["","十","百","千"];function Er(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const a=parseInt(n[l]),p=i-1-l;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&p===1&&l===0?r+=ho[p]:r+=_a[a]+ho[p])}return r}function Rr(e){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:e,border:`1px solid color-mix(in srgb, ${e} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${e} 3%, transparent)`}}const $a={book:o("type-book"),work:o("type-work"),collection:o("type-collection"),entity:o("type-entity")};function za({type:e}){const n=ue();return t.jsx("span",{style:Rr($a[e]),children:n.indexType[e]})}function Ca({isDraft:e}){const n=ue(),i=o(e?"status-draft":"status-official");return t.jsx("span",{style:Rr(i),children:e?n.status.draft:n.status.official})}function Ia({id:e}){const n=ue(),[i,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:o("desc-fg"),background:o("bg-subtle"),border:`1px solid ${o("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:o("fg")},children:e}),t.jsx("span",{onClick:s,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function Ve({children:e,extra:n}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("desc-fg"),letterSpacing:"1px"},children:e}),t.jsx("span",{style:{flex:1}}),n]})}function tt({label:e,children:n}){return t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[t.jsx("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:e}),t.jsx("span",{style:{color:o("fg")},children:n})]})}function Nr({authors:e,type:n,onNavigate:i,renderLink:r}){const{convert:s}=q();return t.jsx("span",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.6},children:e.map((l,a)=>{const p=s(l.name),c=l.entity_id?t.jsx(Ke,{id:l.entity_id,label:p,onNavigate:i,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:p});return t.jsxs("span",{children:[a>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),c,l.role&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},a)})})}function Ke({id:e,label:n,onNavigate:i,renderLink:r}){const s=Pe();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i(e))},style:{color:o("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`,paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{children:n||e})}function Ta({id:e,title:n,edition:i,type:r,isDraft:s,authors:l,volumeText:a,meta:p,headerExtra:c,onNavigate:d,renderLink:u}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:o("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:i}),a&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:a})]}),c&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(za,{type:r}),t.jsx(Ca,{isDraft:s}),t.jsx(Ia,{id:e})]}),((l==null?void 0:l.length)||p.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(Nr,{authors:l,type:r,onNavigate:d,renderLink:u}),p]})]})}function Lr({items:e,label:n,showMeta:i,onNavigate:r,renderLink:s}){const l=ue(),{convert:a}=q();if(!e.length)return null;const[p,c]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((d,u)=>{const g=p===u;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...g?{boxShadow:o("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>c(g?null:u),style:{padding:"8px 12px",background:o("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.15s",transform:g?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:a(d.source)}),!g&&i&&d.title_info&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a(d.title_info)}),d.source_bid&&t.jsx("span",{onClick:x=>x.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Ke,{id:d.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),g&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${o("widget-border")}`},children:[i&&(d.title_info||d.author_info||d.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&t.jsx(tt,{label:l.label.titleInfo,children:a(d.title_info)}),d.author_info&&t.jsx(tt,{label:l.label.authorInfo,children:a(d.author_info)}),d.edition&&t.jsx(tt,{label:l.label.edition,children:a(d.edition)})]}),d.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:a(d.summary)})]}),d.comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.comment)})]}),d.additional_comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.additional_comment)})]})]})]},u)})})]})}function Ea({items:e,onNavigate:n,renderLink:i}){const r=ue();return t.jsx(Lr,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Br({items:e,onNavigate:n,renderLink:i}){const r=ue();return t.jsx(Lr,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function Ar({label:e,items:n}){const{convert:i}=q();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const l=typeof r=="string"?r:r.book_title;return t.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:o("fg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:i(l)},s)})})]}):null}function Ra({items:e}){const n=ue();return t.jsx(Ar,{label:n.section.aliases,items:e})}function Na({items:e}){const n=ue();return t.jsx(Ar,{label:n.section.attachedTexts,items:e})}function La({items:e}){const n=ue(),{convert:i}=q();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.appendix}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:e.map((r,s)=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:o("fg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:["《",i(r.book_title),"》",r.n_juan!=null&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function Ba({items:e}){const n=ue(),{convert:i}=q();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.locationHistory}),t.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[t.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:o("widget-border")}}),e.map((r,s)=>t.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[t.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:o("primary"),border:`1.5px solid ${o("input-bg")}`}}),t.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:o("fg")},children:i(r.name)}),r.description&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),marginLeft:"8px"},children:i(r.description)})]},s))]})]}):null}function Aa({items:e}){const n=ue(),{convert:i}=q();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:n.section.historyOverview}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map((r,s)=>t.jsxs("div",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[t.jsx("span",{style:{position:"absolute",left:0,top:0,color:o("desc-fg")},children:"·"}),i(r)]},s))})]}):null}function bo({title:e,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:l}=q(),[a,p]=f.useState([]);return f.useEffect(()=>{if(!n.length){p([]);return}if(!i){p(n.map(d=>({id:d})));return}let c=!1;return Promise.all(n.map(d=>i.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{c||p(d)}),()=>{c=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(Ve,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",n.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(a.length?a:n.map(c=>({id:c}))).map(c=>{const d=c.edition?`${l(c.title)||c.id}(${l(c.edition)})`:l(c.title)||void 0;return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),transition:"border-color 0.15s"},children:t.jsx(Ke,{id:c.id,label:d,onNavigate:r,renderLink:s})},c.id)})})]}):null}function Nn({book:e,onNavigate:n,renderLink:i}){const r=ue(),{convert:s}=q(),[l,a]=f.useState(!1),p=e.resources&&e.resources.length>0,c=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:o("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(Ke,{id:e.id,label:c,onNavigate:n,renderLink:i})}),p&&t.jsx("span",{onClick:()=>a(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:o("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),p&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(xi,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Wa({ids:e,workData:n,transport:i,onNavigate:r,renderLink:s,footer:l}){const a=ue(),{convert:p}=q(),[c,d]=f.useState([]);if(f.useEffect(()=>{if(!e.length){d([]);return}if(!i){d(e.map(S=>({id:S})));return}let b=!1;return Promise.all(e.map(S=>i.getItem(S).then(h=>({id:S,title:h?h.title:void 0,edition:h?h.edition:void 0,resources:h?h.resources:void 0,resource_groups:h?h.resource_groups:void 0})).catch(()=>({id:S})))).then(S=>{b||d(S)}),()=>{b=!0}},[e,i]),!e.length)return null;const u=c.length?c:e.map(b=>({id:b})),g=new Map(u.map(b=>[b.id,b])),x=n==null?void 0:n.version_graph,m=Ma(e,x);return t.jsxs(t.Fragment,{children:[t.jsxs(Ve,{children:[a.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,m.useGrouping?t.jsxs(t.Fragment,{children:[m.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:m.coreIds.map(b=>{const S=g.get(b);return S?t.jsx(Nn,{book:S,onNavigate:r,renderLink:s},b):null})}),m.groupedIds.map(b=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${o("widget-border")}`,borderRadius:6,background:o("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:o("fg"),userSelect:"none"},children:[p(b.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:o("desc-fg"),fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:o("desc-fg"),fontWeight:400},children:p(b.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(S=>{const h=g.get(S);return h?t.jsx(Nn,{book:h,onNavigate:r,renderLink:s},S):null})})]},b.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(b=>t.jsx(Nn,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Ma(e,n){var h,y;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.length>0||s.length>0,a=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&a.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),c=new Set([...s,...a]),d=j=>{if(c.has(j))return!0;const k=n.node_groups[j];return k!=null&&p.has(k)},u=[],g=new Map,x=[];for(const j of e)if(!((y=n.excluded_books)!=null&&y.includes(j)))if(d(j))u.push(j);else{const k=n.node_groups[j];k?(g.has(k)||g.set(k,[]),g.get(k).push(j)):x.push(j)}if(x.length+[...g.values()].reduce((j,k)=>j+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(j=>[j.id,j])),S=[...g.entries()].map(([j,k])=>{const $=b.get(j);return{id:j,label:($==null?void 0:$.label)??j,description:$==null?void 0:$.description,ids:k}});return x.length>0&&S.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:S}}function Fa({workData:e,onNavigate:n,renderLink:i}){var a,p,c,d;const r=ue(),{convert:s}=q(),l=!!((a=e.description)!=null&&a.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:o("input-bg"),marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`},children:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:t.jsx(Ke,{id:e.id,label:s(e.title),onNavigate:n,renderLink:i})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:s(e.measure_info)}):((p=e.juan_count)==null?void 0:p.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[Er(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(Nr,{authors:e.authors,type:"work",onNavigate:n,renderLink:i})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((c=e.description)==null?void 0:c.text)&&t.jsx(lt,{text:e.description.text,style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(d=e.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:t.jsx(tt,{label:r.label.parentWork,children:t.jsx(Ke,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Pa({items:e,onNavigate:n,renderLink:i}){const r=ue(),{convert:s}=q();return e.length?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(l=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid color-mix(in srgb, ${o("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${o("type-collection")} 3%, transparent)`},children:[t.jsx("span",{style:{fontSize:"11px",color:o("type-collection")},children:r.indexType.collection}),t.jsx(Ke,{id:l.id,label:s(l.title)||l.id,onNavigate:n,renderLink:i}),l.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"2px"},children:Kt(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const fi=({data:e,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:a,className:p,style:c})=>{var P,B,A,W,V,K,E,le;const d=ue(),{convert:u}=q(),[g,x]=f.useState(null),[m,b]=f.useState(!1),[S,h]=f.useState(null),[y,j]=f.useState(null),[k,$]=f.useState([]),v=e||g;if(f.useEffect(()=>{if(e||!n||!i)return;let G=!1;return b(!0),h(null),i.getItem(n).then(ae=>{G||(ae?x(ae):h(d.misc.notFoundEntry))}).catch(ae=>{G||h(ae instanceof Error?ae.message:d.misc.loadFailed)}).finally(()=>{G||b(!1)}),()=>{G=!0}},[e,n,i]),f.useEffect(()=>{if(!v||!i){j(null),$([]);return}let G=!1;const ae=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(ae?i.getItem(ae).then(pe=>{!G&&pe&&pe.type==="work"&&j(pe)}).catch(()=>{}):j(null),v.type==="book"){const pe=v;pe.contained_in&&pe.contained_in.length>0?Promise.all(pe.contained_in.map(ee=>{const X=typeof ee=="string"?ee:ee.id,ie=typeof ee=="string"?void 0:ee.volume_index;return i.getItem(X).then(me=>({id:X,title:me&&me.title||X,volume_index:ie})).catch(()=>({id:X,title:X,volume_index:ie}))})).then(ee=>{G||$(ee)}):$([])}else $([]);return()=>{G=!0}},[v,i]),m)return t.jsx("div",{className:p,style:{...c,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((G,ae)=>t.jsx("div",{style:{height:ae===1?"32px":"16px",width:`${G}px`,background:o("widget-border"),borderRadius:"4px",opacity:.4}},ae))})});if(S)return t.jsx("div",{className:p,style:{...c,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:S});if(!v)return null;if(v.type==="entity")return t.jsx("div",{className:p,style:c,children:t.jsx(Ir,{data:v,transport:i,onNavigate:r,renderLink:s,headerExtra:l})});const _=v.type==="book"?v:null,w=v.type==="collection"?v:null,z=v.type==="work"?v:null;let N=!1;try{N=we.extractStatus(v.id)==="draft"}catch{}let T="";v.measure_info?T=u(v.measure_info):(P=v.juan_count)!=null&&P.number?T=Er(v.juan_count.number)+d.unit.juan:(B=v.juan_count)!=null&&B.description&&(T=u(v.juan_count.description));const C=[];return(A=v.publication_info)!=null&&A.year&&C.push(t.jsx(tt,{label:d.label.year,children:v.publication_info.year},"year")),(W=v.current_location)!=null&&W.name&&C.push(t.jsx(tt,{label:d.label.currentLocation,children:u(v.current_location.name)},"loc")),(V=v.page_count)!=null&&V.description&&C.push(t.jsx(tt,{label:d.label.pageCount,children:v.page_count.description},"page")),_!=null&&_.edition&&C.push(t.jsx(tt,{label:d.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&C.push(t.jsx(tt,{label:d.label.parentWork,children:t.jsx(Ke,{id:z.parent_work.id,label:u(z.parent_work.title),onNavigate:r,renderLink:s})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&C.push(t.jsx(tt,{label:d.label.parentWork,children:z.parent_works.map((G,ae)=>t.jsxs("span",{children:[ae>0&&"、",t.jsx(Ke,{id:G,onNavigate:r,renderLink:s})]},G))},"pws")),t.jsxs("div",{className:p,style:c,children:[t.jsx(Ta,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:N,authors:v.authors,volumeText:T,meta:C,headerExtra:l,onNavigate:r,renderLink:s}),((K=v.description)==null?void 0:K.text)&&t.jsx(lt,{text:v.description.text,style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((G,ae)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:o("bg-subtle"),borderRadius:4,border:`1px solid ${o("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:o("muted")},children:u(G.title)}),t.jsx(lt,{text:G.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:o("fg")}})]},ae))}),k.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:d.section.containedIn}),t.jsx(Pa,{items:k,onNavigate:r,renderLink:s})]}),y&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:d.section.belongsToWork}),t.jsx(Fa,{workData:y,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&t.jsx(La,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&t.jsx(Ra,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&t.jsx(Na,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&t.jsx(Ea,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&t.jsx(Br,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:d.section.resources}),t.jsx(xi,{items:v.resources,resourceGroups:v.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&t.jsx(Ba,{items:_.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&t.jsx(Aa,{items:w.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&t.jsx(bo,{title:d.section.relatedVersions,ids:_.related_books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.books)&&w.books.length>0&&t.jsx(bo,{title:d.section.containedBooks,ids:w.books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.contained_works)&&w.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(Ve,{children:[d.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",w.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.contained_works.map(G=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:t.jsx(Ke,{id:G.id,label:u(G.title),onNavigate:r,renderLink:s})},G.id))})]}),(((E=z==null?void 0:z.books)==null?void 0:E.length)||0)+(((le=z==null?void 0:z.collections)==null?void 0:le.length)||0)>0&&t.jsx(Wa,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z??void 0,transport:i,onNavigate:r,renderLink:s,footer:a}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const G=[],ae=z.related_works.filter(te=>te.relation==="part_of"),pe=z.related_works.filter(te=>te.relation==="has_part"),ee=z.related_works.filter(te=>te.relation==="has_adaptation"),X=z.related_works.filter(te=>te.relation==="text_carried_by"),ie=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),me=z.related_works.filter(te=>!te.relation||!ie.has(te.relation));return ae.length>0&&G.push({label:d.section.belongsToWork,items:ae}),pe.length>0&&G.push({label:d.section.containedWorks,items:pe}),ee.length>0&&G.push({label:d.section.adaptations,items:ee}),X.length>0&&G.push({label:d.section.derivativeWorks,items:X}),me.length>0&&G.push({label:d.section.relatedWorks,items:me}),G.map(te=>t.jsxs("div",{children:[t.jsxs(Ve,{children:[te.label,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",te.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:te.items.map(se=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:t.jsx(Ke,{id:se.id,label:u(se.title),onNavigate:r,renderLink:s})},se.id))})]},te.label))})()]})};function Oa({data:e}){const n=ue(),{convert:i}=q(),{stats:r}=e,s=r.processed_volumes??r.total_found_volumes,l=s!=null&&e.total_volumes>0?Math.round(s/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:i(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"6px"},children:i(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:o("desc-fg")},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:o("fg")},children:e.total_volumes})," ",n.unit.volume]}),l!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:o("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:o("fg")},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&t.jsxs("span",{children:[n.catalog.matched," ",t.jsx("strong",{style:{color:o("fg")},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&t.jsxs("span",{children:[n.catalog.unmatched," ",t.jsx("strong",{style:{color:o("missing-fg")},children:r.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:o("desc-fg")},children:[n.catalog.source," ",e.source]})]})}function Da({sections:e,activeSection:n,onSelect:i}){const r=ue();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:yo(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:yo(n===s.name),children:[s.name,s.volume_range&&t.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function yo(e){return{padding:"4px 12px",border:e?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${o("primary")} 8%, transparent)`:"transparent",color:o(e?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Ha({id:e,label:n,onNavigate:i,renderLink:r}){const s=Pe();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i(e))},style:{color:o("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:n||e})}function Ga(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=e[0],r=e[e.length-1];return r-i+1===e.length?`${i}–${r}`:e.length<=3?e.join(", "):`${i}–${r} (${e.length}${n})`}function jo({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const s=ue(),{convert:l}=q(),a=e.book_id||e.work_id,p=r&&e.volumes.length>0?Ga(e.volumes,s.unit.volume):null,c=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${o("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:o("desc-fg"),textAlign:"right"},children:p}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:o("fg")},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(d=>l(d)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:o(c?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),a&&t.jsx(Ha,{id:a,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!a&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const gi=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:l,style:a})=>{const p=ue(),[c,d]=f.useState(null),[u,g]=f.useState(!1),[x,m]=f.useState(null),[b,S]=f.useState(null),[h,y]=f.useState(""),j=e||c;f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let w=!1;return g(!0),m(null),i.getCollectionCatalog(n).then(z=>{w||(z?d(z):m(p.catalog.notFound))}).catch(z=>{w||m(z instanceof Error?z.message:p.catalog.loadFailed)}).finally(()=>{w||g(!1)}),()=>{w=!0}},[e,n,i,p]);const k=(j==null?void 0:j.sections)&&j.sections.length>0,$=f.useMemo(()=>{if(!j)return!1;if(j.volume_index&&Object.keys(j.volume_index).length>0)return!0;const w=j.books.map(N=>N.volumes[0]).filter(N=>N!=null);return new Set(w).size<w.length},[j]),v=f.useMemo(()=>{if(!j)return[];let w=j.books;if(b&&(w=w.filter(z=>z.section===b)),h.trim()){const z=h.trim().toLowerCase();w=w.filter(N=>N.title.toLowerCase().includes(z)||N.sub_items&&N.sub_items.some(T=>T.toLowerCase().includes(z))||N.edition&&N.edition.toLowerCase().includes(z))}return w},[j,b,h]),_=f.useMemo(()=>{if(!$)return null;const w=[],z=new Map;for(const T of v){if(!T.volumes||T.volumes.length===0)continue;const C=T.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(T)}const N=[...z.keys()].sort((T,C)=>T-C);for(const T of N)w.push({volume:T,books:z.get(T)});return w},[v,$]);return u?t.jsx("div",{className:l,style:{...a,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):x?t.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:x}):j?t.jsxs("div",{className:l,style:a,children:[t.jsx(Oa,{data:j}),k&&t.jsx(Da,{sections:j.sections,activeSection:b,onSelect:S}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:h,onChange:w=>y(w.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:o("desc-fg")},children:[v.length," ",p.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[_?_.map((w,z)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:o("bg"),borderBottom:`1px solid ${o("widget-border")}`,fontSize:"12px",fontWeight:600,color:o("desc-fg"),position:"sticky",top:0,zIndex:1},children:Kt(p.catalog.volume,{n:w.volume})}),w.books.map((N,T)=>t.jsx(jo,{book:N,onNavigate:r,renderLink:s,showVolumes:N.volumes.length>1},`${w.volume}-${T}`))]},`${w.volume}-${z}`)):v.map((w,z)=>t.jsx(jo,{book:w,onNavigate:r,renderLink:s,showVolumes:!0},z)),v.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},jt=()=>{const[e,n]=f.useState(1);return f.useEffect(()=>{const i=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(i)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:o("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(e)})},Wr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Ua={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function We(e){return Ua[e]??e}const It=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],Tt={熹平:172,建安:196,黃初:220,正始:240,廣政:938,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,開成:836,會昌:841,咸通:860,建隆:960,太平興國:976,咸平:998,天禧:1017,慶曆:1041,皇祐:1049,嘉祐:1056,治平:1064,熙寧:1068,元豐:1078,元祐:1086,紹聖:1094,崇寧:1102,大觀:1107,政和:1111,宣和:1119,建炎:1127,紹興:1131,隆興:1163,乾道:1165,淳熙:1174,紹熙:1190,慶元:1195,嘉泰:1201,開禧:1205,嘉定:1208,寶慶:1225,紹定:1228,端平:1234,嘉熙:1237,淳祐:1241,寶祐:1253,開慶:1259,景定:1260,咸淳:1265,大定:1161,明昌:1190,至元:1264,大德:1297,皇慶:1312,延祐:1314,泰定:1324,天曆:1328,至順:1330,至正:1341,洪武:1368,永樂:1403,宣德:1426,正統:1436,景泰:1450,天順:1457,成化:1465,弘治:1488,正德:1506,嘉靖:1522,隆慶:1567,萬曆:1573,泰昌:1620,天啟:1621,崇禎:1628,弘光:1645,隆武:1645,紹武:1646,永曆:1647,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,正保:1644,慶安:1648,承應:1652,明曆:1655,萬治:1658,寬文:1661,延寶:1673,天和:1681,貞享:1684,元祿:1688,寶永:1704,享保:1716,元文:1736,寬保:1741,延享:1744,寬延:1748,寶曆:1751,明和:1764,安永:1772,天明:1781,寬政:1789,享和:1801,文化:1804,文政:1818,天保:1830,弘化:1844,嘉永:1848,安政:1854,萬延:1860,文久:1861,元治:1864,慶應:1865,明治:1868,大正:1912,昭和:1926,天正:1573,文祿:1592,永祿:1558,天文:1532},Mr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function vn(e){const n=e.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const i=parseInt(n[1],10);if(i<100||i>2100)return;const r=n[2]?parseInt(n[2],10):void 0;return{from:i,to:r!=null&&r>=i&&r<=2100?r:void 0}}function Va(e){return e>=1950?"":e>=1912?"民國":e>=1645?"清":e>=1368?"明":e>=1279?"元":e>=960?"宋":e>=907?"五代":e>=618?"唐":e>=581?"隋":e>=420?"南北朝":e>=265?"晉":e>=220?"三國":e>=-202?"漢":""}const Ya=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,vo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function mi(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(vo))if(n.startsWith(s))return vo[s];const i=We(n);if(gt[i]!=null)return i;const r=st(n);if(r&&n.length<=r.length+1)return We(r)}function ft(e,n){if(n){const i=Mr[`${n}|${e}`];if(i!=null)return i}return Tt[e]}const qa=1911;function Ka(e){const n=Tt[e];if(n==null)return;const i=nt[e];let r;for(const[s,l]of Object.entries(Tt))nt[s]===i&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const Ja={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function fn(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,i=0,r=!1;for(const l of e){const a=Ja[l];if(a===void 0)return;r=!0,l==="十"?i=(i||1)*10:l==="廿"||l==="卅"?(n+=a,i=0):i>=10?(n+=i+a,i=0):i=i*10+a}const s=n+i;return r&&s>0?s:void 0}function st(e){for(const n of Wr)if(e.startsWith(n))return n}const nt={};{const e=(n,i)=>{for(const r of i)nt[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function mt(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(Tt))if(e.includes(r)&&!(i&&nt[r]&&nt[r]!==i&&Mr[`${i}|${r}`]==null))return r}function Jt(e){var a,p,c;const n={era:"",reign:"",source:"none"},i=e.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const r=(a=e.lineage)==null?void 0:a.year_text;if(r){const d=st(r)??"";return{era:We(d),reign:mt(r,d)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const d=vn(s);if(d)return{era:Va(d.from),reign:"",source:"publication"};const u=st(s)??mi(s)??((c=It.find(m=>m.pattern.test(s)))==null?void 0:c.era)??"",g=mt(s,u)??"",x=u||(g?nt[g]??"":"");if(x||g)return{era:We(x),reign:g,source:"publication"}}const l=e.edition||e.title||"";if(l){const d=st(l);if(d)return{era:We(d),reign:mt(l,d)??"",source:"edition"};const u=It.find(g=>g.pattern.test(l));if(u)return{era:We(u.era),reign:mt(l,u.era)??u.reign??"",source:"edition"}}return n}function kn(e){var r,s,l,a,p,c,d,u,g;if(((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;if(typeof((s=e.lineage)==null?void 0:s.year)=="number")return e.lineage.year;const n=(l=e.publication_info)==null?void 0:l.year;if(n){const x=vn(n);if(x)return x.from}const i=[(a=e.lineage)==null?void 0:a.year_text,(p=e.publication_info)==null?void 0:p.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const x of i){const m=((c=e.publication_info)==null?void 0:c.year)||((d=e.lineage)==null?void 0:d.year_text);if(m&&x!==m&&(st(m)||mi(m)))break;const b=x.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??x.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const k=parseInt(b[1],10);if(k>=100&&k<=2100)return k}const S=x.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(S){const k=st(x);if(!k||We(k)==="民國"){const v=fn(S[1]);if(v!=null&&v>=1&&v<=120)return qa+v}}const h=st(x)??((u=It.find(k=>k.pattern.test(x)))==null?void 0:u.era),y=h?We(h):void 0,j=mt(x,y)??(st(x)||(g=It.find(k=>k.pattern.test(x)))==null?void 0:g.reign);if(j){const k=ft(j,y);if(k==null)continue;const $=x.indexOf(j),v=$>=0?x.slice($+j.length):"",_=v.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??v.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),w=_?fn(_[1]):void 0;return k+(w?w-1:0)}}}function hi(e){var a,p,c,d,u,g;const n=(a=e.dating)==null?void 0:a.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(p=e.lineage)==null?void 0:p.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const x=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(x){const m=Vn[We(x[1])],b=gt[We(x[2])];if(m!=null&&b!=null)return{from:Math.min(m,b)-20,to:Math.max(m,b)+40}}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const x=vn(s);if((x==null?void 0:x.to)!=null)return{from:x.from,to:x.to};const m=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(m){const b=Vn[We(m[1])],S=gt[We(m[2])];if(b!=null&&S!=null)return{from:Math.min(b,S)-20,to:Math.max(b,S)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const x of l){if(!/[間间]/.test(x))continue;const m=st(x)??mi(x)??((g=It.find(h=>h.pattern.test(x)))==null?void 0:g.era),b=m?We(m):void 0,S=[];for(const h of Object.keys(Tt))x.includes(h)&&(b&&nt[h]&&nt[h]!==b||ft(h,b)!=null&&S.push(h));if(S.length===0){const h=x.match(/([一-鿿])([一-鿿])[間间]/);if(h&&b){for(const y of[h[1],h[2]])for(const j of Object.keys(Tt))if(nt[j]===b&&!(j[0]!==y&&j[j.length-1]!==y)&&ft(j,b)!=null){S.push(j);break}}}if(S.length>0){const h=S.map($=>ft($,b)).filter($=>$!=null),y=Math.min(...h),j=S.reduce(($,v)=>ft($,b)>=ft(v,b)?$:v),k=Ka(j)??Ln(b??"")??Math.max(...h);return{from:y,to:k>y?k:Ln(b??nt[j]??"")??y}}if(b&&gt[b]!=null)return{from:gt[b],to:Ln(b)??gt[b]}}}const gt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Za=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Xa=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,ko=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function So(e,n){for(const i of Wr){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!mt(e.slice(r),We(i)))continue}const s=We(i);if(s===n)continue;const l=e.slice(r),a=mt(l,s)??"";let p;if(a){const c=ft(a,s);if(c!=null){const u=l.slice(l.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),g=u?fn(u[1]):void 0;p=c+(g?g-1:0)}}return{era:s,reign:a,year:p}}for(const i of It)if(i.pattern.test(e))return{era:We(i.era),reign:i.reign??""}}function Qa(e){var y,j,k,$,v;const n=Jt(e),i=((y=e.publication_info)==null?void 0:y.year)??"",r=i?vn(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),a=((j=e.lineage)==null?void 0:j.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(a),c=n.source==="publication"&&Ya.test(i),d=n.source==="publication"&&/[間间]/.test(i),u=a.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let g;l||p||c||d?g=void 0:u?g=parseInt(u[2],10):g=kn(e);const x=g==null?hi(e):void 0;let m;n.source==="publication"&&(c||ko.test(i))?m="uncertain":n.source==="lineage"||n.source==="publication"?m="attested":ko.test(s)||!n.reign&&g==null?m="uncertain":m="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((k=e.lineage)==null?void 0:k.year_text)??(($=e.lineage)==null?void 0:$.year)??""}」`:`出版著錄「${((v=e.publication_info)==null?void 0:v.year)??""}」`,S={era:n.era,reign:n.reign,year:g,yearRange:x,certainty:m,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const _=a.match(/[、,,]\s*([宋元明清])/);_&&_[1]!==S.era&&(S.laterRepair={era:_[1]})}if(!S.laterRepair&&Xa.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(S.laterRepair={era:_[1]})}const h=Za.find(_=>_.re.test(s));if(h){const _=s.search(h.re),w=s.slice(_),z=So(w,n.era)??So(s,n.era);z&&(S.basedOn={era:z.era,reign:z.reign,year:z.year,relation:h.relation})}return S}const Vn={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Ln(e){return Vn[e]}function gn(e){const n=kn(e);if(n!=null)return n;const i=hi(e);if(i)return i.from;const r=Jt(e).era;return r?gt[r]:void 0}const wo=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Yn(e){const n=wo.indexOf(e);return n===-1?wo.length:n}function ec(e){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of e){const l=s.relation;l==="part_of"?n.belongsTo.push(s):l==="collected_in"?n.collected.push(s):l==="has_part"||l==="contains_text_of"?n.contains.push(s):l==="text_carried_by"||l==="studied_by"||l==="derived_from"||l==="followed_by"||l==="has_adaptation"?n.derivative.push(s):l==="studies"||l==="preceded_by"?n.studies.push(s):n.related.push(s)}const i=[],r=(s,l)=>{n[s].length&&i.push({key:s,labelKey:l,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),i}function bi(e,n){const i=di(e||[]),r=new Map,s=[];for(const d of i)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((u,g)=>{const x=m=>m.group_role==="origin"?0:m.group_role==="mirror"?1:2;return x(u)-x(g)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=yt(d),g=u.includes("text"),x=u.includes("image");g&&x?l.textImage.push(d):g?l.text.push(d):x?l.image.push(d):l.physical.push(d)}const p=["text","image","textImage","physical"].filter(d=>l[d].length>0).map(d=>({key:d,items:l[d]})),c=[...r.entries()].map(([d,u])=>{var g,x;return{key:d,label:((g=n==null?void 0:n[d])==null?void 0:g.label)||d,description:(x=n==null?void 0:n[d])==null?void 0:x.description,items:u}});return{buckets:p,mirrors:c,total:i.length}}function Sn(e){const n=[],i=e.metadata||{};i.edition&&n.push(String(i.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const r=bn(e);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),i.version&&n.push(String(i.version)),n.join(" · ")}function Fr(e,n){if(Sn(e)||n.filter(r=>r.name===e.name).length<2)return"";try{const r=new URL(e.url),s=r.searchParams.get("res")||r.searchParams.get("id");if(s)return s;const l=r.pathname.split("/").filter(Boolean).pop();if(l)return decodeURIComponent(l)}catch{}return""}function Pr(e,n){var l,a;const i=e.resources||[],r=[],s=[];for(const p of i){const c=yt(p);c.includes("image")&&r.push(p),c.includes("physical")&&s.push(p)}return{id:e.id,name:e.edition||e.title||e.id,era:Jt(e),year:kn(e),sortYear:gn(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:tc(e.id,n),group:(a=n==null?void 0:n.node_groups)==null?void 0:a[e.id],hasImage:r.length>0}}function tc(e,n){var p,c;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(p=n.collections)==null?void 0:p[i];if(((r==null?void 0:r.book_ids)??(i==="core"?n.core_books??[]:[])).includes(e))return!0;const l=(r==null?void 0:r.groups)??[],a=(c=n.node_groups)==null?void 0:c[e];return!!a&&l.includes(a)}function Or(e,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!r.has(c.id)).map(c=>Pr(c,n));let l=s;i.era&&(l=l.filter(c=>c.era.era===i.era)),i.scanOnly&&(l=l.filter(c=>c.hasImage)),i.sort==="year"?l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=c.r.sortYear,g=d.r.sortYear;return u!=null&&g!=null?u-g||c.i-d.i:u!=null?-1:g!=null?1:c.i-d.i}).map(c=>c.r):l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=g=>(g.important?0:1)*2+(g.hasImage?0:1);return u(c.r)-u(d.r)||c.i-d.i}).map(c=>c.r);const p=[...new Set(s.map(c=>c.era.era).filter(Boolean))].sort((c,d)=>Yn(c)-Yn(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(c=>c.era.source==="edition")}}function nc(e,n){var h,y;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.length>0||s.length>0,a=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&a.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),c=new Set([...s,...a]),d=j=>{if(c.has(j))return!0;const k=n.node_groups[j];return k!=null&&p.has(k)},u=[],g=new Map,x=[];for(const j of e)if(!((y=n.excluded_books)!=null&&y.includes(j)))if(d(j))u.push(j);else{const k=n.node_groups[j];k?(g.has(k)||g.set(k,[]),g.get(k).push(j)):x.push(j)}if(x.length+[...g.values()].reduce((j,k)=>j+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(j=>[j.id,j])),S=[...g.entries()].map(([j,k])=>{const $=b.get(j);return{id:j,label:($==null?void 0:$.label)??j,description:$==null?void 0:$.description,ids:k}});return x.length>0&&S.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:S}}const Dr=["撰","編","注","校","譯","繪","其他"],ic=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function yi(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of ic)if(r.test(n))return i;return"其他"}function ji(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Hr(e){const n=new Map;for(const r of e){const s=yi(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:e.length}];for(const r of Dr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function Gr(e,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(a=>({id:a.work_id||a.book_id||void 0,title:a.title,section:a.section,volumes:a.volumes||[],subItems:a.sub_items,edition:a.edition,found:a.found_volumes,expected:a.expected_volumes})),l=[...new Set(s.map(a=>a.section).filter(Boolean))];return{rows:s,source:"catalog",sections:l,totalVolumes:n.total_volumes}}return e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(l=>({id:l.id,title:l.title,volumes:Ut(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,a;return{id:s,title:((l=i==null?void 0:i.get(s))==null?void 0:l.title)||s,edition:(a=i==null?void 0:i.get(s))==null?void 0:a.edition,volumes:[]}}),source:"books",sections:[]}}function Ut(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(n=>typeof n=="number");if(typeof e=="string"){const n=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[i,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-i+1)},(s,l)=>i+l)}return e.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function wn(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((l,a)=>l-a),r=i[0],s=i[i.length-1];return s-r+1===i.length?`${r}–${s}`:i.length<=3?i.join(", "):`${r}–${s} (${i.length}${n})`}const oc=["〇","一","二","三","四","五","六","七","八","九"],_o=["","十","百","千"];function Ur(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const a=parseInt(n[l]),p=i-1-l;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&p===1&&l===0?r+=_o[p]:r+=oc[a]+_o[p])}return r}function rc(e){return e==null?"":typeof e=="string"?e:e.title??""}function at(e,n="卷"){var r,s;const i=e;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?Ur(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Vr(e){var r;if(e.edition_type)return e.edition_type;if((r=e.lineage)!=null&&r.category)return e.lineage.category;const n=e.edition||e.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,l]of i)if(s.test(n))return l;return""}const sc="guji_markdown";function qn(e){const n=e==null?void 0:e.guji_markdown;if(typeof n!="string")return!1;const i=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!i)return!1;const r=parseInt(i[1],10),s=parseInt(i[2],10);return r>0||s>=2}const lc=/^□\{guess=([^\s{}]+)\}/;function ac(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function Yr(e,n){let i=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
12
- `)return-1;if(s==="\\"){r++;continue}if(s==="[")i++;else if(s==="]"&&(i--,i===0))return r}return-1}function cc(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function dc(e,n){const i=e[n];if(i==="["&&e[n+1]==="["){const r=e.indexOf("]]",n+2);return r>=0&&e.slice(n+2,r).indexOf(`
13
- `)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const r=Yr(e,n+3);return r>n+4?{node:{type:"zi",label:cc(e.slice(n+4,r))},end:r+1}:null}if(i==="□"&&e[n+1]==="{"){const r=lc.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function qr(e,n,i,r){const s=[];let l="";const a=()=>{if(!l)return;const p=r?l.replace(/\\?\|/g,""):l;p&&s.push({type:"text",text:p}),l=""};for(;n<e.length;){const p=e[n];if(i!==null){if(p===i)return a(),{nodes:s,end:n};if(p===`
14
- `)return null}const c=dc(e,n);if(c){a(),s.push(c.node),n=c.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&ac(e,n)&&(d=">"),d){const u=qr(e,n+1,d,!0);if(u){a(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return i!==null?null:(a(),{nodes:s,end:n})}function Kr(e){return qr(e,0,null,!1).nodes}function pc(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function Jr(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Jr(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const uc=216,$o="clamp(280px, 23vw, 360px)",xc=1440,Zr="(max-width: 719px)",fc=`${Zr}, (pointer: coarse)`,gc=`
15
- .bim-d-main.bim-d-main-grid { max-width: ${xc}px; padding: 16px 32px 0; }
11
+ }`,Ir={color:"inherit",textDecoration:"none"},fa=({snippet:e})=>{const{convert:n}=Z();return t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.6},children:vr(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))})},ga=({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:{...Ir,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(fa,{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})]})]})]})},ho=({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:{...Ir,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:"×"})]})},ma=({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 ha(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 ba({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 ya({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 ja({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 va({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 Tr=({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=ha(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(ba,{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(ya,{alt_names:e.alt_names}),t.jsx(ja,{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(va,{works:e.works,transport:n,onNavigate:o,renderLink:r})]})},ka=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function wa(e){const n=e.search(ka);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const Er={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===Sa(e))){const[l,d]=wa(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 Sa(e){try{return decodeURI(e)}catch{return e}}const _a={...Er,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},lt=({text:e,plainStrong:n,style:o,className:r})=>{const{convert:s}=Z(),l=n?_a:Er;return t.jsx("div",{className:r,style:o,children:t.jsx(Tl,{remarkPlugins:[El],components:l,children:s(e)})})},$a=["〇","一","二","三","四","五","六","七","八","九"],bo=["","十","百","千"];function Rr(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+=bo[p]:r+=$a[d]+bo[p])}return r}function Nr(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 za={book:i("type-book"),work:i("type-work"),collection:i("type-collection"),entity:i("type-entity")};function Ca({type:e}){const n=ue();return t.jsx("span",{style:Nr(za[e]),children:n.indexType[e]})}function Ia({isDraft:e}){const n=ue(),o=i(e?"status-draft":"status-official");return t.jsx("span",{style:Nr(o),children:e?n.status.draft:n.status.official})}function Ta({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 Lr({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 Ea({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(Ca,{type:r}),t.jsx(Ia,{isDraft:s}),t.jsx(Ta,{id:e})]}),((l==null?void 0:l.length)||p.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(Lr,{authors:l,type:r,onNavigate:a,renderLink:u}),p]})]})}function Br({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 Ra({items:e,onNavigate:n,renderLink:o}){const r=ue();return t.jsx(Br,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function Ar({items:e,onNavigate:n,renderLink:o}){const r=ue();return t.jsx(Br,{items:e,label:r.section.emendated,onNavigate:n,renderLink:o})}function Wr({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 Na({items:e}){const n=ue();return t.jsx(Wr,{label:n.section.aliases,items:e})}function La({items:e}){const n=ue();return t.jsx(Wr,{label:n.section.attachedTexts,items:e})}function Ba({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 Aa({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 Wa({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 yo({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 Nn({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(fi,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Ma({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=Fa(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(Nn,{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(Nn,{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(Nn,{book:j,onNavigate:r,renderLink:s},j.id))})]})}function Fa(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 Pa({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:[Rr(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(Lr,{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 Oa({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 gi=({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(q=>{F||(q?x(q):h(a.misc.notFoundEntry))}).catch(q=>{F||h(q instanceof Error?q.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 q=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(q?o.getItem(q).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,q)=>t.jsx("div",{style:{height:q===1?"32px":"16px",width:`${F}px`,background:i("widget-border"),borderRadius:"4px",opacity:.4}},q))})});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(Tr,{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=Rr(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,q)=>t.jsxs("span",{children:[q>0&&"、",t.jsx(Je,{id:F,onNavigate:r,renderLink:s})]},F))},"pws")),t.jsxs("div",{className:p,style:c,children:[t.jsx(Ea,{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,q)=>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")}})]},q))}),k.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:a.section.containedIn}),t.jsx(Oa,{items:k,onNavigate:r,renderLink:s})]}),b&&t.jsxs(t.Fragment,{children:[t.jsx(Ve,{children:a.section.belongsToWork}),t.jsx(Pa,{workData:b,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&t.jsx(Ba,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&t.jsx(Na,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&t.jsx(La,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&t.jsx(Ra,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&t.jsx(Ar,{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(fi,{items:v.resources,resourceGroups:v.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&t.jsx(Aa,{items:_.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&t.jsx(Wa,{items:S.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&t.jsx(yo,{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(yo,{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(Ma,{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=[],q=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 q.length>0&&F.push({label:a.section.belongsToWork,items:q}),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 Da({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 Ha({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:jo(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>o(s.name),style:jo(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 jo(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 Ga({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 Ua(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 vo({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?Ua(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(Ga,{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 mi=({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(Da,{data:y}),k&&t.jsx(Ha,{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(vo,{book:N,onNavigate:r,renderLink:s,showVolumes:N.volumes.length>1},`${S.volume}-${T}`))]},`${S.volume}-${z}`)):v.map((S,z)=>t.jsx(vo,{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)})},Mr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Va={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function We(e){return Va[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},Fr={"唐|元和":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 Ya(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 qa=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,ko={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function hi(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(ko))if(n.startsWith(s))return ko[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=Fr[`${n}|${e}`];if(o!=null)return o}return Tt[e]}const Ka=1911;function Ja(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 Za={零: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=Za[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 Mr)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&&Fr[`${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:Ya(a.from),reign:"",source:"publication"};const u=st(s)??hi(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)||hi(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 Ka+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 bi(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=Vn[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=Vn[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)??hi(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=Ja(y)??Ln(j??"")??Math.max(...h);return{from:b,to:k>b?k:Ln(j??it[y]??"")??b}}if(j&&gt[j]!=null)return{from:gt[j],to:Ln(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},Xa=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Qa=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,wo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function So(e,n){for(const o of Mr){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 ec(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"&&qa.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?bi(e):void 0;let m;n.source==="publication"&&(c||wo.test(o))?m="uncertain":n.source==="lineage"||n.source==="publication"?m="attested":wo.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&&Qa.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(w.laterRepair={era:_[1]})}const h=Xa.find(_=>_.re.test(s));if(h){const _=s.search(h.re),S=s.slice(_),z=So(S,n.era)??So(s,n.era);z&&(w.basedOn={era:z.era,reign:z.reign,year:z.year,relation:h.relation})}return w}const Vn={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Ln(e){return Vn[e]}function mn(e){const n=wn(e);if(n!=null)return n;const o=bi(e);if(o)return o.from;const r=Zt(e).era;return r?gt[r]:void 0}const _o=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Yn(e){const n=_o.indexOf(e);return n===-1?_o.length:n}function tc(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 yi(e,n){const o=pi(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 Pr(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 Or(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:nc(e.id,n),group:(d=n==null?void 0:n.node_groups)==null?void 0:d[e.id],hasImage:r.length>0}}function nc(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 Dr(e,n,o={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!r.has(c.id)).map(c=>Or(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)=>Yn(c)-Yn(a));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(c=>c.era.source==="edition")}}function ic(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 Hr=["撰","編","注","校","譯","繪","其他"],oc=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function ji(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:o,re:r}of oc)if(r.test(n))return o;return"其他"}function vi(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Gr(e){const n=new Map;for(const r of e){const s=ji(r);n.set(s,(n.get(s)??0)+1)}const o=[{cls:"全部",label:"全部",count:e.length}];for(const r of Hr){const s=n.get(r);s&&o.push({cls:r,label:r,count:s})}return o.length>2?o:[]}function Ur(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 rc=["〇","一","二","三","四","五","六","七","八","九"],$o=["","十","百","千"];function Vr(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+=$o[p]:r+=rc[d]+$o[p])}return r}function sc(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?Vr(o.juan_count.number)+n:(s=o.juan_count)!=null&&s.description?o.juan_count.description:""}function Yr(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 lc="guji_markdown";function qn(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 ac=/^□\{guess=([^\s{}]+)\}/;function cc(e,n){const o=e[n+1];return o!==void 0&&!/[A-Za-z/!?>\s]/.test(o)}function qr(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 dc(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function pc(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=qr(e,n+3);return r>n+4?{node:{type:"zi",label:dc(e.slice(n+4,r))},end:r+1}:null}if(o==="□"&&e[n+1]==="{"){const r=ac.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function Kr(e,n,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=pc(e,n);if(c){d(),s.push(c.node),n=c.end;continue}let a=null;if(p==="⟨"?a="⟩":p==="<"&&cc(e,n)&&(a=">"),a){const u=Kr(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 Jr(e){return Kr(e,0,null,!1).nodes}function uc(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function Zr(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Zr(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const xc=216,zo="clamp(280px, 23vw, 360px)",fc=1440,Xr="(max-width: 719px)",gc=`${Xr}, (pointer: coarse)`,mc=`
15
+ .bim-d-main.bim-d-main-grid { max-width: ${fc}px; padding: 16px 32px 0; }
16
16
  .bim-d-grid {
17
17
  display: grid;
18
- grid-template-columns: ${uc}px minmax(0, 1fr) ${$o};
18
+ grid-template-columns: ${xc}px minmax(0, 1fr) ${zo};
19
19
  grid-template-rows: auto 1fr;
20
20
  grid-template-areas: "rail main card" "rail main side";
21
21
  column-gap: 32px; row-gap: 28px; align-items: start;
@@ -26,66 +26,66 @@
26
26
  .bim-d-g-side { grid-area: side; min-width: 0; display: flex; flex-direction: column; gap: 28px; }
27
27
  .bim-d-g-side:empty { display: none; }
28
28
 
29
- .bim-d-meta { color: ${o("aux-fg")}; font-size: 13px; }
30
- .bim-d-dot::before { content: "·"; margin: 0 .45em; color: ${o("aux-fg")}; }
29
+ .bim-d-meta { color: ${i("aux-fg")}; font-size: 13px; }
30
+ .bim-d-dot::before { content: "·"; margin: 0 .45em; color: ${i("aux-fg")}; }
31
31
 
32
32
  /* 左栏 */
33
- .bim-d-rail-cap { font-size: 12px; letter-spacing: .2em; color: ${o("aux-fg")}; margin: 0 12px 6px; }
33
+ .bim-d-rail-cap { font-size: 12px; letter-spacing: .2em; color: ${i("aux-fg")}; margin: 0 12px 6px; }
34
34
  .bim-d-rail-nav { list-style: none; margin: 0; padding: 0; }
35
35
  .bim-d-rail-nav a {
36
36
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
37
37
  padding: 7px 12px; border-radius: 6px; font-size: 15px;
38
- color: ${o("quiet-fg")} !important; text-decoration: none !important;
38
+ color: ${i("quiet-fg")} !important; text-decoration: none !important;
39
39
  }
40
- .bim-d-rail-nav a:hover { background: ${o("zebra-bg")}; color: ${o("ink")} !important; }
40
+ .bim-d-rail-nav a:hover { background: ${i("zebra-bg")}; color: ${i("ink")} !important; }
41
41
  .bim-d-rail-nav .bim-d-meta { font-size: 12px; }
42
42
  .bim-d-rail-links { margin-top: 20px; }
43
43
  .bim-d-rail-back { display: inline-flex; align-items: center; min-height: 32px; padding: 0 12px;
44
- font-size: 13px; color: ${o("aux-fg")} !important; }
44
+ font-size: 13px; color: ${i("aux-fg")} !important; }
45
45
 
46
46
  /* 区块 */
47
47
  .bim-d-sec + .bim-d-sec { margin-top: 48px; }
48
48
  .bim-d-sec { scroll-margin-top: 16px; }
49
49
  .bim-d-sec-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; margin-bottom: 14px; }
50
- .bim-d-sec-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .04em; color: ${o("ink")}; }
50
+ .bim-d-sec-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .04em; color: ${i("ink")}; }
51
51
  .bim-d-sec-head .bim-d-sec-act { margin-left: auto; font-size: 13px; }
52
52
 
53
53
  /* 文字页签式筛选。min-height = 页签行高:朝代页签随次级数据晚到,行高先占好(INT Q3) */
54
54
  .bim-d-filters { min-height: 26px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; margin-bottom: 10px; font-size: 13px; }
55
55
  .bim-d-tab {
56
56
  background: none; border: 0; padding: 4px 0; cursor: pointer; font: inherit;
57
- color: ${o("quiet-fg")};
57
+ color: ${i("quiet-fg")};
58
58
  }
59
- .bim-d-tab:hover { color: ${o("ink")}; }
60
- .bim-d-tab[aria-pressed="true"] { color: ${o("accent")}; font-weight: 700; box-shadow: inset 0 -2px 0 ${o("accent")}; }
59
+ .bim-d-tab:hover { color: ${i("ink")}; }
60
+ .bim-d-tab[aria-pressed="true"] { color: ${i("accent")}; font-weight: 700; box-shadow: inset 0 -2px 0 ${i("accent")}; }
61
61
  .bim-d-groupbtn {
62
- background: none; border: 1px dashed ${o("rule-strong")}; border-radius: 3px; padding: 2px 8px; cursor: pointer;
63
- font: inherit; color: ${o("quiet-fg")};
62
+ background: none; border: 1px dashed ${i("rule-strong")}; border-radius: 3px; padding: 2px 8px; cursor: pointer;
63
+ font: inherit; color: ${i("quiet-fg")};
64
64
  }
65
- .bim-d-groupbtn:hover:not(:disabled) { color: ${o("accent")}; border-color: ${o("accent")}; }
65
+ .bim-d-groupbtn:hover:not(:disabled) { color: ${i("accent")}; border-color: ${i("accent")}; }
66
66
  .bim-d-groupbtn:disabled { cursor: progress; }
67
67
  .bim-d-filters .bim-d-spacer { flex: 1; }
68
- .bim-d-check { display: inline-flex; align-items: center; gap: 6px; color: ${o("quiet-fg")}; cursor: pointer; }
69
- .bim-d-check input { accent-color: ${o("accent")}; margin: 0; width: 15px; height: 15px; }
68
+ .bim-d-check { display: inline-flex; align-items: center; gap: 6px; color: ${i("quiet-fg")}; cursor: pointer; }
69
+ .bim-d-check input { accent-color: ${i("accent")}; margin: 0; width: 15px; height: 15px; }
70
70
 
71
71
  /* 斑马表:不画格线 */
72
72
  .bim-d-zt { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 15px; }
73
- .bim-d-zt th { text-align: left; font-weight: 400; color: ${o("aux-fg")}; font-size: 12px;
73
+ .bim-d-zt th { text-align: left; font-weight: 400; color: ${i("aux-fg")}; font-size: 12px;
74
74
  letter-spacing: .1em; padding: 6px 12px; white-space: nowrap; }
75
75
  .bim-d-zt td { padding: 10px 12px; vertical-align: baseline; }
76
- .bim-d-zt tbody tr:nth-child(odd) td { background: ${o("zebra-bg")}; }
76
+ .bim-d-zt tbody tr:nth-child(odd) td { background: ${i("zebra-bg")}; }
77
77
  .bim-d-zt tbody tr td:first-child { border-radius: 6px 0 0 6px; }
78
78
  .bim-d-zt tbody tr td:last-child { border-radius: 0 6px 6px 0; }
79
- .bim-d-zt tbody tr:hover td { background: ${o("tint-bg")}; }
79
+ .bim-d-zt tbody tr:hover td { background: ${i("tint-bg")}; }
80
80
  .bim-d-zt td.bim-d-zt-main { padding: 0; }
81
81
  .bim-d-zt td.bim-d-zt-main > a, .bim-d-zt td.bim-d-zt-main > span.bim-d-zt-name {
82
- display: block; padding: 10px 12px; color: ${o("ink")}; font-weight: 500;
82
+ display: block; padding: 10px 12px; color: ${i("ink")}; font-weight: 500;
83
83
  }
84
- .bim-d-zt td.bim-d-zt-main > a:hover { color: ${o("accent")}; }
84
+ .bim-d-zt td.bim-d-zt-main > a:hover { color: ${i("accent")}; }
85
85
  .bim-d-zt td.bim-d-zt-main .bim-d-meta { display: block; margin: -8px 12px 0; padding-bottom: 10px; font-size: 12px; font-weight: 400; }
86
- .bim-d-zt .bim-d-zt-sub { color: ${o("quiet-fg")}; font-size: 13px; }
86
+ .bim-d-zt .bim-d-zt-sub { color: ${i("quiet-fg")}; font-size: 13px; }
87
87
  .bim-d-zt .bim-d-zt-nowrap { white-space: nowrap; }
88
- .bim-d-zt .bim-d-zt-empty { color: ${o("aux-fg")}; }
88
+ .bim-d-zt .bim-d-zt-empty { color: ${i("aux-fg")}; }
89
89
  /* 版本表:行高先按「有影印」色块那一行的高度占好,解析到的年代、馆藏、色块进来时行不再长高(INT Q3) */
90
90
  .bim-d-zt-ver tbody tr { height: 58px; }
91
91
  /* 版本行一律「版本名 + 一行卷帙小字」(小字晚到,没有时也留空行):行高固定,
@@ -93,15 +93,15 @@
93
93
 
94
94
  .bim-d-flag {
95
95
  display: inline-block; padding: 1px 8px; border-radius: 4px;
96
- background: ${o("flag-bg")}; color: ${o("accent")} !important;
96
+ background: ${i("flag-bg")}; color: ${i("accent")} !important;
97
97
  font-size: 12px; line-height: 20px; white-space: nowrap;
98
98
  }
99
- a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg")}; }
99
+ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg")}; }
100
100
 
101
101
  .bim-d-more {
102
102
  display: inline-flex; align-items: center; min-height: 32px; margin-top: 6px;
103
103
  background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-size: 13px;
104
- color: ${o("accent")};
104
+ color: ${i("accent")};
105
105
  }
106
106
  .bim-d-more:hover { text-decoration: underline; text-underline-offset: 3px; }
107
107
 
@@ -110,208 +110,208 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
110
110
  .bim-d-tl2 { list-style: none; margin: 0 0 18px; padding: 0; display: flex; overflow-x: auto; }
111
111
  .bim-d-tl2 li { flex: 1 0 64px; min-width: 64px; }
112
112
  .bim-d-tl2 button { height: auto; display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; background: none;
113
- border: 0; cursor: pointer; padding: 4px 2px 8px; font: inherit; color: ${o("quiet-fg")}; position: relative; }
114
- .bim-d-tl2 button::before { content: ""; position: absolute; left: 0; right: 0; top: 30px; height: 1px; background: ${o("rule")}; }
115
- .bim-d-tl2-dyn { font-size: 12px; color: ${o("aux-fg")}; min-height: 18px; }
113
+ border: 0; cursor: pointer; padding: 4px 2px 8px; font: inherit; color: ${i("quiet-fg")}; position: relative; }
114
+ .bim-d-tl2 button::before { content: ""; position: absolute; left: 0; right: 0; top: 30px; height: 1px; background: ${i("rule")}; }
115
+ .bim-d-tl2-dyn { font-size: 12px; color: ${i("aux-fg")}; min-height: 18px; }
116
116
  .bim-d-tl2-dot { position: relative; width: 9px; height: 9px; border-radius: 50%; box-sizing: border-box;
117
- background: ${o("page-bg")}; border: 1px solid ${o("aux-fg")}; }
117
+ background: ${i("page-bg")}; border: 1px solid ${i("aux-fg")}; }
118
118
  .bim-d-tl2-name { display: flex; flex-direction: column; align-items: center; font-size: 15px; line-height: 1.25;
119
- font-family: ${o("font-serif")}; }; }
120
- .bim-d-tl2 button:hover .bim-d-tl2-name { color: ${o("accent")}; }
121
- .bim-d-tl2 button[aria-selected="true"] .bim-d-tl2-dot { background: ${o("accent")}; border-color: ${o("accent")}; }
122
- .bim-d-tl2 button[aria-selected="true"] .bim-d-tl2-name { color: ${o("ink")}; font-weight: 700; }
119
+ font-family: ${i("font-serif")}; }; }
120
+ .bim-d-tl2 button:hover .bim-d-tl2-name { color: ${i("accent")}; }
121
+ .bim-d-tl2 button[aria-selected="true"] .bim-d-tl2-dot { background: ${i("accent")}; border-color: ${i("accent")}; }
122
+ .bim-d-tl2 button[aria-selected="true"] .bim-d-tl2-name { color: ${i("ink")}; font-weight: 700; }
123
123
  .bim-d-lu-pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px;
124
- padding-top: 12px; border-top: 1px solid ${o("rule")}; font-size: 13px; }
125
- .bim-d-lu-pager button { background: none; border: 0; padding: 4px 0; cursor: pointer; font: inherit; color: ${o("accent")}; }
124
+ padding-top: 12px; border-top: 1px solid ${i("rule")}; font-size: 13px; }
125
+ .bim-d-lu-pager button { background: none; border: 0; padding: 4px 0; cursor: pointer; font: inherit; color: ${i("accent")}; }
126
126
  .bim-d-lu-pager button:disabled { cursor: default; }
127
127
  .bim-d-lu-pager button:not(:disabled):hover { text-decoration: underline; text-underline-offset: 3px; }
128
- .bim-d-lu-body { padding: 18px 22px 14px; min-width: 0; border-radius: 10px; background: ${o("card-bg")}; }
129
- .bim-d-lu-title { font-size: 17px; font-weight: 700; color: ${o("ink")}; }
130
- .bim-d-quote { margin: 14px 0 0; font-family: ${o("font-serif")}; font-size: 17px; line-height: 2;
131
- color: ${o("ink")}; text-align: justify; }
132
- .bim-d-quote-label { margin-top: 16px; font-size: 12px; letter-spacing: .1em; color: ${o("aux-fg")}; }
128
+ .bim-d-lu-body { padding: 18px 22px 14px; min-width: 0; border-radius: 10px; background: ${i("card-bg")}; }
129
+ .bim-d-lu-title { font-size: 17px; font-weight: 700; color: ${i("ink")}; }
130
+ .bim-d-quote { margin: 14px 0 0; font-family: ${i("font-serif")}; font-size: 17px; line-height: 2;
131
+ color: ${i("ink")}; text-align: justify; }
132
+ .bim-d-quote-label { margin-top: 16px; font-size: 12px; letter-spacing: .1em; color: ${i("aux-fg")}; }
133
133
  .bim-d-quote-label + .bim-d-quote { margin-top: 4px; }
134
134
 
135
135
  /* 提要卡 */
136
- .bim-d-card { background: ${o("card-bg")}; border-radius: 10px; padding: 24px;
137
- box-shadow: ${o("shadow-summary")}; }
136
+ .bim-d-card { background: ${i("card-bg")}; border-radius: 10px; padding: 24px;
137
+ box-shadow: ${i("shadow-summary")}; }
138
138
  .bim-d-card h1 { margin: 0; font-size: 36px; font-weight: 700; letter-spacing: .08em; line-height: 1.25;
139
- color: ${o("ink")}; word-break: break-word; }
139
+ color: ${i("ink")}; word-break: break-word; }
140
140
  .bim-d-card h1.bim-d-card-long { font-size: 26px; letter-spacing: .04em; line-height: 1.35; }
141
- .bim-d-card-sub { margin-top: 6px; font-size: 17px; font-weight: 500; color: ${o("quiet-fg")}; }
142
- .bim-d-card-byline { margin-top: 8px; font-size: 15px; color: ${o("ink")}; }
141
+ .bim-d-card-sub { margin-top: 6px; font-size: 17px; font-weight: 500; color: ${i("quiet-fg")}; }
142
+ .bim-d-card-byline { margin-top: 8px; font-size: 15px; color: ${i("ink")}; }
143
143
  .bim-d-card-cls { margin-top: 4px; }
144
- .bim-d-card-desc { margin-top: 16px; color: ${o("quiet-fg")}; line-height: 1.85; font-size: 15px; }
144
+ .bim-d-card-desc { margin-top: 16px; color: ${i("quiet-fg")}; line-height: 1.85; font-size: 15px; }
145
145
  /* 提要卡顶上的类型小字(版本 / 叢編 / 人物):四类页长得一样,靠它区分 */
146
- .bim-d-card-kind { margin-bottom: 6px; font-size: 12px; letter-spacing: .3em; color: ${o("aux-fg")}; }
146
+ .bim-d-card-kind { margin-bottom: 6px; font-size: 12px; letter-spacing: .3em; color: ${i("aux-fg")}; }
147
147
  /* 简介折叠:截到 N 行(行数由 --detail-clamp 给),「展開」后放开 */
148
148
  .bim-d-card-desc.bim-d-clamp { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden;
149
149
  -webkit-line-clamp: var(--detail-clamp, 6); }
150
150
  /* 截断时里面的 MarkdownText 段落不要再带上下外边距,免得第一行前空一截 */
151
151
  .bim-d-card-desc.bim-d-clamp > * { margin-top: 0; }
152
152
  .bim-d-card-toggle { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-size: 13px;
153
- color: ${o("accent")}; display: inline-flex; align-items: center; min-height: 28px; }
153
+ color: ${i("accent")}; display: inline-flex; align-items: center; min-height: 28px; }
154
154
  .bim-d-card-toggle:hover { text-decoration: underline; text-underline-offset: 3px; }
155
155
  .bim-d-card details.bim-d-more-names { margin-top: 8px; font-size: 13px; }
156
- .bim-d-card details.bim-d-more-names summary { cursor: pointer; color: ${o("accent")}; display: inline-flex;
156
+ .bim-d-card details.bim-d-more-names summary { cursor: pointer; color: ${i("accent")}; display: inline-flex;
157
157
  align-items: center; min-height: 28px; }
158
158
  .bim-d-card details.bim-d-more-names dl { margin-top: 6px; }
159
159
 
160
160
  /* 左栏「上一级」:版本页的所属作品、丛编页的上级丛编 */
161
- .bim-d-up { display: block; margin-top: 16px; padding: 10px 12px; border-radius: 8px; background: ${o("zebra-bg")}; }
162
- .bim-d-up-cap { display: block; font-size: 12px; letter-spacing: .1em; color: ${o("aux-fg")}; }
163
- .bim-d-up a { font-size: 16px; font-weight: 700; color: ${o("ink")} !important; }
164
- .bim-d-up a:hover { color: ${o("accent")} !important; }
165
- .bim-d-up a::after { content: " →"; font-weight: 400; color: ${o("aux-fg")}; }
161
+ .bim-d-up { display: block; margin-top: 16px; padding: 10px 12px; border-radius: 8px; background: ${i("zebra-bg")}; }
162
+ .bim-d-up-cap { display: block; font-size: 12px; letter-spacing: .1em; color: ${i("aux-fg")}; }
163
+ .bim-d-up a { font-size: 16px; font-weight: 700; color: ${i("ink")} !important; }
164
+ .bim-d-up a:hover { color: ${i("accent")} !important; }
165
+ .bim-d-up a::after { content: " →"; font-weight: 400; color: ${i("aux-fg")}; }
166
166
 
167
167
  /* 资源分组:一组一个小标题、一句说明;镜像收成一行文字链接,不再逐行重复组名 */
168
168
  .bim-d-rg + .bim-d-rg { margin-top: 22px; }
169
- .bim-d-rg-h { font-size: 15px; font-weight: 700; color: ${o("ink")}; margin: 0; }
170
- .bim-d-rg-d { font-size: 13px; color: ${o("aux-fg")}; margin: 2px 0 8px; max-width: 46em;
169
+ .bim-d-rg-h { font-size: 15px; font-weight: 700; color: ${i("ink")}; margin: 0; }
170
+ .bim-d-rg-d { font-size: 13px; color: ${i("aux-fg")}; margin: 2px 0 8px; max-width: 46em;
171
171
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
172
- .bim-d-rg-mir { padding: 6px 12px 0; font-size: 13px; color: ${o("quiet-fg")}; }
173
- .bim-d-rg-mir a { color: ${o("accent")} !important; margin-right: 14px; }
172
+ .bim-d-rg-mir { padding: 6px 12px 0; font-size: 13px; color: ${i("quiet-fg")}; }
173
+ .bim-d-rg-mir a { color: ${i("accent")} !important; margin-right: 14px; }
174
174
 
175
175
  /* 本站全文:一块浅底的阅读入口 + 回目网格(不另加按钮,主按钮在提要卡) */
176
176
  .bim-d-ft { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 24px; align-items: center;
177
- padding: 18px 20px; border-radius: 10px; background: ${o("zebra-bg")}; }
178
- .bim-d-ft-h { margin: 0; font-size: 17px; font-weight: 700; color: ${o("ink")}; }
177
+ padding: 18px 20px; border-radius: 10px; background: ${i("zebra-bg")}; }
178
+ .bim-d-ft-h { margin: 0; font-size: 17px; font-weight: 700; color: ${i("ink")}; }
179
179
  .bim-d-ft .bim-d-meta { grid-column: 1; }
180
- .bim-d-ft-go { grid-column: 2; grid-row: 1 / span 2; color: ${o("accent")} !important; font-weight: 500; white-space: nowrap; }
180
+ .bim-d-ft-go { grid-column: 2; grid-row: 1 / span 2; color: ${i("accent")} !important; font-weight: 500; white-space: nowrap; }
181
181
  .bim-d-chap { list-style: none; margin: 12px 0 0; padding: 0; display: grid;
182
182
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0 20px; font-size: 14px; }
183
- .bim-d-chap a { display: flex; gap: 10px; padding: 5px 0; color: ${o("quiet-fg")} !important;
183
+ .bim-d-chap a { display: flex; gap: 10px; padding: 5px 0; color: ${i("quiet-fg")} !important;
184
184
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
185
- .bim-d-chap a:hover { color: ${o("accent")} !important; }
185
+ .bim-d-chap a:hover { color: ${i("accent")} !important; }
186
186
  .bim-d-chap-pending { height: 142px; margin-top: 12px; }
187
- .bim-d-chap b { font-weight: 400; color: ${o("aux-fg")}; flex: none; }
187
+ .bim-d-chap b { font-weight: 400; color: ${i("aux-fg")}; flex: none; }
188
188
 
189
189
  /* 版本源流:一条竖线,靠字重和颜色分层,不画框 */
190
190
  .bim-d-tl { list-style: none; margin: 0; padding: 0 0 0 18px; position: relative; }
191
- .bim-d-tl::before { content: ""; position: absolute; left: 4px; top: 10px; bottom: 10px; width: 1px; background: ${o("rule")}; }
191
+ .bim-d-tl::before { content: ""; position: absolute; left: 4px; top: 10px; bottom: 10px; width: 1px; background: ${i("rule")}; }
192
192
  .bim-d-tl > li { position: relative; padding: 6px 0; }
193
193
  .bim-d-tl > li::before { content: ""; position: absolute; left: -18px; top: 15px; width: 9px; height: 9px;
194
- border-radius: 50%; background: ${o("rule-dashed")}; }
195
- .bim-d-tl > li.bim-d-tl-cur::before { background: ${o("accent")}; }
196
- .bim-d-tl-rel { display: inline-block; min-width: 4.5em; font-size: 12px; color: ${o("aux-fg")}; letter-spacing: .1em; }
197
- .bim-d-tl-t { color: ${o("ink")}; font-weight: 500; }
198
- .bim-d-tl-cur .bim-d-tl-t { color: ${o("accent")}; }
199
- .bim-d-tl-ev { display: block; margin-left: 4.5em; font-size: 12px; color: ${o("aux-fg")}; }
194
+ border-radius: 50%; background: ${i("rule-dashed")}; }
195
+ .bim-d-tl > li.bim-d-tl-cur::before { background: ${i("accent")}; }
196
+ .bim-d-tl-rel { display: inline-block; min-width: 4.5em; font-size: 12px; color: ${i("aux-fg")}; letter-spacing: .1em; }
197
+ .bim-d-tl-t { color: ${i("ink")}; font-weight: 500; }
198
+ .bim-d-tl-cur .bim-d-tl-t { color: ${i("accent")}; }
199
+ .bim-d-tl-ev { display: block; margin-left: 4.5em; font-size: 12px; color: ${i("aux-fg")}; }
200
200
  .bim-d-tl details { margin: 4px 0 0 4.5em; font-size: 13px; }
201
- .bim-d-tl summary { cursor: pointer; color: ${o("accent")}; display: inline-flex; align-items: center; min-height: 28px; }
201
+ .bim-d-tl summary { cursor: pointer; color: ${i("accent")}; display: inline-flex; align-items: center; min-height: 28px; }
202
202
 
203
203
  /* 著作举要:无框的排印块 */
204
204
  .bim-d-picks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 28px; }
205
- .bim-d-pick { padding: 16px 18px; border-radius: 10px; background: ${o("zebra-bg")}; min-width: 0; }
205
+ .bim-d-pick { padding: 16px 18px; border-radius: 10px; background: ${i("zebra-bg")}; min-width: 0; }
206
206
  .bim-d-pick-t { display: block; font-size: 18px; font-weight: 700; letter-spacing: .04em; }
207
- .bim-d-pick-t a { color: ${o("ink")} !important; }
208
- .bim-d-pick-t a:hover { color: ${o("accent")} !important; }
207
+ .bim-d-pick-t a { color: ${i("ink")} !important; }
208
+ .bim-d-pick-t a:hover { color: ${i("accent")} !important; }
209
209
  .bim-d-pick .bim-d-meta { display: block; margin-top: 4px; font-size: 12px; }
210
- .bim-d-pick-n { margin-top: 10px; font-size: 13px; color: ${o("quiet-fg")}; display: flex; gap: 8px; align-items: center; }
210
+ .bim-d-pick-n { margin-top: 10px; font-size: 13px; color: ${i("quiet-fg")}; display: flex; gap: 8px; align-items: center; }
211
211
 
212
212
  /* 著作举要:版本数放大 */
213
- .bim-d-pick-num { font-size: 26px; font-weight: 700; line-height: 1; color: ${o("ink")}; letter-spacing: 0; }
213
+ .bim-d-pick-num { font-size: 26px; font-weight: 700; line-height: 1; color: ${i("ink")}; letter-spacing: 0; }
214
214
  .bim-d-pick-num + span { font-size: 13px; }
215
215
  .bim-d-pick-n { align-items: baseline; }
216
216
  .bim-d-pick-n .bim-d-flag { margin-left: auto; }
217
- .bim-d-sec-sub { margin: -8px 0 16px; font-size: 13px; color: ${o("aux-fg")}; }
217
+ .bim-d-sec-sub { margin: -8px 0 16px; font-size: 13px; color: ${i("aux-fg")}; }
218
218
 
219
219
  /* 提要卡:生卒条、著作四部分布条 */
220
220
  .bim-d-life { margin-top: 18px; }
221
- .bim-d-life-bar { position: relative; height: 6px; border-radius: 3px; background: ${o("rule")}; }
222
- .bim-d-life-bar > i { position: absolute; top: 0; bottom: 0; border-radius: 3px; background: ${o("sect-jing")}; }
223
- .bim-d-life-lab { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: ${o("aux-fg")}; }
221
+ .bim-d-life-bar { position: relative; height: 6px; border-radius: 3px; background: ${i("rule")}; }
222
+ .bim-d-life-bar > i { position: absolute; top: 0; bottom: 0; border-radius: 3px; background: ${i("sect-jing")}; }
223
+ .bim-d-life-lab { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: ${i("aux-fg")}; }
224
224
  .bim-d-dist { margin-top: 18px; }
225
- .bim-d-dist-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: ${o("aux-fg")}; }
226
- .bim-d-dist-head b { font-size: 20px; color: ${o("ink")}; margin-right: 3px; }
225
+ .bim-d-dist-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: ${i("aux-fg")}; }
226
+ .bim-d-dist-head b { font-size: 20px; color: ${i("ink")}; margin-right: 3px; }
227
227
  .bim-d-dist-bar { display: flex; gap: 1px; height: 6px; margin-top: 8px; border-radius: 3px; overflow: hidden; }
228
228
  .bim-d-dist-bar > i { display: block; }
229
- .bim-d-dist-key { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 12px; color: ${o("quiet-fg")}; }
229
+ .bim-d-dist-key { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 12px; color: ${i("quiet-fg")}; }
230
230
  .bim-d-dist-key i { display: inline-block; width: 8px; height: 8px; margin-right: 4px; border-radius: 2px; }
231
231
  .bim-d-dist-seg { display: block; flex-basis: 0; min-width: 2px; height: 100%; padding: 0; border: 0; cursor: pointer; }
232
232
  .bim-d-dist-seg:disabled { cursor: default; }
233
- .bim-d-dist-seg[aria-pressed="true"] { outline: 2px solid ${o("ink")}; outline-offset: -2px; }
233
+ .bim-d-dist-seg[aria-pressed="true"] { outline: 2px solid ${i("ink")}; outline-offset: -2px; }
234
234
  .bim-d-dist-bar:has(.bim-d-dist-seg[aria-pressed="true"]) .bim-d-dist-seg:not([aria-pressed="true"]) { opacity: .35; }
235
235
  .bim-d-sq { display: inline-block; width: 7px; height: 7px; margin-right: 8px; border-radius: 1px; vertical-align: middle; }
236
- .bim-d-side-note { margin: 8px 0 0; font-size: 12px; color: ${o("aux-fg")}; }
236
+ .bim-d-side-note { margin: 8px 0 0; font-size: 12px; color: ${i("aux-fg")}; }
237
237
 
238
238
  /* 提要卡:数字格(版本 / 有影印 / 家著录) */
239
239
  .bim-d-stats { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; margin: 18px 0 0; padding: 14px 0 2px;
240
- border-top: 1px solid ${o("rule")}; }
241
- .bim-d-stats > div + div { padding-left: 14px; border-left: 1px solid ${o("rule")}; }
242
- .bim-d-stats b { display: block; font-size: 24px; font-weight: 700; line-height: 1.1; color: ${o("ink")}; }
243
- .bim-d-stats span { display: block; margin-top: 4px; font-size: 12px; color: ${o("aux-fg")}; }
244
- .bim-d-side-sub { margin: -2px 0 6px; font-size: 12px; color: ${o("aux-fg")}; }
245
- .bim-d-side li .bim-d-kind { padding: 0 6px; border-radius: 3px; background: ${o("zebra-bg")}; line-height: 18px; }
240
+ border-top: 1px solid ${i("rule")}; }
241
+ .bim-d-stats > div + div { padding-left: 14px; border-left: 1px solid ${i("rule")}; }
242
+ .bim-d-stats b { display: block; font-size: 24px; font-weight: 700; line-height: 1.1; color: ${i("ink")}; }
243
+ .bim-d-stats span { display: block; margin-top: 4px; font-size: 12px; color: ${i("aux-fg")}; }
244
+ .bim-d-side-sub { margin: -2px 0 6px; font-size: 12px; color: ${i("aux-fg")}; }
245
+ .bim-d-side li .bim-d-kind { padding: 0 6px; border-radius: 3px; background: ${i("zebra-bg")}; line-height: 18px; }
246
246
 
247
247
  /* 提要卡:版本类型/年代/卷帙 三个标签 */
248
248
  .bim-d-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
249
- .bim-d-tag { padding: 1px 8px; border-radius: 3px; font-size: 12px; line-height: 20px; color: ${o("quiet-fg")};
250
- background: ${o("zebra-bg")}; }
251
- .bim-d-tag-0 { background: ${o("flag-bg")}; color: ${o("accent")}; }
252
- .bim-d-tag-2 { background: none; box-shadow: inset 0 0 0 1px ${o("rule")}; }
249
+ .bim-d-tag { padding: 1px 8px; border-radius: 3px; font-size: 12px; line-height: 20px; color: ${i("quiet-fg")};
250
+ background: ${i("zebra-bg")}; }
251
+ .bim-d-tag-0 { background: ${i("flag-bg")}; color: ${i("accent")}; }
252
+ .bim-d-tag-2 { background: none; box-shadow: inset 0 0 0 1px ${i("rule")}; }
253
253
 
254
254
  /* 分段切换(卡片/关系图) */
255
- .bim-d-seg { display: inline-flex; border-radius: 6px; box-shadow: inset 0 0 0 1px ${o("rule")}; overflow: hidden; }
255
+ .bim-d-seg { display: inline-flex; border-radius: 6px; box-shadow: inset 0 0 0 1px ${i("rule")}; overflow: hidden; }
256
256
  .bim-d-seg button { min-height: 28px; padding: 0 12px; border: 0; background: none; cursor: pointer; font: inherit;
257
- font-size: 13px; color: ${o("quiet-fg")}; }
258
- .bim-d-seg button[aria-pressed="true"] { background: ${o("flag-bg")}; color: ${o("accent")}; font-weight: 700; }
257
+ font-size: 13px; color: ${i("quiet-fg")}; }
258
+ .bim-d-seg button[aria-pressed="true"] { background: ${i("flag-bg")}; color: ${i("accent")}; font-weight: 700; }
259
259
 
260
260
  /* 版本源流·卡片流 */
261
261
  .bim-d-lf-list { list-style: none; margin: 0; padding: 0 0 0 22px; position: relative; }
262
- .bim-d-lf-list::before { content: ""; position: absolute; left: 4px; top: 12px; bottom: 12px; width: 1px; background: ${o("rule")}; }
262
+ .bim-d-lf-list::before { content: ""; position: absolute; left: 4px; top: 12px; bottom: 12px; width: 1px; background: ${i("rule")}; }
263
263
  .bim-d-lf-node { position: relative; padding: 6px 0; }
264
264
  .bim-d-lf-node::before { content: ""; position: absolute; left: -22px; top: 22px; width: 9px; height: 9px; border-radius: 50%;
265
- box-sizing: border-box; background: ${o("page-bg")}; border: 1px solid ${o("aux-fg")}; }
266
- .bim-d-lf-cur::before { background: ${o("accent")}; border-color: ${o("accent")}; }
265
+ box-sizing: border-box; background: ${i("page-bg")}; border: 1px solid ${i("aux-fg")}; }
266
+ .bim-d-lf-cur::before { background: ${i("accent")}; border-color: ${i("accent")}; }
267
267
  .bim-d-lf-out::before { top: 16px; }
268
268
  .bim-d-lf-card, .bim-d-lf-dash { padding: 12px 16px; border-radius: 8px; min-width: 0; }
269
- .bim-d-lf-card { background: ${o("card-bg")}; box-shadow: inset 0 0 0 1px ${o("rule")}; }
270
- .bim-d-lf-dash { box-shadow: inset 0 0 0 1px ${o("rule-dashed")}; }
269
+ .bim-d-lf-card { background: ${i("card-bg")}; box-shadow: inset 0 0 0 1px ${i("rule")}; }
270
+ .bim-d-lf-dash { box-shadow: inset 0 0 0 1px ${i("rule-dashed")}; }
271
271
  .bim-d-lf-tag { display: inline-block; margin-right: 10px; padding: 0 7px; border-radius: 3px; font-size: 12px; line-height: 20px;
272
- background: ${o("zebra-bg")}; color: ${o("quiet-fg")}; }
273
- .bim-d-lf-name { font-weight: 700; color: ${o("ink")}; }
274
- .bim-d-lf-ev { margin: 6px 0 0; font-size: 13px; line-height: 1.8; color: ${o("quiet-fg")}; }
272
+ background: ${i("zebra-bg")}; color: ${i("quiet-fg")}; }
273
+ .bim-d-lf-name { font-weight: 700; color: ${i("ink")}; }
274
+ .bim-d-lf-ev { margin: 6px 0 0; font-size: 13px; line-height: 1.8; color: ${i("quiet-fg")}; }
275
275
  .bim-d-lf-cur { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
276
- .bim-d-lf-here { padding: 12px 16px; border-radius: 8px; background: ${o("accent")}; color: ${o("on-color-fg")}; min-width: 0; }
277
- .bim-d-lf-here .bim-d-lf-name { color: ${o("on-color-fg")}; }
278
- .bim-d-lf-here .bim-d-lf-tag { background: color-mix(in srgb, ${o("on-color-fg")} 18%, transparent); color: ${o("on-color-fg")}; }
276
+ .bim-d-lf-here { padding: 12px 16px; border-radius: 8px; background: ${i("accent")}; color: ${i("on-color-fg")}; min-width: 0; }
277
+ .bim-d-lf-here .bim-d-lf-name { color: ${i("on-color-fg")}; }
278
+ .bim-d-lf-here .bim-d-lf-tag { background: color-mix(in srgb, ${i("on-color-fg")} 18%, transparent); color: ${i("on-color-fg")}; }
279
279
  .bim-d-lf-yr { display: block; margin-top: 4px; font-size: 13px; opacity: .9; }
280
280
  .bim-d-lf-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
281
281
  .bim-d-lf-out { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
282
- .bim-d-lf-out-h { font-size: 12px; letter-spacing: .1em; color: ${o("aux-fg")}; }
282
+ .bim-d-lf-out-h { font-size: 12px; letter-spacing: .1em; color: ${i("aux-fg")}; }
283
283
  .bim-d-lf-chips { display: flex; flex-wrap: wrap; gap: 8px; }
284
284
  .bim-d-lf-chip { display: inline-flex; align-items: baseline; gap: 6px; padding: 3px 10px; border-radius: 6px;
285
- box-shadow: inset 0 0 0 1px ${o("rule")}; font-size: 14px; }
285
+ box-shadow: inset 0 0 0 1px ${i("rule")}; font-size: 14px; }
286
286
  .bim-d-lf-app { margin-top: 10px; font-size: 14px; }
287
- .bim-d-lf-app summary { cursor: pointer; min-height: 28px; display: inline-flex; align-items: center; gap: 6px; color: ${o("accent")}; }
287
+ .bim-d-lf-app summary { cursor: pointer; min-height: 28px; display: inline-flex; align-items: center; gap: 6px; color: ${i("accent")}; }
288
288
 
289
289
  /* 影印分组:一组一张卡 */
290
- .bim-d-rg { padding: 14px 16px 10px; border-radius: 10px; background: ${o("card-bg")}; box-shadow: inset 0 0 0 1px ${o("rule")}; }
290
+ .bim-d-rg { padding: 14px 16px 10px; border-radius: 10px; background: ${i("card-bg")}; box-shadow: inset 0 0 0 1px ${i("rule")}; }
291
291
  .bim-d-rg .bim-d-zt tbody tr:nth-child(odd) td { background: none; }
292
292
 
293
293
  /* 旁栏:时间轴点(同作品版本) */
294
294
  .bim-d-side-tl ul { position: relative; padding-left: 16px; }
295
- .bim-d-side-tl ul::before { content: ""; position: absolute; left: 3px; top: 12px; bottom: 12px; width: 1px; background: ${o("rule")}; }
295
+ .bim-d-side-tl ul::before { content: ""; position: absolute; left: 3px; top: 12px; bottom: 12px; width: 1px; background: ${i("rule")}; }
296
296
  .bim-d-side-tl li { position: relative; }
297
297
  .bim-d-side-tl li::before { content: ""; position: absolute; left: -16px; top: 14px; width: 7px; height: 7px; border-radius: 50%;
298
- box-sizing: border-box; background: ${o("page-bg")}; border: 1px solid ${o("aux-fg")}; }
299
- .bim-d-side-tl li.bim-d-side-cur::before { background: ${o("accent")}; border-color: ${o("accent")}; }
298
+ box-sizing: border-box; background: ${i("page-bg")}; border: 1px solid ${i("aux-fg")}; }
299
+ .bim-d-side-tl li.bim-d-side-cur::before { background: ${i("accent")}; border-color: ${i("accent")}; }
300
300
 
301
301
  /* 本页内检索(丛编子目) */
302
302
  .bim-d-find { height: 30px; min-width: 190px; padding: 0 12px; border: 0; border-radius: 6px; box-sizing: border-box;
303
- background: ${o("tint-bg")}; color: ${o("ink")}; font: inherit; font-size: 13px; }
304
- .bim-d-find::placeholder { color: ${o("aux-fg")}; }
305
- .bim-d-find:focus { outline: 2px solid ${o("accent")}; outline-offset: 1px; }
303
+ background: ${i("tint-bg")}; color: ${i("ink")}; font: inherit; font-size: 13px; }
304
+ .bim-d-find::placeholder { color: ${i("aux-fg")}; }
305
+ .bim-d-find:focus { outline: 2px solid ${i("accent")}; outline-offset: 1px; }
306
306
 
307
307
  /* 旁栏:当前条目高亮 */
308
- .bim-d-side-all a { color: ${o("accent")} !important; }
309
- .bim-d-side li.bim-d-side-cur, .bim-d-side li.bim-d-side-cur .bim-d-meta { color: ${o("accent")}; font-weight: 500; }
308
+ .bim-d-side-all a { color: ${i("accent")} !important; }
309
+ .bim-d-side li.bim-d-side-cur, .bim-d-side li.bim-d-side-cur .bim-d-meta { color: ${i("accent")}; font-weight: 500; }
310
310
  .bim-d-card dl { margin: 18px 0 0; display: grid; grid-template-columns: auto minmax(0, 1fr);
311
311
  gap: 6px 16px; font-size: 13px; }
312
- .bim-d-card dt { color: ${o("aux-fg")}; white-space: nowrap; }
313
- .bim-d-card dd { margin: 0; color: ${o("ink")}; min-width: 0; overflow-wrap: anywhere; }
314
- .bim-d-card-foot { margin-top: 14px; font-size: 12px; text-align: center; color: ${o("aux-fg")}; }
312
+ .bim-d-card dt { color: ${i("aux-fg")}; white-space: nowrap; }
313
+ .bim-d-card dd { margin: 0; color: ${i("ink")}; min-width: 0; overflow-wrap: anywhere; }
314
+ .bim-d-card-foot { margin-top: 14px; font-size: 12px; text-align: center; color: ${i("aux-fg")}; }
315
315
  .bim-d-card-foot:empty { display: none; }
316
316
  .bim-d-card-foot details { text-align: left; margin-top: 6px; }
317
317
  .bim-d-card-foot summary { cursor: pointer; display: inline-flex; align-items: center; min-height: 32px; }
@@ -320,27 +320,27 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
320
320
  .bim-d-btn {
321
321
  display: flex; align-items: center; justify-content: center; margin-top: 22px; width: 100%;
322
322
  height: 44px; padding: 0 24px; border: 0; border-radius: 8px; box-sizing: border-box;
323
- background: ${o("accent")}; color: ${o("on-color-fg")} !important;
324
- font: 500 15px/1 ${o("font-ui")}; letter-spacing: .08em; cursor: pointer; white-space: nowrap;
323
+ background: ${i("accent")}; color: ${i("on-color-fg")} !important;
324
+ font: 500 15px/1 ${i("font-ui")}; letter-spacing: .08em; cursor: pointer; white-space: nowrap;
325
325
  text-decoration: none !important;
326
326
  }
327
- .bim-d-btn:hover { background: ${o("accent-deep")}; }
327
+ .bim-d-btn:hover { background: ${i("accent-deep")}; }
328
328
  .bim-d-card-alt { display: flex; align-items: center; justify-content: center; min-height: 40px; margin-top: 8px;
329
- border-radius: 6px; background: ${o("flag-bg")}; font-size: 14px; color: ${o("accent")} !important; }
330
- .bim-d-card-alt:hover { text-decoration: none !important; background: ${o("tint-bg")}; }
329
+ border-radius: 6px; background: ${i("flag-bg")}; font-size: 14px; color: ${i("accent")} !important; }
330
+ .bim-d-card-alt:hover { text-decoration: none !important; background: ${i("tint-bg")}; }
331
331
 
332
332
  /* 旁栏清单:小标题是 h2(提要卡 h1 之下不跳级,INT Q5),外观仍是 15px 小标题 */
333
- .bim-d-side h3, .bim-d-side .bim-d-side-h { margin: 0 0 6px; font-size: 15px; font-weight: 700; color: ${o("ink")};
333
+ .bim-d-side h3, .bim-d-side .bim-d-side-h { margin: 0 0 6px; font-size: 15px; font-weight: 700; color: ${i("ink")};
334
334
  display: flex; align-items: baseline; gap: 8px; }
335
335
  .bim-d-side h3 .bim-d-meta, .bim-d-side .bim-d-side-h .bim-d-meta { font-weight: 400; font-size: 12px; }
336
336
  .bim-d-side ul { list-style: none; margin: 0; padding: 0; }
337
337
  .bim-d-side li { display: flex; align-items: baseline; gap: 10px; padding: 5px 0; font-size: 15px; min-width: 0; }
338
- .bim-d-side li > a, .bim-d-side li > span:first-child { color: ${o("ink")}; min-width: 0; overflow-wrap: anywhere; }
339
- .bim-d-side li > a:hover { color: ${o("accent")}; }
338
+ .bim-d-side li > a, .bim-d-side li > span:first-child { color: ${i("ink")}; min-width: 0; overflow-wrap: anywhere; }
339
+ .bim-d-side li > a:hover { color: ${i("accent")}; }
340
340
  .bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
341
341
 
342
342
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
343
- @media ${fc} {
343
+ @media ${gc} {
344
344
  .bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
345
345
  .bim-d-card-foot summary, .bim-d-card-toggle, .bim-d-card details.bim-d-more-names summary,
346
346
  .bim-d-tl summary, .bim-d-chap a { min-height: 44px; }
@@ -378,7 +378,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
378
378
  /* 中等宽度:左栏折到顶部一行 */
379
379
  @media (max-width: 1100px) {
380
380
  .bim-d-grid {
381
- grid-template-columns: minmax(0, 1fr) ${$o};
381
+ grid-template-columns: minmax(0, 1fr) ${zo};
382
382
  grid-template-rows: auto auto 1fr;
383
383
  grid-template-areas: "rail rail" "main card" "main side";
384
384
  }
@@ -387,12 +387,12 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
387
387
  .bim-d-rail-links { margin-top: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 0 16px; }
388
388
  .bim-d-rail-links .bim-d-rail-cap { display: none; }
389
389
  .bim-d-rail-links .bim-d-rail-nav { display: flex; flex-wrap: wrap; gap: 0 16px; }
390
- .bim-d-rail-links .bim-d-rail-nav a { padding: 7px 0; color: ${o("accent")} !important; font-size: 14px; }
390
+ .bim-d-rail-links .bim-d-rail-nav a { padding: 7px 0; color: ${i("accent")} !important; font-size: 14px; }
391
391
  .bim-d-up { display: inline-block; margin-top: 12px; }
392
392
  }
393
393
 
394
394
  /* 手机:左栏收起,提要卡 → 正文 → 旁栏 */
395
- @media ${Zr} {
395
+ @media ${Xr} {
396
396
  .bim-d-main.bim-d-main-grid { padding: 8px 16px 0; }
397
397
  .bim-d-grid {
398
398
  grid-template-columns: minmax(0, 1fr);
@@ -406,11 +406,11 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
406
406
  .bim-d-zt thead { display: none; }
407
407
  .bim-d-zt, .bim-d-zt tbody, .bim-d-zt tr, .bim-d-zt td { display: block; width: 100%; box-sizing: border-box; }
408
408
  .bim-d-zt tr { padding: 0 0 10px; border-radius: 6px; }
409
- .bim-d-zt tbody tr:nth-child(odd) { background: ${o("zebra-bg")}; }
409
+ .bim-d-zt tbody tr:nth-child(odd) { background: ${i("zebra-bg")}; }
410
410
  .bim-d-zt tbody tr:nth-child(odd) td, .bim-d-zt tbody tr:hover td { background: transparent; }
411
411
  .bim-d-zt td { padding: 0 12px; }
412
412
  .bim-d-zt td:not(.bim-d-zt-main) { display: inline; width: auto; padding: 0 0 0 12px; font-size: 12px;
413
- color: ${o("aux-fg")}; }
413
+ color: ${i("aux-fg")}; }
414
414
  .bim-d-zt td.bim-d-zt-blank { display: none; }
415
415
  .bim-d-zt td.bim-d-zt-main .bim-d-meta { padding-bottom: 2px; }
416
416
  /* 手机上版本行是块:解析前先按「名 + 卷帙小字 + 一行年代馆藏」占高(实测解析后 81–87px) */
@@ -433,16 +433,16 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
433
433
  .bim-d-pick-n { margin: 0; grid-column: 2; grid-row: 1 / span 2; }
434
434
  .bim-d-find { flex-basis: 100%; min-height: 40px; }
435
435
  }
436
- `;function Zt({railTop:e,back:n,up:i,nav:r,railLinks:s,main:l,card:a,side:p}){const{convert:c}=q(),d=(r||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,n&&t.jsx("div",{style:{marginTop:e?12:0},children:n}),i,d.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":c("本頁導航"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:c("本頁")}),t.jsx("ul",{className:"bim-d-rail-nav",children:d.map(u=>t.jsx("li",{children:t.jsxs("a",{href:`#${u.id}`,children:[t.jsx("span",{children:c(u.label)}),u.count!=null&&t.jsx("span",{className:"bim-d-meta",children:u.count})]})},u.id))})]}),s&&s.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("更多"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:c("更多")}),t.jsx("ul",{className:"bim-d-rail-nav",children:s.map(u=>t.jsx("li",{children:t.jsxs("a",{href:u.href??"#",onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),u.onClick())},children:[t.jsx("span",{children:c(u.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},u.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:l}),t.jsx("div",{className:"bim-d-g-card",children:a}),t.jsx("div",{className:"bim-d-g-side",children:p})]})}function Xr({caption:e,children:n}){const{convert:i}=q();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:i(e)}),n]})}function Fe({id:e,title:n,meta:i,action:r,children:s}){const{convert:l}=q();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:l(n)}),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i}),r&&t.jsx("span",{className:"bim-d-sec-act",children:r})]}),s]})}function Me({items:e,className:n,style:i}){const r=e.filter(s=>s!=null&&s!==""&&s!==!1);return r.length?t.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:i,children:r.map((s,l)=>t.jsxs(f.Fragment,{children:[l>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},l))}):null}function _n({items:e,value:n,onChange:i}){const{convert:r}=q();return t.jsx(t.Fragment,{children:e.map(s=>t.jsx("button",{type:"button",className:[...r(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>i(s.key),children:r(s.label)},s.key))})}function Qr({label:e,checked:n,onChange:i}){const{convert:r}=q();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:s=>i(s.target.checked)}),r(e)]})}function Bt({label:e,onClick:n}){const{convert:i}=q();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:i(e)})}function Xt({kind:e,title:n,subtitle:i,byline:r,meta:s,description:l,clampDescription:a,facts:p,stats:c,readAction:d,secondaryAction:u,children:g,foot:x}){const{convert:m}=q(),b=(p||[]).filter(k=>k.value!=null&&k.value!==""),S=(c||[]).filter(k=>k.value!=null&&k.value!==""&&k.value!==0),[h,y]=f.useState(!1),j=!!a&&!h;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:m(e)}),t.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),i&&t.jsx("div",{className:"bim-d-card-sub",children:i}),r&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:r}),s&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),l&&t.jsx("div",{className:j?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:j?{"--detail-clamp":a}:void 0,children:l}),l&&!!a&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":h,onClick:()=>y(k=>!k),children:m(h?"收起":"展開")}),S.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:S.map((k,$)=>t.jsxs("div",{children:[t.jsx("b",{children:k.value}),t.jsx("span",{children:m(k.label)})]},$))}),b.length>0&&t.jsx("dl",{className:"bim-d-ui",children:b.map((k,$)=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:m(k.label)}),t.jsx("dd",{title:k.title,children:k.value})]},$))}),g,d,u,x&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:x})]})}function vi(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function Kn({href:e,onClick:n,label:i="閱讀全文"}){const{convert:r}=q();return e?t.jsx("a",{className:"bim-d-btn",href:e,onClick:n?s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),n())}:void 0,children:r(i)}):t.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:r(i)})}function ht({id:e,title:n,meta:i,items:r,metas:s,currentIndex:l,cap:a=8,moreLabel:p,foot:c,sub:d,timeline:u}){const{convert:g}=q(),[x,m]=f.useState(!1);if(!r.length)return null;const b=x?r:r.slice(0,a),S=r.length-b.length;return t.jsxs("div",{id:e,className:u?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[g(n),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i})]}),d&&t.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:d}),t.jsx("ul",{children:b.map((h,y)=>t.jsxs("li",{className:y===l?"bim-d-side-cur":void 0,"aria-current":y===l?"page":void 0,children:[h,s!=null&&s[y]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[y]}):null]},y))}),S>0&&t.jsx(Bt,{label:p?p(S):`顯示更多(${S})`,onClick:()=>m(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const mc={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function Qt({revision:e,revisedAt:n,review:i,todo:r}){const{convert:s}=q(),l=i?mc[i.status]:void 0,a=i&&i.status!=="unreviewed"&&l?[l,i.by,i.date].filter(Boolean).join(" "):"",p=[e!=null&&e!==""?`${s("數據版本")} ${e}`:"",n??"",s(a)].filter(Boolean),c=(r||[]).filter(d=>d&&d.what);return!p.length&&!c.length?null:t.jsxs(t.Fragment,{children:[p.length>0&&t.jsx(Me,{items:p,style:{fontSize:12}}),c.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s(`待核 ${c.length} 項`)}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:c.map((d,u)=>t.jsxs("li",{children:[s(d.what),(d.by||d.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[d.by&&s(d.by),d.date].filter(Boolean).join(" · "),")"]})]},u))})]})]})}const pn=1e3,zo=208,hc=1440,bc="(max-width: 719px)",es=`
436
+ `;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 Qr({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})]}),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 es({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 ki(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function Kn({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 hc={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function en({revision:e,revisedAt:n,review:o,todo:r}){const{convert:s}=Z(),l=o?hc[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,Co=208,bc=1440,yc="(max-width: 719px)",ts=`
437
437
  .bim-d-page {
438
- background: ${o("page-bg")};
439
- color: ${o("ink")};
438
+ background: ${i("page-bg")};
439
+ color: ${i("ink")};
440
440
  font-family: var(--bim-font-body, system-ui, sans-serif);
441
441
  min-height: 100%;
442
442
  padding-bottom: 64px;
443
443
  }
444
444
  .bim-d-main {
445
- max-width: ${pn}px;
445
+ max-width: ${un}px;
446
446
  margin: 0 auto;
447
447
  padding: 24px clamp(16px, 4vw, 28px) 0;
448
448
  }
@@ -453,23 +453,23 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
453
453
  * PAGE_MAX_WIDTH,读者的行宽体验不变。
454
454
  */
455
455
  .bim-d-main.bim-d-main-wide {
456
- max-width: ${hc}px;
456
+ max-width: ${bc}px;
457
457
  }
458
458
  .bim-d-ui { font-family: var(--bim-font-ui, system-ui, sans-serif); }
459
459
 
460
- .bim-d-page a { color: ${o("accent")}; text-decoration: none; }
460
+ .bim-d-page a { color: ${i("accent")}; text-decoration: none; }
461
461
  .bim-d-page a:hover {
462
- color: ${o("accent-deep")};
462
+ color: ${i("accent-deep")};
463
463
  text-decoration: underline;
464
464
  text-decoration-thickness: 1px;
465
465
  text-underline-offset: 3px;
466
466
  }
467
- .bim-d-page ::selection { background: ${o("selection-bg")}; }
467
+ .bim-d-page ::selection { background: ${i("selection-bg")}; }
468
468
 
469
469
  /* 表格行 */
470
470
  .bim-d-row { display: grid; align-items: center; padding: 9px 4px;
471
- border-bottom: 1px solid ${o("rule")}; font-size: 14px; }
472
- .bim-d-row:hover { background: ${o("row-hover-bg")}; }
471
+ border-bottom: 1px solid ${i("rule")}; font-size: 14px; }
472
+ .bim-d-row:hover { background: ${i("row-hover-bg")}; }
473
473
 
474
474
  /*
475
475
  * 全文阅读布局(整理本 / Book 全文)。
@@ -485,9 +485,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
485
485
  */
486
486
  .bim-d-reader {
487
487
  display: grid;
488
- grid-template-columns: ${zo}px minmax(0, ${pn}px);
488
+ grid-template-columns: ${Co}px minmax(0, ${un}px);
489
489
  gap: 32px;
490
- max-width: ${zo+pn+32}px;
490
+ max-width: ${Co+un+32}px;
491
491
  margin: 0 auto;
492
492
  align-items: start;
493
493
  }
@@ -498,19 +498,19 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
498
498
  overflow-y: auto;
499
499
  overscroll-behavior: contain;
500
500
  padding-right: 4px;
501
- border-right: 1px solid ${o("rule")};
501
+ border-right: 1px solid ${i("rule")};
502
502
  }
503
503
  .bim-d-reader-main { min-width: 0; }
504
504
 
505
505
  /* intro / 成对区块:宽屏两栏,窄屏单栏 */
506
506
  .bim-d-intro { display: grid; grid-template-columns: minmax(0, 1fr) 244px; gap: 30px;
507
- padding: 20px 0 26px; border-bottom: 1px solid ${o("rule")};
507
+ padding: 20px 0 26px; border-bottom: 1px solid ${i("rule")};
508
508
  margin-bottom: 40px; align-items: start; }
509
509
  .bim-d-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 34px;
510
510
  align-items: start; margin-bottom: 48px; }
511
511
  .bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
512
512
 
513
- @media ${bc} {
513
+ @media ${yc} {
514
514
  .bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
515
515
  .bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
516
516
  /* 表格:meta 列折到第二行,表头隐藏 */
@@ -524,18 +524,18 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
524
524
  .bim-d-reader { grid-template-columns: 1fr; gap: 16px; }
525
525
  .bim-d-reader-aside {
526
526
  position: static; max-height: 240px;
527
- border-right: none; border-bottom: 1px solid ${o("rule")};
527
+ border-right: none; border-bottom: 1px solid ${i("rule")};
528
528
  padding-right: 0; padding-bottom: 12px;
529
529
  }
530
530
  }
531
- ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:es}),t.jsx("div",{className:r?"bim-d-main bim-d-main-grid":i?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function Jn({breadcrumb:e,actions:n}){return t.jsxs("div",{className:"bim-d-ui bim-d-top",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:o("aux-fg")},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:e}),n&&t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function ki({char:e,tone:n="accent"}){return t.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,flex:"none",fontSize:11,fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",background:o(n==="accent"?"accent":"ink"),color:o("page-bg")},children:e})}function Zn({items:e}){const n=Pe();return t.jsx(t.Fragment,{children:e.map((i,r)=>{const s=r===e.length-1,l=r>0&&t.jsx("span",{style:{color:o("hint-fg")},children:"/"},`s${r}`),a=i.id?n(i.id):i.href,p=s||!i.onClick&&!a?t.jsx("span",{style:{color:o("ink")},children:i.label},r):t.jsx("a",{href:a??"#",onClick:i.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i.onClick())}:void 0,style:{color:o("meta-fg")},children:i.label},r);return t.jsxs(f.Fragment,{children:[l,p]},r)})})}function ts({title:e,subtitle:n,aside:i,secondLine:r}){return t.jsxs("header",{style:{borderBottom:`2px solid ${o("rule-strong")}`,paddingBottom:18},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[t.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:e}),n&&t.jsx("span",{style:{fontSize:15,color:o("meta-fg"),letterSpacing:".06em"},children:n})]}),i&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg"),letterSpacing:".06em"},children:i})]}),r&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:o("quiet-fg")},children:r})]})}function yc({children:e,facts:n}){return!e&&n?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${o("rule")}`,marginBottom:40},children:n}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),n]})}function jc({items:e,horizontal:n}){const{convert:i}=q();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${o("accent")}`,paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:e.map((r,s)=>t.jsxs("div",{title:r.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[t.jsx("span",{className:"bim-d-ui",style:{color:o("label-fg"),letterSpacing:".08em",flex:"none"},children:i(r.label)}),t.jsx("span",{style:{color:o("body-fg"),textAlign:n?"left":"right",minWidth:0},children:r.value})]},s))}):null}function vc({glyph:e,tone:n,title:i,count:r,actions:s,id:l}){const{convert:a}=q();return t.jsxs("div",{id:l,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(ki,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:a(i)}),r!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg")},children:r})]}),s&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function ns({label:e,active:n,onClick:i,dashed:r}){const{convert:s}=q();return t.jsx("button",{type:"button",onClick:i,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!n?"dashed":"solid"} ${o(n?"accent":"rule")}`,background:n?o("accent"):"transparent",color:o(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(e)})}function kc({label:e,onClick:n}){const{convert:i}=q();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg"),borderBottom:`1px solid ${o("rule")}`},children:i(e)})}function Sc({label:e,onClick:n,inline:i}){const{convert:r}=q();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:i?0:12,width:i?void 0:"100%",padding:i?"4px 12px":9,background:"none",border:`1px dashed ${o("rule-dashed")}`,cursor:"pointer",fontSize:12,color:o("meta-fg"),letterSpacing:i?void 0:".08em"},children:r(e)})}function is({children:e,href:n,onClick:i,title:r}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${o("rule")}`,fontSize:13,color:o("body-fg"),lineHeight:1.5};return n||i?t.jsx("a",{href:n??"#",title:r,onClick:i?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i())}:void 0,style:s,children:e}):t.jsx("span",{title:r,style:s,children:e})}function wc({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function _c({volumes:e,unit:n="冊",max:i=60}){const[r,s]=f.useState(!1);if(!e.length)return null;const l=r?e:e.slice(0,i);return t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[l.map(a=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${o("rule")}`,color:o("meta-fg")},children:a},a)),!r&&e.length>i&&t.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${o("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:o("meta-fg")},children:["+",e.length-i]}),t.jsx("span",{style:{padding:"2px 6px",color:o("hint-fg")},children:n})]})}function $c({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${o("rule-strong")}`},children:e})}function zc({spec:e}){const{convert:n}=q();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${o("rule-strong")}`,fontSize:11,color:o("label-fg"),letterSpacing:".1em"},children:[t.jsx("span",{}),t.jsx("span",{children:n(e.mainLabel)}),t.jsx("span",{style:{display:"grid",gridTemplateColumns:e.columns.map(i=>i.width).join(" "),gap:12},children:e.columns.map(i=>t.jsx("span",{children:n(i.label)},i.label))})]})}function Cc({no:e,main:n,meta:i,spec:r}){return t.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${r.leadWidth}px 1fr ${r.metaWidth}px`,gap:12},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:o("hint-fg"),textAlign:"right"},children:e}),t.jsx("span",{style:{minWidth:0},children:n}),t.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:r.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:i})]})}function Ic(e){return String(e+1).padStart(2,"0")}function Tc(){return t.jsx("span",{style:{color:o("hint-fg")},children:"—"})}function Ec({open:e,onToggle:n,main:i,action:r,children:s}){return t.jsxs("div",{style:{borderBottom:`1px solid ${o("rule")}`},children:[t.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[t.jsx("button",{type:"button",onClick:n,"aria-expanded":e,className:"bim-d-ui",style:{width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",fontSize:12,lineHeight:1,border:`1px solid ${o(e?"accent":"rule-dashed")}`,background:e?o("accent"):"transparent",color:o(e?"page-bg":"accent")},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:i}),r]}),e&&s&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${o("rule-accent-soft")}`,marginLeft:12},children:s})]})}function os(e){const n=[];for(let i=0;i<e.length;i++){const r=e[i];let s;if(r==="⟨")s="⟩";else if(r==="<"){const p=e[i+1];if(p===void 0||/[A-Za-z/!?>\s]/.test(p))continue;s=">"}else continue;const l=e.indexOf(s,i+1);if(l<0)continue;const a=e.slice(i+1,l);a.includes(`
532
- `)||(n.push({start:i,end:l+1,inner:a}),i=l)}return n}function rs(e,n){if(e.length<=n)return e;let i=n;for(const r of os(e)){if(r.start>=i)break;if(r.end>i){i=r.start>0?r.start:r.end;break}}return e.slice(0,i)}const ss={fontSize:".78em",color:o("meta-fg"),lineHeight:1.55},Rc={display:"inline-block",fontSize:"1em",lineHeight:1.15,padding:"0 .12em",margin:"0 .05em",border:"1px solid color-mix(in srgb, currentColor 40%, transparent)",borderRadius:2,verticalAlign:"baseline",whiteSpace:"nowrap"};function ls(e,n,i){return e.map((r,s)=>{switch(r.type){case"text":return t.jsx(f.Fragment,{children:n(r.text)},s);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:i===0?ss:void 0,children:ls(r.children,n,i+1)},s);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:r.label?`闕文:${r.label}`:"闕文",children:"□"},s);case"qz":return t.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":r.guess,children:"□"},s);case"zi":return t.jsx("span",{className:"bim-zi guji-zi",title:`組字:${r.label}`,style:Rc,children:r.label},s)}})}function Ue(e,n=r=>r,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return pc(e)?ls(Kr(e),n,0):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let s=0,l=0;for(const a of os(e))a.start>s&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s,a.start))},l++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:ss,children:n(a.inner)},l++)),s=a.end;return s<e.length&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),r}function Nc({label:e,children:n}){return t.jsxs("div",{style:{marginBottom:10},children:[e&&t.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:o("label-fg"),marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:o("quiet-fg"),textAlign:"justify"},children:n})]})}function Lc({title:e,tag:n,children:i}){const{convert:r}=q();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${o("rule-strong")}`,marginBottom:2},children:[t.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:r(e)}),n&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:o("accent"),letterSpacing:".06em"},children:r(n)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function as({name:e,note:n,href:i,extra:r}){const s=t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{fontSize:14,minWidth:0},children:e}),t.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:o("hint-fg"),flex:"none"},children:i?"↗":""}),n&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:o("label-fg")},children:n})]}),l={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${o("rule")}`,color:o("body-fg"),alignItems:"baseline"};return t.jsxs(t.Fragment,{children:[i?t.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:l,children:s}):t.jsx("div",{style:l,children:s}),r]})}function Bc({item:e,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=q(),[l,a]=f.useState(!1),p=bn(e),c=i&&!!p&&p.expected>0,d=(e.url?Nt(e.url):void 0)||s(e.name),u=n?Fr(e,n):"",g=u?`${d}(${u})`:d;return t.jsx(as,{name:g,note:Sn(e)||r,href:Lt(e),extra:c?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>a(x=>!x),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:o("meta-fg"),borderBottom:`1px solid ${o("rule")}`},children:l?"收起分冊":`展開 ${p.expected} 冊`}),l&&t.jsx(Si,{item:e})]}):void 0})}function Si({item:e}){return t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(e.volumes||[]).map((n,i)=>{const r=n.status==="missing";return n.url&&!r?t.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{padding:"4px 8px",borderRadius:4,background:o("zebra-bg")},children:n.volume},i):t.jsx("span",{style:{padding:"1px 5px",color:o(r?"missing-fg":"hint-fg"),textDecoration:r?"line-through":void 0},children:n.volume},i)})})}function cs({label:e,items:n}){const{convert:i}=q();return n.length?t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg"),letterSpacing:".08em"},children:e}),n.map((r,s)=>t.jsx(is,{children:i(r)},s))]}):null}function Ac({rows:e}){const n=e.filter(i=>i.items.length>0);return n.length?t.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(i=>t.jsx(cs,{label:i.label,items:i.items},i.label))}):null}function Xn(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ds({left:e,right:n}){return t.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${o("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:o("aux-fg")},children:[t.jsx("span",{children:e}),n&&t.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function Wc({children:e,action:n}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:o("aux-fg"),borderBottom:`1px solid ${o("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),n]})}function Be({id:e,label:n,onNavigate:i,renderLink:r,style:s,dense:l}){const a=Pe();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:l})}):t.jsx("a",{href:a(e),onClick:i?p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(e))}:void 0,style:s,children:n??e})}function Mc({href:e,children:n}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[n," ",t.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const ps="(min-width: 1100px)",us="(max-width: 719px)",Fc=`${us}, (pointer: coarse)`,pt=o("reader-top"),Pc="48px",xs=`
531
+ ${mc}`;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:ts}),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 Jn({breadcrumb:e,actions:n}){return t.jsxs("div",{className:"bim-d-ui bim-d-top",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color: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 wi({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 Zn({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 ns({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 jc({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 vc({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 kc({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(wi,{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 is({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 wc({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 Sc({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 os({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 _c({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function $c({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 zc({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${i("rule-strong")}`},children:e})}function Cc({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 Ic({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 Tc(e){return String(e+1).padStart(2,"0")}function Ec(){return t.jsx("span",{style:{color:i("hint-fg")},children:"—"})}function Rc({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 rs(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(`
532
+ `)||(n.push({start:o,end:l+1,inner:d}),o=l)}return n}function ss(e,n){if(e.length<=n)return e;let o=n;for(const r of rs(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 ls={fontSize:".78em",color:i("meta-fg"),lineHeight:1.55},Nc={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 as(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?ls:void 0,children:as(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:Nc,children:r.label},s)}})}function Ue(e,n=r=>r,o){if(!e)return"";if(o!=null&&o.gujiMarkdown)return uc(e)?as(Jr(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 rs(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:ls,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 Lc({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 Bc({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 cs({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 Ac({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?Pr(e,n):"",f=u?`${a}(${u})`:a;return t.jsx(cs,{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(Si,{item:e})]}):void 0})}function Si({item:e}){return t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(e.volumes||[]).map((n,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 ds({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(os,{children:o(r)},s))]}):null}function Wc({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(ds,{label:o.label,items:o.items},o.label))}):null}function Xn(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ps({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 Mc({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 Fc({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 us="(min-width: 1100px)",xs="(max-width: 719px)",Pc=`${xs}, (pointer: coarse)`,pt=i("reader-top"),Oc="48px",fs=`
533
533
  .bim-rd {
534
534
  position: relative;
535
- background: ${o("page-bg")};
536
- color: ${o("ink")};
537
- font-family: ${o("font-ui")};
538
- --bimrd-bar-h: ${Pc};
535
+ background: ${i("page-bg")};
536
+ color: ${i("ink")};
537
+ font-family: ${i("font-ui")};
538
+ --bimrd-bar-h: ${Oc};
539
539
  }
540
540
  .bim-rd *, .bim-rd *::before, .bim-rd *::after { box-sizing: border-box; }
541
541
 
@@ -549,9 +549,9 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
549
549
  left: 8px; top: 8px; z-index: 60;
550
550
  width: auto; height: auto; margin: 0; overflow: visible; clip: auto; clip-path: none;
551
551
  padding: 8px 14px; border-radius: 6px;
552
- background: ${o("ink")}; color: ${o("page-bg")} !important;
552
+ background: ${i("ink")}; color: ${i("page-bg")} !important;
553
553
  font-size: 14px; text-decoration: none !important;
554
- outline: 2px solid ${o("accent")}; outline-offset: 2px;
554
+ outline: 2px solid ${i("accent")}; outline-offset: 2px;
555
555
  }
556
556
 
557
557
  .bim-rd-sr {
@@ -565,33 +565,50 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
565
565
  height: var(--bimrd-bar-h);
566
566
  display: flex; align-items: center; gap: 16px;
567
567
  padding: 0 20px;
568
- background: color-mix(in srgb, ${o("page-bg")} 94%, transparent);
568
+ background: color-mix(in srgb, ${i("page-bg")} 94%, transparent);
569
569
  backdrop-filter: blur(8px);
570
570
  }
571
571
  .bim-rd-ttl { min-width: 0; display: flex; align-items: baseline; gap: 10px; overflow: hidden; white-space: nowrap; }
572
- .bim-rd-ttl b { font-size: 15px; font-weight: 700; letter-spacing: 0.06em; color: ${o("ink")}; overflow: hidden; text-overflow: ellipsis; }
573
- .bim-rd-ttl span { font-size: 13px; color: ${o("meta-fg")}; overflow: hidden; text-overflow: ellipsis; }
574
- .bim-rd-tools { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; color: ${o("quiet-fg")}; flex: none; }
575
- .bim-rd-tools .bim-rd-sep { width: 1px; height: 14px; background: ${o("rule")}; }
572
+ .bim-rd-ttl b { font-size: 15px; font-weight: 700; letter-spacing: 0.06em; color: ${i("ink")}; overflow: hidden; text-overflow: ellipsis; }
573
+ .bim-rd-ttl span { font-size: 13px; color: ${i("meta-fg")}; overflow: hidden; text-overflow: ellipsis; }
574
+ .bim-rd-ttl b a { color: inherit; text-decoration: none; }
575
+ .bim-rd-ttl b a:hover { color: ${i("accent")}; text-decoration: underline; text-underline-offset: 4px; }
576
+ .bim-rd-ttl .bim-rd-dot { flex: none; }
577
+ .bim-rd-ttl .bim-rd-dot::before { content: "·"; }
578
+ .bim-rd-ttl .bim-rd-cur { color: ${i("ink")}; flex: none; }
579
+ .bim-rd-chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
580
+ .bim-rd-chk input { margin: 0; accent-color: ${i("accent")}; cursor: pointer; }
581
+ .bim-rd-rowhead {
582
+ display: flex; gap: 8px; padding: 8px 10px; border-bottom: 1px solid ${i("ink")};
583
+ font-family: ${i("font-ui")}; font-size: 11.5px; letter-spacing: 0.12em; color: ${i("meta-fg")};
584
+ }
585
+ .bim-rd-entries .bim-rd-row:hover { background: ${i("row-hover-bg")}; }
586
+ .bim-rd-wl {
587
+ display: inline-block; margin-left: 12px; padding: 1px 8px; font-size: 11.5px; letter-spacing: 0; font-weight: 400; line-height: 1.7;
588
+ background: ${i("flag-bg")}; color: ${i("accent")} !important; text-decoration: none !important; vertical-align: 2px; white-space: nowrap;
589
+ }
590
+ .bim-rd-wl:hover { background: ${i("accent")}; color: ${i("page-bg")} !important; }
591
+ .bim-rd-tools { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; color: ${i("quiet-fg")}; flex: none; }
592
+ .bim-rd-tools .bim-rd-sep { width: 1px; height: 14px; background: ${i("rule")}; }
576
593
  .bim-rd-t {
577
594
  background: none; border: 0; margin: 0; padding: 6px 2px;
578
595
  font: inherit; color: inherit; cursor: pointer; line-height: 1;
579
596
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
580
597
  }
581
- .bim-rd-t:hover { color: ${o("ink")}; }
582
- .bim-rd-t[aria-pressed="true"], .bim-rd-t[aria-current="true"] { color: ${o("accent")}; }
598
+ .bim-rd-t:hover { color: ${i("ink")}; }
599
+ .bim-rd-t[aria-pressed="true"], .bim-rd-t[aria-current="true"] { color: ${i("accent")}; }
583
600
  .bim-rd-t:disabled { opacity: 0.4; cursor: default; }
584
601
  .bim-rd-t svg { flex: none; }
585
- .bim-rd-t .bim-rd-on { color: ${o("accent")}; font-weight: 700; }
602
+ .bim-rd-t .bim-rd-on { color: ${i("accent")}; font-weight: 700; }
586
603
  .bim-rd-t .bim-rd-off { opacity: 0.55; }
587
604
  .bim-rd-ver { position: relative; display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
588
605
  .bim-rd-ver-short { display: none; }
589
606
  .bim-rd-ver select {
590
607
  max-width: 16em; min-height: 32px; margin: 0; padding: 0 2px;
591
- background: none; border: 0; font: inherit; color: ${o("ink")}; cursor: pointer;
608
+ background: none; border: 0; font: inherit; color: ${i("ink")}; cursor: pointer;
592
609
  text-overflow: ellipsis;
593
610
  }
594
- .bim-rd :focus-visible { outline: 2px solid ${o("accent")}; outline-offset: 2px; border-radius: 3px; }
611
+ .bim-rd :focus-visible { outline: 2px solid ${i("accent")}; outline-offset: 2px; border-radius: 3px; }
595
612
 
596
613
  /* ── 主体:目录 | 书影 | 正文 ── */
597
614
  .bim-rd-body {
@@ -608,34 +625,34 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
608
625
  width: 248px; height: calc(100vh - ${pt} - var(--bimrd-bar-h));
609
626
  overflow-y: auto; overscroll-behavior: contain;
610
627
  padding: 0 10px 40px;
611
- background: ${o("sidebar-bg")};
628
+ background: ${i("sidebar-bg")};
612
629
  }
613
630
  .bim-rd[data-toc="closed"] .bim-rd-toc { display: none; }
614
631
  .bim-rd-scrim { display: none; }
615
632
  /* 目录标题与搜索框吸在目录顶上:长目录滚动时关闭键、搜索框不跟着滚走 */
616
- .bim-rd-toc-top { position: sticky; top: 0; z-index: 1; padding-top: 16px; background: ${o("sidebar-bg")}; }
617
- .bim-rd-toc-head { display: flex; align-items: center; gap: 8px; margin: 0 8px 10px; min-height: 22px; font-size: 12px; letter-spacing: 0.15em; color: ${o("meta-fg")}; }
633
+ .bim-rd-toc-top { position: sticky; top: 0; z-index: 1; padding-top: 16px; background: ${i("sidebar-bg")}; }
634
+ .bim-rd-toc-head { display: flex; align-items: center; gap: 8px; margin: 0 8px 10px; min-height: 22px; font-size: 12px; letter-spacing: 0.15em; color: ${i("meta-fg")}; }
618
635
  .bim-rd-toc-head .bim-rd-t { margin-left: auto; letter-spacing: 0; }
619
636
  .bim-rd-toc-search {
620
637
  display: block; width: 100%; margin: 0 0 12px;
621
638
  padding: 7px 10px; border-radius: 6px;
622
- border: 1px solid transparent; background: ${o("bg")};
623
- color: ${o("ink")}; font: inherit; font-size: 13px;
639
+ border: 1px solid transparent; background: ${i("bg")};
640
+ color: ${i("ink")}; font: inherit; font-size: 13px;
624
641
  }
625
- .bim-rd-toc-search:focus { border-color: ${o("accent")}; outline: none; }
642
+ .bim-rd-toc-search:focus { border-color: ${i("accent")}; outline: none; }
626
643
  .bim-rd-toc ul { list-style: none; margin: 0; padding: 0; }
627
644
  .bim-rd-toc li ul { padding-left: 14px; }
628
645
  .bim-rd-ti {
629
646
  display: flex; align-items: baseline; gap: 8px; width: 100%;
630
647
  padding: 5px 10px; border: 0; border-radius: 6px; margin: 0;
631
648
  background: none; font: inherit; font-size: 13px; line-height: 1.5; text-align: left;
632
- color: ${o("quiet-fg")}; cursor: pointer;
649
+ color: ${i("quiet-fg")}; cursor: pointer;
633
650
  }
634
- .bim-rd-ti:hover { background: ${o("row-hover-bg")}; color: ${o("ink")}; }
635
- .bim-rd-ti[aria-current="true"] { background: ${o("bg")}; color: ${o("accent")}; font-weight: 700; }
651
+ .bim-rd-ti:hover { background: ${i("row-hover-bg")}; color: ${i("ink")}; }
652
+ .bim-rd-ti[aria-current="true"] { background: ${i("bg")}; color: ${i("accent")}; font-weight: 700; box-shadow: inset 2px 0 0 ${i("accent")}; }
636
653
  .bim-rd-ti:disabled { opacity: 0.45; cursor: default; background: none; }
637
- .bim-rd-ti .bim-rd-hint { margin-left: auto; font-size: 12px; font-weight: 400; color: ${o("meta-fg")}; flex: none; }
638
- .bim-rd-ti-group { font-weight: 600; color: ${o("ink")}; }
654
+ .bim-rd-ti .bim-rd-hint { margin-left: auto; font-size: 12px; font-weight: 400; color: ${i("meta-fg")}; flex: none; }
655
+ .bim-rd-ti-group { font-weight: 600; color: ${i("ink")}; }
639
656
  .bim-rd-ti-group svg { transition: transform 0.15s; flex: none; align-self: center; }
640
657
  .bim-rd-ti-group[aria-expanded="true"] svg { transform: rotate(90deg); }
641
658
 
@@ -650,39 +667,62 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
650
667
  .bim-rd[data-img="closed"] .bim-rd-img { display: none; }
651
668
  .bim-rd-img-box {
652
669
  position: relative; flex: 1; min-height: 0; border-radius: 10px;
653
- background: ${o("sidebar-bg")};
670
+ background: ${i("sidebar-bg")};
654
671
  display: flex; align-items: center; justify-content: center; overflow: hidden;
655
672
  }
656
673
  .bim-rd-img-fig { position: relative; margin: 0; max-width: 100%; max-height: 100%; }
657
674
  .bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${pt} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
658
675
  .bim-rd-img-fig svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
659
- .bim-rd-img-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 24px; text-align: center; font-size: 13px; color: ${o("meta-fg")}; }
660
- .bim-rd-img-empty b { font-size: 15px; font-weight: 500; color: ${o("quiet-fg")}; }
676
+ .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")}; }
677
+ .bim-rd-img-empty b { font-size: 15px; font-weight: 500; color: ${i("quiet-fg")}; }
661
678
  .bim-rd-img-frame {
662
679
  width: 46%; aspect-ratio: 2 / 3; border-radius: 4px; margin-bottom: 10px;
663
- background: repeating-linear-gradient(90deg, transparent 0 22px, color-mix(in srgb, ${o("ink")} 5%, transparent) 22px 24px), ${o("bg")};
664
- }
665
- .bim-rd-img-pager { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 13px; color: ${o("quiet-fg")}; }
680
+ background: repeating-linear-gradient(90deg, transparent 0 22px, color-mix(in srgb, ${i("ink")} 5%, transparent) 22px 24px), ${i("bg")};
681
+ }
682
+ .bim-rd-img-pager { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 13px; color: ${i("quiet-fg")}; }
683
+
684
+ /* 右栏(v3):正文列右侧 220px,≥860px 才显示,吸顶 */
685
+ .bim-rd-rail { display: none; }
686
+ @media (min-width: 860px) {
687
+ .bim-rd-text[data-rail] { display: grid; grid-template-columns: minmax(0, 50em) 220px; gap: 40px; align-items: start; justify-content: start; }
688
+ .bim-rd-text[data-rail] .bim-rd-col { margin: 0; max-width: none; }
689
+ .bim-rd-rail { display: block; position: sticky; top: calc(var(--bimrd-bar-h) + 16px); max-height: calc(100vh - var(--bimrd-bar-h) - 32px); overflow-y: auto; font-family: ${i("font-ui")}; }
690
+ }
691
+ .bim-rd-rail-card { padding: 12px 14px; background: ${i("bg")}; border: 1px solid ${i("rule")}; }
692
+ .bim-rd-rail-cap { font-size: 11.5px; letter-spacing: 0.16em; color: ${i("label-fg")}; }
693
+ .bim-rd-rail-n { display: flex; align-items: baseline; gap: 8px; margin-top: 4px; }
694
+ .bim-rd-rail-n b { font-size: 22px; font-weight: 600; color: ${i("ink")}; }
695
+ .bim-rd-rail-n span { font-size: 12px; color: ${i("meta-fg")}; }
696
+ .bim-rd-rail-n .bim-rd-rail-linked { margin-left: auto; color: ${i("accent")}; white-space: nowrap; }
697
+ .bim-rd-rail-bar { display: flex; height: 5px; margin-top: 8px; background: ${i("rule")}; }
698
+ .bim-rd-rail-bar span { background: ${i("accent")}; }
699
+ .bim-rd-rail-list { list-style: none; margin: 0; padding: 0; }
700
+ .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; }
701
+ .bim-rd-rail-list a > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
702
+ .bim-rd-rail-list a:hover { border-left-color: ${i("accent")}; color: ${i("ink")}; }
703
+ .bim-rd-rail-dot { flex: none; align-self: center; width: 5px; height: 5px; background: ${i("rule")}; }
704
+ .bim-rd-rail-dot.on { background: ${i("accent")}; }
666
705
 
667
706
  /* 正文 */
668
707
  .bim-rd-text { grid-column: 3; min-width: 0; padding: 32px 48px 96px 40px; outline: none; }
669
708
  /* 正文列靠左紧贴目录栏(原来居中,两边各留 ~150px 空隙),并加宽 38em → 50em */
670
709
  .bim-rd-col { max-width: 50em; margin: 0 auto 0 0; font-size: var(--bimrd-fs, 18px); }
671
- .bim-rd-h1 { font-family: ${o("font-ui")}; font-size: 28px; font-weight: 700; letter-spacing: 0.12em; margin: 0; color: ${o("ink")}; line-height: 1.4; }
672
- .bim-rd-meta { margin: 6px 0 0; font-size: 13px; line-height: 1.8; color: ${o("meta-fg")}; font-family: ${o("font-ui")}; }
710
+ .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; }
711
+ .bim-rd-meta { margin: 6px 0 0; font-size: 13px; line-height: 1.8; color: ${i("meta-fg")}; font-family: ${i("font-ui")}; }
673
712
  .bim-rd-meta .bim-rd-dot::before { content: "·"; margin: 0 0.5em; }
713
+ .bim-rd-grade { display: inline-block; margin-left: 6px; padding: 0 6px; font-size: 11.5px; line-height: 1.7; background: ${i("band-bg")}; color: ${i("quiet-fg")}; }
674
714
  .bim-rd-meta select { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
675
- .bim-rd a.bim-rd-link { color: ${o("quiet-fg")}; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
676
- .bim-rd a.bim-rd-link:hover { color: ${o("accent")}; }
677
- .bim-rd-views { display: flex; gap: 14px; margin-top: 10px; font-size: 13px; color: ${o("quiet-fg")}; font-family: ${o("font-ui")}; }
678
- .bim-rd-state { padding: 32px 0; font-size: 14px; color: ${o("meta-fg")}; font-family: ${o("font-ui")}; }
715
+ .bim-rd a.bim-rd-link { color: ${i("quiet-fg")}; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
716
+ .bim-rd a.bim-rd-link:hover { color: ${i("accent")}; }
717
+ .bim-rd-views { display: flex; gap: 14px; margin-top: 10px; font-size: 13px; color: ${i("quiet-fg")}; font-family: ${i("font-ui")}; }
718
+ .bim-rd-state { padding: 32px 0; font-size: 14px; color: ${i("meta-fg")}; font-family: ${i("font-ui")}; }
679
719
 
680
720
  /* 宋体正文:18px / 2.05,避头尾 */
681
721
  .bim-rd-prose {
682
722
  margin-top: 28px;
683
- font-family: ${o("font-reading")};
723
+ font-family: ${i("font-reading")};
684
724
  line-height: 2.05;
685
- color: ${o("ink")};
725
+ color: ${i("ink")};
686
726
  text-align: justify;
687
727
  line-break: strict;
688
728
  hanging-punctuation: allow-end;
@@ -690,7 +730,7 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
690
730
  }
691
731
  .bim-rd-prose p { margin: 0.5em 0; text-indent: 2em; }
692
732
  .bim-rd-prose .bim-rd-noindent { text-indent: 0; }
693
- .bim-rd-prose h2, .bim-rd-prose h3, .bim-rd-prose h4 { font-family: ${o("font-reading")}; color: ${o("ink")}; line-height: 1.6; letter-spacing: 0.04em; }
733
+ .bim-rd-prose h2, .bim-rd-prose h3, .bim-rd-prose h4 { font-family: ${i("font-reading")}; color: ${i("ink")}; line-height: 1.6; letter-spacing: 0.04em; }
694
734
  .bim-rd-prose h2 { font-size: 1.2em; font-weight: 700; margin: 1.6em 0 0.6em; }
695
735
  .bim-rd-prose h3 { font-size: 1.06em; font-weight: 700; margin: 1.4em 0 0.3em; }
696
736
  .bim-rd-prose h4 { font-size: 1em; font-weight: 700; margin: 1.2em 0 0.2em; }
@@ -704,16 +744,16 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
704
744
  .bim-rd-entry { margin-top: 1.6em; }
705
745
  .bim-rd-entry .bim-rd-entry-h { margin: 0 !important; font-size: 1.06em; }
706
746
  .bim-rd-entry .bim-rd-entry-h a { color: inherit !important; text-decoration: none; }
707
- .bim-rd-entry .bim-rd-entry-h a:hover { color: ${o("accent")} !important; text-decoration: underline; text-underline-offset: 4px; }
708
- .bim-rd-entry .bim-rd-sub { font-family: ${o("font-ui")}; font-size: 13px; color: ${o("meta-fg")}; text-indent: 0; margin: 0.2em 0 0; }
709
- .bim-rd-entry .bim-rd-lbl { font-family: ${o("font-ui")}; font-size: 0.72em; letter-spacing: 0.1em; color: ${o("meta-fg")}; margin-right: 0.6em; }
747
+ .bim-rd-entry .bim-rd-entry-h a:hover { color: ${i("accent")} !important; text-decoration: underline; text-underline-offset: 4px; }
748
+ .bim-rd-entry .bim-rd-sub { font-family: ${i("font-ui")}; font-size: 13px; color: ${i("meta-fg")}; text-indent: 0; margin: 0.2em 0 0; }
749
+ .bim-rd-entry .bim-rd-lbl { font-family: ${i("font-ui")}; font-size: 0.72em; letter-spacing: 0.1em; color: ${i("meta-fg")}; margin-right: 0.6em; }
710
750
  .bim-rd-prose strong { font-weight: 700; }
711
751
 
712
752
  /* 专名线:书名加波浪线,书名号隐去(仍可复制) */
713
753
  .bim-rd-pn {
714
754
  text-decoration-line: underline; text-decoration-style: wavy;
715
755
  text-decoration-thickness: 1px; text-underline-offset: 0.32em;
716
- text-decoration-color: ${o("quiet-fg")};
756
+ text-decoration-color: ${i("quiet-fg")};
717
757
  text-decoration-skip-ink: none;
718
758
  }
719
759
 
@@ -723,21 +763,27 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
723
763
  overflow-x: auto; text-align: start;
724
764
  }
725
765
 
726
- .bim-rd-src { margin: 48px 0 0; font-size: 12px; line-height: 1.8; color: ${o("meta-fg")}; font-family: ${o("font-ui")}; }
766
+ .bim-rd-src { margin: 48px 0 0; font-size: 12px; line-height: 1.8; color: ${i("meta-fg")}; font-family: ${i("font-ui")}; }
727
767
  .bim-rd-src .bim-rd-dot::before { content: "·"; margin: 0 0.5em; }
728
- .bim-rd-pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 56px; font-size: 14px; font-family: ${o("font-ui")}; }
729
- .bim-rd-pager .bim-rd-t { color: ${o("quiet-fg")}; max-width: 100%; min-width: 0; }
768
+ .bim-rd-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 48px; font-size: 14px; font-family: ${i("font-ui")}; }
769
+ .bim-rd-pg {
770
+ display: block; min-width: 0; margin: 0; padding: 14px 16px; text-align: left; font: inherit;
771
+ border: 1px solid ${i("rule")}; background: ${i("bg")}; color: ${i("ink")}; cursor: pointer;
772
+ }
773
+ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
774
+ .bim-rd-pg-next { text-align: right; }
775
+ .bim-rd-pg-end { cursor: default; font-size: 13px; color: ${i("label-fg")}; background: none; border-style: dashed; }
776
+ .bim-rd-pgcap { display: block; font-size: 11.5px; color: ${i("label-fg")}; }
777
+ .bim-rd-pg .bim-rd-pglabel { display: block; margin-top: 3px; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
730
778
  /* 长回目不能撑宽页面:两侧各占不超过一半,标题省略号截断(390 宽 scrollWidth 曾到 648) */
731
- .bim-rd-pager > span { display: flex; min-width: 0; max-width: calc(50% - 8px); }
732
- .bim-rd-pager > span:last-child { margin-left: auto; justify-content: flex-end; }
733
779
  .bim-rd-pglabel { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
734
- .bim-rd-refs { margin-top: 48px; font-size: 12px; line-height: 1.8; color: ${o("meta-fg")}; font-family: ${o("font-ui")}; }
735
- .bim-rd-refs h2 { font-size: 12px; font-weight: 600; letter-spacing: 0.2em; margin: 0 0 6px; color: ${o("meta-fg")}; }
780
+ .bim-rd-refs { margin-top: 48px; font-size: 12px; line-height: 1.8; color: ${i("meta-fg")}; font-family: ${i("font-ui")}; }
781
+ .bim-rd-refs h2 { font-size: 12px; font-weight: 600; letter-spacing: 0.2em; margin: 0 0 6px; color: ${i("meta-fg")}; }
736
782
  .bim-rd-refs ol { margin: 0; padding-left: 1.6em; }
737
783
 
738
784
  /* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
739
785
  A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
740
- @media ${Fc} {
786
+ @media ${Pc} {
741
787
  .bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
742
788
  .bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
743
789
  content: ""; position: absolute; left: 50%; top: 50%;
@@ -745,25 +791,25 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
745
791
  }
746
792
  .bim-rd-tools .bim-rd-fs + .bim-rd-fs { margin-left: 12px; }
747
793
  .bim-rd-ver select { min-height: 44px; }
748
- .bim-rd-pager .bim-rd-t { min-height: 44px; }
794
+ .bim-rd-pager .bim-rd-pg { min-height: 44px; }
749
795
  }
750
796
 
751
797
  /* ── 中屏以下:目录改抽屉 ── */
752
- @media not all and ${ps} {
798
+ @media not all and ${us} {
753
799
  .bim-rd-toc {
754
800
  position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto;
755
801
  width: min(86vw, 320px);
756
- box-shadow: ${o("shadow-dialog")};
802
+ box-shadow: ${i("shadow-dialog")};
757
803
  }
758
804
  .bim-rd[data-toc="auto"] .bim-rd-toc { display: none; }
759
805
  .bim-rd[data-toc="open"] .bim-rd-scrim {
760
- display: block; position: fixed; inset: 0; z-index: 45; background: ${o("backdrop")};
806
+ display: block; position: fixed; inset: 0; z-index: 45; background: ${i("backdrop")};
761
807
  }
762
808
  .bim-rd-text { padding: 28px 32px 80px; }
763
809
  }
764
810
 
765
811
  /* ── 窄屏:书影收起,只留正文 ── */
766
- @media ${us} {
812
+ @media ${xs} {
767
813
  .bim-rd-bar { padding: 0 12px; gap: 10px; }
768
814
  .bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
769
815
  .bim-rd-ttl { flex: 1 1 auto; }
@@ -771,7 +817,7 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
771
817
  .bim-rd-ver { min-width: 44px; min-height: 44px; justify-content: center; }
772
818
  .bim-rd-ver-short { display: inline; white-space: nowrap; }
773
819
  .bim-rd-ver select { position: absolute; inset: 0; width: 100%; max-width: none; opacity: 0; }
774
- .bim-rd-ver:focus-within { outline: 2px solid ${o("accent")}; outline-offset: 2px; border-radius: 3px; }
820
+ .bim-rd-ver:focus-within { outline: 2px solid ${i("accent")}; outline-offset: 2px; border-radius: 3px; }
775
821
  .bim-rd-tlabel { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
776
822
  .bim-rd-img { display: none !important; }
777
823
  .bim-rd-body { grid-template-columns: minmax(0, 1fr); }
@@ -779,23 +825,23 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
779
825
  .bim-rd-h1 { font-size: 20px; letter-spacing: 0.06em; }
780
826
  .bim-rd-prose { margin-top: 20px; }
781
827
  }
782
- `;function wi(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(r=>wi(r,n))):!1}const Oc=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Dc({item:e,activeKey:n,onSelect:i,tabKey:r}){const s=wi(e,n),[l,a]=f.useState(s||!!e.defaultExpanded);return f.useEffect(()=>{s&&a(!0)},[s]),f.useEffect(()=>{e.defaultExpanded&&a(!0)},[e.defaultExpanded]),t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>a(p=>!p),children:[t.jsx(Oc,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(fs,{items:e.children,activeKey:n,onSelect:i,tabKey:r})]})}function fs({items:e,activeKey:n,onSelect:i,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Dc,{item:s,activeKey:n,onSelect:i,tabKey:r},s.key):t.jsx("li",{children:t.jsxs("button",{type:"button",className:"bim-rd-ti","aria-current":s.key===n?"true":void 0,disabled:s.disabled,"data-rd-toc-key":s.key,tabIndex:r===s.key?0:-1,onClick:()=>i(s.key),children:[t.jsx("span",{children:s.label}),s.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:s.hint})]})},s.key))})}function Co(e,n){var i;for(const r of e)if(r.key===n||wi(r,n))return r.key;return((i=e[0])==null?void 0:i.key)??null}function gs({items:e,activeKey:n,onSelect:i,label:r="目录"}){const s=f.useRef(null),[l,a]=f.useState(null);f.useEffect(()=>{a(null)},[n]);const p=f.useMemo(()=>l||(n??Co(e,n)),[l,n,e]);f.useEffect(()=>{const d=s.current;if(!d)return;const u=Array.from(d.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const g=u.find(x=>x.dataset.rdTocKey===p)??u.find(x=>x.dataset.rdTocKey===Co(e,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===g?0:-1}),f.useEffect(()=>{const d=s.current,u=d==null?void 0:d.closest(".bim-rd-toc");if(!d||!u||!n)return;const g=Array.from(d.querySelectorAll("[data-rd-toc-key]")).find(m=>m.dataset.rdTocKey===n);if(!g)return;const x=g.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(x<u.scrollTop+80||x>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,x-u.clientHeight/3))},[n]);const c=f.useCallback(d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const g=s.current;if(!g)return;const x=Array.from(g.querySelectorAll("[data-rd-toc-key]")).filter(h=>!h.disabled),m=x.indexOf(document.activeElement);let b=m;if(d.key==="ArrowDown"?b=Math.min(x.length-1,m+1):d.key==="ArrowUp"?b=Math.max(0,m-1):d.key==="Home"?b=0:d.key==="End"&&(b=x.length-1),b<0||b===m)return;d.preventDefault();const S=x[b];for(const h of x)h.tabIndex=-1;S.tabIndex=0,S.focus(),a(S.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:c,children:t.jsx(fs,{items:e,activeKey:n,onSelect:i,tabKey:p})})}function Hc({page:e}){var n;return!((n=e.boxes)!=null&&n.length)||!e.width||!e.height||e.boxFormat&&e.boxFormat!=="bim-charbox-v0"?null:t.jsx("svg",{viewBox:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:e.boxes.map((i,r)=>t.jsx("rect",{x:i.x,y:i.y,width:i.w,height:i.h,fill:"none",stroke:o("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},r))})}function ms({pages:e,loading:n,page:i,onPageChange:r,renderOverlay:s}){const[l,a]=f.useState(0),p=i??l,c=x=>{r?r(x):a(x)};if(f.useEffect(()=>{i===void 0&&a(0)},[e,i]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:"加载书影…"})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:"暂无书影"}),t.jsx("span",{children:"这一卷还没有配上影像;接入后在此与正文逐页对看"})]})});const d=Math.max(0,Math.min(e.length-1,p)),u=e[d],g=u.label??`${d+1}`;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${g} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(Hc,{page:u}),s==null?void 0:s(u,d)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:d===0,onClick:()=>c(d-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${d+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:d===e.length-1,onClick:()=>c(d+1),children:"›"})]})]})}const _i={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal"},$t=[15,16,17,18,20,22,24],Qn=18,hs="bim-reader-prefs",Gc="bim-reading-mode";function Uc(){const e={..._i};try{const n=localStorage.getItem(hs),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&$t.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(Gc))==="paragraph"&&(e.readingMode="paragraph"),i.properNames===!0&&(e.properNames=!0),i.writingMode==="vertical"&&(e.writingMode="vertical")}catch{}return e}function Vc(e){try{localStorage.setItem(hs,JSON.stringify(e))}catch{}}function Io(e,n){const i=e??Qn,r=$t;let s=r.indexOf(i);return s<0&&(s=r.indexOf(Qn)),r[Math.max(0,Math.min(r.length-1,s+n))]}function $i(){const[e,n]=f.useState(_i);f.useEffect(()=>{n(Uc())},[]);const i=f.useCallback(r=>{n(s=>{const l={...s,...r};return Vc(l),l})},[]);return[e,i]}function bs(e){return e.map(n=>({key:n.key,label:n.version_label||n.key,sourceName:n.source_name,license:n.license,sourceUrl:n.source_url,primary:n.primary}))}function ei(e){const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function ys(e,n){if(!(!e||e.length===0))return(n!=null?e.find(i=>i.key===n):void 0)??e.find(i=>i.primary)??e[0]}function js(e){const n=[],i=r=>{for(const s of r)s.children&&s.children.length>0?i(s.children):n.push(s)};return i(e),n}const Yc=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),qc=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),t.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function Kc(e,n){if(!n)return;const i=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(a=>a.tabIndex>=0);if(i.length===0)return;const r=i[0],s=i[i.length-1],l=document.activeElement;e.shiftKey&&(l===r||!n.contains(l))?(e.preventDefault(),s.focus()):!e.shiftKey&&(l===s||!n.contains(l))&&(e.preventDefault(),r.focus())}function Jc(e,n){const[i,r]=f.useState(n);return f.useEffect(()=>{var a;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(s.matches);return(a=s.addEventListener)==null||a.call(s,"change",l),()=>{var p;return(p=s.removeEventListener)==null?void 0:p.call(s,"change",l)}},[e]),i}function Zc(){const e=f.useContext(Rt);if(!e)return null;const n=e.locale==="zh-Hant";return t.jsxs("button",{type:"button",className:"bim-rd-t",title:n?"切换为简体":"切換為繁體","aria-label":n?"切换为简体":"切換為繁體",onClick:()=>e.setLocale(n?"zh-Hans":"zh-Hant"),children:[t.jsx("span",{className:n?"bim-rd-on":"bim-rd-off",children:"繁"}),t.jsx("span",{className:"bim-rd-off",children:"|"}),t.jsx("span",{className:n?"bim-rd-off":"bim-rd-on",children:"简"})]})}function zi({title:e,subtitle:n,toc:i,activeKey:r,onSelect:s,tocHeader:l,tocCaption:a,images:p,imagesLoading:c,renderImageOverlay:d,imagePanel:u="auto",prefs:g,onPrefsChange:x,paragraphToggle:m,properNameToggle:b=!0,allowVertical:S,pager:h=!0,versions:y,currentVersionKey:j,onVersionChange:k,versionSource:$=!0,children:v,className:_,style:w}){const z=f.useId().replace(/:/g,""),N=`bim-rd-toc-${z}`,T=`bim-rd-text-${z}`,C=f.useRef(null),P=f.useRef(null),B=f.useRef(null),A=f.useRef(null),W=Jc(ps,!0),[V,K]=f.useState("auto"),E=V==="auto"?W:V==="open",le=!W,G=!!p&&p.length>0,[ae,pe]=f.useState(u);f.useEffect(()=>{pe(u)},[u]);const ee=ae==="auto"?G||!!c:ae==="open",X=f.useCallback(Z=>{var F;K("auto"),Z&&((F=A.current)==null||F.focus())},[]),ie=()=>K(E?"closed":"open");f.useEffect(()=>{if(!le||V!=="open")return;const Z=B.current,F=Z==null?void 0:Z.querySelector('input, [data-rd-toc-key][tabindex="0"]');F==null||F.focus()},[le,V]);const me=f.useCallback(Z=>{s(Z),le&&X(!1);const F=P.current,I=C.current;if(F&&I&&typeof window<"u"){const D=F.getBoundingClientRect().top-I.getBoundingClientRect().bottom;D<0&&window.scrollBy({top:D})}},[s,le,X]),te=f.useMemo(()=>js(i),[i]),[se,fe]=f.useState(null),be=ys(y,j!==void 0?j:se),ze=(be==null?void 0:be.key)??null,ve=f.useMemo(()=>te.map(Z=>Z.key).join(`
783
- `),[te]),ke=f.useRef(null),Ne=Z=>{Z!==ze&&(ke.current={key:Z,sig:ve,done:!1},j===void 0&&fe(Z),k==null||k(Z))};f.useEffect(()=>{const Z=ke.current;if(!Z||Z.key!==ze)return;const F=te.find(D=>!D.disabled);if(!F)return;const I=ve!==Z.sig;!I&&Z.done||(I?ke.current=null:Z.done=!0,F.key!==r&&me(F.key))},[ze,ve,te,r,me]);const Ee=te.findIndex(Z=>Z.key===r),O=Ee>0?te.slice(0,Ee).reverse().find(Z=>!Z.disabled):void 0,ce=Ee>=0?te.slice(Ee+1).find(Z=>!Z.disabled):void 0,oe=g.fontSize??Qn,he={...w,...g.fontSize?{"--bimrd-fs":`${g.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",g.writingMode==="vertical"&&S?"bim-rd-vertical":"",_].filter(Boolean).join(" "),"data-toc":V,"data-img":ee?"open":"closed",style:he,children:[t.jsx("style",{children:xs}),t.jsx("a",{className:"bim-rd-skip",href:`#${T}`,onClick:Z=>{var F,I,D;Z.preventDefault(),(F=P.current)==null||F.focus(),(D=(I=P.current)==null?void 0:I.scrollIntoView)==null||D.call(I,{block:"start"})},children:"跳到正文"}),t.jsxs("div",{className:"bim-rd-bar",ref:C,children:[(e||n)&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),n&&t.jsx("span",{children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":"阅读设置",children:[y&&y.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:be?ei(be):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:"版本"}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:"版本▾"}),t.jsx("select",{"aria-label":"版本",value:ze??"",onChange:Z=>Ne(Z.target.value),children:y.map(Z=>t.jsx("option",{value:Z.key,children:ei(Z)},Z.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),t.jsxs("button",{ref:A,type:"button",className:"bim-rd-t","aria-expanded":E,"aria-controls":N,onClick:ie,children:[t.jsx(Yc,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":ee,onClick:()=>pe(ee?"closed":"open"),children:[t.jsx(qc,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Zc,{}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"缩小字号",disabled:oe<=$t[0],onClick:()=>x({fontSize:Io(g.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"放大字号",disabled:oe>=$t[$t.length-1],onClick:()=>x({fontSize:Io(g.fontSize,1)}),children:"A+"}),(m||b||S)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),m&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":g.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>x({readingMode:g.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),b&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":g.properNames,title:"书名加波浪线",onClick:()=>x({properNames:!g.properNames}),children:"专名线"}),S&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":g.writingMode==="vertical",onClick:()=>x({writingMode:g.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:N,ref:B,role:le&&E?"dialog":void 0,"aria-modal":le&&E?!0:void 0,"aria-label":le&&E?"目录":void 0,onKeyDown:Z=>{if(!(!le||!E)){if(Z.key==="Escape"){Z.stopPropagation(),X(!0);return}Z.key==="Tab"&&Kc(Z,B.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:a??"目录"}),le&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>X(!0),children:"✕"})]}),l]}),t.jsx(gs,{items:i,activeKey:r,onSelect:me})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>X(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:ee&&t.jsx(ms,{pages:p??null,loading:c,renderOverlay:d})}),t.jsx("div",{className:"bim-rd-text",id:T,ref:P,tabIndex:-1,children:t.jsxs("div",{className:"bim-rd-col",children:[v,$&&be&&(be.sourceName||be.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":be.key,children:[be.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",be.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:be.sourceUrl,target:"_blank",rel:"noreferrer",children:be.sourceName}):be.sourceName]}),be.sourceName&&be.license&&t.jsx("span",{className:"bim-rd-dot"}),be.license&&t.jsxs(t.Fragment,{children:["授权 ",be.license]})]}),h&&(O||ce)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[t.jsx("span",{children:O&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>me(O.key),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-pglabel",children:O.label})]})}),t.jsx("span",{children:ce&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>me(ce.key),children:[t.jsx("span",{className:"bim-rd-pglabel",children:ce.label}),t.jsx("span",{"aria-hidden":"true",children:"›"})]})})]})]})})]})]})}const vs="guji-table-v1";function ks(e){return!!e&&e.table_notation===vs}const Xc=/^:::table(?:\{[^}]*\})?[ \t]*$/,Qc=/^:::[ \t]*$/;function Ss(e){const n=[];let i="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const a=Yr(e,r+3);if(a>r+4){i+=e.slice(r,a+1),r=a;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const a=e[r+1];a!==void 0&&!/[A-Za-z/!?>\s]/.test(a)&&(l=">")}if(l){const a=e.indexOf(l,r+1);if(a>0){i+=e.slice(r,a+1),r=a;continue}}s==="|"?(n.push(i),i=""):i+=s}return n.push(i),n.map(r=>r.trim())}const ed=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function td(e){if(e==="^")return{cont:!0};const n=ed.exec(e),i=n[1].trim(),r=n[2]?Math.max(1,parseInt(n[2],10)):1,s=n[3]?Math.max(1,parseInt(n[3],10)):1,l=i==="_";return{cont:!1,cell:{text:l?"":i,empty:l,colspan:r,rowspan:s}}}function ws(e,n=1){const i=[],r=[],s=[];let l=[];e.forEach((p,c)=>{const d=c+n+1;let u=p.trim();if(!u)return;let g=!1;u.startsWith("!")&&(g=!0,u=u.slice(1));const x=Ss(u).map(td),m=l.map(y=>y>0),b=l.map(y=>y>0?y-1:0),S=[];let h=0;for(const y of x){if(y.cont){m[h]||i.push(`第 ${d} 行第 ${h+1} 列:续格 ^ 上方没有跨行格`),h+=1;continue}const{cell:j}=y;for(let k=h;k<h+j.colspan;k++)if(m[k]){i.push(`第 ${d} 行第 ${k+1} 列:此处被上方跨行格占住,应写 ^`);break}if(j.rowspan>1)for(let k=h;k<h+j.colspan;k++)b[k]=j.rowspan-1;S.push(j),h+=j.colspan}for(let y=h;y<m.length;y++)m[y]&&i.push(`第 ${d} 行第 ${y+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let y=0;y<b.length;y++)b[y]===void 0&&(b[y]=0);l=b,r.push({header:g,cells:S}),s.push({width:h,line:d})});const a=s.reduce((p,c)=>Math.max(p,c.width),0);for(const p of s)p.width!==a&&i.push(`第 ${p.line} 行:占 ${p.width} 列,与总列数 ${a} 不符`);return l.some(p=>p>0)&&i.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&i.push("空表"),{rows:r,columns:a,warnings:i}}function Ci(e){const n=e.split(`
784
- `),i=[];let r=[];const s=()=>{if(r.length===0)return;const a=r.join(`
785
- `);r=[],i.push({type:"text",text:a})};let l=0;for(;l<n.length;){if(Xc.test(n[l].trim())){let a=l+1;for(;a<n.length&&!Qc.test(n[a].trim());)a++;if(a<n.length){s();const p=n.slice(l+1,a);i.push({type:"table",table:ws(p,l+1),source:n.slice(l,a+1).join(`
786
- `)}),l=a+1;continue}}r.push(n[l]),l++}return s(),i.map((a,p)=>{var d,u;if(a.type!=="text")return a;let c=a.text;return((d=i[p-1])==null?void 0:d.type)==="table"&&(c=c.replace(/^\n+/,"")),((u=i[p+1])==null?void 0:u.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(a=>a.type!=="text"||a.text!=="")}const nd={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},id={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},od=`1px solid ${o("table-border")}`,_s={border:od,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},rd={..._s,background:o("table-head-bg"),fontWeight:600};function Ii({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:nd,children:t.jsx("table",{className:"bim-guji-table",style:id,children:t.jsx("tbody",{children:e.rows.map((i,r)=>t.jsx("tr",{children:i.cells.map((s,l)=>{const a=i.header?"th":"td";return t.jsx(a,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:i.header?rd:_s,children:s.empty?null:Ue(s.text,void 0,n)},l)})},r))})})})}function sd(e,n){return e.indexOf("**")<0?Ue(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:Ue(r.trim().slice(2,-2),void 0,n)},s):t.jsx(f.Fragment,{children:Ue(r,void 0,n)},s))}function ld(e,n,i=!1){const r=i?{gujiMarkdown:!0}:void 0;return n?Ci(e).map((s,l)=>s.type==="table"?t.jsx(Ii,{table:s.table,opts:r},l):t.jsx(f.Fragment,{children:sd(s.text,r)},l)):Ue(e,void 0,r)}const ad=/^(#{1,6})\s+(.*)$/,cd=/^\*\*([^*\n]+)\*\*\s*$/;function Ti(e){const n=e.match(ad);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(cd);return i?{level:3,text:i[1].trim()}:null}const Ei=/^<!--.*-->$/;function $s(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function zs(e){return e.split(`
787
- `).map(n=>n.trim()).filter(n=>n&&!Ei.test(n))}const dd=60;function Cs(e){let n=0,i=0;for(const r of e.split(`
788
- `)){const s=r.trim();if(!s||Ei.test(s)||Ti(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>dd&&(i+=l)}return n>0&&i*2>=n}function pd(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function $n(e){if(e=pd(e),Cs(e))return"unknown";const n=$s(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>zs(s).length).filter(s=>s>0);if(i.length===0)return"unknown";const r=i.reduce((s,l)=>s+l,0)/i.length;return r<=4?"record":r>=8?"catalog":"unknown"}function ud(e){const n=e.split(`
789
- `),i=[];let r=null,s=[];const l=()=>{i.push({heading:r,body:s.join(`
790
- `)}),s=[]};for(const a of n){const p=Ti(a);if(p){l(),r={kind:"heading",level:p.level,text:p.text};continue}s.push(a)}return l(),i}function To(e){const n=[];for(const i of e.split(`
791
- `)){const r=Ti(i);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=i.trim();!s||Ei.test(s)||n.push({kind:"body",text:i})}return n}function Is(e){if(!e)return[];const n=$n(e);if(n==="unknown")return To(e);const i=[];for(const{heading:r,body:s}of ud(e)){r&&i.push(r);const l=$s(s);if(l.length!==0){if(Cs(s)){i.push(...To(s));continue}if(n==="record"){const a=l.join(" ");a&&i.push({kind:"body",text:a})}else for(const a of l){const p=zs(a);p.length&&i.push({kind:"body",text:p.join(" ")})}}}return i}const Ts=e=>e;function Es(e,n=Ts){if(e.indexOf("《")<0)return n(e);const i=[],r=/《([^《》\n]+)》/g;let s=0,l=0,a;for(;a=r.exec(e);)a.index>s&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s,a.index))},l++)),i.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(a[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=a.index+a[0].length;return s===0?n(e):(s<e.length&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),i)}function Ri(e,n={}){const i=n.renderText??Ts,r=n.properNames?l=>Es(l,i):i,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Ue(e,r,s)}function Eo(e,n,i){return e.indexOf("**")<0?n(e):e.split(/(\*\*[^*]+\*\*)/g).map((s,l)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?t.jsx("strong",{children:n(s.slice(2,-2))},`${i}-${l}`):t.jsx(f.Fragment,{children:n(s)},`${i}-${l}`))}const Bn=/^(#{1,6})\s+(.*)$/,xd=/^\s*<!--.*-->\s*$/;function Rs(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
792
- `)?"":n)}function fd(e){return e<=1?2:e===2?3:4}function gd(){let e=1;return n=>{const i=fd(n),r=Math.min(i,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${i}`}}}function zn(e){return e?$n(Rs(e))!=="unknown":!1}function Ro({text:e,mode:n,inline:i,dropTitle:r}){const s=Rs(e),l=(d,u,g)=>!!r&&g<=1&&d<=2&&u.trim()===r.trim(),a=gd();if(n==="paragraph"&&$n(s)!=="unknown"){const d=Is(s);return t.jsx(t.Fragment,{children:d.map((u,g)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,g))return null;const{Tag:x,className:m}=a(u.level??1);return t.jsx(x,{className:m,children:i(u.text)},g)}return t.jsx("p",{children:Eo(u.text,i,g)},g)})})}const p=s.split(`
793
- `);let c=0;return t.jsx(t.Fragment,{children:p.map((d,u)=>{const g=d.match(Bn);if(g){const m=c++;if(l(g[1].length,g[2],m))return null;const{Tag:b,className:S}=a(g[1].length);return t.jsx(b,{className:S,children:i(g[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Bn.test(p[u-1])&&!Bn.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(xd.test(d))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:m,className:b}=a(3);return t.jsx(m,{className:b,children:i(d.trim().slice(2,-2))},u)}return t.jsx("p",{children:Eo(d,i,u)},u)})})}function md(e){const{convert:n}=q();return f.useMemo(()=>e?n(e):"",[e,n])}function Ni({text:e,mode:n,tables:i=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:a}){const p=md(e),{convert:c}=q(),d=x=>Ri(x,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,g=a?c(a):void 0;return!i||p.indexOf(":::")<0?t.jsx(Ro,{text:p,mode:n,inline:d,dropTitle:g}):t.jsx(t.Fragment,{children:Ci(p).map((x,m)=>x.type==="table"?t.jsx(Ii,{table:x.table,opts:u},m):t.jsx(Ro,{text:x.text,mode:n,inline:d,dropTitle:m===0?g:void 0},m))})}function Ns(e,n){const[i,r]=f.useState(null),[s,l]=f.useState(!1),a=f.useRef(0);return f.useEffect(()=>{const p=++a.current;if(!e||!n){r(null),l(!1);return}let c;try{c=e(n)}catch{r(null),l(!1);return}if(!c||typeof c.then!="function"){r(c??null),l(!1);return}l(!0),c.then(d=>{p===a.current&&r(d??null)}).catch(()=>{p===a.current&&r(null)}).finally(()=>{p===a.current&&l(!1)})},[e,n]),{images:i,loading:s}}const No={A:"fine",B:"rough",C:"rough",D:"ocr"};function hd(e){return typeof e!="string"?null:e in Hn?e:e in No?No[e]:null}const bd={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},yd={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function it(e){return typeof e!="string"?"":bd[e]??yd[e]??e}const jd=["〇","一","二","三","四","五","六","七","八","九"],Lo=["","十","百","千"],vd=["","萬","億"];function Li(e){if(e===0)return"〇";if(e<0)return`負${Li(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(kd(s,r>0)+vd[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function kd(e,n){const i=[];let r=e;for(;r>0;)i.unshift(r%10),r=Math.floor(r/10);let s="";for(let l=0;l<i.length;l++){const a=i[l],p=i.length-1-l;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&p===1&&l===0&&!n?s+=Lo[p]:s+=jd[a]+Lo[p]}return s.replace(/〇$/,"")}let Vt=null,cn=null;const mn=new Set;function Sd(){return Vt?Promise.resolve():cn||(cn=import("opencc-js/t2cn").then(e=>{Vt=e.Converter({from:"tw",to:"cn"}),mn.forEach(n=>n())}).catch(()=>{Vt=e=>e,mn.forEach(e=>e())}),cn)}const wd=e=>e;function vt(){const[,e]=f.useState(0);return f.useEffect(()=>{if(Vt)return;const n=()=>e(i=>i+1);return mn.add(n),Sd(),()=>{mn.delete(n)}},[]),Vt??wd}function Et(e,n){return n(e).toLowerCase()}const _d=o("highlight-bg");function en(e,n,i){if(!n)return e;const r=Et(n,i);if(!r)return e;const s=Et(e,i);if(s.length!==e.length)return e;const l=[];let a=0,p=0;for(;a<e.length;){const c=s.indexOf(r,a);if(c===-1){l.push(e.slice(a));break}c>a&&l.push(e.slice(a,c)),l.push(t.jsx("mark",{style:{background:_d,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},p++)),a=c+r.length}return t.jsx(t.Fragment,{children:l})}function Bi(e,n,i,r){if(!n)return!0;const s=Et(n,r);return(i?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(a=>typeof a=="string"&&Et(a,r).includes(s))}function $d(e,n,i){return n?Et(e,i).includes(Et(n,i)):!0}const Ai={类:o("section-lei"),书:o("section-shu"),序:o("section-xu"),结语:o("section-jieyu"),注释:o("section-zhushi")},zd={考证:o("section-kaozhen")};function Cd(e){const n=e.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Ls(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((s,l)=>s+Ls(l),0))||0;return n+i}function Id(e,n){const i=[],r=a=>{var p;i.push(...a.files),(p=a.children)==null||p.forEach(r)};if(r(e),i.length===0)return;const s=i.map(a=>n[a]);if(s.every(a=>a===void 0))return;if(s.some(a=>a==="loading"))return"loading";let l=0;for(const a of s)typeof a=="number"&&(l+=a);return l}const Td={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Wi({enabled:e,expanded:n,onClick:i,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...Td,...r},children:s}):t.jsx("span",{style:r,children:s})}function Ed({type:e}){const n=it(e),i=Ai[n]||o("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:i,border:`1px solid ${i}40`,borderRadius:"2px",background:`${i}08`,flexShrink:0},children:n})}function Rd({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=q(),s=Pe(),l=vt(),a=S=>S?Ue(r(S),h=>i?en(h,i,l):h):"",[p,c]=f.useState(!1),d=!!e.summary,u=!!e.comment,g=!!e.additional_comment,x=!!(e.content&&e.content.length>60),m=d||u||g||x;f.useEffect(()=>{i&&c(!0)},[i]);const b=!p&&x?rs(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[t.jsxs("div",{onClick:()=>m&&c(!p),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:m?"pointer":"default",userSelect:"none",background:o("input-bg")},children:[t.jsxs(Wi,{enabled:m,expanded:p,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",a(e.book_title),"》"]}):a(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[Li(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:a(e.author_info||e.author)})]}),!p&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:a(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:a(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:o("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:s(e.work_id),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),p&&m&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${o("widget-border")}`,background:o("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"8px"},children:a(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:a(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(e.additional_comment)})]}),x&&!d&&!u&&!g&&t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)})]})]})}function Nd({section:e,highlightQuery:n=""}){const{convert:i}=q(),r=vt(),s=c=>c?Ue(i(c),d=>n?en(d,n,r):d):"",[l,a]=f.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(Wi,{enabled:p,expanded:l,onClick:()=>a(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(Ed,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:s(e.title)}),p&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&p&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${Ai[it(e.type)]||o("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:o("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(e.content)})})]})}const Ld=100;function Mi(e){return it(e.type)!=="page_header"?!1:(e.content||"").length>=Ld}function Bd({section:e,highlightQuery:n=""}){const{convert:i}=q(),r=vt();if(it(e.type)==="page_header"&&!Mi(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
794
- `)),l=Ue(s,d=>n?en(d,n,r):d),a=it(e.type),p=Ai[a]||o("desc-fg"),c=a==="序"||a==="结语"||a==="注释";return t.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:o("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${p}40`:void 0,background:c?o("bg"):void 0,borderRadius:c?"0 4px 4px 0":void 0,position:"relative"},children:[c&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:a}),l]})}function Ad(e,n,i){const[r,s]=f.useState({});return f.useEffect(()=>{var d;if(!n||e.length===0)return;let l=!1;const a=e.filter(u=>{var g;return!((g=i==null?void 0:i.current)!=null&&g.has(u))}),p={};for(const u of e)(d=i==null?void 0:i.current)!=null&&d.has(u)&&(p[u]=i.current.get(u));if(Object.keys(p).length>0&&s(p),a.length===0)return;const c=async u=>{var g;try{if(n.getEntry){const h=await n.getEntry(u);if(h)return{title:h.title,author:h.author}}const x=await n.getItem(u);if(!x)return null;const m=x.title||u,b=x.authors,S=(g=b==null?void 0:b[0])==null?void 0:g.name;return{title:m,author:S}}catch{return null}};return Promise.all(a.map(async u=>{var x;const g=await c(u);return(x=i==null?void 0:i.current)==null||x.set(u,g),[u,g]})).then(u=>{l||s(g=>{const x={...g};for(const[m,b]of u)x[m]=b;return x})}),()=>{l=!0}},[e.join(","),n]),r}function Wd({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=q(),a=Pe(),p=vt(),c=j=>j?Ue(l(j),k=>s?en(k,s,p):k):"",[d,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const g=it(e.type),x=zd[g]||o("desc-fg"),m=!!e.content,b=e.work_ids||[],S=b.length>1,h=Ad(S?b:[],i,r),y=m&&!d&&e.content.length>80?rs(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${o("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>m&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:m?"pointer":"default",userSelect:"none"},children:[t.jsxs(Wi,{enabled:m,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg"),lineHeight:1.6},children:e.header_line?c(e.header_line):c(e.title)}),!d&&y&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:c(y)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:a(b[0]),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),S&&t.jsxs("span",{style:{fontSize:"11px",color:o("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:g})]})]}),S&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(j=>{const k=h[j],$=k?`${l(k.title)}${k.author?`(${l(k.author)})`:""}`:j.slice(0,8)+"…";return t.jsxs("a",{href:a(j),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(j))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:j,children:["→",$]},j)})}),d&&m&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:o("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${o("widget-border")}`,fontSize:"12px",color:o("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:c(e.comment)})]})]})}function Md({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=vt(),a=n.trim(),p=f.useMemo(()=>a?e.sections.filter(c=>Bi(c,a,!0,l)):e.sections,[e.sections,a,l]);return t.jsxs("div",{children:[t.jsx("div",{children:p.map((c,d)=>t.jsx(Wd,{section:c,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:a},d))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Fd(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Pd({sections:e,onNavigate:n,inline:i}){const r=Pe(),{convert:s}=q(),l=Fd();return t.jsx(t.Fragment,{children:e.map((a,p)=>{const c=it(a.type);if(c==="page_header"&&!Mi(a))return null;if(c==="类")return t.jsxs(f.Fragment,{children:[f.createElement(l("类"),null,i(s(a.title))),a.content&&t.jsx("p",{children:i(s(a.content))})]},p);if(c==="书"||c==="诗"||c==="考证"||c==="注释"){const d=a.book_title?`《${a.book_title}》${a.n_juan!=null?Li(a.n_juan)+"卷":""}`:a.title,u=i(s(d));return t.jsxs("section",{className:"bim-rd-entry",children:[f.createElement(l("条目"),{className:"bim-rd-entry-h"},a.work_id&&n?t.jsx("a",{href:r(a.work_id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),n(a.work_id))},title:"查看作品",children:u}):u),a.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(a.author_info))}),a.content&&a.content.split(/\n+/).map((g,x)=>t.jsx("p",{children:i(s(g))},x)),a.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(a.summary))]}),a.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(a.comment))]}),a.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(a.additional_comment))]})]},p)}return a.content?t.jsx("p",{children:i(s(a.content))},p):null})})}function Od(e){return e.some(n=>{const i=it(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&Mi(n)})}function Dd({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:a,workLabelCache:p,prefs:c}){var B;const{convert:d}=q(),u=vt(),[g,x]=f.useState("text"),m=s.trim(),b=(r==null?void 0:r.type)==="kaozhen",S=f.useCallback(A=>m?en(A,m,u):A,[m,u]),h=A=>Ri(A,{renderText:S,properNames:c.properNames}),y=f.useMemo(()=>m?e.sections.filter(A=>Bi(A,m,b,u)):e.sections,[e.sections,m,b,u]),j=(A,W)=>W.filter(V=>it(V.type)===A).length,k=j("书",e.sections),$=j("诗",e.sections),v=j("考证",e.sections);let _="";b?_=m?`${j("考证",y)} / ${v} ${d("條")}`:`${v} ${d("條")}`:$>0?_=m?`${j("诗",y)} / ${$} 首`:`${$} 首`:k>0&&(_=m?`${j("书",y)} / ${k} ${d("部書")}`:`${k} ${d("部書")}`);const w=r!=null&&r.text_quality?hd(r.text_quality.grade):null,z=[];i&&z.push(i),_&&z.push(_),b&&(r!=null&&r.target_source)&&z.push(t.jsxs(t.Fragment,{children:[d("考證對象")," ",d(r.target_source)]})),w&&z.push(t.jsx("span",{title:Al[w],children:(B=r==null?void 0:r.text_quality)!=null&&B.source_note?t.jsxs(t.Fragment,{children:["底本 ",d(r.text_quality.source_note),"(",d(Hn[w]),")"]}):t.jsxs(t.Fragment,{children:[d("文本質量")," ",d(Hn[w])]})})),e.source_url&&z.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:d("原文來源")}));const N=!b&&Od(e.sections),T=!!n&&(!N||c.readingMode==="paragraph"&&zn(n)),C=!b&&(N||!!n),P=b||!C?"entries":g;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:d(e.title)}),z.length>0&&t.jsx("p",{className:"bim-rd-meta",children:z.map((A,W)=>t.jsxs(f.Fragment,{children:[W>0&&t.jsx("span",{className:"bim-rd-dot"}),A]},W))}),C&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":"看法",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":P==="text",onClick:()=>x("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":P==="entries",onClick:()=>x("entries"),children:d("條目")})]})]}),P==="text"&&t.jsx("article",{className:"bim-rd-prose",children:T?t.jsx(Ni,{text:n,mode:c.readingMode,properNames:c.properNames,renderText:S,dropTitle:e.title}):t.jsx(Pd,{sections:e.sections,onNavigate:l,inline:h})}),P==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:b?t.jsx(Md,{juan:e,searchQuery:s,onNavigate:l,transport:a,workLabelCache:p}):t.jsxs(t.Fragment,{children:[y.map((A,W)=>{const V=it(A.type);return V==="书"||V==="诗"||V==="考证"?t.jsx(Rd,{section:A,onNavigate:l,highlightQuery:m},W):V==="类"?t.jsx(Nd,{section:A,highlightQuery:m},W):t.jsx(Bd,{section:A,highlightQuery:m},W)}),y.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function Bs(e){return e.juan_files&&e.juan_files.length>0?e.juan_files:e.files&&e.files.length>0?e.files.map(n=>n.filename):[]}function Hd(e){const n=Bs(e);return n.length>0?n[0]:null}function Gd(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:a,query:p,isKaozhen:c}=e,d=vt(),u=f.useRef(new Map),[g,x]=f.useState({}),[m,b]=f.useState({}),S=f.useCallback((y,j)=>{const k=j==null?void 0:j.title;k&&b($=>$[y]===k?$:{...$,[y]:k})},[]);f.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:a}),S(s,l))},[s,l,a,S]),f.useEffect(()=>{u.current.clear(),x({}),b({})},[n]);const h=f.useCallback((y,j)=>{let k=0;if(y.juan)for(const $ of y.juan.sections)Bi($,j,c,d)&&k++;return k===0&&y.rawText&&$d(y.rawText,j,d)&&(k=1),k},[c,d]);return f.useEffect(()=>{const y=p.trim();if(!y){x({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let j=!1;const k={},$=[];for(const N of r){const T=u.current.get(N);T?k[N]=h(T,y):(k[N]="loading",$.push(N))}x(k);const v=8;let _=0;const w=async()=>{var N;for(;_<$.length;){if(j)return;const T=_++,C=$[T];try{const[P,B]=await Promise.all([i.getCollatedJuan(n,C),((N=i.getCollatedJuanText)==null?void 0:N.call(i,n,C))??Promise.resolve(null)]),A={juan:P,rawText:B};if(u.current.set(C,A),S(C,P),j)return;x(W=>({...W,[C]:h(A,y)}))}catch{if(j)return;x(P=>({...P,[C]:0}))}}},z=Array.from({length:Math.min(v,$.length)},()=>w());return Promise.all(z),()=>{j=!0}},[p,n,i,r.join(","),h,d,S]),{matchStates:g,titles:m}}const Fi=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:a,style:p,title:c,subtitle:d,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m})=>{const[b,S]=f.useState(null),[h,y]=f.useState(!1),[j,k]=f.useState(null),[$,v]=f.useState(null),[_,w]=f.useState(null),[z,N]=f.useState(!1),[T,C]=f.useState(null),[P,B]=f.useState(""),A=f.useRef(new Map),W=f.useRef(0),V=s??$,K=f.useCallback(X=>{v(X),l==null||l(X)},[l]),E=e||b;f.useEffect(()=>{e&&(y(!1),k(null))},[e]),f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let X=!1;return y(!0),k(null),i.getCollatedEditionIndex(n).then(ie=>{X||(ie?S(ie):k("未找到整理本数据"))}).catch(ie=>{X||k(ie instanceof Error?ie.message:"加载失败")}).finally(()=>{X||y(!1)}),()=>{X=!0}},[e,n,i]),f.useEffect(()=>{if(E&&!V){const X=Hd(E);X&&K(X)}},[E,V,K]);const le=n||(E==null?void 0:E.work_id),G=f.useCallback(async X=>{var me;if(!le||!(i!=null&&i.getCollatedJuan))return;const ie=++W.current;N(!0),w(null),C(null);try{const[te,se]=await Promise.all([i.getCollatedJuan(le,X),((me=i.getCollatedJuanText)==null?void 0:me.call(i,le,X))??Promise.resolve(null)]);if(ie!==W.current)return;w(te),C(se)}catch{if(ie!==W.current)return;w(null),C(null)}finally{ie===W.current&&N(!1)}},[le,i]);f.useEffect(()=>{V&&G(V)},[V,G]);const ae=X=>{K(X)};if(h)return t.jsx("div",{className:a,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(j)return t.jsx("div",{className:a,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:j});if(!E)return null;const pe=E.type==="kaozhen",ee=Bs(E);return t.jsx(Vd,{className:a,style:p,index:E,allFiles:ee,isKaozhen:pe,effectiveWorkId:le,transport:i,activeFile:V,handleSelectFile:ae,juanData:_,juanRawText:T,juanLoading:z,searchQuery:P,setSearchQuery:B,onNavigate:r,workLabelCacheRef:A,reader:{title:c,subtitle:d,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m}})};function As(e,n,i,r){var d,u,g,x;const s=(u=(d=n.juan_metadata)==null?void 0:d[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:Cd(e)),p=((x=(g=n.files)==null?void 0:g.find(m=>m.filename===e))==null?void 0:x.title)??i[e];if(!p)return{position:l,label:l};const c=r(p);return{position:l,label:l===p||l===c?c:`${l} ${c}`}}function Ud(e,n,i,r,s){const l=c=>c==="loading"?"…":typeof c=="number"&&c>0?c:void 0,a=(c,d)=>({key:c,label:d??As(c,e,r,s).label,hint:l(i[c]),disabled:i[c]===0}),p=(c,d)=>{var g;if(c.files.length===1&&!((g=c.children)!=null&&g.length))return a(c.files[0],s(c.label));const u=Id(c,i);return{key:`group:${d}`,label:s(c.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:Ls(c),defaultExpanded:typeof u=="number"&&u>0,children:[...c.files.map(x=>a(x)),...(c.children??[]).map((x,m)=>p(x,`${d}.${m}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((c,d)=>p(c,`${d}`)):n.map(c=>a(c))}const Vd=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:a,activeFile:p,handleSelectFile:c,juanData:d,juanRawText:u,juanLoading:g,searchQuery:x,setSearchQuery:m,onNavigate:b,workLabelCacheRef:S,reader:h})=>{const{convert:y}=q(),[j,k]=$i(),{matchStates:$,titles:v}=Gd({workId:l,transport:a,files:r,activeFile:p,activeJuan:d,activeRawText:u,query:x,isKaozhen:s}),_=Ns(h.resolveImages,p),w=f.useMemo(()=>Ud(i,r,$,v,y),[i,r,$,v,y]),z=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:C=>m(C.target.value)}),N=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(C=>C.vol_label)?"冊":"卷",T=p?As(p,i,v,y).position:void 0;return t.jsxs(zi,{className:e,style:n,title:h.title??(i.title?y(i.title):void 0),subtitle:h.subtitle??y(s?"考證":"整理本"),toc:w,tocCaption:`目录 · ${r.length} ${y(N)}`,tocHeader:z,activeKey:p,onSelect:c,images:_.images,imagesLoading:_.loading,renderImageOverlay:h.renderImageOverlay,imagePanel:h.imagePanel,prefs:j,onPrefsChange:k,paragraphToggle:!s&&zn(u),allowVertical:h.allowVertical,children:[g?t.jsx(jt,{}):d?t.jsx(Dd,{juan:d,rawText:u,positionLabel:T,index:i,searchQuery:x,onNavigate:b,transport:a,workLabelCache:S,prefs:j},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,i.references&&i.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:y("參考文獻")}),t.jsx("ol",{children:i.references.map((C,P)=>t.jsxs("li",{children:[C.url?t.jsx("a",{className:"bim-rd-link",href:C.url,target:"_blank",rel:"noopener noreferrer",children:C.title}):t.jsx("span",{children:C.title}),C.author&&t.jsxs("span",{children:[",",C.author]}),C.note&&t.jsxs("span",{children:["。",C.note]})]},P))})]})]})},Yd={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},qd={label:"其他",color:o("desc-fg")},Kd={pending:{label:"待处理",color:o("warning")},in_progress:{label:"处理中",color:o("primary")},resolved:{label:"已处理",color:o("success")},wontfix:{label:"不采纳",color:o("desc-fg")},duplicate:{label:"重复",color:o("desc-fg")}},Jd={label:"待处理",color:o("warning")};function Zd(e){try{const n=new Date(e),i=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return e}}function Xd(e,n){if(!e)return!1;try{const i=new URL(e,n);if(i.protocol!=="http:"&&i.protocol!=="https:")return!1;const r=new URL(n);return i.hostname===r.hostname}catch{return!1}}const Pi=({items:e,loading:n})=>{const i=Pe();return n?t.jsx(jt,{}):e.length===0?t.jsx("div",{style:Qd,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Yd[r.type]||qd,l=Kd[r.status]||Jd,a=typeof window<"u"&&Xd(r.pageUrl,window.location.href);return t.jsxs("div",{style:ep,children:[t.jsxs("div",{style:tp,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Bo,background:s.color},children:s.label}),t.jsx("span",{style:{...Bo,background:l.color},children:l.label})]}),t.jsx("span",{style:np,children:Zd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:ip,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:An,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(a?t.jsx("a",{href:r.pageUrl,style:An,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:An,children:r.pageUrl}))]}),t.jsx("div",{style:op,children:r.content}),r.reply&&t.jsxs("div",{style:rp,children:[t.jsx("div",{style:sp,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Qd={textAlign:"center",padding:"40px 0",color:o("desc-fg"),fontSize:"14px"},ep={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"16px"},tp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Bo={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},np={fontSize:"12px",color:o("desc-fg")},ip={fontSize:"12px",marginBottom:"6px"},An={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},op={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},rp={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},sp={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},ti=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const a=ue(),[p,c]=f.useState(null),[d,u]=f.useState([]),[g,x]=f.useState("recommend"),[m,b]=f.useState([]),[S,h]=f.useState(!1),y=r??g,j=W=>{x(W),s==null||s(W)},[k,$]=f.useState(!0),[v,_]=f.useState(null),[w,z]=f.useState(null),[N,T]=f.useState(null);f.useEffect(()=>{let W=!1;if(e.getCounts)return e.getCounts().then(V=>{W||c({works:V.works,books:V.books,collections:V.collections})}).catch(()=>{}),()=>{W=!0}},[e]),f.useEffect(()=>{let W=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const K=await e.getRecommended();if(K!=null&&K.groups)return K.groups.flatMap(E=>E.items.map(le=>({...le,group:E.name})))}catch{}return[]})().then(async K=>{if(W)return;const E=K.filter(G=>G.id);if(E.length===0){$(!1);return}const le=await Promise.all(E.map(async G=>{if(G.type)return{id:G.id,title:G.title,type:G.type,author:G.author,dynasty:G.dynasty,role:G.role,edition:G.edition,has_text:G.has_text,has_image:G.has_image,has_collated:G.has_collated,subtype:G.subtype,primary_name:G.primary_name,group:G.group,fallbackDescription:G.description};try{let ae=null;if(e.getEntry)ae=await e.getEntry(G.id);else{const pe=await e.getItem(G.id);pe&&(ae={id:G.id,title:pe.title||G.id,type:pe.type||"work"})}if(ae)return{...ae,group:G.group,fallbackDescription:G.description}}catch{}return{id:G.id,title:G.title,type:we.extractType(G.id),group:G.group,fallbackDescription:G.description}}));W||(u(le.filter(G=>G!==null)),$(!1))}),()=>{W=!0}},[e,i]);const C=f.useRef(!1),P=f.useRef(!1),B=f.useRef(!1);f.useEffect(()=>{if(y!=="catalog"||C.current)return;const W=e.getCatalogProgress??e.getResourceProgress;if(!W)return;C.current=!0;let V=!1;return W.call(e).then(K=>{V||_(K)}).catch(()=>{C.current=!1}),()=>{V=!0}},[e,y]),f.useEffect(()=>{if(y!=="collection"||P.current||!e.getCollectionProgress)return;P.current=!0;let W=!1;return e.getCollectionProgress().then(V=>{W||z(V)}).catch(()=>{P.current=!1}),()=>{W=!0}},[e,y]),f.useEffect(()=>{if(y!=="site"||B.current||!e.getSiteProgress)return;B.current=!0;let W=!1;return e.getSiteProgress().then(V=>{W||T(V)}).catch(()=>{B.current=!1}),()=>{W=!0}},[e,y]),f.useEffect(()=>{if(!l||y!=="feedback")return;let W=!1;return h(!0),fetch(l).then(V=>V.json()).then(V=>{!W&&V.success&&b(V.items||[])}).catch(()=>{}).finally(()=>{W||h(!1)}),()=>{W=!0}},[l,y]);const A=W=>t.jsx(jn,{type:W,size:12});return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:o("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${o("widget-border")}`,marginBottom:"16px"},children:[t.jsx(Ft,{label:a.home.recommendTab,active:y==="recommend",onClick:()=>j("recommend")}),t.jsx(Ft,{label:a.home.catalogTab,active:y==="catalog",onClick:()=>j("catalog")}),t.jsx(Ft,{label:a.home.collectionTab,active:y==="collection",onClick:()=>j("collection")}),t.jsx(Ft,{label:a.home.siteTab,active:y==="site",onClick:()=>j("site")}),l&&t.jsx(Ft,{label:a.home.feedbackTab,active:y==="feedback",onClick:()=>j("feedback")})]}),y==="recommend"&&t.jsx(lp,{recommended:d,loading:k,onNavigate:n,getIcon:A,t:a}),y==="catalog"&&t.jsx(Ao,{progress:v,t:a,onNavigate:n}),y==="collection"&&t.jsx(Ao,{progress:w,t:a,onNavigate:n}),y==="site"&&t.jsx(cp,{progress:N,t:a,totalWorks:(p==null?void 0:p.works)??0}),y==="feedback"&&l&&t.jsx(Pi,{items:m,loading:S})]})})},Ft=({label:e,active:n,onClick:i})=>t.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:o(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${o("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),lp=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=Pe();if(n)return t.jsx(jt,{});if(e.length===0)return null;const a=new Map;for(const p of e){const c=p.group||s.home.recommendedBrowse;a.has(c)||a.set(c,[]),a.get(c).push(p)}return t.jsx(t.Fragment,{children:Array.from(a.entries()).map(([p,c])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:p}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return t.jsxs("a",{href:l(d.id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),i==null||i(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,cursor:"pointer",background:o("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},Ao=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(jt,{});const r=[...e.resources].sort((p,c)=>p.priority-c.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},a={in_progress:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(p=>{const c=r.filter(d=>d.status===p);return c.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:a[p]}}),l[p]," (",c.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(d=>t.jsx(ap,{item:d,t:n,statusColor:a[p],onNavigate:i},d.id))})]},p)})})},ap=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=Pe(),l=e.total>0?Math.round(e.imported/e.total*100):0,a=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=e.edition?`${e.name}·${e.edition}`:e.name,c=e.collection_id||e.work_id;return c&&r?t.jsx("a",{href:s(c),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:p}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:o("widget-border"),color:o("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:a})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Kt(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},cp=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(jt,{});const r=[...e.resources].sort((c,d)=>c.priority-d.priority),s=r.filter(c=>c.imported>0),l=r.filter(c=>c.imported===0),a=s.reduce((c,d)=>Math.max(c,d.imported),0),p=i>0?Math.round(a/i*100):0;return t.jsxs("div",{children:[i>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${o("primary")} 6%, transparent)`,fontSize:"13px",color:o("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:a.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>t.jsx(Wo,{item:c,t:n,totalWorks:i},c.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(c=>t.jsx(Wo,{item:c,t:n,totalWorks:i},c.id))})]})]})},Wo=({item:e,t:n,totalWorks:i})=>{const r=i>0?Math.round(e.imported/i*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:t.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&i>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:o("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},Mo="(max-width: 768px)";function dp(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Mo).matches);return f.useEffect(()=>{const i=window.matchMedia(Mo),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),e}const pp=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var V;const l=ue(),{convert:a}=q(),p=dp(),[c,d]=f.useState(null),[u,g]=f.useState(null),[x,m]=f.useState(!1),[b,S]=f.useState("detail"),[h,y]=f.useState([]),[j,k]=f.useState(!1),[$,v]=f.useState(null),[_,w]=f.useState(!1),z=f.useCallback(async K=>{if(!e.getCollatedEditionIndex){v(null);return}w(!0);try{const E=await e.getCollatedEditionIndex(K);v(E)}catch{v(null)}finally{w(!1)}},[e]),N=f.useCallback(async K=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){y([]);return}k(!0);try{if(e.getCollectionCatalogs){const E=await e.getCollectionCatalogs(K);y(E||[])}else if(e.getCollectionCatalog){const E=await e.getCollectionCatalog(K);y(E?[{resource_id:"",data:E}]:[])}}catch{y([])}finally{k(!1)}},[e]),T=f.useCallback(async K=>{if(i){i(K);return}d(K),g(null),y([]),v(null),S("detail"),m(!0);try{const E=await e.getItem(K.id);E&&(g(E),E.type==="collection"?N(K.id):E.type==="work"&&E.has_collated&&z(K.id))}catch(E){console.error("加载详情失败:",E)}finally{m(!1)}},[e,i,N,z]),C=f.useCallback(async K=>{g(null),y([]),v(null),S("detail"),m(!0);try{const E=await e.getItem(K);E&&(g(E),d({id:K,title:E.title||K,type:E.type||"book"}),E.type==="collection"?N(K):E.type==="work"&&E.has_collated&&z(K))}catch(E){console.error("导航失败:",E)}finally{m(!1)}},[e,N,z]),P=(u==null?void 0:u.type)==="collection"&&(h.length>0||j)||(u==null?void 0:u.type)==="work"&&($||_),B=p&&(x||u),A=f.useCallback(()=>{d(null),g(null),y([]),v(null),S("detail")},[]),W=t.jsx(t.Fragment,{children:x?t.jsx(jt,{}):u?t.jsxs(t.Fragment,{children:[(P||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${o("widget-border")}`,padding:p?"0 12px":"0 48px",background:o("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[P&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>S("detail"),style:dn(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&j&&h.length===0&&t.jsxs("button",{onClick:()=>{},style:dn(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&h.map(K=>t.jsx("button",{onClick:()=>S(`catalog:${K.resource_id}`),style:dn(b===`catalog:${K.resource_id}`),children:K.short_name?`${a(K.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},K.resource_id)),u.type==="work"&&($||_)&&t.jsxs("button",{onClick:()=>S("collated"),style:dn(b==="collated"),children:[l.detailTab.collatedEdition,_&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?t.jsx(fi,{data:u,transport:e,onNavigate:C}):b.startsWith("catalog:")?t.jsx(gi,{data:(V=h.find(K=>`catalog:${K.resource_id}`===b))==null?void 0:V.data,onNavigate:C}):b==="collated"?t.jsx(Fi,{index:$||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(ti,{transport:e,onNavigate:C,recommendedIds:r})});return p?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:B?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${o("widget-border")}`,background:o("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:A,style:{padding:"4px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:W})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Un,{transport:e,onEntryClick:T,hideModeIndicator:n}),!u&&t.jsx(ti,{transport:e,onNavigate:C,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${o("widget-border")}`,display:"flex",flexDirection:"column",background:o("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(Un,{transport:e,onEntryClick:T,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:W})]})};function dn(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function ut(e){return e.replace(/\.md$/,"")}function Fo(e){let n="";if(e.source_url)try{const r=new URL(e.source_url).pathname.split("/").filter(Boolean).pop()??"";n=decodeURIComponent(r).replace(/_/g," ")}catch{}return[e.source_name,n||e.version_label].filter(Boolean).join(" · ")||e.key}const Po={padding:24,color:o("desc-fg")},ni=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:a,onVersionChange:p,title:c,subtitle:d,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m,className:b,style:S})=>{const[h,y]=f.useState(e??null),[j,k]=f.useState(!1),[$,v]=f.useState(null),_=r!==void 0?r:$,w=f.useCallback(ee=>{s?s(ee):v(ee)},[s]),[z,N]=f.useState(null),[T,C]=f.useState(!1);f.useEffect(()=>{e&&y(e)},[e]),f.useEffect(()=>{if(e)return;y(null),k(!1);const ee=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!ee){k(!0);return}let X=!1;return Promise.resolve().then(ee).then(ie=>{X||(ie?y(ie):k(!0))}).catch(()=>{X||k(!0)}),()=>{X=!0}},[n,i,e,l]),f.useEffect(()=>{if(!h||h.chapters.length===0)return;const ee=ut(h.chapters[0].file);if(!_){w(ee);return}const X=ut(_);h.chapters.some(me=>ut(me.file)===X)||w(ee)},[h,_,w]);const P=f.useMemo(()=>{if(!h||!_)return null;const ee=ut(_);return h.chapters.find(X=>ut(X.file)===ee)??null},[h,_]);f.useEffect(()=>{if(!n||!P)return;const ee=l!==void 0?i.getWorkFullTextChapter?ie=>i.getWorkFullTextChapter(n,l,ie):null:i.getBookFullTextChapter?ie=>i.getBookFullTextChapter(n,ie):null;if(!ee)return;let X=!1;return C(!0),N(null),Promise.resolve(P.file).then(ee).then(ie=>{X||N(ie)}).catch(()=>{X||N(null)}).finally(()=>{X||C(!1)}),()=>{X=!0}},[n,P,i,l]);const B=Ns(u,P?ut(P.file):null),[A,W]=$i(),{convert:V}=q(),K=!!(a&&a.length>1&&p),E=f.useMemo(()=>K?bs(a).map((ee,X)=>({...ee,label:Fo(a[X])})):void 0,[K,a]),le=K?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:ee=>p(ee.target.value),children:a.map(ee=>t.jsx("option",{value:ee.key,children:Fo(ee)},ee.key))})]}):null;if(!h)return t.jsxs("div",{style:Po,children:[le&&t.jsx("div",{style:{marginBottom:12},children:le}),j?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:Po,children:[le&&t.jsx("div",{style:{marginBottom:12},children:le}),"全文目录为空"]});const G=h.chapters.map(ee=>({key:ut(ee.file),label:V(ee.title)})),ae=ks(h)||qn(h),pe=z?z.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(zi,{title:c??V(h.version_label),subtitle:d??"全文",toc:G,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:_?ut(_):null,onSelect:w,images:B.images,imagesLoading:B.loading,renderImageOverlay:g,imagePanel:x,prefs:A,onPrefsChange:W,versions:E,currentVersionKey:E?l??null:void 0,onVersionChange:E?p:void 0,versionSource:!1,paragraphToggle:zn(pe),allowVertical:m,className:b,style:S,children:[P&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:V(P.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:h.source.url,target:"_blank",rel:"noreferrer",children:V(h.source.name)}),h.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),h.source.license]})]})]}),T&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!T&&pe!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Ni,{text:pe,mode:A.readingMode,tables:ae,gujiMarkdown:qn(h),properNames:A.properNames})}),!T&&!z&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},up=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=ue(),{convert:l}=q(),[a,p]=f.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[c,d]=f.useState(null);return t.jsxs("div",{className:i,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:l(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[s.catalog.totalVolumes," ",t.jsx("strong",{children:e.total_volumes})," ",s.unit.juan]}),e.stats.zhulu!=null&&t.jsxs("span",{children:["著錄 ",t.jsx("strong",{children:e.stats.zhulu})," ",s.unit.bu]}),e.stats.cunmu!=null&&t.jsxs("span",{children:["存目 ",t.jsx("strong",{children:e.stats.cunmu})," ",s.unit.bu]}),e.stats.categories!=null&&t.jsxs("span",{children:[e.stats.categories," 類"]})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(g=>t.jsx(xp,{division:g,expanded:a===g.name,onToggle:()=>p(a===g.name?null:g.name),expandedCat:c,onCatToggle:x=>d(c===x?null:x),onNavigate:n},g.name))})]})},xp=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:a}=q(),p=e.categories.reduce((c,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return c+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${o("primary")} 6%, transparent)`:o("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:o("fg"),textAlign:"left"},children:[t.jsx("span",{children:a(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg")},children:[e.categories.length," 類 · ",p," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(c=>{const d=`${e.name}/${c.name}`;return t.jsx(fp,{category:c,expanded:r===d,onToggle:()=>s(d),onNavigate:l},c.name)})})]})},fp=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var c,d,u,g;const{convert:s}=q(),l=((c=e.books)==null?void 0:c.zhulu)||[],a=((d=e.books)==null?void 0:d.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((g=e.stats)==null?void 0:g.cunmu)||a.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?o("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:o("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||a.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Oo,{label:"著錄",books:l,onNavigate:r}),a.length>0&&t.jsx(Oo,{label:"存目",books:a,onNavigate:r})]})]})},Oo=({label:e,books:n,onNavigate:i})=>{const{convert:r}=q(),s=Pe(),[l,a]=f.useState(n.length<=20),p=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((c,d)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:o("fg")},children:c.work_id&&i?t.jsx("a",{href:s(c.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},children:r(c.title)}):r(c.title)}),c.volumes&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(c.volumes)}),c.author&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(c.author).slice(0,20)})]},d))}),!l&&t.jsxs("button",{onClick:()=>a(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},qe=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=ue();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:o("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&t.jsx("button",{onClick:i,style:mp,children:"AI"}),n&&t.jsx("button",{onClick:n,style:gp,children:l.action.save})]})]}),s]})},gp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},mp={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Ge=({label:e,value:n,onChange:i,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:l=>i(l.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),bt=({value:e,onChange:n,placeholder:i})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},hn=({children:e,color:n,style:i})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||o("primary-soft"),color:o(n?"on-color-fg":"fg"),...i},children:e});function hp(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const un=({value:e,onChange:n,label:i})=>{const[r,s]=f.useState(!1),l=f.useRef(null),a=hp(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&a?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Do,children:i}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${o("input-border")}`,borderRadius:"2px",background:o("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:o("fg")},children:a.name}),t.jsx(hn,{children:a.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Do,children:i}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Do={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function bp(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function yp(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ws=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=ue(),[s,l]=f.useState(null),a=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},p=g=>{n(e.filter((x,m)=>m!==g)),s===g&&l(null)},c=(g,x,m)=>{const b=[...e];b[g]={...b[g],[x]:m},n(b)},d=(g,x)=>{const m=[...e];m[g]={...m[g],type:x,id:"",name:""},n(m),x==="bookID"&&i&&i(b=>{const S=[...e];S[g]={...S[g],id:b.id,name:b.title,type:"bookID"},n(S)})},u=g=>{i&&i(x=>{const m=[...e];m[g]={...m[g],id:x.id,name:x.title,type:"bookID"},n(m)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((g,x)=>t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===x?null:x),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===x?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:o("fg")},children:g.name||`${r.editor.sourcePlaceholder} ${x+1}`}),g.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:bp(g.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:yp(g.type)}),t.jsx("button",{onClick:m=>{m.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===x&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!g.type&&t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>d(x,"bookID"),style:{...Ho,borderColor:o("source-bookid"),color:o("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>d(x,"url"),style:{...Ho,borderColor:o("source-url"),color:o("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),g.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:ot,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Go,children:r.action.changeType})]}),g.id&&g.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:o("bg"),border:`1px solid ${o("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:o("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:g.name}),t.jsx("code",{style:{fontSize:"11px",background:o("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:g.id})]}),t.jsx("button",{onClick:()=>u(x),style:{background:"transparent",border:`1px solid ${o("widget-border")}`,color:o("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(x),style:{width:"100%",padding:"14px",border:`2px dashed ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),g.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:ot,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Go,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:g.name,onChange:m=>c(x,"name",m.target.value),placeholder:r.editor.sourceNamePlaceholder,style:St})]}),t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:g.id,onChange:m=>c(x,"id",m.target.value),placeholder:"https://...",style:St})]})]}),g.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${o("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...ot,opacity:.7},children:r.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:g.details,onChange:m=>c(x,"details",m.target.value),placeholder:r.editor.detailsPlaceholder,style:St})]}),t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:g.position,onChange:m=>c(x,"position",m.target.value),placeholder:"如: 卷三, p.52",style:St})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:g.version,onChange:m=>c(x,"version",m.target.value),placeholder:"如: v1.0, 2024-01",style:St})]}),t.jsxs("div",{children:[t.jsx("label",{style:ot,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:g.processor_version,onChange:m=>c(x,"processor_version",m.target.value),placeholder:"如: v0.1",style:St})]})]})]})]})})]},x)),t.jsxs("button",{onClick:a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},ot={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},St={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Ho={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:o("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},Go={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Ms(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(i=>({id:i.id||"",name:i.name||"",type:i.type||"",details:i.details||"",position:i.position||"",version:i.version||"",processor_version:i.processor_version||""}))}catch{}return[]}function Fs(e){return!e||e.length===0?"":JSON.stringify(e)}const Ps=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:a,childWorks:p,childCollections:c,containedBooks:d,siblingBooks:u,onLinkEntity:g,onUnlinkEntity:x,onViewEntity:m,onCreateAndLink:b,onSaveRelations:S})=>{const h=ue();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:h.section.relations})]}),S&&t.jsx("button",{onClick:S,style:jp,children:h.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.belongsToWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>g("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Pt,{direction:"up",title:h.relation.containedInCollection,entity:a,onView:m,onUnlink:()=>x("collectionId"),onLink:()=>g("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),l&&u&&u.length>0&&t.jsx(wt,{direction:"horizontal",title:`${h.relation.siblingVersions} (${u.length})`,entities:u,onView:m,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.parentWork,entity:r,onView:m,onUnlink:()=>x("parentWorkId"),onLink:()=>g("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),p&&p.length>0&&t.jsx(wt,{direction:"down",title:`${h.relation.childWorks} (${p.length})`,entities:p,onView:m,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),c&&c.length>0&&t.jsx(wt,{direction:"down",title:`${h.relation.collectionImpl} (${c.length})`,entities:c,onView:m,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(wt,{direction:"down",title:`${h.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>b("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:"up",title:h.relation.correspondingWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>g("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Pt,{direction:"up",title:h.relation.parentCollection,entity:s,onView:m,onUnlink:()=>x("parentCollectionId"),onLink:()=>g("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(wt,{direction:"down",title:`${h.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:m,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(wt,{direction:"down",title:`${h.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},Pt=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:a,linkLabel:p,createLabel:c,notLinkedLabel:d,viewLabel:u,unlinkLabel:g})=>{const x=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:o("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Os(i.type)}),t.jsx("span",{style:{fontWeight:500},children:i.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(Uo,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(Uo,{onClick:s,title:g,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(ii,{onClick:l,children:p}),t.jsx(ii,{onClick:a,primary:!0,children:c})]})]})},wt=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:a,expandMoreLabel:p})=>{const[c,d]=f.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),g=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=c?i:i.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:g}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[x.map(m=>t.jsxs("div",{onClick:()=>r(m),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:o("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:Os(m.type)}),t.jsx("span",{children:m.title})]},m.id)),i.length>5&&!c&&t.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:o("link-fg"),cursor:"pointer"},children:[p," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:a}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(ii,{onClick:s,primary:!0,children:["+ ",l]})})]})},Uo=({onClick:e,title:n,danger:i,children:r})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?o("danger"):"inherit",opacity:.7},children:r}),ii=({onClick:e,primary:n,children:i})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${o("widget-border")}`,borderRadius:"4px",background:n?o("primary"):"transparent",color:n?o("primary-fg"):"inherit",cursor:"pointer"},children:i});function Os(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const jp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Ds=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:a,onSearch:p,isLoading:c,excludeId:d})=>{const[u,g]=f.useState(""),x=d?a.filter(h=>h.id!==d):a;f.useEffect(()=>{e&&(g(""),p(""))},[e]);const m=h=>{g(h),p(h)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",S=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:vp,children:t.jsxs("div",{style:kp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),t.jsx("button",{onClick:s,style:Sp,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:h=>m(h.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:wp})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:Wn,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(h=>t.jsxs("div",{onClick:()=>r(h),style:_p,children:[t.jsx("span",{style:{fontSize:"16px"},children:S}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):u?t.jsxs("div",{style:Wn,children:["未找到匹配的",b]}):t.jsxs("div",{style:Wn,children:["输入关键词搜索",b]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:l,style:$p,children:["创建新",b,"并关联"]})]})]})})},vp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},kp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},Sp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},wp={width:"100%",padding:"10px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},_p={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:o("primary-soft")},Wn={padding:"20px",textAlign:"center",color:o("desc-fg")},$p={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Vo={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},zp={work:"📜",book:"📖",collection:"📚",entity:"👤"},Hs=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[a,p]=f.useState(""),c=f.useRef(null);f.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,m;(x=c.current)==null||x.focus(),(m=c.current)==null||m.select()},100))},[e,r==null?void 0:r.title]);const d=x=>{x.key==="Enter"&&a.trim()?u():x.key==="Escape"&&l()},u=()=>{a.trim()&&s(a.trim(),{...r,title:a.trim()})};if(!e)return null;const g=()=>{switch(i){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Vo[n]}`}};return t.jsx("div",{style:Cp,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:Ip,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:zp[n]}),t.jsx("span",{children:g()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:o("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:o("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:c,type:"text",value:a,onChange:x=>p(x.target.value),onKeyDown:d,placeholder:`请输入${Vo[n]}名称...`,style:Tp})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),background:o("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&t.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:l,style:Ep,children:"取消"}),t.jsx("button",{onClick:u,disabled:!a.trim(),style:{...Rp,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Cp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ip={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:o("shadow-dialog")},Tp={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box"},Ep={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Rp={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function Np(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Gs(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Lp(e){switch(e){case"work":return o("editor-type-work");case"collection":return o("editor-type-collection");case"book":return o("editor-type-book");default:return o("desc-fg")}}const Us=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:a,onSelect:p,onCancel:c,onCreate:d,onSearch:u})=>{const[g,x]=f.useState(""),[m,b]=f.useState([]),[S,h]=f.useState(!1),[y,j]=f.useState("recent");f.useEffect(()=>{e&&(x(""),b([]),j(r.length>0?"recent":"search"))},[e,r.length]),f.useEffect(()=>{if(!g.trim()){b([]);return}const z=setTimeout(async()=>{h(!0);try{b(await u(g,i))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(z)},[g,i,u]);const k=f.useCallback(z=>{x(z.target.value),z.target.value.trim()&&j("search")},[]),$=f.useCallback(z=>s?z.filter(N=>N.id!==s):z,[s]);if(!e)return null;const v=n||(i==="all"?"选择实体":`选择${Gs(i)}`),_=$(r),w=$(m);return t.jsx("div",{style:Ap,children:t.jsxs("div",{style:Wp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:v}),t.jsx("button",{onClick:c,style:Mp,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:g,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Fp}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),S&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),_.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs(Yo,{active:y==="recent",onClick:()=>j("recent"),children:["最近使用 (",_.length,")"]}),t.jsxs(Yo,{active:y==="search",onClick:()=>j("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:y==="recent"&&_.length>0?t.jsx(qo,{entities:_,onSelect:p}):g.trim()?S?t.jsx(Mn,{message:"搜索中..."}):w.length>0?t.jsx(qo,{entities:w,onSelect:p}):t.jsx(Mn,{message:"未找到匹配的结果"}):t.jsx(Mn,{message:"输入关键词开始搜索"})}),l&&d&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:d,style:Pp,children:a||"创建新实体"})]})]})})},Yo=({active:e,onClick:n,children:i})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:i}),qo=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(Bp,{entity:i,onClick:()=>n(i)},i.id))}),Bp=({entity:e,onClick:n})=>{const[i,r]=f.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Np(e.type)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:e.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[t.jsx("code",{style:{fontSize:"10px",background:o("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&t.jsx("span",{children:e.author}),e.dynasty&&t.jsx("span",{children:e.dynasty})]})]}),t.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Lp(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Gs(e.type)})]})},Mn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),Ap={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Wp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},Mp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Fp={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},Pp={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Op={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},Dp={work:"📜",collection:"📚",book:"📖",entity:"👤"},Vs=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:a,onAskAI:p,renderSectionActions:c,onDownloadResource:d,downloadStatuses:u,relations:g,onRelationsChange:x})=>{var Z;const m=ue(),[b,S]=f.useState(!1),[h,y]=f.useState("work"),[j,k]=f.useState(""),[$,v]=f.useState(""),[_,w]=f.useState([]),[z,N]=f.useState(!1),[T,C]=f.useState(!1),[P,B]=f.useState("work"),[A,W]=f.useState(""),[V,K]=f.useState(),[E,le]=f.useState(!1),[G,ae]=f.useState(null),[pe,ee]=f.useState([]);f.useRef(null);const X=e.type,ie=X==="work",me=X==="collection",te=X==="book",se=f.useCallback((F,I)=>{n({...e,[F]:I})},[e,n]),fe=f.useCallback((F,I)=>{k(F),y(I),v(m.editor.selectToLink+m.indexType[I]),w([]),S(!0)},[m]),be=f.useCallback(F=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,F)},[r,e.id]),ze=f.useCallback(F=>{s==null||s(F.id,F.type)},[s]),ve=f.useCallback((F,I,D)=>{const M={...D,author:(D==null?void 0:D.author)||e.author,dynasty:D==null?void 0:D.dynasty};B(I),W(F),K(M),C(!0)},[e.author]),ke=f.useCallback((F,I)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,A,{type:P,title:F,inheritData:I}),C(!1)},[r,e.id,A,P]),Ne=f.useCallback(F=>{if(!F.trim()){w([]);return}N(!0),r!=null&&r.searchEntities&&r.searchEntities(F,h).then(I=>{w(I),N(!1)}).catch(()=>{w([]),N(!1)})},[r,h]),Ee=f.useCallback(F=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,j,F.id),S(!1)},[r,e.id,j]),O=f.useCallback(()=>{i()},[i]),ce=f.useCallback(F=>{ae(()=>F),le(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(ee).catch(()=>{})},[r]),oe=f.useCallback((F,I)=>r!=null&&r.searchEntities?r.searchEntities(F,I==="all"?void 0:I):Promise.resolve([]),[r]),he=f.useCallback(F=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(F),ee(I=>[F,...I.filter(D=>D.id!==F.id)].slice(0,10)),G==null||G(F),le(!1),ae(null)},[r,G]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${o("widget-border")}`,paddingBottom:"16px"},children:t.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Dp[X]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(hn,{children:e.id}),t.jsx(hn,{color:Op[X],children:m.indexType[X]})]})}),t.jsx(qe,{title:m.section.basicInfo,onSave:i,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(un,{label:ie?m.editor.workTitle:me?m.editor.collectionTitle:m.editor.bookTitle,value:e.title,onChange:F=>se("title",F)}),te&&t.jsx(un,{label:m.editor.belongsToWork,value:e.workName||"",onChange:F=>se("workName",F)}),t.jsx(Ge,{label:m.editor.authorLabel,value:e.author||"",onChange:F=>se("author",F)}),t.jsx(Ge,{label:m.editor.publicationYearLabel,value:e.publicationYear||"",onChange:F=>se("publicationYear",F)}),(te||me)&&t.jsx(un,{label:m.editor.containedIn,value:e.collection||"",onChange:F=>se("collection",F)}),(te||me)&&t.jsx(Ge,{label:m.editor.holderLabel,value:e.holder||"",onChange:F=>se("holder",F)}),(te||me)&&t.jsx(Ge,{label:te?m.editor.pageLabel:m.editor.volumeLabel,value:e.pages||"",onChange:F=>se("pages",F)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(Ge,{label:m.editor.firstImageLabel,value:e.firstImage||"",onChange:F=>se("firstImage",F)})})]})}),t.jsx(qe,{title:m.section.description,onSave:i,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(bt,{value:e.description||"",onChange:F=>se("description",F),placeholder:m.editor.descriptionPlaceholder})}),(((Z=e.additional_works)==null?void 0:Z.length)||0)>0&&t.jsx(qe,{title:m.section.additionalWorks,onSave:i,children:t.jsx(Hp,{items:e.additional_works||[],onChange:F=>se("additional_works",F)})}),t.jsx(qe,{title:m.section.indexedBy,onSave:i,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Gp,{items:e.indexed_by||[],onChange:F=>se("indexed_by",F)})}),t.jsx(qe,{title:m.section.emendatedBy,onSave:i,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Up,{items:e.emendated_by||[],onChange:F=>se("emendated_by",F)})}),t.jsx(qe,{title:m.section.textResources,onSave:i,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(Gn,{items:e.resources||[],onChange:F=>se("resources",F),onDownload:d,downloadStatuses:u,filterType:"text"})}),t.jsx(qe,{title:m.section.imageResources,onSave:i,children:t.jsx(Gn,{items:e.resources||[],onChange:F=>se("resources",F),onDownload:d,downloadStatuses:u,filterType:"image"})}),t.jsx(qe,{title:m.section.sources,onSave:i,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(Ws,{items:Ms(e.sources||""),onChange:F=>se("sources",Fs(F)),onOpenEntityPicker:ce})}),(te||me)&&t.jsx(qe,{title:m.section.provenance,onSave:i,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(bt,{value:e.provenance||"",onChange:F=>se("provenance",F),placeholder:m.editor.provenancePlaceholder})}),te&&t.jsx(qe,{title:m.section.otherEditions,onSave:i,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(bt,{value:e.otherEditions||"",onChange:F=>se("otherEditions",F),placeholder:m.editor.otherEditionsPlaceholder})}),t.jsx(Ps,{entityType:X,entityId:e.id,entityTitle:e.title,parentWork:g==null?void 0:g.parentWork,parentCollection:g==null?void 0:g.parentCollection,belongsToWork:g==null?void 0:g.belongsToWork,belongsToCollection:g==null?void 0:g.belongsToCollection,childWorks:g==null?void 0:g.childWorks,childCollections:g==null?void 0:g.childCollections,containedBooks:g==null?void 0:g.containedBooks,siblingBooks:g==null?void 0:g.siblingBooks,onLinkEntity:fe,onUnlinkEntity:be,onViewEntity:ze,onCreateAndLink:ve,onSaveRelations:O}),l&&a&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${o("danger-soft-border")}`,background:o("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:o("danger"),fontWeight:600,marginBottom:"8px"},children:m.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"12px"},children:m.editor.dangerZoneDesc}),t.jsx("button",{onClick:a,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("danger")}`,borderRadius:"4px",background:"transparent",color:o("danger"),cursor:"pointer"},children:m.editor.deleteEntity})]}),t.jsx(Ds,{isOpen:b,entityType:h,title:$,onSelect:Ee,onCancel:()=>S(!1),onCreate:()=>{S(!1),ve(j,h)},searchResults:_,onSearch:Ne,isLoading:z,excludeId:e.id}),t.jsx(Hs,{isOpen:T,entityType:P,relationField:A,inheritData:V,onConfirm:ke,onCancel:()=>C(!1)}),t.jsx(Us,{isOpen:E,title:m.action.selectBookOrWork,filterType:"all",recentEntities:pe,excludeId:e.id,onSelect:he,onCancel:()=>{le(!1),ae(null)},onSearch:oe})]})};function Hp({items:e,onChange:n}){const i=ue(),r=(a,p,c)=>{const d=e.map((u,g)=>g===a?{...u,[p]:c}:u);n(d)},s=a=>n(e.filter((p,c)=>c!==a)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((a,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(Ge,{label:i.editor.bookNameLabel,value:a.book_title,onChange:c=>r(p,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(Ge,{label:i.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:c=>r(p,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Ys({items:e,onChange:n,showMeta:i,addLabel:r}){const s=ue(),[l,a]=f.useState(null),p=(u,g,x)=>{const m=e.map((b,S)=>S===u?{...b,[g]:x||void 0}:b);n(m)},c=u=>{n(e.filter((g,x)=>x!==u)),l===u&&a(null)},d=()=>{n([...e,{source:""}]),a(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,g)=>{const x=l===g;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:x?`color-mix(in srgb, ${o("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>a(x?null:g),children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.2s",transform:x?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:m=>{m.stopPropagation(),c(g)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${o("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:o("muted")},children:"✕"})]}),!x&&i&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:o("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),x&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ge,{label:s.label.sourceName,value:u.source,onChange:m=>p(g,"source",m)}),t.jsx(Ge,{label:s.label.sourceBid,value:u.source_bid||"",onChange:m=>p(g,"source_bid",m)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ge,{label:s.label.titleInfo,value:u.title_info||"",onChange:m=>p(g,"title_info",m)}),t.jsx(Ge,{label:s.label.authorInfo,value:u.author_info||"",onChange:m=>p(g,"author_info",m)})]}),t.jsx(Ge,{label:s.label.edition,value:u.edition||"",onChange:m=>p(g,"edition",m)})]}),t.jsx(bt,{value:u.summary||"",onChange:m=>p(g,"summary",m),placeholder:s.editor.summaryPlaceholder}),t.jsx(bt,{value:u.comment||"",onChange:m=>p(g,"comment",m),placeholder:s.editor.commentPlaceholder}),t.jsx(bt,{value:u.additional_comment||"",onChange:m=>p(g,"additional_comment",m),placeholder:s.editor.additionalCommentPlaceholder})]})]},g)}),t.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Gp({items:e,onChange:n}){const i=ue();return t.jsx(Ys,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Up({items:e,onChange:n}){const i=ue();return t.jsx(Ys,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function qs(e){var p,c,d,u,g,x,m;const n=((c=(p=e.authors)==null?void 0:p[0])==null?void 0:c.name)||"",i=((d=e.publication_info)==null?void 0:d.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(g=e.page_count)!=null&&g.number?String(e.page_count.number):((x=e.page_count)==null?void 0:x.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",a={id:e.id,title:e.title,type:e.type,author:n,publicationYear:i,holder:r,pages:s,description:l,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const b=e;if(Array.isArray(b.related_works)){const S=b.related_works.find(h=>h.relation==="part_of");S&&(a.parentWorkId=S.id,a.parentWorkName=S.title)}}if(e.type==="book"){const b=e;a.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(a.collectionId=(m=b.contained_in[0])==null?void 0:m.id)}return a}function Vp(e){const n={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.publicationYear?{year:e.publicationYear}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(n.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(n.work_id=e.workId,e.collectionId&&(n.contained_in=[{id:e.collectionId}])),n}const Yp=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:a,onSave:p,onDelete:c,onNavigate:d,renderLink:u,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:S,onRelationsChange:h,headerExtra:y,className:j,style:k}=e;ue();const[$,v]=f.useState(s),_=l?s:$;f.useEffect(()=>{s!==$&&v(s)},[s]);const w=f.useCallback(()=>{const A=_==="view"?"edit":"view";l?l(A):v(A)},[_,l]),[z,N]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(A=>{A&&N(A)})},[i,r]);const T=n||z,C=f.useMemo(()=>T?qs(T):null,[T]),P=l||!n?t.jsx("button",{onClick:w,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:_==="edit"?o("accent-bg"):"transparent",color:o(_==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?"切换到编辑模式":"切换到查看模式",children:_==="view"?"✏️ 编辑":"👁 查看"}):null,B=t.jsxs(t.Fragment,{children:[P,y]});return!T&&!C?t.jsx(jt,{}):_==="view"?t.jsx(fi,{data:T,transport:r,onNavigate:d?A=>d(A):void 0,renderLink:u,headerExtra:B,className:j,style:k}):C?t.jsxs("div",{className:j,style:k,children:[B&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:B}),t.jsx(Vs,{data:C,onChange:a||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:d,showDelete:!!c,onDelete:c,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:S,onRelationsChange:h})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},Ko=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ks=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,l]=f.useState(null),[a,p]=f.useState(""),[c,d]=f.useState(""),[u,g]=f.useState("idle"),[x,m]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{e&&(l(null),p(""),d(""),g("idle"),m(""))},[e]),f.useEffect(()=>{s&&setTimeout(()=>{var j;return(j=b.current)==null?void 0:j.focus()},100)},[s]),f.useEffect(()=>{if(u==="success"){const j=setTimeout(n,2e3);return()=>clearTimeout(j)}},[u,n]),f.useEffect(()=>{if(!e)return;const j=k=>{k.key==="Escape"&&n()};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[e,n]);const S=async()=>{if(!(!s||!a.trim())){g("submitting"),m("");try{await i({type:s,content:a.trim(),...c.trim()?{contact:c.trim()}:{}}),g("success")}catch(j){g("error"),m(j instanceof Error?j.message:"提交失败,请稍后重试")}}};if(!e)return null;const h=s&&a.trim()&&u!=="submitting",y=Ko.find(j=>j.value===s);return t.jsx("div",{style:qp,onClick:j=>{j.target===j.currentTarget&&n()},children:t.jsxs("div",{style:Kp,onClick:j=>j.stopPropagation(),children:[t.jsxs("div",{style:Jp,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:Zp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:nu,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:o("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Ko.map(j=>t.jsxs("button",{onClick:()=>l(j.value),style:{...Xp,...s===j.value?Qp:{}},children:[t.jsx("span",{children:j.icon})," ",j.label]},j.value))}),t.jsx("textarea",{ref:b,value:a,onChange:j=>p(j.target.value),placeholder:(y==null?void 0:y.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...eu,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:c,onChange:j=>d(j.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:ou}),t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[a.length," / 2000"]}),u==="error"&&t.jsx("div",{style:iu,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:S,disabled:!h,style:{...tu,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},qp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Kp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},Jp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Zp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:o("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Xp={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Qp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},eu={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},tu={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},nu={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},iu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginBottom:"12px"},ou={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},oi="--bim-feedback-fab-offset",ri=48,ru=16,su=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,a]=f.useState(!1),p=n.bottom??24;return f.useEffect(()=>{if(r||typeof document>"u")return;const c=document.documentElement;return c.style.setProperty(oi,`calc(${p+ri+ru}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(oi)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>a(!0),style:{...lu,zIndex:s??o("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(Ks,{isOpen:l,onClose:()=>a(!1),onSubmit:e,feedbackListUrl:i})]})},lu={position:"fixed",width:`${ri}px`,height:`${ri}px`,borderRadius:"50%",border:"none",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:o("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},Jo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Js=({onSubmit:e})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[l,a]=f.useState(""),[p,c]=f.useState("idle"),[d,u]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var S;return(S=g.current)==null?void 0:S.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){c("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),c("success"),s(""),a(""),i("bug")}catch(S){c("error"),u(S instanceof Error?S.message:"提交失败,请稍后重试")}}},m=n&&r.trim()&&p!=="submitting",b=Jo.find(S=>S.value===n);return p==="success"?t.jsx("div",{style:Zo,children:t.jsxs("div",{style:uu,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>c("idle"),style:xu,children:"继续提交"})]})}):t.jsxs("div",{style:Zo,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Jo.map(S=>t.jsxs("button",{onClick:()=>i(S.value),style:{...au,...n===S.value?cu:{}},children:[t.jsx("span",{children:S.icon})," ",S.label]},S.value))}),t.jsx("textarea",{ref:g,value:r,onChange:S=>s(S.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...du}}),t.jsx("input",{type:"text",value:l,onChange:S=>a(S.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:gu}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:x,disabled:!m,style:{...pu,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:fu,children:d})]})},Zo={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},au={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},cu={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},du={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},pu={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},uu={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},xu={background:"none",border:"none",color:o("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},fu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginTop:"8px"},gu={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function Xo(e){return typeof e=="function"?e():e??"/api/feedback"}const Zs=({resourceId:e,apiUrl:n})=>{const[i,r]=f.useState([]),[s,l]=f.useState(!0),a=f.useCallback(async()=>{const c=Xo(n);l(!0);try{const u=await(await fetch(`${c}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);f.useEffect(()=>{a()},[a]);const p=async c=>{const d=Xo(n),u=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...c,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const g=await u.json().catch(()=>null);throw new Error((g==null?void 0:g.error)||"提交失败")}setTimeout(()=>a(),500)};return t.jsxs("div",{children:[t.jsx(Pi,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Js,{onSubmit:p})})]})},Qo={part_of:"所屬",has_part:"包含",contains_text_of:"收錄",collected_in:"叢編",text_carried_by:"載錄",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"後繼",derived_from:"衍生",has_adaptation:"改編",related:"相關"};function er(e){return e?Qo[e]??e:Qo.related}const mu={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function hu(e){return mu[e]??e}const bu={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function yu(e){return bu[e]??""}function Oi({authors:e,onNavigate:n,renderLink:i}){const{convert:r}=q(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,a)=>{const p=ji(l.role);return t.jsxs(f.Fragment,{children:[a>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Be,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:i,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},a)})}):null}function Xs(e,n){var p,c;const i=bi(e,n),r=i.mirrors.map(d=>({key:d.key,label:d.label,description:d.description,rows:d.items.filter(u=>u.group_role!=="mirror"),mirrors:d.items.filter(u=>u.group_role==="mirror")})),s=i.buckets.filter(d=>d.key==="image"||d.key==="textImage").flatMap(d=>d.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=i.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((c=i.buckets.find(d=>d.key==="text"))==null?void 0:c.items)??[],groups:r}}function Qs(e,n){const i=(e.url?Nt(e.url):void 0)||e.name,r=Fr(e,n);return r?`${i}(${r})`:i}function Di({item:e,siblings:n,listedVolumeCounts:i}){const{convert:r}=q(),[s,l]=f.useState(!1),a=bn(e),p=!!a&&a.expected>0&&!(i!=null&&i.has(a.expected)),c=r(Qs(e,n)),d=Lt(e),u=Sn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var x,m;const g=(x=e.metadata)!=null&&x.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((m=e.metadata)==null?void 0:m.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("殘片")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:r(e.color_mode==="color"?"彩色":"黑白")})]}):null;return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[c," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),g]}):t.jsxs("span",{className:"bim-d-zt-name",children:[c,g]})})(),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(Si,{item:e})})]}),t.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(g=>!g),children:r(s?"收起分冊":`展開 ${a.expected} 冊`)})})]})}function el({groups:e,listedVolumeCounts:n}){const{convert:i}=q();return t.jsx(t.Fragment,{children:e.map(r=>t.jsxs("div",{className:"bim-d-rg",children:[r.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:i(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:i(r.description)}),r.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:r.rows.map((s,l)=>t.jsx(Di,{item:s,siblings:r.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),r.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[r.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:i("鏡像")}),r.mirrors.map((s,l)=>{const a=Lt(s),p=i(Qs(s,r.mirrors));return a?t.jsxs("a",{href:a,target:"_blank",rel:"noopener noreferrer",title:s.details?i(s.details):void 0,children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:p},l)})]})]},r.key))})}const Yt=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function si(e){var i;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(i=Yt.find(r=>n.startsWith(r.key[0])))==null?void 0:i.key}const tr=12,ju=60,tl=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:a,railLinks:p})=>{var ke,Ne,Ee;const c=ue(),{convert:d}=q(),u=f.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[g,x]=f.useState(new Map),[m,b]=f.useState(!1),[S,h]=f.useState(""),[y,j]=f.useState(!1),k=u.length<=ju,$=k||m||!!S||y,v=f.useMemo(()=>$?u:u.slice(0,tr),[u,$]);f.useEffect(()=>{if(!n||v.length===0)return;const O=v.filter(oe=>!g.has(oe));if(O.length===0)return;let ce=!1;return Promise.all(O.map(oe=>n.getItem(oe).then(he=>{const Z=he??{};return[oe,{id:oe,title:Z.title,edition:Z.edition,resources:Z.resources,publication_info:Z.publication_info,current_location:Z.current_location,lineage:Z.lineage,measure_info:Z.measure_info}]}).catch(()=>[oe,{id:oe}]))).then(oe=>{ce||x(he=>{const Z=new Map(he);for(const[F,I]of oe)Z.set(F,I);return Z})}),()=>{ce=!0}},[n,v,g]);const _=f.useMemo(()=>u.map(O=>g.get(O)??{id:O}),[u,g]),w=u.length>0&&u.every(O=>g.has(O)),z=!!n&&v.some(O=>!g.has(O)),N=k||$,T=f.useMemo(()=>Or(_,e.version_graph,{era:S,scanOnly:y,sort:N?"year":"default"}),[_,e.version_graph,S,y,N]),C=m?T.rows:T.rows.slice(0,tr),P=T.allRows.filter(O=>O.hasImage).length,B=e.related_works||[],A=B.filter(O=>O.relation==="collected_in"),W=f.useMemo(()=>{const O=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],ce=oe=>{const he=O.indexOf(oe??"");return he<0?O.length:he};return B.filter(oe=>oe.relation!=="collected_in").map((oe,he)=>({r:oe,i:he})).sort((oe,he)=>ce(oe.r.relation)-ce(he.r.relation)||oe.i-he.i).map(oe=>oe.r)},[B]),V=f.useMemo(()=>{const O=bi(e.resources,e.resource_groups);return[...O.mirrors.flatMap(ce=>ce.items.map(oe=>({r:oe,kind:d(ce.label)}))),...O.buckets.flatMap(ce=>ce.items.map(oe=>({r:oe,kind:d(yu(ce.key))})))]},[e.resources,e.resource_groups,d]),K=e.indexed_by||[],E=e.emendated_by||[],le=f.useMemo(()=>{var M,ne,R;const O=[],ce=(ne=(M=e.authors)==null?void 0:M[0])==null?void 0:ne.dynasty;ce&&O.push({label:"成書",value:d(ce)});const oe=at(e,c.unit.juan);if(oe){const J=(R=e.juan_count)==null?void 0:R.description;O.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[d(oe),J&&J!==oe?t.jsxs("span",{className:"bim-d-meta",children:["(",d(J),")"]}):null]})})}e.loss_status&&O.push({label:"存佚",value:d(hu(e.loss_status))});const he=T.allRows.filter(J=>J.sortYear!=null),Z=he.length>0?he.reduce((J,H)=>J.sortYear<=H.sortYear?J:H):null;Z!=null&&Z.era.era?O.push({label:"最早存世",value:d([Z.era.era,Z.era.reign].filter(Boolean).join(" ")),title:Z.era.source==="edition"?d("據版本題名推斷"):void 0}):z&&O.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),E.length&&O.push({label:"考證",value:`${E.length} ${d("條")}`});const F=nr(e.additional_titles);F.length&&O.push({label:"又名",value:F.map(d).join("、")});const I=nr(e.attached_texts);I.length&&O.push({label:"附載",value:I.map(d).join("、")});const D=(e.additional_works||[]).map(J=>d(J.book_title)+(J.n_juan!=null?` ${J.n_juan}${d(c.unit.juan)}`:""));return D.length&&O.push({label:"附錄",value:D.join("、")}),O},[e,d,c,z,T.allRows,E.length]),ae=[{value:e._edition_count??u.length,label:"版本"},{value:w?P:0,label:"有影印"},{value:K.length,label:"家著錄"}],pe=e.classification,ee=pe?[pe.l1,pe.l2,pe.l3,pe.l4].filter(Boolean).map(O=>d(O)):[],X=e.subtype?d(c.workSubtype[e.subtype]??e.subtype):"",ie=t.jsx(Xt,{title:d(e.title),byline:t.jsx(Oi,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(Me,{items:[...ee,pe!=null&&pe.source?d(`據《${pe.source.split("/")[0]}》`):"",X]}),description:(ke=e.description)!=null&&ke.text?t.jsxs(t.Fragment,{children:[t.jsx(lt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Ne=e.description.sources)!=null&&Ne.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(O=>d(rc(O))).filter(Boolean).join(" · ")}):null]}):void 0,stats:ae,facts:le,readAction:s,foot:t.jsx(Qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Ee=e.appendix)==null?void 0:Ee.map((O,ce)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(O.title)}),t.jsx(lt,{text:O.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},ce))}),me=T.eras.length>=2?[{key:"",label:c.catalog.all},...T.eras.map(O=>({key:O,label:`${O} ${T.allRows.filter(ce=>ce.era.era===O).length}`}))]:[],te=[];u.length&&te.push({id:"versions",label:"版本",count:u.length}),K.length&&te.push({id:"catalogs",label:"著錄",count:K.length}),A.length&&te.push({id:"collected",label:"收入叢編",count:A.length}),W.length&&te.push({id:"related",label:"相關書目",count:W.length}),V.length&&te.push({id:"resources",label:"在線資源",count:V.length});const se=u.length===0&&K.length===0,fe=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Fe,{id:"versions",title:"版本",meta:t.jsx(Me,{items:[d(`共 ${u.length} 種`),w&&P?d(`${P} 種有影印`):"",T.rows.length!==T.allRows.length?d(`當前 ${T.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&me.length===0&&u.length>1?"":void 0,children:[me.length>0&&t.jsx(_n,{items:me,value:S,onChange:O=>{h(O),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Qr,{label:"只看有影印",checked:y,onChange:O=>{j(O),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:d(N?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("版本")}),t.jsx("th",{children:d("年代")}),t.jsx("th",{children:d("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:d("影印")})})]})}),t.jsx("tbody",{children:C.map(O=>{var ce;return t.jsx(vu,{row:O,measure:(ce=g.get(O.id))==null?void 0:ce.measure_info,loaded:g.has(O.id),onNavigate:i,renderLink:r},`${O.id}:${g.has(O.id)?"r":"p"}`)})})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(S||y?"當前篩選下沒有版本":"暫無版本著錄")}),T.rows.length>C.length&&t.jsx(Bt,{label:`展開其餘 ${T.rows.length-C.length} 種版本`,onClick:()=>b(!0)}),T.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:d("部分年代據版本題名推斷,非著錄原文")})]}),K.length>0&&t.jsx(ku,{items:K,transport:n,onNavigate:i,renderLink:r}),se&&t.jsx(Fe,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),be=(O,ce)=>t.jsx(Be,{id:O,label:d(ce),onNavigate:i,renderLink:r,dense:!0}),ze=f.useMemo(()=>{const O=new Map;for(const ce of W){const oe=er(ce.relation);O.set(oe,(O.get(oe)??0)+1)}return O.size>1?[...O.entries()].sort((ce,oe)=>oe[1]-ce[1]).slice(0,4).map(([ce,oe])=>`${d(ce)} ${oe}`).join(" · "):void 0},[W,d]),ve=t.jsxs(t.Fragment,{children:[t.jsx(ht,{id:"collected",title:"收入叢編",items:A.map(O=>be(O.id,O.title))}),t.jsx(ht,{id:"related",title:"相關書目",meta:d(`${W.length} 部`),sub:ze,items:W.map(O=>t.jsxs(t.Fragment,{children:[be(O.id,O.title),t.jsx("span",{className:"bim-d-meta",title:O.note?d(O.note):void 0,children:d(er(O.relation))})]}))}),t.jsx(ht,{id:"resources",title:"在線資源",cap:6,items:V.map(({r:O,kind:ce})=>{const oe=d((O.url?Nt(O.url):void 0)||O.name),he=Lt(O);return t.jsxs(t.Fragment,{children:[he?t.jsxs("a",{href:he,target:"_blank",rel:"noopener noreferrer",children:[oe," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:oe}),ce&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:ce})]})})})]});return t.jsx(Zt,{railTop:l,back:a,nav:te,railLinks:p,main:fe,card:ie,side:ve})};function nr(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ir(e,n){return n((e.url?Nt(e.url):void 0)||e.name)}function vu({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=q(),a=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",c=e.holders[0],d=c?ir(c,l):e.locationName?l(e.locationName):"",u=e.images[0],g=u?Lt(u):void 0,x=e.images.map(m=>ir(m,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Be,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${a?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:a?l(a):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${d?"":" bim-d-zt-blank"}`,children:[d||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(g?t.jsx("a",{className:"bim-d-flag",href:g,target:"_blank",rel:"noopener noreferrer",title:x,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:x,children:l("有影印")}))})]})}function ku({items:e,transport:n,onNavigate:i,renderLink:r}){const s=ue(),{convert:l}=q(),[a,p]=f.useState(0),c=Math.min(a,e.length-1),d=e[c],[u,g]=f.useState(new Map);return f.useEffect(()=>{if(!n)return;const x=[...new Set(e.map(b=>b.source_bid).filter(b=>!!b))];if(x.length===0)return;let m=!1;return Promise.all(x.map(b=>n.getItem(b).then(S=>{var h,y;return[b,((y=(h=S==null?void 0:S.authors)==null?void 0:h[0])==null?void 0:y.dynasty)??""]}).catch(()=>[b,""]))).then(b=>{m||g(new Map(b.filter(([,S])=>S)))}),()=>{m=!0}},[n,e]),t.jsx(Fe,{id:"catalogs",title:"著錄",meta:t.jsx(Me,{items:[l(`歷代書目 ${e.length} 家`),l("按著錄順序")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":l("著錄書目"),children:e.map((x,m)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":m===c,"aria-label":l(x.source),onClick:()=>p(m),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(x.source_bid??"")?l(u.get(x.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...l(x.source)].slice(0,9).map((b,S)=>t.jsx("span",{children:b},S))})]})},m))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:l(d.title_info)}),t.jsx(Me,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?t.jsx(Be,{id:d.source_bid,label:l(d.source),onNavigate:i,renderLink:r,dense:!0}):l(d.source),d.section?l(d.section):"",d.author_info?`${l(s.label.authorInfo)} ${l(d.author_info)}`:"",d.edition?`${l(s.label.edition)} ${l(d.edition)}`:"",d.page??""]}),d.summary&&t.jsx("p",{className:"bim-d-quote",children:Ue(l(d.summary))}),d.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:Ue(l(d.comment))})]}),d.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:Ue(l(d.additional_comment))})]}),!d.summary&&!d.comment&&!d.additional_comment&&!d.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:l("僅著錄書名,無提要。")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?t.jsx("button",{type:"button","aria-label":l(`上一家:${e[c-1].source}`),onClick:()=>p(c-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",l(e[c-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",e.length]}),c<e.length-1?t.jsx("button",{type:"button","aria-label":l(`下一家:${e[c+1].source}`),onClick:()=>p(c+1),children:t.jsxs("span",{"aria-hidden":"true",children:[l(e[c+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function Su(e){var n;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((n=e.year_range)==null?void 0:n[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function wu(e,n){if(!e.lineage)return null;const i=e.lineage;return{id:e.id,kind:"book",label:e.title,year:i.year,year_text:i.year_text,year_uncertain:i.year_uncertain,category:i.category,status:i.status,extant_juan:i.extant_juan,group:n[e.id],note:i.note}}function or(e,n,i){return{id:`derive:${n.ref}->${e}:${i}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function _u(e,n,i){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${i}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function $u(e,n){var d;if(n==="all")return null;const i=(d=e.collections)==null?void 0:d[n],r=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,l=r||s||!!(i!=null&&i.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!i||!l)return null;const a=r?new Set(i.groups):null,p=new Set(i.book_ids??[]);if(a&&e.node_groups)for(const[u,g]of Object.entries(e.node_groups))a.has(g)&&p.add(u);let c=null;if(i.hypothetical_ids&&(c=new Set(i.hypothetical_ids)),a){c||(c=new Set);for(const u of e.hypothetical_nodes??[])u.group&&a.has(u.group)&&c.add(u.id)}return{books:p,hypos:c}}function xn(e,n,i){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const l=new Set(r.excluded_books??[]),a=r.node_groups??{},p=$u(r,i??r.default_collection??"all"),c=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,g=new Set,x=new Set;if(c){const $=new Map(n.map(T=>[T.id,T])),v=new Map((r.hypothetical_nodes??[]).map(T=>[T.id,T])),_=T=>{const C=$.get(T);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(B=>B.ref);const P=v.get(T);return P?(P.derived_from??[]).map(B=>B.ref):[]},w=T=>v.has(T)?!u||u.has(T):!d||d.has(T),z=new Set,N=T=>{if(!z.has(T)){z.add(T);for(const C of _(T))l.has(C)||(w(C)||(v.has(C)?x.add(C):$.has(C)&&g.add(C)),N(C))}};for(const T of n)d&&d.has(T.id)&&!l.has(T.id)&&N(T.id);for(const T of r.hypothetical_nodes??[])u&&u.has(T.id)&&N(T.id)}const m=n.filter($=>!l.has($.id)).filter($=>!d||d.has($.id)||g.has($.id)).map($=>{const v=wu($,a);return v&&g.has($.id)&&(v.bridge=!0),v}).filter($=>$!==null),b=(r.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||x.has($.id)).map($=>{const v=Su($);return x.has($.id)&&(v.bridge=!0),v}),S=[...m,...b],h=new Set(S.map($=>$.id)),y=new Set,j=[],k=$=>{y.has($.id)||!h.has($.source)||!h.has($.target)||(y.add($.id),j.push($))};for(const $ of n)l.has($.id)||!$.lineage||d&&!d.has($.id)&&!g.has($.id)||(($.lineage.derived_from??[]).forEach((v,_)=>{k(or($.id,v,_))}),($.lineage.related_to??[]).forEach((v,_)=>{k(_u($.id,v,_))}));for(const $ of r.hypothetical_nodes??[])u&&!u.has($.id)&&!x.has($.id)||($.derived_from??[]).forEach((v,_)=>{k(or($.id,v,_))});return{nodes:S,edges:j,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function nl(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function zu(e,n){const i=[],r=e.version_graph;if(!r)return i;const s=new Set(n.map(c=>c.id)),l=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),a=new Set([...s,...l]),p=(c,d)=>{a.has(d.ref)||i.push(`${c}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${c}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&i.push(`${c}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const d=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>p(d,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||i.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const d=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>p(d,u))}return i}const il=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:s}=q();if(!e.nodes.length)return t.jsx("div",{style:{...Ou,...r},className:i,children:"暂无版本图数据"});const l=new Map,a=new Map;for(const x of e.edges)if(x.kind==="derive"){const m=l.get(x.target)??[];m.push(x),l.set(x.target,m)}else for(const m of[x.source,x.target]){const b=a.get(m)??[];b.push(x),a.set(m,b)}const p=new Map(e.nodes.map(x=>[x.id,x])),c=new Map,d=[];for(const x of e.nodes)if(x.group){const m=c.get(x.group)??[];m.push(x),c.set(x.group,m)}else d.push(x);const u=(x,m)=>(x.year??9999)-(m.year??9999);c.forEach(x=>x.sort(u)),d.sort(u);const g=e.groups.filter(x=>c.has(x.id));return t.jsxs("div",{className:i,style:{...Iu,...r},children:[e.title&&t.jsx("div",{style:Tu,children:s(e.title)}),e.description&&t.jsx("div",{style:Eu,children:s(e.description)}),g.map(x=>t.jsx(rr,{label:x.label,color:x.color,nodes:c.get(x.id),incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n},x.id)),d.length>0&&t.jsx(rr,{label:"其他",nodes:d,incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n})]})},rr=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:a})=>{const{convert:p}=q();return t.jsxs("div",{style:Ru,children:[t.jsx("div",{style:{...Nu,borderLeftColor:n??o("widget-border")},children:p(e)}),i.map(c=>t.jsx(Cu,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:a},c.id))]})},Cu=({node:e,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",a=e.bridge,{convert:p}=q();return t.jsxs("div",{style:{...Lu,borderStyle:l||a?"dashed":"solid",opacity:a?.55:e.status==="lost"?.7:1,background:a?o("bg-subtle"):void 0},title:a?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:Bu,children:[t.jsx("span",{style:Au,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Wu,children:nl(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Mu,children:[e.category&&t.jsx(Ot,{children:p(e.category)}),e.status==="lost"&&t.jsx(Ot,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(Ot,{tone:"warn",children:"残本"}),l&&t.jsx(Ot,{tone:"info",children:"假想祖本"}),a&&t.jsx(Ot,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Fu,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:Pu,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:lr,children:[t.jsx("div",{style:ar,children:"来源:"}),n.map(c=>{const d=r.get(c.source);return t.jsxs("div",{style:cr(c.confidence),children:[t.jsx("span",{style:dr,children:p(c.relation)}),t.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,p(d.label)):p((d==null?void 0:d.label)??c.source)}),c.confidence!=="consensus"&&c.confidence!=="certain"&&t.jsx(sr,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:pr,children:["· ",p(c.evidence)]})]},c.id)})]}),i.length>0&&t.jsxs("div",{style:lr,children:[t.jsx("div",{style:ar,children:"关联:"}),i.map(c=>{const d=c.source===e.id?c.target:c.source,u=r.get(d);return t.jsxs("div",{style:cr(c.confidence),children:[t.jsx("span",{style:dr,children:p(c.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,p(u.label)):p((u==null?void 0:u.label)??d)}),t.jsx(sr,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:pr,children:["· ",p(c.evidence)]})]},c.id)})]})]})},Ot=({children:e,tone:n="default"})=>{const r={default:{bg:o("tag-bg"),fg:o("fg")},warn:{bg:o("warn-bg"),fg:o("warn-fg")},info:{bg:o("info-bg"),fg:o("info-fg")}}[n];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},sr=({level:e})=>{const i={certain:{label:"确定",color:o("confidence-certain")},consensus:{label:"共识",color:o("confidence-consensus")},probable:{label:"推测",color:o("confidence-probable")},disputed:{label:"有争议",color:o("confidence-disputed")}}[e];return i?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${i.color}`,color:i.color,borderRadius:"8px",marginLeft:"4px"},children:i.label}):null},Iu={fontSize:"14px",color:o("fg")},Tu={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Eu={fontSize:"13px",color:o("muted"),marginBottom:"16px",lineHeight:1.6},Ru={marginBottom:"16px"},Nu={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:o("fg")},Lu={border:`1px solid ${o("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:o("bg")},Bu={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Au={fontSize:"15px",fontWeight:600},Wu={fontSize:"12px",color:o("muted")},Mu={marginBottom:"6px"},Fu={fontSize:"12px",color:o("muted"),margin:"2px 0"},Pu={fontSize:"12px",color:o("muted"),fontStyle:"italic",margin:"4px 0"},lr={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${o("widget-border")}`},ar={fontSize:"11px",color:o("muted"),marginBottom:"2px"},cr=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),dr={display:"inline-block",padding:"0 6px",fontSize:"11px",background:o("tag-bg"),color:o("fg"),borderRadius:"3px",marginRight:"6px"},pr={fontSize:"11px",color:o("muted")},Ou={padding:"20px",textAlign:"center",color:o("muted"),fontSize:"13px"},ol=({selectedNodeId:e,...n})=>{const[i,r]=f.useState("loading"),[s,l]=f.useState(null);return f.useEffect(()=>{let a=!1;return Du().then(p=>{a||(p?(l(p),r("ready")):r("missing"))}),()=>{a=!0}},[]),i==="loading"?t.jsx("div",{style:ur,children:"加载图组件中…"}):i==="missing"||!s?t.jsxs("div",{style:ur,children:[t.jsxs("div",{children:["图组件未安装。请安装 ",t.jsx("code",{children:"@xyflow/react"})," 与 ",t.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),t.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",t.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):t.jsx(Hu,{modules:s,selectedNodeId:e,...n})};async function Du(){try{const[e,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let i=!1;try{await import("@xyflow/react/dist/style.css"),i=!0}catch{i=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:n,cssLoaded:i}}catch{return null}}const Hu=({graph:e,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:l,modules:a})=>{const{ReactFlow:p,Background:c,Controls:d,Handle:u,Position:g,BaseEdge:x,EdgeLabelRenderer:m,getSmoothStepPath:b,dagre:S}=a,h=f.useMemo(()=>({lineage:_=>{var V,K,E,le;const w=((V=_.data)==null?void 0:V.stepPosition)??.85,[z,N,T]=b({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:w,borderRadius:5}),C=!!((K=_.data)!=null&&K.isSibling),P=C?N:_.targetX-18,B=C?T:_.targetY-12,A=(E=_.data)==null?void 0:E.labelStyle,W=(le=_.data)==null?void 0:le.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(x,{id:_.id,path:z,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&t.jsx(m,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${P}px,${B}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:o("bg"),border:`0.5px solid ${o("widget-border")}`,...W,...A},children:_.label})})]})}}),[x,m,b]),y=f.useMemo(()=>({version:_=>{const w=_.data,z=w.kind==="hypothetical",N=w.status==="lost",T=w.isSelected,C=w.bridge,P=w.borderColor??o("muted"),B=C||z?"dashed":"solid",A=C?.5:N?.6:1;return t.jsxs("div",{style:{background:o(C?"bg-subtle":"bg"),border:`2px ${B} ${T?o("primary"):P}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:A,boxShadow:T?o("shadow-node-selected"):z||C?"none":o("shadow-node")},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:g.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!w.renderLink?w.label:w.renderLink(w.bookId,w.label)}),w.description&&t.jsx("div",{style:{fontSize:10,color:o("aux-fg"),lineHeight:1.25,marginTop:1},children:w.description}),w.yearText&&t.jsx("div",{style:{fontSize:10,color:o("aux-fg"),lineHeight:1.2},children:nl(w.yearText,void 0,w.uncertain)}),N&&t.jsx("div",{style:{fontSize:9,color:o("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:g.Right,style:{visibility:"hidden"}})]})}}),[u,g]),{convert:j}=q(),{rfNodes:k,rfEdges:$}=f.useMemo(()=>Gu(e,S,n,l,j),[e,S,n,l,j]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:t.jsxs(p,{nodes:k,edges:$,nodeTypes:y,edgeTypes:h,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(d,{showInteractive:!1})]})})};function Gu(e,n,i,r,s=l=>l??""){const p=e.layout==="LR"||!e.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:p?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const d=new Map(e.groups.map(y=>[y.id,y.color??o("muted")]));for(const y of e.nodes)c.setNode(y.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const y of e.edges)y.kind==="derive"&&(u.has(y.relation)||c.setEdge(y.source,y.target));n.layout(c);const g=e.nodes.map(y=>{const j=c.node(y.id),k=r?y.id===r:void 0,$={kind:y.kind,label:s(y.label),bookId:y.kind==="book"?y.id:void 0,yearText:s(y.year_text??Vu(y)),uncertain:y.year_uncertain,category:y.category,status:y.status,borderColor:y.group?d.get(y.group):void 0,renderLink:i,isSelected:k,description:s(y.description),bridge:y.bridge};return{id:y.id,type:"version",position:{x:j.x-160/2,y:j.y-90/2},data:$,draggable:!1,selected:k}}),x=.78,m=.06,b=new Map;for(const y of e.edges)y.kind==="derive"&&(b.has(y.source)||b.set(y.source,[]),b.get(y.source).push(y));const S=new Map;for(const[y,j]of b){if(j.length<=1)continue;const k=[...j].sort((v,_)=>{var N,T;const w=((N=c.node(v.target))==null?void 0:N.y)??0,z=((T=c.node(_.target))==null?void 0:T.y)??0;return w-z}),$=k.length;k.forEach((v,_)=>{const w=(_-($-1)/2)*m;S.set(v.id,x+w)})}const h=e.edges.map(y=>Uu(y,S.get(y.id),s));return{rfNodes:g,rfEdges:h}}function Uu(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Yu(e.confidence),a={type:"arrowclosed",color:l,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:i(e.relation),data:{labelStyle:{color:o("fg")},isSibling:s,stepPosition:n},style:{stroke:l,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:a,markerStart:s?a:void 0,zIndex:1e3}}function Vu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Yu(e){switch(e){case"certain":return o("confidence-certain");case"consensus":return o("lineage-edge-consensus");case"probable":return o("confidence-probable");case"disputed":return o("confidence-disputed");default:return o("muted")}}const ur={padding:"40px 20px",textAlign:"center",color:o("muted"),fontSize:"13px",border:`1px dashed ${o("widget-border")}`,borderRadius:8,background:o("bg")},Hi=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:a,onCollectionChange:p,collectionsAvailable:c,collectionCounts:d,className:u,style:g})=>{var j;const[x,m]=f.useState(n),b=k=>{m(k),l==null||l(k)},S=(()=>{if(!c)return[];const k=Object.entries(c);return k.length===0||c.all?k:[...k,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),h=!!(p&&S.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:o("muted"),textAlign:"center"},children:"暂无版本传承数据"});const y=a?(j=c==null?void 0:c[a])==null?void 0:j.description:void 0;return t.jsxs("div",{className:u,style:g,children:[t.jsxs("div",{style:qu,children:[t.jsx("button",{onClick:()=>b("list"),style:Fn(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:Fn(x==="graph"),children:"关系图"}),h&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:o("muted"),marginRight:4},children:"集合:"}),S.map(([k,$])=>{const v=d==null?void 0:d[k];return t.jsxs("button",{onClick:()=>p==null?void 0:p(k),style:Fn(a===k),title:$.description,children:[$.label,v!=null?` ${v}`:""]},k)})]})]}),h&&y&&t.jsx("div",{style:{fontSize:12,color:o("muted"),marginBottom:8,padding:"4px 8px",background:o("bg-subtle"),borderRadius:4},children:y}),x==="list"?t.jsx(il,{graph:e,renderLink:i}):t.jsx(ol,{graph:e,renderLink:i,height:r,selectedNodeId:s})]})},qu={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Fn=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${o("widget-border")}`,borderRadius:4,background:e?o("primary"):"transparent",color:o(e?"primary-fg":"fg"),cursor:"pointer"}),xr=40,fr=2,Ku=9,gr={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function Pn(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const rl=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,fullText:l,fullTextPending:a,chapterLink:p,railTop:c,back:d,railLinks:u})=>{var M,ne,R,J,H,U,re,Se,ye,Le,Ye;const g=ue(),{convert:x}=q(),[m,b]=f.useState(null),[S,h]=f.useState(new Map),[y,j]=f.useState([]),[k,$]=f.useState(new Map),[v,_]=f.useState(!1),[w,z]=f.useState("flow"),[N,T]=f.useState(null);f.useEffect(()=>{if(!n||!e.work_id){b(null);return}let L=!1;return n.getItem(e.work_id).then(de=>{!L&&de&&de.type==="work"&&b(de)}).catch(()=>{}),()=>{L=!0}},[n,e.work_id]),f.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){T(null);return}let L=!1;return n.getLineageGraph(e.work_id).then(de=>{L||T(de&&de.nodes.length>1?de:null)}).catch(()=>{L||T(null)}),()=>{L=!0}},[n,e.work_id]),f.useEffect(()=>{const L=e.contained_in||[];if(!n||L.length===0){h(new Map);return}let de=!1;return Promise.all(L.map(ge=>{const $e=typeof ge=="string"?ge:ge.id;return n.getItem($e).then(xe=>[$e,xe]).catch(()=>[$e,null])})).then(ge=>{if(de)return;const $e=new Map;for(const[xe,Ce]of ge)Ce&&$e.set(xe,Ce);h($e)}),()=>{de=!0}},[n,e.contained_in]);const C=f.useMemo(()=>{const L=new Set([...(m==null?void 0:m.books)||[],...e.related_books||[]]);return L.add(e.id),[...L]},[m==null?void 0:m.books,e.related_books,e.id]),P=C.length-1;f.useEffect(()=>{if(!n||P<=0){j([]);return}const L=C.length<=xr,de=L?C:C.slice(0,8);let ge=!1;return Promise.all(de.map($e=>$e===e.id?Promise.resolve({id:$e,title:e.title,edition:e.edition,year:gn(e)}):n.getItem($e).then(xe=>{const Ce=xe??{};return{id:$e,title:Ce.title,edition:Ce.edition,year:xe?gn(Ce):void 0}}).catch(()=>({id:$e})))).then($e=>{if(ge)return;const xe=$e.filter(Ce=>Ce.id===e.id||Ce.title||Ce.edition);L&&xe.sort((Ce,Oe)=>(Ce.year??1/0)-(Oe.year??1/0)),j(xe)}),()=>{ge=!0}},[n,C,P,e]);const B=e.lineage,A=f.useMemo(()=>[...((B==null?void 0:B.derived_from)||[]).filter(L=>L.ref_type==="book").map(L=>L.ref),...((B==null?void 0:B.related_to)||[]).map(L=>L.book_id)].filter(Boolean),[B]);f.useEffect(()=>{if(!n||A.length===0){$(new Map);return}let L=!1;return Promise.all(A.map(de=>n.getItem(de).then(ge=>[de,{id:de,title:ge==null?void 0:ge.title,edition:ge==null?void 0:ge.edition}]).catch(()=>[de,{id:de}]))).then(de=>{L||$(new Map(de))}),()=>{L=!0}},[n,A]);const W=f.useMemo(()=>Xs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),V=W.groups.reduce((L,de)=>L+de.rows.length+de.mirrors.length,0),K=W.groups.length>0&&W.groups.every(L=>L.key==="_physical"),E=Jt(e),le=Vr(e),G=at(e,g.unit.juan),ae=new Set((e.contained_in||[]).map(L=>typeof L=="string"?0:Ut(L.volume_index).length).filter(L=>L>0)),pe=L=>{var $e;const de=($e=e.base_edition)==null?void 0:$e.find(xe=>xe.book_id===L&&xe.name);if(de!=null&&de.name)return de.name;const ge=k.get(L);return(ge==null?void 0:ge.edition)||(ge==null?void 0:ge.title)||""},ee=f.useMemo(()=>{var ct,nn,dt,on,rn;const L=[];le&&L.push({label:"版本類型",value:x(le),title:e.edition_type||(ct=e.lineage)!=null&&ct.category?void 0:x("據版本題名推斷")}),(nn=e.publication_info)!=null&&nn.details?L.push({label:"刊印",value:x(e.publication_info.details)}):(E.era||E.reign)&&L.push({label:"刊寫年代",value:x([E.era,E.reign].filter(Boolean).join(" ")),title:E.source==="edition"?x("據版本題名推斷"):void 0}),G&&L.push({label:"卷帙",value:x(G)});const de=(e.contained_in||[]).flatMap(_e=>typeof _e=="string"?[]:Ut(_e.volume_index));de.length&&L.push({label:"冊次",value:x(`第 ${wn(de,g.unit.volume)} ${g.unit.volume}(${de.length} ${g.unit.volume})`)});const ge=(((dt=e.lineage)==null?void 0:dt.derived_from)||[]).find(_e=>_e.relation==="底本"&&_e.ref_type==="book");ge&&pe(ge.ref)&&L.push({label:"底本",value:t.jsx(Be,{id:ge.ref,label:x(pe(ge.ref)),onNavigate:i,renderLink:r,dense:!0})});const $e=(e.base_edition||[]).filter(_e=>_e&&_e.name);for(const _e of["底本","配補","參校"]){if(_e==="底本"&&ge&&pe(ge.ref))continue;const Ze=$e.filter(Re=>Re.role===_e);Ze.length&&L.push({label:_e,value:Ze.map((Re,kt)=>t.jsxs(f.Fragment,{children:[kt>0&&"、",Re.book_id?t.jsx(Be,{id:Re.book_id,label:x(Re.name),onNavigate:i,renderLink:r,dense:!0}):x(Re.name)]},kt))})}const xe=(e.provenance||[]).filter(_e=>_e&&_e.institution),Ce=(e.resources||[]).filter(_e=>(_e.types||(_e.type?[_e.type]:[])).includes("physical"));if(xe.length){L.push({label:"存藏",value:xe.slice(0,2).map(Re=>x(Re.institution)).join("、")+(xe.length>2?x(` 等 ${xe.length} 處`):"")});const _e=xe.filter(Re=>Re.call_number).slice(0,2).map(Re=>`${x(Re.institution)} ${Re.call_number}`);_e.length&&L.push({label:"索書號",value:_e.join(";")+(xe.filter(Re=>Re.call_number).length>2?"…":"")});const Ze=xe.flatMap(Re=>Re.seals||[]).filter(Boolean);Ze.length&&L.push({label:"藏印",value:x(Ze.join("、"))})}else Ce.length?L.push({label:"存藏",value:Ce.slice(0,2).map(_e=>x(_e.name)).join("、")+(Ce.length>2?x(` 等 ${Ce.length} 處`):"")}):(on=e.current_location)!=null&&on.name&&L.push({label:"存藏",value:x(e.current_location.name)});const Oe=e.physical_description;if(Oe){const _e=[["行款",Oe.leaf_style],["裝幀",Oe.binding],["尺寸",Oe.dimensions],["品相",Oe.condition]];for(const[Ze,Re]of _e)Re&&Re.trim()&&L.push({label:Ze,value:x(Re)})}(rn=e.page_count)!=null&&rn.description&&L.push({label:g.label.pageCount,value:x(e.page_count.description)});const Je=[...Xn(e.additional_titles),...Xn(e.attached_texts)];return Je.length&&L.push({label:"又名",value:Je.map(x).join("、")}),L},[e,x,g,E,le,G,k,i,r]),X=x(e.title),ie=e.edition?x(e.edition):void 0,me=((M=e.lineage)==null?void 0:M.year_text)||"",te=t.jsx(Xt,{kind:"版本",title:X,subtitle:ie,byline:t.jsx(Oi,{authors:e.authors??(m==null?void 0:m.authors),onNavigate:i,renderLink:r}),meta:(()=>{const L=[le?x(le):"",E.era?x([E.era,E.reign].filter(Boolean).join("")):"",G?x(G):""].filter(Boolean);return L.length?t.jsx("span",{className:"bim-d-tags",children:L.map((de,ge)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ge,2)}`,children:de},ge))}):null})(),description:(ne=e.description)!=null&&ne.text?t.jsx(lt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:vi((R=e.description)==null?void 0:R.text)?6:void 0,facts:ee,readAction:s,secondaryAction:s&&V>0&&!K?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(Qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),se=e.contained_in||[],fe=(l==null?void 0:l.chapters)||[],be=fe[0]&&Pn(fe[0].title)[0].slice(-1)||"章",ze=!!((J=B==null?void 0:B.derived_from)!=null&&J.length||(H=B==null?void 0:B.related_to)!=null&&H.length||(U=e.appendix)!=null&&U.length),ve=[];(fe.length||W.text.length||a)&&ve.push({id:"fulltext",label:"全文",count:fe.length?x(`${fe.length} ${be}`):void 0}),W.groups.length&&ve.push({id:"images",label:K?"館藏":"影印",count:V}),ze&&ve.push({id:"lineage",label:"版本源流"}),se.length&&ve.push({id:"collections",label:"收入叢編",count:se.length}),(re=e.location_history)!=null&&re.length&&ve.push({id:"provenance",label:"流轉歷史"});const ke=L=>(p==null?void 0:p(L))??null,Ne=fe[0],Ee=Ne?ke(Ne.file):null,O=v?fe:fe.slice(0,Ku),ce=(L,de,ge)=>L?t.jsx("a",{className:ge,href:L.href??"#",onClick:L.onClick?$e=>{$e.metaKey||$e.ctrlKey||($e.preventDefault(),L.onClick())}:void 0,children:de}):t.jsx("span",{className:ge,children:de}),oe=t.jsxs(t.Fragment,{children:[(fe.length>0||W.text.length>0||a)&&t.jsxs(Fe,{id:"fulltext",title:"全文",meta:fe.length>0?t.jsx(Me,{items:[x(`${fe.length} ${be}`),(Se=l==null?void 0:l.source)!=null&&Se.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[a&&!Ne&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),Ne&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${Pn(Ne.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((Ne.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),ce(Ee,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),fe.length>1&&t.jsx("ul",{className:"bim-d-chap",children:O.map(L=>{const[de,ge]=Pn(L.title);return t.jsx("li",{children:ce(ke(L.file),t.jsxs(t.Fragment,{children:[de&&t.jsx("b",{children:x(de)}),x(ge||L.file)]}))},L.file)})}),fe.length>O.length&&t.jsx(Bt,{label:`展開其餘 ${fe.length-O.length} ${be}`,onClick:()=>_(!0)}),W.text.length>0&&t.jsxs(t.Fragment,{children:[(fe.length>0||a)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:W.text.map((L,de)=>t.jsx(Di,{item:L,siblings:W.text,listedVolumeCounts:ae},`${L.id||L.url||L.name}-${de}`))})})]})]}),W.groups.length>0&&t.jsx(Fe,{id:"images",title:K?"館藏":"影印",meta:t.jsx(Me,{items:[W.groups.length>1?x(`${W.groups.length} 組`):"",x(`${V} 處`)]}),children:t.jsx(el,{groups:W.groups,listedVolumeCounts:ae})}),ze&&t.jsx(Fe,{id:"lineage",title:"版本源流",meta:(ye=B==null?void 0:B.derived_from)!=null&&ye.length?x("據版本傳承著錄"):void 0,action:N?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":x("源流視圖"),children:[t.jsx("button",{type:"button","aria-pressed":w==="flow",onClick:()=>z("flow"),children:x("卡片")}),t.jsx("button",{type:"button","aria-pressed":w==="graph",onClick:()=>z("graph"),children:x("關係圖")})]}):void 0,children:w==="graph"&&N?t.jsx(Hi,{graph:N,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(L,de)=>t.jsx(Be,{id:L,label:x(de),onNavigate:i,renderLink:r,dense:!0})}):t.jsx(Zu,{data:e,heading:ie||X,yearText:me,refName:pe,onNavigate:i,renderLink:r})}),se.length>0&&t.jsx(Fe,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:se.map((L,de)=>{var Oe,Je;const ge=typeof L=="string"?L:L.id,$e=typeof L=="string"?[]:Ut(L.volume_index),xe=S.get(ge),Ce=(xe==null?void 0:xe._member_count)||((Oe=xe==null?void 0:xe.books)==null?void 0:Oe.length)||((Je=xe==null?void 0:xe.contained_works)==null?void 0:Je.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Be,{id:ge,label:xe?x(xe.title):ge,onNavigate:i,renderLink:r,dense:!0}),$e.length>0&&t.jsx(Ju,{volumes:$e,unit:g.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Ce?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Ce>0&&x(`全 ${Ce} ${g.unit.bu}`)})]},`${ge}-${de}`)})})})}),(Le=e.location_history)!=null&&Le.length?t.jsx(Fe,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((L,de)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(L.name)}),([L.start_date,L.end_date].filter(Boolean).join("—")||L.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(Me,{items:[[L.start_date,L.end_date].filter(Boolean).join("—"),L.description?x(L.description):""]})})]},de))})}):null,ve.length===0&&t.jsx(Fe,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),he=y.findIndex(L=>L.id===e.id),Z=C.length<=xr,F=Z&&he>=0?y.slice(Math.max(0,he-fr),he+fr+1):y.filter(L=>L.id!==e.id),I=t.jsxs(t.Fragment,{children:[m&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:x(g.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Be,{id:m.id,label:x(m.title),onNavigate:i,renderLink:r})}),t.jsx(Me,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(m.authors||[]).slice(0,2).map(L=>`${L.dynasty?`〔${x(L.dynasty)}〕`:""}${x(L.name)}`),x(at(m,g.unit.juan)),m._edition_count?x(`${m._edition_count} 種版本`):""]}),((Ye=m.description)==null?void 0:Ye.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:x(m.description.text.replace(/[#*_>`[\]]/g,""))})]}),P>0&&F.length>0&&t.jsxs("div",{children:[t.jsx(ht,{id:"siblings",timeline:!0,title:Z?"同作品版本":g.relation.siblingVersions,meta:x(Z?"按年代":`${P} 種`),cap:F.length,items:F.map(L=>L.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(L.edition||L.title||L.id)}):t.jsx(Be,{id:L.id,label:x(L.edition||L.title||L.id),onNavigate:i,renderLink:r,dense:!0})),metas:F.map(L=>[L.year!=null?L.year<0?`前${-L.year}`:String(L.year):"",L.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:F.findIndex(L=>L.id===e.id)}),m&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Be,{id:m.id,label:x(`在作品頁看全部 ${C.length} 種 →`),onNavigate:i,renderLink:r,dense:!0})})]})]}),D=e.work_id?t.jsx(Xr,{caption:g.section.belongsToWork,children:t.jsx(Be,{id:e.work_id,label:m?x(m.title):" ",onNavigate:i,renderLink:r,dense:!0})}):void 0;return t.jsx(Zt,{railTop:c,back:d,up:D,nav:ve,railLinks:u,main:oe,card:te,side:I})};function Ju({volumes:e,unit:n}){const{convert:i}=q();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${wn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}function Zu({data:e,heading:n,yearText:i,refName:r,onNavigate:s,renderLink:l}){var h;const{convert:a}=q(),p=e.lineage,c=(p==null?void 0:p.derived_from)||[],d=c.filter(y=>y.ref_type!=="book"),u=c.filter(y=>y.ref_type==="book"&&y.relation==="底本"),g=c.filter(y=>y.ref_type==="book"&&y.relation!=="底本"),x=(p==null?void 0:p.related_to)||[],m=c.length>0||x.length>0,b=y=>y&&gr[y]?a(`(${gr[y]})`):"",S=(y,j)=>t.jsx(Be,{id:y,label:a(j||y),onNavigate:s,renderLink:l,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[m&&t.jsxs("ol",{className:"bim-d-lf-list",children:[d.map((y,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(y.relation||"祖本")}),t.jsx("span",{className:"bim-d-lf-name",children:a("擬構祖本")}),y.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[a(y.evidence),b(y.confidence)]})]})},`a-${j}`)),u.map((y,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(y.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:S(y.ref,r(y.ref))}),y.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[a(y.evidence),b(y.confidence)]})]})},`b-${j}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a("本版")}),t.jsx("span",{className:"bim-d-lf-name",children:n}),i&&t.jsx("span",{className:"bim-d-lf-yr",children:a(i)})]}),g.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:g.map((y,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(y.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:S(y.ref,r(y.ref))}),y.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[a(y.evidence),b(y.confidence)]})]},j))})]}),x.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:a("翻刻 · 衍生")}),t.jsx("span",{className:"bim-d-lf-chips",children:x.map((y,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:y.evidence?a(y.evidence):void 0,children:[S(y.book_id,r(y.book_id)),t.jsx("span",{className:"bim-d-meta",children:a(y.relation)})]},j))})]})]}),(h=e.appendix)==null?void 0:h.map((y,j)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:a("附記")})," ",a(y.title)]}),t.jsx(lt,{text:y.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${j}`)),(p==null?void 0:p.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:a(p.note)})]})}const Dt=16,Xu=200,Qu=16,sl=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,railTop:a,back:p,railLinks:c})=>{var he,Z,F,I,D,M,ne;const d=ue(),{convert:u}=q(),[g,x]=f.useState(""),[m,b]=f.useState(!1),[S,h]=f.useState(null),[y,j]=f.useState(""),[k,$]=f.useState(!1),v=f.useMemo(()=>Gr(e,n),[e,n]),[_,w]=f.useState(new Map),z=!!i&&v.rows.length>0&&v.rows.length<=Xu,N=z&&(v.rows.length<=Dt||k),T=N&&v.rows.every(R=>!R.id||_.has(R.id)),C=R=>{var J;return si(R?(J=_.get(R))==null?void 0:J.l1:void 0)},P=f.useMemo(()=>{const R=g.trim(),J=R?u(R):"";return v.rows.filter(H=>{var re,Se;if(y&&si(H.id?(re=_.get(H.id))==null?void 0:re.l1:void 0)!==y)return!1;if(!J)return!0;const U=H.id&&((Se=_.get(H.id))==null?void 0:Se.title)||H.title;return u(U).includes(J)||(H.subItems||[]).some(ye=>u(ye).includes(J))})},[v.rows,g,y,_,u]),B=m?P:P.slice(0,Dt),A=f.useMemo(()=>(N?v.rows:B).filter(R=>R.id&&!_.has(R.id)).map(R=>R.id),[N,v.rows,B,_]);f.useEffect(()=>{if(!i||A.length===0)return;let R=!1;const J=A.slice(0,Qu);return Promise.all(J.map(H=>i.getItem(H).then(U=>{var ye,Le;const re=U??{},Se={title:re.title,edition:re.edition,authors:re.authors,measure:U?at(U,d.unit.juan):void 0,versionCount:re._edition_count??((ye=re.books)==null?void 0:ye.length),l1:((Le=re.classification)==null?void 0:Le.l1)||void 0};return[H,Se]}).catch(()=>[H,{}]))).then(H=>{R||w(U=>{const re=new Map(U);for(const[Se,ye]of H)re.set(Se,ye);return re})}),()=>{R=!0}},[i,A,d.unit.juan]);const W=(e.contained_in||[])[0];f.useEffect(()=>{if(!W){h(null);return}if(h({id:W}),!i)return;let R=!1;return i.getItem(W).then(J=>{R||h({id:W,title:J==null?void 0:J.title})}).catch(()=>{}),()=>{R=!0}},[i,W]);const V=f.useMemo(()=>Xs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),K=V.text.length+V.groups.reduce((R,J)=>R+J.rows.length+J.mirrors.length,0),E=e.contained_works||[],le=new Set(v.rows.map(R=>R.id).filter(Boolean)),G=E.length>0&&!E.every(R=>le.has(R.id)),ae=(()=>{const R=v.rows.map(J=>J.edition).filter(Boolean);return R.length>1&&new Set(R).size===1})(),pe=v.rows.some(R=>R.volumes.length>0||R.expected!=null),ee=e._member_count||((he=e.books)==null?void 0:he.length)||E.length,X=at(e,d.unit.juan),ie=e.count,me=R=>typeof R=="number"&&Number.isFinite(R)?R:null,te=me(ie==null?void 0:ie.juan)??me((Z=e.juan_count)==null?void 0:Z.number),se=me(ie==null?void 0:ie.ce)??(v.totalVolumes||null),fe=[{value:v.rows.length,label:"子目"},{value:te??0,label:d.unit.juan},{value:se??0,label:d.unit.volume}],be=f.useMemo(()=>{var H,U;const R=[];if((H=e.publication_info)!=null&&H.details&&R.push({label:"刊印",value:u(e.publication_info.details)}),ee&&ee!==v.rows.length){const re=e._member_type==="Book"?"所收版本":e._member_type==="Work"?"所收作品":"成員";R.push({label:u(re),value:`${ee} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")})}const J=[me(ie==null?void 0:ie.zhong)!=null?`${ie.zhong} 種`:"",me(ie==null?void 0:ie.han)!=null?`${ie.han} 函`:""].filter(Boolean);return J.length&&R.push({label:"應收",value:u(J.join(" "))}),te==null&&X&&R.push({label:"卷帙",value:u(X),title:(U=e.juan_count)!=null&&U.description?u(e.juan_count.description):void 0}),R},[e,ee,v.rows.length,te,X,ie,u,d]),ze=f.useMemo(()=>{if(!T)return[];const R=new Map;for(const H of v.rows){const U=C(H.id);U&&R.set(U,(R.get(U)??0)+1)}const J=Yt.filter(H=>(R.get(H.key)??0)>0);return J.length<2?[]:[{key:"",label:`${d.catalog.all} ${v.rows.length}`},...J.map(H=>({key:H.key,label:`${H.label} ${R.get(H.key)}`}))]},[T,v.rows,_,d]),ve=f.useMemo(()=>{if(!T||!v.rows.some(U=>U.volumes.length>0))return null;const R=[],J=v.rows.filter(U=>U.volumes.length>0).map(U=>({k:C(U.id)??"",from:Math.min(...U.volumes),to:Math.max(...U.volumes)})).sort((U,re)=>U.from-re.from);for(const U of J){const re=U.to-U.from+1,Se=R[R.length-1];Se&&Se.key===U.k?(Se.to=Math.max(Se.to,U.to),Se.n+=re):R.push({key:U.k,from:U.from,to:U.to,n:re})}const H=J.reduce((U,re)=>Math.max(U,re.to),0);return R.length>1&&R.some(U=>U.key)?{segs:R,last:H}:null},[T,v.rows,_]),ke=(F=e.description)==null?void 0:F.text,Ne=t.jsx(Xt,{kind:"叢編",title:u(e.title),byline:t.jsx(Oi,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Me,{items:[e.subtype==="work_collection"?u("作品集"):"",(I=e.publication_info)!=null&&I.year?u(e.publication_info.year):""]}),description:ke||(D=e.history)!=null&&D.length?t.jsxs(t.Fragment,{children:[ke&&t.jsx(lt,{text:ke,style:{fontSize:15,lineHeight:1.85}}),(M=e.history)!=null&&M.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((R,J)=>t.jsx("li",{children:u(R)},J))}):null]}):void 0,clampDescription:vi(ke)||(((ne=e.history)==null?void 0:ne.length)??0)>2?6:void 0,stats:fe,facts:be,foot:t.jsx(Qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ve&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:u("全帙冊次分佈")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":u("全帙冊次分佈"),children:ve.segs.map((R,J)=>{const H=Yt.find(U=>U.key===R.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!H,title:H?u(`${H.label} 第 ${R.from}–${R.to} 冊`):void 0,"aria-label":u(H?`只看${H.label}`:"未分類"),"aria-pressed":!!H&&y===R.key,style:{flexGrow:R.n,background:o(H?H.token:"rule")},onClick:()=>{H&&(j(y===R.key?"":R.key),b(!1))}},J)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:u(`第 1 ${d.unit.volume}`)}),t.jsx("span",{children:u("點色段篩選部類")}),t.jsx("span",{children:u(`第 ${ve.last} ${d.unit.volume}`)})]})]})}),Ee=[];v.rows.length&&Ee.push({id:"titles",label:"子目",count:v.rows.length}),K&&Ee.push({id:"resources",label:"影印與全文",count:K}),G&&Ee.push({id:"works",label:d.section.containedWorks,count:E.length});const O=t.jsxs(t.Fragment,{children:[v.rows.length>0&&t.jsxs(Fe,{id:"titles",title:"子目",meta:t.jsx(Me,{items:[u(`${v.rows.length} ${d.unit.items}`),v.totalVolumes?u(`全帙 ${v.totalVolumes} ${d.unit.volume}`):"",P.length!==v.rows.length?u(`當前 ${P.length} ${d.unit.items}`):""]}),action:l,children:[(v.rows.length>Dt||ze.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ze.length>0&&t.jsx(_n,{items:ze,value:y,onChange:R=>{j(R),b(!1)}}),z&&v.rows.length>Dt&&!T&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:k,onClick:()=>$(!0),title:u(`將載入全部 ${v.rows.length} ${d.unit.items}`),children:u(k?"正在按部類分組…":"按部類分組")}),t.jsx("span",{className:"bim-d-spacer"}),v.rows.length>Dt&&t.jsx("input",{type:"search",className:"bim-d-find",value:g,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:R=>{x(R.target.value),b(!1)}})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[pe&&t.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),t.jsx("th",{children:u("書名")}),t.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),t.jsx("tbody",{children:B.map((R,J)=>{var Ye;const H=R.id?_.get(R.id):void 0,U=H!=null&&H.title&&R.title===R.id?H.title:R.title,re=((H==null?void 0:H.authors)||[]).find(L=>L&&L.name),Se=[re?`${re.dynasty?`〔${u(re.dynasty)}〕`:""}${u(re.name)}${re.role?` ${u(re.role)}`:""}`:"",H!=null&&H.measure?u(H.measure):"",(Ye=R.subItems)!=null&&Ye.length?R.subItems.map(L=>u(L)).join("、"):"",(H!=null&&H.edition||R.edition)&&!ae?u((H==null?void 0:H.edition)||R.edition||""):""].filter(Boolean),ye=Yt.find(L=>L.key===C(R.id)),Le=R.volumes.length>0?u(`第 ${wn(R.volumes,d.unit.volume)} ${d.unit.volume}`):R.expected!=null?u(`${R.found??0}/${R.expected} ${d.unit.volume}`):"";return t.jsxs("tr",{children:[pe&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Le?"":" bim-d-zt-blank"}`,children:[ye&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:o(ye.token)}}),Le||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[R.id?t.jsx(Be,{id:R.id,label:u(U),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(U)}),Se.length>0?t.jsx(Me,{items:Se}):R.id&&!H&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${H!=null&&H.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:H!=null&&H.versionCount?u(`${H.versionCount} 種`):""})]},`${R.id??R.title}-${J}`)})})]}),B.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),P.length>B.length&&t.jsx(Bt,{label:`展開其餘 ${P.length-B.length} ${d.unit.items}`,onClick:()=>b(!0)})]}),K>0&&t.jsxs(Fe,{id:"resources",title:"影印與全文",meta:u(`${K} 處`),children:[V.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[V.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:V.text.map((R,J)=>t.jsx(Di,{item:R,siblings:V.text},`${R.id||R.url||R.name}-${J}`))})})]}),t.jsx(el,{groups:V.groups})]}),v.rows.length===0&&K===0&&t.jsx(Fe,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),ce=G?t.jsx(ht,{id:"works",title:d.section.containedWorks,meta:u(`${E.length} 種`),cap:12,items:E.map(R=>t.jsx(Be,{id:R.id,label:u(R.title),onNavigate:r,renderLink:s,dense:!0}))}):null,oe=S?t.jsx(Xr,{caption:"上級叢編",children:t.jsx(Be,{id:S.id,label:u(S.title||S.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(Zt,{railTop:a,back:p,up:oe,nav:Ee,railLinks:c,main:O,card:Ne,side:ce})},ex=16,On=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function mr(e){if(!e)return On.length;const n=On.indexOf(e);return n===-1?On.length:n}const tx={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function xt(e){return e==null?"":e<0?`前${-e}`:String(e)}const nx={秦:[-221,-207],西漢:[-202,8],西汉:[-202,8],東漢:[25,220],东汉:[25,220],漢:[-202,220],汉:[-202,220],三國:[220,280],三国:[220,280],西晉:[265,316],西晋:[265,316],東晉:[317,420],东晋:[317,420],隋:[581,618],唐:[618,907],五代:[907,960],北宋:[960,1127],南宋:[1127,1279],宋:[960,1279],遼:[916,1125],辽:[916,1125],金:[1115,1234],元:[1271,1368],明:[1368,1644],清:[1636,1912]},ll=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:a})=>{var ce,oe,he,Z,F;const p=ue(),{convert:c}=q(),[d,u]=f.useState("全部"),[g,x]=f.useState(!1),[m,b]=f.useState("default"),[S,h]=f.useState(new Map),y=f.useMemo(()=>(e.works||[]).map(I=>{const D=S.get(I.work_id);return{id:I.work_id,title:(D==null?void 0:D.title)??I.title??I.work_id,role:I.role||"",cls:yi(I.role),versionCount:D==null?void 0:D.versionCount,section:D==null?void 0:D.cls,l1:D==null?void 0:D.l1,measure:D==null?void 0:D.measure,hasImage:D==null?void 0:D.hasImage,loaded:!!(D!=null&&D.loaded)}}),[e.works,S]),j=f.useMemo(()=>Hr((e.works||[]).map(I=>I.role)),[e.works]),k=f.useMemo(()=>{const I=d==="全部"?y:y.filter(D=>D.cls===d);return m==="versions"?[...I].sort((D,M)=>(M.versionCount??-1)-(D.versionCount??-1)):I},[y,d,m]),$=g?k:k.slice(0,ex),v=f.useMemo(()=>$.filter(I=>!S.has(I.id)).map(I=>I.id),[$,S]);f.useEffect(()=>{if(!n||v.length===0)return;let I=!1;return Promise.all(v.map(D=>n.getItem(D).then(M=>{var H,U,re,Se,ye;const ne=M??{},R=ne._edition_count??(((H=ne.books)==null?void 0:H.length)??0)+(((U=ne.collections)==null?void 0:U.length)??0),J=[(re=ne.classification)==null?void 0:re.l1,(Se=ne.classification)==null?void 0:Se.l2].filter(Boolean).join(" ");return[D,{id:D,title:ne.title,versionCount:R,loaded:!0,cls:J||void 0,l1:((ye=ne.classification)==null?void 0:ye.l1)||void 0,measure:M&&at(M,p.unit.juan)||void 0,hasImage:!!(ne.has_image??ne._has_image)}]}).catch(()=>[D,{id:D,loaded:!0}]))).then(D=>{I||h(M=>{const ne=new Map(M);for(const[R,J]of D)ne.set(R,J);return ne})}),()=>{I=!0}},[n,v,p.unit.juan]);const _=f.useMemo(()=>{const I=new Map;for(const D of e.alt_names||[]){const M=D.type||p.section.aliases;I.has(M)||I.set(M,[]),I.get(M).push(D.name)}return[...I.entries()].sort((D,M)=>mr(D[0])-mr(M[0])).map(([D,M])=>({label:D,names:M}))},[e.alt_names,p]),w=e.birth_year??((ce=e.dates)==null?void 0:ce.birth)??void 0,z=e.death_year??((oe=e.dates)==null?void 0:oe.death)??void 0,N=(he=e.dates)==null?void 0:he.floruit,T=w!=null||z!=null?`${xt(w)||"?"}—${xt(z)||"?"}`:Array.isArray(N)&&N.length===2&&N.every(I=>Number.isFinite(I))?`活躍於 ${xt(N[0])}—${xt(N[1])}`:"",C=new Set(["本名","字","號","号"]),P=_.filter(I=>C.has(I.label)),B=_.filter(I=>!C.has(I.label)),A=B.reduce((I,D)=>I+D.names.length,0),W=f.useMemo(()=>{const I=[];for(const M of P)I.push({label:M.label,value:M.names.map(ne=>c(ne)).join("、")});const D=(e.works||[]).length;return D&&I.push({label:"著作",value:`${D} ${c("種")}`}),I},[e.works,P,c]),V=I=>{var D;return(D=_.find(M=>I.includes(M.label)))==null?void 0:D.names[0]},K=V(["字"]),E=V(["號","号"]),le=[K?`字${K}`:"",E?`號${E}`:""].filter(Boolean).join(","),G=e.native_place,ae=e.dynasty?nx[e.dynasty]:void 0,pe=(()=>{if(!ae||w==null||z==null||z<w)return null;const[I,D]=ae,M=Math.max(w,I),ne=Math.min(z,D);if(ne<=M)return null;const R=D-I;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":c(`${xt(w)}—${xt(z)},一生 ${z-w+1} 年`),children:t.jsx("i",{style:{left:`${(M-I)/R*100}%`,width:`${(ne-M)/R*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:c(`${xt(I)} ${e.dynasty}`)}),t.jsx("span",{children:c(`一生 ${z-w+1} 年`)}),t.jsx("span",{children:xt(D)})]})]})})(),ee=f.useMemo(()=>{if(!n||y.length===0||y.some(M=>!M.loaded))return null;const I=new Map;for(const M of y){const ne=si(M.l1);ne&&I.set(ne,(I.get(ne)??0)+1)}const D=Yt.map(M=>({...M,n:I.get(M.key)??0})).filter(M=>M.n>0);return D.length?D:null},[y,n]),X=t.jsxs(Xt,{kind:tx[e.subtype]??"人物",title:c(e.primary_name||e.title),subtitle:le?c(le):void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(Me,{items:[e.dynasty?c(e.dynasty):"",T?c(T):"",G?c(`${G}人`):""]}),pe]}),description:(Z=e.description)!=null&&Z.text?t.jsx(lt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:vi((F=e.description)==null?void 0:F.text)?6:void 0,facts:W,foot:t.jsx(Qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[A>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c(`更多別名(${A})`)}),t.jsx("dl",{children:B.map(I=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:c(I.label)}),t.jsx("dd",{children:I.names.map(D=>c(D)).join("、")})]},I.label))})]}),ee&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:c("著作分佈")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:ee.map(I=>t.jsx("i",{style:{flexGrow:I.n,background:o(I.token)}},I.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ee.map(I=>t.jsxs("span",{children:[t.jsx("i",{style:{background:o(I.token)}}),c(I.label)," ",I.n]},I.key))})]})]}),ie=f.useMemo(()=>y.filter(I=>I.loaded&&(I.versionCount??0)>0).sort((I,D)=>(D.versionCount??0)-(I.versionCount??0)).slice(0,3),[y]),me=!!n&&y.length>=3&&$.some(I=>!I.loaded),te=d==="全部"&&(me||ie.length>=2),se=e.external_ids||{},fe=[];se.cbdb_id!=null&&fe.push({label:"CBDB",id:String(se.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${se.cbdb_id}`,note:se.cbdb_match==="auto"?"自動匹配":void 0});const be=se.wikidata_id;be&&fe.push({label:"Wikidata",id:be,href:`https://www.wikidata.org/wiki/${be}`});const ze=se.viaf_id;ze&&fe.push({label:"VIAF",id:ze,href:`https://viaf.org/viaf/${ze}`});const ve=j.map(I=>({key:I.cls,label:`${I.label} ${I.count}`})),ke=[...te&&!me?[{id:"featured",label:"著作舉要",count:ie.length}]:[],...y.length?[{id:"works",label:"全部著作",count:y.length}]:[],...fe.length?[{id:"external",label:"站外資料",count:fe.length}]:[]],Ne=te?t.jsxs(Fe,{id:"featured",title:"著作舉要",children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:c("存世版本最多的三部")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":me||void 0,children:[me&&[0,1,2].map(I=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},I)),!me&&ie.map(I=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Be,{id:I.id,label:c(I.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx(Me,{items:[I.section?c(I.section):"",I.measure?c(I.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:I.versionCount}),t.jsx("span",{children:c("種版本")}),I.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("有影印")})]})]},I.id))]})]}):null,Ee=y.length===0?t.jsx(Fe,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該人物的關聯作品。")})}):t.jsxs(t.Fragment,{children:[Ne,t.jsxs(Fe,{id:"works",title:"著作",meta:t.jsx(Me,{items:[c(`共 ${y.length} 種`),k.length!==y.length?c(`當前 ${k.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ve.length>1&&t.jsx(_n,{items:ve,value:d,onChange:I=>{u(I),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":m==="versions",onClick:()=>{m==="default"&&x(!0),b(I=>I==="default"?"versions":"default")},children:c(m==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("作品")}),t.jsx("th",{children:c("部類")}),t.jsx("th",{children:c("職任")}),t.jsx("th",{children:c("存世版本")}),t.jsx("th",{"aria-label":c("影印")})]})}),t.jsx("tbody",{children:$.map(I=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Be,{id:I.id,label:c(I.title),onNavigate:i,renderLink:r,dense:!0}),I.measure?t.jsx(Me,{items:[c(I.measure)]}):!I.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.section||I.loaded?"":" bim-d-zt-blank"}`,children:I.section?c(I.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.role?"":" bim-d-zt-blank"}`,children:I.role?c(I.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.loaded?"":" bim-d-zt-blank"}`,children:I.loaded?I.versionCount?c(`${I.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:c("未著錄")}):""}),t.jsx("td",{className:I.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:I.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("有影印")})})]},I.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("該職任下的著作尚未著錄。")}),k.length>$.length&&t.jsx(Bt,{label:`展開其餘 ${k.length-$.length} 種著作`,onClick:()=>x(!0)})]})]}),O=fe.length>0?t.jsx(ht,{id:"external",title:"站外資料",items:fe.map(I=>t.jsxs("a",{href:I.href,target:"_blank",rel:"noopener noreferrer",children:[I.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:fe.map(I=>I.id),foot:se.cbdb_id!=null&&se.cbdb_match==="auto"?c("CBDB 為自動匹配,未經人工核對"):void 0}):null;return t.jsx(Zt,{railTop:s,back:l,nav:ke,railLinks:a,main:Ee,card:X,side:O})},Gi="(max-width: 719px)",ix=`${Gi}, (pointer: coarse)`,al=`
828
+ `;function _i(e,n){var o;return n?e.key===n?!0:!!((o=e.children)!=null&&o.some(r=>_i(r,n))):!1}const Dc=()=>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 Hc({item:e,activeKey:n,onSelect:o,tabKey:r}){const s=_i(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(Dc,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(gs,{items:e.children,activeKey:n,onSelect:o,tabKey:r})]})}function gs({items:e,activeKey:n,onSelect:o,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Hc,{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 Io(e,n){var o;for(const r of e)if(r.key===n||_i(r,n))return r.key;return((o=e[0])==null?void 0:o.key)??null}function ms({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??Io(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===Io(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(gs,{items:e,activeKey:n,onSelect:o,tabKey:p})})}function Gc({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 hs({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(Gc,{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 $i={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal",workLinks:!0},$t=[15,16,17,18,20,22,24],Qn=18,bs="bim-reader-prefs",Uc="bim-reading-mode";function Vc(){const e={...$i};try{const n=localStorage.getItem(bs),o=n?JSON.parse(n):{};typeof o.fontSize=="number"&&$t.includes(o.fontSize)&&(e.fontSize=o.fontSize),(o.readingMode??localStorage.getItem(Uc))==="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 Yc(e){try{localStorage.setItem(bs,JSON.stringify(e))}catch{}}function To(e,n){const o=e??Qn,r=$t;let s=r.indexOf(o);return s<0&&(s=r.indexOf(Qn)),r[Math.max(0,Math.min(r.length-1,s+n))]}function zi(){const[e,n]=g.useState($i);g.useEffect(()=>{n(Vc())},[]);const o=g.useCallback(r=>{n(s=>{const l={...s,...r};return Yc(l),l})},[]);return[e,o]}function ys(e){return e.map(n=>({key:n.key,label:n.version_label||n.key,sourceName:n.source_name,license:n.license,sourceUrl:n.source_url,primary:n.primary}))}function ei(e){const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function 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 vs(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 qc=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),Kc=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),t.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function Jc(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 Zc(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 Xc(){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 Ci({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=Zc(us,!0),[q,ae]=g.useState("auto"),ne=q==="auto"?F:q==="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||q!=="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,q]);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(()=>vs(o),[o]),[Se,Ne]=g.useState(null),je=js(_,S!==void 0?S:Se),H=(je==null?void 0:je.key)??null,ce=g.useMemo(()=>ye.map(A=>A.key).join(`
829
+ `),[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??Qn,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":q,"data-img":le?"open":"closed",style:W,children:[t.jsx("style",{children:fs}),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?ei(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:ei(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(qc,{}),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(Kc,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Xc,{}),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:To(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:To(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"&&Jc(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(ms,{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(hs,{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 ks="guji-table-v1";function ws(e){return!!e&&e.table_notation===ks}const Qc=/^:::table(?:\{[^}]*\})?[ \t]*$/,ed=/^:::[ \t]*$/;function Ss(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=qr(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 td=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function nd(e){if(e==="^")return{cont:!0};const n=td.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 _s(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=Ss(u).map(nd),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 Ii(e){const n=e.split(`
830
+ `),o=[];let r=[];const s=()=>{if(r.length===0)return;const d=r.join(`
831
+ `);r=[],o.push({type:"text",text:d})};let l=0;for(;l<n.length;){if(Qc.test(n[l].trim())){let d=l+1;for(;d<n.length&&!ed.test(n[d].trim());)d++;if(d<n.length){s();const p=n.slice(l+1,d);o.push({type:"table",table:_s(p,l+1),source:n.slice(l,d+1).join(`
832
+ `)}),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 id={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},od={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},rd=`1px solid ${i("table-border")}`,$s={border:rd,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},sd={...$s,background:i("table-head-bg"),fontWeight:600};function Ti({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:id,children:t.jsx("table",{className:"bim-guji-table",style:od,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?sd:$s,children:s.empty?null:Ue(s.text,void 0,n)},l)})},r))})})})}function ld(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 ad(e,n,o=!1){const r=o?{gujiMarkdown:!0}:void 0;return n?Ii(e).map((s,l)=>s.type==="table"?t.jsx(Ti,{table:s.table,opts:r},l):t.jsx(g.Fragment,{children:ld(s.text,r)},l)):Ue(e,void 0,r)}const cd=/^(#{1,6})\s+(.*)$/,dd=/^\*\*([^*\n]+)\*\*\s*$/;function Ei(e){const n=e.match(cd);if(n)return{level:n[1].length,text:n[2].trim()};const o=e.trim().match(dd);return o?{level:3,text:o[1].trim()}:null}const Ri=/^<!--.*-->$/;function zs(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function Cs(e){return e.split(`
833
+ `).map(n=>n.trim()).filter(n=>n&&!Ri.test(n))}const pd=60;function Is(e){let n=0,o=0;for(const r of e.split(`
834
+ `)){const s=r.trim();if(!s||Ri.test(s)||Ei(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>pd&&(o+=l)}return n>0&&o*2>=n}function ud(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function zn(e){if(e=ud(e),Is(e))return"unknown";const n=zs(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const o=n.map(s=>Cs(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 xd(e){const n=e.split(`
835
+ `),o=[];let r=null,s=[];const l=()=>{o.push({heading:r,body:s.join(`
836
+ `)}),s=[]};for(const d of n){const p=Ei(d);if(p){l(),r={kind:"heading",level:p.level,text:p.text};continue}s.push(d)}return l(),o}function Eo(e){const n=[];for(const o of e.split(`
837
+ `)){const r=Ei(o);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=o.trim();!s||Ri.test(s)||n.push({kind:"body",text:o})}return n}function Ts(e){if(!e)return[];const n=zn(e);if(n==="unknown")return Eo(e);const o=[];for(const{heading:r,body:s}of xd(e)){r&&o.push(r);const l=zs(s);if(l.length!==0){if(Is(s)){o.push(...Eo(s));continue}if(n==="record"){const d=l.join(" ");d&&o.push({kind:"body",text:d})}else for(const d of l){const p=Cs(d);p.length&&o.push({kind:"body",text:p.join(" ")})}}}return o}const Es=e=>e;function Rs(e,n=Es){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 Ni(e,n={}){const o=n.renderText??Es,r=n.properNames?l=>Rs(l,o):o,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Ue(e,r,s)}function Ro(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 Bn=/^(#{1,6})\s+(.*)$/,fd=/^\s*<!--.*-->\s*$/;function Ns(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
838
+ `)?"":n)}function gd(e){return e<=1?2:e===2?3:4}function md(){let e=1;return n=>{const o=gd(n),r=Math.min(o,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${o}`}}}function qt(e){return e?zn(Ns(e))!=="unknown":!1}function No({text:e,mode:n,inline:o,dropTitle:r}){const s=Ns(e),l=(a,u,f)=>!!r&&f<=1&&a<=2&&u.trim()===r.trim(),d=md();if(n==="paragraph"&&zn(s)!=="unknown"){const a=Ts(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:Ro(u.text,o,f)},f)})})}const p=s.split(`
839
+ `);let c=0;return t.jsx(t.Fragment,{children:p.map((a,u)=>{const f=a.match(Bn);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()&&!Bn.test(p[u-1])&&!Bn.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(fd.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:Ro(a,o,u)},u)})})}function hd(e){const{convert:n}=Z();return g.useMemo(()=>e?n(e):"",[e,n])}function Li({text:e,mode:n,tables:o=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:d}){const p=hd(e),{convert:c}=Z(),a=x=>Ni(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(No,{text:p,mode:n,inline:a,dropTitle:f}):t.jsx(t.Fragment,{children:Ii(p).map((x,m)=>x.type==="table"?t.jsx(Ti,{table:x.table,opts:u},m):t.jsx(No,{text:x.text,mode:n,inline:a,dropTitle:m===0?f:void 0},m))})}function Ls(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 Lo={A:"fine",B:"rough",C:"rough",D:"ocr"};function bd(e){return typeof e!="string"?null:e in Hn?e:e in Lo?Lo[e]:null}const yd={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},jd={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function Ye(e){return typeof e!="string"?"":yd[e]??jd[e]??e}const vd=["〇","一","二","三","四","五","六","七","八","九"],Bo=["","十","百","千"],kd=["","萬","億"];function Bi(e){if(e===0)return"〇";if(e<0)return`負${Bi(-e)}`;const n=[];let o=e,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(wd(s,r>0)+kd[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function wd(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+=Bo[p]:s+=vd[d]+Bo[p]}return s.replace(/〇$/,"")}let Vt=null,dn=null;const hn=new Set;function Sd(){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 _d=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),Sd(),()=>{hn.delete(n)}},[]),Vt??_d}function Et(e,n){return n(e).toLowerCase()}const $d=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:$d,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},p++)),d=c+r.length}return t.jsx(t.Fragment,{children:l})}function Ai(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 zd(e,n,o){return n?Et(e,o).includes(Et(n,o)):!0}const Wi={类:i("section-lei"),书:i("section-shu"),序:i("section-xu"),结语:i("section-jieyu"),注释:i("section-zhushi")},Cd={考证:i("section-kaozhen")};function Id(e){const n=e.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Bs(e){var r;const n=e.files.length,o=((r=e.children)==null?void 0:r.reduce((s,l)=>s+Bs(l),0))||0;return n+o}function Td(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 Ed={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Mi({enabled:e,expanded:n,onClick:o,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:o,style:{...Ed,...r},children:s}):t.jsx("span",{style:r,children:s})}function Rd({type:e}){const n=Ye(e),o=Wi[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 Nd({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?ss(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(Mi,{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:[Bi(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 Ld({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(Mi,{enabled:p,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(Rd,{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, ${Wi[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 Bd=100;function Fi(e){return Ye(e.type)!=="page_header"?!1:(e.content||"").length>=Bd}function Ad({section:e,highlightQuery:n=""}){const{convert:o}=Z(),r=vt();if(Ye(e.type)==="page_header"&&!Fi(e)||!e.content&&!e.title)return null;const s=o((e.content||e.title||"").replace(/\n{2,}/g,`
840
+ `)),l=Ue(s,a=>n?tn(a,n,r):a),d=Ye(e.type),p=Wi[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 Wd(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 Md({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=Cd[f]||i("desc-fg"),m=!!e.content,j=e.work_ids||[],w=j.length>1,h=Wd(w?j:[],o,r),b=m&&!a&&e.content.length>80?ss(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(Mi,{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 Fd({juan:e,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const l=vt(),d=n.trim(),p=g.useMemo(()=>d?e.sections.filter(c=>Ai(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(Md,{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 Pd(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Od({sections:e,onNavigate:n,inline:o,workLinks:r=!0}){const s=Pe(),{convert:l}=Z(),d=Pd();return t.jsx(t.Fragment,{children:e.map((p,c)=>{const a=Ye(p.type);if(a==="page_header"&&!Fi(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?Bi(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 As(e){return e.some(n=>{const o=Ye(n.type);return o==="书"||o==="诗"||o==="考证"||o==="注释"||o==="类"||(o==="序"||o==="结语")&&!!n.content||o==="page_header"&&Fi(n)})}function Dd({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=>Ni(ee,{renderText:k,properNames:c.properNames}),v=g.useMemo(()=>b?e.sections.filter(ee=>Ai(ee,b,y,x)):e.sections,[e.sections,b,y,x]),_=(ee,F)=>F.filter(q=>Ye(q.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?bd(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:Wl[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(Hn[C])})]}):t.jsxs(t.Fragment,{children:[f("文本質量"),t.jsx("span",{className:"bim-rd-grade",children:f(Hn[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&&As(e.sections),O=!!n&&(!B||c.readingMode==="paragraph"&&qt(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(Li,{text:n,mode:c.readingMode,properNames:c.properNames,renderText:k,dropTitle:e.title}):t.jsx(Od,{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(Fd,{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 q=Ye(ee.type);return q==="书"||q==="诗"||q==="考证"?(Y+=1,t.jsx(Nd,{domId:`rd-e-${e.sections.indexOf(ee)}`,section:ee,onNavigate:c.workLinks?l:void 0,highlightQuery:b,no:Y,showUnlinked:c.workLinks&&!!l},F)):q==="类"?t.jsx(Ld,{section:ee,highlightQuery:b},F):t.jsx(Ad,{section:ee,highlightQuery:b},F)}),v.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function Ws(e){return e.juan_files&&e.juan_files.length>0?e.juan_files:e.files&&e.files.length>0?e.files.map(n=>n.filename):[]}function Hd(e){const n=Ws(e);return n.length>0?n[0]:null}function Gd(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)Ai($,y,c,a)&&k++;return k===0&&b.rawText&&zd(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 Ud({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 Vd(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 Pi=({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=Hd(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 q=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=Ws(E);return t.jsx(qd,{className:d,style:p,index:E,allFiles:ne,isKaozhen:ae,effectiveWorkId:ee,transport:o,activeFile:X,handleSelectFile:q,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 ti(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}冊`:Id(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 Yd(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??ti(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=Td(c,o);return{key:`group:${a}`,label:s(c.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:Bs(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 qd=({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]=zi(),[$,v]=g.useState("text");g.useEffect(()=>{v("text")},[p]);const{matchStates:_,titles:S}=Gd({workId:l,transport:d,files:r,activeFile:p,activeJuan:a,activeRawText:u,query:x,isKaozhen:s}),z=Ls(h.resolveImages,p),N=g.useMemo(()=>Yd(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:q=>m(q.target.value)}),C=s?"章":o.juan_metadata&&Object.values(o.juan_metadata).some(q=>q.vol_label)?"冊":"卷",D=p?ti(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:q=>{q.metaKey||q.ctrlKey||(q.preventDefault(),j(l))},title:"查看作品",children:O}):O,X=!!a&&!s&&As(a.sections),Y=X&&!(u&&y.readingMode==="paragraph"&&qt(u)),E=a&&!s&&X?t.jsx(Ud,{juan:a,view:$,onView:v,textHasEntries:Y}):void 0,ee=Vd(l,d),F=ee.length>0?b(ee.slice(0,2).map(q=>`${q.dynasty?`〔${q.dynasty}〕`:""}${q.name}${q.role?` ${q.role}`:" 撰"}`).join("、")):void 0;return t.jsxs(Ci,{className:e,style:n,title:M,subtitle:h.subtitle??b(s?"考證":"整理本"),byline:F,pagerUnit:C,rail:E,current:p?ti(p,o,S,b).label:void 0,workLinkToggle:!s&&!!j&&!!(a!=null&&a.sections.some(q=>q.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&&qt(u),allowVertical:h.allowVertical,children:[f?t.jsx(jt,{}):a?t.jsx(Dd,{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((q,ae)=>t.jsxs("li",{children:[q.url?t.jsx("a",{className:"bim-rd-link",href:q.url,target:"_blank",rel:"noopener noreferrer",children:q.title}):t.jsx("span",{children:q.title}),q.author&&t.jsxs("span",{children:[",",q.author]}),q.note&&t.jsxs("span",{children:["。",q.note]})]},ae))})]})]})},Kd={bug:{label:"错误反馈",color:i("danger")},resource:{label:"资源建议",color:i("primary")},suggestion:{label:"功能建议",color:i("primary")},other:{label:"其他",color:i("desc-fg")}},Jd={label:"其他",color:i("desc-fg")},Zd={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")}},Xd={label:"待处理",color:i("warning")};function Qd(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 ep(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 Oi=({items:e,loading:n})=>{const o=Pe();return n?t.jsx(jt,{}):e.length===0?t.jsx("div",{style:tp,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Kd[r.type]||Jd,l=Zd[r.status]||Xd,d=typeof window<"u"&&ep(r.pageUrl,window.location.href);return t.jsxs("div",{style:np,children:[t.jsxs("div",{style:ip,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Ao,background:s.color},children:s.label}),t.jsx("span",{style:{...Ao,background:l.color},children:l.label})]}),t.jsx("span",{style:op,children:Qd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:rp,children:[r.resourceId&&t.jsx("a",{href:o(r.resourceId),style:An,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(d?t.jsx("a",{href:r.pageUrl,style:An,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:An,children:r.pageUrl}))]}),t.jsx("div",{style:sp,children:r.content}),r.reply&&t.jsxs("div",{style:lp,children:[t.jsx("div",{style:ap,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},tp={textAlign:"center",padding:"40px 0",color:i("desc-fg"),fontSize:"14px"},np={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"16px"},ip={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ao={fontSize:"12px",color:i("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},op={fontSize:"12px",color:i("desc-fg")},rp={fontSize:"12px",marginBottom:"6px"},An={color:i("primary"),textDecoration:"none",borderBottom:`1px dashed ${i("primary")}`},sp={fontSize:"14px",lineHeight:"1.6",color:i("fg"),whiteSpace:"pre-wrap"},lp={marginTop:"12px",padding:"10px 12px",background:i("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:i("fg")},ap={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:i("primary")},ni=({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 q=null;if(e.getEntry)q=await e.getEntry(F.id);else{const ae=await e.getItem(F.id);ae&&(q={id:F.id,title:ae.title||F.id,type:ae.type||"work"})}if(q)return{...q,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(cp,{recommended:a,loading:k,onNavigate:n,getIcon:O,t:d}),b==="catalog"&&t.jsx(Wo,{progress:v,t:d,onNavigate:n}),b==="collection"&&t.jsx(Wo,{progress:S,t:d,onNavigate:n}),b==="site"&&t.jsx(pp,{progress:N,t:d,totalWorks:(p==null?void 0:p.works)??0}),b==="feedback"&&l&&t.jsx(Oi,{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}),cp=({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))})},Wo=({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(dp,{item:a,t:n,statusColor:d[p],onNavigate:o},a.id))})]},p)})})},dp=({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})]})},pp=({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(Mo,{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(Mo,{item:c,t:n,totalWorks:o},c.id))})]})]})},Mo=({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})]})},Fo="(max-width: 768px)";function up(){const[e,n]=g.useState(()=>typeof window>"u"?!1:window.matchMedia(Fo).matches);return g.useEffect(()=>{const o=window.matchMedia(Fo),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),e}const xp=({transport:e,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var X;const l=ue(),{convert:d}=Z(),p=up(),[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(gi,{data:u,transport:e,onNavigate:C}):j.startsWith("catalog:")?t.jsx(mi,{data:(X=h.find(Y=>`catalog:${Y.resource_id}`===j))==null?void 0:X.data,onNavigate:C}):j==="collated"?t.jsx(Pi,{index:$||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(ni,{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(Un,{transport:e,onEntryClick:T,hideModeIndicator:n}),!u&&t.jsx(ni,{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(Un,{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 Po(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 Oo={padding:24,color:i("desc-fg")},ii=({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=Ls(u,D?ut(D.file):null),[O,M]=zi(),{convert:X}=Z(),Y=!!(d&&d.length>1&&p),E=g.useMemo(()=>Y?ys(d).map((ne,Q)=>({...ne,label:Po(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:Po(ne)},ne.key))})]}):null;if(!h)return t.jsxs("div",{style:Oo,children:[ee&&t.jsx("div",{style:{marginBottom:12},children:ee}),y?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:Oo,children:[ee&&t.jsx("div",{style:{marginBottom:12},children:ee}),"全文目录为空"]});const F=h.chapters.map(ne=>({key:ut(ne.file),label:X(ne.title)})),q=ws(h)||qn(h),ae=z?z.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(Ci,{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:qt(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(Li,{text:ae,mode:O.readingMode,tables:q,gujiMarkdown:qn(h),properNames:O.properNames})}),!T&&!z&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},fp=({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(gp,{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))})]})},gp=({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(mp,{category:c,expanded:r===a,onToggle:()=>s(a),onNavigate:l},c.name)})})]})},mp=({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(Do,{label:"著錄",books:l,onNavigate:r}),d.length>0&&t.jsx(Do,{label:"存目",books:d,onNavigate:r})]})]})},Do=({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," 條"]})]})},Ke=({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:bp,children:"AI"}),n&&t.jsx("button",{onClick:n,style:hp,children:l.action.save})]})]}),s]})},hp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},bp={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 yp(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=yp(e||"");return g.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&d?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Ho,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:Ho,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"}})]})},Ho={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500};function jp(e){switch(e){case"url":return i("source-url");case"bookID":return i("source-bookid");default:return i("desc-fg")}}function vp(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ms=({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:jp(f.type),color:i("on-color-fg"),borderRadius:"3px",fontWeight:500},children:vp(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:{...Go,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:{...Go,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:Uo,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:Uo,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"},Go={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"},Uo={background:"transparent",border:"none",color:i("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Fs(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 Ps(e){return!e||e.length===0?"":JSON.stringify(e)}const Os=({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:kp,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:Ds(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(Vo,{onClick:()=>r(o),title:u,children:"👁️"}),t.jsx(Vo,{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(oi,{onClick:l,children:p}),t.jsx(oi,{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:Ds(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(oi,{onClick:s,primary:!0,children:["+ ",l]})})]})},Vo=({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}),oi=({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 Ds(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const kp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Hs=({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:wp,children:t.jsxs("div",{style:Sp,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:_p,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:$p})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:Wn,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(h=>t.jsxs("div",{onClick:()=>r(h),style:zp,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:Wn,children:["未找到匹配的",j]}):t.jsxs("div",{style:Wn,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:Cp,children:["创建新",j,"并关联"]})]})]})})},wp={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Sp={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")},_p={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},$p={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"},zp={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:i("primary-soft")},Wn={padding:"20px",textAlign:"center",color:i("desc-fg")},Cp={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Yo={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Ip={work:"📜",book:"📖",collection:"📚",entity:"👤"},Gs=({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`创建新${Yo[n]}`}};return t.jsx("div",{style:Tp,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:Ep,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:Ip[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:`请输入${Yo[n]}名称...`,style:Rp})]}),((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:Np,children:"取消"}),t.jsx("button",{onClick:u,disabled:!d.trim(),style:{...Lp,opacity:d.trim()?1:.6,cursor:d.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Tp={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ep={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")},Rp={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"},Np={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Lp={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg")};function Bp(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Us(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ap(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 Vs=({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"?"选择实体":`选择${Us(o)}`),_=$(r),S=$(m);return t.jsx("div",{style:Mp,children:t.jsxs("div",{style:Fp,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:Pp,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:f,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Op}),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(qo,{active:b==="recent",onClick:()=>y("recent"),children:["最近使用 (",_.length,")"]}),t.jsxs(qo,{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(Ko,{entities:_,onSelect:p}):f.trim()?w?t.jsx(Mn,{message:"搜索中..."}):S.length>0?t.jsx(Ko,{entities:S,onSelect:p}):t.jsx(Mn,{message:"未找到匹配的结果"}):t.jsx(Mn,{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:Dp,children:d||"创建新实体"})]})]})})},qo=({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}),Ko=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(o=>t.jsx(Wp,{entity:o,onClick:()=>n(o)},o.id))}),Wp=({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:Bp(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:Ap(e.type),color:i("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Us(e.type)})]})},Mn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:e}),Mp={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Fp={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")},Pp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Op={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"},Dp={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Hp={work:i("editor-type-work"),collection:i("editor-type-collection"),book:i("editor-type-book"),entity:i("editor-type-entity")},Gp={work:"📜",collection:"📚",book:"📖",entity:"👤"},Ys=({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,q]=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=>{q(()=>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),q(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:Gp[Q]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(bn,{children:e.id}),t.jsx(bn,{color:Hp[Q],children:m.indexType[Q]})]})}),t.jsx(Ke,{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(Ke,{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(Ke,{title:m.section.additionalWorks,onSave:o,children:t.jsx(Up,{items:e.additional_works||[],onChange:U=>le("additional_works",U)})}),t.jsx(Ke,{title:m.section.indexedBy,onSave:o,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Vp,{items:e.indexed_by||[],onChange:U=>le("indexed_by",U)})}),t.jsx(Ke,{title:m.section.emendatedBy,onSave:o,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Yp,{items:e.emendated_by||[],onChange:U=>le("emendated_by",U)})}),t.jsx(Ke,{title:m.section.textResources,onSave:o,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(Gn,{items:e.resources||[],onChange:U=>le("resources",U),onDownload:a,downloadStatuses:u,filterType:"text"})}),t.jsx(Ke,{title:m.section.imageResources,onSave:o,children:t.jsx(Gn,{items:e.resources||[],onChange:U=>le("resources",U),onDownload:a,downloadStatuses:u,filterType:"image"})}),t.jsx(Ke,{title:m.section.sources,onSave:o,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(Ms,{items:Fs(e.sources||""),onChange:U=>le("sources",Ps(U)),onOpenEntityPicker:ce})}),(re||ge)&&t.jsx(Ke,{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(Ke,{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(Os,{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(Hs,{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(Gs,{isOpen:T,entityType:D,relationField:O,inheritData:X,onConfirm:Se,onCancel:()=>C(!1)}),t.jsx(Vs,{isOpen:E,title:m.action.selectBookOrWork,filterType:"all",recentEntities:ae,excludeId:e.id,onSelect:he,onCancel:()=>{ee(!1),q(null)},onSearch:oe})]})};function Up({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 qs({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 Vp({items:e,onChange:n}){const o=ue();return t.jsx(qs,{items:e,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function Yp({items:e,onChange:n}){const o=ue();return t.jsx(qs,{items:e,onChange:n,addLabel:o.action.addEmendatedBy})}function Ks(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 qp(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 Kp=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?Ks(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(gi,{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(Ys,{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:"无数据"})},Jo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Js=({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=Jo.find(y=>y.value===s);return t.jsx("div",{style:Jp,onClick:y=>{y.target===y.currentTarget&&n()},children:t.jsxs("div",{style:Zp,onClick:y=>y.stopPropagation(),children:[t.jsxs("div",{style:Xp,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:Qp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:ou,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:Jo.map(y=>t.jsxs("button",{onClick:()=>l(y.value),style:{...eu,...s===y.value?tu:{}},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:{...nu,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:su}),t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),u==="error"&&t.jsx("div",{style:ru,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:w,disabled:!h,style:{...iu,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},Jp={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Zp={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:i("shadow-dialog")},Xp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Qp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:i("desc-fg"),padding:"4px 8px",borderRadius:"4px"},eu={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"},tu={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},nu={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"},iu={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},ou={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:i("success")},ru={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginBottom:"12px"},su={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"},ri="--bim-feedback-fab-offset",si=48,lu=16,au=({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(ri,`calc(${p+si+lu}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(ri)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...cu,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(Js,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:o})]})},cu={position:"fixed",width:`${si}px`,height:`${si}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"},Zo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Zs=({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=Zo.find(w=>w.value===n);return p==="success"?t.jsx("div",{style:Xo,children:t.jsxs("div",{style:fu,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>c("idle"),style:gu,children:"继续提交"})]})}):t.jsxs("div",{style:Xo,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Zo.map(w=>t.jsxs("button",{onClick:()=>o(w.value),style:{...du,...n===w.value?pu:{}},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:{...uu}}),t.jsx("input",{type:"text",value:l,onChange:w=>d(w.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:hu}),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:{...xu,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:mu,children:a})]})},Xo={padding:"16px",border:`1px solid ${i("widget-border")}`,borderRadius:"8px",background:i("input-bg")},du={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"},pu={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},uu={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"},xu={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},fu={display:"flex",alignItems:"center",gap:"12px",color:i("success"),fontSize:"14px"},gu={background:"none",border:"none",color:i("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},mu={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginTop:"8px"},hu={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 Qo(e){return typeof e=="function"?e():e??"/api/feedback"}const Xs=({resourceId:e,apiUrl:n})=>{const[o,r]=g.useState([]),[s,l]=g.useState(!0),d=g.useCallback(async()=>{const c=Qo(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=Qo(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(Oi,{items:o,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Zs,{onSubmit:p})})]})},er={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 tr(e){return e?er[e]??e:er.related}const bu={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function yu(e){return bu[e]??e}const ju={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function vu(e){return ju[e]??""}function Di({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=vi(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 Qs(e,n){var p,c;const o=yi(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 el(e,n){const o=(e.url?Nt(e.url):void 0)||e.name,r=Pr(e,n);return r?`${o}(${r})`:o}function Hi({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(el(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(Si,{item:e})})]}),t.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(f=>!f),children:r(s?"收起分冊":`展開 ${d.expected} 冊`)})})]})}function tl({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(Hi,{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(el(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 li(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 nr=12,ku=60,nl=({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<=ku,$=k||m||!!w||b,v=g.useMemo(()=>$?u:u.slice(0,nr),[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(()=>Dr(_,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,nr),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=yi(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(vu(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(yu(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=ir(e.additional_titles);U.length&&H.push({label:"又名",value:U.map(a).join("、")});const R=ir(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]),q=[{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(Di,{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(sc(H))).filter(Boolean).join(" · ")}):null]}):void 0,stats:q,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(es,{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(wu,{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(Su,{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=tr(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(tr(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 ir(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function or(e,n){return n((e.url?Nt(e.url):void 0)||e.name)}function wu({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?or(c,l):e.locationName?l(e.locationName):"",u=e.images[0],f=u?Lt(u):void 0,x=e.images.map(m=>or(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 Su({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 _u(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 $u(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 rr(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 zu(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 Cu(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=Cu(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=$u($,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=_u($);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(rr($.id,v,_))}),($.lineage.related_to??[]).forEach((v,_)=>{k(zu($.id,v,_))}));for(const $ of r.hypothetical_nodes??[])u&&!u.has($.id)&&!x.has($.id)||($.derived_from??[]).forEach((v,_)=>{k(rr($.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 il(e,n,o){const r=(e??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Iu(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 ol=({graph:e,renderLink:n,className:o,style:r})=>{const{convert:s}=Z();if(!e.nodes.length)return t.jsx("div",{style:{...Hu,...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:{...Eu,...r},children:[e.title&&t.jsx("div",{style:Ru,children:s(e.title)}),e.description&&t.jsx("div",{style:Nu,children:s(e.description)}),f.map(x=>t.jsx(sr,{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(sr,{label:"其他",nodes:a,incomingMap:l,siblingMap:d,nodeMap:p,renderLink:n})]})},sr=({label:e,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:d})=>{const{convert:p}=Z();return t.jsxs("div",{style:Lu,children:[t.jsx("div",{style:{...Bu,borderLeftColor:n??i("widget-border")},children:p(e)}),o.map(c=>t.jsx(Tu,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:d},c.id))]})},Tu=({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:{...Au,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:Wu,children:[t.jsx("span",{style:Mu,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Fu,children:il(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Pu,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:Ou,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:Du,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:ar,children:[t.jsx("div",{style:cr,children:"来源:"}),n.map(c=>{const a=r.get(c.source);return t.jsxs("div",{style:dr(c.confidence),children:[t.jsx("span",{style:pr,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(lr,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:ur,children:["· ",p(c.evidence)]})]},c.id)})]}),o.length>0&&t.jsxs("div",{style:ar,children:[t.jsx("div",{style:cr,children:"关联:"}),o.map(c=>{const a=c.source===e.id?c.target:c.source,u=r.get(a);return t.jsxs("div",{style:dr(c.confidence),children:[t.jsx("span",{style:pr,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(lr,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:ur,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})},lr=({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},Eu={fontSize:"14px",color:i("fg")},Ru={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Nu={fontSize:"13px",color:i("muted"),marginBottom:"16px",lineHeight:1.6},Lu={marginBottom:"16px"},Bu={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:i("fg")},Au={border:`1px solid ${i("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:i("bg")},Wu={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Mu={fontSize:"15px",fontWeight:600},Fu={fontSize:"12px",color:i("muted")},Pu={marginBottom:"6px"},Ou={fontSize:"12px",color:i("muted"),margin:"2px 0"},Du={fontSize:"12px",color:i("muted"),fontStyle:"italic",margin:"4px 0"},ar={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${i("widget-border")}`},cr={fontSize:"11px",color:i("muted"),marginBottom:"2px"},dr=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),pr={display:"inline-block",padding:"0 6px",fontSize:"11px",background:i("tag-bg"),color:i("fg"),borderRadius:"3px",marginRight:"6px"},ur={fontSize:"11px",color:i("muted")},Hu={padding:"20px",textAlign:"center",color:i("muted"),fontSize:"13px"},rl=({selectedNodeId:e,...n})=>{const[o,r]=g.useState("loading"),[s,l]=g.useState(null);return g.useEffect(()=>{let d=!1;return Gu().then(p=>{d||(p?(l(p),r("ready")):r("missing"))}),()=>{d=!0}},[]),o==="loading"?t.jsx("div",{style:xr,children:"加载图组件中…"}):o==="missing"||!s?t.jsxs("div",{style:xr,children:[t.jsxs("div",{children:["图组件未安装。请安装 ",t.jsx("code",{children:"@xyflow/react"})," 与 ",t.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),t.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",t.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):t.jsx(Uu,{modules:s,selectedNodeId:e,...n})};async function Gu(){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 Uu=({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:il(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(()=>Vu(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 Vu(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??qu(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=>Yu(b,w.get(b.id),s));return{rfNodes:f,rfEdges:h}}function Yu(e,n,o=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Ku(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 qu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Ku(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 xr={padding:"40px 20px",textAlign:"center",color:i("muted"),fontSize:"13px",border:`1px dashed ${i("widget-border")}`,borderRadius:8,background:i("bg")},Gi=({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:Ju,children:[t.jsx("button",{onClick:()=>j("list"),style:Fn(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>j("graph"),style:Fn(x==="graph"),children:"关系图"}),h&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color: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:Fn(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(ol,{graph:e,renderLink:o}):t.jsx(rl,{graph:e,renderLink:o,height:r,selectedNodeId:s})]})},Ju={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Fn=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"}),fr=40,gr=2,Zu=9,mr={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function Pn(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const sl=({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,K,se,ke,be,Le,qe;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<=fr,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(()=>Qs(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=Yr(e),F=at(e,f.unit.juan),q=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=[...Xn(e.additional_titles),...Xn(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(Di,{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:ki((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]&&Pn(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||(K=e.appendix)!=null&&K.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,Zu),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(`從${Pn(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]=Pn(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(Hi,{item:L,siblings:M.text,listedVolumeCounts:q},`${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(tl,{groups:M.groups,listedVolumeCounts:q})}),$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(Gi,{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(Qu,{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(Xu,{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<=fr,U=me&&he>=0?b.slice(Math.max(0,he-gr),he+gr+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} 種版本`):""]}),((qe=m.description)==null?void 0:qe.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(Qr,{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 Xu({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 Qu({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&&mr[b]?d(`(${mr[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,ex=200,tx=16,ll=({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(()=>Ur(e,n),[e,n]),[_,S]=g.useState(new Map),z=!!o&&v.rows.length>0&&v.rows.length<=ex,N=z&&(v.rows.length<=Dt||k),T=N&&v.rows.every(I=>!I.id||_.has(I.id)),C=I=>{var G;return li(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&&li(P.id?(se=_.get(P.id))==null?void 0:se.l1:void 0)!==b)return!1;if(!G)return!0;const K=P.id&&((ke=_.get(P.id))==null?void 0:ke.title)||P.title;return u(K).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,tx);return Promise.all(G.map(P=>o.getItem(P).then(K=>{var be,Le;const se=K??{},ke={title:se.title,edition:se.edition,authors:se.authors,measure:K?at(K,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(K=>{const se=new Map(K);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(()=>Qs(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)),q=(()=>{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,K;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:(K=e.juan_count)!=null&&K.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 K=C(P.id);K&&I.set(K,(I.get(K)??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(K=>K.volumes.length>0))return null;const I=[],G=v.rows.filter(K=>K.volumes.length>0).map(K=>({k:C(K.id)??"",from:Math.min(...K.volumes),to:Math.max(...K.volumes)})).sort((K,se)=>K.from-se.from);for(const K of G){const se=K.to-K.from+1,ke=I[I.length-1];ke&&ke.key===K.k?(ke.to=Math.max(ke.to,K.to),ke.n+=se):I.push({key:K.k,from:K.from,to:K.to,n:se})}const P=G.reduce((K,se)=>Math.max(K,se.to),0);return I.length>1&&I.some(K=>K.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(Di,{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:ki(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(K=>K.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 qe;const P=I.id?_.get(I.id):void 0,K=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):"",(qe=I.subItems)!=null&&qe.length?I.subItems.map(L=>u(L)).join("、"):"",(P!=null&&P.edition||I.edition)&&!q?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(K),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(K)}),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(Hi,{item:I,siblings:X.text},`${I.id||I.url||I.name}-${G}`))})})]}),t.jsx(tl,{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(Qr,{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})},nx=16,On=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function hr(e){if(!e)return On.length;const n=On.indexOf(e);return n===-1?On.length:n}const ix={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function xt(e){return e==null?"":e<0?`前${-e}`:String(e)}const ox={秦:[-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]},al=({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:ji(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(()=>Gr((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,nx),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,K,se,ke,be;const A=W??{},I=A._edition_count??(((P=A.books)==null?void 0:P.length)??0)+(((K=A.collections)==null?void 0:K.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)=>hr(V[0])-hr(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,q=e.dynasty?ox[e.dynasty]:void 0,ae=(()=>{if(!q||S==null||z==null||z<S)return null;const[R,V]=q,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=li(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:ix[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:ki((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})},Ui="(max-width: 719px)",rx=`${Ui}, (pointer: coarse)`,cl=`
795
841
  .bim-ct {
796
842
  display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
797
843
  max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
798
- background: ${o("page-bg")}; color: ${o("ink")}; font-family: ${o("font-ui")};
844
+ background: ${i("page-bg")}; color: ${i("ink")}; font-family: ${i("font-ui")};
799
845
  }
800
846
  .bim-ct *, .bim-ct *::before, .bim-ct *::after { box-sizing: border-box; }
801
847
  .bim-ct-sr {
@@ -804,8 +850,8 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
804
850
  }
805
851
 
806
852
  /* ── 左栏 ── */
807
- .bim-ct-side { position: sticky; top: calc(${o("reader-top")} + 16px); max-height: calc(100vh - ${o("reader-top")} - 32px); overflow-y: auto; }
808
- .bim-ct-side-h { margin: 0 0 8px; padding: 0 10px; font-size: 13px; font-weight: 600; letter-spacing: 0.12em; color: ${o("aux-fg")}; }
853
+ .bim-ct-side { position: sticky; top: calc(${i("reader-top")} + 16px); max-height: calc(100vh - ${i("reader-top")} - 32px); overflow-y: auto; }
854
+ .bim-ct-side-h { margin: 0 0 8px; padding: 0 10px; font-size: 13px; font-weight: 600; letter-spacing: 0.12em; color: ${i("aux-fg")}; }
809
855
  .bim-ct-drawer-btn { display: none; }
810
856
 
811
857
  /* ── 分类树 ── */
@@ -814,33 +860,33 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
814
860
  .bim-ct-row {
815
861
  display: flex; align-items: center; gap: 4px; min-height: 34px;
816
862
  padding: 0 10px 0 calc(var(--bimct-lv, 0) * 14px + 4px); border-radius: 6px;
817
- font-size: 14px; line-height: 1.4; color: ${o("body-fg")}; cursor: pointer; user-select: none;
863
+ font-size: 14px; line-height: 1.4; color: ${i("body-fg")}; cursor: pointer; user-select: none;
818
864
  }
819
- .bim-ct-row:hover { background: ${o("row-hover-bg")}; color: ${o("ink")}; }
820
- .bim-ct-tree li[aria-selected="true"] > .bim-ct-row { background: ${o("zebra-bg")}; color: ${o("accent")}; font-weight: 700; }
821
- .bim-ct-tree li:focus-visible > .bim-ct-row { outline: 2px solid ${o("accent")}; outline-offset: -2px; }
865
+ .bim-ct-row:hover { background: ${i("row-hover-bg")}; color: ${i("ink")}; }
866
+ .bim-ct-tree li[aria-selected="true"] > .bim-ct-row { background: ${i("zebra-bg")}; color: ${i("accent")}; font-weight: 700; }
867
+ .bim-ct-tree li:focus-visible > .bim-ct-row { outline: 2px solid ${i("accent")}; outline-offset: -2px; }
822
868
  .bim-ct-tw {
823
869
  flex: none; width: 20px; align-self: stretch; display: inline-flex; align-items: center; justify-content: center;
824
- color: ${o("aux-fg")};
870
+ color: ${i("aux-fg")};
825
871
  }
826
872
  .bim-ct-tw svg { transition: transform 0.15s; }
827
873
  .bim-ct-tree li[aria-expanded="true"] > .bim-ct-row .bim-ct-tw svg { transform: rotate(90deg); }
828
874
  .bim-ct-lb { min-width: 0; flex: 1; overflow-wrap: anywhere; }
829
- .bim-ct-n { flex: none; margin-left: 8px; font-size: 12px; font-weight: 400; color: ${o("aux-fg")}; font-variant-numeric: tabular-nums; }
830
- .bim-ct-tree li[aria-selected="true"] > .bim-ct-row .bim-ct-n { color: ${o("accent")}; }
831
- .bim-ct-tree .bim-ct-last { margin-top: 6px; padding-top: 6px; border-top: 1px solid ${o("rule")}; }
875
+ .bim-ct-n { flex: none; margin-left: 8px; font-size: 12px; font-weight: 400; color: ${i("aux-fg")}; font-variant-numeric: tabular-nums; }
876
+ .bim-ct-tree li[aria-selected="true"] > .bim-ct-row .bim-ct-n { color: ${i("accent")}; }
877
+ .bim-ct-tree .bim-ct-last { margin-top: 6px; padding-top: 6px; border-top: 1px solid ${i("rule")}; }
832
878
 
833
879
  /* ── 右栏 ── */
834
880
  .bim-ct-main { min-width: 0; }
835
881
  .bim-ct-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 14px; }
836
- .bim-ct-title { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: 0.04em; color: ${o("ink")}; }
837
- .bim-ct-crumb { font-size: 13px; color: ${o("aux-fg")}; }
838
- .bim-ct-stat { font-size: 13px; color: ${o("aux-fg")}; }
882
+ .bim-ct-title { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: 0.04em; color: ${i("ink")}; }
883
+ .bim-ct-crumb { font-size: 13px; color: ${i("aux-fg")}; }
884
+ .bim-ct-stat { font-size: 13px; color: ${i("aux-fg")}; }
839
885
  .bim-ct-search { margin: 0 0 16px; }
840
- .bim-ct-view { margin-left: auto; display: inline-flex; border-radius: 6px; box-shadow: inset 0 0 0 1px ${o("rule")}; overflow: hidden; }
841
- .bim-ct-view button { min-height: 28px; padding: 0 12px; border: 0; background: none; cursor: pointer; font: inherit; font-size: 13px; color: ${o("quiet-fg")}; }
842
- .bim-ct-view button[aria-pressed="true"] { background: ${o("flag-bg")}; color: ${o("accent")}; font-weight: 700; }
843
- .bim-ct-view button:focus-visible { outline: 2px solid ${o("accent")}; outline-offset: -2px; }
886
+ .bim-ct-view { margin-left: auto; display: inline-flex; border-radius: 6px; box-shadow: inset 0 0 0 1px ${i("rule")}; overflow: hidden; }
887
+ .bim-ct-view button { min-height: 28px; padding: 0 12px; border: 0; background: none; cursor: pointer; font: inherit; font-size: 13px; color: ${i("quiet-fg")}; }
888
+ .bim-ct-view button[aria-pressed="true"] { background: ${i("flag-bg")}; color: ${i("accent")}; font-weight: 700; }
889
+ .bim-ct-view button:focus-visible { outline: 2px solid ${i("accent")}; outline-offset: -2px; }
844
890
 
845
891
  /* ── 卡片网格 ── */
846
892
  .bim-ct-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@@ -848,35 +894,35 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
848
894
  .bim-ct-card > a {
849
895
  display: flex; flex-direction: column; gap: 6px; height: 100%; min-height: 44px;
850
896
  padding: 14px 16px 12px; border-radius: 8px;
851
- background: ${o("card-bg")}; color: inherit; text-decoration: none;
897
+ background: ${i("card-bg")}; color: inherit; text-decoration: none;
852
898
  transition: background 0.12s;
853
899
  }
854
- .bim-ct-card > a:hover { background: ${o("tint-bg")}; }
855
- .bim-ct-card > a:hover .bim-ct-ct { color: ${o("accent")}; }
856
- .bim-ct-card > a:focus-visible { outline: 2px solid ${o("accent")}; outline-offset: 2px; }
900
+ .bim-ct-card > a:hover { background: ${i("tint-bg")}; }
901
+ .bim-ct-card > a:hover .bim-ct-ct { color: ${i("accent")}; }
902
+ .bim-ct-card > a:focus-visible { outline: 2px solid ${i("accent")}; outline-offset: 2px; }
857
903
  .bim-ct-ch { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
858
- .bim-ct-ct { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.4; color: ${o("ink")}; overflow-wrap: anywhere; }
859
- .bim-ct-juan { flex: none; font-size: 12px; color: ${o("aux-fg")}; }
860
- .bim-ct-by { font-size: 13px; line-height: 1.5; color: ${o("quiet-fg")}; overflow-wrap: anywhere; }
861
- .bim-ct-dy { font-size: 12px; color: ${o("aux-fg")}; }
904
+ .bim-ct-ct { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.4; color: ${i("ink")}; overflow-wrap: anywhere; }
905
+ .bim-ct-juan { flex: none; font-size: 12px; color: ${i("aux-fg")}; }
906
+ .bim-ct-by { font-size: 13px; line-height: 1.5; color: ${i("quiet-fg")}; overflow-wrap: anywhere; }
907
+ .bim-ct-dy { font-size: 12px; color: ${i("aux-fg")}; }
862
908
  .bim-ct-sum {
863
- margin: 0; font-size: 13px; line-height: 1.65; color: ${o("body-fg")};
909
+ margin: 0; font-size: 13px; line-height: 1.65; color: ${i("body-fg")};
864
910
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden;
865
911
  }
866
- .bim-ct-cls { margin-top: auto; padding-top: 2px; font-size: 12px; color: ${o("aux-fg")}; }
867
- .bim-ct-empty { padding: 48px 0; text-align: center; font-size: 14px; color: ${o("aux-fg")}; }
912
+ .bim-ct-cls { margin-top: auto; padding-top: 2px; font-size: 12px; color: ${i("aux-fg")}; }
913
+ .bim-ct-empty { padding: 48px 0; text-align: center; font-size: 14px; color: ${i("aux-fg")}; }
868
914
 
869
915
  /* ── 列表视图 ── */
870
916
  .bim-ct-list { list-style: none; margin: 0; padding: 0; }
871
- .bim-ct-lrow:nth-child(odd) { background: ${o("zebra-bg")}; border-radius: 6px; }
917
+ .bim-ct-lrow:nth-child(odd) { background: ${i("zebra-bg")}; border-radius: 6px; }
872
918
  .bim-ct-lrow > a {
873
919
  display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr) minmax(0, 2fr); gap: 4px 20px; align-items: baseline;
874
920
  min-height: 44px; padding: 10px 14px; color: inherit; text-decoration: none; border-radius: 6px;
875
921
  }
876
- .bim-ct-lrow > a:hover { background: ${o("tint-bg")}; }
877
- .bim-ct-lrow > a:hover .bim-ct-lt { color: ${o("accent")}; }
878
- .bim-ct-lrow > a:focus-visible { outline: 2px solid ${o("accent")}; outline-offset: -2px; }
879
- .bim-ct-lt { font-size: 16px; font-weight: 700; color: ${o("ink")}; overflow-wrap: anywhere; }
922
+ .bim-ct-lrow > a:hover { background: ${i("tint-bg")}; }
923
+ .bim-ct-lrow > a:hover .bim-ct-lt { color: ${i("accent")}; }
924
+ .bim-ct-lrow > a:focus-visible { outline: 2px solid ${i("accent")}; outline-offset: -2px; }
925
+ .bim-ct-lt { font-size: 16px; font-weight: 700; color: ${i("ink")}; overflow-wrap: anywhere; }
880
926
  .bim-ct-lt .bim-ct-juan { margin-left: 8px; font-weight: 400; }
881
927
  .bim-ct-lrow .bim-ct-cls { margin: 0; padding: 0; }
882
928
 
@@ -885,21 +931,21 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
885
931
  .bim-ct-pager ol { display: contents; list-style: none; }
886
932
  .bim-ct-pg {
887
933
  display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 34px; padding: 0 10px;
888
- border: 0; border-radius: 6px; background: none; font: inherit; color: ${o("body-fg")};
934
+ border: 0; border-radius: 6px; background: none; font: inherit; color: ${i("body-fg")};
889
935
  text-decoration: none; cursor: pointer;
890
936
  }
891
- .bim-ct-pg:hover { background: ${o("row-hover-bg")}; color: ${o("accent")}; }
892
- .bim-ct-pg:focus-visible { outline: 2px solid ${o("accent")}; outline-offset: 1px; }
893
- .bim-ct-pg[aria-current="page"] { background: ${o("zebra-bg")}; color: ${o("accent")}; font-weight: 700; cursor: default; }
894
- .bim-ct-pg[aria-disabled="true"], .bim-ct-pg:disabled { color: ${o("aux-fg")}; opacity: 0.6; cursor: default; background: none; }
895
- .bim-ct-gap { min-width: 24px; text-align: center; color: ${o("aux-fg")}; }
896
- .bim-ct-pg-of { display: none; padding: 0 12px; color: ${o("body-fg")}; font-variant-numeric: tabular-nums; }
937
+ .bim-ct-pg:hover { background: ${i("row-hover-bg")}; color: ${i("accent")}; }
938
+ .bim-ct-pg:focus-visible { outline: 2px solid ${i("accent")}; outline-offset: 1px; }
939
+ .bim-ct-pg[aria-current="page"] { background: ${i("zebra-bg")}; color: ${i("accent")}; font-weight: 700; cursor: default; }
940
+ .bim-ct-pg[aria-disabled="true"], .bim-ct-pg:disabled { color: ${i("aux-fg")}; opacity: 0.6; cursor: default; background: none; }
941
+ .bim-ct-gap { min-width: 24px; text-align: center; color: ${i("aux-fg")}; }
942
+ .bim-ct-pg-of { display: none; padding: 0 12px; color: ${i("body-fg")}; font-variant-numeric: tabular-nums; }
897
943
 
898
944
  @media (max-width: 1199px) {
899
945
  .bim-ct-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
900
946
  }
901
947
 
902
- @media ${Gi} {
948
+ @media ${Ui} {
903
949
  .bim-ct { display: block; padding: 12px 16px 40px; }
904
950
  .bim-ct-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
905
951
  .bim-ct-lrow > a { grid-template-columns: minmax(0, 1fr); }
@@ -908,14 +954,14 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
908
954
  .bim-ct-side-h { display: none; }
909
955
  .bim-ct-drawer-btn {
910
956
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 0 14px;
911
- border: 0; border-radius: 8px; background: ${o("tint-bg")};
912
- font: inherit; font-size: 14px; color: ${o("ink")}; text-align: left; cursor: pointer;
957
+ border: 0; border-radius: 8px; background: ${i("tint-bg")};
958
+ font: inherit; font-size: 14px; color: ${i("ink")}; text-align: left; cursor: pointer;
913
959
  }
914
960
  .bim-ct-drawer-btn span { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
915
- .bim-ct-drawer-btn svg { flex: none; transition: transform 0.15s; color: ${o("aux-fg")}; }
961
+ .bim-ct-drawer-btn svg { flex: none; transition: transform 0.15s; color: ${i("aux-fg")}; }
916
962
  .bim-ct-drawer-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
917
- .bim-ct-drawer-btn:focus-visible { outline: 2px solid ${o("accent")}; outline-offset: 2px; }
918
- .bim-ct-drawer { margin-top: 6px; padding: 6px; border-radius: 8px; background: ${o("card-bg")}; max-height: 70vh; overflow-y: auto; }
963
+ .bim-ct-drawer-btn:focus-visible { outline: 2px solid ${i("accent")}; outline-offset: 2px; }
964
+ .bim-ct-drawer { margin-top: 6px; padding: 6px; border-radius: 8px; background: ${i("card-bg")}; max-height: 70vh; overflow-y: auto; }
919
965
  .bim-ct[data-drawer="closed"] .bim-ct-drawer { display: none; }
920
966
  .bim-ct-title { font-size: 18px; }
921
967
  .bim-ct-pager { flex-wrap: nowrap; justify-content: space-between; }
@@ -924,9 +970,9 @@ ${gc}`;function Ht({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
924
970
  }
925
971
 
926
972
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
927
- @media ${ix} {
973
+ @media ${rx} {
928
974
  .bim-ct-row { min-height: 44px; }
929
975
  .bim-ct-tw { width: 44px; }
930
976
  .bim-ct-pg { min-width: 44px; height: 44px; }
931
977
  }
932
- `,qt="未分類",rt="all",Ui=20;function tn(e){if(!e)return[];const n=[];for(const i of[e.l1,e.l2,e.l3,e.l4]){const r=(i??"").trim();if(!r)break;n.push(r)}return n}function ox(e){const n=tn(e);return n.length?n.join("/"):qt}function rx(e){const n=tn(e);return n.length?n.map((i,r)=>n.slice(0,r+1).join("/")):[qt]}function sx(e,n=[]){const i=new Map;n.forEach((p,c)=>{const d=[p.cata_l1,p.cata_l2,p.cata_l3,p.cata_l4].filter(u=>!!u);d.forEach((u,g)=>{const x=d.slice(0,g+1).join("/");i.has(x)||i.set(x,c)})});const r=new Map;let s=0;for(const p of e){const c=tn(p.classification);if(!c.length){s++;continue}let d=r;c.forEach((u,g)=>{const x=c.slice(0,g+1).join("/");let m=d.get(u);m||(m={id:x,label:u,count:0,children:new Map},d.set(u,m)),m.count++,d=m.children})}const l=p=>[...p.values()].sort((c,d)=>{const u=i.get(c.id)??1/0,g=i.get(d.id)??1/0;return u!==g?u-g:c.label.localeCompare(d.label,"zh")}).map(c=>{const d={id:c.id,label:c.label,count:c.count};return c.children.size&&(d.children=l(c.children)),d}),a=l(r);return s>0&&a.push({id:qt,label:qt,count:s}),a}function zt(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const r=zt(i.children,n);if(r.length)return[i,...r]}}return[]}function Vi(e){return e.reduce((n,i)=>n+i.count,0)}function lx(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function ax(e){var p;const n={id:e.id,title:e.title||e.id},i=e.juan_count,r=typeof i=="number"?i:i==null?void 0:i.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(c=>c==null?void 0:c.name).map(c=>{const d=c.dynasty||(e.authors.length===1?e.dynasty:void 0);return d?{name:c.name,dynasty:d}:{name:c.name}});s.length&&(n.authors=s);const l=lx(typeof e.description=="string"?e.description:(p=e.description)==null?void 0:p.text);l&&(n.summary=l);const a=tn(e.classification);return a.length&&(n.classification=a),n}function cx(e,n){const i=e.summary?0:1,r=n.summary?0:1;return i!==r?i-r:e.title.localeCompare(n.title,"zh")}function dx(e,n=Ui){return Math.max(1,Math.ceil(e/n))}function cl(e,n,i=2){if(n<=1)return[1];const r=new Set([1,n]);for(let a=e-i;a<=e+i;a++)a>=1&&a<=n&&r.add(a);const s=[...r].sort((a,p)=>a-p),l=[];return s.forEach((a,p)=>{if(p>0){const c=a-s[p-1];c===2?l.push(a-1):c>2&&l.push(null)}l.push(a)}),l}const px=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function ux(e,n,i){const r=[];i&&r.push({id:rt,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,a)=>{var p;for(const c of l){const d=(p=c.children)!=null&&p.length?c.children:null;r.push({id:c.id,parentId:a,hasChildren:!!d,firstChildId:d?d[0].id:null}),d&&n.has(c.id)&&s(d,c.id)}};return s(e,null),r}function dl({tree:e,selectedId:n,onSelect:i,allLabel:r="全部",label:s="分類"}){const{convert:l}=q(),a=f.useRef(null),p=n&&n!==rt?n:null,c=r!==null,[d,u]=f.useState(()=>{const v=new Set;for(const _ of zt(e,p))v.add(_.id);return v});f.useEffect(()=>{const v=zt(e,p);v.length&&u(_=>{if(v.every(z=>_.has(z.id)))return _;const w=new Set(_);for(const z of v)w.add(z.id);return w})},[e,p]);const g=f.useMemo(()=>ux(e,d,c),[e,d,c]),[x,m]=f.useState(null);f.useEffect(()=>{m(null)},[n]);const b=p??(c?rt:null),S=f.useMemo(()=>{var w;const v=new Set(g.map(z=>z.id));if(x&&v.has(x))return x;if(b&&v.has(b))return b;const _=zt(e,p).map(z=>z.id).filter(z=>v.has(z));return _.length?_[_.length-1]:((w=g[0])==null?void 0:w.id)??null},[g,x,b,e,p]),h=f.useCallback((v,_)=>{u(w=>{const z=w.has(v),N=_??!z;if(N===z)return w;const T=new Set(w);return N?T.add(v):T.delete(v),T})},[]),y=f.useCallback(v=>{m(v),requestAnimationFrame(()=>{var w;const _=Array.from(((w=a.current)==null?void 0:w.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===v);_==null||_.focus()})},[]),j=f.useCallback((v,_)=>{_&&h(v,!0),i(v)},[i,h]),k=f.useCallback(v=>{const _=v.target.closest("[data-ct-id]");if(!_)return;const w=_.dataset.ctId,z=g.findIndex(C=>C.id===w);if(z<0)return;const N=g[z];let T=null;switch(v.key){case"ArrowDown":T=g[Math.min(g.length-1,z+1)].id;break;case"ArrowUp":T=g[Math.max(0,z-1)].id;break;case"Home":T=g[0].id;break;case"End":T=g[g.length-1].id;break;case"ArrowRight":if(!N.hasChildren)break;d.has(w)?T=N.firstChildId:h(w,!0);break;case"ArrowLeft":N.hasChildren&&d.has(w)?h(w,!1):T=N.parentId;break;case"Enter":case" ":v.preventDefault(),j(w,N.hasChildren);return;default:return}v.preventDefault(),T&&T!==w&&y(T)},[g,d,h,y,j]),$=(v,_)=>v.map((w,z)=>{var B;const N=(B=w.children)!=null&&B.length?w.children:null,T=!!N&&d.has(w.id),C=w.id===p,P=_===1&&v.length>1&&z===v.length-1;return t.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":N?T:void 0,"aria-selected":C,tabIndex:S===w.id?0:-1,"data-ct-id":w.id,className:P?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{m(w.id),j(w.id,!!N)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:N?A=>{A.stopPropagation(),m(w.id),h(w.id)}:void 0,children:N?t.jsx(px,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(w.label)}),t.jsx("span",{className:"bim-ct-n",children:w.count.toLocaleString("en-US")})]}),T&&t.jsx("ul",{role:"group",children:$(N,_+1)})]},w.id)});return t.jsxs("ul",{ref:a,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:k,children:[c&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:S===rt?0:-1,"data-ct-id":rt,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{m(rt),i(rt)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),t.jsx("span",{className:"bim-ct-lb",children:l(r)}),t.jsx("span",{className:"bim-ct-n",children:Vi(e).toLocaleString("en-US")})]})}),$(e,1)]})}const pl=e=>`/item/${encodeURIComponent(e)}`;function xx(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function ul(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function xl({work:e,href:n}){var a,p;const{convert:i}=q(),r=ul(e.juan),s=((a=e.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:n,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:i(e.title)}),r&&t.jsx("span",{className:"bim-ct-juan",children:i(r)})]}),s.length>0&&t.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>t.jsxs(f.Fragment,{children:[d>0&&"、",c.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(c.dynasty),"〕"]}),i(c.name)]},d))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:i(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(c=>i(c)).join(" · ")})]})})}function fl({work:e,href:n}){var a,p;const{convert:i}=q(),r=ul(e.juan),s=((a=e.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-lrow",children:t.jsxs("a",{href:n,children:[t.jsxs("span",{className:"bim-ct-lt",children:[i(e.title),r&&t.jsx("span",{className:"bim-ct-juan",children:i(r)})]}),t.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>t.jsxs(f.Fragment,{children:[d>0&&"、",c.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(c.dynasty),"〕"]}),i(c.name)]},d))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(c=>i(c)).join(" · ")})]})})}function gl({page:e,pageCount:n,onPage:i,pageHref:r,label:s="分頁"}){const{convert:l}=q();if(n<=1)return null;const a=c=>d=>{i&&(r&&!xx(d)||(d.preventDefault(),i(c)))},p=(c,d,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const g={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...g,href:r(c),onClick:a(c),children:d}):t.jsx("button",{type:"button",...g,onClick:u.current?void 0:a(c),children:d})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:cl(e,n).map((c,d)=>t.jsx("li",{style:{display:"contents"},children:c===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(c,c,{current:c===e,aria:l(`第 ${c} 頁`)})},c??`gap${d}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),p(e+1,l("下一頁"),{disabled:e>=n})]})}function ml({works:e,workLink:n=pl,emptyText:i="此類暫無作品",view:r="card",...s}){const{convert:l}=q();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:typeof i=="string"?l(i):i}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(a=>t.jsx(fl,{work:a,href:n(a.id)},a.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(a=>t.jsx(xl,{work:a,href:n(a.id)},a.id))}),t.jsx(gl,{...s})]})}const fx=()=>t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:t.jsx("path",{d:"M2.5 4.5 6 8l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function gx({tree:e,selectedId:n,page:i,pageCount:r,works:s,onSelect:l,onPage:a,searchSlot:p,workLink:c,pageHref:d,allLabel:u="全部",allTitle:g="全部典籍",pageSize:x=Ui,className:m,view:b,onViewChange:S}){const{convert:h}=q(),j=`bim-ct-drawer-${f.useId().replace(/:/g,"")}`,[k,$]=f.useState(!1),[v,_]=f.useState("card"),w=b??v,z=A=>{_(A),S==null||S(A)},N=zt(e,n&&n!==rt?n:null),T=N.length?N[N.length-1]:null,C=T?T.label:g,P=T?T.count:Vi(e),B=f.useCallback(A=>{$(!1),l(A)},[l]);return t.jsxs("div",{className:m?`bim-ct ${m}`:"bim-ct","data-drawer":k?"open":"closed",children:[t.jsx("style",{children:al}),t.jsxs("aside",{className:"bim-ct-side","aria-label":h("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":k,"aria-controls":j,onClick:()=>$(A=>!A),children:[t.jsxs("span",{children:[h("分類"),":",h(N.length?N.map(A=>A.label).join(" › "):u??g)]}),t.jsx(fx,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:j,children:[t.jsx("h2",{className:"bim-ct-side-h",children:h("分類")}),t.jsx(dl,{tree:e,selectedId:n,onSelect:B,allLabel:u})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:h(C)}),N.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:h(N.slice(0,-1).map(A=>A.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[h(`共 ${P.toLocaleString("en-US")} 種 · 每頁 ${x} 條`),r>1&&h(` · 第 ${i} / ${r} 頁`)]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":h("呈現方式"),children:[t.jsx("button",{type:"button","aria-pressed":w==="card",onClick:()=>z("card"),children:h("卡片")}),t.jsx("button",{type:"button","aria-pressed":w==="list",onClick:()=>z("list"),children:h("列表")})]})]}),p&&t.jsx("div",{className:"bim-ct-search",children:p}),t.jsx(ml,{works:s,view:w,workLink:c,page:i,pageCount:r,onPage:a,pageHref:d})]})]})}const li=({style:e})=>{const n=f.useContext(Rt);if(!n)return null;const{locale:i,setLocale:r}=n,s=i==="zh-Hant",l=()=>r(s?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:`1px solid ${o("border")}`,borderRadius:"4px",background:o("bg"),color:o("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:s?o("primary"):void 0,fontWeight:s?700:400},children:"繁"}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:s?void 0:o("primary"),fontWeight:s?400:700},children:"简"})]})},ai=({href:e,label:n="在 GitHub 查看本条目源文件",size:i=16,className:r,style:s})=>t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:o("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:l=>{l.currentTarget.style.color=o("fg")},onMouseLeave:l=>{l.currentTarget.style.color=o("desc-fg")},children:t.jsx("svg",{width:i,height:i,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:t.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})});function Dn(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function mx(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const hx=({id:e,transport:n,initialDetail:i,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:a,onJuanChange:p,lineageMode:c="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:g,initialPage:x=1,selectedLineageNodeId:m,onNavigate:b,onBack:S,backLabel:h,renderLink:y,enrichDetail:j,getSourceLink:k,readLink:$,railTop:v,extraTabs:_=[],showFeedbackTab:w=!0,feedbackApiUrl:z,height:N,footerExtra:T,className:C,style:P})=>{var Ki;const B=ue(),{convert:A}=q(),[W]=f.useState(()=>{if(!mx(e,i))return null;const Y={...i},je=r??Dn(e,Y);return j&&j(je,Y),{id:e,entry:je,detail:Y}}),[V,K]=f.useState((W==null?void 0:W.entry)??null),[E,le]=f.useState((W==null?void 0:W.detail)??null),[G,ae]=f.useState(!W),[pe,ee]=f.useState(!1),[X,ie]=f.useState([]),[me,te]=f.useState(!1),[se,fe]=f.useState(null),[be,ze]=f.useState(!1),[ve,ke]=f.useState(null),[Ne,Ee]=f.useState(!1),[O,ce]=f.useState(null),[oe,he]=f.useState([]),[Z,F]=f.useState(!1),[I,D]=f.useState(null),[M,ne]=f.useState(null),[R,J]=f.useState(!1),H=f.useRef(null),[U,re]=f.useState(null),Se=a!==void 0?a:U,ye=f.useCallback(Y=>{p?p(Y):re(Y)},[p]),Le=f.useCallback(async Y=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){ie([]);return}te(!0);try{if(n.getCollectionCatalogs)ie(await n.getCollectionCatalogs(Y)||[]);else if(n.getCollectionCatalog){const je=await n.getCollectionCatalog(Y);ie(je?[{resource_id:"",data:je}]:[])}}catch{ie([])}finally{te(!1)}},[n]),Ye=f.useCallback(async Y=>{if(!n.getCollatedEditionIndex){fe(null);return}ze(!0);try{fe(await n.getCollatedEditionIndex(Y))}catch{fe(null)}finally{ze(!1)}},[n]),L=f.useCallback(async Y=>{if(!n.getBookFullTextIndex){ke(null);return}Ee(!0);try{ke(await n.getBookFullTextIndex(Y))}catch{ke(null)}finally{Ee(!1),ce(Y)}},[n]),de=f.useCallback(async Y=>{var je;if(!n.getWorkFullTextList){he([]);return}F(!0);try{const Ie=(await n.getWorkFullTextList(Y)??[]).filter(Ae=>Ae.owner_type!=="Book");he(Ie),D(((je=Ie.find(Ae=>Ae.primary)??Ie[0])==null?void 0:je.key)??null)}catch{he([])}finally{F(!1)}},[n]),ge=f.useCallback(async(Y,je)=>{J(!0);try{if(n.getLineageGraph){const De=await n.getLineageGraph(Y);De&&ne(De)}const Ie=je.version_graph;if(!Ie||!Ie.enabled){M||ne(null),H.current=null;return}const Ae=je.books??[],Xe=[];for(const De of Ae)try{const Qe=await n.getItem(De);Qe&&Xe.push(Qe)}catch{}H.current={work:je,books:Xe};const Q=u??Ie.default_collection??(Ie.core_books&&Ie.core_books.length>0?"core":"all"),Te=Q==="core"&&Array.isArray(Ie.core_books)&&Ie.core_books.length>0?"core":Q??"all";ne(xn(je,Xe,Te))}catch{ne(null),H.current=null}finally{J(!1)}},[n]),$e=f.useRef({initialDetail:i,initialEntry:r});$e.current={initialDetail:i,initialEntry:r},f.useEffect(()=>{let Y=!1;const je=Q=>{Q.type==="collection"?Le(e):Q.type==="work"?(Q.has_collated&&Ye(e),(Q.version_graph||n.getLineageGraph)&&ge(e,Q),n.getWorkFullTextList&&de(e)):Q.type==="book"&&Q.has_full_text&&n.getBookFullTextIndex&&L(e)},Ie=$e.current;let Ae=null;if(W&&W.id===e)Ae=W;else if(Ie.initialDetail&&Ie.initialDetail.id===e){const Q={...Ie.initialDetail},Te=Ie.initialEntry??Dn(e,Q);j&&j(Te,Q),Ae={entry:Te,detail:Q}}return Ae?(ee(!1),ie(Q=>Q.length?[]:Q),fe(null),ke(null),he(Q=>Q.length?[]:Q),D(null),ne(null),H.current=null,K(Ae.entry),le(Ae.detail),ae(!1),je(Ae.detail),()=>{Y=!0}):((async()=>{ae(!0),ee(!1),K(null),le(null),ie([]),fe(null),ke(null),he([]),D(null),ne(null),H.current=null;try{const Q=await n.getItem(e);if(Y)return;if(!Q){ee(!0);return}const Te=Q;let De=null;if(n.getEntry&&(De=await n.getEntry(e),Y))return;De||(De=Dn(e,Te)),j&&j(De,Te),K(De),le(Te),je(Te)}catch{Y||ee(!0)}finally{Y||ae(!1)}})(),()=>{Y=!0})},[e,n,W,j,Le,Ye,ge,L,de]),f.useEffect(()=>{const Y=H.current;!Y||!u||ne(xn(Y.work,Y.books,u))},[u]);const xe=[];if(E){if(xe.push({key:"basic",label:B.detailTab.basicInfo}),E.type==="collection"){me&&X.length===0&&xe.push({key:"catalog:loading",label:`${B.detailTab.catalog}…`});for(const Y of X)xe.push({key:`catalog:${Y.resource_id}`,label:Y.short_name?`${A(Y.short_name)}${B.detailTab.catalogSuffix}`:B.detailTab.collectionCatalog})}E.type==="work"&&(se||be)&&s==="collated"&&xe.push({key:"collated",label:be?`${B.detailTab.collatedEdition}…`:B.detailTab.collatedEdition}),E.type==="book"&&(ve||Ne)&&s==="fulltext"&&xe.push({key:"fulltext",label:Ne?`${B.detailTab.fullText}…`:B.detailTab.fullText}),E.type==="work"&&(oe.length>0||Z)&&s==="fulltext"&&xe.push({key:"fulltext",label:Z?`${B.detailTab.fullText}…`:B.detailTab.fullText}),E.type==="work"&&(M||R)&&xe.push({key:"lineage",label:R?`${B.detailTab.lineage}…`:B.detailTab.lineage});for(const Y of _)(Y.position??"before-feedback")==="before-feedback"&&Y.shouldShow(E)&&xe.push({key:Y.key,label:Y.label});w&&s==="feedback"&&xe.push({key:"feedback",label:B.detailTab.feedback});for(const Y of _)Y.position==="after-feedback"&&Y.shouldShow(E)&&xe.push({key:Y.key,label:Y.label})}f.useEffect(()=>{if(s!=="emendated"||!E)return;l("basic");const Y=setTimeout(()=>{var je;(je=document.getElementById("studies"))==null||je.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(Y)},[s,E,l]);const Ce=V&&E&&k?k({activeTab:s,activeJuan:Se,entry:V,detail:E}):null,Oe=f.useMemo(()=>{var Xe;if(!E)return null;const je=(E.authors??[]).map(Q=>{const Te=ji(Q.role);return`${Q.dynasty?`〔${A(Q.dynasty)}〕`:""}${A(Q.name)}${Te?` ${A(Te)}`:""}`}).join(" · ");let Ie=!1;try{Ie=we.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const Q=E;return{title:A(Q.title),subtitle:Q.edition?A(Q.edition):je||void 0,aside:[Ie?B.status.draft:"",je&&Q.edition?je:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const Q=E;return{title:A(Q.title),subtitle:A(at(Q,B.unit.juan))||void 0,aside:[(Xe=Q.publication_info)==null?void 0:Xe.year,Ie?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:je||void 0}}if(E.type==="entity"){const Q=E,Te=Qe=>Qe==null?"":Qe<0?`前${-Qe}`:String(Qe),De=Q.birth_year!=null||Q.death_year!=null?`${Te(Q.birth_year)||"?"}—${Te(Q.death_year)||"?"}`:"";return{title:A(Q.primary_name||Q.title),subtitle:[Q.dynasty?`〔${A(Q.dynasty)}〕`:"",De].filter(Boolean).join(" ")||void 0,aside:Ie?B.status.draft:void 0,secondLine:void 0}}const Ae=A(at(E,B.unit.juan));return{title:A(E.title),subtitle:[Ae,je].filter(Boolean).join(" · ")||void 0,aside:[yx(B,E.subtype),Ie?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,A,B]),Je=E?E.type==="work"?(((Ki=se==null?void 0:se.juan_files)==null?void 0:Ki.length)??0)>0?"collated":oe.length>0?"fulltext":null:E.type==="book"&&(((ve==null?void 0:ve.chapters.length)??0)>0||E.has_full_text&&n.getBookFullTextIndex&&O!==E.id)?"fulltext":null:null,ct=oe.find(Y=>Y.primary)??oe[0],nn=()=>{var Y;Je==="collated"&&((Y=se==null?void 0:se.juan_files)!=null&&Y.length)?(ye(se.juan_files[0]),l("collated")):Je==="fulltext"&&((E==null?void 0:E.type)==="work"&&ct&&D(ct.key),ye(null),l("fulltext"))};let dt=null;if(E&&$){const Y=$({detail:E,kind:Je,fullTextKey:E.type==="work"?ct==null?void 0:ct.key:void 0});Y&&(dt=t.jsx(Kn,{href:Y}))}else Je&&(dt=t.jsx(Kn,{onClick:nn}));const on=Y=>{if(!E)return null;const je=Y.replace(/\.[^.]+$/,"");if($){const Ie=$({detail:E,kind:"fulltext",juan:je});return Ie?{href:Ie}:null}return{onClick:()=>{ye(je),l("fulltext")}}},rn=new Set(_.map(Y=>Y.key)),_e=xe.filter(Y=>Y.key.startsWith("catalog:")&&Y.key!=="catalog:loading"||rn.has(Y.key)).map(Y=>({key:Y.key,label:Y.label,onClick:()=>l(Y.key)})),Ze=()=>{var Y;return E?E.type==="work"?t.jsx(tl,{data:E,transport:n,onNavigate:b,renderLink:y,readAction:dt,railTop:v,railLinks:_e}):E.type==="book"?t.jsx(rl,{data:E,transport:n,onNavigate:b,renderLink:y,readAction:dt,fullText:ve,fullTextPending:!!E.has_full_text&&!!n.getBookFullTextIndex&&O!==E.id,chapterLink:on,railTop:v,railLinks:_e}):E.type==="collection"?t.jsx(sl,{data:E,catalog:(Y=X[0])==null?void 0:Y.data,transport:n,onNavigate:b,renderLink:y,readAction:dt,railTop:v,railLinks:_e,catalogAction:X.length>0?t.jsxs("a",{href:"#catalog",onClick:je=>{je.preventDefault(),l(`catalog:${X[0].resource_id}`)},children:[A(B.detailTab.collectionCatalog)," →"]}):null}):t.jsx(ll,{data:E,transport:n,onNavigate:b,renderLink:y,railTop:v,railLinks:_e}):null},Re=()=>{var je,Ie,Ae,Xe;if(!V||!E)return null;if(s==="basic"||s==="emendated")return Ze();if(typeof s=="string"&&s.startsWith("catalog:")){const Q=(je=X.find(Te=>`catalog:${Te.resource_id}`===s))==null?void 0:je.data;return t.jsx(gi,{data:Q,onNavigate:b,renderLink:y})}if(s==="collated")return t.jsx(Fi,{index:se||void 0,workId:e,transport:n,onNavigate:b,activeJuan:Se,onJuanChange:ye});if(s==="fulltext"&&E.type==="work"){const Q=I??((Ie=oe[0])==null?void 0:Ie.key);return Q?t.jsx(ni,{bookId:e,workKey:Q,versions:oe,onVersionChange:Te=>{D(Te),ye(null)},transport:n,activeChapter:Se,onChapterChange:ye},Q):t.jsx("div",{style:{padding:24,color:o("desc-fg")},children:Z?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(ni,{index:ve||void 0,bookId:e,transport:n,activeChapter:Se,onChapterChange:ye});if(s==="lineage"){if(!M)return t.jsx("div",{style:{color:o("label-fg"),padding:"24px 0"},children:R?"加載中…":"暫無版本圖數據"});const Q=E.type==="work"?E:null;return t.jsx(Hi,{graph:M,renderLink:y,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:d,selectedNodeId:m,collection:u??((Ae=Q==null?void 0:Q.version_graph)==null?void 0:Ae.default_collection),onCollectionChange:g,collectionsAvailable:(Xe=Q==null?void 0:Q.version_graph)==null?void 0:Xe.collections,collectionCounts:(()=>{var Ji,Zi,Xi,Qi,eo,to,no;if(!Q)return;const Te={},De=((Ji=H.current)==null?void 0:Ji.books)??[];Te.all=(((Zi=Q.books)==null?void 0:Zi.length)??0)-(((Qi=(Xi=Q.version_graph)==null?void 0:Xi.excluded_books)==null?void 0:Qi.length)??0);const Qe=(eo=Q.version_graph)==null?void 0:eo.collections;if(Qe)for(const io of Object.keys(Qe))Te[io]=xn(Q,De,io).nodes.filter(oo=>oo.kind==="book"&&!oo.bridge).length;return Te.core==null&&((no=(to=Q.version_graph)==null?void 0:to.core_books)!=null&&no.length)&&(Te.core=Q.version_graph.core_books.length),Te})()})}if(s==="feedback"&&w)return t.jsx(Zs,{resourceId:e,apiUrl:z});const Y=_.find(Q=>Q.key===s);return Y?Y.render({detail:E,entry:V,transport:n,onNavigate:b}):null};if(G)return t.jsx(Ht,{style:{minHeight:N,...P},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((Y,je)=>t.jsx("div",{style:{height:je===1?40:16,width:Y,opacity:.35,background:o("rule")}},je))})});if(pe||!E||!V||!Oe)return t.jsx(Ht,{style:{minHeight:N,...P},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:o("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const kt=s==="basic"||s==="emendated",sn=[{label:h??B.detailTab.backToIndex,onClick:S}];if(E.type==="book"&&E.work_id){const Y=E.work_id;sn.push({label:B.indexType.work,id:Y,onClick:()=>b==null?void 0:b(Y)})}sn.push({label:B.indexType[E.type]});const ln=s==="collated"||s==="fulltext",Yi=typeof T=="string"?B.status[T.trim()]??T:T,qi=t.jsx(ds,{left:t.jsxs(t.Fragment,{children:[Yi,Yi?" · ":"",t.jsx(bx,{id:E.id,label:B.label.id,copied:B.action.copied,copyLabel:B.action.copy})]}),right:t.jsxs(t.Fragment,{children:[w&&!kt&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:B.detailTab.submitVersion}),Ce&&t.jsx("a",{href:Ce.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:o("meta-fg")},children:B.detailTab.dataLicense})]})});return kt?t.jsx("div",{className:C,children:t.jsxs(Ht,{grid:!0,style:{minHeight:N,...P},children:[t.jsx(Jn,{breadcrumb:t.jsx(Zn,{items:sn}),actions:t.jsxs(t.Fragment,{children:[t.jsx(li,{style:{border:"none",background:"transparent"}}),Ce&&t.jsx(ai,{...Ce})]})}),Ze(),qi]})}):t.jsx("div",{className:C,children:t.jsxs(Ht,{wide:ln,style:{minHeight:N,...P},children:[t.jsx(Jn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(ki,{char:"籍"}),t.jsx(Zn,{items:sn})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(li,{}),w&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:B.detailTab.feedback}),Ce&&t.jsx(ai,{...Ce})]})}),t.jsx(ts,{...Oe,aside:ln?t.jsxs("button",{type:"button",onClick:()=>l("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("accent"),borderBottom:`1px solid ${o("rule")}`},children:[A("作品信息")," →"]}):Oe.aside}),!ln&&xe.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:xe.map(Y=>t.jsx(ns,{label:Y.label,active:Y.key===s||kt&&Y.key==="basic",onClick:()=>l(Y.key)},Y.key))}),t.jsx("div",{style:{marginTop:!ln&&xe.length>1?8:0},children:Re()}),qi]})})};function bx({id:e,label:n,copied:i,copyLabel:r}){const[s,l]=f.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var a;(a=navigator.clipboard)==null||a.writeText(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?i:r,"aria-label":s?i:r,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:o("aux-fg")},children:s?"✓":"⧉"})]})}function yx(e,n){return n?e.workSubtype[n]??n:""}const hl=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛藍"}],Cn="zhusha",In="bim-theme";function bl(e){return e==="zhusha"||e==="indigo"}function Tn(e){return bl(e)?e:Cn}function jx(){try{return Tn(window.localStorage.getItem(In))}catch{return Cn}}function yl(e){try{window.localStorage.setItem(In,e)}catch{}}function jl(e){const n=Tn(e);return document.documentElement.setAttribute("data-theme",n),n}function vl(){return Tn(document.documentElement.getAttribute("data-theme"))}const vx=`try{if(localStorage.getItem(${JSON.stringify(In)})==='indigo')document.documentElement.setAttribute('data-theme','indigo')}catch(e){}`,kx={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo"},Sx=({onChange:e,style:n})=>{const{convert:i}=q(),[r,s]=f.useState(Cn);f.useEffect(()=>{s(vl())},[]);const l=a=>{s(jl(a)),yl(a),e==null||e(a)};return t.jsx("div",{role:"radiogroup","aria-label":i("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:hl.map(a=>{const p=r===a.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":p,"aria-label":i(a.label),title:i(a.label),onClick:()=>l(a.name),style:{width:28,height:44,padding:0,border:0,background:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:t.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:"50%",boxSizing:"border-box",background:o(kx[a.name]),boxShadow:p?`0 0 0 2px ${o("page-bg")}, 0 0 0 3.5px ${o("aux-fg")}`:"none"}})},a.name)})})};exports.BidLink=we.BidLink;exports.BookIndexError=we.BookIndexError;exports.BookIndexManager=we.BookIndexManager;exports.BookIndexStorage=we.BookIndexStorage;exports.BundleStorage=we.BundleStorage;exports.ConfigError=we.ConfigError;exports.GithubStorage=we.GithubStorage;exports.IdGenerationError=we.IdGenerationError;exports.IdGenerator=we.IdGenerator;exports.LocalStorage=we.LocalStorage;exports.MigrationError=we.MigrationError;exports.StorageError=we.StorageError;exports.base36Decode=we.base36Decode;exports.base36Encode=we.base36Encode;exports.base58Decode=we.base58Decode;exports.buildId=we.buildId;exports.buildPromotionMap=we.buildPromotionMap;exports.cleanName=we.cleanName;exports.decodeId=we.decodeId;exports.decodeIdString=we.decodeIdString;exports.encodeId=we.encodeId;exports.extractIdFromUrl=we.extractIdFromUrl;exports.extractStatus=we.extractStatus;exports.extractType=we.extractType;exports.normalizeCatalog=we.normalizeCatalog;exports.parseId=we.parseId;exports.shardOf=we.shardOf;exports.smartDecode=we.smartDecode;exports.validateResource=we.validateResource;exports.Badge=hn;exports.BidUrlProvider=Rl;exports.BookDetailLayout=hx;exports.BookFullText=ni;exports.BookPage=rl;exports.Breadcrumb=Zn;exports.CATALOG_ALL_ID=rt;exports.CATALOG_CSS=al;exports.CATALOG_NARROW_QUERY=Gi;exports.CATALOG_PAGE_SIZE=Ui;exports.CATALOG_UNCLASSIFIED_ID=qt;exports.CardFoot=Qt;exports.CatalogPage=gx;exports.CatalogPager=gl;exports.CatalogTree=dl;exports.CheckFilter=Qr;exports.Chip=is;exports.ChipWall=wc;exports.CollatedEdition=Fi;exports.CollectionCatalog=gi;exports.CollectionPage=sl;exports.CreateEntityDialog=Hs;exports.DEFAULT_READER_PREFS=_i;exports.DEFAULT_THEME=Cn;exports.DETAIL_CSS=es;exports.Dash=Tc;exports.DataTable=$c;exports.DetailFooter=ds;exports.DetailGrid=Zt;exports.DetailHeader=ts;exports.EmendatedBySection=Br;exports.EmptyNote=Wc;exports.EntityDetail=Ir;exports.EntityPage=ll;exports.EntityPickerDialog=Us;exports.EntitySelector=Ds;exports.ExpandRow=Ec;exports.ExtLink=Mc;exports.FEEDBACK_FAB_OFFSET_VAR=oi;exports.FONT_SIZE_STEPS=$t;exports.FactList=jc;exports.FeedbackButton=su;exports.FeedbackDialog=Ks;exports.FeedbackForm=Js;exports.FeedbackList=Pi;exports.FeedbackTab=Zs;exports.FilterChip=ns;exports.FormInput=Ge;exports.FormTextArea=bt;exports.GUJI_MARKDOWN_FIELD=sc;exports.GUJI_TABLE_NOTATION=vs;exports.GlyphBadge=ki;exports.GujiTable=Ii;exports.HomePage=ti;exports.ImagePanel=ms;exports.IndexApp=pp;exports.IndexBrowser=Un;exports.IndexDetail=fi;exports.IndexEditor=Vs;exports.IndexView=Yp;exports.IntroGrid=yc;exports.LocaleContext=Rt;exports.LocaleProvider=Vl;exports.LocaleToggle=li;exports.MetaLine=Me;exports.ModeIndicator=$r;exports.MoreButton=Sc;exports.MoreLink=Bt;exports.PAGE_MAX_WIDTH=pn;exports.PageFrame=Ht;exports.Quote=Nc;exports.READER_CSS=xs;exports.RECENT_IDS_STORAGE_KEY=Ct;exports.ROLE_CLASS_ORDER=Dr;exports.ReadButton=Kn;exports.ReaderMdText=Ni;exports.ReaderShell=zi;exports.ReaderToc=gs;exports.RelationPanel=Ps;exports.RepoSourceLink=ai;exports.ResourceEditor=Gn;exports.ResourceGroup=Lc;exports.ResourceLine=Bc;exports.ResourceList=xi;exports.ResourceRow=as;exports.SNIPPET_MARK_END=yr;exports.SNIPPET_MARK_START=br;exports.SearchInput=zr;exports.Sec=Fe;exports.Section=qe;exports.SectionHead=vc;exports.SideList=ht;exports.SmartBidInput=un;exports.SourceEditor=Ws;exports.SummaryCard=Xt;exports.THEMES=hl;exports.THEME_INIT_SCRIPT=vx;exports.THEME_STORAGE_KEY=In;exports.TabFilter=_n;exports.TableHead=zc;exports.TableRow=Cc;exports.TagRow=cs;exports.TagRows=Ac;exports.TextButton=kc;exports.ThemeToggle=Sx;exports.TopStrip=Jn;exports.VersionLineageGraph=ol;exports.VersionLineageList=il;exports.VersionLineageView=Hi;exports.VolumeChips=_c;exports.VolumeLinks=Si;exports.WorkCard=xl;exports.WorkCardGrid=ml;exports.WorkCatalog=up;exports.WorkPage=tl;exports.WorkRow=fl;exports.applyTheme=jl;exports.bucketResources=bi;exports.buildCatalogTree=sx;exports.buildCollectionTable=Gr;exports.buildLineageGraph=xn;exports.buildPageUrl=ui;exports.buildParagraphBlocks=Is;exports.buildVersionRow=Pr;exports.buildVersionTable=Or;exports.canParagraphize=zn;exports.catalogNodeIdOf=ox;exports.catalogNodeIdsOf=rx;exports.catalogPageCount=dx;exports.catalogTotal=Vi;exports.classificationPath=tn;exports.compareCatalogCards=cx;exports.computeVersionPartition=nc;exports.currentTheme=vl;exports.defaultWorkLink=pl;exports.deriveDating=Qa;exports.deriveEditionType=Vr;exports.deriveEra=Jt;exports.deriveYear=kn;exports.deriveYearRange=hi;exports.detailToEditor=qs;exports.detectGenre=$n;exports.displayAuthorRole=ji;exports.editorToDetail=Vp;exports.eraRank=Yn;exports.findCatalogPath=zt;exports.flattenTitles=Xn;exports.flattenToc=js;exports.formatTemplate=Kt;exports.formatVolumeRange=wn;exports.getDisplayNameFromUrl=Nt;exports.getStartPage=pi;exports.getTypeGroupKey=ci;exports.groupRelatedWorks=ec;exports.gujiInlineToPlain=Jr;exports.hasGujiMarkdownV02=qn;exports.hasGujiTableNotation=ks;exports.isThemeName=bl;exports.measureText=at;exports.mergeVolumeResources=di;exports.normalizeEra=We;exports.normalizeRole=yi;exports.normalizeTheme=Tn;exports.normalizeVolumeIndex=Ut;exports.normalizeVolumes=_r;exports.numberToChinese=Ur;exports.paginationItems=cl;exports.parseChineseNumber=fn;exports.parseGujiInline=Kr;exports.parseGujiTable=ws;exports.parseSourceString=Ms;exports.pickReaderVersion=ys;exports.readStoredTheme=jx;exports.readerVersionOptionLabel=ei;exports.readerVersionsFromFullText=bs;exports.renderFullTextBody=ld;exports.renderProperNames=Es;exports.renderReaderInline=Ri;exports.resourceHref=Lt;exports.resourceNote=Sn;exports.roleFacets=Hr;exports.rowNo=Ic;exports.sortYear=gn;exports.splitFullTextTables=Ci;exports.splitHighlightSnippet=jr;exports.splitTableRow=Ss;exports.storeTheme=yl;exports.stringifySources=Fs;exports.toCatalogWorkCard=ax;exports.useBidUrl=Pe;exports.useConvert=q;exports.useReaderPrefs=$i;exports.useT=ue;exports.validateLineageGraph=zu;exports.volumeStats=bn;
978
+ `,Kt="未分類",rt="all",Vi=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 sx(e){const n=nn(e);return n.length?n.join("/"):Kt}function lx(e){const n=nn(e);return n.length?n.map((o,r)=>n.slice(0,r+1).join("/")):[Kt]}function ax(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:Kt,label:Kt,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 Yi(e){return e.reduce((n,o)=>n+o.count,0)}function cx(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function dx(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=cx(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 px(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 ux(e,n=Vi){return Math.max(1,Math.ceil(e/n))}function dl(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 xx=()=>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 fx(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 pl({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(()=>fx(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(xx,{}):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:Yi(e).toLocaleString("en-US")})]})}),$(e,1)]})}const ul=e=>`/item/${encodeURIComponent(e)}`;function gx(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function xl(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function fl({work:e,href:n}){var d,p;const{convert:o}=Z(),r=xl(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 gl({work:e,href:n}){var d,p;const{convert:o}=Z(),r=xl(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 ml({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&&!gx(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:dl(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 hl({works:e,workLink:n=ul,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(gl,{work:d,href:n(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(fl,{work:d,href:n(d.id)},d.id))}),t.jsx(ml,{...s})]})}const mx=()=>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 hx({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=Vi,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:Yi(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:cl}),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(mx,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:y,children:[t.jsx("h2",{className:"bim-ct-side-h",children:h("分類")}),t.jsx(pl,{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(hl,{works:s,view:S,workLink:c,page:o,pageCount:r,onPage:d,pageHref:a})]})]})}const ai=({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:"简"})]})},ci=({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 Dn(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function bx(e,n){if(!n)return!1;const o=n.id;return o===void 0||o===e}const yx=({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 Ji;const B=ue(),{convert:O}=Z(),[M]=g.useState(()=>{if(!bx(e,o))return null;const J={...o},ve=r??Dn(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,q]=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),[K,se]=g.useState(null),ke=d!==void 0?d:K,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]),qe=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&&qe(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??Dn(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),q(!1),ve(Ae.detail),()=>{J=!0}):((async()=>{q(!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=Dn(e,Te)),y&&y(De,Te),Y(De),ee(Te),ve(Te)}catch{J||ne(!0)}finally{J||q(!1)}})(),()=>{J=!0})},[e,n,M,y,Le,qe,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=vi(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:[vx(B,E.subtype),Ie?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,O,B]),Ze=E?E.type==="work"?(((Ji=le==null?void 0:le.juan_files)==null?void 0:Ji.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(Kn,{href:J}))}else Ze&&(dt=t.jsx(Kn,{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(nl,{data:E,transport:n,onNavigate:j,renderLink:b,readAction:dt,railTop:v,railLinks:_e}):E.type==="book"?t.jsx(sl,{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(ll,{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(al,{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(mi,{data:te,onNavigate:j,renderLink:b})}if(s==="collated")return t.jsx(Pi,{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(ii,{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(ii,{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(Gi,{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 Zi,Xi,Qi,eo,to,no,io;if(!te)return;const Te={},De=((Zi=P.current)==null?void 0:Zi.books)??[];Te.all=(((Xi=te.books)==null?void 0:Xi.length)??0)-(((eo=(Qi=te.version_graph)==null?void 0:Qi.excluded_books)==null?void 0:eo.length)??0);const et=(to=te.version_graph)==null?void 0:to.collections;if(et)for(const oo of Object.keys(et))Te[oo]=fn(te,De,oo).nodes.filter(ro=>ro.kind==="book"&&!ro.bridge).length;return Te.core==null&&((io=(no=te.version_graph)==null?void 0:no.core_books)!=null&&io.length)&&(Te.core=te.version_graph.core_books.length),Te})()})}if(s==="feedback"&&S)return t.jsx(Xs,{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",qi=typeof T=="string"?B.status[T.trim()]??T:T,Ki=t.jsx(ps,{left:t.jsxs(t.Fragment,{children:[qi,qi?" · ":"",t.jsx(jx,{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(Jn,{breadcrumb:t.jsx(Zn,{items:ln}),actions:t.jsxs(t.Fragment,{children:[t.jsx(ai,{style:{border:"none",background:"transparent"}}),Ce&&t.jsx(ci,{...Ce})]})}),Xe(),Ki]})}):t.jsx("div",{className:C,children:t.jsxs(Ht,{wide:an,style:{minHeight:N,...D},children:[t.jsx(Jn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(wi,{char:"籍"}),t.jsx(Zn,{items:ln})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(ai,{}),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(ci,{...Ce})]})}),t.jsx(ns,{...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(is,{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()}),Ki]})})};function jx({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 vx(e,n){return n?e.workSubtype[n]??n:""}const bl=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛藍"}],Cn="zhusha",In="bim-theme";function yl(e){return e==="zhusha"||e==="indigo"}function Tn(e){return yl(e)?e:Cn}function kx(){try{return Tn(window.localStorage.getItem(In))}catch{return Cn}}function jl(e){try{window.localStorage.setItem(In,e)}catch{}}function vl(e){const n=Tn(e);return document.documentElement.setAttribute("data-theme",n),n}function kl(){return Tn(document.documentElement.getAttribute("data-theme"))}const wx=`try{if(localStorage.getItem(${JSON.stringify(In)})==='indigo')document.documentElement.setAttribute('data-theme','indigo')}catch(e){}`,Sx={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo"},_x=({onChange:e,style:n})=>{const{convert:o}=Z(),[r,s]=g.useState(Cn);g.useEffect(()=>{s(kl())},[]);const l=d=>{s(vl(d)),jl(d),e==null||e(d)};return t.jsx("div",{role:"radiogroup","aria-label":o("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:bl.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(Sx[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=Nl;exports.BookDetailLayout=yx;exports.BookFullText=ii;exports.BookPage=sl;exports.Breadcrumb=Zn;exports.CATALOG_ALL_ID=rt;exports.CATALOG_CSS=cl;exports.CATALOG_NARROW_QUERY=Ui;exports.CATALOG_PAGE_SIZE=Vi;exports.CATALOG_UNCLASSIFIED_ID=Kt;exports.CardFoot=en;exports.CatalogPage=hx;exports.CatalogPager=ml;exports.CatalogTree=pl;exports.CheckFilter=es;exports.Chip=os;exports.ChipWall=_c;exports.CollatedEdition=Pi;exports.CollectionCatalog=mi;exports.CollectionPage=ll;exports.CreateEntityDialog=Gs;exports.DEFAULT_READER_PREFS=$i;exports.DEFAULT_THEME=Cn;exports.DETAIL_CSS=ts;exports.Dash=Ec;exports.DataTable=zc;exports.DetailFooter=ps;exports.DetailGrid=Xt;exports.DetailHeader=ns;exports.EmendatedBySection=Ar;exports.EmptyNote=Mc;exports.EntityDetail=Tr;exports.EntityPage=al;exports.EntityPickerDialog=Vs;exports.EntitySelector=Hs;exports.ExpandRow=Rc;exports.ExtLink=Fc;exports.FEEDBACK_FAB_OFFSET_VAR=ri;exports.FONT_SIZE_STEPS=$t;exports.FactList=vc;exports.FeedbackButton=au;exports.FeedbackDialog=Js;exports.FeedbackForm=Zs;exports.FeedbackList=Oi;exports.FeedbackTab=Xs;exports.FilterChip=is;exports.FormInput=Ge;exports.FormTextArea=bt;exports.GUJI_MARKDOWN_FIELD=lc;exports.GUJI_TABLE_NOTATION=ks;exports.GlyphBadge=wi;exports.GujiTable=Ti;exports.HomePage=ni;exports.ImagePanel=hs;exports.IndexApp=xp;exports.IndexBrowser=Un;exports.IndexDetail=gi;exports.IndexEditor=Ys;exports.IndexView=Kp;exports.IntroGrid=jc;exports.LocaleContext=Rt;exports.LocaleProvider=Yl;exports.LocaleToggle=ai;exports.MetaLine=Me;exports.ModeIndicator=zr;exports.MoreButton=Sc;exports.MoreLink=Bt;exports.PAGE_MAX_WIDTH=un;exports.PageFrame=Ht;exports.Quote=Lc;exports.READER_CSS=fs;exports.RECENT_IDS_STORAGE_KEY=Ct;exports.ROLE_CLASS_ORDER=Hr;exports.ReadButton=Kn;exports.ReaderMdText=Li;exports.ReaderShell=Ci;exports.ReaderToc=ms;exports.RelationPanel=Os;exports.RepoSourceLink=ci;exports.ResourceEditor=Gn;exports.ResourceGroup=Bc;exports.ResourceLine=Ac;exports.ResourceList=fi;exports.ResourceRow=cs;exports.SNIPPET_MARK_END=jr;exports.SNIPPET_MARK_START=yr;exports.SearchInput=Cr;exports.Sec=Fe;exports.Section=Ke;exports.SectionHead=kc;exports.SideList=ht;exports.SmartBidInput=xn;exports.SourceEditor=Ms;exports.SummaryCard=Qt;exports.THEMES=bl;exports.THEME_INIT_SCRIPT=wx;exports.THEME_STORAGE_KEY=In;exports.TabFilter=$n;exports.TableHead=Cc;exports.TableRow=Ic;exports.TagRow=ds;exports.TagRows=Wc;exports.TextButton=wc;exports.ThemeToggle=_x;exports.TopStrip=Jn;exports.VersionLineageGraph=rl;exports.VersionLineageList=ol;exports.VersionLineageView=Gi;exports.VolumeChips=$c;exports.VolumeLinks=Si;exports.WorkCard=fl;exports.WorkCardGrid=hl;exports.WorkCatalog=fp;exports.WorkPage=nl;exports.WorkRow=gl;exports.applyTheme=vl;exports.bucketResources=yi;exports.buildCatalogTree=ax;exports.buildCollectionTable=Ur;exports.buildLineageGraph=fn;exports.buildPageUrl=xi;exports.buildParagraphBlocks=Ts;exports.buildVersionRow=Or;exports.buildVersionTable=Dr;exports.canParagraphize=qt;exports.catalogNodeIdOf=sx;exports.catalogNodeIdsOf=lx;exports.catalogPageCount=ux;exports.catalogTotal=Yi;exports.classificationPath=nn;exports.compareCatalogCards=px;exports.computeVersionPartition=ic;exports.currentTheme=kl;exports.defaultWorkLink=ul;exports.deriveDating=ec;exports.deriveEditionType=Yr;exports.deriveEra=Zt;exports.deriveYear=wn;exports.deriveYearRange=bi;exports.detailToEditor=Ks;exports.detectGenre=zn;exports.displayAuthorRole=vi;exports.editorToDetail=qp;exports.eraRank=Yn;exports.findCatalogPath=zt;exports.flattenTitles=Xn;exports.flattenToc=vs;exports.formatTemplate=Jt;exports.formatVolumeRange=_n;exports.getDisplayNameFromUrl=Nt;exports.getStartPage=ui;exports.getTypeGroupKey=di;exports.groupRelatedWorks=tc;exports.gujiInlineToPlain=Zr;exports.hasGujiMarkdownV02=qn;exports.hasGujiTableNotation=ws;exports.isThemeName=yl;exports.measureText=at;exports.mergeVolumeResources=pi;exports.normalizeEra=We;exports.normalizeRole=ji;exports.normalizeTheme=Tn;exports.normalizeVolumeIndex=Ut;exports.normalizeVolumes=$r;exports.numberToChinese=Vr;exports.paginationItems=dl;exports.parseChineseNumber=gn;exports.parseGujiInline=Jr;exports.parseGujiTable=_s;exports.parseSourceString=Fs;exports.pickReaderVersion=js;exports.readStoredTheme=kx;exports.readerVersionOptionLabel=ei;exports.readerVersionsFromFullText=ys;exports.renderFullTextBody=ad;exports.renderProperNames=Rs;exports.renderReaderInline=Ni;exports.resourceHref=Lt;exports.resourceNote=Sn;exports.roleFacets=Gr;exports.rowNo=Tc;exports.sortYear=mn;exports.splitFullTextTables=Ii;exports.splitHighlightSnippet=vr;exports.splitTableRow=Ss;exports.storeTheme=jl;exports.stringifySources=Ps;exports.toCatalogWorkCard=dx;exports.useBidUrl=Pe;exports.useConvert=Z;exports.useReaderPrefs=zi;exports.useT=ue;exports.validateLineageGraph=Iu;exports.volumeStats=yn;