book-index-ui 0.11.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +36 -36
- package/dist/index.d.ts +65 -0
- package/dist/index.js +2198 -2148
- package/dist/storage.d.ts +63 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ll=Object.create;var Yi=Object.defineProperty;var al=Object.getOwnPropertyDescriptor;var cl=Object.getOwnPropertyNames;var dl=Object.getPrototypeOf,pl=Object.prototype.hasOwnProperty;var ul=(e,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of cl(n))!pl.call(e,s)&&s!==i&&Yi(e,s,{get:()=>n[s],enumerable:!(r=al(n,s))||r.enumerable});return e};var Qt=(e,n,i)=>(i=e!=null?ll(dl(e)):{},ul(n||!e||!e.__esModule?Yi(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const he=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),g=require("react"),xl=require("opencc-js/t2cn"),fl=require("react-markdown"),gl=require("remark-gfm"),ml=e=>`/book-index?id=${e}`,rr=g.createContext(ml);function hl({buildUrl:e,children:n}){const i=g.useMemo(()=>e,[e]);return t.jsx(rr.Provider,{value:i,children:n})}function Ne(){return g.useContext(rr)}const sr="",lr="";function ar(e){const n=[];let i=!1,r=e;for(;r.length;){const s=i?lr:sr,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 Fe(e,n){return{title:e,tokens:n}}const Ki='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',bl=[Fe("基础(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"}}),Fe("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),Fe("提示与警告",{"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)"}}),Fe("遮罩与阴影",{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)"}}),Fe("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),Fe("资源",{"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"}}),Fe("整理本(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"}}),Fe("版本传承(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"}}),Fe("编辑器视图(主要在 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")'}}),Fe("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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}}),Fe("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),Fe("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),Fe("字体(全站无衬线,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:Ki,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:Ki,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],yl=Object.assign({},...bl.map(e=>e.tokens)),cr={};for(const[e,n]of Object.entries(yl))cr[e]=`var(--bim-${e}, ${n.value})`;function o(e){const n=cr[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function ft(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function jl(e,n){return ft(e).includes(n)}const Rn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},vl={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};o("quality-published"),o("quality-fine"),o("quality-rough"),o("quality-ocr");const $t=g.createContext(null),dr={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:"圖片資源"}},kl={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=["曹霑"];function wl(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function _l(e,n=Sl){const i=[...new Set(n.filter(Boolean))].sort((l,c)=>c.length-l.length);if(!i.length)return e;const r=new RegExp(`(${i.map(wl).join("|")})`,"g"),s=new Set(i);return l=>{if(!l)return e(l);const c=l.split(r);return c.length===1?e(l):c.map((p,a)=>a%2===1&&s.has(p)?p:p&&e(p)).join("")}}let Et=null;function $l(){if(Et)return Et;try{Et=_l(xl.Converter({from:"tw",to:"cn"}))}catch{Et=e=>e}return Et}const zl={"zh-Hant":dr,"zh-Hans":kl},pr="bim-locale";function Cl(){try{const e=localStorage.getItem(pr);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Il(e){try{localStorage.setItem(pr,e)}catch{}}const Tl="zh-Hans",Rl=({locale:e,onLocaleChange:n,converter:i,children:r})=>{const[s,l]=g.useState(e??Tl),c=e??s;g.useEffect(()=>{if(e)return;const u=Cl();u&&u!==s&&l(u)},[]);const p=g.useMemo(()=>c==="zh-Hans"?i??$l():null,[c,i]),a=g.useCallback(u=>{l(u),Il(u),n==null||n(u)},[n]),d=g.useMemo(()=>({locale:c,setLocale:a,messages:zl[c],converter:p}),[c,a,p]);return t.jsx($t.Provider,{value:d,children:r})};function ae(){const e=g.useContext($t);return(e==null?void 0:e.messages)??dr}const El=2e3;function V(){const e=g.useContext($t),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,r=g.useRef(new Map),s=g.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const l=g.useCallback(c=>{if(!c)return"";if(!i)return c;const p=r.current.get(c);if(p!==void 0)return p;const a=i(c);if(r.current.size>=El){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(c,a),a},[i]);return g.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Ht(e,n){return e.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function Nl(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 Ll(){return{id:"",name:"",url:"",type:"text",details:""}}const En=({items:e,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const l=ae(),[c,p]=g.useState(null),a=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],d=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=y=>{if(!s)return!0;const k=ft(y);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},f=e.map((y,k)=>({item:y,originalIndex:k})).filter(({item:y})=>u(y)),x=()=>{const y=Ll();s&&(y.type=s),n([...e,y]),p(e.length)},m=y=>{n(e.filter((k,_)=>_!==y)),p(null)},b=(y,k,_)=>{const v=[...e];if(v[y]={...v[y],[k]:_},k==="url"&&!v[y].id){const $=Nl(_);$&&(v[y].id=$)}n(v)},w=(y,k,_)=>{const $={...e[y].metadata||{}};_?$[k]=_:delete $[k],b(y,"metadata",Object.keys($).length>0?$:void 0)},h=(y,k)=>{const _=k.trim()?k.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;b(y,"structure",_)},j=(y,k,_)=>{const $=e[y].coverage||{level:1,ranges:""};k==="level"?$.level=parseInt(_)||1:$.ranges=_,b(y,"coverage",$.ranges?$:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[f.map(({item:y,originalIndex:k})=>{var _,v,$;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(c===k?null:k),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:c===k?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Bl(y.type??"text"),color:o("on-color-fg")},children:(()=>{var z,T;const S=ft(y);return S.length===0?y.type??"text":S.length===1?((z=a.find(R=>R.value===S[0]))==null?void 0:z.label)??S[0]:S.includes("text")&&S.includes("image")?((T=a.find(R=>R.value==="text+image"))==null?void 0:T.label)??"text+image":S.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${l.editor.resourcePlaceholder} ${k+1}`}),y.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:y.id}),y.url&&t.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&y.url&&Al(k,r==null?void 0:r[k],i,l),t.jsx("button",{onClick:S=>{S.stopPropagation(),m(k)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),c===k&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:[jl(y,"image")&&y.url&&Wl(y,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Nt,children:[t.jsx("span",{style:Lt,children:l.label.type}),t.jsx("select",{value:y.type,onChange:S=>b(k,"type",S.target.value),style:{...qe,flex:1},children:a.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]}),t.jsxs("label",{style:Nt,children:[t.jsx("span",{style:Lt,children:l.label.rootType}),t.jsx("select",{value:y.root_type||"catalog",onChange:S=>b(k,"root_type",S.target.value),style:{...qe,flex:1},children:d.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:y.id,onChange:S=>b(k,"id",S.target.value),placeholder:l.editor.idAutoExtract,style:{...qe,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:y.name,onChange:S=>b(k,"name",S.target.value),placeholder:l.editor.resourceName,style:{...qe,flex:1}})]}),t.jsx("input",{type:"text",value:y.url,onChange:S=>b(k,"url",S.target.value),placeholder:l.editor.resourceUrl,style:qe}),t.jsx("input",{type:"text",value:((_=y.structure)==null?void 0:_.join("、"))||"",onChange:S=>h(k,S.target.value),placeholder:l.editor.structurePlaceholder,style:qe}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Nt,children:[t.jsx("span",{style:Lt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((v=y.coverage)==null?void 0:v.level)??"",onChange:S=>j(k,"level",S.target.value),placeholder:"1",style:{...qe,width:"60px"}})]}),t.jsxs("label",{style:{...Nt,flex:1},children:[t.jsx("span",{style:Lt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:(($=y.coverage)==null?void 0:$.ranges)||"",onChange:S=>j(k,"ranges",S.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...qe,flex:1}})]})]}),t.jsx("textarea",{value:y.details||"",onChange:S=>b(k,"details",S.target.value),placeholder:l.editor.detailsPlaceholder,style:{...qe,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(([S,z])=>{var T;return t.jsxs("label",{style:{...Nt,gap:"4px"},children:[t.jsx("span",{style:{...Lt,minWidth:"56px"},children:z}),t.jsx("input",{type:"text",value:((T=y.metadata)==null?void 0:T[S])||"",onChange:R=>w(k,S,R.target.value),placeholder:z,style:{...qe,flex:1}})]},S)})})]})]})]})]},k)}),t.jsxs("button",{onClick:x,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:l.action.addResource})]})]})};function Bl(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 Al(e,n,i,r){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:c=>{c.stopPropagation(),s||i(e,"")},disabled:s,style:{background:"transparent",border:"none",color:o(l?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:l?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":s?"⏳":"⬇"})}function Wl(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 qe={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Nt={display:"flex",alignItems:"center",gap:"6px"},Lt={fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap"},Ml={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive","www.shuge.org":"書格","shuge.org":"書格","pan.baidu.com":"百度網盤"};function zt(e){try{return Ml[new URL(e).hostname]}catch{return}}const qi={text:0,image:1,physical:2};function Jn(e){return e.length===0?"physical":[...e].sort((n,i)=>(qi[n]??99)-(qi[i]??99)).join("+")}function Zn(e){var c;const n=p=>{const a=p.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const d=p.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},i=new Map;for(let p=0;p<e.length;p++){const a=e[p];if(a.volumes&&a.volumes.length>0)continue;const d=n(a.name);if(!d)continue;const[u,f]=d,x=`${u}|${Jn(ft(a))}`;i.has(x)||i.set(x,{base:{...a,name:u,url:"",volumes:[]},volumes:[],indices:[]});const m=i.get(x);m.volumes.push({volume:f,url:a.url||void 0,status:"found"}),m.indices.push(p)}const r=[],s=new Set;for(const p of i.values())if(!(p.volumes.length<2)){p.volumes.sort((a,d)=>a.volume-d.volume),p.base.volumes=p.volumes,p.base.expected_volumes=p.volumes.length,p.base.url||(p.base.url=((c=p.volumes.find(a=>a.url))==null?void 0:c.url)??""),r.push(p.base);for(const a of p.indices)s.add(a)}const l=[...r];for(let p=0;p<e.length;p++)s.has(p)||l.push(e[p]);return l}function ur(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 xr(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||ur(n)}))}function dn(e){const n=xr(e);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,r=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:r,expected:e.expected_volumes??i+r}}function Xn(e){if(!e)return;const n=e.file_page_range||e.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function Qn(e,n){try{if(new URL(e).hostname.includes("wikimedia.org")){const r=e.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const s=new URL(e);return s.searchParams.set("page",String(n)),s.toString()}return e}catch{return e}}function Ct(e){if(!e.url)return;const n=Xn(e.metadata);return n?Qn(e.url,n):e.url}const Ji={text:o("restype-text"),image:o("restype-image"),"text+image":o("restype-text-image"),physical:o("restype-physical")};function Fl(e){return e.includes("text")&&e.includes("image")?Ji["text+image"]:Ji[e[0]||"physical"]}const ei=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const l=ae(),{convert:c}=V(),p=g.useMemo(()=>Zn(e||[]),[e]),{mirrorGroups:a,ungroupedItems:d}=g.useMemo(()=>{const h=new Map,j=[];for(const y of p){const k=y.group;k?(h.has(k)||h.set(k,[]),h.get(k).push(y)):j.push(y)}for(const y of h.values())y.sort((k,_)=>{const v=$=>$.group_role==="origin"?0:$.group_role==="mirror"?1:2;return v(k)-v(_)});return{mirrorGroups:h,ungroupedItems:j}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},f=h=>u[h]?u[h]:h.split("+").map(j=>u[j]||j).join("+");if(!p||p.length===0)return t.jsx("div",{style:{padding:"16px",color:o("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((h,j)=>t.jsx(yn,{item:h},h.id||j))});const x=(h,j)=>{const y=i==null?void 0:i[h],k=(y==null?void 0:y.label)||h,_=y==null?void 0:y.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:c(k)}),_&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.5},children:c(_)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((v,$)=>t.jsx(yn,{item:v,onNavigate:r,renderLink:s},v.id||$))})]},`group-${h}`)},m=new Map;for(const h of d){const j=Jn(ft(h));m.has(j)||m.set(j,[]),m.get(j).push(h)}const b=["text","image","text+image","physical"],w=[...b.filter(h=>m.has(h)),...[...m.keys()].filter(h=>!b.includes(h)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([h,j])=>x(h,j)),w.map(h=>{const j=m.get(h),y=Fl(h.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:y,whiteSpace:"nowrap",flexShrink:0},children:f(h)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((k,_)=>t.jsx(yn,{item:k,onNavigate:r,renderLink:s},k.id||_))})]},h)})]})},Pl={bw:{label:"",bg:o("colormode-bw-bg"),fg:o("colormode-bw-fg")},color:{label:"",bg:o("colormode-color-bg"),fg:o("colormode-color-fg")}},yn=({item:e})=>{const n=ae(),{convert:i}=V(),[r,s]=g.useState(!1),l=g.useMemo(()=>(e.url?zt(e.url):void 0)||i(e.name),[e.url,e.name,i]),c=g.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(b=>({...b,url:b.url||ur(b)})),[e.volumes]),p=c&&c.length>0,a=p?new Set(c.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=p?new Set(c.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=e.expected_volumes??(p?a+d:0),f=e.color_mode?{...Pl[e.color_mode],label:n.colorMode[e.color_mode]}:null,x=e.details&&!p?i(e.details):null,m={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",background:o("input-bg"),fontSize:"12px",color:o("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:m,children:[t.jsx("span",{style:{fontWeight:500},children:l}),f&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:f.bg,color:f.fg},children:f.label}),x&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:x}),p&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[a,"/",u,n.unit.volume,d>0&&t.jsxs("span",{style:{color:o("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),e.url&&t.jsx("a",{href:(()=>{const b=Xn(e.metadata);return b?Qn(e.url,b):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:o("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),p&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),p&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:c.map(b=>{const w=b.status==="missing";return b.url&&!w?t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${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(w?"missing-fg":"desc-fg"),textDecoration:w?"line-through":"none",opacity:w?.6:1},children:b.volume},b.volume)})})]})},fr=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:c})=>{const p=ae(),a=e==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",f=u?u.split(/[/\\]/).pop()||u:"",x={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:o("primary-soft"),color:o("primary")},m={onMouseOver:w=>w.currentTarget.style.opacity="0.8",onMouseOut:w=>w.currentTarget.style.opacity="1"},b=t.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...x,background:o(d?"warning":"success"),color:o("on-color-fg")},...m,children:[t.jsx("span",{children:d?"📝":"📚"}),t.jsx("span",{children:d?"draft":"official"})]});return i==="index-browser"?a?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,t.jsxs("div",{onClick:r,title:p.mode.switchToSync,style:x,...m,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:p.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:c,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px"},...m,children:[t.jsx("span",{children:"📂"}),f&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:p.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:f||p.mode.configurePath,style:{...x,background:"transparent",padding:"6px",fontSize:"12px"},...m,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:a?p.mode.switchToGithub:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:a?"📁":"🌐"}),t.jsx("span",{children:a?p.mode.localMode:p.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&t.jsxs("div",{onClick:c,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...m,children:[t.jsx("span",{children:"📂"}),f&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]}),!a&&f&&t.jsxs("div",{style:{...x,background:o("mode-active-bg"),color:o("on-color-fg"),cursor:"default"},title:u,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:f})]})]})},pn="bim-search-history",Zi=10,Xi=8;function Ft(){try{const e=localStorage.getItem(pn);return e?JSON.parse(e):[]}catch{return[]}}function Ol(e){try{const n=Ft().filter(i=>i!==e);n.unshift(e),n.length>Zi&&(n.length=Zi),localStorage.setItem(pn,JSON.stringify(n))}catch{}}function Dl(e){try{const n=Ft().filter(i=>i!==e);localStorage.setItem(pn,JSON.stringify(n))}catch{}}function Hl(){try{localStorage.removeItem(pn)}catch{}}const gr=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:l})=>{const c=ae(),p=l??c.search.placeholder,a={work:c.indexType.work,book:c.indexType.book,collection:c.indexType.collection,entity:c.indexType.entity},[d,u]=g.useState(!1),[f,x]=g.useState([]),[m,b]=g.useState(-1),[w,h]=g.useState(Ft),j=g.useRef(null),y=g.useRef(null),k=g.useRef(null),_=g.useRef(!1);g.useEffect(()=>{b(-1);const C=n.trim();if(!C){x(w.map(A=>({type:"history",text:A})));return}if(!e.searchAll){x([]);return}let P=!1;const W=setTimeout(()=>{e.searchAll(C,Xi).then(A=>{if(P)return;const M=[...A.works,...A.books,...A.collections,...A.entities??[]];x(M.slice(0,Xi).map(U=>({type:"entry",text:U.title||U.id,entry:U})))}).catch(()=>{P||x([])})},80);return()=>{P=!0,clearTimeout(W)}},[n,w,e]),g.useEffect(()=>{const C=P=>{k.current&&!k.current.contains(P.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),g.useEffect(()=>{const C=P=>{var W,A;if(P.key==="/"&&document.activeElement!==j.current){const M=(W=document.activeElement)==null?void 0:W.tagName;if(M==="INPUT"||M==="TEXTAREA"||M==="SELECT")return;P.preventDefault(),(A=j.current)==null||A.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const v=g.useCallback(C=>{C.trim()&&(Ol(C.trim()),h(Ft())),r(C),u(!1)},[r]),$=g.useCallback(C=>{C.type==="history"?(i(C.text),v(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(i(C.text),v(C.text)))},[i,v,s]),S=g.useCallback(C=>{if(!d||f.length===0){C.key==="Enter"&&v(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(P=>(P+1)%f.length);break;case"ArrowUp":C.preventDefault(),b(P=>(P-1+f.length)%f.length);break;case"Enter":C.preventDefault(),m>=0&&m<f.length?$(f[m]):v(n);break;case"Escape":C.preventDefault(),u(!1);break}},[d,f,m,n,v,$]),z=g.useCallback((C,P)=>{P.stopPropagation(),Dl(C),h(Ft()),x(W=>W.filter(A=>!(A.type==="history"&&A.text===C)))},[]),T=g.useCallback(C=>{C.stopPropagation(),Hl(),h([]),x([])},[]);g.useEffect(()=>{if(m>=0&&y.current){const C=y.current.children;C[m]&&C[m].scrollIntoView({block:"nearest"})}},[m]);const R=!n.trim()&&w.length>0;return t.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:j,type:"text",placeholder:p,value:n,onChange:C=>{i(C.target.value),u(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{u(!0)},onKeyDown:S,style:{width:"100%",padding:"8px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),d&&f.length>0&&t.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:o("input-bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"6px",boxShadow:o("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[R&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:o("desc-fg"),borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("span",{children:c.search.history}),t.jsx("button",{onClick:T,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:c.search.clearAll})]}),f.map((C,P)=>t.jsxs("div",{onClick:()=>$(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:o("fg"),background:P===m?o("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:[a[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&t.jsx("button",{onClick:W=>z(C.text,W),style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:c.action.remove,children:"×"})]},`${C.type}-${C.text}-${P}`))]})]})},kt="bim-recent-ids",Qi="bim-recent-entries",eo=50,jn=5,Gl=50,Ul=200;function yt(){try{const e=localStorage.getItem(kt);if(e)return JSON.parse(e);const n=localStorage.getItem(Qi);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(kt,JSON.stringify(i)),localStorage.removeItem(Qi),i}return[]}catch{return[]}}function to(e){try{const n=yt().filter(i=>i!==e);n.unshift(e),n.length>eo&&(n.length=eo),localStorage.setItem(kt,JSON.stringify(n))}catch{}}function Vl(e){try{const n=yt().filter(i=>i!==e);localStorage.setItem(kt,JSON.stringify(n))}catch{}}function Yl(){try{localStorage.removeItem(kt)}catch{}}const Kl={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Nn=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a,hideModeIndicator:d,resultVariant:u="compact",renderEntry:f,initialQuery:x,onQueryChange:m,headerRight:b,reserveViewportHeight:w=!1})=>{const h=ae(),j=[{type:"work",icon:"✍️",name:h.indexType.work,key:"works"},{type:"book",icon:"📖",name:h.indexType.book,key:"books"},{type:"collection",icon:"📚",name:h.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:h.indexType.entity,key:"entities"}],[y,k]=g.useState(x??""),[_,v]=g.useState(null),[$,S]=g.useState(null),[z,T]=g.useState(!1),[R,C]=g.useState(null),[P,W]=g.useState(""),[A,M]=g.useState(!(x!=null&&x.trim())),[U,G]=g.useState(yt),[E,ie]=g.useState([]),[F,re]=g.useState(!1),[ce,Z]=g.useState(!1),[O,q]=g.useState(null),[de,se]=g.useState(null),ee=g.useRef(void 0),D=g.useRef(!1),Y=g.useCallback(async(N,ne)=>{if(!N.trim()){M(!0),v(null),S(null);return}M(!1),T(!0),W("");try{if(e.searchAll){const oe=await e.searchAll(N,ne??jn);v(oe)}else{const oe=["work","book","collection","entity"],be=await Promise.all(oe.map(fe=>e.search(N,fe,{page:1,pageSize:ne??jn})));v({works:be[0].entries,books:be[1].entries,collections:be[2].entries,entities:be[3].entries,totalWorks:be[0].total,totalBooks:be[1].total,totalCollections:be[2].total,totalEntities:be[3].total})}}catch(oe){W(oe instanceof Error?oe.message:String(oe)),v(null)}finally{T(!1)}},[e]);g.useEffect(()=>{let N=!1;const ne=()=>{var we,Le;const oe=["work","book","collection","entity"],be=Promise.all(oe.map(We=>e.loadEntries(We,{page:1,pageSize:1}).catch(()=>({total:0})))),fe=((we=e.getResourceCounts)==null?void 0:we.call(e).catch(()=>null))??Promise.resolve(null),$e=((Le=e.getSubtypeStats)==null?void 0:Le.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([be,fe,$e]).then(([We,ze,De])=>{N||(q({works:We[0].total,books:We[1].total,collections:We[2].total,entities:We[3].total,hasText:ze==null?void 0:ze.hasText,hasImage:ze==null?void 0:ze.hasImage}),De&&se(De))})};return e.getCounts?e.getCounts().then(oe=>{var be,fe;N||(q({works:oe.works,books:oe.books,collections:oe.collections,entities:oe.entities,hasText:(be=oe.resourceCounts)==null?void 0:be.hasText,hasImage:(fe=oe.resourceCounts)==null?void 0:fe.hasImage}),oe.subtypeStats&&se(oe.subtypeStats))}).catch(()=>{N||ne()}):ne(),()=>{N=!0}},[e]),g.useEffect(()=>{D.current||!(x!=null&&x.trim())||(D.current=!0,Y(x))},[x,Y]);const Q=g.useCallback(N=>{if(k(N),!N.trim()){m==null||m(N),M(!0),v(null),S(null);return}ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{S(null),m==null||m(N),Y(N)},Ul)},[Y,m]),L=g.useCallback(N=>{ee.current&&clearTimeout(ee.current),m==null||m(N),Y(N)},[Y,m]),I=g.useCallback(N=>{S(N),Y(y,Gl)},[y,Y]);g.useEffect(()=>{if(!U.length){ie([]);return}let N=!1;return re(!0),Promise.all(U.slice(0,10).map(async ne=>{var oe,be,fe;try{if(e.getEntry){const we=await e.getEntry(ne);if(we)return we}const $e=await e.getItem(ne);if($e){const we=$e.authors;return{id:ne,title:$e.title||ne,type:$e.type||"work",author:(oe=we==null?void 0:we[0])==null?void 0:oe.name,dynasty:(be=we==null?void 0:we[0])==null?void 0:be.dynasty,role:(fe=we==null?void 0:we[0])==null?void 0:fe.role,edition:$e.edition||void 0}}}catch{}return{id:ne,title:ne,type:"work",notFound:!0}})).then(ne=>{N||(ie(ne),re(!1))}),()=>{N=!0}},[U,e]);const K=N=>{C(N.id),to(N.id),G(yt()),r==null||r(N)},X=(N,ne)=>{if(r&&Jl(ne)){ne.preventDefault(),K(N);return}to(N.id),G(yt())},ue=N=>{Vl(N),G(yt())},xe=()=>{Yl(),G([])},ve=N=>j.find(ne=>ne.type===N),_e=!A&&!_&&!P,te=_&&(_.works.length>0||_.books.length>0||_.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",style:w?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:Zl}),t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("h1",{style:{margin:0,fontSize:"18px",color:o("fg")},children:h.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&t.jsx(fr,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(gr,{transport:e,value:y,onChange:Q,onSearch:L,onEntrySelect:K}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${o("primary")}`,borderRadius:"6px",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"13px"},children:h.action.newEntry})]}),A&&t.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:O&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:de?t.jsxs(t.Fragment,{children:[(de.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:o("fg")},children:de.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:o("fg")},children:O.books.toLocaleString()})," 本"]}),de.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:o("fg")},children:de.article.toLocaleString()})," 篇"]}):null,de.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:o("fg")},children:de.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:o("fg")},children:O.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[h.indexType.work," ",t.jsx("strong",{style:{color:o("fg")},children:O.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.book," ",t.jsx("strong",{style:{color:o("fg")},children:O.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.collection," ",t.jsx("strong",{style:{color:o("fg")},children:O.collections.toLocaleString()}),O.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.entity," ",t.jsx("strong",{style:{color:o("fg")},children:O.entities.toLocaleString()})]})]})}),O.hasImage!=null&&O.hasText!=null&&t.jsxs("span",{children:[h.resourceType.image," ",t.jsx("strong",{style:{color:o("fg")},children:O.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.resourceType.text," ",t.jsx("strong",{style:{color:o("fg")},children:O.hasText.toLocaleString()})]})]})}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:z||_e?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg"),minHeight:ql,boxSizing:"border-box"},children:h.search.searching}):P?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:P})]}):A?t.jsx("div",{style:{flex:1},children:F?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:h.search.loading}):E.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:h.search.recentBrowse}),t.jsx("button",{onClick:xe,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:h.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:E.slice(0,ce?10:3).map(N=>N.notFound?t.jsx(ta,{id:N.id,onRemove:ue,t:h},N.id):t.jsx(no,{entry:N,selected:R===N.id,onClick:X,getConfig:ve,onRemove:ue},N.id))}),!ce&&E.length>3&&t.jsx("button",{onClick:()=>Z(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:h.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:h.search.searchTitle}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:h.search.searchSubtitle})]})}):te?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:Xl}),j.map(({type:N,icon:ne,name:oe,key:be})=>{const fe=_[be]??[],$e=Kl[be],we=_[$e]??0;if(fe.length===0)return null;const We=!($===N)&&we>jn;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:[ne," ",oe,t.jsxs("span",{style:{fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[we," ",h.unit.items]})]}),We&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>I(N),style:{border:"none",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"12px"},children:h.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:fe.map(ze=>{if(f)return t.jsx(g.Fragment,{children:f(ze)},ze.id);const De=u==="card"?ea:no;return t.jsx(De,{entry:ze,selected:R===ze.id,onClick:X,getConfig:ve,query:y},ze.id)})})]},N)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:Ht(h.search.noResultsFor,{query:y})}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:h.search.tryOther})]})})]})},ql=240;function Jl(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const Zl=`
|
|
1
|
+
"use strict";var ll=Object.create;var Zi=Object.defineProperty;var al=Object.getOwnPropertyDescriptor;var cl=Object.getOwnPropertyNames;var dl=Object.getPrototypeOf,pl=Object.prototype.hasOwnProperty;var ul=(e,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of cl(n))!pl.call(e,s)&&s!==i&&Zi(e,s,{get:()=>n[s],enumerable:!(r=al(n,s))||r.enumerable});return e};var on=(e,n,i)=>(i=e!=null?ll(dl(e)):{},ul(n||!e||!e.__esModule?Zi(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ve=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),g=require("react"),xl=require("opencc-js/t2cn"),fl=require("react-markdown"),gl=require("remark-gfm"),ml=e=>`/book-index?id=${e}`,ar=g.createContext(ml);function hl({buildUrl:e,children:n}){const i=g.useMemo(()=>e,[e]);return t.jsx(ar.Provider,{value:i,children:n})}function Ae(){return g.useContext(ar)}const cr="",dr="";function pr(e){const n=[];let i=!1,r=e;for(;r.length;){const s=i?dr:cr,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 Pe(e,n){return{title:e,tokens:n}}const Xi='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',bl=[Pe("基础(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"}}),Pe("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),Pe("提示与警告",{"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)"}}),Pe("遮罩与阴影",{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)"}}),Pe("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),Pe("资源",{"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"}}),Pe("整理本(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"}}),Pe("版本传承(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"}}),Pe("编辑器视图(主要在 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")'}}),Pe("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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}}),Pe("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),Pe("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),Pe("字体(全站无衬线,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:Xi,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:Xi,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],yl=Object.assign({},...bl.map(e=>e.tokens)),ur={};for(const[e,n]of Object.entries(yl))ur[e]=`var(--bim-${e}, ${n.value})`;function o(e){const n=ur[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function ht(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function jl(e,n){return ht(e).includes(n)}const An={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},vl={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};o("quality-published"),o("quality-fine"),o("quality-rough"),o("quality-ocr");const It=g.createContext(null),xr={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:"圖片資源"}},kl={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=["曹霑"];function wl(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function _l(e,n=Sl){const i=[...new Set(n.filter(Boolean))].sort((l,c)=>c.length-l.length);if(!i.length)return e;const r=new RegExp(`(${i.map(wl).join("|")})`,"g"),s=new Set(i);return l=>{if(!l)return e(l);const c=l.split(r);return c.length===1?e(l):c.map((p,a)=>a%2===1&&s.has(p)?p:p&&e(p)).join("")}}let Lt=null;function $l(){if(Lt)return Lt;try{Lt=_l(xl.Converter({from:"tw",to:"cn"}))}catch{Lt=e=>e}return Lt}const zl={"zh-Hant":xr,"zh-Hans":kl},fr="bim-locale";function Cl(){try{const e=localStorage.getItem(fr);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Il(e){try{localStorage.setItem(fr,e)}catch{}}const Tl="zh-Hans",Rl=({locale:e,onLocaleChange:n,converter:i,children:r})=>{const[s,l]=g.useState(e??Tl),c=e??s;g.useEffect(()=>{if(e)return;const u=Cl();u&&u!==s&&l(u)},[]);const p=g.useMemo(()=>c==="zh-Hans"?i??$l():null,[c,i]),a=g.useCallback(u=>{l(u),Il(u),n==null||n(u)},[n]),d=g.useMemo(()=>({locale:c,setLocale:a,messages:zl[c],converter:p}),[c,a,p]);return t.jsx(It.Provider,{value:d,children:r})};function ce(){const e=g.useContext(It);return(e==null?void 0:e.messages)??xr}const El=2e3;function V(){const e=g.useContext(It),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,r=g.useRef(new Map),s=g.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const l=g.useCallback(c=>{if(!c)return"";if(!i)return c;const p=r.current.get(c);if(p!==void 0)return p;const a=i(c);if(r.current.size>=El){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(c,a),a},[i]);return g.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Ut(e,n){return e.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function Nl(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 Ll(){return{id:"",name:"",url:"",type:"text",details:""}}const Wn=({items:e,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const l=ce(),[c,p]=g.useState(null),a=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],d=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=y=>{if(!s)return!0;const k=ht(y);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},f=e.map((y,k)=>({item:y,originalIndex:k})).filter(({item:y})=>u(y)),x=()=>{const y=Ll();s&&(y.type=s),n([...e,y]),p(e.length)},m=y=>{n(e.filter((k,_)=>_!==y)),p(null)},b=(y,k,_)=>{const v=[...e];if(v[y]={...v[y],[k]:_},k==="url"&&!v[y].id){const $=Nl(_);$&&(v[y].id=$)}n(v)},w=(y,k,_)=>{const $={...e[y].metadata||{}};_?$[k]=_:delete $[k],b(y,"metadata",Object.keys($).length>0?$:void 0)},h=(y,k)=>{const _=k.trim()?k.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;b(y,"structure",_)},j=(y,k,_)=>{const $=e[y].coverage||{level:1,ranges:""};k==="level"?$.level=parseInt(_)||1:$.ranges=_,b(y,"coverage",$.ranges?$:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[f.map(({item:y,originalIndex:k})=>{var _,v,$;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(c===k?null:k),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:c===k?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Bl(y.type??"text"),color:o("on-color-fg")},children:(()=>{var z,I;const S=ht(y);return S.length===0?y.type??"text":S.length===1?((z=a.find(R=>R.value===S[0]))==null?void 0:z.label)??S[0]:S.includes("text")&&S.includes("image")?((I=a.find(R=>R.value==="text+image"))==null?void 0:I.label)??"text+image":S.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${l.editor.resourcePlaceholder} ${k+1}`}),y.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:y.id}),y.url&&t.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&y.url&&Al(k,r==null?void 0:r[k],i,l),t.jsx("button",{onClick:S=>{S.stopPropagation(),m(k)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),c===k&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:[jl(y,"image")&&y.url&&Wl(y,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Bt,children:[t.jsx("span",{style:At,children:l.label.type}),t.jsx("select",{value:y.type,onChange:S=>b(k,"type",S.target.value),style:{...Ze,flex:1},children:a.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]}),t.jsxs("label",{style:Bt,children:[t.jsx("span",{style:At,children:l.label.rootType}),t.jsx("select",{value:y.root_type||"catalog",onChange:S=>b(k,"root_type",S.target.value),style:{...Ze,flex:1},children:d.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:y.id,onChange:S=>b(k,"id",S.target.value),placeholder:l.editor.idAutoExtract,style:{...Ze,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:y.name,onChange:S=>b(k,"name",S.target.value),placeholder:l.editor.resourceName,style:{...Ze,flex:1}})]}),t.jsx("input",{type:"text",value:y.url,onChange:S=>b(k,"url",S.target.value),placeholder:l.editor.resourceUrl,style:Ze}),t.jsx("input",{type:"text",value:((_=y.structure)==null?void 0:_.join("、"))||"",onChange:S=>h(k,S.target.value),placeholder:l.editor.structurePlaceholder,style:Ze}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Bt,children:[t.jsx("span",{style:At,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((v=y.coverage)==null?void 0:v.level)??"",onChange:S=>j(k,"level",S.target.value),placeholder:"1",style:{...Ze,width:"60px"}})]}),t.jsxs("label",{style:{...Bt,flex:1},children:[t.jsx("span",{style:At,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:(($=y.coverage)==null?void 0:$.ranges)||"",onChange:S=>j(k,"ranges",S.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...Ze,flex:1}})]})]}),t.jsx("textarea",{value:y.details||"",onChange:S=>b(k,"details",S.target.value),placeholder:l.editor.detailsPlaceholder,style:{...Ze,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(([S,z])=>{var I;return t.jsxs("label",{style:{...Bt,gap:"4px"},children:[t.jsx("span",{style:{...At,minWidth:"56px"},children:z}),t.jsx("input",{type:"text",value:((I=y.metadata)==null?void 0:I[S])||"",onChange:R=>w(k,S,R.target.value),placeholder:z,style:{...Ze,flex:1}})]},S)})})]})]})]})]},k)}),t.jsxs("button",{onClick:x,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:l.action.addResource})]})]})};function Bl(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 Al(e,n,i,r){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:c=>{c.stopPropagation(),s||i(e,"")},disabled:s,style:{background:"transparent",border:"none",color:o(l?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:l?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":s?"⏳":"⬇"})}function Wl(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 Ze={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"},Bt={display:"flex",alignItems:"center",gap:"6px"},At={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","www.shuge.org":"書格","shuge.org":"書格","pan.baidu.com":"百度網盤"};function Tt(e){try{return Ml[new URL(e).hostname]}catch{return}}const Qi={text:0,image:1,physical:2};function ti(e){return e.length===0?"physical":[...e].sort((n,i)=>(Qi[n]??99)-(Qi[i]??99)).join("+")}function ni(e){var c;const n=p=>{const a=p.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const d=p.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},i=new Map;for(let p=0;p<e.length;p++){const a=e[p];if(a.volumes&&a.volumes.length>0)continue;const d=n(a.name);if(!d)continue;const[u,f]=d,x=`${u}|${ti(ht(a))}`;i.has(x)||i.set(x,{base:{...a,name:u,url:"",volumes:[]},volumes:[],indices:[]});const m=i.get(x);m.volumes.push({volume:f,url:a.url||void 0,status:"found"}),m.indices.push(p)}const r=[],s=new Set;for(const p of i.values())if(!(p.volumes.length<2)){p.volumes.sort((a,d)=>a.volume-d.volume),p.base.volumes=p.volumes,p.base.expected_volumes=p.volumes.length,p.base.url||(p.base.url=((c=p.volumes.find(a=>a.url))==null?void 0:c.url)??""),r.push(p.base);for(const a of p.indices)s.add(a)}const l=[...r];for(let p=0;p<e.length;p++)s.has(p)||l.push(e[p]);return l}function gr(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 mr(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||gr(n)}))}function gn(e){const n=mr(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 ii(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 oi(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 Rt(e){if(!e.url)return;const n=ii(e.metadata);return n?oi(e.url,n):e.url}const eo={text:o("restype-text"),image:o("restype-image"),"text+image":o("restype-text-image"),physical:o("restype-physical")};function Fl(e){return e.includes("text")&&e.includes("image")?eo["text+image"]:eo[e[0]||"physical"]}const ri=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const l=ce(),{convert:c}=V(),p=g.useMemo(()=>ni(e||[]),[e]),{mirrorGroups:a,ungroupedItems:d}=g.useMemo(()=>{const h=new Map,j=[];for(const y of p){const k=y.group;k?(h.has(k)||h.set(k,[]),h.get(k).push(y)):j.push(y)}for(const y of h.values())y.sort((k,_)=>{const v=$=>$.group_role==="origin"?0:$.group_role==="mirror"?1:2;return v(k)-v(_)});return{mirrorGroups:h,ungroupedItems:j}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},f=h=>u[h]?u[h]:h.split("+").map(j=>u[j]||j).join("+");if(!p||p.length===0)return t.jsx("div",{style:{padding:"16px",color:o("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((h,j)=>t.jsx(wn,{item:h},h.id||j))});const x=(h,j)=>{const y=i==null?void 0:i[h],k=(y==null?void 0:y.label)||h,_=y==null?void 0:y.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:c(k)}),_&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.5},children:c(_)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((v,$)=>t.jsx(wn,{item:v,onNavigate:r,renderLink:s},v.id||$))})]},`group-${h}`)},m=new Map;for(const h of d){const j=ti(ht(h));m.has(j)||m.set(j,[]),m.get(j).push(h)}const b=["text","image","text+image","physical"],w=[...b.filter(h=>m.has(h)),...[...m.keys()].filter(h=>!b.includes(h)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([h,j])=>x(h,j)),w.map(h=>{const j=m.get(h),y=Fl(h.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:y,whiteSpace:"nowrap",flexShrink:0},children:f(h)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((k,_)=>t.jsx(wn,{item:k,onNavigate:r,renderLink:s},k.id||_))})]},h)})]})},Pl={bw:{label:"",bg:o("colormode-bw-bg"),fg:o("colormode-bw-fg")},color:{label:"",bg:o("colormode-color-bg"),fg:o("colormode-color-fg")}},wn=({item:e})=>{const n=ce(),{convert:i}=V(),[r,s]=g.useState(!1),l=g.useMemo(()=>(e.url?Tt(e.url):void 0)||i(e.name),[e.url,e.name,i]),c=g.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(b=>({...b,url:b.url||gr(b)})),[e.volumes]),p=c&&c.length>0,a=p?new Set(c.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=p?new Set(c.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=e.expected_volumes??(p?a+d:0),f=e.color_mode?{...Pl[e.color_mode],label:n.colorMode[e.color_mode]}:null,x=e.details&&!p?i(e.details):null,m={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",background:o("input-bg"),fontSize:"12px",color:o("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:m,children:[t.jsx("span",{style:{fontWeight:500},children:l}),f&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:f.bg,color:f.fg},children:f.label}),x&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:x}),p&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[a,"/",u,n.unit.volume,d>0&&t.jsxs("span",{style:{color:o("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),e.url&&t.jsx("a",{href:(()=>{const b=ii(e.metadata);return b?oi(e.url,b):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:o("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),p&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),p&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${o("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:c.map(b=>{const w=b.status==="missing";return b.url&&!w?t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${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(w?"missing-fg":"desc-fg"),textDecoration:w?"line-through":"none",opacity:w?.6:1},children:b.volume},b.volume)})})]})},hr=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:c})=>{const p=ce(),a=e==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",f=u?u.split(/[/\\]/).pop()||u:"",x={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:o("primary-soft"),color:o("primary")},m={onMouseOver:w=>w.currentTarget.style.opacity="0.8",onMouseOut:w=>w.currentTarget.style.opacity="1"},b=t.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...x,background:o(d?"warning":"success"),color:o("on-color-fg")},...m,children:[t.jsx("span",{children:d?"📝":"📚"}),t.jsx("span",{children:d?"draft":"official"})]});return i==="index-browser"?a?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,t.jsxs("div",{onClick:r,title:p.mode.switchToSync,style:x,...m,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:p.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:c,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px"},...m,children:[t.jsx("span",{children:"📂"}),f&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:p.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:f||p.mode.configurePath,style:{...x,background:"transparent",padding:"6px",fontSize:"12px"},...m,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:a?p.mode.switchToGithub:p.mode.switchToLocal,style:x,...m,children:[t.jsx("span",{children:a?"📁":"🌐"}),t.jsx("span",{children:a?p.mode.localMode:p.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&t.jsxs("div",{onClick:c,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...m,children:[t.jsx("span",{children:"📂"}),f&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]}),!a&&f&&t.jsxs("div",{style:{...x,background:o("mode-active-bg"),color:o("on-color-fg"),cursor:"default"},title:u,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:f})]})]})},mn="bim-search-history",to=10,no=8;function Ot(){try{const e=localStorage.getItem(mn);return e?JSON.parse(e):[]}catch{return[]}}function Ol(e){try{const n=Ot().filter(i=>i!==e);n.unshift(e),n.length>to&&(n.length=to),localStorage.setItem(mn,JSON.stringify(n))}catch{}}function Dl(e){try{const n=Ot().filter(i=>i!==e);localStorage.setItem(mn,JSON.stringify(n))}catch{}}function Hl(){try{localStorage.removeItem(mn)}catch{}}const br=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:l})=>{const c=ce(),p=l??c.search.placeholder,a={work:c.indexType.work,book:c.indexType.book,collection:c.indexType.collection,entity:c.indexType.entity},[d,u]=g.useState(!1),[f,x]=g.useState([]),[m,b]=g.useState(-1),[w,h]=g.useState(Ot),j=g.useRef(null),y=g.useRef(null),k=g.useRef(null),_=g.useRef(!1);g.useEffect(()=>{b(-1);const C=n.trim();if(!C){x(w.map(B=>({type:"history",text:B})));return}if(!e.searchAll){x([]);return}let F=!1;const W=setTimeout(()=>{e.searchAll(C,no).then(B=>{if(F)return;const M=[...B.works,...B.books,...B.collections,...B.entities??[]];x(M.slice(0,no).map(U=>({type:"entry",text:U.title||U.id,entry:U})))}).catch(()=>{F||x([])})},80);return()=>{F=!0,clearTimeout(W)}},[n,w,e]),g.useEffect(()=>{const C=F=>{k.current&&!k.current.contains(F.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),g.useEffect(()=>{const C=F=>{var W,B;if(F.key==="/"&&document.activeElement!==j.current){const M=(W=document.activeElement)==null?void 0:W.tagName;if(M==="INPUT"||M==="TEXTAREA"||M==="SELECT")return;F.preventDefault(),(B=j.current)==null||B.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const v=g.useCallback(C=>{C.trim()&&(Ol(C.trim()),h(Ot())),r(C),u(!1)},[r]),$=g.useCallback(C=>{C.type==="history"?(i(C.text),v(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(i(C.text),v(C.text)))},[i,v,s]),S=g.useCallback(C=>{if(!d||f.length===0){C.key==="Enter"&&v(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(F=>(F+1)%f.length);break;case"ArrowUp":C.preventDefault(),b(F=>(F-1+f.length)%f.length);break;case"Enter":C.preventDefault(),m>=0&&m<f.length?$(f[m]):v(n);break;case"Escape":C.preventDefault(),u(!1);break}},[d,f,m,n,v,$]),z=g.useCallback((C,F)=>{F.stopPropagation(),Dl(C),h(Ot()),x(W=>W.filter(B=>!(B.type==="history"&&B.text===C)))},[]),I=g.useCallback(C=>{C.stopPropagation(),Hl(),h([]),x([])},[]);g.useEffect(()=>{if(m>=0&&y.current){const C=y.current.children;C[m]&&C[m].scrollIntoView({block:"nearest"})}},[m]);const R=!n.trim()&&w.length>0;return t.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:j,type:"text",placeholder:p,value:n,onChange:C=>{i(C.target.value),u(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{u(!0)},onKeyDown:S,style:{width:"100%",padding:"8px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),d&&f.length>0&&t.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:o("input-bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"6px",boxShadow:o("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[R&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:o("desc-fg"),borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("span",{children:c.search.history}),t.jsx("button",{onClick:I,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:c.search.clearAll})]}),f.map((C,F)=>t.jsxs("div",{onClick:()=>$(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:o("fg"),background:F===m?o("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:[a[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&t.jsx("button",{onClick:W=>z(C.text,W),style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:c.action.remove,children:"×"})]},`${C.type}-${C.text}-${F}`))]})]})},_t="bim-recent-ids",io="bim-recent-entries",oo=50,_n=5,Gl=50,Ul=200;function kt(){try{const e=localStorage.getItem(_t);if(e)return JSON.parse(e);const n=localStorage.getItem(io);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(_t,JSON.stringify(i)),localStorage.removeItem(io),i}return[]}catch{return[]}}function ro(e){try{const n=kt().filter(i=>i!==e);n.unshift(e),n.length>oo&&(n.length=oo),localStorage.setItem(_t,JSON.stringify(n))}catch{}}function Vl(e){try{const n=kt().filter(i=>i!==e);localStorage.setItem(_t,JSON.stringify(n))}catch{}}function Yl(){try{localStorage.removeItem(_t)}catch{}}const Kl={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Mn=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a,hideModeIndicator:d,resultVariant:u="compact",renderEntry:f,initialQuery:x,onQueryChange:m,headerRight:b,reserveViewportHeight:w=!1})=>{const h=ce(),j=[{type:"work",icon:"✍️",name:h.indexType.work,key:"works"},{type:"book",icon:"📖",name:h.indexType.book,key:"books"},{type:"collection",icon:"📚",name:h.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:h.indexType.entity,key:"entities"}],[y,k]=g.useState(x??""),[_,v]=g.useState(null),[$,S]=g.useState(null),[z,I]=g.useState(!1),[R,C]=g.useState(null),[F,W]=g.useState(""),[B,M]=g.useState(!(x!=null&&x.trim())),[U,G]=g.useState(kt),[E,oe]=g.useState([]),[P,le]=g.useState(!1),[ge,Q]=g.useState(!1),[O,q]=g.useState(null),[de,se]=g.useState(null),te=g.useRef(void 0),D=g.useRef(!1),K=g.useCallback(async(T,ee)=>{if(!T.trim()){M(!0),v(null),S(null);return}M(!1),I(!0),W("");try{if(e.searchAll){const ie=await e.searchAll(T,ee??_n);v(ie)}else{const ie=["work","book","collection","entity"],ye=await Promise.all(ie.map(me=>e.search(T,me,{page:1,pageSize:ee??_n})));v({works:ye[0].entries,books:ye[1].entries,collections:ye[2].entries,entities:ye[3].entries,totalWorks:ye[0].total,totalBooks:ye[1].total,totalCollections:ye[2].total,totalEntities:ye[3].total})}}catch(ie){W(ie instanceof Error?ie.message:String(ie)),v(null)}finally{I(!1)}},[e]);g.useEffect(()=>{let T=!1;const ee=()=>{var _e,We;const ie=["work","book","collection","entity"],ye=Promise.all(ie.map(Fe=>e.loadEntries(Fe,{page:1,pageSize:1}).catch(()=>({total:0})))),me=((_e=e.getResourceCounts)==null?void 0:_e.call(e).catch(()=>null))??Promise.resolve(null),Ce=((We=e.getSubtypeStats)==null?void 0:We.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([ye,me,Ce]).then(([Fe,Te,He])=>{T||(q({works:Fe[0].total,books:Fe[1].total,collections:Fe[2].total,entities:Fe[3].total,hasText:Te==null?void 0:Te.hasText,hasImage:Te==null?void 0:Te.hasImage}),He&&se(He))})};return e.getCounts?e.getCounts().then(ie=>{var ye,me;T||(q({works:ie.works,books:ie.books,collections:ie.collections,entities:ie.entities,hasText:(ye=ie.resourceCounts)==null?void 0:ye.hasText,hasImage:(me=ie.resourceCounts)==null?void 0:me.hasImage}),ie.subtypeStats&&se(ie.subtypeStats))}).catch(()=>{T||ee()}):ee(),()=>{T=!0}},[e]),g.useEffect(()=>{D.current||!(x!=null&&x.trim())||(D.current=!0,K(x))},[x,K]);const X=g.useCallback(T=>{if(k(T),!T.trim()){m==null||m(T),M(!0),v(null),S(null);return}te.current&&clearTimeout(te.current),te.current=setTimeout(()=>{S(null),m==null||m(T),K(T)},Ul)},[K,m]),xe=g.useCallback(T=>{te.current&&clearTimeout(te.current),m==null||m(T),K(T)},[K,m]),A=g.useCallback(T=>{S(T),K(y,Gl)},[y,K]);g.useEffect(()=>{if(!U.length){oe([]);return}let T=!1;return le(!0),Promise.all(U.slice(0,10).map(async ee=>{var ie,ye,me;try{if(e.getEntry){const _e=await e.getEntry(ee);if(_e)return _e}const Ce=await e.getItem(ee);if(Ce){const _e=Ce.authors;return{id:ee,title:Ce.title||ee,type:Ce.type||"work",author:(ie=_e==null?void 0:_e[0])==null?void 0:ie.name,dynasty:(ye=_e==null?void 0:_e[0])==null?void 0:ye.dynasty,role:(me=_e==null?void 0:_e[0])==null?void 0:me.role,edition:Ce.edition||void 0}}}catch{}return{id:ee,title:ee,type:"work",notFound:!0}})).then(ee=>{T||(oe(ee),le(!1))}),()=>{T=!0}},[U,e]);const re=T=>{C(T.id),ro(T.id),G(kt()),r==null||r(T)},ne=(T,ee)=>{if(r&&Jl(ee)){ee.preventDefault(),re(T);return}ro(T.id),G(kt())},pe=T=>{Vl(T),G(kt())},fe=()=>{Yl(),G([])},L=T=>j.find(ee=>ee.type===T),J=!B&&!_&&!F,Y=_&&(_.works.length>0||_.books.length>0||_.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",style:w?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:Zl}),t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("h1",{style:{margin:0,fontSize:"18px",color:o("fg")},children:h.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&t.jsx(hr,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(br,{transport:e,value:y,onChange:X,onSearch:xe,onEntrySelect:re}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${o("primary")}`,borderRadius:"6px",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"13px"},children:h.action.newEntry})]}),B&&t.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:O&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:de?t.jsxs(t.Fragment,{children:[(de.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:o("fg")},children:de.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:o("fg")},children:O.books.toLocaleString()})," 本"]}),de.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:o("fg")},children:de.article.toLocaleString()})," 篇"]}):null,de.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:o("fg")},children:de.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:o("fg")},children:O.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[h.indexType.work," ",t.jsx("strong",{style:{color:o("fg")},children:O.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.book," ",t.jsx("strong",{style:{color:o("fg")},children:O.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.collection," ",t.jsx("strong",{style:{color:o("fg")},children:O.collections.toLocaleString()}),O.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.indexType.entity," ",t.jsx("strong",{style:{color:o("fg")},children:O.entities.toLocaleString()})]})]})}),O.hasImage!=null&&O.hasText!=null&&t.jsxs("span",{children:[h.resourceType.image," ",t.jsx("strong",{style:{color:o("fg")},children:O.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),h.resourceType.text," ",t.jsx("strong",{style:{color:o("fg")},children:O.hasText.toLocaleString()})]})]})}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:z||J?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg"),minHeight:ql,boxSizing:"border-box"},children:h.search.searching}):F?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:F})]}):B?t.jsx("div",{style:{flex:1},children:P?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:o("desc-fg")},children:h.search.loading}):E.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:o("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:h.search.recentBrowse}),t.jsx("button",{onClick:fe,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:h.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:E.slice(0,ge?10:3).map(T=>T.notFound?t.jsx(ta,{id:T.id,onRemove:pe,t:h},T.id):t.jsx(so,{entry:T,selected:R===T.id,onClick:ne,getConfig:L,onRemove:pe},T.id))}),!ge&&E.length>3&&t.jsx("button",{onClick:()=>Q(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:h.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:h.search.searchTitle}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:h.search.searchSubtitle})]})}):Y?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:Xl}),j.map(({type:T,icon:ee,name:ie,key:ye})=>{const me=_[ye]??[],Ce=Kl[ye],_e=_[Ce]??0;if(me.length===0)return null;const Fe=!($===T)&&_e>_n;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:[ee," ",ie,t.jsxs("span",{style:{fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[_e," ",h.unit.items]})]}),Fe&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>A(T),style:{border:"none",background:"transparent",color:o("primary"),cursor:"pointer",fontSize:"12px"},children:h.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:me.map(Te=>{if(f)return t.jsx(g.Fragment,{children:f(Te)},Te.id);const He=u==="card"?ea:so;return t.jsx(He,{entry:Te,selected:R===Te.id,onClick:ne,getConfig:L,query:y},Te.id)})})]},T)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:o("fg")},children:Ut(h.search.noResultsFor,{query:y})}),t.jsx("p",{style:{color:o("desc-fg"),fontSize:"13px"},children:h.search.tryOther})]})})]})},ql=240;function Jl(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const Zl=`
|
|
2
2
|
.bim-ib-stats { min-height: 25px; box-sizing: content-box; }
|
|
3
3
|
@media (max-width: 719px) { .bim-ib-stats { min-height: 46px; } }
|
|
4
4
|
`,Xl=`
|
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
content: ""; position: absolute; left: 50%; top: 50%;
|
|
9
9
|
width: max(calc(100% + 8px), 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
|
|
10
10
|
}
|
|
11
|
-
}`,mr={color:"inherit",textDecoration:"none"},Ql=({snippet:e})=>{const{convert:n}=V();return t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.6},children:ar(e).map((i,r)=>i.marked?t.jsx("mark",{style:{background:o("highlight-bg"),color:o("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(i.text)},r):t.jsx(g.Fragment,{children:n(i.text)},r))})},ea=({entry:e,selected:n,onClick:i,getConfig:r,query:s})=>{const l=ae(),{convert:c}=V(),p=c(e.title||e.primary_name||e.id),a=e.measure_info?c(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",d=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&d.length?d.find(m=>{const b=typeof m=="string"?m:m==null?void 0:m.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,f=o("cover-accent"),x=Ne();return t.jsxs("a",{href:x(e.id),onClick:m=>i(e,m),className:"bim-result-card",style:{...mr,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:o("bg"),border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[t.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${f} 50%, ${o("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${f} 14%, ${o("bg")}), color-mix(in srgb, ${f} 7%, ${o("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[t.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${f} 45%, transparent)`}}),t.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:f},children:Array.from(p).map((m,b)=>t.jsx("span",{children:m},b))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:o("fg")},children:p}),a&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:a})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",c(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:c(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",c(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",c(e.era),"〕"]}),e.edition&&t.jsx("span",{children:c(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[l.search.alias,":",c(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(Ql,{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]})]})]})]})},no=({entry:e,selected:n,onClick:i,getConfig:r,query:s,onRemove:l})=>{const c=ae(),{convert:p}=V(),a=[...e.additional_titles||[],...e.attached_texts||[]],d=s&&a.length?a.find(f=>{const x=typeof f=="string"?f:f==null?void 0:f.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,u=Ne();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("a",{href:u(e.id),onClick:f=>i(e,f),className:"bim-result-card",style:{...mr,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx("span",{style:{fontSize:"16px"},children:r(e.type).icon}),t.jsx("span",{style:{fontSize:"9px",color:o("desc-fg"),lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:p(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{title:c.misc.textResource,children:"📝"}),e.has_image&&t.jsx("span",{title:c.misc.imageResource,children:"🖼️"})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",p(e.era),"〕"]}),e.edition&&p(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:p(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.juan_count,c.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",p(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:p(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",p(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),d&&t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:[c.search.alias,":",p(d)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:c.search.removeFromRecent,"aria-label":c.search.removeFromRecent,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},ta=({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 na(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 ia({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 oa({alt_names:e}){const{convert:n}=V(),i=new Map;for(const l of e){const c=l.type||"別名";i.has(c)||i.set(c,[]),i.get(c).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((l,c)=>{const p=r.indexOf(l),a=r.indexOf(c);return p===-1&&a===-1?0:p===-1?1:a===-1?-1:p-a});return t.jsx("div",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const c=i.get(l);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:o("desc-fg"),fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),t.jsx("span",{children:c.map((p,a)=>t.jsxs("span",{children:[a>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},a))})]},l)})})}function ra({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 sa({works:e,transport:n,onNavigate:i,renderLink:r}){const s=ae(),{convert:l}=V(),c=Ne(),[p,a]=g.useState(new Map);g.useEffect(()=>{if(!n)return;let x=!1;const m=e.map(w=>w.work_id);return(async()=>{const w=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(m);let _=!0;for(let v=0;v<m.length;v++){const $=k[v];$!=null&&$.title?w.set(m[v],$.title):$!=null&&$.primary_name?w.set(m[v],$.primary_name):_=!1}if(_)return w}catch{}const h=[...m],j=8,y=new Array(j).fill(0).map(async()=>{for(;h.length;){const k=h.shift();if(!k)break;if(!w.has(k))try{if(n.getEntry){const $=await n.getEntry(k);if($!=null&&$.title){w.set(k,$.title);continue}}const _=await n.getItem(k),v=_&&(_.title||_.primary_name)||k;w.set(k,v)}catch{w.set(k,k)}}});return await Promise.all(y),w})().then(w=>{x||a(w)}),()=>{x=!0}},[e,n]);const d=new Map;for(const x of e){const m=x.role||"";d.has(m)||d.set(m,[]),d.get(m).push(x)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],f=[...d.keys()].sort((x,m)=>{const b=u.indexOf(x),w=u.indexOf(m);return b===-1&&w===-1?x.localeCompare(m):b===-1?1:w===-1?-1:b-w});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:o("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:o("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),f.map(x=>{const m=d.get(x);return t.jsxs("div",{style:{marginBottom:"8px"},children:[x&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"2px"},children:[l(x)," ",t.jsxs("span",{style:{color:o("desc-fg")},children:["(",m.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:x?"16px":"0",listStyle:x?"disc":"none",fontSize:"14px",lineHeight:1.8},children:m.map((b,w)=>{const h=l(p.get(b.work_id)||b.work_id);return r?t.jsx("li",{children:r(b.work_id,h)},w):i?t.jsx("li",{children:t.jsx("a",{href:c(b.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),i(b.work_id))},style:{color:o("link-fg"),textDecoration:"underline",cursor:"pointer"},children:h})},w):t.jsx("li",{children:h},w)})})]},x)})]})}const hr=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:l})=>{var f;const c=ae(),{convert:p}=V();let a=!1;try{a=he.extractStatus(e.id)==="draft"}catch{}const d=na(e),u=e.subtype==="people"?"人物":e.subtype==="place"?"地名":e.subtype==="dynasty"?"朝代":e.subtype==="anonymous"?"佚名":e.subtype==="collective"?"集体":e.subtype;return t.jsxs("div",{children:[!l&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:o("fg")},children:[p(e.primary_name),t.jsx(ia,{data:e})]}),s]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o("type-entity"),border:`1px solid color-mix(in srgb, ${o("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${o("type-entity")} 3%, transparent)`},children:c.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),a&&t.jsx("span",{style:{padding:"1px 6px",background:o("warn-bg"),border:`1px solid ${o("warn-border")}`,borderRadius:"2px",color:o("warn-fg")},children:c.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),d&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:o("widget-bg"),border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(oa,{alt_names:e.alt_names}),t.jsx(ra,{data:e}),((f=e.description)==null?void 0:f.text)&&t.jsx("p",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(e.description.text)}),e.works&&e.works.length>0&&t.jsx(sa,{works:e.works,transport:n,onNavigate:i,renderLink:r})]})},la=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function aa(e){const n=e.search(la);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const br={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>{let i=e,r="",s=n;if(e&&typeof n=="string"&&(n===e||n===ca(e))){const[l,c]=aa(n);c&&(i=encodeURI(l),s=l,r=c)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:i,target:i!=null&&i.startsWith("http")?"_blank":void 0,rel:i!=null&&i.startsWith("http")?"noopener noreferrer":void 0,style:{color:o("link")},children:s}),r]})},code:({children:e})=>t.jsx("code",{style:{background:o("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function ca(e){try{return decodeURI(e)}catch{return e}}const da={...br,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},it=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:s}=V(),l=n?da:br;return t.jsx("div",{className:r,style:i,children:t.jsx(fl,{remarkPlugins:[gl],components:l,children:s(e)})})},pa=["〇","一","二","三","四","五","六","七","八","九"],io=["","十","百","千"];function yr(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const c=parseInt(n[l]),p=i-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=io[p]:r+=pa[c]+io[p])}return r}function jr(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 ua={book:o("type-book"),work:o("type-work"),collection:o("type-collection"),entity:o("type-entity")};function xa({type:e}){const n=ae();return t.jsx("span",{style:jr(ua[e]),children:n.indexType[e]})}function fa({isDraft:e}){const n=ae(),i=o(e?"status-draft":"status-official");return t.jsx("span",{style:jr(i),children:e?n.status.draft:n.status.official})}function ga({id:e}){const n=ae(),[i,r]=g.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:o("desc-fg"),background:o("bg-subtle"),border:`1px solid ${o("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:o("fg")},children:e}),t.jsx("span",{onClick:s,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function He({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 Je({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 vr({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,c)=>{const p=s(l.name),a=l.entity_id?t.jsx(Ue,{id:l.entity_id,label:p,onNavigate:i,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:p});return t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),a,l.role&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},c)})})}function Ue({id:e,label:n,onNavigate:i,renderLink:r}){const s=Ne();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i(e))},style:{color:o("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`,paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{children:n||e})}function ma({id:e,title:n,edition:i,type:r,isDraft:s,authors:l,volumeText:c,meta:p,headerExtra:a,onNavigate:d,renderLink:u}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:o("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:i}),c&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:c})]}),a&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(xa,{type:r}),t.jsx(fa,{isDraft:s}),t.jsx(ga,{id:e})]}),((l==null?void 0:l.length)||p.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(vr,{authors:l,type:r,onNavigate:d,renderLink:u}),p]})]})}function kr({items:e,label:n,showMeta:i,onNavigate:r,renderLink:s}){const l=ae(),{convert:c}=V();if(!e.length)return null;const[p,a]=g.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(He,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((d,u)=>{const f=p===u;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...f?{boxShadow:o("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>a(f?null:u),style:{padding:"8px 12px",background:o("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.15s",transform:f?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:c(d.source)}),!f&&i&&d.title_info&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c(d.title_info)}),d.source_bid&&t.jsx("span",{onClick:x=>x.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Ue,{id:d.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),f&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${o("widget-border")}`},children:[i&&(d.title_info||d.author_info||d.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&t.jsx(Je,{label:l.label.titleInfo,children:c(d.title_info)}),d.author_info&&t.jsx(Je,{label:l.label.authorInfo,children:c(d.author_info)}),d.edition&&t.jsx(Je,{label:l.label.edition,children:c(d.edition)})]}),d.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:c(d.summary)})]}),d.comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(d.comment)})]}),d.additional_comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(d.additional_comment)})]})]})]},u)})})]})}function ha({items:e,onNavigate:n,renderLink:i}){const r=ae();return t.jsx(kr,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Sr({items:e,onNavigate:n,renderLink:i}){const r=ae();return t.jsx(kr,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function wr({label:e,items:n}){const{convert:i}=V();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(He,{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 ba({items:e}){const n=ae();return t.jsx(wr,{label:n.section.aliases,items:e})}function ya({items:e}){const n=ae();return t.jsx(wr,{label:n.section.attachedTexts,items:e})}function ja({items:e}){const n=ae(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(He,{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 va({items:e}){const n=ae(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(He,{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 ka({items:e}){const n=ae(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(He,{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 oo({title:e,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:l}=V(),[c,p]=g.useState([]);return g.useEffect(()=>{if(!n.length){p([]);return}if(!i){p(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>i.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{a||p(d)}),()=>{a=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(He,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",n.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(c.length?c:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${l(a.title)||a.id}(${l(a.edition)})`:l(a.title)||void 0;return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),transition:"border-color 0.15s"},children:t.jsx(Ue,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function vn({book:e,onNavigate:n,renderLink:i}){const r=ae(),{convert:s}=V(),[l,c]=g.useState(!1),p=e.resources&&e.resources.length>0,a=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:o("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(Ue,{id:e.id,label:a,onNavigate:n,renderLink:i})}),p&&t.jsx("span",{onClick:()=>c(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:o("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),p&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(ei,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Sa({ids:e,workData:n,transport:i,onNavigate:r,renderLink:s,footer:l}){const c=ae(),{convert:p}=V(),[a,d]=g.useState([]);if(g.useEffect(()=>{if(!e.length){d([]);return}if(!i){d(e.map(w=>({id:w})));return}let b=!1;return Promise.all(e.map(w=>i.getItem(w).then(h=>({id:w,title:h?h.title:void 0,edition:h?h.edition:void 0,resources:h?h.resources:void 0,resource_groups:h?h.resource_groups:void 0})).catch(()=>({id:w})))).then(w=>{b||d(w)}),()=>{b=!0}},[e,i]),!e.length)return null;const u=a.length?a:e.map(b=>({id:b})),f=new Map(u.map(b=>[b.id,b])),x=n==null?void 0:n.version_graph,m=wa(e,x);return t.jsxs(t.Fragment,{children:[t.jsxs(He,{children:[c.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,m.useGrouping?t.jsxs(t.Fragment,{children:[m.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:m.coreIds.map(b=>{const w=f.get(b);return w?t.jsx(vn,{book:w,onNavigate:r,renderLink:s},b):null})}),m.groupedIds.map(b=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${o("widget-border")}`,borderRadius:6,background:o("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:o("fg"),userSelect:"none"},children:[p(b.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:o("desc-fg"),fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:o("desc-fg"),fontWeight:400},children:p(b.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(w=>{const h=f.get(w);return h?t.jsx(vn,{book:h,onNavigate:r,renderLink:s},w):null})})]},b.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(b=>t.jsx(vn,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function wa(e,n){var h,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.length>0||s.length>0,c=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&c.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...c]),d=y=>{if(a.has(y))return!0;const k=n.node_groups[y];return k!=null&&p.has(k)},u=[],f=new Map,x=[];for(const y of e)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))u.push(y);else{const k=n.node_groups[y];k?(f.has(k)||f.set(k,[]),f.get(k).push(y)):x.push(y)}if(x.length+[...f.values()].reduce((y,k)=>y+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(y=>[y.id,y])),w=[...f.entries()].map(([y,k])=>{const _=b.get(y);return{id:y,label:(_==null?void 0:_.label)??y,description:_==null?void 0:_.description,ids:k}});return x.length>0&&w.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:w}}function _a({workData:e,onNavigate:n,renderLink:i}){var c,p,a,d;const r=ae(),{convert:s}=V(),l=!!((c=e.description)!=null&&c.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:o("input-bg"),marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`},children:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:t.jsx(Ue,{id:e.id,label:s(e.title),onNavigate:n,renderLink:i})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:s(e.measure_info)}):((p=e.juan_count)==null?void 0:p.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[yr(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(vr,{authors:e.authors,type:"work",onNavigate:n,renderLink:i})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((a=e.description)==null?void 0:a.text)&&t.jsx(it,{text:e.description.text,style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(d=e.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:t.jsx(Je,{label:r.label.parentWork,children:t.jsx(Ue,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function $a({items:e,onNavigate:n,renderLink:i}){const r=ae(),{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(Ue,{id:l.id,label:s(l.title)||l.id,onNavigate:n,renderLink:i}),l.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"2px"},children:Ht(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const ti=({data:e,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:c,className:p,style:a})=>{var P,W,A,M,U,G,E,ie;const d=ae(),{convert:u}=V(),[f,x]=g.useState(null),[m,b]=g.useState(!1),[w,h]=g.useState(null),[j,y]=g.useState(null),[k,_]=g.useState([]),v=e||f;if(g.useEffect(()=>{if(e||!n||!i)return;let F=!1;return b(!0),h(null),i.getItem(n).then(re=>{F||(re?x(re):h(d.misc.notFoundEntry))}).catch(re=>{F||h(re instanceof Error?re.message:d.misc.loadFailed)}).finally(()=>{F||b(!1)}),()=>{F=!0}},[e,n,i]),g.useEffect(()=>{if(!v||!i){y(null),_([]);return}let F=!1;const re=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(re?i.getItem(re).then(ce=>{!F&&ce&&ce.type==="work"&&y(ce)}).catch(()=>{}):y(null),v.type==="book"){const ce=v;ce.contained_in&&ce.contained_in.length>0?Promise.all(ce.contained_in.map(Z=>{const O=typeof Z=="string"?Z:Z.id,q=typeof Z=="string"?void 0:Z.volume_index;return i.getItem(O).then(de=>({id:O,title:de&&de.title||O,volume_index:q})).catch(()=>({id:O,title:O,volume_index:q}))})).then(Z=>{F||_(Z)}):_([])}else _([]);return()=>{F=!0}},[v,i]),m)return t.jsx("div",{className:p,style:{...a,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((F,re)=>t.jsx("div",{style:{height:re===1?"32px":"16px",width:`${F}px`,background:o("widget-border"),borderRadius:"4px",opacity:.4}},re))})});if(w)return t.jsx("div",{className:p,style:{...a,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:w});if(!v)return null;if(v.type==="entity")return t.jsx("div",{className:p,style:a,children:t.jsx(hr,{data:v,transport:i,onNavigate:r,renderLink:s,headerExtra:l})});const $=v.type==="book"?v:null,S=v.type==="collection"?v:null,z=v.type==="work"?v:null;let T=!1;try{T=he.extractStatus(v.id)==="draft"}catch{}let R="";v.measure_info?R=u(v.measure_info):(P=v.juan_count)!=null&&P.number?R=yr(v.juan_count.number)+d.unit.juan:(W=v.juan_count)!=null&&W.description&&(R=u(v.juan_count.description));const C=[];return(A=v.publication_info)!=null&&A.year&&C.push(t.jsx(Je,{label:d.label.year,children:v.publication_info.year},"year")),(M=v.current_location)!=null&&M.name&&C.push(t.jsx(Je,{label:d.label.currentLocation,children:u(v.current_location.name)},"loc")),(U=v.page_count)!=null&&U.description&&C.push(t.jsx(Je,{label:d.label.pageCount,children:v.page_count.description},"page")),$!=null&&$.edition&&C.push(t.jsx(Je,{label:d.label.edition,children:u($.edition)},"ver")),z!=null&&z.parent_work&&C.push(t.jsx(Je,{label:d.label.parentWork,children:t.jsx(Ue,{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(Je,{label:d.label.parentWork,children:z.parent_works.map((F,re)=>t.jsxs("span",{children:[re>0&&"、",t.jsx(Ue,{id:F,onNavigate:r,renderLink:s})]},F))},"pws")),t.jsxs("div",{className:p,style:a,children:[t.jsx(ma,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:T,authors:v.authors,volumeText:R,meta:C,headerExtra:l,onNavigate:r,renderLink:s}),((G=v.description)==null?void 0:G.text)&&t.jsx(it,{text:v.description.text,style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((F,re)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:o("bg-subtle"),borderRadius:4,border:`1px solid ${o("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:o("muted")},children:u(F.title)}),t.jsx(it,{text:F.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:o("fg")}})]},re))}),k.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(He,{children:d.section.containedIn}),t.jsx($a,{items:k,onNavigate:r,renderLink:s})]}),j&&t.jsxs(t.Fragment,{children:[t.jsx(He,{children:d.section.belongsToWork}),t.jsx(_a,{workData:j,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&t.jsx(ja,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&t.jsx(ba,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&t.jsx(ya,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&t.jsx(ha,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&t.jsx(Sr,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(He,{children:d.section.resources}),t.jsx(ei,{items:v.resources,resourceGroups:v.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),($==null?void 0:$.location_history)&&$.location_history.length>0&&t.jsx(va,{items:$.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&t.jsx(ka,{items:S.history}),($==null?void 0:$.related_books)&&$.related_books.length>0&&t.jsx(oo,{title:d.section.relatedVersions,ids:$.related_books,transport:i,onNavigate:r,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&t.jsx(oo,{title:d.section.containedBooks,ids:S.books,transport:i,onNavigate:r,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(He,{children:[d.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",S.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(F=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:t.jsx(Ue,{id:F.id,label:u(F.title),onNavigate:r,renderLink:s})},F.id))})]}),(((E=z==null?void 0:z.books)==null?void 0:E.length)||0)+(((ie=z==null?void 0:z.collections)==null?void 0:ie.length)||0)>0&&t.jsx(Sa,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z??void 0,transport:i,onNavigate:r,renderLink:s,footer:c}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const F=[],re=z.related_works.filter(se=>se.relation==="part_of"),ce=z.related_works.filter(se=>se.relation==="has_part"),Z=z.related_works.filter(se=>se.relation==="has_adaptation"),O=z.related_works.filter(se=>se.relation==="text_carried_by"),q=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),de=z.related_works.filter(se=>!se.relation||!q.has(se.relation));return re.length>0&&F.push({label:d.section.belongsToWork,items:re}),ce.length>0&&F.push({label:d.section.containedWorks,items:ce}),Z.length>0&&F.push({label:d.section.adaptations,items:Z}),O.length>0&&F.push({label:d.section.derivativeWorks,items:O}),de.length>0&&F.push({label:d.section.relatedWorks,items:de}),F.map(se=>t.jsxs("div",{children:[t.jsxs(He,{children:[se.label,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",se.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:se.items.map(ee=>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(Ue,{id:ee.id,label:u(ee.title),onNavigate:r,renderLink:s})},ee.id))})]},se.label))})()]})};function za({data:e}){const n=ae(),{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 Ca({sections:e,activeSection:n,onSelect:i}){const r=ae();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:ro(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:ro(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 ro(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 Ia({id:e,label:n,onNavigate:i,renderLink:r}){const s=Ne();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i(e))},style:{color:o("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:n||e})}function Ta(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=e[0],r=e[e.length-1];return r-i+1===e.length?`${i}–${r}`:e.length<=3?e.join(", "):`${i}–${r} (${e.length}${n})`}function so({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const s=ae(),{convert:l}=V(),c=e.book_id||e.work_id,p=r&&e.volumes.length>0?Ta(e.volumes,s.unit.volume):null,a=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${o("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:o("desc-fg"),textAlign:"right"},children:p}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:o("fg")},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(d=>l(d)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:o(a?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),c&&t.jsx(Ia,{id:c,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!c&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const ni=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:l,style:c})=>{const p=ae(),[a,d]=g.useState(null),[u,f]=g.useState(!1),[x,m]=g.useState(null),[b,w]=g.useState(null),[h,j]=g.useState(""),y=e||a;g.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let S=!1;return f(!0),m(null),i.getCollectionCatalog(n).then(z=>{S||(z?d(z):m(p.catalog.notFound))}).catch(z=>{S||m(z instanceof Error?z.message:p.catalog.loadFailed)}).finally(()=>{S||f(!1)}),()=>{S=!0}},[e,n,i,p]);const k=(y==null?void 0:y.sections)&&y.sections.length>0,_=g.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const S=y.books.map(T=>T.volumes[0]).filter(T=>T!=null);return new Set(S).size<S.length},[y]),v=g.useMemo(()=>{if(!y)return[];let S=y.books;if(b&&(S=S.filter(z=>z.section===b)),h.trim()){const z=h.trim().toLowerCase();S=S.filter(T=>T.title.toLowerCase().includes(z)||T.sub_items&&T.sub_items.some(R=>R.toLowerCase().includes(z))||T.edition&&T.edition.toLowerCase().includes(z))}return S},[y,b,h]),$=g.useMemo(()=>{if(!_)return null;const S=[],z=new Map;for(const R of v){if(!R.volumes||R.volumes.length===0)continue;const C=R.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(R)}const T=[...z.keys()].sort((R,C)=>R-C);for(const R of T)S.push({volume:R,books:z.get(R)});return S},[v,_]);return u?t.jsx("div",{className:l,style:{...c,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):x?t.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:x}):y?t.jsxs("div",{className:l,style:c,children:[t.jsx(za,{data:y}),k&&t.jsx(Ca,{sections:y.sections,activeSection:b,onSelect:w}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:h,onChange:S=>j(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:o("desc-fg")},children:[v.length," ",p.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[$?$.map((S,z)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:o("bg"),borderBottom:`1px solid ${o("widget-border")}`,fontSize:"12px",fontWeight:600,color:o("desc-fg"),position:"sticky",top:0,zIndex:1},children:Ht(p.catalog.volume,{n:S.volume})}),S.books.map((T,R)=>t.jsx(so,{book:T,onNavigate:r,renderLink:s,showVolumes:T.volumes.length>1},`${S.volume}-${R}`))]},`${S.volume}-${z}`)):v.map((S,z)=>t.jsx(so,{book:S,onNavigate:r,renderLink:s,showVolumes:!0},z)),v.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},gt=()=>{const[e,n]=g.useState(1);return g.useEffect(()=>{const i=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(i)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:o("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(e)})},_r=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Ra={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Te(e){return Ra[e]??e}const St=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],wt={熹平:172,建安:196,黃初:220,正始:240,廣政:938,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,開成:836,會昌:841,咸通:860,建隆:960,太平興國:976,咸平:998,天禧:1017,慶曆:1041,皇祐:1049,嘉祐:1056,治平:1064,熙寧:1068,元豐:1078,元祐:1086,紹聖:1094,崇寧:1102,大觀:1107,政和:1111,宣和:1119,建炎:1127,紹興:1131,隆興:1163,乾道:1165,淳熙:1174,紹熙:1190,慶元:1195,嘉泰:1201,開禧:1205,嘉定:1208,寶慶:1225,紹定:1228,端平:1234,嘉熙:1237,淳祐:1241,寶祐:1253,開慶:1259,景定:1260,咸淳:1265,大定:1161,明昌:1190,至元:1264,大德:1297,皇慶:1312,延祐:1314,泰定:1324,天曆:1328,至順:1330,至正:1341,洪武:1368,永樂:1403,宣德:1426,正統:1436,景泰:1450,天順:1457,成化:1465,弘治:1488,正德:1506,嘉靖:1522,隆慶:1567,萬曆:1573,泰昌:1620,天啟:1621,崇禎:1628,弘光:1645,隆武:1645,紹武:1646,永曆:1647,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,正保:1644,慶安:1648,承應:1652,明曆:1655,萬治:1658,寬文:1661,延寶:1673,天和:1681,貞享:1684,元祿:1688,寶永:1704,享保:1716,元文:1736,寬保:1741,延享:1744,寬延:1748,寶曆:1751,明和:1764,安永:1772,天明:1781,寬政:1789,享和:1801,文化:1804,文政:1818,天保:1830,弘化:1844,嘉永:1848,安政:1854,萬延:1860,文久:1861,元治:1864,慶應:1865,明治:1868,大正:1912,昭和:1926,天正:1573,文祿:1592,永祿:1558,天文:1532},$r={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function un(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 Ea(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 Na=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,lo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function ii(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(lo))if(n.startsWith(s))return lo[s];const i=Te(n);if(dt[i]!=null)return i;const r=nt(n);if(r&&n.length<=r.length+1)return Te(r)}function ct(e,n){if(n){const i=$r[`${n}|${e}`];if(i!=null)return i}return wt[e]}const La=1911;function Ba(e){const n=wt[e];if(n==null)return;const i=Ze[e];let r;for(const[s,l]of Object.entries(wt))Ze[s]===i&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const Aa={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function sn(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,i=0,r=!1;for(const l of e){const c=Aa[l];if(c===void 0)return;r=!0,l==="十"?i=(i||1)*10:l==="廿"||l==="卅"?(n+=c,i=0):i>=10?(n+=i+c,i=0):i=i*10+c}const s=n+i;return r&&s>0?s:void 0}function nt(e){for(const n of _r)if(e.startsWith(n))return n}const Ze={};{const e=(n,i)=>{for(const r of i)Ze[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function pt(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(wt))if(e.includes(r)&&!(i&&Ze[r]&&Ze[r]!==i&&$r[`${i}|${r}`]==null))return r}function Gt(e){var c,p,a;const n={era:"",reign:"",source:"none"},i=e.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const d=nt(r)??"";return{era:Te(d),reign:pt(r,d)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const d=un(s);if(d)return{era:Ea(d.from),reign:"",source:"publication"};const u=nt(s)??ii(s)??((a=St.find(m=>m.pattern.test(s)))==null?void 0:a.era)??"",f=pt(s,u)??"",x=u||(f?Ze[f]??"":"");if(x||f)return{era:Te(x),reign:f,source:"publication"}}const l=e.edition||e.title||"";if(l){const d=nt(l);if(d)return{era:Te(d),reign:pt(l,d)??"",source:"edition"};const u=St.find(f=>f.pattern.test(l));if(u)return{era:Te(u.era),reign:pt(l,u.era)??u.reign??"",source:"edition"}}return n}function xn(e){var r,s,l,c,p,a,d,u,f;if(((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;if(typeof((s=e.lineage)==null?void 0:s.year)=="number")return e.lineage.year;const n=(l=e.publication_info)==null?void 0:l.year;if(n){const x=un(n);if(x)return x.from}const i=[(c=e.lineage)==null?void 0:c.year_text,(p=e.publication_info)==null?void 0:p.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const x of i){const m=((a=e.publication_info)==null?void 0:a.year)||((d=e.lineage)==null?void 0:d.year_text);if(m&&x!==m&&(nt(m)||ii(m)))break;const b=x.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??x.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const k=parseInt(b[1],10);if(k>=100&&k<=2100)return k}const w=x.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(w){const k=nt(x);if(!k||Te(k)==="民國"){const v=sn(w[1]);if(v!=null&&v>=1&&v<=120)return La+v}}const h=nt(x)??((u=St.find(k=>k.pattern.test(x)))==null?void 0:u.era),j=h?Te(h):void 0,y=pt(x,j)??(nt(x)||(f=St.find(k=>k.pattern.test(x)))==null?void 0:f.reign);if(y){const k=ct(y,j);if(k==null)continue;const _=x.indexOf(y),v=_>=0?x.slice(_+y.length):"",$=v.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??v.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=$?sn($[1]):void 0;return k+(S?S-1:0)}}}function oi(e){var c,p,a,d,u,f;const n=(c=e.dating)==null?void 0:c.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(p=e.lineage)==null?void 0:p.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(a=e.lineage)==null?void 0:a.year_text;if(r){const x=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(x){const m=Ln[Te(x[1])],b=dt[Te(x[2])];if(m!=null&&b!=null)return{from:Math.min(m,b)-20,to:Math.max(m,b)+40}}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const x=un(s);if((x==null?void 0:x.to)!=null)return{from:x.from,to:x.to};const m=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(m){const b=Ln[Te(m[1])],w=dt[Te(m[2])];if(b!=null&&w!=null)return{from:Math.min(b,w)-20,to:Math.max(b,w)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const x of l){if(!/[間间]/.test(x))continue;const m=nt(x)??ii(x)??((f=St.find(h=>h.pattern.test(x)))==null?void 0:f.era),b=m?Te(m):void 0,w=[];for(const h of Object.keys(wt))x.includes(h)&&(b&&Ze[h]&&Ze[h]!==b||ct(h,b)!=null&&w.push(h));if(w.length===0){const h=x.match(/([一-鿿])([一-鿿])[間间]/);if(h&&b){for(const j of[h[1],h[2]])for(const y of Object.keys(wt))if(Ze[y]===b&&!(y[0]!==j&&y[y.length-1]!==j)&&ct(y,b)!=null){w.push(y);break}}}if(w.length>0){const h=w.map(_=>ct(_,b)).filter(_=>_!=null),j=Math.min(...h),y=w.reduce((_,v)=>ct(_,b)>=ct(v,b)?_:v),k=Ba(y)??kn(b??"")??Math.max(...h);return{from:j,to:k>j?k:kn(b??Ze[y]??"")??j}}if(b&&dt[b]!=null)return{from:dt[b],to:kn(b)??dt[b]}}}const dt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Wa=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Ma=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,ao=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function co(e,n){for(const i of _r){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const a=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(a)&&!pt(e.slice(r),Te(i)))continue}const s=Te(i);if(s===n)continue;const l=e.slice(r),c=pt(l,s)??"";let p;if(c){const a=ct(c,s);if(a!=null){const u=l.slice(l.indexOf(c)+c.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),f=u?sn(u[1]):void 0;p=a+(f?f-1:0)}}return{era:s,reign:c,year:p}}for(const i of St)if(i.pattern.test(e))return{era:Te(i.era),reign:i.reign??""}}function Fa(e){var j,y,k,_,v;const n=Gt(e),i=((j=e.publication_info)==null?void 0:j.year)??"",r=i?un(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),c=((y=e.lineage)==null?void 0:y.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(c),a=n.source==="publication"&&Na.test(i),d=n.source==="publication"&&/[間间]/.test(i),u=c.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let f;l||p||a||d?f=void 0:u?f=parseInt(u[2],10):f=xn(e);const x=f==null?oi(e):void 0;let m;n.source==="publication"&&(a||ao.test(i))?m="uncertain":n.source==="lineage"||n.source==="publication"?m="attested":ao.test(s)||!n.reign&&f==null?m="uncertain":m="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((k=e.lineage)==null?void 0:k.year_text)??((_=e.lineage)==null?void 0:_.year)??""}」`:`出版著錄「${((v=e.publication_info)==null?void 0:v.year)??""}」`,w={era:n.era,reign:n.reign,year:f,yearRange:x,certainty:m,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const $=c.match(/[、,,]\s*([宋元明清])/);$&&$[1]!==w.era&&(w.laterRepair={era:$[1]})}if(!w.laterRepair&&Ma.test(s)){const $=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);$&&$[1]!==n.era&&(w.laterRepair={era:$[1]})}const h=Wa.find($=>$.re.test(s));if(h){const $=s.search(h.re),S=s.slice($),z=co(S,n.era)??co(s,n.era);z&&(w.basedOn={era:z.era,reign:z.reign,year:z.year,relation:h.relation})}return w}const Ln={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function kn(e){return Ln[e]}function ln(e){const n=xn(e);if(n!=null)return n;const i=oi(e);if(i)return i.from;const r=Gt(e).era;return r?dt[r]:void 0}const po=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Bn(e){const n=po.indexOf(e);return n===-1?po.length:n}function Pa(e){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of e){const l=s.relation;l==="part_of"?n.belongsTo.push(s):l==="collected_in"?n.collected.push(s):l==="has_part"||l==="contains_text_of"?n.contains.push(s):l==="text_carried_by"||l==="studied_by"||l==="derived_from"||l==="followed_by"||l==="has_adaptation"?n.derivative.push(s):l==="studies"||l==="preceded_by"?n.studies.push(s):n.related.push(s)}const i=[],r=(s,l)=>{n[s].length&&i.push({key:s,labelKey:l,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),i}function ri(e,n){const i=Zn(e||[]),r=new Map,s=[];for(const d of i)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((u,f)=>{const x=m=>m.group_role==="origin"?0:m.group_role==="mirror"?1:2;return x(u)-x(f)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=ft(d),f=u.includes("text"),x=u.includes("image");f&&x?l.textImage.push(d):f?l.text.push(d):x?l.image.push(d):l.physical.push(d)}const p=["text","image","textImage","physical"].filter(d=>l[d].length>0).map(d=>({key:d,items:l[d]})),a=[...r.entries()].map(([d,u])=>{var f,x;return{key:d,label:((f=n==null?void 0:n[d])==null?void 0:f.label)||d,description:(x=n==null?void 0:n[d])==null?void 0:x.description,items:u}});return{buckets:p,mirrors:a,total:i.length}}function fn(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=dn(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 zr(e,n){if(fn(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 Cr(e,n){var l,c;const i=e.resources||[],r=[],s=[];for(const p of i){const a=ft(p);a.includes("image")&&r.push(p),a.includes("physical")&&s.push(p)}return{id:e.id,name:e.edition||e.title||e.id,era:Gt(e),year:xn(e),sortYear:ln(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:Oa(e.id,n),group:(c=n==null?void 0:n.node_groups)==null?void 0:c[e.id],hasImage:r.length>0}}function Oa(e,n){var p,a;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(p=n.collections)==null?void 0:p[i];if(((r==null?void 0:r.book_ids)??(i==="core"?n.core_books??[]:[])).includes(e))return!0;const l=(r==null?void 0:r.groups)??[],c=(a=n.node_groups)==null?void 0:a[e];return!!c&&l.includes(c)}function Ir(e,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(a=>!r.has(a.id)).map(a=>Cr(a,n));let l=s;i.era&&(l=l.filter(a=>a.era.era===i.era)),i.scanOnly&&(l=l.filter(a=>a.hasImage)),i.sort==="year"?l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=a.r.sortYear,f=d.r.sortYear;return u!=null&&f!=null?u-f||a.i-d.i:u!=null?-1:f!=null?1:a.i-d.i}).map(a=>a.r):l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=f=>(f.important?0:1)*2+(f.hasImage?0:1);return u(a.r)-u(d.r)||a.i-d.i}).map(a=>a.r);const p=[...new Set(s.map(a=>a.era.era).filter(Boolean))].sort((a,d)=>Bn(a)-Bn(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(a=>a.era.source==="edition")}}function Da(e,n){var h,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.length>0||s.length>0,c=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&c.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...c]),d=y=>{if(a.has(y))return!0;const k=n.node_groups[y];return k!=null&&p.has(k)},u=[],f=new Map,x=[];for(const y of e)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))u.push(y);else{const k=n.node_groups[y];k?(f.has(k)||f.set(k,[]),f.get(k).push(y)):x.push(y)}if(x.length+[...f.values()].reduce((y,k)=>y+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(y=>[y.id,y])),w=[...f.entries()].map(([y,k])=>{const _=b.get(y);return{id:y,label:(_==null?void 0:_.label)??y,description:_==null?void 0:_.description,ids:k}});return x.length>0&&w.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:w}}const Tr=["撰","編","注","校","譯","繪","其他"],Ha=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function si(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of Ha)if(r.test(n))return i;return"其他"}function li(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Rr(e){const n=new Map;for(const r of e){const s=si(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:e.length}];for(const r of Tr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function Er(e,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(c=>({id:c.work_id||c.book_id||void 0,title:c.title,section:c.section,volumes:c.volumes||[],subItems:c.sub_items,edition:c.edition,found:c.found_volumes,expected:c.expected_volumes})),l=[...new Set(s.map(c=>c.section).filter(Boolean))];return{rows:s,source:"catalog",sections:l,totalVolumes:n.total_volumes}}return e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(l=>({id:l.id,title:l.title,volumes:Pt(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,c;return{id:s,title:((l=i==null?void 0:i.get(s))==null?void 0:l.title)||s,edition:(c=i==null?void 0:i.get(s))==null?void 0:c.edition,volumes:[]}}),source:"books",sections:[]}}function Pt(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(n=>typeof n=="number");if(typeof e=="string"){const n=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[i,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-i+1)},(s,l)=>i+l)}return e.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function gn(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((l,c)=>l-c),r=i[0],s=i[i.length-1];return s-r+1===i.length?`${r}–${s}`:i.length<=3?i.join(", "):`${r}–${s} (${i.length}${n})`}const Ga=["〇","一","二","三","四","五","六","七","八","九"],uo=["","十","百","千"];function Nr(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const c=parseInt(n[l]),p=i-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=uo[p]:r+=Ga[c]+uo[p])}return r}function Ua(e){return e==null?"":typeof e=="string"?e:e.title??""}function ot(e,n="卷"){var r,s;const i=e;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?Nr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Lr(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 Va="guji_markdown";function An(e){const n=e==null?void 0:e.guji_markdown;if(typeof n!="string")return!1;const i=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!i)return!1;const r=parseInt(i[1],10),s=parseInt(i[2],10);return r>0||s>=2}const Ya=/^□\{guess=([^\s{}]+)\}/;function Ka(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function Br(e,n){let i=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
|
|
11
|
+
}`,yr={color:"inherit",textDecoration:"none"},Ql=({snippet:e})=>{const{convert:n}=V();return t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),lineHeight:1.6},children:pr(e).map((i,r)=>i.marked?t.jsx("mark",{style:{background:o("highlight-bg"),color:o("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(i.text)},r):t.jsx(g.Fragment,{children:n(i.text)},r))})},ea=({entry:e,selected:n,onClick:i,getConfig:r,query:s})=>{const l=ce(),{convert:c}=V(),p=c(e.title||e.primary_name||e.id),a=e.measure_info?c(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",d=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&d.length?d.find(m=>{const b=typeof m=="string"?m:m==null?void 0:m.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,f=o("cover-accent"),x=Ae();return t.jsxs("a",{href:x(e.id),onClick:m=>i(e,m),className:"bim-result-card",style:{...yr,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:o("bg"),border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[t.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${f} 50%, ${o("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${f} 14%, ${o("bg")}), color-mix(in srgb, ${f} 7%, ${o("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[t.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${f} 45%, transparent)`}}),t.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:f},children:Array.from(p).map((m,b)=>t.jsx("span",{children:m},b))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:o("fg")},children:p}),a&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:a})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",c(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:c(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",c(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",c(e.era),"〕"]}),e.edition&&t.jsx("span",{children:c(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg")},children:[l.search.alias,":",c(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(Ql,{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]})]})]})]})},so=({entry:e,selected:n,onClick:i,getConfig:r,query:s,onRemove:l})=>{const c=ce(),{convert:p}=V(),a=[...e.additional_titles||[],...e.attached_texts||[]],d=s&&a.length?a.find(f=>{const x=typeof f=="string"?f:f==null?void 0:f.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,u=Ae();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${o("primary")}`:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("a",{href:u(e.id),onClick:f=>i(e,f),className:"bim-result-card",style:{...yr,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx("span",{style:{fontSize:"16px"},children:r(e.type).icon}),t.jsx("span",{style:{fontSize:"9px",color:o("desc-fg"),lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:p(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{title:c.misc.textResource,children:"📝"}),e.has_image&&t.jsx("span",{title:c.misc.imageResource,children:"🖼️"})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",p(e.era),"〕"]}),e.edition&&p(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:p(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[e.juan_count,c.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",p(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:p(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",p(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),d&&t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginTop:"2px"},children:[c.search.alias,":",p(d)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:c.search.removeFromRecent,"aria-label":c.search.removeFromRecent,style:{border:"none",background:"transparent",color:o("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},ta=({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 na(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 ia({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 oa({alt_names:e}){const{convert:n}=V(),i=new Map;for(const l of e){const c=l.type||"別名";i.has(c)||i.set(c,[]),i.get(c).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((l,c)=>{const p=r.indexOf(l),a=r.indexOf(c);return p===-1&&a===-1?0:p===-1?1:a===-1?-1:p-a});return t.jsx("div",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const c=i.get(l);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:o("desc-fg"),fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),t.jsx("span",{children:c.map((p,a)=>t.jsxs("span",{children:[a>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},a))})]},l)})})}function ra({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 sa({works:e,transport:n,onNavigate:i,renderLink:r}){const s=ce(),{convert:l}=V(),c=Ae(),[p,a]=g.useState(new Map);g.useEffect(()=>{if(!n)return;let x=!1;const m=e.map(w=>w.work_id);return(async()=>{const w=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(m);let _=!0;for(let v=0;v<m.length;v++){const $=k[v];$!=null&&$.title?w.set(m[v],$.title):$!=null&&$.primary_name?w.set(m[v],$.primary_name):_=!1}if(_)return w}catch{}const h=[...m],j=8,y=new Array(j).fill(0).map(async()=>{for(;h.length;){const k=h.shift();if(!k)break;if(!w.has(k))try{if(n.getEntry){const $=await n.getEntry(k);if($!=null&&$.title){w.set(k,$.title);continue}}const _=await n.getItem(k),v=_&&(_.title||_.primary_name)||k;w.set(k,v)}catch{w.set(k,k)}}});return await Promise.all(y),w})().then(w=>{x||a(w)}),()=>{x=!0}},[e,n]);const d=new Map;for(const x of e){const m=x.role||"";d.has(m)||d.set(m,[]),d.get(m).push(x)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],f=[...d.keys()].sort((x,m)=>{const b=u.indexOf(x),w=u.indexOf(m);return b===-1&&w===-1?x.localeCompare(m):b===-1?1:w===-1?-1:b-w});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:o("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:o("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),f.map(x=>{const m=d.get(x);return t.jsxs("div",{style:{marginBottom:"8px"},children:[x&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"2px"},children:[l(x)," ",t.jsxs("span",{style:{color:o("desc-fg")},children:["(",m.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:x?"16px":"0",listStyle:x?"disc":"none",fontSize:"14px",lineHeight:1.8},children:m.map((b,w)=>{const h=l(p.get(b.work_id)||b.work_id);return r?t.jsx("li",{children:r(b.work_id,h)},w):i?t.jsx("li",{children:t.jsx("a",{href:c(b.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),i(b.work_id))},style:{color:o("link-fg"),textDecoration:"underline",cursor:"pointer"},children:h})},w):t.jsx("li",{children:h},w)})})]},x)})]})}const jr=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:l})=>{var f;const c=ce(),{convert:p}=V();let a=!1;try{a=ve.extractStatus(e.id)==="draft"}catch{}const d=na(e),u=e.subtype==="people"?"人物":e.subtype==="place"?"地名":e.subtype==="dynasty"?"朝代":e.subtype==="anonymous"?"佚名":e.subtype==="collective"?"集体":e.subtype;return t.jsxs("div",{children:[!l&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:o("fg")},children:[p(e.primary_name),t.jsx(ia,{data:e})]}),s]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o("type-entity"),border:`1px solid color-mix(in srgb, ${o("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${o("type-entity")} 3%, transparent)`},children:c.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),a&&t.jsx("span",{style:{padding:"1px 6px",background:o("warn-bg"),border:`1px solid ${o("warn-border")}`,borderRadius:"2px",color:o("warn-fg")},children:c.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),d&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:o("widget-bg"),border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(oa,{alt_names:e.alt_names}),t.jsx(ra,{data:e}),((f=e.description)==null?void 0:f.text)&&t.jsx("p",{style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(e.description.text)}),e.works&&e.works.length>0&&t.jsx(sa,{works:e.works,transport:n,onNavigate:i,renderLink:r})]})},la=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function aa(e){const n=e.search(la);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const vr={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>{let i=e,r="",s=n;if(e&&typeof n=="string"&&(n===e||n===ca(e))){const[l,c]=aa(n);c&&(i=encodeURI(l),s=l,r=c)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:i,target:i!=null&&i.startsWith("http")?"_blank":void 0,rel:i!=null&&i.startsWith("http")?"noopener noreferrer":void 0,style:{color:o("link")},children:s}),r]})},code:({children:e})=>t.jsx("code",{style:{background:o("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function ca(e){try{return decodeURI(e)}catch{return e}}const da={...vr,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},rt=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:s}=V(),l=n?da:vr;return t.jsx("div",{className:r,style:i,children:t.jsx(fl,{remarkPlugins:[gl],components:l,children:s(e)})})},pa=["〇","一","二","三","四","五","六","七","八","九"],lo=["","十","百","千"];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 c=parseInt(n[l]),p=i-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=lo[p]:r+=pa[c]+lo[p])}return r}function Sr(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 ua={book:o("type-book"),work:o("type-work"),collection:o("type-collection"),entity:o("type-entity")};function xa({type:e}){const n=ce();return t.jsx("span",{style:Sr(ua[e]),children:n.indexType[e]})}function fa({isDraft:e}){const n=ce(),i=o(e?"status-draft":"status-official");return t.jsx("span",{style:Sr(i),children:e?n.status.draft:n.status.official})}function ga({id:e}){const n=ce(),[i,r]=g.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:o("desc-fg"),background:o("bg-subtle"),border:`1px solid ${o("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:o("fg")},children:e}),t.jsx("span",{onClick:s,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function Ue({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 Xe({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 wr({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,c)=>{const p=s(l.name),a=l.entity_id?t.jsx(Ye,{id:l.entity_id,label:p,onNavigate:i,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:p});return t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:o("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),a,l.role&&t.jsxs("span",{style:{color:o("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},c)})})}function Ye({id:e,label:n,onNavigate:i,renderLink:r}){const s=Ae();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 ma({id:e,title:n,edition:i,type:r,isDraft:s,authors:l,volumeText:c,meta:p,headerExtra:a,onNavigate:d,renderLink:u}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:o("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:i}),c&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:c})]}),a&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(xa,{type:r}),t.jsx(fa,{isDraft:s}),t.jsx(ga,{id:e})]}),((l==null?void 0:l.length)||p.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(wr,{authors:l,type:r,onNavigate:d,renderLink:u}),p]})]})}function _r({items:e,label:n,showMeta:i,onNavigate:r,renderLink:s}){const l=ce(),{convert:c}=V();if(!e.length)return null;const[p,a]=g.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(Ue,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((d,u)=>{const f=p===u;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...f?{boxShadow:o("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>a(f?null:u),style:{padding:"8px 12px",background:o("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.15s",transform:f?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:o("fg")},children:c(d.source)}),!f&&i&&d.title_info&&t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c(d.title_info)}),d.source_bid&&t.jsx("span",{onClick:x=>x.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Ye,{id:d.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),f&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${o("widget-border")}`},children:[i&&(d.title_info||d.author_info||d.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&t.jsx(Xe,{label:l.label.titleInfo,children:c(d.title_info)}),d.author_info&&t.jsx(Xe,{label:l.label.authorInfo,children:c(d.author_info)}),d.edition&&t.jsx(Xe,{label:l.label.edition,children:c(d.edition)})]}),d.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:c(d.summary)})]}),d.comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(d.comment)})]}),d.additional_comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(d.additional_comment)})]})]})]},u)})})]})}function ha({items:e,onNavigate:n,renderLink:i}){const r=ce();return t.jsx(_r,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function $r({items:e,onNavigate:n,renderLink:i}){const r=ce();return t.jsx(_r,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function zr({label:e,items:n}){const{convert:i}=V();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(Ue,{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 ba({items:e}){const n=ce();return t.jsx(zr,{label:n.section.aliases,items:e})}function ya({items:e}){const n=ce();return t.jsx(zr,{label:n.section.attachedTexts,items:e})}function ja({items:e}){const n=ce(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ue,{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 va({items:e}){const n=ce(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ue,{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 ka({items:e}){const n=ce(),{convert:i}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(Ue,{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 ao({title:e,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:l}=V(),[c,p]=g.useState([]);return g.useEffect(()=>{if(!n.length){p([]);return}if(!i){p(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>i.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{a||p(d)}),()=>{a=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(Ue,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",n.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(c.length?c:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${l(a.title)||a.id}(${l(a.edition)})`:l(a.title)||void 0;return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),transition:"border-color 0.15s"},children:t.jsx(Ye,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function $n({book:e,onNavigate:n,renderLink:i}){const r=ce(),{convert:s}=V(),[l,c]=g.useState(!1),p=e.resources&&e.resources.length>0,a=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:o("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(Ye,{id:e.id,label:a,onNavigate:n,renderLink:i})}),p&&t.jsx("span",{onClick:()=>c(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:o("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),p&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(ri,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Sa({ids:e,workData:n,transport:i,onNavigate:r,renderLink:s,footer:l}){const c=ce(),{convert:p}=V(),[a,d]=g.useState([]);if(g.useEffect(()=>{if(!e.length){d([]);return}if(!i){d(e.map(w=>({id:w})));return}let b=!1;return Promise.all(e.map(w=>i.getItem(w).then(h=>({id:w,title:h?h.title:void 0,edition:h?h.edition:void 0,resources:h?h.resources:void 0,resource_groups:h?h.resource_groups:void 0})).catch(()=>({id:w})))).then(w=>{b||d(w)}),()=>{b=!0}},[e,i]),!e.length)return null;const u=a.length?a:e.map(b=>({id:b})),f=new Map(u.map(b=>[b.id,b])),x=n==null?void 0:n.version_graph,m=wa(e,x);return t.jsxs(t.Fragment,{children:[t.jsxs(Ue,{children:[c.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,m.useGrouping?t.jsxs(t.Fragment,{children:[m.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:m.coreIds.map(b=>{const w=f.get(b);return w?t.jsx($n,{book:w,onNavigate:r,renderLink:s},b):null})}),m.groupedIds.map(b=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${o("widget-border")}`,borderRadius:6,background:o("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:o("fg"),userSelect:"none"},children:[p(b.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:o("desc-fg"),fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:o("desc-fg"),fontWeight:400},children:p(b.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(w=>{const h=f.get(w);return h?t.jsx($n,{book:h,onNavigate:r,renderLink:s},w):null})})]},b.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(b=>t.jsx($n,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function wa(e,n){var h,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.length>0||s.length>0,c=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&c.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...c]),d=y=>{if(a.has(y))return!0;const k=n.node_groups[y];return k!=null&&p.has(k)},u=[],f=new Map,x=[];for(const y of e)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))u.push(y);else{const k=n.node_groups[y];k?(f.has(k)||f.set(k,[]),f.get(k).push(y)):x.push(y)}if(x.length+[...f.values()].reduce((y,k)=>y+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(y=>[y.id,y])),w=[...f.entries()].map(([y,k])=>{const _=b.get(y);return{id:y,label:(_==null?void 0:_.label)??y,description:_==null?void 0:_.description,ids:k}});return x.length>0&&w.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:w}}function _a({workData:e,onNavigate:n,renderLink:i}){var c,p,a,d;const r=ce(),{convert:s}=V(),l=!!((c=e.description)!=null&&c.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:o("input-bg"),marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?`1px solid ${o("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`},children:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:t.jsx(Ye,{id:e.id,label:s(e.title),onNavigate:n,renderLink:i})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:s(e.measure_info)}):((p=e.juan_count)==null?void 0:p.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[kr(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(wr,{authors:e.authors,type:"work",onNavigate:n,renderLink:i})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((a=e.description)==null?void 0:a.text)&&t.jsx(rt,{text:e.description.text,style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(d=e.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:t.jsx(Xe,{label:r.label.parentWork,children:t.jsx(Ye,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function $a({items:e,onNavigate:n,renderLink:i}){const r=ce(),{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(Ye,{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:Ut(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const si=({data:e,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:c,className:p,style:a})=>{var F,W,B,M,U,G,E,oe;const d=ce(),{convert:u}=V(),[f,x]=g.useState(null),[m,b]=g.useState(!1),[w,h]=g.useState(null),[j,y]=g.useState(null),[k,_]=g.useState([]),v=e||f;if(g.useEffect(()=>{if(e||!n||!i)return;let P=!1;return b(!0),h(null),i.getItem(n).then(le=>{P||(le?x(le):h(d.misc.notFoundEntry))}).catch(le=>{P||h(le instanceof Error?le.message:d.misc.loadFailed)}).finally(()=>{P||b(!1)}),()=>{P=!0}},[e,n,i]),g.useEffect(()=>{if(!v||!i){y(null),_([]);return}let P=!1;const le=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(le?i.getItem(le).then(ge=>{!P&&ge&&ge.type==="work"&&y(ge)}).catch(()=>{}):y(null),v.type==="book"){const ge=v;ge.contained_in&&ge.contained_in.length>0?Promise.all(ge.contained_in.map(Q=>{const O=typeof Q=="string"?Q:Q.id,q=typeof Q=="string"?void 0:Q.volume_index;return i.getItem(O).then(de=>({id:O,title:de&&de.title||O,volume_index:q})).catch(()=>({id:O,title:O,volume_index:q}))})).then(Q=>{P||_(Q)}):_([])}else _([]);return()=>{P=!0}},[v,i]),m)return t.jsx("div",{className:p,style:{...a,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((P,le)=>t.jsx("div",{style:{height:le===1?"32px":"16px",width:`${P}px`,background:o("widget-border"),borderRadius:"4px",opacity:.4}},le))})});if(w)return t.jsx("div",{className:p,style:{...a,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:w});if(!v)return null;if(v.type==="entity")return t.jsx("div",{className:p,style:a,children:t.jsx(jr,{data:v,transport:i,onNavigate:r,renderLink:s,headerExtra:l})});const $=v.type==="book"?v:null,S=v.type==="collection"?v:null,z=v.type==="work"?v:null;let I=!1;try{I=ve.extractStatus(v.id)==="draft"}catch{}let R="";v.measure_info?R=u(v.measure_info):(F=v.juan_count)!=null&&F.number?R=kr(v.juan_count.number)+d.unit.juan:(W=v.juan_count)!=null&&W.description&&(R=u(v.juan_count.description));const C=[];return(B=v.publication_info)!=null&&B.year&&C.push(t.jsx(Xe,{label:d.label.year,children:v.publication_info.year},"year")),(M=v.current_location)!=null&&M.name&&C.push(t.jsx(Xe,{label:d.label.currentLocation,children:u(v.current_location.name)},"loc")),(U=v.page_count)!=null&&U.description&&C.push(t.jsx(Xe,{label:d.label.pageCount,children:v.page_count.description},"page")),$!=null&&$.edition&&C.push(t.jsx(Xe,{label:d.label.edition,children:u($.edition)},"ver")),z!=null&&z.parent_work&&C.push(t.jsx(Xe,{label:d.label.parentWork,children:t.jsx(Ye,{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(Xe,{label:d.label.parentWork,children:z.parent_works.map((P,le)=>t.jsxs("span",{children:[le>0&&"、",t.jsx(Ye,{id:P,onNavigate:r,renderLink:s})]},P))},"pws")),t.jsxs("div",{className:p,style:a,children:[t.jsx(ma,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:I,authors:v.authors,volumeText:R,meta:C,headerExtra:l,onNavigate:r,renderLink:s}),((G=v.description)==null?void 0:G.text)&&t.jsx(rt,{text:v.description.text,style:{fontSize:"14px",color:o("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((P,le)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:o("bg-subtle"),borderRadius:4,border:`1px solid ${o("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:o("muted")},children:u(P.title)}),t.jsx(rt,{text:P.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:o("fg")}})]},le))}),k.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{children:d.section.containedIn}),t.jsx($a,{items:k,onNavigate:r,renderLink:s})]}),j&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{children:d.section.belongsToWork}),t.jsx(_a,{workData:j,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&t.jsx(ja,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&t.jsx(ba,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&t.jsx(ya,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&t.jsx(ha,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&t.jsx($r,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{children:d.section.resources}),t.jsx(ri,{items:v.resources,resourceGroups:v.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),($==null?void 0:$.location_history)&&$.location_history.length>0&&t.jsx(va,{items:$.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&t.jsx(ka,{items:S.history}),($==null?void 0:$.related_books)&&$.related_books.length>0&&t.jsx(ao,{title:d.section.relatedVersions,ids:$.related_books,transport:i,onNavigate:r,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&t.jsx(ao,{title:d.section.containedBooks,ids:S.books,transport:i,onNavigate:r,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(Ue,{children:[d.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",S.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(P=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg")},children:t.jsx(Ye,{id:P.id,label:u(P.title),onNavigate:r,renderLink:s})},P.id))})]}),(((E=z==null?void 0:z.books)==null?void 0:E.length)||0)+(((oe=z==null?void 0:z.collections)==null?void 0:oe.length)||0)>0&&t.jsx(Sa,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z??void 0,transport:i,onNavigate:r,renderLink:s,footer:c}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const P=[],le=z.related_works.filter(se=>se.relation==="part_of"),ge=z.related_works.filter(se=>se.relation==="has_part"),Q=z.related_works.filter(se=>se.relation==="has_adaptation"),O=z.related_works.filter(se=>se.relation==="text_carried_by"),q=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),de=z.related_works.filter(se=>!se.relation||!q.has(se.relation));return le.length>0&&P.push({label:d.section.belongsToWork,items:le}),ge.length>0&&P.push({label:d.section.containedWorks,items:ge}),Q.length>0&&P.push({label:d.section.adaptations,items:Q}),O.length>0&&P.push({label:d.section.derivativeWorks,items:O}),de.length>0&&P.push({label:d.section.relatedWorks,items:de}),P.map(se=>t.jsxs("div",{children:[t.jsxs(Ue,{children:[se.label,t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400},children:["(",se.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:se.items.map(te=>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(Ye,{id:te.id,label:u(te.title),onNavigate:r,renderLink:s})},te.id))})]},se.label))})()]})};function za({data:e}){const n=ce(),{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 Ca({sections:e,activeSection:n,onSelect:i}){const r=ce();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:co(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:co(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 co(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 Ia({id:e,label:n,onNavigate:i,renderLink:r}){const s=Ae();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i(e))},style:{color:o("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg")},children:n||e})}function Ta(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=e[0],r=e[e.length-1];return r-i+1===e.length?`${i}–${r}`:e.length<=3?e.join(", "):`${i}–${r} (${e.length}${n})`}function po({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const s=ce(),{convert:l}=V(),c=e.book_id||e.work_id,p=r&&e.volumes.length>0?Ta(e.volumes,s.unit.volume):null,a=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${o("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:o("desc-fg"),textAlign:"right"},children:p}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:o("fg")},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(d=>l(d)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:o(a?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),c&&t.jsx(Ia,{id:c,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!c&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const li=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:l,style:c})=>{const p=ce(),[a,d]=g.useState(null),[u,f]=g.useState(!1),[x,m]=g.useState(null),[b,w]=g.useState(null),[h,j]=g.useState(""),y=e||a;g.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let S=!1;return f(!0),m(null),i.getCollectionCatalog(n).then(z=>{S||(z?d(z):m(p.catalog.notFound))}).catch(z=>{S||m(z instanceof Error?z.message:p.catalog.loadFailed)}).finally(()=>{S||f(!1)}),()=>{S=!0}},[e,n,i,p]);const k=(y==null?void 0:y.sections)&&y.sections.length>0,_=g.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const S=y.books.map(I=>I.volumes[0]).filter(I=>I!=null);return new Set(S).size<S.length},[y]),v=g.useMemo(()=>{if(!y)return[];let S=y.books;if(b&&(S=S.filter(z=>z.section===b)),h.trim()){const z=h.trim().toLowerCase();S=S.filter(I=>I.title.toLowerCase().includes(z)||I.sub_items&&I.sub_items.some(R=>R.toLowerCase().includes(z))||I.edition&&I.edition.toLowerCase().includes(z))}return S},[y,b,h]),$=g.useMemo(()=>{if(!_)return null;const S=[],z=new Map;for(const R of v){if(!R.volumes||R.volumes.length===0)continue;const C=R.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(R)}const I=[...z.keys()].sort((R,C)=>R-C);for(const R of I)S.push({volume:R,books:z.get(R)});return S},[v,_]);return u?t.jsx("div",{className:l,style:{...c,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):x?t.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:x}):y?t.jsxs("div",{className:l,style:c,children:[t.jsx(za,{data:y}),k&&t.jsx(Ca,{sections:y.sections,activeSection:b,onSelect:w}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:h,onChange:S=>j(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:o("desc-fg")},children:[v.length," ",p.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[$?$.map((S,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:Ut(p.catalog.volume,{n:S.volume})}),S.books.map((I,R)=>t.jsx(po,{book:I,onNavigate:r,renderLink:s,showVolumes:I.volumes.length>1},`${S.volume}-${R}`))]},`${S.volume}-${z}`)):v.map((S,z)=>t.jsx(po,{book:S,onNavigate:r,renderLink:s,showVolumes:!0},z)),v.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},bt=()=>{const[e,n]=g.useState(1);return g.useEffect(()=>{const i=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(i)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:o("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(e)})},Cr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Ra={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Ne(e){return Ra[e]??e}const $t=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],zt={熹平: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},Ir={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function hn(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 Ea(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 Na=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,uo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function ai(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(uo))if(n.startsWith(s))return uo[s];const i=Ne(n);if(xt[i]!=null)return i;const r=ot(n);if(r&&n.length<=r.length+1)return Ne(r)}function ut(e,n){if(n){const i=Ir[`${n}|${e}`];if(i!=null)return i}return zt[e]}const La=1911;function Ba(e){const n=zt[e];if(n==null)return;const i=Qe[e];let r;for(const[s,l]of Object.entries(zt))Qe[s]===i&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const Aa={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function pn(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,i=0,r=!1;for(const l of e){const c=Aa[l];if(c===void 0)return;r=!0,l==="十"?i=(i||1)*10:l==="廿"||l==="卅"?(n+=c,i=0):i>=10?(n+=i+c,i=0):i=i*10+c}const s=n+i;return r&&s>0?s:void 0}function ot(e){for(const n of Cr)if(e.startsWith(n))return n}const Qe={};{const e=(n,i)=>{for(const r of i)Qe[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function ft(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(zt))if(e.includes(r)&&!(i&&Qe[r]&&Qe[r]!==i&&Ir[`${i}|${r}`]==null))return r}function Vt(e){var c,p,a;const n={era:"",reign:"",source:"none"},i=e.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const d=ot(r)??"";return{era:Ne(d),reign:ft(r,d)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const d=hn(s);if(d)return{era:Ea(d.from),reign:"",source:"publication"};const u=ot(s)??ai(s)??((a=$t.find(m=>m.pattern.test(s)))==null?void 0:a.era)??"",f=ft(s,u)??"",x=u||(f?Qe[f]??"":"");if(x||f)return{era:Ne(x),reign:f,source:"publication"}}const l=e.edition||e.title||"";if(l){const d=ot(l);if(d)return{era:Ne(d),reign:ft(l,d)??"",source:"edition"};const u=$t.find(f=>f.pattern.test(l));if(u)return{era:Ne(u.era),reign:ft(l,u.era)??u.reign??"",source:"edition"}}return n}function bn(e){var r,s,l,c,p,a,d,u,f;if(((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;if(typeof((s=e.lineage)==null?void 0:s.year)=="number")return e.lineage.year;const n=(l=e.publication_info)==null?void 0:l.year;if(n){const x=hn(n);if(x)return x.from}const i=[(c=e.lineage)==null?void 0:c.year_text,(p=e.publication_info)==null?void 0:p.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const x of i){const m=((a=e.publication_info)==null?void 0:a.year)||((d=e.lineage)==null?void 0:d.year_text);if(m&&x!==m&&(ot(m)||ai(m)))break;const b=x.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??x.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const k=parseInt(b[1],10);if(k>=100&&k<=2100)return k}const w=x.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(w){const k=ot(x);if(!k||Ne(k)==="民國"){const v=pn(w[1]);if(v!=null&&v>=1&&v<=120)return La+v}}const h=ot(x)??((u=$t.find(k=>k.pattern.test(x)))==null?void 0:u.era),j=h?Ne(h):void 0,y=ft(x,j)??(ot(x)||(f=$t.find(k=>k.pattern.test(x)))==null?void 0:f.reign);if(y){const k=ut(y,j);if(k==null)continue;const _=x.indexOf(y),v=_>=0?x.slice(_+y.length):"",$=v.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??v.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=$?pn($[1]):void 0;return k+(S?S-1:0)}}}function ci(e){var c,p,a,d,u,f;const n=(c=e.dating)==null?void 0:c.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(p=e.lineage)==null?void 0:p.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(a=e.lineage)==null?void 0:a.year_text;if(r){const x=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(x){const m=Fn[Ne(x[1])],b=xt[Ne(x[2])];if(m!=null&&b!=null)return{from:Math.min(m,b)-20,to:Math.max(m,b)+40}}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const x=hn(s);if((x==null?void 0:x.to)!=null)return{from:x.from,to:x.to};const m=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(m){const b=Fn[Ne(m[1])],w=xt[Ne(m[2])];if(b!=null&&w!=null)return{from:Math.min(b,w)-20,to:Math.max(b,w)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const x of l){if(!/[間间]/.test(x))continue;const m=ot(x)??ai(x)??((f=$t.find(h=>h.pattern.test(x)))==null?void 0:f.era),b=m?Ne(m):void 0,w=[];for(const h of Object.keys(zt))x.includes(h)&&(b&&Qe[h]&&Qe[h]!==b||ut(h,b)!=null&&w.push(h));if(w.length===0){const h=x.match(/([一-鿿])([一-鿿])[間间]/);if(h&&b){for(const j of[h[1],h[2]])for(const y of Object.keys(zt))if(Qe[y]===b&&!(y[0]!==j&&y[y.length-1]!==j)&&ut(y,b)!=null){w.push(y);break}}}if(w.length>0){const h=w.map(_=>ut(_,b)).filter(_=>_!=null),j=Math.min(...h),y=w.reduce((_,v)=>ut(_,b)>=ut(v,b)?_:v),k=Ba(y)??zn(b??"")??Math.max(...h);return{from:j,to:k>j?k:zn(b??Qe[y]??"")??j}}if(b&&xt[b]!=null)return{from:xt[b],to:zn(b)??xt[b]}}}const xt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Wa=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Ma=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,xo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function fo(e,n){for(const i of Cr){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const a=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(a)&&!ft(e.slice(r),Ne(i)))continue}const s=Ne(i);if(s===n)continue;const l=e.slice(r),c=ft(l,s)??"";let p;if(c){const a=ut(c,s);if(a!=null){const u=l.slice(l.indexOf(c)+c.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),f=u?pn(u[1]):void 0;p=a+(f?f-1:0)}}return{era:s,reign:c,year:p}}for(const i of $t)if(i.pattern.test(e))return{era:Ne(i.era),reign:i.reign??""}}function Fa(e){var j,y,k,_,v;const n=Vt(e),i=((j=e.publication_info)==null?void 0:j.year)??"",r=i?hn(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),c=((y=e.lineage)==null?void 0:y.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(c),a=n.source==="publication"&&Na.test(i),d=n.source==="publication"&&/[間间]/.test(i),u=c.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let f;l||p||a||d?f=void 0:u?f=parseInt(u[2],10):f=bn(e);const x=f==null?ci(e):void 0;let m;n.source==="publication"&&(a||xo.test(i))?m="uncertain":n.source==="lineage"||n.source==="publication"?m="attested":xo.test(s)||!n.reign&&f==null?m="uncertain":m="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((k=e.lineage)==null?void 0:k.year_text)??((_=e.lineage)==null?void 0:_.year)??""}」`:`出版著錄「${((v=e.publication_info)==null?void 0:v.year)??""}」`,w={era:n.era,reign:n.reign,year:f,yearRange:x,certainty:m,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const $=c.match(/[、,,]\s*([宋元明清])/);$&&$[1]!==w.era&&(w.laterRepair={era:$[1]})}if(!w.laterRepair&&Ma.test(s)){const $=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);$&&$[1]!==n.era&&(w.laterRepair={era:$[1]})}const h=Wa.find($=>$.re.test(s));if(h){const $=s.search(h.re),S=s.slice($),z=fo(S,n.era)??fo(s,n.era);z&&(w.basedOn={era:z.era,reign:z.reign,year:z.year,relation:h.relation})}return w}const Fn={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function zn(e){return Fn[e]}function un(e){const n=bn(e);if(n!=null)return n;const i=ci(e);if(i)return i.from;const r=Vt(e).era;return r?xt[r]:void 0}const go=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Pn(e){const n=go.indexOf(e);return n===-1?go.length:n}function Pa(e){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of e){const l=s.relation;l==="part_of"?n.belongsTo.push(s):l==="collected_in"?n.collected.push(s):l==="has_part"||l==="contains_text_of"?n.contains.push(s):l==="text_carried_by"||l==="studied_by"||l==="derived_from"||l==="followed_by"||l==="has_adaptation"?n.derivative.push(s):l==="studies"||l==="preceded_by"?n.studies.push(s):n.related.push(s)}const i=[],r=(s,l)=>{n[s].length&&i.push({key:s,labelKey:l,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),i}function di(e,n){const i=ni(e||[]),r=new Map,s=[];for(const d of i)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((u,f)=>{const x=m=>m.group_role==="origin"?0:m.group_role==="mirror"?1:2;return x(u)-x(f)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=ht(d),f=u.includes("text"),x=u.includes("image");f&&x?l.textImage.push(d):f?l.text.push(d):x?l.image.push(d):l.physical.push(d)}const p=["text","image","textImage","physical"].filter(d=>l[d].length>0).map(d=>({key:d,items:l[d]})),a=[...r.entries()].map(([d,u])=>{var f,x;return{key:d,label:((f=n==null?void 0:n[d])==null?void 0:f.label)||d,description:(x=n==null?void 0:n[d])==null?void 0:x.description,items:u}});return{buckets:p,mirrors:a,total:i.length}}function yn(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=gn(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 Tr(e,n){if(yn(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 Rr(e,n){var l,c;const i=e.resources||[],r=[],s=[];for(const p of i){const a=ht(p);a.includes("image")&&r.push(p),a.includes("physical")&&s.push(p)}return{id:e.id,name:e.edition||e.title||e.id,era:Vt(e),year:bn(e),sortYear:un(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:Oa(e.id,n),group:(c=n==null?void 0:n.node_groups)==null?void 0:c[e.id],hasImage:r.length>0}}function Oa(e,n){var p,a;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(p=n.collections)==null?void 0:p[i];if(((r==null?void 0:r.book_ids)??(i==="core"?n.core_books??[]:[])).includes(e))return!0;const l=(r==null?void 0:r.groups)??[],c=(a=n.node_groups)==null?void 0:a[e];return!!c&&l.includes(c)}function Er(e,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(a=>!r.has(a.id)).map(a=>Rr(a,n));let l=s;i.era&&(l=l.filter(a=>a.era.era===i.era)),i.scanOnly&&(l=l.filter(a=>a.hasImage)),i.sort==="year"?l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=a.r.sortYear,f=d.r.sortYear;return u!=null&&f!=null?u-f||a.i-d.i:u!=null?-1:f!=null?1:a.i-d.i}).map(a=>a.r):l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=f=>(f.important?0:1)*2+(f.hasImage?0:1);return u(a.r)-u(d.r)||a.i-d.i}).map(a=>a.r);const p=[...new Set(s.map(a=>a.era.era).filter(Boolean))].sort((a,d)=>Pn(a)-Pn(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(a=>a.era.source==="edition")}}function Da(e,n){var h,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],l=r.length>0||s.length>0,c=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&c.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...c]),d=y=>{if(a.has(y))return!0;const k=n.node_groups[y];return k!=null&&p.has(k)},u=[],f=new Map,x=[];for(const y of e)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))u.push(y);else{const k=n.node_groups[y];k?(f.has(k)||f.set(k,[]),f.get(k).push(y)):x.push(y)}if(x.length+[...f.values()].reduce((y,k)=>y+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(y=>[y.id,y])),w=[...f.entries()].map(([y,k])=>{const _=b.get(y);return{id:y,label:(_==null?void 0:_.label)??y,description:_==null?void 0:_.description,ids:k}});return x.length>0&&w.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:w}}const Nr=["撰","編","注","校","譯","繪","其他"],Ha=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function pi(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 ui(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Lr(e){const n=new Map;for(const r of e){const s=pi(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:e.length}];for(const r of Nr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function Br(e,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(c=>({id:c.work_id||c.book_id||void 0,title:c.title,section:c.section,volumes:c.volumes||[],subItems:c.sub_items,edition:c.edition,found:c.found_volumes,expected:c.expected_volumes})),l=[...new Set(s.map(c=>c.section).filter(Boolean))];return{rows:s,source:"catalog",sections:l,totalVolumes:n.total_volumes}}return e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(l=>({id:l.id,title:l.title,volumes:Dt(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,c;return{id:s,title:((l=i==null?void 0:i.get(s))==null?void 0:l.title)||s,edition:(c=i==null?void 0:i.get(s))==null?void 0:c.edition,volumes:[]}}),source:"books",sections:[]}}function Dt(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 jn(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((l,c)=>l-c),r=i[0],s=i[i.length-1];return s-r+1===i.length?`${r}–${s}`:i.length<=3?i.join(", "):`${r}–${s} (${i.length}${n})`}const Ga=["〇","一","二","三","四","五","六","七","八","九"],mo=["","十","百","千"];function Ar(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",s=!1;for(let l=0;l<i;l++){const c=parseInt(n[l]),p=i-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=mo[p]:r+=Ga[c]+mo[p])}return r}function Ua(e){return e==null?"":typeof e=="string"?e:e.title??""}function st(e,n="卷"){var r,s;const i=e;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?Ar(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Wr(e){var r;if(e.edition_type)return e.edition_type;if((r=e.lineage)!=null&&r.category)return e.lineage.category;const n=e.edition||e.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,l]of i)if(s.test(n))return l;return""}const Va="guji_markdown";function On(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 Ya=/^□\{guess=([^\s{}]+)\}/;function Ka(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function Mr(e,n){let i=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
|
|
12
12
|
`)return-1;if(s==="\\"){r++;continue}if(s==="[")i++;else if(s==="]"&&(i--,i===0))return r}return-1}function qa(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function Ja(e,n){const i=e[n];if(i==="["&&e[n+1]==="["){const r=e.indexOf("]]",n+2);return r>=0&&e.slice(n+2,r).indexOf(`
|
|
13
|
-
`)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const r=
|
|
14
|
-
`)return null}const a=Ja(e,n);if(a){c(),s.push(a.node),n=a.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&Ka(e,n)&&(d=">"),d){const u=
|
|
13
|
+
`)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const r=Mr(e,n+3);return r>n+4?{node:{type:"zi",label:qa(e.slice(n+4,r))},end:r+1}:null}if(i==="□"&&e[n+1]==="{"){const r=Ya.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function Fr(e,n,i,r){const s=[];let l="";const c=()=>{if(!l)return;const p=r?l.replace(/\\?\|/g,""):l;p&&s.push({type:"text",text:p}),l=""};for(;n<e.length;){const p=e[n];if(i!==null){if(p===i)return c(),{nodes:s,end:n};if(p===`
|
|
14
|
+
`)return null}const a=Ja(e,n);if(a){c(),s.push(a.node),n=a.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&Ka(e,n)&&(d=">"),d){const u=Fr(e,n+1,d,!0);if(u){c(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return i!==null?null:(c(),{nodes:s,end:n})}function Pr(e){return Fr(e,0,null,!1).nodes}function Za(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function Or(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Or(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const Xa=216,ho="clamp(280px, 23vw, 360px)",Qa=1440,Dr="(max-width: 719px)",ec=`${Dr}, (pointer: coarse)`,tc=`
|
|
15
15
|
.bim-d-main.bim-d-main-grid { max-width: ${Qa}px; padding: 16px 32px 0; }
|
|
16
16
|
.bim-d-grid {
|
|
17
17
|
display: grid;
|
|
18
|
-
grid-template-columns: ${Xa}px minmax(0, 1fr) ${
|
|
18
|
+
grid-template-columns: ${Xa}px minmax(0, 1fr) ${ho};
|
|
19
19
|
grid-template-rows: auto 1fr;
|
|
20
20
|
grid-template-areas: "rail main card" "rail main side";
|
|
21
21
|
column-gap: 32px; row-gap: 28px; align-items: start;
|
|
@@ -271,7 +271,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
|
|
|
271
271
|
/* 中等宽度:左栏折到顶部一行 */
|
|
272
272
|
@media (max-width: 1100px) {
|
|
273
273
|
.bim-d-grid {
|
|
274
|
-
grid-template-columns: minmax(0, 1fr) ${
|
|
274
|
+
grid-template-columns: minmax(0, 1fr) ${ho};
|
|
275
275
|
grid-template-rows: auto auto 1fr;
|
|
276
276
|
grid-template-areas: "rail rail" "main card" "main side";
|
|
277
277
|
}
|
|
@@ -285,7 +285,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
|
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
/* 手机:左栏收起,提要卡 → 正文 → 旁栏 */
|
|
288
|
-
@media ${
|
|
288
|
+
@media ${Dr} {
|
|
289
289
|
.bim-d-main.bim-d-main-grid { padding: 8px 16px 0; }
|
|
290
290
|
.bim-d-grid {
|
|
291
291
|
grid-template-columns: minmax(0, 1fr);
|
|
@@ -326,7 +326,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
|
|
|
326
326
|
.bim-d-pick-n { margin: 0; grid-column: 2; grid-row: 1 / span 2; }
|
|
327
327
|
.bim-d-find { flex-basis: 100%; min-height: 40px; }
|
|
328
328
|
}
|
|
329
|
-
`;function
|
|
329
|
+
`;function Yt({railTop:e,back:n,up:i,nav:r,railLinks:s,main:l,card:c,side:p}){const{convert:a}=V(),d=(r||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,n&&t.jsx("div",{style:{marginTop:e?12:0},children:n}),i,d.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":a("本頁導航"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:a("本頁")}),t.jsx("ul",{className:"bim-d-rail-nav",children:d.map(u=>t.jsx("li",{children:t.jsxs("a",{href:`#${u.id}`,children:[t.jsx("span",{children:a(u.label)}),u.count!=null&&t.jsx("span",{className:"bim-d-meta",children:u.count})]})},u.id))})]}),s&&s.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":a("更多"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:a("更多")}),t.jsx("ul",{className:"bim-d-rail-nav",children:s.map(u=>t.jsx("li",{children:t.jsxs("a",{href:u.href??"#",onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),u.onClick())},children:[t.jsx("span",{children:a(u.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},u.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:l}),t.jsx("div",{className:"bim-d-g-card",children:c}),t.jsx("div",{className:"bim-d-g-side",children:p})]})}function Hr({caption:e,children:n}){const{convert:i}=V();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:i(e)}),n]})}function Be({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 Le({items:e,className:n,style:i}){const r=e.filter(s=>s!=null&&s!==""&&s!==!1);return r.length?t.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:i,children:r.map((s,l)=>t.jsxs(g.Fragment,{children:[l>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},l))}):null}function xi({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 Gr({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 Et({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 Kt({kind:e,title:n,subtitle:i,byline:r,meta:s,description:l,clampDescription:c,facts:p,readAction:a,secondaryAction:d,children:u,foot:f}){const{convert:x}=V(),m=(p||[]).filter(j=>j.value!=null&&j.value!==""),[b,w]=g.useState(!1),h=!!c&&!b;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:x(e)}),t.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),i&&t.jsx("div",{className:"bim-d-card-sub",children:i}),r&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:r}),s&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),l&&t.jsx("div",{className:h?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:h?{"--detail-clamp":c}:void 0,children:l}),l&&!!c&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":b,onClick:()=>w(j=>!j),children:x(b?"收起":"展開")}),m.length>0&&t.jsx("dl",{className:"bim-d-ui",children:m.map((j,y)=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:x(j.label)}),t.jsx("dd",{title:j.title,children:j.value})]},y))}),u,a,d,f&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:f})]})}function fi(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function Dn({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 gt({id:e,title:n,meta:i,items:r,metas:s,currentIndex:l,cap:c=8,moreLabel:p}){const{convert:a}=V(),[d,u]=g.useState(!1);if(!r.length)return null;const f=d?r:r.slice(0,c),x=r.length-f.length;return t.jsxs("div",{id:e,className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[a(n),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i})]}),t.jsx("ul",{children:f.map((m,b)=>t.jsxs("li",{className:b===l?"bim-d-side-cur":void 0,"aria-current":b===l?"page":void 0,children:[m,s!=null&&s[b]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[b]}):null]},b))}),x>0&&t.jsx(Et,{label:p?p(x):`顯示更多(${x})`,onClick:()=>u(!0)})]})}const nc={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function qt({revision:e,revisedAt:n,review:i,todo:r}){const{convert:s}=V(),l=i?nc[i.status]:void 0,c=i&&i.status!=="unreviewed"&&l?[l,i.by,i.date].filter(Boolean).join(" "):"",p=[e!=null&&e!==""?`${s("數據版本")} ${e}`:"",n??"",s(c)].filter(Boolean),a=(r||[]).filter(d=>d&&d.what);return!p.length&&!a.length?null:t.jsxs(t.Fragment,{children:[p.length>0&&t.jsx(Le,{items:p,style:{fontSize:12}}),a.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s(`待核 ${a.length} 項`)}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:a.map((d,u)=>t.jsxs("li",{children:[s(d.what),(d.by||d.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[d.by&&s(d.by),d.date].filter(Boolean).join(" · "),")"]})]},u))})]})]})}const an=1e3,bo=208,ic=1440,oc="(max-width: 719px)",Ur=`
|
|
330
330
|
.bim-d-page {
|
|
331
331
|
background: ${o("page-bg")};
|
|
332
332
|
color: ${o("ink")};
|
|
@@ -335,7 +335,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
|
|
|
335
335
|
padding-bottom: 64px;
|
|
336
336
|
}
|
|
337
337
|
.bim-d-main {
|
|
338
|
-
max-width: ${
|
|
338
|
+
max-width: ${an}px;
|
|
339
339
|
margin: 0 auto;
|
|
340
340
|
padding: 24px clamp(16px, 4vw, 28px) 0;
|
|
341
341
|
}
|
|
@@ -378,9 +378,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
|
|
|
378
378
|
*/
|
|
379
379
|
.bim-d-reader {
|
|
380
380
|
display: grid;
|
|
381
|
-
grid-template-columns: ${
|
|
381
|
+
grid-template-columns: ${bo}px minmax(0, ${an}px);
|
|
382
382
|
gap: 32px;
|
|
383
|
-
max-width: ${
|
|
383
|
+
max-width: ${bo+an+32}px;
|
|
384
384
|
margin: 0 auto;
|
|
385
385
|
align-items: start;
|
|
386
386
|
}
|
|
@@ -421,8 +421,8 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${o("tint-bg"
|
|
|
421
421
|
padding-right: 0; padding-bottom: 12px;
|
|
422
422
|
}
|
|
423
423
|
}
|
|
424
|
-
${tc}`;function
|
|
425
|
-
`)||(n.push({start:i,end:l+1,inner:c}),i=l)}return n}function
|
|
424
|
+
${tc}`;function Pt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Ur}),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 Hn({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 gi({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 Gn({items:e}){const n=Ae();return t.jsx(t.Fragment,{children:e.map((i,r)=>{const s=r===e.length-1,l=r>0&&t.jsx("span",{style:{color:o("hint-fg")},children:"/"},`s${r}`),c=i.id?n(i.id):i.href,p=s||!i.onClick&&!c?t.jsx("span",{style:{color:o("ink")},children:i.label},r):t.jsx("a",{href:c??"#",onClick:i.onClick?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i.onClick())}:void 0,style:{color:o("meta-fg")},children:i.label},r);return t.jsxs(g.Fragment,{children:[l,p]},r)})})}function Vr({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 rc({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 sc({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 lc({glyph:e,tone:n,title:i,count:r,actions:s,id:l}){const{convert:c}=V();return t.jsxs("div",{id:l,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(gi,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:c(i)}),r!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:o("label-fg")},children:r})]}),s&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function Yr({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 ac({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 cc({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 Kr({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 dc({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function pc({volumes:e,unit:n="冊",max:i=60}){const[r,s]=g.useState(!1);if(!e.length)return null;const l=r?e:e.slice(0,i);return t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[l.map(c=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${o("rule")}`,color:o("meta-fg")},children:c},c)),!r&&e.length>i&&t.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${o("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:o("meta-fg")},children:["+",e.length-i]}),t.jsx("span",{style:{padding:"2px 6px",color:o("hint-fg")},children:n})]})}function uc({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${o("rule-strong")}`},children:e})}function xc({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 fc({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 gc(e){return String(e+1).padStart(2,"0")}function mc(){return t.jsx("span",{style:{color:o("hint-fg")},children:"—"})}function hc({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 qr(e){const n=[];for(let i=0;i<e.length;i++){const r=e[i];let s;if(r==="⟨")s="⟩";else if(r==="<"){const p=e[i+1];if(p===void 0||/[A-Za-z/!?>\s]/.test(p))continue;s=">"}else continue;const l=e.indexOf(s,i+1);if(l<0)continue;const c=e.slice(i+1,l);c.includes(`
|
|
425
|
+
`)||(n.push({start:i,end:l+1,inner:c}),i=l)}return n}function Jr(e,n){if(e.length<=n)return e;let i=n;for(const r of qr(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 Zr={fontSize:".78em",color:o("meta-fg"),lineHeight:1.55},bc={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 Xr(e,n,i){return e.map((r,s)=>{switch(r.type){case"text":return t.jsx(g.Fragment,{children:n(r.text)},s);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:i===0?Zr:void 0,children:Xr(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:bc,children:r.label},s)}})}function De(e,n=r=>r,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return Za(e)?Xr(Pr(e),n,0):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let s=0,l=0;for(const c of qr(e))c.start>s&&r.push(t.jsx(g.Fragment,{children:n(e.slice(s,c.start))},l++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:Zr,children:n(c.inner)},l++)),s=c.end;return s<e.length&&r.push(t.jsx(g.Fragment,{children:n(e.slice(s))},l++)),r}function yc({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 jc({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 Qr({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 vc({item:e,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=V(),[l,c]=g.useState(!1),p=gn(e),a=i&&!!p&&p.expected>0,d=(e.url?Tt(e.url):void 0)||s(e.name),u=n?Tr(e,n):"",f=u?`${d}(${u})`:d;return t.jsx(Qr,{name:f,note:yn(e)||r,href:Rt(e),extra:a?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>c(x=>!x),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:o("meta-fg"),borderBottom:`1px solid ${o("rule")}`},children:l?"收起分冊":`展開 ${p.expected} 冊`}),l&&t.jsx(mi,{item:e})]}):void 0})}function mi({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 es({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(Kr,{children:i(r)},s))]}):null}function kc({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(es,{label:i.label,items:i.items},i.label))}):null}function Un(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ts({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 Sc({children:e,action:n}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:o("aux-fg"),borderBottom:`1px solid ${o("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),n]})}function Ie({id:e,label:n,onNavigate:i,renderLink:r,style:s,dense:l}){const c=Ae();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:l})}):t.jsx("a",{href:c(e),onClick:i?p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(e))}:void 0,style:s,children:n??e})}function wc({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 ns="(min-width: 1100px)",is="(max-width: 719px)",_c=`${is}, (pointer: coarse)`,ct=o("reader-top"),$c="48px",os=`
|
|
426
426
|
.bim-rd {
|
|
427
427
|
position: relative;
|
|
428
428
|
background: ${o("page-bg")};
|
|
@@ -454,7 +454,7 @@ ${tc}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
|
|
|
454
454
|
|
|
455
455
|
/* ── 工具条:文字 + 图标,不画按钮外框 ── */
|
|
456
456
|
.bim-rd-bar {
|
|
457
|
-
position: sticky; top: ${
|
|
457
|
+
position: sticky; top: ${ct}; z-index: 30;
|
|
458
458
|
height: var(--bimrd-bar-h);
|
|
459
459
|
display: flex; align-items: center; gap: 16px;
|
|
460
460
|
padding: 0 20px;
|
|
@@ -491,14 +491,14 @@ ${tc}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
|
|
|
491
491
|
display: grid;
|
|
492
492
|
grid-template-columns: auto auto minmax(0, 1fr);
|
|
493
493
|
align-items: start;
|
|
494
|
-
min-height: calc(100vh - ${
|
|
494
|
+
min-height: calc(100vh - ${ct} - var(--bimrd-bar-h));
|
|
495
495
|
}
|
|
496
496
|
|
|
497
497
|
/* 目录:宽屏是侧栏 */
|
|
498
498
|
.bim-rd-toc {
|
|
499
499
|
grid-column: 1;
|
|
500
|
-
position: sticky; top: calc(${
|
|
501
|
-
width: 248px; height: calc(100vh - ${
|
|
500
|
+
position: sticky; top: calc(${ct} + var(--bimrd-bar-h));
|
|
501
|
+
width: 248px; height: calc(100vh - ${ct} - var(--bimrd-bar-h));
|
|
502
502
|
overflow-y: auto; overscroll-behavior: contain;
|
|
503
503
|
padding: 0 10px 40px;
|
|
504
504
|
background: ${o("sidebar-bg")};
|
|
@@ -535,8 +535,8 @@ ${tc}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
|
|
|
535
535
|
/* 书影:正文左侧 */
|
|
536
536
|
.bim-rd-img {
|
|
537
537
|
grid-column: 2;
|
|
538
|
-
position: sticky; top: calc(${
|
|
539
|
-
width: clamp(300px, 32vw, 560px); height: calc(100vh - ${
|
|
538
|
+
position: sticky; top: calc(${ct} + var(--bimrd-bar-h));
|
|
539
|
+
width: clamp(300px, 32vw, 560px); height: calc(100vh - ${ct} - var(--bimrd-bar-h));
|
|
540
540
|
padding: 16px 0 16px 20px;
|
|
541
541
|
display: flex; flex-direction: column; gap: 8px;
|
|
542
542
|
}
|
|
@@ -547,7 +547,7 @@ ${tc}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
|
|
|
547
547
|
display: flex; align-items: center; justify-content: center; overflow: hidden;
|
|
548
548
|
}
|
|
549
549
|
.bim-rd-img-fig { position: relative; margin: 0; max-width: 100%; max-height: 100%; }
|
|
550
|
-
.bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${
|
|
550
|
+
.bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${ct} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
|
|
551
551
|
.bim-rd-img-fig svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
|
|
552
552
|
.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")}; }
|
|
553
553
|
.bim-rd-img-empty b { font-size: 15px; font-weight: 500; color: ${o("quiet-fg")}; }
|
|
@@ -612,7 +612,7 @@ ${tc}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
|
|
|
612
612
|
|
|
613
613
|
/* 竖排(预留):只在宿主打开 allowVertical 时可切换 */
|
|
614
614
|
.bim-rd-vertical .bim-rd-prose {
|
|
615
|
-
writing-mode: vertical-rl; max-height: calc(100vh - ${
|
|
615
|
+
writing-mode: vertical-rl; max-height: calc(100vh - ${ct} - var(--bimrd-bar-h) - 120px);
|
|
616
616
|
overflow-x: auto; text-align: start;
|
|
617
617
|
}
|
|
618
618
|
|
|
@@ -642,7 +642,7 @@ ${tc}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
|
|
|
642
642
|
}
|
|
643
643
|
|
|
644
644
|
/* ── 中屏以下:目录改抽屉 ── */
|
|
645
|
-
@media not all and ${
|
|
645
|
+
@media not all and ${ns} {
|
|
646
646
|
.bim-rd-toc {
|
|
647
647
|
position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto;
|
|
648
648
|
width: min(86vw, 320px);
|
|
@@ -656,7 +656,7 @@ ${tc}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
|
|
|
656
656
|
}
|
|
657
657
|
|
|
658
658
|
/* ── 窄屏:书影收起,只留正文 ── */
|
|
659
|
-
@media ${
|
|
659
|
+
@media ${is} {
|
|
660
660
|
.bim-rd-bar { padding: 0 12px; gap: 10px; }
|
|
661
661
|
.bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
|
|
662
662
|
.bim-rd-ttl { flex: 1 1 auto; }
|
|
@@ -672,19 +672,19 @@ ${tc}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
|
|
|
672
672
|
.bim-rd-h1 { font-size: 20px; letter-spacing: 0.06em; }
|
|
673
673
|
.bim-rd-prose { margin-top: 20px; }
|
|
674
674
|
}
|
|
675
|
-
`;function
|
|
676
|
-
`),[se]),
|
|
675
|
+
`;function hi(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(r=>hi(r,n))):!1}const zc=()=>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 Cc({item:e,activeKey:n,onSelect:i,tabKey:r}){const s=hi(e,n),[l,c]=g.useState(s||!!e.defaultExpanded);return g.useEffect(()=>{s&&c(!0)},[s]),g.useEffect(()=>{e.defaultExpanded&&c(!0)},[e.defaultExpanded]),t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>c(p=>!p),children:[t.jsx(zc,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(rs,{items:e.children,activeKey:n,onSelect:i,tabKey:r})]})}function rs({items:e,activeKey:n,onSelect:i,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Cc,{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 yo(e,n){var i;for(const r of e)if(r.key===n||hi(r,n))return r.key;return((i=e[0])==null?void 0:i.key)??null}function ss({items:e,activeKey:n,onSelect:i,label:r="目录"}){const s=g.useRef(null),[l,c]=g.useState(null);g.useEffect(()=>{c(null)},[n]);const p=g.useMemo(()=>l||(n??yo(e,n)),[l,n,e]);g.useEffect(()=>{const d=s.current;if(!d)return;const u=Array.from(d.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const f=u.find(x=>x.dataset.rdTocKey===p)??u.find(x=>x.dataset.rdTocKey===yo(e,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===f?0:-1}),g.useEffect(()=>{const d=s.current,u=d==null?void 0:d.closest(".bim-rd-toc");if(!d||!u||!n)return;const f=Array.from(d.querySelectorAll("[data-rd-toc-key]")).find(m=>m.dataset.rdTocKey===n);if(!f)return;const x=f.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(x<u.scrollTop+80||x>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,x-u.clientHeight/3))},[n]);const a=g.useCallback(d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const f=s.current;if(!f)return;const x=Array.from(f.querySelectorAll("[data-rd-toc-key]")).filter(h=>!h.disabled),m=x.indexOf(document.activeElement);let b=m;if(d.key==="ArrowDown"?b=Math.min(x.length-1,m+1):d.key==="ArrowUp"?b=Math.max(0,m-1):d.key==="Home"?b=0:d.key==="End"&&(b=x.length-1),b<0||b===m)return;d.preventDefault();const w=x[b];for(const h of x)h.tabIndex=-1;w.tabIndex=0,w.focus(),c(w.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:a,children:t.jsx(rs,{items:e,activeKey:n,onSelect:i,tabKey:p})})}function Ic({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 ls({pages:e,loading:n,page:i,onPageChange:r,renderOverlay:s}){const[l,c]=g.useState(0),p=i??l,a=x=>{r?r(x):c(x)};if(g.useEffect(()=>{i===void 0&&c(0)},[e,i]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:"加载书影…"})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:"暂无书影"}),t.jsx("span",{children:"这一卷还没有配上影像;接入后在此与正文逐页对看"})]})});const d=Math.max(0,Math.min(e.length-1,p)),u=e[d],f=u.label??`${d+1}`;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${f} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(Ic,{page:u}),s==null?void 0:s(u,d)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:d===0,onClick:()=>a(d-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${d+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:d===e.length-1,onClick:()=>a(d+1),children:"›"})]})]})}const bi={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal"},St=[15,16,17,18,20,22,24],Vn=18,as="bim-reader-prefs",Tc="bim-reading-mode";function Rc(){const e={...bi};try{const n=localStorage.getItem(as),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&St.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(Tc))==="paragraph"&&(e.readingMode="paragraph"),i.properNames===!0&&(e.properNames=!0),i.writingMode==="vertical"&&(e.writingMode="vertical")}catch{}return e}function Ec(e){try{localStorage.setItem(as,JSON.stringify(e))}catch{}}function jo(e,n){const i=e??Vn,r=St;let s=r.indexOf(i);return s<0&&(s=r.indexOf(Vn)),r[Math.max(0,Math.min(r.length-1,s+n))]}function yi(){const[e,n]=g.useState(bi);g.useEffect(()=>{n(Rc())},[]);const i=g.useCallback(r=>{n(s=>{const l={...s,...r};return Ec(l),l})},[]);return[e,i]}function cs(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 Yn(e){const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function ds(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 ps(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 Nc=()=>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 Bc(e,n){if(!n)return;const i=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(c=>c.tabIndex>=0);if(i.length===0)return;const r=i[0],s=i[i.length-1],l=document.activeElement;e.shiftKey&&(l===r||!n.contains(l))?(e.preventDefault(),s.focus()):!e.shiftKey&&(l===s||!n.contains(l))&&(e.preventDefault(),r.focus())}function Ac(e,n){const[i,r]=g.useState(n);return g.useEffect(()=>{var c;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(s.matches);return(c=s.addEventListener)==null||c.call(s,"change",l),()=>{var p;return(p=s.removeEventListener)==null?void 0:p.call(s,"change",l)}},[e]),i}function Wc(){const e=g.useContext(It);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 ji({title:e,subtitle:n,toc:i,activeKey:r,onSelect:s,tocHeader:l,tocCaption:c,images:p,imagesLoading:a,renderImageOverlay:d,imagePanel:u="auto",prefs:f,onPrefsChange:x,paragraphToggle:m,properNameToggle:b=!0,allowVertical:w,pager:h=!0,versions:j,currentVersionKey:y,onVersionChange:k,versionSource:_=!0,children:v,className:$,style:S}){const z=g.useId().replace(/:/g,""),I=`bim-rd-toc-${z}`,R=`bim-rd-text-${z}`,C=g.useRef(null),F=g.useRef(null),W=g.useRef(null),B=g.useRef(null),M=Ac(ns,!0),[U,G]=g.useState("auto"),E=U==="auto"?M:U==="open",oe=!M,P=!!p&&p.length>0,[le,ge]=g.useState(u);g.useEffect(()=>{ge(u)},[u]);const Q=le==="auto"?P||!!a:le==="open",O=g.useCallback(Y=>{var T;G("auto"),Y&&((T=B.current)==null||T.focus())},[]),q=()=>G(E?"closed":"open");g.useEffect(()=>{if(!oe||U!=="open")return;const Y=W.current,T=Y==null?void 0:Y.querySelector('input, [data-rd-toc-key][tabindex="0"]');T==null||T.focus()},[oe,U]);const de=g.useCallback(Y=>{s(Y),oe&&O(!1);const T=F.current,ee=C.current;if(T&&ee&&typeof window<"u"){const ie=T.getBoundingClientRect().top-ee.getBoundingClientRect().bottom;ie<0&&window.scrollBy({top:ie})}},[s,oe,O]),se=g.useMemo(()=>ps(i),[i]),[te,D]=g.useState(null),K=ds(j,y!==void 0?y:te),X=(K==null?void 0:K.key)??null,xe=g.useMemo(()=>se.map(Y=>Y.key).join(`
|
|
676
|
+
`),[se]),A=g.useRef(null),re=Y=>{Y!==X&&(A.current={key:Y,sig:xe,done:!1},y===void 0&&D(Y),k==null||k(Y))};g.useEffect(()=>{const Y=A.current;if(!Y||Y.key!==X)return;const T=se.find(ie=>!ie.disabled);if(!T)return;const ee=xe!==Y.sig;!ee&&Y.done||(ee?A.current=null:Y.done=!0,T.key!==r&&de(T.key))},[X,xe,se,r,de]);const ne=se.findIndex(Y=>Y.key===r),pe=ne>0?se.slice(0,ne).reverse().find(Y=>!Y.disabled):void 0,fe=ne>=0?se.slice(ne+1).find(Y=>!Y.disabled):void 0,L=f.fontSize??Vn,J={...S,...f.fontSize?{"--bimrd-fs":`${f.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",f.writingMode==="vertical"&&w?"bim-rd-vertical":"",$].filter(Boolean).join(" "),"data-toc":U,"data-img":Q?"open":"closed",style:J,children:[t.jsx("style",{children:os}),t.jsx("a",{className:"bim-rd-skip",href:`#${R}`,onClick:Y=>{var T,ee,ie;Y.preventDefault(),(T=F.current)==null||T.focus(),(ie=(ee=F.current)==null?void 0:ee.scrollIntoView)==null||ie.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:[j&&j.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:K?Yn(K):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:X??"",onChange:Y=>re(Y.target.value),children:j.map(Y=>t.jsx("option",{value:Y.key,children:Yn(Y)},Y.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),t.jsxs("button",{ref:B,type:"button",className:"bim-rd-t","aria-expanded":E,"aria-controls":I,onClick:q,children:[t.jsx(Nc,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":Q,onClick:()=>ge(Q?"closed":"open"),children:[t.jsx(Lc,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Wc,{}),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:L<=St[0],onClick:()=>x({fontSize:jo(f.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"放大字号",disabled:L>=St[St.length-1],onClick:()=>x({fontSize:jo(f.fontSize,1)}),children:"A+"}),(m||b||w)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),m&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":f.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>x({readingMode:f.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),b&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":f.properNames,title:"书名加波浪线",onClick:()=>x({properNames:!f.properNames}),children:"专名线"}),w&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":f.writingMode==="vertical",onClick:()=>x({writingMode:f.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:I,ref:W,role:oe&&E?"dialog":void 0,"aria-modal":oe&&E?!0:void 0,"aria-label":oe&&E?"目录":void 0,onKeyDown:Y=>{if(!(!oe||!E)){if(Y.key==="Escape"){Y.stopPropagation(),O(!0);return}Y.key==="Tab"&&Bc(Y,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:c??"目录"}),oe&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>O(!0),children:"✕"})]}),l]}),t.jsx(ss,{items:i,activeKey:r,onSelect:de})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>O(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:Q&&t.jsx(ls,{pages:p??null,loading:a,renderOverlay:d})}),t.jsx("div",{className:"bim-rd-text",id:R,ref:F,tabIndex:-1,children:t.jsxs("div",{className:"bim-rd-col",children:[v,_&&K&&(K.sourceName||K.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":K.key,children:[K.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",K.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:K.sourceUrl,target:"_blank",rel:"noreferrer",children:K.sourceName}):K.sourceName]}),K.sourceName&&K.license&&t.jsx("span",{className:"bim-rd-dot"}),K.license&&t.jsxs(t.Fragment,{children:["授权 ",K.license]})]}),h&&(pe||fe)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[t.jsx("span",{children:pe&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>de(pe.key),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-pglabel",children:pe.label})]})}),t.jsx("span",{children:fe&&t.jsxs("button",{type:"button",className:"bim-rd-t",onClick:()=>de(fe.key),children:[t.jsx("span",{className:"bim-rd-pglabel",children:fe.label}),t.jsx("span",{"aria-hidden":"true",children:"›"})]})})]})]})})]})]})}const us="guji-table-v1";function xs(e){return!!e&&e.table_notation===us}const Mc=/^:::table(?:\{[^}]*\})?[ \t]*$/,Fc=/^:::[ \t]*$/;function fs(e){const n=[];let i="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const c=Mr(e,r+3);if(c>r+4){i+=e.slice(r,c+1),r=c;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const c=e[r+1];c!==void 0&&!/[A-Za-z/!?>\s]/.test(c)&&(l=">")}if(l){const c=e.indexOf(l,r+1);if(c>0){i+=e.slice(r,c+1),r=c;continue}}s==="|"?(n.push(i),i=""):i+=s}return n.push(i),n.map(r=>r.trim())}const Pc=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function Oc(e){if(e==="^")return{cont:!0};const n=Pc.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 gs(e,n=1){const i=[],r=[],s=[];let l=[];e.forEach((p,a)=>{const d=a+n+1;let u=p.trim();if(!u)return;let f=!1;u.startsWith("!")&&(f=!0,u=u.slice(1));const x=fs(u).map(Oc),m=l.map(j=>j>0),b=l.map(j=>j>0?j-1:0),w=[];let h=0;for(const j of x){if(j.cont){m[h]||i.push(`第 ${d} 行第 ${h+1} 列:续格 ^ 上方没有跨行格`),h+=1;continue}const{cell:y}=j;for(let k=h;k<h+y.colspan;k++)if(m[k]){i.push(`第 ${d} 行第 ${k+1} 列:此处被上方跨行格占住,应写 ^`);break}if(y.rowspan>1)for(let k=h;k<h+y.colspan;k++)b[k]=y.rowspan-1;w.push(y),h+=y.colspan}for(let j=h;j<m.length;j++)m[j]&&i.push(`第 ${d} 行第 ${j+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let j=0;j<b.length;j++)b[j]===void 0&&(b[j]=0);l=b,r.push({header:f,cells:w}),s.push({width:h,line:d})});const c=s.reduce((p,a)=>Math.max(p,a.width),0);for(const p of s)p.width!==c&&i.push(`第 ${p.line} 行:占 ${p.width} 列,与总列数 ${c} 不符`);return l.some(p=>p>0)&&i.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&i.push("空表"),{rows:r,columns:c,warnings:i}}function vi(e){const n=e.split(`
|
|
677
677
|
`),i=[];let r=[];const s=()=>{if(r.length===0)return;const c=r.join(`
|
|
678
|
-
`);r=[],i.push({type:"text",text:c})};let l=0;for(;l<n.length;){if(Mc.test(n[l].trim())){let c=l+1;for(;c<n.length&&!Fc.test(n[c].trim());)c++;if(c<n.length){s();const p=n.slice(l+1,c);i.push({type:"table",table:
|
|
679
|
-
`)}),l=c+1;continue}}r.push(n[l]),l++}return s(),i.map((c,p)=>{var d,u;if(c.type!=="text")return c;let a=c.text;return((d=i[p-1])==null?void 0:d.type)==="table"&&(a=a.replace(/^\n+/,"")),((u=i[p+1])==null?void 0:u.type)==="table"&&(a=a.replace(/\n+$/,"")),{type:"text",text:a}}).filter(c=>c.type!=="text"||c.text!=="")}const Dc={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},Hc={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},Gc=`1px solid ${o("table-border")}`,
|
|
680
|
-
`).map(n=>n.trim()).filter(n=>n&&!
|
|
681
|
-
`)){const s=r.trim();if(!s||
|
|
678
|
+
`);r=[],i.push({type:"text",text:c})};let l=0;for(;l<n.length;){if(Mc.test(n[l].trim())){let c=l+1;for(;c<n.length&&!Fc.test(n[c].trim());)c++;if(c<n.length){s();const p=n.slice(l+1,c);i.push({type:"table",table:gs(p,l+1),source:n.slice(l,c+1).join(`
|
|
679
|
+
`)}),l=c+1;continue}}r.push(n[l]),l++}return s(),i.map((c,p)=>{var d,u;if(c.type!=="text")return c;let a=c.text;return((d=i[p-1])==null?void 0:d.type)==="table"&&(a=a.replace(/^\n+/,"")),((u=i[p+1])==null?void 0:u.type)==="table"&&(a=a.replace(/\n+$/,"")),{type:"text",text:a}}).filter(c=>c.type!=="text"||c.text!=="")}const Dc={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},Hc={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},Gc=`1px solid ${o("table-border")}`,ms={border:Gc,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},Uc={...ms,background:o("table-head-bg"),fontWeight:600};function ki({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:Dc,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 c=i.header?"th":"td";return t.jsx(c,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:i.header?Uc:ms,children:s.empty?null:De(s.text,void 0,n)},l)})},r))})})})}function Vc(e,n){return e.indexOf("**")<0?De(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:De(r.trim().slice(2,-2),void 0,n)},s):t.jsx(g.Fragment,{children:De(r,void 0,n)},s))}function Yc(e,n,i=!1){const r=i?{gujiMarkdown:!0}:void 0;return n?vi(e).map((s,l)=>s.type==="table"?t.jsx(ki,{table:s.table,opts:r},l):t.jsx(g.Fragment,{children:Vc(s.text,r)},l)):De(e,void 0,r)}const Kc=/^(#{1,6})\s+(.*)$/,qc=/^\*\*([^*\n]+)\*\*\s*$/;function Si(e){const n=e.match(Kc);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(qc);return i?{level:3,text:i[1].trim()}:null}const wi=/^<!--.*-->$/;function hs(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function bs(e){return e.split(`
|
|
680
|
+
`).map(n=>n.trim()).filter(n=>n&&!wi.test(n))}const Jc=60;function ys(e){let n=0,i=0;for(const r of e.split(`
|
|
681
|
+
`)){const s=r.trim();if(!s||wi.test(s)||Si(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>Jc&&(i+=l)}return n>0&&i*2>=n}function Zc(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function vn(e){if(e=Zc(e),ys(e))return"unknown";const n=hs(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>bs(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 Xc(e){const n=e.split(`
|
|
682
682
|
`),i=[];let r=null,s=[];const l=()=>{i.push({heading:r,body:s.join(`
|
|
683
|
-
`)}),s=[]};for(const c of n){const p=
|
|
684
|
-
`)){const r=
|
|
685
|
-
`)?"":n)}function ed(e){return e<=1?2:e===2?3:4}function td(){let e=1;return n=>{const i=ed(n),r=Math.min(i,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${i}`}}}function
|
|
686
|
-
`);let a=0;return t.jsx(t.Fragment,{children:p.map((d,u)=>{const f=d.match(Sn);if(f){const m=a++;if(l(f[1].length,f[2],m))return null;const{Tag:b,className:w}=c(f[1].length);return t.jsx(b,{className:w,children:i(f[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Sn.test(p[u-1])&&!Sn.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(Qc.test(d))return null;if(a++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:m,className:b}=c(3);return t.jsx(m,{className:b,children:i(d.trim().slice(2,-2))},u)}return t.jsx("p",{children:bo(d,i,u)},u)})})}function nd(e){const{convert:n}=V();return g.useMemo(()=>e?n(e):"",[e,n])}function vi({text:e,mode:n,tables:i=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:c}){const p=nd(e),{convert:a}=V(),d=x=>ji(x,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,f=c?a(c):void 0;return!i||p.indexOf(":::")<0?t.jsx(yo,{text:p,mode:n,inline:d,dropTitle:f}):t.jsx(t.Fragment,{children:mi(p).map((x,m)=>x.type==="table"?t.jsx(hi,{table:x.table,opts:u},m):t.jsx(yo,{text:x.text,mode:n,inline:d,dropTitle:m===0?f:void 0},m))})}function vs(e,n){const[i,r]=g.useState(null),[s,l]=g.useState(!1),c=g.useRef(0);return g.useEffect(()=>{const p=++c.current;if(!e||!n){r(null),l(!1);return}let a;try{a=e(n)}catch{r(null),l(!1);return}if(!a||typeof a.then!="function"){r(a??null),l(!1);return}l(!0),a.then(d=>{p===c.current&&r(d??null)}).catch(()=>{p===c.current&&r(null)}).finally(()=>{p===c.current&&l(!1)})},[e,n]),{images:i,loading:s}}const jo={A:"fine",B:"rough",C:"rough",D:"ocr"};function id(e){return typeof e!="string"?null:e in Rn?e:e in jo?jo[e]:null}const od={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},rd={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function Xe(e){return typeof e!="string"?"":od[e]??rd[e]??e}const sd=["〇","一","二","三","四","五","六","七","八","九"],vo=["","十","百","千"],ld=["","萬","億"];function ki(e){if(e===0)return"〇";if(e<0)return`負${ki(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(ad(s,r>0)+ld[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function ad(e,n){const i=[];let r=e;for(;r>0;)i.unshift(r%10),r=Math.floor(r/10);let s="";for(let l=0;l<i.length;l++){const c=i[l],p=i.length-1-l;c===0?s&&!s.endsWith("〇")&&(s+="〇"):c===1&&p===1&&l===0&&!n?s+=vo[p]:s+=sd[c]+vo[p]}return s.replace(/〇$/,"")}let Ot=null,en=null;const an=new Set;function cd(){return Ot?Promise.resolve():en||(en=import("opencc-js/t2cn").then(e=>{Ot=e.Converter({from:"tw",to:"cn"}),an.forEach(n=>n())}).catch(()=>{Ot=e=>e,an.forEach(e=>e())}),en)}const dd=e=>e;function mt(){const[,e]=g.useState(0);return g.useEffect(()=>{if(Ot)return;const n=()=>e(i=>i+1);return an.add(n),cd(),()=>{an.delete(n)}},[]),Ot??dd}function _t(e,n){return n(e).toLowerCase()}const pd=o("highlight-bg");function Kt(e,n,i){if(!n)return e;const r=_t(n,i);if(!r)return e;const s=_t(e,i);if(s.length!==e.length)return e;const l=[];let c=0,p=0;for(;c<e.length;){const a=s.indexOf(r,c);if(a===-1){l.push(e.slice(c));break}a>c&&l.push(e.slice(c,a)),l.push(t.jsx("mark",{style:{background:pd,padding:0,color:"inherit"},children:e.slice(a,a+r.length)},p++)),c=a+r.length}return t.jsx(t.Fragment,{children:l})}function Si(e,n,i,r){if(!n)return!0;const s=_t(n,r);return(i?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(c=>typeof c=="string"&&_t(c,r).includes(s))}function ud(e,n,i){return n?_t(e,i).includes(_t(n,i)):!0}const wi={类:o("section-lei"),书:o("section-shu"),序:o("section-xu"),结语:o("section-jieyu"),注释:o("section-zhushi")},xd={考证:o("section-kaozhen")};function fd(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 ks(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((s,l)=>s+ks(l),0))||0;return n+i}function gd(e,n){const i=[],r=c=>{var p;i.push(...c.files),(p=c.children)==null||p.forEach(r)};if(r(e),i.length===0)return;const s=i.map(c=>n[c]);if(s.every(c=>c===void 0))return;if(s.some(c=>c==="loading"))return"loading";let l=0;for(const c of s)typeof c=="number"&&(l+=c);return l}const md={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function _i({enabled:e,expanded:n,onClick:i,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...md,...r},children:s}):t.jsx("span",{style:r,children:s})}function hd({type:e}){const n=Xe(e),i=wi[n]||o("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:i,border:`1px solid ${i}40`,borderRadius:"2px",background:`${i}08`,flexShrink:0},children:n})}function bd({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=V(),s=Ne(),l=mt(),c=w=>w?Oe(r(w),h=>i?Kt(h,i,l):h):"",[p,a]=g.useState(!1),d=!!e.summary,u=!!e.comment,f=!!e.additional_comment,x=!!(e.content&&e.content.length>60),m=d||u||f||x;g.useEffect(()=>{i&&a(!0)},[i]);const b=!p&&x?Yr(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[t.jsxs("div",{onClick:()=>m&&a(!p),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:m?"pointer":"default",userSelect:"none",background:o("input-bg")},children:[t.jsxs(_i,{enabled:m,expanded:p,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",c(e.book_title),"》"]}):c(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[ki(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:c(e.author_info||e.author)})]}),!p&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:c(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:c(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:o("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:s(e.work_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),w.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),p&&m&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${o("widget-border")}`,background:o("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"8px"},children:c(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:c(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(e.additional_comment)})]}),x&&!d&&!u&&!f&&t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(e.content)})]})]})}function yd({section:e,highlightQuery:n=""}){const{convert:i}=V(),r=mt(),s=a=>a?Oe(i(a),d=>n?Kt(d,n,r):d):"",[l,c]=g.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(_i,{enabled:p,expanded:l,onClick:()=>c(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(hd,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:s(e.title)}),p&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&p&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${wi[Xe(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 jd=100;function $i(e){return Xe(e.type)!=="page_header"?!1:(e.content||"").length>=jd}function vd({section:e,highlightQuery:n=""}){const{convert:i}=V(),r=mt();if(Xe(e.type)==="page_header"&&!$i(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
687
|
-
`)),l=Oe(s,d=>n?Kt(d,n,r):d),c=Xe(e.type),p=wi[c]||o("desc-fg"),a=c==="序"||c==="结语"||c==="注释";return t.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:o("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${p}40`:void 0,background:a?o("bg"):void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:c}),l]})}function kd(e,n,i){const[r,s]=g.useState({});return g.useEffect(()=>{var d;if(!n||e.length===0)return;let l=!1;const c=e.filter(u=>{var f;return!((f=i==null?void 0:i.current)!=null&&f.has(u))}),p={};for(const u of e)(d=i==null?void 0:i.current)!=null&&d.has(u)&&(p[u]=i.current.get(u));if(Object.keys(p).length>0&&s(p),c.length===0)return;const a=async u=>{var f;try{if(n.getEntry){const h=await n.getEntry(u);if(h)return{title:h.title,author:h.author}}const x=await n.getItem(u);if(!x)return null;const m=x.title||u,b=x.authors,w=(f=b==null?void 0:b[0])==null?void 0:f.name;return{title:m,author:w}}catch{return null}};return Promise.all(c.map(async u=>{var x;const f=await a(u);return(x=i==null?void 0:i.current)==null||x.set(u,f),[u,f]})).then(u=>{l||s(f=>{const x={...f};for(const[m,b]of u)x[m]=b;return x})}),()=>{l=!0}},[e.join(","),n]),r}function Sd({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=V(),c=Ne(),p=mt(),a=y=>y?Oe(l(y),k=>s?Kt(k,s,p):k):"",[d,u]=g.useState(!1);g.useEffect(()=>{s&&u(!0)},[s]);const f=Xe(e.type),x=xd[f]||o("desc-fg"),m=!!e.content,b=e.work_ids||[],w=b.length>1,h=kd(w?b:[],i,r),j=m&&!d&&e.content.length>80?Yr(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${o("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>m&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:m?"pointer":"default",userSelect:"none"},children:[t.jsxs(_i,{enabled:m,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg"),lineHeight:1.6},children:e.header_line?a(e.header_line):a(e.title)}),!d&&j&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:a(j)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:c(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:"→作品"}),w&&t.jsxs("span",{style:{fontSize:"11px",color:o("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:f})]})]}),w&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(y=>{const k=h[y],_=k?`${l(k.title)}${k.author?`(${l(k.author)})`:""}`:y.slice(0,8)+"…";return t.jsxs("a",{href:c(y),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(y))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",_]},y)})}),d&&m&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:o("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${o("widget-border")}`,fontSize:"12px",color:o("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:a(e.comment)})]})]})}function wd({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=mt(),c=n.trim(),p=g.useMemo(()=>c?e.sections.filter(a=>Si(a,c,!0,l)):e.sections,[e.sections,c,l]);return t.jsxs("div",{children:[t.jsx("div",{children:p.map((a,d)=>t.jsx(Sd,{section:a,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:c},d))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function _d(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function $d({sections:e,onNavigate:n,inline:i}){const r=Ne(),{convert:s}=V(),l=_d();return t.jsx(t.Fragment,{children:e.map((c,p)=>{const a=Xe(c.type);if(a==="page_header"&&!$i(c))return null;if(a==="类")return t.jsxs(g.Fragment,{children:[g.createElement(l("类"),null,i(s(c.title))),c.content&&t.jsx("p",{children:i(s(c.content))})]},p);if(a==="书"||a==="诗"||a==="考证"||a==="注释"){const d=c.book_title?`《${c.book_title}》${c.n_juan!=null?ki(c.n_juan)+"卷":""}`:c.title,u=i(s(d));return t.jsxs("section",{className:"bim-rd-entry",children:[g.createElement(l("条目"),{className:"bim-rd-entry-h"},c.work_id&&n?t.jsx("a",{href:r(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(c.work_id))},title:"查看作品",children:u}):u),c.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(c.author_info))}),c.content&&c.content.split(/\n+/).map((f,x)=>t.jsx("p",{children:i(s(f))},x)),c.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(c.summary))]}),c.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(c.comment))]}),c.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(c.additional_comment))]})]},p)}return c.content?t.jsx("p",{children:i(s(c.content))},p):null})})}function zd(e){return e.some(n=>{const i=Xe(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&$i(n)})}function Cd({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:c,workLabelCache:p,prefs:a}){var W;const{convert:d}=V(),u=mt(),[f,x]=g.useState("text"),m=s.trim(),b=(r==null?void 0:r.type)==="kaozhen",w=g.useCallback(A=>m?Kt(A,m,u):A,[m,u]),h=A=>ji(A,{renderText:w,properNames:a.properNames}),j=g.useMemo(()=>m?e.sections.filter(A=>Si(A,m,b,u)):e.sections,[e.sections,m,b,u]),y=(A,M)=>M.filter(U=>Xe(U.type)===A).length,k=y("书",e.sections),_=y("诗",e.sections),v=y("考证",e.sections);let $="";b?$=m?`${y("考证",j)} / ${v} ${d("條")}`:`${v} ${d("條")}`:_>0?$=m?`${y("诗",j)} / ${_} 首`:`${_} 首`:k>0&&($=m?`${y("书",j)} / ${k} ${d("部書")}`:`${k} ${d("部書")}`);const S=r!=null&&r.text_quality?id(r.text_quality.grade):null,z=[];i&&z.push(i),$&&z.push($),b&&(r!=null&&r.target_source)&&z.push(t.jsxs(t.Fragment,{children:[d("考證對象")," ",d(r.target_source)]})),S&&z.push(t.jsx("span",{title:vl[S],children:(W=r==null?void 0:r.text_quality)!=null&&W.source_note?t.jsxs(t.Fragment,{children:["底本 ",d(r.text_quality.source_note),"(",d(Rn[S]),")"]}):t.jsxs(t.Fragment,{children:[d("文本質量")," ",d(Rn[S])]})})),e.source_url&&z.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:d("原文來源")}));const T=!b&&zd(e.sections),R=!!n&&(!T||a.readingMode==="paragraph"&&hn(n)),C=!b&&(T||!!n),P=b||!C?"entries":f;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:d(e.title)}),z.length>0&&t.jsx("p",{className:"bim-rd-meta",children:z.map((A,M)=>t.jsxs(g.Fragment,{children:[M>0&&t.jsx("span",{className:"bim-rd-dot"}),A]},M))}),C&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":"看法",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":P==="text",onClick:()=>x("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":P==="entries",onClick:()=>x("entries"),children:d("條目")})]})]}),P==="text"&&t.jsx("article",{className:"bim-rd-prose",children:R?t.jsx(vi,{text:n,mode:a.readingMode,properNames:a.properNames,renderText:w,dropTitle:e.title}):t.jsx($d,{sections:e.sections,onNavigate:l,inline:h})}),P==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:b?t.jsx(wd,{juan:e,searchQuery:s,onNavigate:l,transport:c,workLabelCache:p}):t.jsxs(t.Fragment,{children:[j.map((A,M)=>{const U=Xe(A.type);return U==="书"||U==="诗"||U==="考证"?t.jsx(bd,{section:A,onNavigate:l,highlightQuery:m},M):U==="类"?t.jsx(yd,{section:A,highlightQuery:m},M):t.jsx(vd,{section:A,highlightQuery:m},M)}),j.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function Ss(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 Id(e){const n=Ss(e);return n.length>0?n[0]:null}function Td(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:c,query:p,isKaozhen:a}=e,d=mt(),u=g.useRef(new Map),[f,x]=g.useState({}),[m,b]=g.useState({}),w=g.useCallback((j,y)=>{const k=y==null?void 0:y.title;k&&b(_=>_[j]===k?_:{..._,[j]:k})},[]);g.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:c}),w(s,l))},[s,l,c,w]),g.useEffect(()=>{u.current.clear(),x({}),b({})},[n]);const h=g.useCallback((j,y)=>{let k=0;if(j.juan)for(const _ of j.juan.sections)Si(_,y,a,d)&&k++;return k===0&&j.rawText&&ud(j.rawText,y,d)&&(k=1),k},[a,d]);return g.useEffect(()=>{const j=p.trim();if(!j){x({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let y=!1;const k={},_=[];for(const T of r){const R=u.current.get(T);R?k[T]=h(R,j):(k[T]="loading",_.push(T))}x(k);const v=8;let $=0;const S=async()=>{var T;for(;$<_.length;){if(y)return;const R=$++,C=_[R];try{const[P,W]=await Promise.all([i.getCollatedJuan(n,C),((T=i.getCollatedJuanText)==null?void 0:T.call(i,n,C))??Promise.resolve(null)]),A={juan:P,rawText:W};if(u.current.set(C,A),w(C,P),y)return;x(M=>({...M,[C]:h(A,j)}))}catch{if(y)return;x(P=>({...P,[C]:0}))}}},z=Array.from({length:Math.min(v,_.length)},()=>S());return Promise.all(z),()=>{y=!0}},[p,n,i,r.join(","),h,d,w]),{matchStates:f,titles:m}}const zi=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:c,style:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m})=>{const[b,w]=g.useState(null),[h,j]=g.useState(!1),[y,k]=g.useState(null),[_,v]=g.useState(null),[$,S]=g.useState(null),[z,T]=g.useState(!1),[R,C]=g.useState(null),[P,W]=g.useState(""),A=g.useRef(new Map),M=g.useRef(0),U=s??_,G=g.useCallback(O=>{v(O),l==null||l(O)},[l]),E=e||b;g.useEffect(()=>{e&&(j(!1),k(null))},[e]),g.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let O=!1;return j(!0),k(null),i.getCollatedEditionIndex(n).then(q=>{O||(q?w(q):k("未找到整理本数据"))}).catch(q=>{O||k(q instanceof Error?q.message:"加载失败")}).finally(()=>{O||j(!1)}),()=>{O=!0}},[e,n,i]),g.useEffect(()=>{if(E&&!U){const O=Id(E);O&&G(O)}},[E,U,G]);const ie=n||(E==null?void 0:E.work_id),F=g.useCallback(async O=>{var de;if(!ie||!(i!=null&&i.getCollatedJuan))return;const q=++M.current;T(!0),S(null),C(null);try{const[se,ee]=await Promise.all([i.getCollatedJuan(ie,O),((de=i.getCollatedJuanText)==null?void 0:de.call(i,ie,O))??Promise.resolve(null)]);if(q!==M.current)return;S(se),C(ee)}catch{if(q!==M.current)return;S(null),C(null)}finally{q===M.current&&T(!1)}},[ie,i]);g.useEffect(()=>{U&&F(U)},[U,F]);const re=O=>{G(O)};if(h)return t.jsx("div",{className:c,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(y)return t.jsx("div",{className:c,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:y});if(!E)return null;const ce=E.type==="kaozhen",Z=Ss(E);return t.jsx(Ed,{className:c,style:p,index:E,allFiles:Z,isKaozhen:ce,effectiveWorkId:ie,transport:i,activeFile:U,handleSelectFile:re,juanData:$,juanRawText:R,juanLoading:z,searchQuery:P,setSearchQuery:W,onNavigate:r,workLabelCacheRef:A,reader:{title:a,subtitle:d,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m}})};function ws(e,n,i,r){var d,u,f,x;const s=(u=(d=n.juan_metadata)==null?void 0:d[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:fd(e)),p=((x=(f=n.files)==null?void 0:f.find(m=>m.filename===e))==null?void 0:x.title)??i[e];if(!p)return{position:l,label:l};const a=r(p);return{position:l,label:l===p||l===a?a:`${l} ${a}`}}function Rd(e,n,i,r,s){const l=a=>a==="loading"?"…":typeof a=="number"&&a>0?a:void 0,c=(a,d)=>({key:a,label:d??ws(a,e,r,s).label,hint:l(i[a]),disabled:i[a]===0}),p=(a,d)=>{var f;if(a.files.length===1&&!((f=a.children)!=null&&f.length))return c(a.files[0],s(a.label));const u=gd(a,i);return{key:`group:${d}`,label:s(a.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:ks(a),defaultExpanded:typeof u=="number"&&u>0,children:[...a.files.map(x=>c(x)),...(a.children??[]).map((x,m)=>p(x,`${d}.${m}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((a,d)=>p(a,`${d}`)):n.map(a=>c(a))}const Ed=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:c,activeFile:p,handleSelectFile:a,juanData:d,juanRawText:u,juanLoading:f,searchQuery:x,setSearchQuery:m,onNavigate:b,workLabelCacheRef:w,reader:h})=>{const{convert:j}=V(),[y,k]=fi(),{matchStates:_,titles:v}=Td({workId:l,transport:c,files:r,activeFile:p,activeJuan:d,activeRawText:u,query:x,isKaozhen:s}),$=vs(h.resolveImages,p),S=g.useMemo(()=>Rd(i,r,_,v,j),[i,r,_,v,j]),z=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:C=>m(C.target.value)}),T=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(C=>C.vol_label)?"冊":"卷",R=p?ws(p,i,v,j).position:void 0;return t.jsxs(gi,{className:e,style:n,title:h.title??(i.title?j(i.title):void 0),subtitle:h.subtitle??j(s?"考證":"整理本"),toc:S,tocCaption:`目录 · ${r.length} ${j(T)}`,tocHeader:z,activeKey:p,onSelect:a,images:$.images,imagesLoading:$.loading,renderImageOverlay:h.renderImageOverlay,imagePanel:h.imagePanel,prefs:y,onPrefsChange:k,paragraphToggle:!s&&hn(u),allowVertical:h.allowVertical,children:[f?t.jsx(gt,{}):d?t.jsx(Cd,{juan:d,rawText:u,positionLabel:R,index:i,searchQuery:x,onNavigate:b,transport:c,workLabelCache:w,prefs:y},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,i.references&&i.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:j("參考文獻")}),t.jsx("ol",{children:i.references.map((C,P)=>t.jsxs("li",{children:[C.url?t.jsx("a",{className:"bim-rd-link",href:C.url,target:"_blank",rel:"noopener noreferrer",children:C.title}):t.jsx("span",{children:C.title}),C.author&&t.jsxs("span",{children:[",",C.author]}),C.note&&t.jsxs("span",{children:["。",C.note]})]},P))})]})]})},Nd={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},Ld={label:"其他",color:o("desc-fg")},Bd={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 Wd(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 Md(e,n){if(!e)return!1;try{const i=new URL(e,n);if(i.protocol!=="http:"&&i.protocol!=="https:")return!1;const r=new URL(n);return i.hostname===r.hostname}catch{return!1}}const Ci=({items:e,loading:n})=>{const i=Ne();return n?t.jsx(gt,{}):e.length===0?t.jsx("div",{style:Fd,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Nd[r.type]||Ld,l=Bd[r.status]||Ad,c=typeof window<"u"&&Md(r.pageUrl,window.location.href);return t.jsxs("div",{style:Pd,children:[t.jsxs("div",{style:Od,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...ko,background:s.color},children:s.label}),t.jsx("span",{style:{...ko,background:l.color},children:l.label})]}),t.jsx("span",{style:Dd,children:Wd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:Hd,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:wn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(c?t.jsx("a",{href:r.pageUrl,style:wn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:wn,children:r.pageUrl}))]}),t.jsx("div",{style:Gd,children:r.content}),r.reply&&t.jsxs("div",{style:Ud,children:[t.jsx("div",{style:Vd,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Fd={textAlign:"center",padding:"40px 0",color:o("desc-fg"),fontSize:"14px"},Pd={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"16px"},Od={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},ko={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Dd={fontSize:"12px",color:o("desc-fg")},Hd={fontSize:"12px",marginBottom:"6px"},wn={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},Gd={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},Ud={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},Vd={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},Hn=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const c=ae(),[p,a]=g.useState(null),[d,u]=g.useState([]),[f,x]=g.useState("recommend"),[m,b]=g.useState([]),[w,h]=g.useState(!1),j=r??f,y=M=>{x(M),s==null||s(M)},[k,_]=g.useState(!0),[v,$]=g.useState(null),[S,z]=g.useState(null),[T,R]=g.useState(null);g.useEffect(()=>{let M=!1;if(e.getCounts)return e.getCounts().then(U=>{M||a({works:U.works,books:U.books,collections:U.collections})}).catch(()=>{}),()=>{M=!0}},[e]),g.useEffect(()=>{let M=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const G=await e.getRecommended();if(G!=null&&G.groups)return G.groups.flatMap(E=>E.items.map(ie=>({...ie,group:E.name})))}catch{}return[]})().then(async G=>{if(M)return;const E=G.filter(F=>F.id);if(E.length===0){_(!1);return}const ie=await Promise.all(E.map(async F=>{if(F.type)return{id:F.id,title:F.title,type:F.type,author:F.author,dynasty:F.dynasty,role:F.role,edition:F.edition,has_text:F.has_text,has_image:F.has_image,has_collated:F.has_collated,subtype:F.subtype,primary_name:F.primary_name,group:F.group,fallbackDescription:F.description};try{let re=null;if(e.getEntry)re=await e.getEntry(F.id);else{const ce=await e.getItem(F.id);ce&&(re={id:F.id,title:ce.title||F.id,type:ce.type||"work"})}if(re)return{...re,group:F.group,fallbackDescription:F.description}}catch{}return{id:F.id,title:F.title,type:he.extractType(F.id),group:F.group,fallbackDescription:F.description}}));M||(u(ie.filter(F=>F!==null)),_(!1))}),()=>{M=!0}},[e,i]);const C=g.useRef(!1),P=g.useRef(!1),W=g.useRef(!1);g.useEffect(()=>{if(j!=="catalog"||C.current)return;const M=e.getCatalogProgress??e.getResourceProgress;if(!M)return;C.current=!0;let U=!1;return M.call(e).then(G=>{U||$(G)}).catch(()=>{C.current=!1}),()=>{U=!0}},[e,j]),g.useEffect(()=>{if(j!=="collection"||P.current||!e.getCollectionProgress)return;P.current=!0;let M=!1;return e.getCollectionProgress().then(U=>{M||z(U)}).catch(()=>{P.current=!1}),()=>{M=!0}},[e,j]),g.useEffect(()=>{if(j!=="site"||W.current||!e.getSiteProgress)return;W.current=!0;let M=!1;return e.getSiteProgress().then(U=>{M||R(U)}).catch(()=>{W.current=!1}),()=>{M=!0}},[e,j]),g.useEffect(()=>{if(!l||j!=="feedback")return;let M=!1;return h(!0),fetch(l).then(U=>U.json()).then(U=>{!M&&U.success&&b(U.items||[])}).catch(()=>{}).finally(()=>{M||h(!1)}),()=>{M=!0}},[l,j]);const A=M=>{switch(M){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:o("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${o("widget-border")}`,marginBottom:"16px"},children:[t.jsx(Bt,{label:c.home.recommendTab,active:j==="recommend",onClick:()=>y("recommend")}),t.jsx(Bt,{label:c.home.catalogTab,active:j==="catalog",onClick:()=>y("catalog")}),t.jsx(Bt,{label:c.home.collectionTab,active:j==="collection",onClick:()=>y("collection")}),t.jsx(Bt,{label:c.home.siteTab,active:j==="site",onClick:()=>y("site")}),l&&t.jsx(Bt,{label:c.home.feedbackTab,active:j==="feedback",onClick:()=>y("feedback")})]}),j==="recommend"&&t.jsx(Yd,{recommended:d,loading:k,onNavigate:n,getIcon:A,t:c}),j==="catalog"&&t.jsx(So,{progress:v,t:c,onNavigate:n}),j==="collection"&&t.jsx(So,{progress:S,t:c,onNavigate:n}),j==="site"&&t.jsx(qd,{progress:T,t:c,totalWorks:(p==null?void 0:p.works)??0}),j==="feedback"&&l&&t.jsx(Ci,{items:m,loading:w})]})})},Bt=({label:e,active:n,onClick:i})=>t.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:o(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${o("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),Yd=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=Ne();if(n)return t.jsx(gt,{});if(e.length===0)return null;const c=new Map;for(const p of e){const a=p.group||s.home.recommendedBrowse;c.has(a)||c.set(a,[]),c.get(a).push(p)}return t.jsx(t.Fragment,{children:Array.from(c.entries()).map(([p,a])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:p}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return t.jsxs("a",{href:l(d.id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),i==null||i(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,cursor:"pointer",background:o("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},So=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(gt,{});const r=[...e.resources].sort((p,a)=>p.priority-a.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},c={in_progress:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(p=>{const a=r.filter(d=>d.status===p);return a.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:c[p]}}),l[p]," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>t.jsx(Kd,{item:d,t:n,statusColor:c[p],onNavigate:i},d.id))})]},p)})})},Kd=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=Ne(),l=e.total>0?Math.round(e.imported/e.total*100):0,c=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=e.edition?`${e.name}·${e.edition}`:e.name,a=e.collection_id||e.work_id;return a&&r?t.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:p}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:o("widget-border"),color:o("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:c})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Ht(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},qd=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(gt,{});const r=[...e.resources].sort((a,d)=>a.priority-d.priority),s=r.filter(a=>a.imported>0),l=r.filter(a=>a.imported===0),c=s.reduce((a,d)=>Math.max(a,d.imported),0),p=i>0?Math.round(c/i*100):0;return t.jsxs("div",{children:[i>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${o("primary")} 6%, transparent)`,fontSize:"13px",color:o("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:c.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>t.jsx(wo,{item:a,t:n,totalWorks:i},a.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(a=>t.jsx(wo,{item:a,t:n,totalWorks:i},a.id))})]})]})},wo=({item:e,t:n,totalWorks:i})=>{const r=i>0?Math.round(e.imported/i*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:t.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&i>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:o("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},_o="(max-width: 768px)";function Jd(){const[e,n]=g.useState(()=>typeof window>"u"?!1:window.matchMedia(_o).matches);return g.useEffect(()=>{const i=window.matchMedia(_o),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),e}const Zd=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var U;const l=ae(),{convert:c}=V(),p=Jd(),[a,d]=g.useState(null),[u,f]=g.useState(null),[x,m]=g.useState(!1),[b,w]=g.useState("detail"),[h,j]=g.useState([]),[y,k]=g.useState(!1),[_,v]=g.useState(null),[$,S]=g.useState(!1),z=g.useCallback(async G=>{if(!e.getCollatedEditionIndex){v(null);return}S(!0);try{const E=await e.getCollatedEditionIndex(G);v(E)}catch{v(null)}finally{S(!1)}},[e]),T=g.useCallback(async G=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){j([]);return}k(!0);try{if(e.getCollectionCatalogs){const E=await e.getCollectionCatalogs(G);j(E||[])}else if(e.getCollectionCatalog){const E=await e.getCollectionCatalog(G);j(E?[{resource_id:"",data:E}]:[])}}catch{j([])}finally{k(!1)}},[e]),R=g.useCallback(async G=>{if(i){i(G);return}d(G),f(null),j([]),v(null),w("detail"),m(!0);try{const E=await e.getItem(G.id);E&&(f(E),E.type==="collection"?T(G.id):E.type==="work"&&E.has_collated&&z(G.id))}catch(E){console.error("加载详情失败:",E)}finally{m(!1)}},[e,i,T,z]),C=g.useCallback(async G=>{f(null),j([]),v(null),w("detail"),m(!0);try{const E=await e.getItem(G);E&&(f(E),d({id:G,title:E.title||G,type:E.type||"book"}),E.type==="collection"?T(G):E.type==="work"&&E.has_collated&&z(G))}catch(E){console.error("导航失败:",E)}finally{m(!1)}},[e,T,z]),P=(u==null?void 0:u.type)==="collection"&&(h.length>0||y)||(u==null?void 0:u.type)==="work"&&(_||$),W=p&&(x||u),A=g.useCallback(()=>{d(null),f(null),j([]),v(null),w("detail")},[]),M=t.jsx(t.Fragment,{children:x?t.jsx(gt,{}):u?t.jsxs(t.Fragment,{children:[(P||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${o("widget-border")}`,padding:p?"0 12px":"0 48px",background:o("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[P&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>w("detail"),style:tn(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&y&&h.length===0&&t.jsxs("button",{onClick:()=>{},style:tn(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&h.map(G=>t.jsx("button",{onClick:()=>w(`catalog:${G.resource_id}`),style:tn(b===`catalog:${G.resource_id}`),children:G.short_name?`${c(G.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},G.resource_id)),u.type==="work"&&(_||$)&&t.jsxs("button",{onClick:()=>w("collated"),style:tn(b==="collated"),children:[l.detailTab.collatedEdition,$&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?t.jsx(ti,{data:u,transport:e,onNavigate:C}):b.startsWith("catalog:")?t.jsx(ni,{data:(U=h.find(G=>`catalog:${G.resource_id}`===b))==null?void 0:U.data,onNavigate:C}):b==="collated"?t.jsx(zi,{index:_||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(Hn,{transport:e,onNavigate:C,recommendedIds:r})});return p?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children: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:A,style:{padding:"4px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:M})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Nn,{transport:e,onEntryClick:R,hideModeIndicator:n}),!u&&t.jsx(Hn,{transport:e,onNavigate:C,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${o("widget-border")}`,display:"flex",flexDirection:"column",background:o("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(Nn,{transport:e,onEntryClick:R,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:M})]})};function tn(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function lt(e){return e.replace(/\.md$/,"")}function $o(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 zo={padding:24,color:o("desc-fg")},Gn=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:c,onVersionChange:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m,className:b,style:w})=>{const[h,j]=g.useState(e??null),[y,k]=g.useState(!1),[_,v]=g.useState(null),$=r!==void 0?r:_,S=g.useCallback(Z=>{s?s(Z):v(Z)},[s]),[z,T]=g.useState(null),[R,C]=g.useState(!1);g.useEffect(()=>{e&&j(e)},[e]),g.useEffect(()=>{if(e)return;j(null),k(!1);const Z=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!Z){k(!0);return}let O=!1;return Promise.resolve().then(Z).then(q=>{O||(q?j(q):k(!0))}).catch(()=>{O||k(!0)}),()=>{O=!0}},[n,i,e,l]),g.useEffect(()=>{if(!h||h.chapters.length===0)return;const Z=lt(h.chapters[0].file);if(!$){S(Z);return}const O=lt($);h.chapters.some(de=>lt(de.file)===O)||S(Z)},[h,$,S]);const P=g.useMemo(()=>{if(!h||!$)return null;const Z=lt($);return h.chapters.find(O=>lt(O.file)===Z)??null},[h,$]);g.useEffect(()=>{if(!n||!P)return;const Z=l!==void 0?i.getWorkFullTextChapter?q=>i.getWorkFullTextChapter(n,l,q):null:i.getBookFullTextChapter?q=>i.getBookFullTextChapter(n,q):null;if(!Z)return;let O=!1;return C(!0),T(null),Promise.resolve(P.file).then(Z).then(q=>{O||T(q)}).catch(()=>{O||T(null)}).finally(()=>{O||C(!1)}),()=>{O=!0}},[n,P,i,l]);const W=vs(u,P?lt(P.file):null),[A,M]=fi(),{convert:U}=V(),G=!!(c&&c.length>1&&p),E=g.useMemo(()=>G?ss(c).map((Z,O)=>({...Z,label:$o(c[O])})):void 0,[G,c]),ie=G?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:Z=>p(Z.target.value),children:c.map(Z=>t.jsx("option",{value:Z.key,children:$o(Z)},Z.key))})]}):null;if(!h)return t.jsxs("div",{style:zo,children:[ie&&t.jsx("div",{style:{marginBottom:12},children:ie}),y?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:zo,children:[ie&&t.jsx("div",{style:{marginBottom:12},children:ie}),"全文目录为空"]});const F=h.chapters.map(Z=>({key:lt(Z.file),label:U(Z.title)})),re=ds(h)||An(h),ce=z?z.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(gi,{title:a??U(h.version_label),subtitle:d??"全文",toc:F,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:$?lt($):null,onSelect:S,images:W.images,imagesLoading:W.loading,renderImageOverlay:f,imagePanel:x,prefs:A,onPrefsChange:M,versions:E,currentVersionKey:E?l??null:void 0,onVersionChange:E?p:void 0,versionSource:!1,paragraphToggle:hn(ce),allowVertical:m,className:b,style:w,children:[P&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:U(P.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:h.source.url,target:"_blank",rel:"noreferrer",children:U(h.source.name)}),h.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),h.source.license]})]})]}),R&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!R&&ce!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(vi,{text:ce,mode:A.readingMode,tables:re,gujiMarkdown:An(h),properNames:A.properNames})}),!R&&!z&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},Xd=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=ae(),{convert:l}=V(),[c,p]=g.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[a,d]=g.useState(null);return t.jsxs("div",{className:i,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:l(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[s.catalog.totalVolumes," ",t.jsx("strong",{children:e.total_volumes})," ",s.unit.juan]}),e.stats.zhulu!=null&&t.jsxs("span",{children:["著錄 ",t.jsx("strong",{children:e.stats.zhulu})," ",s.unit.bu]}),e.stats.cunmu!=null&&t.jsxs("span",{children:["存目 ",t.jsx("strong",{children:e.stats.cunmu})," ",s.unit.bu]}),e.stats.categories!=null&&t.jsxs("span",{children:[e.stats.categories," 類"]})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(f=>t.jsx(Qd,{division:f,expanded:c===f.name,onToggle:()=>p(c===f.name?null:f.name),expandedCat:a,onCatToggle:x=>d(a===x?null:x),onNavigate:n},f.name))})]})},Qd=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:c}=V(),p=e.categories.reduce((a,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return a+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${o("primary")} 6%, transparent)`:o("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:o("fg"),textAlign:"left"},children:[t.jsx("span",{children:c(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg")},children:[e.categories.length," 類 · ",p," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(a=>{const d=`${e.name}/${a.name}`;return t.jsx(ep,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:l},a.name)})})]})},ep=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var a,d,u,f;const{convert:s}=V(),l=((a=e.books)==null?void 0:a.zhulu)||[],c=((d=e.books)==null?void 0:d.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((f=e.stats)==null?void 0:f.cunmu)||c.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?o("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:o("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||c.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Co,{label:"著錄",books:l,onNavigate:r}),c.length>0&&t.jsx(Co,{label:"存目",books:c,onNavigate:r})]})]})},Co=({label:e,books:n,onNavigate:i})=>{const{convert:r}=V(),s=Ne(),[l,c]=g.useState(n.length<=20),p=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((a,d)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:o("fg")},children:a.work_id&&i?t.jsx("a",{href:s(a.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},children:r(a.title)}):r(a.title)}),a.volumes&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.volumes)}),a.author&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.author).slice(0,20)})]},d))}),!l&&t.jsxs("button",{onClick:()=>c(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},Ge=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=ae();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:o("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&t.jsx("button",{onClick:i,style:np,children:"AI"}),n&&t.jsx("button",{onClick:n,style:tp,children:l.action.save})]})]}),s]})},tp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},np={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Pe=({label:e,value:n,onChange:i,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:l=>i(l.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),xt=({value:e,onChange:n,placeholder:i})=>{const r=g.useRef(null);return g.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},cn=({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 ip(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const on=({value:e,onChange:n,label:i})=>{const[r,s]=g.useState(!1),l=g.useRef(null),c=ip(e||"");return g.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&c?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Io,children:i}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${o("input-border")}`,borderRadius:"2px",background:o("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:o("fg")},children:c.name}),t.jsx(cn,{children:c.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Io,children:i}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Io={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function op(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function rp(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const _s=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=ae(),[s,l]=g.useState(null),c=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},p=f=>{n(e.filter((x,m)=>m!==f)),s===f&&l(null)},a=(f,x,m)=>{const b=[...e];b[f]={...b[f],[x]:m},n(b)},d=(f,x)=>{const m=[...e];m[f]={...m[f],type:x,id:"",name:""},n(m),x==="bookID"&&i&&i(b=>{const w=[...e];w[f]={...w[f],id:b.id,name:b.title,type:"bookID"},n(w)})},u=f=>{i&&i(x=>{const m=[...e];m[f]={...m[f],id:x.id,name:x.title,type:"bookID"},n(m)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((f,x)=>t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===x?null:x),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===x?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:o("fg")},children:f.name||`${r.editor.sourcePlaceholder} ${x+1}`}),f.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:op(f.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:rp(f.type)}),t.jsx("button",{onClick:m=>{m.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===x&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!f.type&&t.jsxs("div",{children:[t.jsx("label",{style:et,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>d(x,"bookID"),style:{...To,borderColor:o("source-bookid"),color:o("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>d(x,"url"),style:{...To,borderColor:o("source-url"),color:o("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),f.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:et,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Ro,children:r.action.changeType})]}),f.id&&f.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:o("bg"),border:`1px solid ${o("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:o("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:f.name}),t.jsx("code",{style:{fontSize:"11px",background:o("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:f.id})]}),t.jsx("button",{onClick:()=>u(x),style:{background:"transparent",border:`1px solid ${o("widget-border")}`,color:o("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(x),style:{width:"100%",padding:"14px",border:`2px dashed ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),f.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:et,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Ro,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:f.name,onChange:m=>a(x,"name",m.target.value),placeholder:r.editor.sourceNamePlaceholder,style:ht})]}),t.jsxs("div",{children:[t.jsx("label",{style:et,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:f.id,onChange:m=>a(x,"id",m.target.value),placeholder:"https://...",style:ht})]})]}),f.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${o("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...et,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:et,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:f.details,onChange:m=>a(x,"details",m.target.value),placeholder:r.editor.detailsPlaceholder,style:ht})]}),t.jsxs("div",{children:[t.jsx("label",{style:et,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:f.position,onChange:m=>a(x,"position",m.target.value),placeholder:"如: 卷三, p.52",style:ht})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:et,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:f.version,onChange:m=>a(x,"version",m.target.value),placeholder:"如: v1.0, 2024-01",style:ht})]}),t.jsxs("div",{children:[t.jsx("label",{style:et,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:f.processor_version,onChange:m=>a(x,"processor_version",m.target.value),placeholder:"如: v0.1",style:ht})]})]})]})]})})]},x)),t.jsxs("button",{onClick:c,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},et={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},ht={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},To={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"},Ro={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function $s(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 zs(e){return!e||e.length===0?"":JSON.stringify(e)}const Cs=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:c,childWorks:p,childCollections:a,containedBooks:d,siblingBooks:u,onLinkEntity:f,onUnlinkEntity:x,onViewEntity:m,onCreateAndLink:b,onSaveRelations:w})=>{const h=ae();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:h.section.relations})]}),w&&t.jsx("button",{onClick:w,style:sp,children:h.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(At,{direction:"up",title:h.relation.belongsToWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>f("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(At,{direction:"up",title:h.relation.containedInCollection,entity:c,onView:m,onUnlink:()=>x("collectionId"),onLink:()=>f("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),l&&u&&u.length>0&&t.jsx(bt,{direction:"horizontal",title:`${h.relation.siblingVersions} (${u.length})`,entities:u,onView:m,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(At,{direction:"up",title:h.relation.parentWork,entity:r,onView:m,onUnlink:()=>x("parentWorkId"),onLink:()=>f("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),p&&p.length>0&&t.jsx(bt,{direction:"down",title:`${h.relation.childWorks} (${p.length})`,entities:p,onView:m,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),a&&a.length>0&&t.jsx(bt,{direction:"down",title:`${h.relation.collectionImpl} (${a.length})`,entities:a,onView:m,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(bt,{direction:"down",title:`${h.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>b("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(At,{direction:"up",title:h.relation.correspondingWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>f("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(At,{direction:"up",title:h.relation.parentCollection,entity:s,onView:m,onUnlink:()=>x("parentCollectionId"),onLink:()=>f("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(bt,{direction:"down",title:`${h.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:m,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(bt,{direction:"down",title:`${h.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},At=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:c,linkLabel:p,createLabel:a,notLinkedLabel:d,viewLabel:u,unlinkLabel:f})=>{const x=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:o("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Is(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(Eo,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(Eo,{onClick:s,title:f,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(Un,{onClick:l,children:p}),t.jsx(Un,{onClick:c,primary:!0,children:a})]})]})},bt=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:c,expandMoreLabel:p})=>{const[a,d]=g.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),f=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=a?i:i.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:f}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[x.map(m=>t.jsxs("div",{onClick:()=>r(m),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:o("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:Is(m.type)}),t.jsx("span",{children:m.title})]},m.id)),i.length>5&&!a&&t.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:o("link-fg"),cursor:"pointer"},children:[p," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:c}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(Un,{onClick:s,primary:!0,children:["+ ",l]})})]})},Eo=({onClick:e,title:n,danger:i,children:r})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?o("danger"):"inherit",opacity:.7},children:r}),Un=({onClick:e,primary:n,children:i})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${o("widget-border")}`,borderRadius:"4px",background:n?o("primary"):"transparent",color:n?o("primary-fg"):"inherit",cursor:"pointer"},children:i});function Is(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const sp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Ts=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:c,onSearch:p,isLoading:a,excludeId:d})=>{const[u,f]=g.useState(""),x=d?c.filter(h=>h.id!==d):c;g.useEffect(()=>{e&&(f(""),p(""))},[e]);const m=h=>{f(h),p(h)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",w=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:lp,children:t.jsxs("div",{style:ap,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:cp,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:h=>m(h.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:dp})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?t.jsx("div",{style:_n,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(h=>t.jsxs("div",{onClick:()=>r(h),style:pp,children:[t.jsx("span",{style:{fontSize:"16px"},children:w}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):u?t.jsxs("div",{style:_n,children:["未找到匹配的",b]}):t.jsxs("div",{style:_n,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:up,children:["创建新",b,"并关联"]})]})]})})},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",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},cp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},dp={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"},pp={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:o("primary-soft")},_n={padding:"20px",textAlign:"center",color:o("desc-fg")},up={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},No={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},xp={work:"📜",book:"📖",collection:"📚",entity:"👤"},Rs=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[c,p]=g.useState(""),a=g.useRef(null);g.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,m;(x=a.current)==null||x.focus(),(m=a.current)==null||m.select()},100))},[e,r==null?void 0:r.title]);const d=x=>{x.key==="Enter"&&c.trim()?u():x.key==="Escape"&&l()},u=()=>{c.trim()&&s(c.trim(),{...r,title:c.trim()})};if(!e)return null;const f=()=>{switch(i){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${No[n]}`}};return t.jsx("div",{style:fp,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:gp,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:xp[n]}),t.jsx("span",{children:f()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:o("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:o("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:a,type:"text",value:c,onChange:x=>p(x.target.value),onKeyDown:d,placeholder:`请输入${No[n]}名称...`,style:mp})]}),((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:hp,children:"取消"}),t.jsx("button",{onClick:u,disabled:!c.trim(),style:{...bp,opacity:c.trim()?1:.6,cursor:c.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},fp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},gp={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")},mp={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"},hp={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},bp={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function yp(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Es(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function jp(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 Ns=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:c,onSelect:p,onCancel:a,onCreate:d,onSearch:u})=>{const[f,x]=g.useState(""),[m,b]=g.useState([]),[w,h]=g.useState(!1),[j,y]=g.useState("recent");g.useEffect(()=>{e&&(x(""),b([]),y(r.length>0?"recent":"search"))},[e,r.length]),g.useEffect(()=>{if(!f.trim()){b([]);return}const z=setTimeout(async()=>{h(!0);try{b(await u(f,i))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(z)},[f,i,u]);const k=g.useCallback(z=>{x(z.target.value),z.target.value.trim()&&y("search")},[]),_=g.useCallback(z=>s?z.filter(T=>T.id!==s):z,[s]);if(!e)return null;const v=n||(i==="all"?"选择实体":`选择${Es(i)}`),$=_(r),S=_(m);return t.jsx("div",{style:kp,children:t.jsxs("div",{style:Sp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:v}),t.jsx("button",{onClick:a,style:wp,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:f,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:_p}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),w&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),$.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs(Lo,{active:j==="recent",onClick:()=>y("recent"),children:["最近使用 (",$.length,")"]}),t.jsxs(Lo,{active:j==="search",onClick:()=>y("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&$.length>0?t.jsx(Bo,{entities:$,onSelect:p}):f.trim()?w?t.jsx($n,{message:"搜索中..."}):S.length>0?t.jsx(Bo,{entities:S,onSelect:p}):t.jsx($n,{message:"未找到匹配的结果"}):t.jsx($n,{message:"输入关键词开始搜索"})}),l&&d&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:d,style:$p,children:c||"创建新实体"})]})]})})},Lo=({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}),Bo=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(vp,{entity:i,onClick:()=>n(i)},i.id))}),vp=({entity:e,onClick:n})=>{const[i,r]=g.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:yp(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:jp(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Es(e.type)})]})},$n=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),kp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Sp={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")},wp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},_p={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"},$p={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},zp={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},Cp={work:"📜",collection:"📚",book:"📖",entity:"👤"},Ls=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:c,onAskAI:p,renderSectionActions:a,onDownloadResource:d,downloadStatuses:u,relations:f,onRelationsChange:x})=>{var te;const m=ae(),[b,w]=g.useState(!1),[h,j]=g.useState("work"),[y,k]=g.useState(""),[_,v]=g.useState(""),[$,S]=g.useState([]),[z,T]=g.useState(!1),[R,C]=g.useState(!1),[P,W]=g.useState("work"),[A,M]=g.useState(""),[U,G]=g.useState(),[E,ie]=g.useState(!1),[F,re]=g.useState(null),[ce,Z]=g.useState([]);g.useRef(null);const O=e.type,q=O==="work",de=O==="collection",se=O==="book",ee=g.useCallback((N,ne)=>{n({...e,[N]:ne})},[e,n]),D=g.useCallback((N,ne)=>{k(N),j(ne),v(m.editor.selectToLink+m.indexType[ne]),S([]),w(!0)},[m]),Y=g.useCallback(N=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,N)},[r,e.id]),Q=g.useCallback(N=>{s==null||s(N.id,N.type)},[s]),L=g.useCallback((N,ne,oe)=>{const be={...oe,author:(oe==null?void 0:oe.author)||e.author,dynasty:oe==null?void 0:oe.dynasty};W(ne),M(N),G(be),C(!0)},[e.author]),I=g.useCallback((N,ne)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,A,{type:P,title:N,inheritData:ne}),C(!1)},[r,e.id,A,P]),K=g.useCallback(N=>{if(!N.trim()){S([]);return}T(!0),r!=null&&r.searchEntities&&r.searchEntities(N,h).then(ne=>{S(ne),T(!1)}).catch(()=>{S([]),T(!1)})},[r,h]),X=g.useCallback(N=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,y,N.id),w(!1)},[r,e.id,y]),ue=g.useCallback(()=>{i()},[i]),xe=g.useCallback(N=>{re(()=>N),ie(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Z).catch(()=>{})},[r]),ve=g.useCallback((N,ne)=>r!=null&&r.searchEntities?r.searchEntities(N,ne==="all"?void 0:ne):Promise.resolve([]),[r]),_e=g.useCallback(N=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(N),Z(ne=>[N,...ne.filter(oe=>oe.id!==N.id)].slice(0,10)),F==null||F(N),ie(!1),re(null)},[r,F]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${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:Cp[O]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(cn,{children:e.id}),t.jsx(cn,{color:zp[O],children:m.indexType[O]})]})}),t.jsx(Ge,{title:m.section.basicInfo,onSave:i,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(on,{label:q?m.editor.workTitle:de?m.editor.collectionTitle:m.editor.bookTitle,value:e.title,onChange:N=>ee("title",N)}),se&&t.jsx(on,{label:m.editor.belongsToWork,value:e.workName||"",onChange:N=>ee("workName",N)}),t.jsx(Pe,{label:m.editor.authorLabel,value:e.author||"",onChange:N=>ee("author",N)}),t.jsx(Pe,{label:m.editor.publicationYearLabel,value:e.publicationYear||"",onChange:N=>ee("publicationYear",N)}),(se||de)&&t.jsx(on,{label:m.editor.containedIn,value:e.collection||"",onChange:N=>ee("collection",N)}),(se||de)&&t.jsx(Pe,{label:m.editor.holderLabel,value:e.holder||"",onChange:N=>ee("holder",N)}),(se||de)&&t.jsx(Pe,{label:se?m.editor.pageLabel:m.editor.volumeLabel,value:e.pages||"",onChange:N=>ee("pages",N)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(Pe,{label:m.editor.firstImageLabel,value:e.firstImage||"",onChange:N=>ee("firstImage",N)})})]})}),t.jsx(Ge,{title:m.section.description,onSave:i,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(xt,{value:e.description||"",onChange:N=>ee("description",N),placeholder:m.editor.descriptionPlaceholder})}),(((te=e.additional_works)==null?void 0:te.length)||0)>0&&t.jsx(Ge,{title:m.section.additionalWorks,onSave:i,children:t.jsx(Ip,{items:e.additional_works||[],onChange:N=>ee("additional_works",N)})}),t.jsx(Ge,{title:m.section.indexedBy,onSave:i,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Tp,{items:e.indexed_by||[],onChange:N=>ee("indexed_by",N)})}),t.jsx(Ge,{title:m.section.emendatedBy,onSave:i,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Rp,{items:e.emendated_by||[],onChange:N=>ee("emendated_by",N)})}),t.jsx(Ge,{title:m.section.textResources,onSave:i,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(En,{items:e.resources||[],onChange:N=>ee("resources",N),onDownload:d,downloadStatuses:u,filterType:"text"})}),t.jsx(Ge,{title:m.section.imageResources,onSave:i,children:t.jsx(En,{items:e.resources||[],onChange:N=>ee("resources",N),onDownload:d,downloadStatuses:u,filterType:"image"})}),t.jsx(Ge,{title:m.section.sources,onSave:i,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(_s,{items:$s(e.sources||""),onChange:N=>ee("sources",zs(N)),onOpenEntityPicker:xe})}),(se||de)&&t.jsx(Ge,{title:m.section.provenance,onSave:i,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(xt,{value:e.provenance||"",onChange:N=>ee("provenance",N),placeholder:m.editor.provenancePlaceholder})}),se&&t.jsx(Ge,{title:m.section.otherEditions,onSave:i,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(xt,{value:e.otherEditions||"",onChange:N=>ee("otherEditions",N),placeholder:m.editor.otherEditionsPlaceholder})}),t.jsx(Cs,{entityType:O,entityId:e.id,entityTitle:e.title,parentWork:f==null?void 0:f.parentWork,parentCollection:f==null?void 0:f.parentCollection,belongsToWork:f==null?void 0:f.belongsToWork,belongsToCollection:f==null?void 0:f.belongsToCollection,childWorks:f==null?void 0:f.childWorks,childCollections:f==null?void 0:f.childCollections,containedBooks:f==null?void 0:f.containedBooks,siblingBooks:f==null?void 0:f.siblingBooks,onLinkEntity:D,onUnlinkEntity:Y,onViewEntity:Q,onCreateAndLink:L,onSaveRelations:ue}),l&&c&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${o("danger-soft-border")}`,background:o("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:o("danger"),fontWeight:600,marginBottom:"8px"},children:m.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"12px"},children:m.editor.dangerZoneDesc}),t.jsx("button",{onClick:c,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("danger")}`,borderRadius:"4px",background:"transparent",color:o("danger"),cursor:"pointer"},children:m.editor.deleteEntity})]}),t.jsx(Ts,{isOpen:b,entityType:h,title:_,onSelect:X,onCancel:()=>w(!1),onCreate:()=>{w(!1),L(y,h)},searchResults:$,onSearch:K,isLoading:z,excludeId:e.id}),t.jsx(Rs,{isOpen:R,entityType:P,relationField:A,inheritData:U,onConfirm:I,onCancel:()=>C(!1)}),t.jsx(Ns,{isOpen:E,title:m.action.selectBookOrWork,filterType:"all",recentEntities:ce,excludeId:e.id,onSelect:_e,onCancel:()=>{ie(!1),re(null)},onSearch:ve})]})};function Ip({items:e,onChange:n}){const i=ae(),r=(c,p,a)=>{const d=e.map((u,f)=>f===c?{...u,[p]:a}:u);n(d)},s=c=>n(e.filter((p,a)=>a!==c)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((c,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(Pe,{label:i.editor.bookNameLabel,value:c.book_title,onChange:a=>r(p,"book_title",a)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(Pe,{label:i.label.juanCount,value:c.n_juan!=null?String(c.n_juan):"",onChange:a=>r(p,"n_juan",a&&parseInt(a,10)||void 0)})}),t.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Bs({items:e,onChange:n,showMeta:i,addLabel:r}){const s=ae(),[l,c]=g.useState(null),p=(u,f,x)=>{const m=e.map((b,w)=>w===u?{...b,[f]:x||void 0}:b);n(m)},a=u=>{n(e.filter((f,x)=>x!==u)),l===u&&c(null)},d=()=>{n([...e,{source:""}]),c(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,f)=>{const x=l===f;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:x?`color-mix(in srgb, ${o("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>c(x?null:f),children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.2s",transform:x?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:m=>{m.stopPropagation(),a(f)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${o("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:o("muted")},children:"✕"})]}),!x&&i&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:o("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),x&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Pe,{label:s.label.sourceName,value:u.source,onChange:m=>p(f,"source",m)}),t.jsx(Pe,{label:s.label.sourceBid,value:u.source_bid||"",onChange:m=>p(f,"source_bid",m)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Pe,{label:s.label.titleInfo,value:u.title_info||"",onChange:m=>p(f,"title_info",m)}),t.jsx(Pe,{label:s.label.authorInfo,value:u.author_info||"",onChange:m=>p(f,"author_info",m)})]}),t.jsx(Pe,{label:s.label.edition,value:u.edition||"",onChange:m=>p(f,"edition",m)})]}),t.jsx(xt,{value:u.summary||"",onChange:m=>p(f,"summary",m),placeholder:s.editor.summaryPlaceholder}),t.jsx(xt,{value:u.comment||"",onChange:m=>p(f,"comment",m),placeholder:s.editor.commentPlaceholder}),t.jsx(xt,{value:u.additional_comment||"",onChange:m=>p(f,"additional_comment",m),placeholder:s.editor.additionalCommentPlaceholder})]})]},f)}),t.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Tp({items:e,onChange:n}){const i=ae();return t.jsx(Bs,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Rp({items:e,onChange:n}){const i=ae();return t.jsx(Bs,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function As(e){var p,a,d,u,f,x,m;const n=((a=(p=e.authors)==null?void 0:p[0])==null?void 0:a.name)||"",i=((d=e.publication_info)==null?void 0:d.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(f=e.page_count)!=null&&f.number?String(e.page_count.number):((x=e.page_count)==null?void 0:x.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",c={id:e.id,title:e.title,type:e.type,author:n,publicationYear:i,holder:r,pages:s,description:l,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const b=e;if(Array.isArray(b.related_works)){const w=b.related_works.find(h=>h.relation==="part_of");w&&(c.parentWorkId=w.id,c.parentWorkName=w.title)}}if(e.type==="book"){const b=e;c.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(c.collectionId=(m=b.contained_in[0])==null?void 0:m.id)}return c}function Ep(e){const n={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.publicationYear?{year:e.publicationYear}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(n.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(n.work_id=e.workId,e.collectionId&&(n.contained_in=[{id:e.collectionId}])),n}const Np=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:c,onSave:p,onDelete:a,onNavigate:d,renderLink:u,onAskAI:f,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:w,onRelationsChange:h,headerExtra:j,className:y,style:k}=e;ae();const[_,v]=g.useState(s),$=l?s:_;g.useEffect(()=>{s!==_&&v(s)},[s]);const S=g.useCallback(()=>{const A=$==="view"?"edit":"view";l?l(A):v(A)},[$,l]),[z,T]=g.useState(null);g.useEffect(()=>{i&&r&&r.getItem(i).then(A=>{A&&T(A)})},[i,r]);const R=n||z,C=g.useMemo(()=>R?As(R):null,[R]),P=l||!n?t.jsx("button",{onClick:S,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:[P,j]});return!R&&!C?t.jsx(gt,{}):$==="view"?t.jsx(ti,{data:R,transport:r,onNavigate:d?A=>d(A):void 0,renderLink:u,headerExtra:W,className:y,style:k}):C?t.jsxs("div",{className:y,style:k,children:[W&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:W}),t.jsx(Ls,{data:C,onChange:c||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:f,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:w,onRelationsChange:h})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},Ao=[{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]=g.useState(null),[c,p]=g.useState(""),[a,d]=g.useState(""),[u,f]=g.useState("idle"),[x,m]=g.useState(""),b=g.useRef(null);g.useEffect(()=>{e&&(l(null),p(""),d(""),f("idle"),m(""))},[e]),g.useEffect(()=>{s&&setTimeout(()=>{var y;return(y=b.current)==null?void 0:y.focus()},100)},[s]),g.useEffect(()=>{if(u==="success"){const y=setTimeout(n,2e3);return()=>clearTimeout(y)}},[u,n]),g.useEffect(()=>{if(!e)return;const y=k=>{k.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[e,n]);const w=async()=>{if(!(!s||!c.trim())){f("submitting"),m("");try{await i({type:s,content:c.trim(),...a.trim()?{contact:a.trim()}:{}}),f("success")}catch(y){f("error"),m(y instanceof Error?y.message:"提交失败,请稍后重试")}}};if(!e)return null;const h=s&&c.trim()&&u!=="submitting",j=Ao.find(y=>y.value===s);return t.jsx("div",{style:Lp,onClick:y=>{y.target===y.currentTarget&&n()},children:t.jsxs("div",{style:Bp,onClick:y=>y.stopPropagation(),children:[t.jsxs("div",{style:Ap,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:Wp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:Dp,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:o("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Ao.map(y=>t.jsxs("button",{onClick:()=>l(y.value),style:{...Mp,...s===y.value?Fp:{}},children:[t.jsx("span",{children:y.icon})," ",y.label]},y.value))}),t.jsx("textarea",{ref:b,value:c,onChange:y=>p(y.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...Pp,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:a,onChange:y=>d(y.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:Gp}),t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[c.length," / 2000"]}),u==="error"&&t.jsx("div",{style:Hp,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:w,disabled:!h,style:{...Op,opacity:h?1:.6,cursor:h?"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},Bp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},Ap={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Wp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:o("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Mp={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"},Fp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},Pp={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"},Op={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},Dp={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},Hp={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Gp={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},Vn="--bim-feedback-fab-offset",Yn=48,Up=16,Vp=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,c]=g.useState(!1),p=n.bottom??24;return g.useEffect(()=>{if(r||typeof document>"u")return;const a=document.documentElement;return a.style.setProperty(Vn,`calc(${p+Yn+Up}px + env(safe-area-inset-bottom, 0px))`),()=>{a.style.removeProperty(Vn)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>c(!0),style:{...Yp,zIndex:s??o("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(Ws,{isOpen:l,onClose:()=>c(!1),onSubmit:e,feedbackListUrl:i})]})},Yp={position:"fixed",width:`${Yn}px`,height:`${Yn}px`,borderRadius:"50%",border:"none",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:o("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},Wo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ms=({onSubmit:e})=>{const[n,i]=g.useState("bug"),[r,s]=g.useState(""),[l,c]=g.useState(""),[p,a]=g.useState("idle"),[d,u]=g.useState(""),f=g.useRef(null);g.useEffect(()=>{n&&setTimeout(()=>{var w;return(w=f.current)==null?void 0:w.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){a("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),a("success"),s(""),c(""),i("bug")}catch(w){a("error"),u(w instanceof Error?w.message:"提交失败,请稍后重试")}}},m=n&&r.trim()&&p!=="submitting",b=Wo.find(w=>w.value===n);return p==="success"?t.jsx("div",{style:Mo,children:t.jsxs("div",{style:Xp,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>a("idle"),style:Qp,children:"继续提交"})]})}):t.jsxs("div",{style:Mo,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Wo.map(w=>t.jsxs("button",{onClick:()=>i(w.value),style:{...Kp,...n===w.value?qp:{}},children:[t.jsx("span",{children:w.icon})," ",w.label]},w.value))}),t.jsx("textarea",{ref:f,value:r,onChange:w=>s(w.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...Jp}}),t.jsx("input",{type:"text",value:l,onChange:w=>c(w.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:tu}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:x,disabled:!m,style:{...Zp,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:eu,children:d})]})},Mo={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},Kp={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"},qp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},Jp={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"},Zp={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},Xp={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},Qp={background:"none",border:"none",color:o("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},eu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginTop:"8px"},tu={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 Fo(e){return typeof e=="function"?e():e??"/api/feedback"}const Fs=({resourceId:e,apiUrl:n})=>{const[i,r]=g.useState([]),[s,l]=g.useState(!0),c=g.useCallback(async()=>{const a=Fo(n);l(!0);try{const u=await(await fetch(`${a}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);g.useEffect(()=>{c()},[c]);const p=async a=>{const d=Fo(n),u=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const f=await u.json().catch(()=>null);throw new Error((f==null?void 0:f.error)||"提交失败")}setTimeout(()=>c(),500)};return t.jsxs("div",{children:[t.jsx(Ci,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Ms,{onSubmit:p})})]})},Po={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 nu(e){return e?Po[e]??e:Po.related}const iu={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function ou(e){return iu[e]??e}const ru={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function su(e){return ru[e]??""}function Ii({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,c)=>{const p=li(l.role);return t.jsxs(g.Fragment,{children:[c>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Ie,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:i,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},c)})}):null}function Ps(e,n){var p,a;const i=ri(e,n),r=i.mirrors.map(d=>({key:d.key,label:d.label,description:d.description,rows:d.items.filter(u=>u.group_role!=="mirror"),mirrors:d.items.filter(u=>u.group_role==="mirror")})),s=i.buckets.filter(d=>d.key==="image"||d.key==="textImage").flatMap(d=>d.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=i.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((a=i.buckets.find(d=>d.key==="text"))==null?void 0:a.items)??[],groups:r}}function Os(e,n){const i=(e.url?zt(e.url):void 0)||e.name,r=zr(e,n);return r?`${i}(${r})`:i}function Ti({item:e,siblings:n,listedVolumeCounts:i}){const{convert:r}=V(),[s,l]=g.useState(!1),c=dn(e),p=!!c&&c.expected>0&&!(i!=null&&i.has(c.expected)),a=r(Os(e,n)),d=Ct(e),u=fn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[a," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:a}),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(pi,{item:e})})]}),t.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(f=>!f),children:r(s?"收起分冊":`展開 ${c.expected} 冊`)})})]})}function Ds({groups:e,listedVolumeCounts:n}){const{convert:i}=V();return t.jsx(t.Fragment,{children:e.map(r=>t.jsxs("div",{className:"bim-d-rg",children:[r.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:i(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:i(r.description)}),r.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:r.rows.map((s,l)=>t.jsx(Ti,{item:s,siblings:r.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),r.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[r.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:i("鏡像")}),r.mirrors.map((s,l)=>{const c=Ct(s),p=i(Os(s,r.mirrors));return c?t.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",title:s.details?i(s.details):void 0,children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:p},l)})]})]},r.key))})}const Oo=12,lu=60,Hs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:c,railLinks:p})=>{var Y,Q,L;const a=ae(),{convert:d}=V(),u=g.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[f,x]=g.useState(new Map),[m,b]=g.useState(!1),[w,h]=g.useState(""),[j,y]=g.useState(!1),k=u.length<=lu,_=k||m||!!w||j,v=g.useMemo(()=>_?u:u.slice(0,Oo),[u,_]);g.useEffect(()=>{if(!n||v.length===0)return;const I=v.filter(X=>!f.has(X));if(I.length===0)return;let K=!1;return Promise.all(I.map(X=>n.getItem(X).then(ue=>{const xe=ue??{};return[X,{id:X,title:xe.title,edition:xe.edition,resources:xe.resources,publication_info:xe.publication_info,current_location:xe.current_location,lineage:xe.lineage,measure_info:xe.measure_info}]}).catch(()=>[X,{id:X}]))).then(X=>{K||x(ue=>{const xe=new Map(ue);for(const[ve,_e]of X)xe.set(ve,_e);return xe})}),()=>{K=!0}},[n,v,f]);const $=g.useMemo(()=>u.map(I=>f.get(I)??{id:I}),[u,f]),S=u.length>0&&u.every(I=>f.has(I)),z=!!n&&v.some(I=>!f.has(I)),T=k||_,R=g.useMemo(()=>Ir($,e.version_graph,{era:w,scanOnly:j,sort:T?"year":"default"}),[$,e.version_graph,w,j,T]),C=m?R.rows:R.rows.slice(0,Oo),P=R.allRows.filter(I=>I.hasImage).length,W=e.related_works||[],A=W.filter(I=>I.relation==="collected_in"),M=g.useMemo(()=>{const I=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],K=X=>{const ue=I.indexOf(X??"");return ue<0?I.length:ue};return W.filter(X=>X.relation!=="collected_in").map((X,ue)=>({r:X,i:ue})).sort((X,ue)=>K(X.r.relation)-K(ue.r.relation)||X.i-ue.i).map(X=>X.r)},[W]),U=g.useMemo(()=>{const I=ri(e.resources,e.resource_groups);return[...I.mirrors.flatMap(K=>K.items.map(X=>({r:X,kind:d(K.label)}))),...I.buckets.flatMap(K=>K.items.map(X=>({r:X,kind:d(su(K.key))})))]},[e.resources,e.resource_groups,d]),G=e.indexed_by||[],E=e.emendated_by||[],ie=g.useMemo(()=>{var ne,oe,be;const I=[],K=(oe=(ne=e.authors)==null?void 0:ne[0])==null?void 0:oe.dynasty;K&&I.push({label:"成書",value:d(K)});const X=ot(e,a.unit.juan);if(X){const fe=(be=e.juan_count)==null?void 0:be.description;I.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[d(X),fe&&fe!==X?t.jsxs("span",{className:"bim-d-meta",children:["(",d(fe),")"]}):null]})})}e.loss_status&&I.push({label:"存佚",value:d(ou(e.loss_status))});const ue=e._edition_count??u.length;ue&&I.push({label:"版本",value:t.jsxs(t.Fragment,{children:[ue," ",d("種"),S&&P?t.jsxs("span",{className:"bim-d-meta",children:[" ",d(`${P} 種有影印`)]}):null]})});const xe=R.allRows.filter(fe=>fe.sortYear!=null),ve=xe.length>0?xe.reduce((fe,$e)=>fe.sortYear<=$e.sortYear?fe:$e):null;ve!=null&&ve.era.era?I.push({label:"最早存世",value:d([ve.era.era,ve.era.reign].filter(Boolean).join(" ")),title:ve.era.source==="edition"?d("據版本題名推斷"):void 0}):z&&I.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),(G.length||E.length)&&I.push({label:"著錄",value:t.jsxs(t.Fragment,{children:[G.length?`${G.length} ${d("家")}`:"—",E.length?t.jsxs("span",{className:"bim-d-meta",children:[" ",d(`考證 ${E.length} 條`)]}):null]})});const _e=Do(e.additional_titles);_e.length&&I.push({label:"又名",value:_e.map(d).join("、")});const te=Do(e.attached_texts);te.length&&I.push({label:"附載",value:te.map(d).join("、")});const N=(e.additional_works||[]).map(fe=>d(fe.book_title)+(fe.n_juan!=null?` ${fe.n_juan}${d(a.unit.juan)}`:""));return N.length&&I.push({label:"附錄",value:N.join("、")}),I},[e,d,a,u.length,S,z,P,R.allRows,G.length,E.length]),F=e.classification,re=F?[F.l1,F.l2,F.l3,F.l4].filter(Boolean).map(I=>d(I)):[],ce=e.subtype?d(a.workSubtype[e.subtype]??e.subtype):"",Z=t.jsx(Vt,{title:d(e.title),byline:t.jsx(Ii,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(Re,{items:[...re,F!=null&&F.source?d(`據《${F.source.split("/")[0]}》`):"",ce]}),description:(Y=e.description)!=null&&Y.text?t.jsxs(t.Fragment,{children:[t.jsx(it,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Q=e.description.sources)!=null&&Q.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(I=>d(Ua(I))).filter(Boolean).join(" · ")}):null]}):void 0,facts:ie,readAction:s,foot:t.jsx(Yt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(L=e.appendix)==null?void 0:L.map((I,K)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(I.title)}),t.jsx(it,{text:I.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},K))}),O=R.eras.length>=2?[{key:"",label:a.catalog.all},...R.eras.map(I=>({key:I,label:I}))]:[],q=[];u.length&&q.push({id:"versions",label:"版本",count:u.length}),G.length&&q.push({id:"catalogs",label:"著錄",count:G.length}),A.length&&q.push({id:"collected",label:"收入叢編",count:A.length}),M.length&&q.push({id:"related",label:"相關書目",count:M.length}),U.length&&q.push({id:"resources",label:"在線資源",count:U.length});const de=u.length===0&&G.length===0,se=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Ee,{id:"versions",title:"版本",meta:t.jsx(Re,{items:[d(`共 ${u.length} 種`),S&&P?d(`${P} 種有影印`):"",R.rows.length!==R.allRows.length?d(`當前 ${R.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&O.length===0&&u.length>1?"":void 0,children:[O.length>0&&t.jsx(ai,{items:O,value:w,onChange:I=>{h(I),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Or,{label:"只看有影印",checked:j,onChange:I=>{y(I),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:d(T?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("版本")}),t.jsx("th",{children:d("年代")}),t.jsx("th",{children:d("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:d("影印")})})]})}),t.jsx("tbody",{children:C.map(I=>{var K;return t.jsx(au,{row:I,measure:(K=f.get(I.id))==null?void 0:K.measure_info,loaded:f.has(I.id),onNavigate:i,renderLink:r},`${I.id}:${f.has(I.id)?"r":"p"}`)})})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(w||j?"當前篩選下沒有版本":"暫無版本著錄")}),R.rows.length>C.length&&t.jsx(It,{label:`展開其餘 ${R.rows.length-C.length} 種版本`,onClick:()=>b(!0)}),R.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:d("部分年代據版本題名推斷,非著錄原文")})]}),G.length>0&&t.jsx(cu,{items:G,onNavigate:i,renderLink:r}),de&&t.jsx(Ee,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),ee=(I,K)=>t.jsx(Ie,{id:I,label:d(K),onNavigate:i,renderLink:r,dense:!0}),D=t.jsxs(t.Fragment,{children:[t.jsx(ut,{id:"collected",title:"收入叢編",items:A.map(I=>ee(I.id,I.title))}),t.jsx(ut,{id:"related",title:"相關書目",meta:d(`${M.length} 部`),items:M.map(I=>t.jsxs(t.Fragment,{children:[ee(I.id,I.title),t.jsx("span",{className:"bim-d-meta",title:I.note?d(I.note):void 0,children:d(nu(I.relation))})]}))}),t.jsx(ut,{id:"resources",title:"在線資源",cap:6,items:U.map(({r:I,kind:K})=>{const X=d((I.url?zt(I.url):void 0)||I.name),ue=Ct(I);return t.jsxs(t.Fragment,{children:[ue?t.jsxs("a",{href:ue,target:"_blank",rel:"noopener noreferrer",children:[X," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:X}),K&&t.jsx("span",{className:"bim-d-meta",children:K})]})})})]});return t.jsx(Ut,{railTop:l,back:c,nav:q,railLinks:p,main:se,card:Z,side:D})};function Do(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Ho(e,n){return n((e.url?zt(e.url):void 0)||e.name)}function au({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=V(),c=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",a=e.holders[0],d=a?Ho(a,l):e.locationName?l(e.locationName):"",u=e.images[0],f=u?Ct(u):void 0,x=e.images.map(m=>Ho(m,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Ie,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${c?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:c?l(c):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${d?"":" bim-d-zt-blank"}`,children:[d||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(f?t.jsx("a",{className:"bim-d-flag",href:f,target:"_blank",rel:"noopener noreferrer",title:x,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:x,children:l("有影印")}))})]})}function cu({items:e,onNavigate:n,renderLink:i}){const r=ae(),{convert:s}=V(),[l,c]=g.useState(0),p=e[Math.min(l,e.length-1)];return t.jsx(Ee,{id:"catalogs",title:"著錄",meta:s(`歷代書目 ${e.length} 家`),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-lu-list bim-d-ui",role:"tablist","aria-label":s("著錄書目"),children:e.map((a,d)=>t.jsx("li",{role:"presentation",children:t.jsx("button",{type:"button",role:"tab","aria-selected":d===l,onClick:()=>c(d),children:s(a.source)})},d))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[p.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:s(p.title_info)}),t.jsx(Re,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[p.source_bid?t.jsx(Ie,{id:p.source_bid,label:s(p.source),onNavigate:n,renderLink:i,dense:!0}):s(p.source),p.section?s(p.section):"",p.author_info?`${s(r.label.authorInfo)} ${s(p.author_info)}`:"",p.edition?`${s(r.label.edition)} ${s(p.edition)}`:"",p.page??""]}),p.summary&&t.jsx("p",{className:"bim-d-quote",children:Oe(s(p.summary))}),p.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s(r.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:Oe(s(p.comment))})]}),p.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s(r.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:Oe(s(p.additional_comment))})]}),!p.summary&&!p.comment&&!p.additional_comment&&!p.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:s("僅著錄書名,無提要。")})]})]})})}const Go=40,Uo=2,du=9,Vo={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function zn(e){if(!e)return["",""];const n=e.split(/[ ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Gs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,fullText:l,fullTextPending:c,chapterLink:p,railTop:a,back:d,railLinks:u})=>{var te,N,ne,oe,be,fe,$e,we,Le,We,ze,De,Ve,Tt;const f=ae(),{convert:x}=V(),[m,b]=g.useState(null),[w,h]=g.useState(new Map),[j,y]=g.useState([]),[k,_]=g.useState(new Map),[v,$]=g.useState(!1);g.useEffect(()=>{if(!n||!e.work_id){b(null);return}let B=!1;return n.getItem(e.work_id).then(le=>{!B&&le&&le.type==="work"&&b(le)}).catch(()=>{}),()=>{B=!0}},[n,e.work_id]),g.useEffect(()=>{const B=e.contained_in||[];if(!n||B.length===0){h(new Map);return}let le=!1;return Promise.all(B.map(pe=>{const ye=typeof pe=="string"?pe:pe.id;return n.getItem(ye).then(je=>[ye,je]).catch(()=>[ye,null])})).then(pe=>{if(le)return;const ye=new Map;for(const[je,me]of pe)me&&ye.set(je,me);h(ye)}),()=>{le=!0}},[n,e.contained_in]);const S=g.useMemo(()=>{const B=new Set([...(m==null?void 0:m.books)||[],...e.related_books||[]]);return B.add(e.id),[...B]},[m==null?void 0:m.books,e.related_books,e.id]),z=S.length-1;g.useEffect(()=>{if(!n||z<=0){y([]);return}const B=S.length<=Go,le=B?S:S.slice(0,8);let pe=!1;return Promise.all(le.map(ye=>ye===e.id?Promise.resolve({id:ye,title:e.title,edition:e.edition,year:ln(e)}):n.getItem(ye).then(je=>{const me=je??{};return{id:ye,title:me.title,edition:me.edition,year:je?ln(me):void 0}}).catch(()=>({id:ye})))).then(ye=>{if(pe)return;const je=ye.filter(me=>me.id===e.id||me.title||me.edition);B&&je.sort((me,Be)=>(me.year??1/0)-(Be.year??1/0)),y(je)}),()=>{pe=!0}},[n,S,z,e]);const T=e.lineage,R=g.useMemo(()=>[...((T==null?void 0:T.derived_from)||[]).filter(B=>B.ref_type==="book").map(B=>B.ref),...((T==null?void 0:T.related_to)||[]).map(B=>B.book_id)].filter(Boolean),[T]);g.useEffect(()=>{if(!n||R.length===0){_(new Map);return}let B=!1;return Promise.all(R.map(le=>n.getItem(le).then(pe=>[le,{id:le,title:pe==null?void 0:pe.title,edition:pe==null?void 0:pe.edition}]).catch(()=>[le,{id:le}]))).then(le=>{B||_(new Map(le))}),()=>{B=!0}},[n,R]);const C=g.useMemo(()=>Ps(e.resources,e.resource_groups),[e.resources,e.resource_groups]),P=C.groups.reduce((B,le)=>B+le.rows.length+le.mirrors.length,0),W=C.groups.length>0&&C.groups.every(B=>B.key==="_physical"),A=Gt(e),M=Lr(e),U=ot(e,f.unit.juan),G=new Set((e.contained_in||[]).map(B=>typeof B=="string"?0:Pt(B.volume_index).length).filter(B=>B>0)),E=B=>{var ye;const le=(ye=e.base_edition)==null?void 0:ye.find(je=>je.book_id===B&&je.name);if(le!=null&&le.name)return le.name;const pe=k.get(B);return(pe==null?void 0:pe.edition)||(pe==null?void 0:pe.title)||""},ie=g.useMemo(()=>{var me,Be,Qe,at,rt;const B=[];M&&B.push({label:"版本類型",value:x(M),title:(me=e.lineage)!=null&&me.category?void 0:x("據版本題名推斷")}),(Be=e.publication_info)!=null&&Be.details?B.push({label:"刊印",value:x(e.publication_info.details)}):(A.era||A.reign)&&B.push({label:"刊寫年代",value:x([A.era,A.reign].filter(Boolean).join(" ")),title:A.source==="edition"?x("據版本題名推斷"):void 0}),U&&B.push({label:"卷帙",value:x(U)});const le=(e.contained_in||[]).flatMap(Me=>typeof Me=="string"?[]:Pt(Me.volume_index));le.length&&B.push({label:"冊次",value:x(`第 ${gn(le,f.unit.volume)} ${f.unit.volume}(${le.length} ${f.unit.volume})`)});const pe=(((Qe=e.lineage)==null?void 0:Qe.derived_from)||[]).find(Me=>Me.relation==="底本"&&Me.ref_type==="book");pe&&E(pe.ref)&&B.push({label:"底本",value:t.jsx(Ie,{id:pe.ref,label:x(E(pe.ref)),onNavigate:i,renderLink:r,dense:!0})});const ye=(e.resources||[]).filter(Me=>(Me.types||(Me.type?[Me.type]:[])).includes("physical"));ye.length?B.push({label:"存藏",value:ye.slice(0,2).map(Me=>x(Me.name)).join("、")+(ye.length>2?x(` 等 ${ye.length} 處`):"")}):(at=e.current_location)!=null&&at.name&&B.push({label:"存藏",value:x(e.current_location.name)}),(rt=e.page_count)!=null&&rt.description&&B.push({label:f.label.pageCount,value:x(e.page_count.description)});const je=[...Pn(e.additional_titles),...Pn(e.attached_texts)];return je.length&&B.push({label:"又名",value:je.map(x).join("、")}),B},[e,x,f,A,M,U,k,i,r]),F=x(e.title),re=e.edition?x(e.edition):void 0,ce=((te=e.lineage)==null?void 0:te.year_text)||"",Z=t.jsx(Vt,{kind:"版本",title:F,subtitle:re,byline:t.jsx(Ii,{authors:e.authors??(m==null?void 0:m.authors),onNavigate:i,renderLink:r}),meta:t.jsx(Re,{items:[M?x(M):"",A.era?x([A.era,A.reign].filter(Boolean).join("")):"",U?x(U):""]}),description:(N=e.description)!=null&&N.text?t.jsx(it,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ci((ne=e.description)==null?void 0:ne.text)?6:void 0,facts:ie,readAction:s,secondaryAction:s&&P>0&&!W?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(Yt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),O=e.contained_in||[],q=(l==null?void 0:l.chapters)||[],de=q[0]&&zn(q[0].title)[0].slice(-1)||"章",se=!!((oe=T==null?void 0:T.derived_from)!=null&&oe.length||(be=T==null?void 0:T.related_to)!=null&&be.length||(fe=e.appendix)!=null&&fe.length),ee=[];(q.length||C.text.length||c)&&ee.push({id:"fulltext",label:"全文",count:q.length?x(`${q.length} ${de}`):void 0}),C.groups.length&&ee.push({id:"images",label:W?"館藏":"影印",count:P}),se&&ee.push({id:"lineage",label:"版本源流"}),O.length&&ee.push({id:"collections",label:"收入叢編",count:O.length}),($e=e.location_history)!=null&&$e.length&&ee.push({id:"provenance",label:"流轉歷史"});const D=B=>(p==null?void 0:p(B))??null,Y=q[0],Q=Y?D(Y.file):null,L=v?q:q.slice(0,du),I=(B,le,pe)=>B?t.jsx("a",{className:pe,href:B.href??"#",onClick:B.onClick?ye=>{ye.metaKey||ye.ctrlKey||(ye.preventDefault(),B.onClick())}:void 0,children:le}):t.jsx("span",{className:pe,children:le}),K=t.jsxs(t.Fragment,{children:[(q.length>0||C.text.length>0||c)&&t.jsxs(Ee,{id:"fulltext",title:"全文",meta:q.length>0?t.jsx(Re,{items:[x(`${q.length} ${de}`),(we=l==null?void 0:l.source)!=null&&we.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[c&&!Y&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),Y&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${zn(Y.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((Y.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),I(Q,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),q.length>1&&t.jsx("ul",{className:"bim-d-chap",children:L.map(B=>{const[le,pe]=zn(B.title);return t.jsx("li",{children:I(D(B.file),t.jsxs(t.Fragment,{children:[le&&t.jsx("b",{children:x(le)}),x(pe||B.file)]}))},B.file)})}),q.length>L.length&&t.jsx(It,{label:`展開其餘 ${q.length-L.length} ${de}`,onClick:()=>$(!0)}),C.text.length>0&&t.jsxs(t.Fragment,{children:[(q.length>0||c)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:C.text.map((B,le)=>t.jsx(Ti,{item:B,siblings:C.text,listedVolumeCounts:G},`${B.id||B.url||B.name}-${le}`))})})]})]}),C.groups.length>0&&t.jsx(Ee,{id:"images",title:W?"館藏":"影印",meta:t.jsx(Re,{items:[C.groups.length>1?x(`${C.groups.length} 組`):"",x(`${P} 處`)]}),children:t.jsx(Ds,{groups:C.groups,listedVolumeCounts:G})}),se&&t.jsxs(Ee,{id:"lineage",title:"版本源流",meta:(Le=T==null?void 0:T.derived_from)!=null&&Le.length?x("據版本傳承著錄"):void 0,children:[t.jsxs("ul",{className:"bim-d-tl",children:[((T==null?void 0:T.derived_from)||[]).map((B,le)=>{const pe=B.ref_type==="book"?E(B.ref):"";return t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(B.relation)}),B.ref_type==="book"?t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(Ie,{id:B.ref,label:x(pe||B.ref),onNavigate:i,renderLink:r,dense:!0})}):t.jsx("span",{className:"bim-d-tl-t",children:x("擬構祖本")}),(B.evidence||B.confidence)&&t.jsxs("span",{className:"bim-d-tl-ev",children:[B.evidence?x(B.evidence):"",B.confidence&&Vo[B.confidence]?x(`(${Vo[B.confidence]})`):""]})]},`d-${le}`)}),(We=T==null?void 0:T.derived_from)!=null&&We.length||(ze=T==null?void 0:T.related_to)!=null&&ze.length?t.jsxs("li",{className:"bim-d-tl-cur",children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("本版")}),t.jsx("span",{className:"bim-d-tl-t",children:re||F}),ce&&t.jsxs("span",{className:"bim-d-meta",children:[t.jsx("span",{className:"bim-d-dot"}),x(ce)]})]}):null,((T==null?void 0:T.related_to)||[]).map((B,le)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(B.relation)}),t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(Ie,{id:B.book_id,label:x(E(B.book_id)||B.book_id),onNavigate:i,renderLink:r,dense:!0})}),B.evidence&&t.jsx("span",{className:"bim-d-tl-ev",children:x(B.evidence)})]},`r-${le}`)),(De=e.appendix)==null?void 0:De.map((B,le)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("附記")}),t.jsx("span",{className:"bim-d-tl-t",children:x(B.title)}),t.jsxs("details",{children:[t.jsx("summary",{className:"bim-d-ui",children:x("展開")}),t.jsx(it,{text:B.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]})]},`a-${le}`))]}),(T==null?void 0:T.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"10px 0 0",maxWidth:"46em"},children:x(T.note)})]}),O.length>0&&t.jsx(Ee,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:O.map((B,le)=>{var Be,Qe;const pe=typeof B=="string"?B:B.id,ye=typeof B=="string"?[]:Pt(B.volume_index),je=w.get(pe),me=(je==null?void 0:je._member_count)||((Be=je==null?void 0:je.books)==null?void 0:Be.length)||((Qe=je==null?void 0:je.contained_works)==null?void 0:Qe.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Ie,{id:pe,label:je?x(je.title):pe,onNavigate:i,renderLink:r,dense:!0}),ye.length>0&&t.jsx(pu,{volumes:ye,unit:f.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${me?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:me>0&&x(`全 ${me} ${f.unit.bu}`)})]},`${pe}-${le}`)})})})}),(Ve=e.location_history)!=null&&Ve.length?t.jsx(Ee,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((B,le)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(B.name)}),([B.start_date,B.end_date].filter(Boolean).join("—")||B.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(Re,{items:[[B.start_date,B.end_date].filter(Boolean).join("—"),B.description?x(B.description):""]})})]},le))})}):null,ee.length===0&&t.jsx(Ee,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),X=j.findIndex(B=>B.id===e.id),ue=S.length<=Go,xe=ue&&X>=0?j.slice(Math.max(0,X-Uo),X+Uo+1):j.filter(B=>B.id!==e.id),ve=t.jsxs(t.Fragment,{children:[m&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:x(f.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Ie,{id:m.id,label:x(m.title),onNavigate:i,renderLink:r})}),t.jsx(Re,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(m.authors||[]).slice(0,2).map(B=>`${B.dynasty?`〔${x(B.dynasty)}〕`:""}${x(B.name)}`),x(ot(m,f.unit.juan)),m._edition_count?x(`${m._edition_count} 種版本`):""]}),((Tt=m.description)==null?void 0:Tt.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:x(m.description.text.replace(/[#*_>`[\]]/g,""))})]}),z>0&&xe.length>0&&t.jsxs("div",{children:[t.jsx(ut,{id:"siblings",title:ue?"同作品版本":f.relation.siblingVersions,meta:x(ue?"按年代":`${z} 種`),cap:xe.length,items:xe.map(B=>B.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(B.edition||B.title||B.id)}):t.jsx(Ie,{id:B.id,label:x(B.edition||B.title||B.id),onNavigate:i,renderLink:r,dense:!0})),metas:xe.map(B=>[B.year!=null?B.year<0?`前${-B.year}`:String(B.year):"",B.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:xe.findIndex(B=>B.id===e.id)}),m&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Ie,{id:m.id,label:x(`在作品頁看全部 ${S.length} 種 →`),onNavigate:i,renderLink:r,dense:!0})})]})]}),_e=e.work_id?t.jsx(Pr,{caption:f.section.belongsToWork,children:t.jsx(Ie,{id:e.work_id,label:m?x(m.title):" ",onNavigate:i,renderLink:r,dense:!0})}):void 0;return t.jsx(Ut,{railTop:a,back:d,up:_e,nav:ee,railLinks:u,main:K,card:Z,side:ve})};function pu({volumes:e,unit:n}){const{convert:i}=V();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${gn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}const Yo=16,Us=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,railTop:c,back:p,railLinks:a})=>{var Z,O,q,de,se,ee;const d=ae(),{convert:u}=V(),[f,x]=g.useState(""),[m,b]=g.useState(!1),[w,h]=g.useState(null),j=g.useMemo(()=>Er(e,n),[e,n]),[y,k]=g.useState(new Map),_=g.useMemo(()=>{const D=f.trim();if(!D)return j.rows;const Y=u(D);return j.rows.filter(Q=>{var I;const L=Q.id&&((I=y.get(Q.id))==null?void 0:I.title)||Q.title;return u(L).includes(Y)||(Q.subItems||[]).some(K=>u(K).includes(Y))})},[j.rows,f,y,u]),v=m?_:_.slice(0,Yo),$=g.useMemo(()=>v.filter(D=>D.id&&!y.has(D.id)).map(D=>D.id),[v,y]);g.useEffect(()=>{if(!i||$.length===0)return;let D=!1;return Promise.all($.map(Y=>i.getItem(Y).then(Q=>{var K;const L=Q??{},I={title:L.title,edition:L.edition,authors:L.authors,measure:Q?ot(Q,d.unit.juan):void 0,versionCount:L._edition_count??((K=L.books)==null?void 0:K.length)};return[Y,I]}).catch(()=>[Y,{}]))).then(Y=>{D||k(Q=>{const L=new Map(Q);for(const[I,K]of Y)L.set(I,K);return L})}),()=>{D=!0}},[i,$,d.unit.juan]);const S=(e.contained_in||[])[0];g.useEffect(()=>{if(!S){h(null);return}if(h({id:S}),!i)return;let D=!1;return i.getItem(S).then(Y=>{D||h({id:S,title:Y==null?void 0:Y.title})}).catch(()=>{}),()=>{D=!0}},[i,S]);const z=g.useMemo(()=>Ps(e.resources,e.resource_groups),[e.resources,e.resource_groups]),T=z.text.length+z.groups.reduce((D,Y)=>D+Y.rows.length+Y.mirrors.length,0),R=e.contained_works||[],C=new Set(j.rows.map(D=>D.id).filter(Boolean)),P=R.length>0&&!R.every(D=>C.has(D.id)),W=(()=>{const D=j.rows.map(Y=>Y.edition).filter(Boolean);return D.length>1&&new Set(D).size===1})(),A=j.rows.some(D=>D.volumes.length>0||D.expected!=null),M=e._member_count||((Z=e.books)==null?void 0:Z.length)||R.length,U=g.useMemo(()=>{var L,I,K;const D=[];j.rows.length&&D.push({label:"子目",value:`${j.rows.length} ${u(d.unit.items)}`}),M&&M!==j.rows.length&&D.push({label:"成員",value:`${M} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")});const Y=ot(e,d.unit.juan),Q=j.totalVolumes?`${j.totalVolumes} ${u(d.unit.volume)}`:"";return(Y||Q)&&D.push({label:"卷帙",value:[Y?u(Y):"",Q].filter(Boolean).join(" "),title:(L=e.juan_count)!=null&&L.description?u(e.juan_count.description):void 0}),(I=e.publication_info)!=null&&I.details&&D.push({label:"刊印",value:u(e.publication_info.details)}),(K=e.publication_info)!=null&&K.year&&D.push({label:"年代",value:u(e.publication_info.year)}),D},[e,M,j.rows.length,j.totalVolumes,u,d]),G=(O=e.description)==null?void 0:O.text,E=t.jsx(Vt,{kind:"叢編",title:u(e.title),byline:t.jsx(Ii,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Re,{items:[e.subtype==="work_collection"?u("作品集"):"",(q=e.publication_info)!=null&&q.year?u(e.publication_info.year):""]}),description:G||(de=e.history)!=null&&de.length?t.jsxs(t.Fragment,{children:[G&&t.jsx(it,{text:G,style:{fontSize:15,lineHeight:1.85}}),(se=e.history)!=null&&se.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((D,Y)=>t.jsx("li",{children:u(D)},Y))}):null]}):void 0,clampDescription:ci(G)||(((ee=e.history)==null?void 0:ee.length)??0)>2?6:void 0,facts:U,foot:t.jsx(Yt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),ie=[];j.rows.length&&ie.push({id:"titles",label:"子目",count:j.rows.length}),T&&ie.push({id:"resources",label:"影印與全文",count:T}),P&&ie.push({id:"works",label:d.section.containedWorks,count:R.length});const F=t.jsxs(t.Fragment,{children:[j.rows.length>0&&t.jsxs(Ee,{id:"titles",title:"子目",meta:t.jsx(Re,{items:[u(`${j.rows.length} ${d.unit.items}`),j.totalVolumes?u(`全帙 ${j.totalVolumes} ${d.unit.volume}`):"",_.length!==j.rows.length?u(`當前 ${_.length} ${d.unit.items}`):""]}),action:l,children:[j.rows.length>Yo&&t.jsx("div",{className:"bim-d-filters bim-d-ui",children:t.jsx("input",{type:"search",className:"bim-d-find",value:f,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:D=>{x(D.target.value),b(!1)}})}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[A&&t.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),t.jsx("th",{children:u("書名")}),t.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),t.jsx("tbody",{children:v.map((D,Y)=>{var ue;const Q=D.id?y.get(D.id):void 0,L=Q!=null&&Q.title&&D.title===D.id?Q.title:D.title,I=((Q==null?void 0:Q.authors)||[]).find(xe=>xe&&xe.name),K=[I?`${I.dynasty?`〔${u(I.dynasty)}〕`:""}${u(I.name)}${I.role?` ${u(I.role)}`:""}`:"",Q!=null&&Q.measure?u(Q.measure):"",(ue=D.subItems)!=null&&ue.length?D.subItems.map(xe=>u(xe)).join("、"):"",(Q!=null&&Q.edition||D.edition)&&!W?u((Q==null?void 0:Q.edition)||D.edition||""):""].filter(Boolean),X=D.volumes.length>0?u(`第 ${gn(D.volumes,d.unit.volume)} ${d.unit.volume}`):D.expected!=null?u(`${D.found??0}/${D.expected} ${d.unit.volume}`):"";return t.jsxs("tr",{children:[A&&t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${X?"":" bim-d-zt-blank"}`,children:X||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsxs("td",{className:"bim-d-zt-main",children:[D.id?t.jsx(Ie,{id:D.id,label:u(L),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(L)}),K.length>0?t.jsx(Re,{items:K}):D.id&&!Q&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Q!=null&&Q.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Q!=null&&Q.versionCount?u(`${Q.versionCount} 種`):""})]},`${D.id??D.title}-${Y}`)})})]}),v.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),_.length>v.length&&t.jsx(It,{label:`展開其餘 ${_.length-v.length} ${d.unit.items}`,onClick:()=>b(!0)})]}),T>0&&t.jsxs(Ee,{id:"resources",title:"影印與全文",meta:u(`${T} 處`),children:[z.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[z.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:z.text.map((D,Y)=>t.jsx(Ti,{item:D,siblings:z.text},`${D.id||D.url||D.name}-${Y}`))})})]}),t.jsx(Ds,{groups:z.groups})]}),j.rows.length===0&&T===0&&t.jsx(Ee,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),re=P?t.jsx(ut,{id:"works",title:d.section.containedWorks,meta:u(`${R.length} 種`),cap:12,items:R.map(D=>t.jsx(Ie,{id:D.id,label:u(D.title),onNavigate:r,renderLink:s,dense:!0}))}):null,ce=w?t.jsx(Pr,{caption:"上級叢編",children:t.jsx(Ie,{id:w.id,label:u(w.title||w.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(Ut,{railTop:c,back:p,up:ce,nav:ie,railLinks:a,main:F,card:E,side:re})},uu=16,Cn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Ko(e){if(!e)return Cn.length;const n=Cn.indexOf(e);return n===-1?Cn.length:n}const xu={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function qo(e){return e==null?"":e<0?`前${-e}`:String(e)}const Vs=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:c})=>{var Y,Q;const p=ae(),{convert:a}=V(),[d,u]=g.useState("全部"),[f,x]=g.useState(!1),[m,b]=g.useState("default"),[w,h]=g.useState(new Map),j=g.useMemo(()=>(e.works||[]).map(L=>{const I=w.get(L.work_id);return{id:L.work_id,title:(I==null?void 0:I.title)??L.title??L.work_id,role:L.role||"",cls:si(L.role),versionCount:I==null?void 0:I.versionCount,section:I==null?void 0:I.cls,measure:I==null?void 0:I.measure,hasImage:I==null?void 0:I.hasImage,loaded:!!(I!=null&&I.loaded)}}),[e.works,w]),y=g.useMemo(()=>Rr((e.works||[]).map(L=>L.role)),[e.works]),k=g.useMemo(()=>{const L=d==="全部"?j:j.filter(I=>I.cls===d);return m==="versions"?[...L].sort((I,K)=>(K.versionCount??-1)-(I.versionCount??-1)):L},[j,d,m]),_=f?k:k.slice(0,uu),v=g.useMemo(()=>_.filter(L=>!w.has(L.id)).map(L=>L.id),[_,w]);g.useEffect(()=>{if(!n||v.length===0)return;let L=!1;return Promise.all(v.map(I=>n.getItem(I).then(K=>{var ve,_e,te,N;const X=K??{},ue=X._edition_count??(((ve=X.books)==null?void 0:ve.length)??0)+(((_e=X.collections)==null?void 0:_e.length)??0),xe=[(te=X.classification)==null?void 0:te.l1,(N=X.classification)==null?void 0:N.l2].filter(Boolean).join(" ");return[I,{id:I,title:X.title,versionCount:ue,loaded:!0,cls:xe||void 0,measure:K&&ot(K,p.unit.juan)||void 0,hasImage:!!(X.has_image??X._has_image)}]}).catch(()=>[I,{id:I,loaded:!0}]))).then(I=>{L||h(K=>{const X=new Map(K);for(const[ue,xe]of I)X.set(ue,xe);return X})}),()=>{L=!0}},[n,v,p.unit.juan]);const $=g.useMemo(()=>{const L=new Map;for(const I of e.alt_names||[]){const K=I.type||p.section.aliases;L.has(K)||L.set(K,[]),L.get(K).push(I.name)}return[...L.entries()].sort((I,K)=>Ko(I[0])-Ko(K[0])).map(([I,K])=>({label:I,names:K}))},[e.alt_names,p]),S=e.birth_year!=null||e.death_year!=null?`${qo(e.birth_year)||"?"}—${qo(e.death_year)||"?"}`:"",z=new Set(["本名","字","號","号"]),T=$.filter(L=>z.has(L.label)),R=$.filter(L=>!z.has(L.label)),C=R.reduce((L,I)=>L+I.names.length,0),P=g.useMemo(()=>{const L=[];for(const K of T)L.push({label:K.label,value:K.names.map(X=>a(X)).join("、")});const I=(e.works||[]).length;return I&&L.push({label:"著作",value:`${I} ${a("種")}`}),L},[e.works,T,a]),W=L=>{var I;return(I=$.find(K=>L.includes(K.label)))==null?void 0:I.names[0]},A=W(["字"]),M=W(["號","号"]),U=[A?`字${A}`:"",M?`號${M}`:""].filter(Boolean).join(","),G=e.native_place,E=t.jsx(Vt,{kind:xu[e.subtype]??"人物",title:a(e.primary_name||e.title),subtitle:U?a(U):void 0,meta:t.jsx(Re,{items:[e.dynasty?a(e.dynasty):"",S,G?a(`${G}人`):""]}),description:(Y=e.description)!=null&&Y.text?t.jsx(it,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ci((Q=e.description)==null?void 0:Q.text)?6:void 0,facts:P,foot:t.jsx(Yt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:C>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:a(`更多別名(${C})`)}),t.jsx("dl",{children:R.map(L=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:a(L.label)}),t.jsx("dd",{children:L.names.map(I=>a(I)).join("、")})]},L.label))})]})}),ie=g.useMemo(()=>j.filter(L=>L.loaded&&(L.versionCount??0)>0).sort((L,I)=>(I.versionCount??0)-(L.versionCount??0)).slice(0,3),[j]),F=!!n&&j.length>=3&&_.some(L=>!L.loaded),re=d==="全部"&&(F||ie.length>=2),ce=e.external_ids||{},Z=[];ce.cbdb_id!=null&&Z.push({label:"CBDB",id:String(ce.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${ce.cbdb_id}`,note:ce.cbdb_match==="auto"?"自動匹配":void 0});const O=ce.wikidata_id;O&&Z.push({label:"Wikidata",id:O,href:`https://www.wikidata.org/wiki/${O}`});const q=ce.viaf_id;q&&Z.push({label:"VIAF",id:q,href:`https://viaf.org/viaf/${q}`});const de=y.map(L=>({key:L.cls,label:`${L.label} ${L.count}`})),se=j.length?[{id:"works",label:"著作",count:j.length}]:[],ee=j.length===0?t.jsx(Ee,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該人物的關聯作品。")})}):t.jsxs(Ee,{id:"works",title:"著作",meta:t.jsx(Re,{items:[a(`共 ${j.length} 種`),k.length!==j.length?a(`當前 ${k.length} 種`):""]}),children:[re&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"-6px 0 10px",fontSize:14},children:a("著作舉要")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":F||void 0,children:[F&&[0,1,2].map(L=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},L)),!F&&ie.map(L=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Ie,{id:L.id,label:a(L.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx(Re,{items:[L.section?a(L.section):"",L.measure?a(L.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[a(`${L.versionCount} 種版本`),L.hasImage&&t.jsx("span",{className:"bim-d-flag",children:a("有影印")})]})]},L.id))]})]}),t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[de.length>1&&t.jsx(ai,{items:de,value:d,onChange:L=>{u(L),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":m==="versions",onClick:()=>{m==="default"&&x(!0),b(L=>L==="default"?"versions":"default")},children:a(m==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("作品")}),t.jsx("th",{children:a("職任")}),t.jsx("th",{children:a("存世版本")}),t.jsx("th",{"aria-label":a("影印")})]})}),t.jsx("tbody",{children:_.map(L=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Ie,{id:L.id,label:a(L.title),onNavigate:i,renderLink:r,dense:!0}),L.section||L.measure?t.jsx(Re,{items:[L.section?a(L.section):"",L.measure?a(L.measure):""]}):!L.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${L.role?"":" bim-d-zt-blank"}`,children:L.role?a(L.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${L.loaded?"":" bim-d-zt-blank"}`,children:L.loaded?L.versionCount?a(`${L.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:a("未著錄")}):""}),t.jsx("td",{className:L.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:L.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:a("有影印")})})]},L.id))})]}),_.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a("該職任下的著作尚未著錄。")}),k.length>_.length&&t.jsx(It,{label:`展開其餘 ${k.length-_.length} 種著作`,onClick:()=>x(!0)})]}),D=Z.length>0?t.jsx(ut,{id:"external",title:"站外資料",items:Z.map(L=>t.jsxs("a",{href:L.href,target:"_blank",rel:"noopener noreferrer",children:[L.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:Z.map(L=>[L.id,L.note?a(L.note):""].filter(Boolean).join(" · "))}):null;return t.jsx(Ut,{railTop:s,back:l,nav:se,railLinks:c,main:ee,card:E,side:D})},Ri="(max-width: 719px)",fu=`${Ri}, (pointer: coarse)`,Ys=`
|
|
683
|
+
`)}),s=[]};for(const c of n){const p=Si(c);if(p){l(),r={kind:"heading",level:p.level,text:p.text};continue}s.push(c)}return l(),i}function vo(e){const n=[];for(const i of e.split(`
|
|
684
|
+
`)){const r=Si(i);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=i.trim();!s||wi.test(s)||n.push({kind:"body",text:i})}return n}function js(e){if(!e)return[];const n=vn(e);if(n==="unknown")return vo(e);const i=[];for(const{heading:r,body:s}of Xc(e)){r&&i.push(r);const l=hs(s);if(l.length!==0){if(ys(s)){i.push(...vo(s));continue}if(n==="record"){const c=l.join(" ");c&&i.push({kind:"body",text:c})}else for(const c of l){const p=bs(c);p.length&&i.push({kind:"body",text:p.join(" ")})}}}return i}const vs=e=>e;function ks(e,n=vs){if(e.indexOf("《")<0)return n(e);const i=[],r=/《([^《》\n]+)》/g;let s=0,l=0,c;for(;c=r.exec(e);)c.index>s&&i.push(t.jsx(g.Fragment,{children:n(e.slice(s,c.index))},l++)),i.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(c[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=c.index+c[0].length;return s===0?n(e):(s<e.length&&i.push(t.jsx(g.Fragment,{children:n(e.slice(s))},l++)),i)}function _i(e,n={}){const i=n.renderText??vs,r=n.properNames?l=>ks(l,i):i,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return De(e,r,s)}function ko(e,n,i){return e.indexOf("**")<0?n(e):e.split(/(\*\*[^*]+\*\*)/g).map((s,l)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?t.jsx("strong",{children:n(s.slice(2,-2))},`${i}-${l}`):t.jsx(g.Fragment,{children:n(s)},`${i}-${l}`))}const Cn=/^(#{1,6})\s+(.*)$/,Qc=/^\s*<!--.*-->\s*$/;function Ss(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
|
|
685
|
+
`)?"":n)}function ed(e){return e<=1?2:e===2?3:4}function td(){let e=1;return n=>{const i=ed(n),r=Math.min(i,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${i}`}}}function kn(e){return e?vn(Ss(e))!=="unknown":!1}function So({text:e,mode:n,inline:i,dropTitle:r}){const s=Ss(e),l=(d,u,f)=>!!r&&f<=1&&d<=2&&u.trim()===r.trim(),c=td();if(n==="paragraph"&&vn(s)!=="unknown"){const d=js(s);return t.jsx(t.Fragment,{children:d.map((u,f)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,f))return null;const{Tag:x,className:m}=c(u.level??1);return t.jsx(x,{className:m,children:i(u.text)},f)}return t.jsx("p",{children:ko(u.text,i,f)},f)})})}const p=s.split(`
|
|
686
|
+
`);let a=0;return t.jsx(t.Fragment,{children:p.map((d,u)=>{const f=d.match(Cn);if(f){const m=a++;if(l(f[1].length,f[2],m))return null;const{Tag:b,className:w}=c(f[1].length);return t.jsx(b,{className:w,children:i(f[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Cn.test(p[u-1])&&!Cn.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(Qc.test(d))return null;if(a++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:m,className:b}=c(3);return t.jsx(m,{className:b,children:i(d.trim().slice(2,-2))},u)}return t.jsx("p",{children:ko(d,i,u)},u)})})}function nd(e){const{convert:n}=V();return g.useMemo(()=>e?n(e):"",[e,n])}function $i({text:e,mode:n,tables:i=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:c}){const p=nd(e),{convert:a}=V(),d=x=>_i(x,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,f=c?a(c):void 0;return!i||p.indexOf(":::")<0?t.jsx(So,{text:p,mode:n,inline:d,dropTitle:f}):t.jsx(t.Fragment,{children:vi(p).map((x,m)=>x.type==="table"?t.jsx(ki,{table:x.table,opts:u},m):t.jsx(So,{text:x.text,mode:n,inline:d,dropTitle:m===0?f:void 0},m))})}function ws(e,n){const[i,r]=g.useState(null),[s,l]=g.useState(!1),c=g.useRef(0);return g.useEffect(()=>{const p=++c.current;if(!e||!n){r(null),l(!1);return}let a;try{a=e(n)}catch{r(null),l(!1);return}if(!a||typeof a.then!="function"){r(a??null),l(!1);return}l(!0),a.then(d=>{p===c.current&&r(d??null)}).catch(()=>{p===c.current&&r(null)}).finally(()=>{p===c.current&&l(!1)})},[e,n]),{images:i,loading:s}}const wo={A:"fine",B:"rough",C:"rough",D:"ocr"};function id(e){return typeof e!="string"?null:e in An?e:e in wo?wo[e]:null}const od={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},rd={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function et(e){return typeof e!="string"?"":od[e]??rd[e]??e}const sd=["〇","一","二","三","四","五","六","七","八","九"],_o=["","十","百","千"],ld=["","萬","億"];function zi(e){if(e===0)return"〇";if(e<0)return`負${zi(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(ad(s,r>0)+ld[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function ad(e,n){const i=[];let r=e;for(;r>0;)i.unshift(r%10),r=Math.floor(r/10);let s="";for(let l=0;l<i.length;l++){const c=i[l],p=i.length-1-l;c===0?s&&!s.endsWith("〇")&&(s+="〇"):c===1&&p===1&&l===0&&!n?s+=_o[p]:s+=sd[c]+_o[p]}return s.replace(/〇$/,"")}let Ht=null,rn=null;const xn=new Set;function cd(){return Ht?Promise.resolve():rn||(rn=import("opencc-js/t2cn").then(e=>{Ht=e.Converter({from:"tw",to:"cn"}),xn.forEach(n=>n())}).catch(()=>{Ht=e=>e,xn.forEach(e=>e())}),rn)}const dd=e=>e;function yt(){const[,e]=g.useState(0);return g.useEffect(()=>{if(Ht)return;const n=()=>e(i=>i+1);return xn.add(n),cd(),()=>{xn.delete(n)}},[]),Ht??dd}function Ct(e,n){return n(e).toLowerCase()}const pd=o("highlight-bg");function Jt(e,n,i){if(!n)return e;const r=Ct(n,i);if(!r)return e;const s=Ct(e,i);if(s.length!==e.length)return e;const l=[];let c=0,p=0;for(;c<e.length;){const a=s.indexOf(r,c);if(a===-1){l.push(e.slice(c));break}a>c&&l.push(e.slice(c,a)),l.push(t.jsx("mark",{style:{background:pd,padding:0,color:"inherit"},children:e.slice(a,a+r.length)},p++)),c=a+r.length}return t.jsx(t.Fragment,{children:l})}function Ci(e,n,i,r){if(!n)return!0;const s=Ct(n,r);return(i?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(c=>typeof c=="string"&&Ct(c,r).includes(s))}function ud(e,n,i){return n?Ct(e,i).includes(Ct(n,i)):!0}const Ii={类:o("section-lei"),书:o("section-shu"),序:o("section-xu"),结语:o("section-jieyu"),注释:o("section-zhushi")},xd={考证:o("section-kaozhen")};function fd(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 _s(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((s,l)=>s+_s(l),0))||0;return n+i}function gd(e,n){const i=[],r=c=>{var p;i.push(...c.files),(p=c.children)==null||p.forEach(r)};if(r(e),i.length===0)return;const s=i.map(c=>n[c]);if(s.every(c=>c===void 0))return;if(s.some(c=>c==="loading"))return"loading";let l=0;for(const c of s)typeof c=="number"&&(l+=c);return l}const md={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Ti({enabled:e,expanded:n,onClick:i,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...md,...r},children:s}):t.jsx("span",{style:r,children:s})}function hd({type:e}){const n=et(e),i=Ii[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 bd({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=V(),s=Ae(),l=yt(),c=w=>w?De(r(w),h=>i?Jt(h,i,l):h):"",[p,a]=g.useState(!1),d=!!e.summary,u=!!e.comment,f=!!e.additional_comment,x=!!(e.content&&e.content.length>60),m=d||u||f||x;g.useEffect(()=>{i&&a(!0)},[i]);const b=!p&&x?Jr(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[t.jsxs("div",{onClick:()=>m&&a(!p),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:m?"pointer":"default",userSelect:"none",background:o("input-bg")},children:[t.jsxs(Ti,{enabled:m,expanded:p,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",c(e.book_title),"》"]}):c(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[zi(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:c(e.author_info||e.author)})]}),!p&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:c(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:c(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:o("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:s(e.work_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),w.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),p&&m&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${o("widget-border")}`,background:o("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"8px"},children:c(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:c(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(e.additional_comment)})]}),x&&!d&&!u&&!f&&t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(e.content)})]})]})}function yd({section:e,highlightQuery:n=""}){const{convert:i}=V(),r=yt(),s=a=>a?De(i(a),d=>n?Jt(d,n,r):d):"",[l,c]=g.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(Ti,{enabled:p,expanded:l,onClick:()=>c(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(hd,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:s(e.title)}),p&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&p&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${Ii[et(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 jd=100;function Ri(e){return et(e.type)!=="page_header"?!1:(e.content||"").length>=jd}function vd({section:e,highlightQuery:n=""}){const{convert:i}=V(),r=yt();if(et(e.type)==="page_header"&&!Ri(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
687
|
+
`)),l=De(s,d=>n?Jt(d,n,r):d),c=et(e.type),p=Ii[c]||o("desc-fg"),a=c==="序"||c==="结语"||c==="注释";return t.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:o("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${p}40`:void 0,background:a?o("bg"):void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:c}),l]})}function kd(e,n,i){const[r,s]=g.useState({});return g.useEffect(()=>{var d;if(!n||e.length===0)return;let l=!1;const c=e.filter(u=>{var f;return!((f=i==null?void 0:i.current)!=null&&f.has(u))}),p={};for(const u of e)(d=i==null?void 0:i.current)!=null&&d.has(u)&&(p[u]=i.current.get(u));if(Object.keys(p).length>0&&s(p),c.length===0)return;const a=async u=>{var f;try{if(n.getEntry){const h=await n.getEntry(u);if(h)return{title:h.title,author:h.author}}const x=await n.getItem(u);if(!x)return null;const m=x.title||u,b=x.authors,w=(f=b==null?void 0:b[0])==null?void 0:f.name;return{title:m,author:w}}catch{return null}};return Promise.all(c.map(async u=>{var x;const f=await a(u);return(x=i==null?void 0:i.current)==null||x.set(u,f),[u,f]})).then(u=>{l||s(f=>{const x={...f};for(const[m,b]of u)x[m]=b;return x})}),()=>{l=!0}},[e.join(","),n]),r}function Sd({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=V(),c=Ae(),p=yt(),a=y=>y?De(l(y),k=>s?Jt(k,s,p):k):"",[d,u]=g.useState(!1);g.useEffect(()=>{s&&u(!0)},[s]);const f=et(e.type),x=xd[f]||o("desc-fg"),m=!!e.content,b=e.work_ids||[],w=b.length>1,h=kd(w?b:[],i,r),j=m&&!d&&e.content.length>80?Jr(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${o("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>m&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:m?"pointer":"default",userSelect:"none"},children:[t.jsxs(Ti,{enabled:m,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg"),lineHeight:1.6},children:e.header_line?a(e.header_line):a(e.title)}),!d&&j&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:a(j)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:c(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:"→作品"}),w&&t.jsxs("span",{style:{fontSize:"11px",color:o("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:f})]})]}),w&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(y=>{const k=h[y],_=k?`${l(k.title)}${k.author?`(${l(k.author)})`:""}`:y.slice(0,8)+"…";return t.jsxs("a",{href:c(y),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(y))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",_]},y)})}),d&&m&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:o("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${o("widget-border")}`,fontSize:"12px",color:o("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:a(e.comment)})]})]})}function wd({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=yt(),c=n.trim(),p=g.useMemo(()=>c?e.sections.filter(a=>Ci(a,c,!0,l)):e.sections,[e.sections,c,l]);return t.jsxs("div",{children:[t.jsx("div",{children:p.map((a,d)=>t.jsx(Sd,{section:a,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:c},d))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function _d(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function $d({sections:e,onNavigate:n,inline:i}){const r=Ae(),{convert:s}=V(),l=_d();return t.jsx(t.Fragment,{children:e.map((c,p)=>{const a=et(c.type);if(a==="page_header"&&!Ri(c))return null;if(a==="类")return t.jsxs(g.Fragment,{children:[g.createElement(l("类"),null,i(s(c.title))),c.content&&t.jsx("p",{children:i(s(c.content))})]},p);if(a==="书"||a==="诗"||a==="考证"||a==="注释"){const d=c.book_title?`《${c.book_title}》${c.n_juan!=null?zi(c.n_juan)+"卷":""}`:c.title,u=i(s(d));return t.jsxs("section",{className:"bim-rd-entry",children:[g.createElement(l("条目"),{className:"bim-rd-entry-h"},c.work_id&&n?t.jsx("a",{href:r(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(c.work_id))},title:"查看作品",children:u}):u),c.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(c.author_info))}),c.content&&c.content.split(/\n+/).map((f,x)=>t.jsx("p",{children:i(s(f))},x)),c.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(c.summary))]}),c.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(c.comment))]}),c.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(c.additional_comment))]})]},p)}return c.content?t.jsx("p",{children:i(s(c.content))},p):null})})}function zd(e){return e.some(n=>{const i=et(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&Ri(n)})}function Cd({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:c,workLabelCache:p,prefs:a}){var W;const{convert:d}=V(),u=yt(),[f,x]=g.useState("text"),m=s.trim(),b=(r==null?void 0:r.type)==="kaozhen",w=g.useCallback(B=>m?Jt(B,m,u):B,[m,u]),h=B=>_i(B,{renderText:w,properNames:a.properNames}),j=g.useMemo(()=>m?e.sections.filter(B=>Ci(B,m,b,u)):e.sections,[e.sections,m,b,u]),y=(B,M)=>M.filter(U=>et(U.type)===B).length,k=y("书",e.sections),_=y("诗",e.sections),v=y("考证",e.sections);let $="";b?$=m?`${y("考证",j)} / ${v} ${d("條")}`:`${v} ${d("條")}`:_>0?$=m?`${y("诗",j)} / ${_} 首`:`${_} 首`:k>0&&($=m?`${y("书",j)} / ${k} ${d("部書")}`:`${k} ${d("部書")}`);const S=r!=null&&r.text_quality?id(r.text_quality.grade):null,z=[];i&&z.push(i),$&&z.push($),b&&(r!=null&&r.target_source)&&z.push(t.jsxs(t.Fragment,{children:[d("考證對象")," ",d(r.target_source)]})),S&&z.push(t.jsx("span",{title:vl[S],children:(W=r==null?void 0:r.text_quality)!=null&&W.source_note?t.jsxs(t.Fragment,{children:["底本 ",d(r.text_quality.source_note),"(",d(An[S]),")"]}):t.jsxs(t.Fragment,{children:[d("文本質量")," ",d(An[S])]})})),e.source_url&&z.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:d("原文來源")}));const I=!b&&zd(e.sections),R=!!n&&(!I||a.readingMode==="paragraph"&&kn(n)),C=!b&&(I||!!n),F=b||!C?"entries":f;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:d(e.title)}),z.length>0&&t.jsx("p",{className:"bim-rd-meta",children:z.map((B,M)=>t.jsxs(g.Fragment,{children:[M>0&&t.jsx("span",{className:"bim-rd-dot"}),B]},M))}),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":F==="text",onClick:()=>x("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":F==="entries",onClick:()=>x("entries"),children:d("條目")})]})]}),F==="text"&&t.jsx("article",{className:"bim-rd-prose",children:R?t.jsx($i,{text:n,mode:a.readingMode,properNames:a.properNames,renderText:w,dropTitle:e.title}):t.jsx($d,{sections:e.sections,onNavigate:l,inline:h})}),F==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:b?t.jsx(wd,{juan:e,searchQuery:s,onNavigate:l,transport:c,workLabelCache:p}):t.jsxs(t.Fragment,{children:[j.map((B,M)=>{const U=et(B.type);return U==="书"||U==="诗"||U==="考证"?t.jsx(bd,{section:B,onNavigate:l,highlightQuery:m},M):U==="类"?t.jsx(yd,{section:B,highlightQuery:m},M):t.jsx(vd,{section:B,highlightQuery:m},M)}),j.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function $s(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 Id(e){const n=$s(e);return n.length>0?n[0]:null}function Td(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:c,query:p,isKaozhen:a}=e,d=yt(),u=g.useRef(new Map),[f,x]=g.useState({}),[m,b]=g.useState({}),w=g.useCallback((j,y)=>{const k=y==null?void 0:y.title;k&&b(_=>_[j]===k?_:{..._,[j]:k})},[]);g.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:c}),w(s,l))},[s,l,c,w]),g.useEffect(()=>{u.current.clear(),x({}),b({})},[n]);const h=g.useCallback((j,y)=>{let k=0;if(j.juan)for(const _ of j.juan.sections)Ci(_,y,a,d)&&k++;return k===0&&j.rawText&&ud(j.rawText,y,d)&&(k=1),k},[a,d]);return g.useEffect(()=>{const j=p.trim();if(!j){x({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let y=!1;const k={},_=[];for(const I of r){const R=u.current.get(I);R?k[I]=h(R,j):(k[I]="loading",_.push(I))}x(k);const v=8;let $=0;const S=async()=>{var I;for(;$<_.length;){if(y)return;const R=$++,C=_[R];try{const[F,W]=await Promise.all([i.getCollatedJuan(n,C),((I=i.getCollatedJuanText)==null?void 0:I.call(i,n,C))??Promise.resolve(null)]),B={juan:F,rawText:W};if(u.current.set(C,B),w(C,F),y)return;x(M=>({...M,[C]:h(B,j)}))}catch{if(y)return;x(F=>({...F,[C]:0}))}}},z=Array.from({length:Math.min(v,_.length)},()=>S());return Promise.all(z),()=>{y=!0}},[p,n,i,r.join(","),h,d,w]),{matchStates:f,titles:m}}const Ei=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:c,style:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m})=>{const[b,w]=g.useState(null),[h,j]=g.useState(!1),[y,k]=g.useState(null),[_,v]=g.useState(null),[$,S]=g.useState(null),[z,I]=g.useState(!1),[R,C]=g.useState(null),[F,W]=g.useState(""),B=g.useRef(new Map),M=g.useRef(0),U=s??_,G=g.useCallback(O=>{v(O),l==null||l(O)},[l]),E=e||b;g.useEffect(()=>{e&&(j(!1),k(null))},[e]),g.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let O=!1;return j(!0),k(null),i.getCollatedEditionIndex(n).then(q=>{O||(q?w(q):k("未找到整理本数据"))}).catch(q=>{O||k(q instanceof Error?q.message:"加载失败")}).finally(()=>{O||j(!1)}),()=>{O=!0}},[e,n,i]),g.useEffect(()=>{if(E&&!U){const O=Id(E);O&&G(O)}},[E,U,G]);const oe=n||(E==null?void 0:E.work_id),P=g.useCallback(async O=>{var de;if(!oe||!(i!=null&&i.getCollatedJuan))return;const q=++M.current;I(!0),S(null),C(null);try{const[se,te]=await Promise.all([i.getCollatedJuan(oe,O),((de=i.getCollatedJuanText)==null?void 0:de.call(i,oe,O))??Promise.resolve(null)]);if(q!==M.current)return;S(se),C(te)}catch{if(q!==M.current)return;S(null),C(null)}finally{q===M.current&&I(!1)}},[oe,i]);g.useEffect(()=>{U&&P(U)},[U,P]);const le=O=>{G(O)};if(h)return t.jsx("div",{className:c,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(y)return t.jsx("div",{className:c,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:y});if(!E)return null;const ge=E.type==="kaozhen",Q=$s(E);return t.jsx(Ed,{className:c,style:p,index:E,allFiles:Q,isKaozhen:ge,effectiveWorkId:oe,transport:i,activeFile:U,handleSelectFile:le,juanData:$,juanRawText:R,juanLoading:z,searchQuery:F,setSearchQuery:W,onNavigate:r,workLabelCacheRef:B,reader:{title:a,subtitle:d,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m}})};function zs(e,n,i,r){var d,u,f,x;const s=(u=(d=n.juan_metadata)==null?void 0:d[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:fd(e)),p=((x=(f=n.files)==null?void 0:f.find(m=>m.filename===e))==null?void 0:x.title)??i[e];if(!p)return{position:l,label:l};const a=r(p);return{position:l,label:l===p||l===a?a:`${l} ${a}`}}function Rd(e,n,i,r,s){const l=a=>a==="loading"?"…":typeof a=="number"&&a>0?a:void 0,c=(a,d)=>({key:a,label:d??zs(a,e,r,s).label,hint:l(i[a]),disabled:i[a]===0}),p=(a,d)=>{var f;if(a.files.length===1&&!((f=a.children)!=null&&f.length))return c(a.files[0],s(a.label));const u=gd(a,i);return{key:`group:${d}`,label:s(a.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:_s(a),defaultExpanded:typeof u=="number"&&u>0,children:[...a.files.map(x=>c(x)),...(a.children??[]).map((x,m)=>p(x,`${d}.${m}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((a,d)=>p(a,`${d}`)):n.map(a=>c(a))}const Ed=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:c,activeFile:p,handleSelectFile:a,juanData:d,juanRawText:u,juanLoading:f,searchQuery:x,setSearchQuery:m,onNavigate:b,workLabelCacheRef:w,reader:h})=>{const{convert:j}=V(),[y,k]=yi(),{matchStates:_,titles:v}=Td({workId:l,transport:c,files:r,activeFile:p,activeJuan:d,activeRawText:u,query:x,isKaozhen:s}),$=ws(h.resolveImages,p),S=g.useMemo(()=>Rd(i,r,_,v,j),[i,r,_,v,j]),z=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:C=>m(C.target.value)}),I=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(C=>C.vol_label)?"冊":"卷",R=p?zs(p,i,v,j).position:void 0;return t.jsxs(ji,{className:e,style:n,title:h.title??(i.title?j(i.title):void 0),subtitle:h.subtitle??j(s?"考證":"整理本"),toc:S,tocCaption:`目录 · ${r.length} ${j(I)}`,tocHeader:z,activeKey:p,onSelect:a,images:$.images,imagesLoading:$.loading,renderImageOverlay:h.renderImageOverlay,imagePanel:h.imagePanel,prefs:y,onPrefsChange:k,paragraphToggle:!s&&kn(u),allowVertical:h.allowVertical,children:[f?t.jsx(bt,{}):d?t.jsx(Cd,{juan:d,rawText:u,positionLabel:R,index:i,searchQuery:x,onNavigate:b,transport:c,workLabelCache:w,prefs:y},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,i.references&&i.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:j("參考文獻")}),t.jsx("ol",{children:i.references.map((C,F)=>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]})]},F))})]})]})},Nd={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},Ld={label:"其他",color:o("desc-fg")},Bd={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 Wd(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 Md(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 Ni=({items:e,loading:n})=>{const i=Ae();return n?t.jsx(bt,{}):e.length===0?t.jsx("div",{style:Fd,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Nd[r.type]||Ld,l=Bd[r.status]||Ad,c=typeof window<"u"&&Md(r.pageUrl,window.location.href);return t.jsxs("div",{style:Pd,children:[t.jsxs("div",{style:Od,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...$o,background:s.color},children:s.label}),t.jsx("span",{style:{...$o,background:l.color},children:l.label})]}),t.jsx("span",{style:Dd,children:Wd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:Hd,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:In,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(c?t.jsx("a",{href:r.pageUrl,style:In,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:In,children:r.pageUrl}))]}),t.jsx("div",{style:Gd,children:r.content}),r.reply&&t.jsxs("div",{style:Ud,children:[t.jsx("div",{style:Vd,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Fd={textAlign:"center",padding:"40px 0",color:o("desc-fg"),fontSize:"14px"},Pd={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"16px"},Od={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},$o={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Dd={fontSize:"12px",color:o("desc-fg")},Hd={fontSize:"12px",marginBottom:"6px"},In={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},Gd={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},Ud={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},Vd={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},Kn=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const c=ce(),[p,a]=g.useState(null),[d,u]=g.useState([]),[f,x]=g.useState("recommend"),[m,b]=g.useState([]),[w,h]=g.useState(!1),j=r??f,y=M=>{x(M),s==null||s(M)},[k,_]=g.useState(!0),[v,$]=g.useState(null),[S,z]=g.useState(null),[I,R]=g.useState(null);g.useEffect(()=>{let M=!1;if(e.getCounts)return e.getCounts().then(U=>{M||a({works:U.works,books:U.books,collections:U.collections})}).catch(()=>{}),()=>{M=!0}},[e]),g.useEffect(()=>{let M=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const G=await e.getRecommended();if(G!=null&&G.groups)return G.groups.flatMap(E=>E.items.map(oe=>({...oe,group:E.name})))}catch{}return[]})().then(async G=>{if(M)return;const E=G.filter(P=>P.id);if(E.length===0){_(!1);return}const oe=await Promise.all(E.map(async P=>{if(P.type)return{id:P.id,title:P.title,type:P.type,author:P.author,dynasty:P.dynasty,role:P.role,edition:P.edition,has_text:P.has_text,has_image:P.has_image,has_collated:P.has_collated,subtype:P.subtype,primary_name:P.primary_name,group:P.group,fallbackDescription:P.description};try{let le=null;if(e.getEntry)le=await e.getEntry(P.id);else{const ge=await e.getItem(P.id);ge&&(le={id:P.id,title:ge.title||P.id,type:ge.type||"work"})}if(le)return{...le,group:P.group,fallbackDescription:P.description}}catch{}return{id:P.id,title:P.title,type:ve.extractType(P.id),group:P.group,fallbackDescription:P.description}}));M||(u(oe.filter(P=>P!==null)),_(!1))}),()=>{M=!0}},[e,i]);const C=g.useRef(!1),F=g.useRef(!1),W=g.useRef(!1);g.useEffect(()=>{if(j!=="catalog"||C.current)return;const M=e.getCatalogProgress??e.getResourceProgress;if(!M)return;C.current=!0;let U=!1;return M.call(e).then(G=>{U||$(G)}).catch(()=>{C.current=!1}),()=>{U=!0}},[e,j]),g.useEffect(()=>{if(j!=="collection"||F.current||!e.getCollectionProgress)return;F.current=!0;let M=!1;return e.getCollectionProgress().then(U=>{M||z(U)}).catch(()=>{F.current=!1}),()=>{M=!0}},[e,j]),g.useEffect(()=>{if(j!=="site"||W.current||!e.getSiteProgress)return;W.current=!0;let M=!1;return e.getSiteProgress().then(U=>{M||R(U)}).catch(()=>{W.current=!1}),()=>{M=!0}},[e,j]),g.useEffect(()=>{if(!l||j!=="feedback")return;let M=!1;return h(!0),fetch(l).then(U=>U.json()).then(U=>{!M&&U.success&&b(U.items||[])}).catch(()=>{}).finally(()=>{M||h(!1)}),()=>{M=!0}},[l,j]);const B=M=>{switch(M){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(Wt,{label:c.home.recommendTab,active:j==="recommend",onClick:()=>y("recommend")}),t.jsx(Wt,{label:c.home.catalogTab,active:j==="catalog",onClick:()=>y("catalog")}),t.jsx(Wt,{label:c.home.collectionTab,active:j==="collection",onClick:()=>y("collection")}),t.jsx(Wt,{label:c.home.siteTab,active:j==="site",onClick:()=>y("site")}),l&&t.jsx(Wt,{label:c.home.feedbackTab,active:j==="feedback",onClick:()=>y("feedback")})]}),j==="recommend"&&t.jsx(Yd,{recommended:d,loading:k,onNavigate:n,getIcon:B,t:c}),j==="catalog"&&t.jsx(zo,{progress:v,t:c,onNavigate:n}),j==="collection"&&t.jsx(zo,{progress:S,t:c,onNavigate:n}),j==="site"&&t.jsx(qd,{progress:I,t:c,totalWorks:(p==null?void 0:p.works)??0}),j==="feedback"&&l&&t.jsx(Ni,{items:m,loading:w})]})})},Wt=({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=Ae();if(n)return t.jsx(bt,{});if(e.length===0)return null;const c=new Map;for(const p of e){const a=p.group||s.home.recommendedBrowse;c.has(a)||c.set(a,[]),c.get(a).push(p)}return t.jsx(t.Fragment,{children:Array.from(c.entries()).map(([p,a])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:p}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return t.jsxs("a",{href:l(d.id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),i==null||i(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,cursor:"pointer",background:o("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},zo=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(bt,{});const r=[...e.resources].sort((p,a)=>p.priority-a.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},c={in_progress:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(p=>{const a=r.filter(d=>d.status===p);return a.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:c[p]}}),l[p]," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>t.jsx(Kd,{item:d,t:n,statusColor:c[p],onNavigate:i},d.id))})]},p)})})},Kd=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=Ae(),l=e.total>0?Math.round(e.imported/e.total*100):0,c=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=e.edition?`${e.name}·${e.edition}`:e.name,a=e.collection_id||e.work_id;return a&&r?t.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:p}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:o("widget-border"),color:o("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:c})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Ut(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})]})},qd=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(bt,{});const r=[...e.resources].sort((a,d)=>a.priority-d.priority),s=r.filter(a=>a.imported>0),l=r.filter(a=>a.imported===0),c=s.reduce((a,d)=>Math.max(a,d.imported),0),p=i>0?Math.round(c/i*100):0;return t.jsxs("div",{children:[i>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${o("primary")} 6%, transparent)`,fontSize:"13px",color:o("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:c.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>t.jsx(Co,{item:a,t:n,totalWorks:i},a.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(a=>t.jsx(Co,{item:a,t:n,totalWorks:i},a.id))})]})]})},Co=({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})]})},Io="(max-width: 768px)";function Jd(){const[e,n]=g.useState(()=>typeof window>"u"?!1:window.matchMedia(Io).matches);return g.useEffect(()=>{const i=window.matchMedia(Io),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),e}const Zd=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var U;const l=ce(),{convert:c}=V(),p=Jd(),[a,d]=g.useState(null),[u,f]=g.useState(null),[x,m]=g.useState(!1),[b,w]=g.useState("detail"),[h,j]=g.useState([]),[y,k]=g.useState(!1),[_,v]=g.useState(null),[$,S]=g.useState(!1),z=g.useCallback(async G=>{if(!e.getCollatedEditionIndex){v(null);return}S(!0);try{const E=await e.getCollatedEditionIndex(G);v(E)}catch{v(null)}finally{S(!1)}},[e]),I=g.useCallback(async G=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){j([]);return}k(!0);try{if(e.getCollectionCatalogs){const E=await e.getCollectionCatalogs(G);j(E||[])}else if(e.getCollectionCatalog){const E=await e.getCollectionCatalog(G);j(E?[{resource_id:"",data:E}]:[])}}catch{j([])}finally{k(!1)}},[e]),R=g.useCallback(async G=>{if(i){i(G);return}d(G),f(null),j([]),v(null),w("detail"),m(!0);try{const E=await e.getItem(G.id);E&&(f(E),E.type==="collection"?I(G.id):E.type==="work"&&E.has_collated&&z(G.id))}catch(E){console.error("加载详情失败:",E)}finally{m(!1)}},[e,i,I,z]),C=g.useCallback(async G=>{f(null),j([]),v(null),w("detail"),m(!0);try{const E=await e.getItem(G);E&&(f(E),d({id:G,title:E.title||G,type:E.type||"book"}),E.type==="collection"?I(G):E.type==="work"&&E.has_collated&&z(G))}catch(E){console.error("导航失败:",E)}finally{m(!1)}},[e,I,z]),F=(u==null?void 0:u.type)==="collection"&&(h.length>0||y)||(u==null?void 0:u.type)==="work"&&(_||$),W=p&&(x||u),B=g.useCallback(()=>{d(null),f(null),j([]),v(null),w("detail")},[]),M=t.jsx(t.Fragment,{children:x?t.jsx(bt,{}):u?t.jsxs(t.Fragment,{children:[(F||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${o("widget-border")}`,padding:p?"0 12px":"0 48px",background:o("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[F&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>w("detail"),style:sn(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&y&&h.length===0&&t.jsxs("button",{onClick:()=>{},style:sn(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&h.map(G=>t.jsx("button",{onClick:()=>w(`catalog:${G.resource_id}`),style:sn(b===`catalog:${G.resource_id}`),children:G.short_name?`${c(G.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},G.resource_id)),u.type==="work"&&(_||$)&&t.jsxs("button",{onClick:()=>w("collated"),style:sn(b==="collated"),children:[l.detailTab.collatedEdition,$&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?t.jsx(si,{data:u,transport:e,onNavigate:C}):b.startsWith("catalog:")?t.jsx(li,{data:(U=h.find(G=>`catalog:${G.resource_id}`===b))==null?void 0:U.data,onNavigate:C}):b==="collated"?t.jsx(Ei,{index:_||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(Kn,{transport:e,onNavigate:C,recommendedIds:r})});return p?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children: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:B,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:M})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Mn,{transport:e,onEntryClick:R,hideModeIndicator:n}),!u&&t.jsx(Kn,{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(Mn,{transport:e,onEntryClick:R,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:M})]})};function sn(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 dt(e){return e.replace(/\.md$/,"")}function To(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 Ro={padding:24,color:o("desc-fg")},qn=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:c,onVersionChange:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:f,imagePanel:x,allowVertical:m,className:b,style:w})=>{const[h,j]=g.useState(e??null),[y,k]=g.useState(!1),[_,v]=g.useState(null),$=r!==void 0?r:_,S=g.useCallback(Q=>{s?s(Q):v(Q)},[s]),[z,I]=g.useState(null),[R,C]=g.useState(!1);g.useEffect(()=>{e&&j(e)},[e]),g.useEffect(()=>{if(e)return;j(null),k(!1);const Q=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!Q){k(!0);return}let O=!1;return Promise.resolve().then(Q).then(q=>{O||(q?j(q):k(!0))}).catch(()=>{O||k(!0)}),()=>{O=!0}},[n,i,e,l]),g.useEffect(()=>{if(!h||h.chapters.length===0)return;const Q=dt(h.chapters[0].file);if(!$){S(Q);return}const O=dt($);h.chapters.some(de=>dt(de.file)===O)||S(Q)},[h,$,S]);const F=g.useMemo(()=>{if(!h||!$)return null;const Q=dt($);return h.chapters.find(O=>dt(O.file)===Q)??null},[h,$]);g.useEffect(()=>{if(!n||!F)return;const Q=l!==void 0?i.getWorkFullTextChapter?q=>i.getWorkFullTextChapter(n,l,q):null:i.getBookFullTextChapter?q=>i.getBookFullTextChapter(n,q):null;if(!Q)return;let O=!1;return C(!0),I(null),Promise.resolve(F.file).then(Q).then(q=>{O||I(q)}).catch(()=>{O||I(null)}).finally(()=>{O||C(!1)}),()=>{O=!0}},[n,F,i,l]);const W=ws(u,F?dt(F.file):null),[B,M]=yi(),{convert:U}=V(),G=!!(c&&c.length>1&&p),E=g.useMemo(()=>G?cs(c).map((Q,O)=>({...Q,label:To(c[O])})):void 0,[G,c]),oe=G?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:Q=>p(Q.target.value),children:c.map(Q=>t.jsx("option",{value:Q.key,children:To(Q)},Q.key))})]}):null;if(!h)return t.jsxs("div",{style:Ro,children:[oe&&t.jsx("div",{style:{marginBottom:12},children:oe}),y?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:Ro,children:[oe&&t.jsx("div",{style:{marginBottom:12},children:oe}),"全文目录为空"]});const P=h.chapters.map(Q=>({key:dt(Q.file),label:U(Q.title)})),le=xs(h)||On(h),ge=z?z.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(ji,{title:a??U(h.version_label),subtitle:d??"全文",toc:P,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:$?dt($):null,onSelect:S,images:W.images,imagesLoading:W.loading,renderImageOverlay:f,imagePanel:x,prefs:B,onPrefsChange:M,versions:E,currentVersionKey:E?l??null:void 0,onVersionChange:E?p:void 0,versionSource:!1,paragraphToggle:kn(ge),allowVertical:m,className:b,style:w,children:[F&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:U(F.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:h.source.url,target:"_blank",rel:"noreferrer",children:U(h.source.name)}),h.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),h.source.license]})]})]}),R&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!R&&ge!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx($i,{text:ge,mode:B.readingMode,tables:le,gujiMarkdown:On(h),properNames:B.properNames})}),!R&&!z&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},Xd=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=ce(),{convert:l}=V(),[c,p]=g.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[a,d]=g.useState(null);return t.jsxs("div",{className:i,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:l(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[s.catalog.totalVolumes," ",t.jsx("strong",{children:e.total_volumes})," ",s.unit.juan]}),e.stats.zhulu!=null&&t.jsxs("span",{children:["著錄 ",t.jsx("strong",{children:e.stats.zhulu})," ",s.unit.bu]}),e.stats.cunmu!=null&&t.jsxs("span",{children:["存目 ",t.jsx("strong",{children:e.stats.cunmu})," ",s.unit.bu]}),e.stats.categories!=null&&t.jsxs("span",{children:[e.stats.categories," 類"]})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(f=>t.jsx(Qd,{division:f,expanded:c===f.name,onToggle:()=>p(c===f.name?null:f.name),expandedCat:a,onCatToggle:x=>d(a===x?null:x),onNavigate:n},f.name))})]})},Qd=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:c}=V(),p=e.categories.reduce((a,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return a+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${o("primary")} 6%, transparent)`:o("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:o("fg"),textAlign:"left"},children:[t.jsx("span",{children:c(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg")},children:[e.categories.length," 類 · ",p," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(a=>{const d=`${e.name}/${a.name}`;return t.jsx(ep,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:l},a.name)})})]})},ep=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var a,d,u,f;const{convert:s}=V(),l=((a=e.books)==null?void 0:a.zhulu)||[],c=((d=e.books)==null?void 0:d.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((f=e.stats)==null?void 0:f.cunmu)||c.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?o("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:o("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||c.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Eo,{label:"著錄",books:l,onNavigate:r}),c.length>0&&t.jsx(Eo,{label:"存目",books:c,onNavigate:r})]})]})},Eo=({label:e,books:n,onNavigate:i})=>{const{convert:r}=V(),s=Ae(),[l,c]=g.useState(n.length<=20),p=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((a,d)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:o("fg")},children:a.work_id&&i?t.jsx("a",{href:s(a.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},children:r(a.title)}):r(a.title)}),a.volumes&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.volumes)}),a.author&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.author).slice(0,20)})]},d))}),!l&&t.jsxs("button",{onClick:()=>c(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},Ve=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=ce();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:o("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&t.jsx("button",{onClick:i,style:np,children:"AI"}),n&&t.jsx("button",{onClick:n,style:tp,children:l.action.save})]})]}),s]})},tp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},np={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Oe=({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"}})]}),mt=({value:e,onChange:n,placeholder:i})=>{const r=g.useRef(null);return g.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},fn=({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 ip(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const cn=({value:e,onChange:n,label:i})=>{const[r,s]=g.useState(!1),l=g.useRef(null),c=ip(e||"");return g.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&c?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:No,children:i}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${o("input-border")}`,borderRadius:"2px",background:o("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:o("fg")},children:c.name}),t.jsx(fn,{children:c.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:No,children:i}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},No={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function op(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function rp(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Cs=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=ce(),[s,l]=g.useState(null),c=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},p=f=>{n(e.filter((x,m)=>m!==f)),s===f&&l(null)},a=(f,x,m)=>{const b=[...e];b[f]={...b[f],[x]:m},n(b)},d=(f,x)=>{const m=[...e];m[f]={...m[f],type:x,id:"",name:""},n(m),x==="bookID"&&i&&i(b=>{const w=[...e];w[f]={...w[f],id:b.id,name:b.title,type:"bookID"},n(w)})},u=f=>{i&&i(x=>{const m=[...e];m[f]={...m[f],id:x.id,name:x.title,type:"bookID"},n(m)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((f,x)=>t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===x?null:x),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===x?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:o("fg")},children:f.name||`${r.editor.sourcePlaceholder} ${x+1}`}),f.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:op(f.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:rp(f.type)}),t.jsx("button",{onClick:m=>{m.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===x&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!f.type&&t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>d(x,"bookID"),style:{...Lo,borderColor:o("source-bookid"),color:o("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>d(x,"url"),style:{...Lo,borderColor:o("source-url"),color:o("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),f.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:nt,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Bo,children:r.action.changeType})]}),f.id&&f.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:o("bg"),border:`1px solid ${o("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:o("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:f.name}),t.jsx("code",{style:{fontSize:"11px",background:o("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:f.id})]}),t.jsx("button",{onClick:()=>u(x),style:{background:"transparent",border:`1px solid ${o("widget-border")}`,color:o("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(x),style:{width:"100%",padding:"14px",border:`2px dashed ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),f.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:nt,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Bo,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:f.name,onChange:m=>a(x,"name",m.target.value),placeholder:r.editor.sourceNamePlaceholder,style:jt})]}),t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:f.id,onChange:m=>a(x,"id",m.target.value),placeholder:"https://...",style:jt})]})]}),f.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${o("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...nt,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:nt,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:f.details,onChange:m=>a(x,"details",m.target.value),placeholder:r.editor.detailsPlaceholder,style:jt})]}),t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:f.position,onChange:m=>a(x,"position",m.target.value),placeholder:"如: 卷三, p.52",style:jt})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:f.version,onChange:m=>a(x,"version",m.target.value),placeholder:"如: v1.0, 2024-01",style:jt})]}),t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:f.processor_version,onChange:m=>a(x,"processor_version",m.target.value),placeholder:"如: v0.1",style:jt})]})]})]})]})})]},x)),t.jsxs("button",{onClick:c,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},nt={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},jt={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"},Lo={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"},Bo={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Is(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 Ts(e){return!e||e.length===0?"":JSON.stringify(e)}const Rs=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:c,childWorks:p,childCollections:a,containedBooks:d,siblingBooks:u,onLinkEntity:f,onUnlinkEntity:x,onViewEntity:m,onCreateAndLink:b,onSaveRelations:w})=>{const h=ce();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:h.section.relations})]}),w&&t.jsx("button",{onClick:w,style:sp,children:h.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Mt,{direction:"up",title:h.relation.belongsToWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>f("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Mt,{direction:"up",title:h.relation.containedInCollection,entity:c,onView:m,onUnlink:()=>x("collectionId"),onLink:()=>f("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),l&&u&&u.length>0&&t.jsx(vt,{direction:"horizontal",title:`${h.relation.siblingVersions} (${u.length})`,entities:u,onView:m,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Mt,{direction:"up",title:h.relation.parentWork,entity:r,onView:m,onUnlink:()=>x("parentWorkId"),onLink:()=>f("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),p&&p.length>0&&t.jsx(vt,{direction:"down",title:`${h.relation.childWorks} (${p.length})`,entities:p,onView:m,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),a&&a.length>0&&t.jsx(vt,{direction:"down",title:`${h.relation.collectionImpl} (${a.length})`,entities:a,onView:m,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(vt,{direction:"down",title:`${h.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>b("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Mt,{direction:"up",title:h.relation.correspondingWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>f("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Mt,{direction:"up",title:h.relation.parentCollection,entity:s,onView:m,onUnlink:()=>x("parentCollectionId"),onLink:()=>f("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(vt,{direction:"down",title:`${h.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:m,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(vt,{direction:"down",title:`${h.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:m,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},Mt=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:c,linkLabel:p,createLabel:a,notLinkedLabel:d,viewLabel:u,unlinkLabel:f})=>{const x=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:o("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Es(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(Ao,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(Ao,{onClick:s,title:f,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(Jn,{onClick:l,children:p}),t.jsx(Jn,{onClick:c,primary:!0,children:a})]})]})},vt=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:c,expandMoreLabel:p})=>{const[a,d]=g.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),f=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=a?i:i.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:f}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[x.map(m=>t.jsxs("div",{onClick:()=>r(m),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:o("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:Es(m.type)}),t.jsx("span",{children:m.title})]},m.id)),i.length>5&&!a&&t.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:o("link-fg"),cursor:"pointer"},children:[p," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:c}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(Jn,{onClick:s,primary:!0,children:["+ ",l]})})]})},Ao=({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}),Jn=({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 Es(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const sp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Ns=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:c,onSearch:p,isLoading:a,excludeId:d})=>{const[u,f]=g.useState(""),x=d?c.filter(h=>h.id!==d):c;g.useEffect(()=>{e&&(f(""),p(""))},[e]);const m=h=>{f(h),p(h)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",w=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:lp,children:t.jsxs("div",{style:ap,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:cp,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:h=>m(h.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:dp})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?t.jsx("div",{style:Tn,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(h=>t.jsxs("div",{onClick:()=>r(h),style:pp,children:[t.jsx("span",{style:{fontSize:"16px"},children:w}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):u?t.jsxs("div",{style:Tn,children:["未找到匹配的",b]}):t.jsxs("div",{style:Tn,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:up,children:["创建新",b,"并关联"]})]})]})})},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",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},cp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},dp={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"},pp={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:o("primary-soft")},Tn={padding:"20px",textAlign:"center",color:o("desc-fg")},up={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Wo={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},xp={work:"📜",book:"📖",collection:"📚",entity:"👤"},Ls=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[c,p]=g.useState(""),a=g.useRef(null);g.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,m;(x=a.current)==null||x.focus(),(m=a.current)==null||m.select()},100))},[e,r==null?void 0:r.title]);const d=x=>{x.key==="Enter"&&c.trim()?u():x.key==="Escape"&&l()},u=()=>{c.trim()&&s(c.trim(),{...r,title:c.trim()})};if(!e)return null;const f=()=>{switch(i){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Wo[n]}`}};return t.jsx("div",{style:fp,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:gp,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:xp[n]}),t.jsx("span",{children:f()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:o("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:o("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:a,type:"text",value:c,onChange:x=>p(x.target.value),onKeyDown:d,placeholder:`请输入${Wo[n]}名称...`,style:mp})]}),((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:hp,children:"取消"}),t.jsx("button",{onClick:u,disabled:!c.trim(),style:{...bp,opacity:c.trim()?1:.6,cursor:c.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},fp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},gp={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")},mp={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"},hp={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},bp={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function yp(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Bs(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function jp(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 As=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:c,onSelect:p,onCancel:a,onCreate:d,onSearch:u})=>{const[f,x]=g.useState(""),[m,b]=g.useState([]),[w,h]=g.useState(!1),[j,y]=g.useState("recent");g.useEffect(()=>{e&&(x(""),b([]),y(r.length>0?"recent":"search"))},[e,r.length]),g.useEffect(()=>{if(!f.trim()){b([]);return}const z=setTimeout(async()=>{h(!0);try{b(await u(f,i))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(z)},[f,i,u]);const k=g.useCallback(z=>{x(z.target.value),z.target.value.trim()&&y("search")},[]),_=g.useCallback(z=>s?z.filter(I=>I.id!==s):z,[s]);if(!e)return null;const v=n||(i==="all"?"选择实体":`选择${Bs(i)}`),$=_(r),S=_(m);return t.jsx("div",{style:kp,children:t.jsxs("div",{style:Sp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:v}),t.jsx("button",{onClick:a,style:wp,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:f,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:_p}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),w&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),$.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs(Mo,{active:j==="recent",onClick:()=>y("recent"),children:["最近使用 (",$.length,")"]}),t.jsxs(Mo,{active:j==="search",onClick:()=>y("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&$.length>0?t.jsx(Fo,{entities:$,onSelect:p}):f.trim()?w?t.jsx(Rn,{message:"搜索中..."}):S.length>0?t.jsx(Fo,{entities:S,onSelect:p}):t.jsx(Rn,{message:"未找到匹配的结果"}):t.jsx(Rn,{message:"输入关键词开始搜索"})}),l&&d&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:d,style:$p,children:c||"创建新实体"})]})]})})},Mo=({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}),Fo=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(vp,{entity:i,onClick:()=>n(i)},i.id))}),vp=({entity:e,onClick:n})=>{const[i,r]=g.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:yp(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:jp(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Bs(e.type)})]})},Rn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),kp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Sp={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")},wp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},_p={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"},$p={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},zp={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},Cp={work:"📜",collection:"📚",book:"📖",entity:"👤"},Ws=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:c,onAskAI:p,renderSectionActions:a,onDownloadResource:d,downloadStatuses:u,relations:f,onRelationsChange:x})=>{var Y;const m=ce(),[b,w]=g.useState(!1),[h,j]=g.useState("work"),[y,k]=g.useState(""),[_,v]=g.useState(""),[$,S]=g.useState([]),[z,I]=g.useState(!1),[R,C]=g.useState(!1),[F,W]=g.useState("work"),[B,M]=g.useState(""),[U,G]=g.useState(),[E,oe]=g.useState(!1),[P,le]=g.useState(null),[ge,Q]=g.useState([]);g.useRef(null);const O=e.type,q=O==="work",de=O==="collection",se=O==="book",te=g.useCallback((T,ee)=>{n({...e,[T]:ee})},[e,n]),D=g.useCallback((T,ee)=>{k(T),j(ee),v(m.editor.selectToLink+m.indexType[ee]),S([]),w(!0)},[m]),K=g.useCallback(T=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,T)},[r,e.id]),X=g.useCallback(T=>{s==null||s(T.id,T.type)},[s]),xe=g.useCallback((T,ee,ie)=>{const ye={...ie,author:(ie==null?void 0:ie.author)||e.author,dynasty:ie==null?void 0:ie.dynasty};W(ee),M(T),G(ye),C(!0)},[e.author]),A=g.useCallback((T,ee)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,B,{type:F,title:T,inheritData:ee}),C(!1)},[r,e.id,B,F]),re=g.useCallback(T=>{if(!T.trim()){S([]);return}I(!0),r!=null&&r.searchEntities&&r.searchEntities(T,h).then(ee=>{S(ee),I(!1)}).catch(()=>{S([]),I(!1)})},[r,h]),ne=g.useCallback(T=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,y,T.id),w(!1)},[r,e.id,y]),pe=g.useCallback(()=>{i()},[i]),fe=g.useCallback(T=>{le(()=>T),oe(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Q).catch(()=>{})},[r]),L=g.useCallback((T,ee)=>r!=null&&r.searchEntities?r.searchEntities(T,ee==="all"?void 0:ee):Promise.resolve([]),[r]),J=g.useCallback(T=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(T),Q(ee=>[T,...ee.filter(ie=>ie.id!==T.id)].slice(0,10)),P==null||P(T),oe(!1),le(null)},[r,P]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${o("widget-border")}`,paddingBottom:"16px"},children:t.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Cp[O]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(fn,{children:e.id}),t.jsx(fn,{color:zp[O],children:m.indexType[O]})]})}),t.jsx(Ve,{title:m.section.basicInfo,onSave:i,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(cn,{label:q?m.editor.workTitle:de?m.editor.collectionTitle:m.editor.bookTitle,value:e.title,onChange:T=>te("title",T)}),se&&t.jsx(cn,{label:m.editor.belongsToWork,value:e.workName||"",onChange:T=>te("workName",T)}),t.jsx(Oe,{label:m.editor.authorLabel,value:e.author||"",onChange:T=>te("author",T)}),t.jsx(Oe,{label:m.editor.publicationYearLabel,value:e.publicationYear||"",onChange:T=>te("publicationYear",T)}),(se||de)&&t.jsx(cn,{label:m.editor.containedIn,value:e.collection||"",onChange:T=>te("collection",T)}),(se||de)&&t.jsx(Oe,{label:m.editor.holderLabel,value:e.holder||"",onChange:T=>te("holder",T)}),(se||de)&&t.jsx(Oe,{label:se?m.editor.pageLabel:m.editor.volumeLabel,value:e.pages||"",onChange:T=>te("pages",T)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(Oe,{label:m.editor.firstImageLabel,value:e.firstImage||"",onChange:T=>te("firstImage",T)})})]})}),t.jsx(Ve,{title:m.section.description,onSave:i,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(mt,{value:e.description||"",onChange:T=>te("description",T),placeholder:m.editor.descriptionPlaceholder})}),(((Y=e.additional_works)==null?void 0:Y.length)||0)>0&&t.jsx(Ve,{title:m.section.additionalWorks,onSave:i,children:t.jsx(Ip,{items:e.additional_works||[],onChange:T=>te("additional_works",T)})}),t.jsx(Ve,{title:m.section.indexedBy,onSave:i,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Tp,{items:e.indexed_by||[],onChange:T=>te("indexed_by",T)})}),t.jsx(Ve,{title:m.section.emendatedBy,onSave:i,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Rp,{items:e.emendated_by||[],onChange:T=>te("emendated_by",T)})}),t.jsx(Ve,{title:m.section.textResources,onSave:i,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(Wn,{items:e.resources||[],onChange:T=>te("resources",T),onDownload:d,downloadStatuses:u,filterType:"text"})}),t.jsx(Ve,{title:m.section.imageResources,onSave:i,children:t.jsx(Wn,{items:e.resources||[],onChange:T=>te("resources",T),onDownload:d,downloadStatuses:u,filterType:"image"})}),t.jsx(Ve,{title:m.section.sources,onSave:i,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(Cs,{items:Is(e.sources||""),onChange:T=>te("sources",Ts(T)),onOpenEntityPicker:fe})}),(se||de)&&t.jsx(Ve,{title:m.section.provenance,onSave:i,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(mt,{value:e.provenance||"",onChange:T=>te("provenance",T),placeholder:m.editor.provenancePlaceholder})}),se&&t.jsx(Ve,{title:m.section.otherEditions,onSave:i,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(mt,{value:e.otherEditions||"",onChange:T=>te("otherEditions",T),placeholder:m.editor.otherEditionsPlaceholder})}),t.jsx(Rs,{entityType:O,entityId:e.id,entityTitle:e.title,parentWork:f==null?void 0:f.parentWork,parentCollection:f==null?void 0:f.parentCollection,belongsToWork:f==null?void 0:f.belongsToWork,belongsToCollection:f==null?void 0:f.belongsToCollection,childWorks:f==null?void 0:f.childWorks,childCollections:f==null?void 0:f.childCollections,containedBooks:f==null?void 0:f.containedBooks,siblingBooks:f==null?void 0:f.siblingBooks,onLinkEntity:D,onUnlinkEntity:K,onViewEntity:X,onCreateAndLink:xe,onSaveRelations:pe}),l&&c&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${o("danger-soft-border")}`,background:o("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:o("danger"),fontWeight:600,marginBottom:"8px"},children:m.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"12px"},children:m.editor.dangerZoneDesc}),t.jsx("button",{onClick:c,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("danger")}`,borderRadius:"4px",background:"transparent",color:o("danger"),cursor:"pointer"},children:m.editor.deleteEntity})]}),t.jsx(Ns,{isOpen:b,entityType:h,title:_,onSelect:ne,onCancel:()=>w(!1),onCreate:()=>{w(!1),xe(y,h)},searchResults:$,onSearch:re,isLoading:z,excludeId:e.id}),t.jsx(Ls,{isOpen:R,entityType:F,relationField:B,inheritData:U,onConfirm:A,onCancel:()=>C(!1)}),t.jsx(As,{isOpen:E,title:m.action.selectBookOrWork,filterType:"all",recentEntities:ge,excludeId:e.id,onSelect:J,onCancel:()=>{oe(!1),le(null)},onSearch:L})]})};function Ip({items:e,onChange:n}){const i=ce(),r=(c,p,a)=>{const d=e.map((u,f)=>f===c?{...u,[p]:a}:u);n(d)},s=c=>n(e.filter((p,a)=>a!==c)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((c,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(Oe,{label:i.editor.bookNameLabel,value:c.book_title,onChange:a=>r(p,"book_title",a)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(Oe,{label:i.label.juanCount,value:c.n_juan!=null?String(c.n_juan):"",onChange:a=>r(p,"n_juan",a&&parseInt(a,10)||void 0)})}),t.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Ms({items:e,onChange:n,showMeta:i,addLabel:r}){const s=ce(),[l,c]=g.useState(null),p=(u,f,x)=>{const m=e.map((b,w)=>w===u?{...b,[f]:x||void 0}:b);n(m)},a=u=>{n(e.filter((f,x)=>x!==u)),l===u&&c(null)},d=()=>{n([...e,{source:""}]),c(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,f)=>{const x=l===f;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:x?`color-mix(in srgb, ${o("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>c(x?null:f),children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.2s",transform:x?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:m=>{m.stopPropagation(),a(f)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${o("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:o("muted")},children:"✕"})]}),!x&&i&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:o("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),x&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Oe,{label:s.label.sourceName,value:u.source,onChange:m=>p(f,"source",m)}),t.jsx(Oe,{label:s.label.sourceBid,value:u.source_bid||"",onChange:m=>p(f,"source_bid",m)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Oe,{label:s.label.titleInfo,value:u.title_info||"",onChange:m=>p(f,"title_info",m)}),t.jsx(Oe,{label:s.label.authorInfo,value:u.author_info||"",onChange:m=>p(f,"author_info",m)})]}),t.jsx(Oe,{label:s.label.edition,value:u.edition||"",onChange:m=>p(f,"edition",m)})]}),t.jsx(mt,{value:u.summary||"",onChange:m=>p(f,"summary",m),placeholder:s.editor.summaryPlaceholder}),t.jsx(mt,{value:u.comment||"",onChange:m=>p(f,"comment",m),placeholder:s.editor.commentPlaceholder}),t.jsx(mt,{value:u.additional_comment||"",onChange:m=>p(f,"additional_comment",m),placeholder:s.editor.additionalCommentPlaceholder})]})]},f)}),t.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Tp({items:e,onChange:n}){const i=ce();return t.jsx(Ms,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Rp({items:e,onChange:n}){const i=ce();return t.jsx(Ms,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function Fs(e){var p,a,d,u,f,x,m;const n=((a=(p=e.authors)==null?void 0:p[0])==null?void 0:a.name)||"",i=((d=e.publication_info)==null?void 0:d.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(f=e.page_count)!=null&&f.number?String(e.page_count.number):((x=e.page_count)==null?void 0:x.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",c={id:e.id,title:e.title,type:e.type,author:n,publicationYear:i,holder:r,pages:s,description:l,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const b=e;if(Array.isArray(b.related_works)){const w=b.related_works.find(h=>h.relation==="part_of");w&&(c.parentWorkId=w.id,c.parentWorkName=w.title)}}if(e.type==="book"){const b=e;c.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(c.collectionId=(m=b.contained_in[0])==null?void 0:m.id)}return c}function Ep(e){const n={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.publicationYear?{year:e.publicationYear}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(n.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(n.work_id=e.workId,e.collectionId&&(n.contained_in=[{id:e.collectionId}])),n}const Np=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:c,onSave:p,onDelete:a,onNavigate:d,renderLink:u,onAskAI:f,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:w,onRelationsChange:h,headerExtra:j,className:y,style:k}=e;ce();const[_,v]=g.useState(s),$=l?s:_;g.useEffect(()=>{s!==_&&v(s)},[s]);const S=g.useCallback(()=>{const B=$==="view"?"edit":"view";l?l(B):v(B)},[$,l]),[z,I]=g.useState(null);g.useEffect(()=>{i&&r&&r.getItem(i).then(B=>{B&&I(B)})},[i,r]);const R=n||z,C=g.useMemo(()=>R?Fs(R):null,[R]),F=l||!n?t.jsx("button",{onClick:S,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:[F,j]});return!R&&!C?t.jsx(bt,{}):$==="view"?t.jsx(si,{data:R,transport:r,onNavigate:d?B=>d(B):void 0,renderLink:u,headerExtra:W,className:y,style:k}):C?t.jsxs("div",{className:y,style:k,children:[W&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:W}),t.jsx(Ws,{data:C,onChange:c||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:f,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:w,onRelationsChange:h})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},Po=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ps=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,l]=g.useState(null),[c,p]=g.useState(""),[a,d]=g.useState(""),[u,f]=g.useState("idle"),[x,m]=g.useState(""),b=g.useRef(null);g.useEffect(()=>{e&&(l(null),p(""),d(""),f("idle"),m(""))},[e]),g.useEffect(()=>{s&&setTimeout(()=>{var y;return(y=b.current)==null?void 0:y.focus()},100)},[s]),g.useEffect(()=>{if(u==="success"){const y=setTimeout(n,2e3);return()=>clearTimeout(y)}},[u,n]),g.useEffect(()=>{if(!e)return;const y=k=>{k.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[e,n]);const w=async()=>{if(!(!s||!c.trim())){f("submitting"),m("");try{await i({type:s,content:c.trim(),...a.trim()?{contact:a.trim()}:{}}),f("success")}catch(y){f("error"),m(y instanceof Error?y.message:"提交失败,请稍后重试")}}};if(!e)return null;const h=s&&c.trim()&&u!=="submitting",j=Po.find(y=>y.value===s);return t.jsx("div",{style:Lp,onClick:y=>{y.target===y.currentTarget&&n()},children:t.jsxs("div",{style:Bp,onClick:y=>y.stopPropagation(),children:[t.jsxs("div",{style:Ap,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:Wp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:Dp,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:o("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Po.map(y=>t.jsxs("button",{onClick:()=>l(y.value),style:{...Mp,...s===y.value?Fp:{}},children:[t.jsx("span",{children:y.icon})," ",y.label]},y.value))}),t.jsx("textarea",{ref:b,value:c,onChange:y=>p(y.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...Pp,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:a,onChange:y=>d(y.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:Gp}),t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[c.length," / 2000"]}),u==="error"&&t.jsx("div",{style:Hp,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:w,disabled:!h,style:{...Op,opacity:h?1:.6,cursor:h?"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},Bp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},Ap={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Wp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:o("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Mp={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"},Fp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},Pp={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"},Op={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},Dp={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},Hp={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Gp={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"},Zn="--bim-feedback-fab-offset",Xn=48,Up=16,Vp=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,c]=g.useState(!1),p=n.bottom??24;return g.useEffect(()=>{if(r||typeof document>"u")return;const a=document.documentElement;return a.style.setProperty(Zn,`calc(${p+Xn+Up}px + env(safe-area-inset-bottom, 0px))`),()=>{a.style.removeProperty(Zn)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>c(!0),style:{...Yp,zIndex:s??o("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(Ps,{isOpen:l,onClose:()=>c(!1),onSubmit:e,feedbackListUrl:i})]})},Yp={position:"fixed",width:`${Xn}px`,height:`${Xn}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"},Oo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Os=({onSubmit:e})=>{const[n,i]=g.useState("bug"),[r,s]=g.useState(""),[l,c]=g.useState(""),[p,a]=g.useState("idle"),[d,u]=g.useState(""),f=g.useRef(null);g.useEffect(()=>{n&&setTimeout(()=>{var w;return(w=f.current)==null?void 0:w.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){a("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),a("success"),s(""),c(""),i("bug")}catch(w){a("error"),u(w instanceof Error?w.message:"提交失败,请稍后重试")}}},m=n&&r.trim()&&p!=="submitting",b=Oo.find(w=>w.value===n);return p==="success"?t.jsx("div",{style:Do,children:t.jsxs("div",{style:Xp,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>a("idle"),style:Qp,children:"继续提交"})]})}):t.jsxs("div",{style:Do,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Oo.map(w=>t.jsxs("button",{onClick:()=>i(w.value),style:{...Kp,...n===w.value?qp:{}},children:[t.jsx("span",{children:w.icon})," ",w.label]},w.value))}),t.jsx("textarea",{ref:f,value:r,onChange:w=>s(w.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...Jp}}),t.jsx("input",{type:"text",value:l,onChange:w=>c(w.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:tu}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:x,disabled:!m,style:{...Zp,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:eu,children:d})]})},Do={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},Kp={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"},qp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},Jp={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"},Zp={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},Xp={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},Qp={background:"none",border:"none",color:o("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},eu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginTop:"8px"},tu={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 Ho(e){return typeof e=="function"?e():e??"/api/feedback"}const Ds=({resourceId:e,apiUrl:n})=>{const[i,r]=g.useState([]),[s,l]=g.useState(!0),c=g.useCallback(async()=>{const a=Ho(n);l(!0);try{const u=await(await fetch(`${a}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);g.useEffect(()=>{c()},[c]);const p=async a=>{const d=Ho(n),u=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const f=await u.json().catch(()=>null);throw new Error((f==null?void 0:f.error)||"提交失败")}setTimeout(()=>c(),500)};return t.jsxs("div",{children:[t.jsx(Ni,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Os,{onSubmit:p})})]})},Go={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 nu(e){return e?Go[e]??e:Go.related}const iu={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function ou(e){return iu[e]??e}const ru={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function su(e){return ru[e]??""}function Li({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,c)=>{const p=ui(l.role);return t.jsxs(g.Fragment,{children:[c>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Ie,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:i,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},c)})}):null}function Hs(e,n){var p,a;const i=di(e,n),r=i.mirrors.map(d=>({key:d.key,label:d.label,description:d.description,rows:d.items.filter(u=>u.group_role!=="mirror"),mirrors:d.items.filter(u=>u.group_role==="mirror")})),s=i.buckets.filter(d=>d.key==="image"||d.key==="textImage").flatMap(d=>d.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=i.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((a=i.buckets.find(d=>d.key==="text"))==null?void 0:a.items)??[],groups:r}}function Gs(e,n){const i=(e.url?Tt(e.url):void 0)||e.name,r=Tr(e,n);return r?`${i}(${r})`:i}function Bi({item:e,siblings:n,listedVolumeCounts:i}){const{convert:r}=V(),[s,l]=g.useState(!1),c=gn(e),p=!!c&&c.expected>0&&!(i!=null&&i.has(c.expected)),a=r(Gs(e,n)),d=Rt(e),u=yn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[a," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:a}),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(mi,{item:e})})]}),t.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(f=>!f),children:r(s?"收起分冊":`展開 ${c.expected} 冊`)})})]})}function Us({groups:e,listedVolumeCounts:n}){const{convert:i}=V();return t.jsx(t.Fragment,{children:e.map(r=>t.jsxs("div",{className:"bim-d-rg",children:[r.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:i(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:i(r.description)}),r.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:r.rows.map((s,l)=>t.jsx(Bi,{item:s,siblings:r.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),r.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[r.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:i("鏡像")}),r.mirrors.map((s,l)=>{const c=Rt(s),p=i(Gs(s,r.mirrors));return c?t.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",title:s.details?i(s.details):void 0,children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:p},l)})]})]},r.key))})}const Uo=12,lu=60,Vs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:c,railLinks:p})=>{var K,X,xe;const a=ce(),{convert:d}=V(),u=g.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[f,x]=g.useState(new Map),[m,b]=g.useState(!1),[w,h]=g.useState(""),[j,y]=g.useState(!1),k=u.length<=lu,_=k||m||!!w||j,v=g.useMemo(()=>_?u:u.slice(0,Uo),[u,_]);g.useEffect(()=>{if(!n||v.length===0)return;const A=v.filter(ne=>!f.has(ne));if(A.length===0)return;let re=!1;return Promise.all(A.map(ne=>n.getItem(ne).then(pe=>{const fe=pe??{};return[ne,{id:ne,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(()=>[ne,{id:ne}]))).then(ne=>{re||x(pe=>{const fe=new Map(pe);for(const[L,J]of ne)fe.set(L,J);return fe})}),()=>{re=!0}},[n,v,f]);const $=g.useMemo(()=>u.map(A=>f.get(A)??{id:A}),[u,f]),S=u.length>0&&u.every(A=>f.has(A)),z=!!n&&v.some(A=>!f.has(A)),I=k||_,R=g.useMemo(()=>Er($,e.version_graph,{era:w,scanOnly:j,sort:I?"year":"default"}),[$,e.version_graph,w,j,I]),C=m?R.rows:R.rows.slice(0,Uo),F=R.allRows.filter(A=>A.hasImage).length,W=e.related_works||[],B=W.filter(A=>A.relation==="collected_in"),M=g.useMemo(()=>{const A=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],re=ne=>{const pe=A.indexOf(ne??"");return pe<0?A.length:pe};return W.filter(ne=>ne.relation!=="collected_in").map((ne,pe)=>({r:ne,i:pe})).sort((ne,pe)=>re(ne.r.relation)-re(pe.r.relation)||ne.i-pe.i).map(ne=>ne.r)},[W]),U=g.useMemo(()=>{const A=di(e.resources,e.resource_groups);return[...A.mirrors.flatMap(re=>re.items.map(ne=>({r:ne,kind:d(re.label)}))),...A.buckets.flatMap(re=>re.items.map(ne=>({r:ne,kind:d(su(re.key))})))]},[e.resources,e.resource_groups,d]),G=e.indexed_by||[],E=e.emendated_by||[],oe=g.useMemo(()=>{var ee,ie,ye;const A=[],re=(ie=(ee=e.authors)==null?void 0:ee[0])==null?void 0:ie.dynasty;re&&A.push({label:"成書",value:d(re)});const ne=st(e,a.unit.juan);if(ne){const me=(ye=e.juan_count)==null?void 0:ye.description;A.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[d(ne),me&&me!==ne?t.jsxs("span",{className:"bim-d-meta",children:["(",d(me),")"]}):null]})})}e.loss_status&&A.push({label:"存佚",value:d(ou(e.loss_status))});const pe=e._edition_count??u.length;pe&&A.push({label:"版本",value:t.jsxs(t.Fragment,{children:[pe," ",d("種"),S&&F?t.jsxs("span",{className:"bim-d-meta",children:[" ",d(`${F} 種有影印`)]}):null]})});const fe=R.allRows.filter(me=>me.sortYear!=null),L=fe.length>0?fe.reduce((me,Ce)=>me.sortYear<=Ce.sortYear?me:Ce):null;L!=null&&L.era.era?A.push({label:"最早存世",value:d([L.era.era,L.era.reign].filter(Boolean).join(" ")),title:L.era.source==="edition"?d("據版本題名推斷"):void 0}):z&&A.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),(G.length||E.length)&&A.push({label:"著錄",value:t.jsxs(t.Fragment,{children:[G.length?`${G.length} ${d("家")}`:"—",E.length?t.jsxs("span",{className:"bim-d-meta",children:[" ",d(`考證 ${E.length} 條`)]}):null]})});const J=Vo(e.additional_titles);J.length&&A.push({label:"又名",value:J.map(d).join("、")});const Y=Vo(e.attached_texts);Y.length&&A.push({label:"附載",value:Y.map(d).join("、")});const T=(e.additional_works||[]).map(me=>d(me.book_title)+(me.n_juan!=null?` ${me.n_juan}${d(a.unit.juan)}`:""));return T.length&&A.push({label:"附錄",value:T.join("、")}),A},[e,d,a,u.length,S,z,F,R.allRows,G.length,E.length]),P=e.classification,le=P?[P.l1,P.l2,P.l3,P.l4].filter(Boolean).map(A=>d(A)):[],ge=e.subtype?d(a.workSubtype[e.subtype]??e.subtype):"",Q=t.jsx(Kt,{title:d(e.title),byline:t.jsx(Li,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(Le,{items:[...le,P!=null&&P.source?d(`據《${P.source.split("/")[0]}》`):"",ge]}),description:(K=e.description)!=null&&K.text?t.jsxs(t.Fragment,{children:[t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(X=e.description.sources)!=null&&X.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(A=>d(Ua(A))).filter(Boolean).join(" · ")}):null]}):void 0,facts:oe,readAction:s,foot:t.jsx(qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(xe=e.appendix)==null?void 0:xe.map((A,re)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(A.title)}),t.jsx(rt,{text:A.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},re))}),O=R.eras.length>=2?[{key:"",label:a.catalog.all},...R.eras.map(A=>({key:A,label:A}))]:[],q=[];u.length&&q.push({id:"versions",label:"版本",count:u.length}),G.length&&q.push({id:"catalogs",label:"著錄",count:G.length}),B.length&&q.push({id:"collected",label:"收入叢編",count:B.length}),M.length&&q.push({id:"related",label:"相關書目",count:M.length}),U.length&&q.push({id:"resources",label:"在線資源",count:U.length});const de=u.length===0&&G.length===0,se=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Be,{id:"versions",title:"版本",meta:t.jsx(Le,{items:[d(`共 ${u.length} 種`),S&&F?d(`${F} 種有影印`):"",R.rows.length!==R.allRows.length?d(`當前 ${R.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&O.length===0&&u.length>1?"":void 0,children:[O.length>0&&t.jsx(xi,{items:O,value:w,onChange:A=>{h(A),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Gr,{label:"只看有影印",checked:j,onChange:A=>{y(A),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:d(I?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("版本")}),t.jsx("th",{children:d("年代")}),t.jsx("th",{children:d("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:d("影印")})})]})}),t.jsx("tbody",{children:C.map(A=>{var re;return t.jsx(au,{row:A,measure:(re=f.get(A.id))==null?void 0:re.measure_info,loaded:f.has(A.id),onNavigate:i,renderLink:r},`${A.id}:${f.has(A.id)?"r":"p"}`)})})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(w||j?"當前篩選下沒有版本":"暫無版本著錄")}),R.rows.length>C.length&&t.jsx(Et,{label:`展開其餘 ${R.rows.length-C.length} 種版本`,onClick:()=>b(!0)}),R.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:d("部分年代據版本題名推斷,非著錄原文")})]}),G.length>0&&t.jsx(cu,{items:G,onNavigate:i,renderLink:r}),de&&t.jsx(Be,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),te=(A,re)=>t.jsx(Ie,{id:A,label:d(re),onNavigate:i,renderLink:r,dense:!0}),D=t.jsxs(t.Fragment,{children:[t.jsx(gt,{id:"collected",title:"收入叢編",items:B.map(A=>te(A.id,A.title))}),t.jsx(gt,{id:"related",title:"相關書目",meta:d(`${M.length} 部`),items:M.map(A=>t.jsxs(t.Fragment,{children:[te(A.id,A.title),t.jsx("span",{className:"bim-d-meta",title:A.note?d(A.note):void 0,children:d(nu(A.relation))})]}))}),t.jsx(gt,{id:"resources",title:"在線資源",cap:6,items:U.map(({r:A,kind:re})=>{const ne=d((A.url?Tt(A.url):void 0)||A.name),pe=Rt(A);return t.jsxs(t.Fragment,{children:[pe?t.jsxs("a",{href:pe,target:"_blank",rel:"noopener noreferrer",children:[ne," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:ne}),re&&t.jsx("span",{className:"bim-d-meta",children:re})]})})})]});return t.jsx(Yt,{railTop:l,back:c,nav:q,railLinks:p,main:se,card:Q,side:D})};function Vo(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Yo(e,n){return n((e.url?Tt(e.url):void 0)||e.name)}function au({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=V(),c=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",a=e.holders[0],d=a?Yo(a,l):e.locationName?l(e.locationName):"",u=e.images[0],f=u?Rt(u):void 0,x=e.images.map(m=>Yo(m,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Ie,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${c?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:c?l(c):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${d?"":" bim-d-zt-blank"}`,children:[d||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(f?t.jsx("a",{className:"bim-d-flag",href:f,target:"_blank",rel:"noopener noreferrer",title:x,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:x,children:l("有影印")}))})]})}function cu({items:e,onNavigate:n,renderLink:i}){const r=ce(),{convert:s}=V(),[l,c]=g.useState(0),p=e[Math.min(l,e.length-1)];return t.jsx(Be,{id:"catalogs",title:"著錄",meta:s(`歷代書目 ${e.length} 家`),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-lu-list bim-d-ui",role:"tablist","aria-label":s("著錄書目"),children:e.map((a,d)=>t.jsx("li",{role:"presentation",children:t.jsx("button",{type:"button",role:"tab","aria-selected":d===l,onClick:()=>c(d),children:s(a.source)})},d))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[p.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:s(p.title_info)}),t.jsx(Le,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[p.source_bid?t.jsx(Ie,{id:p.source_bid,label:s(p.source),onNavigate:n,renderLink:i,dense:!0}):s(p.source),p.section?s(p.section):"",p.author_info?`${s(r.label.authorInfo)} ${s(p.author_info)}`:"",p.edition?`${s(r.label.edition)} ${s(p.edition)}`:"",p.page??""]}),p.summary&&t.jsx("p",{className:"bim-d-quote",children:De(s(p.summary))}),p.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s(r.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:De(s(p.comment))})]}),p.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s(r.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:De(s(p.additional_comment))})]}),!p.summary&&!p.comment&&!p.additional_comment&&!p.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:s("僅著錄書名,無提要。")})]})]})})}const Ko=40,qo=2,du=9,Jo={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function En(e){if(!e)return["",""];const n=e.split(/[ ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Ys=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,fullText:l,fullTextPending:c,chapterLink:p,railTop:a,back:d,railLinks:u})=>{var Y,T,ee,ie,ye,me,Ce,_e,We,Fe,Te,He,Ke,Nt;const f=ce(),{convert:x}=V(),[m,b]=g.useState(null),[w,h]=g.useState(new Map),[j,y]=g.useState([]),[k,_]=g.useState(new Map),[v,$]=g.useState(!1);g.useEffect(()=>{if(!n||!e.work_id){b(null);return}let N=!1;return n.getItem(e.work_id).then(ae=>{!N&&ae&&ae.type==="work"&&b(ae)}).catch(()=>{}),()=>{N=!0}},[n,e.work_id]),g.useEffect(()=>{const N=e.contained_in||[];if(!n||N.length===0){h(new Map);return}let ae=!1;return Promise.all(N.map(ue=>{const ke=typeof ue=="string"?ue:ue.id;return n.getItem(ke).then(je=>[ke,je]).catch(()=>[ke,null])})).then(ue=>{if(ae)return;const ke=new Map;for(const[je,he]of ue)he&&ke.set(je,he);h(ke)}),()=>{ae=!0}},[n,e.contained_in]);const S=g.useMemo(()=>{const N=new Set([...(m==null?void 0:m.books)||[],...e.related_books||[]]);return N.add(e.id),[...N]},[m==null?void 0:m.books,e.related_books,e.id]),z=S.length-1;g.useEffect(()=>{if(!n||z<=0){y([]);return}const N=S.length<=Ko,ae=N?S:S.slice(0,8);let ue=!1;return Promise.all(ae.map(ke=>ke===e.id?Promise.resolve({id:ke,title:e.title,edition:e.edition,year:un(e)}):n.getItem(ke).then(je=>{const he=je??{};return{id:ke,title:he.title,edition:he.edition,year:je?un(he):void 0}}).catch(()=>({id:ke})))).then(ke=>{if(ue)return;const je=ke.filter(he=>he.id===e.id||he.title||he.edition);N&&je.sort((he,Re)=>(he.year??1/0)-(Re.year??1/0)),y(je)}),()=>{ue=!0}},[n,S,z,e]);const I=e.lineage,R=g.useMemo(()=>[...((I==null?void 0:I.derived_from)||[]).filter(N=>N.ref_type==="book").map(N=>N.ref),...((I==null?void 0:I.related_to)||[]).map(N=>N.book_id)].filter(Boolean),[I]);g.useEffect(()=>{if(!n||R.length===0){_(new Map);return}let N=!1;return Promise.all(R.map(ae=>n.getItem(ae).then(ue=>[ae,{id:ae,title:ue==null?void 0:ue.title,edition:ue==null?void 0:ue.edition}]).catch(()=>[ae,{id:ae}]))).then(ae=>{N||_(new Map(ae))}),()=>{N=!0}},[n,R]);const C=g.useMemo(()=>Hs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),F=C.groups.reduce((N,ae)=>N+ae.rows.length+ae.mirrors.length,0),W=C.groups.length>0&&C.groups.every(N=>N.key==="_physical"),B=Vt(e),M=Wr(e),U=st(e,f.unit.juan),G=new Set((e.contained_in||[]).map(N=>typeof N=="string"?0:Dt(N.volume_index).length).filter(N=>N>0)),E=N=>{var ke;const ae=(ke=e.base_edition)==null?void 0:ke.find(je=>je.book_id===N&&je.name);if(ae!=null&&ae.name)return ae.name;const ue=k.get(N);return(ue==null?void 0:ue.edition)||(ue==null?void 0:ue.title)||""},oe=g.useMemo(()=>{var pt,lt,Xt,at,Qt;const N=[];M&&N.push({label:"版本類型",value:x(M),title:e.edition_type||(pt=e.lineage)!=null&&pt.category?void 0:x("據版本題名推斷")}),(lt=e.publication_info)!=null&<.details?N.push({label:"刊印",value:x(e.publication_info.details)}):(B.era||B.reign)&&N.push({label:"刊寫年代",value:x([B.era,B.reign].filter(Boolean).join(" ")),title:B.source==="edition"?x("據版本題名推斷"):void 0}),U&&N.push({label:"卷帙",value:x(U)});const ae=(e.contained_in||[]).flatMap(Se=>typeof Se=="string"?[]:Dt(Se.volume_index));ae.length&&N.push({label:"冊次",value:x(`第 ${jn(ae,f.unit.volume)} ${f.unit.volume}(${ae.length} ${f.unit.volume})`)});const ue=(((Xt=e.lineage)==null?void 0:Xt.derived_from)||[]).find(Se=>Se.relation==="底本"&&Se.ref_type==="book");ue&&E(ue.ref)&&N.push({label:"底本",value:t.jsx(Ie,{id:ue.ref,label:x(E(ue.ref)),onNavigate:i,renderLink:r,dense:!0})});const ke=(e.base_edition||[]).filter(Se=>Se&&Se.name);for(const Se of["底本","配補","參校"]){if(Se==="底本"&&ue&&E(ue.ref))continue;const Ge=ke.filter(ze=>ze.role===Se);Ge.length&&N.push({label:Se,value:Ge.map((ze,en)=>t.jsxs(g.Fragment,{children:[en>0&&"、",ze.book_id?t.jsx(Ie,{id:ze.book_id,label:x(ze.name),onNavigate:i,renderLink:r,dense:!0}):x(ze.name)]},en))})}const je=(e.provenance||[]).filter(Se=>Se&&Se.institution),he=(e.resources||[]).filter(Se=>(Se.types||(Se.type?[Se.type]:[])).includes("physical"));if(je.length){N.push({label:"存藏",value:je.slice(0,2).map(ze=>x(ze.institution)).join("、")+(je.length>2?x(` 等 ${je.length} 處`):"")});const Se=je.filter(ze=>ze.call_number).slice(0,2).map(ze=>`${x(ze.institution)} ${ze.call_number}`);Se.length&&N.push({label:"索書號",value:Se.join(";")+(je.filter(ze=>ze.call_number).length>2?"…":"")});const Ge=je.flatMap(ze=>ze.seals||[]).filter(Boolean);Ge.length&&N.push({label:"藏印",value:x(Ge.join("、"))})}else he.length?N.push({label:"存藏",value:he.slice(0,2).map(Se=>x(Se.name)).join("、")+(he.length>2?x(` 等 ${he.length} 處`):"")}):(at=e.current_location)!=null&&at.name&&N.push({label:"存藏",value:x(e.current_location.name)});const Re=e.physical_description;if(Re){const Se=[["行款",Re.leaf_style],["裝幀",Re.binding],["尺寸",Re.dimensions],["品相",Re.condition]];for(const[Ge,ze]of Se)ze&&ze.trim()&&N.push({label:Ge,value:x(ze)})}(Qt=e.page_count)!=null&&Qt.description&&N.push({label:f.label.pageCount,value:x(e.page_count.description)});const tt=[...Un(e.additional_titles),...Un(e.attached_texts)];return tt.length&&N.push({label:"又名",value:tt.map(x).join("、")}),N},[e,x,f,B,M,U,k,i,r]),P=x(e.title),le=e.edition?x(e.edition):void 0,ge=((Y=e.lineage)==null?void 0:Y.year_text)||"",Q=t.jsx(Kt,{kind:"版本",title:P,subtitle:le,byline:t.jsx(Li,{authors:e.authors??(m==null?void 0:m.authors),onNavigate:i,renderLink:r}),meta:t.jsx(Le,{items:[M?x(M):"",B.era?x([B.era,B.reign].filter(Boolean).join("")):"",U?x(U):""]}),description:(T=e.description)!=null&&T.text?t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:fi((ee=e.description)==null?void 0:ee.text)?6:void 0,facts:oe,readAction:s,secondaryAction:s&&F>0&&!W?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),O=e.contained_in||[],q=(l==null?void 0:l.chapters)||[],de=q[0]&&En(q[0].title)[0].slice(-1)||"章",se=!!((ie=I==null?void 0:I.derived_from)!=null&&ie.length||(ye=I==null?void 0:I.related_to)!=null&&ye.length||(me=e.appendix)!=null&&me.length),te=[];(q.length||C.text.length||c)&&te.push({id:"fulltext",label:"全文",count:q.length?x(`${q.length} ${de}`):void 0}),C.groups.length&&te.push({id:"images",label:W?"館藏":"影印",count:F}),se&&te.push({id:"lineage",label:"版本源流"}),O.length&&te.push({id:"collections",label:"收入叢編",count:O.length}),(Ce=e.location_history)!=null&&Ce.length&&te.push({id:"provenance",label:"流轉歷史"});const D=N=>(p==null?void 0:p(N))??null,K=q[0],X=K?D(K.file):null,xe=v?q:q.slice(0,du),A=(N,ae,ue)=>N?t.jsx("a",{className:ue,href:N.href??"#",onClick:N.onClick?ke=>{ke.metaKey||ke.ctrlKey||(ke.preventDefault(),N.onClick())}:void 0,children:ae}):t.jsx("span",{className:ue,children:ae}),re=t.jsxs(t.Fragment,{children:[(q.length>0||C.text.length>0||c)&&t.jsxs(Be,{id:"fulltext",title:"全文",meta:q.length>0?t.jsx(Le,{items:[x(`${q.length} ${de}`),(_e=l==null?void 0:l.source)!=null&&_e.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[c&&!K&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),K&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${En(K.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((K.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),A(X,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),q.length>1&&t.jsx("ul",{className:"bim-d-chap",children:xe.map(N=>{const[ae,ue]=En(N.title);return t.jsx("li",{children:A(D(N.file),t.jsxs(t.Fragment,{children:[ae&&t.jsx("b",{children:x(ae)}),x(ue||N.file)]}))},N.file)})}),q.length>xe.length&&t.jsx(Et,{label:`展開其餘 ${q.length-xe.length} ${de}`,onClick:()=>$(!0)}),C.text.length>0&&t.jsxs(t.Fragment,{children:[(q.length>0||c)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:C.text.map((N,ae)=>t.jsx(Bi,{item:N,siblings:C.text,listedVolumeCounts:G},`${N.id||N.url||N.name}-${ae}`))})})]})]}),C.groups.length>0&&t.jsx(Be,{id:"images",title:W?"館藏":"影印",meta:t.jsx(Le,{items:[C.groups.length>1?x(`${C.groups.length} 組`):"",x(`${F} 處`)]}),children:t.jsx(Us,{groups:C.groups,listedVolumeCounts:G})}),se&&t.jsxs(Be,{id:"lineage",title:"版本源流",meta:(We=I==null?void 0:I.derived_from)!=null&&We.length?x("據版本傳承著錄"):void 0,children:[t.jsxs("ul",{className:"bim-d-tl",children:[((I==null?void 0:I.derived_from)||[]).map((N,ae)=>{const ue=N.ref_type==="book"?E(N.ref):"";return t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(N.relation)}),N.ref_type==="book"?t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(Ie,{id:N.ref,label:x(ue||N.ref),onNavigate:i,renderLink:r,dense:!0})}):t.jsx("span",{className:"bim-d-tl-t",children:x("擬構祖本")}),(N.evidence||N.confidence)&&t.jsxs("span",{className:"bim-d-tl-ev",children:[N.evidence?x(N.evidence):"",N.confidence&&Jo[N.confidence]?x(`(${Jo[N.confidence]})`):""]})]},`d-${ae}`)}),(Fe=I==null?void 0:I.derived_from)!=null&&Fe.length||(Te=I==null?void 0:I.related_to)!=null&&Te.length?t.jsxs("li",{className:"bim-d-tl-cur",children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("本版")}),t.jsx("span",{className:"bim-d-tl-t",children:le||P}),ge&&t.jsxs("span",{className:"bim-d-meta",children:[t.jsx("span",{className:"bim-d-dot"}),x(ge)]})]}):null,((I==null?void 0:I.related_to)||[]).map((N,ae)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(N.relation)}),t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(Ie,{id:N.book_id,label:x(E(N.book_id)||N.book_id),onNavigate:i,renderLink:r,dense:!0})}),N.evidence&&t.jsx("span",{className:"bim-d-tl-ev",children:x(N.evidence)})]},`r-${ae}`)),(He=e.appendix)==null?void 0:He.map((N,ae)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("附記")}),t.jsx("span",{className:"bim-d-tl-t",children:x(N.title)}),t.jsxs("details",{children:[t.jsx("summary",{className:"bim-d-ui",children:x("展開")}),t.jsx(rt,{text:N.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]})]},`a-${ae}`))]}),(I==null?void 0:I.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"10px 0 0",maxWidth:"46em"},children:x(I.note)})]}),O.length>0&&t.jsx(Be,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:O.map((N,ae)=>{var Re,tt;const ue=typeof N=="string"?N:N.id,ke=typeof N=="string"?[]:Dt(N.volume_index),je=w.get(ue),he=(je==null?void 0:je._member_count)||((Re=je==null?void 0:je.books)==null?void 0:Re.length)||((tt=je==null?void 0:je.contained_works)==null?void 0:tt.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Ie,{id:ue,label:je?x(je.title):ue,onNavigate:i,renderLink:r,dense:!0}),ke.length>0&&t.jsx(pu,{volumes:ke,unit:f.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${he?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:he>0&&x(`全 ${he} ${f.unit.bu}`)})]},`${ue}-${ae}`)})})})}),(Ke=e.location_history)!=null&&Ke.length?t.jsx(Be,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((N,ae)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(N.name)}),([N.start_date,N.end_date].filter(Boolean).join("—")||N.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(Le,{items:[[N.start_date,N.end_date].filter(Boolean).join("—"),N.description?x(N.description):""]})})]},ae))})}):null,te.length===0&&t.jsx(Be,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),ne=j.findIndex(N=>N.id===e.id),pe=S.length<=Ko,fe=pe&&ne>=0?j.slice(Math.max(0,ne-qo),ne+qo+1):j.filter(N=>N.id!==e.id),L=t.jsxs(t.Fragment,{children:[m&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:x(f.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Ie,{id:m.id,label:x(m.title),onNavigate:i,renderLink:r})}),t.jsx(Le,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(m.authors||[]).slice(0,2).map(N=>`${N.dynasty?`〔${x(N.dynasty)}〕`:""}${x(N.name)}`),x(st(m,f.unit.juan)),m._edition_count?x(`${m._edition_count} 種版本`):""]}),((Nt=m.description)==null?void 0:Nt.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:x(m.description.text.replace(/[#*_>`[\]]/g,""))})]}),z>0&&fe.length>0&&t.jsxs("div",{children:[t.jsx(gt,{id:"siblings",title:pe?"同作品版本":f.relation.siblingVersions,meta:x(pe?"按年代":`${z} 種`),cap:fe.length,items:fe.map(N=>N.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(N.edition||N.title||N.id)}):t.jsx(Ie,{id:N.id,label:x(N.edition||N.title||N.id),onNavigate:i,renderLink:r,dense:!0})),metas:fe.map(N=>[N.year!=null?N.year<0?`前${-N.year}`:String(N.year):"",N.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:fe.findIndex(N=>N.id===e.id)}),m&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Ie,{id:m.id,label:x(`在作品頁看全部 ${S.length} 種 →`),onNavigate:i,renderLink:r,dense:!0})})]})]}),J=e.work_id?t.jsx(Hr,{caption:f.section.belongsToWork,children:t.jsx(Ie,{id:e.work_id,label:m?x(m.title):" ",onNavigate:i,renderLink:r,dense:!0})}):void 0;return t.jsx(Yt,{railTop:a,back:d,up:J,nav:te,railLinks:u,main:re,card:Q,side:L})};function pu({volumes:e,unit:n}){const{convert:i}=V();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${jn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}const Zo=16,Ks=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,railTop:c,back:p,railLinks:a})=>{var Q,O,q,de,se,te;const d=ce(),{convert:u}=V(),[f,x]=g.useState(""),[m,b]=g.useState(!1),[w,h]=g.useState(null),j=g.useMemo(()=>Br(e,n),[e,n]),[y,k]=g.useState(new Map),_=g.useMemo(()=>{const D=f.trim();if(!D)return j.rows;const K=u(D);return j.rows.filter(X=>{var A;const xe=X.id&&((A=y.get(X.id))==null?void 0:A.title)||X.title;return u(xe).includes(K)||(X.subItems||[]).some(re=>u(re).includes(K))})},[j.rows,f,y,u]),v=m?_:_.slice(0,Zo),$=g.useMemo(()=>v.filter(D=>D.id&&!y.has(D.id)).map(D=>D.id),[v,y]);g.useEffect(()=>{if(!i||$.length===0)return;let D=!1;return Promise.all($.map(K=>i.getItem(K).then(X=>{var re;const xe=X??{},A={title:xe.title,edition:xe.edition,authors:xe.authors,measure:X?st(X,d.unit.juan):void 0,versionCount:xe._edition_count??((re=xe.books)==null?void 0:re.length)};return[K,A]}).catch(()=>[K,{}]))).then(K=>{D||k(X=>{const xe=new Map(X);for(const[A,re]of K)xe.set(A,re);return xe})}),()=>{D=!0}},[i,$,d.unit.juan]);const S=(e.contained_in||[])[0];g.useEffect(()=>{if(!S){h(null);return}if(h({id:S}),!i)return;let D=!1;return i.getItem(S).then(K=>{D||h({id:S,title:K==null?void 0:K.title})}).catch(()=>{}),()=>{D=!0}},[i,S]);const z=g.useMemo(()=>Hs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),I=z.text.length+z.groups.reduce((D,K)=>D+K.rows.length+K.mirrors.length,0),R=e.contained_works||[],C=new Set(j.rows.map(D=>D.id).filter(Boolean)),F=R.length>0&&!R.every(D=>C.has(D.id)),W=(()=>{const D=j.rows.map(K=>K.edition).filter(Boolean);return D.length>1&&new Set(D).size===1})(),B=j.rows.some(D=>D.volumes.length>0||D.expected!=null),M=e._member_count||((Q=e.books)==null?void 0:Q.length)||R.length,U=g.useMemo(()=>{var A,re,ne;const D=[];if(j.rows.length&&D.push({label:"子目",value:`${j.rows.length} ${u(d.unit.items)}`}),M&&M!==j.rows.length){const pe=e._member_type==="Book"?"所收版本":e._member_type==="Work"?"所收作品":"成員";D.push({label:u(pe),value:`${M} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")})}const K=st(e,d.unit.juan),X=e.count;if(X){const pe=L=>typeof L=="number"&&Number.isFinite(L)?L:null,fe=[pe(X.zhong)!=null?`${X.zhong} 種`:"",pe(X.ce)!=null?`${X.ce} ${d.unit.volume}`:"",pe(X.han)!=null?`${X.han} 函`:"",!K&&pe(X.juan)!=null?`${X.juan} ${d.unit.juan}`:""].filter(Boolean);fe.length&&D.push({label:"應收",value:u(fe.join(" "))})}const xe=j.totalVolumes?`${j.totalVolumes} ${u(d.unit.volume)}`:"";return(K||xe)&&D.push({label:"卷帙",value:[K?u(K):"",xe].filter(Boolean).join(" "),title:(A=e.juan_count)!=null&&A.description?u(e.juan_count.description):void 0}),(re=e.publication_info)!=null&&re.details&&D.push({label:"刊印",value:u(e.publication_info.details)}),(ne=e.publication_info)!=null&&ne.year&&D.push({label:"年代",value:u(e.publication_info.year)}),D},[e,M,j.rows.length,j.totalVolumes,u,d]),G=(O=e.description)==null?void 0:O.text,E=t.jsx(Kt,{kind:"叢編",title:u(e.title),byline:t.jsx(Li,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Le,{items:[e.subtype==="work_collection"?u("作品集"):"",(q=e.publication_info)!=null&&q.year?u(e.publication_info.year):""]}),description:G||(de=e.history)!=null&&de.length?t.jsxs(t.Fragment,{children:[G&&t.jsx(rt,{text:G,style:{fontSize:15,lineHeight:1.85}}),(se=e.history)!=null&&se.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((D,K)=>t.jsx("li",{children:u(D)},K))}):null]}):void 0,clampDescription:fi(G)||(((te=e.history)==null?void 0:te.length)??0)>2?6:void 0,facts:U,foot:t.jsx(qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),oe=[];j.rows.length&&oe.push({id:"titles",label:"子目",count:j.rows.length}),I&&oe.push({id:"resources",label:"影印與全文",count:I}),F&&oe.push({id:"works",label:d.section.containedWorks,count:R.length});const P=t.jsxs(t.Fragment,{children:[j.rows.length>0&&t.jsxs(Be,{id:"titles",title:"子目",meta:t.jsx(Le,{items:[u(`${j.rows.length} ${d.unit.items}`),j.totalVolumes?u(`全帙 ${j.totalVolumes} ${d.unit.volume}`):"",_.length!==j.rows.length?u(`當前 ${_.length} ${d.unit.items}`):""]}),action:l,children:[j.rows.length>Zo&&t.jsx("div",{className:"bim-d-filters bim-d-ui",children:t.jsx("input",{type:"search",className:"bim-d-find",value:f,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:D=>{x(D.target.value),b(!1)}})}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[B&&t.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),t.jsx("th",{children:u("書名")}),t.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),t.jsx("tbody",{children:v.map((D,K)=>{var pe;const X=D.id?y.get(D.id):void 0,xe=X!=null&&X.title&&D.title===D.id?X.title:D.title,A=((X==null?void 0:X.authors)||[]).find(fe=>fe&&fe.name),re=[A?`${A.dynasty?`〔${u(A.dynasty)}〕`:""}${u(A.name)}${A.role?` ${u(A.role)}`:""}`:"",X!=null&&X.measure?u(X.measure):"",(pe=D.subItems)!=null&&pe.length?D.subItems.map(fe=>u(fe)).join("、"):"",(X!=null&&X.edition||D.edition)&&!W?u((X==null?void 0:X.edition)||D.edition||""):""].filter(Boolean),ne=D.volumes.length>0?u(`第 ${jn(D.volumes,d.unit.volume)} ${d.unit.volume}`):D.expected!=null?u(`${D.found??0}/${D.expected} ${d.unit.volume}`):"";return t.jsxs("tr",{children:[B&&t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ne?"":" bim-d-zt-blank"}`,children:ne||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsxs("td",{className:"bim-d-zt-main",children:[D.id?t.jsx(Ie,{id:D.id,label:u(xe),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(xe)}),re.length>0?t.jsx(Le,{items:re}):D.id&&!X&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${X!=null&&X.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:X!=null&&X.versionCount?u(`${X.versionCount} 種`):""})]},`${D.id??D.title}-${K}`)})})]}),v.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),_.length>v.length&&t.jsx(Et,{label:`展開其餘 ${_.length-v.length} ${d.unit.items}`,onClick:()=>b(!0)})]}),I>0&&t.jsxs(Be,{id:"resources",title:"影印與全文",meta:u(`${I} 處`),children:[z.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[z.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:z.text.map((D,K)=>t.jsx(Bi,{item:D,siblings:z.text},`${D.id||D.url||D.name}-${K}`))})})]}),t.jsx(Us,{groups:z.groups})]}),j.rows.length===0&&I===0&&t.jsx(Be,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),le=F?t.jsx(gt,{id:"works",title:d.section.containedWorks,meta:u(`${R.length} 種`),cap:12,items:R.map(D=>t.jsx(Ie,{id:D.id,label:u(D.title),onNavigate:r,renderLink:s,dense:!0}))}):null,ge=w?t.jsx(Hr,{caption:"上級叢編",children:t.jsx(Ie,{id:w.id,label:u(w.title||w.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(Yt,{railTop:c,back:p,up:ge,nav:oe,railLinks:a,main:P,card:E,side:le})},uu=16,Nn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Xo(e){if(!e)return Nn.length;const n=Nn.indexOf(e);return n===-1?Nn.length:n}const xu={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function ln(e){return e==null?"":e<0?`前${-e}`:String(e)}const qs=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:c})=>{var A,re,ne,pe,fe;const p=ce(),{convert:a}=V(),[d,u]=g.useState("全部"),[f,x]=g.useState(!1),[m,b]=g.useState("default"),[w,h]=g.useState(new Map),j=g.useMemo(()=>(e.works||[]).map(L=>{const J=w.get(L.work_id);return{id:L.work_id,title:(J==null?void 0:J.title)??L.title??L.work_id,role:L.role||"",cls:pi(L.role),versionCount:J==null?void 0:J.versionCount,section:J==null?void 0:J.cls,measure:J==null?void 0:J.measure,hasImage:J==null?void 0:J.hasImage,loaded:!!(J!=null&&J.loaded)}}),[e.works,w]),y=g.useMemo(()=>Lr((e.works||[]).map(L=>L.role)),[e.works]),k=g.useMemo(()=>{const L=d==="全部"?j:j.filter(J=>J.cls===d);return m==="versions"?[...L].sort((J,Y)=>(Y.versionCount??-1)-(J.versionCount??-1)):L},[j,d,m]),_=f?k:k.slice(0,uu),v=g.useMemo(()=>_.filter(L=>!w.has(L.id)).map(L=>L.id),[_,w]);g.useEffect(()=>{if(!n||v.length===0)return;let L=!1;return Promise.all(v.map(J=>n.getItem(J).then(Y=>{var ye,me,Ce,_e;const T=Y??{},ee=T._edition_count??(((ye=T.books)==null?void 0:ye.length)??0)+(((me=T.collections)==null?void 0:me.length)??0),ie=[(Ce=T.classification)==null?void 0:Ce.l1,(_e=T.classification)==null?void 0:_e.l2].filter(Boolean).join(" ");return[J,{id:J,title:T.title,versionCount:ee,loaded:!0,cls:ie||void 0,measure:Y&&st(Y,p.unit.juan)||void 0,hasImage:!!(T.has_image??T._has_image)}]}).catch(()=>[J,{id:J,loaded:!0}]))).then(J=>{L||h(Y=>{const T=new Map(Y);for(const[ee,ie]of J)T.set(ee,ie);return T})}),()=>{L=!0}},[n,v,p.unit.juan]);const $=g.useMemo(()=>{const L=new Map;for(const J of e.alt_names||[]){const Y=J.type||p.section.aliases;L.has(Y)||L.set(Y,[]),L.get(Y).push(J.name)}return[...L.entries()].sort((J,Y)=>Xo(J[0])-Xo(Y[0])).map(([J,Y])=>({label:J,names:Y}))},[e.alt_names,p]),S=e.birth_year??((A=e.dates)==null?void 0:A.birth)??void 0,z=e.death_year??((re=e.dates)==null?void 0:re.death)??void 0,I=(ne=e.dates)==null?void 0:ne.floruit,R=S!=null||z!=null?`${ln(S)||"?"}—${ln(z)||"?"}`:Array.isArray(I)&&I.length===2&&I.every(L=>Number.isFinite(L))?`活躍於 ${ln(I[0])}—${ln(I[1])}`:"",C=new Set(["本名","字","號","号"]),F=$.filter(L=>C.has(L.label)),W=$.filter(L=>!C.has(L.label)),B=W.reduce((L,J)=>L+J.names.length,0),M=g.useMemo(()=>{const L=[];for(const Y of F)L.push({label:Y.label,value:Y.names.map(T=>a(T)).join("、")});const J=(e.works||[]).length;return J&&L.push({label:"著作",value:`${J} ${a("種")}`}),L},[e.works,F,a]),U=L=>{var J;return(J=$.find(Y=>L.includes(Y.label)))==null?void 0:J.names[0]},G=U(["字"]),E=U(["號","号"]),oe=[G?`字${G}`:"",E?`號${E}`:""].filter(Boolean).join(","),P=e.native_place,le=t.jsx(Kt,{kind:xu[e.subtype]??"人物",title:a(e.primary_name||e.title),subtitle:oe?a(oe):void 0,meta:t.jsx(Le,{items:[e.dynasty?a(e.dynasty):"",R?a(R):"",P?a(`${P}人`):""]}),description:(pe=e.description)!=null&&pe.text?t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:fi((fe=e.description)==null?void 0:fe.text)?6:void 0,facts:M,foot:t.jsx(qt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:B>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:a(`更多別名(${B})`)}),t.jsx("dl",{children:W.map(L=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:a(L.label)}),t.jsx("dd",{children:L.names.map(J=>a(J)).join("、")})]},L.label))})]})}),ge=g.useMemo(()=>j.filter(L=>L.loaded&&(L.versionCount??0)>0).sort((L,J)=>(J.versionCount??0)-(L.versionCount??0)).slice(0,3),[j]),Q=!!n&&j.length>=3&&_.some(L=>!L.loaded),O=d==="全部"&&(Q||ge.length>=2),q=e.external_ids||{},de=[];q.cbdb_id!=null&&de.push({label:"CBDB",id:String(q.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${q.cbdb_id}`,note:q.cbdb_match==="auto"?"自動匹配":void 0});const se=q.wikidata_id;se&&de.push({label:"Wikidata",id:se,href:`https://www.wikidata.org/wiki/${se}`});const te=q.viaf_id;te&&de.push({label:"VIAF",id:te,href:`https://viaf.org/viaf/${te}`});const D=y.map(L=>({key:L.cls,label:`${L.label} ${L.count}`})),K=j.length?[{id:"works",label:"著作",count:j.length}]:[],X=j.length===0?t.jsx(Be,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該人物的關聯作品。")})}):t.jsxs(Be,{id:"works",title:"著作",meta:t.jsx(Le,{items:[a(`共 ${j.length} 種`),k.length!==j.length?a(`當前 ${k.length} 種`):""]}),children:[O&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"-6px 0 10px",fontSize:14},children:a("著作舉要")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":Q||void 0,children:[Q&&[0,1,2].map(L=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},L)),!Q&&ge.map(L=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Ie,{id:L.id,label:a(L.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx(Le,{items:[L.section?a(L.section):"",L.measure?a(L.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[a(`${L.versionCount} 種版本`),L.hasImage&&t.jsx("span",{className:"bim-d-flag",children:a("有影印")})]})]},L.id))]})]}),t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[D.length>1&&t.jsx(xi,{items:D,value:d,onChange:L=>{u(L),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":m==="versions",onClick:()=>{m==="default"&&x(!0),b(L=>L==="default"?"versions":"default")},children:a(m==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("作品")}),t.jsx("th",{children:a("職任")}),t.jsx("th",{children:a("存世版本")}),t.jsx("th",{"aria-label":a("影印")})]})}),t.jsx("tbody",{children:_.map(L=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Ie,{id:L.id,label:a(L.title),onNavigate:i,renderLink:r,dense:!0}),L.section||L.measure?t.jsx(Le,{items:[L.section?a(L.section):"",L.measure?a(L.measure):""]}):!L.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${L.role?"":" bim-d-zt-blank"}`,children:L.role?a(L.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${L.loaded?"":" bim-d-zt-blank"}`,children:L.loaded?L.versionCount?a(`${L.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:a("未著錄")}):""}),t.jsx("td",{className:L.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:L.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:a("有影印")})})]},L.id))})]}),_.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a("該職任下的著作尚未著錄。")}),k.length>_.length&&t.jsx(Et,{label:`展開其餘 ${k.length-_.length} 種著作`,onClick:()=>x(!0)})]}),xe=de.length>0?t.jsx(gt,{id:"external",title:"站外資料",items:de.map(L=>t.jsxs("a",{href:L.href,target:"_blank",rel:"noopener noreferrer",children:[L.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:de.map(L=>[L.id,L.note?a(L.note):""].filter(Boolean).join(" · "))}):null;return t.jsx(Yt,{railTop:s,back:l,nav:K,railLinks:c,main:X,card:le,side:xe})},Ai="(max-width: 719px)",fu=`${Ai}, (pointer: coarse)`,Js=`
|
|
688
688
|
.bim-ct {
|
|
689
689
|
display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
|
|
690
690
|
max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
|
|
@@ -774,7 +774,7 @@ ${tc}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
|
|
|
774
774
|
.bim-ct-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
775
775
|
}
|
|
776
776
|
|
|
777
|
-
@media ${
|
|
777
|
+
@media ${Ai} {
|
|
778
778
|
.bim-ct { display: block; padding: 12px 16px 40px; }
|
|
779
779
|
.bim-ct-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
|
|
780
780
|
.bim-ct-side { position: static; max-height: none; overflow: visible; margin: 0 0 12px; }
|
|
@@ -802,4 +802,4 @@ ${tc}`;function Mt({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
|
|
|
802
802
|
.bim-ct-tw { width: 44px; }
|
|
803
803
|
.bim-ct-pg { min-width: 44px; height: 44px; }
|
|
804
804
|
}
|
|
805
|
-
`,Dt="未分類",tt="all",Ei=20;function qt(e){if(!e)return[];const n=[];for(const i of[e.l1,e.l2,e.l3,e.l4]){const r=(i??"").trim();if(!r)break;n.push(r)}return n}function gu(e){const n=qt(e);return n.length?n.join("/"):Dt}function mu(e){const n=qt(e);return n.length?n.map((i,r)=>n.slice(0,r+1).join("/")):[Dt]}function hu(e,n=[]){const i=new Map;n.forEach((p,a)=>{const d=[p.cata_l1,p.cata_l2,p.cata_l3,p.cata_l4].filter(u=>!!u);d.forEach((u,f)=>{const x=d.slice(0,f+1).join("/");i.has(x)||i.set(x,a)})});const r=new Map;let s=0;for(const p of e){const a=qt(p.classification);if(!a.length){s++;continue}let d=r;a.forEach((u,f)=>{const x=a.slice(0,f+1).join("/");let m=d.get(u);m||(m={id:x,label:u,count:0,children:new Map},d.set(u,m)),m.count++,d=m.children})}const l=p=>[...p.values()].sort((a,d)=>{const u=i.get(a.id)??1/0,f=i.get(d.id)??1/0;return u!==f?u-f:a.label.localeCompare(d.label,"zh")}).map(a=>{const d={id:a.id,label:a.label,count:a.count};return a.children.size&&(d.children=l(a.children)),d}),c=l(r);return s>0&&c.push({id:Dt,label:Dt,count:s}),c}function vt(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const r=vt(i.children,n);if(r.length)return[i,...r]}}return[]}function Ni(e){return e.reduce((n,i)=>n+i.count,0)}function bu(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function yu(e){var p;const n={id:e.id,title:e.title||e.id},i=e.juan_count,r=typeof i=="number"?i:i==null?void 0:i.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(a=>a==null?void 0:a.name).map(a=>{const d=a.dynasty||(e.authors.length===1?e.dynasty:void 0);return d?{name:a.name,dynasty:d}:{name:a.name}});s.length&&(n.authors=s);const l=bu(typeof e.description=="string"?e.description:(p=e.description)==null?void 0:p.text);l&&(n.summary=l);const c=qt(e.classification);return c.length&&(n.classification=c),n}function ju(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 vu(e,n=Ei){return Math.max(1,Math.ceil(e/n))}function Ks(e,n,i=2){if(n<=1)return[1];const r=new Set([1,n]);for(let c=e-i;c<=e+i;c++)c>=1&&c<=n&&r.add(c);const s=[...r].sort((c,p)=>c-p),l=[];return s.forEach((c,p)=>{if(p>0){const a=c-s[p-1];a===2?l.push(c-1):a>2&&l.push(null)}l.push(c)}),l}const ku=()=>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 Su(e,n,i){const r=[];i&&r.push({id:tt,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,c)=>{var p;for(const a of l){const d=(p=a.children)!=null&&p.length?a.children:null;r.push({id:a.id,parentId:c,hasChildren:!!d,firstChildId:d?d[0].id:null}),d&&n.has(a.id)&&s(d,a.id)}};return s(e,null),r}function qs({tree:e,selectedId:n,onSelect:i,allLabel:r="全部",label:s="分類"}){const{convert:l}=V(),c=g.useRef(null),p=n&&n!==tt?n:null,a=r!==null,[d,u]=g.useState(()=>{const v=new Set;for(const $ of vt(e,p))v.add($.id);return v});g.useEffect(()=>{const v=vt(e,p);v.length&&u($=>{if(v.every(z=>$.has(z.id)))return $;const S=new Set($);for(const z of v)S.add(z.id);return S})},[e,p]);const f=g.useMemo(()=>Su(e,d,a),[e,d,a]),[x,m]=g.useState(null);g.useEffect(()=>{m(null)},[n]);const b=p??(a?tt:null),w=g.useMemo(()=>{var S;const v=new Set(f.map(z=>z.id));if(x&&v.has(x))return x;if(b&&v.has(b))return b;const $=vt(e,p).map(z=>z.id).filter(z=>v.has(z));return $.length?$[$.length-1]:((S=f[0])==null?void 0:S.id)??null},[f,x,b,e,p]),h=g.useCallback((v,$)=>{u(S=>{const z=S.has(v),T=$??!z;if(T===z)return S;const R=new Set(S);return T?R.add(v):R.delete(v),R})},[]),j=g.useCallback(v=>{m(v),requestAnimationFrame(()=>{var S;const $=Array.from(((S=c.current)==null?void 0:S.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===v);$==null||$.focus()})},[]),y=g.useCallback((v,$)=>{$&&h(v,!0),i(v)},[i,h]),k=g.useCallback(v=>{const $=v.target.closest("[data-ct-id]");if(!$)return;const S=$.dataset.ctId,z=f.findIndex(C=>C.id===S);if(z<0)return;const T=f[z];let R=null;switch(v.key){case"ArrowDown":R=f[Math.min(f.length-1,z+1)].id;break;case"ArrowUp":R=f[Math.max(0,z-1)].id;break;case"Home":R=f[0].id;break;case"End":R=f[f.length-1].id;break;case"ArrowRight":if(!T.hasChildren)break;d.has(S)?R=T.firstChildId:h(S,!0);break;case"ArrowLeft":T.hasChildren&&d.has(S)?h(S,!1):R=T.parentId;break;case"Enter":case" ":v.preventDefault(),y(S,T.hasChildren);return;default:return}v.preventDefault(),R&&R!==S&&j(R)},[f,d,h,j,y]),_=(v,$)=>v.map((S,z)=>{var W;const T=(W=S.children)!=null&&W.length?S.children:null,R=!!T&&d.has(S.id),C=S.id===p,P=$===1&&v.length>1&&z===v.length-1;return t.jsxs("li",{role:"treeitem","aria-level":$,"aria-expanded":T?R:void 0,"aria-selected":C,tabIndex:w===S.id?0:-1,"data-ct-id":S.id,className:P?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":$-1},onClick:()=>{m(S.id),y(S.id,!!T)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:T?A=>{A.stopPropagation(),m(S.id),h(S.id)}:void 0,children:T?t.jsx(ku,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(S.label)}),t.jsx("span",{className:"bim-ct-n",children:S.count.toLocaleString("en-US")})]}),R&&t.jsx("ul",{role:"group",children:_(T,$+1)})]},S.id)});return t.jsxs("ul",{ref:c,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:k,children:[a&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:w===tt?0:-1,"data-ct-id":tt,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{m(tt),i(tt)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),t.jsx("span",{className:"bim-ct-lb",children:l(r)}),t.jsx("span",{className:"bim-ct-n",children:Ni(e).toLocaleString("en-US")})]})}),_(e,1)]})}const Js=e=>`/item/${encodeURIComponent(e)}`;function wu(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function _u(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function Zs({work:e,href:n}){var c,p;const{convert:i}=V(),r=_u(e.juan),s=((c=e.authors)==null?void 0:c.filter(a=>a.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:n,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:i(e.title)}),r&&t.jsx("span",{className:"bim-ct-juan",children:i(r)})]}),s.length>0&&t.jsx("span",{className:"bim-ct-by",children:s.map((a,d)=>t.jsxs(g.Fragment,{children:[d>0&&"、",a.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(a.dynasty),"〕"]}),i(a.name)]},d))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:i(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(a=>i(a)).join(" · ")})]})})}function Xs({page:e,pageCount:n,onPage:i,pageHref:r,label:s="分頁"}){const{convert:l}=V();if(n<=1)return null;const c=a=>d=>{i&&(r&&!wu(d)||(d.preventDefault(),i(a)))},p=(a,d,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const f={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...f,href:r(a),onClick:c(a),children:d}):t.jsx("button",{type:"button",...f,onClick:u.current?void 0:c(a),children:d})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:Ks(e,n).map((a,d)=>t.jsx("li",{style:{display:"contents"},children:a===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(a,a,{current:a===e,aria:l(`第 ${a} 頁`)})},a??`gap${d}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),p(e+1,l("下一頁"),{disabled:e>=n})]})}function Qs({works:e,workLink:n=Js,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(Zs,{work:l,href:n(l.id)},l.id))}),t.jsx(Xs,{...r})]})}const $u=()=>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 zu({tree:e,selectedId:n,page:i,pageCount:r,works:s,onSelect:l,onPage:c,searchSlot:p,workLink:a,pageHref:d,allLabel:u="全部",allTitle:f="全部典籍",pageSize:x=Ei,className:m}){const{convert:b}=V(),h=`bim-ct-drawer-${g.useId().replace(/:/g,"")}`,[j,y]=g.useState(!1),k=vt(e,n&&n!==tt?n:null),_=k.length?k[k.length-1]:null,v=_?_.label:f,$=_?_.count:Ni(e),S=g.useCallback(z=>{y(!1),l(z)},[l]);return t.jsxs("div",{className:m?`bim-ct ${m}`:"bim-ct","data-drawer":j?"open":"closed",children:[t.jsx("style",{children:Ys}),t.jsxs("aside",{className:"bim-ct-side","aria-label":b("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":j,"aria-controls":h,onClick:()=>y(z=>!z),children:[t.jsxs("span",{children:[b("分類"),":",b(k.length?k.map(z=>z.label).join(" › "):u??f)]}),t.jsx($u,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:h,children:[t.jsx("h2",{className:"bim-ct-side-h",children:b("分類")}),t.jsx(qs,{tree:e,selectedId:n,onSelect:S,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(v)}),k.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:b(k.slice(0,-1).map(z=>z.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[b(`共 ${$.toLocaleString("en-US")} 種 · 每頁 ${x} 條`),r>1&&b(` · 第 ${i} / ${r} 頁`)]})]}),p&&t.jsx("div",{className:"bim-ct-search",children:p}),t.jsx(Qs,{works:s,workLink:a,page:i,pageCount:r,onPage:c,pageHref:d})]})]})}function Cu(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 Iu(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 Jo(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 Tu(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 Ru(e,n){var d;if(n==="all")return null;const i=(d=e.collections)==null?void 0:d[n],r=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,l=r||s||!!(i!=null&&i.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!i||!l)return null;const c=r?new Set(i.groups):null,p=new Set(i.book_ids??[]);if(c&&e.node_groups)for(const[u,f]of Object.entries(e.node_groups))c.has(f)&&p.add(u);let a=null;if(i.hypothetical_ids&&(a=new Set(i.hypothetical_ids)),c){a||(a=new Set);for(const u of e.hypothetical_nodes??[])u.group&&c.has(u.group)&&a.add(u.id)}return{books:p,hypos:a}}function rn(e,n,i){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const l=new Set(r.excluded_books??[]),c=r.node_groups??{},p=Ru(r,i??r.default_collection??"all"),a=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,f=new Set,x=new Set;if(a){const _=new Map(n.map(R=>[R.id,R])),v=new Map((r.hypothetical_nodes??[]).map(R=>[R.id,R])),$=R=>{const C=_.get(R);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(W=>W.ref);const P=v.get(R);return P?(P.derived_from??[]).map(W=>W.ref):[]},S=R=>v.has(R)?!u||u.has(R):!d||d.has(R),z=new Set,T=R=>{if(!z.has(R)){z.add(R);for(const C of $(R))l.has(C)||(S(C)||(v.has(C)?x.add(C):_.has(C)&&f.add(C)),T(C))}};for(const R of n)d&&d.has(R.id)&&!l.has(R.id)&&T(R.id);for(const R of r.hypothetical_nodes??[])u&&u.has(R.id)&&T(R.id)}const m=n.filter(_=>!l.has(_.id)).filter(_=>!d||d.has(_.id)||f.has(_.id)).map(_=>{const v=Iu(_,c);return v&&f.has(_.id)&&(v.bridge=!0),v}).filter(_=>_!==null),b=(r.hypothetical_nodes??[]).filter(_=>!u||u.has(_.id)||x.has(_.id)).map(_=>{const v=Cu(_);return x.has(_.id)&&(v.bridge=!0),v}),w=[...m,...b],h=new Set(w.map(_=>_.id)),j=new Set,y=[],k=_=>{j.has(_.id)||!h.has(_.source)||!h.has(_.target)||(j.add(_.id),y.push(_))};for(const _ of n)l.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!f.has(_.id)||((_.lineage.derived_from??[]).forEach((v,$)=>{k(Jo(_.id,v,$))}),(_.lineage.related_to??[]).forEach((v,$)=>{k(Tu(_.id,v,$))}));for(const _ of r.hypothetical_nodes??[])u&&!u.has(_.id)&&!x.has(_.id)||(_.derived_from??[]).forEach((v,$)=>{k(Jo(_.id,v,$))});return{nodes:w,edges:y,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function el(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Eu(e,n){const i=[],r=e.version_graph;if(!r)return i;const s=new Set(n.map(a=>a.id)),l=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),c=new Set([...s,...l]),p=(a,d)=>{c.has(d.ref)||i.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(u=>p(d,u)),(a.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||i.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(u=>p(d,u))}return i}const tl=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:s}=V();if(!e.nodes.length)return t.jsx("div",{style:{...Vu,...r},className:i,children:"暂无版本图数据"});const l=new Map,c=new Map;for(const x of e.edges)if(x.kind==="derive"){const m=l.get(x.target)??[];m.push(x),l.set(x.target,m)}else for(const m of[x.source,x.target]){const b=c.get(m)??[];b.push(x),c.set(m,b)}const p=new Map(e.nodes.map(x=>[x.id,x])),a=new Map,d=[];for(const x of e.nodes)if(x.group){const m=a.get(x.group)??[];m.push(x),a.set(x.group,m)}else d.push(x);const u=(x,m)=>(x.year??9999)-(m.year??9999);a.forEach(x=>x.sort(u)),d.sort(u);const f=e.groups.filter(x=>a.has(x.id));return t.jsxs("div",{className:i,style:{...Lu,...r},children:[e.title&&t.jsx("div",{style:Bu,children:s(e.title)}),e.description&&t.jsx("div",{style:Au,children:s(e.description)}),f.map(x=>t.jsx(Zo,{label:x.label,color:x.color,nodes:a.get(x.id),incomingMap:l,siblingMap:c,nodeMap:p,renderLink:n},x.id)),d.length>0&&t.jsx(Zo,{label:"其他",nodes:d,incomingMap:l,siblingMap:c,nodeMap:p,renderLink:n})]})},Zo=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:c})=>{const{convert:p}=V();return t.jsxs("div",{style:Wu,children:[t.jsx("div",{style:{...Mu,borderLeftColor:n??o("widget-border")},children:p(e)}),i.map(a=>t.jsx(Nu,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:l,renderLink:c},a.id))]})},Nu=({node:e,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",c=e.bridge,{convert:p}=V();return t.jsxs("div",{style:{...Fu,borderStyle:l||c?"dashed":"solid",opacity:c?.55:e.status==="lost"?.7:1,background:c?o("bg-subtle"):void 0},title:c?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:Pu,children:[t.jsx("span",{style:Ou,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Du,children:el(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Hu,children:[e.category&&t.jsx(Wt,{children:p(e.category)}),e.status==="lost"&&t.jsx(Wt,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(Wt,{tone:"warn",children:"残本"}),l&&t.jsx(Wt,{tone:"info",children:"假想祖本"}),c&&t.jsx(Wt,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Gu,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:Uu,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:Qo,children:[t.jsx("div",{style:er,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return t.jsxs("div",{style:tr(a.confidence),children:[t.jsx("span",{style:nr,children:p(a.relation)}),t.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,p(d.label)):p((d==null?void 0:d.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&t.jsx(Xo,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:ir,children:["· ",p(a.evidence)]})]},a.id)})]}),i.length>0&&t.jsxs("div",{style:Qo,children:[t.jsx("div",{style:er,children:"关联:"}),i.map(a=>{const d=a.source===e.id?a.target:a.source,u=r.get(d);return t.jsxs("div",{style:tr(a.confidence),children:[t.jsx("span",{style:nr,children:p(a.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,p(u.label)):p((u==null?void 0:u.label)??d)}),t.jsx(Xo,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:ir,children:["· ",p(a.evidence)]})]},a.id)})]})]})},Wt=({children:e,tone:n="default"})=>{const r={default:{bg:o("tag-bg"),fg:o("fg")},warn:{bg:o("warn-bg"),fg:o("warn-fg")},info:{bg:o("info-bg"),fg:o("info-fg")}}[n];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},Xo=({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")},Bu={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Au={fontSize:"13px",color:o("muted"),marginBottom:"16px",lineHeight:1.6},Wu={marginBottom:"16px"},Mu={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:o("fg")},Fu={border:`1px solid ${o("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:o("bg")},Pu={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Ou={fontSize:"15px",fontWeight:600},Du={fontSize:"12px",color:o("muted")},Hu={marginBottom:"6px"},Gu={fontSize:"12px",color:o("muted"),margin:"2px 0"},Uu={fontSize:"12px",color:o("muted"),fontStyle:"italic",margin:"4px 0"},Qo={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${o("widget-border")}`},er={fontSize:"11px",color:o("muted"),marginBottom:"2px"},tr=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),nr={display:"inline-block",padding:"0 6px",fontSize:"11px",background:o("tag-bg"),color:o("fg"),borderRadius:"3px",marginRight:"6px"},ir={fontSize:"11px",color:o("muted")},Vu={padding:"20px",textAlign:"center",color:o("muted"),fontSize:"13px"},nl=({selectedNodeId:e,...n})=>{const[i,r]=g.useState("loading"),[s,l]=g.useState(null);return g.useEffect(()=>{let c=!1;return Yu().then(p=>{c||(p?(l(p),r("ready")):r("missing"))}),()=>{c=!0}},[]),i==="loading"?t.jsx("div",{style:or,children:"加载图组件中…"}):i==="missing"||!s?t.jsxs("div",{style:or,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(Ku,{modules:s,selectedNodeId:e,...n})};async function Yu(){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 Ku=({graph:e,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:l,modules:c})=>{const{ReactFlow:p,Background:a,Controls:d,Handle:u,Position:f,BaseEdge:x,EdgeLabelRenderer:m,getSmoothStepPath:b,dagre:w}=c,h=g.useMemo(()=>({lineage:$=>{var U,G,E,ie;const S=((U=$.data)==null?void 0:U.stepPosition)??.85,[z,T,R]=b({sourceX:$.sourceX,sourceY:$.sourceY,sourcePosition:$.sourcePosition,targetX:$.targetX,targetY:$.targetY,targetPosition:$.targetPosition,stepPosition:S,borderRadius:5}),C=!!((G=$.data)!=null&&G.isSibling),P=C?T:$.targetX-18,W=C?R:$.targetY-12,A=(E=$.data)==null?void 0:E.labelStyle,M=(ie=$.data)==null?void 0:ie.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(x,{id:$.id,path:z,style:$.style,markerStart:$.markerStart,markerEnd:$.markerEnd}),$.label&&t.jsx(m,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${P}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")}`,...M,...A},children:$.label})})]})}}),[x,m,b]),j=g.useMemo(()=>({version:$=>{const S=$.data,z=S.kind==="hypothetical",T=S.status==="lost",R=S.isSelected,C=S.bridge,P=S.borderColor??o("muted"),W=C||z?"dashed":"solid",A=C?.5:T?.6:1;return t.jsxs("div",{style:{background:o(C?"bg-subtle":"bg"),border:`2px ${W} ${R?o("primary"):P}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:A,boxShadow:R?o("shadow-node-selected"):z||C?"none":o("shadow-node")},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:f.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&t.jsx("div",{style:{fontSize:10,color:o("muted"),lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&t.jsx("div",{style:{fontSize:10,color:o("muted"),lineHeight:1.2},children:el(S.yearText,void 0,S.uncertain)}),T&&t.jsx("div",{style:{fontSize:9,color:o("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:f.Right,style:{visibility:"hidden"}})]})}}),[u,f]),{convert:y}=V(),{rfNodes:k,rfEdges:_}=g.useMemo(()=>qu(e,w,n,l,y),[e,w,n,l,y]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:t.jsxs(p,{nodes:k,edges:_,nodeTypes:j,edgeTypes:h,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(a,{gap:16}),t.jsx(d,{showInteractive:!1})]})})};function qu(e,n,i,r,s=l=>l??""){const p=e.layout==="LR"||!e.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:p?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(e.groups.map(j=>[j.id,j.color??o("muted")]));for(const j of e.nodes)a.setNode(j.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of e.edges)j.kind==="derive"&&(u.has(j.relation)||a.setEdge(j.source,j.target));n.layout(a);const f=e.nodes.map(j=>{const y=a.node(j.id),k=r?j.id===r:void 0,_={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??Zu(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:i,isSelected:k,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:y.x-160/2,y:y.y-90/2},data:_,draggable:!1,selected:k}}),x=.78,m=.06,b=new Map;for(const j of e.edges)j.kind==="derive"&&(b.has(j.source)||b.set(j.source,[]),b.get(j.source).push(j));const w=new Map;for(const[j,y]of b){if(y.length<=1)continue;const k=[...y].sort((v,$)=>{var T,R;const S=((T=a.node(v.target))==null?void 0:T.y)??0,z=((R=a.node($.target))==null?void 0:R.y)??0;return S-z}),_=k.length;k.forEach((v,$)=>{const S=($-(_-1)/2)*m;w.set(v.id,x+S)})}const h=e.edges.map(j=>Ju(j,w.get(j.id),s));return{rfNodes:f,rfEdges:h}}function Ju(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Xu(e.confidence),c={type:"arrowclosed",color:l,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:i(e.relation),data:{labelStyle:{color:o("fg")},isSibling:s,stepPosition:n},style:{stroke:l,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:c,markerStart:s?c:void 0,zIndex:1e3}}function Zu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Xu(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 or={padding:"40px 20px",textAlign:"center",color:o("muted"),fontSize:"13px",border:`1px dashed ${o("widget-border")}`,borderRadius:8,background:o("bg")},il=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:c,onCollectionChange:p,collectionsAvailable:a,collectionCounts:d,className:u,style:f})=>{var y;const[x,m]=g.useState(n),b=k=>{m(k),l==null||l(k)},w=(()=>{if(!a)return[];const k=Object.entries(a);return k.length===0||a.all?k:[...k,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),h=!!(p&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:o("muted"),textAlign:"center"},children:"暂无版本传承数据"});const j=c?(y=a==null?void 0:a[c])==null?void 0:y.description:void 0;return t.jsxs("div",{className:u,style:f,children:[t.jsxs("div",{style:Qu,children:[t.jsx("button",{onClick:()=>b("list"),style:In(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:In(x==="graph"),children:"关系图"}),h&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:o("muted"),marginRight:4},children:"集合:"}),w.map(([k,_])=>{const v=d==null?void 0:d[k];return t.jsxs("button",{onClick:()=>p==null?void 0:p(k),style:In(c===k),title:_.description,children:[_.label,v!=null?` ${v}`:""]},k)})]})]}),h&&j&&t.jsx("div",{style:{fontSize:12,color:o("muted"),marginBottom:8,padding:"4px 8px",background:o("bg-subtle"),borderRadius:4},children:j}),x==="list"?t.jsx(tl,{graph:e,renderLink:i}):t.jsx(nl,{graph:e,renderLink:i,height:r,selectedNodeId:s})]})},Qu={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},In=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${o("widget-border")}`,borderRadius:4,background:e?o("primary"):"transparent",color:o(e?"primary-fg":"fg"),cursor:"pointer"}),Kn=({style:e})=>{const n=g.useContext($t);if(!n)return null;const{locale:i,setLocale:r}=n,s=i==="zh-Hant",l=()=>r(s?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:`1px solid ${o("border")}`,borderRadius:"4px",background:o("bg"),color:o("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:s?o("primary"):void 0,fontWeight:s?700:400},children:"繁"}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:s?void 0:o("primary"),fontWeight:s?400:700},children:"简"})]})},qn=({href:e,label:n="在 GitHub 查看本条目源文件",size:i=16,className:r,style:s})=>t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:o("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:l=>{l.currentTarget.style.color=o("fg")},onMouseLeave:l=>{l.currentTarget.style.color=o("desc-fg")},children:t.jsx("svg",{width:i,height:i,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:t.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})});function Tn(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function ex(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const tx=({id:e,transport:n,initialDetail:i,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:c,onJuanChange:p,lineageMode:a="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:f,initialPage:x=1,selectedLineageNodeId:m,onNavigate:b,onBack:w,backLabel:h,renderLink:j,enrichDetail:y,getSourceLink:k,readLink:_,railTop:v,extraTabs:$=[],showFeedbackTab:S=!0,feedbackApiUrl:z,height:T,footerExtra:R,className:C,style:P})=>{var Wi;const W=ae(),{convert:A}=V(),[M]=g.useState(()=>{if(!ex(e,i))return null;const H={...i},ge=r??Tn(e,H);return y&&y(ge,H),{id:e,entry:ge,detail:H}}),[U,G]=g.useState((M==null?void 0:M.entry)??null),[E,ie]=g.useState((M==null?void 0:M.detail)??null),[F,re]=g.useState(!M),[ce,Z]=g.useState(!1),[O,q]=g.useState([]),[de,se]=g.useState(!1),[ee,D]=g.useState(null),[Y,Q]=g.useState(!1),[L,I]=g.useState(null),[K,X]=g.useState(!1),[ue,xe]=g.useState(null),[ve,_e]=g.useState([]),[te,N]=g.useState(!1),[ne,oe]=g.useState(null),[be,fe]=g.useState(null),[$e,we]=g.useState(!1),Le=g.useRef(null),[We,ze]=g.useState(null),De=c!==void 0?c:We,Ve=g.useCallback(H=>{p?p(H):ze(H)},[p]),Tt=g.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){q([]);return}se(!0);try{if(n.getCollectionCatalogs)q(await n.getCollectionCatalogs(H)||[]);else if(n.getCollectionCatalog){const ge=await n.getCollectionCatalog(H);q(ge?[{resource_id:"",data:ge}]:[])}}catch{q([])}finally{se(!1)}},[n]),B=g.useCallback(async H=>{if(!n.getCollatedEditionIndex){D(null);return}Q(!0);try{D(await n.getCollatedEditionIndex(H))}catch{D(null)}finally{Q(!1)}},[n]),le=g.useCallback(async H=>{if(!n.getBookFullTextIndex){I(null);return}X(!0);try{I(await n.getBookFullTextIndex(H))}catch{I(null)}finally{X(!1),xe(H)}},[n]),pe=g.useCallback(async H=>{var ge;if(!n.getWorkFullTextList){_e([]);return}N(!0);try{const ke=(await n.getWorkFullTextList(H)??[]).filter(Ce=>Ce.owner_type!=="Book");_e(ke),oe(((ge=ke.find(Ce=>Ce.primary)??ke[0])==null?void 0:ge.key)??null)}catch{_e([])}finally{N(!1)}},[n]),ye=g.useCallback(async(H,ge)=>{we(!0);try{if(n.getLineageGraph){const Ae=await n.getLineageGraph(H);Ae&&fe(Ae)}const ke=ge.version_graph;if(!ke||!ke.enabled){be||fe(null),Le.current=null;return}const Ce=ge.books??[],Ye=[];for(const Ae of Ce)try{const Ke=await n.getItem(Ae);Ke&&Ye.push(Ke)}catch{}Le.current={work:ge,books:Ye};const J=u??ke.default_collection??(ke.core_books&&ke.core_books.length>0?"core":"all"),Se=J==="core"&&Array.isArray(ke.core_books)&&ke.core_books.length>0?"core":J??"all";fe(rn(ge,Ye,Se))}catch{fe(null),Le.current=null}finally{we(!1)}},[n]),je=g.useRef({initialDetail:i,initialEntry:r});je.current={initialDetail:i,initialEntry:r},g.useEffect(()=>{let H=!1;const ge=J=>{J.type==="collection"?Tt(e):J.type==="work"?(J.has_collated&&B(e),(J.version_graph||n.getLineageGraph)&&ye(e,J),n.getWorkFullTextList&&pe(e)):J.type==="book"&&J.has_full_text&&n.getBookFullTextIndex&&le(e)},ke=je.current;let Ce=null;if(M&&M.id===e)Ce=M;else if(ke.initialDetail&&ke.initialDetail.id===e){const J={...ke.initialDetail},Se=ke.initialEntry??Tn(e,J);y&&y(Se,J),Ce={entry:Se,detail:J}}return Ce?(Z(!1),q(J=>J.length?[]:J),D(null),I(null),_e(J=>J.length?[]:J),oe(null),fe(null),Le.current=null,G(Ce.entry),ie(Ce.detail),re(!1),ge(Ce.detail),()=>{H=!0}):((async()=>{re(!0),Z(!1),G(null),ie(null),q([]),D(null),I(null),_e([]),oe(null),fe(null),Le.current=null;try{const J=await n.getItem(e);if(H)return;if(!J){Z(!0);return}const Se=J;let Ae=null;if(n.getEntry&&(Ae=await n.getEntry(e),H))return;Ae||(Ae=Tn(e,Se)),y&&y(Ae,Se),G(Ae),ie(Se),ge(Se)}catch{H||Z(!0)}finally{H||re(!1)}})(),()=>{H=!0})},[e,n,M,y,Tt,B,ye,le,pe]),g.useEffect(()=>{const H=Le.current;!H||!u||fe(rn(H.work,H.books,u))},[u]);const me=[];if(E){if(me.push({key:"basic",label:W.detailTab.basicInfo}),E.type==="collection"){de&&O.length===0&&me.push({key:"catalog:loading",label:`${W.detailTab.catalog}…`});for(const H of O)me.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${A(H.short_name)}${W.detailTab.catalogSuffix}`:W.detailTab.collectionCatalog})}E.type==="work"&&(ee||Y)&&s==="collated"&&me.push({key:"collated",label:Y?`${W.detailTab.collatedEdition}…`:W.detailTab.collatedEdition}),E.type==="book"&&(L||K)&&s==="fulltext"&&me.push({key:"fulltext",label:K?`${W.detailTab.fullText}…`:W.detailTab.fullText}),E.type==="work"&&(ve.length>0||te)&&s==="fulltext"&&me.push({key:"fulltext",label:te?`${W.detailTab.fullText}…`:W.detailTab.fullText}),E.type==="work"&&(be||$e)&&me.push({key:"lineage",label:$e?`${W.detailTab.lineage}…`:W.detailTab.lineage});for(const H of $)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(E)&&me.push({key:H.key,label:H.label});S&&s==="feedback"&&me.push({key:"feedback",label:W.detailTab.feedback});for(const H of $)H.position==="after-feedback"&&H.shouldShow(E)&&me.push({key:H.key,label:H.label})}g.useEffect(()=>{if(s!=="emendated"||!E)return;l("basic");const H=setTimeout(()=>{var ge;(ge=document.getElementById("studies"))==null||ge.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[s,E,l]);const Be=U&&E&&k?k({activeTab:s,activeJuan:De,entry:U,detail:E}):null,Qe=g.useMemo(()=>{var Ye;if(!E)return null;const ge=(E.authors??[]).map(J=>{const Se=li(J.role);return`${J.dynasty?`〔${A(J.dynasty)}〕`:""}${A(J.name)}${Se?` ${A(Se)}`:""}`}).join(" · ");let ke=!1;try{ke=he.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const J=E;return{title:A(J.title),subtitle:J.edition?A(J.edition):ge||void 0,aside:[ke?W.status.draft:"",ge&&J.edition?ge:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const J=E;return{title:A(J.title),subtitle:A(ot(J,W.unit.juan))||void 0,aside:[(Ye=J.publication_info)==null?void 0:Ye.year,ke?W.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:ge||void 0}}if(E.type==="entity"){const J=E,Se=Ke=>Ke==null?"":Ke<0?`前${-Ke}`:String(Ke),Ae=J.birth_year!=null||J.death_year!=null?`${Se(J.birth_year)||"?"}—${Se(J.death_year)||"?"}`:"";return{title:A(J.primary_name||J.title),subtitle:[J.dynasty?`〔${A(J.dynasty)}〕`:"",Ae].filter(Boolean).join(" ")||void 0,aside:ke?W.status.draft:void 0,secondLine:void 0}}const Ce=A(ot(E,W.unit.juan));return{title:A(E.title),subtitle:[Ce,ge].filter(Boolean).join(" · ")||void 0,aside:[ix(W,E.subtype),ke?W.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,A,W]),at=E?E.type==="work"?(((Wi=ee==null?void 0:ee.juan_files)==null?void 0:Wi.length)??0)>0?"collated":ve.length>0?"fulltext":null:E.type==="book"&&(((L==null?void 0:L.chapters.length)??0)>0||E.has_full_text&&n.getBookFullTextIndex&&ue!==E.id)?"fulltext":null:null,rt=ve.find(H=>H.primary)??ve[0],Me=()=>{var H;at==="collated"&&((H=ee==null?void 0:ee.juan_files)!=null&&H.length)?(Ve(ee.juan_files[0]),l("collated")):at==="fulltext"&&((E==null?void 0:E.type)==="work"&&rt&&oe(rt.key),Ve(null),l("fulltext"))};let Rt=null;if(E&&_){const H=_({detail:E,kind:at,fullTextKey:E.type==="work"?rt==null?void 0:rt.key:void 0});H&&(Rt=t.jsx(Wn,{href:H}))}else at&&(Rt=t.jsx(Wn,{onClick:Me}));const ol=H=>{if(!E)return null;const ge=H.replace(/\.[^.]+$/,"");if(_){const ke=_({detail:E,kind:"fulltext",juan:ge});return ke?{href:ke}:null}return{onClick:()=>{Ve(ge),l("fulltext")}}},rl=new Set($.map(H=>H.key)),Jt=me.filter(H=>H.key.startsWith("catalog:")&&H.key!=="catalog:loading"||rl.has(H.key)).map(H=>({key:H.key,label:H.label,onClick:()=>l(H.key)})),Li=()=>{var H;return E?E.type==="work"?t.jsx(Hs,{data:E,transport:n,onNavigate:b,renderLink:j,readAction:Rt,railTop:v,railLinks:Jt}):E.type==="book"?t.jsx(Gs,{data:E,transport:n,onNavigate:b,renderLink:j,readAction:Rt,fullText:L,fullTextPending:!!E.has_full_text&&!!n.getBookFullTextIndex&&ue!==E.id,chapterLink:ol,railTop:v,railLinks:Jt}):E.type==="collection"?t.jsx(Us,{data:E,catalog:(H=O[0])==null?void 0:H.data,transport:n,onNavigate:b,renderLink:j,readAction:Rt,railTop:v,railLinks:Jt,catalogAction:O.length>0?t.jsxs("a",{href:"#catalog",onClick:ge=>{ge.preventDefault(),l(`catalog:${O[0].resource_id}`)},children:[A(W.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Vs,{data:E,transport:n,onNavigate:b,renderLink:j,railTop:v,railLinks:Jt}):null},sl=()=>{var ge,ke,Ce,Ye;if(!U||!E)return null;if(s==="basic"||s==="emendated")return Li();if(typeof s=="string"&&s.startsWith("catalog:")){const J=(ge=O.find(Se=>`catalog:${Se.resource_id}`===s))==null?void 0:ge.data;return t.jsx(ni,{data:J,onNavigate:b,renderLink:j})}if(s==="collated")return t.jsx(zi,{index:ee||void 0,workId:e,transport:n,onNavigate:b,activeJuan:De,onJuanChange:Ve});if(s==="fulltext"&&E.type==="work"){const J=ne??((ke=ve[0])==null?void 0:ke.key);return J?t.jsx(Gn,{bookId:e,workKey:J,versions:ve,onVersionChange:Se=>{oe(Se),Ve(null)},transport:n,activeChapter:De,onChapterChange:Ve},J):t.jsx("div",{style:{padding:24,color:o("desc-fg")},children:te?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(Gn,{index:L||void 0,bookId:e,transport:n,activeChapter:De,onChapterChange:Ve});if(s==="lineage"){if(!be)return t.jsx("div",{style:{color:o("label-fg"),padding:"24px 0"},children:$e?"加載中…":"暫無版本圖數據"});const J=E.type==="work"?E:null;return t.jsx(il,{graph:be,renderLink:j,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:a,onModeChange:d,selectedNodeId:m,collection:u??((Ce=J==null?void 0:J.version_graph)==null?void 0:Ce.default_collection),onCollectionChange:f,collectionsAvailable:(Ye=J==null?void 0:J.version_graph)==null?void 0:Ye.collections,collectionCounts:(()=>{var Mi,Fi,Pi,Oi,Di,Hi,Gi;if(!J)return;const Se={},Ae=((Mi=Le.current)==null?void 0:Mi.books)??[];Se.all=(((Fi=J.books)==null?void 0:Fi.length)??0)-(((Oi=(Pi=J.version_graph)==null?void 0:Pi.excluded_books)==null?void 0:Oi.length)??0);const Ke=(Di=J.version_graph)==null?void 0:Di.collections;if(Ke)for(const Ui of Object.keys(Ke))Se[Ui]=rn(J,Ae,Ui).nodes.filter(Vi=>Vi.kind==="book"&&!Vi.bridge).length;return Se.core==null&&((Gi=(Hi=J.version_graph)==null?void 0:Hi.core_books)!=null&&Gi.length)&&(Se.core=J.version_graph.core_books.length),Se})()})}if(s==="feedback"&&S)return t.jsx(Fs,{resourceId:e,apiUrl:z});const H=$.find(J=>J.key===s);return H?H.render({detail:E,entry:U,transport:n,onNavigate:b}):null};if(F)return t.jsx(Mt,{style:{minHeight:T,...P},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((H,ge)=>t.jsx("div",{style:{height:ge===1?40:16,width:H,opacity:.35,background:o("rule")}},ge))})});if(ce||!E||!U||!Qe)return t.jsx(Mt,{style:{minHeight:T,...P},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:o("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const bn=s==="basic"||s==="emendated",Zt=[{label:h??W.detailTab.backToIndex,onClick:w}];if(E.type==="book"&&E.work_id){const H=E.work_id;Zt.push({label:W.indexType.work,id:H,onClick:()=>b==null?void 0:b(H)})}Zt.push({label:W.indexType[E.type]});const Xt=s==="collated"||s==="fulltext",Bi=typeof R=="string"?W.status[R.trim()]??R:R,Ai=t.jsx(Xr,{left:t.jsxs(t.Fragment,{children:[Bi,Bi?" · ":"",t.jsx(nx,{id:E.id,label:W.label.id,copied:W.action.copied,copyLabel:W.action.copy})]}),right:t.jsxs(t.Fragment,{children:[S&&!bn&&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}),Be&&t.jsx("a",{href:Be.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:o("meta-fg")},children:W.detailTab.dataLicense})]})});return bn?t.jsx("div",{className:C,children:t.jsxs(Mt,{grid:!0,style:{minHeight:T,...P},children:[t.jsx(Mn,{breadcrumb:t.jsx(Fn,{items:Zt}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Kn,{style:{border:"none",background:"transparent"}}),Be&&t.jsx(qn,{...Be})]})}),Li(),Ai]})}):t.jsx("div",{className:C,children:t.jsxs(Mt,{wide:Xt,style:{minHeight:T,...P},children:[t.jsx(Mn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(di,{char:"籍"}),t.jsx(Fn,{items:Zt})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Kn,{}),S&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:W.detailTab.feedback}),Be&&t.jsx(qn,{...Be})]})}),t.jsx(Hr,{...Qe,aside:Xt?t.jsxs("button",{type:"button",onClick:()=>l("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("accent"),borderBottom:`1px solid ${o("rule")}`},children:[A("作品信息")," →"]}):Qe.aside}),!Xt&&me.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:me.map(H=>t.jsx(Gr,{label:H.label,active:H.key===s||bn&&H.key==="basic",onClick:()=>l(H.key)},H.key))}),t.jsx("div",{style:{marginTop:!Xt&&me.length>1?8:0},children:sl()}),Ai]})})};function nx({id:e,label:n,copied:i,copyLabel:r}){const[s,l]=g.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var c;(c=navigator.clipboard)==null||c.writeText(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?i:r,"aria-label":s?i:r,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:o("aux-fg")},children:s?"✓":"⧉"})]})}function ix(e,n){return n?e.workSubtype[n]??n:""}exports.BidLink=he.BidLink;exports.BookIndexError=he.BookIndexError;exports.BookIndexManager=he.BookIndexManager;exports.BookIndexStorage=he.BookIndexStorage;exports.BundleStorage=he.BundleStorage;exports.ConfigError=he.ConfigError;exports.GithubStorage=he.GithubStorage;exports.IdGenerationError=he.IdGenerationError;exports.IdGenerator=he.IdGenerator;exports.LocalStorage=he.LocalStorage;exports.MigrationError=he.MigrationError;exports.StorageError=he.StorageError;exports.base36Decode=he.base36Decode;exports.base36Encode=he.base36Encode;exports.base58Decode=he.base58Decode;exports.buildId=he.buildId;exports.buildPromotionMap=he.buildPromotionMap;exports.cleanName=he.cleanName;exports.decodeId=he.decodeId;exports.decodeIdString=he.decodeIdString;exports.encodeId=he.encodeId;exports.extractIdFromUrl=he.extractIdFromUrl;exports.extractStatus=he.extractStatus;exports.extractType=he.extractType;exports.normalizeCatalog=he.normalizeCatalog;exports.parseId=he.parseId;exports.shardOf=he.shardOf;exports.smartDecode=he.smartDecode;exports.validateResource=he.validateResource;exports.Badge=cn;exports.BidUrlProvider=hl;exports.BookDetailLayout=tx;exports.BookFullText=Gn;exports.BookPage=Gs;exports.Breadcrumb=Fn;exports.CATALOG_ALL_ID=tt;exports.CATALOG_CSS=Ys;exports.CATALOG_NARROW_QUERY=Ri;exports.CATALOG_PAGE_SIZE=Ei;exports.CATALOG_UNCLASSIFIED_ID=Dt;exports.CardFoot=Yt;exports.CatalogPage=zu;exports.CatalogPager=Xs;exports.CatalogTree=qs;exports.CheckFilter=Or;exports.Chip=Ur;exports.ChipWall=dc;exports.CollatedEdition=zi;exports.CollectionCatalog=ni;exports.CollectionPage=Us;exports.CreateEntityDialog=Rs;exports.DEFAULT_READER_PREFS=xi;exports.DETAIL_CSS=Dr;exports.Dash=mc;exports.DataTable=uc;exports.DetailFooter=Xr;exports.DetailGrid=Ut;exports.DetailHeader=Hr;exports.EmendatedBySection=Sr;exports.EmptyNote=Sc;exports.EntityDetail=hr;exports.EntityPage=Vs;exports.EntityPickerDialog=Ns;exports.EntitySelector=Ts;exports.ExpandRow=hc;exports.ExtLink=wc;exports.FEEDBACK_FAB_OFFSET_VAR=Vn;exports.FONT_SIZE_STEPS=jt;exports.FactList=sc;exports.FeedbackButton=Vp;exports.FeedbackDialog=Ws;exports.FeedbackForm=Ms;exports.FeedbackList=Ci;exports.FeedbackTab=Fs;exports.FilterChip=Gr;exports.FormInput=Pe;exports.FormTextArea=xt;exports.GUJI_MARKDOWN_FIELD=Va;exports.GUJI_TABLE_NOTATION=cs;exports.GlyphBadge=di;exports.GujiTable=hi;exports.HomePage=Hn;exports.ImagePanel=os;exports.IndexApp=Zd;exports.IndexBrowser=Nn;exports.IndexDetail=ti;exports.IndexEditor=Ls;exports.IndexView=Np;exports.IntroGrid=rc;exports.LocaleContext=$t;exports.LocaleProvider=Rl;exports.LocaleToggle=Kn;exports.MetaLine=Re;exports.ModeIndicator=fr;exports.MoreButton=cc;exports.MoreLink=It;exports.PAGE_MAX_WIDTH=nn;exports.PageFrame=Mt;exports.Quote=yc;exports.READER_CSS=ts;exports.RECENT_IDS_STORAGE_KEY=kt;exports.ROLE_CLASS_ORDER=Tr;exports.ReadButton=Wn;exports.ReaderMdText=vi;exports.ReaderShell=gi;exports.ReaderToc=is;exports.RelationPanel=Cs;exports.RepoSourceLink=qn;exports.ResourceEditor=En;exports.ResourceGroup=jc;exports.ResourceLine=vc;exports.ResourceList=ei;exports.ResourceRow=Jr;exports.SNIPPET_MARK_END=lr;exports.SNIPPET_MARK_START=sr;exports.SearchInput=gr;exports.Sec=Ee;exports.Section=Ge;exports.SectionHead=lc;exports.SideList=ut;exports.SmartBidInput=on;exports.SourceEditor=_s;exports.SummaryCard=Vt;exports.TabFilter=ai;exports.TableHead=xc;exports.TableRow=fc;exports.TagRow=Zr;exports.TagRows=kc;exports.TextButton=ac;exports.TopStrip=Mn;exports.VersionLineageGraph=nl;exports.VersionLineageList=tl;exports.VersionLineageView=il;exports.VolumeChips=pc;exports.VolumeLinks=pi;exports.WorkCard=Zs;exports.WorkCardGrid=Qs;exports.WorkCatalog=Xd;exports.WorkPage=Hs;exports.bucketResources=ri;exports.buildCatalogTree=hu;exports.buildCollectionTable=Er;exports.buildLineageGraph=rn;exports.buildPageUrl=Qn;exports.buildParagraphBlocks=hs;exports.buildVersionRow=Cr;exports.buildVersionTable=Ir;exports.canParagraphize=hn;exports.catalogNodeIdOf=gu;exports.catalogNodeIdsOf=mu;exports.catalogPageCount=vu;exports.catalogTotal=Ni;exports.classificationPath=qt;exports.compareCatalogCards=ju;exports.computeVersionPartition=Da;exports.defaultWorkLink=Js;exports.deriveDating=Fa;exports.deriveEditionType=Lr;exports.deriveEra=Gt;exports.deriveYear=xn;exports.deriveYearRange=oi;exports.detailToEditor=As;exports.detectGenre=mn;exports.displayAuthorRole=li;exports.editorToDetail=Ep;exports.eraRank=Bn;exports.findCatalogPath=vt;exports.flattenTitles=Pn;exports.flattenToc=as;exports.formatTemplate=Ht;exports.formatVolumeRange=gn;exports.getDisplayNameFromUrl=zt;exports.getStartPage=Xn;exports.getTypeGroupKey=Jn;exports.groupRelatedWorks=Pa;exports.gujiInlineToPlain=Mr;exports.hasGujiMarkdownV02=An;exports.hasGujiTableNotation=ds;exports.measureText=ot;exports.mergeVolumeResources=Zn;exports.normalizeEra=Te;exports.normalizeRole=si;exports.normalizeVolumeIndex=Pt;exports.normalizeVolumes=xr;exports.numberToChinese=Nr;exports.paginationItems=Ks;exports.parseChineseNumber=sn;exports.parseGujiInline=Wr;exports.parseGujiTable=us;exports.parseSourceString=$s;exports.pickReaderVersion=ls;exports.readerVersionOptionLabel=Dn;exports.readerVersionsFromFullText=ss;exports.renderFullTextBody=Yc;exports.renderProperNames=ys;exports.renderReaderInline=ji;exports.resourceHref=Ct;exports.resourceNote=fn;exports.roleFacets=Rr;exports.rowNo=gc;exports.sortYear=ln;exports.splitFullTextTables=mi;exports.splitHighlightSnippet=ar;exports.splitTableRow=ps;exports.stringifySources=zs;exports.toCatalogWorkCard=yu;exports.useBidUrl=Ne;exports.useConvert=V;exports.useReaderPrefs=fi;exports.useT=ae;exports.validateLineageGraph=Eu;exports.volumeStats=dn;
|
|
805
|
+
`,Gt="未分類",it="all",Wi=20;function Zt(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 gu(e){const n=Zt(e);return n.length?n.join("/"):Gt}function mu(e){const n=Zt(e);return n.length?n.map((i,r)=>n.slice(0,r+1).join("/")):[Gt]}function hu(e,n=[]){const i=new Map;n.forEach((p,a)=>{const d=[p.cata_l1,p.cata_l2,p.cata_l3,p.cata_l4].filter(u=>!!u);d.forEach((u,f)=>{const x=d.slice(0,f+1).join("/");i.has(x)||i.set(x,a)})});const r=new Map;let s=0;for(const p of e){const a=Zt(p.classification);if(!a.length){s++;continue}let d=r;a.forEach((u,f)=>{const x=a.slice(0,f+1).join("/");let m=d.get(u);m||(m={id:x,label:u,count:0,children:new Map},d.set(u,m)),m.count++,d=m.children})}const l=p=>[...p.values()].sort((a,d)=>{const u=i.get(a.id)??1/0,f=i.get(d.id)??1/0;return u!==f?u-f:a.label.localeCompare(d.label,"zh")}).map(a=>{const d={id:a.id,label:a.label,count:a.count};return a.children.size&&(d.children=l(a.children)),d}),c=l(r);return s>0&&c.push({id:Gt,label:Gt,count:s}),c}function wt(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const r=wt(i.children,n);if(r.length)return[i,...r]}}return[]}function Mi(e){return e.reduce((n,i)=>n+i.count,0)}function bu(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function yu(e){var p;const n={id:e.id,title:e.title||e.id},i=e.juan_count,r=typeof i=="number"?i:i==null?void 0:i.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(a=>a==null?void 0:a.name).map(a=>{const d=a.dynasty||(e.authors.length===1?e.dynasty:void 0);return d?{name:a.name,dynasty:d}:{name:a.name}});s.length&&(n.authors=s);const l=bu(typeof e.description=="string"?e.description:(p=e.description)==null?void 0:p.text);l&&(n.summary=l);const c=Zt(e.classification);return c.length&&(n.classification=c),n}function ju(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 vu(e,n=Wi){return Math.max(1,Math.ceil(e/n))}function Zs(e,n,i=2){if(n<=1)return[1];const r=new Set([1,n]);for(let c=e-i;c<=e+i;c++)c>=1&&c<=n&&r.add(c);const s=[...r].sort((c,p)=>c-p),l=[];return s.forEach((c,p)=>{if(p>0){const a=c-s[p-1];a===2?l.push(c-1):a>2&&l.push(null)}l.push(c)}),l}const ku=()=>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 Su(e,n,i){const r=[];i&&r.push({id:it,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,c)=>{var p;for(const a of l){const d=(p=a.children)!=null&&p.length?a.children:null;r.push({id:a.id,parentId:c,hasChildren:!!d,firstChildId:d?d[0].id:null}),d&&n.has(a.id)&&s(d,a.id)}};return s(e,null),r}function Xs({tree:e,selectedId:n,onSelect:i,allLabel:r="全部",label:s="分類"}){const{convert:l}=V(),c=g.useRef(null),p=n&&n!==it?n:null,a=r!==null,[d,u]=g.useState(()=>{const v=new Set;for(const $ of wt(e,p))v.add($.id);return v});g.useEffect(()=>{const v=wt(e,p);v.length&&u($=>{if(v.every(z=>$.has(z.id)))return $;const S=new Set($);for(const z of v)S.add(z.id);return S})},[e,p]);const f=g.useMemo(()=>Su(e,d,a),[e,d,a]),[x,m]=g.useState(null);g.useEffect(()=>{m(null)},[n]);const b=p??(a?it:null),w=g.useMemo(()=>{var S;const v=new Set(f.map(z=>z.id));if(x&&v.has(x))return x;if(b&&v.has(b))return b;const $=wt(e,p).map(z=>z.id).filter(z=>v.has(z));return $.length?$[$.length-1]:((S=f[0])==null?void 0:S.id)??null},[f,x,b,e,p]),h=g.useCallback((v,$)=>{u(S=>{const z=S.has(v),I=$??!z;if(I===z)return S;const R=new Set(S);return I?R.add(v):R.delete(v),R})},[]),j=g.useCallback(v=>{m(v),requestAnimationFrame(()=>{var S;const $=Array.from(((S=c.current)==null?void 0:S.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===v);$==null||$.focus()})},[]),y=g.useCallback((v,$)=>{$&&h(v,!0),i(v)},[i,h]),k=g.useCallback(v=>{const $=v.target.closest("[data-ct-id]");if(!$)return;const S=$.dataset.ctId,z=f.findIndex(C=>C.id===S);if(z<0)return;const I=f[z];let R=null;switch(v.key){case"ArrowDown":R=f[Math.min(f.length-1,z+1)].id;break;case"ArrowUp":R=f[Math.max(0,z-1)].id;break;case"Home":R=f[0].id;break;case"End":R=f[f.length-1].id;break;case"ArrowRight":if(!I.hasChildren)break;d.has(S)?R=I.firstChildId:h(S,!0);break;case"ArrowLeft":I.hasChildren&&d.has(S)?h(S,!1):R=I.parentId;break;case"Enter":case" ":v.preventDefault(),y(S,I.hasChildren);return;default:return}v.preventDefault(),R&&R!==S&&j(R)},[f,d,h,j,y]),_=(v,$)=>v.map((S,z)=>{var W;const I=(W=S.children)!=null&&W.length?S.children:null,R=!!I&&d.has(S.id),C=S.id===p,F=$===1&&v.length>1&&z===v.length-1;return t.jsxs("li",{role:"treeitem","aria-level":$,"aria-expanded":I?R:void 0,"aria-selected":C,tabIndex:w===S.id?0:-1,"data-ct-id":S.id,className:F?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":$-1},onClick:()=>{m(S.id),y(S.id,!!I)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:I?B=>{B.stopPropagation(),m(S.id),h(S.id)}:void 0,children:I?t.jsx(ku,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(S.label)}),t.jsx("span",{className:"bim-ct-n",children:S.count.toLocaleString("en-US")})]}),R&&t.jsx("ul",{role:"group",children:_(I,$+1)})]},S.id)});return t.jsxs("ul",{ref:c,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:k,children:[a&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:w===it?0:-1,"data-ct-id":it,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{m(it),i(it)},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:Mi(e).toLocaleString("en-US")})]})}),_(e,1)]})}const Qs=e=>`/item/${encodeURIComponent(e)}`;function wu(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function _u(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function el({work:e,href:n}){var c,p;const{convert:i}=V(),r=_u(e.juan),s=((c=e.authors)==null?void 0:c.filter(a=>a.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:n,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:i(e.title)}),r&&t.jsx("span",{className:"bim-ct-juan",children:i(r)})]}),s.length>0&&t.jsx("span",{className:"bim-ct-by",children:s.map((a,d)=>t.jsxs(g.Fragment,{children:[d>0&&"、",a.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",i(a.dynasty),"〕"]}),i(a.name)]},d))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:i(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(a=>i(a)).join(" · ")})]})})}function tl({page:e,pageCount:n,onPage:i,pageHref:r,label:s="分頁"}){const{convert:l}=V();if(n<=1)return null;const c=a=>d=>{i&&(r&&!wu(d)||(d.preventDefault(),i(a)))},p=(a,d,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const f={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...f,href:r(a),onClick:c(a),children:d}):t.jsx("button",{type:"button",...f,onClick:u.current?void 0:c(a),children:d})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:Zs(e,n).map((a,d)=>t.jsx("li",{style:{display:"contents"},children:a===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(a,a,{current:a===e,aria:l(`第 ${a} 頁`)})},a??`gap${d}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),p(e+1,l("下一頁"),{disabled:e>=n})]})}function nl({works:e,workLink:n=Qs,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(el,{work:l,href:n(l.id)},l.id))}),t.jsx(tl,{...r})]})}const $u=()=>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 zu({tree:e,selectedId:n,page:i,pageCount:r,works:s,onSelect:l,onPage:c,searchSlot:p,workLink:a,pageHref:d,allLabel:u="全部",allTitle:f="全部典籍",pageSize:x=Wi,className:m}){const{convert:b}=V(),h=`bim-ct-drawer-${g.useId().replace(/:/g,"")}`,[j,y]=g.useState(!1),k=wt(e,n&&n!==it?n:null),_=k.length?k[k.length-1]:null,v=_?_.label:f,$=_?_.count:Mi(e),S=g.useCallback(z=>{y(!1),l(z)},[l]);return t.jsxs("div",{className:m?`bim-ct ${m}`:"bim-ct","data-drawer":j?"open":"closed",children:[t.jsx("style",{children:Js}),t.jsxs("aside",{className:"bim-ct-side","aria-label":b("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":j,"aria-controls":h,onClick:()=>y(z=>!z),children:[t.jsxs("span",{children:[b("分類"),":",b(k.length?k.map(z=>z.label).join(" › "):u??f)]}),t.jsx($u,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:h,children:[t.jsx("h2",{className:"bim-ct-side-h",children:b("分類")}),t.jsx(Xs,{tree:e,selectedId:n,onSelect:S,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(v)}),k.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:b(k.slice(0,-1).map(z=>z.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[b(`共 ${$.toLocaleString("en-US")} 種 · 每頁 ${x} 條`),r>1&&b(` · 第 ${i} / ${r} 頁`)]})]}),p&&t.jsx("div",{className:"bim-ct-search",children:p}),t.jsx(nl,{works:s,workLink:a,page:i,pageCount:r,onPage:c,pageHref:d})]})]})}function Cu(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 Iu(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 Qo(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 Tu(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 Ru(e,n){var d;if(n==="all")return null;const i=(d=e.collections)==null?void 0:d[n],r=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,l=r||s||!!(i!=null&&i.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!i||!l)return null;const c=r?new Set(i.groups):null,p=new Set(i.book_ids??[]);if(c&&e.node_groups)for(const[u,f]of Object.entries(e.node_groups))c.has(f)&&p.add(u);let a=null;if(i.hypothetical_ids&&(a=new Set(i.hypothetical_ids)),c){a||(a=new Set);for(const u of e.hypothetical_nodes??[])u.group&&c.has(u.group)&&a.add(u.id)}return{books:p,hypos:a}}function dn(e,n,i){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const l=new Set(r.excluded_books??[]),c=r.node_groups??{},p=Ru(r,i??r.default_collection??"all"),a=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,f=new Set,x=new Set;if(a){const _=new Map(n.map(R=>[R.id,R])),v=new Map((r.hypothetical_nodes??[]).map(R=>[R.id,R])),$=R=>{const C=_.get(R);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(W=>W.ref);const F=v.get(R);return F?(F.derived_from??[]).map(W=>W.ref):[]},S=R=>v.has(R)?!u||u.has(R):!d||d.has(R),z=new Set,I=R=>{if(!z.has(R)){z.add(R);for(const C of $(R))l.has(C)||(S(C)||(v.has(C)?x.add(C):_.has(C)&&f.add(C)),I(C))}};for(const R of n)d&&d.has(R.id)&&!l.has(R.id)&&I(R.id);for(const R of r.hypothetical_nodes??[])u&&u.has(R.id)&&I(R.id)}const m=n.filter(_=>!l.has(_.id)).filter(_=>!d||d.has(_.id)||f.has(_.id)).map(_=>{const v=Iu(_,c);return v&&f.has(_.id)&&(v.bridge=!0),v}).filter(_=>_!==null),b=(r.hypothetical_nodes??[]).filter(_=>!u||u.has(_.id)||x.has(_.id)).map(_=>{const v=Cu(_);return x.has(_.id)&&(v.bridge=!0),v}),w=[...m,...b],h=new Set(w.map(_=>_.id)),j=new Set,y=[],k=_=>{j.has(_.id)||!h.has(_.source)||!h.has(_.target)||(j.add(_.id),y.push(_))};for(const _ of n)l.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!f.has(_.id)||((_.lineage.derived_from??[]).forEach((v,$)=>{k(Qo(_.id,v,$))}),(_.lineage.related_to??[]).forEach((v,$)=>{k(Tu(_.id,v,$))}));for(const _ of r.hypothetical_nodes??[])u&&!u.has(_.id)&&!x.has(_.id)||(_.derived_from??[]).forEach((v,$)=>{k(Qo(_.id,v,$))});return{nodes:w,edges:y,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function il(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Eu(e,n){const i=[],r=e.version_graph;if(!r)return i;const s=new Set(n.map(a=>a.id)),l=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),c=new Set([...s,...l]),p=(a,d)=>{c.has(d.ref)||i.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(u=>p(d,u)),(a.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||i.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(u=>p(d,u))}return i}const ol=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:s}=V();if(!e.nodes.length)return t.jsx("div",{style:{...Vu,...r},className:i,children:"暂无版本图数据"});const l=new Map,c=new Map;for(const x of e.edges)if(x.kind==="derive"){const m=l.get(x.target)??[];m.push(x),l.set(x.target,m)}else for(const m of[x.source,x.target]){const b=c.get(m)??[];b.push(x),c.set(m,b)}const p=new Map(e.nodes.map(x=>[x.id,x])),a=new Map,d=[];for(const x of e.nodes)if(x.group){const m=a.get(x.group)??[];m.push(x),a.set(x.group,m)}else d.push(x);const u=(x,m)=>(x.year??9999)-(m.year??9999);a.forEach(x=>x.sort(u)),d.sort(u);const f=e.groups.filter(x=>a.has(x.id));return t.jsxs("div",{className:i,style:{...Lu,...r},children:[e.title&&t.jsx("div",{style:Bu,children:s(e.title)}),e.description&&t.jsx("div",{style:Au,children:s(e.description)}),f.map(x=>t.jsx(er,{label:x.label,color:x.color,nodes:a.get(x.id),incomingMap:l,siblingMap:c,nodeMap:p,renderLink:n},x.id)),d.length>0&&t.jsx(er,{label:"其他",nodes:d,incomingMap:l,siblingMap:c,nodeMap:p,renderLink:n})]})},er=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:c})=>{const{convert:p}=V();return t.jsxs("div",{style:Wu,children:[t.jsx("div",{style:{...Mu,borderLeftColor:n??o("widget-border")},children:p(e)}),i.map(a=>t.jsx(Nu,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:l,renderLink:c},a.id))]})},Nu=({node:e,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",c=e.bridge,{convert:p}=V();return t.jsxs("div",{style:{...Fu,borderStyle:l||c?"dashed":"solid",opacity:c?.55:e.status==="lost"?.7:1,background:c?o("bg-subtle"):void 0},title:c?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:Pu,children:[t.jsx("span",{style:Ou,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Du,children:il(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Hu,children:[e.category&&t.jsx(Ft,{children:p(e.category)}),e.status==="lost"&&t.jsx(Ft,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(Ft,{tone:"warn",children:"残本"}),l&&t.jsx(Ft,{tone:"info",children:"假想祖本"}),c&&t.jsx(Ft,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Gu,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:Uu,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:nr,children:[t.jsx("div",{style:ir,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return t.jsxs("div",{style:or(a.confidence),children:[t.jsx("span",{style:rr,children:p(a.relation)}),t.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,p(d.label)):p((d==null?void 0:d.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&t.jsx(tr,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:sr,children:["· ",p(a.evidence)]})]},a.id)})]}),i.length>0&&t.jsxs("div",{style:nr,children:[t.jsx("div",{style:ir,children:"关联:"}),i.map(a=>{const d=a.source===e.id?a.target:a.source,u=r.get(d);return t.jsxs("div",{style:or(a.confidence),children:[t.jsx("span",{style:rr,children:p(a.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,p(u.label)):p((u==null?void 0:u.label)??d)}),t.jsx(tr,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:sr,children:["· ",p(a.evidence)]})]},a.id)})]})]})},Ft=({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})},tr=({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")},Bu={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Au={fontSize:"13px",color:o("muted"),marginBottom:"16px",lineHeight:1.6},Wu={marginBottom:"16px"},Mu={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:o("fg")},Fu={border:`1px solid ${o("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:o("bg")},Pu={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Ou={fontSize:"15px",fontWeight:600},Du={fontSize:"12px",color:o("muted")},Hu={marginBottom:"6px"},Gu={fontSize:"12px",color:o("muted"),margin:"2px 0"},Uu={fontSize:"12px",color:o("muted"),fontStyle:"italic",margin:"4px 0"},nr={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${o("widget-border")}`},ir={fontSize:"11px",color:o("muted"),marginBottom:"2px"},or=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),rr={display:"inline-block",padding:"0 6px",fontSize:"11px",background:o("tag-bg"),color:o("fg"),borderRadius:"3px",marginRight:"6px"},sr={fontSize:"11px",color:o("muted")},Vu={padding:"20px",textAlign:"center",color:o("muted"),fontSize:"13px"},rl=({selectedNodeId:e,...n})=>{const[i,r]=g.useState("loading"),[s,l]=g.useState(null);return g.useEffect(()=>{let c=!1;return Yu().then(p=>{c||(p?(l(p),r("ready")):r("missing"))}),()=>{c=!0}},[]),i==="loading"?t.jsx("div",{style:lr,children:"加载图组件中…"}):i==="missing"||!s?t.jsxs("div",{style:lr,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(Ku,{modules:s,selectedNodeId:e,...n})};async function Yu(){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 Ku=({graph:e,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:l,modules:c})=>{const{ReactFlow:p,Background:a,Controls:d,Handle:u,Position:f,BaseEdge:x,EdgeLabelRenderer:m,getSmoothStepPath:b,dagre:w}=c,h=g.useMemo(()=>({lineage:$=>{var U,G,E,oe;const S=((U=$.data)==null?void 0:U.stepPosition)??.85,[z,I,R]=b({sourceX:$.sourceX,sourceY:$.sourceY,sourcePosition:$.sourcePosition,targetX:$.targetX,targetY:$.targetY,targetPosition:$.targetPosition,stepPosition:S,borderRadius:5}),C=!!((G=$.data)!=null&&G.isSibling),F=C?I:$.targetX-18,W=C?R:$.targetY-12,B=(E=$.data)==null?void 0:E.labelStyle,M=(oe=$.data)==null?void 0:oe.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(x,{id:$.id,path:z,style:$.style,markerStart:$.markerStart,markerEnd:$.markerEnd}),$.label&&t.jsx(m,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${F}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")}`,...M,...B},children:$.label})})]})}}),[x,m,b]),j=g.useMemo(()=>({version:$=>{const S=$.data,z=S.kind==="hypothetical",I=S.status==="lost",R=S.isSelected,C=S.bridge,F=S.borderColor??o("muted"),W=C||z?"dashed":"solid",B=C?.5:I?.6:1;return t.jsxs("div",{style:{background:o(C?"bg-subtle":"bg"),border:`2px ${W} ${R?o("primary"):F}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:B,boxShadow:R?o("shadow-node-selected"):z||C?"none":o("shadow-node")},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:f.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&t.jsx("div",{style:{fontSize:10,color:o("muted"),lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&t.jsx("div",{style:{fontSize:10,color:o("muted"),lineHeight:1.2},children:il(S.yearText,void 0,S.uncertain)}),I&&t.jsx("div",{style:{fontSize:9,color:o("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:f.Right,style:{visibility:"hidden"}})]})}}),[u,f]),{convert:y}=V(),{rfNodes:k,rfEdges:_}=g.useMemo(()=>qu(e,w,n,l,y),[e,w,n,l,y]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:t.jsxs(p,{nodes:k,edges:_,nodeTypes:j,edgeTypes:h,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(a,{gap:16}),t.jsx(d,{showInteractive:!1})]})})};function qu(e,n,i,r,s=l=>l??""){const p=e.layout==="LR"||!e.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:p?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(e.groups.map(j=>[j.id,j.color??o("muted")]));for(const j of e.nodes)a.setNode(j.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of e.edges)j.kind==="derive"&&(u.has(j.relation)||a.setEdge(j.source,j.target));n.layout(a);const f=e.nodes.map(j=>{const y=a.node(j.id),k=r?j.id===r:void 0,_={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??Zu(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:i,isSelected:k,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:y.x-160/2,y:y.y-90/2},data:_,draggable:!1,selected:k}}),x=.78,m=.06,b=new Map;for(const j of e.edges)j.kind==="derive"&&(b.has(j.source)||b.set(j.source,[]),b.get(j.source).push(j));const w=new Map;for(const[j,y]of b){if(y.length<=1)continue;const k=[...y].sort((v,$)=>{var I,R;const S=((I=a.node(v.target))==null?void 0:I.y)??0,z=((R=a.node($.target))==null?void 0:R.y)??0;return S-z}),_=k.length;k.forEach((v,$)=>{const S=($-(_-1)/2)*m;w.set(v.id,x+S)})}const h=e.edges.map(j=>Ju(j,w.get(j.id),s));return{rfNodes:f,rfEdges:h}}function Ju(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Xu(e.confidence),c={type:"arrowclosed",color:l,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:i(e.relation),data:{labelStyle:{color:o("fg")},isSibling:s,stepPosition:n},style:{stroke:l,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:c,markerStart:s?c:void 0,zIndex:1e3}}function Zu(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Xu(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 lr={padding:"40px 20px",textAlign:"center",color:o("muted"),fontSize:"13px",border:`1px dashed ${o("widget-border")}`,borderRadius:8,background:o("bg")},sl=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:c,onCollectionChange:p,collectionsAvailable:a,collectionCounts:d,className:u,style:f})=>{var y;const[x,m]=g.useState(n),b=k=>{m(k),l==null||l(k)},w=(()=>{if(!a)return[];const k=Object.entries(a);return k.length===0||a.all?k:[...k,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),h=!!(p&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:o("muted"),textAlign:"center"},children:"暂无版本传承数据"});const j=c?(y=a==null?void 0:a[c])==null?void 0:y.description:void 0;return t.jsxs("div",{className:u,style:f,children:[t.jsxs("div",{style:Qu,children:[t.jsx("button",{onClick:()=>b("list"),style:Ln(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:Ln(x==="graph"),children:"关系图"}),h&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:o("muted"),marginRight:4},children:"集合:"}),w.map(([k,_])=>{const v=d==null?void 0:d[k];return t.jsxs("button",{onClick:()=>p==null?void 0:p(k),style:Ln(c===k),title:_.description,children:[_.label,v!=null?` ${v}`:""]},k)})]})]}),h&&j&&t.jsx("div",{style:{fontSize:12,color:o("muted"),marginBottom:8,padding:"4px 8px",background:o("bg-subtle"),borderRadius:4},children:j}),x==="list"?t.jsx(ol,{graph:e,renderLink:i}):t.jsx(rl,{graph:e,renderLink:i,height:r,selectedNodeId:s})]})},Qu={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Ln=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"}),Qn=({style:e})=>{const n=g.useContext(It);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:"简"})]})},ei=({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 Bn(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function ex(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const tx=({id:e,transport:n,initialDetail:i,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:c,onJuanChange:p,lineageMode:a="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:f,initialPage:x=1,selectedLineageNodeId:m,onNavigate:b,onBack:w,backLabel:h,renderLink:j,enrichDetail:y,getSourceLink:k,readLink:_,railTop:v,extraTabs:$=[],showFeedbackTab:S=!0,feedbackApiUrl:z,height:I,footerExtra:R,className:C,style:F})=>{var Oi;const W=ce(),{convert:B}=V(),[M]=g.useState(()=>{if(!ex(e,i))return null;const H={...i},be=r??Bn(e,H);return y&&y(be,H),{id:e,entry:be,detail:H}}),[U,G]=g.useState((M==null?void 0:M.entry)??null),[E,oe]=g.useState((M==null?void 0:M.detail)??null),[P,le]=g.useState(!M),[ge,Q]=g.useState(!1),[O,q]=g.useState([]),[de,se]=g.useState(!1),[te,D]=g.useState(null),[K,X]=g.useState(!1),[xe,A]=g.useState(null),[re,ne]=g.useState(!1),[pe,fe]=g.useState(null),[L,J]=g.useState([]),[Y,T]=g.useState(!1),[ee,ie]=g.useState(null),[ye,me]=g.useState(null),[Ce,_e]=g.useState(!1),We=g.useRef(null),[Fe,Te]=g.useState(null),He=c!==void 0?c:Fe,Ke=g.useCallback(H=>{p?p(H):Te(H)},[p]),Nt=g.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){q([]);return}se(!0);try{if(n.getCollectionCatalogs)q(await n.getCollectionCatalogs(H)||[]);else if(n.getCollectionCatalog){const be=await n.getCollectionCatalog(H);q(be?[{resource_id:"",data:be}]:[])}}catch{q([])}finally{se(!1)}},[n]),N=g.useCallback(async H=>{if(!n.getCollatedEditionIndex){D(null);return}X(!0);try{D(await n.getCollatedEditionIndex(H))}catch{D(null)}finally{X(!1)}},[n]),ae=g.useCallback(async H=>{if(!n.getBookFullTextIndex){A(null);return}ne(!0);try{A(await n.getBookFullTextIndex(H))}catch{A(null)}finally{ne(!1),fe(H)}},[n]),ue=g.useCallback(async H=>{var be;if(!n.getWorkFullTextList){J([]);return}T(!0);try{const we=(await n.getWorkFullTextList(H)??[]).filter(Ee=>Ee.owner_type!=="Book");J(we),ie(((be=we.find(Ee=>Ee.primary)??we[0])==null?void 0:be.key)??null)}catch{J([])}finally{T(!1)}},[n]),ke=g.useCallback(async(H,be)=>{_e(!0);try{if(n.getLineageGraph){const Me=await n.getLineageGraph(H);Me&&me(Me)}const we=be.version_graph;if(!we||!we.enabled){ye||me(null),We.current=null;return}const Ee=be.books??[],qe=[];for(const Me of Ee)try{const Je=await n.getItem(Me);Je&&qe.push(Je)}catch{}We.current={work:be,books:qe};const Z=u??we.default_collection??(we.core_books&&we.core_books.length>0?"core":"all"),$e=Z==="core"&&Array.isArray(we.core_books)&&we.core_books.length>0?"core":Z??"all";me(dn(be,qe,$e))}catch{me(null),We.current=null}finally{_e(!1)}},[n]),je=g.useRef({initialDetail:i,initialEntry:r});je.current={initialDetail:i,initialEntry:r},g.useEffect(()=>{let H=!1;const be=Z=>{Z.type==="collection"?Nt(e):Z.type==="work"?(Z.has_collated&&N(e),(Z.version_graph||n.getLineageGraph)&&ke(e,Z),n.getWorkFullTextList&&ue(e)):Z.type==="book"&&Z.has_full_text&&n.getBookFullTextIndex&&ae(e)},we=je.current;let Ee=null;if(M&&M.id===e)Ee=M;else if(we.initialDetail&&we.initialDetail.id===e){const Z={...we.initialDetail},$e=we.initialEntry??Bn(e,Z);y&&y($e,Z),Ee={entry:$e,detail:Z}}return Ee?(Q(!1),q(Z=>Z.length?[]:Z),D(null),A(null),J(Z=>Z.length?[]:Z),ie(null),me(null),We.current=null,G(Ee.entry),oe(Ee.detail),le(!1),be(Ee.detail),()=>{H=!0}):((async()=>{le(!0),Q(!1),G(null),oe(null),q([]),D(null),A(null),J([]),ie(null),me(null),We.current=null;try{const Z=await n.getItem(e);if(H)return;if(!Z){Q(!0);return}const $e=Z;let Me=null;if(n.getEntry&&(Me=await n.getEntry(e),H))return;Me||(Me=Bn(e,$e)),y&&y(Me,$e),G(Me),oe($e),be($e)}catch{H||Q(!0)}finally{H||le(!1)}})(),()=>{H=!0})},[e,n,M,y,Nt,N,ke,ae,ue]),g.useEffect(()=>{const H=We.current;!H||!u||me(dn(H.work,H.books,u))},[u]);const he=[];if(E){if(he.push({key:"basic",label:W.detailTab.basicInfo}),E.type==="collection"){de&&O.length===0&&he.push({key:"catalog:loading",label:`${W.detailTab.catalog}…`});for(const H of O)he.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${B(H.short_name)}${W.detailTab.catalogSuffix}`:W.detailTab.collectionCatalog})}E.type==="work"&&(te||K)&&s==="collated"&&he.push({key:"collated",label:K?`${W.detailTab.collatedEdition}…`:W.detailTab.collatedEdition}),E.type==="book"&&(xe||re)&&s==="fulltext"&&he.push({key:"fulltext",label:re?`${W.detailTab.fullText}…`:W.detailTab.fullText}),E.type==="work"&&(L.length>0||Y)&&s==="fulltext"&&he.push({key:"fulltext",label:Y?`${W.detailTab.fullText}…`:W.detailTab.fullText}),E.type==="work"&&(ye||Ce)&&he.push({key:"lineage",label:Ce?`${W.detailTab.lineage}…`:W.detailTab.lineage});for(const H of $)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(E)&&he.push({key:H.key,label:H.label});S&&s==="feedback"&&he.push({key:"feedback",label:W.detailTab.feedback});for(const H of $)H.position==="after-feedback"&&H.shouldShow(E)&&he.push({key:H.key,label:H.label})}g.useEffect(()=>{if(s!=="emendated"||!E)return;l("basic");const H=setTimeout(()=>{var be;(be=document.getElementById("studies"))==null||be.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[s,E,l]);const Re=U&&E&&k?k({activeTab:s,activeJuan:He,entry:U,detail:E}):null,tt=g.useMemo(()=>{var qe;if(!E)return null;const be=(E.authors??[]).map(Z=>{const $e=ui(Z.role);return`${Z.dynasty?`〔${B(Z.dynasty)}〕`:""}${B(Z.name)}${$e?` ${B($e)}`:""}`}).join(" · ");let we=!1;try{we=ve.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const Z=E;return{title:B(Z.title),subtitle:Z.edition?B(Z.edition):be||void 0,aside:[we?W.status.draft:"",be&&Z.edition?be:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const Z=E;return{title:B(Z.title),subtitle:B(st(Z,W.unit.juan))||void 0,aside:[(qe=Z.publication_info)==null?void 0:qe.year,we?W.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:be||void 0}}if(E.type==="entity"){const Z=E,$e=Je=>Je==null?"":Je<0?`前${-Je}`:String(Je),Me=Z.birth_year!=null||Z.death_year!=null?`${$e(Z.birth_year)||"?"}—${$e(Z.death_year)||"?"}`:"";return{title:B(Z.primary_name||Z.title),subtitle:[Z.dynasty?`〔${B(Z.dynasty)}〕`:"",Me].filter(Boolean).join(" ")||void 0,aside:we?W.status.draft:void 0,secondLine:void 0}}const Ee=B(st(E,W.unit.juan));return{title:B(E.title),subtitle:[Ee,be].filter(Boolean).join(" · ")||void 0,aside:[ix(W,E.subtype),we?W.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,B,W]),pt=E?E.type==="work"?(((Oi=te==null?void 0:te.juan_files)==null?void 0:Oi.length)??0)>0?"collated":L.length>0?"fulltext":null:E.type==="book"&&(((xe==null?void 0:xe.chapters.length)??0)>0||E.has_full_text&&n.getBookFullTextIndex&&pe!==E.id)?"fulltext":null:null,lt=L.find(H=>H.primary)??L[0],Xt=()=>{var H;pt==="collated"&&((H=te==null?void 0:te.juan_files)!=null&&H.length)?(Ke(te.juan_files[0]),l("collated")):pt==="fulltext"&&((E==null?void 0:E.type)==="work"&<&&ie(lt.key),Ke(null),l("fulltext"))};let at=null;if(E&&_){const H=_({detail:E,kind:pt,fullTextKey:E.type==="work"?lt==null?void 0:lt.key:void 0});H&&(at=t.jsx(Dn,{href:H}))}else pt&&(at=t.jsx(Dn,{onClick:Xt}));const Qt=H=>{if(!E)return null;const be=H.replace(/\.[^.]+$/,"");if(_){const we=_({detail:E,kind:"fulltext",juan:be});return we?{href:we}:null}return{onClick:()=>{Ke(be),l("fulltext")}}},Se=new Set($.map(H=>H.key)),Ge=he.filter(H=>H.key.startsWith("catalog:")&&H.key!=="catalog:loading"||Se.has(H.key)).map(H=>({key:H.key,label:H.label,onClick:()=>l(H.key)})),ze=()=>{var H;return E?E.type==="work"?t.jsx(Vs,{data:E,transport:n,onNavigate:b,renderLink:j,readAction:at,railTop:v,railLinks:Ge}):E.type==="book"?t.jsx(Ys,{data:E,transport:n,onNavigate:b,renderLink:j,readAction:at,fullText:xe,fullTextPending:!!E.has_full_text&&!!n.getBookFullTextIndex&&pe!==E.id,chapterLink:Qt,railTop:v,railLinks:Ge}):E.type==="collection"?t.jsx(Ks,{data:E,catalog:(H=O[0])==null?void 0:H.data,transport:n,onNavigate:b,renderLink:j,readAction:at,railTop:v,railLinks:Ge,catalogAction:O.length>0?t.jsxs("a",{href:"#catalog",onClick:be=>{be.preventDefault(),l(`catalog:${O[0].resource_id}`)},children:[B(W.detailTab.collectionCatalog)," →"]}):null}):t.jsx(qs,{data:E,transport:n,onNavigate:b,renderLink:j,railTop:v,railLinks:Ge}):null},en=()=>{var be,we,Ee,qe;if(!U||!E)return null;if(s==="basic"||s==="emendated")return ze();if(typeof s=="string"&&s.startsWith("catalog:")){const Z=(be=O.find($e=>`catalog:${$e.resource_id}`===s))==null?void 0:be.data;return t.jsx(li,{data:Z,onNavigate:b,renderLink:j})}if(s==="collated")return t.jsx(Ei,{index:te||void 0,workId:e,transport:n,onNavigate:b,activeJuan:He,onJuanChange:Ke});if(s==="fulltext"&&E.type==="work"){const Z=ee??((we=L[0])==null?void 0:we.key);return Z?t.jsx(qn,{bookId:e,workKey:Z,versions:L,onVersionChange:$e=>{ie($e),Ke(null)},transport:n,activeChapter:He,onChapterChange:Ke},Z):t.jsx("div",{style:{padding:24,color:o("desc-fg")},children:Y?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(qn,{index:xe||void 0,bookId:e,transport:n,activeChapter:He,onChapterChange:Ke});if(s==="lineage"){if(!ye)return t.jsx("div",{style:{color:o("label-fg"),padding:"24px 0"},children:Ce?"加載中…":"暫無版本圖數據"});const Z=E.type==="work"?E:null;return t.jsx(sl,{graph:ye,renderLink:j,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:a,onModeChange:d,selectedNodeId:m,collection:u??((Ee=Z==null?void 0:Z.version_graph)==null?void 0:Ee.default_collection),onCollectionChange:f,collectionsAvailable:(qe=Z==null?void 0:Z.version_graph)==null?void 0:qe.collections,collectionCounts:(()=>{var Di,Hi,Gi,Ui,Vi,Yi,Ki;if(!Z)return;const $e={},Me=((Di=We.current)==null?void 0:Di.books)??[];$e.all=(((Hi=Z.books)==null?void 0:Hi.length)??0)-(((Ui=(Gi=Z.version_graph)==null?void 0:Gi.excluded_books)==null?void 0:Ui.length)??0);const Je=(Vi=Z.version_graph)==null?void 0:Vi.collections;if(Je)for(const qi of Object.keys(Je))$e[qi]=dn(Z,Me,qi).nodes.filter(Ji=>Ji.kind==="book"&&!Ji.bridge).length;return $e.core==null&&((Ki=(Yi=Z.version_graph)==null?void 0:Yi.core_books)!=null&&Ki.length)&&($e.core=Z.version_graph.core_books.length),$e})()})}if(s==="feedback"&&S)return t.jsx(Ds,{resourceId:e,apiUrl:z});const H=$.find(Z=>Z.key===s);return H?H.render({detail:E,entry:U,transport:n,onNavigate:b}):null};if(P)return t.jsx(Pt,{style:{minHeight:I,...F},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((H,be)=>t.jsx("div",{style:{height:be===1?40:16,width:H,opacity:.35,background:o("rule")}},be))})});if(ge||!E||!U||!tt)return t.jsx(Pt,{style:{minHeight:I,...F},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:o("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const Sn=s==="basic"||s==="emendated",tn=[{label:h??W.detailTab.backToIndex,onClick:w}];if(E.type==="book"&&E.work_id){const H=E.work_id;tn.push({label:W.indexType.work,id:H,onClick:()=>b==null?void 0:b(H)})}tn.push({label:W.indexType[E.type]});const nn=s==="collated"||s==="fulltext",Fi=typeof R=="string"?W.status[R.trim()]??R:R,Pi=t.jsx(ts,{left:t.jsxs(t.Fragment,{children:[Fi,Fi?" · ":"",t.jsx(nx,{id:E.id,label:W.label.id,copied:W.action.copied,copyLabel:W.action.copy})]}),right:t.jsxs(t.Fragment,{children:[S&&!Sn&&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}),Re&&t.jsx("a",{href:Re.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:o("meta-fg")},children:W.detailTab.dataLicense})]})});return Sn?t.jsx("div",{className:C,children:t.jsxs(Pt,{grid:!0,style:{minHeight:I,...F},children:[t.jsx(Hn,{breadcrumb:t.jsx(Gn,{items:tn}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Qn,{style:{border:"none",background:"transparent"}}),Re&&t.jsx(ei,{...Re})]})}),ze(),Pi]})}):t.jsx("div",{className:C,children:t.jsxs(Pt,{wide:nn,style:{minHeight:I,...F},children:[t.jsx(Hn,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(gi,{char:"籍"}),t.jsx(Gn,{items:tn})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Qn,{}),S&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:o("meta-fg")},children:W.detailTab.feedback}),Re&&t.jsx(ei,{...Re})]})}),t.jsx(Vr,{...tt,aside:nn?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:[B("作品信息")," →"]}):tt.aside}),!nn&&he.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:he.map(H=>t.jsx(Yr,{label:H.label,active:H.key===s||Sn&&H.key==="basic",onClick:()=>l(H.key)},H.key))}),t.jsx("div",{style:{marginTop:!nn&&he.length>1?8:0},children:en()}),Pi]})})};function nx({id:e,label:n,copied:i,copyLabel:r}){const[s,l]=g.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var c;(c=navigator.clipboard)==null||c.writeText(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?i:r,"aria-label":s?i:r,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:o("aux-fg")},children:s?"✓":"⧉"})]})}function ix(e,n){return n?e.workSubtype[n]??n:""}exports.BidLink=ve.BidLink;exports.BookIndexError=ve.BookIndexError;exports.BookIndexManager=ve.BookIndexManager;exports.BookIndexStorage=ve.BookIndexStorage;exports.BundleStorage=ve.BundleStorage;exports.ConfigError=ve.ConfigError;exports.GithubStorage=ve.GithubStorage;exports.IdGenerationError=ve.IdGenerationError;exports.IdGenerator=ve.IdGenerator;exports.LocalStorage=ve.LocalStorage;exports.MigrationError=ve.MigrationError;exports.StorageError=ve.StorageError;exports.base36Decode=ve.base36Decode;exports.base36Encode=ve.base36Encode;exports.base58Decode=ve.base58Decode;exports.buildId=ve.buildId;exports.buildPromotionMap=ve.buildPromotionMap;exports.cleanName=ve.cleanName;exports.decodeId=ve.decodeId;exports.decodeIdString=ve.decodeIdString;exports.encodeId=ve.encodeId;exports.extractIdFromUrl=ve.extractIdFromUrl;exports.extractStatus=ve.extractStatus;exports.extractType=ve.extractType;exports.normalizeCatalog=ve.normalizeCatalog;exports.parseId=ve.parseId;exports.shardOf=ve.shardOf;exports.smartDecode=ve.smartDecode;exports.validateResource=ve.validateResource;exports.Badge=fn;exports.BidUrlProvider=hl;exports.BookDetailLayout=tx;exports.BookFullText=qn;exports.BookPage=Ys;exports.Breadcrumb=Gn;exports.CATALOG_ALL_ID=it;exports.CATALOG_CSS=Js;exports.CATALOG_NARROW_QUERY=Ai;exports.CATALOG_PAGE_SIZE=Wi;exports.CATALOG_UNCLASSIFIED_ID=Gt;exports.CardFoot=qt;exports.CatalogPage=zu;exports.CatalogPager=tl;exports.CatalogTree=Xs;exports.CheckFilter=Gr;exports.Chip=Kr;exports.ChipWall=dc;exports.CollatedEdition=Ei;exports.CollectionCatalog=li;exports.CollectionPage=Ks;exports.CreateEntityDialog=Ls;exports.DEFAULT_READER_PREFS=bi;exports.DETAIL_CSS=Ur;exports.Dash=mc;exports.DataTable=uc;exports.DetailFooter=ts;exports.DetailGrid=Yt;exports.DetailHeader=Vr;exports.EmendatedBySection=$r;exports.EmptyNote=Sc;exports.EntityDetail=jr;exports.EntityPage=qs;exports.EntityPickerDialog=As;exports.EntitySelector=Ns;exports.ExpandRow=hc;exports.ExtLink=wc;exports.FEEDBACK_FAB_OFFSET_VAR=Zn;exports.FONT_SIZE_STEPS=St;exports.FactList=sc;exports.FeedbackButton=Vp;exports.FeedbackDialog=Ps;exports.FeedbackForm=Os;exports.FeedbackList=Ni;exports.FeedbackTab=Ds;exports.FilterChip=Yr;exports.FormInput=Oe;exports.FormTextArea=mt;exports.GUJI_MARKDOWN_FIELD=Va;exports.GUJI_TABLE_NOTATION=us;exports.GlyphBadge=gi;exports.GujiTable=ki;exports.HomePage=Kn;exports.ImagePanel=ls;exports.IndexApp=Zd;exports.IndexBrowser=Mn;exports.IndexDetail=si;exports.IndexEditor=Ws;exports.IndexView=Np;exports.IntroGrid=rc;exports.LocaleContext=It;exports.LocaleProvider=Rl;exports.LocaleToggle=Qn;exports.MetaLine=Le;exports.ModeIndicator=hr;exports.MoreButton=cc;exports.MoreLink=Et;exports.PAGE_MAX_WIDTH=an;exports.PageFrame=Pt;exports.Quote=yc;exports.READER_CSS=os;exports.RECENT_IDS_STORAGE_KEY=_t;exports.ROLE_CLASS_ORDER=Nr;exports.ReadButton=Dn;exports.ReaderMdText=$i;exports.ReaderShell=ji;exports.ReaderToc=ss;exports.RelationPanel=Rs;exports.RepoSourceLink=ei;exports.ResourceEditor=Wn;exports.ResourceGroup=jc;exports.ResourceLine=vc;exports.ResourceList=ri;exports.ResourceRow=Qr;exports.SNIPPET_MARK_END=dr;exports.SNIPPET_MARK_START=cr;exports.SearchInput=br;exports.Sec=Be;exports.Section=Ve;exports.SectionHead=lc;exports.SideList=gt;exports.SmartBidInput=cn;exports.SourceEditor=Cs;exports.SummaryCard=Kt;exports.TabFilter=xi;exports.TableHead=xc;exports.TableRow=fc;exports.TagRow=es;exports.TagRows=kc;exports.TextButton=ac;exports.TopStrip=Hn;exports.VersionLineageGraph=rl;exports.VersionLineageList=ol;exports.VersionLineageView=sl;exports.VolumeChips=pc;exports.VolumeLinks=mi;exports.WorkCard=el;exports.WorkCardGrid=nl;exports.WorkCatalog=Xd;exports.WorkPage=Vs;exports.bucketResources=di;exports.buildCatalogTree=hu;exports.buildCollectionTable=Br;exports.buildLineageGraph=dn;exports.buildPageUrl=oi;exports.buildParagraphBlocks=js;exports.buildVersionRow=Rr;exports.buildVersionTable=Er;exports.canParagraphize=kn;exports.catalogNodeIdOf=gu;exports.catalogNodeIdsOf=mu;exports.catalogPageCount=vu;exports.catalogTotal=Mi;exports.classificationPath=Zt;exports.compareCatalogCards=ju;exports.computeVersionPartition=Da;exports.defaultWorkLink=Qs;exports.deriveDating=Fa;exports.deriveEditionType=Wr;exports.deriveEra=Vt;exports.deriveYear=bn;exports.deriveYearRange=ci;exports.detailToEditor=Fs;exports.detectGenre=vn;exports.displayAuthorRole=ui;exports.editorToDetail=Ep;exports.eraRank=Pn;exports.findCatalogPath=wt;exports.flattenTitles=Un;exports.flattenToc=ps;exports.formatTemplate=Ut;exports.formatVolumeRange=jn;exports.getDisplayNameFromUrl=Tt;exports.getStartPage=ii;exports.getTypeGroupKey=ti;exports.groupRelatedWorks=Pa;exports.gujiInlineToPlain=Or;exports.hasGujiMarkdownV02=On;exports.hasGujiTableNotation=xs;exports.measureText=st;exports.mergeVolumeResources=ni;exports.normalizeEra=Ne;exports.normalizeRole=pi;exports.normalizeVolumeIndex=Dt;exports.normalizeVolumes=mr;exports.numberToChinese=Ar;exports.paginationItems=Zs;exports.parseChineseNumber=pn;exports.parseGujiInline=Pr;exports.parseGujiTable=gs;exports.parseSourceString=Is;exports.pickReaderVersion=ds;exports.readerVersionOptionLabel=Yn;exports.readerVersionsFromFullText=cs;exports.renderFullTextBody=Yc;exports.renderProperNames=ks;exports.renderReaderInline=_i;exports.resourceHref=Rt;exports.resourceNote=yn;exports.roleFacets=Lr;exports.rowNo=gc;exports.sortYear=un;exports.splitFullTextTables=vi;exports.splitHighlightSnippet=pr;exports.splitTableRow=fs;exports.stringifySources=Ts;exports.toCatalogWorkCard=yu;exports.useBidUrl=Ae;exports.useConvert=V;exports.useReaderPrefs=yi;exports.useT=ce;exports.validateLineageGraph=Eu;exports.volumeStats=gn;
|