book-index-ui 0.10.0 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +320 -150
- package/dist/index.d.ts +225 -2
- package/dist/index.js +4617 -3955
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";var Cs=Object.create;var Bo=Object.defineProperty;var Is=Object.getOwnPropertyDescriptor;var Ts=Object.getOwnPropertyNames;var Rs=Object.getPrototypeOf,Es=Object.prototype.hasOwnProperty;var Ls=(e,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Ts(n))!Es.call(e,s)&&s!==o&&Bo(e,s,{get:()=>n[s],enumerable:!(r=Is(n,s))||r.enumerable});return e};var bt=(e,n,o)=>(o=e!=null?Cs(Rs(e)):{},Ls(n||!e||!e.__esModule?Bo(o,"default",{value:e,enumerable:!0}):o,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ae=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),f=require("react"),Bs=require("react-markdown"),Ns=require("remark-gfm"),Ws=e=>`/book-index?id=${e}`,Pi=f.createContext(Ws);function As({buildUrl:e,children:n}){const o=f.useMemo(()=>e,[e]);return t.jsx(Pi.Provider,{value:o,children:n})}function je(){return f.useContext(Pi)}const Oi="",Hi="";function Di(e){const n=[];let o=!1,r=e;for(;r.length;){const s=o?Hi:Oi,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 we(e,n){return{title:e,tokens:n}}const No='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Ms=[we("基础(VS Code 环境下跟随 --vscode-*)",{bg:{value:"#ffffff",vscode:"--vscode-editor-background"},fg:{value:"#333333",vscode:"--vscode-foreground"},"input-bg":{value:"#ffffff",vscode:"--vscode-input-background"},"input-fg":{value:"#333333",vscode:"--vscode-input-foreground"},"input-border":{value:"#cccccc",vscode:"--vscode-input-border"},"widget-border":{value:"#e0e0e0",vscode:"--vscode-widget-border"},"link-fg":{value:"#0066cc",vscode:"--vscode-textLink-foreground"},"desc-fg":{value:"#717171",vscode:"--vscode-descriptionForeground"},primary:{value:"#0078d4",vscode:"--vscode-button-background"},"primary-fg":{value:"#ffffff",vscode:"--vscode-button-foreground"},"primary-soft":{value:"rgba(0, 120, 212, 0.15)",css:"color-mix(in srgb, var(--bim-primary) 15%, transparent)"},danger:{value:"#f44336"},warning:{value:"#ff9800"},success:{value:"#4caf50"},"sidebar-bg":{value:"#f3f3f3",vscode:"--vscode-sideBar-background"},"list-hover-bg":{value:"rgba(0, 0, 0, 0.04)",vscode:"--vscode-list-hoverBackground"},"list-active-bg":{value:"rgba(0, 120, 212, 0.1)",vscode:"--vscode-list-activeSelectionBackground"},"focus-border":{value:"#0078d4",vscode:"--vscode-focusBorder"}}),we("底色层次 / 文字与描边 / 链接",{"bg-subtle":{value:"#fafafa"},"widget-bg":{value:"#f8f8f8"},muted:{value:"#888888"},border:{value:"#e5e5e5"},"primary-bg":{value:"#fdf4f4"},link:{value:"#1976d2"},"tag-bg":{value:"#f0f0f0"},"accent-bg":{value:"#1976d2"},"on-color-fg":{value:"#ffffff",note:"彩色底(徽章、选中态按钮)上的文字"}}),we("提示与警告",{"info-fg":{value:"#0c5380"},"info-bg":{value:"#e7f3ff"},"info-border":{value:"#b3dbff"},"warn-fg":{value:"#856404"},"warn-bg":{value:"#fff3cd"},"warn-border":{value:"#ffc107"},"danger-bg":{value:"rgba(244, 67, 54, 0.08)",note:"错误提示条底色"},"danger-soft-bg":{value:"rgba(244, 67, 54, 0.03)",note:"编辑器危险区块"},"danger-soft-border":{value:"rgba(244, 67, 54, 0.13)"}}),we("遮罩与阴影",{backdrop:{value:"rgba(0, 0, 0, 0.5)",note:"对话框遮罩"},"overlay-bg":{value:"#00000010",note:"轻量遮罩底(图片占位等)"},"shadow-dialog":{value:"0 4px 20px rgba(0, 0, 0, 0.3)"},"shadow-dropdown":{value:"0 4px 12px rgba(0, 0, 0, 0.1)"},"shadow-tooltip":{value:"0 2px 8px rgba(0, 0, 0, 0.08)"},"shadow-fab":{value:"0 2px 8px rgba(0, 0, 0, 0.25)",note:"悬浮按钮(反馈)"},"shadow-card":{value:"0 1px 4px rgba(0, 0, 0, 0.06)",note:"展开的卡片"},"shadow-node":{value:"0 1px 3px rgba(0, 0, 0, 0.1)",note:"谱系图节点"},"shadow-node-selected":{value:"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)"}}),we("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),we("资源",{"restype-text":{value:"#2196f3"},"restype-image":{value:"#ff9800"},"restype-text-image":{value:"#9c27b0"},"restype-physical":{value:"#795548"},"missing-fg":{value:"#e67e22",note:"资源缺册提示"},"colormode-bw-bg":{value:"#f5f5f5",note:"影印件色彩模式标记(黑白 / 彩色)"},"colormode-bw-fg":{value:"#757575"},"colormode-color-bg":{value:"#fff8e1"},"colormode-color-fg":{value:"#f57f17"},"progress-active":{value:"#f59e0b",note:"资源导入进度"},"progress-done":{value:"#10b981"},"progress-todo":{value:"#9ca3af"},"check-fine-bg":{value:"#e8f5e9",note:"文字资源校对程度徽章(精校 / 粗校 / AI整理)"},"check-fine-fg":{value:"#2e7d32"},"check-rough-bg":{value:"#fff3e0"},"check-rough-fg":{value:"#e65100"},"check-ai-bg":{value:"#e3f2fd"},"check-ai-fg":{value:"#1565c0"}}),we("整理本(CollatedEdition)",{"highlight-bg":{value:"#fff59d",note:"搜索命中高亮底"},"highlight-fg":{value:"inherit",root:!1},"section-lei":{value:"#8e6f3e",note:"章节类型标记:类 / 书 / 序 / 结语 / 考证 / 注释"},"section-shu":{value:"#c0392b"},"section-xu":{value:"#1a5276"},"section-jieyu":{value:"#7d6608"},"section-kaozhen":{value:"#5d6d7e"},"section-zhushi":{value:"#6c5b7b"},"section-tag-fg":{value:"#e74c3c",note:"章节标记(△ 等)"},"matchstate-fg":{value:"#b78900",note:"与底本匹配状态提示"},"quality-published":{value:"#1b5e20",note:"文本质量等级(出版 / 精校 / 粗校 / OCR)"},"quality-fine":{value:"#2e7d32"},"quality-rough":{value:"#1565c0"},"quality-ocr":{value:"#e65100"}}),we("版本传承(VersionLineageGraph / List) / 关系方向(RelationPanel)",{"lost-fg":{value:"#c62828",note:"佚失标记"},"confidence-certain":{value:"#2e7d32",note:"关系置信度"},"confidence-consensus":{value:"#1976d2"},"confidence-probable":{value:"#ed6c02"},"confidence-disputed":{value:"#c62828"},"lineage-edge-consensus":{value:"#555555",note:"⚠️ 同为 consensus,List 徽章用 --bim-confidence-consensus(蓝),Graph 连线用这个(灰)。若要统一,覆盖成 var(--bim-confidence-consensus)"},"relation-up":{value:"#2196f3"},"relation-down":{value:"#4caf50"},"relation-flat":{value:"#ff9800"}}),we("编辑器视图(主要在 guji-platform 插件中可见)",{"editor-type-work":{value:"#4caf50",note:"⚠️ 与展示视图的 --bim-type-* 是两套配色(历史如此)。若要统一,覆盖成对应的 var(--bim-type-*)"},"editor-type-collection":{value:"#2196f3"},"editor-type-book":{value:"#ff9800"},"editor-type-entity":{value:"#9c27b0"},"source-url":{value:"#2196f3",note:"来源类型(SourceEditor)"},"source-bookid":{value:"#4caf50"},"mode-active-bg":{value:"#2196f3",note:"模式指示器当前态(ModeIndicator)"},"cover-accent":{value:"#8e6f3e",note:'书目卡片「封面」点缀(IndexBrowser resultVariant="card")'}}),we("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --bim-primary 等控件色",{"page-bg":{value:"#fbf9f3",note:"纸"},"row-hover-bg":{value:"#f5f1e5"},"selection-bg":{value:"#ecdcbc",note:"选区"},"band-bg":{value:"#f0e4cb",note:"全文入口横幅(暖沙)"},"band-bg-hover":{value:"#e6d5b4"},ink:{value:"#2a231c",note:"文字层次:墨 → 正文 → 提要 → meta → 标签 → 提示"},"body-fg":{value:"#3b3228"},"quiet-fg":{value:"#5b4f40"},"meta-fg":{value:"#7b6a54"},"label-fg":{value:"#6f6457",note:"标签 / 提示:2026-09 N3a 调深,纸底与斑马底上对比度均 ≥4.5(原 #a3937b 2.8、#b3a385 2.3)"},"hint-fg":{value:"#756a5e"},accent:{value:"#9c3a2c",note:"朱"},"accent-deep":{value:"#6f2a20",note:"链接 hover"},"rule-strong":{value:"#2a231c",note:"分隔线:强 → 常规 → 虚线 → 提要左线"},rule:{value:"#e4dbc9"},"rule-dashed":{value:"#d6c9ae"},"rule-accent-soft":{value:"#e0d3b6"},"aux-fg":{value:"#6f6457",note:"辅助字(元数据、注记、「·」分隔的浅色小字)。须在 page-bg / zebra-bg 上对比度 ≥4.5(Q5 巡检)"},"card-bg":{value:"#fffdf9",note:"提要卡:抬起的面"},"zebra-bg":{value:"#f6f2eb",note:"表格斑马纹 / 左栏分组底(不画格线,靠这一阶底色分行)"},"tint-bg":{value:"#f3eee6",note:"检索框、悬停"},"shadow-summary":{value:"0 10px 32px rgba(60, 50, 40, 0.07)",note:"提要卡投影"},"flag-bg":{value:"rgba(158, 42, 43, 0.08)",note:"唯一的状态色块「有影印」"},"table-border":{value:"color-mix(in srgb, currentColor 28%, transparent)",root:!1,note:"古籍表格(跟随当前文字色)"},"table-head-bg":{value:"color-mix(in srgb, currentColor 8%, transparent)",root:!1}}),we("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),we("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),we("字体(全站无衬线,2026-09-05 定)",{"font-ui":{value:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif'},"font-body":{value:"system-ui, sans-serif",css:"var(--bim-font-ui)"},"font-serif":{value:No,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:No,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Fs=Object.assign({},...Ms.map(e=>e.tokens)),Gi={};for(const[e,n]of Object.entries(Fs))Gi[e]=`var(--bim-${e}, ${n.value})`;function i(e){const n=Gi[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function Xe(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function Ps(e,n){return Xe(e).includes(n)}const yn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Os={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};i("quality-published"),i("quality-fine"),i("quality-rough"),i("quality-ocr");const xt=f.createContext(null),Vi={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:"搜索古籍索引",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:"圖片資源"}},Hs={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:"搜索古籍索引",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:"图片资源"}},Ds={"zh-Hant":Vi,"zh-Hans":Hs},Ui="bim-locale";function Gs(){try{const e=localStorage.getItem(Ui);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Vs(e){try{localStorage.setItem(Ui,e)}catch{}}const Us="zh-Hans",Ys=({locale:e,onLocaleChange:n,children:o})=>{const[r,s]=f.useState(e??Us),l=e??r;f.useEffect(()=>{if(e)return;const u=Gs();u&&u!==r&&s(u)},[]);const[p,d]=f.useState(null);f.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(u=>{const x=u.Converter({from:"tw",to:"cn"});d(()=>x)}).catch(()=>{d(()=>u=>u)}):d(null)},[l]);const c=f.useCallback(u=>{s(u),Vs(u),n==null||n(u)},[n]),a=f.useMemo(()=>({locale:l,setLocale:c,messages:Ds[l],converter:p}),[l,c,p]);return t.jsx(xt.Provider,{value:a,children:o})};function te(){const e=f.useContext(xt);return(e==null?void 0:e.messages)??Vi}const Ks=2e3;function Y(){const e=f.useContext(xt),n=(e==null?void 0:e.locale)??"zh-Hant",o=(e==null?void 0:e.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const l=f.useCallback(p=>{if(!p)return"";if(!o)return p;const d=r.current.get(p);if(d!==void 0)return d;const c=o(p);if(r.current.size>=Ks){const a=r.current.keys().next().value;a!==void 0&&r.current.delete(a)}return r.current.set(p,c),c},[o]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Tt(e,n){return e.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function qs(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 Js(){return{id:"",name:"",url:"",type:"text",details:""}}const jn=({items:e,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const l=te(),[p,d]=f.useState(null),c=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],a=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=b=>{if(!s)return!0;const j=Xe(b);return s==="text"?j.includes("text"):s==="image"?j.includes("image")||j.includes("physical"):s==="physical"?j.includes("physical"):j.includes(s)},x=e.map((b,j)=>({item:b,originalIndex:j})).filter(({item:b})=>u(b)),g=()=>{const b=Js();s&&(b.type=s),n([...e,b]),d(e.length)},h=b=>{n(e.filter((j,w)=>w!==b)),d(null)},y=(b,j,w)=>{const S=[...e];if(S[b]={...S[b],[j]:w},j==="url"&&!S[b].id){const z=qs(w);z&&(S[b].id=z)}n(S)},k=(b,j,w)=>{const z={...e[b].metadata||{}};w?z[j]=w:delete z[j],y(b,"metadata",Object.keys(z).length>0?z:void 0)},m=(b,j)=>{const w=j.trim()?j.split(/[,,、]/).map(S=>S.trim()).filter(Boolean):void 0;y(b,"structure",w)},v=(b,j,w)=>{const z=e[b].coverage||{level:1,ranges:""};j==="level"?z.level=parseInt(w)||1:z.ranges=w,y(b,"coverage",z.ranges?z:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:b,originalIndex:j})=>{var w,S,z;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:()=>d(p===j?null:j),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:p===j?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Zs(b.type??"text"),color:i("on-color-fg")},children:(()=>{var T,B;const _=Xe(b);return _.length===0?b.type??"text":_.length===1?((T=c.find(L=>L.value===_[0]))==null?void 0:T.label)??_[0]:_.includes("text")&&_.includes("image")?((B=c.find(L=>L.value==="text+image"))==null?void 0:B.label)??"text+image":_.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:b.name||`${l.editor.resourcePlaceholder} ${j+1}`}),b.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:b.id}),b.url&&t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",onClick:_=>_.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&b.url&&Xs(j,r==null?void 0:r[j],o,l),t.jsx("button",{onClick:_=>{_.stopPropagation(),h(j)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),p===j&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:[Ps(b,"image")&&b.url&&Qs(b,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:yt,children:[t.jsx("span",{style:jt,children:l.label.type}),t.jsx("select",{value:b.type,onChange:_=>y(j,"type",_.target.value),style:{...Ae,flex:1},children:c.map(_=>t.jsx("option",{value:_.value,children:_.label},_.value))})]}),t.jsxs("label",{style:yt,children:[t.jsx("span",{style:jt,children:l.label.rootType}),t.jsx("select",{value:b.root_type||"catalog",onChange:_=>y(j,"root_type",_.target.value),style:{...Ae,flex:1},children:a.map(_=>t.jsx("option",{value:_.value,children:_.label},_.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:b.id,onChange:_=>y(j,"id",_.target.value),placeholder:l.editor.idAutoExtract,style:{...Ae,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:b.name,onChange:_=>y(j,"name",_.target.value),placeholder:l.editor.resourceName,style:{...Ae,flex:1}})]}),t.jsx("input",{type:"text",value:b.url,onChange:_=>y(j,"url",_.target.value),placeholder:l.editor.resourceUrl,style:Ae}),t.jsx("input",{type:"text",value:((w=b.structure)==null?void 0:w.join("、"))||"",onChange:_=>m(j,_.target.value),placeholder:l.editor.structurePlaceholder,style:Ae}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:yt,children:[t.jsx("span",{style:jt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((S=b.coverage)==null?void 0:S.level)??"",onChange:_=>v(j,"level",_.target.value),placeholder:"1",style:{...Ae,width:"60px"}})]}),t.jsxs("label",{style:{...yt,flex:1},children:[t.jsx("span",{style:jt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:((z=b.coverage)==null?void 0:z.ranges)||"",onChange:_=>v(j,"ranges",_.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...Ae,flex:1}})]})]}),t.jsx("textarea",{value:b.details||"",onChange:_=>y(j,"details",_.target.value),placeholder:l.editor.detailsPlaceholder,style:{...Ae,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(([_,T])=>{var B;return t.jsxs("label",{style:{...yt,gap:"4px"},children:[t.jsx("span",{style:{...jt,minWidth:"56px"},children:T}),t.jsx("input",{type:"text",value:((B=b.metadata)==null?void 0:B[_])||"",onChange:L=>k(j,_,L.target.value),placeholder:T,style:{...Ae,flex:1}})]},_)})})]})]})]})]},j)}),t.jsxs("button",{onClick:g,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 Zs(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 Xs(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:p=>{p.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 Qs(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 Ae={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"},yt={display:"flex",alignItems:"center",gap:"6px"},jt={fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap"},el={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function et(e){try{return el[new URL(e).hostname]}catch{return}}const Wo={text:0,image:1,physical:2};function An(e){return e.length===0?"physical":[...e].sort((n,o)=>(Wo[n]??99)-(Wo[o]??99)).join("+")}function Mn(e){var p;const n=d=>{const c=d.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const a=d.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},o=new Map;for(let d=0;d<e.length;d++){const c=e[d];if(c.volumes&&c.volumes.length>0)continue;const a=n(c.name);if(!a)continue;const[u,x]=a,g=`${u}|${An(Xe(c))}`;o.has(g)||o.set(g,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const h=o.get(g);h.volumes.push({volume:x,url:c.url||void 0,status:"found"}),h.indices.push(d)}const r=[],s=new Set;for(const d of o.values())if(!(d.volumes.length<2)){d.volumes.sort((c,a)=>c.volume-a.volume),d.base.volumes=d.volumes,d.base.expected_volumes=d.volumes.length,d.base.url||(d.base.url=((p=d.volumes.find(c=>c.url))==null?void 0:p.url)??""),r.push(d.base);for(const c of d.indices)s.add(c)}const l=[...r];for(let d=0;d<e.length;d++)s.has(d)||l.push(e[d]);return l}function Yi(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 Ki(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||Yi(n)}))}function Kt(e){const n=Ki(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 Fn(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 Pn(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 ft(e){if(!e.url)return;const n=Fn(e.metadata);return n?Pn(e.url,n):e.url}const Ao={text:i("restype-text"),image:i("restype-image"),"text+image":i("restype-text-image"),physical:i("restype-physical")};function tl(e){return e.includes("text")&&e.includes("image")?Ao["text+image"]:Ao[e[0]||"physical"]}const On=({items:e,groupByType:n=!0,resourceGroups:o,onNavigate:r,renderLink:s})=>{const l=te(),{convert:p}=Y(),d=f.useMemo(()=>Mn(e||[]),[e]),{mirrorGroups:c,ungroupedItems:a}=f.useMemo(()=>{const m=new Map,v=[];for(const b of d){const j=b.group;j?(m.has(j)||m.set(j,[]),m.get(j).push(b)):v.push(b)}for(const b of m.values())b.sort((j,w)=>{const S=z=>z.group_role==="origin"?0:z.group_role==="mirror"?1:2;return S(j)-S(w)});return{mirrorGroups:m,ungroupedItems:v}},[d]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},x=m=>u[m]?u[m]:m.split("+").map(v=>u[v]||v).join("+");if(!d||d.length===0)return t.jsx("div",{style:{padding:"16px",color: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:d.map((m,v)=>t.jsx(sn,{item:m},m.id||v))});const g=(m,v)=>{const b=o==null?void 0:o[m],j=(b==null?void 0:b.label)||m,w=b==null?void 0:b.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:p(j)}),w&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.5},children:p(w)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((S,z)=>t.jsx(sn,{item:S,onNavigate:r,renderLink:s},S.id||z))})]},`group-${m}`)},h=new Map;for(const m of a){const v=An(Xe(m));h.has(v)||h.set(v,[]),h.get(v).push(m)}const y=["text","image","text+image","physical"],k=[...y.filter(m=>h.has(m)),...[...h.keys()].filter(m=>!y.includes(m)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([m,v])=>g(m,v)),k.map(m=>{const v=h.get(m),b=tl(m.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:b,whiteSpace:"nowrap",flexShrink:0},children:x(m)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((j,w)=>t.jsx(sn,{item:j,onNavigate:r,renderLink:s},j.id||w))})]},m)})]})},nl={bw:{label:"",bg:i("colormode-bw-bg"),fg:i("colormode-bw-fg")},color:{label:"",bg:i("colormode-color-bg"),fg:i("colormode-color-fg")}},sn=({item:e})=>{const n=te(),{convert:o}=Y(),[r,s]=f.useState(!1),l=f.useMemo(()=>(e.url?et(e.url):void 0)||o(e.name),[e.url,e.name,o]),p=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(y=>({...y,url:y.url||Yi(y)})),[e.volumes]),d=p&&p.length>0,c=d?new Set(p.filter(y=>y.status!=="missing").map(y=>y.volume)).size:0,a=d?new Set(p.filter(y=>y.status==="missing").map(y=>y.volume)).size:0,u=e.expected_volumes??(d?c+a:0),x=e.color_mode?{...nl[e.color_mode],label:n.colorMode[e.color_mode]}:null,g=e.details&&!d?o(e.details):null,h={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:h,children:[t.jsx("span",{style:{fontWeight:500},children:l}),x&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),g&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:g}),d&&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 y=Fn(e.metadata);return y?Pn(e.url,y):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:i("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),d&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),d&&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:p.map(y=>{const k=y.status==="missing";return y.url&&!k?t.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${i("widget-border")}`,color:i("link-fg"),textDecoration:"none"},children:y.volume},y.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:i(k?"missing-fg":"desc-fg"),textDecoration:k?"line-through":"none",opacity:k?.6:1},children:y.volume},y.volume)})})]})},qi=({indexSource:e,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:p})=>{const d=te(),c=e==="local",a=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",x=u?u.split(/[/\\]/).pop()||u:"",g={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:i("primary-soft"),color:i("primary")},h={onMouseOver:k=>k.currentTarget.style.opacity="0.8",onMouseOut:k=>k.currentTarget.style.opacity="1"},y=t.jsxs("div",{onClick:s,title:a?d.mode.switchToOfficial:d.mode.switchToDraft,style:{...g,background:i(a?"warning":"success"),color:i("on-color-fg")},...h,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:[y,t.jsxs("div",{onClick:r,title:d.mode.switchToSync,style:g,...h,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:d.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:p,title:u||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...h,children:[t.jsx("span",{children:"📂"}),x&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[y,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:d.mode.switchToLocal,style:g,...h,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:d.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:x||d.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...h,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:c?d.mode.switchToGithub:d.mode.switchToLocal,style:g,...h,children:[t.jsx("span",{children:c?"📁":"🌐"}),t.jsx("span",{children:c?d.mode.localMode:d.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&t.jsxs("div",{onClick:p,title:u||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...h,children:[t.jsx("span",{children:"📂"}),x&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!c&&x&&t.jsxs("div",{style:{...g,background: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:x})]})]})},qt="bim-search-history",Mo=10,Fo=8;function zt(){try{const e=localStorage.getItem(qt);return e?JSON.parse(e):[]}catch{return[]}}function ol(e){try{const n=zt().filter(o=>o!==e);n.unshift(e),n.length>Mo&&(n.length=Mo),localStorage.setItem(qt,JSON.stringify(n))}catch{}}function il(e){try{const n=zt().filter(o=>o!==e);localStorage.setItem(qt,JSON.stringify(n))}catch{}}function rl(){try{localStorage.removeItem(qt)}catch{}}const Ji=({transport:e,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:l})=>{const p=te(),d=l??p.search.placeholder,c={work:p.indexType.work,book:p.indexType.book,collection:p.indexType.collection,entity:p.indexType.entity},[a,u]=f.useState(!1),[x,g]=f.useState([]),[h,y]=f.useState(-1),[k,m]=f.useState(zt),v=f.useRef(null),b=f.useRef(null),j=f.useRef(null),w=f.useRef(!1);f.useEffect(()=>{y(-1);const $=n.trim();if(!$){g(k.map(I=>({type:"history",text:I})));return}if(!e.searchAll){g([]);return}let F=!1;const W=setTimeout(()=>{e.searchAll($,Fo).then(I=>{if(F)return;const R=[...I.works,...I.books,...I.collections,...I.entities??[]];g(R.slice(0,Fo).map(N=>({type:"entry",text:N.title||N.id,entry:N})))}).catch(()=>{F||g([])})},80);return()=>{F=!0,clearTimeout(W)}},[n,k,e]),f.useEffect(()=>{const $=F=>{j.current&&!j.current.contains(F.target)&&u(!1)};return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[]),f.useEffect(()=>{const $=F=>{var W,I;if(F.key==="/"&&document.activeElement!==v.current){const R=(W=document.activeElement)==null?void 0:W.tagName;if(R==="INPUT"||R==="TEXTAREA"||R==="SELECT")return;F.preventDefault(),(I=v.current)==null||I.focus()}};return document.addEventListener("keydown",$),()=>document.removeEventListener("keydown",$)},[]);const S=f.useCallback($=>{$.trim()&&(ol($.trim()),m(zt())),r($),u(!1)},[r]),z=f.useCallback($=>{$.type==="history"?(o($.text),S($.text)):$.entry&&(s?(s($.entry),u(!1)):(o($.text),S($.text)))},[o,S,s]),_=f.useCallback($=>{if(!a||x.length===0){$.key==="Enter"&&S(n);return}switch($.key){case"ArrowDown":$.preventDefault(),y(F=>(F+1)%x.length);break;case"ArrowUp":$.preventDefault(),y(F=>(F-1+x.length)%x.length);break;case"Enter":$.preventDefault(),h>=0&&h<x.length?z(x[h]):S(n);break;case"Escape":$.preventDefault(),u(!1);break}},[a,x,h,n,S,z]),T=f.useCallback(($,F)=>{F.stopPropagation(),il($),m(zt()),g(W=>W.filter(I=>!(I.type==="history"&&I.text===$)))},[]),B=f.useCallback($=>{$.stopPropagation(),rl(),m([]),g([])},[]);f.useEffect(()=>{if(h>=0&&b.current){const $=b.current.children;$[h]&&$[h].scrollIntoView({block:"nearest"})}},[h]);const L=!n.trim()&&k.length>0;return t.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:v,type:"text",placeholder:d,value:n,onChange:$=>{o($.target.value),u(!0)},onCompositionStart:()=>{w.current=!0},onCompositionEnd:()=>{w.current=!1},onFocus:()=>{u(!0)},onKeyDown:_,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&&x.length>0&&t.jsxs("div",{ref:b,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:[L&&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:p.search.history}),t.jsx("button",{onClick:B,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:p.search.clearAll})]}),x.map(($,F)=>t.jsxs("div",{onClick:()=>z($),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:i("fg"),background:F===h?i("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:$.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:$.text}),$.entry&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:[c[$.entry.type],$.entry.edition&&` · ${$.entry.edition}`,$.entry.author&&` · ${$.entry.author}`]}),$.type==="history"&&t.jsx("button",{onClick:W=>T($.text,W),style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:p.action.remove,children:"×"})]},`${$.type}-${$.text}-${F}`))]})]})},It="bim-recent-ids",Po="bim-recent-entries",Oo=50,ln=5,sl=50,ll=200;function lt(){try{const e=localStorage.getItem(It);if(e)return JSON.parse(e);const n=localStorage.getItem(Po);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(It,JSON.stringify(o)),localStorage.removeItem(Po),o}return[]}catch{return[]}}function Ho(e){try{const n=lt().filter(o=>o!==e);n.unshift(e),n.length>Oo&&(n.length=Oo),localStorage.setItem(It,JSON.stringify(n))}catch{}}function al(e){try{const n=lt().filter(o=>o!==e);localStorage.setItem(It,JSON.stringify(n))}catch{}}function cl(){try{localStorage.removeItem(It)}catch{}}const dl={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},vn=({transport:e,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:p,onConfigurePath:d,onSelectFolder:c,hideModeIndicator:a,resultVariant:u="compact",renderEntry:x,initialQuery:g,onQueryChange:h,headerRight:y})=>{const k=te(),m=[{type:"work",icon:"✍️",name:k.indexType.work,key:"works"},{type:"book",icon:"📖",name:k.indexType.book,key:"books"},{type:"collection",icon:"📚",name:k.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:k.indexType.entity,key:"entities"}],[v,b]=f.useState(g??""),[j,w]=f.useState(null),[S,z]=f.useState(null),[_,T]=f.useState(!1),[B,L]=f.useState(null),[$,F]=f.useState(""),[W,I]=f.useState(!g),[R,N]=f.useState(lt),[O,E]=f.useState([]),[X,C]=f.useState(!1),[A,K]=f.useState(!1),[U,G]=f.useState(null),[ee,P]=f.useState(null),q=f.useRef(void 0),Z=f.useRef(!1),V=f.useCallback(async(Q,ce)=>{if(!Q.trim()){I(!0),w(null),z(null);return}I(!1),T(!0),F("");try{if(e.searchAll){const M=await e.searchAll(Q,ce??ln);w(M)}else{const M=["work","book","collection","entity"],oe=await Promise.all(M.map(ne=>e.search(Q,ne,{page:1,pageSize:ce??ln})));w({works:oe[0].entries,books:oe[1].entries,collections:oe[2].entries,entities:oe[3].entries,totalWorks:oe[0].total,totalBooks:oe[1].total,totalCollections:oe[2].total,totalEntities:oe[3].total})}}catch(M){F(M instanceof Error?M.message:String(M)),w(null)}finally{T(!1)}},[e]);f.useEffect(()=>{let Q=!1;const ce=()=>{var ge,Re;const M=["work","book","collection","entity"],oe=Promise.all(M.map(Be=>e.loadEntries(Be,{page:1,pageSize:1}).catch(()=>({total:0})))),ne=((ge=e.getResourceCounts)==null?void 0:ge.call(e).catch(()=>null))??Promise.resolve(null),he=((Re=e.getSubtypeStats)==null?void 0:Re.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([oe,ne,he]).then(([Be,ve,He])=>{Q||(G({works:Be[0].total,books:Be[1].total,collections:Be[2].total,entities:Be[3].total,hasText:ve==null?void 0:ve.hasText,hasImage:ve==null?void 0:ve.hasImage}),He&&P(He))})};return e.getCounts?e.getCounts().then(M=>{var oe,ne;Q||(G({works:M.works,books:M.books,collections:M.collections,entities:M.entities,hasText:(oe=M.resourceCounts)==null?void 0:oe.hasText,hasImage:(ne=M.resourceCounts)==null?void 0:ne.hasImage}),M.subtypeStats&&P(M.subtypeStats))}).catch(()=>{Q||ce()}):ce(),()=>{Q=!0}},[e]),f.useEffect(()=>{Z.current||!(g!=null&&g.trim())||(Z.current=!0,V(g))},[g,V]);const se=f.useCallback(Q=>{if(b(Q),!Q.trim()){h==null||h(Q),I(!0),w(null),z(null);return}q.current&&clearTimeout(q.current),q.current=setTimeout(()=>{z(null),h==null||h(Q),V(Q)},ll)},[V,h]),de=f.useCallback(Q=>{q.current&&clearTimeout(q.current),h==null||h(Q),V(Q)},[V,h]),H=f.useCallback(Q=>{z(Q),V(v,sl)},[v,V]);f.useEffect(()=>{if(!R.length){E([]);return}let Q=!1;return C(!0),Promise.all(R.slice(0,10).map(async ce=>{var M,oe,ne;try{if(e.getEntry){const ge=await e.getEntry(ce);if(ge)return ge}const he=await e.getItem(ce);if(he){const ge=he.authors;return{id:ce,title:he.title||ce,type:he.type||"work",author:(M=ge==null?void 0:ge[0])==null?void 0:M.name,dynasty:(oe=ge==null?void 0:ge[0])==null?void 0:oe.dynasty,role:(ne=ge==null?void 0:ge[0])==null?void 0:ne.role,edition:he.edition||void 0}}}catch{}return{id:ce,title:ce,type:"work",notFound:!0}})).then(ce=>{Q||(E(ce),C(!1))}),()=>{Q=!0}},[R,e]);const re=Q=>{L(Q.id),Ho(Q.id),N(lt()),r==null||r(Q)},ie=(Q,ce)=>{if(r&&pl(ce)){ce.preventDefault(),re(Q);return}Ho(Q.id),N(lt())},pe=Q=>{al(Q),N(lt())},fe=()=>{cl(),N([])},ye=Q=>m.find(ce=>ce.type===Q),Ce=j&&(j.works.length>0||j.books.length>0||j.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",children:[t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${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:k.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[y,!a&&t.jsx(qi,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:l,onToggleDraft:p,onConfigurePath:d,onSelectFolder:c})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(Ji,{transport:e,value:v,onChange:se,onSearch:de,onEntrySelect:re}),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:k.action.newEntry})]}),U&&W&&t.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[t.jsx("span",{children:ee?t.jsxs(t.Fragment,{children:[(ee.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:i("fg")},children:ee.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:i("fg")},children:U.books.toLocaleString()})," 本"]}),ee.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:i("fg")},children:ee.article.toLocaleString()})," 篇"]}):null,ee.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:i("fg")},children:ee.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:i("fg")},children:U.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[k.indexType.work," ",t.jsx("strong",{style:{color:i("fg")},children:U.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.indexType.book," ",t.jsx("strong",{style:{color:i("fg")},children:U.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.indexType.collection," ",t.jsx("strong",{style:{color:i("fg")},children:U.collections.toLocaleString()}),U.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.indexType.entity," ",t.jsx("strong",{style:{color:i("fg")},children:U.entities.toLocaleString()})]})]})}),U.hasImage!=null&&U.hasText!=null&&t.jsxs("span",{children:[k.resourceType.image," ",t.jsx("strong",{style:{color:i("fg")},children:U.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.resourceType.text," ",t.jsx("strong",{style:{color:i("fg")},children:U.hasText.toLocaleString()})]})]}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:_?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg")},children:k.search.searching}):$?t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),t.jsx("p",{style:{color:i("desc-fg")},children:$})]}):W?t.jsx("div",{style:{flex:1},children:X?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg")},children:k.search.loading}):O.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:k.search.recentBrowse}),t.jsx("button",{onClick:fe,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:k.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:O.slice(0,A?10:3).map(Q=>Q.notFound?t.jsx(fl,{id:Q.id,onRemove:pe,t:k},Q.id):t.jsx(Do,{entry:Q,selected:B===Q.id,onClick:ie,getConfig:ye,onRemove:pe},Q.id))}),!A&&O.length>3&&t.jsx("button",{onClick:()=>K(!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:k.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h3",{style:{margin:"0 0 8px",color:i("fg")},children:k.search.searchTitle}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:k.search.searchSubtitle})]})}):Ce?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:m.map(({type:Q,icon:ce,name:M,key:oe})=>{const ne=j[oe]??[],he=dl[oe],ge=j[he]??0;if(ne.length===0)return null;const Be=!(S===Q)&&ge>ln;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:[ce," ",M,t.jsxs("span",{style:{fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[ge," ",k.unit.items]})]}),Be&&t.jsx("button",{onClick:()=>H(Q),style:{border:"none",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"12px"},children:k.action.viewAll})]}),t.jsx("div",{style:u==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:ne.map(ve=>{if(x)return t.jsx(f.Fragment,{children:x(ve)},ve.id);const He=u==="card"?xl:Do;return t.jsx(He,{entry:ve,selected:B===ve.id,onClick:ie,getConfig:ye,query:v},ve.id)})})]},Q)})}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h3",{style:{margin:"0 0 8px",color:i("fg")},children:Tt(k.search.noResultsFor,{query:v})}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:k.search.tryOther})]})})]})};function pl(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const Zi={color:"inherit",textDecoration:"none"},ul=({snippet:e})=>{const{convert:n}=Y();return t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.6},children:Di(e).map((o,r)=>o.marked?t.jsx("mark",{style:{background:i("highlight-bg"),color:i("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(o.text)},r):t.jsx(f.Fragment,{children:n(o.text)},r))})},xl=({entry:e,selected:n,onClick:o,getConfig:r,query:s})=>{const l=te(),{convert:p}=Y(),d=p(e.title||e.primary_name||e.id),c=e.measure_info?p(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",a=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&a.length?a.find(h=>{const y=typeof h=="string"?h:h==null?void 0:h.book_title;return y==null?void 0:y.toLowerCase().includes(s.toLowerCase())}):void 0,x=i("cover-accent"),g=je();return t.jsxs("a",{href:g(e.id),onClick:h=>o(e,h),className:"bim-result-card",style:{...Zi,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, ${x} 50%, ${i("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${x} 14%, ${i("bg")}), color-mix(in srgb, ${x} 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, ${x} 45%, transparent)`}}),t.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:x},children:Array.from(d).map((h,y)=>t.jsx("span",{children:h},y))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:i("fg")},children:d}),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:["〔",p(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:p(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",p(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",p(e.era),"〕"]}),e.edition&&t.jsx("span",{children:p(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[l.search.alias,":",p(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(ul,{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:[r(e.type).icon," ",r(e.type).name]}),e.has_text&&t.jsxs("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.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:["🖼️ ",l.misc.imageResource]})]})]})]})},Do=({entry:e,selected:n,onClick:o,getConfig:r,query:s,onRemove:l})=>{const p=te(),{convert:d}=Y(),c=[...e.additional_titles||[],...e.attached_texts||[]],a=s&&c.length?c.find(x=>{const g=typeof x=="string"?x:x==null?void 0:x.book_title;return g==null?void 0:g.toLowerCase().includes(s.toLowerCase())}):void 0,u=je();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("a",{href:u(e.id),onClick:x=>o(e,x),className:"bim-result-card",style:{...Zi,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx("span",{style:{fontSize:"16px"},children:r(e.type).icon}),t.jsx("span",{style:{fontSize:"9px",color: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:d(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{title:p.misc.textResource,children:"📝"}),e.has_image&&t.jsx("span",{title:p.misc.imageResource,children:"🖼️"})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",d(e.era),"〕"]}),e.edition&&d(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:d(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,p.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:["〔",d(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:d(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",d(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),a&&t.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:[p.search.alias,":",d(a)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:p.search.removeFromRecent,"aria-label":p.search.removeFromRecent,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},fl=({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 gl(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 hl({data:e}){const{convert:n}=Y(),{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 ml({alt_names:e}){const{convert:n}=Y(),o=new Map;for(const l of e){const p=l.type||"別名";o.has(p)||o.set(p,[]),o.get(p).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((l,p)=>{const d=r.indexOf(l),c=r.indexOf(p);return d===-1&&c===-1?0:d===-1?1:c===-1?-1:d-c});return t.jsx("div",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const p=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:p.map((d,c)=>t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),n(d)]},c))})]},l)})})}function bl({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 yl({works:e,transport:n,onNavigate:o,renderLink:r}){const s=te(),{convert:l}=Y(),p=je(),[d,c]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let g=!1;const h=e.map(k=>k.work_id);return(async()=>{const k=new Map;if(n.getEntriesByIds)try{const j=await n.getEntriesByIds(h);let w=!0;for(let S=0;S<h.length;S++){const z=j[S];z!=null&&z.title?k.set(h[S],z.title):z!=null&&z.primary_name?k.set(h[S],z.primary_name):w=!1}if(w)return k}catch{}const m=[...h],v=8,b=new Array(v).fill(0).map(async()=>{for(;m.length;){const j=m.shift();if(!j)break;if(!k.has(j))try{if(n.getEntry){const z=await n.getEntry(j);if(z!=null&&z.title){k.set(j,z.title);continue}}const w=await n.getItem(j),S=w&&(w.title||w.primary_name)||j;k.set(j,S)}catch{k.set(j,j)}}});return await Promise.all(b),k})().then(k=>{g||c(k)}),()=>{g=!0}},[e,n]);const a=new Map;for(const g of e){const h=g.role||"";a.has(h)||a.set(h,[]),a.get(h).push(g)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...a.keys()].sort((g,h)=>{const y=u.indexOf(g),k=u.indexOf(h);return y===-1&&k===-1?g.localeCompare(h):y===-1?1:k===-1?-1:y-k});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color: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,")"]})]}),x.map(g=>{const h=a.get(g);return t.jsxs("div",{style:{marginBottom:"8px"},children:[g&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"2px"},children:[l(g)," ",t.jsxs("span",{style:{color:i("desc-fg")},children:["(",h.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:h.map((y,k)=>{const m=l(d.get(y.work_id)||y.work_id);return r?t.jsx("li",{children:r(y.work_id,m)},k):o?t.jsx("li",{children:t.jsx("a",{href:p(y.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),o(y.work_id))},style:{color:i("link-fg"),textDecoration:"underline",cursor:"pointer"},children:m})},k):t.jsx("li",{children:m},k)})})]},g)})]})}const Xi=({data:e,transport:n,onNavigate:o,renderLink:r,headerExtra:s,hideHeader:l})=>{var x;const p=te(),{convert:d}=Y();let c=!1;try{c=ae.extractStatus(e.id)==="draft"}catch{}const a=gl(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:[d(e.primary_name),t.jsx(hl,{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:p.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:p.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(ml,{alt_names:e.alt_names}),t.jsx(bl,{data:e}),((x=e.description)==null?void 0:x.text)&&t.jsx("p",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:d(e.description.text)}),e.works&&e.works.length>0&&t.jsx(yl,{works:e.works,transport:n,onNavigate:o,renderLink:r})]})},Qi={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>t.jsx("a",{href:e,target:e!=null&&e.startsWith("http")?"_blank":void 0,rel:e!=null&&e.startsWith("http")?"noopener noreferrer":void 0,style:{color:i("link")},children:n}),code:({children:e})=>t.jsx("code",{style:{background:i("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})},jl={...Qi,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},Ye=({text:e,plainStrong:n,style:o,className:r})=>{const{convert:s}=Y(),l=n?jl:Qi;return t.jsx("div",{className:r,style:o,children:t.jsx(Bs,{remarkPlugins:[Ns],components:l,children:s(e)})})},vl=["〇","一","二","三","四","五","六","七","八","九"],Go=["","十","百","千"];function er(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 p=parseInt(n[l]),d=o-1-l;p===0?s=!0:(s&&r&&(r+="〇"),s=!1,p===1&&d===1&&l===0?r+=Go[d]:r+=vl[p]+Go[d])}return r}function tr(e){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:e,border:`1px solid color-mix(in srgb, ${e} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${e} 3%, transparent)`}}const kl={book:i("type-book"),work:i("type-work"),collection:i("type-collection"),entity:i("type-entity")};function Sl({type:e}){const n=te();return t.jsx("span",{style:tr(kl[e]),children:n.indexType[e]})}function wl({isDraft:e}){const n=te(),o=i(e?"status-draft":"status-official");return t.jsx("span",{style:tr(o),children:e?n.status.draft:n.status.official})}function _l({id:e}){const n=te(),[o,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:i("desc-fg"),background:i("bg-subtle"),border:`1px solid ${i("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:i("fg")},children:e}),t.jsx("span",{onClick:s,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function Ie({children:e,extra:n}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("desc-fg"),letterSpacing:"1px"},children:e}),t.jsx("span",{style:{flex:1}}),n]})}function Me({label:e,children:n}){return t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[t.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:e}),t.jsx("span",{style:{color:i("fg")},children:n})]})}function nr({authors:e,type:n,onNavigate:o,renderLink:r}){const{convert:s}=Y();return t.jsx("span",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.6},children:e.map((l,p)=>{const d=s(l.name),c=l.entity_id?t.jsx(Le,{id:l.entity_id,label:d,onNavigate:o,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:d});return t.jsxs("span",{children:[p>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)]})]},p)})})}function Le({id:e,label:n,onNavigate:o,renderLink:r}){const s=je();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 zl({id:e,title:n,edition:o,type:r,isDraft:s,authors:l,volumeText:p,meta:d,headerExtra:c,onNavigate:a,renderLink:u}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color: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}),p&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:p})]}),c&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(Sl,{type:r}),t.jsx(wl,{isDraft:s}),t.jsx(_l,{id:e})]}),((l==null?void 0:l.length)||d.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(nr,{authors:l,type:r,onNavigate:a,renderLink:u}),d]})]})}function or({items:e,label:n,showMeta:o,onNavigate:r,renderLink:s}){const l=te(),{convert:p}=Y();if(!e.length)return null;const[d,c]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(Ie,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((a,u)=>{const x=d===u;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:i("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>c(x?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:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:p(a.source)}),!x&&o&&a.title_info&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p(a.title_info)}),a.source_bid&&t.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Le,{id:a.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),x&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${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(Me,{label:l.label.titleInfo,children:p(a.title_info)}),a.author_info&&t.jsx(Me,{label:l.label.authorInfo,children:p(a.author_info)}),a.edition&&t.jsx(Me,{label:l.label.edition,children:p(a.edition)})]}),a.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${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:p(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:p(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:p(a.additional_comment)})]})]})]},u)})})]})}function $l({items:e,onNavigate:n,renderLink:o}){const r=te();return t.jsx(or,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function ir({items:e,onNavigate:n,renderLink:o}){const r=te();return t.jsx(or,{items:e,label:r.section.emendated,onNavigate:n,renderLink:o})}function rr({label:e,items:n}){const{convert:o}=Y();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const l=typeof r=="string"?r:r.book_title;return t.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:i("fg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:o(l)},s)})})]}):null}function Cl({items:e}){const n=te();return t.jsx(rr,{label:n.section.aliases,items:e})}function Il({items:e}){const n=te();return t.jsx(rr,{label:n.section.attachedTexts,items:e})}function Tl({items:e}){const n=te(),{convert:o}=Y();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{children:n.section.appendix}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:e.map((r,s)=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color: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 Rl({items:e}){const n=te(),{convert:o}=Y();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{children:n.section.locationHistory}),t.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[t.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background: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 El({items:e}){const n=te(),{convert:o}=Y();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{children:n.section.historyOverview}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map((r,s)=>t.jsxs("div",{style:{fontSize:"13px",color: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 Vo({title:e,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:l}=Y(),[p,d]=f.useState([]);return f.useEffect(()=>{if(!n.length){d([]);return}if(!o){d(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||d(a)}),()=>{c=!0}},[n,o]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(Ie,{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:(p.length?p:n.map(c=>({id:c}))).map(c=>{const a=c.edition?`${l(c.title)||c.id}(${l(c.edition)})`:l(c.title)||void 0;return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),transition:"border-color 0.15s"},children:t.jsx(Le,{id:c.id,label:a,onNavigate:r,renderLink:s})},c.id)})})]}):null}function an({book:e,onNavigate:n,renderLink:o}){const r=te(),{convert:s}=Y(),[l,p]=f.useState(!1),d=e.resources&&e.resources.length>0,c=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:i("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:d&&!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(Le,{id:e.id,label:c,onNavigate:n,renderLink:o})}),d&&t.jsx("span",{onClick:()=>p(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:"▼"})]}),d&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(On,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Ll({ids:e,workData:n,transport:o,onNavigate:r,renderLink:s,footer:l}){const p=te(),{convert:d}=Y(),[c,a]=f.useState([]);if(f.useEffect(()=>{if(!e.length){a([]);return}if(!o){a(e.map(k=>({id:k})));return}let y=!1;return Promise.all(e.map(k=>o.getItem(k).then(m=>({id:k,title:m?m.title:void 0,edition:m?m.edition:void 0,resources:m?m.resources:void 0,resource_groups:m?m.resource_groups:void 0})).catch(()=>({id:k})))).then(k=>{y||a(k)}),()=>{y=!0}},[e,o]),!e.length)return null;const u=c.length?c:e.map(y=>({id:y})),x=new Map(u.map(y=>[y.id,y])),g=n==null?void 0:n.version_graph,h=Bl(e,g);return t.jsxs(t.Fragment,{children:[t.jsxs(Ie,{children:[p.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,h.useGrouping?t.jsxs(t.Fragment,{children:[h.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:h.coreIds.map(y=>{const k=x.get(y);return k?t.jsx(an,{book:k,onNavigate:r,renderLink:s},y):null})}),h.groupedIds.map(y=>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:[d(y.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:i("desc-fg"),fontWeight:400},children:["(",y.ids.length,")"]}),y.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:i("desc-fg"),fontWeight:400},children:d(y.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:y.ids.map(k=>{const m=x.get(k);return m?t.jsx(an,{book:m,onNavigate:r,renderLink:s},k):null})})]},y.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(y=>t.jsx(an,{book:y,onNavigate:r,renderLink:s},y.id))})]})}function Bl(e,n){var m,v;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const o=(m=n.collections)==null?void 0:m[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,p=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&p.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const d=new Set(r),c=new Set([...s,...p]),a=b=>{if(c.has(b))return!0;const j=n.node_groups[b];return j!=null&&d.has(j)},u=[],x=new Map,g=[];for(const b of e)if(!((v=n.excluded_books)!=null&&v.includes(b)))if(a(b))u.push(b);else{const j=n.node_groups[b];j?(x.has(j)||x.set(j,[]),x.get(j).push(b)):g.push(b)}if(g.length+[...x.values()].reduce((b,j)=>b+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const y=new Map((n.groups??[]).map(b=>[b.id,b])),k=[...x.entries()].map(([b,j])=>{const w=y.get(b);return{id:b,label:(w==null?void 0:w.label)??b,description:w==null?void 0:w.description,ids:j}});return g.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:u,groupedIds:k}}function Nl({workData:e,onNavigate:n,renderLink:o}){var p,d,c,a;const r=te(),{convert:s}=Y(),l=!!((p=e.description)!=null&&p.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${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(Le,{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)}):((d=e.juan_count)==null?void 0:d.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:i("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:o})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((c=e.description)==null?void 0:c.text)&&t.jsx(Ye,{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(Me,{label:r.label.parentWork,children:t.jsx(Le,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Wl({items:e,onNavigate:n,renderLink:o}){const r=te(),{convert:s}=Y();return e.length?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(l=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid color-mix(in srgb, ${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(Le,{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:Tt(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Hn=({data:e,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:p,className:d,style:c})=>{var F,W,I,R,N,O,E,X;const a=te(),{convert:u}=Y(),[x,g]=f.useState(null),[h,y]=f.useState(!1),[k,m]=f.useState(null),[v,b]=f.useState(null),[j,w]=f.useState([]),S=e||x;if(f.useEffect(()=>{if(e||!n||!o)return;let C=!1;return y(!0),m(null),o.getItem(n).then(A=>{C||(A?g(A):m(a.misc.notFoundEntry))}).catch(A=>{C||m(A instanceof Error?A.message:a.misc.loadFailed)}).finally(()=>{C||y(!1)}),()=>{C=!0}},[e,n,o]),f.useEffect(()=>{if(!S||!o){b(null),w([]);return}let C=!1;const A=S.type==="book"||S.type==="collection"?S.work_id:void 0;if(A?o.getItem(A).then(K=>{!C&&K&&K.type==="work"&&b(K)}).catch(()=>{}):b(null),S.type==="book"){const K=S;K.contained_in&&K.contained_in.length>0?Promise.all(K.contained_in.map(U=>{const G=typeof U=="string"?U:U.id,ee=typeof U=="string"?void 0:U.volume_index;return o.getItem(G).then(P=>({id:G,title:P&&P.title||G,volume_index:ee})).catch(()=>({id:G,title:G,volume_index:ee}))})).then(U=>{C||w(U)}):w([])}else w([]);return()=>{C=!0}},[S,o]),h)return t.jsx("div",{className:d,style:{...c,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((C,A)=>t.jsx("div",{style:{height:A===1?"32px":"16px",width:`${C}px`,background:i("widget-border"),borderRadius:"4px",opacity:.4}},A))})});if(k)return t.jsx("div",{className:d,style:{...c,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:k});if(!S)return null;if(S.type==="entity")return t.jsx("div",{className:d,style:c,children:t.jsx(Xi,{data:S,transport:o,onNavigate:r,renderLink:s,headerExtra:l})});const z=S.type==="book"?S:null,_=S.type==="collection"?S:null,T=S.type==="work"?S:null;let B=!1;try{B=ae.extractStatus(S.id)==="draft"}catch{}let L="";S.measure_info?L=u(S.measure_info):(F=S.juan_count)!=null&&F.number?L=er(S.juan_count.number)+a.unit.juan:(W=S.juan_count)!=null&&W.description&&(L=u(S.juan_count.description));const $=[];return(I=S.publication_info)!=null&&I.year&&$.push(t.jsx(Me,{label:a.label.year,children:S.publication_info.year},"year")),(R=S.current_location)!=null&&R.name&&$.push(t.jsx(Me,{label:a.label.currentLocation,children:u(S.current_location.name)},"loc")),(N=S.page_count)!=null&&N.description&&$.push(t.jsx(Me,{label:a.label.pageCount,children:S.page_count.description},"page")),z!=null&&z.edition&&$.push(t.jsx(Me,{label:a.label.edition,children:u(z.edition)},"ver")),T!=null&&T.parent_work&&$.push(t.jsx(Me,{label:a.label.parentWork,children:t.jsx(Le,{id:T.parent_work.id,label:u(T.parent_work.title),onNavigate:r,renderLink:s})},"pw")),T!=null&&T.parent_works&&T.parent_works.length>0&&!T.parent_work&&$.push(t.jsx(Me,{label:a.label.parentWork,children:T.parent_works.map((C,A)=>t.jsxs("span",{children:[A>0&&"、",t.jsx(Le,{id:C,onNavigate:r,renderLink:s})]},C))},"pws")),t.jsxs("div",{className:d,style:c,children:[t.jsx(zl,{id:S.id,title:u(S.title),edition:S.edition?u(S.edition):void 0,type:S.type,isDraft:B,authors:S.authors,volumeText:L,meta:$,headerExtra:l,onNavigate:r,renderLink:s}),((O=S.description)==null?void 0:O.text)&&t.jsx(Ye,{text:S.description.text,style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),S.appendix&&S.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:S.appendix.map((C,A)=>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(C.title)}),t.jsx(Ye,{text:C.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:i("fg")}})]},A))}),j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ie,{children:a.section.containedIn}),t.jsx(Wl,{items:j,onNavigate:r,renderLink:s})]}),v&&t.jsxs(t.Fragment,{children:[t.jsx(Ie,{children:a.section.belongsToWork}),t.jsx(Nl,{workData:v,onNavigate:r,renderLink:s})]}),S.additional_works&&S.additional_works.length>0&&t.jsx(Tl,{items:S.additional_works}),S.additional_titles&&S.additional_titles.length>0&&t.jsx(Cl,{items:S.additional_titles}),S.attached_texts&&S.attached_texts.length>0&&t.jsx(Il,{items:S.attached_texts}),S.indexed_by&&S.indexed_by.length>0&&t.jsx($l,{items:S.indexed_by,onNavigate:r,renderLink:s}),S.emendated_by&&S.emendated_by.length>0&&t.jsx(ir,{items:S.emendated_by,onNavigate:r,renderLink:s}),S.resources&&S.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ie,{children:a.section.resources}),t.jsx(On,{items:S.resources,resourceGroups:S.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(z==null?void 0:z.location_history)&&z.location_history.length>0&&t.jsx(Rl,{items:z.location_history}),(_==null?void 0:_.history)&&_.history.length>0&&t.jsx(El,{items:_.history}),(z==null?void 0:z.related_books)&&z.related_books.length>0&&t.jsx(Vo,{title:a.section.relatedVersions,ids:z.related_books,transport:o,onNavigate:r,renderLink:s}),(_==null?void 0:_.books)&&_.books.length>0&&t.jsx(Vo,{title:a.section.containedBooks,ids:_.books,transport:o,onNavigate:r,renderLink:s}),(_==null?void 0:_.contained_works)&&_.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(Ie,{children:[a.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",_.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:_.contained_works.map(C=>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(Le,{id:C.id,label:u(C.title),onNavigate:r,renderLink:s})},C.id))})]}),(((E=T==null?void 0:T.books)==null?void 0:E.length)||0)+(((X=T==null?void 0:T.collections)==null?void 0:X.length)||0)>0&&t.jsx(Ll,{ids:[...(T==null?void 0:T.books)||[],...(T==null?void 0:T.collections)||[]],workData:T,transport:o,onNavigate:r,renderLink:s,footer:p}),(T==null?void 0:T.related_works)&&T.related_works.length>0&&(()=>{const C=[],A=T.related_works.filter(q=>q.relation==="part_of"),K=T.related_works.filter(q=>q.relation==="has_part"),U=T.related_works.filter(q=>q.relation==="has_adaptation"),G=T.related_works.filter(q=>q.relation==="text_carried_by"),ee=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),P=T.related_works.filter(q=>!q.relation||!ee.has(q.relation));return A.length>0&&C.push({label:a.section.belongsToWork,items:A}),K.length>0&&C.push({label:a.section.containedWorks,items:K}),U.length>0&&C.push({label:a.section.adaptations,items:U}),G.length>0&&C.push({label:a.section.derivativeWorks,items:G}),P.length>0&&C.push({label:a.section.relatedWorks,items:P}),C.map(q=>t.jsxs("div",{children:[t.jsxs(Ie,{children:[q.label,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",q.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:q.items.map(Z=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:t.jsx(Le,{id:Z.id,label:u(Z.title),onNavigate:r,renderLink:s})},Z.id))})]},q.label))})()]})};function Al({data:e}){const n=te(),{convert:o}=Y(),{stats:r}=e,s=r.processed_volumes??r.total_found_volumes,l=s!=null&&e.total_volumes>0?Math.round(s/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color: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 Ml({sections:e,activeSection:n,onSelect:o}){const r=te();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>o(null),style:Uo(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>o(s.name),style:Uo(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 Uo(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 Fl({id:e,label:n,onNavigate:o,renderLink:r}){const s=je();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 Pl(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 Yo({book:e,onNavigate:n,renderLink:o,showVolumes:r}){const s=te(),{convert:l}=Y(),p=e.book_id||e.work_id,d=r&&e.volumes.length>0?Pl(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:d}),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]}),p&&t.jsx(Fl,{id:p,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!p&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const Dn=({data:e,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:l,style:p})=>{const d=te(),[c,a]=f.useState(null),[u,x]=f.useState(!1),[g,h]=f.useState(null),[y,k]=f.useState(null),[m,v]=f.useState(""),b=e||c;f.useEffect(()=>{if(e||!n||!(o!=null&&o.getCollectionCatalog))return;let _=!1;return x(!0),h(null),o.getCollectionCatalog(n).then(T=>{_||(T?a(T):h(d.catalog.notFound))}).catch(T=>{_||h(T instanceof Error?T.message:d.catalog.loadFailed)}).finally(()=>{_||x(!1)}),()=>{_=!0}},[e,n,o,d]);const j=(b==null?void 0:b.sections)&&b.sections.length>0,w=f.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const _=b.books.map(B=>B.volumes[0]).filter(B=>B!=null);return new Set(_).size<_.length},[b]),S=f.useMemo(()=>{if(!b)return[];let _=b.books;if(y&&(_=_.filter(T=>T.section===y)),m.trim()){const T=m.trim().toLowerCase();_=_.filter(B=>B.title.toLowerCase().includes(T)||B.sub_items&&B.sub_items.some(L=>L.toLowerCase().includes(T))||B.edition&&B.edition.toLowerCase().includes(T))}return _},[b,y,m]),z=f.useMemo(()=>{if(!w)return null;const _=[],T=new Map;for(const L of S){if(!L.volumes||L.volumes.length===0)continue;const $=L.volumes[0];T.has($)||T.set($,[]),T.get($).push(L)}const B=[...T.keys()].sort((L,$)=>L-$);for(const L of B)_.push({volume:L,books:T.get(L)});return _},[S,w]);return u?t.jsx("div",{className:l,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):g?t.jsx("div",{className:l,style:{...p,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:g}):b?t.jsxs("div",{className:l,style:p,children:[t.jsx(Al,{data:b}),j&&t.jsx(Ml,{sections:b.sections,activeSection:y,onSelect:k}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:m,onChange:_=>v(_.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:[S.length," ",d.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[z?z.map((_,T)=>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:Tt(d.catalog.volume,{n:_.volume})}),_.books.map((B,L)=>t.jsx(Yo,{book:B,onNavigate:r,renderLink:s,showVolumes:B.volumes.length>1},`${_.volume}-${L}`))]},`${_.volume}-${T}`)):S.map((_,T)=>t.jsx(Yo,{book:_,onNavigate:r,renderLink:s,showVolumes:!0},T)),S.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},tt=()=>{const[e,n]=f.useState(1);return f.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:i("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(e)})},sr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Ol={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function be(e){return Ol[e]??e}const dt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],pt={熹平: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},lr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Jt(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 Hl(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 Dl=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Ko={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Gn(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(Ko))if(n.startsWith(s))return Ko[s];const o=be(n);if(qe[o]!=null)return o;const r=Ge(n);if(r&&n.length<=r.length+1)return be(r)}function Ke(e,n){if(n){const o=lr[`${n}|${e}`];if(o!=null)return o}return pt[e]}const Gl=1911;function Vl(e){const n=pt[e];if(n==null)return;const o=Fe[e];let r;for(const[s,l]of Object.entries(pt))Fe[s]===o&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const Ul={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Vt(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 p=Ul[l];if(p===void 0)return;r=!0,l==="十"?o=(o||1)*10:l==="廿"||l==="卅"?(n+=p,o=0):o>=10?(n+=o+p,o=0):o=o*10+p}const s=n+o;return r&&s>0?s:void 0}function Ge(e){for(const n of sr)if(e.startsWith(n))return n}const Fe={};{const e=(n,o)=>{for(const r of o)Fe[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Je(e,n){const o=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(pt))if(e.includes(r)&&!(o&&Fe[r]&&Fe[r]!==o&&lr[`${o}|${r}`]==null))return r}function Rt(e){var p,d,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=(p=e.lineage)==null?void 0:p.year_text;if(r){const a=Ge(r)??"";return{era:be(a),reign:Je(r,a)??"",source:"lineage"}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const a=Jt(s);if(a)return{era:Hl(a.from),reign:"",source:"publication"};const u=Ge(s)??Gn(s)??((c=dt.find(h=>h.pattern.test(s)))==null?void 0:c.era)??"",x=Je(s,u)??"",g=u||(x?Fe[x]??"":"");if(g||x)return{era:be(g),reign:x,source:"publication"}}const l=e.edition||e.title||"";if(l){const a=Ge(l);if(a)return{era:be(a),reign:Je(l,a)??"",source:"edition"};const u=dt.find(x=>x.pattern.test(l));if(u)return{era:be(u.era),reign:Je(l,u.era)??u.reign??"",source:"edition"}}return n}function Zt(e){var r,s,l,p,d,c,a,u,x;if(((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;if(typeof((s=e.lineage)==null?void 0:s.year)=="number")return e.lineage.year;const n=(l=e.publication_info)==null?void 0:l.year;if(n){const g=Jt(n);if(g)return g.from}const o=[(p=e.lineage)==null?void 0:p.year_text,(d=e.publication_info)==null?void 0:d.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const g of o){const h=((c=e.publication_info)==null?void 0:c.year)||((a=e.lineage)==null?void 0:a.year_text);if(h&&g!==h&&(Ge(h)||Gn(h)))break;const y=g.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??g.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(y){const j=parseInt(y[1],10);if(j>=100&&j<=2100)return j}const k=g.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(k){const j=Ge(g);if(!j||be(j)==="民國"){const S=Vt(k[1]);if(S!=null&&S>=1&&S<=120)return Gl+S}}const m=Ge(g)??((u=dt.find(j=>j.pattern.test(g)))==null?void 0:u.era),v=m?be(m):void 0,b=Je(g,v)??(Ge(g)||(x=dt.find(j=>j.pattern.test(g)))==null?void 0:x.reign);if(b){const j=Ke(b,v);if(j==null)continue;const w=g.indexOf(b),S=w>=0?g.slice(w+b.length):"",z=S.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??S.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),_=z?Vt(z[1]):void 0;return j+(_?_-1:0)}}}function Vn(e){var p,d,c,a,u,x;const n=(p=e.dating)==null?void 0:p.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const o=(d=e.lineage)==null?void 0:d.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 g=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const h=kn[be(g[1])],y=qe[be(g[2])];if(h!=null&&y!=null)return{from:Math.min(h,y)-20,to:Math.max(h,y)+40}}}const s=(a=e.publication_info)==null?void 0:a.year;if(s){const g=Jt(s);if((g==null?void 0:g.to)!=null)return{from:g.from,to:g.to};const h=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(h){const y=kn[be(h[1])],k=qe[be(h[2])];if(y!=null&&k!=null)return{from:Math.min(y,k)-20,to:Math.max(y,k)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const g of l){if(!/[間间]/.test(g))continue;const h=Ge(g)??Gn(g)??((x=dt.find(m=>m.pattern.test(g)))==null?void 0:x.era),y=h?be(h):void 0,k=[];for(const m of Object.keys(pt))g.includes(m)&&(y&&Fe[m]&&Fe[m]!==y||Ke(m,y)!=null&&k.push(m));if(k.length===0){const m=g.match(/([一-鿿])([一-鿿])[間间]/);if(m&&y){for(const v of[m[1],m[2]])for(const b of Object.keys(pt))if(Fe[b]===y&&!(b[0]!==v&&b[b.length-1]!==v)&&Ke(b,y)!=null){k.push(b);break}}}if(k.length>0){const m=k.map(w=>Ke(w,y)).filter(w=>w!=null),v=Math.min(...m),b=k.reduce((w,S)=>Ke(w,y)>=Ke(S,y)?w:S),j=Vl(b)??cn(y??"")??Math.max(...m);return{from:v,to:j>v?j:cn(y??Fe[b]??"")??v}}if(y&&qe[y]!=null)return{from:qe[y],to:cn(y)??qe[y]}}}const qe={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Yl=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Kl=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,qo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Jo(e,n){for(const o of sr){const r=e.indexOf(o);if(r<0)continue;if(o.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!Je(e.slice(r),be(o)))continue}const s=be(o);if(s===n)continue;const l=e.slice(r),p=Je(l,s)??"";let d;if(p){const c=Ke(p,s);if(c!=null){const u=l.slice(l.indexOf(p)+p.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),x=u?Vt(u[1]):void 0;d=c+(x?x-1:0)}}return{era:s,reign:p,year:d}}for(const o of dt)if(o.pattern.test(e))return{era:be(o.era),reign:o.reign??""}}function ql(e){var v,b,j,w,S;const n=Rt(e),o=((v=e.publication_info)==null?void 0:v.year)??"",r=o?Jt(o):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),p=((b=e.lineage)==null?void 0:b.year_text)??"",d=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(p),c=n.source==="publication"&&Dl.test(o),a=n.source==="publication"&&/[間间]/.test(o),u=p.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let x;l||d||c||a?x=void 0:u?x=parseInt(u[2],10):x=Zt(e);const g=x==null?Vn(e):void 0;let h;n.source==="publication"&&(c||qo.test(o))?h="uncertain":n.source==="lineage"||n.source==="publication"?h="attested":qo.test(s)||!n.reign&&x==null?h="uncertain":h="inferred";const y=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((j=e.lineage)==null?void 0:j.year_text)??((w=e.lineage)==null?void 0:w.year)??""}」`:`出版著錄「${((S=e.publication_info)==null?void 0:S.year)??""}」`,k={era:n.era,reign:n.reign,year:x,yearRange:g,certainty:h,source:n.source==="edition"?"edition":"catalog",basis:y};if(u){const z=p.match(/[、,,]\s*([宋元明清])/);z&&z[1]!==k.era&&(k.laterRepair={era:z[1]})}if(!k.laterRepair&&Kl.test(s)){const z=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);z&&z[1]!==n.era&&(k.laterRepair={era:z[1]})}const m=Yl.find(z=>z.re.test(s));if(m){const z=s.search(m.re),_=s.slice(z),T=Jo(_,n.era)??Jo(s,n.era);T&&(k.basedOn={era:T.era,reign:T.reign,year:T.year,relation:m.relation})}return k}const kn={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function cn(e){return kn[e]}function ar(e){const n=Zt(e);if(n!=null)return n;const o=Vn(e);if(o)return o.from;const r=Rt(e).era;return r?qe[r]:void 0}const Zo=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Sn(e){const n=Zo.indexOf(e);return n===-1?Zo.length:n}function Jl(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 Xt(e,n){const o=Mn(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,x)=>{const g=h=>h.group_role==="origin"?0:h.group_role==="mirror"?1:2;return g(u)-g(x)});const l={text:[],image:[],textImage:[],physical:[]};for(const a of s){const u=Xe(a),x=u.includes("text"),g=u.includes("image");x&&g?l.textImage.push(a):x?l.text.push(a):g?l.image.push(a):l.physical.push(a)}const d=["text","image","textImage","physical"].filter(a=>l[a].length>0).map(a=>({key:a,items:l[a]})),c=[...r.entries()].map(([a,u])=>{var x,g;return{key:a,label:((x=n==null?void 0:n[a])==null?void 0:x.label)||a,description:(g=n==null?void 0:n[a])==null?void 0:g.description,items:u}});return{buckets:d,mirrors:c,total:o.length}}function Et(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=Kt(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 cr(e,n){if(Et(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 dr(e,n){var l,p;const o=e.resources||[],r=[],s=[];for(const d of o){const c=Xe(d);c.includes("image")&&r.push(d),c.includes("physical")&&s.push(d)}return{id:e.id,name:e.edition||e.title||e.id,era:Rt(e),year:Zt(e),sortYear:ar(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:Zl(e.id,n),group:(p=n==null?void 0:n.node_groups)==null?void 0:p[e.id],hasImage:r.length>0}}function Zl(e,n){var d,c;if(!n)return!1;const o=n.default_collection;if(!o)return!1;const r=(d=n.collections)==null?void 0:d[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)??[],p=(c=n.node_groups)==null?void 0:c[e];return!!p&&l.includes(p)}function pr(e,n,o={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!r.has(c.id)).map(c=>dr(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,x=a.r.sortYear;return u!=null&&x!=null?u-x||c.i-a.i:u!=null?-1:x!=null?1:c.i-a.i}).map(c=>c.r):l=l.map((c,a)=>({r:c,i:a})).sort((c,a)=>{const u=x=>(x.important?0:1)*2+(x.hasImage?0:1);return u(c.r)-u(a.r)||c.i-a.i}).map(c=>c.r);const d=[...new Set(s.map(c=>c.era.era).filter(Boolean))].sort((c,a)=>Sn(c)-Sn(a));return{rows:l,allRows:s,eras:d,hasInferredEra:s.some(c=>c.era.source==="edition")}}function Xl(e,n){var m,v;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const o=(m=n.collections)==null?void 0:m[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,p=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&p.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const d=new Set(r),c=new Set([...s,...p]),a=b=>{if(c.has(b))return!0;const j=n.node_groups[b];return j!=null&&d.has(j)},u=[],x=new Map,g=[];for(const b of e)if(!((v=n.excluded_books)!=null&&v.includes(b)))if(a(b))u.push(b);else{const j=n.node_groups[b];j?(x.has(j)||x.set(j,[]),x.get(j).push(b)):g.push(b)}if(g.length+[...x.values()].reduce((b,j)=>b+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const y=new Map((n.groups??[]).map(b=>[b.id,b])),k=[...x.entries()].map(([b,j])=>{const w=y.get(b);return{id:b,label:(w==null?void 0:w.label)??b,description:w==null?void 0:w.description,ids:j}});return g.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:u,groupedIds:k}}const ur=["撰","編","注","校","譯","繪","其他"],Ql=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function Un(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:o,re:r}of Ql)if(r.test(n))return o;return"其他"}function Yn(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function xr(e){const n=new Map;for(const r of e){const s=Un(r);n.set(s,(n.get(s)??0)+1)}const o=[{cls:"全部",label:"全部",count:e.length}];for(const r of ur){const s=n.get(r);s&&o.push({cls:r,label:r,count:s})}return o.length>2?o:[]}function fr(e,n,o){if(n&&n.books&&n.books.length>0){const s=n.books.map(p=>({id:p.work_id||p.book_id||void 0,title:p.title,section:p.section,volumes:p.volumes||[],subItems:p.sub_items,edition:p.edition,found:p.found_volumes,expected:p.expected_volumes})),l=[...new Set(s.map(p=>p.section).filter(Boolean))];return{rows:s,source:"catalog",sections:l,totalVolumes:n.total_volumes}}return e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(l=>({id:l.id,title:l.title,volumes:$t(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,p;return{id:s,title:((l=o==null?void 0:o.get(s))==null?void 0:l.title)||s,edition:(p=o==null?void 0:o.get(s))==null?void 0:p.edition,volumes:[]}}),source:"books",sections:[]}}function $t(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 Qt(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const o=[...e].sort((l,p)=>l-p),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 ea=["〇","一","二","三","四","五","六","七","八","九"],Xo=["","十","百","千"];function gr(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 p=parseInt(n[l]),d=o-1-l;p===0?s=!0:(s&&r&&(r+="〇"),s=!1,p===1&&d===1&&l===0?r+=Xo[d]:r+=ea[p]+Xo[d])}return r}function ta(e){return e==null?"":typeof e=="string"?e:e.title??""}function Qe(e,n="卷"){var r,s;const o=e;return o.measure_info?o.measure_info:(r=o.juan_count)!=null&&r.number?gr(o.juan_count.number)+n:(s=o.juan_count)!=null&&s.description?o.juan_count.description:""}function hr(e){var r;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 na="guji_markdown";function wn(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 oa=/^□\{guess=([^\s{}]+)\}/;function ia(e,n){const o=e[n+1];return o!==void 0&&!/[A-Za-z/!?>\s]/.test(o)}function ra(e,n){let o=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
|
|
2
|
-
`)return-1;if(s==="\\"){r++;continue}if(s==="[")
|
|
3
|
-
`)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(
|
|
4
|
-
`)return null}const c=
|
|
5
|
-
.bim-d-main.bim-d-main-grid { max-width: ${
|
|
1
|
+
"use strict";var Us=Object.create;var Pi=Object.defineProperty;var Vs=Object.getOwnPropertyDescriptor;var Ys=Object.getOwnPropertyNames;var Ks=Object.getPrototypeOf,qs=Object.prototype.hasOwnProperty;var Js=(e,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Ys(n))!qs.call(e,s)&&s!==i&&Pi(e,s,{get:()=>n[s],enumerable:!(r=Vs(n,s))||r.enumerable});return e};var kt=(e,n,i)=>(i=e!=null?Us(Ks(e)):{},Js(n||!e||!e.__esModule?Pi(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const pe=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),f=require("react"),Zs=require("react-markdown"),Xs=require("remark-gfm"),Qs=e=>`/book-index?id=${e}`,Yo=f.createContext(Qs);function el({buildUrl:e,children:n}){const i=f.useMemo(()=>e,[e]);return t.jsx(Yo.Provider,{value:i,children:n})}function ve(){return f.useContext(Yo)}const Ko="",qo="";function Jo(e){const n=[];let i=!1,r=e;for(;r.length;){const s=i?qo:Ko,l=r.indexOf(s);if(l===-1){n.push({text:r,marked:i});break}l>0&&n.push({text:r.slice(0,l),marked:i}),r=r.slice(l+1),i=!i}return n}function $e(e,n){return{title:e,tokens:n}}const Oi='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',tl=[$e("基础(VS Code 环境下跟随 --vscode-*)",{bg:{value:"#ffffff",vscode:"--vscode-editor-background"},fg:{value:"#333333",vscode:"--vscode-foreground"},"input-bg":{value:"#ffffff",vscode:"--vscode-input-background"},"input-fg":{value:"#333333",vscode:"--vscode-input-foreground"},"input-border":{value:"#cccccc",vscode:"--vscode-input-border"},"widget-border":{value:"#e0e0e0",vscode:"--vscode-widget-border"},"link-fg":{value:"#0066cc",vscode:"--vscode-textLink-foreground"},"desc-fg":{value:"#717171",vscode:"--vscode-descriptionForeground"},primary:{value:"#0078d4",vscode:"--vscode-button-background"},"primary-fg":{value:"#ffffff",vscode:"--vscode-button-foreground"},"primary-soft":{value:"rgba(0, 120, 212, 0.15)",css:"color-mix(in srgb, var(--bim-primary) 15%, transparent)"},danger:{value:"#f44336"},warning:{value:"#ff9800"},success:{value:"#4caf50"},"sidebar-bg":{value:"#f3f3f3",vscode:"--vscode-sideBar-background"},"list-hover-bg":{value:"rgba(0, 0, 0, 0.04)",vscode:"--vscode-list-hoverBackground"},"list-active-bg":{value:"rgba(0, 120, 212, 0.1)",vscode:"--vscode-list-activeSelectionBackground"},"focus-border":{value:"#0078d4",vscode:"--vscode-focusBorder"}}),$e("底色层次 / 文字与描边 / 链接",{"bg-subtle":{value:"#fafafa"},"widget-bg":{value:"#f8f8f8"},muted:{value:"#888888"},border:{value:"#e5e5e5"},"primary-bg":{value:"#fdf4f4"},link:{value:"#1976d2"},"tag-bg":{value:"#f0f0f0"},"accent-bg":{value:"#1976d2"},"on-color-fg":{value:"#ffffff",note:"彩色底(徽章、选中态按钮)上的文字"}}),$e("提示与警告",{"info-fg":{value:"#0c5380"},"info-bg":{value:"#e7f3ff"},"info-border":{value:"#b3dbff"},"warn-fg":{value:"#856404"},"warn-bg":{value:"#fff3cd"},"warn-border":{value:"#ffc107"},"danger-bg":{value:"rgba(244, 67, 54, 0.08)",note:"错误提示条底色"},"danger-soft-bg":{value:"rgba(244, 67, 54, 0.03)",note:"编辑器危险区块"},"danger-soft-border":{value:"rgba(244, 67, 54, 0.13)"}}),$e("遮罩与阴影",{backdrop:{value:"rgba(0, 0, 0, 0.5)",note:"对话框遮罩"},"overlay-bg":{value:"#00000010",note:"轻量遮罩底(图片占位等)"},"shadow-dialog":{value:"0 4px 20px rgba(0, 0, 0, 0.3)"},"shadow-dropdown":{value:"0 4px 12px rgba(0, 0, 0, 0.1)"},"shadow-tooltip":{value:"0 2px 8px rgba(0, 0, 0, 0.08)"},"shadow-fab":{value:"0 2px 8px rgba(0, 0, 0, 0.25)",note:"悬浮按钮(反馈)"},"shadow-card":{value:"0 1px 4px rgba(0, 0, 0, 0.06)",note:"展开的卡片"},"shadow-node":{value:"0 1px 3px rgba(0, 0, 0, 0.1)",note:"谱系图节点"},"shadow-node-selected":{value:"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)"}}),$e("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),$e("资源",{"restype-text":{value:"#2196f3"},"restype-image":{value:"#ff9800"},"restype-text-image":{value:"#9c27b0"},"restype-physical":{value:"#795548"},"missing-fg":{value:"#e67e22",note:"资源缺册提示"},"colormode-bw-bg":{value:"#f5f5f5",note:"影印件色彩模式标记(黑白 / 彩色)"},"colormode-bw-fg":{value:"#757575"},"colormode-color-bg":{value:"#fff8e1"},"colormode-color-fg":{value:"#f57f17"},"progress-active":{value:"#f59e0b",note:"资源导入进度"},"progress-done":{value:"#10b981"},"progress-todo":{value:"#9ca3af"},"check-fine-bg":{value:"#e8f5e9",note:"文字资源校对程度徽章(精校 / 粗校 / AI整理)"},"check-fine-fg":{value:"#2e7d32"},"check-rough-bg":{value:"#fff3e0"},"check-rough-fg":{value:"#e65100"},"check-ai-bg":{value:"#e3f2fd"},"check-ai-fg":{value:"#1565c0"}}),$e("整理本(CollatedEdition)",{"highlight-bg":{value:"#fff59d",note:"搜索命中高亮底"},"highlight-fg":{value:"inherit",root:!1},"section-lei":{value:"#8e6f3e",note:"章节类型标记:类 / 书 / 序 / 结语 / 考证 / 注释"},"section-shu":{value:"#c0392b"},"section-xu":{value:"#1a5276"},"section-jieyu":{value:"#7d6608"},"section-kaozhen":{value:"#5d6d7e"},"section-zhushi":{value:"#6c5b7b"},"section-tag-fg":{value:"#e74c3c",note:"章节标记(△ 等)"},"matchstate-fg":{value:"#b78900",note:"与底本匹配状态提示"},"quality-published":{value:"#1b5e20",note:"文本质量等级(出版 / 精校 / 粗校 / OCR)"},"quality-fine":{value:"#2e7d32"},"quality-rough":{value:"#1565c0"},"quality-ocr":{value:"#e65100"}}),$e("版本传承(VersionLineageGraph / List) / 关系方向(RelationPanel)",{"lost-fg":{value:"#c62828",note:"佚失标记"},"confidence-certain":{value:"#2e7d32",note:"关系置信度"},"confidence-consensus":{value:"#1976d2"},"confidence-probable":{value:"#ed6c02"},"confidence-disputed":{value:"#c62828"},"lineage-edge-consensus":{value:"#555555",note:"⚠️ 同为 consensus,List 徽章用 --bim-confidence-consensus(蓝),Graph 连线用这个(灰)。若要统一,覆盖成 var(--bim-confidence-consensus)"},"relation-up":{value:"#2196f3"},"relation-down":{value:"#4caf50"},"relation-flat":{value:"#ff9800"}}),$e("编辑器视图(主要在 guji-platform 插件中可见)",{"editor-type-work":{value:"#4caf50",note:"⚠️ 与展示视图的 --bim-type-* 是两套配色(历史如此)。若要统一,覆盖成对应的 var(--bim-type-*)"},"editor-type-collection":{value:"#2196f3"},"editor-type-book":{value:"#ff9800"},"editor-type-entity":{value:"#9c27b0"},"source-url":{value:"#2196f3",note:"来源类型(SourceEditor)"},"source-bookid":{value:"#4caf50"},"mode-active-bg":{value:"#2196f3",note:"模式指示器当前态(ModeIndicator)"},"cover-accent":{value:"#8e6f3e",note:'书目卡片「封面」点缀(IndexBrowser resultVariant="card")'}}),$e("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --bim-primary 等控件色",{"page-bg":{value:"#fbf9f3",note:"纸"},"row-hover-bg":{value:"#f5f1e5"},"selection-bg":{value:"#ecdcbc",note:"选区"},"band-bg":{value:"#f0e4cb",note:"全文入口横幅(暖沙)"},"band-bg-hover":{value:"#e6d5b4"},ink:{value:"#2a231c",note:"文字层次:墨 → 正文 → 提要 → meta → 标签 → 提示"},"body-fg":{value:"#3b3228"},"quiet-fg":{value:"#5b4f40"},"meta-fg":{value:"#7b6a54"},"label-fg":{value:"#6f6457",note:"标签 / 提示:2026-09 N3a 调深,纸底与斑马底上对比度均 ≥4.5(原 #a3937b 2.8、#b3a385 2.3)"},"hint-fg":{value:"#756a5e"},accent:{value:"#9c3a2c",note:"朱"},"accent-deep":{value:"#6f2a20",note:"链接 hover"},"rule-strong":{value:"#2a231c",note:"分隔线:强 → 常规 → 虚线 → 提要左线"},rule:{value:"#e4dbc9"},"rule-dashed":{value:"#d6c9ae"},"rule-accent-soft":{value:"#e0d3b6"},"aux-fg":{value:"#6f6457",note:"辅助字(元数据、注记、「·」分隔的浅色小字)。须在 page-bg / zebra-bg 上对比度 ≥4.5(Q5 巡检)"},"card-bg":{value:"#fffdf9",note:"提要卡:抬起的面"},"zebra-bg":{value:"#f6f2eb",note:"表格斑马纹 / 左栏分组底(不画格线,靠这一阶底色分行)"},"tint-bg":{value:"#f3eee6",note:"检索框、悬停"},"shadow-summary":{value:"0 10px 32px rgba(60, 50, 40, 0.07)",note:"提要卡投影"},"flag-bg":{value:"rgba(158, 42, 43, 0.08)",note:"唯一的状态色块「有影印」"},"table-border":{value:"color-mix(in srgb, currentColor 28%, transparent)",root:!1,note:"古籍表格(跟随当前文字色)"},"table-head-bg":{value:"color-mix(in srgb, currentColor 8%, transparent)",root:!1}}),$e("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),$e("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),$e("字体(全站无衬线,2026-09-05 定)",{"font-ui":{value:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif'},"font-body":{value:"system-ui, sans-serif",css:"var(--bim-font-ui)"},"font-serif":{value:Oi,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:Oi,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],nl=Object.assign({},...tl.map(e=>e.tokens)),Zo={};for(const[e,n]of Object.entries(nl))Zo[e]=`var(--bim-${e}, ${n.value})`;function o(e){const n=Zo[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function Qe(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function il(e,n){return Qe(e).includes(n)}const kn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},ol={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};o("quality-published"),o("quality-fine"),o("quality-rough"),o("quality-ocr");const mt=f.createContext(null),Xo={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:o("check-fine-bg"),fg:o("check-fine-fg")},粗校:{label:"粗校",bg:o("check-rough-bg"),fg:o("check-rough-fg")},AI整理:{label:"AI整理",bg:o("check-ai-bg"),fg:o("check-ai-fg")}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入叢編",collectedIn:"收入叢編",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評註",studies:"所考典籍"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"概覽",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄",fullText:"全文",lineage:"版本傳承",feedback:"勘誤反饋",dataSource:"數據源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"數據源與授權"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},workSubtype:{book:"書",article:"篇",poem:"詩",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},rl={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:o("check-fine-bg"),fg:o("check-fine-fg")},粗校:{label:"粗校",bg:o("check-rough-bg"),fg:o("check-rough-fg")},AI整理:{label:"AI整理",bg:o("check-ai-bg"),fg:o("check-ai-fg")}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入丛编",collectedIn:"收入丛编",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评注",studies:"所考典籍"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"概览",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录",fullText:"全文",lineage:"版本传承",feedback:"勘误反馈",dataSource:"数据源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"数据源与授权"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},workSubtype:{book:"书",article:"篇",poem:"诗",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},sl={"zh-Hant":Xo,"zh-Hans":rl},Qo="bim-locale";function ll(){try{const e=localStorage.getItem(Qo);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function al(e){try{localStorage.setItem(Qo,e)}catch{}}const cl="zh-Hans",dl=({locale:e,onLocaleChange:n,children:i})=>{const[r,s]=f.useState(e??cl),l=e??r;f.useEffect(()=>{if(e)return;const u=ll();u&&u!==r&&s(u)},[]);const[p,d]=f.useState(null);f.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(u=>{const x=u.Converter({from:"tw",to:"cn"});d(()=>x)}).catch(()=>{d(()=>u=>u)}):d(null)},[l]);const c=f.useCallback(u=>{s(u),al(u),n==null||n(u)},[n]),a=f.useMemo(()=>({locale:l,setLocale:c,messages:sl[l],converter:p}),[l,c,p]);return t.jsx(mt.Provider,{value:a,children:i})};function ie(){const e=f.useContext(mt);return(e==null?void 0:e.messages)??Xo}const pl=2e3;function V(){const e=f.useContext(mt),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const l=f.useCallback(p=>{if(!p)return"";if(!i)return p;const d=r.current.get(p);if(d!==void 0)return d;const c=i(p);if(r.current.size>=pl){const a=r.current.keys().next().value;a!==void 0&&r.current.delete(a)}return r.current.set(p,c),c},[i]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Lt(e,n){return e.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function ul(e){if(!e)return"";try{const n=new URL(e).hostname,i={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(i[n])return i[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function xl(){return{id:"",name:"",url:"",type:"text",details:""}}const Sn=({items:e,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const l=ie(),[p,d]=f.useState(null),c=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],a=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=y=>{if(!s)return!0;const j=Qe(y);return s==="text"?j.includes("text"):s==="image"?j.includes("image")||j.includes("physical"):s==="physical"?j.includes("physical"):j.includes(s)},x=e.map((y,j)=>({item:y,originalIndex:j})).filter(({item:y})=>u(y)),g=()=>{const y=xl();s&&(y.type=s),n([...e,y]),d(e.length)},h=y=>{n(e.filter((j,$)=>$!==y)),d(null)},b=(y,j,$)=>{const S=[...e];if(S[y]={...S[y],[j]:$},j==="url"&&!S[y].id){const _=ul($);_&&(S[y].id=_)}n(S)},k=(y,j,$)=>{const _={...e[y].metadata||{}};$?_[j]=$:delete _[j],b(y,"metadata",Object.keys(_).length>0?_:void 0)},m=(y,j)=>{const $=j.trim()?j.split(/[,,、]/).map(S=>S.trim()).filter(Boolean):void 0;b(y,"structure",$)},v=(y,j,$)=>{const _=e[y].coverage||{level:1,ranges:""};j==="level"?_.level=parseInt($)||1:_.ranges=$,b(y,"coverage",_.ranges?_:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:y,originalIndex:j})=>{var $,S,_;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>d(p===j?null:j),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:p===j?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:fl(y.type??"text"),color:o("on-color-fg")},children:(()=>{var z,B;const w=Qe(y);return w.length===0?y.type??"text":w.length===1?((z=c.find(E=>E.value===w[0]))==null?void 0:z.label)??w[0]:w.includes("text")&&w.includes("image")?((B=c.find(E=>E.value==="text+image"))==null?void 0:B.label)??"text+image":w.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${l.editor.resourcePlaceholder} ${j+1}`}),y.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:y.id}),y.url&&t.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:w=>w.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&y.url&&gl(j,r==null?void 0:r[j],i,l),t.jsx("button",{onClick:w=>{w.stopPropagation(),h(j)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),p===j&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:[il(y,"image")&&y.url&&hl(y,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:St,children:[t.jsx("span",{style:wt,children:l.label.type}),t.jsx("select",{value:y.type,onChange:w=>b(j,"type",w.target.value),style:{...Ae,flex:1},children:c.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]}),t.jsxs("label",{style:St,children:[t.jsx("span",{style:wt,children:l.label.rootType}),t.jsx("select",{value:y.root_type||"catalog",onChange:w=>b(j,"root_type",w.target.value),style:{...Ae,flex:1},children:a.map(w=>t.jsx("option",{value:w.value,children:w.label},w.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:y.id,onChange:w=>b(j,"id",w.target.value),placeholder:l.editor.idAutoExtract,style:{...Ae,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:y.name,onChange:w=>b(j,"name",w.target.value),placeholder:l.editor.resourceName,style:{...Ae,flex:1}})]}),t.jsx("input",{type:"text",value:y.url,onChange:w=>b(j,"url",w.target.value),placeholder:l.editor.resourceUrl,style:Ae}),t.jsx("input",{type:"text",value:(($=y.structure)==null?void 0:$.join("、"))||"",onChange:w=>m(j,w.target.value),placeholder:l.editor.structurePlaceholder,style:Ae}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:St,children:[t.jsx("span",{style:wt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((S=y.coverage)==null?void 0:S.level)??"",onChange:w=>v(j,"level",w.target.value),placeholder:"1",style:{...Ae,width:"60px"}})]}),t.jsxs("label",{style:{...St,flex:1},children:[t.jsx("span",{style:wt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:((_=y.coverage)==null?void 0:_.ranges)||"",onChange:w=>v(j,"ranges",w.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...Ae,flex:1}})]})]}),t.jsx("textarea",{value:y.details||"",onChange:w=>b(j,"details",w.target.value),placeholder:l.editor.detailsPlaceholder,style:{...Ae,minHeight:"60px",resize:"vertical"}}),t.jsxs("div",{style:{borderTop:`1px solid ${o("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"6px"},children:l.label.metadata}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([w,z])=>{var B;return t.jsxs("label",{style:{...St,gap:"4px"},children:[t.jsx("span",{style:{...wt,minWidth:"56px"},children:z}),t.jsx("input",{type:"text",value:((B=y.metadata)==null?void 0:B[w])||"",onChange:E=>k(j,w,E.target.value),placeholder:z,style:{...Ae,flex:1}})]},w)})})]})]})]})]},j)}),t.jsxs("button",{onClick:g,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:l.action.addResource})]})]})};function fl(e){switch(e){case"text":return o("restype-text");case"image":return o("restype-image");case"text+image":return o("restype-text-image");case"physical":return o("restype-physical")}}function gl(e,n,i,r){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:p=>{p.stopPropagation(),s||i(e,"")},disabled:s,style:{background:"transparent",border:"none",color:o(l?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:l?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":s?"⏳":"⬇"})}function hl(e,n){const i=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(e.url)||e.url.includes("iiif")||e.url.includes("image");return t.jsx("div",{style:{marginBottom:"12px"},children:i?t.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:o("overlay-bg")},children:t.jsx("img",{src:e.url,alt:e.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):t.jsx("div",{style:{padding:"12px",background:o("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:o("desc-fg")},children:n.editor.imageResourceLink})})}const Ae={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},St={display:"flex",alignItems:"center",gap:"6px"},wt={fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap"},ml={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function tt(e){try{return ml[new URL(e).hostname]}catch{return}}const Di={text:0,image:1,physical:2};function On(e){return e.length===0?"physical":[...e].sort((n,i)=>(Di[n]??99)-(Di[i]??99)).join("+")}function Dn(e){var p;const n=d=>{const c=d.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const a=d.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},i=new Map;for(let d=0;d<e.length;d++){const c=e[d];if(c.volumes&&c.volumes.length>0)continue;const a=n(c.name);if(!a)continue;const[u,x]=a,g=`${u}|${On(Qe(c))}`;i.has(g)||i.set(g,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const h=i.get(g);h.volumes.push({volume:x,url:c.url||void 0,status:"found"}),h.indices.push(d)}const r=[],s=new Set;for(const d of i.values())if(!(d.volumes.length<2)){d.volumes.sort((c,a)=>c.volume-a.volume),d.base.volumes=d.volumes,d.base.expected_volumes=d.volumes.length,d.base.url||(d.base.url=((p=d.volumes.find(c=>c.url))==null?void 0:p.url)??""),r.push(d.base);for(const c of d.indices)s.add(c)}const l=[...r];for(let d=0;d<e.length;d++)s.has(d)||l.push(e[d]);return l}function er(e){if(e.url)return e.url;for(const[n,i]of Object.entries(e))if(n.endsWith("_url")&&typeof i=="string")return i}function tr(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||er(n)}))}function Xt(e){const n=tr(e);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,r=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:r,expected:e.expected_volumes??i+r}}function Hn(e){if(!e)return;const n=e.file_page_range||e.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function Gn(e,n){try{if(new URL(e).hostname.includes("wikimedia.org")){const r=e.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const s=new URL(e);return s.searchParams.set("page",String(n)),s.toString()}return e}catch{return e}}function bt(e){if(!e.url)return;const n=Hn(e.metadata);return n?Gn(e.url,n):e.url}const Hi={text:o("restype-text"),image:o("restype-image"),"text+image":o("restype-text-image"),physical:o("restype-physical")};function bl(e){return e.includes("text")&&e.includes("image")?Hi["text+image"]:Hi[e[0]||"physical"]}const Un=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const l=ie(),{convert:p}=V(),d=f.useMemo(()=>Dn(e||[]),[e]),{mirrorGroups:c,ungroupedItems:a}=f.useMemo(()=>{const m=new Map,v=[];for(const y of d){const j=y.group;j?(m.has(j)||m.set(j,[]),m.get(j).push(y)):v.push(y)}for(const y of m.values())y.sort((j,$)=>{const S=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return S(j)-S($)});return{mirrorGroups:m,ungroupedItems:v}},[d]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},x=m=>u[m]?u[m]:m.split("+").map(v=>u[v]||v).join("+");if(!d||d.length===0)return t.jsx("div",{style:{padding:"16px",color:o("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:d.map((m,v)=>t.jsx(dn,{item:m},m.id||v))});const g=(m,v)=>{const y=i==null?void 0:i[m],j=(y==null?void 0:y.label)||m,$=y==null?void 0:y.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:p(j)}),$&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.5},children:p($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((S,_)=>t.jsx(dn,{item:S,onNavigate:r,renderLink:s},S.id||_))})]},`group-${m}`)},h=new Map;for(const m of a){const v=On(Qe(m));h.has(v)||h.set(v,[]),h.get(v).push(m)}const b=["text","image","text+image","physical"],k=[...b.filter(m=>h.has(m)),...[...h.keys()].filter(m=>!b.includes(m)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([m,v])=>g(m,v)),k.map(m=>{const v=h.get(m),y=bl(m.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:y,whiteSpace:"nowrap",flexShrink:0},children:x(m)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((j,$)=>t.jsx(dn,{item:j,onNavigate:r,renderLink:s},j.id||$))})]},m)})]})},yl={bw:{label:"",bg:o("colormode-bw-bg"),fg:o("colormode-bw-fg")},color:{label:"",bg:o("colormode-color-bg"),fg:o("colormode-color-fg")}},dn=({item:e})=>{const n=ie(),{convert:i}=V(),[r,s]=f.useState(!1),l=f.useMemo(()=>(e.url?tt(e.url):void 0)||i(e.name),[e.url,e.name,i]),p=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(b=>({...b,url:b.url||er(b)})),[e.volumes]),d=p&&p.length>0,c=d?new Set(p.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,a=d?new Set(p.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=e.expected_volumes??(d?c+a:0),x=e.color_mode?{...yl[e.color_mode],label:n.colorMode[e.color_mode]}:null,g=e.details&&!d?i(e.details):null,h={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",background:o("input-bg"),fontSize:"12px",color:o("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:h,children:[t.jsx("span",{style:{fontWeight:500},children:l}),x&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),g&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:g}),d&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[c,"/",u,n.unit.volume,a>0&&t.jsxs("span",{style:{color:o("missing-fg"),marginLeft:"3px"},children:["缺",a]})]}),e.url&&t.jsx("a",{href:(()=>{const b=Hn(e.metadata);return b?Gn(e.url,b):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:o("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),d&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),d&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:p.map(b=>{const k=b.status==="missing";return b.url&&!k?t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${o("widget-border")}`,color:o("link-fg"),textDecoration:"none"},children:b.volume},b.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:o(k?"missing-fg":"desc-fg"),textDecoration:k?"line-through":"none",opacity:k?.6:1},children:b.volume},b.volume)})})]})},nr=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:p})=>{const d=ie(),c=e==="local",a=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",x=u?u.split(/[/\\]/).pop()||u:"",g={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:o("primary-soft"),color:o("primary")},h={onMouseOver:k=>k.currentTarget.style.opacity="0.8",onMouseOut:k=>k.currentTarget.style.opacity="1"},b=t.jsxs("div",{onClick:s,title:a?d.mode.switchToOfficial:d.mode.switchToDraft,style:{...g,background:o(a?"warning":"success"),color:o("on-color-fg")},...h,children:[t.jsx("span",{children:a?"📝":"📚"}),t.jsx("span",{children:a?"draft":"official"})]});return i==="index-browser"?c?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,t.jsxs("div",{onClick:r,title:d.mode.switchToSync,style:g,...h,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:d.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:p,title:u||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...h,children:[t.jsx("span",{children:"📂"}),x&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:d.mode.switchToLocal,style:g,...h,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:d.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:x||d.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...h,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:c?d.mode.switchToGithub:d.mode.switchToLocal,style:g,...h,children:[t.jsx("span",{children:c?"📁":"🌐"}),t.jsx("span",{children:c?d.mode.localMode:d.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&t.jsxs("div",{onClick:p,title:u||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...h,children:[t.jsx("span",{children:"📂"}),x&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!c&&x&&t.jsxs("div",{style:{...g,background:o("mode-active-bg"),color:o("on-color-fg"),cursor:"default"},title:u,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Qt="bim-search-history",Gi=10,Ui=8;function Tt(){try{const e=localStorage.getItem(Qt);return e?JSON.parse(e):[]}catch{return[]}}function jl(e){try{const n=Tt().filter(i=>i!==e);n.unshift(e),n.length>Gi&&(n.length=Gi),localStorage.setItem(Qt,JSON.stringify(n))}catch{}}function vl(e){try{const n=Tt().filter(i=>i!==e);localStorage.setItem(Qt,JSON.stringify(n))}catch{}}function kl(){try{localStorage.removeItem(Qt)}catch{}}const ir=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:l})=>{const p=ie(),d=l??p.search.placeholder,c={work:p.indexType.work,book:p.indexType.book,collection:p.indexType.collection,entity:p.indexType.entity},[a,u]=f.useState(!1),[x,g]=f.useState([]),[h,b]=f.useState(-1),[k,m]=f.useState(Tt),v=f.useRef(null),y=f.useRef(null),j=f.useRef(null),$=f.useRef(!1);f.useEffect(()=>{b(-1);const C=n.trim();if(!C){g(k.map(T=>({type:"history",text:T})));return}if(!e.searchAll){g([]);return}let A=!1;const W=setTimeout(()=>{e.searchAll(C,Ui).then(T=>{if(A)return;const L=[...T.works,...T.books,...T.collections,...T.entities??[]];g(L.slice(0,Ui).map(M=>({type:"entry",text:M.title||M.id,entry:M})))}).catch(()=>{A||g([])})},80);return()=>{A=!0,clearTimeout(W)}},[n,k,e]),f.useEffect(()=>{const C=A=>{j.current&&!j.current.contains(A.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=A=>{var W,T;if(A.key==="/"&&document.activeElement!==v.current){const L=(W=document.activeElement)==null?void 0:W.tagName;if(L==="INPUT"||L==="TEXTAREA"||L==="SELECT")return;A.preventDefault(),(T=v.current)==null||T.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const S=f.useCallback(C=>{C.trim()&&(jl(C.trim()),m(Tt())),r(C),u(!1)},[r]),_=f.useCallback(C=>{C.type==="history"?(i(C.text),S(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(i(C.text),S(C.text)))},[i,S,s]),w=f.useCallback(C=>{if(!a||x.length===0){C.key==="Enter"&&S(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(A=>(A+1)%x.length);break;case"ArrowUp":C.preventDefault(),b(A=>(A-1+x.length)%x.length);break;case"Enter":C.preventDefault(),h>=0&&h<x.length?_(x[h]):S(n);break;case"Escape":C.preventDefault(),u(!1);break}},[a,x,h,n,S,_]),z=f.useCallback((C,A)=>{A.stopPropagation(),vl(C),m(Tt()),g(W=>W.filter(T=>!(T.type==="history"&&T.text===C)))},[]),B=f.useCallback(C=>{C.stopPropagation(),kl(),m([]),g([])},[]);f.useEffect(()=>{if(h>=0&&y.current){const C=y.current.children;C[h]&&C[h].scrollIntoView({block:"nearest"})}},[h]);const E=!n.trim()&&k.length>0;return t.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:v,type:"text",placeholder:d,value:n,onChange:C=>{i(C.target.value),u(!0)},onCompositionStart:()=>{$.current=!0},onCompositionEnd:()=>{$.current=!1},onFocus:()=>{u(!0)},onKeyDown:w,style:{width:"100%",padding:"8px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),a&&x.length>0&&t.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:o("input-bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"6px",boxShadow:o("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[E&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:o("desc-fg"),borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("span",{children:p.search.history}),t.jsx("button",{onClick:B,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:p.search.clearAll})]}),x.map((C,A)=>t.jsxs("div",{onClick:()=>_(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:o("fg"),background:A===h?o("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:[c[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&t.jsx("button",{onClick:W=>z(C.text,W),style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:p.action.remove,children:"×"})]},`${C.type}-${C.text}-${A}`))]})]})},ut="bim-recent-ids",Vi="bim-recent-entries",Yi=50,pn=5,Sl=50,wl=200;function at(){try{const e=localStorage.getItem(ut);if(e)return JSON.parse(e);const n=localStorage.getItem(Vi);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(ut,JSON.stringify(i)),localStorage.removeItem(Vi),i}return[]}catch{return[]}}function Ki(e){try{const n=at().filter(i=>i!==e);n.unshift(e),n.length>Yi&&(n.length=Yi),localStorage.setItem(ut,JSON.stringify(n))}catch{}}function _l(e){try{const n=at().filter(i=>i!==e);localStorage.setItem(ut,JSON.stringify(n))}catch{}}function $l(){try{localStorage.removeItem(ut)}catch{}}const zl={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},wn=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:p,onConfigurePath:d,onSelectFolder:c,hideModeIndicator:a,resultVariant:u="compact",renderEntry:x,initialQuery:g,onQueryChange:h,headerRight:b})=>{const k=ie(),m=[{type:"work",icon:"✍️",name:k.indexType.work,key:"works"},{type:"book",icon:"📖",name:k.indexType.book,key:"books"},{type:"collection",icon:"📚",name:k.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:k.indexType.entity,key:"entities"}],[v,y]=f.useState(g??""),[j,$]=f.useState(null),[S,_]=f.useState(null),[w,z]=f.useState(!1),[B,E]=f.useState(null),[C,A]=f.useState(""),[W,T]=f.useState(!g),[L,M]=f.useState(at),[P,R]=f.useState([]),[ne,I]=f.useState(!1),[F,K]=f.useState(!1),[G,U]=f.useState(null),[te,O]=f.useState(null),Y=f.useRef(void 0),Z=f.useRef(!1),X=f.useCallback(async(Q,q)=>{if(!Q.trim()){T(!0),$(null),_(null);return}T(!1),z(!0),A("");try{if(e.searchAll){const N=await e.searchAll(Q,q??pn);$(N)}else{const N=["work","book","collection","entity"],ee=await Promise.all(N.map(re=>e.search(Q,re,{page:1,pageSize:q??pn})));$({works:ee[0].entries,books:ee[1].entries,collections:ee[2].entries,entities:ee[3].entries,totalWorks:ee[0].total,totalBooks:ee[1].total,totalCollections:ee[2].total,totalEntities:ee[3].total})}}catch(N){A(N instanceof Error?N.message:String(N)),$(null)}finally{z(!1)}},[e]);f.useEffect(()=>{let Q=!1;const q=()=>{var ae,ke;const N=["work","book","collection","entity"],ee=Promise.all(N.map(Ne=>e.loadEntries(Ne,{page:1,pageSize:1}).catch(()=>({total:0})))),re=((ae=e.getResourceCounts)==null?void 0:ae.call(e).catch(()=>null))??Promise.resolve(null),be=((ke=e.getSubtypeStats)==null?void 0:ke.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([ee,re,be]).then(([Ne,Se,De])=>{Q||(U({works:Ne[0].total,books:Ne[1].total,collections:Ne[2].total,entities:Ne[3].total,hasText:Se==null?void 0:Se.hasText,hasImage:Se==null?void 0:Se.hasImage}),De&&O(De))})};return e.getCounts?e.getCounts().then(N=>{var ee,re;Q||(U({works:N.works,books:N.books,collections:N.collections,entities:N.entities,hasText:(ee=N.resourceCounts)==null?void 0:ee.hasText,hasImage:(re=N.resourceCounts)==null?void 0:re.hasImage}),N.subtypeStats&&O(N.subtypeStats))}).catch(()=>{Q||q()}):q(),()=>{Q=!0}},[e]),f.useEffect(()=>{Z.current||!(g!=null&&g.trim())||(Z.current=!0,X(g))},[g,X]);const se=f.useCallback(Q=>{if(y(Q),!Q.trim()){h==null||h(Q),T(!0),$(null),_(null);return}Y.current&&clearTimeout(Y.current),Y.current=setTimeout(()=>{_(null),h==null||h(Q),X(Q)},wl)},[X,h]),ge=f.useCallback(Q=>{Y.current&&clearTimeout(Y.current),h==null||h(Q),X(Q)},[X,h]),he=f.useCallback(Q=>{_(Q),X(v,Sl)},[v,X]);f.useEffect(()=>{if(!L.length){R([]);return}let Q=!1;return I(!0),Promise.all(L.slice(0,10).map(async q=>{var N,ee,re;try{if(e.getEntry){const ae=await e.getEntry(q);if(ae)return ae}const be=await e.getItem(q);if(be){const ae=be.authors;return{id:q,title:be.title||q,type:be.type||"work",author:(N=ae==null?void 0:ae[0])==null?void 0:N.name,dynasty:(ee=ae==null?void 0:ae[0])==null?void 0:ee.dynasty,role:(re=ae==null?void 0:ae[0])==null?void 0:re.role,edition:be.edition||void 0}}}catch{}return{id:q,title:q,type:"work",notFound:!0}})).then(q=>{Q||(R(q),I(!1))}),()=>{Q=!0}},[L,e]);const D=Q=>{E(Q.id),Ki(Q.id),M(at()),r==null||r(Q)},le=(Q,q)=>{if(r&&Cl(q)){q.preventDefault(),D(Q);return}Ki(Q.id),M(at())},oe=Q=>{_l(Q),M(at())},ce=()=>{$l(),M([])},ue=Q=>m.find(q=>q.type===Q),me=j&&(j.works.length>0||j.books.length>0||j.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",children:[t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("h1",{style:{margin:0,fontSize:"18px",color:o("fg")},children:k.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!a&&t.jsx(nr,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:l,onToggleDraft:p,onConfigurePath:d,onSelectFolder:c})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(ir,{transport:e,value:v,onChange:se,onSearch:ge,onEntrySelect:D}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${o("primary")}`,borderRadius:"6px",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"13px"},children:k.action.newEntry})]}),G&&W&&t.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[t.jsx("span",{children:te?t.jsxs(t.Fragment,{children:[(te.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:o("fg")},children:te.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:o("fg")},children:G.books.toLocaleString()})," 本"]}),te.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:o("fg")},children:te.article.toLocaleString()})," 篇"]}):null,te.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:o("fg")},children:te.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:o("fg")},children:G.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[k.indexType.work," ",t.jsx("strong",{style:{color:o("fg")},children:G.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.indexType.book," ",t.jsx("strong",{style:{color:o("fg")},children:G.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.indexType.collection," ",t.jsx("strong",{style:{color:o("fg")},children:G.collections.toLocaleString()}),G.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.indexType.entity," ",t.jsx("strong",{style:{color:o("fg")},children:G.entities.toLocaleString()})]})]})}),G.hasImage!=null&&G.hasText!=null&&t.jsxs("span",{children:[k.resourceType.image," ",t.jsx("strong",{style:{color:o("fg")},children:G.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),k.resourceType.text," ",t.jsx("strong",{style:{color:o("fg")},children:G.hasText.toLocaleString()})]})]}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:w?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:k.search.searching}):C?t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),t.jsx("p",{style:{color:o("desc-fg")},children:C})]}):W?t.jsx("div",{style:{flex:1},children:ne?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:k.search.loading}):P.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:k.search.recentBrowse}),t.jsx("button",{onClick:ce,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:k.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:P.slice(0,F?10:3).map(Q=>Q.notFound?t.jsx(Rl,{id:Q.id,onRemove:oe,t:k},Q.id):t.jsx(qi,{entry:Q,selected:B===Q.id,onClick:le,getConfig:ue,onRemove:oe},Q.id))}),!F&&P.length>3&&t.jsx("button",{onClick:()=>K(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:k.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h3",{style:{margin:"0 0 8px",color:o("fg")},children:k.search.searchTitle}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:k.search.searchSubtitle})]})}):me?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:m.map(({type:Q,icon:q,name:N,key:ee})=>{const re=j[ee]??[],be=zl[ee],ae=j[be]??0;if(re.length===0)return null;const Ne=!(S===Q)&&ae>pn;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${o("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:[q," ",N,t.jsxs("span",{style:{fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[ae," ",k.unit.items]})]}),Ne&&t.jsx("button",{onClick:()=>he(Q),style:{border:"none",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"12px"},children:k.action.viewAll})]}),t.jsx("div",{style:u==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:re.map(Se=>{if(x)return t.jsx(f.Fragment,{children:x(Se)},Se.id);const De=u==="card"?Tl:qi;return t.jsx(De,{entry:Se,selected:B===Se.id,onClick:le,getConfig:ue,query:v},Se.id)})})]},Q)})}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h3",{style:{margin:"0 0 8px",color:o("fg")},children:Lt(k.search.noResultsFor,{query:v})}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:k.search.tryOther})]})})]})};function Cl(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const or={color:"inherit",textDecoration:"none"},Il=({snippet:e})=>{const{convert:n}=V();return t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.6},children:Jo(e).map((i,r)=>i.marked?t.jsx("mark",{style:{background:o("highlight-bg"),color:o("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(i.text)},r):t.jsx(f.Fragment,{children:n(i.text)},r))})},Tl=({entry:e,selected:n,onClick:i,getConfig:r,query:s})=>{const l=ie(),{convert:p}=V(),d=p(e.title||e.primary_name||e.id),c=e.measure_info?p(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",a=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&a.length?a.find(h=>{const b=typeof h=="string"?h:h==null?void 0:h.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,x=o("cover-accent"),g=ve();return t.jsxs("a",{href:g(e.id),onClick:h=>i(e,h),className:"bim-result-card",style:{...or,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:o("bg"),border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[t.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${x} 50%, ${o("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${x} 14%, ${o("bg")}), color-mix(in srgb, ${x} 7%, ${o("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[t.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${x} 45%, transparent)`}}),t.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:x},children:Array.from(d).map((h,b)=>t.jsx("span",{children:h},b))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:o("fg")},children:d}),c&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",p(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:p(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",p(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",p(e.era),"〕"]}),e.edition&&t.jsx("span",{children:p(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[l.search.alias,":",p(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(Il,{snippet:e.descriptionSnippet}),t.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[t.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:[r(e.type).icon," ",r(e.type).name]}),e.has_text&&t.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:["📝 ",l.misc.textResource]}),e.has_image&&t.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:o("desc-fg"),border:`1px solid ${o("widget-border")}`},children:["🖼️ ",l.misc.imageResource]})]})]})]})},qi=({entry:e,selected:n,onClick:i,getConfig:r,query:s,onRemove:l})=>{const p=ie(),{convert:d}=V(),c=[...e.additional_titles||[],...e.attached_texts||[]],a=s&&c.length?c.find(x=>{const g=typeof x=="string"?x:x==null?void 0:x.book_title;return g==null?void 0:g.toLowerCase().includes(s.toLowerCase())}):void 0,u=ve();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("a",{href:u(e.id),onClick:x=>i(e,x),className:"bim-result-card",style:{...or,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx("span",{style:{fontSize:"16px"},children:r(e.type).icon}),t.jsx("span",{style:{fontSize:"9px",color:o("desc-fg"),lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:d(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{title:p.misc.textResource,children:"📝"}),e.has_image&&t.jsx("span",{title:p.misc.imageResource,children:"🖼️"})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",d(e.era),"〕"]}),e.edition&&d(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:d(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.juan_count,p.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",d(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:d(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",d(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),a&&t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:[p.search.alias,":",d(a)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:p.search.removeFromRecent,"aria-label":p.search.removeFromRecent,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},Rl=({id:e,onRemove:n,t:i})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${o("widget-border")}`,background:o("input-bg"),opacity:.6},children:[t.jsx("span",{style:{fontSize:"16px"},children:"❓"}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:"13px",color:o("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:i.search.itemNotFound})]}),t.jsx("button",{onClick:()=>n(e),title:i.search.removeFromRecent,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function El(e){var n;return!e.dynasty&&!e.birth_year&&!e.death_year&&(!e.alt_names||e.alt_names.length===0)&&!((n=e.description)!=null&&n.text)}function Ll({data:e}){const{convert:n}=V(),{dynasty:i,birth_year:r,death_year:s}=e,l=[];return i&&l.push(`〔${n(i)}〕`),r!==void 0&&s!==void 0?l.push(`${r}—${s}`):r!==void 0?l.push(`${r}—?`):s!==void 0&&l.push(`?—${s}`),l.length===0?null:t.jsx("span",{style:{fontSize:"14px",color:o("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function Nl({alt_names:e}){const{convert:n}=V(),i=new Map;for(const l of e){const p=l.type||"別名";i.has(p)||i.set(p,[]),i.get(p).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((l,p)=>{const d=r.indexOf(l),c=r.indexOf(p);return d===-1&&c===-1?0:d===-1?1:c===-1?-1:d-c});return t.jsx("div",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const p=i.get(l);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:o("desc-fg"),fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),t.jsx("span",{children:p.map((d,c)=>t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),n(d)]},c))})]},l)})})}function Bl({data:e}){const n=e.external_ids;if(!n)return null;const i=[];return n.cbdb_id&&i.push(t.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:o("link-fg"),border:`1px solid ${o("link-fg")}40`,borderRadius:"3px",textDecoration:"none",background:`${o("link-fg")}08`},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),i.length===0?null:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:i})}function Wl({works:e,transport:n,onNavigate:i,renderLink:r}){const s=ie(),{convert:l}=V(),p=ve(),[d,c]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let g=!1;const h=e.map(k=>k.work_id);return(async()=>{const k=new Map;if(n.getEntriesByIds)try{const j=await n.getEntriesByIds(h);let $=!0;for(let S=0;S<h.length;S++){const _=j[S];_!=null&&_.title?k.set(h[S],_.title):_!=null&&_.primary_name?k.set(h[S],_.primary_name):$=!1}if($)return k}catch{}const m=[...h],v=8,y=new Array(v).fill(0).map(async()=>{for(;m.length;){const j=m.shift();if(!j)break;if(!k.has(j))try{if(n.getEntry){const _=await n.getEntry(j);if(_!=null&&_.title){k.set(j,_.title);continue}}const $=await n.getItem(j),S=$&&($.title||$.primary_name)||j;k.set(j,S)}catch{k.set(j,j)}}});return await Promise.all(y),k})().then(k=>{g||c(k)}),()=>{g=!0}},[e,n]);const a=new Map;for(const g of e){const h=g.role||"";a.has(h)||a.set(h,[]),a.get(h).push(g)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...a.keys()].sort((g,h)=>{const b=u.indexOf(g),k=u.indexOf(h);return b===-1&&k===-1?g.localeCompare(h):b===-1?1:k===-1?-1:b-k});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:o("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:o("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),x.map(g=>{const h=a.get(g);return t.jsxs("div",{style:{marginBottom:"8px"},children:[g&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"2px"},children:[l(g)," ",t.jsxs("span",{style:{color:o("desc-fg")},children:["(",h.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:h.map((b,k)=>{const m=l(d.get(b.work_id)||b.work_id);return r?t.jsx("li",{children:r(b.work_id,m)},k):i?t.jsx("li",{children:t.jsx("a",{href:p(b.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),i(b.work_id))},style:{color:o("link-fg"),textDecoration:"underline",cursor:"pointer"},children:m})},k):t.jsx("li",{children:m},k)})})]},g)})]})}const rr=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:l})=>{var x;const p=ie(),{convert:d}=V();let c=!1;try{c=pe.extractStatus(e.id)==="draft"}catch{}const a=El(e),u=e.subtype==="people"?"人物":e.subtype==="place"?"地名":e.subtype==="dynasty"?"朝代":e.subtype==="anonymous"?"佚名":e.subtype==="collective"?"集体":e.subtype;return t.jsxs("div",{children:[!l&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:o("fg")},children:[d(e.primary_name),t.jsx(Ll,{data:e})]}),s]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o("type-entity"),border:`1px solid color-mix(in srgb, ${o("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${o("type-entity")} 3%, transparent)`},children:p.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),c&&t.jsx("span",{style:{padding:"1px 6px",background:o("warn-bg"),border:`1px solid ${o("warn-border")}`,borderRadius:"2px",color:o("warn-fg")},children:p.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),a&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:o("widget-bg"),border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(Nl,{alt_names:e.alt_names}),t.jsx(Bl,{data:e}),((x=e.description)==null?void 0:x.text)&&t.jsx("p",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:d(e.description.text)}),e.works&&e.works.length>0&&t.jsx(Wl,{works:e.works,transport:n,onNavigate:i,renderLink:r})]})},sr={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>t.jsx("a",{href:e,target:e!=null&&e.startsWith("http")?"_blank":void 0,rel:e!=null&&e.startsWith("http")?"noopener noreferrer":void 0,style:{color:o("link")},children:n}),code:({children:e})=>t.jsx("code",{style:{background:o("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})},Al={...sr,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},Ke=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:s}=V(),l=n?Al:sr;return t.jsx("div",{className:r,style:i,children:t.jsx(Zs,{remarkPlugins:[Xs],components:l,children:s(e)})})},Ml=["〇","一","二","三","四","五","六","七","八","九"],Ji=["","十","百","千"];function lr(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const p=parseInt(n[l]),d=i-1-l;p===0?s=!0:(s&&r&&(r+="〇"),s=!1,p===1&&d===1&&l===0?r+=Ji[d]:r+=Ml[p]+Ji[d])}return r}function ar(e){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:e,border:`1px solid color-mix(in srgb, ${e} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${e} 3%, transparent)`}}const Fl={book:o("type-book"),work:o("type-work"),collection:o("type-collection"),entity:o("type-entity")};function Pl({type:e}){const n=ie();return t.jsx("span",{style:ar(Fl[e]),children:n.indexType[e]})}function Ol({isDraft:e}){const n=ie(),i=o(e?"status-draft":"status-official");return t.jsx("span",{style:ar(i),children:e?n.status.draft:n.status.official})}function Dl({id:e}){const n=ie(),[i,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:o("desc-fg"),background:o("bg-subtle"),border:`1px solid ${o("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:o("fg")},children:e}),t.jsx("span",{onClick:s,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function Te({children:e,extra:n}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("desc-fg"),letterSpacing:"1px"},children:e}),t.jsx("span",{style:{flex:1}}),n]})}function Me({label:e,children:n}){return t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[t.jsx("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:e}),t.jsx("span",{style:{color:o("fg")},children:n})]})}function cr({authors:e,type:n,onNavigate:i,renderLink:r}){const{convert:s}=V();return t.jsx("span",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.6},children:e.map((l,p)=>{const d=s(l.name),c=l.entity_id?t.jsx(Le,{id:l.entity_id,label:d,onNavigate:i,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:d});return t.jsxs("span",{children:[p>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),c,l.role&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},p)})})}function Le({id:e,label:n,onNavigate:i,renderLink:r}){const s=ve();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i(e))},style:{color:o("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`,paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{children:n||e})}function Hl({id:e,title:n,edition:i,type:r,isDraft:s,authors:l,volumeText:p,meta:d,headerExtra:c,onNavigate:a,renderLink:u}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:o("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:i}),p&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:p})]}),c&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(Pl,{type:r}),t.jsx(Ol,{isDraft:s}),t.jsx(Dl,{id:e})]}),((l==null?void 0:l.length)||d.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(cr,{authors:l,type:r,onNavigate:a,renderLink:u}),d]})]})}function dr({items:e,label:n,showMeta:i,onNavigate:r,renderLink:s}){const l=ie(),{convert:p}=V();if(!e.length)return null;const[d,c]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(Te,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((a,u)=>{const x=d===u;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:o("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>c(x?null:u),style:{padding:"8px 12px",background:o("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:p(a.source)}),!x&&i&&a.title_info&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p(a.title_info)}),a.source_bid&&t.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Le,{id:a.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),x&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${o("widget-border")}`},children:[i&&(a.title_info||a.author_info||a.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[a.title_info&&t.jsx(Me,{label:l.label.titleInfo,children:p(a.title_info)}),a.author_info&&t.jsx(Me,{label:l.label.authorInfo,children:p(a.author_info)}),a.edition&&t.jsx(Me,{label:l.label.edition,children:p(a.edition)})]}),a.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:p(a.summary)})]}),a.comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:p(a.comment)})]}),a.additional_comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:p(a.additional_comment)})]})]})]},u)})})]})}function Gl({items:e,onNavigate:n,renderLink:i}){const r=ie();return t.jsx(dr,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function pr({items:e,onNavigate:n,renderLink:i}){const r=ie();return t.jsx(dr,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function ur({label:e,items:n}){const{convert:i}=V();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(Te,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const l=typeof r=="string"?r:r.book_title;return t.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:o("fg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:i(l)},s)})})]}):null}function Ul({items:e}){const n=ie();return t.jsx(ur,{label:n.section.aliases,items:e})}function Vl({items:e}){const n=ie();return t.jsx(ur,{label:n.section.attachedTexts,items:e})}function Yl({items:e}){const n=ie(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Te,{children:n.section.appendix}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:e.map((r,s)=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:o("fg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:["《",i(r.book_title),"》",r.n_juan!=null&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function Kl({items:e}){const n=ie(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Te,{children:n.section.locationHistory}),t.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[t.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:o("widget-border")}}),e.map((r,s)=>t.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[t.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:o("primary"),border:`1.5px solid ${o("input-bg")}`}}),t.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:o("fg")},children:i(r.name)}),r.description&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),marginLeft:"8px"},children:i(r.description)})]},s))]})]}):null}function ql({items:e}){const n=ie(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Te,{children:n.section.historyOverview}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map((r,s)=>t.jsxs("div",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[t.jsx("span",{style:{position:"absolute",left:0,top:0,color:o("desc-fg")},children:"·"}),i(r)]},s))})]}):null}function Zi({title:e,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:l}=V(),[p,d]=f.useState([]);return f.useEffect(()=>{if(!n.length){d([]);return}if(!i){d(n.map(a=>({id:a})));return}let c=!1;return Promise.all(n.map(a=>i.getItem(a).then(u=>({id:a,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:a})))).then(a=>{c||d(a)}),()=>{c=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(Te,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",n.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(p.length?p:n.map(c=>({id:c}))).map(c=>{const a=c.edition?`${l(c.title)||c.id}(${l(c.edition)})`:l(c.title)||void 0;return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),transition:"border-color 0.15s"},children:t.jsx(Le,{id:c.id,label:a,onNavigate:r,renderLink:s})},c.id)})})]}):null}function un({book:e,onNavigate:n,renderLink:i}){const r=ie(),{convert:s}=V(),[l,p]=f.useState(!1),d=e.resources&&e.resources.length>0,c=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:o("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:d&&!l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(Le,{id:e.id,label:c,onNavigate:n,renderLink:i})}),d&&t.jsx("span",{onClick:()=>p(a=>!a),style:{cursor:"pointer",fontSize:"10px",color:o("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),d&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(Un,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Jl({ids:e,workData:n,transport:i,onNavigate:r,renderLink:s,footer:l}){const p=ie(),{convert:d}=V(),[c,a]=f.useState([]);if(f.useEffect(()=>{if(!e.length){a([]);return}if(!i){a(e.map(k=>({id:k})));return}let b=!1;return Promise.all(e.map(k=>i.getItem(k).then(m=>({id:k,title:m?m.title:void 0,edition:m?m.edition:void 0,resources:m?m.resources:void 0,resource_groups:m?m.resource_groups:void 0})).catch(()=>({id:k})))).then(k=>{b||a(k)}),()=>{b=!0}},[e,i]),!e.length)return null;const u=c.length?c:e.map(b=>({id:b})),x=new Map(u.map(b=>[b.id,b])),g=n==null?void 0:n.version_graph,h=Zl(e,g);return t.jsxs(t.Fragment,{children:[t.jsxs(Te,{children:[p.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,h.useGrouping?t.jsxs(t.Fragment,{children:[h.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:h.coreIds.map(b=>{const k=x.get(b);return k?t.jsx(un,{book:k,onNavigate:r,renderLink:s},b):null})}),h.groupedIds.map(b=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${o("widget-border")}`,borderRadius:6,background:o("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:o("fg"),userSelect:"none"},children:[d(b.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:o("desc-fg"),fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:o("desc-fg"),fontWeight:400},children:d(b.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(k=>{const m=x.get(k);return m?t.jsx(un,{book:m,onNavigate:r,renderLink:s},k):null})})]},b.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(b=>t.jsx(un,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Zl(e,n){var m,v;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.length>0||s.length>0,p=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&p.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const d=new Set(r),c=new Set([...s,...p]),a=y=>{if(c.has(y))return!0;const j=n.node_groups[y];return j!=null&&d.has(j)},u=[],x=new Map,g=[];for(const y of e)if(!((v=n.excluded_books)!=null&&v.includes(y)))if(a(y))u.push(y);else{const j=n.node_groups[y];j?(x.has(j)||x.set(j,[]),x.get(j).push(y)):g.push(y)}if(g.length+[...x.values()].reduce((y,j)=>y+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(y=>[y.id,y])),k=[...x.entries()].map(([y,j])=>{const $=b.get(y);return{id:y,label:($==null?void 0:$.label)??y,description:$==null?void 0:$.description,ids:j}});return g.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:u,groupedIds:k}}function Xl({workData:e,onNavigate:n,renderLink:i}){var p,d,c,a;const r=ie(),{convert:s}=V(),l=!!((p=e.description)!=null&&p.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:o("input-bg"),marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`},children:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:t.jsx(Le,{id:e.id,label:s(e.title),onNavigate:n,renderLink:i})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:s(e.measure_info)}):((d=e.juan_count)==null?void 0:d.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[lr(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(cr,{authors:e.authors,type:"work",onNavigate:n,renderLink:i})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((c=e.description)==null?void 0:c.text)&&t.jsx(Ke,{text:e.description.text,style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(a=e.description)!=null&&a.text?"8px":0,fontSize:"13px"},children:t.jsx(Me,{label:r.label.parentWork,children:t.jsx(Le,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Ql({items:e,onNavigate:n,renderLink:i}){const r=ie(),{convert:s}=V();return e.length?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(l=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid color-mix(in srgb, ${o("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${o("type-collection")} 3%, transparent)`},children:[t.jsx("span",{style:{fontSize:"11px",color:o("type-collection")},children:r.indexType.collection}),t.jsx(Le,{id:l.id,label:s(l.title)||l.id,onNavigate:n,renderLink:i}),l.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"2px"},children:Lt(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Vn=({data:e,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:p,className:d,style:c})=>{var A,W,T,L,M,P,R,ne;const a=ie(),{convert:u}=V(),[x,g]=f.useState(null),[h,b]=f.useState(!1),[k,m]=f.useState(null),[v,y]=f.useState(null),[j,$]=f.useState([]),S=e||x;if(f.useEffect(()=>{if(e||!n||!i)return;let I=!1;return b(!0),m(null),i.getItem(n).then(F=>{I||(F?g(F):m(a.misc.notFoundEntry))}).catch(F=>{I||m(F instanceof Error?F.message:a.misc.loadFailed)}).finally(()=>{I||b(!1)}),()=>{I=!0}},[e,n,i]),f.useEffect(()=>{if(!S||!i){y(null),$([]);return}let I=!1;const F=S.type==="book"||S.type==="collection"?S.work_id:void 0;if(F?i.getItem(F).then(K=>{!I&&K&&K.type==="work"&&y(K)}).catch(()=>{}):y(null),S.type==="book"){const K=S;K.contained_in&&K.contained_in.length>0?Promise.all(K.contained_in.map(G=>{const U=typeof G=="string"?G:G.id,te=typeof G=="string"?void 0:G.volume_index;return i.getItem(U).then(O=>({id:U,title:O&&O.title||U,volume_index:te})).catch(()=>({id:U,title:U,volume_index:te}))})).then(G=>{I||$(G)}):$([])}else $([]);return()=>{I=!0}},[S,i]),h)return t.jsx("div",{className:d,style:{...c,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((I,F)=>t.jsx("div",{style:{height:F===1?"32px":"16px",width:`${I}px`,background:o("widget-border"),borderRadius:"4px",opacity:.4}},F))})});if(k)return t.jsx("div",{className:d,style:{...c,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:k});if(!S)return null;if(S.type==="entity")return t.jsx("div",{className:d,style:c,children:t.jsx(rr,{data:S,transport:i,onNavigate:r,renderLink:s,headerExtra:l})});const _=S.type==="book"?S:null,w=S.type==="collection"?S:null,z=S.type==="work"?S:null;let B=!1;try{B=pe.extractStatus(S.id)==="draft"}catch{}let E="";S.measure_info?E=u(S.measure_info):(A=S.juan_count)!=null&&A.number?E=lr(S.juan_count.number)+a.unit.juan:(W=S.juan_count)!=null&&W.description&&(E=u(S.juan_count.description));const C=[];return(T=S.publication_info)!=null&&T.year&&C.push(t.jsx(Me,{label:a.label.year,children:S.publication_info.year},"year")),(L=S.current_location)!=null&&L.name&&C.push(t.jsx(Me,{label:a.label.currentLocation,children:u(S.current_location.name)},"loc")),(M=S.page_count)!=null&&M.description&&C.push(t.jsx(Me,{label:a.label.pageCount,children:S.page_count.description},"page")),_!=null&&_.edition&&C.push(t.jsx(Me,{label:a.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&C.push(t.jsx(Me,{label:a.label.parentWork,children:t.jsx(Le,{id:z.parent_work.id,label:u(z.parent_work.title),onNavigate:r,renderLink:s})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&C.push(t.jsx(Me,{label:a.label.parentWork,children:z.parent_works.map((I,F)=>t.jsxs("span",{children:[F>0&&"、",t.jsx(Le,{id:I,onNavigate:r,renderLink:s})]},I))},"pws")),t.jsxs("div",{className:d,style:c,children:[t.jsx(Hl,{id:S.id,title:u(S.title),edition:S.edition?u(S.edition):void 0,type:S.type,isDraft:B,authors:S.authors,volumeText:E,meta:C,headerExtra:l,onNavigate:r,renderLink:s}),((P=S.description)==null?void 0:P.text)&&t.jsx(Ke,{text:S.description.text,style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),S.appendix&&S.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:S.appendix.map((I,F)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:o("bg-subtle"),borderRadius:4,border:`1px solid ${o("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:o("muted")},children:u(I.title)}),t.jsx(Ke,{text:I.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:o("fg")}})]},F))}),j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Te,{children:a.section.containedIn}),t.jsx(Ql,{items:j,onNavigate:r,renderLink:s})]}),v&&t.jsxs(t.Fragment,{children:[t.jsx(Te,{children:a.section.belongsToWork}),t.jsx(Xl,{workData:v,onNavigate:r,renderLink:s})]}),S.additional_works&&S.additional_works.length>0&&t.jsx(Yl,{items:S.additional_works}),S.additional_titles&&S.additional_titles.length>0&&t.jsx(Ul,{items:S.additional_titles}),S.attached_texts&&S.attached_texts.length>0&&t.jsx(Vl,{items:S.attached_texts}),S.indexed_by&&S.indexed_by.length>0&&t.jsx(Gl,{items:S.indexed_by,onNavigate:r,renderLink:s}),S.emendated_by&&S.emendated_by.length>0&&t.jsx(pr,{items:S.emendated_by,onNavigate:r,renderLink:s}),S.resources&&S.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Te,{children:a.section.resources}),t.jsx(Un,{items:S.resources,resourceGroups:S.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&t.jsx(Kl,{items:_.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&t.jsx(ql,{items:w.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&t.jsx(Zi,{title:a.section.relatedVersions,ids:_.related_books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.books)&&w.books.length>0&&t.jsx(Zi,{title:a.section.containedBooks,ids:w.books,transport:i,onNavigate:r,renderLink:s}),(w==null?void 0:w.contained_works)&&w.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(Te,{children:[a.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",w.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.contained_works.map(I=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:t.jsx(Le,{id:I.id,label:u(I.title),onNavigate:r,renderLink:s})},I.id))})]}),(((R=z==null?void 0:z.books)==null?void 0:R.length)||0)+(((ne=z==null?void 0:z.collections)==null?void 0:ne.length)||0)>0&&t.jsx(Jl,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z,transport:i,onNavigate:r,renderLink:s,footer:p}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const I=[],F=z.related_works.filter(Y=>Y.relation==="part_of"),K=z.related_works.filter(Y=>Y.relation==="has_part"),G=z.related_works.filter(Y=>Y.relation==="has_adaptation"),U=z.related_works.filter(Y=>Y.relation==="text_carried_by"),te=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),O=z.related_works.filter(Y=>!Y.relation||!te.has(Y.relation));return F.length>0&&I.push({label:a.section.belongsToWork,items:F}),K.length>0&&I.push({label:a.section.containedWorks,items:K}),G.length>0&&I.push({label:a.section.adaptations,items:G}),U.length>0&&I.push({label:a.section.derivativeWorks,items:U}),O.length>0&&I.push({label:a.section.relatedWorks,items:O}),I.map(Y=>t.jsxs("div",{children:[t.jsxs(Te,{children:[Y.label,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",Y.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:Y.items.map(Z=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:t.jsx(Le,{id:Z.id,label:u(Z.title),onNavigate:r,renderLink:s})},Z.id))})]},Y.label))})()]})};function ea({data:e}){const n=ie(),{convert:i}=V(),{stats:r}=e,s=r.processed_volumes??r.total_found_volumes,l=s!=null&&e.total_volumes>0?Math.round(s/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:i(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"6px"},children:i(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:o("desc-fg")},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:o("fg")},children:e.total_volumes})," ",n.unit.volume]}),l!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:o("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:o("fg")},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&t.jsxs("span",{children:[n.catalog.matched," ",t.jsx("strong",{style:{color:o("fg")},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&t.jsxs("span",{children:[n.catalog.unmatched," ",t.jsx("strong",{style:{color:o("missing-fg")},children:r.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:o("desc-fg")},children:[n.catalog.source," ",e.source]})]})}function ta({sections:e,activeSection:n,onSelect:i}){const r=ie();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:Xi(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:Xi(n===s.name),children:[s.name,s.volume_range&&t.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function Xi(e){return{padding:"4px 12px",border:e?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${o("primary")} 8%, transparent)`:"transparent",color:o(e?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function na({id:e,label:n,onNavigate:i,renderLink:r}){const s=ve();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i(e))},style:{color:o("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:n||e})}function ia(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=e[0],r=e[e.length-1];return r-i+1===e.length?`${i}–${r}`:e.length<=3?e.join(", "):`${i}–${r} (${e.length}${n})`}function Qi({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const s=ie(),{convert:l}=V(),p=e.book_id||e.work_id,d=r&&e.volumes.length>0?ia(e.volumes,s.unit.volume):null,c=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${o("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:o("desc-fg"),textAlign:"right"},children:d}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:o("fg")},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(a=>l(a)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:o(c?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),p&&t.jsx(na,{id:p,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!p&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const Yn=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:l,style:p})=>{const d=ie(),[c,a]=f.useState(null),[u,x]=f.useState(!1),[g,h]=f.useState(null),[b,k]=f.useState(null),[m,v]=f.useState(""),y=e||c;f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let w=!1;return x(!0),h(null),i.getCollectionCatalog(n).then(z=>{w||(z?a(z):h(d.catalog.notFound))}).catch(z=>{w||h(z instanceof Error?z.message:d.catalog.loadFailed)}).finally(()=>{w||x(!1)}),()=>{w=!0}},[e,n,i,d]);const j=(y==null?void 0:y.sections)&&y.sections.length>0,$=f.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const w=y.books.map(B=>B.volumes[0]).filter(B=>B!=null);return new Set(w).size<w.length},[y]),S=f.useMemo(()=>{if(!y)return[];let w=y.books;if(b&&(w=w.filter(z=>z.section===b)),m.trim()){const z=m.trim().toLowerCase();w=w.filter(B=>B.title.toLowerCase().includes(z)||B.sub_items&&B.sub_items.some(E=>E.toLowerCase().includes(z))||B.edition&&B.edition.toLowerCase().includes(z))}return w},[y,b,m]),_=f.useMemo(()=>{if(!$)return null;const w=[],z=new Map;for(const E of S){if(!E.volumes||E.volumes.length===0)continue;const C=E.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(E)}const B=[...z.keys()].sort((E,C)=>E-C);for(const E of B)w.push({volume:E,books:z.get(E)});return w},[S,$]);return u?t.jsx("div",{className:l,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):g?t.jsx("div",{className:l,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:g}):y?t.jsxs("div",{className:l,style:p,children:[t.jsx(ea,{data:y}),j&&t.jsx(ta,{sections:y.sections,activeSection:b,onSelect:k}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:m,onChange:w=>v(w.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:o("desc-fg")},children:[S.length," ",d.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[_?_.map((w,z)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:o("bg"),borderBottom:`1px solid ${o("widget-border")}`,fontSize:"12px",fontWeight:600,color:o("desc-fg"),position:"sticky",top:0,zIndex:1},children:Lt(d.catalog.volume,{n:w.volume})}),w.books.map((B,E)=>t.jsx(Qi,{book:B,onNavigate:r,renderLink:s,showVolumes:B.volumes.length>1},`${w.volume}-${E}`))]},`${w.volume}-${z}`)):S.map((w,z)=>t.jsx(Qi,{book:w,onNavigate:r,renderLink:s,showVolumes:!0},z)),S.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},nt=()=>{const[e,n]=f.useState(1);return f.useEffect(()=>{const i=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(i)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:o("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(e)})},xr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],oa={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function je(e){return oa[e]??e}const xt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],ft={熹平:172,建安:196,黃初:220,正始:240,廣政:938,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,開成:836,會昌:841,咸通:860,建隆:960,太平興國:976,咸平:998,天禧:1017,慶曆:1041,皇祐:1049,嘉祐:1056,治平:1064,熙寧:1068,元豐:1078,元祐:1086,紹聖:1094,崇寧:1102,大觀:1107,政和:1111,宣和:1119,建炎:1127,紹興:1131,隆興:1163,乾道:1165,淳熙:1174,紹熙:1190,慶元:1195,嘉泰:1201,開禧:1205,嘉定:1208,寶慶:1225,紹定:1228,端平:1234,嘉熙:1237,淳祐:1241,寶祐:1253,開慶:1259,景定:1260,咸淳:1265,大定:1161,明昌:1190,至元:1264,大德:1297,皇慶:1312,延祐:1314,泰定:1324,天曆:1328,至順:1330,至正:1341,洪武:1368,永樂:1403,宣德:1426,正統:1436,景泰:1450,天順:1457,成化:1465,弘治:1488,正德:1506,嘉靖:1522,隆慶:1567,萬曆:1573,泰昌:1620,天啟:1621,崇禎:1628,弘光:1645,隆武:1645,紹武:1646,永曆:1647,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,正保:1644,慶安:1648,承應:1652,明曆:1655,萬治:1658,寬文:1661,延寶:1673,天和:1681,貞享:1684,元祿:1688,寶永:1704,享保:1716,元文:1736,寬保:1741,延享:1744,寬延:1748,寶曆:1751,明和:1764,安永:1772,天明:1781,寬政:1789,享和:1801,文化:1804,文政:1818,天保:1830,弘化:1844,嘉永:1848,安政:1854,萬延:1860,文久:1861,元治:1864,慶應:1865,明治:1868,大正:1912,昭和:1926,天正:1573,文祿:1592,永祿:1558,天文:1532},fr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function en(e){const n=e.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const i=parseInt(n[1],10);if(i<100||i>2100)return;const r=n[2]?parseInt(n[2],10):void 0;return{from:i,to:r!=null&&r>=i&&r<=2100?r:void 0}}function ra(e){return e>=1950?"":e>=1912?"民國":e>=1645?"清":e>=1368?"明":e>=1279?"元":e>=960?"宋":e>=907?"五代":e>=618?"唐":e>=581?"隋":e>=420?"南北朝":e>=265?"晉":e>=220?"三國":e>=-202?"漢":""}const sa=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,eo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Kn(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(eo))if(n.startsWith(s))return eo[s];const i=je(n);if(Je[i]!=null)return i;const r=Ue(n);if(r&&n.length<=r.length+1)return je(r)}function qe(e,n){if(n){const i=fr[`${n}|${e}`];if(i!=null)return i}return ft[e]}const la=1911;function aa(e){const n=ft[e];if(n==null)return;const i=Fe[e];let r;for(const[s,l]of Object.entries(ft))Fe[s]===i&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const ca={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function qt(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,i=0,r=!1;for(const l of e){const p=ca[l];if(p===void 0)return;r=!0,l==="十"?i=(i||1)*10:l==="廿"||l==="卅"?(n+=p,i=0):i>=10?(n+=i+p,i=0):i=i*10+p}const s=n+i;return r&&s>0?s:void 0}function Ue(e){for(const n of xr)if(e.startsWith(n))return n}const Fe={};{const e=(n,i)=>{for(const r of i)Fe[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Ze(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(ft))if(e.includes(r)&&!(i&&Fe[r]&&Fe[r]!==i&&fr[`${i}|${r}`]==null))return r}function Nt(e){var p,d,c;const n={era:"",reign:"",source:"none"},i=e.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const r=(p=e.lineage)==null?void 0:p.year_text;if(r){const a=Ue(r)??"";return{era:je(a),reign:Ze(r,a)??"",source:"lineage"}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const a=en(s);if(a)return{era:ra(a.from),reign:"",source:"publication"};const u=Ue(s)??Kn(s)??((c=xt.find(h=>h.pattern.test(s)))==null?void 0:c.era)??"",x=Ze(s,u)??"",g=u||(x?Fe[x]??"":"");if(g||x)return{era:je(g),reign:x,source:"publication"}}const l=e.edition||e.title||"";if(l){const a=Ue(l);if(a)return{era:je(a),reign:Ze(l,a)??"",source:"edition"};const u=xt.find(x=>x.pattern.test(l));if(u)return{era:je(u.era),reign:Ze(l,u.era)??u.reign??"",source:"edition"}}return n}function tn(e){var r,s,l,p,d,c,a,u,x;if(((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;if(typeof((s=e.lineage)==null?void 0:s.year)=="number")return e.lineage.year;const n=(l=e.publication_info)==null?void 0:l.year;if(n){const g=en(n);if(g)return g.from}const i=[(p=e.lineage)==null?void 0:p.year_text,(d=e.publication_info)==null?void 0:d.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const g of i){const h=((c=e.publication_info)==null?void 0:c.year)||((a=e.lineage)==null?void 0:a.year_text);if(h&&g!==h&&(Ue(h)||Kn(h)))break;const b=g.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??g.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const j=parseInt(b[1],10);if(j>=100&&j<=2100)return j}const k=g.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(k){const j=Ue(g);if(!j||je(j)==="民國"){const S=qt(k[1]);if(S!=null&&S>=1&&S<=120)return la+S}}const m=Ue(g)??((u=xt.find(j=>j.pattern.test(g)))==null?void 0:u.era),v=m?je(m):void 0,y=Ze(g,v)??(Ue(g)||(x=xt.find(j=>j.pattern.test(g)))==null?void 0:x.reign);if(y){const j=qe(y,v);if(j==null)continue;const $=g.indexOf(y),S=$>=0?g.slice($+y.length):"",_=S.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??S.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),w=_?qt(_[1]):void 0;return j+(w?w-1:0)}}}function qn(e){var p,d,c,a,u,x;const n=(p=e.dating)==null?void 0:p.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(d=e.lineage)==null?void 0:d.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const g=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const h=_n[je(g[1])],b=Je[je(g[2])];if(h!=null&&b!=null)return{from:Math.min(h,b)-20,to:Math.max(h,b)+40}}}const s=(a=e.publication_info)==null?void 0:a.year;if(s){const g=en(s);if((g==null?void 0:g.to)!=null)return{from:g.from,to:g.to};const h=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(h){const b=_n[je(h[1])],k=Je[je(h[2])];if(b!=null&&k!=null)return{from:Math.min(b,k)-20,to:Math.max(b,k)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const g of l){if(!/[間间]/.test(g))continue;const h=Ue(g)??Kn(g)??((x=xt.find(m=>m.pattern.test(g)))==null?void 0:x.era),b=h?je(h):void 0,k=[];for(const m of Object.keys(ft))g.includes(m)&&(b&&Fe[m]&&Fe[m]!==b||qe(m,b)!=null&&k.push(m));if(k.length===0){const m=g.match(/([一-鿿])([一-鿿])[間间]/);if(m&&b){for(const v of[m[1],m[2]])for(const y of Object.keys(ft))if(Fe[y]===b&&!(y[0]!==v&&y[y.length-1]!==v)&&qe(y,b)!=null){k.push(y);break}}}if(k.length>0){const m=k.map($=>qe($,b)).filter($=>$!=null),v=Math.min(...m),y=k.reduce(($,S)=>qe($,b)>=qe(S,b)?$:S),j=aa(y)??xn(b??"")??Math.max(...m);return{from:v,to:j>v?j:xn(b??Fe[y]??"")??v}}if(b&&Je[b]!=null)return{from:Je[b],to:xn(b)??Je[b]}}}const Je={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},da=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],pa=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,to=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function no(e,n){for(const i of xr){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!Ze(e.slice(r),je(i)))continue}const s=je(i);if(s===n)continue;const l=e.slice(r),p=Ze(l,s)??"";let d;if(p){const c=qe(p,s);if(c!=null){const u=l.slice(l.indexOf(p)+p.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),x=u?qt(u[1]):void 0;d=c+(x?x-1:0)}}return{era:s,reign:p,year:d}}for(const i of xt)if(i.pattern.test(e))return{era:je(i.era),reign:i.reign??""}}function ua(e){var v,y,j,$,S;const n=Nt(e),i=((v=e.publication_info)==null?void 0:v.year)??"",r=i?en(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),p=((y=e.lineage)==null?void 0:y.year_text)??"",d=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(p),c=n.source==="publication"&&sa.test(i),a=n.source==="publication"&&/[間间]/.test(i),u=p.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let x;l||d||c||a?x=void 0:u?x=parseInt(u[2],10):x=tn(e);const g=x==null?qn(e):void 0;let h;n.source==="publication"&&(c||to.test(i))?h="uncertain":n.source==="lineage"||n.source==="publication"?h="attested":to.test(s)||!n.reign&&x==null?h="uncertain":h="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((j=e.lineage)==null?void 0:j.year_text)??(($=e.lineage)==null?void 0:$.year)??""}」`:`出版著錄「${((S=e.publication_info)==null?void 0:S.year)??""}」`,k={era:n.era,reign:n.reign,year:x,yearRange:g,certainty:h,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const _=p.match(/[、,,]\s*([宋元明清])/);_&&_[1]!==k.era&&(k.laterRepair={era:_[1]})}if(!k.laterRepair&&pa.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(k.laterRepair={era:_[1]})}const m=da.find(_=>_.re.test(s));if(m){const _=s.search(m.re),w=s.slice(_),z=no(w,n.era)??no(s,n.era);z&&(k.basedOn={era:z.era,reign:z.reign,year:z.year,relation:m.relation})}return k}const _n={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function xn(e){return _n[e]}function gr(e){const n=tn(e);if(n!=null)return n;const i=qn(e);if(i)return i.from;const r=Nt(e).era;return r?Je[r]:void 0}const io=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function $n(e){const n=io.indexOf(e);return n===-1?io.length:n}function xa(e){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of e){const l=s.relation;l==="part_of"?n.belongsTo.push(s):l==="collected_in"?n.collected.push(s):l==="has_part"||l==="contains_text_of"?n.contains.push(s):l==="text_carried_by"||l==="studied_by"||l==="derived_from"||l==="followed_by"||l==="has_adaptation"?n.derivative.push(s):l==="studies"||l==="preceded_by"?n.studies.push(s):n.related.push(s)}const i=[],r=(s,l)=>{n[s].length&&i.push({key:s,labelKey:l,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),i}function nn(e,n){const i=Dn(e||[]),r=new Map,s=[];for(const a of i)a.group?(r.has(a.group)||r.set(a.group,[]),r.get(a.group).push(a)):s.push(a);for(const a of r.values())a.sort((u,x)=>{const g=h=>h.group_role==="origin"?0:h.group_role==="mirror"?1:2;return g(u)-g(x)});const l={text:[],image:[],textImage:[],physical:[]};for(const a of s){const u=Qe(a),x=u.includes("text"),g=u.includes("image");x&&g?l.textImage.push(a):x?l.text.push(a):g?l.image.push(a):l.physical.push(a)}const d=["text","image","textImage","physical"].filter(a=>l[a].length>0).map(a=>({key:a,items:l[a]})),c=[...r.entries()].map(([a,u])=>{var x,g;return{key:a,label:((x=n==null?void 0:n[a])==null?void 0:x.label)||a,description:(g=n==null?void 0:n[a])==null?void 0:g.description,items:u}});return{buckets:d,mirrors:c,total:i.length}}function Bt(e){const n=[],i=e.metadata||{};i.edition&&n.push(String(i.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const r=Xt(e);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),i.version&&n.push(String(i.version)),n.join(" · ")}function hr(e,n){if(Bt(e)||n.filter(r=>r.name===e.name).length<2)return"";try{const r=new URL(e.url),s=r.searchParams.get("res")||r.searchParams.get("id");if(s)return s;const l=r.pathname.split("/").filter(Boolean).pop();if(l)return decodeURIComponent(l)}catch{}return""}function mr(e,n){var l,p;const i=e.resources||[],r=[],s=[];for(const d of i){const c=Qe(d);c.includes("image")&&r.push(d),c.includes("physical")&&s.push(d)}return{id:e.id,name:e.edition||e.title||e.id,era:Nt(e),year:tn(e),sortYear:gr(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:fa(e.id,n),group:(p=n==null?void 0:n.node_groups)==null?void 0:p[e.id],hasImage:r.length>0}}function fa(e,n){var d,c;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(d=n.collections)==null?void 0:d[i];if(((r==null?void 0:r.book_ids)??(i==="core"?n.core_books??[]:[])).includes(e))return!0;const l=(r==null?void 0:r.groups)??[],p=(c=n.node_groups)==null?void 0:c[e];return!!p&&l.includes(p)}function br(e,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!r.has(c.id)).map(c=>mr(c,n));let l=s;i.era&&(l=l.filter(c=>c.era.era===i.era)),i.scanOnly&&(l=l.filter(c=>c.hasImage)),i.sort==="year"?l=l.map((c,a)=>({r:c,i:a})).sort((c,a)=>{const u=c.r.sortYear,x=a.r.sortYear;return u!=null&&x!=null?u-x||c.i-a.i:u!=null?-1:x!=null?1:c.i-a.i}).map(c=>c.r):l=l.map((c,a)=>({r:c,i:a})).sort((c,a)=>{const u=x=>(x.important?0:1)*2+(x.hasImage?0:1);return u(c.r)-u(a.r)||c.i-a.i}).map(c=>c.r);const d=[...new Set(s.map(c=>c.era.era).filter(Boolean))].sort((c,a)=>$n(c)-$n(a));return{rows:l,allRows:s,eras:d,hasInferredEra:s.some(c=>c.era.source==="edition")}}function ga(e,n){var m,v;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.length>0||s.length>0,p=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&p.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const d=new Set(r),c=new Set([...s,...p]),a=y=>{if(c.has(y))return!0;const j=n.node_groups[y];return j!=null&&d.has(j)},u=[],x=new Map,g=[];for(const y of e)if(!((v=n.excluded_books)!=null&&v.includes(y)))if(a(y))u.push(y);else{const j=n.node_groups[y];j?(x.has(j)||x.set(j,[]),x.get(j).push(y)):g.push(y)}if(g.length+[...x.values()].reduce((y,j)=>y+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(y=>[y.id,y])),k=[...x.entries()].map(([y,j])=>{const $=b.get(y);return{id:y,label:($==null?void 0:$.label)??y,description:$==null?void 0:$.description,ids:j}});return g.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:u,groupedIds:k}}const yr=["撰","編","注","校","譯","繪","其他"],ha=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function Jn(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of ha)if(r.test(n))return i;return"其他"}function Zn(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function jr(e){const n=new Map;for(const r of e){const s=Jn(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:e.length}];for(const r of yr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function vr(e,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(p=>({id:p.work_id||p.book_id||void 0,title:p.title,section:p.section,volumes:p.volumes||[],subItems:p.sub_items,edition:p.edition,found:p.found_volumes,expected:p.expected_volumes})),l=[...new Set(s.map(p=>p.section).filter(Boolean))];return{rows:s,source:"catalog",sections:l,totalVolumes:n.total_volumes}}return e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(l=>({id:l.id,title:l.title,volumes:Rt(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,p;return{id:s,title:((l=i==null?void 0:i.get(s))==null?void 0:l.title)||s,edition:(p=i==null?void 0:i.get(s))==null?void 0:p.edition,volumes:[]}}),source:"books",sections:[]}}function Rt(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(n=>typeof n=="number");if(typeof e=="string"){const n=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[i,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-i+1)},(s,l)=>i+l)}return e.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function on(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((l,p)=>l-p),r=i[0],s=i[i.length-1];return s-r+1===i.length?`${r}–${s}`:i.length<=3?i.join(", "):`${r}–${s} (${i.length}${n})`}const ma=["〇","一","二","三","四","五","六","七","八","九"],oo=["","十","百","千"];function kr(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const p=parseInt(n[l]),d=i-1-l;p===0?s=!0:(s&&r&&(r+="〇"),s=!1,p===1&&d===1&&l===0?r+=oo[d]:r+=ma[p]+oo[d])}return r}function ba(e){return e==null?"":typeof e=="string"?e:e.title??""}function et(e,n="卷"){var r,s;const i=e;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?kr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Sr(e){var r;if((r=e.lineage)!=null&&r.category)return e.lineage.category;const n=e.edition||e.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,l]of i)if(s.test(n))return l;return""}const ya="guji_markdown";function zn(e){const n=e==null?void 0:e.guji_markdown;if(typeof n!="string")return!1;const i=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!i)return!1;const r=parseInt(i[1],10),s=parseInt(i[2],10);return r>0||s>=2}const ja=/^□\{guess=([^\s{}]+)\}/;function va(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function wr(e,n){let i=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
|
|
2
|
+
`)return-1;if(s==="\\"){r++;continue}if(s==="[")i++;else if(s==="]"&&(i--,i===0))return r}return-1}function ka(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function Sa(e,n){const i=e[n];if(i==="["&&e[n+1]==="["){const r=e.indexOf("]]",n+2);return r>=0&&e.slice(n+2,r).indexOf(`
|
|
3
|
+
`)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const r=wr(e,n+3);return r>n+4?{node:{type:"zi",label:ka(e.slice(n+4,r))},end:r+1}:null}if(i==="□"&&e[n+1]==="{"){const r=ja.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function _r(e,n,i,r){const s=[];let l="";const p=()=>{if(!l)return;const d=r?l.replace(/\\?\|/g,""):l;d&&s.push({type:"text",text:d}),l=""};for(;n<e.length;){const d=e[n];if(i!==null){if(d===i)return p(),{nodes:s,end:n};if(d===`
|
|
4
|
+
`)return null}const c=Sa(e,n);if(c){p(),s.push(c.node),n=c.end;continue}let a=null;if(d==="⟨"?a="⟩":d==="<"&&va(e,n)&&(a=">"),a){const u=_r(e,n+1,a,!0);if(u){p(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=d,n++}return i!==null?null:(p(),{nodes:s,end:n})}function $r(e){return _r(e,0,null,!1).nodes}function wa(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function zr(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${zr(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const _a=216,ro="clamp(280px, 23vw, 360px)",$a=1440,Cr="(max-width: 719px)",za=`${Cr}, (pointer: coarse)`,Ca=`
|
|
5
|
+
.bim-d-main.bim-d-main-grid { max-width: ${$a}px; padding: 16px 32px 0; }
|
|
6
6
|
.bim-d-grid {
|
|
7
7
|
display: grid;
|
|
8
|
-
grid-template-columns: ${
|
|
8
|
+
grid-template-columns: ${_a}px minmax(0, 1fr) ${ro};
|
|
9
9
|
grid-template-rows: auto 1fr;
|
|
10
10
|
grid-template-areas: "rail main card" "rail main side";
|
|
11
11
|
column-gap: 32px; row-gap: 28px; align-items: start;
|
|
@@ -16,72 +16,74 @@
|
|
|
16
16
|
.bim-d-g-side { grid-area: side; min-width: 0; display: flex; flex-direction: column; gap: 28px; }
|
|
17
17
|
.bim-d-g-side:empty { display: none; }
|
|
18
18
|
|
|
19
|
-
.bim-d-meta { color: ${
|
|
20
|
-
.bim-d-dot::before { content: "·"; margin: 0 .45em; color: ${
|
|
19
|
+
.bim-d-meta { color: ${o("aux-fg")}; font-size: 13px; }
|
|
20
|
+
.bim-d-dot::before { content: "·"; margin: 0 .45em; color: ${o("aux-fg")}; }
|
|
21
21
|
|
|
22
22
|
/* 左栏 */
|
|
23
|
-
.bim-d-rail-cap { font-size: 12px; letter-spacing: .2em; color: ${
|
|
23
|
+
.bim-d-rail-cap { font-size: 12px; letter-spacing: .2em; color: ${o("aux-fg")}; margin: 0 12px 6px; }
|
|
24
24
|
.bim-d-rail-nav { list-style: none; margin: 0; padding: 0; }
|
|
25
25
|
.bim-d-rail-nav a {
|
|
26
26
|
display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
|
|
27
27
|
padding: 7px 12px; border-radius: 6px; font-size: 15px;
|
|
28
|
-
color: ${
|
|
28
|
+
color: ${o("quiet-fg")} !important; text-decoration: none !important;
|
|
29
29
|
}
|
|
30
|
-
.bim-d-rail-nav a:hover { background: ${
|
|
30
|
+
.bim-d-rail-nav a:hover { background: ${o("zebra-bg")}; color: ${o("ink")} !important; }
|
|
31
31
|
.bim-d-rail-nav .bim-d-meta { font-size: 12px; }
|
|
32
32
|
.bim-d-rail-links { margin-top: 20px; }
|
|
33
33
|
.bim-d-rail-back { display: inline-flex; align-items: center; min-height: 32px; padding: 0 12px;
|
|
34
|
-
font-size: 13px; color: ${
|
|
34
|
+
font-size: 13px; color: ${o("aux-fg")} !important; }
|
|
35
35
|
|
|
36
36
|
/* 区块 */
|
|
37
37
|
.bim-d-sec + .bim-d-sec { margin-top: 48px; }
|
|
38
38
|
.bim-d-sec { scroll-margin-top: 16px; }
|
|
39
39
|
.bim-d-sec-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; margin-bottom: 14px; }
|
|
40
|
-
.bim-d-sec-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .04em; color: ${
|
|
40
|
+
.bim-d-sec-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .04em; color: ${o("ink")}; }
|
|
41
41
|
.bim-d-sec-head .bim-d-sec-act { margin-left: auto; font-size: 13px; }
|
|
42
42
|
|
|
43
|
-
/*
|
|
44
|
-
.bim-d-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; margin-bottom: 10px; font-size: 13px; }
|
|
43
|
+
/* 文字页签式筛选。min-height = 页签行高:朝代页签随次级数据晚到,行高先占好(INT Q3) */
|
|
44
|
+
.bim-d-filters { min-height: 26px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; margin-bottom: 10px; font-size: 13px; }
|
|
45
45
|
.bim-d-tab {
|
|
46
46
|
background: none; border: 0; padding: 4px 0; cursor: pointer; font: inherit;
|
|
47
|
-
color: ${
|
|
47
|
+
color: ${o("quiet-fg")};
|
|
48
48
|
}
|
|
49
|
-
.bim-d-tab:hover { color: ${
|
|
50
|
-
.bim-d-tab[aria-pressed="true"] { color: ${
|
|
49
|
+
.bim-d-tab:hover { color: ${o("ink")}; }
|
|
50
|
+
.bim-d-tab[aria-pressed="true"] { color: ${o("accent")}; font-weight: 700; box-shadow: inset 0 -2px 0 ${o("accent")}; }
|
|
51
51
|
.bim-d-filters .bim-d-spacer { flex: 1; }
|
|
52
|
-
.bim-d-check { display: inline-flex; align-items: center; gap: 6px; color: ${
|
|
53
|
-
.bim-d-check input { accent-color: ${
|
|
52
|
+
.bim-d-check { display: inline-flex; align-items: center; gap: 6px; color: ${o("quiet-fg")}; cursor: pointer; }
|
|
53
|
+
.bim-d-check input { accent-color: ${o("accent")}; margin: 0; width: 15px; height: 15px; }
|
|
54
54
|
|
|
55
55
|
/* 斑马表:不画格线 */
|
|
56
56
|
.bim-d-zt { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 15px; }
|
|
57
|
-
.bim-d-zt th { text-align: left; font-weight: 400; color: ${
|
|
57
|
+
.bim-d-zt th { text-align: left; font-weight: 400; color: ${o("aux-fg")}; font-size: 12px;
|
|
58
58
|
letter-spacing: .1em; padding: 6px 12px; white-space: nowrap; }
|
|
59
59
|
.bim-d-zt td { padding: 10px 12px; vertical-align: baseline; }
|
|
60
|
-
.bim-d-zt tbody tr:nth-child(odd) td { background: ${
|
|
60
|
+
.bim-d-zt tbody tr:nth-child(odd) td { background: ${o("zebra-bg")}; }
|
|
61
61
|
.bim-d-zt tbody tr td:first-child { border-radius: 6px 0 0 6px; }
|
|
62
62
|
.bim-d-zt tbody tr td:last-child { border-radius: 0 6px 6px 0; }
|
|
63
|
-
.bim-d-zt tbody tr:hover td { background: ${
|
|
63
|
+
.bim-d-zt tbody tr:hover td { background: ${o("tint-bg")}; }
|
|
64
64
|
.bim-d-zt td.bim-d-zt-main { padding: 0; }
|
|
65
65
|
.bim-d-zt td.bim-d-zt-main > a, .bim-d-zt td.bim-d-zt-main > span.bim-d-zt-name {
|
|
66
|
-
display: block; padding: 10px 12px; color: ${
|
|
66
|
+
display: block; padding: 10px 12px; color: ${o("ink")}; font-weight: 500;
|
|
67
67
|
}
|
|
68
|
-
.bim-d-zt td.bim-d-zt-main > a:hover { color: ${
|
|
68
|
+
.bim-d-zt td.bim-d-zt-main > a:hover { color: ${o("accent")}; }
|
|
69
69
|
.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; }
|
|
70
|
-
.bim-d-zt .bim-d-zt-sub { color: ${
|
|
70
|
+
.bim-d-zt .bim-d-zt-sub { color: ${o("quiet-fg")}; font-size: 13px; }
|
|
71
71
|
.bim-d-zt .bim-d-zt-nowrap { white-space: nowrap; }
|
|
72
|
-
.bim-d-zt .bim-d-zt-empty { color: ${
|
|
72
|
+
.bim-d-zt .bim-d-zt-empty { color: ${o("aux-fg")}; }
|
|
73
|
+
/* 版本表:行高先按「有影印」色块那一行的高度占好,解析到的年代、馆藏、色块进来时行不再长高(INT Q3) */
|
|
74
|
+
.bim-d-zt-ver tbody tr { height: 42px; }
|
|
73
75
|
|
|
74
76
|
.bim-d-flag {
|
|
75
77
|
display: inline-block; padding: 1px 8px; border-radius: 4px;
|
|
76
|
-
background: ${
|
|
78
|
+
background: ${o("flag-bg")}; color: ${o("accent")} !important;
|
|
77
79
|
font-size: 12px; line-height: 20px; white-space: nowrap;
|
|
78
80
|
}
|
|
79
|
-
a.bim-d-flag:hover { text-decoration: none !important; background: ${
|
|
81
|
+
a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg")}; }
|
|
80
82
|
|
|
81
83
|
.bim-d-more {
|
|
82
84
|
display: inline-flex; align-items: center; min-height: 32px; margin-top: 6px;
|
|
83
85
|
background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-size: 13px;
|
|
84
|
-
color: ${
|
|
86
|
+
color: ${o("accent")};
|
|
85
87
|
}
|
|
86
88
|
.bim-d-more:hover { text-decoration: underline; text-underline-offset: 3px; }
|
|
87
89
|
|
|
@@ -90,32 +92,32 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
90
92
|
.bim-d-lu-list { list-style: none; margin: 0; padding: 0; }
|
|
91
93
|
.bim-d-lu-list button {
|
|
92
94
|
display: block; width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
|
|
93
|
-
padding: 7px 12px; border-radius: 6px; font: inherit; font-size: 15px; color: ${
|
|
95
|
+
padding: 7px 12px; border-radius: 6px; font: inherit; font-size: 15px; color: ${o("quiet-fg")};
|
|
94
96
|
}
|
|
95
|
-
.bim-d-lu-list button:hover { background: ${
|
|
96
|
-
.bim-d-lu-list button[aria-selected="true"] { background: ${
|
|
97
|
+
.bim-d-lu-list button:hover { background: ${o("zebra-bg")}; }
|
|
98
|
+
.bim-d-lu-list button[aria-selected="true"] { background: ${o("flag-bg")}; color: ${o("accent")}; font-weight: 500; }
|
|
97
99
|
.bim-d-lu-body { padding: 4px 0; min-width: 0; }
|
|
98
|
-
.bim-d-lu-title { font-size: 17px; font-weight: 700; color: ${
|
|
99
|
-
.bim-d-quote { margin: 14px 0 0; font-family: ${
|
|
100
|
-
color: ${
|
|
101
|
-
.bim-d-quote-label { margin-top: 16px; font-size: 12px; letter-spacing: .1em; color: ${
|
|
100
|
+
.bim-d-lu-title { font-size: 17px; font-weight: 700; color: ${o("ink")}; }
|
|
101
|
+
.bim-d-quote { margin: 14px 0 0; font-family: ${o("font-serif")}; font-size: 17px; line-height: 2;
|
|
102
|
+
color: ${o("ink")}; text-align: justify; }
|
|
103
|
+
.bim-d-quote-label { margin-top: 16px; font-size: 12px; letter-spacing: .1em; color: ${o("aux-fg")}; }
|
|
102
104
|
.bim-d-quote-label + .bim-d-quote { margin-top: 4px; }
|
|
103
105
|
|
|
104
106
|
/* 提要卡 */
|
|
105
|
-
.bim-d-card { background: ${
|
|
106
|
-
box-shadow: ${
|
|
107
|
+
.bim-d-card { background: ${o("card-bg")}; border-radius: 10px; padding: 24px;
|
|
108
|
+
box-shadow: ${o("shadow-summary")}; }
|
|
107
109
|
.bim-d-card h1 { margin: 0; font-size: 36px; font-weight: 700; letter-spacing: .08em; line-height: 1.25;
|
|
108
|
-
color: ${
|
|
110
|
+
color: ${o("ink")}; word-break: break-word; }
|
|
109
111
|
.bim-d-card h1.bim-d-card-long { font-size: 26px; letter-spacing: .04em; line-height: 1.35; }
|
|
110
|
-
.bim-d-card-sub { margin-top: 6px; font-size: 17px; font-weight: 500; color: ${
|
|
111
|
-
.bim-d-card-byline { margin-top: 8px; font-size: 15px; color: ${
|
|
112
|
+
.bim-d-card-sub { margin-top: 6px; font-size: 17px; font-weight: 500; color: ${o("quiet-fg")}; }
|
|
113
|
+
.bim-d-card-byline { margin-top: 8px; font-size: 15px; color: ${o("ink")}; }
|
|
112
114
|
.bim-d-card-cls { margin-top: 4px; }
|
|
113
|
-
.bim-d-card-desc { margin-top: 16px; color: ${
|
|
115
|
+
.bim-d-card-desc { margin-top: 16px; color: ${o("quiet-fg")}; line-height: 1.85; font-size: 15px; }
|
|
114
116
|
.bim-d-card dl { margin: 18px 0 0; display: grid; grid-template-columns: auto minmax(0, 1fr);
|
|
115
117
|
gap: 6px 16px; font-size: 13px; }
|
|
116
|
-
.bim-d-card dt { color: ${
|
|
117
|
-
.bim-d-card dd { margin: 0; color: ${
|
|
118
|
-
.bim-d-card-foot { margin-top: 14px; font-size: 12px; text-align: center; color: ${
|
|
118
|
+
.bim-d-card dt { color: ${o("aux-fg")}; white-space: nowrap; }
|
|
119
|
+
.bim-d-card dd { margin: 0; color: ${o("ink")}; min-width: 0; overflow-wrap: anywhere; }
|
|
120
|
+
.bim-d-card-foot { margin-top: 14px; font-size: 12px; text-align: center; color: ${o("aux-fg")}; }
|
|
119
121
|
.bim-d-card-foot:empty { display: none; }
|
|
120
122
|
.bim-d-card-foot details { text-align: left; margin-top: 6px; }
|
|
121
123
|
.bim-d-card-foot summary { cursor: pointer; display: inline-flex; align-items: center; min-height: 32px; }
|
|
@@ -124,24 +126,24 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
124
126
|
.bim-d-btn {
|
|
125
127
|
display: flex; align-items: center; justify-content: center; margin-top: 22px; width: 100%;
|
|
126
128
|
height: 44px; padding: 0 24px; border: 0; border-radius: 8px; box-sizing: border-box;
|
|
127
|
-
background: ${
|
|
128
|
-
font: 500 15px/1 ${
|
|
129
|
+
background: ${o("accent")}; color: ${o("on-color-fg")} !important;
|
|
130
|
+
font: 500 15px/1 ${o("font-ui")}; letter-spacing: .08em; cursor: pointer; white-space: nowrap;
|
|
129
131
|
text-decoration: none !important;
|
|
130
132
|
}
|
|
131
|
-
.bim-d-btn:hover { background: ${
|
|
133
|
+
.bim-d-btn:hover { background: ${o("accent-deep")}; }
|
|
132
134
|
|
|
133
|
-
/*
|
|
134
|
-
.bim-d-side h3 { margin: 0 0 6px; font-size: 15px; font-weight: 700; color: ${
|
|
135
|
+
/* 旁栏清单:小标题是 h2(提要卡 h1 之下不跳级,INT Q5),外观仍是 15px 小标题 */
|
|
136
|
+
.bim-d-side h3, .bim-d-side .bim-d-side-h { margin: 0 0 6px; font-size: 15px; font-weight: 700; color: ${o("ink")};
|
|
135
137
|
display: flex; align-items: baseline; gap: 8px; }
|
|
136
|
-
.bim-d-side h3 .bim-d-meta { font-weight: 400; font-size: 12px; }
|
|
138
|
+
.bim-d-side h3 .bim-d-meta, .bim-d-side .bim-d-side-h .bim-d-meta { font-weight: 400; font-size: 12px; }
|
|
137
139
|
.bim-d-side ul { list-style: none; margin: 0; padding: 0; }
|
|
138
140
|
.bim-d-side li { display: flex; align-items: baseline; gap: 10px; padding: 5px 0; font-size: 15px; min-width: 0; }
|
|
139
|
-
.bim-d-side li > a, .bim-d-side li > span:first-child { color: ${
|
|
140
|
-
.bim-d-side li > a:hover { color: ${
|
|
141
|
+
.bim-d-side li > a, .bim-d-side li > span:first-child { color: ${o("ink")}; min-width: 0; overflow-wrap: anywhere; }
|
|
142
|
+
.bim-d-side li > a:hover { color: ${o("accent")}; }
|
|
141
143
|
.bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
|
|
142
144
|
|
|
143
145
|
/* 点击目标 ≥44px(Q5):触屏与窄屏 */
|
|
144
|
-
@media ${
|
|
146
|
+
@media ${za} {
|
|
145
147
|
.bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
|
|
146
148
|
.bim-d-card-foot summary { min-height: 44px; }
|
|
147
149
|
.bim-d-side li { padding: 0; }
|
|
@@ -151,18 +153,27 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
151
153
|
align-items: center; justify-content: center; }
|
|
152
154
|
.bim-d-zt td.bim-d-zt-main > a, .bim-d-zt td.bim-d-zt-main > span.bim-d-zt-name {
|
|
153
155
|
min-height: 44px; box-sizing: border-box; display: flex; align-items: center; }
|
|
154
|
-
/*
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
/*
|
|
157
|
+
* 视觉不变、热区外扩到 44×44(INT Q4):「有影印」色块、顶条的面包屑(返回索引)/ 繁简 / GitHub 图标、
|
|
158
|
+
* 朝代页签(单字「宋」「元」只有 13px 宽)。伪元素居中外扩,宽高都至少 44px。
|
|
159
|
+
*/
|
|
160
|
+
.bim-d-flag, .bim-d-top a, .bim-d-top button, .bim-d-tab { position: relative; }
|
|
161
|
+
.bim-d-flag::after, .bim-d-top a::after, .bim-d-top button::after, .bim-d-tab::after {
|
|
162
|
+
content: ""; position: absolute; left: 50%; top: 50%;
|
|
163
|
+
width: max(calc(100% + 8px), 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
|
|
159
164
|
}
|
|
165
|
+
/*
|
|
166
|
+
* 相邻热区不能叠:两字页签(26px)两边各扩 9px,间距 18px 正好贴边,放宽到 20px;
|
|
167
|
+
* 单字页签(13px)两边各扩 15.5px,再左右各多留 7px
|
|
168
|
+
*/
|
|
169
|
+
.bim-d-filters { column-gap: 20px; }
|
|
170
|
+
.bim-d-tab.bim-d-tab-1 { margin: 0 7px; }
|
|
160
171
|
}
|
|
161
172
|
|
|
162
173
|
/* 中等宽度:左栏折到顶部一行 */
|
|
163
174
|
@media (max-width: 1100px) {
|
|
164
175
|
.bim-d-grid {
|
|
165
|
-
grid-template-columns: minmax(0, 1fr) ${
|
|
176
|
+
grid-template-columns: minmax(0, 1fr) ${ro};
|
|
166
177
|
grid-template-rows: auto auto 1fr;
|
|
167
178
|
grid-template-areas: "rail rail" "main card" "main side";
|
|
168
179
|
}
|
|
@@ -171,11 +182,11 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
171
182
|
.bim-d-rail-links { margin-top: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 0 16px; }
|
|
172
183
|
.bim-d-rail-links .bim-d-rail-cap { display: none; }
|
|
173
184
|
.bim-d-rail-links .bim-d-rail-nav { display: flex; flex-wrap: wrap; gap: 0 16px; }
|
|
174
|
-
.bim-d-rail-links .bim-d-rail-nav a { padding: 7px 0; color: ${
|
|
185
|
+
.bim-d-rail-links .bim-d-rail-nav a { padding: 7px 0; color: ${o("accent")} !important; font-size: 14px; }
|
|
175
186
|
}
|
|
176
187
|
|
|
177
188
|
/* 手机:左栏收起,提要卡 → 正文 → 旁栏 */
|
|
178
|
-
@media ${
|
|
189
|
+
@media ${Cr} {
|
|
179
190
|
.bim-d-main.bim-d-main-grid { padding: 8px 16px 0; }
|
|
180
191
|
.bim-d-grid {
|
|
181
192
|
grid-template-columns: minmax(0, 1fr);
|
|
@@ -189,27 +200,32 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
189
200
|
.bim-d-zt thead { display: none; }
|
|
190
201
|
.bim-d-zt, .bim-d-zt tbody, .bim-d-zt tr, .bim-d-zt td { display: block; width: 100%; box-sizing: border-box; }
|
|
191
202
|
.bim-d-zt tr { padding: 0 0 10px; border-radius: 6px; }
|
|
192
|
-
.bim-d-zt tbody tr:nth-child(odd) { background: ${
|
|
203
|
+
.bim-d-zt tbody tr:nth-child(odd) { background: ${o("zebra-bg")}; }
|
|
193
204
|
.bim-d-zt tbody tr:nth-child(odd) td, .bim-d-zt tbody tr:hover td { background: transparent; }
|
|
194
205
|
.bim-d-zt td { padding: 0 12px; }
|
|
195
206
|
.bim-d-zt td:not(.bim-d-zt-main) { display: inline; width: auto; padding: 0 0 0 12px; font-size: 12px;
|
|
196
|
-
color: ${
|
|
207
|
+
color: ${o("aux-fg")}; }
|
|
197
208
|
.bim-d-zt td.bim-d-zt-blank { display: none; }
|
|
198
209
|
.bim-d-zt td.bim-d-zt-main .bim-d-meta { padding-bottom: 2px; }
|
|
210
|
+
/* 手机上版本行是块:解析前只有版本名一行,先按「名 + 一行年代馆藏」占高 */
|
|
211
|
+
.bim-d-zt-ver tbody tr { height: auto; }
|
|
212
|
+
/* 朝代页签晚到、在手机上自成一行:解析中先占两行(页签一行 + 复选框一行) */
|
|
213
|
+
.bim-d-filters[data-pending] { min-height: 92px; align-content: flex-end; }
|
|
214
|
+
.bim-d-zt-ver tbody tr[data-loading] { min-height: 64px; }
|
|
199
215
|
.bim-d-lu { grid-template-columns: 1fr; gap: 12px; }
|
|
200
216
|
.bim-d-lu-list { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
|
|
201
217
|
.bim-d-lu-list button { white-space: nowrap; padding: 6px 12px; }
|
|
202
218
|
}
|
|
203
|
-
`;function
|
|
219
|
+
`;function Wt({railTop:e,back:n,nav:i,railLinks:r,main:s,card:l,side:p}){const{convert:d}=V(),c=(i||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,n&&t.jsx("div",{style:{marginTop:e?12:0},children:n}),c.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":d("本頁導航"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:d("本頁")}),t.jsx("ul",{className:"bim-d-rail-nav",children:c.map(a=>t.jsx("li",{children:t.jsxs("a",{href:`#${a.id}`,children:[t.jsx("span",{children:d(a.label)}),a.count!=null&&t.jsx("span",{className:"bim-d-meta",children:a.count})]})},a.id))})]}),r&&r.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":d("更多"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:d("更多")}),t.jsx("ul",{className:"bim-d-rail-nav",children:r.map(a=>t.jsx("li",{children:t.jsxs("a",{href:a.href??"#",onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),a.onClick())},children:[t.jsx("span",{children:d(a.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},a.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:s}),t.jsx("div",{className:"bim-d-g-card",children:l}),t.jsx("div",{className:"bim-d-g-side",children:p})]})}function Ce({id:e,title:n,meta:i,action:r,children:s}){const{convert:l}=V();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:l(n)}),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i}),r&&t.jsx("span",{className:"bim-d-sec-act",children:r})]}),s]})}function Re({items:e,className:n,style:i}){const r=e.filter(s=>s!=null&&s!==""&&s!==!1);return r.length?t.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:i,children:r.map((s,l)=>t.jsxs(f.Fragment,{children:[l>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},l))}):null}function rn({items:e,value:n,onChange:i}){const{convert:r}=V();return t.jsx(t.Fragment,{children:e.map(s=>t.jsx("button",{type:"button",className:[...r(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>i(s.key),children:r(s.label)},s.key))})}function Ir({label:e,checked:n,onChange:i}){const{convert:r}=V();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:s=>i(s.target.checked)}),r(e)]})}function yt({label:e,onClick:n}){const{convert:i}=V();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:i(e)})}function At({title:e,subtitle:n,byline:i,meta:r,description:s,facts:l,readAction:p,children:d,foot:c}){const{convert:a}=V(),u=(l||[]).filter(x=>x.value!=null&&x.value!=="");return t.jsxs("div",{className:"bim-d-card",children:[t.jsx("h1",{className:typeof e=="string"&&[...e].length>7?"bim-d-card-long":void 0,children:e}),n&&t.jsx("div",{className:"bim-d-card-sub",children:n}),i&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:i}),r&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:r}),s&&t.jsx("div",{className:"bim-d-card-desc",children:s}),u.length>0&&t.jsx("dl",{className:"bim-d-ui",children:u.map((x,g)=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:a(x.label)}),t.jsx("dd",{title:x.title,children:x.value})]},g))}),d,p,c&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:c})]})}function Cn({href:e,onClick:n,label:i="閱讀全文"}){const{convert:r}=V();return e?t.jsx("a",{className:"bim-d-btn",href:e,onClick:n?s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),n())}:void 0,children:r(i)}):t.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:r(i)})}function ct({id:e,title:n,meta:i,items:r,cap:s=8,moreLabel:l}){const{convert:p}=V(),[d,c]=f.useState(!1);if(!r.length)return null;const a=d?r:r.slice(0,s),u=r.length-a.length;return t.jsxs("div",{id:e,className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[p(n),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i})]}),t.jsx("ul",{children:a.map((x,g)=>t.jsx("li",{children:x},g))}),u>0&&t.jsx(yt,{label:l?l(u):`顯示更多(${u})`,onClick:()=>c(!0)})]})}const Ia={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核"};function Mt({revision:e,revisedAt:n,review:i,todo:r}){const{convert:s}=V(),l=i&&i.status!=="unreviewed"?[Ia[i.status]??i.status,i.by,i.date].filter(Boolean).join(" "):"",p=[e!=null&&e!==""?`${s("數據版本")} ${e}`:"",n??"",s(l)].filter(Boolean),d=(r||[]).filter(c=>c&&c.what);return!p.length&&!d.length?null:t.jsxs(t.Fragment,{children:[p.length>0&&t.jsx(Re,{items:p,style:{fontSize:12}}),d.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s(`待核 ${d.length} 項`)}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:d.map((c,a)=>t.jsxs("li",{children:[s(c.what),(c.by||c.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[c.by&&s(c.by),c.date].filter(Boolean).join(" · "),")"]})]},a))})]})]})}const Ct=1e3,fn=208,Ta="(max-width: 719px)",Tr=`
|
|
204
220
|
.bim-d-page {
|
|
205
|
-
background: ${
|
|
206
|
-
color: ${
|
|
221
|
+
background: ${o("page-bg")};
|
|
222
|
+
color: ${o("ink")};
|
|
207
223
|
font-family: var(--bim-font-body, system-ui, sans-serif);
|
|
208
224
|
min-height: 100%;
|
|
209
225
|
padding-bottom: 64px;
|
|
210
226
|
}
|
|
211
227
|
.bim-d-main {
|
|
212
|
-
max-width: ${
|
|
228
|
+
max-width: ${Ct}px;
|
|
213
229
|
margin: 0 auto;
|
|
214
230
|
padding: 24px clamp(16px, 4vw, 28px) 0;
|
|
215
231
|
}
|
|
@@ -220,23 +236,23 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
220
236
|
* PAGE_MAX_WIDTH,读者的行宽体验不变。
|
|
221
237
|
*/
|
|
222
238
|
.bim-d-main.bim-d-main-wide {
|
|
223
|
-
max-width: ${
|
|
239
|
+
max-width: ${fn+Ct+32}px;
|
|
224
240
|
}
|
|
225
241
|
.bim-d-ui { font-family: var(--bim-font-ui, system-ui, sans-serif); }
|
|
226
242
|
|
|
227
|
-
.bim-d-page a { color: ${
|
|
243
|
+
.bim-d-page a { color: ${o("accent")}; text-decoration: none; }
|
|
228
244
|
.bim-d-page a:hover {
|
|
229
|
-
color: ${
|
|
245
|
+
color: ${o("accent-deep")};
|
|
230
246
|
text-decoration: underline;
|
|
231
247
|
text-decoration-thickness: 1px;
|
|
232
248
|
text-underline-offset: 3px;
|
|
233
249
|
}
|
|
234
|
-
.bim-d-page ::selection { background: ${
|
|
250
|
+
.bim-d-page ::selection { background: ${o("selection-bg")}; }
|
|
235
251
|
|
|
236
252
|
/* 表格行 */
|
|
237
253
|
.bim-d-row { display: grid; align-items: center; padding: 9px 4px;
|
|
238
|
-
border-bottom: 1px solid ${
|
|
239
|
-
.bim-d-row:hover { background: ${
|
|
254
|
+
border-bottom: 1px solid ${o("rule")}; font-size: 14px; }
|
|
255
|
+
.bim-d-row:hover { background: ${o("row-hover-bg")}; }
|
|
240
256
|
|
|
241
257
|
/*
|
|
242
258
|
* 全文阅读布局(整理本 / Book 全文)。
|
|
@@ -252,9 +268,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
252
268
|
*/
|
|
253
269
|
.bim-d-reader {
|
|
254
270
|
display: grid;
|
|
255
|
-
grid-template-columns: ${
|
|
271
|
+
grid-template-columns: ${fn}px minmax(0, ${Ct}px);
|
|
256
272
|
gap: 32px;
|
|
257
|
-
max-width: ${
|
|
273
|
+
max-width: ${fn+Ct+32}px;
|
|
258
274
|
margin: 0 auto;
|
|
259
275
|
align-items: start;
|
|
260
276
|
}
|
|
@@ -265,19 +281,19 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
265
281
|
overflow-y: auto;
|
|
266
282
|
overscroll-behavior: contain;
|
|
267
283
|
padding-right: 4px;
|
|
268
|
-
border-right: 1px solid ${
|
|
284
|
+
border-right: 1px solid ${o("rule")};
|
|
269
285
|
}
|
|
270
286
|
.bim-d-reader-main { min-width: 0; }
|
|
271
287
|
|
|
272
288
|
/* intro / 成对区块:宽屏两栏,窄屏单栏 */
|
|
273
289
|
.bim-d-intro { display: grid; grid-template-columns: minmax(0, 1fr) 244px; gap: 30px;
|
|
274
|
-
padding: 20px 0 26px; border-bottom: 1px solid ${
|
|
290
|
+
padding: 20px 0 26px; border-bottom: 1px solid ${o("rule")};
|
|
275
291
|
margin-bottom: 40px; align-items: start; }
|
|
276
292
|
.bim-d-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 34px;
|
|
277
293
|
align-items: start; margin-bottom: 48px; }
|
|
278
294
|
.bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
|
|
279
295
|
|
|
280
|
-
@media ${
|
|
296
|
+
@media ${Ta} {
|
|
281
297
|
.bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
|
|
282
298
|
.bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
|
|
283
299
|
/* 表格:meta 列折到第二行,表头隐藏 */
|
|
@@ -291,30 +307,35 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
291
307
|
.bim-d-reader { grid-template-columns: 1fr; gap: 16px; }
|
|
292
308
|
.bim-d-reader-aside {
|
|
293
309
|
position: static; max-height: 240px;
|
|
294
|
-
border-right: none; border-bottom: 1px solid ${
|
|
310
|
+
border-right: none; border-bottom: 1px solid ${o("rule")};
|
|
295
311
|
padding-right: 0; padding-bottom: 12px;
|
|
296
312
|
}
|
|
297
313
|
}
|
|
298
|
-
${
|
|
299
|
-
`)||(n.push({start:
|
|
314
|
+
${Ca}`;function It({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Tr}),t.jsx("div",{className:r?"bim-d-main bim-d-main-grid":i?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function In({breadcrumb:e,actions:n}){return t.jsxs("div",{className:"bim-d-ui bim-d-top",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:o("aux-fg")},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:e}),n&&t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function Xn({char:e,tone:n="accent"}){return t.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,flex:"none",fontSize:11,fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",background:o(n==="accent"?"accent":"ink"),color:o("page-bg")},children:e})}function Tn({items:e}){const n=ve();return t.jsx(t.Fragment,{children:e.map((i,r)=>{const s=r===e.length-1,l=r>0&&t.jsx("span",{style:{color:o("hint-fg")},children:"/"},`s${r}`),p=i.id?n(i.id):i.href,d=s||!i.onClick&&!p?t.jsx("span",{style:{color:o("ink")},children:i.label},r):t.jsx("a",{href:p??"#",onClick:i.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i.onClick())}:void 0,style:{color:o("meta-fg")},children:i.label},r);return t.jsxs(f.Fragment,{children:[l,d]},r)})})}function Rr({title:e,subtitle:n,aside:i,secondLine:r}){return t.jsxs("header",{style:{borderBottom:`2px solid ${o("rule-strong")}`,paddingBottom:18},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[t.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:e}),n&&t.jsx("span",{style:{fontSize:15,color:o("meta-fg"),letterSpacing:".06em"},children:n})]}),i&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg"),letterSpacing:".06em"},children:i})]}),r&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:o("quiet-fg")},children:r})]})}function Ra({children:e,facts:n}){return!e&&n?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${o("rule")}`,marginBottom:40},children:n}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),n]})}function Ea({items:e,horizontal:n}){const{convert:i}=V();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${o("accent")}`,paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:e.map((r,s)=>t.jsxs("div",{title:r.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[t.jsx("span",{className:"bim-d-ui",style:{color:o("label-fg"),letterSpacing:".08em",flex:"none"},children:i(r.label)}),t.jsx("span",{style:{color:o("body-fg"),textAlign:n?"left":"right",minWidth:0},children:r.value})]},s))}):null}function La({glyph:e,tone:n,title:i,count:r,actions:s,id:l}){const{convert:p}=V();return t.jsxs("div",{id:l,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(Xn,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:p(i)}),r!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg")},children:r})]}),s&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function Er({label:e,active:n,onClick:i,dashed:r}){const{convert:s}=V();return t.jsx("button",{type:"button",onClick:i,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!n?"dashed":"solid"} ${o(n?"accent":"rule")}`,background:n?o("accent"):"transparent",color:o(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(e)})}function Na({label:e,onClick:n}){const{convert:i}=V();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg"),borderBottom:`1px solid ${o("rule")}`},children:i(e)})}function Ba({label:e,onClick:n,inline:i}){const{convert:r}=V();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:i?0:12,width:i?void 0:"100%",padding:i?"4px 12px":9,background:"none",border:`1px dashed ${o("rule-dashed")}`,cursor:"pointer",fontSize:12,color:o("meta-fg"),letterSpacing:i?void 0:".08em"},children:r(e)})}function Lr({children:e,href:n,onClick:i,title:r}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${o("rule")}`,fontSize:13,color:o("body-fg"),lineHeight:1.5};return n||i?t.jsx("a",{href:n??"#",title:r,onClick:i?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i())}:void 0,style:s,children:e}):t.jsx("span",{title:r,style:s,children:e})}function Wa({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function Aa({volumes:e,unit:n="冊",max:i=60}){const[r,s]=f.useState(!1);if(!e.length)return null;const l=r?e:e.slice(0,i);return t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[l.map(p=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${o("rule")}`,color:o("meta-fg")},children:p},p)),!r&&e.length>i&&t.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${o("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:o("meta-fg")},children:["+",e.length-i]}),t.jsx("span",{style:{padding:"2px 6px",color:o("hint-fg")},children:n})]})}function Ma({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${o("rule-strong")}`},children:e})}function Fa({spec:e}){const{convert:n}=V();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${o("rule-strong")}`,fontSize:11,color:o("label-fg"),letterSpacing:".1em"},children:[t.jsx("span",{}),t.jsx("span",{children:n(e.mainLabel)}),t.jsx("span",{style:{display:"grid",gridTemplateColumns:e.columns.map(i=>i.width).join(" "),gap:12},children:e.columns.map(i=>t.jsx("span",{children:n(i.label)},i.label))})]})}function Pa({no:e,main:n,meta:i,spec:r}){return t.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${r.leadWidth}px 1fr ${r.metaWidth}px`,gap:12},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:o("hint-fg"),textAlign:"right"},children:e}),t.jsx("span",{style:{minWidth:0},children:n}),t.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:r.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:i})]})}function Oa(e){return String(e+1).padStart(2,"0")}function Da(){return t.jsx("span",{style:{color:o("hint-fg")},children:"—"})}function Ha({open:e,onToggle:n,main:i,action:r,children:s}){return t.jsxs("div",{style:{borderBottom:`1px solid ${o("rule")}`},children:[t.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[t.jsx("button",{type:"button",onClick:n,"aria-expanded":e,className:"bim-d-ui",style:{width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",fontSize:12,lineHeight:1,border:`1px solid ${o(e?"accent":"rule-dashed")}`,background:e?o("accent"):"transparent",color:o(e?"page-bg":"accent")},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:i}),r]}),e&&s&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${o("rule-accent-soft")}`,marginLeft:12},children:s})]})}function Nr(e){const n=[];for(let i=0;i<e.length;i++){const r=e[i];let s;if(r==="⟨")s="⟩";else if(r==="<"){const d=e[i+1];if(d===void 0||/[A-Za-z/!?>\s]/.test(d))continue;s=">"}else continue;const l=e.indexOf(s,i+1);if(l<0)continue;const p=e.slice(i+1,l);p.includes(`
|
|
315
|
+
`)||(n.push({start:i,end:l+1,inner:p}),i=l)}return n}function Br(e,n){if(e.length<=n)return e;let i=n;for(const r of Nr(e)){if(r.start>=i)break;if(r.end>i){i=r.start>0?r.start:r.end;break}}return e.slice(0,i)}const Wr={fontSize:".78em",color:o("meta-fg"),lineHeight:1.55},Ga={display:"inline-block",fontSize:"1em",lineHeight:1.15,padding:"0 .12em",margin:"0 .05em",border:"1px solid color-mix(in srgb, currentColor 40%, transparent)",borderRadius:2,verticalAlign:"baseline",whiteSpace:"nowrap"};function Ar(e,n,i){return e.map((r,s)=>{switch(r.type){case"text":return t.jsx(f.Fragment,{children:n(r.text)},s);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:i===0?Wr:void 0,children:Ar(r.children,n,i+1)},s);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:r.label?`闕文:${r.label}`:"闕文",children:"□"},s);case"qz":return t.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":r.guess,children:"□"},s);case"zi":return t.jsx("span",{className:"bim-zi guji-zi",title:`組字:${r.label}`,style:Ga,children:r.label},s)}})}function Ie(e,n=r=>r,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return wa(e)?Ar($r(e),n,0):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let s=0,l=0;for(const p of Nr(e))p.start>s&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s,p.start))},l++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:Wr,children:n(p.inner)},l++)),s=p.end;return s<e.length&&r.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),r}function Ua({label:e,children:n}){return t.jsxs("div",{style:{marginBottom:10},children:[e&&t.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:o("label-fg"),marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:o("quiet-fg"),textAlign:"justify"},children:n})]})}function Va({title:e,tag:n,children:i}){const{convert:r}=V();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${o("rule-strong")}`,marginBottom:2},children:[t.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:r(e)}),n&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:o("accent"),letterSpacing:".06em"},children:r(n)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function Mr({name:e,note:n,href:i,extra:r}){const s=t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{fontSize:14,minWidth:0},children:e}),t.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:o("hint-fg"),flex:"none"},children:i?"↗":""}),n&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:o("label-fg")},children:n})]}),l={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${o("rule")}`,color:o("body-fg"),alignItems:"baseline"};return t.jsxs(t.Fragment,{children:[i?t.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:l,children:s}):t.jsx("div",{style:l,children:s}),r]})}function Ya({item:e,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=V(),[l,p]=f.useState(!1),d=Xt(e),c=i&&!!d&&d.expected>0,a=(e.url?tt(e.url):void 0)||s(e.name),u=n?hr(e,n):"",x=u?`${a}(${u})`:a;return t.jsx(Mr,{name:x,note:Bt(e)||r,href:bt(e),extra:c?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>p(g=>!g),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:o("meta-fg"),borderBottom:`1px solid ${o("rule")}`},children:l?"收起分冊":`展開 ${d.expected} 冊`}),l&&t.jsx(Qn,{item:e})]}):void 0})}function Qn({item:e}){return t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(e.volumes||[]).map((n,i)=>{const r=n.status==="missing";return n.url&&!r?t.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{padding:"4px 8px",borderRadius:4,background:o("zebra-bg")},children:n.volume},i):t.jsx("span",{style:{padding:"1px 5px",color:o(r?"missing-fg":"hint-fg"),textDecoration:r?"line-through":void 0},children:n.volume},i)})})}function Fr({label:e,items:n}){const{convert:i}=V();return n.length?t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg"),letterSpacing:".08em"},children:e}),n.map((r,s)=>t.jsx(Lr,{children:i(r)},s))]}):null}function Ka({rows:e}){const n=e.filter(i=>i.items.length>0);return n.length?t.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(i=>t.jsx(Fr,{label:i.label,items:i.items},i.label))}):null}function Rn(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Pr({left:e,right:n}){return t.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${o("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:o("aux-fg")},children:[t.jsx("span",{children:e}),n&&t.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function qa({children:e,action:n}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:o("aux-fg"),borderBottom:`1px solid ${o("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),n]})}function Pe({id:e,label:n,onNavigate:i,renderLink:r,style:s,dense:l}){const p=ve();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:l})}):t.jsx("a",{href:p(e),onClick:i?d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),i(e))}:void 0,style:s,children:n??e})}function Ja({href:e,children:n}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[n," ",t.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const Or="(min-width: 1100px)",Dr="(max-width: 719px)",Za=`${Dr}, (pointer: coarse)`,Ve=o("reader-top"),Xa="48px",Hr=`
|
|
300
316
|
.bim-rd {
|
|
301
317
|
position: relative;
|
|
302
|
-
background: ${
|
|
303
|
-
color: ${
|
|
304
|
-
font-family: ${
|
|
305
|
-
--bimrd-bar-h: ${
|
|
318
|
+
background: ${o("page-bg")};
|
|
319
|
+
color: ${o("ink")};
|
|
320
|
+
font-family: ${o("font-ui")};
|
|
321
|
+
--bimrd-bar-h: ${Xa};
|
|
306
322
|
}
|
|
307
323
|
.bim-rd *, .bim-rd *::before, .bim-rd *::after { box-sizing: border-box; }
|
|
308
324
|
|
|
309
|
-
/*
|
|
325
|
+
/* 跳到正文:平时按标准 visually-hidden 收成 1px 并裁掉(任何宽度都不外露),
|
|
326
|
+
获得焦点时才还原成左上角的按钮 */
|
|
310
327
|
.bim-rd-skip {
|
|
311
|
-
position: absolute;
|
|
328
|
+
position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
|
|
329
|
+
overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
|
|
330
|
+
}
|
|
331
|
+
.bim-rd-skip:focus {
|
|
332
|
+
left: 8px; top: 8px; z-index: 60;
|
|
333
|
+
width: auto; height: auto; margin: 0; overflow: visible; clip: auto; clip-path: none;
|
|
312
334
|
padding: 8px 14px; border-radius: 6px;
|
|
313
|
-
background: ${
|
|
335
|
+
background: ${o("ink")}; color: ${o("page-bg")} !important;
|
|
314
336
|
font-size: 14px; text-decoration: none !important;
|
|
315
|
-
|
|
337
|
+
outline: 2px solid ${o("accent")}; outline-offset: 2px;
|
|
316
338
|
}
|
|
317
|
-
.bim-rd-skip:focus { transform: none; outline: 2px solid ${i("accent")}; outline-offset: 2px; }
|
|
318
339
|
|
|
319
340
|
.bim-rd-sr {
|
|
320
341
|
position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
|
|
@@ -327,26 +348,33 @@ ${ua}`;function _t({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
327
348
|
height: var(--bimrd-bar-h);
|
|
328
349
|
display: flex; align-items: center; gap: 16px;
|
|
329
350
|
padding: 0 20px;
|
|
330
|
-
background: color-mix(in srgb, ${
|
|
351
|
+
background: color-mix(in srgb, ${o("page-bg")} 94%, transparent);
|
|
331
352
|
backdrop-filter: blur(8px);
|
|
332
353
|
}
|
|
333
354
|
.bim-rd-ttl { min-width: 0; display: flex; align-items: baseline; gap: 10px; overflow: hidden; white-space: nowrap; }
|
|
334
|
-
.bim-rd-ttl b { font-size: 15px; font-weight: 700; letter-spacing: 0.06em; color: ${
|
|
335
|
-
.bim-rd-ttl span { font-size: 13px; color: ${
|
|
336
|
-
.bim-rd-tools { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; color: ${
|
|
337
|
-
.bim-rd-tools .bim-rd-sep { width: 1px; height: 14px; background: ${
|
|
355
|
+
.bim-rd-ttl b { font-size: 15px; font-weight: 700; letter-spacing: 0.06em; color: ${o("ink")}; overflow: hidden; text-overflow: ellipsis; }
|
|
356
|
+
.bim-rd-ttl span { font-size: 13px; color: ${o("meta-fg")}; overflow: hidden; text-overflow: ellipsis; }
|
|
357
|
+
.bim-rd-tools { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; color: ${o("quiet-fg")}; flex: none; }
|
|
358
|
+
.bim-rd-tools .bim-rd-sep { width: 1px; height: 14px; background: ${o("rule")}; }
|
|
338
359
|
.bim-rd-t {
|
|
339
360
|
background: none; border: 0; margin: 0; padding: 6px 2px;
|
|
340
361
|
font: inherit; color: inherit; cursor: pointer; line-height: 1;
|
|
341
362
|
display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
|
|
342
363
|
}
|
|
343
|
-
.bim-rd-t:hover { color: ${
|
|
344
|
-
.bim-rd-t[aria-pressed="true"], .bim-rd-t[aria-current="true"] { color: ${
|
|
364
|
+
.bim-rd-t:hover { color: ${o("ink")}; }
|
|
365
|
+
.bim-rd-t[aria-pressed="true"], .bim-rd-t[aria-current="true"] { color: ${o("accent")}; }
|
|
345
366
|
.bim-rd-t:disabled { opacity: 0.4; cursor: default; }
|
|
346
367
|
.bim-rd-t svg { flex: none; }
|
|
347
|
-
.bim-rd-t .bim-rd-on { color: ${
|
|
368
|
+
.bim-rd-t .bim-rd-on { color: ${o("accent")}; font-weight: 700; }
|
|
348
369
|
.bim-rd-t .bim-rd-off { opacity: 0.55; }
|
|
349
|
-
.bim-rd
|
|
370
|
+
.bim-rd-ver { position: relative; display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
|
|
371
|
+
.bim-rd-ver-short { display: none; }
|
|
372
|
+
.bim-rd-ver select {
|
|
373
|
+
max-width: 16em; min-height: 32px; margin: 0; padding: 0 2px;
|
|
374
|
+
background: none; border: 0; font: inherit; color: ${o("ink")}; cursor: pointer;
|
|
375
|
+
text-overflow: ellipsis;
|
|
376
|
+
}
|
|
377
|
+
.bim-rd :focus-visible { outline: 2px solid ${o("accent")}; outline-offset: 2px; border-radius: 3px; }
|
|
350
378
|
|
|
351
379
|
/* ── 主体:目录 | 书影 | 正文 ── */
|
|
352
380
|
.bim-rd-body {
|
|
@@ -363,34 +391,34 @@ ${ua}`;function _t({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
363
391
|
width: 248px; height: calc(100vh - ${Ve} - var(--bimrd-bar-h));
|
|
364
392
|
overflow-y: auto; overscroll-behavior: contain;
|
|
365
393
|
padding: 0 10px 40px;
|
|
366
|
-
background: ${
|
|
394
|
+
background: ${o("sidebar-bg")};
|
|
367
395
|
}
|
|
368
396
|
.bim-rd[data-toc="closed"] .bim-rd-toc { display: none; }
|
|
369
397
|
.bim-rd-scrim { display: none; }
|
|
370
398
|
/* 目录标题与搜索框吸在目录顶上:长目录滚动时关闭键、搜索框不跟着滚走 */
|
|
371
|
-
.bim-rd-toc-top { position: sticky; top: 0; z-index: 1; padding-top: 16px; background: ${
|
|
372
|
-
.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: ${
|
|
399
|
+
.bim-rd-toc-top { position: sticky; top: 0; z-index: 1; padding-top: 16px; background: ${o("sidebar-bg")}; }
|
|
400
|
+
.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")}; }
|
|
373
401
|
.bim-rd-toc-head .bim-rd-t { margin-left: auto; letter-spacing: 0; }
|
|
374
402
|
.bim-rd-toc-search {
|
|
375
403
|
display: block; width: 100%; margin: 0 0 12px;
|
|
376
404
|
padding: 7px 10px; border-radius: 6px;
|
|
377
|
-
border: 1px solid transparent; background: ${
|
|
378
|
-
color: ${
|
|
405
|
+
border: 1px solid transparent; background: ${o("bg")};
|
|
406
|
+
color: ${o("ink")}; font: inherit; font-size: 13px;
|
|
379
407
|
}
|
|
380
|
-
.bim-rd-toc-search:focus { border-color: ${
|
|
408
|
+
.bim-rd-toc-search:focus { border-color: ${o("accent")}; outline: none; }
|
|
381
409
|
.bim-rd-toc ul { list-style: none; margin: 0; padding: 0; }
|
|
382
410
|
.bim-rd-toc li ul { padding-left: 14px; }
|
|
383
411
|
.bim-rd-ti {
|
|
384
412
|
display: flex; align-items: baseline; gap: 8px; width: 100%;
|
|
385
413
|
padding: 5px 10px; border: 0; border-radius: 6px; margin: 0;
|
|
386
414
|
background: none; font: inherit; font-size: 13px; line-height: 1.5; text-align: left;
|
|
387
|
-
color: ${
|
|
415
|
+
color: ${o("quiet-fg")}; cursor: pointer;
|
|
388
416
|
}
|
|
389
|
-
.bim-rd-ti:hover { background: ${
|
|
390
|
-
.bim-rd-ti[aria-current="true"] { background: ${
|
|
417
|
+
.bim-rd-ti:hover { background: ${o("row-hover-bg")}; color: ${o("ink")}; }
|
|
418
|
+
.bim-rd-ti[aria-current="true"] { background: ${o("bg")}; color: ${o("accent")}; font-weight: 700; }
|
|
391
419
|
.bim-rd-ti:disabled { opacity: 0.45; cursor: default; background: none; }
|
|
392
|
-
.bim-rd-ti .bim-rd-hint { margin-left: auto; font-size: 12px; font-weight: 400; color: ${
|
|
393
|
-
.bim-rd-ti-group { font-weight: 600; color: ${
|
|
420
|
+
.bim-rd-ti .bim-rd-hint { margin-left: auto; font-size: 12px; font-weight: 400; color: ${o("meta-fg")}; flex: none; }
|
|
421
|
+
.bim-rd-ti-group { font-weight: 600; color: ${o("ink")}; }
|
|
394
422
|
.bim-rd-ti-group svg { transition: transform 0.15s; flex: none; align-self: center; }
|
|
395
423
|
.bim-rd-ti-group[aria-expanded="true"] svg { transform: rotate(90deg); }
|
|
396
424
|
|
|
@@ -405,38 +433,38 @@ ${ua}`;function _t({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
405
433
|
.bim-rd[data-img="closed"] .bim-rd-img { display: none; }
|
|
406
434
|
.bim-rd-img-box {
|
|
407
435
|
position: relative; flex: 1; min-height: 0; border-radius: 10px;
|
|
408
|
-
background: ${
|
|
436
|
+
background: ${o("sidebar-bg")};
|
|
409
437
|
display: flex; align-items: center; justify-content: center; overflow: hidden;
|
|
410
438
|
}
|
|
411
439
|
.bim-rd-img-fig { position: relative; margin: 0; max-width: 100%; max-height: 100%; }
|
|
412
440
|
.bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${Ve} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
|
|
413
441
|
.bim-rd-img-fig svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
|
|
414
|
-
.bim-rd-img-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 24px; text-align: center; font-size: 13px; color: ${
|
|
415
|
-
.bim-rd-img-empty b { font-size: 15px; font-weight: 500; color: ${
|
|
442
|
+
.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")}; }
|
|
443
|
+
.bim-rd-img-empty b { font-size: 15px; font-weight: 500; color: ${o("quiet-fg")}; }
|
|
416
444
|
.bim-rd-img-frame {
|
|
417
445
|
width: 46%; aspect-ratio: 2 / 3; border-radius: 4px; margin-bottom: 10px;
|
|
418
|
-
background: repeating-linear-gradient(90deg, transparent 0 22px, color-mix(in srgb, ${
|
|
446
|
+
background: repeating-linear-gradient(90deg, transparent 0 22px, color-mix(in srgb, ${o("ink")} 5%, transparent) 22px 24px), ${o("bg")};
|
|
419
447
|
}
|
|
420
|
-
.bim-rd-img-pager { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 13px; color: ${
|
|
448
|
+
.bim-rd-img-pager { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 13px; color: ${o("quiet-fg")}; }
|
|
421
449
|
|
|
422
450
|
/* 正文 */
|
|
423
451
|
.bim-rd-text { grid-column: 3; min-width: 0; padding: 32px 48px 96px; outline: none; }
|
|
424
452
|
.bim-rd-col { max-width: 38em; margin: 0 auto; font-size: var(--bimrd-fs, 18px); }
|
|
425
|
-
.bim-rd-h1 { font-family: ${
|
|
426
|
-
.bim-rd-meta { margin: 6px 0 0; font-size: 13px; line-height: 1.8; color: ${
|
|
453
|
+
.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; }
|
|
454
|
+
.bim-rd-meta { margin: 6px 0 0; font-size: 13px; line-height: 1.8; color: ${o("meta-fg")}; font-family: ${o("font-ui")}; }
|
|
427
455
|
.bim-rd-meta .bim-rd-dot::before { content: "·"; margin: 0 0.5em; }
|
|
428
456
|
.bim-rd-meta select { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
|
|
429
|
-
.bim-rd a.bim-rd-link { color: ${
|
|
430
|
-
.bim-rd a.bim-rd-link:hover { color: ${
|
|
431
|
-
.bim-rd-views { display: flex; gap: 14px; margin-top: 10px; font-size: 13px; color: ${
|
|
432
|
-
.bim-rd-state { padding: 32px 0; font-size: 14px; color: ${
|
|
457
|
+
.bim-rd a.bim-rd-link { color: ${o("quiet-fg")}; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
|
|
458
|
+
.bim-rd a.bim-rd-link:hover { color: ${o("accent")}; }
|
|
459
|
+
.bim-rd-views { display: flex; gap: 14px; margin-top: 10px; font-size: 13px; color: ${o("quiet-fg")}; font-family: ${o("font-ui")}; }
|
|
460
|
+
.bim-rd-state { padding: 32px 0; font-size: 14px; color: ${o("meta-fg")}; font-family: ${o("font-ui")}; }
|
|
433
461
|
|
|
434
462
|
/* 宋体正文:18px / 2.05,避头尾 */
|
|
435
463
|
.bim-rd-prose {
|
|
436
464
|
margin-top: 28px;
|
|
437
|
-
font-family: ${
|
|
465
|
+
font-family: ${o("font-reading")};
|
|
438
466
|
line-height: 2.05;
|
|
439
|
-
color: ${
|
|
467
|
+
color: ${o("ink")};
|
|
440
468
|
text-align: justify;
|
|
441
469
|
line-break: strict;
|
|
442
470
|
hanging-punctuation: allow-end;
|
|
@@ -444,25 +472,30 @@ ${ua}`;function _t({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
444
472
|
}
|
|
445
473
|
.bim-rd-prose p { margin: 0.5em 0; text-indent: 2em; }
|
|
446
474
|
.bim-rd-prose .bim-rd-noindent { text-indent: 0; }
|
|
447
|
-
.bim-rd-prose h2, .bim-rd-prose h3, .bim-rd-prose h4 { font-family: ${
|
|
475
|
+
.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; }
|
|
448
476
|
.bim-rd-prose h2 { font-size: 1.2em; font-weight: 700; margin: 1.6em 0 0.6em; }
|
|
449
477
|
.bim-rd-prose h3 { font-size: 1.06em; font-weight: 700; margin: 1.4em 0 0.3em; }
|
|
450
478
|
.bim-rd-prose h4 { font-size: 1em; font-weight: 700; margin: 1.2em 0 0.2em; }
|
|
451
479
|
.bim-rd-prose > :first-child { margin-top: 0; }
|
|
480
|
+
/* 标题标签按层级不跳级(h1 下先 h2,INT Q5),外观按 md 原层级走 class */
|
|
481
|
+
.bim-rd-prose .bim-rd-hl2 { font-size: 1.2em; font-weight: 700; margin: 1.6em 0 0.6em; }
|
|
482
|
+
.bim-rd-prose .bim-rd-hl3 { font-size: 1.06em; font-weight: 700; margin: 1.4em 0 0.3em; }
|
|
483
|
+
.bim-rd-prose .bim-rd-hl4 { font-size: 1em; font-weight: 700; margin: 1.2em 0 0.2em; }
|
|
484
|
+
.bim-rd-prose > .bim-rd-hl2:first-child, .bim-rd-prose > .bim-rd-hl3:first-child, .bim-rd-prose > .bim-rd-hl4:first-child { margin-top: 0; }
|
|
452
485
|
.bim-rd-prose .bim-rd-gap { height: 0.6em; }
|
|
453
486
|
.bim-rd-entry { margin-top: 1.6em; }
|
|
454
487
|
.bim-rd-entry h3 { margin: 0 !important; }
|
|
455
488
|
.bim-rd-entry h3 a { color: inherit !important; text-decoration: none; }
|
|
456
|
-
.bim-rd-entry h3 a:hover { color: ${
|
|
457
|
-
.bim-rd-entry .bim-rd-sub { font-family: ${
|
|
458
|
-
.bim-rd-entry .bim-rd-lbl { font-family: ${
|
|
489
|
+
.bim-rd-entry h3 a:hover { color: ${o("accent")} !important; text-decoration: underline; text-underline-offset: 4px; }
|
|
490
|
+
.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; }
|
|
491
|
+
.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; }
|
|
459
492
|
.bim-rd-prose strong { font-weight: 700; }
|
|
460
493
|
|
|
461
494
|
/* 专名线:书名加波浪线,书名号隐去(仍可复制) */
|
|
462
495
|
.bim-rd-pn {
|
|
463
496
|
text-decoration-line: underline; text-decoration-style: wavy;
|
|
464
497
|
text-decoration-thickness: 1px; text-underline-offset: 0.32em;
|
|
465
|
-
text-decoration-color: ${
|
|
498
|
+
text-decoration-color: ${o("quiet-fg")};
|
|
466
499
|
text-decoration-skip-ink: none;
|
|
467
500
|
}
|
|
468
501
|
|
|
@@ -472,32 +505,50 @@ ${ua}`;function _t({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
472
505
|
overflow-x: auto; text-align: start;
|
|
473
506
|
}
|
|
474
507
|
|
|
475
|
-
.bim-rd-
|
|
476
|
-
.bim-rd-
|
|
477
|
-
.bim-rd-
|
|
478
|
-
.bim-rd-
|
|
508
|
+
.bim-rd-src { margin: 48px 0 0; font-size: 12px; line-height: 1.8; color: ${o("meta-fg")}; font-family: ${o("font-ui")}; }
|
|
509
|
+
.bim-rd-src .bim-rd-dot::before { content: "·"; margin: 0 0.5em; }
|
|
510
|
+
.bim-rd-pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 56px; font-size: 14px; font-family: ${o("font-ui")}; }
|
|
511
|
+
.bim-rd-pager .bim-rd-t { color: ${o("quiet-fg")}; }
|
|
512
|
+
.bim-rd-refs { margin-top: 48px; font-size: 12px; line-height: 1.8; color: ${o("meta-fg")}; font-family: ${o("font-ui")}; }
|
|
513
|
+
.bim-rd-refs h2 { font-size: 12px; font-weight: 600; letter-spacing: 0.2em; margin: 0 0 6px; color: ${o("meta-fg")}; }
|
|
479
514
|
.bim-rd-refs ol { margin: 0; padding-left: 1.6em; }
|
|
480
515
|
|
|
516
|
+
/* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
|
|
517
|
+
A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
|
|
518
|
+
@media ${Za} {
|
|
519
|
+
.bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
|
|
520
|
+
.bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
|
|
521
|
+
content: ""; position: absolute; left: 50%; top: 50%;
|
|
522
|
+
width: max(100%, 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
|
|
523
|
+
}
|
|
524
|
+
.bim-rd-tools .bim-rd-fs + .bim-rd-fs { margin-left: 12px; }
|
|
525
|
+
.bim-rd-ver select { min-height: 44px; }
|
|
526
|
+
}
|
|
527
|
+
|
|
481
528
|
/* ── 中屏以下:目录改抽屉 ── */
|
|
482
|
-
@media not all and ${
|
|
529
|
+
@media not all and ${Or} {
|
|
483
530
|
.bim-rd-toc {
|
|
484
531
|
position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto;
|
|
485
532
|
width: min(86vw, 320px);
|
|
486
|
-
box-shadow: ${
|
|
533
|
+
box-shadow: ${o("shadow-dialog")};
|
|
487
534
|
}
|
|
488
535
|
.bim-rd[data-toc="auto"] .bim-rd-toc { display: none; }
|
|
489
536
|
.bim-rd[data-toc="open"] .bim-rd-scrim {
|
|
490
|
-
display: block; position: fixed; inset: 0; z-index: 45; background: ${
|
|
537
|
+
display: block; position: fixed; inset: 0; z-index: 45; background: ${o("backdrop")};
|
|
491
538
|
}
|
|
492
539
|
.bim-rd-text { padding: 28px 32px 80px; }
|
|
493
540
|
}
|
|
494
541
|
|
|
495
542
|
/* ── 窄屏:书影收起,只留正文 ── */
|
|
496
|
-
@media ${
|
|
543
|
+
@media ${Dr} {
|
|
497
544
|
.bim-rd-bar { padding: 0 12px; gap: 10px; }
|
|
498
545
|
.bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
|
|
499
546
|
.bim-rd-ttl { flex: 1 1 auto; }
|
|
500
547
|
.bim-rd-tools { gap: 10px; }
|
|
548
|
+
.bim-rd-ver { min-width: 44px; min-height: 44px; justify-content: center; }
|
|
549
|
+
.bim-rd-ver-short { display: inline; white-space: nowrap; }
|
|
550
|
+
.bim-rd-ver select { position: absolute; inset: 0; width: 100%; max-width: none; opacity: 0; }
|
|
551
|
+
.bim-rd-ver:focus-within { outline: 2px solid ${o("accent")}; outline-offset: 2px; border-radius: 3px; }
|
|
501
552
|
.bim-rd-tlabel { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
502
553
|
.bim-rd-img { display: none !important; }
|
|
503
554
|
.bim-rd-body { grid-template-columns: minmax(0, 1fr); }
|
|
@@ -505,15 +556,134 @@ ${ua}`;function _t({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
505
556
|
.bim-rd-h1 { font-size: 20px; letter-spacing: 0.06em; }
|
|
506
557
|
.bim-rd-prose { margin-top: 20px; }
|
|
507
558
|
}
|
|
508
|
-
`;function Jn(e,n){var o;return n?e.key===n?!0:!!((o=e.children)!=null&&o.some(r=>Jn(r,n))):!1}const Aa=()=>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 Ma({item:e,activeKey:n,onSelect:o,tabKey:r}){const s=Jn(e,n),[l,p]=f.useState(s||!!e.defaultExpanded);return f.useEffect(()=>{s&&p(!0)},[s]),f.useEffect(()=>{e.defaultExpanded&&p(!0)},[e.defaultExpanded]),t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>p(d=>!d),children:[t.jsx(Aa,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Nr,{items:e.children,activeKey:n,onSelect:o,tabKey:r})]})}function Nr({items:e,activeKey:n,onSelect:o,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Ma,{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 ei(e,n){var o;for(const r of e)if(r.key===n||Jn(r,n))return r.key;return((o=e[0])==null?void 0:o.key)??null}function Wr({items:e,activeKey:n,onSelect:o,label:r="目录"}){const s=f.useRef(null),[l,p]=f.useState(null);f.useEffect(()=>{p(null)},[n]);const d=f.useMemo(()=>l||(n??ei(e,n)),[l,n,e]);f.useEffect(()=>{const a=s.current;if(!a)return;const u=Array.from(a.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const x=u.find(g=>g.dataset.rdTocKey===d)??u.find(g=>g.dataset.rdTocKey===ei(e,n))??u.find(g=>!g.disabled)??u[0];for(const g of u)g.tabIndex=g===x?0:-1}),f.useEffect(()=>{const a=s.current,u=a==null?void 0:a.closest(".bim-rd-toc");if(!a||!u||!n)return;const x=Array.from(a.querySelectorAll("[data-rd-toc-key]")).find(h=>h.dataset.rdTocKey===n);if(!x)return;const g=x.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(g<u.scrollTop+80||g>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,g-u.clientHeight/3))},[n]);const c=f.useCallback(a=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(a.key))return;const x=s.current;if(!x)return;const g=Array.from(x.querySelectorAll("[data-rd-toc-key]")).filter(m=>!m.disabled),h=g.indexOf(document.activeElement);let y=h;if(a.key==="ArrowDown"?y=Math.min(g.length-1,h+1):a.key==="ArrowUp"?y=Math.max(0,h-1):a.key==="Home"?y=0:a.key==="End"&&(y=g.length-1),y<0||y===h)return;a.preventDefault();const k=g[y];for(const m of g)m.tabIndex=-1;k.tabIndex=0,k.focus(),p(k.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:c,children:t.jsx(Nr,{items:e,activeKey:n,onSelect:o,tabKey:d})})}function Fa({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 Ar({pages:e,loading:n,page:o,onPageChange:r,renderOverlay:s}){const[l,p]=f.useState(0),d=o??l,c=g=>{r?r(g):p(g)};if(f.useEffect(()=>{o===void 0&&p(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,d)),u=e[a],x=u.label??`${a+1}`;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${x} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(Fa,{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 Zn={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal"},ct=[15,16,17,18,20,22,24],In=18,Mr="bim-reader-prefs",Pa="bim-reading-mode";function Oa(){const e={...Zn};try{const n=localStorage.getItem(Mr),o=n?JSON.parse(n):{};typeof o.fontSize=="number"&&ct.includes(o.fontSize)&&(e.fontSize=o.fontSize),(o.readingMode??localStorage.getItem(Pa))==="paragraph"&&(e.readingMode="paragraph"),o.properNames===!0&&(e.properNames=!0),o.writingMode==="vertical"&&(e.writingMode="vertical")}catch{}return e}function Ha(e){try{localStorage.setItem(Mr,JSON.stringify(e))}catch{}}function ti(e,n){const o=e??In,r=ct;let s=r.indexOf(o);return s<0&&(s=r.indexOf(In)),r[Math.max(0,Math.min(r.length-1,s+n))]}function Xn(){const[e,n]=f.useState(Zn);f.useEffect(()=>{n(Oa())},[]);const o=f.useCallback(r=>{n(s=>{const l={...s,...r};return Ha(l),l})},[]);return[e,o]}function Fr(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 Da=()=>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"})}),Ga=()=>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 Va(e,n){if(!n)return;const o=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(p=>p.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 Ua(e,n){const[o,r]=f.useState(n);return f.useEffect(()=>{var p;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(s.matches);return(p=s.addEventListener)==null||p.call(s,"change",l),()=>{var d;return(d=s.removeEventListener)==null?void 0:d.call(s,"change",l)}},[e]),o}function Ya(){const e=f.useContext(xt);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 Qn({title:e,subtitle:n,toc:o,activeKey:r,onSelect:s,tocHeader:l,tocCaption:p,images:d,imagesLoading:c,renderImageOverlay:a,imagePanel:u="auto",prefs:x,onPrefsChange:g,paragraphToggle:h,properNameToggle:y=!0,allowVertical:k,pager:m=!0,children:v,className:b,style:j}){const w=f.useId().replace(/:/g,""),S=`bim-rd-toc-${w}`,z=`bim-rd-text-${w}`,_=f.useRef(null),T=f.useRef(null),B=f.useRef(null),L=f.useRef(null),$=Ua(Lr,!0),[F,W]=f.useState("auto"),I=F==="auto"?$:F==="open",R=!$,N=!!d&&d.length>0,[O,E]=f.useState(u);f.useEffect(()=>{E(u)},[u]);const X=O==="auto"?N||!!c:O==="open",C=f.useCallback(V=>{var se;W("auto"),V&&((se=L.current)==null||se.focus())},[]),A=()=>W(I?"closed":"open");f.useEffect(()=>{if(!R||F!=="open")return;const V=B.current,se=V==null?void 0:V.querySelector('input, [data-rd-toc-key][tabindex="0"]');se==null||se.focus()},[R,F]);const K=f.useCallback(V=>{s(V),R&&C(!1);const se=T.current,de=_.current;if(se&&de&&typeof window<"u"){const H=se.getBoundingClientRect().top-de.getBoundingClientRect().bottom;H<0&&window.scrollBy({top:H})}},[s,R,C]),U=f.useMemo(()=>Fr(o),[o]),G=U.findIndex(V=>V.key===r),ee=G>0?U.slice(0,G).reverse().find(V=>!V.disabled):void 0,P=G>=0?U.slice(G+1).find(V=>!V.disabled):void 0,q=x.fontSize??In,Z={...j,...x.fontSize?{"--bimrd-fs":`${x.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",x.writingMode==="vertical"&&k?"bim-rd-vertical":"",b].filter(Boolean).join(" "),"data-toc":F,"data-img":X?"open":"closed",style:Z,children:[t.jsx("style",{children:Br}),t.jsx("a",{className:"bim-rd-skip",href:`#${z}`,onClick:V=>{var se,de,H;V.preventDefault(),(se=T.current)==null||se.focus(),(H=(de=T.current)==null?void 0:de.scrollIntoView)==null||H.call(de,{block:"start"})},children:"跳到正文"}),t.jsxs("div",{className:"bim-rd-bar",ref:_,children:[(e||n)&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),n&&t.jsx("span",{children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":"阅读设置",children:[t.jsxs("button",{ref:L,type:"button",className:"bim-rd-t","aria-expanded":I,"aria-controls":S,onClick:A,children:[t.jsx(Da,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":X,onClick:()=>E(X?"closed":"open"),children:[t.jsx(Ga,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Ya,{}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"缩小字号",disabled:q<=ct[0],onClick:()=>g({fontSize:ti(x.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大字号",disabled:q>=ct[ct.length-1],onClick:()=>g({fontSize:ti(x.fontSize,1)}),children:"A+"}),(h||y||k)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),h&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":x.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>g({readingMode:x.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),y&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":x.properNames,title:"书名加波浪线",onClick:()=>g({properNames:!x.properNames}),children:"专名线"}),k&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":x.writingMode==="vertical",onClick:()=>g({writingMode:x.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:S,ref:B,role:R&&I?"dialog":void 0,"aria-modal":R&&I?!0:void 0,"aria-label":R&&I?"目录":void 0,onKeyDown:V=>{if(!(!R||!I)){if(V.key==="Escape"){V.stopPropagation(),C(!0);return}V.key==="Tab"&&Va(V,B.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:p??"目录"}),R&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>C(!0),children:"✕"})]}),l]}),t.jsx(Wr,{items:o,activeKey:r,onSelect:K})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>C(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:X&&t.jsx(Ar,{pages:d??null,loading:c,renderOverlay:a})}),t.jsx("div",{className:"bim-rd-text",id:z,ref:T,tabIndex:-1,children:t.jsxs("div",{className:"bim-rd-col",children:[v,m&&(ee||P)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[t.jsx("span",{children:ee&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>K(ee.key),children:["‹ ",ee.label]})}),t.jsx("span",{children:P&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>K(P.key),children:[P.label," ›"]})})]})]})})]})]})}const Pr="guji-table-v1";function Or(e){return!!e&&e.table_notation===Pr}const Ka=/^:::table(?:\{[^}]*\})?[ \t]*$/,qa=/^:::[ \t]*$/;function Hr(e){const n=[];let o="";for(let r=0;r<e.length;r++){const s=e[r];let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const p=e[r+1];p!==void 0&&!/[A-Za-z/!?>\s]/.test(p)&&(l=">")}if(l){const p=e.indexOf(l,r+1);if(p>0){o+=e.slice(r,p+1),r=p;continue}}s==="|"?(n.push(o),o=""):o+=s}return n.push(o),n.map(r=>r.trim())}const Ja=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function Za(e){if(e==="^")return{cont:!0};const n=Ja.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 Dr(e,n=1){const o=[],r=[],s=[];let l=[];e.forEach((d,c)=>{const a=c+n+1;let u=d.trim();if(!u)return;let x=!1;u.startsWith("!")&&(x=!0,u=u.slice(1));const g=Hr(u).map(Za),h=l.map(v=>v>0),y=l.map(v=>v>0?v-1:0),k=[];let m=0;for(const v of g){if(v.cont){h[m]||o.push(`第 ${a} 行第 ${m+1} 列:续格 ^ 上方没有跨行格`),m+=1;continue}const{cell:b}=v;for(let j=m;j<m+b.colspan;j++)if(h[j]){o.push(`第 ${a} 行第 ${j+1} 列:此处被上方跨行格占住,应写 ^`);break}if(b.rowspan>1)for(let j=m;j<m+b.colspan;j++)y[j]=b.rowspan-1;k.push(b),m+=b.colspan}for(let v=m;v<h.length;v++)h[v]&&o.push(`第 ${a} 行第 ${v+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let v=0;v<y.length;v++)y[v]===void 0&&(y[v]=0);l=y,r.push({header:x,cells:k}),s.push({width:m,line:a})});const p=s.reduce((d,c)=>Math.max(d,c.width),0);for(const d of s)d.width!==p&&o.push(`第 ${d.line} 行:占 ${d.width} 列,与总列数 ${p} 不符`);return l.some(d=>d>0)&&o.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&o.push("空表"),{rows:r,columns:p,warnings:o}}function eo(e){const n=e.split(`
|
|
509
|
-
`),
|
|
510
|
-
`)
|
|
511
|
-
`)
|
|
512
|
-
`).map(
|
|
513
|
-
`)
|
|
514
|
-
`)
|
|
515
|
-
`)
|
|
516
|
-
`))
|
|
517
|
-
`)
|
|
518
|
-
`);let d=0;return t.jsx(t.Fragment,{children:p.map((c,a)=>{const u=c.match(pn);if(u){const g=d++;if(l(u[1].length,u[2],g))return null;const h=un(u[1].length);return t.jsx(h,{children:o(u[2])},a)}if(!c.trim())return a>=2&&!!p[a-1].trim()&&!!p[a-2].trim()&&!pn.test(p[a-1])&&!pn.test(p[a-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},a):null;if(cc.test(c))return null;if(d++,/^\*\*[^*]+\*\*\s*$/.test(c.trim())){const g=un(3);return t.jsx(g,{children:o(c.trim().slice(2,-2))},a)}return t.jsx("p",{children:oi(c,o,a)},a)})})}function dc(e){const{convert:n}=Y();return f.useMemo(()=>e?n(e):"",[e,n])}function ro({text:e,mode:n,tables:o=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:p}){const d=dc(e),{convert:c}=Y(),a=g=>io(g,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,x=p?c(p):void 0;return!o||d.indexOf(":::")<0?t.jsx(ii,{text:d,mode:n,inline:a,dropTitle:x}):t.jsx(t.Fragment,{children:eo(d).map((g,h)=>g.type==="table"?t.jsx(to,{table:g.table,opts:u},h):t.jsx(ii,{text:g.text,mode:n,inline:a,dropTitle:h===0?x:void 0},h))})}function Xr(e,n){const[o,r]=f.useState(null),[s,l]=f.useState(!1),p=f.useRef(0);return f.useEffect(()=>{const d=++p.current;if(!e||!n){r(null),l(!1);return}let c;try{c=e(n)}catch{r(null),l(!1);return}if(!c||typeof c.then!="function"){r(c??null),l(!1);return}l(!0),c.then(a=>{d===p.current&&r(a??null)}).catch(()=>{d===p.current&&r(null)}).finally(()=>{d===p.current&&l(!1)})},[e,n]),{images:o,loading:s}}const ri={A:"fine",B:"rough",C:"rough",D:"ocr"};function pc(e){return typeof e!="string"?null:e in yn?e:e in ri?ri[e]:null}const uc={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},xc={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function Oe(e){return typeof e!="string"?"":uc[e]??xc[e]??e}const fc=["〇","一","二","三","四","五","六","七","八","九"],si=["","十","百","千"],gc=["","萬","億"];function so(e){if(e===0)return"〇";if(e<0)return`負${so(-e)}`;const n=[];let o=e,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(hc(s,r>0)+gc[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function hc(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 p=o[l],d=o.length-1-l;p===0?s&&!s.endsWith("〇")&&(s+="〇"):p===1&&d===1&&l===0&&!n?s+=si[d]:s+=fc[p]+si[d]}return s.replace(/〇$/,"")}let Ct=null,Ot=null;const Ut=new Set;function mc(){return Ct?Promise.resolve():Ot||(Ot=import("opencc-js/t2cn").then(e=>{Ct=e.Converter({from:"tw",to:"cn"}),Ut.forEach(n=>n())}).catch(()=>{Ct=e=>e,Ut.forEach(e=>e())}),Ot)}const bc=e=>e;function nt(){const[,e]=f.useState(0);return f.useEffect(()=>{if(Ct)return;const n=()=>e(o=>o+1);return Ut.add(n),mc(),()=>{Ut.delete(n)}},[]),Ct??bc}function ut(e,n){return n(e).toLowerCase()}const yc=i("highlight-bg");function Wt(e,n,o){if(!n)return e;const r=ut(n,o);if(!r)return e;const s=ut(e,o);if(s.length!==e.length)return e;const l=[];let p=0,d=0;for(;p<e.length;){const c=s.indexOf(r,p);if(c===-1){l.push(e.slice(p));break}c>p&&l.push(e.slice(p,c)),l.push(t.jsx("mark",{style:{background:yc,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},d++)),p=c+r.length}return t.jsx(t.Fragment,{children:l})}function lo(e,n,o,r){if(!n)return!0;const s=ut(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(p=>typeof p=="string"&&ut(p,r).includes(s))}function jc(e,n,o){return n?ut(e,o).includes(ut(n,o)):!0}const ao={类:i("section-lei"),书:i("section-shu"),序:i("section-xu"),结语:i("section-jieyu"),注释:i("section-zhushi")},vc={考证:i("section-kaozhen")};function kc(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 Qr(e){var r;const n=e.files.length,o=((r=e.children)==null?void 0:r.reduce((s,l)=>s+Qr(l),0))||0;return n+o}function Sc(e,n){const o=[],r=p=>{var d;o.push(...p.files),(d=p.children)==null||d.forEach(r)};if(r(e),o.length===0)return;const s=o.map(p=>n[p]);if(s.every(p=>p===void 0))return;if(s.some(p=>p==="loading"))return"loading";let l=0;for(const p of s)typeof p=="number"&&(l+=p);return l}const wc={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function co({enabled:e,expanded:n,onClick:o,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:o,style:{...wc,...r},children:s}):t.jsx("span",{style:r,children:s})}function _c({type:e}){const n=Oe(e),o=ao[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 zc({section:e,onNavigate:n,highlightQuery:o=""}){const{convert:r}=Y(),s=je(),l=nt(),p=k=>k?$e(r(k),m=>o?Wt(m,o,l):m):"",[d,c]=f.useState(!1),a=!!e.summary,u=!!e.comment,x=!!e.additional_comment,g=!!(e.content&&e.content.length>60),h=a||u||x||g;f.useEffect(()=>{o&&c(!0)},[o]);const y=!d&&g?$r(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[t.jsxs("div",{onClick:()=>h&&c(!d),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:h?"pointer":"default",userSelect:"none",background:i("input-bg")},children:[t.jsxs(co,{enabled:h,expanded:d,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[h&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",p(e.book_title),"》"]}):p(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[so(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:p(e.author_info||e.author)})]}),!d&&y&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:p(y)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:p(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:s(e.work_id),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),d&&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:p(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:p(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:p(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:p(e.additional_comment)})]}),g&&!a&&!u&&!x&&t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:p(e.content)})]})]})}function $c({section:e,highlightQuery:n=""}){const{convert:o}=Y(),r=nt(),s=c=>c?$e(o(c),a=>n?Wt(a,n,r):a):"",[l,p]=f.useState(!1),d=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(co,{enabled:d,expanded:l,onClick:()=>p(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:d?"pointer":"default",userSelect:"none"},children:[t.jsx(_c,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:s(e.title)}),d&&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&&d&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${ao[Oe(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 Cc=100;function po(e){return Oe(e.type)!=="page_header"?!1:(e.content||"").length>=Cc}function Ic({section:e,highlightQuery:n=""}){const{convert:o}=Y(),r=nt();if(Oe(e.type)==="page_header"&&!po(e)||!e.content&&!e.title)return null;const s=o((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
519
|
-
`)),l=$e(s,a=>n?Wt(a,n,r):a),p=Oe(e.type),d=ao[p]||i("desc-fg"),c=p==="序"||p==="结语"||p==="注释";return t.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:i("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${d}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:d,marginRight:"8px",padding:"1px 5px",border:`1px solid ${d}40`,borderRadius:"2px",background:`${d}08`,verticalAlign:"middle"},children:p}),l]})}function Tc(e,n,o){const[r,s]=f.useState({});return f.useEffect(()=>{var a;if(!n||e.length===0)return;let l=!1;const p=e.filter(u=>{var x;return!((x=o==null?void 0:o.current)!=null&&x.has(u))}),d={};for(const u of e)(a=o==null?void 0:o.current)!=null&&a.has(u)&&(d[u]=o.current.get(u));if(Object.keys(d).length>0&&s(d),p.length===0)return;const c=async u=>{var x;try{if(n.getEntry){const m=await n.getEntry(u);if(m)return{title:m.title,author:m.author}}const g=await n.getItem(u);if(!g)return null;const h=g.title||u,y=g.authors,k=(x=y==null?void 0:y[0])==null?void 0:x.name;return{title:h,author:k}}catch{return null}};return Promise.all(p.map(async u=>{var g;const x=await c(u);return(g=o==null?void 0:o.current)==null||g.set(u,x),[u,x]})).then(u=>{l||s(x=>{const g={...x};for(const[h,y]of u)g[h]=y;return g})}),()=>{l=!0}},[e.join(","),n]),r}function Rc({section:e,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=Y(),p=je(),d=nt(),c=b=>b?$e(l(b),j=>s?Wt(j,s,d):j):"",[a,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const x=Oe(e.type),g=vc[x]||i("desc-fg"),h=!!e.content,y=e.work_ids||[],k=y.length>1,m=Tc(k?y:[],o,r),v=h&&!a&&e.content.length>80?$r(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${i("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>h&&u(!a),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:h?"pointer":"default",userSelect:"none"},children:[t.jsxs(co,{enabled:h,expanded:a,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[h&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color: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&&v&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:i("desc-fg"),lineHeight:1.7},children:c(v)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[y.length===1&&n&&t.jsx("a",{href:p(y[0]),onClick:b=>{b.metaKey||b.ctrlKey||(b.preventDefault(),b.stopPropagation(),n(y[0]))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),k&&t.jsxs("span",{style:{fontSize:"11px",color:i("link-fg"),flexShrink:0},children:[y.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:g,border:`1px solid ${g}40`,borderRadius:"2px",background:`${g}08`},children:x})]})]}),k&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:y.map(b=>{const j=m[b],w=j?`${l(j.title)}${j.author?`(${l(j.author)})`:""}`:b.slice(0,8)+"…";return t.jsxs("a",{href:p(b),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(b))},style:{fontSize:"12px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:b,children:["→",w]},b)})}),a&&h&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}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 Ec({juan:e,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const l=nt(),p=n.trim(),d=f.useMemo(()=>p?e.sections.filter(c=>lo(c,p,!0,l)):e.sections,[e.sections,p,l]);return t.jsxs("div",{children:[t.jsx("div",{children:d.map((c,a)=>t.jsx(Rc,{section:c,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:p},a))}),d.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Lc({sections:e,onNavigate:n,inline:o}){const r=je(),{convert:s}=Y();return t.jsx(t.Fragment,{children:e.map((l,p)=>{const d=Oe(l.type);if(d==="page_header"&&!po(l))return null;if(d==="类")return t.jsxs(f.Fragment,{children:[t.jsx("h2",{children:o(s(l.title))}),l.content&&t.jsx("p",{children:o(s(l.content))})]},p);if(d==="书"||d==="诗"||d==="考证"||d==="注释"){const c=l.book_title?`《${l.book_title}》${l.n_juan!=null?so(l.n_juan)+"卷":""}`:l.title,a=o(s(c));return t.jsxs("section",{className:"bim-rd-entry",children:[t.jsx("h3",{children:l.work_id&&n?t.jsx("a",{href:r(l.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),n(l.work_id))},title:"查看作品",children:a}):a}),l.author_info&&t.jsx("p",{className:"bim-rd-sub",children:o(s(l.author_info))}),l.content&&l.content.split(/\n+/).map((u,x)=>t.jsx("p",{children:o(s(u))},x)),l.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),o(s(l.summary))]}),l.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),o(s(l.comment))]}),l.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),o(s(l.additional_comment))]})]},p)}return l.content?t.jsx("p",{children:o(s(l.content))},p):null})})}function Bc(e){return e.some(n=>{const o=Oe(n.type);return o==="书"||o==="诗"||o==="考证"||o==="注释"||o==="类"||(o==="序"||o==="结语")&&!!n.content||o==="page_header"&&po(n)})}function Nc({juan:e,rawText:n,positionLabel:o,index:r,searchQuery:s,onNavigate:l,transport:p,workLabelCache:d,prefs:c}){var W;const{convert:a}=Y(),u=nt(),[x,g]=f.useState("text"),h=s.trim(),y=(r==null?void 0:r.type)==="kaozhen",k=f.useCallback(I=>h?Wt(I,h,u):I,[h,u]),m=I=>io(I,{renderText:k,properNames:c.properNames}),v=f.useMemo(()=>h?e.sections.filter(I=>lo(I,h,y,u)):e.sections,[e.sections,h,y,u]),b=(I,R)=>R.filter(N=>Oe(N.type)===I).length,j=b("书",e.sections),w=b("诗",e.sections),S=b("考证",e.sections);let z="";y?z=h?`${b("考证",v)} / ${S} ${a("條")}`:`${S} ${a("條")}`:w>0?z=h?`${b("诗",v)} / ${w} 首`:`${w} 首`:j>0&&(z=h?`${b("书",v)} / ${j} ${a("部書")}`:`${j} ${a("部書")}`);const _=r!=null&&r.text_quality?pc(r.text_quality.grade):null,T=[];o&&T.push(o),z&&T.push(z),y&&(r!=null&&r.target_source)&&T.push(t.jsxs(t.Fragment,{children:[a("考證對象")," ",a(r.target_source)]})),_&&T.push(t.jsx("span",{title:Os[_],children:(W=r==null?void 0:r.text_quality)!=null&&W.source_note?t.jsxs(t.Fragment,{children:["底本 ",a(r.text_quality.source_note),"(",a(yn[_]),")"]}):t.jsxs(t.Fragment,{children:[a("文本質量")," ",a(yn[_])]})})),e.source_url&&T.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:a("原文來源")}));const B=!y&&Bc(e.sections),L=!!n&&(!B||c.readingMode==="paragraph"&&nn(n)),$=!y&&(B||!!n),F=y||!$?"entries":x;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:a(e.title)}),T.length>0&&t.jsx("p",{className:"bim-rd-meta",children:T.map((I,R)=>t.jsxs(f.Fragment,{children:[R>0&&t.jsx("span",{className:"bim-rd-dot"}),I]},R))}),$&&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":F==="text",onClick:()=>g("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":F==="entries",onClick:()=>g("entries"),children:a("條目")})]})]}),F==="text"&&t.jsx("article",{className:"bim-rd-prose",children:L?t.jsx(ro,{text:n,mode:c.readingMode,properNames:c.properNames,renderText:k,dropTitle:e.title}):t.jsx(Lc,{sections:e.sections,onNavigate:l,inline:m})}),F==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:y?t.jsx(Ec,{juan:e,searchQuery:s,onNavigate:l,transport:p,workLabelCache:d}):t.jsxs(t.Fragment,{children:[v.map((I,R)=>{const N=Oe(I.type);return N==="书"||N==="诗"||N==="考证"?t.jsx(zc,{section:I,onNavigate:l,highlightQuery:h},R):N==="类"?t.jsx($c,{section:I,highlightQuery:h},R):t.jsx(Ic,{section:I,highlightQuery:h},R)}),v.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function es(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 Wc(e){const n=es(e);return n.length>0?n[0]:null}function Ac(e){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:l,activeRawText:p,query:d,isKaozhen:c}=e,a=nt(),u=f.useRef(new Map),[x,g]=f.useState({}),[h,y]=f.useState({}),k=f.useCallback((v,b)=>{const j=b==null?void 0:b.title;j&&y(w=>w[v]===j?w:{...w,[v]:j})},[]);f.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:p}),k(s,l))},[s,l,p,k]),f.useEffect(()=>{u.current.clear(),g({}),y({})},[n]);const m=f.useCallback((v,b)=>{let j=0;if(v.juan)for(const w of v.juan.sections)lo(w,b,c,a)&&j++;return j===0&&v.rawText&&jc(v.rawText,b,a)&&(j=1),j},[c,a]);return f.useEffect(()=>{const v=d.trim();if(!v){g({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let b=!1;const j={},w=[];for(const B of r){const L=u.current.get(B);L?j[B]=m(L,v):(j[B]="loading",w.push(B))}g(j);const S=8;let z=0;const _=async()=>{var B;for(;z<w.length;){if(b)return;const L=z++,$=w[L];try{const[F,W]=await Promise.all([o.getCollatedJuan(n,$),((B=o.getCollatedJuanText)==null?void 0:B.call(o,n,$))??Promise.resolve(null)]),I={juan:F,rawText:W};if(u.current.set($,I),k($,F),b)return;g(R=>({...R,[$]:m(I,v)}))}catch{if(b)return;g(F=>({...F,[$]:0}))}}},T=Array.from({length:Math.min(S,w.length)},()=>_());return Promise.all(T),()=>{b=!0}},[d,n,o,r.join(","),m,a,k]),{matchStates:x,titles:h}}const uo=({index:e,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:l,className:p,style:d,title:c,subtitle:a,resolveImages:u,renderImageOverlay:x,imagePanel:g,allowVertical:h})=>{const[y,k]=f.useState(null),[m,v]=f.useState(!1),[b,j]=f.useState(null),[w,S]=f.useState(null),[z,_]=f.useState(null),[T,B]=f.useState(!1),[L,$]=f.useState(null),[F,W]=f.useState(""),I=f.useRef(new Map),R=f.useRef(0),N=s??w,O=f.useCallback(G=>{S(G),l==null||l(G)},[l]),E=e||y;f.useEffect(()=>{e&&(v(!1),j(null))},[e]),f.useEffect(()=>{if(e||!n||!(o!=null&&o.getCollatedEditionIndex))return;let G=!1;return v(!0),j(null),o.getCollatedEditionIndex(n).then(ee=>{G||(ee?k(ee):j("未找到整理本数据"))}).catch(ee=>{G||j(ee instanceof Error?ee.message:"加载失败")}).finally(()=>{G||v(!1)}),()=>{G=!0}},[e,n,o]),f.useEffect(()=>{if(E&&!N){const G=Wc(E);G&&O(G)}},[E,N,O]);const X=n||(E==null?void 0:E.work_id),C=f.useCallback(async G=>{var P;if(!X||!(o!=null&&o.getCollatedJuan))return;const ee=++R.current;B(!0),_(null),$(null);try{const[q,Z]=await Promise.all([o.getCollatedJuan(X,G),((P=o.getCollatedJuanText)==null?void 0:P.call(o,X,G))??Promise.resolve(null)]);if(ee!==R.current)return;_(q),$(Z)}catch{if(ee!==R.current)return;_(null),$(null)}finally{ee===R.current&&B(!1)}},[X,o]);f.useEffect(()=>{N&&C(N)},[N,C]);const A=G=>{O(G)};if(m)return t.jsx("div",{className:p,style:{...d,padding:"24px"},children:t.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(b)return t.jsx("div",{className:p,style:{...d,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:b});if(!E)return null;const K=E.type==="kaozhen",U=es(E);return t.jsx(Fc,{className:p,style:d,index:E,allFiles:U,isKaozhen:K,effectiveWorkId:X,transport:o,activeFile:N,handleSelectFile:A,juanData:z,juanRawText:L,juanLoading:T,searchQuery:F,setSearchQuery:W,onNavigate:r,workLabelCacheRef:I,reader:{title:c,subtitle:a,resolveImages:u,renderImageOverlay:x,imagePanel:g,allowVertical:h}})};function ts(e,n,o,r){var a,u,x,g;const s=(u=(a=n.juan_metadata)==null?void 0:a[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:kc(e)),d=((g=(x=n.files)==null?void 0:x.find(h=>h.filename===e))==null?void 0:g.title)??o[e];if(!d)return{position:l,label:l};const c=r(d);return{position:l,label:l===d||l===c?c:`${l} ${c}`}}function Mc(e,n,o,r,s){const l=c=>c==="loading"?"…":typeof c=="number"&&c>0?c:void 0,p=(c,a)=>({key:c,label:a??ts(c,e,r,s).label,hint:l(o[c]),disabled:o[c]===0}),d=(c,a)=>{var x;if(c.files.length===1&&!((x=c.children)!=null&&x.length))return p(c.files[0],s(c.label));const u=Sc(c,o);return{key:`group:${a}`,label:s(c.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:Qr(c),defaultExpanded:typeof u=="number"&&u>0,children:[...c.files.map(g=>p(g)),...(c.children??[]).map((g,h)=>d(g,`${a}.${h}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((c,a)=>d(c,`${a}`)):n.map(c=>p(c))}const Fc=({className:e,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:p,activeFile:d,handleSelectFile:c,juanData:a,juanRawText:u,juanLoading:x,searchQuery:g,setSearchQuery:h,onNavigate:y,workLabelCacheRef:k,reader:m})=>{const{convert:v}=Y(),[b,j]=Xn(),{matchStates:w,titles:S}=Ac({workId:l,transport:p,files:r,activeFile:d,activeJuan:a,activeRawText:u,query:g,isKaozhen:s}),z=Xr(m.resolveImages,d),_=f.useMemo(()=>Mc(o,r,w,S,v),[o,r,w,S,v]),T=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:g,onChange:$=>h($.target.value)}),B=s?"章":o.juan_metadata&&Object.values(o.juan_metadata).some($=>$.vol_label)?"冊":"卷",L=d?ts(d,o,S,v).position:void 0;return t.jsxs(Qn,{className:e,style:n,title:m.title??(o.title?v(o.title):void 0),subtitle:m.subtitle??v(s?"考證":"整理本"),toc:_,tocCaption:`目录 · ${r.length} ${v(B)}`,tocHeader:T,activeKey:d,onSelect:c,images:z.images,imagesLoading:z.loading,renderImageOverlay:m.renderImageOverlay,imagePanel:m.imagePanel,prefs:b,onPrefsChange:j,paragraphToggle:!s&&nn(u),allowVertical:m.allowVertical,children:[x?t.jsx(tt,{}):a?t.jsx(Nc,{juan:a,rawText:u,positionLabel:L,index:o,searchQuery:g,onNavigate:y,transport:p,workLabelCache:k,prefs:b},d??""):d?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:v("參考文獻")}),t.jsx("ol",{children:o.references.map(($,F)=>t.jsxs("li",{children:[$.url?t.jsx("a",{className:"bim-rd-link",href:$.url,target:"_blank",rel:"noopener noreferrer",children:$.title}):t.jsx("span",{children:$.title}),$.author&&t.jsxs("span",{children:[",",$.author]}),$.note&&t.jsxs("span",{children:["。",$.note]})]},F))})]})]})},Pc={bug:{label:"错误反馈",color:i("danger")},resource:{label:"资源建议",color:i("primary")},suggestion:{label:"功能建议",color:i("primary")},other:{label:"其他",color:i("desc-fg")}},Oc={label:"其他",color:i("desc-fg")},Hc={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")}},Dc={label:"待处理",color:i("warning")};function Gc(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 Vc(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 xo=({items:e,loading:n})=>{const o=je();return n?t.jsx(tt,{}):e.length===0?t.jsx("div",{style:Uc,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Pc[r.type]||Oc,l=Hc[r.status]||Dc,p=typeof window<"u"&&Vc(r.pageUrl,window.location.href);return t.jsxs("div",{style:Yc,children:[t.jsxs("div",{style:Kc,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...li,background:s.color},children:s.label}),t.jsx("span",{style:{...li,background:l.color},children:l.label})]}),t.jsx("span",{style:qc,children:Gc(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:Jc,children:[r.resourceId&&t.jsx("a",{href:o(r.resourceId),style:xn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(p?t.jsx("a",{href:r.pageUrl,style:xn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:xn,children:r.pageUrl}))]}),t.jsx("div",{style:Zc,children:r.content}),r.reply&&t.jsxs("div",{style:Xc,children:[t.jsx("div",{style:Qc,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Uc={textAlign:"center",padding:"40px 0",color:i("desc-fg"),fontSize:"14px"},Yc={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"16px"},Kc={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},li={fontSize:"12px",color:i("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},qc={fontSize:"12px",color:i("desc-fg")},Jc={fontSize:"12px",marginBottom:"6px"},xn={color:i("primary"),textDecoration:"none",borderBottom:`1px dashed ${i("primary")}`},Zc={fontSize:"14px",lineHeight:"1.6",color:i("fg"),whiteSpace:"pre-wrap"},Xc={marginTop:"12px",padding:"10px 12px",background:i("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:i("fg")},Qc={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:i("primary")},Tn=({transport:e,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const p=te(),[d,c]=f.useState(null),[a,u]=f.useState([]),[x,g]=f.useState("recommend"),[h,y]=f.useState([]),[k,m]=f.useState(!1),v=r??x,b=R=>{g(R),s==null||s(R)},[j,w]=f.useState(!0),[S,z]=f.useState(null),[_,T]=f.useState(null),[B,L]=f.useState(null);f.useEffect(()=>{let R=!1;if(e.getCounts)return e.getCounts().then(N=>{R||c({works:N.works,books:N.books,collections:N.collections})}).catch(()=>{}),()=>{R=!0}},[e]),f.useEffect(()=>{let R=!1;return(async()=>{if(o)return o;if(e.getRecommended)try{const O=await e.getRecommended();if(O!=null&&O.groups)return O.groups.flatMap(E=>E.items.map(X=>({...X,group:E.name})))}catch{}return[]})().then(async O=>{if(R)return;const E=O.filter(C=>C.id);if(E.length===0){w(!1);return}const X=await Promise.all(E.map(async C=>{if(C.type)return{id:C.id,title:C.title,type:C.type,author:C.author,dynasty:C.dynasty,role:C.role,edition:C.edition,has_text:C.has_text,has_image:C.has_image,has_collated:C.has_collated,subtype:C.subtype,primary_name:C.primary_name,group:C.group,fallbackDescription:C.description};try{let A=null;if(e.getEntry)A=await e.getEntry(C.id);else{const K=await e.getItem(C.id);K&&(A={id:C.id,title:K.title||C.id,type:K.type||"work"})}if(A)return{...A,group:C.group,fallbackDescription:C.description}}catch{}return{id:C.id,title:C.title,type:ae.extractType(C.id),group:C.group,fallbackDescription:C.description}}));R||(u(X.filter(C=>C!==null)),w(!1))}),()=>{R=!0}},[e,o]);const $=f.useRef(!1),F=f.useRef(!1),W=f.useRef(!1);f.useEffect(()=>{if(v!=="catalog"||$.current)return;const R=e.getCatalogProgress??e.getResourceProgress;if(!R)return;$.current=!0;let N=!1;return R.call(e).then(O=>{N||z(O)}).catch(()=>{$.current=!1}),()=>{N=!0}},[e,v]),f.useEffect(()=>{if(v!=="collection"||F.current||!e.getCollectionProgress)return;F.current=!0;let R=!1;return e.getCollectionProgress().then(N=>{R||T(N)}).catch(()=>{F.current=!1}),()=>{R=!0}},[e,v]),f.useEffect(()=>{if(v!=="site"||W.current||!e.getSiteProgress)return;W.current=!0;let R=!1;return e.getSiteProgress().then(N=>{R||L(N)}).catch(()=>{W.current=!1}),()=>{R=!0}},[e,v]),f.useEffect(()=>{if(!l||v!=="feedback")return;let R=!1;return m(!0),fetch(l).then(N=>N.json()).then(N=>{!R&&N.success&&y(N.items||[])}).catch(()=>{}).finally(()=>{R||m(!1)}),()=>{R=!0}},[l,v]);const I=R=>{switch(R){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color: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(vt,{label:p.home.recommendTab,active:v==="recommend",onClick:()=>b("recommend")}),t.jsx(vt,{label:p.home.catalogTab,active:v==="catalog",onClick:()=>b("catalog")}),t.jsx(vt,{label:p.home.collectionTab,active:v==="collection",onClick:()=>b("collection")}),t.jsx(vt,{label:p.home.siteTab,active:v==="site",onClick:()=>b("site")}),l&&t.jsx(vt,{label:p.home.feedbackTab,active:v==="feedback",onClick:()=>b("feedback")})]}),v==="recommend"&&t.jsx(ed,{recommended:a,loading:j,onNavigate:n,getIcon:I,t:p}),v==="catalog"&&t.jsx(ai,{progress:S,t:p,onNavigate:n}),v==="collection"&&t.jsx(ai,{progress:_,t:p,onNavigate:n}),v==="site"&&t.jsx(nd,{progress:B,t:p,totalWorks:(d==null?void 0:d.works)??0}),v==="feedback"&&l&&t.jsx(xo,{items:h,loading:k})]})})},vt=({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}),ed=({recommended:e,loading:n,onNavigate:o,getIcon:r,t:s})=>{const l=je();if(n)return t.jsx(tt,{});if(e.length===0)return null;const p=new Map;for(const d of e){const c=d.group||s.home.recommendedBrowse;p.has(c)||p.set(c,[]),p.get(c).push(d)}return t.jsx(t.Fragment,{children:Array.from(p.entries()).map(([d,c])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:d}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(a=>{const u=a.dynasty||a.author?`${a.dynasty?`〔${a.dynasty}〕`:""}${a.author||""}`:a.fallbackDescription;return t.jsxs("a",{href:l(a.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),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)})})]},d))})},ai=({progress:e,t:n,onNavigate:o})=>{if(!e)return t.jsx(tt,{});const r=[...e.resources].sort((d,c)=>d.priority-c.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},p={in_progress:i("progress-active"),done:i("progress-done"),todo:i("progress-todo")};return t.jsx("div",{children:s.map(d=>{const c=r.filter(a=>a.status===d);return c.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:p[d]}}),l[d]," (",c.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(a=>t.jsx(td,{item:a,t:n,statusColor:p[d],onNavigate:o},a.id))})]},d)})})},td=({item:e,t:n,statusColor:o,onNavigate:r})=>{const s=je(),l=e.total>0?Math.round(e.imported/e.total*100):0,p=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${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 d=e.edition?`${e.name}·${e.edition}`:e.name,c=e.collection_id||e.work_id;return c&&r?t.jsx("a",{href:s(c),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},onMouseEnter:a=>a.currentTarget.style.borderBottomStyle="solid",onMouseLeave:a=>a.currentTarget.style.borderBottomStyle="dashed",children:d}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:d}):d})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:i("widget-border"),color:i("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:p})]}),t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Tt(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})]})},nd=({progress:e,t:n,totalWorks:o})=>{if(!e)return t.jsx(tt,{});const r=[...e.resources].sort((c,a)=>c.priority-a.priority),s=r.filter(c=>c.imported>0),l=r.filter(c=>c.imported===0),p=s.reduce((c,a)=>Math.max(c,a.imported),0),d=o>0?Math.round(p/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:p.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",d,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color: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(ci,{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(ci,{item:c,t:n,totalWorks:o},c.id))})]})]})},ci=({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})]})},di="(max-width: 768px)";function od(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(di).matches);return f.useEffect(()=>{const o=window.matchMedia(di),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),e}const id=({transport:e,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var N;const l=te(),{convert:p}=Y(),d=od(),[c,a]=f.useState(null),[u,x]=f.useState(null),[g,h]=f.useState(!1),[y,k]=f.useState("detail"),[m,v]=f.useState([]),[b,j]=f.useState(!1),[w,S]=f.useState(null),[z,_]=f.useState(!1),T=f.useCallback(async O=>{if(!e.getCollatedEditionIndex){S(null);return}_(!0);try{const E=await e.getCollatedEditionIndex(O);S(E)}catch{S(null)}finally{_(!1)}},[e]),B=f.useCallback(async O=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){v([]);return}j(!0);try{if(e.getCollectionCatalogs){const E=await e.getCollectionCatalogs(O);v(E||[])}else if(e.getCollectionCatalog){const E=await e.getCollectionCatalog(O);v(E?[{resource_id:"",data:E}]:[])}}catch{v([])}finally{j(!1)}},[e]),L=f.useCallback(async O=>{if(o){o(O);return}a(O),x(null),v([]),S(null),k("detail"),h(!0);try{const E=await e.getItem(O.id);E&&(x(E),E.type==="collection"?B(O.id):E.type==="work"&&E.has_collated&&T(O.id))}catch(E){console.error("加载详情失败:",E)}finally{h(!1)}},[e,o,B,T]),$=f.useCallback(async O=>{x(null),v([]),S(null),k("detail"),h(!0);try{const E=await e.getItem(O);E&&(x(E),a({id:O,title:E.title||O,type:E.type||"book"}),E.type==="collection"?B(O):E.type==="work"&&E.has_collated&&T(O))}catch(E){console.error("导航失败:",E)}finally{h(!1)}},[e,B,T]),F=(u==null?void 0:u.type)==="collection"&&(m.length>0||b)||(u==null?void 0:u.type)==="work"&&(w||z),W=d&&(g||u),I=f.useCallback(()=>{a(null),x(null),v([]),S(null),k("detail")},[]),R=t.jsx(t.Fragment,{children:g?t.jsx(tt,{}):u?t.jsxs(t.Fragment,{children:[(F||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${i("widget-border")}`,padding:d?"0 12px":"0 48px",background:i("input-bg"),flexShrink:0,overflowX:d?"auto":void 0},children:[F&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>k("detail"),style:Ht(y==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&b&&m.length===0&&t.jsxs("button",{onClick:()=>{},style:Ht(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&m.map(O=>t.jsx("button",{onClick:()=>k(`catalog:${O.resource_id}`),style:Ht(y===`catalog:${O.resource_id}`),children:O.short_name?`${p(O.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},O.resource_id)),u.type==="work"&&(w||z)&&t.jsxs("button",{onClick:()=>k("collated"),style:Ht(y==="collated"),children:[l.detailTab.collatedEdition,z&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:d?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:y==="detail"?t.jsx(Hn,{data:u,transport:e,onNavigate:$}):y.startsWith("catalog:")?t.jsx(Dn,{data:(N=m.find(O=>`catalog:${O.resource_id}`===y))==null?void 0:N.data,onNavigate:$}):y==="collated"?t.jsx(uo,{index:w||void 0,workId:u.id,transport:e,onNavigate:$}):null})]}):t.jsx(Tn,{transport:e,onNavigate:$,recommendedIds:r})});return d?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:W?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:I,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:R})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(vn,{transport:e,onEntryClick:L,hideModeIndicator:n}),!u&&t.jsx(Tn,{transport:e,onNavigate:$,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(vn,{transport:e,onEntryClick:L,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:i("bg"),display:"flex",flexDirection:"column"},children:R})]})};function Ht(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 Ue(e){return e.replace(/\.md$/,"")}function rd(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 pi={padding:24,color:i("desc-fg")},Rn=({index:e,bookId:n,transport:o,activeChapter:r,onChapterChange:s,workKey:l,versions:p,onVersionChange:d,title:c,subtitle:a,resolveImages:u,renderImageOverlay:x,imagePanel:g,allowVertical:h,className:y,style:k})=>{const[m,v]=f.useState(e??null),[b,j]=f.useState(!1),[w,S]=f.useState(null),z=r!==void 0?r:w,_=f.useCallback(A=>{s?s(A):S(A)},[s]),[T,B]=f.useState(null),[L,$]=f.useState(!1);f.useEffect(()=>{e&&v(e)},[e]),f.useEffect(()=>{if(e)return;v(null),j(!1);const A=l!==void 0?o.getWorkFullTextIndex?()=>o.getWorkFullTextIndex(n,l):null:o.getBookFullTextIndex?()=>o.getBookFullTextIndex(n):null;if(!n||!A){j(!0);return}let K=!1;return Promise.resolve().then(A).then(U=>{K||(U?v(U):j(!0))}).catch(()=>{K||j(!0)}),()=>{K=!0}},[n,o,e,l]),f.useEffect(()=>{if(!m||m.chapters.length===0)return;const A=Ue(m.chapters[0].file);if(!z){_(A);return}const K=Ue(z);m.chapters.some(G=>Ue(G.file)===K)||_(A)},[m,z,_]);const F=f.useMemo(()=>{if(!m||!z)return null;const A=Ue(z);return m.chapters.find(K=>Ue(K.file)===A)??null},[m,z]);f.useEffect(()=>{if(!n||!F)return;const A=l!==void 0?o.getWorkFullTextChapter?U=>o.getWorkFullTextChapter(n,l,U):null:o.getBookFullTextChapter?U=>o.getBookFullTextChapter(n,U):null;if(!A)return;let K=!1;return $(!0),B(null),Promise.resolve(F.file).then(A).then(U=>{K||B(U)}).catch(()=>{K||B(null)}).finally(()=>{K||$(!1)}),()=>{K=!0}},[n,F,o,l]);const W=Xr(u,F?Ue(F.file):null),[I,R]=Xn(),{convert:N}=Y(),O=p&&p.length>1&&d?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:A=>d(A.target.value),children:p.map(A=>t.jsx("option",{value:A.key,children:rd(A)},A.key))})]}):null;if(!m)return t.jsxs("div",{style:pi,children:[O&&t.jsx("div",{style:{marginBottom:12},children:O}),b?"无法加载全文目录":"加载全文目录…"]});if(m.chapters.length===0)return t.jsxs("div",{style:pi,children:[O&&t.jsx("div",{style:{marginBottom:12},children:O}),"全文目录为空"]});const E=m.chapters.map(A=>({key:Ue(A.file),label:N(A.title)})),X=Or(m)||wn(m),C=T?T.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(Qn,{title:c??N(m.version_label),subtitle:a??"全文",toc:E,tocCaption:`目录 · ${m.chapters.length} ${m.chapters.length>1?"卷":"篇"}`,activeKey:z?Ue(z):null,onSelect:_,images:W.images,imagesLoading:W.loading,renderImageOverlay:x,imagePanel:g,prefs:I,onPrefsChange:R,paragraphToggle:nn(C),allowVertical:h,className:y,style:k,children:[F&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:N(F.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:m.source.url,target:"_blank",rel:"noreferrer",children:N(m.source.name)}),m.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),m.source.license]}),O&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),O]})]})]}),L&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!L&&C!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(ro,{text:C,mode:I.readingMode,tables:X,gujiMarkdown:wn(m),properNames:I.properNames})}),!L&&!T&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},sd=({data:e,onNavigate:n,className:o,style:r})=>{var u;const s=te(),{convert:l}=Y(),[p,d]=f.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[c,a]=f.useState(null);return t.jsxs("div",{className: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(x=>t.jsx(ld,{division:x,expanded:p===x.name,onToggle:()=>d(p===x.name?null:x.name),expandedCat:c,onCatToggle:g=>a(c===g?null:g),onNavigate:n},x.name))})]})},ld=({division:e,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:p}=Y(),d=e.categories.reduce((c,a)=>{const u=a.stats||{zhulu:0,cunmu:0};return c+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${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:p(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg")},children:[e.categories.length," 類 · ",d," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(c=>{const a=`${e.name}/${c.name}`;return t.jsx(ad,{category:c,expanded:r===a,onToggle:()=>s(a),onNavigate:l},c.name)})})]})},ad=({category:e,expanded:n,onToggle:o,onNavigate:r})=>{var c,a,u,x;const{convert:s}=Y(),l=((c=e.books)==null?void 0:c.zhulu)||[],p=((a=e.books)==null?void 0:a.cunmu)||[],d=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((x=e.stats)==null?void 0:x.cunmu)||p.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick: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:[d," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||p.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(ui,{label:"著錄",books:l,onNavigate:r}),p.length>0&&t.jsx(ui,{label:"存目",books:p,onNavigate:r})]})]})},ui=({label:e,books:n,onNavigate:o})=>{const{convert:r}=Y(),s=je(),[l,p]=f.useState(n.length<=20),d=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:d.map((c,a)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color: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:()=>p(!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," 條"]})]})},Ee=({title:e,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const l=te();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:dd,children:"AI"}),n&&t.jsx("button",{onClick:n,style:cd,children:l.action.save})]})]}),s]})},cd={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},dd={padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},_e=({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"}})]}),Ze=({value:e,onChange:n,placeholder:o})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Yt=({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 pd(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Dt=({value:e,onChange:n,label:o})=>{const[r,s]=f.useState(!1),l=f.useRef(null),p=pd(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&p?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:xi,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:p.name}),t.jsx(Yt,{children:p.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:xi,children:o}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:d=>n(d.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},xi={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500};function ud(e){switch(e){case"url":return i("source-url");case"bookID":return i("source-bookid");default:return i("desc-fg")}}function xd(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const ns=({items:e,onChange:n,onOpenEntityPicker:o})=>{const r=te(),[s,l]=f.useState(null),p=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},d=x=>{n(e.filter((g,h)=>h!==x)),s===x&&l(null)},c=(x,g,h)=>{const y=[...e];y[x]={...y[x],[g]:h},n(y)},a=(x,g)=>{const h=[...e];h[x]={...h[x],type:g,id:"",name:""},n(h),g==="bookID"&&o&&o(y=>{const k=[...e];k[x]={...k[x],id:y.id,name:y.title,type:"bookID"},n(k)})},u=x=>{o&&o(g=>{const h=[...e];h[x]={...h[x],id:g.id,name:g.title,type:"bookID"},n(h)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((x,g)=>t.jsxs("div",{style:{border:`1px solid ${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===g?null:g),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:i("fg")},children:x.name||`${r.editor.sourcePlaceholder} ${g+1}`}),x.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:ud(x.type),color:i("on-color-fg"),borderRadius:"3px",fontWeight:500},children:xd(x.type)}),t.jsx("button",{onClick:h=>{h.stopPropagation(),d(g)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===g&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&t.jsxs("div",{children:[t.jsx("label",{style:De,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>a(g,"bookID"),style:{...fi,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(g,"url"),style:{...fi,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})]})]})]}),x.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:De,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const h=[...e];h[g]={...h[g],type:"",id:"",name:""},n(h)},style:gi,children:r.action.changeType})]}),x.id&&x.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:x.name}),t.jsx("code",{style:{fontSize:"11px",background:i("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),t.jsx("button",{onClick:()=>u(g),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(g),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})]})]})}),x.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:De,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const h=[...e];h[g]={...h[g],type:"",id:"",name:""},n(h)},style:gi,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:x.name,onChange:h=>c(g,"name",h.target.value),placeholder:r.editor.sourceNamePlaceholder,style:rt})]}),t.jsxs("div",{children:[t.jsx("label",{style:De,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:x.id,onChange:h=>c(g,"id",h.target.value),placeholder:"https://...",style:rt})]})]}),x.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:{...De,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:De,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:x.details,onChange:h=>c(g,"details",h.target.value),placeholder:r.editor.detailsPlaceholder,style:rt})]}),t.jsxs("div",{children:[t.jsx("label",{style:De,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:x.position,onChange:h=>c(g,"position",h.target.value),placeholder:"如: 卷三, p.52",style:rt})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:De,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:x.version,onChange:h=>c(g,"version",h.target.value),placeholder:"如: v1.0, 2024-01",style:rt})]}),t.jsxs("div",{children:[t.jsx("label",{style:De,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:x.processor_version,onChange:h=>c(g,"processor_version",h.target.value),placeholder:"如: v0.1",style:rt})]})]})]})]})})]},g)),t.jsxs("button",{onClick:p,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})]})]})},De={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},rt={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"},fi={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"},gi={background:"transparent",border:"none",color:i("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function os(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 is(e){return!e||e.length===0?"":JSON.stringify(e)}const rs=({entityType:e,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:p,childWorks:d,childCollections:c,containedBooks:a,siblingBooks:u,onLinkEntity:x,onUnlinkEntity:g,onViewEntity:h,onCreateAndLink:y,onSaveRelations:k})=>{const m=te();return t.jsxs("div",{style:{background: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:m.section.relations})]}),k&&t.jsx("button",{onClick:k,style:fd,children:m.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(kt,{direction:"up",title:m.relation.belongsToWork,entity:l,onView:h,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>y("workId","work",{title:o}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),t.jsx(kt,{direction:"up",title:m.relation.containedInCollection,entity:p,onView:h,onUnlink:()=>g("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>y("collectionId","collection",{title:o}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),l&&u&&u.length>0&&t.jsx(st,{direction:"horizontal",title:`${m.relation.siblingVersions} (${u.length})`,entities:u,onView:h,onAdd:()=>y("siblingBook","book",{workId:l.id}),addLabel:m.relation.addVersionForWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(kt,{direction:"up",title:m.relation.parentWork,entity:r,onView:h,onUnlink:()=>g("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>y("parentWorkId","work"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),d&&d.length>0&&t.jsx(st,{direction:"down",title:`${m.relation.childWorks} (${d.length})`,entities:d,onView:h,onAdd:()=>y("childWork","work",{parentWorkId:n}),addLabel:m.action.addSubWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),c&&c.length>0&&t.jsx(st,{direction:"down",title:`${m.relation.collectionImpl} (${c.length})`,entities:c,onView:h,onAdd:()=>y("childCollection","collection",{workId:n}),addLabel:m.action.addCollectionImpl,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),t.jsx(st,{direction:"down",title:`${m.relation.allVersions} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:h,onAdd:()=>y("childBook","book",{workId:n}),addLabel:m.action.addVersion,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(kt,{direction:"up",title:m.relation.correspondingWork,entity:l,onView:h,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>y("workId","work",{title:o}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),t.jsx(kt,{direction:"up",title:m.relation.parentCollection,entity:s,onView:h,onUnlink:()=>g("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>y("parentCollectionId","collection"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),t.jsx(st,{direction:"down",title:`${m.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:h,onAdd:()=>y("childCollection","collection",{parentCollectionId:n}),addLabel:m.action.addSubCollection,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),t.jsx(st,{direction:"down",title:`${m.relation.containedBooks} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:h,onAdd:()=>y("childBook","book",{collectionId:n}),addLabel:m.action.addBook,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]})]})]})},kt=({direction:e,title:n,entity:o,onView:r,onUnlink:s,onLink:l,onCreate:p,linkLabel:d,createLabel:c,notLinkedLabel:a,viewLabel:u,unlinkLabel:x})=>{const g=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),h=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:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:h}),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:ss(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(hi,{onClick:()=>r(o),title:u,children:"👁️"}),t.jsx(hi,{onClick:s,title:x,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(En,{onClick:l,children:d}),t.jsx(En,{onClick:p,primary:!0,children:c})]})]})},st=({direction:e,title:n,entities:o,onView:r,onAdd:s,addLabel:l,noneLabel:p,expandMoreLabel:d})=>{const[c,a]=f.useState(!1),u=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),x=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",g=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:x}),t.jsx("span",{children:n})]}),o.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(h=>t.jsxs("div",{onClick:()=>r(h),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:i("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:ss(h.type)}),t.jsx("span",{children:h.title})]},h.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:[d," (",o.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:p}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(En,{onClick:s,primary:!0,children:["+ ",l]})})]})},hi=({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}),En=({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 ss(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const fd={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},ls=({isOpen:e,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:l,searchResults:p,onSearch:d,isLoading:c,excludeId:a})=>{const[u,x]=f.useState(""),g=a?p.filter(m=>m.id!==a):p;f.useEffect(()=>{e&&(x(""),d(""))},[e]);const h=m=>{x(m),d(m)};if(!e)return null;const y=n==="work"?"作品":n==="book"?"书籍":"丛编",k=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:gd,children:t.jsxs("div",{style:hd,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:md,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:m=>h(m.target.value),placeholder:`搜索${y}名称或 ID...`,autoFocus:!0,style:bd})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:fn,children:"搜索中..."}):g.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(m=>t.jsxs("div",{onClick:()=>r(m),style:yd,children:[t.jsx("span",{style:{fontSize:"16px"},children:k}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[m.title,m.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:m.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[m.id,m.author&&` · ${m.author}`,m.dynasty&&` · ${m.dynasty}`]})]})]},m.id))}):u?t.jsxs("div",{style:fn,children:["未找到匹配的",y]}):t.jsxs("div",{style:fn,children:["输入关键词搜索",y]})}),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:jd,children:["创建新",y,"并关联"]})]})]})})},gd={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},hd={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")},md={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},bd={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"},yd={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:i("primary-soft")},fn={padding:"20px",textAlign:"center",color:i("desc-fg")},jd={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},mi={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},vd={work:"📜",book:"📖",collection:"📚",entity:"👤"},as=({isOpen:e,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:l})=>{const[p,d]=f.useState(""),c=f.useRef(null);f.useEffect(()=>{e&&(d((r==null?void 0:r.title)||""),setTimeout(()=>{var g,h;(g=c.current)==null||g.focus(),(h=c.current)==null||h.select()},100))},[e,r==null?void 0:r.title]);const a=g=>{g.key==="Enter"&&p.trim()?u():g.key==="Escape"&&l()},u=()=>{p.trim()&&s(p.trim(),{...r,title:p.trim()})};if(!e)return null;const x=()=>{switch(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`创建新${mi[n]}`}};return t.jsx("div",{style:kd,onClick:g=>{g.target===g.currentTarget&&l()},children:t.jsxs("div",{style:Sd,onClick:g=>g.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:vd[n]}),t.jsx("span",{children:x()})]}),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:p,onChange:g=>d(g.target.value),onKeyDown:a,placeholder:`请输入${mi[n]}名称...`,style:wd})]}),((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:_d,children:"取消"}),t.jsx("button",{onClick:u,disabled:!p.trim(),style:{...zd,opacity:p.trim()?1:.6,cursor:p.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},kd={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Sd={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")},wd={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"},_d={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},zd={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg")};function $d(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function cs(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Cd(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 ds=({isOpen:e,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:p,onSelect:d,onCancel:c,onCreate:a,onSearch:u})=>{const[x,g]=f.useState(""),[h,y]=f.useState([]),[k,m]=f.useState(!1),[v,b]=f.useState("recent");f.useEffect(()=>{e&&(g(""),y([]),b(r.length>0?"recent":"search"))},[e,r.length]),f.useEffect(()=>{if(!x.trim()){y([]);return}const T=setTimeout(async()=>{m(!0);try{y(await u(x,o))}catch{y([])}finally{m(!1)}},300);return()=>clearTimeout(T)},[x,o,u]);const j=f.useCallback(T=>{g(T.target.value),T.target.value.trim()&&b("search")},[]),w=f.useCallback(T=>s?T.filter(B=>B.id!==s):T,[s]);if(!e)return null;const S=n||(o==="all"?"选择实体":`选择${cs(o)}`),z=w(r),_=w(h);return t.jsx("div",{style:Td,children:t.jsxs("div",{style:Rd,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:S}),t.jsx("button",{onClick:c,style:Ed,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:x,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Ld}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),k&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),z.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsxs(bi,{active:v==="recent",onClick:()=>b("recent"),children:["最近使用 (",z.length,")"]}),t.jsxs(bi,{active:v==="search",onClick:()=>b("search"),children:["搜索结果 ",_.length>0&&`(${_.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:v==="recent"&&z.length>0?t.jsx(yi,{entities:z,onSelect:d}):x.trim()?k?t.jsx(gn,{message:"搜索中..."}):_.length>0?t.jsx(yi,{entities:_,onSelect:d}):t.jsx(gn,{message:"未找到匹配的结果"}):t.jsx(gn,{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:Bd,children:p||"创建新实体"})]})]})})},bi=({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}),yi=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(o=>t.jsx(Id,{entity:o,onClick:()=>n(o)},o.id))}),Id=({entity:e,onClick:n})=>{const[o,r]=f.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:$d(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:Cd(e.type),color:i("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:cs(e.type)})]})},gn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:e}),Td={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Rd={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")},Ed={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Ld={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"},Bd={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Nd={work:i("editor-type-work"),collection:i("editor-type-collection"),book:i("editor-type-book"),entity:i("editor-type-entity")},Wd={work:"📜",collection:"📚",book:"📖",entity:"👤"},ps=({data:e,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:l,onDelete:p,onAskAI:d,renderSectionActions:c,onDownloadResource:a,downloadStatuses:u,relations:x,onRelationsChange:g})=>{var ce;const h=te(),[y,k]=f.useState(!1),[m,v]=f.useState("work"),[b,j]=f.useState(""),[w,S]=f.useState(""),[z,_]=f.useState([]),[T,B]=f.useState(!1),[L,$]=f.useState(!1),[F,W]=f.useState("work"),[I,R]=f.useState(""),[N,O]=f.useState(),[E,X]=f.useState(!1),[C,A]=f.useState(null),[K,U]=f.useState([]);f.useRef(null);const G=e.type,ee=G==="work",P=G==="collection",q=G==="book",Z=f.useCallback((M,oe)=>{n({...e,[M]:oe})},[e,n]),V=f.useCallback((M,oe)=>{j(M),v(oe),S(h.editor.selectToLink+h.indexType[oe]),_([]),k(!0)},[h]),se=f.useCallback(M=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,M)},[r,e.id]),de=f.useCallback(M=>{s==null||s(M.id,M.type)},[s]),H=f.useCallback((M,oe,ne)=>{const he={...ne,author:(ne==null?void 0:ne.author)||e.author,dynasty:ne==null?void 0:ne.dynasty};W(oe),R(M),O(he),$(!0)},[e.author]),re=f.useCallback((M,oe)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,I,{type:F,title:M,inheritData:oe}),$(!1)},[r,e.id,I,F]),ie=f.useCallback(M=>{if(!M.trim()){_([]);return}B(!0),r!=null&&r.searchEntities&&r.searchEntities(M,m).then(oe=>{_(oe),B(!1)}).catch(()=>{_([]),B(!1)})},[r,m]),pe=f.useCallback(M=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,b,M.id),k(!1)},[r,e.id,b]),fe=f.useCallback(()=>{o()},[o]),ye=f.useCallback(M=>{A(()=>M),X(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(U).catch(()=>{})},[r]),Ce=f.useCallback((M,oe)=>r!=null&&r.searchEntities?r.searchEntities(M,oe==="all"?void 0:oe):Promise.resolve([]),[r]),Q=f.useCallback(M=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(M),U(oe=>[M,...oe.filter(ne=>ne.id!==M.id)].slice(0,10)),C==null||C(M),X(!1),A(null)},[r,C]);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:Wd[G]}),t.jsx("span",{children:e.title||h.editor.untitled}),t.jsx(Yt,{children:e.id}),t.jsx(Yt,{color:Nd[G],children:h.indexType[G]})]})}),t.jsx(Ee,{title:h.section.basicInfo,onSave:o,onAskAI:d?()=>d("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(Dt,{label:ee?h.editor.workTitle:P?h.editor.collectionTitle:h.editor.bookTitle,value:e.title,onChange:M=>Z("title",M)}),q&&t.jsx(Dt,{label:h.editor.belongsToWork,value:e.workName||"",onChange:M=>Z("workName",M)}),t.jsx(_e,{label:h.editor.authorLabel,value:e.author||"",onChange:M=>Z("author",M)}),t.jsx(_e,{label:h.editor.publicationYearLabel,value:e.publicationYear||"",onChange:M=>Z("publicationYear",M)}),(q||P)&&t.jsx(Dt,{label:h.editor.containedIn,value:e.collection||"",onChange:M=>Z("collection",M)}),(q||P)&&t.jsx(_e,{label:h.editor.holderLabel,value:e.holder||"",onChange:M=>Z("holder",M)}),(q||P)&&t.jsx(_e,{label:q?h.editor.pageLabel:h.editor.volumeLabel,value:e.pages||"",onChange:M=>Z("pages",M)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(_e,{label:h.editor.firstImageLabel,value:e.firstImage||"",onChange:M=>Z("firstImage",M)})})]})}),t.jsx(Ee,{title:h.section.description,onSave:o,onAskAI:d?()=>d("介绍"):void 0,children:t.jsx(Ze,{value:e.description||"",onChange:M=>Z("description",M),placeholder:h.editor.descriptionPlaceholder})}),(((ce=e.additional_works)==null?void 0:ce.length)||0)>0&&t.jsx(Ee,{title:h.section.additionalWorks,onSave:o,children:t.jsx(Ad,{items:e.additional_works||[],onChange:M=>Z("additional_works",M)})}),t.jsx(Ee,{title:h.section.indexedBy,onSave:o,onAskAI:d?()=>d("收录于"):void 0,children:t.jsx(Md,{items:e.indexed_by||[],onChange:M=>Z("indexed_by",M)})}),t.jsx(Ee,{title:h.section.emendatedBy,onSave:o,onAskAI:d?()=>d("考证"):void 0,children:t.jsx(Fd,{items:e.emendated_by||[],onChange:M=>Z("emendated_by",M)})}),t.jsx(Ee,{title:h.section.textResources,onSave:o,onAskAI:d?()=>d("资源"):void 0,children:t.jsx(jn,{items:e.resources||[],onChange:M=>Z("resources",M),onDownload:a,downloadStatuses:u,filterType:"text"})}),t.jsx(Ee,{title:h.section.imageResources,onSave:o,children:t.jsx(jn,{items:e.resources||[],onChange:M=>Z("resources",M),onDownload:a,downloadStatuses:u,filterType:"image"})}),t.jsx(Ee,{title:h.section.sources,onSave:o,onAskAI:d?()=>d("资料来源"):void 0,children:t.jsx(ns,{items:os(e.sources||""),onChange:M=>Z("sources",is(M)),onOpenEntityPicker:ye})}),(q||P)&&t.jsx(Ee,{title:h.section.provenance,onSave:o,onAskAI:d?()=>d("收藏历史"):void 0,children:t.jsx(Ze,{value:e.provenance||"",onChange:M=>Z("provenance",M),placeholder:h.editor.provenancePlaceholder})}),q&&t.jsx(Ee,{title:h.section.otherEditions,onSave:o,onAskAI:d?()=>d("其他版本"):void 0,children:t.jsx(Ze,{value:e.otherEditions||"",onChange:M=>Z("otherEditions",M),placeholder:h.editor.otherEditionsPlaceholder})}),t.jsx(rs,{entityType:G,entityId:e.id,entityTitle:e.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:V,onUnlinkEntity:se,onViewEntity:de,onCreateAndLink:H,onSaveRelations:fe}),l&&p&&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:h.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"12px"},children:h.editor.dangerZoneDesc}),t.jsx("button",{onClick:p,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("danger")}`,borderRadius:"4px",background:"transparent",color:i("danger"),cursor:"pointer"},children:h.editor.deleteEntity})]}),t.jsx(ls,{isOpen:y,entityType:m,title:w,onSelect:pe,onCancel:()=>k(!1),onCreate:()=>{k(!1),H(b,m)},searchResults:z,onSearch:ie,isLoading:T,excludeId:e.id}),t.jsx(as,{isOpen:L,entityType:F,relationField:I,inheritData:N,onConfirm:re,onCancel:()=>$(!1)}),t.jsx(ds,{isOpen:E,title:h.action.selectBookOrWork,filterType:"all",recentEntities:K,excludeId:e.id,onSelect:Q,onCancel:()=>{X(!1),A(null)},onSearch:Ce})]})};function Ad({items:e,onChange:n}){const o=te(),r=(p,d,c)=>{const a=e.map((u,x)=>x===p?{...u,[d]:c}:u);n(a)},s=p=>n(e.filter((d,c)=>c!==p)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((p,d)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(_e,{label:o.editor.bookNameLabel,value:p.book_title,onChange:c=>r(d,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(_e,{label:o.label.juanCount,value:p.n_juan!=null?String(p.n_juan):"",onChange:c=>r(d,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(d),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("muted"),marginTop:"18px"},children:"✕"})]},d)),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 us({items:e,onChange:n,showMeta:o,addLabel:r}){const s=te(),[l,p]=f.useState(null),d=(u,x,g)=>{const h=e.map((y,k)=>k===u?{...y,[x]:g||void 0}:y);n(h)},c=u=>{n(e.filter((x,g)=>g!==u)),l===u&&p(null)},a=()=>{n([...e,{source:""}]),p(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,x)=>{const g=l===x;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?`color-mix(in srgb, ${i("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>p(g?null:x),children:[t.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:h=>{h.stopPropagation(),c(x)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${i("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:i("muted")},children:"✕"})]}),!g&&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]}),g&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(_e,{label:s.label.sourceName,value:u.source,onChange:h=>d(x,"source",h)}),t.jsx(_e,{label:s.label.sourceBid,value:u.source_bid||"",onChange:h=>d(x,"source_bid",h)})]}),o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(_e,{label:s.label.titleInfo,value:u.title_info||"",onChange:h=>d(x,"title_info",h)}),t.jsx(_e,{label:s.label.authorInfo,value:u.author_info||"",onChange:h=>d(x,"author_info",h)})]}),t.jsx(_e,{label:s.label.edition,value:u.edition||"",onChange:h=>d(x,"edition",h)})]}),t.jsx(Ze,{value:u.summary||"",onChange:h=>d(x,"summary",h),placeholder:s.editor.summaryPlaceholder}),t.jsx(Ze,{value:u.comment||"",onChange:h=>d(x,"comment",h),placeholder:s.editor.commentPlaceholder}),t.jsx(Ze,{value:u.additional_comment||"",onChange:h=>d(x,"additional_comment",h),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),t.jsx("button",{onClick:a,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Md({items:e,onChange:n}){const o=te();return t.jsx(us,{items:e,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function Fd({items:e,onChange:n}){const o=te();return t.jsx(us,{items:e,onChange:n,addLabel:o.action.addEmendatedBy})}function xs(e){var d,c,a,u,x,g,h;const n=((c=(d=e.authors)==null?void 0:d[0])==null?void 0:c.name)||"",o=((a=e.publication_info)==null?void 0:a.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(x=e.page_count)!=null&&x.number?String(e.page_count.number):((g=e.page_count)==null?void 0:g.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",p={id:e.id,title:e.title,type:e.type,author:n,publicationYear: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 y=e;if(Array.isArray(y.related_works)){const k=y.related_works.find(m=>m.relation==="part_of");k&&(p.parentWorkId=k.id,p.parentWorkName=k.title)}}if(e.type==="book"){const y=e;p.workId=y.work_id,Array.isArray(y.contained_in)&&y.contained_in.length>0&&(p.collectionId=(h=y.contained_in[0])==null?void 0:h.id)}return p}function Pd(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 Od=e=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:l,onChange:p,onSave:d,onDelete:c,onNavigate:a,renderLink:u,onAskAI:x,renderSectionActions:g,onDownloadResource:h,downloadStatuses:y,relations:k,onRelationsChange:m,headerExtra:v,className:b,style:j}=e;te();const[w,S]=f.useState(s),z=l?s:w;f.useEffect(()=>{s!==w&&S(s)},[s]);const _=f.useCallback(()=>{const I=z==="view"?"edit":"view";l?l(I):S(I)},[z,l]),[T,B]=f.useState(null);f.useEffect(()=>{o&&r&&r.getItem(o).then(I=>{I&&B(I)})},[o,r]);const L=n||T,$=f.useMemo(()=>L?xs(L):null,[L]),F=l||!n?t.jsx("button",{onClick:_,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:z==="edit"?i("accent-bg"):"transparent",color:i(z==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:z==="view"?"切换到编辑模式":"切换到查看模式",children:z==="view"?"✏️ 编辑":"👁 查看"}):null,W=t.jsxs(t.Fragment,{children:[F,v]});return!L&&!$?t.jsx(tt,{}):z==="view"?t.jsx(Hn,{data:L,transport:r,onNavigate:a?I=>a(I):void 0,renderLink:u,headerExtra:W,className:b,style:j}):$?t.jsxs("div",{className:b,style:j,children:[W&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:W}),t.jsx(ps,{data:$,onChange:p||(()=>{}),onSave:d||(()=>{}),transport:r,onNavigate:a,showDelete:!!c,onDelete:c,onAskAI:x,renderSectionActions:g,onDownloadResource:h,downloadStatuses:y,relations:k,onRelationsChange:m})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:i("muted")},children:"无数据"})},ji=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],fs=({isOpen:e,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,l]=f.useState(null),[p,d]=f.useState(""),[c,a]=f.useState(""),[u,x]=f.useState("idle"),[g,h]=f.useState(""),y=f.useRef(null);f.useEffect(()=>{e&&(l(null),d(""),a(""),x("idle"),h(""))},[e]),f.useEffect(()=>{s&&setTimeout(()=>{var b;return(b=y.current)==null?void 0:b.focus()},100)},[s]),f.useEffect(()=>{if(u==="success"){const b=setTimeout(n,2e3);return()=>clearTimeout(b)}},[u,n]),f.useEffect(()=>{if(!e)return;const b=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[e,n]);const k=async()=>{if(!(!s||!p.trim())){x("submitting"),h("");try{await o({type:s,content:p.trim(),...c.trim()?{contact:c.trim()}:{}}),x("success")}catch(b){x("error"),h(b instanceof Error?b.message:"提交失败,请稍后重试")}}};if(!e)return null;const m=s&&p.trim()&&u!=="submitting",v=ji.find(b=>b.value===s);return t.jsx("div",{style:Hd,onClick:b=>{b.target===b.currentTarget&&n()},children:t.jsxs("div",{style:Dd,onClick:b=>b.stopPropagation(),children:[t.jsxs("div",{style:Gd,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:Vd,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:Jd,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:ji.map(b=>t.jsxs("button",{onClick:()=>l(b.value),style:{...Ud,...s===b.value?Yd:{}},children:[t.jsx("span",{children:b.icon})," ",b.label]},b.value))}),t.jsx("textarea",{ref:y,value:p,onChange:b=>d(b.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...Kd,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:c,onChange:b=>a(b.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:Xd}),t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[p.length," / 2000"]}),u==="error"&&t.jsx("div",{style:Zd,children:g}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:k,disabled:!m,style:{...qd,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},Hd={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Dd={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:i("shadow-dialog")},Gd={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Vd={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:i("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Ud={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"},Yd={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Kd={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"},qd={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},Jd={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:i("success")},Zd={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Xd={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"},Ln="--bim-feedback-fab-offset",Bn=48,Qd=16,ep=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:o,hidden:r=!1,zIndex:s})=>{const[l,p]=f.useState(!1),d=n.bottom??24;return f.useEffect(()=>{if(r||typeof document>"u")return;const c=document.documentElement;return c.style.setProperty(Ln,`calc(${d+Bn+Qd}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(Ln)}},[r,d]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>p(!0),style:{...tp,zIndex:s??i("feedback-fab-z"),bottom:`calc(${d}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(fs,{isOpen:l,onClose:()=>p(!1),onSubmit:e,feedbackListUrl:o})]})},tp={position:"fixed",width:`${Bn}px`,height:`${Bn}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"},vi=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],gs=({onSubmit:e})=>{const[n,o]=f.useState("bug"),[r,s]=f.useState(""),[l,p]=f.useState(""),[d,c]=f.useState("idle"),[a,u]=f.useState(""),x=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var k;return(k=x.current)==null?void 0:k.focus()},100)},[n]);const g=async()=>{if(!(!n||!r.trim())){c("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),c("success"),s(""),p(""),o("bug")}catch(k){c("error"),u(k instanceof Error?k.message:"提交失败,请稍后重试")}}},h=n&&r.trim()&&d!=="submitting",y=vi.find(k=>k.value===n);return d==="success"?t.jsx("div",{style:ki,children:t.jsxs("div",{style:sp,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>c("idle"),style:lp,children:"继续提交"})]})}):t.jsxs("div",{style:ki,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:vi.map(k=>t.jsxs("button",{onClick:()=>o(k.value),style:{...np,...n===k.value?op:{}},children:[t.jsx("span",{children:k.icon})," ",k.label]},k.value))}),t.jsx("textarea",{ref:x,value:r,onChange:k=>s(k.target.value),placeholder:(y==null?void 0:y.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:d==="submitting",style:{...ip}}),t.jsx("input",{type:"text",value:l,onChange:k=>p(k.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:d==="submitting","aria-label":"联系方式(选填)",style:cp}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:g,disabled:!h,style:{...rp,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:d==="submitting"?"提交中...":"提交"})]}),d==="error"&&t.jsx("div",{style:ap,children:a})]})},ki={padding:"16px",border:`1px solid ${i("widget-border")}`,borderRadius:"8px",background:i("input-bg")},np={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"},op={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},ip={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"},rp={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},sp={display:"flex",alignItems:"center",gap:"12px",color:i("success"),fontSize:"14px"},lp={background:"none",border:"none",color:i("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ap={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginTop:"8px"},cp={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 Si(e){return typeof e=="function"?e():e??"/api/feedback"}const hs=({resourceId:e,apiUrl:n})=>{const[o,r]=f.useState([]),[s,l]=f.useState(!0),p=f.useCallback(async()=>{const c=Si(n);l(!0);try{const u=await(await fetch(`${c}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);f.useEffect(()=>{p()},[p]);const d=async c=>{const a=Si(n),u=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...c,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const x=await u.json().catch(()=>null);throw new Error((x==null?void 0:x.error)||"提交失败")}setTimeout(()=>p(),500)};return t.jsxs("div",{children:[t.jsx(xo,{items:o,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(gs,{onSubmit:d})})]})},wi={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 dp(e){return e?wi[e]??e:wi.related}const pp={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function up(e){return pp[e]??e}const xp={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function fo(e){return xp[e]??""}function go({authors:e,onNavigate:n,renderLink:o}){const{convert:r}=Y(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,p)=>{const d=Yn(l.role);return t.jsxs(f.Fragment,{children:[p>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Pe,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:o,dense:!0}):r(l.name),d&&t.jsx("span",{style:{marginLeft:4},children:r(d)})]},p)})}):null}const _i=12,fp=60,ms=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,railTop:l,back:p,railLinks:d})=>{var V,se,de;const c=te(),{convert:a}=Y(),u=f.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[x,g]=f.useState(new Map),[h,y]=f.useState(!1),[k,m]=f.useState(""),[v,b]=f.useState(!1),j=u.length<=fp,w=j||h||!!k||v,S=f.useMemo(()=>w?u:u.slice(0,_i),[u,w]);f.useEffect(()=>{if(!n||S.length===0)return;const H=S.filter(ie=>!x.has(ie));if(H.length===0)return;let re=!1;return Promise.all(H.map(ie=>n.getItem(ie).then(pe=>{const fe=pe??{};return[ie,{id:ie,title:fe.title,edition:fe.edition,resources:fe.resources,publication_info:fe.publication_info,current_location:fe.current_location,lineage:fe.lineage,measure_info:fe.measure_info}]}).catch(()=>[ie,{id:ie}]))).then(ie=>{re||g(pe=>{const fe=new Map(pe);for(const[ye,Ce]of ie)fe.set(ye,Ce);return fe})}),()=>{re=!0}},[n,S,x]);const z=f.useMemo(()=>u.map(H=>x.get(H)??{id:H}),[u,x]),_=u.length>0&&u.every(H=>x.has(H)),T=j||w,B=f.useMemo(()=>pr(z,e.version_graph,{era:k,scanOnly:v,sort:T?"year":"default"}),[z,e.version_graph,k,v,T]),L=h?B.rows:B.rows.slice(0,_i),$=B.allRows.filter(H=>H.hasImage).length,F=e.related_works||[],W=F.filter(H=>H.relation==="collected_in"),I=f.useMemo(()=>{const H=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],re=ie=>{const pe=H.indexOf(ie??"");return pe<0?H.length:pe};return F.filter(ie=>ie.relation!=="collected_in").map((ie,pe)=>({r:ie,i:pe})).sort((ie,pe)=>re(ie.r.relation)-re(pe.r.relation)||ie.i-pe.i).map(ie=>ie.r)},[F]),R=f.useMemo(()=>{const H=Xt(e.resources,e.resource_groups);return[...H.mirrors.flatMap(re=>re.items.map(ie=>({r:ie,kind:a(re.label)}))),...H.buckets.flatMap(re=>re.items.map(ie=>({r:ie,kind:a(fo(re.key))})))]},[e.resources,e.resource_groups,a]),N=e.indexed_by||[],O=e.emendated_by||[],E=f.useMemo(()=>{var ce,M,oe;const H=[],re=(M=(ce=e.authors)==null?void 0:ce[0])==null?void 0:M.dynasty;re&&H.push({label:"成書",value:a(re)});const ie=Qe(e,c.unit.juan);if(ie){const ne=(oe=e.juan_count)==null?void 0:oe.description;H.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[a(ie),ne&&ne!==ie?t.jsxs("span",{className:"bim-d-meta",children:["(",a(ne),")"]}):null]})})}e.loss_status&&H.push({label:"存佚",value:a(up(e.loss_status))});const pe=e._edition_count??u.length;pe&&H.push({label:"版本",value:t.jsxs(t.Fragment,{children:[pe," ",a("種"),_&&$?t.jsxs("span",{className:"bim-d-meta",children:[" ",a(`${$} 種有影印`)]}):null]})});const fe=B.allRows.filter(ne=>ne.sortYear!=null);if(fe.length>0){const ne=fe.reduce((he,ge)=>he.sortYear<=ge.sortYear?he:ge);ne.era.era&&H.push({label:"最早存世",value:a([ne.era.era,ne.era.reign].filter(Boolean).join(" ")),title:ne.era.source==="edition"?a("據版本題名推斷"):void 0})}(N.length||O.length)&&H.push({label:"著錄",value:t.jsxs(t.Fragment,{children:[N.length?`${N.length} ${a("家")}`:"—",O.length?t.jsxs("span",{className:"bim-d-meta",children:[" ",a(`考證 ${O.length} 條`)]}):null]})});const ye=zi(e.additional_titles);ye.length&&H.push({label:"又名",value:ye.map(a).join("、")});const Ce=zi(e.attached_texts);Ce.length&&H.push({label:"附載",value:Ce.map(a).join("、")});const Q=(e.additional_works||[]).map(ne=>a(ne.book_title)+(ne.n_juan!=null?` ${ne.n_juan}${a(c.unit.juan)}`:""));return Q.length&&H.push({label:"附錄",value:Q.join("、")}),H},[e,a,c,u.length,_,$,B.allRows,N.length,O.length]),X=e.classification,C=X?[X.l1,X.l2,X.l3,X.l4].filter(Boolean).map(H=>a(H)):[],A=e.subtype?a(c.workSubtype[e.subtype]??e.subtype):"",K=t.jsx(Bt,{title:a(e.title),byline:t.jsx(go,{authors:e.authors,onNavigate:o,renderLink:r}),meta:t.jsx(Te,{items:[...C,X!=null&&X.source?a(`據《${X.source.split("/")[0]}》`):"",A]}),description:(V=e.description)!=null&&V.text?t.jsxs(t.Fragment,{children:[t.jsx(Ye,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(se=e.description.sources)!=null&&se.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(H=>a(ta(H))).filter(Boolean).join(" · ")}):null]}):void 0,facts:E,readAction:s,foot:t.jsx(Nt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(de=e.appendix)==null?void 0:de.map((H,re)=>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(Ye,{text:H.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},re))}),U=B.eras.length>=2?[{key:"",label:c.catalog.all},...B.eras.map(H=>({key:H,label:H}))]:[],G=[];u.length&&G.push({id:"versions",label:"版本",count:u.length}),N.length&&G.push({id:"catalogs",label:"著錄",count:N.length}),W.length&&G.push({id:"collected",label:"收入叢編",count:W.length}),I.length&&G.push({id:"related",label:"相關書目",count:I.length}),R.length&&G.push({id:"resources",label:"在線資源",count:R.length});const ee=u.length===0&&N.length===0,P=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(ze,{id:"versions",title:"版本",meta:t.jsx(Te,{items:[a(`共 ${u.length} 種`),_&&$?a(`${$} 種有影印`):"",B.rows.length!==B.allRows.length?a(`當前 ${B.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[U.length>0&&t.jsx(en,{items:U,value:k,onChange:H=>{m(H),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(vr,{label:"只看有影印",checked:v,onChange:H=>{b(H),y(!1)}}),t.jsx("span",{className:"bim-d-meta",children:a(T?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("版本")}),t.jsx("th",{children:a("年代")}),t.jsx("th",{children:a("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:a("影印")})})]})}),t.jsx("tbody",{children:L.map(H=>{var re;return t.jsx(gp,{row:H,measure:(re=x.get(H.id))==null?void 0:re.measure_info,loaded:x.has(H.id),onNavigate:o,renderLink:r},H.id)})})]}),L.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a(k||v?"當前篩選下沒有版本":"暫無版本著錄")}),B.rows.length>L.length&&t.jsx(gt,{label:`展開其餘 ${B.rows.length-L.length} 種版本`,onClick:()=>y(!0)}),B.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:a("部分年代據版本題名推斷,非著錄原文")})]}),N.length>0&&t.jsx(hp,{items:N,onNavigate:o,renderLink:r}),ee&&t.jsx(ze,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該作品的版本與書目收錄。")})})]}),q=(H,re)=>t.jsx(Pe,{id:H,label:a(re),onNavigate:o,renderLink:r,dense:!0}),Z=t.jsxs(t.Fragment,{children:[t.jsx(at,{id:"collected",title:"收入叢編",items:W.map(H=>q(H.id,H.title))}),t.jsx(at,{id:"related",title:"相關書目",meta:a(`${I.length} 部`),items:I.map(H=>t.jsxs(t.Fragment,{children:[q(H.id,H.title),t.jsx("span",{className:"bim-d-meta",title:H.note?a(H.note):void 0,children:a(dp(H.relation))})]}))}),t.jsx(at,{id:"resources",title:"在線資源",cap:6,items:R.map(({r:H,kind:re})=>{const ie=a((H.url?et(H.url):void 0)||H.name),pe=ft(H);return t.jsxs(t.Fragment,{children:[pe?t.jsxs("a",{href:pe,target:"_blank",rel:"noopener noreferrer",children:[ie," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:ie}),re&&t.jsx("span",{className:"bim-d-meta",children:re})]})})})]});return t.jsx(Lt,{railTop:l,back:p,nav:G,railLinks:d,main:P,card:K,side:Z})};function zi(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function $i(e,n){return n((e.url?et(e.url):void 0)||e.name)}function gp({row:e,measure:n,loaded:o,onNavigate:r,renderLink:s}){const{convert:l}=Y(),p=[e.era.era,e.era.reign].filter(Boolean).join(" "),d=e.era.source==="edition",c=e.holders[0],a=c?$i(c,l):e.locationName?l(e.locationName):"",u=e.images[0],x=u?ft(u):void 0,g=e.images.map(h=>$i(h,l)).join("、");return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Pe,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n&&t.jsx("span",{className:"bim-d-meta",children:l(n)})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${p?"":" bim-d-zt-blank"}`,title:d?l("據版本題名推斷"):void 0,children:p?l(p):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&&(x?t.jsx("a",{className:"bim-d-flag",href:x,target:"_blank",rel:"noopener noreferrer",title:g,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:g,children:l("有影印")}))})]})}function hp({items:e,onNavigate:n,renderLink:o}){const r=te(),{convert:s}=Y(),[l,p]=f.useState(0),d=e[Math.min(l,e.length-1)];return t.jsx(ze,{id:"catalogs",title:"著錄",meta:s(`歷代書目 ${e.length} 家`),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-lu-list bim-d-ui",role:"tablist","aria-label":s("著錄書目"),children:e.map((c,a)=>t.jsx("li",{role:"presentation",children:t.jsx("button",{type:"button",role:"tab","aria-selected":a===l,onClick:()=>p(a),children:s(c.source)})},a))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:s(d.title_info)}),t.jsx(Te,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?t.jsx(Pe,{id:d.source_bid,label:s(d.source),onNavigate:n,renderLink:o,dense:!0}):s(d.source),d.section?s(d.section):"",d.author_info?`${s(r.label.authorInfo)} ${s(d.author_info)}`:"",d.edition?`${s(r.label.edition)} ${s(d.edition)}`:"",d.page??""]}),d.summary&&t.jsx("p",{className:"bim-d-quote",children:$e(s(d.summary))}),d.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s(r.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:$e(s(d.comment))})]}),d.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s(r.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:$e(s(d.additional_comment))})]}),!d.summary&&!d.comment&&!d.additional_comment&&!d.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:s("僅著錄書名,無提要。")})]})]})})}const Ci=8,bs=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,railTop:l,back:p,railLinks:d})=>{var R,N,O,E,X;const c=te(),{convert:a}=Y(),[u,x]=f.useState(null),[g,h]=f.useState(new Map),[y,k]=f.useState([]),[m,v]=f.useState(!1);f.useEffect(()=>{if(!n||!e.work_id){x(null);return}let C=!1;return n.getItem(e.work_id).then(A=>{!C&&A&&A.type==="work"&&x(A)}).catch(()=>{}),()=>{C=!0}},[n,e.work_id]),f.useEffect(()=>{const C=e.contained_in||[];if(!n||C.length===0){h(new Map);return}let A=!1;return Promise.all(C.map(K=>{const U=typeof K=="string"?K:K.id;return n.getItem(U).then(G=>[U,G]).catch(()=>[U,null])})).then(K=>{if(A)return;const U=new Map;for(const[G,ee]of K)ee&&U.set(G,ee);h(U)}),()=>{A=!0}},[n,e.contained_in]);const b=f.useMemo(()=>{const C=new Set([...(u==null?void 0:u.books)||[],...e.related_books||[]]);return C.delete(e.id),[...C]},[u==null?void 0:u.books,e.related_books,e.id]);f.useEffect(()=>{if(!n||b.length===0){k([]);return}const C=m?b:b.slice(0,Ci);let A=!1;return Promise.all(C.map(K=>n.getItem(K).then(U=>({id:K,title:U==null?void 0:U.title,edition:U==null?void 0:U.edition})).catch(()=>({id:K})))).then(K=>{A||k(K)}),()=>{A=!0}},[n,b,m]);const j=f.useMemo(()=>{const C=Xt(e.resources,e.resource_groups);return[...C.mirrors.flatMap(A=>A.items.map(K=>({r:K,kind:a(A.label),all:A.items}))),...C.buckets.flatMap(A=>A.items.map(K=>({r:K,kind:a(fo(A.key)),all:A.items})))]},[e.resources,e.resource_groups,a]),w=Rt(e),S=hr(e),z=new Set((e.contained_in||[]).map(C=>typeof C=="string"?0:$t(C.volume_index).length).filter(C=>C>0)),_=f.useMemo(()=>{var ee,P,q,Z;const C=[];S&&C.push({label:"版本類型",value:a(S),title:(ee=e.lineage)!=null&&ee.category?void 0:a("據版本題名推斷")}),(w.era||w.reign)&&C.push({label:"刊寫年代",value:a([w.era,w.reign].filter(Boolean).join(" ")),title:w.source==="edition"?a("據版本題名推斷"):void 0});const A=Qe(e,c.unit.juan);A&&C.push({label:"卷帙",value:a(A)});const K=(e.contained_in||[]).flatMap(V=>typeof V=="string"?[]:$t(V.volume_index));K.length&&C.push({label:"冊次",value:a(`第 ${Qt(K,c.unit.volume)} ${c.unit.volume}(${K.length} ${c.unit.volume})`)});const U=(e.resources||[]).filter(V=>(V.types||(V.type?[V.type]:[])).includes("physical"));U.length?C.push({label:"存藏",value:U.slice(0,2).map(V=>a(V.name)).join("、")+(U.length>2?a(` 等 ${U.length} 處`):"")}):(P=e.current_location)!=null&&P.name&&C.push({label:"存藏",value:a(e.current_location.name)}),(q=e.page_count)!=null&&q.description&&C.push({label:c.label.pageCount,value:a(e.page_count.description)}),(Z=e.publication_info)!=null&&Z.details&&C.push({label:"刊印",value:a(e.publication_info.details)});const G=[...Cn(e.additional_titles),...Cn(e.attached_texts)];return G.length&&C.push({label:"又名",value:G.map(a).join("、")}),C},[e,a,c,w,S]),T=a(e.title),B=e.edition?a(e.edition):void 0,L=t.jsx(Bt,{title:T,subtitle:B,byline:t.jsx(go,{authors:e.authors??(u==null?void 0:u.authors),onNavigate:o,renderLink:r}),meta:t.jsx(Te,{items:[a("版本"),S?a(S):"",w.era?a(w.era):""]}),description:(R=e.description)!=null&&R.text?t.jsx(Ye,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,facts:_,readAction:s,foot:t.jsx(Nt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),$=e.contained_in||[],F=[];j.length&&F.push({id:"resources",label:"影印與全文",count:j.length}),$.length&&F.push({id:"collections",label:"收入叢編",count:$.length}),(N=e.location_history)!=null&&N.length&&F.push({id:"provenance",label:"流轉歷史"}),u&&F.push({id:"work",label:"所屬作品"}),b.length&&F.push({id:"siblings",label:"其他版本",count:b.length});const W=t.jsxs(t.Fragment,{children:[j.length>0&&t.jsx(ze,{id:"resources",title:"影印與全文",meta:a(`${j.length} 處`),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:j.map(({r:C,kind:A,all:K},U)=>t.jsx(mp,{item:C,kind:A,siblings:K,listedVolumeCounts:z},`${C.id||C.url||C.name}-${U}`))})})}),$.length>0&&t.jsx(ze,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:$.map((C,A)=>{var P,q;const K=typeof C=="string"?C:C.id,U=typeof C=="string"?[]:$t(C.volume_index),G=g.get(K),ee=(G==null?void 0:G._member_count)||((P=G==null?void 0:G.books)==null?void 0:P.length)||((q=G==null?void 0:G.contained_works)==null?void 0:q.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Pe,{id:K,label:G?a(G.title):K,onNavigate:o,renderLink:r,dense:!0}),U.length>0&&t.jsx(bp,{volumes:U,unit:c.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ee?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ee>0&&a(`全 ${ee} ${c.unit.bu}`)})]},`${K}-${A}`)})})})}),(O=e.location_history)!=null&&O.length?t.jsx(ze,{id:"provenance",title:"流轉歷史",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:e.location_history.map((C,A)=>t.jsxs("tr",{children:[t.jsx("td",{className:"bim-d-zt-main",children:t.jsx("span",{className:"bim-d-zt-name",children:a(C.name)})}),t.jsx("td",{className:`bim-d-zt-sub${C.description||C.start_date?"":" bim-d-zt-blank"}`,children:t.jsx(Te,{items:[[C.start_date,C.end_date].filter(Boolean).join("—"),C.description?a(C.description):""]})})]},A))})})}):null,j.length===0&&$.length===0&&!((E=e.location_history)!=null&&E.length)&&t.jsx(ze,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該版本的影印、全文與收藏信息。")})})]}),I=t.jsxs(t.Fragment,{children:[u&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h3",{className:"bim-d-ui",children:a(c.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Pe,{id:u.id,label:a(u.title),onNavigate:o,renderLink:r})}),t.jsx(Te,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[a(Qe(u,c.unit.juan)),...(u.authors||[]).slice(0,2).map(C=>`${C.dynasty?`〔${a(C.dynasty)}〕`:""}${a(C.name)}`),u._edition_count?a(`${u._edition_count} 種版本`):""]}),((X=u.description)==null?void 0:X.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:4,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:a(u.description.text.replace(/[#*_>`[\]]/g,""))})]}),b.length>0&&t.jsxs("div",{children:[t.jsx(at,{id:"siblings",title:c.relation.siblingVersions,meta:a(`${b.length} 種`),cap:m?y.length:Ci,items:y.map(C=>t.jsx(Pe,{id:C.id,label:a(C.edition||C.title||C.id),onNavigate:o,renderLink:r,dense:!0}))}),!m&&b.length>y.length&&y.length>0&&t.jsx(gt,{label:`顯示更多(${b.length-y.length})`,onClick:()=>v(!0)})]})]});return t.jsx(Lt,{railTop:l,back:p,nav:F,railLinks:d,main:W,card:L,side:I})};function mp({item:e,kind:n,siblings:o,listedVolumeCounts:r}){const{convert:s}=Y(),[l,p]=f.useState(!1),d=Kt(e),c=!!d&&d.expected>0&&!r.has(d.expected),a=(e.url?et(e.url):void 0)||e.name,u=cr(e,o),x=s(u?`${a}(${u})`:a),g=ft(e),h=Et(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[g?t.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",children:[x," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:x}),h&&t.jsx("span",{className:"bim-d-meta",children:s(h)}),c&&l&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(qn,{item:e})})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${n?"":" bim-d-zt-blank"}`,children:n}),t.jsx("td",{className:c?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:c&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":l,onClick:()=>p(y=>!y),children:s(l?"收起分冊":`展開 ${d.expected} 冊`)})})]})}function bp({volumes:e,unit:n}){const{convert:o}=Y();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[o(`第 ${Qt(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),o(`${e.length} ${n}`)]})]})}const yp=16,ys=({data:e,catalog:n,transport:o,onNavigate:r,renderLink:s,catalogAction:l,readAction:p,railTop:d,back:c,railLinks:a})=>{var C,A,K,U,G,ee;const u=te(),{convert:x}=Y(),[g,h]=f.useState(""),[y,k]=f.useState(!1),m=f.useMemo(()=>fr(e,n),[e,n]),v=f.useMemo(()=>g?m.rows.filter(P=>P.section===g):m.rows,[m.rows,g]),b=y?v:v.slice(0,yp),[j,w]=f.useState(new Map),S=f.useMemo(()=>b.filter(P=>P.id&&P.title===P.id&&!j.has(P.id)).map(P=>P.id),[b,j]);f.useEffect(()=>{if(!o||S.length===0)return;let P=!1;return Promise.all(S.map(q=>o.getItem(q).then(Z=>[q,{title:Z==null?void 0:Z.title,edition:Z==null?void 0:Z.edition}]).catch(()=>[q,{}]))).then(q=>{P||w(Z=>{const V=new Map(Z);for(const[se,de]of q)V.set(se,de);return V})}),()=>{P=!0}},[o,S]);const z=f.useMemo(()=>{const P=Xt(e.resources,e.resource_groups);return[...P.mirrors.flatMap(q=>q.items.map(Z=>({r:Z,kind:x(q.label)}))),...P.buckets.flatMap(q=>q.items.map(Z=>({r:Z,kind:x(fo(q.key))})))]},[e.resources,e.resource_groups,x]),_=e.contained_works||[],T=new Set(m.rows.map(P=>P.id).filter(Boolean)),B=_.length>0&&!_.every(P=>T.has(P.id)),L=(()=>{const P=m.rows.map(q=>q.edition).filter(Boolean);return P.length>1&&new Set(P).size===1})(),$=m.sections.length>0,F=m.rows.some(P=>P.volumes.length>0||P.expected!=null),W=e._member_count||((C=e.books)==null?void 0:C.length)||_.length,I=f.useMemo(()=>{var Z,V,se;const P=[];W&&P.push({label:"種數",value:`${W} ${x(u.unit.bu)}`});const q=Qe(e,u.unit.juan);return q&&P.push({label:"卷數",value:x(q),title:(Z=e.juan_count)!=null&&Z.description?x(e.juan_count.description):void 0}),m.totalVolumes&&P.push({label:"全帙冊數",value:`${m.totalVolumes} ${x(u.unit.volume)}`}),(V=e.publication_info)!=null&&V.details&&P.push({label:"刊印",value:x(e.publication_info.details)}),(se=e.publication_info)!=null&&se.year&&P.push({label:"年代",value:x(e.publication_info.year)}),P},[e,W,m.totalVolumes,x,u]),R=t.jsx(Bt,{title:x(e.title),byline:t.jsx(go,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Te,{items:[x("叢編"),e.subtype==="work_collection"?x("作品集"):"",(A=e.publication_info)!=null&&A.year?x(e.publication_info.year):""]}),description:(K=e.description)!=null&&K.text||(U=e.history)!=null&&U.length?t.jsxs(t.Fragment,{children:[((G=e.description)==null?void 0:G.text)&&t.jsx(Ye,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(ee=e.history)!=null&&ee.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((P,q)=>t.jsx("li",{children:x(P)},q))}):null]}):void 0,facts:I,readAction:p,foot:t.jsx(Nt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),N=[];m.rows.length&&N.push({id:"titles",label:u.section.containedBooks,count:m.rows.length}),z.length&&N.push({id:"resources",label:"影印與全文",count:z.length}),B&&N.push({id:"works",label:u.section.containedWorks,count:_.length});const O=$?[{key:"",label:u.catalog.all},...m.sections.map(P=>({key:P,label:P}))]:[],E=t.jsxs(t.Fragment,{children:[m.rows.length>0&&t.jsxs(ze,{id:"titles",title:u.section.containedBooks,meta:t.jsx(Te,{items:[x(`共 ${m.rows.length} ${u.unit.items}`),W&&W!==m.rows.length?x(`成員 ${W} ${u.unit.bu}`):"",v.length!==m.rows.length?x(`當前 ${v.length} ${u.unit.items}`):""]}),action:l,children:[O.length>0&&t.jsx("div",{className:"bim-d-filters bim-d-ui",children:t.jsx(en,{items:O,value:g,onChange:P=>{h(P),k(!1)}})}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:x("書名")}),$&&t.jsx("th",{children:x("部類")}),F&&t.jsx("th",{children:x("全帙冊次")})]})}),t.jsx("tbody",{children:b.map((P,q)=>{var re;const Z=P.id?j.get(P.id):void 0,V=Z!=null&&Z.title?{...P,title:Z.title}:P,se=[(re=V.subItems)!=null&&re.length?V.subItems.map(ie=>x(ie)).join("、"):"",V.edition&&!L?x(V.edition):""].filter(Boolean).join(" · "),de=V.volumes.length>0?x(`第 ${Qt(V.volumes,u.unit.volume)} ${u.unit.volume}`):V.expected!=null?x(`${V.found??0}/${V.expected} ${u.unit.volume}`):"",H=V.section?x(V.section.endsWith("部")?V.section:`${V.section}部`):"";return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[V.id?t.jsx(Pe,{id:V.id,label:x(V.title),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:x(V.title)}),se&&t.jsx("span",{className:"bim-d-meta",children:se})]}),$&&t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${H?"":" bim-d-zt-blank"}`,children:H||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),F&&t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${de?"":" bim-d-zt-blank"}`,children:de||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})})]},`${V.id??V.title}-${q}`)})})]}),b.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:x(u.catalog.noMatch)}),v.length>b.length&&t.jsx(gt,{label:`展開其餘 ${v.length-b.length} ${u.unit.items}`,onClick:()=>k(!0)})]}),z.length>0&&t.jsx(ze,{id:"resources",title:"影印與全文",meta:x(`${z.length} 處`),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:z.map(({r:P,kind:q},Z)=>{const V=x((P.url?et(P.url):void 0)||P.name),se=ft(P),de=Et(P)||P.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[se?t.jsxs("a",{href:se,target:"_blank",rel:"noopener noreferrer",children:[V," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:V}),de&&t.jsx("span",{className:"bim-d-meta",children:x(de)})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${q?"":" bim-d-zt-blank"}`,children:q})]},`${P.id||P.url||P.name}-${Z}`)})})})}),m.rows.length===0&&z.length===0&&t.jsx(ze,{title:u.section.containedBooks,children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該叢編的子目。")})})]}),X=B?t.jsx(at,{id:"works",title:u.section.containedWorks,meta:x(`${_.length} 種`),cap:12,items:_.map(P=>t.jsx(Pe,{id:P.id,label:x(P.title),onNavigate:r,renderLink:s,dense:!0}))}):null;return t.jsx(Lt,{railTop:d,back:c,nav:N,railLinks:a,main:E,card:R,side:X})},jp=16,hn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Ii(e){if(!e)return hn.length;const n=hn.indexOf(e);return n===-1?hn.length:n}const vp={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function Ti(e){return e==null?"":e<0?`前${-e}`:String(e)}const js=({data:e,transport:n,onNavigate:o,renderLink:r,railTop:s,back:l,railLinks:p})=>{var W;const d=te(),{convert:c}=Y(),[a,u]=f.useState("全部"),[x,g]=f.useState(!1),[h,y]=f.useState("default"),[k,m]=f.useState(new Map),v=f.useMemo(()=>(e.works||[]).map(I=>{const R=k.get(I.work_id);return{id:I.work_id,title:(R==null?void 0:R.title)??I.title??I.work_id,role:I.role||"",cls:Un(I.role),versionCount:R==null?void 0:R.versionCount,loaded:!!(R!=null&&R.loaded)}}),[e.works,k]),b=f.useMemo(()=>xr((e.works||[]).map(I=>I.role)),[e.works]),j=f.useMemo(()=>{const I=a==="全部"?v:v.filter(R=>R.cls===a);return h==="versions"?[...I].sort((R,N)=>(N.versionCount??-1)-(R.versionCount??-1)):I},[v,a,h]),w=x?j:j.slice(0,jp),S=f.useMemo(()=>w.filter(I=>!k.has(I.id)).map(I=>I.id),[w,k]);f.useEffect(()=>{if(!n||S.length===0)return;let I=!1;return Promise.all(S.map(R=>n.getItem(R).then(N=>{var X,C;const O=N??{},E=O._edition_count??(((X=O.books)==null?void 0:X.length)??0)+(((C=O.collections)==null?void 0:C.length)??0);return[R,{id:R,title:O.title,versionCount:E,loaded:!0}]}).catch(()=>[R,{id:R,loaded:!0}]))).then(R=>{I||m(N=>{const O=new Map(N);for(const[E,X]of R)O.set(E,X);return O})}),()=>{I=!0}},[n,S]);const z=f.useMemo(()=>{const I=new Map;for(const R of e.alt_names||[]){const N=R.type||d.section.aliases;I.has(N)||I.set(N,[]),I.get(N).push(R.name)}return[...I.entries()].sort((R,N)=>Ii(R[0])-Ii(N[0])).map(([R,N])=>({label:R,names:N}))},[e.alt_names,d]),_=e.birth_year!=null||e.death_year!=null?`${Ti(e.birth_year)||"?"}—${Ti(e.death_year)||"?"}`:"",T=f.useMemo(()=>{var O,E;const I=[];for(const X of z)I.push({label:X.label,value:X.names.map(C=>c(C)).join("、")});e.dynasty&&I.push({label:"時代",value:c(e.dynasty)}),_&&I.push({label:"生卒",value:_});const R=(e.works||[]).length;R&&I.push({label:"著作",value:`${R} ${c("種")}`});const N=(O=e.external_ids)==null?void 0:O.cbdb_id;return N!=null&&I.push({label:"CBDB",value:t.jsxs(t.Fragment,{children:[N,((E=e.external_ids)==null?void 0:E.cbdb_match)==="auto"&&t.jsx("span",{className:"bim-d-meta",title:c("由姓名、朝代與著作重合度自動匹配,未經人工複核"),children:c("自動匹配")})]})}),I},[e,z,_,c]),B=t.jsx(Bt,{title:c(e.primary_name||e.title),meta:t.jsx(Te,{items:[c(vp[e.subtype]??""),_]}),description:(W=e.description)!=null&&W.text?t.jsx(Ye,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,facts:T,foot:t.jsx(Nt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),L=b.map(I=>({key:I.cls,label:`${I.label} ${I.count}`})),$=v.length?[{id:"works",label:"著作",count:v.length}]:[],F=v.length===0?t.jsx(ze,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該人物的關聯作品。")})}):t.jsxs(ze,{id:"works",title:"著作",meta:t.jsx(Te,{items:[c(`共 ${v.length} 種`),j.length!==v.length?c(`當前 ${j.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[L.length>1&&t.jsx(en,{items:L,value:a,onChange:I=>{u(I),g(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":h==="versions",onClick:()=>{h==="default"&&g(!0),y(I=>I==="default"?"versions":"default")},children:c(h==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("作品")}),t.jsx("th",{children:c("職任")}),t.jsx("th",{children:c("存世版本")})]})}),t.jsx("tbody",{children:w.map(I=>t.jsxs("tr",{children:[t.jsx("td",{className:"bim-d-zt-main",children:t.jsx(Pe,{id:I.id,label:c(I.title),onNavigate:o,renderLink:r,dense:!0})}),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("未著錄")}):""})]},I.id))})]}),w.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("該職任下的著作尚未著錄。")}),j.length>w.length&&t.jsx(gt,{label:`展開其餘 ${j.length-w.length} 種著作`,onClick:()=>g(!0)})]});return t.jsx(Lt,{railTop:s,back:l,nav:$,railLinks:p,main:F,card:B})};function kp(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 Sp(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 Ri(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 wp(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 _p(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 p=r?new Set(o.groups):null,d=new Set(o.book_ids??[]);if(p&&e.node_groups)for(const[u,x]of Object.entries(e.node_groups))p.has(x)&&d.add(u);let c=null;if(o.hypothetical_ids&&(c=new Set(o.hypothetical_ids)),p){c||(c=new Set);for(const u of e.hypothetical_nodes??[])u.group&&p.has(u.group)&&c.add(u.id)}return{books:d,hypos:c}}function Gt(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??[]),p=r.node_groups??{},d=_p(r,o??r.default_collection??"all"),c=d!==null,a=(d==null?void 0:d.books)??null,u=(d==null?void 0:d.hypos)??null,x=new Set,g=new Set;if(c){const w=new Map(n.map(L=>[L.id,L])),S=new Map((r.hypothetical_nodes??[]).map(L=>[L.id,L])),z=L=>{const $=w.get(L);if($&&$.lineage)return($.lineage.derived_from??[]).map(W=>W.ref);const F=S.get(L);return F?(F.derived_from??[]).map(W=>W.ref):[]},_=L=>S.has(L)?!u||u.has(L):!a||a.has(L),T=new Set,B=L=>{if(!T.has(L)){T.add(L);for(const $ of z(L))l.has($)||(_($)||(S.has($)?g.add($):w.has($)&&x.add($)),B($))}};for(const L of n)a&&a.has(L.id)&&!l.has(L.id)&&B(L.id);for(const L of r.hypothetical_nodes??[])u&&u.has(L.id)&&B(L.id)}const h=n.filter(w=>!l.has(w.id)).filter(w=>!a||a.has(w.id)||x.has(w.id)).map(w=>{const S=Sp(w,p);return S&&x.has(w.id)&&(S.bridge=!0),S}).filter(w=>w!==null),y=(r.hypothetical_nodes??[]).filter(w=>!u||u.has(w.id)||g.has(w.id)).map(w=>{const S=kp(w);return g.has(w.id)&&(S.bridge=!0),S}),k=[...h,...y],m=new Set(k.map(w=>w.id)),v=new Set,b=[],j=w=>{v.has(w.id)||!m.has(w.source)||!m.has(w.target)||(v.add(w.id),b.push(w))};for(const w of n)l.has(w.id)||!w.lineage||a&&!a.has(w.id)&&!x.has(w.id)||((w.lineage.derived_from??[]).forEach((S,z)=>{j(Ri(w.id,S,z))}),(w.lineage.related_to??[]).forEach((S,z)=>{j(wp(w.id,S,z))}));for(const w of r.hypothetical_nodes??[])u&&!u.has(w.id)&&!g.has(w.id)||(w.derived_from??[]).forEach((S,z)=>{j(Ri(w.id,S,z))});return{nodes:k,edges:b,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function vs(e,n,o){const r=(e??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function zp(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)),p=new Set([...s,...l]),d=(c,a)=>{p.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=>d(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=>d(a,u))}return o}const ks=({graph:e,renderLink:n,className:o,style:r})=>{const{convert:s}=Y();if(!e.nodes.length)return t.jsx("div",{style:{...Pp,...r},className:o,children:"暂无版本图数据"});const l=new Map,p=new Map;for(const g of e.edges)if(g.kind==="derive"){const h=l.get(g.target)??[];h.push(g),l.set(g.target,h)}else for(const h of[g.source,g.target]){const y=p.get(h)??[];y.push(g),p.set(h,y)}const d=new Map(e.nodes.map(g=>[g.id,g])),c=new Map,a=[];for(const g of e.nodes)if(g.group){const h=c.get(g.group)??[];h.push(g),c.set(g.group,h)}else a.push(g);const u=(g,h)=>(g.year??9999)-(h.year??9999);c.forEach(g=>g.sort(u)),a.sort(u);const x=e.groups.filter(g=>c.has(g.id));return t.jsxs("div",{className:o,style:{...Cp,...r},children:[e.title&&t.jsx("div",{style:Ip,children:s(e.title)}),e.description&&t.jsx("div",{style:Tp,children:s(e.description)}),x.map(g=>t.jsx(Ei,{label:g.label,color:g.color,nodes:c.get(g.id),incomingMap:l,siblingMap:p,nodeMap:d,renderLink:n},g.id)),a.length>0&&t.jsx(Ei,{label:"其他",nodes:a,incomingMap:l,siblingMap:p,nodeMap:d,renderLink:n})]})},Ei=({label:e,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:p})=>{const{convert:d}=Y();return t.jsxs("div",{style:Rp,children:[t.jsx("div",{style:{...Ep,borderLeftColor:n??i("widget-border")},children:d(e)}),o.map(c=>t.jsx($p,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:p},c.id))]})},$p=({node:e,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",p=e.bridge,{convert:d}=Y();return t.jsxs("div",{style:{...Lp,borderStyle:l||p?"dashed":"solid",opacity:p?.55:e.status==="lost"?.7:1,background:p?i("bg-subtle"):void 0},title:p?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:Bp,children:[t.jsx("span",{style:Np,children:l||!s?d(e.label):s(e.id,d(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Wp,children:vs(d(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Ap,children:[e.category&&t.jsx(St,{children:d(e.category)}),e.status==="lost"&&t.jsx(St,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(St,{tone:"warn",children:"残本"}),l&&t.jsx(St,{tone:"info",children:"假想祖本"}),p&&t.jsx(St,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Mp,children:["现存:",d(e.extant_juan)]}),e.note&&t.jsx("div",{style:Fp,children:d(e.note)}),n.length>0&&t.jsxs("div",{style:Bi,children:[t.jsx("div",{style:Ni,children:"来源:"}),n.map(c=>{const a=r.get(c.source);return t.jsxs("div",{style:Wi(c.confidence),children:[t.jsx("span",{style:Ai,children:d(c.relation)}),t.jsx("span",{children:(a==null?void 0:a.kind)==="book"&&s?s(a.id,d(a.label)):d((a==null?void 0:a.label)??c.source)}),c.confidence!=="consensus"&&c.confidence!=="certain"&&t.jsx(Li,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:Mi,children:["· ",d(c.evidence)]})]},c.id)})]}),o.length>0&&t.jsxs("div",{style:Bi,children:[t.jsx("div",{style:Ni,children:"关联:"}),o.map(c=>{const a=c.source===e.id?c.target:c.source,u=r.get(a);return t.jsxs("div",{style:Wi(c.confidence),children:[t.jsx("span",{style:Ai,children:d(c.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,d(u.label)):d((u==null?void 0:u.label)??a)}),t.jsx(Li,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:Mi,children:["· ",d(c.evidence)]})]},c.id)})]})]})},St=({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})},Li=({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},Cp={fontSize:"14px",color:i("fg")},Ip={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Tp={fontSize:"13px",color:i("muted"),marginBottom:"16px",lineHeight:1.6},Rp={marginBottom:"16px"},Ep={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:i("fg")},Lp={border:`1px solid ${i("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:i("bg")},Bp={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Np={fontSize:"15px",fontWeight:600},Wp={fontSize:"12px",color:i("muted")},Ap={marginBottom:"6px"},Mp={fontSize:"12px",color:i("muted"),margin:"2px 0"},Fp={fontSize:"12px",color:i("muted"),fontStyle:"italic",margin:"4px 0"},Bi={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${i("widget-border")}`},Ni={fontSize:"11px",color:i("muted"),marginBottom:"2px"},Wi=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Ai={display:"inline-block",padding:"0 6px",fontSize:"11px",background:i("tag-bg"),color:i("fg"),borderRadius:"3px",marginRight:"6px"},Mi={fontSize:"11px",color:i("muted")},Pp={padding:"20px",textAlign:"center",color:i("muted"),fontSize:"13px"},Ss=({selectedNodeId:e,...n})=>{const[o,r]=f.useState("loading"),[s,l]=f.useState(null);return f.useEffect(()=>{let p=!1;return Op().then(d=>{p||(d?(l(d),r("ready")):r("missing"))}),()=>{p=!0}},[]),o==="loading"?t.jsx("div",{style:Fi,children:"加载图组件中…"}):o==="missing"||!s?t.jsxs("div",{style:Fi,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(Hp,{modules:s,selectedNodeId:e,...n})};async function Op(){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 Hp=({graph:e,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:l,modules:p})=>{const{ReactFlow:d,Background:c,Controls:a,Handle:u,Position:x,BaseEdge:g,EdgeLabelRenderer:h,getSmoothStepPath:y,dagre:k}=p,m=f.useMemo(()=>({lineage:z=>{var N,O,E,X;const _=((N=z.data)==null?void 0:N.stepPosition)??.85,[T,B,L]=y({sourceX:z.sourceX,sourceY:z.sourceY,sourcePosition:z.sourcePosition,targetX:z.targetX,targetY:z.targetY,targetPosition:z.targetPosition,stepPosition:_,borderRadius:5}),$=!!((O=z.data)!=null&&O.isSibling),F=$?B:z.targetX-18,W=$?L:z.targetY-12,I=(E=z.data)==null?void 0:E.labelStyle,R=(X=z.data)==null?void 0:X.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(g,{id:z.id,path:T,style:z.style,markerStart:z.markerStart,markerEnd:z.markerEnd}),z.label&&t.jsx(h,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${F}px,${W}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:i("bg"),border:`0.5px solid ${i("widget-border")}`,...R,...I},children:z.label})})]})}}),[g,h,y]),v=f.useMemo(()=>({version:z=>{const _=z.data,T=_.kind==="hypothetical",B=_.status==="lost",L=_.isSelected,$=_.bridge,F=_.borderColor??i("muted"),W=$||T?"dashed":"solid",I=$?.5:B?.6:1;return t.jsxs("div",{style:{background:i($?"bg-subtle":"bg"),border:`2px ${W} ${L?i("primary"):F}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:I,boxShadow:L?i("shadow-node-selected"):T||$?"none":i("shadow-node")},title:$?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:x.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:T||!_.renderLink?_.label:_.renderLink(_.bookId,_.label)}),_.description&&t.jsx("div",{style:{fontSize:10,color:i("muted"),lineHeight:1.25,marginTop:1},children:_.description}),_.yearText&&t.jsx("div",{style:{fontSize:10,color:i("muted"),lineHeight:1.2},children:vs(_.yearText,void 0,_.uncertain)}),B&&t.jsx("div",{style:{fontSize:9,color:i("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[u,x]),{convert:b}=Y(),{rfNodes:j,rfEdges:w}=f.useMemo(()=>Dp(e,k,n,l,b),[e,k,n,l,b]);return t.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:t.jsxs(d,{nodes:j,edges:w,nodeTypes:v,edgeTypes:m,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(a,{showInteractive:!1})]})})};function Dp(e,n,o,r,s=l=>l??""){const d=e.layout==="LR"||!e.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:d?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const a=new Map(e.groups.map(v=>[v.id,v.color??i("muted")]));for(const v of e.nodes)c.setNode(v.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const v of e.edges)v.kind==="derive"&&(u.has(v.relation)||c.setEdge(v.source,v.target));n.layout(c);const x=e.nodes.map(v=>{const b=c.node(v.id),j=r&&v.id===r,w={kind:v.kind,label:s(v.label),bookId:v.kind==="book"?v.id:void 0,yearText:s(v.year_text??Vp(v)),uncertain:v.year_uncertain,category:v.category,status:v.status,borderColor:v.group?a.get(v.group):void 0,renderLink:o,isSelected:j,description:s(v.description),bridge:v.bridge};return{id:v.id,type:"version",position:{x:b.x-160/2,y:b.y-90/2},data:w,draggable:!1,selected:j}}),g=.78,h=.06,y=new Map;for(const v of e.edges)v.kind==="derive"&&(y.has(v.source)||y.set(v.source,[]),y.get(v.source).push(v));const k=new Map;for(const[v,b]of y){if(b.length<=1)continue;const j=[...b].sort((S,z)=>{var B,L;const _=((B=c.node(S.target))==null?void 0:B.y)??0,T=((L=c.node(z.target))==null?void 0:L.y)??0;return _-T}),w=j.length;j.forEach((S,z)=>{const _=(z-(w-1)/2)*h;k.set(S.id,g+_)})}const m=e.edges.map(v=>Gp(v,k.get(v.id),s));return{rfNodes:x,rfEdges:m}}function Gp(e,n,o=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Up(e.confidence),p={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:p,markerStart:s?p:void 0,zIndex:1e3}}function Vp(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Up(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 Fi={padding:"40px 20px",textAlign:"center",color:i("muted"),fontSize:"13px",border:`1px dashed ${i("widget-border")}`,borderRadius:8,background:i("bg")},ws=({graph:e,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:p,onCollectionChange:d,collectionsAvailable:c,collectionCounts:a,className:u,style:x})=>{var b;const[g,h]=f.useState(n),y=j=>{h(j),l==null||l(j)},k=(()=>{if(!c)return[];const j=Object.entries(c);return j.length===0||c.all?j:[...j,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),m=!!(d&&k.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:i("muted"),textAlign:"center"},children:"暂无版本传承数据"});const v=p?(b=c==null?void 0:c[p])==null?void 0:b.description:void 0;return t.jsxs("div",{className:u,style:x,children:[t.jsxs("div",{style:Yp,children:[t.jsx("button",{onClick:()=>y("list"),style:mn(g==="list"),children:"列表"}),t.jsx("button",{onClick:()=>y("graph"),style:mn(g==="graph"),children:"关系图"}),m&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:i("muted"),marginRight:4},children:"集合:"}),k.map(([j,w])=>{const S=a==null?void 0:a[j];return t.jsxs("button",{onClick:()=>d==null?void 0:d(j),style:mn(p===j),title:w.description,children:[w.label,S!=null?` ${S}`:""]},j)})]})]}),m&&v&&t.jsx("div",{style:{fontSize:12,color:i("muted"),marginBottom:8,padding:"4px 8px",background:i("bg-subtle"),borderRadius:4},children:v}),g==="list"?t.jsx(ks,{graph:e,renderLink:o}):t.jsx(Ss,{graph:e,renderLink:o,height:r,selectedNodeId:s})]})},Yp={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},mn=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"}),Nn=({style:e})=>{const n=f.useContext(xt);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:"简"})]})},Wn=({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 bn(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function Kp(e,n){if(!n)return!1;const o=n.id;return o===void 0||o===e}const qp=({id:e,transport:n,initialDetail:o,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:p,onJuanChange:d,lineageMode:c="list",onLineageModeChange:a,lineageCollection:u,onLineageCollectionChange:x,initialPage:g=1,selectedLineageNodeId:h,onNavigate:y,onBack:k,backLabel:m,renderLink:v,enrichDetail:b,getSourceLink:j,readLink:w,railTop:S,extraTabs:z=[],showFeedbackTab:_=!0,feedbackApiUrl:T,height:B,footerExtra:L,className:$,style:F})=>{var wo;const W=te(),{convert:I}=Y(),[R]=f.useState(()=>{if(!Kp(e,o))return null;const D={...o},le=r??bn(e,D);return b&&b(le,D),{id:e,entry:le,detail:D}}),[N,O]=f.useState((R==null?void 0:R.entry)??null),[E,X]=f.useState((R==null?void 0:R.detail)??null),[C,A]=f.useState(!R),[K,U]=f.useState(!1),[G,ee]=f.useState([]),[P,q]=f.useState(!1),[Z,V]=f.useState(null),[se,de]=f.useState(!1),[H,re]=f.useState(null),[ie,pe]=f.useState(!1),[fe,ye]=f.useState([]),[Ce,Q]=f.useState(!1),[ce,M]=f.useState(null),[oe,ne]=f.useState(null),[he,ge]=f.useState(!1),Re=f.useRef(null),[Be,ve]=f.useState(null),He=p!==void 0?p:Be,ot=f.useCallback(D=>{d?d(D):ve(D)},[d]),ho=f.useCallback(async D=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){ee([]);return}q(!0);try{if(n.getCollectionCatalogs)ee(await n.getCollectionCatalogs(D)||[]);else if(n.getCollectionCatalog){const le=await n.getCollectionCatalog(D);ee(le?[{resource_id:"",data:le}]:[])}}catch{ee([])}finally{q(!1)}},[n]),mo=f.useCallback(async D=>{if(!n.getCollatedEditionIndex){V(null);return}de(!0);try{V(await n.getCollatedEditionIndex(D))}catch{V(null)}finally{de(!1)}},[n]),bo=f.useCallback(async D=>{if(!n.getBookFullTextIndex){re(null);return}pe(!0);try{re(await n.getBookFullTextIndex(D))}catch{re(null)}finally{pe(!1)}},[n]),yo=f.useCallback(async D=>{var le;if(!n.getWorkFullTextList){ye([]);return}Q(!0);try{const ue=(await n.getWorkFullTextList(D)??[]).filter(me=>me.owner_type!=="Book");ye(ue),M(((le=ue.find(me=>me.primary)??ue[0])==null?void 0:le.key)??null)}catch{ye([])}finally{Q(!1)}},[n]),jo=f.useCallback(async(D,le)=>{ge(!0);try{if(n.getLineageGraph){const Se=await n.getLineageGraph(D);Se&&ne(Se)}const ue=le.version_graph;if(!ue||!ue.enabled){oe||ne(null),Re.current=null;return}const me=le.books??[],Ne=[];for(const Se of me)try{const We=await n.getItem(Se);We&&Ne.push(We)}catch{}Re.current={work:le,books:Ne};const J=u??ue.default_collection??(ue.core_books&&ue.core_books.length>0?"core":"all"),xe=J==="core"&&Array.isArray(ue.core_books)&&ue.core_books.length>0?"core":J??"all";ne(Gt(le,Ne,xe))}catch{ne(null),Re.current=null}finally{ge(!1)}},[n]),vo=f.useRef({initialDetail:o,initialEntry:r});vo.current={initialDetail:o,initialEntry:r},f.useEffect(()=>{let D=!1;const le=J=>{J.type==="collection"?ho(e):J.type==="work"?((J.has_collated||n.getCollatedEditionIndex)&&mo(e),(J.version_graph||n.getLineageGraph)&&jo(e,J),n.getWorkFullTextList&&yo(e)):J.type==="book"&&J.has_full_text&&n.getBookFullTextIndex&&bo(e)},ue=vo.current;let me=null;if(R&&R.id===e)me=R;else if(ue.initialDetail&&ue.initialDetail.id===e){const J={...ue.initialDetail},xe=ue.initialEntry??bn(e,J);b&&b(xe,J),me={entry:xe,detail:J}}return me?(U(!1),ee(J=>J.length?[]:J),V(null),re(null),ye(J=>J.length?[]:J),M(null),ne(null),Re.current=null,O(me.entry),X(me.detail),A(!1),le(me.detail),()=>{D=!0}):((async()=>{A(!0),U(!1),O(null),X(null),ee([]),V(null),re(null),ye([]),M(null),ne(null),Re.current=null;try{const J=await n.getItem(e);if(D)return;if(!J){U(!0);return}const xe=J;let Se=null;if(n.getEntry&&(Se=await n.getEntry(e),D))return;Se||(Se=bn(e,xe)),b&&b(Se,xe),O(Se),X(xe),le(xe)}catch{D||U(!0)}finally{D||A(!1)}})(),()=>{D=!0})},[e,n,R,b,ho,mo,jo,bo,yo]),f.useEffect(()=>{const D=Re.current;!D||!u||ne(Gt(D.work,D.books,u))},[u]);const ke=[];if(E){if(ke.push({key:"basic",label:W.detailTab.basicInfo}),E.type==="collection"){P&&G.length===0&&ke.push({key:"catalog:loading",label:`${W.detailTab.catalog}…`});for(const D of G)ke.push({key:`catalog:${D.resource_id}`,label:D.short_name?`${I(D.short_name)}${W.detailTab.catalogSuffix}`:W.detailTab.collectionCatalog})}E.type==="work"&&(Z||se)&&s==="collated"&&ke.push({key:"collated",label:se?`${W.detailTab.collatedEdition}…`:W.detailTab.collatedEdition}),E.type==="book"&&(H||ie)&&s==="fulltext"&&ke.push({key:"fulltext",label:ie?`${W.detailTab.fullText}…`:W.detailTab.fullText}),E.type==="work"&&(fe.length>0||Ce)&&s==="fulltext"&&ke.push({key:"fulltext",label:Ce?`${W.detailTab.fullText}…`:W.detailTab.fullText}),E.type==="work"&&(oe||he)&&ke.push({key:"lineage",label:he?`${W.detailTab.lineage}…`:W.detailTab.lineage});for(const D of z)(D.position??"before-feedback")==="before-feedback"&&D.shouldShow(E)&&ke.push({key:D.key,label:D.label});_&&s==="feedback"&&ke.push({key:"feedback",label:W.detailTab.feedback});for(const D of z)D.position==="after-feedback"&&D.shouldShow(E)&&ke.push({key:D.key,label:D.label})}f.useEffect(()=>{if(s!=="emendated"||!E)return;l("basic");const D=setTimeout(()=>{var le;(le=document.getElementById("studies"))==null||le.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(D)},[s,E,l]);const it=N&&E&&j?j({activeTab:s,activeJuan:He,entry:N,detail:E}):null,on=f.useMemo(()=>{var Ne;if(!E)return null;const le=(E.authors??[]).map(J=>{const xe=Yn(J.role);return`${J.dynasty?`〔${I(J.dynasty)}〕`:""}${I(J.name)}${xe?` ${I(xe)}`:""}`}).join(" · ");let ue=!1;try{ue=ae.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const J=E;return{title:I(J.title),subtitle:J.edition?I(J.edition):le||void 0,aside:[ue?W.status.draft:"",le&&J.edition?le:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const J=E;return{title:I(J.title),subtitle:I(Qe(J,W.unit.juan))||void 0,aside:[(Ne=J.publication_info)==null?void 0:Ne.year,ue?W.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:le||void 0}}if(E.type==="entity"){const J=E,xe=We=>We==null?"":We<0?`前${-We}`:String(We),Se=J.birth_year!=null||J.death_year!=null?`${xe(J.birth_year)||"?"}—${xe(J.death_year)||"?"}`:"";return{title:I(J.primary_name||J.title),subtitle:[J.dynasty?`〔${I(J.dynasty)}〕`:"",Se].filter(Boolean).join(" ")||void 0,aside:ue?W.status.draft:void 0,secondLine:void 0}}const me=I(Qe(E,W.unit.juan));return{title:I(E.title),subtitle:[me,le].filter(Boolean).join(" · ")||void 0,aside:[Zp(W,E.subtype),ue?W.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,I,W]),At=E?E.type==="work"?(((wo=Z==null?void 0:Z.juan_files)==null?void 0:wo.length)??0)>0?"collated":fe.length>0?"fulltext":null:E.type==="book"&&((H==null?void 0:H.chapters.length)??0)>0?"fulltext":null:null,ht=fe.find(D=>D.primary)??fe[0],_s=()=>{var D;At==="collated"&&((D=Z==null?void 0:Z.juan_files)!=null&&D.length)?(ot(Z.juan_files[0]),l("collated")):At==="fulltext"&&((E==null?void 0:E.type)==="work"&&ht&&M(ht.key),ot(null),l("fulltext"))};let mt=null;if(E&&w){const D=w({detail:E,kind:At,fullTextKey:E.type==="work"?ht==null?void 0:ht.key:void 0});D&&(mt=t.jsx(_n,{href:D}))}else At&&(mt=t.jsx(_n,{onClick:_s}));const zs=new Set(z.map(D=>D.key)),Mt=ke.filter(D=>D.key.startsWith("catalog:")&&D.key!=="catalog:loading"||zs.has(D.key)).map(D=>({key:D.key,label:D.label,onClick:()=>l(D.key)})),ko=()=>{var D;return E?E.type==="work"?t.jsx(ms,{data:E,transport:n,onNavigate:y,renderLink:v,readAction:mt,railTop:S,railLinks:Mt}):E.type==="book"?t.jsx(bs,{data:E,transport:n,onNavigate:y,renderLink:v,readAction:mt,railTop:S,railLinks:Mt}):E.type==="collection"?t.jsx(ys,{data:E,catalog:(D=G[0])==null?void 0:D.data,transport:n,onNavigate:y,renderLink:v,readAction:mt,railTop:S,railLinks:Mt,catalogAction:G.length>0?t.jsxs("a",{href:"#catalog",onClick:le=>{le.preventDefault(),l(`catalog:${G[0].resource_id}`)},children:[I(W.detailTab.collectionCatalog)," →"]}):null}):t.jsx(js,{data:E,transport:n,onNavigate:y,renderLink:v,railTop:S,railLinks:Mt}):null},$s=()=>{var le,ue,me,Ne;if(!N||!E)return null;if(s==="basic"||s==="emendated")return ko();if(typeof s=="string"&&s.startsWith("catalog:")){const J=(le=G.find(xe=>`catalog:${xe.resource_id}`===s))==null?void 0:le.data;return t.jsx(Dn,{data:J,onNavigate:y,renderLink:v})}if(s==="collated")return t.jsx(uo,{index:Z||void 0,workId:e,transport:n,onNavigate:y,activeJuan:He,onJuanChange:ot});if(s==="fulltext"&&E.type==="work"){const J=ce??((ue=fe[0])==null?void 0:ue.key);return J?t.jsx(Rn,{bookId:e,workKey:J,versions:fe,onVersionChange:xe=>{M(xe),ot(null)},transport:n,activeChapter:He,onChapterChange:ot},J):t.jsx("div",{style:{padding:24,color:i("desc-fg")},children:Ce?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(Rn,{index:H||void 0,bookId:e,transport:n,activeChapter:He,onChapterChange:ot});if(s==="lineage"){if(!oe)return t.jsx("div",{style:{color:i("label-fg"),padding:"24px 0"},children:he?"加載中…":"暫無版本圖數據"});const J=E.type==="work"?E:null;return t.jsx(ws,{graph:oe,renderLink:v,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:a,selectedNodeId:h,collection:u??((me=J==null?void 0:J.version_graph)==null?void 0:me.default_collection),onCollectionChange:x,collectionsAvailable:(Ne=J==null?void 0:J.version_graph)==null?void 0:Ne.collections,collectionCounts:(()=>{var _o,zo,$o,Co,Io,To,Ro;if(!J)return;const xe={},Se=((_o=Re.current)==null?void 0:_o.books)??[];xe.all=(((zo=J.books)==null?void 0:zo.length)??0)-(((Co=($o=J.version_graph)==null?void 0:$o.excluded_books)==null?void 0:Co.length)??0);const We=(Io=J.version_graph)==null?void 0:Io.collections;if(We)for(const Eo of Object.keys(We))xe[Eo]=Gt(J,Se,Eo).nodes.filter(Lo=>Lo.kind==="book"&&!Lo.bridge).length;return xe.core==null&&((Ro=(To=J.version_graph)==null?void 0:To.core_books)!=null&&Ro.length)&&(xe.core=J.version_graph.core_books.length),xe})()})}if(s==="feedback"&&_)return t.jsx(hs,{resourceId:e,apiUrl:T});const D=z.find(J=>J.key===s);return D?D.render({detail:E,entry:N,transport:n,onNavigate:y}):null};if(C)return t.jsx(_t,{style:{minHeight:B,...F},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((D,le)=>t.jsx("div",{style:{height:le===1?40:16,width:D,opacity:.35,background:i("rule")}},le))})});if(K||!E||!N||!on)return t.jsx(_t,{style:{minHeight:B,...F},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:i("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const rn=s==="basic"||s==="emendated",Ft=[{label:m??W.detailTab.backToIndex,onClick:k}];if(E.type==="book"&&E.work_id){const D=E.work_id;Ft.push({label:W.indexType.work,id:D,onClick:()=>y==null?void 0:y(D)})}Ft.push({label:W.indexType[E.type]});const Pt=s==="collated"||s==="fulltext",So=t.jsx(Er,{left:t.jsxs(t.Fragment,{children:[L,L?" · ":"",t.jsx(Jp,{id:E.id,label:W.label.id,copied:W.action.copied,copyLabel:W.action.copy})]}),right:t.jsxs(t.Fragment,{children:[_&&!rn&&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:W.detailTab.submitVersion}),it&&t.jsx("a",{href:it.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:i("meta-fg")},children:W.detailTab.dataLicense})]})});return rn?t.jsx("div",{className:$,children:t.jsxs(_t,{grid:!0,style:{minHeight:B,...F},children:[t.jsx(zn,{breadcrumb:t.jsx($n,{items:Ft}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Nn,{style:{border:"none",background:"transparent"}}),it&&t.jsx(Wn,{...it})]})}),ko(),So]})}):t.jsx("div",{className:$,children:t.jsxs(_t,{wide:Pt,style:{minHeight:B,...F},children:[t.jsx(zn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Kn,{char:"籍"}),t.jsx($n,{items:Ft})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Nn,{}),_&&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:W.detailTab.feedback}),it&&t.jsx(Wn,{...it})]})}),t.jsx(Sr,{...on,aside:Pt?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:[I("作品信息")," →"]}):on.aside}),!Pt&&ke.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:ke.map(D=>t.jsx(wr,{label:D.label,active:D.key===s||rn&&D.key==="basic",onClick:()=>l(D.key)},D.key))}),t.jsx("div",{style:{marginTop:!Pt&&ke.length>1?8:0},children:$s()}),So]})})};function Jp({id:e,label:n,copied:o,copyLabel:r}){const[s,l]=f.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var p;(p=navigator.clipboard)==null||p.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 Zp(e,n){return n?e.workSubtype[n]??n:""}exports.BidLink=ae.BidLink;exports.BookIndexError=ae.BookIndexError;exports.BookIndexManager=ae.BookIndexManager;exports.BookIndexStorage=ae.BookIndexStorage;exports.BundleStorage=ae.BundleStorage;exports.ConfigError=ae.ConfigError;exports.GithubStorage=ae.GithubStorage;exports.IdGenerationError=ae.IdGenerationError;exports.IdGenerator=ae.IdGenerator;exports.LocalStorage=ae.LocalStorage;exports.MigrationError=ae.MigrationError;exports.StorageError=ae.StorageError;exports.base36Decode=ae.base36Decode;exports.base36Encode=ae.base36Encode;exports.base58Decode=ae.base58Decode;exports.buildId=ae.buildId;exports.buildPromotionMap=ae.buildPromotionMap;exports.cleanName=ae.cleanName;exports.decodeId=ae.decodeId;exports.decodeIdString=ae.decodeIdString;exports.encodeId=ae.encodeId;exports.extractIdFromUrl=ae.extractIdFromUrl;exports.extractStatus=ae.extractStatus;exports.extractType=ae.extractType;exports.normalizeCatalog=ae.normalizeCatalog;exports.parseId=ae.parseId;exports.shardOf=ae.shardOf;exports.smartDecode=ae.smartDecode;exports.validateResource=ae.validateResource;exports.Badge=Yt;exports.BidUrlProvider=As;exports.BookDetailLayout=qp;exports.BookFullText=Rn;exports.BookPage=bs;exports.Breadcrumb=$n;exports.CardFoot=Nt;exports.CheckFilter=vr;exports.Chip=_r;exports.ChipWall=ja;exports.CollatedEdition=uo;exports.CollectionCatalog=Dn;exports.CollectionPage=ys;exports.CreateEntityDialog=as;exports.DEFAULT_READER_PREFS=Zn;exports.DETAIL_CSS=kr;exports.Dash=za;exports.DataTable=ka;exports.DetailFooter=Er;exports.DetailGrid=Lt;exports.DetailHeader=Sr;exports.EmendatedBySection=ir;exports.EmptyNote=La;exports.EntityDetail=Xi;exports.EntityPage=js;exports.EntityPickerDialog=ds;exports.EntitySelector=ls;exports.ExpandRow=$a;exports.ExtLink=Ba;exports.FEEDBACK_FAB_OFFSET_VAR=Ln;exports.FONT_SIZE_STEPS=ct;exports.FactList=ha;exports.FeedbackButton=ep;exports.FeedbackDialog=fs;exports.FeedbackForm=gs;exports.FeedbackList=xo;exports.FeedbackTab=hs;exports.FilterChip=wr;exports.FormInput=_e;exports.FormTextArea=Ze;exports.GUJI_MARKDOWN_FIELD=na;exports.GUJI_TABLE_NOTATION=Pr;exports.GlyphBadge=Kn;exports.GujiTable=to;exports.HomePage=Tn;exports.ImagePanel=Ar;exports.IndexApp=id;exports.IndexBrowser=vn;exports.IndexDetail=Hn;exports.IndexEditor=ps;exports.IndexView=Od;exports.IntroGrid=ga;exports.LocaleContext=xt;exports.LocaleProvider=Ys;exports.LocaleToggle=Nn;exports.MetaLine=Te;exports.ModeIndicator=qi;exports.MoreButton=ya;exports.MoreLink=gt;exports.PAGE_MAX_WIDTH=wt;exports.PageFrame=_t;exports.Quote=Ia;exports.READER_CSS=Br;exports.ROLE_CLASS_ORDER=ur;exports.ReadButton=_n;exports.ReaderMdText=ro;exports.ReaderShell=Qn;exports.ReaderToc=Wr;exports.RelationPanel=rs;exports.RepoSourceLink=Wn;exports.ResourceEditor=jn;exports.ResourceGroup=Ta;exports.ResourceLine=Ra;exports.ResourceList=On;exports.ResourceRow=Tr;exports.SNIPPET_MARK_END=Hi;exports.SNIPPET_MARK_START=Oi;exports.SearchInput=Ji;exports.Sec=ze;exports.Section=Ee;exports.SectionHead=ma;exports.SideList=at;exports.SmartBidInput=Dt;exports.SourceEditor=ns;exports.SummaryCard=Bt;exports.TabFilter=en;exports.TableHead=Sa;exports.TableRow=wa;exports.TagRow=Rr;exports.TagRows=Ea;exports.TextButton=ba;exports.TopStrip=zn;exports.VersionLineageGraph=Ss;exports.VersionLineageList=ks;exports.VersionLineageView=ws;exports.VolumeChips=va;exports.VolumeLinks=qn;exports.WorkCatalog=sd;exports.WorkPage=ms;exports.bucketResources=Xt;exports.buildCollectionTable=fr;exports.buildLineageGraph=Gt;exports.buildPageUrl=Pn;exports.buildParagraphBlocks=Kr;exports.buildVersionRow=dr;exports.buildVersionTable=pr;exports.canParagraphize=nn;exports.computeVersionPartition=Xl;exports.deriveDating=ql;exports.deriveEditionType=hr;exports.deriveEra=Rt;exports.deriveYear=Zt;exports.deriveYearRange=Vn;exports.detailToEditor=xs;exports.detectGenre=tn;exports.displayAuthorRole=Yn;exports.editorToDetail=Pd;exports.eraRank=Sn;exports.flattenTitles=Cn;exports.flattenToc=Fr;exports.formatTemplate=Tt;exports.formatVolumeRange=Qt;exports.getDisplayNameFromUrl=et;exports.getStartPage=Fn;exports.getTypeGroupKey=An;exports.groupRelatedWorks=Jl;exports.gujiInlineToPlain=yr;exports.hasGujiMarkdownV02=wn;exports.hasGujiTableNotation=Or;exports.measureText=Qe;exports.mergeVolumeResources=Mn;exports.normalizeEra=be;exports.normalizeRole=Un;exports.normalizeVolumeIndex=$t;exports.normalizeVolumes=Ki;exports.numberToChinese=gr;exports.parseChineseNumber=Vt;exports.parseGujiInline=br;exports.parseGujiTable=Dr;exports.parseSourceString=os;exports.renderFullTextBody=oc;exports.renderProperNames=Jr;exports.renderReaderInline=io;exports.resourceHref=ft;exports.resourceNote=Et;exports.roleFacets=xr;exports.rowNo=_a;exports.sortYear=ar;exports.splitFullTextTables=eo;exports.splitHighlightSnippet=Di;exports.splitTableRow=Hr;exports.stringifySources=is;exports.useBidUrl=je;exports.useConvert=Y;exports.useReaderPrefs=Xn;exports.useT=te;exports.validateLineageGraph=zp;exports.volumeStats=Kt;
|
|
559
|
+
`;function ei(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(r=>ei(r,n))):!1}const Qa=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function ec({item:e,activeKey:n,onSelect:i,tabKey:r}){const s=ei(e,n),[l,p]=f.useState(s||!!e.defaultExpanded);return f.useEffect(()=>{s&&p(!0)},[s]),f.useEffect(()=>{e.defaultExpanded&&p(!0)},[e.defaultExpanded]),t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>p(d=>!d),children:[t.jsx(Qa,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Gr,{items:e.children,activeKey:n,onSelect:i,tabKey:r})]})}function Gr({items:e,activeKey:n,onSelect:i,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(ec,{item:s,activeKey:n,onSelect:i,tabKey:r},s.key):t.jsx("li",{children:t.jsxs("button",{type:"button",className:"bim-rd-ti","aria-current":s.key===n?"true":void 0,disabled:s.disabled,"data-rd-toc-key":s.key,tabIndex:r===s.key?0:-1,onClick:()=>i(s.key),children:[t.jsx("span",{children:s.label}),s.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:s.hint})]})},s.key))})}function so(e,n){var i;for(const r of e)if(r.key===n||ei(r,n))return r.key;return((i=e[0])==null?void 0:i.key)??null}function Ur({items:e,activeKey:n,onSelect:i,label:r="目录"}){const s=f.useRef(null),[l,p]=f.useState(null);f.useEffect(()=>{p(null)},[n]);const d=f.useMemo(()=>l||(n??so(e,n)),[l,n,e]);f.useEffect(()=>{const a=s.current;if(!a)return;const u=Array.from(a.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const x=u.find(g=>g.dataset.rdTocKey===d)??u.find(g=>g.dataset.rdTocKey===so(e,n))??u.find(g=>!g.disabled)??u[0];for(const g of u)g.tabIndex=g===x?0:-1}),f.useEffect(()=>{const a=s.current,u=a==null?void 0:a.closest(".bim-rd-toc");if(!a||!u||!n)return;const x=Array.from(a.querySelectorAll("[data-rd-toc-key]")).find(h=>h.dataset.rdTocKey===n);if(!x)return;const g=x.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(g<u.scrollTop+80||g>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,g-u.clientHeight/3))},[n]);const c=f.useCallback(a=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(a.key))return;const x=s.current;if(!x)return;const g=Array.from(x.querySelectorAll("[data-rd-toc-key]")).filter(m=>!m.disabled),h=g.indexOf(document.activeElement);let b=h;if(a.key==="ArrowDown"?b=Math.min(g.length-1,h+1):a.key==="ArrowUp"?b=Math.max(0,h-1):a.key==="Home"?b=0:a.key==="End"&&(b=g.length-1),b<0||b===h)return;a.preventDefault();const k=g[b];for(const m of g)m.tabIndex=-1;k.tabIndex=0,k.focus(),p(k.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:c,children:t.jsx(Gr,{items:e,activeKey:n,onSelect:i,tabKey:d})})}function tc({page:e}){var n;return!((n=e.boxes)!=null&&n.length)||!e.width||!e.height||e.boxFormat&&e.boxFormat!=="bim-charbox-v0"?null:t.jsx("svg",{viewBox:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:e.boxes.map((i,r)=>t.jsx("rect",{x:i.x,y:i.y,width:i.w,height:i.h,fill:"none",stroke:o("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},r))})}function Vr({pages:e,loading:n,page:i,onPageChange:r,renderOverlay:s}){const[l,p]=f.useState(0),d=i??l,c=g=>{r?r(g):p(g)};if(f.useEffect(()=>{i===void 0&&p(0)},[e,i]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:"加载书影…"})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:"暂无书影"}),t.jsx("span",{children:"这一卷还没有配上影像;接入后在此与正文逐页对看"})]})});const a=Math.max(0,Math.min(e.length-1,d)),u=e[a],x=u.label??`${a+1}`;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${x} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(tc,{page:u}),s==null?void 0:s(u,a)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:a===0,onClick:()=>c(a-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${a+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:a===e.length-1,onClick:()=>c(a+1),children:"›"})]})]})}const ti={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal"},dt=[15,16,17,18,20,22,24],En=18,Yr="bim-reader-prefs",nc="bim-reading-mode";function ic(){const e={...ti};try{const n=localStorage.getItem(Yr),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&dt.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(nc))==="paragraph"&&(e.readingMode="paragraph"),i.properNames===!0&&(e.properNames=!0),i.writingMode==="vertical"&&(e.writingMode="vertical")}catch{}return e}function oc(e){try{localStorage.setItem(Yr,JSON.stringify(e))}catch{}}function lo(e,n){const i=e??En,r=dt;let s=r.indexOf(i);return s<0&&(s=r.indexOf(En)),r[Math.max(0,Math.min(r.length-1,s+n))]}function ni(){const[e,n]=f.useState(ti);f.useEffect(()=>{n(ic())},[]);const i=f.useCallback(r=>{n(s=>{const l={...s,...r};return oc(l),l})},[]);return[e,i]}function rc(e){return e.map(n=>({key:n.key,label:n.version_label||n.key,sourceName:n.source_name,license:n.license,sourceUrl:n.source_url,primary:n.primary}))}function Ln(e){const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function Kr(e,n){if(!(!e||e.length===0))return(n!=null?e.find(i=>i.key===n):void 0)??e.find(i=>i.primary)??e[0]}function qr(e){const n=[],i=r=>{for(const s of r)s.children&&s.children.length>0?i(s.children):n.push(s)};return i(e),n}const sc=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),lc=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),t.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function ac(e,n){if(!n)return;const i=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(p=>p.tabIndex>=0);if(i.length===0)return;const r=i[0],s=i[i.length-1],l=document.activeElement;e.shiftKey&&(l===r||!n.contains(l))?(e.preventDefault(),s.focus()):!e.shiftKey&&(l===s||!n.contains(l))&&(e.preventDefault(),r.focus())}function cc(e,n){const[i,r]=f.useState(n);return f.useEffect(()=>{var p;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(s.matches);return(p=s.addEventListener)==null||p.call(s,"change",l),()=>{var d;return(d=s.removeEventListener)==null?void 0:d.call(s,"change",l)}},[e]),i}function dc(){const e=f.useContext(mt);if(!e)return null;const n=e.locale==="zh-Hant";return t.jsxs("button",{type:"button",className:"bim-rd-t",title:n?"切换为简体":"切換為繁體","aria-label":n?"切换为简体":"切換為繁體",onClick:()=>e.setLocale(n?"zh-Hans":"zh-Hant"),children:[t.jsx("span",{className:n?"bim-rd-on":"bim-rd-off",children:"繁"}),t.jsx("span",{className:"bim-rd-off",children:"|"}),t.jsx("span",{className:n?"bim-rd-off":"bim-rd-on",children:"简"})]})}function ii({title:e,subtitle:n,toc:i,activeKey:r,onSelect:s,tocHeader:l,tocCaption:p,images:d,imagesLoading:c,renderImageOverlay:a,imagePanel:u="auto",prefs:x,onPrefsChange:g,paragraphToggle:h,properNameToggle:b=!0,allowVertical:k,pager:m=!0,versions:v,currentVersionKey:y,onVersionChange:j,versionSource:$=!0,children:S,className:_,style:w}){const z=f.useId().replace(/:/g,""),B=`bim-rd-toc-${z}`,E=`bim-rd-text-${z}`,C=f.useRef(null),A=f.useRef(null),W=f.useRef(null),T=f.useRef(null),L=cc(Or,!0),[M,P]=f.useState("auto"),R=M==="auto"?L:M==="open",ne=!L,I=!!d&&d.length>0,[F,K]=f.useState(u);f.useEffect(()=>{K(u)},[u]);const G=F==="auto"?I||!!c:F==="open",U=f.useCallback(q=>{var N;P("auto"),q&&((N=T.current)==null||N.focus())},[]),te=()=>P(R?"closed":"open");f.useEffect(()=>{if(!ne||M!=="open")return;const q=W.current,N=q==null?void 0:q.querySelector('input, [data-rd-toc-key][tabindex="0"]');N==null||N.focus()},[ne,M]);const O=f.useCallback(q=>{s(q),ne&&U(!1);const N=A.current,ee=C.current;if(N&&ee&&typeof window<"u"){const re=N.getBoundingClientRect().top-ee.getBoundingClientRect().bottom;re<0&&window.scrollBy({top:re})}},[s,ne,U]),Y=f.useMemo(()=>qr(i),[i]),[Z,X]=f.useState(null),se=Kr(v,y!==void 0?y:Z),ge=(se==null?void 0:se.key)??null,he=f.useMemo(()=>Y.map(q=>q.key).join(`
|
|
560
|
+
`),[Y]),D=f.useRef(null),le=q=>{q!==ge&&(D.current={key:q,sig:he,done:!1},y===void 0&&X(q),j==null||j(q))};f.useEffect(()=>{const q=D.current;if(!q||q.key!==ge)return;const N=Y.find(re=>!re.disabled);if(!N)return;const ee=he!==q.sig;!ee&&q.done||(ee?D.current=null:q.done=!0,N.key!==r&&O(N.key))},[ge,he,Y,r,O]);const oe=Y.findIndex(q=>q.key===r),ce=oe>0?Y.slice(0,oe).reverse().find(q=>!q.disabled):void 0,ue=oe>=0?Y.slice(oe+1).find(q=>!q.disabled):void 0,me=x.fontSize??En,Q={...w,...x.fontSize?{"--bimrd-fs":`${x.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",x.writingMode==="vertical"&&k?"bim-rd-vertical":"",_].filter(Boolean).join(" "),"data-toc":M,"data-img":G?"open":"closed",style:Q,children:[t.jsx("style",{children:Hr}),t.jsx("a",{className:"bim-rd-skip",href:`#${E}`,onClick:q=>{var N,ee,re;q.preventDefault(),(N=A.current)==null||N.focus(),(re=(ee=A.current)==null?void 0:ee.scrollIntoView)==null||re.call(ee,{block:"start"})},children:"跳到正文"}),t.jsxs("div",{className:"bim-rd-bar",ref:C,children:[(e||n)&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),n&&t.jsx("span",{children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":"阅读设置",children:[v&&v.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:se?Ln(se):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:"版本"}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:"版本▾"}),t.jsx("select",{"aria-label":"版本",value:ge??"",onChange:q=>le(q.target.value),children:v.map(q=>t.jsx("option",{value:q.key,children:Ln(q)},q.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),t.jsxs("button",{ref:T,type:"button",className:"bim-rd-t","aria-expanded":R,"aria-controls":B,onClick:te,children:[t.jsx(sc,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":G,onClick:()=>K(G?"closed":"open"),children:[t.jsx(lc,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(dc,{}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"缩小字号",disabled:me<=dt[0],onClick:()=>g({fontSize:lo(x.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"放大字号",disabled:me>=dt[dt.length-1],onClick:()=>g({fontSize:lo(x.fontSize,1)}),children:"A+"}),(h||b||k)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),h&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":x.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>g({readingMode:x.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),b&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":x.properNames,title:"书名加波浪线",onClick:()=>g({properNames:!x.properNames}),children:"专名线"}),k&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":x.writingMode==="vertical",onClick:()=>g({writingMode:x.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:B,ref:W,role:ne&&R?"dialog":void 0,"aria-modal":ne&&R?!0:void 0,"aria-label":ne&&R?"目录":void 0,onKeyDown:q=>{if(!(!ne||!R)){if(q.key==="Escape"){q.stopPropagation(),U(!0);return}q.key==="Tab"&&ac(q,W.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:p??"目录"}),ne&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>U(!0),children:"✕"})]}),l]}),t.jsx(Ur,{items:i,activeKey:r,onSelect:O})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>U(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:G&&t.jsx(Vr,{pages:d??null,loading:c,renderOverlay:a})}),t.jsx("div",{className:"bim-rd-text",id:E,ref:A,tabIndex:-1,children:t.jsxs("div",{className:"bim-rd-col",children:[S,$&&se&&(se.sourceName||se.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":se.key,children:[se.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",se.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:se.sourceUrl,target:"_blank",rel:"noreferrer",children:se.sourceName}):se.sourceName]}),se.sourceName&&se.license&&t.jsx("span",{className:"bim-rd-dot"}),se.license&&t.jsxs(t.Fragment,{children:["授权 ",se.license]})]}),m&&(ce||ue)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[t.jsx("span",{children:ce&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>O(ce.key),children:["‹ ",ce.label]})}),t.jsx("span",{children:ue&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>O(ue.key),children:[ue.label," ›"]})})]})]})})]})]})}const Jr="guji-table-v1";function Zr(e){return!!e&&e.table_notation===Jr}const pc=/^:::table(?:\{[^}]*\})?[ \t]*$/,uc=/^:::[ \t]*$/;function Xr(e){const n=[];let i="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const p=wr(e,r+3);if(p>r+4){i+=e.slice(r,p+1),r=p;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const p=e[r+1];p!==void 0&&!/[A-Za-z/!?>\s]/.test(p)&&(l=">")}if(l){const p=e.indexOf(l,r+1);if(p>0){i+=e.slice(r,p+1),r=p;continue}}s==="|"?(n.push(i),i=""):i+=s}return n.push(i),n.map(r=>r.trim())}const xc=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function fc(e){if(e==="^")return{cont:!0};const n=xc.exec(e),i=n[1].trim(),r=n[2]?Math.max(1,parseInt(n[2],10)):1,s=n[3]?Math.max(1,parseInt(n[3],10)):1,l=i==="_";return{cont:!1,cell:{text:l?"":i,empty:l,colspan:r,rowspan:s}}}function Qr(e,n=1){const i=[],r=[],s=[];let l=[];e.forEach((d,c)=>{const a=c+n+1;let u=d.trim();if(!u)return;let x=!1;u.startsWith("!")&&(x=!0,u=u.slice(1));const g=Xr(u).map(fc),h=l.map(v=>v>0),b=l.map(v=>v>0?v-1:0),k=[];let m=0;for(const v of g){if(v.cont){h[m]||i.push(`第 ${a} 行第 ${m+1} 列:续格 ^ 上方没有跨行格`),m+=1;continue}const{cell:y}=v;for(let j=m;j<m+y.colspan;j++)if(h[j]){i.push(`第 ${a} 行第 ${j+1} 列:此处被上方跨行格占住,应写 ^`);break}if(y.rowspan>1)for(let j=m;j<m+y.colspan;j++)b[j]=y.rowspan-1;k.push(y),m+=y.colspan}for(let v=m;v<h.length;v++)h[v]&&i.push(`第 ${a} 行第 ${v+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let v=0;v<b.length;v++)b[v]===void 0&&(b[v]=0);l=b,r.push({header:x,cells:k}),s.push({width:m,line:a})});const p=s.reduce((d,c)=>Math.max(d,c.width),0);for(const d of s)d.width!==p&&i.push(`第 ${d.line} 行:占 ${d.width} 列,与总列数 ${p} 不符`);return l.some(d=>d>0)&&i.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&i.push("空表"),{rows:r,columns:p,warnings:i}}function oi(e){const n=e.split(`
|
|
561
|
+
`),i=[];let r=[];const s=()=>{if(r.length===0)return;const p=r.join(`
|
|
562
|
+
`);r=[],i.push({type:"text",text:p})};let l=0;for(;l<n.length;){if(pc.test(n[l].trim())){let p=l+1;for(;p<n.length&&!uc.test(n[p].trim());)p++;if(p<n.length){s();const d=n.slice(l+1,p);i.push({type:"table",table:Qr(d,l+1),source:n.slice(l,p+1).join(`
|
|
563
|
+
`)}),l=p+1;continue}}r.push(n[l]),l++}return s(),i.map((p,d)=>{var a,u;if(p.type!=="text")return p;let c=p.text;return((a=i[d-1])==null?void 0:a.type)==="table"&&(c=c.replace(/^\n+/,"")),((u=i[d+1])==null?void 0:u.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(p=>p.type!=="text"||p.text!=="")}const gc={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},hc={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},mc=`1px solid ${o("table-border")}`,es={border:mc,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},bc={...es,background:o("table-head-bg"),fontWeight:600};function ri({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:gc,children:t.jsx("table",{className:"bim-guji-table",style:hc,children:t.jsx("tbody",{children:e.rows.map((i,r)=>t.jsx("tr",{children:i.cells.map((s,l)=>{const p=i.header?"th":"td";return t.jsx(p,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:i.header?bc:es,children:s.empty?null:Ie(s.text,void 0,n)},l)})},r))})})})}function yc(e,n){return e.indexOf("**")<0?Ie(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:Ie(r.trim().slice(2,-2),void 0,n)},s):t.jsx(f.Fragment,{children:Ie(r,void 0,n)},s))}function jc(e,n,i=!1){const r=i?{gujiMarkdown:!0}:void 0;return n?oi(e).map((s,l)=>s.type==="table"?t.jsx(ri,{table:s.table,opts:r},l):t.jsx(f.Fragment,{children:yc(s.text,r)},l)):Ie(e,void 0,r)}const vc=/^(#{1,6})\s+(.*)$/,kc=/^\*\*([^*\n]+)\*\*\s*$/;function si(e){const n=e.match(vc);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(kc);return i?{level:3,text:i[1].trim()}:null}const li=/^<!--.*-->$/;function ts(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function ns(e){return e.split(`
|
|
564
|
+
`).map(n=>n.trim()).filter(n=>n&&!li.test(n))}const Sc=60;function is(e){let n=0,i=0;for(const r of e.split(`
|
|
565
|
+
`)){const s=r.trim();if(!s||li.test(s)||si(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>Sc&&(i+=l)}return n>0&&i*2>=n}function wc(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function sn(e){if(e=wc(e),is(e))return"unknown";const n=ts(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>ns(s).length).filter(s=>s>0);if(i.length===0)return"unknown";const r=i.reduce((s,l)=>s+l,0)/i.length;return r<=4?"record":r>=8?"catalog":"unknown"}function _c(e){const n=e.split(`
|
|
566
|
+
`),i=[];let r=null,s=[];const l=()=>{i.push({heading:r,body:s.join(`
|
|
567
|
+
`)}),s=[]};for(const p of n){const d=si(p);if(d){l(),r={kind:"heading",level:d.level,text:d.text};continue}s.push(p)}return l(),i}function ao(e){const n=[];for(const i of e.split(`
|
|
568
|
+
`)){const r=si(i);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=i.trim();!s||li.test(s)||n.push({kind:"body",text:i})}return n}function os(e){if(!e)return[];const n=sn(e);if(n==="unknown")return ao(e);const i=[];for(const{heading:r,body:s}of _c(e)){r&&i.push(r);const l=ts(s);if(l.length!==0){if(is(s)){i.push(...ao(s));continue}if(n==="record"){const p=l.join(" ");p&&i.push({kind:"body",text:p})}else for(const p of l){const d=ns(p);d.length&&i.push({kind:"body",text:d.join(" ")})}}}return i}const rs=e=>e;function ss(e,n=rs){if(e.indexOf("《")<0)return n(e);const i=[],r=/《([^《》\n]+)》/g;let s=0,l=0,p;for(;p=r.exec(e);)p.index>s&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s,p.index))},l++)),i.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(p[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=p.index+p[0].length;return s===0?n(e):(s<e.length&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),i)}function ai(e,n={}){const i=n.renderText??rs,r=n.properNames?l=>ss(l,i):i,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Ie(e,r,s)}function co(e,n,i){return e.indexOf("**")<0?n(e):e.split(/(\*\*[^*]+\*\*)/g).map((s,l)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?t.jsx("strong",{children:n(s.slice(2,-2))},`${i}-${l}`):t.jsx(f.Fragment,{children:n(s)},`${i}-${l}`))}const gn=/^(#{1,6})\s+(.*)$/,$c=/^\s*<!--.*-->\s*$/;function ls(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
|
|
569
|
+
`)?"":n)}function zc(e){return e<=1?2:e===2?3:4}function Cc(){let e=1;return n=>{const i=zc(n),r=Math.min(i,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${i}`}}}function ln(e){return e?sn(ls(e))!=="unknown":!1}function po({text:e,mode:n,inline:i,dropTitle:r}){const s=ls(e),l=(a,u,x)=>!!r&&x<=1&&a<=2&&u.trim()===r.trim(),p=Cc();if(n==="paragraph"&&sn(s)!=="unknown"){const a=os(s);return t.jsx(t.Fragment,{children:a.map((u,x)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,x))return null;const{Tag:g,className:h}=p(u.level??1);return t.jsx(g,{className:h,children:i(u.text)},x)}return t.jsx("p",{children:co(u.text,i,x)},x)})})}const d=s.split(`
|
|
570
|
+
`);let c=0;return t.jsx(t.Fragment,{children:d.map((a,u)=>{const x=a.match(gn);if(x){const h=c++;if(l(x[1].length,x[2],h))return null;const{Tag:b,className:k}=p(x[1].length);return t.jsx(b,{className:k,children:i(x[2])},u)}if(!a.trim())return u>=2&&!!d[u-1].trim()&&!!d[u-2].trim()&&!gn.test(d[u-1])&&!gn.test(d[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if($c.test(a))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(a.trim())){const{Tag:h,className:b}=p(3);return t.jsx(h,{className:b,children:i(a.trim().slice(2,-2))},u)}return t.jsx("p",{children:co(a,i,u)},u)})})}function Ic(e){const{convert:n}=V();return f.useMemo(()=>e?n(e):"",[e,n])}function ci({text:e,mode:n,tables:i=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:p}){const d=Ic(e),{convert:c}=V(),a=g=>ai(g,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,x=p?c(p):void 0;return!i||d.indexOf(":::")<0?t.jsx(po,{text:d,mode:n,inline:a,dropTitle:x}):t.jsx(t.Fragment,{children:oi(d).map((g,h)=>g.type==="table"?t.jsx(ri,{table:g.table,opts:u},h):t.jsx(po,{text:g.text,mode:n,inline:a,dropTitle:h===0?x:void 0},h))})}function as(e,n){const[i,r]=f.useState(null),[s,l]=f.useState(!1),p=f.useRef(0);return f.useEffect(()=>{const d=++p.current;if(!e||!n){r(null),l(!1);return}let c;try{c=e(n)}catch{r(null),l(!1);return}if(!c||typeof c.then!="function"){r(c??null),l(!1);return}l(!0),c.then(a=>{d===p.current&&r(a??null)}).catch(()=>{d===p.current&&r(null)}).finally(()=>{d===p.current&&l(!1)})},[e,n]),{images:i,loading:s}}const uo={A:"fine",B:"rough",C:"rough",D:"ocr"};function Tc(e){return typeof e!="string"?null:e in kn?e:e in uo?uo[e]:null}const Rc={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Ec={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function Oe(e){return typeof e!="string"?"":Rc[e]??Ec[e]??e}const Lc=["〇","一","二","三","四","五","六","七","八","九"],xo=["","十","百","千"],Nc=["","萬","億"];function di(e){if(e===0)return"〇";if(e<0)return`負${di(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(Bc(s,r>0)+Nc[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Bc(e,n){const i=[];let r=e;for(;r>0;)i.unshift(r%10),r=Math.floor(r/10);let s="";for(let l=0;l<i.length;l++){const p=i[l],d=i.length-1-l;p===0?s&&!s.endsWith("〇")&&(s+="〇"):p===1&&d===1&&l===0&&!n?s+=xo[d]:s+=Lc[p]+xo[d]}return s.replace(/〇$/,"")}let Et=null,Ut=null;const Jt=new Set;function Wc(){return Et?Promise.resolve():Ut||(Ut=import("opencc-js/t2cn").then(e=>{Et=e.Converter({from:"tw",to:"cn"}),Jt.forEach(n=>n())}).catch(()=>{Et=e=>e,Jt.forEach(e=>e())}),Ut)}const Ac=e=>e;function it(){const[,e]=f.useState(0);return f.useEffect(()=>{if(Et)return;const n=()=>e(i=>i+1);return Jt.add(n),Wc(),()=>{Jt.delete(n)}},[]),Et??Ac}function gt(e,n){return n(e).toLowerCase()}const Mc=o("highlight-bg");function Ft(e,n,i){if(!n)return e;const r=gt(n,i);if(!r)return e;const s=gt(e,i);if(s.length!==e.length)return e;const l=[];let p=0,d=0;for(;p<e.length;){const c=s.indexOf(r,p);if(c===-1){l.push(e.slice(p));break}c>p&&l.push(e.slice(p,c)),l.push(t.jsx("mark",{style:{background:Mc,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},d++)),p=c+r.length}return t.jsx(t.Fragment,{children:l})}function pi(e,n,i,r){if(!n)return!0;const s=gt(n,r);return(i?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(p=>typeof p=="string"&>(p,r).includes(s))}function Fc(e,n,i){return n?gt(e,i).includes(gt(n,i)):!0}const ui={类:o("section-lei"),书:o("section-shu"),序:o("section-xu"),结语:o("section-jieyu"),注释:o("section-zhushi")},Pc={考证:o("section-kaozhen")};function Oc(e){const n=e.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function cs(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((s,l)=>s+cs(l),0))||0;return n+i}function Dc(e,n){const i=[],r=p=>{var d;i.push(...p.files),(d=p.children)==null||d.forEach(r)};if(r(e),i.length===0)return;const s=i.map(p=>n[p]);if(s.every(p=>p===void 0))return;if(s.some(p=>p==="loading"))return"loading";let l=0;for(const p of s)typeof p=="number"&&(l+=p);return l}const Hc={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function xi({enabled:e,expanded:n,onClick:i,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...Hc,...r},children:s}):t.jsx("span",{style:r,children:s})}function Gc({type:e}){const n=Oe(e),i=ui[n]||o("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:i,border:`1px solid ${i}40`,borderRadius:"2px",background:`${i}08`,flexShrink:0},children:n})}function Uc({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=V(),s=ve(),l=it(),p=k=>k?Ie(r(k),m=>i?Ft(m,i,l):m):"",[d,c]=f.useState(!1),a=!!e.summary,u=!!e.comment,x=!!e.additional_comment,g=!!(e.content&&e.content.length>60),h=a||u||x||g;f.useEffect(()=>{i&&c(!0)},[i]);const b=!d&&g?Br(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[t.jsxs("div",{onClick:()=>h&&c(!d),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:h?"pointer":"default",userSelect:"none",background:o("input-bg")},children:[t.jsxs(xi,{enabled:h,expanded:d,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[h&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",p(e.book_title),"》"]}):p(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[di(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:p(e.author_info||e.author)})]}),!d&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:p(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:p(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:o("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:s(e.work_id),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),d&&h&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${o("widget-border")}`,background:o("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"8px"},children:p(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:p(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:p(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:p(e.additional_comment)})]}),g&&!a&&!u&&!x&&t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:p(e.content)})]})]})}function Vc({section:e,highlightQuery:n=""}){const{convert:i}=V(),r=it(),s=c=>c?Ie(i(c),a=>n?Ft(a,n,r):a):"",[l,p]=f.useState(!1),d=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(xi,{enabled:d,expanded:l,onClick:()=>p(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:d?"pointer":"default",userSelect:"none"},children:[t.jsx(Gc,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:s(e.title)}),d&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&d&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${ui[Oe(e.type)]||o("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:o("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(e.content)})})]})}const Yc=100;function fi(e){return Oe(e.type)!=="page_header"?!1:(e.content||"").length>=Yc}function Kc({section:e,highlightQuery:n=""}){const{convert:i}=V(),r=it();if(Oe(e.type)==="page_header"&&!fi(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
571
|
+
`)),l=Ie(s,a=>n?Ft(a,n,r):a),p=Oe(e.type),d=ui[p]||o("desc-fg"),c=p==="序"||p==="结语"||p==="注释";return t.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:o("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${d}40`:void 0,background:c?o("bg"):void 0,borderRadius:c?"0 4px 4px 0":void 0,position:"relative"},children:[c&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:d,marginRight:"8px",padding:"1px 5px",border:`1px solid ${d}40`,borderRadius:"2px",background:`${d}08`,verticalAlign:"middle"},children:p}),l]})}function qc(e,n,i){const[r,s]=f.useState({});return f.useEffect(()=>{var a;if(!n||e.length===0)return;let l=!1;const p=e.filter(u=>{var x;return!((x=i==null?void 0:i.current)!=null&&x.has(u))}),d={};for(const u of e)(a=i==null?void 0:i.current)!=null&&a.has(u)&&(d[u]=i.current.get(u));if(Object.keys(d).length>0&&s(d),p.length===0)return;const c=async u=>{var x;try{if(n.getEntry){const m=await n.getEntry(u);if(m)return{title:m.title,author:m.author}}const g=await n.getItem(u);if(!g)return null;const h=g.title||u,b=g.authors,k=(x=b==null?void 0:b[0])==null?void 0:x.name;return{title:h,author:k}}catch{return null}};return Promise.all(p.map(async u=>{var g;const x=await c(u);return(g=i==null?void 0:i.current)==null||g.set(u,x),[u,x]})).then(u=>{l||s(x=>{const g={...x};for(const[h,b]of u)g[h]=b;return g})}),()=>{l=!0}},[e.join(","),n]),r}function Jc({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=V(),p=ve(),d=it(),c=y=>y?Ie(l(y),j=>s?Ft(j,s,d):j):"",[a,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const x=Oe(e.type),g=Pc[x]||o("desc-fg"),h=!!e.content,b=e.work_ids||[],k=b.length>1,m=qc(k?b:[],i,r),v=h&&!a&&e.content.length>80?Br(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${o("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>h&&u(!a),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:h?"pointer":"default",userSelect:"none"},children:[t.jsxs(xi,{enabled:h,expanded:a,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[h&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:a?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg"),lineHeight:1.6},children:e.header_line?c(e.header_line):c(e.title)}),!a&&v&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:c(v)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:p(b[0]),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),k&&t.jsxs("span",{style:{fontSize:"11px",color:o("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:g,border:`1px solid ${g}40`,borderRadius:"2px",background:`${g}08`},children:x})]})]}),k&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(y=>{const j=m[y],$=j?`${l(j.title)}${j.author?`(${l(j.author)})`:""}`:y.slice(0,8)+"…";return t.jsxs("a",{href:p(y),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(y))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",$]},y)})}),a&&h&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}40`,borderRadius:"0 4px 4px 0",background:o("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${o("widget-border")}`,fontSize:"12px",color:o("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:c(e.comment)})]})]})}function Zc({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=it(),p=n.trim(),d=f.useMemo(()=>p?e.sections.filter(c=>pi(c,p,!0,l)):e.sections,[e.sections,p,l]);return t.jsxs("div",{children:[t.jsx("div",{children:d.map((c,a)=>t.jsx(Jc,{section:c,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:p},a))}),d.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Xc({sections:e,onNavigate:n,inline:i}){const r=ve(),{convert:s}=V();return t.jsx(t.Fragment,{children:e.map((l,p)=>{const d=Oe(l.type);if(d==="page_header"&&!fi(l))return null;if(d==="类")return t.jsxs(f.Fragment,{children:[t.jsx("h2",{children:i(s(l.title))}),l.content&&t.jsx("p",{children:i(s(l.content))})]},p);if(d==="书"||d==="诗"||d==="考证"||d==="注释"){const c=l.book_title?`《${l.book_title}》${l.n_juan!=null?di(l.n_juan)+"卷":""}`:l.title,a=i(s(c));return t.jsxs("section",{className:"bim-rd-entry",children:[t.jsx("h3",{children:l.work_id&&n?t.jsx("a",{href:r(l.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),n(l.work_id))},title:"查看作品",children:a}):a}),l.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(l.author_info))}),l.content&&l.content.split(/\n+/).map((u,x)=>t.jsx("p",{children:i(s(u))},x)),l.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(l.summary))]}),l.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(l.comment))]}),l.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(l.additional_comment))]})]},p)}return l.content?t.jsx("p",{children:i(s(l.content))},p):null})})}function Qc(e){return e.some(n=>{const i=Oe(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&fi(n)})}function ed({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:p,workLabelCache:d,prefs:c}){var W;const{convert:a}=V(),u=it(),[x,g]=f.useState("text"),h=s.trim(),b=(r==null?void 0:r.type)==="kaozhen",k=f.useCallback(T=>h?Ft(T,h,u):T,[h,u]),m=T=>ai(T,{renderText:k,properNames:c.properNames}),v=f.useMemo(()=>h?e.sections.filter(T=>pi(T,h,b,u)):e.sections,[e.sections,h,b,u]),y=(T,L)=>L.filter(M=>Oe(M.type)===T).length,j=y("书",e.sections),$=y("诗",e.sections),S=y("考证",e.sections);let _="";b?_=h?`${y("考证",v)} / ${S} ${a("條")}`:`${S} ${a("條")}`:$>0?_=h?`${y("诗",v)} / ${$} 首`:`${$} 首`:j>0&&(_=h?`${y("书",v)} / ${j} ${a("部書")}`:`${j} ${a("部書")}`);const w=r!=null&&r.text_quality?Tc(r.text_quality.grade):null,z=[];i&&z.push(i),_&&z.push(_),b&&(r!=null&&r.target_source)&&z.push(t.jsxs(t.Fragment,{children:[a("考證對象")," ",a(r.target_source)]})),w&&z.push(t.jsx("span",{title:ol[w],children:(W=r==null?void 0:r.text_quality)!=null&&W.source_note?t.jsxs(t.Fragment,{children:["底本 ",a(r.text_quality.source_note),"(",a(kn[w]),")"]}):t.jsxs(t.Fragment,{children:[a("文本質量")," ",a(kn[w])]})})),e.source_url&&z.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:a("原文來源")}));const B=!b&&Qc(e.sections),E=!!n&&(!B||c.readingMode==="paragraph"&&ln(n)),C=!b&&(B||!!n),A=b||!C?"entries":x;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:a(e.title)}),z.length>0&&t.jsx("p",{className:"bim-rd-meta",children:z.map((T,L)=>t.jsxs(f.Fragment,{children:[L>0&&t.jsx("span",{className:"bim-rd-dot"}),T]},L))}),C&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":"看法",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":A==="text",onClick:()=>g("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":A==="entries",onClick:()=>g("entries"),children:a("條目")})]})]}),A==="text"&&t.jsx("article",{className:"bim-rd-prose",children:E?t.jsx(ci,{text:n,mode:c.readingMode,properNames:c.properNames,renderText:k,dropTitle:e.title}):t.jsx(Xc,{sections:e.sections,onNavigate:l,inline:m})}),A==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:b?t.jsx(Zc,{juan:e,searchQuery:s,onNavigate:l,transport:p,workLabelCache:d}):t.jsxs(t.Fragment,{children:[v.map((T,L)=>{const M=Oe(T.type);return M==="书"||M==="诗"||M==="考证"?t.jsx(Uc,{section:T,onNavigate:l,highlightQuery:h},L):M==="类"?t.jsx(Vc,{section:T,highlightQuery:h},L):t.jsx(Kc,{section:T,highlightQuery:h},L)}),v.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function ds(e){return e.juan_files&&e.juan_files.length>0?e.juan_files:e.files&&e.files.length>0?e.files.map(n=>n.filename):[]}function td(e){const n=ds(e);return n.length>0?n[0]:null}function nd(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:p,query:d,isKaozhen:c}=e,a=it(),u=f.useRef(new Map),[x,g]=f.useState({}),[h,b]=f.useState({}),k=f.useCallback((v,y)=>{const j=y==null?void 0:y.title;j&&b($=>$[v]===j?$:{...$,[v]:j})},[]);f.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:p}),k(s,l))},[s,l,p,k]),f.useEffect(()=>{u.current.clear(),g({}),b({})},[n]);const m=f.useCallback((v,y)=>{let j=0;if(v.juan)for(const $ of v.juan.sections)pi($,y,c,a)&&j++;return j===0&&v.rawText&&Fc(v.rawText,y,a)&&(j=1),j},[c,a]);return f.useEffect(()=>{const v=d.trim();if(!v){g({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let y=!1;const j={},$=[];for(const B of r){const E=u.current.get(B);E?j[B]=m(E,v):(j[B]="loading",$.push(B))}g(j);const S=8;let _=0;const w=async()=>{var B;for(;_<$.length;){if(y)return;const E=_++,C=$[E];try{const[A,W]=await Promise.all([i.getCollatedJuan(n,C),((B=i.getCollatedJuanText)==null?void 0:B.call(i,n,C))??Promise.resolve(null)]),T={juan:A,rawText:W};if(u.current.set(C,T),k(C,A),y)return;g(L=>({...L,[C]:m(T,v)}))}catch{if(y)return;g(A=>({...A,[C]:0}))}}},z=Array.from({length:Math.min(S,$.length)},()=>w());return Promise.all(z),()=>{y=!0}},[d,n,i,r.join(","),m,a,k]),{matchStates:x,titles:h}}const gi=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:p,style:d,title:c,subtitle:a,resolveImages:u,renderImageOverlay:x,imagePanel:g,allowVertical:h})=>{const[b,k]=f.useState(null),[m,v]=f.useState(!1),[y,j]=f.useState(null),[$,S]=f.useState(null),[_,w]=f.useState(null),[z,B]=f.useState(!1),[E,C]=f.useState(null),[A,W]=f.useState(""),T=f.useRef(new Map),L=f.useRef(0),M=s??$,P=f.useCallback(U=>{S(U),l==null||l(U)},[l]),R=e||b;f.useEffect(()=>{e&&(v(!1),j(null))},[e]),f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let U=!1;return v(!0),j(null),i.getCollatedEditionIndex(n).then(te=>{U||(te?k(te):j("未找到整理本数据"))}).catch(te=>{U||j(te instanceof Error?te.message:"加载失败")}).finally(()=>{U||v(!1)}),()=>{U=!0}},[e,n,i]),f.useEffect(()=>{if(R&&!M){const U=td(R);U&&P(U)}},[R,M,P]);const ne=n||(R==null?void 0:R.work_id),I=f.useCallback(async U=>{var O;if(!ne||!(i!=null&&i.getCollatedJuan))return;const te=++L.current;B(!0),w(null),C(null);try{const[Y,Z]=await Promise.all([i.getCollatedJuan(ne,U),((O=i.getCollatedJuanText)==null?void 0:O.call(i,ne,U))??Promise.resolve(null)]);if(te!==L.current)return;w(Y),C(Z)}catch{if(te!==L.current)return;w(null),C(null)}finally{te===L.current&&B(!1)}},[ne,i]);f.useEffect(()=>{M&&I(M)},[M,I]);const F=U=>{P(U)};if(m)return t.jsx("div",{className:p,style:{...d,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(y)return t.jsx("div",{className:p,style:{...d,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:y});if(!R)return null;const K=R.type==="kaozhen",G=ds(R);return t.jsx(od,{className:p,style:d,index:R,allFiles:G,isKaozhen:K,effectiveWorkId:ne,transport:i,activeFile:M,handleSelectFile:F,juanData:_,juanRawText:E,juanLoading:z,searchQuery:A,setSearchQuery:W,onNavigate:r,workLabelCacheRef:T,reader:{title:c,subtitle:a,resolveImages:u,renderImageOverlay:x,imagePanel:g,allowVertical:h}})};function ps(e,n,i,r){var a,u,x,g;const s=(u=(a=n.juan_metadata)==null?void 0:a[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:Oc(e)),d=((g=(x=n.files)==null?void 0:x.find(h=>h.filename===e))==null?void 0:g.title)??i[e];if(!d)return{position:l,label:l};const c=r(d);return{position:l,label:l===d||l===c?c:`${l} ${c}`}}function id(e,n,i,r,s){const l=c=>c==="loading"?"…":typeof c=="number"&&c>0?c:void 0,p=(c,a)=>({key:c,label:a??ps(c,e,r,s).label,hint:l(i[c]),disabled:i[c]===0}),d=(c,a)=>{var x;if(c.files.length===1&&!((x=c.children)!=null&&x.length))return p(c.files[0],s(c.label));const u=Dc(c,i);return{key:`group:${a}`,label:s(c.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:cs(c),defaultExpanded:typeof u=="number"&&u>0,children:[...c.files.map(g=>p(g)),...(c.children??[]).map((g,h)=>d(g,`${a}.${h}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((c,a)=>d(c,`${a}`)):n.map(c=>p(c))}const od=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:p,activeFile:d,handleSelectFile:c,juanData:a,juanRawText:u,juanLoading:x,searchQuery:g,setSearchQuery:h,onNavigate:b,workLabelCacheRef:k,reader:m})=>{const{convert:v}=V(),[y,j]=ni(),{matchStates:$,titles:S}=nd({workId:l,transport:p,files:r,activeFile:d,activeJuan:a,activeRawText:u,query:g,isKaozhen:s}),_=as(m.resolveImages,d),w=f.useMemo(()=>id(i,r,$,S,v),[i,r,$,S,v]),z=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:g,onChange:C=>h(C.target.value)}),B=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(C=>C.vol_label)?"冊":"卷",E=d?ps(d,i,S,v).position:void 0;return t.jsxs(ii,{className:e,style:n,title:m.title??(i.title?v(i.title):void 0),subtitle:m.subtitle??v(s?"考證":"整理本"),toc:w,tocCaption:`目录 · ${r.length} ${v(B)}`,tocHeader:z,activeKey:d,onSelect:c,images:_.images,imagesLoading:_.loading,renderImageOverlay:m.renderImageOverlay,imagePanel:m.imagePanel,prefs:y,onPrefsChange:j,paragraphToggle:!s&&ln(u),allowVertical:m.allowVertical,children:[x?t.jsx(nt,{}):a?t.jsx(ed,{juan:a,rawText:u,positionLabel:E,index:i,searchQuery:g,onNavigate:b,transport:p,workLabelCache:k,prefs:y},d??""):d?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,i.references&&i.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:v("參考文獻")}),t.jsx("ol",{children:i.references.map((C,A)=>t.jsxs("li",{children:[C.url?t.jsx("a",{className:"bim-rd-link",href:C.url,target:"_blank",rel:"noopener noreferrer",children:C.title}):t.jsx("span",{children:C.title}),C.author&&t.jsxs("span",{children:[",",C.author]}),C.note&&t.jsxs("span",{children:["。",C.note]})]},A))})]})]})},rd={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},sd={label:"其他",color:o("desc-fg")},ld={pending:{label:"待处理",color:o("warning")},in_progress:{label:"处理中",color:o("primary")},resolved:{label:"已处理",color:o("success")},wontfix:{label:"不采纳",color:o("desc-fg")},duplicate:{label:"重复",color:o("desc-fg")}},ad={label:"待处理",color:o("warning")};function cd(e){try{const n=new Date(e),i=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return e}}function dd(e,n){if(!e)return!1;try{const i=new URL(e,n);if(i.protocol!=="http:"&&i.protocol!=="https:")return!1;const r=new URL(n);return i.hostname===r.hostname}catch{return!1}}const hi=({items:e,loading:n})=>{const i=ve();return n?t.jsx(nt,{}):e.length===0?t.jsx("div",{style:pd,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=rd[r.type]||sd,l=ld[r.status]||ad,p=typeof window<"u"&&dd(r.pageUrl,window.location.href);return t.jsxs("div",{style:ud,children:[t.jsxs("div",{style:xd,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...fo,background:s.color},children:s.label}),t.jsx("span",{style:{...fo,background:l.color},children:l.label})]}),t.jsx("span",{style:fd,children:cd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:gd,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:hn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(p?t.jsx("a",{href:r.pageUrl,style:hn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:hn,children:r.pageUrl}))]}),t.jsx("div",{style:hd,children:r.content}),r.reply&&t.jsxs("div",{style:md,children:[t.jsx("div",{style:bd,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},pd={textAlign:"center",padding:"40px 0",color:o("desc-fg"),fontSize:"14px"},ud={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"16px"},xd={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},fo={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},fd={fontSize:"12px",color:o("desc-fg")},gd={fontSize:"12px",marginBottom:"6px"},hn={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},hd={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},md={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},bd={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},Nn=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const p=ie(),[d,c]=f.useState(null),[a,u]=f.useState([]),[x,g]=f.useState("recommend"),[h,b]=f.useState([]),[k,m]=f.useState(!1),v=r??x,y=L=>{g(L),s==null||s(L)},[j,$]=f.useState(!0),[S,_]=f.useState(null),[w,z]=f.useState(null),[B,E]=f.useState(null);f.useEffect(()=>{let L=!1;if(e.getCounts)return e.getCounts().then(M=>{L||c({works:M.works,books:M.books,collections:M.collections})}).catch(()=>{}),()=>{L=!0}},[e]),f.useEffect(()=>{let L=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const P=await e.getRecommended();if(P!=null&&P.groups)return P.groups.flatMap(R=>R.items.map(ne=>({...ne,group:R.name})))}catch{}return[]})().then(async P=>{if(L)return;const R=P.filter(I=>I.id);if(R.length===0){$(!1);return}const ne=await Promise.all(R.map(async I=>{if(I.type)return{id:I.id,title:I.title,type:I.type,author:I.author,dynasty:I.dynasty,role:I.role,edition:I.edition,has_text:I.has_text,has_image:I.has_image,has_collated:I.has_collated,subtype:I.subtype,primary_name:I.primary_name,group:I.group,fallbackDescription:I.description};try{let F=null;if(e.getEntry)F=await e.getEntry(I.id);else{const K=await e.getItem(I.id);K&&(F={id:I.id,title:K.title||I.id,type:K.type||"work"})}if(F)return{...F,group:I.group,fallbackDescription:I.description}}catch{}return{id:I.id,title:I.title,type:pe.extractType(I.id),group:I.group,fallbackDescription:I.description}}));L||(u(ne.filter(I=>I!==null)),$(!1))}),()=>{L=!0}},[e,i]);const C=f.useRef(!1),A=f.useRef(!1),W=f.useRef(!1);f.useEffect(()=>{if(v!=="catalog"||C.current)return;const L=e.getCatalogProgress??e.getResourceProgress;if(!L)return;C.current=!0;let M=!1;return L.call(e).then(P=>{M||_(P)}).catch(()=>{C.current=!1}),()=>{M=!0}},[e,v]),f.useEffect(()=>{if(v!=="collection"||A.current||!e.getCollectionProgress)return;A.current=!0;let L=!1;return e.getCollectionProgress().then(M=>{L||z(M)}).catch(()=>{A.current=!1}),()=>{L=!0}},[e,v]),f.useEffect(()=>{if(v!=="site"||W.current||!e.getSiteProgress)return;W.current=!0;let L=!1;return e.getSiteProgress().then(M=>{L||E(M)}).catch(()=>{W.current=!1}),()=>{L=!0}},[e,v]),f.useEffect(()=>{if(!l||v!=="feedback")return;let L=!1;return m(!0),fetch(l).then(M=>M.json()).then(M=>{!L&&M.success&&b(M.items||[])}).catch(()=>{}).finally(()=>{L||m(!1)}),()=>{L=!0}},[l,v]);const T=L=>{switch(L){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:o("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${o("widget-border")}`,marginBottom:"16px"},children:[t.jsx(_t,{label:p.home.recommendTab,active:v==="recommend",onClick:()=>y("recommend")}),t.jsx(_t,{label:p.home.catalogTab,active:v==="catalog",onClick:()=>y("catalog")}),t.jsx(_t,{label:p.home.collectionTab,active:v==="collection",onClick:()=>y("collection")}),t.jsx(_t,{label:p.home.siteTab,active:v==="site",onClick:()=>y("site")}),l&&t.jsx(_t,{label:p.home.feedbackTab,active:v==="feedback",onClick:()=>y("feedback")})]}),v==="recommend"&&t.jsx(yd,{recommended:a,loading:j,onNavigate:n,getIcon:T,t:p}),v==="catalog"&&t.jsx(go,{progress:S,t:p,onNavigate:n}),v==="collection"&&t.jsx(go,{progress:w,t:p,onNavigate:n}),v==="site"&&t.jsx(vd,{progress:B,t:p,totalWorks:(d==null?void 0:d.works)??0}),v==="feedback"&&l&&t.jsx(hi,{items:h,loading:k})]})})},_t=({label:e,active:n,onClick:i})=>t.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:o(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${o("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),yd=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=ve();if(n)return t.jsx(nt,{});if(e.length===0)return null;const p=new Map;for(const d of e){const c=d.group||s.home.recommendedBrowse;p.has(c)||p.set(c,[]),p.get(c).push(d)}return t.jsx(t.Fragment,{children:Array.from(p.entries()).map(([d,c])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:d}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(a=>{const u=a.dynasty||a.author?`${a.dynasty?`〔${a.dynasty}〕`:""}${a.author||""}`:a.fallbackDescription;return t.jsxs("a",{href:l(a.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),i==null||i(a.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,cursor:"pointer",background:o("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(a.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[a.title,a.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:a.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},a.id)})})]},d))})},go=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(nt,{});const r=[...e.resources].sort((d,c)=>d.priority-c.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},p={in_progress:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(d=>{const c=r.filter(a=>a.status===d);return c.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:p[d]}}),l[d]," (",c.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(a=>t.jsx(jd,{item:a,t:n,statusColor:p[d],onNavigate:i},a.id))})]},d)})})},jd=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=ve(),l=e.total>0?Math.round(e.imported/e.total*100):0,p=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const d=e.edition?`${e.name}·${e.edition}`:e.name,c=e.collection_id||e.work_id;return c&&r?t.jsx("a",{href:s(c),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:a=>a.currentTarget.style.borderBottomStyle="solid",onMouseLeave:a=>a.currentTarget.style.borderBottomStyle="dashed",children:d}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:d}):d})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:o("widget-border"),color:o("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:p})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Lt(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},vd=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(nt,{});const r=[...e.resources].sort((c,a)=>c.priority-a.priority),s=r.filter(c=>c.imported>0),l=r.filter(c=>c.imported===0),p=s.reduce((c,a)=>Math.max(c,a.imported),0),d=i>0?Math.round(p/i*100):0;return t.jsxs("div",{children:[i>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${o("primary")} 6%, transparent)`,fontSize:"13px",color:o("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:p.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",d,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>t.jsx(ho,{item:c,t:n,totalWorks:i},c.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(c=>t.jsx(ho,{item:c,t:n,totalWorks:i},c.id))})]})]})},ho=({item:e,t:n,totalWorks:i})=>{const r=i>0?Math.round(e.imported/i*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:t.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&i>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:o("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},mo="(max-width: 768px)";function kd(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(mo).matches);return f.useEffect(()=>{const i=window.matchMedia(mo),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),e}const Sd=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var M;const l=ie(),{convert:p}=V(),d=kd(),[c,a]=f.useState(null),[u,x]=f.useState(null),[g,h]=f.useState(!1),[b,k]=f.useState("detail"),[m,v]=f.useState([]),[y,j]=f.useState(!1),[$,S]=f.useState(null),[_,w]=f.useState(!1),z=f.useCallback(async P=>{if(!e.getCollatedEditionIndex){S(null);return}w(!0);try{const R=await e.getCollatedEditionIndex(P);S(R)}catch{S(null)}finally{w(!1)}},[e]),B=f.useCallback(async P=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){v([]);return}j(!0);try{if(e.getCollectionCatalogs){const R=await e.getCollectionCatalogs(P);v(R||[])}else if(e.getCollectionCatalog){const R=await e.getCollectionCatalog(P);v(R?[{resource_id:"",data:R}]:[])}}catch{v([])}finally{j(!1)}},[e]),E=f.useCallback(async P=>{if(i){i(P);return}a(P),x(null),v([]),S(null),k("detail"),h(!0);try{const R=await e.getItem(P.id);R&&(x(R),R.type==="collection"?B(P.id):R.type==="work"&&R.has_collated&&z(P.id))}catch(R){console.error("加载详情失败:",R)}finally{h(!1)}},[e,i,B,z]),C=f.useCallback(async P=>{x(null),v([]),S(null),k("detail"),h(!0);try{const R=await e.getItem(P);R&&(x(R),a({id:P,title:R.title||P,type:R.type||"book"}),R.type==="collection"?B(P):R.type==="work"&&R.has_collated&&z(P))}catch(R){console.error("导航失败:",R)}finally{h(!1)}},[e,B,z]),A=(u==null?void 0:u.type)==="collection"&&(m.length>0||y)||(u==null?void 0:u.type)==="work"&&($||_),W=d&&(g||u),T=f.useCallback(()=>{a(null),x(null),v([]),S(null),k("detail")},[]),L=t.jsx(t.Fragment,{children:g?t.jsx(nt,{}):u?t.jsxs(t.Fragment,{children:[(A||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${o("widget-border")}`,padding:d?"0 12px":"0 48px",background:o("input-bg"),flexShrink:0,overflowX:d?"auto":void 0},children:[A&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>k("detail"),style:Vt(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&y&&m.length===0&&t.jsxs("button",{onClick:()=>{},style:Vt(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&m.map(P=>t.jsx("button",{onClick:()=>k(`catalog:${P.resource_id}`),style:Vt(b===`catalog:${P.resource_id}`),children:P.short_name?`${p(P.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},P.resource_id)),u.type==="work"&&($||_)&&t.jsxs("button",{onClick:()=>k("collated"),style:Vt(b==="collated"),children:[l.detailTab.collatedEdition,_&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:d?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?t.jsx(Vn,{data:u,transport:e,onNavigate:C}):b.startsWith("catalog:")?t.jsx(Yn,{data:(M=m.find(P=>`catalog:${P.resource_id}`===b))==null?void 0:M.data,onNavigate:C}):b==="collated"?t.jsx(gi,{index:$||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(Nn,{transport:e,onNavigate:C,recommendedIds:r})});return d?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:W?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${o("widget-border")}`,background:o("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:T,style:{padding:"4px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:L})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(wn,{transport:e,onEntryClick:E,hideModeIndicator:n}),!u&&t.jsx(Nn,{transport:e,onNavigate:C,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${o("widget-border")}`,display:"flex",flexDirection:"column",background:o("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(wn,{transport:e,onEntryClick:E,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:L})]})};function Vt(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Ye(e){return e.replace(/\.md$/,"")}function wd(e){let n="";if(e.source_url)try{const r=new URL(e.source_url).pathname.split("/").filter(Boolean).pop()??"";n=decodeURIComponent(r).replace(/_/g," ")}catch{}return[e.source_name,n||e.version_label].filter(Boolean).join(" · ")||e.key}const bo={padding:24,color:o("desc-fg")},Bn=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:p,onVersionChange:d,title:c,subtitle:a,resolveImages:u,renderImageOverlay:x,imagePanel:g,allowVertical:h,className:b,style:k})=>{const[m,v]=f.useState(e??null),[y,j]=f.useState(!1),[$,S]=f.useState(null),_=r!==void 0?r:$,w=f.useCallback(F=>{s?s(F):S(F)},[s]),[z,B]=f.useState(null),[E,C]=f.useState(!1);f.useEffect(()=>{e&&v(e)},[e]),f.useEffect(()=>{if(e)return;v(null),j(!1);const F=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!F){j(!0);return}let K=!1;return Promise.resolve().then(F).then(G=>{K||(G?v(G):j(!0))}).catch(()=>{K||j(!0)}),()=>{K=!0}},[n,i,e,l]),f.useEffect(()=>{if(!m||m.chapters.length===0)return;const F=Ye(m.chapters[0].file);if(!_){w(F);return}const K=Ye(_);m.chapters.some(U=>Ye(U.file)===K)||w(F)},[m,_,w]);const A=f.useMemo(()=>{if(!m||!_)return null;const F=Ye(_);return m.chapters.find(K=>Ye(K.file)===F)??null},[m,_]);f.useEffect(()=>{if(!n||!A)return;const F=l!==void 0?i.getWorkFullTextChapter?G=>i.getWorkFullTextChapter(n,l,G):null:i.getBookFullTextChapter?G=>i.getBookFullTextChapter(n,G):null;if(!F)return;let K=!1;return C(!0),B(null),Promise.resolve(A.file).then(F).then(G=>{K||B(G)}).catch(()=>{K||B(null)}).finally(()=>{K||C(!1)}),()=>{K=!0}},[n,A,i,l]);const W=as(u,A?Ye(A.file):null),[T,L]=ni(),{convert:M}=V(),P=p&&p.length>1&&d?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:F=>d(F.target.value),children:p.map(F=>t.jsx("option",{value:F.key,children:wd(F)},F.key))})]}):null;if(!m)return t.jsxs("div",{style:bo,children:[P&&t.jsx("div",{style:{marginBottom:12},children:P}),y?"无法加载全文目录":"加载全文目录…"]});if(m.chapters.length===0)return t.jsxs("div",{style:bo,children:[P&&t.jsx("div",{style:{marginBottom:12},children:P}),"全文目录为空"]});const R=m.chapters.map(F=>({key:Ye(F.file),label:M(F.title)})),ne=Zr(m)||zn(m),I=z?z.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(ii,{title:c??M(m.version_label),subtitle:a??"全文",toc:R,tocCaption:`目录 · ${m.chapters.length} ${m.chapters.length>1?"卷":"篇"}`,activeKey:_?Ye(_):null,onSelect:w,images:W.images,imagesLoading:W.loading,renderImageOverlay:x,imagePanel:g,prefs:T,onPrefsChange:L,paragraphToggle:ln(I),allowVertical:h,className:b,style:k,children:[A&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:M(A.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:m.source.url,target:"_blank",rel:"noreferrer",children:M(m.source.name)}),m.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),m.source.license]}),P&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),P]})]})]}),E&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!E&&I!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(ci,{text:I,mode:T.readingMode,tables:ne,gujiMarkdown:zn(m),properNames:T.properNames})}),!E&&!z&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},_d=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=ie(),{convert:l}=V(),[p,d]=f.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[c,a]=f.useState(null);return t.jsxs("div",{className:i,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:l(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[s.catalog.totalVolumes," ",t.jsx("strong",{children:e.total_volumes})," ",s.unit.juan]}),e.stats.zhulu!=null&&t.jsxs("span",{children:["著錄 ",t.jsx("strong",{children:e.stats.zhulu})," ",s.unit.bu]}),e.stats.cunmu!=null&&t.jsxs("span",{children:["存目 ",t.jsx("strong",{children:e.stats.cunmu})," ",s.unit.bu]}),e.stats.categories!=null&&t.jsxs("span",{children:[e.stats.categories," 類"]})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(x=>t.jsx($d,{division:x,expanded:p===x.name,onToggle:()=>d(p===x.name?null:x.name),expandedCat:c,onCatToggle:g=>a(c===g?null:g),onNavigate:n},x.name))})]})},$d=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:p}=V(),d=e.categories.reduce((c,a)=>{const u=a.stats||{zhulu:0,cunmu:0};return c+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${o("primary")} 6%, transparent)`:o("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:o("fg"),textAlign:"left"},children:[t.jsx("span",{children:p(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg")},children:[e.categories.length," 類 · ",d," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(c=>{const a=`${e.name}/${c.name}`;return t.jsx(zd,{category:c,expanded:r===a,onToggle:()=>s(a),onNavigate:l},c.name)})})]})},zd=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var c,a,u,x;const{convert:s}=V(),l=((c=e.books)==null?void 0:c.zhulu)||[],p=((a=e.books)==null?void 0:a.cunmu)||[],d=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((x=e.stats)==null?void 0:x.cunmu)||p.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?o("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:o("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[d," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||p.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(yo,{label:"著錄",books:l,onNavigate:r}),p.length>0&&t.jsx(yo,{label:"存目",books:p,onNavigate:r})]})]})},yo=({label:e,books:n,onNavigate:i})=>{const{convert:r}=V(),s=ve(),[l,p]=f.useState(n.length<=20),d=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:d.map((c,a)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:o("fg")},children:c.work_id&&i?t.jsx("a",{href:s(c.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},children:r(c.title)}):r(c.title)}),c.volumes&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(c.volumes)}),c.author&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(c.author).slice(0,20)})]},a))}),!l&&t.jsxs("button",{onClick:()=>p(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},Ee=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=ie();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:o("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&t.jsx("button",{onClick:i,style:Id,children:"AI"}),n&&t.jsx("button",{onClick:n,style:Cd,children:l.action.save})]})]}),s]})},Cd={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Id={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},ze=({label:e,value:n,onChange:i,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:l=>i(l.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),Xe=({value:e,onChange:n,placeholder:i})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Zt=({children:e,color:n,style:i})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||o("primary-soft"),color:o(n?"on-color-fg":"fg"),...i},children:e});function Td(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Yt=({value:e,onChange:n,label:i})=>{const[r,s]=f.useState(!1),l=f.useRef(null),p=Td(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&p?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:jo,children:i}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${o("input-border")}`,borderRadius:"2px",background:o("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:o("fg")},children:p.name}),t.jsx(Zt,{children:p.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:jo,children:i}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:d=>n(d.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},jo={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function Rd(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function Ed(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const us=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=ie(),[s,l]=f.useState(null),p=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},d=x=>{n(e.filter((g,h)=>h!==x)),s===x&&l(null)},c=(x,g,h)=>{const b=[...e];b[x]={...b[x],[g]:h},n(b)},a=(x,g)=>{const h=[...e];h[x]={...h[x],type:g,id:"",name:""},n(h),g==="bookID"&&i&&i(b=>{const k=[...e];k[x]={...k[x],id:b.id,name:b.title,type:"bookID"},n(k)})},u=x=>{i&&i(g=>{const h=[...e];h[x]={...h[x],id:g.id,name:g.title,type:"bookID"},n(h)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((x,g)=>t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===g?null:g),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:o("fg")},children:x.name||`${r.editor.sourcePlaceholder} ${g+1}`}),x.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Rd(x.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:Ed(x.type)}),t.jsx("button",{onClick:h=>{h.stopPropagation(),d(g)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===g&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>a(g,"bookID"),style:{...vo,borderColor:o("source-bookid"),color:o("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>a(g,"url"),style:{...vo,borderColor:o("source-url"),color:o("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),x.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:He,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const h=[...e];h[g]={...h[g],type:"",id:"",name:""},n(h)},style:ko,children:r.action.changeType})]}),x.id&&x.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:o("bg"),border:`1px solid ${o("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:o("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:x.name}),t.jsx("code",{style:{fontSize:"11px",background:o("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),t.jsx("button",{onClick:()=>u(g),style:{background:"transparent",border:`1px solid ${o("widget-border")}`,color:o("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(g),style:{width:"100%",padding:"14px",border:`2px dashed ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:He,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const h=[...e];h[g]={...h[g],type:"",id:"",name:""},n(h)},style:ko,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:x.name,onChange:h=>c(g,"name",h.target.value),placeholder:r.editor.sourceNamePlaceholder,style:st})]}),t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:x.id,onChange:h=>c(g,"id",h.target.value),placeholder:"https://...",style:st})]})]}),x.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${o("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...He,opacity:.7},children:r.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:x.details,onChange:h=>c(g,"details",h.target.value),placeholder:r.editor.detailsPlaceholder,style:st})]}),t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:x.position,onChange:h=>c(g,"position",h.target.value),placeholder:"如: 卷三, p.52",style:st})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:x.version,onChange:h=>c(g,"version",h.target.value),placeholder:"如: v1.0, 2024-01",style:st})]}),t.jsxs("div",{children:[t.jsx("label",{style:He,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:x.processor_version,onChange:h=>c(g,"processor_version",h.target.value),placeholder:"如: v0.1",style:st})]})]})]})]})})]},g)),t.jsxs("button",{onClick:p,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},He={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},st={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},vo={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:o("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},ko={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function xs(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(i=>({id:i.id||"",name:i.name||"",type:i.type||"",details:i.details||"",position:i.position||"",version:i.version||"",processor_version:i.processor_version||""}))}catch{}return[]}function fs(e){return!e||e.length===0?"":JSON.stringify(e)}const gs=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:p,childWorks:d,childCollections:c,containedBooks:a,siblingBooks:u,onLinkEntity:x,onUnlinkEntity:g,onViewEntity:h,onCreateAndLink:b,onSaveRelations:k})=>{const m=ie();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:m.section.relations})]}),k&&t.jsx("button",{onClick:k,style:Ld,children:m.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx($t,{direction:"up",title:m.relation.belongsToWork,entity:l,onView:h,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),t.jsx($t,{direction:"up",title:m.relation.containedInCollection,entity:p,onView:h,onUnlink:()=>g("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),l&&u&&u.length>0&&t.jsx(lt,{direction:"horizontal",title:`${m.relation.siblingVersions} (${u.length})`,entities:u,onView:h,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:m.relation.addVersionForWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx($t,{direction:"up",title:m.relation.parentWork,entity:r,onView:h,onUnlink:()=>g("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),d&&d.length>0&&t.jsx(lt,{direction:"down",title:`${m.relation.childWorks} (${d.length})`,entities:d,onView:h,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:m.action.addSubWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),c&&c.length>0&&t.jsx(lt,{direction:"down",title:`${m.relation.collectionImpl} (${c.length})`,entities:c,onView:h,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:m.action.addCollectionImpl,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),t.jsx(lt,{direction:"down",title:`${m.relation.allVersions} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:h,onAdd:()=>b("childBook","book",{workId:n}),addLabel:m.action.addVersion,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx($t,{direction:"up",title:m.relation.correspondingWork,entity:l,onView:h,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),t.jsx($t,{direction:"up",title:m.relation.parentCollection,entity:s,onView:h,onUnlink:()=>g("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),t.jsx(lt,{direction:"down",title:`${m.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:h,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:m.action.addSubCollection,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),t.jsx(lt,{direction:"down",title:`${m.relation.containedBooks} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:h,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:m.action.addBook,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]})]})]})},$t=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:p,linkLabel:d,createLabel:c,notLinkedLabel:a,viewLabel:u,unlinkLabel:x})=>{const g=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),h=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:h}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:o("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:hs(i.type)}),t.jsx("span",{style:{fontWeight:500},children:i.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(So,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(So,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:a}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(Wn,{onClick:l,children:d}),t.jsx(Wn,{onClick:p,primary:!0,children:c})]})]})},lt=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:p,expandMoreLabel:d})=>{const[c,a]=f.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),x=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",g=c?i:i.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:x}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(h=>t.jsxs("div",{onClick:()=>r(h),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:o("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:hs(h.type)}),t.jsx("span",{children:h.title})]},h.id)),i.length>5&&!c&&t.jsxs("div",{onClick:()=>a(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:o("link-fg"),cursor:"pointer"},children:[d," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:p}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(Wn,{onClick:s,primary:!0,children:["+ ",l]})})]})},So=({onClick:e,title:n,danger:i,children:r})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?o("danger"):"inherit",opacity:.7},children:r}),Wn=({onClick:e,primary:n,children:i})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${o("widget-border")}`,borderRadius:"4px",background:n?o("primary"):"transparent",color:n?o("primary-fg"):"inherit",cursor:"pointer"},children:i});function hs(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Ld={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},ms=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:p,onSearch:d,isLoading:c,excludeId:a})=>{const[u,x]=f.useState(""),g=a?p.filter(m=>m.id!==a):p;f.useEffect(()=>{e&&(x(""),d(""))},[e]);const h=m=>{x(m),d(m)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",k=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:Nd,children:t.jsxs("div",{style:Bd,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),t.jsx("button",{onClick:s,style:Wd,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:m=>h(m.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:Ad})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:mn,children:"搜索中..."}):g.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(m=>t.jsxs("div",{onClick:()=>r(m),style:Md,children:[t.jsx("span",{style:{fontSize:"16px"},children:k}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[m.title,m.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:m.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[m.id,m.author&&` · ${m.author}`,m.dynasty&&` · ${m.dynasty}`]})]})]},m.id))}):u?t.jsxs("div",{style:mn,children:["未找到匹配的",b]}):t.jsxs("div",{style:mn,children:["输入关键词搜索",b]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:l,style:Fd,children:["创建新",b,"并关联"]})]})]})})},Nd={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Bd={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},Wd={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Ad={width:"100%",padding:"10px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},Md={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:o("primary-soft")},mn={padding:"20px",textAlign:"center",color:o("desc-fg")},Fd={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},wo={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Pd={work:"📜",book:"📖",collection:"📚",entity:"👤"},bs=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[p,d]=f.useState(""),c=f.useRef(null);f.useEffect(()=>{e&&(d((r==null?void 0:r.title)||""),setTimeout(()=>{var g,h;(g=c.current)==null||g.focus(),(h=c.current)==null||h.select()},100))},[e,r==null?void 0:r.title]);const a=g=>{g.key==="Enter"&&p.trim()?u():g.key==="Escape"&&l()},u=()=>{p.trim()&&s(p.trim(),{...r,title:p.trim()})};if(!e)return null;const x=()=>{switch(i){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${wo[n]}`}};return t.jsx("div",{style:Od,onClick:g=>{g.target===g.currentTarget&&l()},children:t.jsxs("div",{style:Dd,onClick:g=>g.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Pd[n]}),t.jsx("span",{children:x()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:o("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:o("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:c,type:"text",value:p,onChange:g=>d(g.target.value),onKeyDown:a,placeholder:`请输入${wo[n]}名称...`,style:Hd})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),background:o("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&t.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:l,style:Gd,children:"取消"}),t.jsx("button",{onClick:u,disabled:!p.trim(),style:{...Ud,opacity:p.trim()?1:.6,cursor:p.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Od={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Dd={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:o("shadow-dialog")},Hd={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box"},Gd={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Ud={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function Vd(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function ys(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Yd(e){switch(e){case"work":return o("editor-type-work");case"collection":return o("editor-type-collection");case"book":return o("editor-type-book");default:return o("desc-fg")}}const js=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:p,onSelect:d,onCancel:c,onCreate:a,onSearch:u})=>{const[x,g]=f.useState(""),[h,b]=f.useState([]),[k,m]=f.useState(!1),[v,y]=f.useState("recent");f.useEffect(()=>{e&&(g(""),b([]),y(r.length>0?"recent":"search"))},[e,r.length]),f.useEffect(()=>{if(!x.trim()){b([]);return}const z=setTimeout(async()=>{m(!0);try{b(await u(x,i))}catch{b([])}finally{m(!1)}},300);return()=>clearTimeout(z)},[x,i,u]);const j=f.useCallback(z=>{g(z.target.value),z.target.value.trim()&&y("search")},[]),$=f.useCallback(z=>s?z.filter(B=>B.id!==s):z,[s]);if(!e)return null;const S=n||(i==="all"?"选择实体":`选择${ys(i)}`),_=$(r),w=$(h);return t.jsx("div",{style:qd,children:t.jsxs("div",{style:Jd,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:S}),t.jsx("button",{onClick:c,style:Zd,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:x,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Xd}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),k&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),_.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs(_o,{active:v==="recent",onClick:()=>y("recent"),children:["最近使用 (",_.length,")"]}),t.jsxs(_o,{active:v==="search",onClick:()=>y("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:v==="recent"&&_.length>0?t.jsx($o,{entities:_,onSelect:d}):x.trim()?k?t.jsx(bn,{message:"搜索中..."}):w.length>0?t.jsx($o,{entities:w,onSelect:d}):t.jsx(bn,{message:"未找到匹配的结果"}):t.jsx(bn,{message:"输入关键词开始搜索"})}),l&&a&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:a,style:Qd,children:p||"创建新实体"})]})]})})},_o=({active:e,onClick:n,children:i})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:i}),$o=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(Kd,{entity:i,onClick:()=>n(i)},i.id))}),Kd=({entity:e,onClick:n})=>{const[i,r]=f.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Vd(e.type)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:e.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[t.jsx("code",{style:{fontSize:"10px",background:o("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&t.jsx("span",{children:e.author}),e.dynasty&&t.jsx("span",{children:e.dynasty})]})]}),t.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Yd(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:ys(e.type)})]})},bn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),qd={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Jd={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},Zd={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Xd={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},Qd={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},ep={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},tp={work:"📜",collection:"📚",book:"📖",entity:"👤"},vs=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:p,onAskAI:d,renderSectionActions:c,onDownloadResource:a,downloadStatuses:u,relations:x,onRelationsChange:g})=>{var q;const h=ie(),[b,k]=f.useState(!1),[m,v]=f.useState("work"),[y,j]=f.useState(""),[$,S]=f.useState(""),[_,w]=f.useState([]),[z,B]=f.useState(!1),[E,C]=f.useState(!1),[A,W]=f.useState("work"),[T,L]=f.useState(""),[M,P]=f.useState(),[R,ne]=f.useState(!1),[I,F]=f.useState(null),[K,G]=f.useState([]);f.useRef(null);const U=e.type,te=U==="work",O=U==="collection",Y=U==="book",Z=f.useCallback((N,ee)=>{n({...e,[N]:ee})},[e,n]),X=f.useCallback((N,ee)=>{j(N),v(ee),S(h.editor.selectToLink+h.indexType[ee]),w([]),k(!0)},[h]),se=f.useCallback(N=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,N)},[r,e.id]),ge=f.useCallback(N=>{s==null||s(N.id,N.type)},[s]),he=f.useCallback((N,ee,re)=>{const be={...re,author:(re==null?void 0:re.author)||e.author,dynasty:re==null?void 0:re.dynasty};W(ee),L(N),P(be),C(!0)},[e.author]),D=f.useCallback((N,ee)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,T,{type:A,title:N,inheritData:ee}),C(!1)},[r,e.id,T,A]),le=f.useCallback(N=>{if(!N.trim()){w([]);return}B(!0),r!=null&&r.searchEntities&&r.searchEntities(N,m).then(ee=>{w(ee),B(!1)}).catch(()=>{w([]),B(!1)})},[r,m]),oe=f.useCallback(N=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,y,N.id),k(!1)},[r,e.id,y]),ce=f.useCallback(()=>{i()},[i]),ue=f.useCallback(N=>{F(()=>N),ne(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(G).catch(()=>{})},[r]),me=f.useCallback((N,ee)=>r!=null&&r.searchEntities?r.searchEntities(N,ee==="all"?void 0:ee):Promise.resolve([]),[r]),Q=f.useCallback(N=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(N),G(ee=>[N,...ee.filter(re=>re.id!==N.id)].slice(0,10)),I==null||I(N),ne(!1),F(null)},[r,I]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${o("widget-border")}`,paddingBottom:"16px"},children:t.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:tp[U]}),t.jsx("span",{children:e.title||h.editor.untitled}),t.jsx(Zt,{children:e.id}),t.jsx(Zt,{color:ep[U],children:h.indexType[U]})]})}),t.jsx(Ee,{title:h.section.basicInfo,onSave:i,onAskAI:d?()=>d("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(Yt,{label:te?h.editor.workTitle:O?h.editor.collectionTitle:h.editor.bookTitle,value:e.title,onChange:N=>Z("title",N)}),Y&&t.jsx(Yt,{label:h.editor.belongsToWork,value:e.workName||"",onChange:N=>Z("workName",N)}),t.jsx(ze,{label:h.editor.authorLabel,value:e.author||"",onChange:N=>Z("author",N)}),t.jsx(ze,{label:h.editor.publicationYearLabel,value:e.publicationYear||"",onChange:N=>Z("publicationYear",N)}),(Y||O)&&t.jsx(Yt,{label:h.editor.containedIn,value:e.collection||"",onChange:N=>Z("collection",N)}),(Y||O)&&t.jsx(ze,{label:h.editor.holderLabel,value:e.holder||"",onChange:N=>Z("holder",N)}),(Y||O)&&t.jsx(ze,{label:Y?h.editor.pageLabel:h.editor.volumeLabel,value:e.pages||"",onChange:N=>Z("pages",N)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(ze,{label:h.editor.firstImageLabel,value:e.firstImage||"",onChange:N=>Z("firstImage",N)})})]})}),t.jsx(Ee,{title:h.section.description,onSave:i,onAskAI:d?()=>d("介绍"):void 0,children:t.jsx(Xe,{value:e.description||"",onChange:N=>Z("description",N),placeholder:h.editor.descriptionPlaceholder})}),(((q=e.additional_works)==null?void 0:q.length)||0)>0&&t.jsx(Ee,{title:h.section.additionalWorks,onSave:i,children:t.jsx(np,{items:e.additional_works||[],onChange:N=>Z("additional_works",N)})}),t.jsx(Ee,{title:h.section.indexedBy,onSave:i,onAskAI:d?()=>d("收录于"):void 0,children:t.jsx(ip,{items:e.indexed_by||[],onChange:N=>Z("indexed_by",N)})}),t.jsx(Ee,{title:h.section.emendatedBy,onSave:i,onAskAI:d?()=>d("考证"):void 0,children:t.jsx(op,{items:e.emendated_by||[],onChange:N=>Z("emendated_by",N)})}),t.jsx(Ee,{title:h.section.textResources,onSave:i,onAskAI:d?()=>d("资源"):void 0,children:t.jsx(Sn,{items:e.resources||[],onChange:N=>Z("resources",N),onDownload:a,downloadStatuses:u,filterType:"text"})}),t.jsx(Ee,{title:h.section.imageResources,onSave:i,children:t.jsx(Sn,{items:e.resources||[],onChange:N=>Z("resources",N),onDownload:a,downloadStatuses:u,filterType:"image"})}),t.jsx(Ee,{title:h.section.sources,onSave:i,onAskAI:d?()=>d("资料来源"):void 0,children:t.jsx(us,{items:xs(e.sources||""),onChange:N=>Z("sources",fs(N)),onOpenEntityPicker:ue})}),(Y||O)&&t.jsx(Ee,{title:h.section.provenance,onSave:i,onAskAI:d?()=>d("收藏历史"):void 0,children:t.jsx(Xe,{value:e.provenance||"",onChange:N=>Z("provenance",N),placeholder:h.editor.provenancePlaceholder})}),Y&&t.jsx(Ee,{title:h.section.otherEditions,onSave:i,onAskAI:d?()=>d("其他版本"):void 0,children:t.jsx(Xe,{value:e.otherEditions||"",onChange:N=>Z("otherEditions",N),placeholder:h.editor.otherEditionsPlaceholder})}),t.jsx(gs,{entityType:U,entityId:e.id,entityTitle:e.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:X,onUnlinkEntity:se,onViewEntity:ge,onCreateAndLink:he,onSaveRelations:ce}),l&&p&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${o("danger-soft-border")}`,background:o("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:o("danger"),fontWeight:600,marginBottom:"8px"},children:h.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"12px"},children:h.editor.dangerZoneDesc}),t.jsx("button",{onClick:p,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("danger")}`,borderRadius:"4px",background:"transparent",color:o("danger"),cursor:"pointer"},children:h.editor.deleteEntity})]}),t.jsx(ms,{isOpen:b,entityType:m,title:$,onSelect:oe,onCancel:()=>k(!1),onCreate:()=>{k(!1),he(y,m)},searchResults:_,onSearch:le,isLoading:z,excludeId:e.id}),t.jsx(bs,{isOpen:E,entityType:A,relationField:T,inheritData:M,onConfirm:D,onCancel:()=>C(!1)}),t.jsx(js,{isOpen:R,title:h.action.selectBookOrWork,filterType:"all",recentEntities:K,excludeId:e.id,onSelect:Q,onCancel:()=>{ne(!1),F(null)},onSearch:me})]})};function np({items:e,onChange:n}){const i=ie(),r=(p,d,c)=>{const a=e.map((u,x)=>x===p?{...u,[d]:c}:u);n(a)},s=p=>n(e.filter((d,c)=>c!==p)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((p,d)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(ze,{label:i.editor.bookNameLabel,value:p.book_title,onChange:c=>r(d,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(ze,{label:i.label.juanCount,value:p.n_juan!=null?String(p.n_juan):"",onChange:c=>r(d,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(d),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("muted"),marginTop:"18px"},children:"✕"})]},d)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function ks({items:e,onChange:n,showMeta:i,addLabel:r}){const s=ie(),[l,p]=f.useState(null),d=(u,x,g)=>{const h=e.map((b,k)=>k===u?{...b,[x]:g||void 0}:b);n(h)},c=u=>{n(e.filter((x,g)=>g!==u)),l===u&&p(null)},a=()=>{n([...e,{source:""}]),p(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,x)=>{const g=l===x;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?`color-mix(in srgb, ${o("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>p(g?null:x),children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:h=>{h.stopPropagation(),c(x)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${o("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:o("muted")},children:"✕"})]}),!g&&i&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:o("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),g&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(ze,{label:s.label.sourceName,value:u.source,onChange:h=>d(x,"source",h)}),t.jsx(ze,{label:s.label.sourceBid,value:u.source_bid||"",onChange:h=>d(x,"source_bid",h)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(ze,{label:s.label.titleInfo,value:u.title_info||"",onChange:h=>d(x,"title_info",h)}),t.jsx(ze,{label:s.label.authorInfo,value:u.author_info||"",onChange:h=>d(x,"author_info",h)})]}),t.jsx(ze,{label:s.label.edition,value:u.edition||"",onChange:h=>d(x,"edition",h)})]}),t.jsx(Xe,{value:u.summary||"",onChange:h=>d(x,"summary",h),placeholder:s.editor.summaryPlaceholder}),t.jsx(Xe,{value:u.comment||"",onChange:h=>d(x,"comment",h),placeholder:s.editor.commentPlaceholder}),t.jsx(Xe,{value:u.additional_comment||"",onChange:h=>d(x,"additional_comment",h),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),t.jsx("button",{onClick:a,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:r})]})}function ip({items:e,onChange:n}){const i=ie();return t.jsx(ks,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function op({items:e,onChange:n}){const i=ie();return t.jsx(ks,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function Ss(e){var d,c,a,u,x,g,h;const n=((c=(d=e.authors)==null?void 0:d[0])==null?void 0:c.name)||"",i=((a=e.publication_info)==null?void 0:a.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(x=e.page_count)!=null&&x.number?String(e.page_count.number):((g=e.page_count)==null?void 0:g.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",p={id:e.id,title:e.title,type:e.type,author:n,publicationYear:i,holder:r,pages:s,description:l,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const b=e;if(Array.isArray(b.related_works)){const k=b.related_works.find(m=>m.relation==="part_of");k&&(p.parentWorkId=k.id,p.parentWorkName=k.title)}}if(e.type==="book"){const b=e;p.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(p.collectionId=(h=b.contained_in[0])==null?void 0:h.id)}return p}function rp(e){const n={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.publicationYear?{year:e.publicationYear}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(n.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(n.work_id=e.workId,e.collectionId&&(n.contained_in=[{id:e.collectionId}])),n}const sp=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:p,onSave:d,onDelete:c,onNavigate:a,renderLink:u,onAskAI:x,renderSectionActions:g,onDownloadResource:h,downloadStatuses:b,relations:k,onRelationsChange:m,headerExtra:v,className:y,style:j}=e;ie();const[$,S]=f.useState(s),_=l?s:$;f.useEffect(()=>{s!==$&&S(s)},[s]);const w=f.useCallback(()=>{const T=_==="view"?"edit":"view";l?l(T):S(T)},[_,l]),[z,B]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(T=>{T&&B(T)})},[i,r]);const E=n||z,C=f.useMemo(()=>E?Ss(E):null,[E]),A=l||!n?t.jsx("button",{onClick:w,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:_==="edit"?o("accent-bg"):"transparent",color:o(_==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?"切换到编辑模式":"切换到查看模式",children:_==="view"?"✏️ 编辑":"👁 查看"}):null,W=t.jsxs(t.Fragment,{children:[A,v]});return!E&&!C?t.jsx(nt,{}):_==="view"?t.jsx(Vn,{data:E,transport:r,onNavigate:a?T=>a(T):void 0,renderLink:u,headerExtra:W,className:y,style:j}):C?t.jsxs("div",{className:y,style:j,children:[W&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:W}),t.jsx(vs,{data:C,onChange:p||(()=>{}),onSave:d||(()=>{}),transport:r,onNavigate:a,showDelete:!!c,onDelete:c,onAskAI:x,renderSectionActions:g,onDownloadResource:h,downloadStatuses:b,relations:k,onRelationsChange:m})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},zo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],ws=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,l]=f.useState(null),[p,d]=f.useState(""),[c,a]=f.useState(""),[u,x]=f.useState("idle"),[g,h]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{e&&(l(null),d(""),a(""),x("idle"),h(""))},[e]),f.useEffect(()=>{s&&setTimeout(()=>{var y;return(y=b.current)==null?void 0:y.focus()},100)},[s]),f.useEffect(()=>{if(u==="success"){const y=setTimeout(n,2e3);return()=>clearTimeout(y)}},[u,n]),f.useEffect(()=>{if(!e)return;const y=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[e,n]);const k=async()=>{if(!(!s||!p.trim())){x("submitting"),h("");try{await i({type:s,content:p.trim(),...c.trim()?{contact:c.trim()}:{}}),x("success")}catch(y){x("error"),h(y instanceof Error?y.message:"提交失败,请稍后重试")}}};if(!e)return null;const m=s&&p.trim()&&u!=="submitting",v=zo.find(y=>y.value===s);return t.jsx("div",{style:lp,onClick:y=>{y.target===y.currentTarget&&n()},children:t.jsxs("div",{style:ap,onClick:y=>y.stopPropagation(),children:[t.jsxs("div",{style:cp,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:dp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:gp,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:o("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:zo.map(y=>t.jsxs("button",{onClick:()=>l(y.value),style:{...pp,...s===y.value?up:{}},children:[t.jsx("span",{children:y.icon})," ",y.label]},y.value))}),t.jsx("textarea",{ref:b,value:p,onChange:y=>d(y.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...xp,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:c,onChange:y=>a(y.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:mp}),t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[p.length," / 2000"]}),u==="error"&&t.jsx("div",{style:hp,children:g}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:k,disabled:!m,style:{...fp,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},lp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ap={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},cp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},dp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:o("desc-fg"),padding:"4px 8px",borderRadius:"4px"},pp={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},up={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},xp={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},fp={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},gp={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},hp={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginBottom:"12px"},mp={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},An="--bim-feedback-fab-offset",Mn=48,bp=16,yp=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,p]=f.useState(!1),d=n.bottom??24;return f.useEffect(()=>{if(r||typeof document>"u")return;const c=document.documentElement;return c.style.setProperty(An,`calc(${d+Mn+bp}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(An)}},[r,d]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>p(!0),style:{...jp,zIndex:s??o("feedback-fab-z"),bottom:`calc(${d}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(ws,{isOpen:l,onClose:()=>p(!1),onSubmit:e,feedbackListUrl:i})]})},jp={position:"fixed",width:`${Mn}px`,height:`${Mn}px`,borderRadius:"50%",border:"none",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:o("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},Co=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],_s=({onSubmit:e})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[l,p]=f.useState(""),[d,c]=f.useState("idle"),[a,u]=f.useState(""),x=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var k;return(k=x.current)==null?void 0:k.focus()},100)},[n]);const g=async()=>{if(!(!n||!r.trim())){c("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),c("success"),s(""),p(""),i("bug")}catch(k){c("error"),u(k instanceof Error?k.message:"提交失败,请稍后重试")}}},h=n&&r.trim()&&d!=="submitting",b=Co.find(k=>k.value===n);return d==="success"?t.jsx("div",{style:Io,children:t.jsxs("div",{style:_p,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>c("idle"),style:$p,children:"继续提交"})]})}):t.jsxs("div",{style:Io,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Co.map(k=>t.jsxs("button",{onClick:()=>i(k.value),style:{...vp,...n===k.value?kp:{}},children:[t.jsx("span",{children:k.icon})," ",k.label]},k.value))}),t.jsx("textarea",{ref:x,value:r,onChange:k=>s(k.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:d==="submitting",style:{...Sp}}),t.jsx("input",{type:"text",value:l,onChange:k=>p(k.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:d==="submitting","aria-label":"联系方式(选填)",style:Cp}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:g,disabled:!h,style:{...wp,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:d==="submitting"?"提交中...":"提交"})]}),d==="error"&&t.jsx("div",{style:zp,children:a})]})},Io={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},vp={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},kp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},Sp={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},wp={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},_p={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},$p={background:"none",border:"none",color:o("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},zp={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginTop:"8px"},Cp={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function To(e){return typeof e=="function"?e():e??"/api/feedback"}const $s=({resourceId:e,apiUrl:n})=>{const[i,r]=f.useState([]),[s,l]=f.useState(!0),p=f.useCallback(async()=>{const c=To(n);l(!0);try{const u=await(await fetch(`${c}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);f.useEffect(()=>{p()},[p]);const d=async c=>{const a=To(n),u=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...c,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const x=await u.json().catch(()=>null);throw new Error((x==null?void 0:x.error)||"提交失败")}setTimeout(()=>p(),500)};return t.jsxs("div",{children:[t.jsx(hi,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(_s,{onSubmit:d})})]})},Ro={part_of:"所屬",has_part:"包含",contains_text_of:"收錄",collected_in:"叢編",text_carried_by:"載錄",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"後繼",derived_from:"衍生",has_adaptation:"改編",related:"相關"};function Ip(e){return e?Ro[e]??e:Ro.related}const Tp={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function Rp(e){return Tp[e]??e}const Ep={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function mi(e){return Ep[e]??""}function bi({authors:e,onNavigate:n,renderLink:i}){const{convert:r}=V(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,p)=>{const d=Zn(l.role);return t.jsxs(f.Fragment,{children:[p>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Pe,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:i,dense:!0}):r(l.name),d&&t.jsx("span",{style:{marginLeft:4},children:r(d)})]},p)})}):null}const Eo=12,Lp=60,zs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:p,railLinks:d})=>{var se,ge,he;const c=ie(),{convert:a}=V(),u=f.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[x,g]=f.useState(new Map),[h,b]=f.useState(!1),[k,m]=f.useState(""),[v,y]=f.useState(!1),j=u.length<=Lp,$=j||h||!!k||v,S=f.useMemo(()=>$?u:u.slice(0,Eo),[u,$]);f.useEffect(()=>{if(!n||S.length===0)return;const D=S.filter(oe=>!x.has(oe));if(D.length===0)return;let le=!1;return Promise.all(D.map(oe=>n.getItem(oe).then(ce=>{const ue=ce??{};return[oe,{id:oe,title:ue.title,edition:ue.edition,resources:ue.resources,publication_info:ue.publication_info,current_location:ue.current_location,lineage:ue.lineage,measure_info:ue.measure_info}]}).catch(()=>[oe,{id:oe}]))).then(oe=>{le||g(ce=>{const ue=new Map(ce);for(const[me,Q]of oe)ue.set(me,Q);return ue})}),()=>{le=!0}},[n,S,x]);const _=f.useMemo(()=>u.map(D=>x.get(D)??{id:D}),[u,x]),w=u.length>0&&u.every(D=>x.has(D)),z=!!n&&S.some(D=>!x.has(D)),B=j||$,E=f.useMemo(()=>br(_,e.version_graph,{era:k,scanOnly:v,sort:B?"year":"default"}),[_,e.version_graph,k,v,B]),C=h?E.rows:E.rows.slice(0,Eo),A=E.allRows.filter(D=>D.hasImage).length,W=e.related_works||[],T=W.filter(D=>D.relation==="collected_in"),L=f.useMemo(()=>{const D=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],le=oe=>{const ce=D.indexOf(oe??"");return ce<0?D.length:ce};return W.filter(oe=>oe.relation!=="collected_in").map((oe,ce)=>({r:oe,i:ce})).sort((oe,ce)=>le(oe.r.relation)-le(ce.r.relation)||oe.i-ce.i).map(oe=>oe.r)},[W]),M=f.useMemo(()=>{const D=nn(e.resources,e.resource_groups);return[...D.mirrors.flatMap(le=>le.items.map(oe=>({r:oe,kind:a(le.label)}))),...D.buckets.flatMap(le=>le.items.map(oe=>({r:oe,kind:a(mi(le.key))})))]},[e.resources,e.resource_groups,a]),P=e.indexed_by||[],R=e.emendated_by||[],ne=f.useMemo(()=>{var ee,re,be;const D=[],le=(re=(ee=e.authors)==null?void 0:ee[0])==null?void 0:re.dynasty;le&&D.push({label:"成書",value:a(le)});const oe=et(e,c.unit.juan);if(oe){const ae=(be=e.juan_count)==null?void 0:be.description;D.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[a(oe),ae&&ae!==oe?t.jsxs("span",{className:"bim-d-meta",children:["(",a(ae),")"]}):null]})})}e.loss_status&&D.push({label:"存佚",value:a(Rp(e.loss_status))});const ce=e._edition_count??u.length;ce&&D.push({label:"版本",value:t.jsxs(t.Fragment,{children:[ce," ",a("種"),w&&A?t.jsxs("span",{className:"bim-d-meta",children:[" ",a(`${A} 種有影印`)]}):null]})});const ue=E.allRows.filter(ae=>ae.sortYear!=null),me=ue.length>0?ue.reduce((ae,ke)=>ae.sortYear<=ke.sortYear?ae:ke):null;me!=null&&me.era.era?D.push({label:"最早存世",value:a([me.era.era,me.era.reign].filter(Boolean).join(" ")),title:me.era.source==="edition"?a("據版本題名推斷"):void 0}):z&&D.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":a("載入中"),children:"…"})}),(P.length||R.length)&&D.push({label:"著錄",value:t.jsxs(t.Fragment,{children:[P.length?`${P.length} ${a("家")}`:"—",R.length?t.jsxs("span",{className:"bim-d-meta",children:[" ",a(`考證 ${R.length} 條`)]}):null]})});const Q=Lo(e.additional_titles);Q.length&&D.push({label:"又名",value:Q.map(a).join("、")});const q=Lo(e.attached_texts);q.length&&D.push({label:"附載",value:q.map(a).join("、")});const N=(e.additional_works||[]).map(ae=>a(ae.book_title)+(ae.n_juan!=null?` ${ae.n_juan}${a(c.unit.juan)}`:""));return N.length&&D.push({label:"附錄",value:N.join("、")}),D},[e,a,c,u.length,w,z,A,E.allRows,P.length,R.length]),I=e.classification,F=I?[I.l1,I.l2,I.l3,I.l4].filter(Boolean).map(D=>a(D)):[],K=e.subtype?a(c.workSubtype[e.subtype]??e.subtype):"",G=t.jsx(At,{title:a(e.title),byline:t.jsx(bi,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(Re,{items:[...F,I!=null&&I.source?a(`據《${I.source.split("/")[0]}》`):"",K]}),description:(se=e.description)!=null&&se.text?t.jsxs(t.Fragment,{children:[t.jsx(Ke,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(ge=e.description.sources)!=null&&ge.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(D=>a(ba(D))).filter(Boolean).join(" · ")}):null]}):void 0,facts:ne,readAction:s,foot:t.jsx(Mt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(he=e.appendix)==null?void 0:he.map((D,le)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:a(D.title)}),t.jsx(Ke,{text:D.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},le))}),U=E.eras.length>=2?[{key:"",label:c.catalog.all},...E.eras.map(D=>({key:D,label:D}))]:[],te=[];u.length&&te.push({id:"versions",label:"版本",count:u.length}),P.length&&te.push({id:"catalogs",label:"著錄",count:P.length}),T.length&&te.push({id:"collected",label:"收入叢編",count:T.length}),L.length&&te.push({id:"related",label:"相關書目",count:L.length}),M.length&&te.push({id:"resources",label:"在線資源",count:M.length});const O=u.length===0&&P.length===0,Y=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Ce,{id:"versions",title:"版本",meta:t.jsx(Re,{items:[a(`共 ${u.length} 種`),w&&A?a(`${A} 種有影印`):"",E.rows.length!==E.allRows.length?a(`當前 ${E.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&U.length===0&&u.length>1?"":void 0,children:[U.length>0&&t.jsx(rn,{items:U,value:k,onChange:D=>{m(D),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Ir,{label:"只看有影印",checked:v,onChange:D=>{y(D),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:a(B?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("版本")}),t.jsx("th",{children:a("年代")}),t.jsx("th",{children:a("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:a("影印")})})]})}),t.jsx("tbody",{children:C.map(D=>{var le;return t.jsx(Np,{row:D,measure:(le=x.get(D.id))==null?void 0:le.measure_info,loaded:x.has(D.id),onNavigate:i,renderLink:r},D.id)})})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a(k||v?"當前篩選下沒有版本":"暫無版本著錄")}),E.rows.length>C.length&&t.jsx(yt,{label:`展開其餘 ${E.rows.length-C.length} 種版本`,onClick:()=>b(!0)}),E.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:a("部分年代據版本題名推斷,非著錄原文")})]}),P.length>0&&t.jsx(Bp,{items:P,onNavigate:i,renderLink:r}),O&&t.jsx(Ce,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該作品的版本與書目收錄。")})})]}),Z=(D,le)=>t.jsx(Pe,{id:D,label:a(le),onNavigate:i,renderLink:r,dense:!0}),X=t.jsxs(t.Fragment,{children:[t.jsx(ct,{id:"collected",title:"收入叢編",items:T.map(D=>Z(D.id,D.title))}),t.jsx(ct,{id:"related",title:"相關書目",meta:a(`${L.length} 部`),items:L.map(D=>t.jsxs(t.Fragment,{children:[Z(D.id,D.title),t.jsx("span",{className:"bim-d-meta",title:D.note?a(D.note):void 0,children:a(Ip(D.relation))})]}))}),t.jsx(ct,{id:"resources",title:"在線資源",cap:6,items:M.map(({r:D,kind:le})=>{const oe=a((D.url?tt(D.url):void 0)||D.name),ce=bt(D);return t.jsxs(t.Fragment,{children:[ce?t.jsxs("a",{href:ce,target:"_blank",rel:"noopener noreferrer",children:[oe," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:oe}),le&&t.jsx("span",{className:"bim-d-meta",children:le})]})})})]});return t.jsx(Wt,{railTop:l,back:p,nav:te,railLinks:d,main:Y,card:G,side:X})};function Lo(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function No(e,n){return n((e.url?tt(e.url):void 0)||e.name)}function Np({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=V(),p=[e.era.era,e.era.reign].filter(Boolean).join(" "),d=e.era.source==="edition",c=e.holders[0],a=c?No(c,l):e.locationName?l(e.locationName):"",u=e.images[0],x=u?bt(u):void 0,g=e.images.map(h=>No(h,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Pe,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n&&t.jsx("span",{className:"bim-d-meta",children:l(n)})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${p?"":" bim-d-zt-blank"}`,title:d?l("據版本題名推斷"):void 0,children:p?l(p):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${a?"":" bim-d-zt-blank"}`,children:[a||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(x?t.jsx("a",{className:"bim-d-flag",href:x,target:"_blank",rel:"noopener noreferrer",title:g,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:g,children:l("有影印")}))})]})}function Bp({items:e,onNavigate:n,renderLink:i}){const r=ie(),{convert:s}=V(),[l,p]=f.useState(0),d=e[Math.min(l,e.length-1)];return t.jsx(Ce,{id:"catalogs",title:"著錄",meta:s(`歷代書目 ${e.length} 家`),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-lu-list bim-d-ui",role:"tablist","aria-label":s("著錄書目"),children:e.map((c,a)=>t.jsx("li",{role:"presentation",children:t.jsx("button",{type:"button",role:"tab","aria-selected":a===l,onClick:()=>p(a),children:s(c.source)})},a))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:s(d.title_info)}),t.jsx(Re,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?t.jsx(Pe,{id:d.source_bid,label:s(d.source),onNavigate:n,renderLink:i,dense:!0}):s(d.source),d.section?s(d.section):"",d.author_info?`${s(r.label.authorInfo)} ${s(d.author_info)}`:"",d.edition?`${s(r.label.edition)} ${s(d.edition)}`:"",d.page??""]}),d.summary&&t.jsx("p",{className:"bim-d-quote",children:Ie(s(d.summary))}),d.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s(r.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:Ie(s(d.comment))})]}),d.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s(r.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:Ie(s(d.additional_comment))})]}),!d.summary&&!d.comment&&!d.additional_comment&&!d.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:s("僅著錄書名,無提要。")})]})]})})}const Bo=8,Cs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:p,railLinks:d})=>{var L,M,P,R,ne;const c=ie(),{convert:a}=V(),[u,x]=f.useState(null),[g,h]=f.useState(new Map),[b,k]=f.useState([]),[m,v]=f.useState(!1);f.useEffect(()=>{if(!n||!e.work_id){x(null);return}let I=!1;return n.getItem(e.work_id).then(F=>{!I&&F&&F.type==="work"&&x(F)}).catch(()=>{}),()=>{I=!0}},[n,e.work_id]),f.useEffect(()=>{const I=e.contained_in||[];if(!n||I.length===0){h(new Map);return}let F=!1;return Promise.all(I.map(K=>{const G=typeof K=="string"?K:K.id;return n.getItem(G).then(U=>[G,U]).catch(()=>[G,null])})).then(K=>{if(F)return;const G=new Map;for(const[U,te]of K)te&&G.set(U,te);h(G)}),()=>{F=!0}},[n,e.contained_in]);const y=f.useMemo(()=>{const I=new Set([...(u==null?void 0:u.books)||[],...e.related_books||[]]);return I.delete(e.id),[...I]},[u==null?void 0:u.books,e.related_books,e.id]);f.useEffect(()=>{if(!n||y.length===0){k([]);return}const I=m?y:y.slice(0,Bo);let F=!1;return Promise.all(I.map(K=>n.getItem(K).then(G=>({id:K,title:G==null?void 0:G.title,edition:G==null?void 0:G.edition})).catch(()=>({id:K})))).then(K=>{F||k(K)}),()=>{F=!0}},[n,y,m]);const j=f.useMemo(()=>{const I=nn(e.resources,e.resource_groups);return[...I.mirrors.flatMap(F=>F.items.map(K=>({r:K,kind:a(F.label),all:F.items}))),...I.buckets.flatMap(F=>F.items.map(K=>({r:K,kind:a(mi(F.key)),all:F.items})))]},[e.resources,e.resource_groups,a]),$=Nt(e),S=Sr(e),_=new Set((e.contained_in||[]).map(I=>typeof I=="string"?0:Rt(I.volume_index).length).filter(I=>I>0)),w=f.useMemo(()=>{var te,O,Y,Z;const I=[];S&&I.push({label:"版本類型",value:a(S),title:(te=e.lineage)!=null&&te.category?void 0:a("據版本題名推斷")}),($.era||$.reign)&&I.push({label:"刊寫年代",value:a([$.era,$.reign].filter(Boolean).join(" ")),title:$.source==="edition"?a("據版本題名推斷"):void 0});const F=et(e,c.unit.juan);F&&I.push({label:"卷帙",value:a(F)});const K=(e.contained_in||[]).flatMap(X=>typeof X=="string"?[]:Rt(X.volume_index));K.length&&I.push({label:"冊次",value:a(`第 ${on(K,c.unit.volume)} ${c.unit.volume}(${K.length} ${c.unit.volume})`)});const G=(e.resources||[]).filter(X=>(X.types||(X.type?[X.type]:[])).includes("physical"));G.length?I.push({label:"存藏",value:G.slice(0,2).map(X=>a(X.name)).join("、")+(G.length>2?a(` 等 ${G.length} 處`):"")}):(O=e.current_location)!=null&&O.name&&I.push({label:"存藏",value:a(e.current_location.name)}),(Y=e.page_count)!=null&&Y.description&&I.push({label:c.label.pageCount,value:a(e.page_count.description)}),(Z=e.publication_info)!=null&&Z.details&&I.push({label:"刊印",value:a(e.publication_info.details)});const U=[...Rn(e.additional_titles),...Rn(e.attached_texts)];return U.length&&I.push({label:"又名",value:U.map(a).join("、")}),I},[e,a,c,$,S]),z=a(e.title),B=e.edition?a(e.edition):void 0,E=t.jsx(At,{title:z,subtitle:B,byline:t.jsx(bi,{authors:e.authors??(u==null?void 0:u.authors),onNavigate:i,renderLink:r}),meta:t.jsx(Re,{items:[a("版本"),S?a(S):"",$.era?a($.era):""]}),description:(L=e.description)!=null&&L.text?t.jsx(Ke,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,facts:w,readAction:s,foot:t.jsx(Mt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),C=e.contained_in||[],A=[];j.length&&A.push({id:"resources",label:"影印與全文",count:j.length}),C.length&&A.push({id:"collections",label:"收入叢編",count:C.length}),(M=e.location_history)!=null&&M.length&&A.push({id:"provenance",label:"流轉歷史"}),u&&A.push({id:"work",label:"所屬作品"}),y.length&&A.push({id:"siblings",label:"其他版本",count:y.length});const W=t.jsxs(t.Fragment,{children:[j.length>0&&t.jsx(Ce,{id:"resources",title:"影印與全文",meta:a(`${j.length} 處`),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:j.map(({r:I,kind:F,all:K},G)=>t.jsx(Wp,{item:I,kind:F,siblings:K,listedVolumeCounts:_},`${I.id||I.url||I.name}-${G}`))})})}),C.length>0&&t.jsx(Ce,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:C.map((I,F)=>{var O,Y;const K=typeof I=="string"?I:I.id,G=typeof I=="string"?[]:Rt(I.volume_index),U=g.get(K),te=(U==null?void 0:U._member_count)||((O=U==null?void 0:U.books)==null?void 0:O.length)||((Y=U==null?void 0:U.contained_works)==null?void 0:Y.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Pe,{id:K,label:U?a(U.title):K,onNavigate:i,renderLink:r,dense:!0}),G.length>0&&t.jsx(Ap,{volumes:G,unit:c.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${te?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:te>0&&a(`全 ${te} ${c.unit.bu}`)})]},`${K}-${F}`)})})})}),(P=e.location_history)!=null&&P.length?t.jsx(Ce,{id:"provenance",title:"流轉歷史",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:e.location_history.map((I,F)=>t.jsxs("tr",{children:[t.jsx("td",{className:"bim-d-zt-main",children:t.jsx("span",{className:"bim-d-zt-name",children:a(I.name)})}),t.jsx("td",{className:`bim-d-zt-sub${I.description||I.start_date?"":" bim-d-zt-blank"}`,children:t.jsx(Re,{items:[[I.start_date,I.end_date].filter(Boolean).join("—"),I.description?a(I.description):""]})})]},F))})})}):null,j.length===0&&C.length===0&&!((R=e.location_history)!=null&&R.length)&&t.jsx(Ce,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該版本的影印、全文與收藏信息。")})})]}),T=t.jsxs(t.Fragment,{children:[u&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:a(c.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Pe,{id:u.id,label:a(u.title),onNavigate:i,renderLink:r})}),t.jsx(Re,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[a(et(u,c.unit.juan)),...(u.authors||[]).slice(0,2).map(I=>`${I.dynasty?`〔${a(I.dynasty)}〕`:""}${a(I.name)}`),u._edition_count?a(`${u._edition_count} 種版本`):""]}),((ne=u.description)==null?void 0:ne.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:4,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:a(u.description.text.replace(/[#*_>`[\]]/g,""))})]}),y.length>0&&t.jsxs("div",{children:[t.jsx(ct,{id:"siblings",title:c.relation.siblingVersions,meta:a(`${y.length} 種`),cap:m?b.length:Bo,items:b.map(I=>t.jsx(Pe,{id:I.id,label:a(I.edition||I.title||I.id),onNavigate:i,renderLink:r,dense:!0}))}),!m&&y.length>b.length&&b.length>0&&t.jsx(yt,{label:`顯示更多(${y.length-b.length})`,onClick:()=>v(!0)})]})]});return t.jsx(Wt,{railTop:l,back:p,nav:A,railLinks:d,main:W,card:E,side:T})};function Wp({item:e,kind:n,siblings:i,listedVolumeCounts:r}){const{convert:s}=V(),[l,p]=f.useState(!1),d=Xt(e),c=!!d&&d.expected>0&&!r.has(d.expected),a=(e.url?tt(e.url):void 0)||e.name,u=hr(e,i),x=s(u?`${a}(${u})`:a),g=bt(e),h=Bt(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[g?t.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",children:[x," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:x}),h&&t.jsx("span",{className:"bim-d-meta",children:s(h)}),c&&l&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(Qn,{item:e})})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${n?"":" bim-d-zt-blank"}`,children:n}),t.jsx("td",{className:c?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:c&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":l,onClick:()=>p(b=>!b),children:s(l?"收起分冊":`展開 ${d.expected} 冊`)})})]})}function Ap({volumes:e,unit:n}){const{convert:i}=V();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${on(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}const Mp=16,Is=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,readAction:p,railTop:d,back:c,railLinks:a})=>{var I,F,K,G,U,te;const u=ie(),{convert:x}=V(),[g,h]=f.useState(""),[b,k]=f.useState(!1),m=f.useMemo(()=>vr(e,n),[e,n]),v=f.useMemo(()=>g?m.rows.filter(O=>O.section===g):m.rows,[m.rows,g]),y=b?v:v.slice(0,Mp),[j,$]=f.useState(new Map),S=f.useMemo(()=>y.filter(O=>O.id&&O.title===O.id&&!j.has(O.id)).map(O=>O.id),[y,j]);f.useEffect(()=>{if(!i||S.length===0)return;let O=!1;return Promise.all(S.map(Y=>i.getItem(Y).then(Z=>[Y,{title:Z==null?void 0:Z.title,edition:Z==null?void 0:Z.edition}]).catch(()=>[Y,{}]))).then(Y=>{O||$(Z=>{const X=new Map(Z);for(const[se,ge]of Y)X.set(se,ge);return X})}),()=>{O=!0}},[i,S]);const _=f.useMemo(()=>{const O=nn(e.resources,e.resource_groups);return[...O.mirrors.flatMap(Y=>Y.items.map(Z=>({r:Z,kind:x(Y.label)}))),...O.buckets.flatMap(Y=>Y.items.map(Z=>({r:Z,kind:x(mi(Y.key))})))]},[e.resources,e.resource_groups,x]),w=e.contained_works||[],z=new Set(m.rows.map(O=>O.id).filter(Boolean)),B=w.length>0&&!w.every(O=>z.has(O.id)),E=(()=>{const O=m.rows.map(Y=>Y.edition).filter(Boolean);return O.length>1&&new Set(O).size===1})(),C=m.sections.length>0,A=m.rows.some(O=>O.volumes.length>0||O.expected!=null),W=e._member_count||((I=e.books)==null?void 0:I.length)||w.length,T=f.useMemo(()=>{var Z,X,se;const O=[];W&&O.push({label:"種數",value:`${W} ${x(u.unit.bu)}`});const Y=et(e,u.unit.juan);return Y&&O.push({label:"卷數",value:x(Y),title:(Z=e.juan_count)!=null&&Z.description?x(e.juan_count.description):void 0}),m.totalVolumes&&O.push({label:"全帙冊數",value:`${m.totalVolumes} ${x(u.unit.volume)}`}),(X=e.publication_info)!=null&&X.details&&O.push({label:"刊印",value:x(e.publication_info.details)}),(se=e.publication_info)!=null&&se.year&&O.push({label:"年代",value:x(e.publication_info.year)}),O},[e,W,m.totalVolumes,x,u]),L=t.jsx(At,{title:x(e.title),byline:t.jsx(bi,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Re,{items:[x("叢編"),e.subtype==="work_collection"?x("作品集"):"",(F=e.publication_info)!=null&&F.year?x(e.publication_info.year):""]}),description:(K=e.description)!=null&&K.text||(G=e.history)!=null&&G.length?t.jsxs(t.Fragment,{children:[((U=e.description)==null?void 0:U.text)&&t.jsx(Ke,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(te=e.history)!=null&&te.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((O,Y)=>t.jsx("li",{children:x(O)},Y))}):null]}):void 0,facts:T,readAction:p,foot:t.jsx(Mt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),M=[];m.rows.length&&M.push({id:"titles",label:u.section.containedBooks,count:m.rows.length}),_.length&&M.push({id:"resources",label:"影印與全文",count:_.length}),B&&M.push({id:"works",label:u.section.containedWorks,count:w.length});const P=C?[{key:"",label:u.catalog.all},...m.sections.map(O=>({key:O,label:O}))]:[],R=t.jsxs(t.Fragment,{children:[m.rows.length>0&&t.jsxs(Ce,{id:"titles",title:u.section.containedBooks,meta:t.jsx(Re,{items:[x(`共 ${m.rows.length} ${u.unit.items}`),W&&W!==m.rows.length?x(`成員 ${W} ${u.unit.bu}`):"",v.length!==m.rows.length?x(`當前 ${v.length} ${u.unit.items}`):""]}),action:l,children:[P.length>0&&t.jsx("div",{className:"bim-d-filters bim-d-ui",children:t.jsx(rn,{items:P,value:g,onChange:O=>{h(O),k(!1)}})}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:x("書名")}),C&&t.jsx("th",{children:x("部類")}),A&&t.jsx("th",{children:x("全帙冊次")})]})}),t.jsx("tbody",{children:y.map((O,Y)=>{var D;const Z=O.id?j.get(O.id):void 0,X=Z!=null&&Z.title?{...O,title:Z.title}:O,se=[(D=X.subItems)!=null&&D.length?X.subItems.map(le=>x(le)).join("、"):"",X.edition&&!E?x(X.edition):""].filter(Boolean).join(" · "),ge=X.volumes.length>0?x(`第 ${on(X.volumes,u.unit.volume)} ${u.unit.volume}`):X.expected!=null?x(`${X.found??0}/${X.expected} ${u.unit.volume}`):"",he=X.section?x(X.section.endsWith("部")?X.section:`${X.section}部`):"";return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[X.id?t.jsx(Pe,{id:X.id,label:x(X.title),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:x(X.title)}),se&&t.jsx("span",{className:"bim-d-meta",children:se})]}),C&&t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${he?"":" bim-d-zt-blank"}`,children:he||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),A&&t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ge?"":" bim-d-zt-blank"}`,children:ge||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})})]},`${X.id??X.title}-${Y}`)})})]}),y.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:x(u.catalog.noMatch)}),v.length>y.length&&t.jsx(yt,{label:`展開其餘 ${v.length-y.length} ${u.unit.items}`,onClick:()=>k(!0)})]}),_.length>0&&t.jsx(Ce,{id:"resources",title:"影印與全文",meta:x(`${_.length} 處`),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:_.map(({r:O,kind:Y},Z)=>{const X=x((O.url?tt(O.url):void 0)||O.name),se=bt(O),ge=Bt(O)||O.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[se?t.jsxs("a",{href:se,target:"_blank",rel:"noopener noreferrer",children:[X," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:X}),ge&&t.jsx("span",{className:"bim-d-meta",children:x(ge)})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Y?"":" bim-d-zt-blank"}`,children:Y})]},`${O.id||O.url||O.name}-${Z}`)})})})}),m.rows.length===0&&_.length===0&&t.jsx(Ce,{title:u.section.containedBooks,children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該叢編的子目。")})})]}),ne=B?t.jsx(ct,{id:"works",title:u.section.containedWorks,meta:x(`${w.length} 種`),cap:12,items:w.map(O=>t.jsx(Pe,{id:O.id,label:x(O.title),onNavigate:r,renderLink:s,dense:!0}))}):null;return t.jsx(Wt,{railTop:d,back:c,nav:M,railLinks:a,main:R,card:L,side:ne})},Fp=16,yn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Wo(e){if(!e)return yn.length;const n=yn.indexOf(e);return n===-1?yn.length:n}const Pp={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function Ao(e){return e==null?"":e<0?`前${-e}`:String(e)}const Ts=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:p})=>{var W;const d=ie(),{convert:c}=V(),[a,u]=f.useState("全部"),[x,g]=f.useState(!1),[h,b]=f.useState("default"),[k,m]=f.useState(new Map),v=f.useMemo(()=>(e.works||[]).map(T=>{const L=k.get(T.work_id);return{id:T.work_id,title:(L==null?void 0:L.title)??T.title??T.work_id,role:T.role||"",cls:Jn(T.role),versionCount:L==null?void 0:L.versionCount,loaded:!!(L!=null&&L.loaded)}}),[e.works,k]),y=f.useMemo(()=>jr((e.works||[]).map(T=>T.role)),[e.works]),j=f.useMemo(()=>{const T=a==="全部"?v:v.filter(L=>L.cls===a);return h==="versions"?[...T].sort((L,M)=>(M.versionCount??-1)-(L.versionCount??-1)):T},[v,a,h]),$=x?j:j.slice(0,Fp),S=f.useMemo(()=>$.filter(T=>!k.has(T.id)).map(T=>T.id),[$,k]);f.useEffect(()=>{if(!n||S.length===0)return;let T=!1;return Promise.all(S.map(L=>n.getItem(L).then(M=>{var ne,I;const P=M??{},R=P._edition_count??(((ne=P.books)==null?void 0:ne.length)??0)+(((I=P.collections)==null?void 0:I.length)??0);return[L,{id:L,title:P.title,versionCount:R,loaded:!0}]}).catch(()=>[L,{id:L,loaded:!0}]))).then(L=>{T||m(M=>{const P=new Map(M);for(const[R,ne]of L)P.set(R,ne);return P})}),()=>{T=!0}},[n,S]);const _=f.useMemo(()=>{const T=new Map;for(const L of e.alt_names||[]){const M=L.type||d.section.aliases;T.has(M)||T.set(M,[]),T.get(M).push(L.name)}return[...T.entries()].sort((L,M)=>Wo(L[0])-Wo(M[0])).map(([L,M])=>({label:L,names:M}))},[e.alt_names,d]),w=e.birth_year!=null||e.death_year!=null?`${Ao(e.birth_year)||"?"}—${Ao(e.death_year)||"?"}`:"",z=f.useMemo(()=>{var P,R;const T=[];for(const ne of _)T.push({label:ne.label,value:ne.names.map(I=>c(I)).join("、")});e.dynasty&&T.push({label:"時代",value:c(e.dynasty)}),w&&T.push({label:"生卒",value:w});const L=(e.works||[]).length;L&&T.push({label:"著作",value:`${L} ${c("種")}`});const M=(P=e.external_ids)==null?void 0:P.cbdb_id;return M!=null&&T.push({label:"CBDB",value:t.jsxs(t.Fragment,{children:[M,((R=e.external_ids)==null?void 0:R.cbdb_match)==="auto"&&t.jsx("span",{className:"bim-d-meta",title:c("由姓名、朝代與著作重合度自動匹配,未經人工複核"),children:c("自動匹配")})]})}),T},[e,_,w,c]),B=t.jsx(At,{title:c(e.primary_name||e.title),meta:t.jsx(Re,{items:[c(Pp[e.subtype]??""),w]}),description:(W=e.description)!=null&&W.text?t.jsx(Ke,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,facts:z,foot:t.jsx(Mt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),E=y.map(T=>({key:T.cls,label:`${T.label} ${T.count}`})),C=v.length?[{id:"works",label:"著作",count:v.length}]:[],A=v.length===0?t.jsx(Ce,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該人物的關聯作品。")})}):t.jsxs(Ce,{id:"works",title:"著作",meta:t.jsx(Re,{items:[c(`共 ${v.length} 種`),j.length!==v.length?c(`當前 ${j.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[E.length>1&&t.jsx(rn,{items:E,value:a,onChange:T=>{u(T),g(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":h==="versions",onClick:()=>{h==="default"&&g(!0),b(T=>T==="default"?"versions":"default")},children:c(h==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("作品")}),t.jsx("th",{children:c("職任")}),t.jsx("th",{children:c("存世版本")})]})}),t.jsx("tbody",{children:$.map(T=>t.jsxs("tr",{children:[t.jsx("td",{className:"bim-d-zt-main",children:t.jsx(Pe,{id:T.id,label:c(T.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${T.role?"":" bim-d-zt-blank"}`,children:T.role?c(T.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${T.loaded?"":" bim-d-zt-blank"}`,children:T.loaded?T.versionCount?c(`${T.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:c("未著錄")}):""})]},T.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("該職任下的著作尚未著錄。")}),j.length>$.length&&t.jsx(yt,{label:`展開其餘 ${j.length-$.length} 種著作`,onClick:()=>g(!0)})]});return t.jsx(Wt,{railTop:s,back:l,nav:C,railLinks:p,main:A,card:B})},yi="(max-width: 719px)",Op=`${yi}, (pointer: coarse)`,Rs=`
|
|
572
|
+
.bim-ct {
|
|
573
|
+
display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
|
|
574
|
+
max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
|
|
575
|
+
background: ${o("page-bg")}; color: ${o("ink")}; font-family: ${o("font-ui")};
|
|
576
|
+
}
|
|
577
|
+
.bim-ct *, .bim-ct *::before, .bim-ct *::after { box-sizing: border-box; }
|
|
578
|
+
.bim-ct-sr {
|
|
579
|
+
position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
|
|
580
|
+
overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/* ── 左栏 ── */
|
|
584
|
+
.bim-ct-side { position: sticky; top: calc(${o("reader-top")} + 16px); max-height: calc(100vh - ${o("reader-top")} - 32px); overflow-y: auto; }
|
|
585
|
+
.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")}; }
|
|
586
|
+
.bim-ct-drawer-btn { display: none; }
|
|
587
|
+
|
|
588
|
+
/* ── 分类树 ── */
|
|
589
|
+
.bim-ct-tree, .bim-ct-tree ul { list-style: none; margin: 0; padding: 0; }
|
|
590
|
+
.bim-ct-tree li { outline: none; }
|
|
591
|
+
.bim-ct-row {
|
|
592
|
+
display: flex; align-items: center; gap: 4px; min-height: 34px;
|
|
593
|
+
padding: 0 10px 0 calc(var(--bimct-lv, 0) * 14px + 4px); border-radius: 6px;
|
|
594
|
+
font-size: 14px; line-height: 1.4; color: ${o("body-fg")}; cursor: pointer; user-select: none;
|
|
595
|
+
}
|
|
596
|
+
.bim-ct-row:hover { background: ${o("row-hover-bg")}; color: ${o("ink")}; }
|
|
597
|
+
.bim-ct-tree li[aria-selected="true"] > .bim-ct-row { background: ${o("zebra-bg")}; color: ${o("accent")}; font-weight: 700; }
|
|
598
|
+
.bim-ct-tree li:focus-visible > .bim-ct-row { outline: 2px solid ${o("accent")}; outline-offset: -2px; }
|
|
599
|
+
.bim-ct-tw {
|
|
600
|
+
flex: none; width: 20px; align-self: stretch; display: inline-flex; align-items: center; justify-content: center;
|
|
601
|
+
color: ${o("aux-fg")};
|
|
602
|
+
}
|
|
603
|
+
.bim-ct-tw svg { transition: transform 0.15s; }
|
|
604
|
+
.bim-ct-tree li[aria-expanded="true"] > .bim-ct-row .bim-ct-tw svg { transform: rotate(90deg); }
|
|
605
|
+
.bim-ct-lb { min-width: 0; flex: 1; overflow-wrap: anywhere; }
|
|
606
|
+
.bim-ct-n { flex: none; margin-left: 8px; font-size: 12px; font-weight: 400; color: ${o("aux-fg")}; font-variant-numeric: tabular-nums; }
|
|
607
|
+
.bim-ct-tree li[aria-selected="true"] > .bim-ct-row .bim-ct-n { color: ${o("accent")}; }
|
|
608
|
+
.bim-ct-tree .bim-ct-last { margin-top: 6px; padding-top: 6px; border-top: 1px solid ${o("rule")}; }
|
|
609
|
+
|
|
610
|
+
/* ── 右栏 ── */
|
|
611
|
+
.bim-ct-main { min-width: 0; }
|
|
612
|
+
.bim-ct-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 14px; }
|
|
613
|
+
.bim-ct-title { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: 0.04em; color: ${o("ink")}; }
|
|
614
|
+
.bim-ct-crumb { font-size: 13px; color: ${o("aux-fg")}; }
|
|
615
|
+
.bim-ct-stat { font-size: 13px; color: ${o("aux-fg")}; }
|
|
616
|
+
.bim-ct-search { margin: 0 0 16px; }
|
|
617
|
+
|
|
618
|
+
/* ── 卡片网格 ── */
|
|
619
|
+
.bim-ct-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
|
|
620
|
+
.bim-ct-card { min-width: 0; }
|
|
621
|
+
.bim-ct-card > a {
|
|
622
|
+
display: flex; flex-direction: column; gap: 6px; height: 100%; min-height: 44px;
|
|
623
|
+
padding: 14px 16px 12px; border-radius: 8px;
|
|
624
|
+
background: ${o("card-bg")}; color: inherit; text-decoration: none;
|
|
625
|
+
transition: background 0.12s;
|
|
626
|
+
}
|
|
627
|
+
.bim-ct-card > a:hover { background: ${o("tint-bg")}; }
|
|
628
|
+
.bim-ct-card > a:hover .bim-ct-ct { color: ${o("accent")}; }
|
|
629
|
+
.bim-ct-card > a:focus-visible { outline: 2px solid ${o("accent")}; outline-offset: 2px; }
|
|
630
|
+
.bim-ct-ch { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
|
|
631
|
+
.bim-ct-ct { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.4; color: ${o("ink")}; overflow-wrap: anywhere; }
|
|
632
|
+
.bim-ct-juan { flex: none; font-size: 12px; color: ${o("aux-fg")}; }
|
|
633
|
+
.bim-ct-by { font-size: 13px; line-height: 1.5; color: ${o("quiet-fg")}; overflow-wrap: anywhere; }
|
|
634
|
+
.bim-ct-dy { font-size: 12px; color: ${o("aux-fg")}; }
|
|
635
|
+
.bim-ct-sum {
|
|
636
|
+
margin: 0; font-size: 13px; line-height: 1.65; color: ${o("body-fg")};
|
|
637
|
+
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden;
|
|
638
|
+
}
|
|
639
|
+
.bim-ct-cls { margin-top: auto; padding-top: 2px; font-size: 12px; color: ${o("aux-fg")}; }
|
|
640
|
+
.bim-ct-empty { padding: 48px 0; text-align: center; font-size: 14px; color: ${o("aux-fg")}; }
|
|
641
|
+
|
|
642
|
+
/* ── 分页 ── */
|
|
643
|
+
.bim-ct-pager { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px; margin: 24px 0 0; font-size: 14px; }
|
|
644
|
+
.bim-ct-pager ol { display: contents; list-style: none; }
|
|
645
|
+
.bim-ct-pg {
|
|
646
|
+
display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 34px; padding: 0 10px;
|
|
647
|
+
border: 0; border-radius: 6px; background: none; font: inherit; color: ${o("body-fg")};
|
|
648
|
+
text-decoration: none; cursor: pointer;
|
|
649
|
+
}
|
|
650
|
+
.bim-ct-pg:hover { background: ${o("row-hover-bg")}; color: ${o("accent")}; }
|
|
651
|
+
.bim-ct-pg:focus-visible { outline: 2px solid ${o("accent")}; outline-offset: 1px; }
|
|
652
|
+
.bim-ct-pg[aria-current="page"] { background: ${o("zebra-bg")}; color: ${o("accent")}; font-weight: 700; cursor: default; }
|
|
653
|
+
.bim-ct-pg[aria-disabled="true"], .bim-ct-pg:disabled { color: ${o("aux-fg")}; opacity: 0.6; cursor: default; background: none; }
|
|
654
|
+
.bim-ct-gap { min-width: 24px; text-align: center; color: ${o("aux-fg")}; }
|
|
655
|
+
.bim-ct-pg-of { display: none; padding: 0 12px; color: ${o("body-fg")}; font-variant-numeric: tabular-nums; }
|
|
656
|
+
|
|
657
|
+
@media (max-width: 1199px) {
|
|
658
|
+
.bim-ct-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
@media ${yi} {
|
|
662
|
+
.bim-ct { display: block; padding: 12px 16px 40px; }
|
|
663
|
+
.bim-ct-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
|
|
664
|
+
.bim-ct-side { position: static; max-height: none; overflow: visible; margin: 0 0 12px; }
|
|
665
|
+
.bim-ct-side-h { display: none; }
|
|
666
|
+
.bim-ct-drawer-btn {
|
|
667
|
+
display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 0 14px;
|
|
668
|
+
border: 0; border-radius: 8px; background: ${o("tint-bg")};
|
|
669
|
+
font: inherit; font-size: 14px; color: ${o("ink")}; text-align: left; cursor: pointer;
|
|
670
|
+
}
|
|
671
|
+
.bim-ct-drawer-btn span { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
672
|
+
.bim-ct-drawer-btn svg { flex: none; transition: transform 0.15s; color: ${o("aux-fg")}; }
|
|
673
|
+
.bim-ct-drawer-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
|
|
674
|
+
.bim-ct-drawer-btn:focus-visible { outline: 2px solid ${o("accent")}; outline-offset: 2px; }
|
|
675
|
+
.bim-ct-drawer { margin-top: 6px; padding: 6px; border-radius: 8px; background: ${o("card-bg")}; max-height: 70vh; overflow-y: auto; }
|
|
676
|
+
.bim-ct[data-drawer="closed"] .bim-ct-drawer { display: none; }
|
|
677
|
+
.bim-ct-title { font-size: 18px; }
|
|
678
|
+
.bim-ct-pager { flex-wrap: nowrap; justify-content: space-between; }
|
|
679
|
+
.bim-ct-pager ol { display: none; }
|
|
680
|
+
.bim-ct-pg-of { display: inline; }
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/* 点击目标 ≥44px(Q5):触屏与窄屏 */
|
|
684
|
+
@media ${Op} {
|
|
685
|
+
.bim-ct-row { min-height: 44px; }
|
|
686
|
+
.bim-ct-tw { width: 44px; }
|
|
687
|
+
.bim-ct-pg { min-width: 44px; height: 44px; }
|
|
688
|
+
}
|
|
689
|
+
`,ht="未分類",Ge="all",ji=20;function Pt(e){if(!e)return[];const n=[];for(const i of[e.l1,e.l2,e.l3,e.l4]){const r=(i??"").trim();if(!r)break;n.push(r)}return n}function Dp(e){const n=Pt(e);return n.length?n.join("/"):ht}function Hp(e){const n=Pt(e);return n.length?n.map((i,r)=>n.slice(0,r+1).join("/")):[ht]}function Gp(e,n=[]){const i=new Map;n.forEach((d,c)=>{const a=[d.cata_l1,d.cata_l2,d.cata_l3,d.cata_l4].filter(u=>!!u);a.forEach((u,x)=>{const g=a.slice(0,x+1).join("/");i.has(g)||i.set(g,c)})});const r=new Map;let s=0;for(const d of e){const c=Pt(d.classification);if(!c.length){s++;continue}let a=r;c.forEach((u,x)=>{const g=c.slice(0,x+1).join("/");let h=a.get(u);h||(h={id:g,label:u,count:0,children:new Map},a.set(u,h)),h.count++,a=h.children})}const l=d=>[...d.values()].sort((c,a)=>{const u=i.get(c.id)??1/0,x=i.get(a.id)??1/0;return u!==x?u-x:c.label.localeCompare(a.label,"zh")}).map(c=>{const a={id:c.id,label:c.label,count:c.count};return c.children.size&&(a.children=l(c.children)),a}),p=l(r);return s>0&&p.push({id:ht,label:ht,count:s}),p}function pt(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const r=pt(i.children,n);if(r.length)return[i,...r]}}return[]}function vi(e){return e.reduce((n,i)=>n+i.count,0)}function Up(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function Vp(e){var d;const n={id:e.id,title:e.title||e.id},i=e.juan_count,r=typeof i=="number"?i:i==null?void 0:i.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(c=>c==null?void 0:c.name).map(c=>{const a=c.dynasty||(e.authors.length===1?e.dynasty:void 0);return a?{name:c.name,dynasty:a}:{name:c.name}});s.length&&(n.authors=s);const l=Up(typeof e.description=="string"?e.description:(d=e.description)==null?void 0:d.text);l&&(n.summary=l);const p=Pt(e.classification);return p.length&&(n.classification=p),n}function Yp(e,n){const i=e.summary?0:1,r=n.summary?0:1;return i!==r?i-r:e.title.localeCompare(n.title,"zh")}function Kp(e,n=ji){return Math.max(1,Math.ceil(e/n))}function Es(e,n,i=2){if(n<=1)return[1];const r=new Set([1,n]);for(let p=e-i;p<=e+i;p++)p>=1&&p<=n&&r.add(p);const s=[...r].sort((p,d)=>p-d),l=[];return s.forEach((p,d)=>{if(d>0){const c=p-s[d-1];c===2?l.push(p-1):c>2&&l.push(null)}l.push(p)}),l}const qp=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Jp(e,n,i){const r=[];i&&r.push({id:Ge,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,p)=>{var d;for(const c of l){const a=(d=c.children)!=null&&d.length?c.children:null;r.push({id:c.id,parentId:p,hasChildren:!!a,firstChildId:a?a[0].id:null}),a&&n.has(c.id)&&s(a,c.id)}};return s(e,null),r}function Ls({tree:e,selectedId:n,onSelect:i,allLabel:r="全部",label:s="分類"}){const{convert:l}=V(),p=f.useRef(null),d=n&&n!==Ge?n:null,c=r!==null,[a,u]=f.useState(()=>{const S=new Set;for(const _ of pt(e,d))S.add(_.id);return S});f.useEffect(()=>{const S=pt(e,d);S.length&&u(_=>{if(S.every(z=>_.has(z.id)))return _;const w=new Set(_);for(const z of S)w.add(z.id);return w})},[e,d]);const x=f.useMemo(()=>Jp(e,a,c),[e,a,c]),[g,h]=f.useState(null);f.useEffect(()=>{h(null)},[n]);const b=d??(c?Ge:null),k=f.useMemo(()=>{var w;const S=new Set(x.map(z=>z.id));if(g&&S.has(g))return g;if(b&&S.has(b))return b;const _=pt(e,d).map(z=>z.id).filter(z=>S.has(z));return _.length?_[_.length-1]:((w=x[0])==null?void 0:w.id)??null},[x,g,b,e,d]),m=f.useCallback((S,_)=>{u(w=>{const z=w.has(S),B=_??!z;if(B===z)return w;const E=new Set(w);return B?E.add(S):E.delete(S),E})},[]),v=f.useCallback(S=>{h(S),requestAnimationFrame(()=>{var w;const _=Array.from(((w=p.current)==null?void 0:w.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===S);_==null||_.focus()})},[]),y=f.useCallback((S,_)=>{_&&m(S,!0),i(S)},[i,m]),j=f.useCallback(S=>{const _=S.target.closest("[data-ct-id]");if(!_)return;const w=_.dataset.ctId,z=x.findIndex(C=>C.id===w);if(z<0)return;const B=x[z];let E=null;switch(S.key){case"ArrowDown":E=x[Math.min(x.length-1,z+1)].id;break;case"ArrowUp":E=x[Math.max(0,z-1)].id;break;case"Home":E=x[0].id;break;case"End":E=x[x.length-1].id;break;case"ArrowRight":if(!B.hasChildren)break;a.has(w)?E=B.firstChildId:m(w,!0);break;case"ArrowLeft":B.hasChildren&&a.has(w)?m(w,!1):E=B.parentId;break;case"Enter":case" ":S.preventDefault(),y(w,B.hasChildren);return;default:return}S.preventDefault(),E&&E!==w&&v(E)},[x,a,m,v,y]),$=(S,_)=>S.map(w=>{var A;const z=(A=w.children)!=null&&A.length?w.children:null,B=!!z&&a.has(w.id),E=w.id===d,C=_===1&&w.id===ht;return t.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":z?B:void 0,"aria-selected":E,tabIndex:k===w.id?0:-1,"data-ct-id":w.id,className:C?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{h(w.id),y(w.id,!!z)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:z?W=>{W.stopPropagation(),h(w.id),m(w.id)}:void 0,children:z?t.jsx(qp,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(w.label)}),t.jsx("span",{className:"bim-ct-n",children:w.count.toLocaleString("en-US")})]}),B&&t.jsx("ul",{role:"group",children:$(z,_+1)})]},w.id)});return t.jsxs("ul",{ref:p,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:j,children:[c&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!d,tabIndex:k===Ge?0:-1,"data-ct-id":Ge,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{h(Ge),i(Ge)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),t.jsx("span",{className:"bim-ct-lb",children:l(r)}),t.jsx("span",{className:"bim-ct-n",children:vi(e).toLocaleString("en-US")})]})}),$(e,1)]})}const Ns=e=>`/item/${encodeURIComponent(e)}`;function Zp(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Xp(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function Bs({work:e,href:n}){var p,d;const{convert:i}=V(),r=Xp(e.juan),s=((p=e.authors)==null?void 0:p.filter(c=>c.name))??[],l=((d=e.classification)==null?void 0:d.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:n,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:i(e.title)}),r&&t.jsx("span",{className:"bim-ct-juan",children:i(r)})]}),s.length>0&&t.jsx("span",{className:"bim-ct-by",children:s.map((c,a)=>t.jsxs(f.Fragment,{children:[a>0&&"、",c.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(c.dynasty),"〕"]}),i(c.name)]},a))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:i(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(c=>i(c)).join(" · ")})]})})}function Ws({page:e,pageCount:n,onPage:i,pageHref:r,label:s="分頁"}){const{convert:l}=V();if(n<=1)return null;const p=c=>a=>{i&&(r&&!Zp(a)||(a.preventDefault(),i(c)))},d=(c,a,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:a});const x={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...x,href:r(c),onClick:p(c),children:a}):t.jsx("button",{type:"button",...x,onClick:u.current?void 0:p(c),children:a})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[d(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:Es(e,n).map((c,a)=>t.jsx("li",{style:{display:"contents"},children:c===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):d(c,c,{current:c===e,aria:l(`第 ${c} 頁`)})},c??`gap${a}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),d(e+1,l("下一頁"),{disabled:e>=n})]})}function As({works:e,workLink:n=Ns,emptyText:i="此類暫無作品",...r}){const{convert:s}=V();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:typeof i=="string"?s(i):i}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(l=>t.jsx(Bs,{work:l,href:n(l.id)},l.id))}),t.jsx(Ws,{...r})]})}const Qp=()=>t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:t.jsx("path",{d:"M2.5 4.5 6 8l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function eu({tree:e,selectedId:n,page:i,pageCount:r,works:s,onSelect:l,onPage:p,searchSlot:d,workLink:c,pageHref:a,allLabel:u="全部",allTitle:x="全部典籍",pageSize:g=ji,className:h}){const{convert:b}=V(),m=`bim-ct-drawer-${f.useId().replace(/:/g,"")}`,[v,y]=f.useState(!1),j=pt(e,n&&n!==Ge?n:null),$=j.length?j[j.length-1]:null,S=$?$.label:x,_=$?$.count:vi(e),w=f.useCallback(z=>{y(!1),l(z)},[l]);return t.jsxs("div",{className:h?`bim-ct ${h}`:"bim-ct","data-drawer":v?"open":"closed",children:[t.jsx("style",{children:Rs}),t.jsxs("aside",{className:"bim-ct-side","aria-label":b("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":v,"aria-controls":m,onClick:()=>y(z=>!z),children:[t.jsxs("span",{children:[b("分類"),":",b(j.length?j.map(z=>z.label).join(" › "):u??x)]}),t.jsx(Qp,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:m,children:[t.jsx("h2",{className:"bim-ct-side-h",children:b("分類")}),t.jsx(Ls,{tree:e,selectedId:n,onSelect:w,allLabel:u})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:b(S)}),j.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:b(j.slice(0,-1).map(z=>z.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[b(`共 ${_.toLocaleString("en-US")} 種 · 每頁 ${g} 條`),r>1&&b(` · 第 ${i} / ${r} 頁`)]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(As,{works:s,workLink:c,page:i,pageCount:r,onPage:p,pageHref:a})]})]})}function tu(e){var n;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((n=e.year_range)==null?void 0:n[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function nu(e,n){if(!e.lineage)return null;const i=e.lineage;return{id:e.id,kind:"book",label:e.title,year:i.year,year_text:i.year_text,year_uncertain:i.year_uncertain,category:i.category,status:i.status,extant_juan:i.extant_juan,group:n[e.id],note:i.note}}function Mo(e,n,i){return{id:`derive:${n.ref}->${e}:${i}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function iu(e,n,i){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${i}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function ou(e,n){var a;if(n==="all")return null;const i=(a=e.collections)==null?void 0:a[n],r=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,l=r||s||!!(i!=null&&i.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!i||!l)return null;const p=r?new Set(i.groups):null,d=new Set(i.book_ids??[]);if(p&&e.node_groups)for(const[u,x]of Object.entries(e.node_groups))p.has(x)&&d.add(u);let c=null;if(i.hypothetical_ids&&(c=new Set(i.hypothetical_ids)),p){c||(c=new Set);for(const u of e.hypothetical_nodes??[])u.group&&p.has(u.group)&&c.add(u.id)}return{books:d,hypos:c}}function Kt(e,n,i){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const l=new Set(r.excluded_books??[]),p=r.node_groups??{},d=ou(r,i??r.default_collection??"all"),c=d!==null,a=(d==null?void 0:d.books)??null,u=(d==null?void 0:d.hypos)??null,x=new Set,g=new Set;if(c){const $=new Map(n.map(E=>[E.id,E])),S=new Map((r.hypothetical_nodes??[]).map(E=>[E.id,E])),_=E=>{const C=$.get(E);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(W=>W.ref);const A=S.get(E);return A?(A.derived_from??[]).map(W=>W.ref):[]},w=E=>S.has(E)?!u||u.has(E):!a||a.has(E),z=new Set,B=E=>{if(!z.has(E)){z.add(E);for(const C of _(E))l.has(C)||(w(C)||(S.has(C)?g.add(C):$.has(C)&&x.add(C)),B(C))}};for(const E of n)a&&a.has(E.id)&&!l.has(E.id)&&B(E.id);for(const E of r.hypothetical_nodes??[])u&&u.has(E.id)&&B(E.id)}const h=n.filter($=>!l.has($.id)).filter($=>!a||a.has($.id)||x.has($.id)).map($=>{const S=nu($,p);return S&&x.has($.id)&&(S.bridge=!0),S}).filter($=>$!==null),b=(r.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||g.has($.id)).map($=>{const S=tu($);return g.has($.id)&&(S.bridge=!0),S}),k=[...h,...b],m=new Set(k.map($=>$.id)),v=new Set,y=[],j=$=>{v.has($.id)||!m.has($.source)||!m.has($.target)||(v.add($.id),y.push($))};for(const $ of n)l.has($.id)||!$.lineage||a&&!a.has($.id)&&!x.has($.id)||(($.lineage.derived_from??[]).forEach((S,_)=>{j(Mo($.id,S,_))}),($.lineage.related_to??[]).forEach((S,_)=>{j(iu($.id,S,_))}));for(const $ of r.hypothetical_nodes??[])u&&!u.has($.id)&&!g.has($.id)||($.derived_from??[]).forEach((S,_)=>{j(Mo($.id,S,_))});return{nodes:k,edges:y,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function Ms(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function ru(e,n){const i=[],r=e.version_graph;if(!r)return i;const s=new Set(n.map(c=>c.id)),l=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),p=new Set([...s,...l]),d=(c,a)=>{p.has(a.ref)||i.push(`${c}: derived_from.ref "${a.ref}" 未在 books 或 hypothetical_nodes 中找到`),a.ref_type==="book"&&!s.has(a.ref)&&i.push(`${c}: derived_from.ref "${a.ref}" 标记为 book 但不在 books 列表中`),a.ref_type==="hypothetical"&&!l.has(a.ref)&&i.push(`${c}: derived_from.ref "${a.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const a=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>d(a,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||i.push(`${a}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const a=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>d(a,u))}return i}const Fs=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:s}=V();if(!e.nodes.length)return t.jsx("div",{style:{...yu,...r},className:i,children:"暂无版本图数据"});const l=new Map,p=new Map;for(const g of e.edges)if(g.kind==="derive"){const h=l.get(g.target)??[];h.push(g),l.set(g.target,h)}else for(const h of[g.source,g.target]){const b=p.get(h)??[];b.push(g),p.set(h,b)}const d=new Map(e.nodes.map(g=>[g.id,g])),c=new Map,a=[];for(const g of e.nodes)if(g.group){const h=c.get(g.group)??[];h.push(g),c.set(g.group,h)}else a.push(g);const u=(g,h)=>(g.year??9999)-(h.year??9999);c.forEach(g=>g.sort(u)),a.sort(u);const x=e.groups.filter(g=>c.has(g.id));return t.jsxs("div",{className:i,style:{...lu,...r},children:[e.title&&t.jsx("div",{style:au,children:s(e.title)}),e.description&&t.jsx("div",{style:cu,children:s(e.description)}),x.map(g=>t.jsx(Fo,{label:g.label,color:g.color,nodes:c.get(g.id),incomingMap:l,siblingMap:p,nodeMap:d,renderLink:n},g.id)),a.length>0&&t.jsx(Fo,{label:"其他",nodes:a,incomingMap:l,siblingMap:p,nodeMap:d,renderLink:n})]})},Fo=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:p})=>{const{convert:d}=V();return t.jsxs("div",{style:du,children:[t.jsx("div",{style:{...pu,borderLeftColor:n??o("widget-border")},children:d(e)}),i.map(c=>t.jsx(su,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:p},c.id))]})},su=({node:e,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",p=e.bridge,{convert:d}=V();return t.jsxs("div",{style:{...uu,borderStyle:l||p?"dashed":"solid",opacity:p?.55:e.status==="lost"?.7:1,background:p?o("bg-subtle"):void 0},title:p?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:xu,children:[t.jsx("span",{style:fu,children:l||!s?d(e.label):s(e.id,d(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:gu,children:Ms(d(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:hu,children:[e.category&&t.jsx(zt,{children:d(e.category)}),e.status==="lost"&&t.jsx(zt,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(zt,{tone:"warn",children:"残本"}),l&&t.jsx(zt,{tone:"info",children:"假想祖本"}),p&&t.jsx(zt,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:mu,children:["现存:",d(e.extant_juan)]}),e.note&&t.jsx("div",{style:bu,children:d(e.note)}),n.length>0&&t.jsxs("div",{style:Oo,children:[t.jsx("div",{style:Do,children:"来源:"}),n.map(c=>{const a=r.get(c.source);return t.jsxs("div",{style:Ho(c.confidence),children:[t.jsx("span",{style:Go,children:d(c.relation)}),t.jsx("span",{children:(a==null?void 0:a.kind)==="book"&&s?s(a.id,d(a.label)):d((a==null?void 0:a.label)??c.source)}),c.confidence!=="consensus"&&c.confidence!=="certain"&&t.jsx(Po,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:Uo,children:["· ",d(c.evidence)]})]},c.id)})]}),i.length>0&&t.jsxs("div",{style:Oo,children:[t.jsx("div",{style:Do,children:"关联:"}),i.map(c=>{const a=c.source===e.id?c.target:c.source,u=r.get(a);return t.jsxs("div",{style:Ho(c.confidence),children:[t.jsx("span",{style:Go,children:d(c.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,d(u.label)):d((u==null?void 0:u.label)??a)}),t.jsx(Po,{level:c.confidence}),c.evidence&&t.jsxs("span",{style:Uo,children:["· ",d(c.evidence)]})]},c.id)})]})]})},zt=({children:e,tone:n="default"})=>{const r={default:{bg:o("tag-bg"),fg:o("fg")},warn:{bg:o("warn-bg"),fg:o("warn-fg")},info:{bg:o("info-bg"),fg:o("info-fg")}}[n];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},Po=({level:e})=>{const i={certain:{label:"确定",color:o("confidence-certain")},consensus:{label:"共识",color:o("confidence-consensus")},probable:{label:"推测",color:o("confidence-probable")},disputed:{label:"有争议",color:o("confidence-disputed")}}[e];return i?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${i.color}`,color:i.color,borderRadius:"8px",marginLeft:"4px"},children:i.label}):null},lu={fontSize:"14px",color:o("fg")},au={fontSize:"16px",fontWeight:600,marginBottom:"8px"},cu={fontSize:"13px",color:o("muted"),marginBottom:"16px",lineHeight:1.6},du={marginBottom:"16px"},pu={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:o("fg")},uu={border:`1px solid ${o("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:o("bg")},xu={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},fu={fontSize:"15px",fontWeight:600},gu={fontSize:"12px",color:o("muted")},hu={marginBottom:"6px"},mu={fontSize:"12px",color:o("muted"),margin:"2px 0"},bu={fontSize:"12px",color:o("muted"),fontStyle:"italic",margin:"4px 0"},Oo={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${o("widget-border")}`},Do={fontSize:"11px",color:o("muted"),marginBottom:"2px"},Ho=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Go={display:"inline-block",padding:"0 6px",fontSize:"11px",background:o("tag-bg"),color:o("fg"),borderRadius:"3px",marginRight:"6px"},Uo={fontSize:"11px",color:o("muted")},yu={padding:"20px",textAlign:"center",color:o("muted"),fontSize:"13px"},Ps=({selectedNodeId:e,...n})=>{const[i,r]=f.useState("loading"),[s,l]=f.useState(null);return f.useEffect(()=>{let p=!1;return ju().then(d=>{p||(d?(l(d),r("ready")):r("missing"))}),()=>{p=!0}},[]),i==="loading"?t.jsx("div",{style:Vo,children:"加载图组件中…"}):i==="missing"||!s?t.jsxs("div",{style:Vo,children:[t.jsxs("div",{children:["图组件未安装。请安装 ",t.jsx("code",{children:"@xyflow/react"})," 与 ",t.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),t.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",t.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):t.jsx(vu,{modules:s,selectedNodeId:e,...n})};async function ju(){try{const[e,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let i=!1;try{await import("@xyflow/react/dist/style.css"),i=!0}catch{i=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:n,cssLoaded:i}}catch{return null}}const vu=({graph:e,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:l,modules:p})=>{const{ReactFlow:d,Background:c,Controls:a,Handle:u,Position:x,BaseEdge:g,EdgeLabelRenderer:h,getSmoothStepPath:b,dagre:k}=p,m=f.useMemo(()=>({lineage:_=>{var M,P,R,ne;const w=((M=_.data)==null?void 0:M.stepPosition)??.85,[z,B,E]=b({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:w,borderRadius:5}),C=!!((P=_.data)!=null&&P.isSibling),A=C?B:_.targetX-18,W=C?E:_.targetY-12,T=(R=_.data)==null?void 0:R.labelStyle,L=(ne=_.data)==null?void 0:ne.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(g,{id:_.id,path:z,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&t.jsx(h,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${A}px,${W}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:o("bg"),border:`0.5px solid ${o("widget-border")}`,...L,...T},children:_.label})})]})}}),[g,h,b]),v=f.useMemo(()=>({version:_=>{const w=_.data,z=w.kind==="hypothetical",B=w.status==="lost",E=w.isSelected,C=w.bridge,A=w.borderColor??o("muted"),W=C||z?"dashed":"solid",T=C?.5:B?.6:1;return t.jsxs("div",{style:{background:o(C?"bg-subtle":"bg"),border:`2px ${W} ${E?o("primary"):A}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:T,boxShadow:E?o("shadow-node-selected"):z||C?"none":o("shadow-node")},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:x.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!w.renderLink?w.label:w.renderLink(w.bookId,w.label)}),w.description&&t.jsx("div",{style:{fontSize:10,color:o("muted"),lineHeight:1.25,marginTop:1},children:w.description}),w.yearText&&t.jsx("div",{style:{fontSize:10,color:o("muted"),lineHeight:1.2},children:Ms(w.yearText,void 0,w.uncertain)}),B&&t.jsx("div",{style:{fontSize:9,color:o("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[u,x]),{convert:y}=V(),{rfNodes:j,rfEdges:$}=f.useMemo(()=>ku(e,k,n,l,y),[e,k,n,l,y]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:t.jsxs(d,{nodes:j,edges:$,nodeTypes:v,edgeTypes:m,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(a,{showInteractive:!1})]})})};function ku(e,n,i,r,s=l=>l??""){const d=e.layout==="LR"||!e.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:d?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const a=new Map(e.groups.map(v=>[v.id,v.color??o("muted")]));for(const v of e.nodes)c.setNode(v.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const v of e.edges)v.kind==="derive"&&(u.has(v.relation)||c.setEdge(v.source,v.target));n.layout(c);const x=e.nodes.map(v=>{const y=c.node(v.id),j=r&&v.id===r,$={kind:v.kind,label:s(v.label),bookId:v.kind==="book"?v.id:void 0,yearText:s(v.year_text??wu(v)),uncertain:v.year_uncertain,category:v.category,status:v.status,borderColor:v.group?a.get(v.group):void 0,renderLink:i,isSelected:j,description:s(v.description),bridge:v.bridge};return{id:v.id,type:"version",position:{x:y.x-160/2,y:y.y-90/2},data:$,draggable:!1,selected:j}}),g=.78,h=.06,b=new Map;for(const v of e.edges)v.kind==="derive"&&(b.has(v.source)||b.set(v.source,[]),b.get(v.source).push(v));const k=new Map;for(const[v,y]of b){if(y.length<=1)continue;const j=[...y].sort((S,_)=>{var B,E;const w=((B=c.node(S.target))==null?void 0:B.y)??0,z=((E=c.node(_.target))==null?void 0:E.y)??0;return w-z}),$=j.length;j.forEach((S,_)=>{const w=(_-($-1)/2)*h;k.set(S.id,g+w)})}const m=e.edges.map(v=>Su(v,k.get(v.id),s));return{rfNodes:x,rfEdges:m}}function Su(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=_u(e.confidence),p={type:"arrowclosed",color:l,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:i(e.relation),data:{labelStyle:{color:o("fg")},isSibling:s,stepPosition:n},style:{stroke:l,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:p,markerStart:s?p:void 0,zIndex:1e3}}function wu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function _u(e){switch(e){case"certain":return o("confidence-certain");case"consensus":return o("lineage-edge-consensus");case"probable":return o("confidence-probable");case"disputed":return o("confidence-disputed");default:return o("muted")}}const Vo={padding:"40px 20px",textAlign:"center",color:o("muted"),fontSize:"13px",border:`1px dashed ${o("widget-border")}`,borderRadius:8,background:o("bg")},Os=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:p,onCollectionChange:d,collectionsAvailable:c,collectionCounts:a,className:u,style:x})=>{var y;const[g,h]=f.useState(n),b=j=>{h(j),l==null||l(j)},k=(()=>{if(!c)return[];const j=Object.entries(c);return j.length===0||c.all?j:[...j,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),m=!!(d&&k.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:o("muted"),textAlign:"center"},children:"暂无版本传承数据"});const v=p?(y=c==null?void 0:c[p])==null?void 0:y.description:void 0;return t.jsxs("div",{className:u,style:x,children:[t.jsxs("div",{style:$u,children:[t.jsx("button",{onClick:()=>b("list"),style:jn(g==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:jn(g==="graph"),children:"关系图"}),m&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:o("muted"),marginRight:4},children:"集合:"}),k.map(([j,$])=>{const S=a==null?void 0:a[j];return t.jsxs("button",{onClick:()=>d==null?void 0:d(j),style:jn(p===j),title:$.description,children:[$.label,S!=null?` ${S}`:""]},j)})]})]}),m&&v&&t.jsx("div",{style:{fontSize:12,color:o("muted"),marginBottom:8,padding:"4px 8px",background:o("bg-subtle"),borderRadius:4},children:v}),g==="list"?t.jsx(Fs,{graph:e,renderLink:i}):t.jsx(Ps,{graph:e,renderLink:i,height:r,selectedNodeId:s})]})},$u={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},jn=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${o("widget-border")}`,borderRadius:4,background:e?o("primary"):"transparent",color:o(e?"primary-fg":"fg"),cursor:"pointer"}),Fn=({style:e})=>{const n=f.useContext(mt);if(!n)return null;const{locale:i,setLocale:r}=n,s=i==="zh-Hant",l=()=>r(s?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:`1px solid ${o("border")}`,borderRadius:"4px",background:o("bg"),color:o("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:s?o("primary"):void 0,fontWeight:s?700:400},children:"繁"}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:s?void 0:o("primary"),fontWeight:s?400:700},children:"简"})]})},Pn=({href:e,label:n="在 GitHub 查看本条目源文件",size:i=16,className:r,style:s})=>t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:o("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:l=>{l.currentTarget.style.color=o("fg")},onMouseLeave:l=>{l.currentTarget.style.color=o("desc-fg")},children:t.jsx("svg",{width:i,height:i,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:t.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})});function vn(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function zu(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const Cu=({id:e,transport:n,initialDetail:i,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:p,onJuanChange:d,lineageMode:c="list",onLineageModeChange:a,lineageCollection:u,onLineageCollectionChange:x,initialPage:g=1,selectedLineageNodeId:h,onNavigate:b,onBack:k,backLabel:m,renderLink:v,enrichDetail:y,getSourceLink:j,readLink:$,railTop:S,extraTabs:_=[],showFeedbackTab:w=!0,feedbackApiUrl:z,height:B,footerExtra:E,className:C,style:A})=>{var Ti;const W=ie(),{convert:T}=V(),[L]=f.useState(()=>{if(!zu(e,i))return null;const H={...i},de=r??vn(e,H);return y&&y(de,H),{id:e,entry:de,detail:H}}),[M,P]=f.useState((L==null?void 0:L.entry)??null),[R,ne]=f.useState((L==null?void 0:L.detail)??null),[I,F]=f.useState(!L),[K,G]=f.useState(!1),[U,te]=f.useState([]),[O,Y]=f.useState(!1),[Z,X]=f.useState(null),[se,ge]=f.useState(!1),[he,D]=f.useState(null),[le,oe]=f.useState(!1),[ce,ue]=f.useState([]),[me,Q]=f.useState(!1),[q,N]=f.useState(null),[ee,re]=f.useState(null),[be,ae]=f.useState(!1),ke=f.useRef(null),[Ne,Se]=f.useState(null),De=p!==void 0?p:Ne,ot=f.useCallback(H=>{d?d(H):Se(H)},[d]),ki=f.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){te([]);return}Y(!0);try{if(n.getCollectionCatalogs)te(await n.getCollectionCatalogs(H)||[]);else if(n.getCollectionCatalog){const de=await n.getCollectionCatalog(H);te(de?[{resource_id:"",data:de}]:[])}}catch{te([])}finally{Y(!1)}},[n]),Si=f.useCallback(async H=>{if(!n.getCollatedEditionIndex){X(null);return}ge(!0);try{X(await n.getCollatedEditionIndex(H))}catch{X(null)}finally{ge(!1)}},[n]),wi=f.useCallback(async H=>{if(!n.getBookFullTextIndex){D(null);return}oe(!0);try{D(await n.getBookFullTextIndex(H))}catch{D(null)}finally{oe(!1)}},[n]),_i=f.useCallback(async H=>{var de;if(!n.getWorkFullTextList){ue([]);return}Q(!0);try{const xe=(await n.getWorkFullTextList(H)??[]).filter(ye=>ye.owner_type!=="Book");ue(xe),N(((de=xe.find(ye=>ye.primary)??xe[0])==null?void 0:de.key)??null)}catch{ue([])}finally{Q(!1)}},[n]),$i=f.useCallback(async(H,de)=>{ae(!0);try{if(n.getLineageGraph){const _e=await n.getLineageGraph(H);_e&&re(_e)}const xe=de.version_graph;if(!xe||!xe.enabled){ee||re(null),ke.current=null;return}const ye=de.books??[],Be=[];for(const _e of ye)try{const We=await n.getItem(_e);We&&Be.push(We)}catch{}ke.current={work:de,books:Be};const J=u??xe.default_collection??(xe.core_books&&xe.core_books.length>0?"core":"all"),fe=J==="core"&&Array.isArray(xe.core_books)&&xe.core_books.length>0?"core":J??"all";re(Kt(de,Be,fe))}catch{re(null),ke.current=null}finally{ae(!1)}},[n]),zi=f.useRef({initialDetail:i,initialEntry:r});zi.current={initialDetail:i,initialEntry:r},f.useEffect(()=>{let H=!1;const de=J=>{J.type==="collection"?ki(e):J.type==="work"?((J.has_collated||n.getCollatedEditionIndex)&&Si(e),(J.version_graph||n.getLineageGraph)&&$i(e,J),n.getWorkFullTextList&&_i(e)):J.type==="book"&&J.has_full_text&&n.getBookFullTextIndex&&wi(e)},xe=zi.current;let ye=null;if(L&&L.id===e)ye=L;else if(xe.initialDetail&&xe.initialDetail.id===e){const J={...xe.initialDetail},fe=xe.initialEntry??vn(e,J);y&&y(fe,J),ye={entry:fe,detail:J}}return ye?(G(!1),te(J=>J.length?[]:J),X(null),D(null),ue(J=>J.length?[]:J),N(null),re(null),ke.current=null,P(ye.entry),ne(ye.detail),F(!1),de(ye.detail),()=>{H=!0}):((async()=>{F(!0),G(!1),P(null),ne(null),te([]),X(null),D(null),ue([]),N(null),re(null),ke.current=null;try{const J=await n.getItem(e);if(H)return;if(!J){G(!0);return}const fe=J;let _e=null;if(n.getEntry&&(_e=await n.getEntry(e),H))return;_e||(_e=vn(e,fe)),y&&y(_e,fe),P(_e),ne(fe),de(fe)}catch{H||G(!0)}finally{H||F(!1)}})(),()=>{H=!0})},[e,n,L,y,ki,Si,$i,wi,_i]),f.useEffect(()=>{const H=ke.current;!H||!u||re(Kt(H.work,H.books,u))},[u]);const we=[];if(R){if(we.push({key:"basic",label:W.detailTab.basicInfo}),R.type==="collection"){O&&U.length===0&&we.push({key:"catalog:loading",label:`${W.detailTab.catalog}…`});for(const H of U)we.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${T(H.short_name)}${W.detailTab.catalogSuffix}`:W.detailTab.collectionCatalog})}R.type==="work"&&(Z||se)&&s==="collated"&&we.push({key:"collated",label:se?`${W.detailTab.collatedEdition}…`:W.detailTab.collatedEdition}),R.type==="book"&&(he||le)&&s==="fulltext"&&we.push({key:"fulltext",label:le?`${W.detailTab.fullText}…`:W.detailTab.fullText}),R.type==="work"&&(ce.length>0||me)&&s==="fulltext"&&we.push({key:"fulltext",label:me?`${W.detailTab.fullText}…`:W.detailTab.fullText}),R.type==="work"&&(ee||be)&&we.push({key:"lineage",label:be?`${W.detailTab.lineage}…`:W.detailTab.lineage});for(const H of _)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(R)&&we.push({key:H.key,label:H.label});w&&s==="feedback"&&we.push({key:"feedback",label:W.detailTab.feedback});for(const H of _)H.position==="after-feedback"&&H.shouldShow(R)&&we.push({key:H.key,label:H.label})}f.useEffect(()=>{if(s!=="emendated"||!R)return;l("basic");const H=setTimeout(()=>{var de;(de=document.getElementById("studies"))==null||de.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[s,R,l]);const rt=M&&R&&j?j({activeTab:s,activeJuan:De,entry:M,detail:R}):null,an=f.useMemo(()=>{var Be;if(!R)return null;const de=(R.authors??[]).map(J=>{const fe=Zn(J.role);return`${J.dynasty?`〔${T(J.dynasty)}〕`:""}${T(J.name)}${fe?` ${T(fe)}`:""}`}).join(" · ");let xe=!1;try{xe=pe.extractStatus(R.id)==="draft"}catch{}if(R.type==="book"){const J=R;return{title:T(J.title),subtitle:J.edition?T(J.edition):de||void 0,aside:[xe?W.status.draft:"",de&&J.edition?de:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(R.type==="collection"){const J=R;return{title:T(J.title),subtitle:T(et(J,W.unit.juan))||void 0,aside:[(Be=J.publication_info)==null?void 0:Be.year,xe?W.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:de||void 0}}if(R.type==="entity"){const J=R,fe=We=>We==null?"":We<0?`前${-We}`:String(We),_e=J.birth_year!=null||J.death_year!=null?`${fe(J.birth_year)||"?"}—${fe(J.death_year)||"?"}`:"";return{title:T(J.primary_name||J.title),subtitle:[J.dynasty?`〔${T(J.dynasty)}〕`:"",_e].filter(Boolean).join(" ")||void 0,aside:xe?W.status.draft:void 0,secondLine:void 0}}const ye=T(et(R,W.unit.juan));return{title:T(R.title),subtitle:[ye,de].filter(Boolean).join(" · ")||void 0,aside:[Tu(W,R.subtype),xe?W.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[R,T,W]),Ot=R?R.type==="work"?(((Ti=Z==null?void 0:Z.juan_files)==null?void 0:Ti.length)??0)>0?"collated":ce.length>0?"fulltext":null:R.type==="book"&&((he==null?void 0:he.chapters.length)??0)>0?"fulltext":null:null,jt=ce.find(H=>H.primary)??ce[0],Ds=()=>{var H;Ot==="collated"&&((H=Z==null?void 0:Z.juan_files)!=null&&H.length)?(ot(Z.juan_files[0]),l("collated")):Ot==="fulltext"&&((R==null?void 0:R.type)==="work"&&jt&&N(jt.key),ot(null),l("fulltext"))};let vt=null;if(R&&$){const H=$({detail:R,kind:Ot,fullTextKey:R.type==="work"?jt==null?void 0:jt.key:void 0});H&&(vt=t.jsx(Cn,{href:H}))}else Ot&&(vt=t.jsx(Cn,{onClick:Ds}));const Hs=new Set(_.map(H=>H.key)),Dt=we.filter(H=>H.key.startsWith("catalog:")&&H.key!=="catalog:loading"||Hs.has(H.key)).map(H=>({key:H.key,label:H.label,onClick:()=>l(H.key)})),Ci=()=>{var H;return R?R.type==="work"?t.jsx(zs,{data:R,transport:n,onNavigate:b,renderLink:v,readAction:vt,railTop:S,railLinks:Dt}):R.type==="book"?t.jsx(Cs,{data:R,transport:n,onNavigate:b,renderLink:v,readAction:vt,railTop:S,railLinks:Dt}):R.type==="collection"?t.jsx(Is,{data:R,catalog:(H=U[0])==null?void 0:H.data,transport:n,onNavigate:b,renderLink:v,readAction:vt,railTop:S,railLinks:Dt,catalogAction:U.length>0?t.jsxs("a",{href:"#catalog",onClick:de=>{de.preventDefault(),l(`catalog:${U[0].resource_id}`)},children:[T(W.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Ts,{data:R,transport:n,onNavigate:b,renderLink:v,railTop:S,railLinks:Dt}):null},Gs=()=>{var de,xe,ye,Be;if(!M||!R)return null;if(s==="basic"||s==="emendated")return Ci();if(typeof s=="string"&&s.startsWith("catalog:")){const J=(de=U.find(fe=>`catalog:${fe.resource_id}`===s))==null?void 0:de.data;return t.jsx(Yn,{data:J,onNavigate:b,renderLink:v})}if(s==="collated")return t.jsx(gi,{index:Z||void 0,workId:e,transport:n,onNavigate:b,activeJuan:De,onJuanChange:ot});if(s==="fulltext"&&R.type==="work"){const J=q??((xe=ce[0])==null?void 0:xe.key);return J?t.jsx(Bn,{bookId:e,workKey:J,versions:ce,onVersionChange:fe=>{N(fe),ot(null)},transport:n,activeChapter:De,onChapterChange:ot},J):t.jsx("div",{style:{padding:24,color:o("desc-fg")},children:me?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(Bn,{index:he||void 0,bookId:e,transport:n,activeChapter:De,onChapterChange:ot});if(s==="lineage"){if(!ee)return t.jsx("div",{style:{color:o("label-fg"),padding:"24px 0"},children:be?"加載中…":"暫無版本圖數據"});const J=R.type==="work"?R:null;return t.jsx(Os,{graph:ee,renderLink:v,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:a,selectedNodeId:h,collection:u??((ye=J==null?void 0:J.version_graph)==null?void 0:ye.default_collection),onCollectionChange:x,collectionsAvailable:(Be=J==null?void 0:J.version_graph)==null?void 0:Be.collections,collectionCounts:(()=>{var Ri,Ei,Li,Ni,Bi,Wi,Ai;if(!J)return;const fe={},_e=((Ri=ke.current)==null?void 0:Ri.books)??[];fe.all=(((Ei=J.books)==null?void 0:Ei.length)??0)-(((Ni=(Li=J.version_graph)==null?void 0:Li.excluded_books)==null?void 0:Ni.length)??0);const We=(Bi=J.version_graph)==null?void 0:Bi.collections;if(We)for(const Mi of Object.keys(We))fe[Mi]=Kt(J,_e,Mi).nodes.filter(Fi=>Fi.kind==="book"&&!Fi.bridge).length;return fe.core==null&&((Ai=(Wi=J.version_graph)==null?void 0:Wi.core_books)!=null&&Ai.length)&&(fe.core=J.version_graph.core_books.length),fe})()})}if(s==="feedback"&&w)return t.jsx($s,{resourceId:e,apiUrl:z});const H=_.find(J=>J.key===s);return H?H.render({detail:R,entry:M,transport:n,onNavigate:b}):null};if(I)return t.jsx(It,{style:{minHeight:B,...A},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((H,de)=>t.jsx("div",{style:{height:de===1?40:16,width:H,opacity:.35,background:o("rule")}},de))})});if(K||!R||!M||!an)return t.jsx(It,{style:{minHeight:B,...A},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:o("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const cn=s==="basic"||s==="emendated",Ht=[{label:m??W.detailTab.backToIndex,onClick:k}];if(R.type==="book"&&R.work_id){const H=R.work_id;Ht.push({label:W.indexType.work,id:H,onClick:()=>b==null?void 0:b(H)})}Ht.push({label:W.indexType[R.type]});const Gt=s==="collated"||s==="fulltext",Ii=t.jsx(Pr,{left:t.jsxs(t.Fragment,{children:[E,E?" · ":"",t.jsx(Iu,{id:R.id,label:W.label.id,copied:W.action.copied,copyLabel:W.action.copy})]}),right:t.jsxs(t.Fragment,{children:[w&&!cn&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:W.detailTab.submitVersion}),rt&&t.jsx("a",{href:rt.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:o("meta-fg")},children:W.detailTab.dataLicense})]})});return cn?t.jsx("div",{className:C,children:t.jsxs(It,{grid:!0,style:{minHeight:B,...A},children:[t.jsx(In,{breadcrumb:t.jsx(Tn,{items:Ht}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Fn,{style:{border:"none",background:"transparent"}}),rt&&t.jsx(Pn,{...rt})]})}),Ci(),Ii]})}):t.jsx("div",{className:C,children:t.jsxs(It,{wide:Gt,style:{minHeight:B,...A},children:[t.jsx(In,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Xn,{char:"籍"}),t.jsx(Tn,{items:Ht})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Fn,{}),w&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:W.detailTab.feedback}),rt&&t.jsx(Pn,{...rt})]})}),t.jsx(Rr,{...an,aside:Gt?t.jsxs("button",{type:"button",onClick:()=>l("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("accent"),borderBottom:`1px solid ${o("rule")}`},children:[T("作品信息")," →"]}):an.aside}),!Gt&&we.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:we.map(H=>t.jsx(Er,{label:H.label,active:H.key===s||cn&&H.key==="basic",onClick:()=>l(H.key)},H.key))}),t.jsx("div",{style:{marginTop:!Gt&&we.length>1?8:0},children:Gs()}),Ii]})})};function Iu({id:e,label:n,copied:i,copyLabel:r}){const[s,l]=f.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var p;(p=navigator.clipboard)==null||p.writeText(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?i:r,"aria-label":s?i:r,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:o("aux-fg")},children:s?"✓":"⧉"})]})}function Tu(e,n){return n?e.workSubtype[n]??n:""}exports.BidLink=pe.BidLink;exports.BookIndexError=pe.BookIndexError;exports.BookIndexManager=pe.BookIndexManager;exports.BookIndexStorage=pe.BookIndexStorage;exports.BundleStorage=pe.BundleStorage;exports.ConfigError=pe.ConfigError;exports.GithubStorage=pe.GithubStorage;exports.IdGenerationError=pe.IdGenerationError;exports.IdGenerator=pe.IdGenerator;exports.LocalStorage=pe.LocalStorage;exports.MigrationError=pe.MigrationError;exports.StorageError=pe.StorageError;exports.base36Decode=pe.base36Decode;exports.base36Encode=pe.base36Encode;exports.base58Decode=pe.base58Decode;exports.buildId=pe.buildId;exports.buildPromotionMap=pe.buildPromotionMap;exports.cleanName=pe.cleanName;exports.decodeId=pe.decodeId;exports.decodeIdString=pe.decodeIdString;exports.encodeId=pe.encodeId;exports.extractIdFromUrl=pe.extractIdFromUrl;exports.extractStatus=pe.extractStatus;exports.extractType=pe.extractType;exports.normalizeCatalog=pe.normalizeCatalog;exports.parseId=pe.parseId;exports.shardOf=pe.shardOf;exports.smartDecode=pe.smartDecode;exports.validateResource=pe.validateResource;exports.Badge=Zt;exports.BidUrlProvider=el;exports.BookDetailLayout=Cu;exports.BookFullText=Bn;exports.BookPage=Cs;exports.Breadcrumb=Tn;exports.CATALOG_ALL_ID=Ge;exports.CATALOG_CSS=Rs;exports.CATALOG_NARROW_QUERY=yi;exports.CATALOG_PAGE_SIZE=ji;exports.CATALOG_UNCLASSIFIED_ID=ht;exports.CardFoot=Mt;exports.CatalogPage=eu;exports.CatalogPager=Ws;exports.CatalogTree=Ls;exports.CheckFilter=Ir;exports.Chip=Lr;exports.ChipWall=Wa;exports.CollatedEdition=gi;exports.CollectionCatalog=Yn;exports.CollectionPage=Is;exports.CreateEntityDialog=bs;exports.DEFAULT_READER_PREFS=ti;exports.DETAIL_CSS=Tr;exports.Dash=Da;exports.DataTable=Ma;exports.DetailFooter=Pr;exports.DetailGrid=Wt;exports.DetailHeader=Rr;exports.EmendatedBySection=pr;exports.EmptyNote=qa;exports.EntityDetail=rr;exports.EntityPage=Ts;exports.EntityPickerDialog=js;exports.EntitySelector=ms;exports.ExpandRow=Ha;exports.ExtLink=Ja;exports.FEEDBACK_FAB_OFFSET_VAR=An;exports.FONT_SIZE_STEPS=dt;exports.FactList=Ea;exports.FeedbackButton=yp;exports.FeedbackDialog=ws;exports.FeedbackForm=_s;exports.FeedbackList=hi;exports.FeedbackTab=$s;exports.FilterChip=Er;exports.FormInput=ze;exports.FormTextArea=Xe;exports.GUJI_MARKDOWN_FIELD=ya;exports.GUJI_TABLE_NOTATION=Jr;exports.GlyphBadge=Xn;exports.GujiTable=ri;exports.HomePage=Nn;exports.ImagePanel=Vr;exports.IndexApp=Sd;exports.IndexBrowser=wn;exports.IndexDetail=Vn;exports.IndexEditor=vs;exports.IndexView=sp;exports.IntroGrid=Ra;exports.LocaleContext=mt;exports.LocaleProvider=dl;exports.LocaleToggle=Fn;exports.MetaLine=Re;exports.ModeIndicator=nr;exports.MoreButton=Ba;exports.MoreLink=yt;exports.PAGE_MAX_WIDTH=Ct;exports.PageFrame=It;exports.Quote=Ua;exports.READER_CSS=Hr;exports.RECENT_IDS_STORAGE_KEY=ut;exports.ROLE_CLASS_ORDER=yr;exports.ReadButton=Cn;exports.ReaderMdText=ci;exports.ReaderShell=ii;exports.ReaderToc=Ur;exports.RelationPanel=gs;exports.RepoSourceLink=Pn;exports.ResourceEditor=Sn;exports.ResourceGroup=Va;exports.ResourceLine=Ya;exports.ResourceList=Un;exports.ResourceRow=Mr;exports.SNIPPET_MARK_END=qo;exports.SNIPPET_MARK_START=Ko;exports.SearchInput=ir;exports.Sec=Ce;exports.Section=Ee;exports.SectionHead=La;exports.SideList=ct;exports.SmartBidInput=Yt;exports.SourceEditor=us;exports.SummaryCard=At;exports.TabFilter=rn;exports.TableHead=Fa;exports.TableRow=Pa;exports.TagRow=Fr;exports.TagRows=Ka;exports.TextButton=Na;exports.TopStrip=In;exports.VersionLineageGraph=Ps;exports.VersionLineageList=Fs;exports.VersionLineageView=Os;exports.VolumeChips=Aa;exports.VolumeLinks=Qn;exports.WorkCard=Bs;exports.WorkCardGrid=As;exports.WorkCatalog=_d;exports.WorkPage=zs;exports.bucketResources=nn;exports.buildCatalogTree=Gp;exports.buildCollectionTable=vr;exports.buildLineageGraph=Kt;exports.buildPageUrl=Gn;exports.buildParagraphBlocks=os;exports.buildVersionRow=mr;exports.buildVersionTable=br;exports.canParagraphize=ln;exports.catalogNodeIdOf=Dp;exports.catalogNodeIdsOf=Hp;exports.catalogPageCount=Kp;exports.catalogTotal=vi;exports.classificationPath=Pt;exports.compareCatalogCards=Yp;exports.computeVersionPartition=ga;exports.defaultWorkLink=Ns;exports.deriveDating=ua;exports.deriveEditionType=Sr;exports.deriveEra=Nt;exports.deriveYear=tn;exports.deriveYearRange=qn;exports.detailToEditor=Ss;exports.detectGenre=sn;exports.displayAuthorRole=Zn;exports.editorToDetail=rp;exports.eraRank=$n;exports.findCatalogPath=pt;exports.flattenTitles=Rn;exports.flattenToc=qr;exports.formatTemplate=Lt;exports.formatVolumeRange=on;exports.getDisplayNameFromUrl=tt;exports.getStartPage=Hn;exports.getTypeGroupKey=On;exports.groupRelatedWorks=xa;exports.gujiInlineToPlain=zr;exports.hasGujiMarkdownV02=zn;exports.hasGujiTableNotation=Zr;exports.measureText=et;exports.mergeVolumeResources=Dn;exports.normalizeEra=je;exports.normalizeRole=Jn;exports.normalizeVolumeIndex=Rt;exports.normalizeVolumes=tr;exports.numberToChinese=kr;exports.paginationItems=Es;exports.parseChineseNumber=qt;exports.parseGujiInline=$r;exports.parseGujiTable=Qr;exports.parseSourceString=xs;exports.pickReaderVersion=Kr;exports.readerVersionOptionLabel=Ln;exports.readerVersionsFromFullText=rc;exports.renderFullTextBody=jc;exports.renderProperNames=ss;exports.renderReaderInline=ai;exports.resourceHref=bt;exports.resourceNote=Bt;exports.roleFacets=jr;exports.rowNo=Oa;exports.sortYear=gr;exports.splitFullTextTables=oi;exports.splitHighlightSnippet=Jo;exports.splitTableRow=Xr;exports.stringifySources=fs;exports.toCatalogWorkCard=Vp;exports.useBidUrl=ve;exports.useConvert=V;exports.useReaderPrefs=ni;exports.useT=ie;exports.validateLineageGraph=ru;exports.volumeStats=Xt;
|