book-index-ui 0.28.0 → 0.28.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -1
- package/dist/index.cjs +64 -55
- package/dist/index.d.ts +178 -1
- package/dist/index.js +4829 -4391
- package/dist/storage-entry-DGtRxALe.cjs +2 -0
- package/dist/{storage-entry-BVyXjZhm.js → storage-entry-Du6ytidI.js} +224 -160
- package/dist/storage.cjs +1 -1
- package/dist/storage.d.ts +99 -0
- package/dist/storage.js +7 -7
- package/package.json +1 -1
- package/dist/storage-entry-BLfpDWdl.cjs +0 -2
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ea=Object.create;var So=Object.defineProperty;var ta=Object.getOwnPropertyDescriptor;var na=Object.getOwnPropertyNames;var ia=Object.getPrototypeOf,oa=Object.prototype.hasOwnProperty;var ra=(e,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of na(n))!oa.call(e,s)&&s!==o&&So(e,s,{get:()=>n[s],enumerable:!(r=ta(n,s))||r.enumerable});return e};var xn=(e,n,o)=>(o=e!=null?ea(ia(e)):{},ra(n||!e||!e.__esModule?So(o,"default",{value:e,enumerable:!0}):o,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $e=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),f=require("react"),sa=require("opencc-js/t2cn"),la=require("react-markdown"),aa=require("remark-gfm"),ca=e=>`/book-index?id=${e}`,Dr=f.createContext(ca);function da({buildUrl:e,children:n}){const o=f.useMemo(()=>e,[e]);return t.jsx(Dr.Provider,{value:o,children:n})}function Fe(){return f.useContext(Dr)}const Hr="",Gr="";function wi(e){const n=[];let o=!1,r=e;for(;r.length;){const s=o?Gr:Hr,l=r.indexOf(s);if(l===-1){n.push({text:r,marked:o});break}l>0&&n.push({text:r.slice(0,l),marked:o}),r=r.slice(l+1),o=!o}return n}function Ve(e,n){return{title:e,tokens:n}}const $o='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',pa=[Ve("基础(VS Code 环境下跟随 --vscode-*)",{bg:{value:"#ffffff",vscode:"--vscode-editor-background"},fg:{value:"#333333",vscode:"--vscode-foreground"},"input-bg":{value:"#ffffff",vscode:"--vscode-input-background"},"input-fg":{value:"#333333",vscode:"--vscode-input-foreground"},"input-border":{value:"#cccccc",vscode:"--vscode-input-border"},"widget-border":{value:"#e0e0e0",vscode:"--vscode-widget-border"},"link-fg":{value:"#0066cc",vscode:"--vscode-textLink-foreground"},"desc-fg":{value:"#717171",vscode:"--vscode-descriptionForeground"},primary:{value:"#0078d4",vscode:"--vscode-button-background"},"primary-fg":{value:"#ffffff",vscode:"--vscode-button-foreground"},"primary-soft":{value:"rgba(0, 120, 212, 0.15)",css:"color-mix(in srgb, var(--bim-primary) 15%, transparent)"},danger:{value:"#f44336"},warning:{value:"#ff9800"},success:{value:"#4caf50"},"sidebar-bg":{value:"#f3f3f3",vscode:"--vscode-sideBar-background"},"list-hover-bg":{value:"rgba(0, 0, 0, 0.04)",vscode:"--vscode-list-hoverBackground"},"list-active-bg":{value:"rgba(0, 120, 212, 0.1)",vscode:"--vscode-list-activeSelectionBackground"},"focus-border":{value:"#0078d4",vscode:"--vscode-focusBorder"}}),Ve("底色层次 / 文字与描边 / 链接",{"bg-subtle":{value:"#fafafa"},"widget-bg":{value:"#f8f8f8"},muted:{value:"#888888"},border:{value:"#e5e5e5"},"primary-bg":{value:"#fdf4f4"},link:{value:"#1976d2"},"tag-bg":{value:"#f0f0f0"},"accent-bg":{value:"#1976d2"},"on-color-fg":{value:"#ffffff",note:"彩色底(徽章、选中态按钮)上的文字"}}),Ve("提示与警告",{"info-fg":{value:"#0c5380"},"info-bg":{value:"#e7f3ff"},"info-border":{value:"#b3dbff"},"warn-fg":{value:"#856404"},"warn-bg":{value:"#fff3cd"},"warn-border":{value:"#ffc107"},"danger-bg":{value:"rgba(244, 67, 54, 0.08)",note:"错误提示条底色"},"danger-soft-bg":{value:"rgba(244, 67, 54, 0.03)",note:"编辑器危险区块"},"danger-soft-border":{value:"rgba(244, 67, 54, 0.13)"}}),Ve("遮罩与阴影",{backdrop:{value:"rgba(0, 0, 0, 0.5)",note:"对话框遮罩"},"overlay-bg":{value:"#00000010",note:"轻量遮罩底(图片占位等)"},"shadow-dialog":{value:"0 4px 20px rgba(0, 0, 0, 0.3)"},"shadow-dropdown":{value:"0 4px 12px rgba(0, 0, 0, 0.1)"},"shadow-tooltip":{value:"0 2px 8px rgba(0, 0, 0, 0.08)"},"shadow-fab":{value:"0 2px 8px rgba(0, 0, 0, 0.25)",note:"悬浮按钮(反馈)"},"shadow-card":{value:"0 1px 4px rgba(0, 0, 0, 0.06)",note:"展开的卡片"},"shadow-node":{value:"0 1px 3px rgba(0, 0, 0, 0.1)",note:"谱系图节点"},"shadow-node-selected":{value:"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)"}}),Ve("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),Ve("资源",{"restype-text":{value:"#2196f3"},"restype-image":{value:"#ff9800"},"restype-text-image":{value:"#9c27b0"},"restype-physical":{value:"#795548"},"missing-fg":{value:"#e67e22",note:"资源缺册提示"},"colormode-bw-bg":{value:"#f5f5f5",note:"影印件色彩模式标记(黑白 / 彩色)"},"colormode-bw-fg":{value:"#757575"},"colormode-color-bg":{value:"#fff8e1"},"colormode-color-fg":{value:"#f57f17"},"progress-active":{value:"#f59e0b",note:"资源导入进度"},"progress-done":{value:"#10b981"},"progress-todo":{value:"#9ca3af"},"check-fine-bg":{value:"#e8f5e9",note:"文字资源校对程度徽章(精校 / 粗校 / AI整理)"},"check-fine-fg":{value:"#2e7d32"},"check-rough-bg":{value:"#fff3e0"},"check-rough-fg":{value:"#e65100"},"check-ai-bg":{value:"#e3f2fd"},"check-ai-fg":{value:"#1565c0"}}),Ve("整理本(CollatedEdition)",{"highlight-bg":{value:"#fff59d",note:"搜索命中高亮底"},"highlight-fg":{value:"inherit",root:!1},"section-lei":{value:"#8e6f3e",note:"章节类型标记:类 / 书 / 序 / 结语 / 考证 / 注释"},"section-shu":{value:"#c0392b"},"section-xu":{value:"#1a5276"},"section-jieyu":{value:"#7d6608"},"section-kaozhen":{value:"#5d6d7e"},"section-zhushi":{value:"#6c5b7b"},"section-tag-fg":{value:"#e74c3c",note:"章节标记(△ 等)"},"matchstate-fg":{value:"#b78900",note:"与底本匹配状态提示"},"quality-published":{value:"#1b5e20",note:"文本质量等级(出版 / 精校 / 粗校 / OCR)"},"quality-fine":{value:"#2e7d32"},"quality-rough":{value:"#1565c0"},"quality-ocr":{value:"#e65100"}}),Ve("版本传承(VersionLineageGraph / List) / 关系方向(RelationPanel)",{"lost-fg":{value:"#c62828",note:"佚失标记"},"confidence-certain":{value:"#2e7d32",note:"关系置信度"},"confidence-consensus":{value:"#1976d2"},"confidence-probable":{value:"#ed6c02"},"confidence-disputed":{value:"#c62828"},"lineage-edge-consensus":{value:"#555555",note:"⚠️ 同为 consensus,List 徽章用 --bim-confidence-consensus(蓝),Graph 连线用这个(灰)。若要统一,覆盖成 var(--bim-confidence-consensus)"},"relation-up":{value:"#2196f3"},"relation-down":{value:"#4caf50"},"relation-flat":{value:"#ff9800"}}),Ve("编辑器视图(主要在 guji-platform 插件中可见)",{"editor-type-work":{value:"#4caf50",note:"⚠️ 与展示视图的 --bim-type-* 是两套配色(历史如此)。若要统一,覆盖成对应的 var(--bim-type-*)"},"editor-type-collection":{value:"#2196f3"},"editor-type-book":{value:"#ff9800"},"editor-type-entity":{value:"#9c27b0"},"source-url":{value:"#2196f3",note:"来源类型(SourceEditor)"},"source-bookid":{value:"#4caf50"},"mode-active-bg":{value:"#2196f3",note:"模式指示器当前态(ModeIndicator)"},"cover-accent":{value:"#8e6f3e",note:'书目卡片「封面」点缀(IndexBrowser resultVariant="card")'}}),Ve("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --bim-primary 等控件色",{"page-bg":{value:"#fbf9f3",note:"纸"},"row-hover-bg":{value:"#f5f1e5"},"selection-bg":{value:"#ecdcbc",note:"选区"},"band-bg":{value:"#f0e4cb",note:"全文入口横幅(暖沙)"},"band-bg-hover":{value:"#e6d5b4"},ink:{value:"#2a231c",note:"文字层次:墨 → 正文 → 提要 → meta → 标签 → 提示"},"body-fg":{value:"#3b3228"},"quiet-fg":{value:"#5b4f40"},"meta-fg":{value:"#7b6a54"},"label-fg":{value:"#6f6457",note:"标签 / 提示:2026-09 N3a 调深,纸底与斑马底上对比度均 ≥4.5(原 #a3937b 2.8、#b3a385 2.3)"},"hint-fg":{value:"#756a5e"},accent:{value:"#9c3a2c",note:"朱"},"accent-deep":{value:"#6f2a20",note:"链接 hover"},"rule-strong":{value:"#2a231c",note:"分隔线:强 → 常规 → 虚线 → 提要左线"},rule:{value:"#e4dbc9"},"rule-dashed":{value:"#d6c9ae"},"rule-accent-soft":{value:"#e0d3b6"},"aux-fg":{value:"#6f6457",note:"辅助字(元数据、注记、「·」分隔的浅色小字)。须在 page-bg / zebra-bg 上对比度 ≥4.5(Q5 巡检)"},"card-bg":{value:"#fffdf9",note:"提要卡:抬起的面"},"zebra-bg":{value:"#f6f2eb",note:"表格斑马纹 / 左栏分组底(不画格线,靠这一阶底色分行)"},"tint-bg":{value:"#f3eee6",note:"检索框、悬停"},"shadow-summary":{value:"0 10px 32px rgba(60, 50, 40, 0.07)",note:"提要卡投影"},"flag-bg":{value:"rgba(158, 42, 43, 0.08)",note:"唯一的状态色块「有影印」"},"theme-dot-zhusha":{value:"#9c3a2c",note:"主题切换控件的色点:朱砂(不随主题变,两套主题下都要认得出)"},"theme-dot-indigo":{value:"#2e5266",note:"主题切换控件的色点:靛青"},"theme-dot-ink":{value:"#222221",note:"主题切换控件的色点:墨"},"sect-jing":{value:"#2e5266",note:"四部分布条:經部(人物页提要卡;无别处使用)"},"sect-shi":{value:"#9a7a3b",note:"四部分布条:史部"},"sect-zi":{value:"#4f7a5c",note:"四部分布条:子部"},"sect-ji":{value:"#9fb3bc",note:"四部分布条:集部"},"table-border":{value:"color-mix(in srgb, currentColor 28%, transparent)",root:!1,note:"古籍表格(跟随当前文字色)"},"table-head-bg":{value:"color-mix(in srgb, currentColor 8%, transparent)",root:!1}}),Ve('版式(v4 外观系统,overview#291):疏朗=留白分区(默认,下列值即疏朗);界栏=框线分区(`<html data-layout="boxed">`)',{"fr-bd":{value:"0 solid transparent",note:"区块外框(border 简写)。疏朗无框;界栏 1px 实线"},"fr-bg":{value:"transparent",note:"区块底。界栏=卡面色"},"fr-hd-pad":{value:"0",note:"区块标题栏内边距(界栏:标题栏与正文之间有分隔线)"},"fr-hd-bd":{value:"0 solid transparent",note:"区块标题栏下沿线(border 简写)"},"fr-bd-pad":{value:"0",note:"区块正文内边距"},"fr-gap":{value:"56px",note:"区块之间的间距。界栏收紧到 24px(框线本身已分隔)"},"fr-side-gap":{value:"34px",note:"侧栏各块之间的间距;界栏 20px"},"fr-shadow":{value:"0 1px 0 var(--bim-rule), 0 12px 32px -18px rgba(40, 36, 31, 0.25)",note:"抬起的面(提要卡)的投影;界栏不用投影,靠框线"},"fr-tab-bd":{value:"transparent",note:"页签行下沿线颜色(疏朗不画,界栏画)"}}),Ve("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),Ve("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),Ve("字体(全站无衬线,2026-09-05 定)",{"font-ui":{value:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif'},"font-body":{value:"system-ui, sans-serif",css:"var(--bim-font-ui)"},"font-serif":{value:$o,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:$o,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],ua=Object.assign({},...pa.map(e=>e.tokens)),Ur={};for(const[e,n]of Object.entries(ua))Ur[e]=`var(--bim-${e}, ${n.value})`;function i(e){const n=Ur[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function vt(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function xa(e,n){return vt(e).includes(n)}const ti={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},fa={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};i("quality-published"),i("quality-fine"),i("quality-rough"),i("quality-ocr");const Lt=f.createContext(null),Vr={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:i("check-fine-bg"),fg:i("check-fine-fg")},粗校:{label:"粗校",bg:i("check-rough-bg"),fg:i("check-rough-fg")},AI整理:{label:"AI整理",bg:i("check-ai-bg"),fg:i("check-ai-fg")}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入叢編",collectedIn:"收入叢編",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評註",studies:"所考典籍"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"結果分類",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},searchV4:{filterTitle:"篩選",dynasty:"朝代",classification:"部類",resources:"資源",extant:"存佚",clearAllFilters:"清除全部篩選",hasImage:"有影印",hasText:"有全文",hasCollated:"有整理本",filterButton:"篩選",filterSelected:"{n} 項已選",expand:"展開",collapse:"收起",filteredCount:"篩出 {n} 條",removeFilter:"取消篩選:{name}",viewLabel:"結果視圖",viewTable:"表格",viewCard:"卡片",colTitle:"題名",colType:"類型",colAuthor:"責任者",colEra:"年代",colClass:"部類",colResource:"資源",tagImage:"影印",tagText:"全文",tagCollated:"整理本",tagLost:"佚",pageInfo:"共 {total} 條 · 每頁 {size} 條 · 第 {page} / {pages} 頁",pagerLabel:"翻頁",prevPage:"上一頁",nextPage:"下一頁",emptyFiltered:"沒有找到匹配的條目。試試更短的書名、減少篩選,或切換繁 / 簡。",limitedNote:"各類只列前幾條,點上方分類頁籤看全部。",sortLabel:"排序",sortRelevance:"相關度",sortEra:"年代",sortTitle:"書名",sortEraAsc:"由早到晚",sortEraDesc:"由晚到早",sortTitleAsc:"拼音 A→Z",sortTitleDesc:"拼音 Z→A",onlyWorksNote:"部類、存佚只適用於作品;選了它們,版本、叢編、人物不參與。"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"概覽",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄",fullText:"全文",lineage:"版本傳承",feedback:"勘誤反饋",dataSource:"數據源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"數據源與授權"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},workSubtype:{book:"書",article:"篇",poem:"詩",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},ma={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:i("check-fine-bg"),fg:i("check-fine-fg")},粗校:{label:"粗校",bg:i("check-rough-bg"),fg:i("check-rough-fg")},AI整理:{label:"AI整理",bg:i("check-ai-bg"),fg:i("check-ai-fg")}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入丛编",collectedIn:"收入丛编",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评注",studies:"所考典籍"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"结果分类",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},searchV4:{filterTitle:"筛选",dynasty:"朝代",classification:"部类",resources:"资源",extant:"存佚",clearAllFilters:"清除全部筛选",hasImage:"有影印",hasText:"有全文",hasCollated:"有整理本",filterButton:"筛选",filterSelected:"{n} 项已选",expand:"展开",collapse:"收起",filteredCount:"筛出 {n} 条",removeFilter:"取消筛选:{name}",viewLabel:"结果视图",viewTable:"表格",viewCard:"卡片",colTitle:"题名",colType:"类型",colAuthor:"责任者",colEra:"年代",colClass:"部类",colResource:"资源",tagImage:"影印",tagText:"全文",tagCollated:"整理本",tagLost:"佚",pageInfo:"共 {total} 条 · 每页 {size} 条 · 第 {page} / {pages} 页",pagerLabel:"翻页",prevPage:"上一页",nextPage:"下一页",emptyFiltered:"没有找到匹配的条目。试试更短的书名、减少筛选,或切换繁 / 简。",limitedNote:"各类只列前几条,点上方分类页签看全部。",sortLabel:"排序",sortRelevance:"相关度",sortEra:"年代",sortTitle:"书名",sortEraAsc:"由早到晚",sortEraDesc:"由晚到早",sortTitleAsc:"拼音 A→Z",sortTitleDesc:"拼音 Z→A",onlyWorksNote:"部类、存佚只适用于作品;选了它们,版本、丛编、人物不参与。"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"概览",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录",fullText:"全文",lineage:"版本传承",feedback:"勘误反馈",dataSource:"数据源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"数据源与授权"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},workSubtype:{book:"书",article:"篇",poem:"诗",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},ga=["曹霑"];function ha(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ba(e,n=ga){const o=[...new Set(n.filter(Boolean))].sort((l,c)=>c.length-l.length);if(!o.length)return e;const r=new RegExp(`(${o.map(ha).join("|")})`,"g"),s=new Set(o);return l=>{if(!l)return e(l);const c=l.split(r);return c.length===1?e(l):c.map((p,a)=>a%2===1&&s.has(p)?p:p&&e(p)).join("")}}let Ft=null;function ya(){if(Ft)return Ft;try{Ft=ba(sa.Converter({from:"tw",to:"cn"}))}catch{Ft=e=>e}return Ft}const ja={"zh-Hant":Vr,"zh-Hans":ma},Yr="bim-locale";function va(){try{const e=localStorage.getItem(Yr);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function ka(e){try{localStorage.setItem(Yr,e)}catch{}}const wa="zh-Hans",Sa=({locale:e,onLocaleChange:n,converter:o,children:r})=>{const[s,l]=f.useState(e??wa),c=e??s;f.useEffect(()=>{if(e)return;const u=va();u&&u!==s&&l(u)},[]);const p=f.useMemo(()=>c==="zh-Hans"?o??ya():null,[c,o]),a=f.useCallback(u=>{l(u),ka(u),n==null||n(u)},[n]),d=f.useMemo(()=>({locale:c,setLocale:a,messages:ja[c],converter:p}),[c,a,p]);return t.jsx(Lt.Provider,{value:d,children:r})};function me(){const e=f.useContext(Lt);return(e==null?void 0:e.messages)??Vr}const $a=2e3;function V(){const e=f.useContext(Lt),n=(e==null?void 0:e.locale)??"zh-Hant",o=(e==null?void 0:e.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const l=f.useCallback(c=>{if(!c)return"";if(!o)return c;const p=r.current.get(c);if(p!==void 0)return p;const a=o(c);if(r.current.size>=$a){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(c,a),a},[o]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Qe(e,n){return e.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function _a(e){if(!e)return"";try{const n=new URL(e).hostname,o={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function za(){return{id:"",name:"",url:"",type:"text",details:""}}const ni=({items:e,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const l=me(),[c,p]=f.useState(null),a=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],d=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=h=>{if(!s)return!0;const v=vt(h);return s==="text"?v.includes("text"):s==="image"?v.includes("image")||v.includes("physical"):s==="physical"?v.includes("physical"):v.includes(s)},m=e.map((h,v)=>({item:h,originalIndex:v})).filter(({item:h})=>u(h)),x=()=>{const h=za();s&&(h.type=s),n([...e,h]),p(e.length)},g=h=>{n(e.filter((v,$)=>$!==h)),p(null)},b=(h,v,$)=>{const k=[...e];if(k[h]={...k[h],[v]:$},v==="url"&&!k[h].id){const _=_a($);_&&(k[h].id=_)}n(k)},w=(h,v,$)=>{const _={...e[h].metadata||{}};$?_[v]=$:delete _[v],b(h,"metadata",Object.keys(_).length>0?_:void 0)},y=(h,v)=>{const $=v.trim()?v.split(/[,,、]/).map(k=>k.trim()).filter(Boolean):void 0;b(h,"structure",$)},j=(h,v,$)=>{const _=e[h].coverage||{level:1,ranges:""};v==="level"?_.level=parseInt($)||1:_.ranges=$,b(h,"coverage",_.ranges?_:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[m.map(({item:h,originalIndex:v})=>{var $,k,_;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(c===v?null:v),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:c===v?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Ca(h.type??"text"),color:i("on-color-fg")},children:(()=>{var z,N;const S=vt(h);return S.length===0?h.type??"text":S.length===1?((z=a.find(R=>R.value===S[0]))==null?void 0:z.label)??S[0]:S.includes("text")&&S.includes("image")?((N=a.find(R=>R.value==="text+image"))==null?void 0:N.label)??"text+image":S.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:h.name||`${l.editor.resourcePlaceholder} ${v+1}`}),h.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:h.id}),h.url&&t.jsx("a",{href:h.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&h.url&&Ta(v,r==null?void 0:r[v],o,l),t.jsx("button",{onClick:S=>{S.stopPropagation(),g(v)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),c===v&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:[xa(h,"image")&&h.url&&Ia(h,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Pt,children:[t.jsx("span",{style:Ot,children:l.label.type}),t.jsx("select",{value:h.type,onChange:S=>b(v,"type",S.target.value),style:{...ot,flex:1},children:a.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]}),t.jsxs("label",{style:Pt,children:[t.jsx("span",{style:Ot,children:l.label.rootType}),t.jsx("select",{value:h.root_type||"catalog",onChange:S=>b(v,"root_type",S.target.value),style:{...ot,flex:1},children:d.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:h.id,onChange:S=>b(v,"id",S.target.value),placeholder:l.editor.idAutoExtract,style:{...ot,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:h.name,onChange:S=>b(v,"name",S.target.value),placeholder:l.editor.resourceName,style:{...ot,flex:1}})]}),t.jsx("input",{type:"text",value:h.url,onChange:S=>b(v,"url",S.target.value),placeholder:l.editor.resourceUrl,style:ot}),t.jsx("input",{type:"text",value:(($=h.structure)==null?void 0:$.join("、"))||"",onChange:S=>y(v,S.target.value),placeholder:l.editor.structurePlaceholder,style:ot}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Pt,children:[t.jsx("span",{style:Ot,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((k=h.coverage)==null?void 0:k.level)??"",onChange:S=>j(v,"level",S.target.value),placeholder:"1",style:{...ot,width:"60px"}})]}),t.jsxs("label",{style:{...Pt,flex:1},children:[t.jsx("span",{style:Ot,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:((_=h.coverage)==null?void 0:_.ranges)||"",onChange:S=>j(v,"ranges",S.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...ot,flex:1}})]})]}),t.jsx("textarea",{value:h.details||"",onChange:S=>b(v,"details",S.target.value),placeholder:l.editor.detailsPlaceholder,style:{...ot,minHeight:"60px",resize:"vertical"}}),t.jsxs("div",{style:{borderTop:`1px solid ${i("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"6px"},children:l.label.metadata}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([S,z])=>{var N;return t.jsxs("label",{style:{...Pt,gap:"4px"},children:[t.jsx("span",{style:{...Ot,minWidth:"56px"},children:z}),t.jsx("input",{type:"text",value:((N=h.metadata)==null?void 0:N[S])||"",onChange:R=>w(v,S,R.target.value),placeholder:z,style:{...ot,flex:1}})]},S)})})]})]})]})]},v)}),t.jsxs("button",{onClick:x,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:l.action.addResource})]})]})};function Ca(e){switch(e){case"text":return i("restype-text");case"image":return i("restype-image");case"text+image":return i("restype-text-image");case"physical":return i("restype-physical")}}function Ta(e,n,o,r){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:c=>{c.stopPropagation(),s||o(e,"")},disabled:s,style:{background:"transparent",border:"none",color:i(l?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:l?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":s?"⏳":"⬇"})}function Ia(e,n){const o=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(e.url)||e.url.includes("iiif")||e.url.includes("image");return t.jsx("div",{style:{marginBottom:"12px"},children:o?t.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:i("overlay-bg")},children:t.jsx("img",{src:e.url,alt:e.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):t.jsx("div",{style:{padding:"12px",background:i("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:i("desc-fg")},children:n.editor.imageResourceLink})})}const ot={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Pt={display:"flex",alignItems:"center",gap:"6px"},Ot={fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap"},Ea={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive","www.shuge.org":"書格","shuge.org":"書格","pan.baidu.com":"百度網盤"};function Bt(e){try{return Ea[new URL(e).hostname]}catch{return}}const _o={text:0,image:1,physical:2};function Si(e){return e.length===0?"physical":[...e].sort((n,o)=>(_o[n]??99)-(_o[o]??99)).join("+")}function $i(e){var c;const n=p=>{const a=p.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const d=p.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},o=new Map;for(let p=0;p<e.length;p++){const a=e[p];if(a.volumes&&a.volumes.length>0)continue;const d=n(a.name);if(!d)continue;const[u,m]=d,x=`${u}|${Si(vt(a))}`;o.has(x)||o.set(x,{base:{...a,name:u,url:"",volumes:[]},volumes:[],indices:[]});const g=o.get(x);g.volumes.push({volume:m,url:a.url||void 0,status:"found"}),g.indices.push(p)}const r=[],s=new Set;for(const p of o.values())if(!(p.volumes.length<2)){p.volumes.sort((a,d)=>a.volume-d.volume),p.base.volumes=p.volumes,p.base.expected_volumes=p.volumes.length,p.base.url||(p.base.url=((c=p.volumes.find(a=>a.url))==null?void 0:c.url)??""),r.push(p.base);for(const a of p.indices)s.add(a)}const l=[...r];for(let p=0;p<e.length;p++)s.has(p)||l.push(e[p]);return l}function Kr(e){if(e.url)return e.url;for(const[n,o]of Object.entries(e))if(n.endsWith("_url")&&typeof o=="string")return o}function qr(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||Kr(n)}))}function Sn(e){const n=qr(e);if(!n)return null;const o=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,r=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:o,missing:r,expected:e.expected_volumes??o+r}}function _i(e){if(!e)return;const n=e.file_page_range||e.page_range;if(!n||typeof n!="string")return;const o=n.match(/^(\d+)/);return o?parseInt(o[1],10):void 0}function zi(e,n){try{if(new URL(e).hostname.includes("wikimedia.org")){const r=e.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const s=new URL(e);return s.searchParams.set("page",String(n)),s.toString()}return e}catch{return e}}function At(e){if(!e.url)return;const n=_i(e.metadata);return n?zi(e.url,n):e.url}const zo={text:i("restype-text"),image:i("restype-image"),"text+image":i("restype-text-image"),physical:i("restype-physical")};function Ra(e){return e.includes("text")&&e.includes("image")?zo["text+image"]:zo[e[0]||"physical"]}const Ci=({items:e,groupByType:n=!0,resourceGroups:o,onNavigate:r,renderLink:s})=>{const l=me(),{convert:c}=V(),p=f.useMemo(()=>$i(e||[]),[e]),{mirrorGroups:a,ungroupedItems:d}=f.useMemo(()=>{const y=new Map,j=[];for(const h of p){const v=h.group;v?(y.has(v)||y.set(v,[]),y.get(v).push(h)):j.push(h)}for(const h of y.values())h.sort((v,$)=>{const k=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return k(v)-k($)});return{mirrorGroups:y,ungroupedItems:j}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},m=y=>u[y]?u[y]:y.split("+").map(j=>u[j]||j).join("+");if(!p||p.length===0)return t.jsx("div",{style:{padding:"16px",color:i("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((y,j)=>t.jsx(On,{item:y},y.id||j))});const x=(y,j)=>{const h=o==null?void 0:o[y],v=(h==null?void 0:h.label)||y,$=h==null?void 0:h.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:c(v)}),$&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.5},children:c($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((k,_)=>t.jsx(On,{item:k,onNavigate:r,renderLink:s},k.id||_))})]},`group-${y}`)},g=new Map;for(const y of d){const j=Si(vt(y));g.has(j)||g.set(j,[]),g.get(j).push(y)}const b=["text","image","text+image","physical"],w=[...b.filter(y=>g.has(y)),...[...g.keys()].filter(y=>!b.includes(y)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([y,j])=>x(y,j)),w.map(y=>{const j=g.get(y),h=Ra(y.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:h,whiteSpace:"nowrap",flexShrink:0},children:m(y)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((v,$)=>t.jsx(On,{item:v,onNavigate:r,renderLink:s},v.id||$))})]},y)})]})},Na={bw:{label:"",bg:i("colormode-bw-bg"),fg:i("colormode-bw-fg")},color:{label:"",bg:i("colormode-color-bg"),fg:i("colormode-color-fg")}},On=({item:e})=>{const n=me(),{convert:o}=V(),[r,s]=f.useState(!1),l=f.useMemo(()=>(e.url?Bt(e.url):void 0)||o(e.name),[e.url,e.name,o]),c=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(b=>({...b,url:b.url||Kr(b)})),[e.volumes]),p=c&&c.length>0,a=p?new Set(c.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=p?new Set(c.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=e.expected_volumes??(p?a+d:0),m=e.color_mode?{...Na[e.color_mode],label:n.colorMode[e.color_mode]}:null,x=e.details&&!p?o(e.details):null,g={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",background:i("input-bg"),fontSize:"12px",color:i("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:g,children:[t.jsx("span",{style:{fontWeight:500},children:l}),m&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:m.bg,color:m.fg},children:m.label}),x&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:x}),p&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[a,"/",u,n.unit.volume,d>0&&t.jsxs("span",{style:{color:i("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),e.url&&t.jsx("a",{href:(()=>{const b=_i(e.metadata);return b?zi(e.url,b):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:i("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),p&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),p&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:c.map(b=>{const w=b.status==="missing";return b.url&&!w?t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${i("widget-border")}`,color:i("link-fg"),textDecoration:"none"},children:b.volume},b.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:i(w?"missing-fg":"desc-fg"),textDecoration:w?"line-through":"none",opacity:w?.6:1},children:b.volume},b.volume)})})]})},Jr=({indexSource:e,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:c})=>{const p=me(),a=e==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",m=u?u.split(/[/\\]/).pop()||u:"",x={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:i("primary-soft"),color:i("primary")},g={onMouseOver:w=>w.currentTarget.style.opacity="0.8",onMouseOut:w=>w.currentTarget.style.opacity="1"},b=t.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...x,background:i(d?"warning":"success"),color:i("on-color-fg")},...g,children:[t.jsx("span",{children:d?"📝":"📚"}),t.jsx("span",{children:d?"draft":"official"})]});return o==="index-browser"?a?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,t.jsxs("div",{onClick:r,title:p.mode.switchToSync,style:x,...g,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:p.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:c,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px"},...g,children:[t.jsx("span",{children:"📂"}),m&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:m})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:p.mode.switchToLocal,style:x,...g,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:p.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:m||p.mode.configurePath,style:{...x,background:"transparent",padding:"6px",fontSize:"12px"},...g,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:a?p.mode.switchToGithub:p.mode.switchToLocal,style:x,...g,children:[t.jsx("span",{children:a?"📁":"🌐"}),t.jsx("span",{children:a?p.mode.localMode:p.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&t.jsxs("div",{onClick:c,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...g,children:[t.jsx("span",{children:"📂"}),m&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:m})]}),!a&&m&&t.jsxs("div",{style:{...x,background:i("mode-active-bg"),color:i("on-color-fg"),cursor:"default"},title:u,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:m})]})]})},$n="bim-search-history",Co=10,To=8;function qt(){try{const e=localStorage.getItem($n);return e?JSON.parse(e):[]}catch{return[]}}function La(e){try{const n=qt().filter(o=>o!==e);n.unshift(e),n.length>Co&&(n.length=Co),localStorage.setItem($n,JSON.stringify(n))}catch{}}function Ba(e){try{const n=qt().filter(o=>o!==e);localStorage.setItem($n,JSON.stringify(n))}catch{}}function Aa(){try{localStorage.removeItem($n)}catch{}}const Zr=({transport:e,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:l})=>{const c=me(),p=l??c.search.placeholder,a={work:c.indexType.work,book:c.indexType.book,collection:c.indexType.collection,entity:c.indexType.entity},[d,u]=f.useState(!1),[m,x]=f.useState([]),[g,b]=f.useState(-1),[w,y]=f.useState(qt),j=f.useRef(null),h=f.useRef(null),v=f.useRef(null),$=f.useRef(!1);f.useEffect(()=>{b(-1);const C=n.trim();if(!C){x(w.map(M=>({type:"history",text:M})));return}if(!e.searchAll){x([]);return}let H=!1;const L=setTimeout(()=>{e.searchAll(C,To).then(M=>{if(H)return;const F=[...M.works,...M.books,...M.collections,...M.entities??[]];x(F.slice(0,To).map(X=>({type:"entry",text:X.title||X.id,entry:X})))}).catch(()=>{H||x([])})},80);return()=>{H=!0,clearTimeout(L)}},[n,w,e]),f.useEffect(()=>{const C=H=>{v.current&&!v.current.contains(H.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=H=>{var L,M;if(H.key==="/"&&document.activeElement!==j.current){const F=(L=document.activeElement)==null?void 0:L.tagName;if(F==="INPUT"||F==="TEXTAREA"||F==="SELECT")return;H.preventDefault(),(M=j.current)==null||M.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const k=f.useCallback(C=>{C.trim()&&(La(C.trim()),y(qt())),r(C),u(!1)},[r]),_=f.useCallback(C=>{C.type==="history"?(o(C.text),k(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(o(C.text),k(C.text)))},[o,k,s]),S=f.useCallback(C=>{if(!d||m.length===0){C.key==="Enter"&&k(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(H=>(H+1)%m.length);break;case"ArrowUp":C.preventDefault(),b(H=>(H-1+m.length)%m.length);break;case"Enter":C.preventDefault(),g>=0&&g<m.length?_(m[g]):k(n);break;case"Escape":C.preventDefault(),u(!1);break}},[d,m,g,n,k,_]),z=f.useCallback((C,H)=>{H.stopPropagation(),Ba(C),y(qt()),x(L=>L.filter(M=>!(M.type==="history"&&M.text===C)))},[]),N=f.useCallback(C=>{C.stopPropagation(),Aa(),y([]),x([])},[]);f.useEffect(()=>{if(g>=0&&h.current){const C=h.current.children;C[g]&&C[g].scrollIntoView({block:"nearest"})}},[g]);const R=!n.trim()&&w.length>0;return t.jsxs("div",{ref:v,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:j,type:"text",placeholder:p,value:n,onChange:C=>{o(C.target.value),u(!0)},onCompositionStart:()=>{$.current=!0},onCompositionEnd:()=>{$.current=!1},onFocus:()=>{u(!0)},onKeyDown:S,style:{width:"100%",padding:"8px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),d&&m.length>0&&t.jsxs("div",{ref:h,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:i("input-bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"6px",boxShadow:i("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[R&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:i("desc-fg"),borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("span",{children:c.search.history}),t.jsx("button",{onClick:N,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:c.search.clearAll})]}),m.map((C,H)=>t.jsxs("div",{onClick:()=>_(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:i("fg"),background:H===g?i("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:[a[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&t.jsx("button",{onClick:L=>z(C.text,L),style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:c.action.remove,children:"×"})]},`${C.type}-${C.text}-${H}`))]})]})},Wt=({type:e,size:n=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:n,borderRadius:1,flex:"none",background:i(`type-${e}`),verticalAlign:"middle"}}),_n={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},Xr=new Set(["work","book","entity"]);function Wa(e){return es(e)||!!e.sort}function Ma(e,n){return n.sort&&Xr.has(e)?n.sort:void 0}const zn=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Cn=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Ti=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],Qr={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function Tn(e){return e.dynasty.length+e.classification.length+(e.hasImage?1:0)+(e.hasText?1:0)+(e.hasCollated?1:0)+(e.loss?1:0)}function es(e){return Tn(e)>0}function Fa(e){const n=[];return e.dynasty.length&&n.push("dynasty"),e.classification.length&&n.push("classification"),e.hasImage&&n.push("hasImage"),e.hasText&&n.push("hasText"),e.hasCollated&&n.push("hasCollated"),e.loss&&n.push("loss"),n}function ts(e,n){const o=Qr[e];return Fa(n).every(r=>o.has(r))}const Dt=e=>JSON.stringify(e);function Pa(e,n){if(!ts(n,e))return null;const o=[];if(e.dynasty.length){const r=Array.from(new Set(e.dynasty.flatMap(s=>{var l;return((l=zn.find(c=>c.key===s))==null?void 0:l.values)??[]})));r.length===1?o.push(`dynasty = ${Dt(r[0])}`):r.length>1&&o.push(`dynasty IN [${r.map(Dt).join(", ")}]`)}return e.classification.length&&o.push(e.classification.length===1?`classification = ${Dt(e.classification[0])}`:`classification IN [${e.classification.map(Dt).join(", ")}]`),e.hasImage&&o.push("has_image = true"),e.hasText&&o.push("has_text = true"),e.hasCollated&&o.push("has_collated = true"),e.loss&&o.push(`loss_status = ${Dt(e.loss)}`),o.join(" AND ")}const Ge={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},ns="_";function yn(e,n=new URLSearchParams){for(const o of Object.values(Ge))n.delete(o);return e.dynasty.length&&n.set(Ge.dynasty,e.dynasty.join(",")),e.classification.length&&n.set(Ge.classification,e.classification.map(o=>o||ns).join(",")),e.hasImage&&n.set(Ge.hasImage,"1"),e.hasText&&n.set(Ge.hasText,"1"),e.hasCollated&&n.set(Ge.hasCollated,"1"),e.loss&&n.set(Ge.loss,e.loss),e.sort&&n.set(Ge.sort,e.sort),n}function Oa(e){const n=l=>(e.get(l)??"").split(",").map(c=>c.trim()).filter(Boolean),o=new Set(zn.map(l=>l.key)),r=new Set(Cn.map(l=>l.value)),s=e.get(Ge.loss);return{dynasty:Array.from(new Set(n(Ge.dynasty).filter(l=>o.has(l)))),classification:Array.from(new Set(n(Ge.classification).map(l=>l===ns?"":l).filter(l=>r.has(l)))),hasImage:e.get(Ge.hasImage)==="1",hasText:e.get(Ge.hasText)==="1",hasCollated:e.get(Ge.hasCollated)==="1",loss:s==="extant"||s==="partially_extant"||s==="lost"?s:"",sort:["era:asc","era:desc","title:asc","title:desc"].find(l=>l===e.get(Ge.sort))??""}}function Da(e,n){return JSON.stringify([e.dynasty.slice().sort(),e.classification.slice().sort(),e.hasImage,e.hasText,e.hasCollated,e.loss,e.sort])===JSON.stringify([n.dynasty.slice().sort(),n.classification.slice().sort(),n.hasImage,n.hasText,n.hasCollated,n.loss,n.sort])}function Io(e,n){return e.includes(n)?e.filter(o=>o!==n):[...e,n]}const Ha=({filters:e,onChange:n})=>{const o=me().searchV4,{convert:r}=V(),[s,l]=f.useState(!1),c=f.useId(),p=Tn(e),a=d=>n({...e,...d});return t.jsxs("aside",{className:"bim-sr-aside","aria-label":r(o.filterTitle),children:[t.jsxs("button",{type:"button",className:"bim-sr-fbtn","aria-expanded":s,"aria-controls":c,onClick:()=>l(d=>!d),children:[t.jsxs("span",{children:[r(o.filterButton),p>0&&t.jsx("span",{className:"bim-sr-fn",children:r(Qe(o.filterSelected,{n:p}))})]}),t.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[r(s?o.collapse:o.expand)," ",s?"▴":"▾"]})]}),t.jsxs("div",{className:"bim-sr-filters",id:c,"data-open":s?"true":"false",...s?{}:{"data-collapsed":"true"},children:[t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:r(o.dynasty)}),t.jsx("div",{className:"bim-sr-chips",children:zn.map(d=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(d.key),onClick:()=>a({dynasty:Io(e.dynasty,d.key)}),children:r(d.key)},d.key))})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:r(o.classification)}),Cn.map(d=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(d.value),onChange:()=>a({classification:Io(e.classification,d.value)})}),r(d.label)]},d.value||"_"))]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:r(o.resources)}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasImage,onChange:d=>a({hasImage:d.target.checked})}),r(o.hasImage)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasText,onChange:d=>a({hasText:d.target.checked})}),r(o.hasText)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasCollated,onChange:d=>a({hasCollated:d.target.checked})}),r(o.hasCollated)]})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{id:`${c}-loss`,children:r(o.extant)}),t.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${c}-loss`,children:Ti.map(d=>t.jsx("button",{type:"button","aria-pressed":e.loss===d.value,onClick:()=>a({loss:d.value}),children:r(d.label)},d.value||"all"))})]}),t.jsx("p",{className:"bim-sr-note",children:r(o.onlyWorksNote)}),p>0&&t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>n({..._n,sort:e.sort}),children:r(o.clearAllFilters)})]})]})};function is({text:e,query:n}){const o=(n??"").trim();if(!o||!e)return t.jsx(t.Fragment,{children:e});const r=e.toLowerCase(),s=o.toLowerCase(),l=[];let c=0,p=0;for(;c<e.length;){const a=r.indexOf(s,c);if(a<0){l.push(e.slice(c));break}a>c&&l.push(e.slice(c,a)),l.push(t.jsx("mark",{className:"bim-sr-hl",children:e.slice(a,a+s.length)},p++)),c=a+s.length}return t.jsx(t.Fragment,{children:l})}const Eo=({entries:e,query:n,onEntryLinkClick:o,typeName:r})=>{const s=me(),l=s.searchV4,{convert:c}=V(),p=Fe();return t.jsx("div",{className:"bim-sr-tablewrap",children:t.jsxs("table",{className:"bim-sr-table",children:[t.jsxs("colgroup",{children:[t.jsx("col",{style:{width:"34%"}}),t.jsx("col",{style:{width:"8%"}}),t.jsx("col",{style:{width:"19%"}}),t.jsx("col",{style:{width:"13%"}}),t.jsx("col",{style:{width:"12%"}}),t.jsx("col",{style:{width:"14%"}})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:c(l.colTitle)}),t.jsx("th",{scope:"col",children:c(l.colType)}),t.jsx("th",{scope:"col",children:c(l.colAuthor)}),t.jsx("th",{scope:"col",children:c(l.colEra)}),t.jsx("th",{scope:"col",children:c(l.colClass)}),t.jsx("th",{scope:"col",style:{textAlign:"right"},children:c(l.colResource)})]})}),t.jsx("tbody",{children:e.map(a=>{const d=c(a.title||a.primary_name||a.id),u=a.measure_info?c(a.measure_info):a.juan_count?`${a.juan_count}${s.unit.juan}`:"",m=a.type==="entity"?[a.birth_year!=null||a.death_year!=null?`${a.birth_year??"?"}—${a.death_year??"?"}`:""].filter(Boolean).join(""):a.author?`${c(a.author)}${a.role&&a.role!=="author"?` ${c(a.role)}`:""}`:"",x=a.type==="book"?a.era??a.dynasty:a.dynasty,g=x?c(x):"",b=a.classification?c(a.classification):"",w=[];a.has_image&&w.push({label:l.tagImage,cls:"bim-sr-tag--img"}),a.has_text&&w.push({label:l.tagText,cls:""}),a.has_collated&&w.push({label:l.tagCollated,cls:""}),a.loss_status==="lost"&&w.push({label:l.tagLost,cls:"bim-sr-tag--lost"});const y=[m,g,b].filter(Boolean).join(" · ");return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-sr-c-title",children:[t.jsxs("div",{className:"bim-sr-tl",children:[t.jsx("a",{href:p(a.id),onClick:j=>o(a,j),children:t.jsx(is,{text:d,query:n?c(n):void 0})}),u&&t.jsx("span",{className:"bim-sr-measure",children:u})]}),y&&t.jsx("span",{className:"bim-sr-sub",children:y})]}),t.jsxs("td",{className:"bim-sr-c-type",children:[t.jsx(Wt,{type:a.type,size:6})," ",r(a.type)]}),t.jsx("td",{className:"bim-sr-c-who",children:m||"—"}),t.jsx("td",{className:"bim-sr-c-era",children:g||"—"}),t.jsx("td",{className:"bim-sr-c-cls",children:b||"—"}),t.jsx("td",{className:"bim-sr-c-res",children:w.map(j=>t.jsx("span",{className:`bim-sr-tag ${j.cls}`,children:c(j.label)},j.label))})]},a.id)})})]})})},Ga=`
|
|
1
|
+
"use strict";var ca=Object.create;var Io=Object.defineProperty;var da=Object.getOwnPropertyDescriptor;var pa=Object.getOwnPropertyNames;var ua=Object.getPrototypeOf,xa=Object.prototype.hasOwnProperty;var fa=(e,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of pa(n))!xa.call(e,s)&&s!==o&&Io(e,s,{get:()=>n[s],enumerable:!(r=da(n,s))||r.enumerable});return e};var gn=(e,n,o)=>(o=e!=null?ca(ua(e)):{},fa(n||!e||!e.__esModule?Io(o,"default",{value:e,enumerable:!0}):o,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const je=require("./storage-entry-DGtRxALe.cjs"),t=require("react/jsx-runtime"),x=require("react"),ma=require("opencc-js/t2cn"),ga=require("react-markdown"),ha=require("remark-gfm"),ba=e=>`/book-index?id=${e}`,qr=x.createContext(ba);function ya({buildUrl:e,children:n}){const o=x.useMemo(()=>e,[e]);return t.jsx(qr.Provider,{value:o,children:n})}function Fe(){return x.useContext(qr)}const Jr="",Zr="";function Ii(e){const n=[];let o=!1,r=e;for(;r.length;){const s=o?Zr:Jr,l=r.indexOf(s);if(l===-1){n.push({text:r,marked:o});break}l>0&&n.push({text:r.slice(0,l),marked:o}),r=r.slice(l+1),o=!o}return n}function Ke(e,n){return{title:e,tokens:n}}const Eo='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',ja=[Ke("基础(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"}}),Ke("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),Ke("提示与警告",{"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)"}}),Ke("遮罩与阴影",{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)"}}),Ke("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),Ke("资源",{"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"}}),Ke("整理本(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"}}),Ke("版本传承(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"}}),Ke("编辑器视图(主要在 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")'}}),Ke("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --bim-primary 等控件色",{"page-bg":{value:"#fbf9f3",note:"纸"},"row-hover-bg":{value:"#f5f1e5"},"selection-bg":{value:"#ecdcbc",note:"选区"},"band-bg":{value:"#f0e4cb",note:"全文入口横幅(暖沙)"},"band-bg-hover":{value:"#e6d5b4"},ink:{value:"#2a231c",note:"文字层次:墨 → 正文 → 提要 → meta → 标签 → 提示"},"body-fg":{value:"#3b3228"},"quiet-fg":{value:"#5b4f40"},"meta-fg":{value:"#7b6a54"},"label-fg":{value:"#6f6457",note:"标签 / 提示:2026-09 N3a 调深,纸底与斑马底上对比度均 ≥4.5(原 #a3937b 2.8、#b3a385 2.3)"},"hint-fg":{value:"#756a5e"},accent:{value:"#9c3a2c",note:"朱"},"accent-deep":{value:"#6f2a20",note:"链接 hover"},"rule-strong":{value:"#2a231c",note:"分隔线:强 → 常规 → 虚线 → 提要左线"},rule:{value:"#e4dbc9"},"rule-dashed":{value:"#d6c9ae"},"rule-accent-soft":{value:"#e0d3b6"},"aux-fg":{value:"#6f6457",note:"辅助字(元数据、注记、「·」分隔的浅色小字)。须在 page-bg / zebra-bg 上对比度 ≥4.5(Q5 巡检)"},"card-bg":{value:"#fffdf9",note:"提要卡:抬起的面"},"zebra-bg":{value:"#f6f2eb",note:"表格斑马纹 / 左栏分组底(不画格线,靠这一阶底色分行)"},"tint-bg":{value:"#f3eee6",note:"检索框、悬停"},"shadow-summary":{value:"0 10px 32px rgba(60, 50, 40, 0.07)",note:"提要卡投影"},"flag-bg":{value:"rgba(158, 42, 43, 0.08)",note:"唯一的状态色块「有影印」"},"theme-dot-zhusha":{value:"#9c3a2c",note:"主题切换控件的色点:朱砂(不随主题变,两套主题下都要认得出)"},"theme-dot-indigo":{value:"#2e5266",note:"主题切换控件的色点:靛青"},"theme-dot-ink":{value:"#222221",note:"主题切换控件的色点:墨"},"sect-jing":{value:"#2e5266",note:"四部分布条:經部(人物页提要卡;无别处使用)"},"sect-shi":{value:"#9a7a3b",note:"四部分布条:史部"},"sect-zi":{value:"#4f7a5c",note:"四部分布条:子部"},"sect-ji":{value:"#9fb3bc",note:"四部分布条:集部"},"table-border":{value:"color-mix(in srgb, currentColor 28%, transparent)",root:!1,note:"古籍表格(跟随当前文字色)"},"table-head-bg":{value:"color-mix(in srgb, currentColor 8%, transparent)",root:!1}}),Ke('版式(v4 外观系统,overview#291):疏朗=留白分区(默认,下列值即疏朗);界栏=框线分区(`<html data-layout="boxed">`)',{"fr-bd":{value:"0 solid transparent",note:"区块外框(border 简写)。疏朗无框;界栏 1px 实线"},"fr-bg":{value:"transparent",note:"区块底。界栏=卡面色"},"fr-hd-pad":{value:"0",note:"区块标题栏内边距(界栏:标题栏与正文之间有分隔线)"},"fr-hd-bd":{value:"0 solid transparent",note:"区块标题栏下沿线(border 简写)"},"fr-bd-pad":{value:"0",note:"区块正文内边距"},"fr-gap":{value:"56px",note:"区块之间的间距。界栏收紧到 24px(框线本身已分隔)"},"fr-side-gap":{value:"34px",note:"侧栏各块之间的间距;界栏 20px"},"fr-shadow":{value:"0 1px 0 var(--bim-rule), 0 12px 32px -18px rgba(40, 36, 31, 0.25)",note:"抬起的面(提要卡)的投影;界栏不用投影,靠框线"},"fr-tab-bd":{value:"transparent",note:"页签行下沿线颜色(疏朗不画,界栏画)"}}),Ke("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),Ke("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),Ke("字体(全站无衬线,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:Eo,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:Eo,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],va=Object.assign({},...ja.map(e=>e.tokens)),Xr={};for(const[e,n]of Object.entries(va))Xr[e]=`var(--bim-${e}, ${n.value})`;function i(e){const n=Xr[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function _t(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function ka(e,n){return _t(e).includes(n)}const ci={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},wa={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};i("quality-published"),i("quality-fine"),i("quality-rough"),i("quality-ocr");const Ot=x.createContext(null),Qr={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:i("check-fine-bg"),fg:i("check-fine-fg")},粗校:{label:"粗校",bg:i("check-rough-bg"),fg:i("check-rough-fg")},AI整理:{label:"AI整理",bg:i("check-ai-bg"),fg:i("check-ai-fg")}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入叢編",collectedIn:"收入叢編",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評註",studies:"所考典籍"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"結果分類",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},searchV4:{filterTitle:"篩選",dynasty:"朝代",classification:"部類",resources:"資源",extant:"存佚",clearAllFilters:"清除全部篩選",hasImage:"有影印",hasText:"有全文",hasCollated:"有整理本",filterButton:"篩選",filterSelected:"{n} 項已選",expand:"展開",collapse:"收起",filteredCount:"篩出 {n} 條",removeFilter:"取消篩選:{name}",viewLabel:"結果視圖",viewTable:"表格",viewCard:"卡片",colTitle:"題名",colType:"類型",colAuthor:"責任者",colEra:"年代",colClass:"部類",colResource:"資源",tagImage:"影印",tagText:"全文",tagCollated:"整理本",tagLost:"佚",pageInfo:"共 {total} 條 · 每頁 {size} 條 · 第 {page} / {pages} 頁",pagerLabel:"翻頁",prevPage:"上一頁",nextPage:"下一頁",emptyFiltered:"沒有找到匹配的條目。試試更短的書名、減少篩選,或切換繁 / 簡。",limitedNote:"各類只列前幾條,點上方分類頁籤看全部。",sortLabel:"排序",sortRelevance:"相關度",sortEra:"年代",sortTitle:"書名",sortEraAsc:"由早到晚",sortEraDesc:"由晚到早",sortTitleAsc:"拼音 A→Z",sortTitleDesc:"拼音 Z→A",onlyWorksNote:"部類、存佚只適用於作品;選了它們,版本、叢編、人物不參與。"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"概覽",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄",fullText:"全文",lineage:"版本傳承",feedback:"勘誤反饋",dataSource:"數據源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"數據源與授權"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},workSubtype:{book:"書",article:"篇",poem:"詩",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},Sa={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:i("check-fine-bg"),fg:i("check-fine-fg")},粗校:{label:"粗校",bg:i("check-rough-bg"),fg:i("check-rough-fg")},AI整理:{label:"AI整理",bg:i("check-ai-bg"),fg:i("check-ai-fg")}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入丛编",collectedIn:"收入丛编",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评注",studies:"所考典籍"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",allTab:"全部",resultTabs:"结果分类",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},searchV4:{filterTitle:"筛选",dynasty:"朝代",classification:"部类",resources:"资源",extant:"存佚",clearAllFilters:"清除全部筛选",hasImage:"有影印",hasText:"有全文",hasCollated:"有整理本",filterButton:"筛选",filterSelected:"{n} 项已选",expand:"展开",collapse:"收起",filteredCount:"筛出 {n} 条",removeFilter:"取消筛选:{name}",viewLabel:"结果视图",viewTable:"表格",viewCard:"卡片",colTitle:"题名",colType:"类型",colAuthor:"责任者",colEra:"年代",colClass:"部类",colResource:"资源",tagImage:"影印",tagText:"全文",tagCollated:"整理本",tagLost:"佚",pageInfo:"共 {total} 条 · 每页 {size} 条 · 第 {page} / {pages} 页",pagerLabel:"翻页",prevPage:"上一页",nextPage:"下一页",emptyFiltered:"没有找到匹配的条目。试试更短的书名、减少筛选,或切换繁 / 简。",limitedNote:"各类只列前几条,点上方分类页签看全部。",sortLabel:"排序",sortRelevance:"相关度",sortEra:"年代",sortTitle:"书名",sortEraAsc:"由早到晚",sortEraDesc:"由晚到早",sortTitleAsc:"拼音 A→Z",sortTitleDesc:"拼音 Z→A",onlyWorksNote:"部类、存佚只适用于作品;选了它们,版本、丛编、人物不参与。"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"概览",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录",fullText:"全文",lineage:"版本传承",feedback:"勘误反馈",dataSource:"数据源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"数据源与授权"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},workSubtype:{book:"书",article:"篇",poem:"诗",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},$a=["曹霑"];function _a(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ca(e,n=$a){const o=[...new Set(n.filter(Boolean))].sort((l,c)=>c.length-l.length);if(!o.length)return e;const r=new RegExp(`(${o.map(_a).join("|")})`,"g"),s=new Set(o);return l=>{if(!l)return e(l);const c=l.split(r);return c.length===1?e(l):c.map((p,a)=>a%2===1&&s.has(p)?p:p&&e(p)).join("")}}let Ut=null;function za(){if(Ut)return Ut;try{Ut=Ca(ma.Converter({from:"tw",to:"cn"}))}catch{Ut=e=>e}return Ut}const Ta={"zh-Hant":Qr,"zh-Hans":Sa},es="bim-locale";function Ia(){try{const e=localStorage.getItem(es);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Ea(e){try{localStorage.setItem(es,e)}catch{}}const Ra="zh-Hans",Na=({locale:e,onLocaleChange:n,converter:o,children:r})=>{const[s,l]=x.useState(e??Ra),c=e??s;x.useEffect(()=>{if(e)return;const u=Ia();u&&u!==s&&l(u)},[]);const p=x.useMemo(()=>c==="zh-Hans"?o??za():null,[c,o]),a=x.useCallback(u=>{l(u),Ea(u),n==null||n(u)},[n]),d=x.useMemo(()=>({locale:c,setLocale:a,messages:Ta[c],converter:p}),[c,a,p]);return t.jsx(Ot.Provider,{value:d,children:r})};function ge(){const e=x.useContext(Ot);return(e==null?void 0:e.messages)??Qr}const La=2e3;function X(){const e=x.useContext(Ot),n=(e==null?void 0:e.locale)??"zh-Hant",o=(e==null?void 0:e.converter)??null,r=x.useRef(new Map),s=x.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const l=x.useCallback(c=>{if(!c)return"";if(!o)return c;const p=r.current.get(c);if(p!==void 0)return p;const a=o(c);if(r.current.size>=La){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(c,a),a},[o]);return x.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function it(e,n){return e.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function Aa(e){if(!e)return"";try{const n=new URL(e).hostname,o={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function Ba(){return{id:"",name:"",url:"",type:"text",details:""}}const di=({items:e,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const l=ge(),[c,p]=x.useState(null),a=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],d=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=h=>{if(!s)return!0;const v=_t(h);return s==="text"?v.includes("text"):s==="image"?v.includes("image")||v.includes("physical"):s==="physical"?v.includes("physical"):v.includes(s)},m=e.map((h,v)=>({item:h,originalIndex:v})).filter(({item:h})=>u(h)),f=()=>{const h=Ba();s&&(h.type=s),n([...e,h]),p(e.length)},g=h=>{n(e.filter((v,_)=>_!==h)),p(null)},b=(h,v,_)=>{const k=[...e];if(k[h]={...k[h],[v]:_},v==="url"&&!k[h].id){const $=Aa(_);$&&(k[h].id=$)}n(k)},w=(h,v,_)=>{const $={...e[h].metadata||{}};_?$[v]=_:delete $[v],b(h,"metadata",Object.keys($).length>0?$:void 0)},y=(h,v)=>{const _=v.trim()?v.split(/[,,、]/).map(k=>k.trim()).filter(Boolean):void 0;b(h,"structure",_)},j=(h,v,_)=>{const $=e[h].coverage||{level:1,ranges:""};v==="level"?$.level=parseInt(_)||1:$.ranges=_,b(h,"coverage",$.ranges?$:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[m.map(({item:h,originalIndex:v})=>{var _,k,$;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(c===v?null:v),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:c===v?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Ma(h.type??"text"),color:i("on-color-fg")},children:(()=>{var C,L;const S=_t(h);return S.length===0?h.type??"text":S.length===1?((C=a.find(I=>I.value===S[0]))==null?void 0:C.label)??S[0]:S.includes("text")&&S.includes("image")?((L=a.find(I=>I.value==="text+image"))==null?void 0:L.label)??"text+image":S.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:h.name||`${l.editor.resourcePlaceholder} ${v+1}`}),h.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:h.id}),h.url&&t.jsx("a",{href:h.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&h.url&&Wa(v,r==null?void 0:r[v],o,l),t.jsx("button",{onClick:S=>{S.stopPropagation(),g(v)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),c===v&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:[ka(h,"image")&&h.url&&Fa(h,l),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Yt,children:[t.jsx("span",{style:Kt,children:l.label.type}),t.jsx("select",{value:h.type,onChange:S=>b(v,"type",S.target.value),style:{...lt,flex:1},children:a.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]}),t.jsxs("label",{style:Yt,children:[t.jsx("span",{style:Kt,children:l.label.rootType}),t.jsx("select",{value:h.root_type||"catalog",onChange:S=>b(v,"root_type",S.target.value),style:{...lt,flex:1},children:d.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:h.id,onChange:S=>b(v,"id",S.target.value),placeholder:l.editor.idAutoExtract,style:{...lt,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:h.name,onChange:S=>b(v,"name",S.target.value),placeholder:l.editor.resourceName,style:{...lt,flex:1}})]}),t.jsx("input",{type:"text",value:h.url,onChange:S=>b(v,"url",S.target.value),placeholder:l.editor.resourceUrl,style:lt}),t.jsx("input",{type:"text",value:((_=h.structure)==null?void 0:_.join("、"))||"",onChange:S=>y(v,S.target.value),placeholder:l.editor.structurePlaceholder,style:lt}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Yt,children:[t.jsx("span",{style:Kt,children:l.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((k=h.coverage)==null?void 0:k.level)??"",onChange:S=>j(v,"level",S.target.value),placeholder:"1",style:{...lt,width:"60px"}})]}),t.jsxs("label",{style:{...Yt,flex:1},children:[t.jsx("span",{style:Kt,children:l.label.coverageRange}),t.jsx("input",{type:"text",value:(($=h.coverage)==null?void 0:$.ranges)||"",onChange:S=>j(v,"ranges",S.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...lt,flex:1}})]})]}),t.jsx("textarea",{value:h.details||"",onChange:S=>b(v,"details",S.target.value),placeholder:l.editor.detailsPlaceholder,style:{...lt,minHeight:"60px",resize:"vertical"}}),t.jsxs("div",{style:{borderTop:`1px solid ${i("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"6px"},children:l.label.metadata}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([S,C])=>{var L;return t.jsxs("label",{style:{...Yt,gap:"4px"},children:[t.jsx("span",{style:{...Kt,minWidth:"56px"},children:C}),t.jsx("input",{type:"text",value:((L=h.metadata)==null?void 0:L[S])||"",onChange:I=>w(v,S,I.target.value),placeholder:C,style:{...lt,flex:1}})]},S)})})]})]})]})]},v)}),t.jsxs("button",{onClick:f,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:l.action.addResource})]})]})};function Ma(e){switch(e){case"text":return i("restype-text");case"image":return i("restype-image");case"text+image":return i("restype-text-image");case"physical":return i("restype-physical")}}function Wa(e,n,o,r){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:c=>{c.stopPropagation(),s||o(e,"")},disabled:s,style:{background:"transparent",border:"none",color:i(l?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:l?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":s?"⏳":"⬇"})}function Fa(e,n){const o=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(e.url)||e.url.includes("iiif")||e.url.includes("image");return t.jsx("div",{style:{marginBottom:"12px"},children:o?t.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:i("overlay-bg")},children:t.jsx("img",{src:e.url,alt:e.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):t.jsx("div",{style:{padding:"12px",background:i("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:i("desc-fg")},children:n.editor.imageResourceLink})})}const lt={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Yt={display:"flex",alignItems:"center",gap:"6px"},Kt={fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap"},Oa={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive","www.shuge.org":"書格","shuge.org":"書格","pan.baidu.com":"百度網盤"};function Pt(e){try{return Oa[new URL(e).hostname]}catch{return}}const Ro={text:0,image:1,physical:2};function Ei(e){return e.length===0?"physical":[...e].sort((n,o)=>(Ro[n]??99)-(Ro[o]??99)).join("+")}function Ri(e){var c;const n=p=>{const a=p.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const d=p.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},o=new Map;for(let p=0;p<e.length;p++){const a=e[p];if(a.volumes&&a.volumes.length>0)continue;const d=n(a.name);if(!d)continue;const[u,m]=d,f=`${u}|${Ei(_t(a))}`;o.has(f)||o.set(f,{base:{...a,name:u,url:"",volumes:[]},volumes:[],indices:[]});const g=o.get(f);g.volumes.push({volume:m,url:a.url||void 0,status:"found"}),g.indices.push(p)}const r=[],s=new Set;for(const p of o.values())if(!(p.volumes.length<2)){p.volumes.sort((a,d)=>a.volume-d.volume),p.base.volumes=p.volumes,p.base.expected_volumes=p.volumes.length,p.base.url||(p.base.url=((c=p.volumes.find(a=>a.url))==null?void 0:c.url)??""),r.push(p.base);for(const a of p.indices)s.add(a)}const l=[...r];for(let p=0;p<e.length;p++)s.has(p)||l.push(e[p]);return l}function ts(e){if(e.url)return e.url;for(const[n,o]of Object.entries(e))if(n.endsWith("_url")&&typeof o=="string")return o}function ns(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||ts(n)}))}function zn(e){const n=ns(e);if(!n)return null;const o=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,r=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:o,missing:r,expected:e.expected_volumes??o+r}}function Ni(e){if(!e)return;const n=e.file_page_range||e.page_range;if(!n||typeof n!="string")return;const o=n.match(/^(\d+)/);return o?parseInt(o[1],10):void 0}function Li(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 Dt(e){if(!e.url)return;const n=Ni(e.metadata);return n?Li(e.url,n):e.url}const No={text:i("restype-text"),image:i("restype-image"),"text+image":i("restype-text-image"),physical:i("restype-physical")};function Pa(e){return e.includes("text")&&e.includes("image")?No["text+image"]:No[e[0]||"physical"]}const Ai=({items:e,groupByType:n=!0,resourceGroups:o,onNavigate:r,renderLink:s})=>{const l=ge(),{convert:c}=X(),p=x.useMemo(()=>Ri(e||[]),[e]),{mirrorGroups:a,ungroupedItems:d}=x.useMemo(()=>{const y=new Map,j=[];for(const h of p){const v=h.group;v?(y.has(v)||y.set(v,[]),y.get(v).push(h)):j.push(h)}for(const h of y.values())h.sort((v,_)=>{const k=$=>$.group_role==="origin"?0:$.group_role==="mirror"?1:2;return k(v)-k(_)});return{mirrorGroups:y,ungroupedItems:j}},[p]),u={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},m=y=>u[y]?u[y]:y.split("+").map(j=>u[j]||j).join("+");if(!p||p.length===0)return t.jsx("div",{style:{padding:"16px",color:i("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((y,j)=>t.jsx(Kn,{item:y},y.id||j))});const f=(y,j)=>{const h=o==null?void 0:o[y],v=(h==null?void 0:h.label)||y,_=h==null?void 0:h.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:c(v)}),_&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.5},children:c(_)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((k,$)=>t.jsx(Kn,{item:k,onNavigate:r,renderLink:s},k.id||$))})]},`group-${y}`)},g=new Map;for(const y of d){const j=Ei(_t(y));g.has(j)||g.set(j,[]),g.get(j).push(y)}const b=["text","image","text+image","physical"],w=[...b.filter(y=>g.has(y)),...[...g.keys()].filter(y=>!b.includes(y)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([y,j])=>f(y,j)),w.map(y=>{const j=g.get(y),h=Pa(y.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:h,whiteSpace:"nowrap",flexShrink:0},children:m(y)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((v,_)=>t.jsx(Kn,{item:v,onNavigate:r,renderLink:s},v.id||_))})]},y)})]})},Da={bw:{label:"",bg:i("colormode-bw-bg"),fg:i("colormode-bw-fg")},color:{label:"",bg:i("colormode-color-bg"),fg:i("colormode-color-fg")}},Kn=({item:e})=>{const n=ge(),{convert:o}=X(),[r,s]=x.useState(!1),l=x.useMemo(()=>(e.url?Pt(e.url):void 0)||o(e.name),[e.url,e.name,o]),c=x.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(b=>({...b,url:b.url||ts(b)})),[e.volumes]),p=c&&c.length>0,a=p?new Set(c.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=p?new Set(c.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=e.expected_volumes??(p?a+d:0),m=e.color_mode?{...Da[e.color_mode],label:n.colorMode[e.color_mode]}:null,f=e.details&&!p?o(e.details):null,g={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",background:i("input-bg"),fontSize:"12px",color:i("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:g,children:[t.jsx("span",{style:{fontWeight:500},children:l}),m&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:m.bg,color:m.fg},children:m.label}),f&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:f}),p&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[a,"/",u,n.unit.volume,d>0&&t.jsxs("span",{style:{color:i("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),e.url&&t.jsx("a",{href:(()=>{const b=Ni(e.metadata);return b?Li(e.url,b):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:i("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),p&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),p&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:c.map(b=>{const w=b.status==="missing";return b.url&&!w?t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${i("widget-border")}`,color:i("link-fg"),textDecoration:"none"},children:b.volume},b.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:i(w?"missing-fg":"desc-fg"),textDecoration:w?"line-through":"none",opacity:w?.6:1},children:b.volume},b.volume)})})]})},is=({indexSource:e,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:l,onSelectFolder:c})=>{const p=ge(),a=e==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",m=u?u.split(/[/\\]/).pop()||u:"",f={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:i("primary-soft"),color:i("primary")},g={onMouseOver:w=>w.currentTarget.style.opacity="0.8",onMouseOut:w=>w.currentTarget.style.opacity="1"},b=t.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...f,background:i(d?"warning":"success"),color:i("on-color-fg")},...g,children:[t.jsx("span",{children:d?"📝":"📚"}),t.jsx("span",{children:d?"draft":"official"})]});return o==="index-browser"?a?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,t.jsxs("div",{onClick:r,title:p.mode.switchToSync,style:f,...g,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:p.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:c,title:u||p.mode.selectFolder,style:{...f,paddingLeft:"8px",paddingRight:"8px"},...g,children:[t.jsx("span",{children:"📂"}),m&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:m})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:p.mode.switchToLocal,style:f,...g,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:p.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:l,title:m||p.mode.configurePath,style:{...f,background:"transparent",padding:"6px",fontSize:"12px"},...g,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:a?p.mode.switchToGithub:p.mode.switchToLocal,style:f,...g,children:[t.jsx("span",{children:a?"📁":"🌐"}),t.jsx("span",{children:a?p.mode.localMode:p.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&t.jsxs("div",{onClick:c,title:u||p.mode.selectFolder,style:{...f,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...g,children:[t.jsx("span",{children:"📂"}),m&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:m})]}),!a&&m&&t.jsxs("div",{style:{...f,background:i("mode-active-bg"),color:i("on-color-fg"),cursor:"default"},title:u,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:m})]})]})},Tn="bim-search-history",Lo=10,Ao=8;function nn(){try{const e=localStorage.getItem(Tn);return e?JSON.parse(e):[]}catch{return[]}}function Ha(e){try{const n=nn().filter(o=>o!==e);n.unshift(e),n.length>Lo&&(n.length=Lo),localStorage.setItem(Tn,JSON.stringify(n))}catch{}}function Ga(e){try{const n=nn().filter(o=>o!==e);localStorage.setItem(Tn,JSON.stringify(n))}catch{}}function Va(){try{localStorage.removeItem(Tn)}catch{}}const os=({transport:e,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:l})=>{const c=ge(),p=l??c.search.placeholder,a={work:c.indexType.work,book:c.indexType.book,collection:c.indexType.collection,entity:c.indexType.entity},[d,u]=x.useState(!1),[m,f]=x.useState([]),[g,b]=x.useState(-1),[w,y]=x.useState(nn),j=x.useRef(null),h=x.useRef(null),v=x.useRef(null),_=x.useRef(!1);x.useEffect(()=>{b(-1);const T=n.trim();if(!T){f(w.map(F=>({type:"history",text:F})));return}if(!e.searchAll){f([]);return}let U=!1;const M=setTimeout(()=>{e.searchAll(T,Ao).then(F=>{if(U)return;const O=[...F.works,...F.books,...F.collections,...F.entities??[]];f(O.slice(0,Ao).map(D=>({type:"entry",text:D.title||D.id,entry:D})))}).catch(()=>{U||f([])})},80);return()=>{U=!0,clearTimeout(M)}},[n,w,e]),x.useEffect(()=>{const T=U=>{v.current&&!v.current.contains(U.target)&&u(!1)};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[]),x.useEffect(()=>{const T=U=>{var M,F;if(U.key==="/"&&document.activeElement!==j.current){const O=(M=document.activeElement)==null?void 0:M.tagName;if(O==="INPUT"||O==="TEXTAREA"||O==="SELECT")return;U.preventDefault(),(F=j.current)==null||F.focus()}};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[]);const k=x.useCallback(T=>{T.trim()&&(Ha(T.trim()),y(nn())),r(T),u(!1)},[r]),$=x.useCallback(T=>{T.type==="history"?(o(T.text),k(T.text)):T.entry&&(s?(s(T.entry),u(!1)):(o(T.text),k(T.text)))},[o,k,s]),S=x.useCallback(T=>{if(!d||m.length===0){T.key==="Enter"&&k(n);return}switch(T.key){case"ArrowDown":T.preventDefault(),b(U=>(U+1)%m.length);break;case"ArrowUp":T.preventDefault(),b(U=>(U-1+m.length)%m.length);break;case"Enter":T.preventDefault(),g>=0&&g<m.length?$(m[g]):k(n);break;case"Escape":T.preventDefault(),u(!1);break}},[d,m,g,n,k,$]),C=x.useCallback((T,U)=>{U.stopPropagation(),Ga(T),y(nn()),f(M=>M.filter(F=>!(F.type==="history"&&F.text===T)))},[]),L=x.useCallback(T=>{T.stopPropagation(),Va(),y([]),f([])},[]);x.useEffect(()=>{if(g>=0&&h.current){const T=h.current.children;T[g]&&T[g].scrollIntoView({block:"nearest"})}},[g]);const I=!n.trim()&&w.length>0;return t.jsxs("div",{ref:v,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:j,type:"text",placeholder:p,value:n,onChange:T=>{o(T.target.value),u(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{u(!0)},onKeyDown:S,style:{width:"100%",padding:"8px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),d&&m.length>0&&t.jsxs("div",{ref:h,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:i("input-bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"6px",boxShadow:i("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[I&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:i("desc-fg"),borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("span",{children:c.search.history}),t.jsx("button",{onClick:L,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:c.search.clearAll})]}),m.map((T,U)=>t.jsxs("div",{onClick:()=>$(T),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:i("fg"),background:U===g?i("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:T.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:T.text}),T.entry&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:[a[T.entry.type],T.entry.edition&&` · ${T.entry.edition}`,T.entry.author&&` · ${T.entry.author}`]}),T.type==="history"&&t.jsx("button",{onClick:M=>C(T.text,M),style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:c.action.remove,children:"×"})]},`${T.type}-${T.text}-${U}`))]})]})},Ht=({type:e,size:n=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:n,borderRadius:1,flex:"none",background:i(`type-${e}`),verticalAlign:"middle"}}),In={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},rs=new Set(["work","book","entity"]);function Ua(e){return ls(e)||!!e.sort}function Ya(e,n){return n.sort&&rs.has(e)?n.sort:void 0}const En=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Rn=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Bi=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],ss={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function Nn(e){return e.dynasty.length+e.classification.length+(e.hasImage?1:0)+(e.hasText?1:0)+(e.hasCollated?1:0)+(e.loss?1:0)}function ls(e){return Nn(e)>0}function Ka(e){const n=[];return e.dynasty.length&&n.push("dynasty"),e.classification.length&&n.push("classification"),e.hasImage&&n.push("hasImage"),e.hasText&&n.push("hasText"),e.hasCollated&&n.push("hasCollated"),e.loss&&n.push("loss"),n}function as(e,n){const o=ss[e];return Ka(n).every(r=>o.has(r))}const qt=e=>JSON.stringify(e);function qa(e,n){if(!as(n,e))return null;const o=[];if(e.dynasty.length){const r=Array.from(new Set(e.dynasty.flatMap(s=>{var l;return((l=En.find(c=>c.key===s))==null?void 0:l.values)??[]})));r.length===1?o.push(`dynasty = ${qt(r[0])}`):r.length>1&&o.push(`dynasty IN [${r.map(qt).join(", ")}]`)}return e.classification.length&&o.push(e.classification.length===1?`classification = ${qt(e.classification[0])}`:`classification IN [${e.classification.map(qt).join(", ")}]`),e.hasImage&&o.push("has_image = true"),e.hasText&&o.push("has_text = true"),e.hasCollated&&o.push("has_collated = true"),e.loss&&o.push(`loss_status = ${qt(e.loss)}`),o.join(" AND ")}const Ve={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},cs="_";function wn(e,n=new URLSearchParams){for(const o of Object.values(Ve))n.delete(o);return e.dynasty.length&&n.set(Ve.dynasty,e.dynasty.join(",")),e.classification.length&&n.set(Ve.classification,e.classification.map(o=>o||cs).join(",")),e.hasImage&&n.set(Ve.hasImage,"1"),e.hasText&&n.set(Ve.hasText,"1"),e.hasCollated&&n.set(Ve.hasCollated,"1"),e.loss&&n.set(Ve.loss,e.loss),e.sort&&n.set(Ve.sort,e.sort),n}function Ja(e){const n=l=>(e.get(l)??"").split(",").map(c=>c.trim()).filter(Boolean),o=new Set(En.map(l=>l.key)),r=new Set(Rn.map(l=>l.value)),s=e.get(Ve.loss);return{dynasty:Array.from(new Set(n(Ve.dynasty).filter(l=>o.has(l)))),classification:Array.from(new Set(n(Ve.classification).map(l=>l===cs?"":l).filter(l=>r.has(l)))),hasImage:e.get(Ve.hasImage)==="1",hasText:e.get(Ve.hasText)==="1",hasCollated:e.get(Ve.hasCollated)==="1",loss:s==="extant"||s==="partially_extant"||s==="lost"?s:"",sort:["era:asc","era:desc","title:asc","title:desc"].find(l=>l===e.get(Ve.sort))??""}}function Za(e,n){return JSON.stringify([e.dynasty.slice().sort(),e.classification.slice().sort(),e.hasImage,e.hasText,e.hasCollated,e.loss,e.sort])===JSON.stringify([n.dynasty.slice().sort(),n.classification.slice().sort(),n.hasImage,n.hasText,n.hasCollated,n.loss,n.sort])}function Bo(e,n){return e.includes(n)?e.filter(o=>o!==n):[...e,n]}const Xa=({filters:e,onChange:n})=>{const o=ge().searchV4,{convert:r}=X(),[s,l]=x.useState(!1),c=x.useId(),p=Nn(e),a=d=>n({...e,...d});return t.jsxs("aside",{className:"bim-sr-aside","aria-label":r(o.filterTitle),children:[t.jsxs("button",{type:"button",className:"bim-sr-fbtn","aria-expanded":s,"aria-controls":c,onClick:()=>l(d=>!d),children:[t.jsxs("span",{children:[r(o.filterButton),p>0&&t.jsx("span",{className:"bim-sr-fn",children:r(it(o.filterSelected,{n:p}))})]}),t.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[r(s?o.collapse:o.expand)," ",s?"▴":"▾"]})]}),t.jsxs("div",{className:"bim-sr-filters",id:c,"data-open":s?"true":"false",...s?{}:{"data-collapsed":"true"},children:[t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:r(o.dynasty)}),t.jsx("div",{className:"bim-sr-chips",children:En.map(d=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(d.key),onClick:()=>a({dynasty:Bo(e.dynasty,d.key)}),children:r(d.key)},d.key))})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:r(o.classification)}),Rn.map(d=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(d.value),onChange:()=>a({classification:Bo(e.classification,d.value)})}),r(d.label)]},d.value||"_"))]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:r(o.resources)}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasImage,onChange:d=>a({hasImage:d.target.checked})}),r(o.hasImage)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasText,onChange:d=>a({hasText:d.target.checked})}),r(o.hasText)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasCollated,onChange:d=>a({hasCollated:d.target.checked})}),r(o.hasCollated)]})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{id:`${c}-loss`,children:r(o.extant)}),t.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${c}-loss`,children:Bi.map(d=>t.jsx("button",{type:"button","aria-pressed":e.loss===d.value,onClick:()=>a({loss:d.value}),children:r(d.label)},d.value||"all"))})]}),t.jsx("p",{className:"bim-sr-note",children:r(o.onlyWorksNote)}),p>0&&t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>n({...In,sort:e.sort}),children:r(o.clearAllFilters)})]})]})};function ds({text:e,query:n}){const o=(n??"").trim();if(!o||!e)return t.jsx(t.Fragment,{children:e});const r=e.toLowerCase(),s=o.toLowerCase(),l=[];let c=0,p=0;for(;c<e.length;){const a=r.indexOf(s,c);if(a<0){l.push(e.slice(c));break}a>c&&l.push(e.slice(c,a)),l.push(t.jsx("mark",{className:"bim-sr-hl",children:e.slice(a,a+s.length)},p++)),c=a+s.length}return t.jsx(t.Fragment,{children:l})}const Mo=({entries:e,query:n,onEntryLinkClick:o,typeName:r})=>{const s=ge(),l=s.searchV4,{convert:c}=X(),p=Fe();return t.jsx("div",{className:"bim-sr-tablewrap",children:t.jsxs("table",{className:"bim-sr-table",children:[t.jsxs("colgroup",{children:[t.jsx("col",{style:{width:"34%"}}),t.jsx("col",{style:{width:"8%"}}),t.jsx("col",{style:{width:"19%"}}),t.jsx("col",{style:{width:"13%"}}),t.jsx("col",{style:{width:"12%"}}),t.jsx("col",{style:{width:"14%"}})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:c(l.colTitle)}),t.jsx("th",{scope:"col",children:c(l.colType)}),t.jsx("th",{scope:"col",children:c(l.colAuthor)}),t.jsx("th",{scope:"col",children:c(l.colEra)}),t.jsx("th",{scope:"col",children:c(l.colClass)}),t.jsx("th",{scope:"col",style:{textAlign:"right"},children:c(l.colResource)})]})}),t.jsx("tbody",{children:e.map(a=>{const d=c(a.title||a.primary_name||a.id),u=a.measure_info?c(a.measure_info):a.juan_count?`${a.juan_count}${s.unit.juan}`:"",m=a.type==="entity"?[a.birth_year!=null||a.death_year!=null?`${a.birth_year??"?"}—${a.death_year??"?"}`:""].filter(Boolean).join(""):a.author?`${c(a.author)}${a.role&&a.role!=="author"?` ${c(a.role)}`:""}`:"",f=a.type==="book"?a.era??a.dynasty:a.dynasty,g=f?c(f):"",b=a.classification?c(a.classification):"",w=[];a.has_image&&w.push({label:l.tagImage,cls:"bim-sr-tag--img"}),a.has_text&&w.push({label:l.tagText,cls:""}),a.has_collated&&w.push({label:l.tagCollated,cls:""}),a.loss_status==="lost"&&w.push({label:l.tagLost,cls:"bim-sr-tag--lost"});const y=[m,g,b].filter(Boolean).join(" · ");return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-sr-c-title",children:[t.jsxs("div",{className:"bim-sr-tl",children:[t.jsx("a",{href:p(a.id),onClick:j=>o(a,j),children:t.jsx(ds,{text:d,query:n?c(n):void 0})}),u&&t.jsx("span",{className:"bim-sr-measure",children:u})]}),y&&t.jsx("span",{className:"bim-sr-sub",children:y})]}),t.jsxs("td",{className:"bim-sr-c-type",children:[t.jsx(Ht,{type:a.type,size:6})," ",r(a.type)]}),t.jsx("td",{className:"bim-sr-c-who",children:m||"—"}),t.jsx("td",{className:"bim-sr-c-era",children:g||"—"}),t.jsx("td",{className:"bim-sr-c-cls",children:b||"—"}),t.jsx("td",{className:"bim-sr-c-res",children:w.map(j=>t.jsx("span",{className:`bim-sr-tag ${j.cls}`,children:c(j.label)},j.label))})]},a.id)})})]})})},Qa=`
|
|
2
2
|
.bim-sc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 10px; }
|
|
3
3
|
.bim-sc { display: flex; flex-direction: column; min-width: 0; padding: 14px 16px 12px; border: 1px solid ${i("rule")}; background: ${i("card-bg")}; color: inherit; text-decoration: none; }
|
|
4
4
|
.bim-sc:hover { border-color: ${i("rule-dashed")}; box-shadow: ${i("fr-shadow")}; }
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
.bim-sc-fl { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: ${i("aux-fg")}; }
|
|
13
13
|
.bim-sc-tags { display: flex; gap: 4px; flex: none; }
|
|
14
14
|
:root[data-layout="boxed"] .bim-sc { box-shadow: none; }
|
|
15
|
-
`,
|
|
15
|
+
`,Wo=({entries:e,query:n,onEntryLinkClick:o,typeName:r})=>{const s=ge(),l=s.searchV4,{convert:c}=X(),p=Fe();return t.jsxs("div",{className:"bim-sc-grid",children:[t.jsx("style",{children:Qa}),e.map(a=>{const d=c(a.title||a.primary_name||a.id),u=a.measure_info?c(a.measure_info):a.juan_count?`${a.juan_count}${s.unit.juan}`:"",f=[a.type==="entity"?a.birth_year!=null||a.death_year!=null?`${a.birth_year??"?"}—${a.death_year??"?"}`:"":`${a.dynasty?`〔${c(a.dynasty)}〕`:""}${a.author?c(a.author):""}`,a.type==="book"&&a.edition?c(a.edition):"",u].filter(Boolean).join(" · "),g=[r(a.type),a.classification?c(a.classification):""].filter(Boolean).join(" · "),b=[];return a.has_image&&b.push({label:l.tagImage,cls:"bim-sr-tag--img"}),a.has_text&&b.push({label:l.tagText,cls:""}),a.has_collated&&b.push({label:l.tagCollated,cls:""}),a.loss_status==="lost"&&b.push({label:l.tagLost,cls:"bim-sr-tag--lost"}),t.jsxs("a",{className:"bim-sc",href:p(a.id),onClick:w=>o(a,w),children:[t.jsx("span",{className:"bim-sc-t",children:t.jsx(ds,{text:d,query:n?c(n):void 0})}),f&&t.jsx("span",{className:"bim-sc-m",children:f}),a.descriptionSnippet&&t.jsx("p",{className:"bim-sc-s",children:Ii(a.descriptionSnippet).map((w,y)=>w.marked?t.jsx("mark",{children:c(w.text)},y):t.jsx(x.Fragment,{children:c(w.text)},y))}),t.jsx("span",{className:"bim-sc-sp"}),t.jsxs("div",{className:"bim-sc-f",children:[t.jsx("span",{className:"bim-sc-fl",children:g}),t.jsx("span",{className:"bim-sc-tags",children:b.map(w=>t.jsx("span",{className:`bim-sr-tag ${w.cls}`,children:c(w.label)},w.label))})]})]},a.id)})]})};function ec(e,n){const o=new Set([1,n,e-1,e,e+1].filter(l=>l>=1&&l<=n)),r=Array.from(o).sort((l,c)=>l-c),s=[];return r.forEach((l,c)=>{c>0&&l-r[c-1]>1&&s.push("gap"),s.push(l)}),s}function tc(e,n,o){const r=Math.max(1,Math.ceil(n/o));return Math.min(Math.max(1,e),r)}const nc=({page:e,pageSize:n,total:o,onPage:r})=>{const s=ge().searchV4,{convert:l}=X(),c=Math.max(1,Math.ceil(o/n));return o<=0?null:t.jsxs("nav",{className:"bim-sr-pager","aria-label":l(s.pagerLabel),children:[t.jsx("span",{className:"bim-sr-info",children:l(it(s.pageInfo,{total:o.toLocaleString(),size:n,page:e,pages:c}))}),c>1&&t.jsxs("ul",{children:[t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e<=1,onClick:()=>r(e-1),children:l(s.prevPage)})}),ec(e,c).map((p,a)=>p==="gap"?t.jsx("li",{className:"bim-sr-gap","aria-hidden":"true",children:"…"},`g${a}`):t.jsx("li",{children:t.jsx("button",{type:"button","aria-current":p===e?"page":void 0,"aria-label":`${p}`,onClick:()=>r(p),children:p})},p)),t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e>=c,onClick:()=>r(e+1),children:l(s.nextPage)})})]})]})},ps="(max-width: 719px)",ic=`${ps}, (pointer: coarse)`,oc=`
|
|
16
16
|
.bim-sr-layout { display: grid; grid-template-columns: 208px minmax(0, 1fr); column-gap: 40px; align-items: start; padding: 0 20px; }
|
|
17
17
|
.bim-sr-layout[data-nofilters] { grid-template-columns: minmax(0, 1fr); }
|
|
18
18
|
.bim-sr-aside { position: sticky; top: calc(${i("reader-top")} + 16px); padding-top: 2px; }
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
.bim-sr-pager .bim-sr-gap { color: ${i("aux-fg")}; padding: 0 2px; }
|
|
82
82
|
.bim-sr-empty { padding: 60px 0; text-align: center; font-size: 14px; color: ${i("meta-fg")}; }
|
|
83
83
|
|
|
84
|
-
@media ${
|
|
84
|
+
@media ${ps} {
|
|
85
85
|
.bim-sr-layout { grid-template-columns: minmax(0, 1fr); row-gap: 16px; padding: 0 16px; }
|
|
86
86
|
.bim-sr-aside { position: static; }
|
|
87
87
|
.bim-sr-fbtn {
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
.bim-sr-table td.bim-sr-c-res { text-align: left; padding-bottom: 2px; }
|
|
103
103
|
.bim-sr-table td.bim-sr-c-res:empty { display: none; }
|
|
104
104
|
}
|
|
105
|
-
@media ${
|
|
105
|
+
@media ${ic} {
|
|
106
106
|
.bim-sr-chip { min-height: 36px; }
|
|
107
107
|
.bim-sr-opt { min-height: 44px; }
|
|
108
108
|
.bim-sr-seg button { min-height: 44px; }
|
|
@@ -117,24 +117,24 @@
|
|
|
117
117
|
:root[data-layout="boxed"] .bim-sr-table th { background: ${i("fr-bg")}; }
|
|
118
118
|
/* 墨:强调色≈正文色,标题链接另加下划线 */
|
|
119
119
|
:root[data-theme="ink"] .bim-sr-table td.bim-sr-c-title a { text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); text-underline-offset: 3px; }
|
|
120
|
-
`,Ii="bim-search-view",Dn=50,No=5,Lo=1e3,Bo=["work","collection","book","entity"],Ja={work:"works",collection:"collections",book:"books",entity:"entities"},Za={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function Xa(){try{return window.localStorage.getItem(Ii)==="card"?"card":"table"}catch{return"table"}}function Qa(e){try{window.localStorage.setItem(Ii,e)}catch{}}const Ht=(e,n)=>(e==null?void 0:e[Za[n]])??0,Hn=(e,n)=>(e==null?void 0:e[Ja[n]])??[],rs=({transport:e,query:n,filters:o,onFiltersChange:r,onEntryLinkClick:s,typeName:l})=>{const c=me(),p=c.searchV4,{convert:a}=V(),d=!!e.supportsSearchFilters,u=f.useMemo(()=>d?o:_n,[d,o]),[m,x]=f.useState("table");f.useEffect(()=>{x(Xa())},[]);const g=A=>{x(A),Qa(A)},[b,w]=f.useState("all"),[y,j]=f.useState(1),[h,v]=f.useState(null),[$,k]=f.useState(null),[_,S]=f.useState(!1),[z,N]=f.useState(""),R=yn(u).toString(),C=Tn(u)>0,H=yn({...u,sort:""}).toString(),L=f.useRef({query:n,filterOnlyKey:H,sort:u.sort});f.useEffect(()=>{const A=L.current;A.query!==n||A.filterOnlyKey!==H?(w("all"),j(1)):A.sort!==u.sort&&j(1),L.current={query:n,filterOnlyKey:H,sort:u.sort}},[n,H,u.sort]),f.useEffect(()=>{let A=!1;return S(!0),N(""),(async()=>{try{let ee;if(e.searchAll)ee=await e.searchAll(n,No,u);else{const de=["work","book","collection","entity"],G=await Promise.all(de.map(q=>e.search(n,q,{page:1,pageSize:No,filters:u})));ee={works:G[0].entries,books:G[1].entries,collections:G[2].entries,entities:G[3].entries,totalWorks:G[0].total,totalBooks:G[1].total,totalCollections:G[2].total,totalEntities:G[3].total}}A||v(ee)}catch(ee){A||(N(ee instanceof Error?ee.message:String(ee)),v(null))}finally{A||S(!1)}})(),()=>{A=!0}},[e,n,R]),f.useEffect(()=>{if(b==="all"){k(null);return}let A=!1;return S(!0),(async()=>{try{const ee=await e.search(n,b,{page:y,pageSize:Dn,filters:u});A||k({entries:ee.entries,total:ee.total})}catch(ee){A||(N(ee instanceof Error?ee.message:String(ee)),k(null))}finally{A||S(!1)}})(),()=>{A=!0}},[e,n,R,b,y]),f.useEffect(()=>{if(b==="all"||!$||_)return;const A=Math.min($.total,Lo),ee=Va(y,A,Dn);$.entries.length===0&&A>0&&ee!==y&&j(ee)},[b,$,_,y]);const M=f.useMemo(()=>Bo.filter(A=>Ht(h,A)>0),[h]),F=M.reduce((A,ee)=>A+Ht(h,ee),0),X=!_&&!z&&h!==null&&F===0,U=f.useCallback(A=>{w(A),j(1)},[]),T=f.useMemo(()=>{var ee;const A=[];return u.dynasty.forEach(de=>A.push({name:de,remove:()=>r({...u,dynasty:u.dynasty.filter(G=>G!==de)})})),u.classification.forEach(de=>{var G;return A.push({name:((G=Cn.find(q=>q.value===de))==null?void 0:G.label)??de,remove:()=>r({...u,classification:u.classification.filter(q=>q!==de)})})}),u.hasImage&&A.push({name:p.hasImage,remove:()=>r({...u,hasImage:!1})}),u.hasText&&A.push({name:p.hasText,remove:()=>r({...u,hasText:!1})}),u.hasCollated&&A.push({name:p.hasCollated,remove:()=>r({...u,hasCollated:!1})}),u.loss&&A.push({name:`${p.extant}:${((ee=Ti.find(de=>de.value===u.loss))==null?void 0:ee.label)??""}`,remove:()=>r({...u,loss:""})}),A},[u,r,p]),ce={query:n,onEntryLinkClick:s,typeName:l},B=A=>m==="table"?t.jsx(Eo,{entries:A,...ce}):t.jsx(Ro,{entries:A,...ce}),D=Bo.flatMap(A=>Hn(h,A));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":d?void 0:"true",children:[t.jsx("style",{children:qa}),d&&t.jsx(Ha,{filters:u,onChange:r}),t.jsxs("div",{className:"bim-sr-main","aria-busy":_,children:[M.length>0&&t.jsxs("div",{className:"bim-sr-tabs",role:"group","aria-label":c.search.resultTabs,style:{display:"flex",flexWrap:"wrap",gap:"0 4px",borderBottom:`1px solid ${i("rule")}`},children:[t.jsxs(Ao,{on:b==="all",onClick:()=>U("all"),children:[c.search.allTab," ",t.jsx("small",{children:F.toLocaleString()})]}),M.map(A=>t.jsxs(Ao,{on:b===A,onClick:()=>U(A),children:[l(A)," ",t.jsx("small",{children:Ht(h,A).toLocaleString()})]},A))]}),t.jsxs("div",{className:"bim-sr-tools",children:[d&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":a(p.sortLabel),children:[t.jsx("button",{type:"button","aria-pressed":!u.sort,onClick:()=>r({...u,sort:""}),children:a(p.sortRelevance)}),["era","title"].map(A=>{const ee=u.sort.startsWith(`${A}:`)?u.sort.endsWith("desc")?"desc":"asc":null,de=A==="era"?p.sortEra:p.sortTitle,G=A==="era"?ee==="desc"?p.sortEraDesc:p.sortEraAsc:ee==="desc"?p.sortTitleDesc:p.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":ee!==null,title:a(G),onClick:()=>r({...u,sort:`${A}:${ee==="asc"?"desc":"asc"}`}),children:[a(de),ee?t.jsxs("span",{"aria-hidden":"true",children:[" ",ee==="asc"?"↑":"↓"]}):null]},A)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":a(p.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":m==="table",onClick:()=>g("table"),children:a(p.viewTable)}),t.jsx("button",{type:"button","aria-pressed":m==="card",onClick:()=>g("card"),children:a(p.viewCard)})]})]}),C&&t.jsxs("div",{className:"bim-sr-chips-row",children:[t.jsx("span",{className:"bim-sr-count",role:"status",children:a(Qe(p.filteredCount,{n:F.toLocaleString()}))}),T.map(A=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":a(Qe(p.removeFilter,{name:A.name})),onClick:A.remove,children:[a(A.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},A.name))]}),z&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:z}),X&&t.jsx("div",{className:"bim-sr-empty",children:a(C?p.emptyFiltered:Qe(c.search.noResultsFor,{query:n}))}),!z&&!X&&b==="all"&&h&&(m==="table"?t.jsxs(t.Fragment,{children:[t.jsx(Eo,{entries:D,...ce}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:a(p.limitedNote)})]}):t.jsx(t.Fragment,{children:M.map(A=>t.jsxs("section",{style:{marginTop:22},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[t.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[t.jsx(Wt,{type:A,size:8}),l(A),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:i("meta-fg")},children:[Ht(h,A).toLocaleString()," ",c.unit.items]})]}),Ht(h,A)>Hn(h,A).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>U(A),children:c.action.viewAll})]}),t.jsx(Ro,{entries:Hn(h,A),...ce})]},A))})),!z&&b!=="all"&&$&&$.entries.length>0&&t.jsxs(t.Fragment,{children:[B($.entries),t.jsx(Ya,{page:y,pageSize:Dn,total:Math.min($.total,Lo),onPage:j})]}),!z&&b!=="all"&&$&&$.entries.length===0&&!_&&t.jsxs("div",{className:"bim-sr-empty",children:[a(C?p.emptyFiltered:Qe(c.search.noResultsFor,{query:n})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>U("all"),children:c.search.allTab})})]})]})]})};function Ao({on:e,onClick:n,children:o}){return t.jsx("button",{type:"button","aria-pressed":e,onClick:n,style:{border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:14.5,minHeight:44,padding:"8px 12px",letterSpacing:".06em",color:i(e?"ink":"meta-fg"),fontWeight:e?700:400,boxShadow:e?`inset 0 -2px 0 ${i("accent")}`:"none"},children:o})}const It="bim-recent-ids",Wo="bim-recent-entries",Mo=50,Gn=5,ec=50,tc=200;function zt(){try{const e=localStorage.getItem(It);if(e)return JSON.parse(e);const n=localStorage.getItem(Wo);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(It,JSON.stringify(o)),localStorage.removeItem(Wo),o}return[]}catch{return[]}}function Fo(e){try{const n=zt().filter(o=>o!==e);n.unshift(e),n.length>Mo&&(n.length=Mo),localStorage.setItem(It,JSON.stringify(n))}catch{}}function nc(e){try{const n=zt().filter(o=>o!==e);localStorage.setItem(It,JSON.stringify(n))}catch{}}function ic(){try{localStorage.removeItem(It)}catch{}}const Po={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},ii=({transport:e,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a,hideModeIndicator:d,resultVariant:u="compact",renderEntry:m,initialQuery:x,onQueryChange:g,headerRight:b,reserveViewportHeight:w=!1,filtersEnabled:y=!1,filters:j=_n,onFiltersChange:h})=>{const v=me(),$=[{type:"work",name:v.indexType.work,key:"works"},{type:"book",name:v.indexType.book,key:"books"},{type:"collection",name:v.indexType.collection,key:"collections"},{type:"entity",name:v.indexType.entity,key:"entities"}],k=["work","collection","book","entity"],[_,S]=f.useState(x??""),[z,N]=f.useState(null),[R,C]=f.useState(x??""),H=yn(j).toString(),[L,M]=f.useState(j);f.useEffect(()=>{M(j)},[H]);const F=ne=>{M(ne),h==null||h(ne)},[X,U]=f.useState(null),[T,ce]=f.useState("all"),[B,D]=f.useState(!1),[A,ee]=f.useState(null),[de,G]=f.useState(""),[q,ie]=f.useState(!(x!=null&&x.trim())),[pe,ge]=f.useState(zt),[Ee,Ne]=f.useState([]),[ze,Te]=f.useState(!1),[Ce,Ae]=f.useState(!1),[P,se]=f.useState(null),[re,ye]=f.useState(null),be=f.useRef(void 0),K=f.useRef(!1),I=f.useCallback(async(ne,we)=>{if(!ne.trim()){ie(!0),N(null),U(null);return}if(ie(!1),y){C(ne);return}D(!0),G("");try{if(e.searchAll){const E=await e.searchAll(ne,we??Gn);N(E)}else{const E=["work","book","collection","entity"],Q=await Promise.all(E.map(ue=>e.search(ne,ue,{page:1,pageSize:we??Gn})));N({works:Q[0].entries,books:Q[1].entries,collections:Q[2].entries,entities:Q[3].entries,totalWorks:Q[0].total,totalBooks:Q[1].total,totalCollections:Q[2].total,totalEntities:Q[3].total})}}catch(E){G(E instanceof Error?E.message:String(E)),N(null)}finally{D(!1)}},[e,y]);f.useEffect(()=>{let ne=!1;const we=()=>{var te,ke;const E=["work","book","collection","entity"],Q=Promise.all(E.map(Ie=>e.loadEntries(Ie,{page:1,pageSize:1}).catch(()=>({total:0})))),ue=((te=e.getResourceCounts)==null?void 0:te.call(e).catch(()=>null))??Promise.resolve(null),le=((ke=e.getSubtypeStats)==null?void 0:ke.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([Q,ue,le]).then(([Ie,We,Ze])=>{ne||(se({works:Ie[0].total,books:Ie[1].total,collections:Ie[2].total,entities:Ie[3].total,hasText:We==null?void 0:We.hasText,hasImage:We==null?void 0:We.hasImage}),Ze&&ye(Ze))})};return e.getCounts?e.getCounts().then(E=>{var Q,ue;ne||(se({works:E.works,books:E.books,collections:E.collections,entities:E.entities,hasText:(Q=E.resourceCounts)==null?void 0:Q.hasText,hasImage:(ue=E.resourceCounts)==null?void 0:ue.hasImage}),E.subtypeStats&&ye(E.subtypeStats))}).catch(()=>{ne||we()}):we(),()=>{ne=!0}},[e]),f.useEffect(()=>{K.current||!(x!=null&&x.trim())||(K.current=!0,I(x))},[x,I]);const Y=f.useCallback(ne=>{if(S(ne),!ne.trim()){g==null||g(ne),ie(!0),N(null),U(null),ce("all");return}be.current&&clearTimeout(be.current),be.current=setTimeout(()=>{U(null),ce("all"),g==null||g(ne),I(ne)},tc)},[I,g]),fe=f.useCallback(ne=>{be.current&&clearTimeout(be.current),ce("all"),g==null||g(ne),I(ne)},[I,g]),he=f.useCallback(ne=>{U(ne),I(_,ec)},[_,I]);f.useEffect(()=>{if(!pe.length){Ne([]);return}let ne=!1;return Te(!0),Promise.all(pe.slice(0,10).map(async we=>{var E,Q,ue;try{if(e.getEntry){const te=await e.getEntry(we);if(te)return te}const le=await e.getItem(we);if(le){const te=le.authors;return{id:we,title:le.title||we,type:le.type||"work",author:(E=te==null?void 0:te[0])==null?void 0:E.name,dynasty:(Q=te==null?void 0:te[0])==null?void 0:Q.dynasty,role:(ue=te==null?void 0:te[0])==null?void 0:ue.role,edition:le.edition||void 0}}}catch{}return{id:we,title:we,type:"work",notFound:!0}})).then(we=>{ne||(Ne(we),Te(!1))}),()=>{ne=!0}},[pe,e]);const W=ne=>{ee(ne.id),Fo(ne.id),ge(zt()),r==null||r(ne)},ae=(ne,we)=>{if(r&&rc(we)){we.preventDefault(),W(ne);return}Fo(ne.id),ge(zt())},J=ne=>{nc(ne),ge(zt())},O=()=>{ic(),ge([])},xe=ne=>$.find(we=>we.type===ne),je=!q&&!z&&!de,Se=z&&(z.works.length>0||z.books.length>0||z.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",style:w?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:sc}),t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("h1",{style:{margin:0,fontSize:"18px",color:i("fg")},children:v.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&t.jsx(Jr,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(Zr,{transport:e,value:_,onChange:Y,onSearch:fe,onEntrySelect:W}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${i("primary")}`,borderRadius:"6px",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"13px"},children:v.action.newEntry})]}),q&&t.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:P&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:re?t.jsxs(t.Fragment,{children:[(re.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:i("fg")},children:re.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:i("fg")},children:P.books.toLocaleString()})," 本"]}),re.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:i("fg")},children:re.article.toLocaleString()})," 篇"]}):null,re.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:i("fg")},children:re.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:i("fg")},children:P.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[v.indexType.work," ",t.jsx("strong",{style:{color:i("fg")},children:P.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.book," ",t.jsx("strong",{style:{color:i("fg")},children:P.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.collection," ",t.jsx("strong",{style:{color:i("fg")},children:P.collections.toLocaleString()}),P.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.entity," ",t.jsx("strong",{style:{color:i("fg")},children:P.entities.toLocaleString()})]})]})}),P.hasImage!=null&&P.hasText!=null&&t.jsxs("span",{children:[v.resourceType.image," ",t.jsx("strong",{style:{color:i("fg")},children:P.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.resourceType.text," ",t.jsx("strong",{style:{color:i("fg")},children:P.hasText.toLocaleString()})]})]})}),y&&!q&&t.jsx(rs,{transport:e,query:R,filters:L,onFiltersChange:F,onEntryLinkClick:ae,typeName:ne=>xe(ne).name}),!(y&&!q)&&t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:B||je?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg"),minHeight:oc,boxSizing:"border-box"},children:v.search.searching}):de?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:i("desc-fg")},children:de})}):q?t.jsx("div",{style:{flex:1},children:ze?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg")},children:v.search.loading}):Ee.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:v.search.recentBrowse}),t.jsx("button",{onClick:O,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:v.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:Ee.slice(0,Ce?10:3).map(ne=>ne.notFound?t.jsx(dc,{id:ne.id,onRemove:J,t:v},ne.id):t.jsx(Oo,{entry:ne,selected:A===ne.id,onClick:ae,getConfig:xe,onRemove:J},ne.id))}),!Ce&&Ee.length>3&&t.jsx("button",{onClick:()=>Ae(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:v.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:v.search.searchTitle}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:v.search.searchSubtitle})]})}):Se?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:lc}),(()=>{const ne=le=>z[Po[le]]??0,we=k.map(le=>$.find(te=>te.type===le)).filter(le=>ne(le.key)>0);if(we.length<2)return null;const E=we.reduce((le,te)=>le+ne(te.key),0),Q=le=>{if(ce(le),le!=="all"&&X!==le){const te=$.find(Ie=>Ie.type===le),ke=(z[te.key]??[]).length;ne(te.key)>ke&&he(le)}},ue=le=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:i(le?"fg":"desc-fg"),fontWeight:le?700:400,boxShadow:le?`inset 0 -2px 0 ${i("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":v.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":T==="all",style:ue(T==="all"),onClick:()=>Q("all"),children:[v.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:E.toLocaleString()})]}),we.map(le=>t.jsxs("button",{type:"button","aria-pressed":T===le.type,style:ue(T===le.type),onClick:()=>Q(le.type),children:[le.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:ne(le.key).toLocaleString()})]},le.type))]})})(),$.map(({type:ne,name:we,key:E})=>{const Q=z[E]??[],ue=Po[E],le=z[ue]??0;if(Q.length===0||T!=="all"&&T!==ne)return null;const ke=T==="all"&&!(X===ne)&&le>Gn;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:[t.jsx(Wt,{type:ne})," ",we,t.jsxs("span",{style:{fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[le," ",v.unit.items]})]}),ke&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>he(ne),style:{border:"none",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"12px"},children:v.action.viewAll})]}),t.jsx("div",{style:u==="list"?{display:"flex",flexDirection:"column",gap:0}:u==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:Q.map(Ie=>{if(m)return t.jsx(f.Fragment,{children:m(Ie)},Ie.id);const We=u==="card"?cc:Oo;return t.jsx(We,{entry:Ie,selected:A===Ie.id,onClick:ae,getConfig:xe,query:_},Ie.id)})})]},ne)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:Qe(v.search.noResultsFor,{query:_})}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:v.search.tryOther})]})})]})},oc=240;function rc(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const sc=`
|
|
120
|
+
`,Mi="bim-search-view",qn=50,Fo=5,Oo=1e3,Po=["work","collection","book","entity"],rc={work:"works",collection:"collections",book:"books",entity:"entities"},sc={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function lc(){try{return window.localStorage.getItem(Mi)==="card"?"card":"table"}catch{return"table"}}function ac(e){try{window.localStorage.setItem(Mi,e)}catch{}}const Jt=(e,n)=>(e==null?void 0:e[sc[n]])??0,Jn=(e,n)=>(e==null?void 0:e[rc[n]])??[],us=({transport:e,query:n,filters:o,onFiltersChange:r,onEntryLinkClick:s,typeName:l})=>{const c=ge(),p=c.searchV4,{convert:a}=X(),d=!!e.supportsSearchFilters,u=x.useMemo(()=>d?o:In,[d,o]),[m,f]=x.useState("table");x.useEffect(()=>{f(lc())},[]);const g=E=>{f(E),ac(E)},[b,w]=x.useState("all"),[y,j]=x.useState(1),[h,v]=x.useState(null),[_,k]=x.useState(null),[$,S]=x.useState(!1),[C,L]=x.useState(""),I=wn(u).toString(),T=Nn(u)>0,U=wn({...u,sort:""}).toString(),M=x.useRef({query:n,filterOnlyKey:U,sort:u.sort});x.useEffect(()=>{const E=M.current;E.query!==n||E.filterOnlyKey!==U?(w("all"),j(1)):E.sort!==u.sort&&j(1),M.current={query:n,filterOnlyKey:U,sort:u.sort}},[n,U,u.sort]),x.useEffect(()=>{let E=!1;return S(!0),L(""),(async()=>{try{let W;if(e.searchAll)W=await e.searchAll(n,Fo,u);else{const ce=["work","book","collection","entity"],Y=await Promise.all(ce.map(ee=>e.search(n,ee,{page:1,pageSize:Fo,filters:u})));W={works:Y[0].entries,books:Y[1].entries,collections:Y[2].entries,entities:Y[3].entries,totalWorks:Y[0].total,totalBooks:Y[1].total,totalCollections:Y[2].total,totalEntities:Y[3].total}}E||v(W)}catch(W){E||(L(W instanceof Error?W.message:String(W)),v(null))}finally{E||S(!1)}})(),()=>{E=!0}},[e,n,I]),x.useEffect(()=>{if(b==="all"){k(null);return}let E=!1;return S(!0),(async()=>{try{const W=await e.search(n,b,{page:y,pageSize:qn,filters:u});E||k({entries:W.entries,total:W.total})}catch(W){E||(L(W instanceof Error?W.message:String(W)),k(null))}finally{E||S(!1)}})(),()=>{E=!0}},[e,n,I,b,y]),x.useEffect(()=>{if(b==="all"||!_||$)return;const E=Math.min(_.total,Oo),W=tc(y,E,qn);_.entries.length===0&&E>0&&W!==y&&j(W)},[b,_,$,y]);const F=x.useMemo(()=>Po.filter(E=>Jt(h,E)>0),[h]),O=F.reduce((E,W)=>E+Jt(h,W),0),D=!$&&!C&&h!==null&&O===0,H=x.useCallback(E=>{w(E),j(1)},[]),z=x.useMemo(()=>{var W;const E=[];return u.dynasty.forEach(ce=>E.push({name:ce,remove:()=>r({...u,dynasty:u.dynasty.filter(Y=>Y!==ce)})})),u.classification.forEach(ce=>{var Y;return E.push({name:((Y=Rn.find(ee=>ee.value===ce))==null?void 0:Y.label)??ce,remove:()=>r({...u,classification:u.classification.filter(ee=>ee!==ce)})})}),u.hasImage&&E.push({name:p.hasImage,remove:()=>r({...u,hasImage:!1})}),u.hasText&&E.push({name:p.hasText,remove:()=>r({...u,hasText:!1})}),u.hasCollated&&E.push({name:p.hasCollated,remove:()=>r({...u,hasCollated:!1})}),u.loss&&E.push({name:`${p.extant}:${((W=Bi.find(ce=>ce.value===u.loss))==null?void 0:W.label)??""}`,remove:()=>r({...u,loss:""})}),E},[u,r,p]),pe={query:n,onEntryLinkClick:s,typeName:l},A=E=>m==="table"?t.jsx(Mo,{entries:E,...pe}):t.jsx(Wo,{entries:E,...pe}),oe=Po.flatMap(E=>Jn(h,E));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":d?void 0:"true",children:[t.jsx("style",{children:oc}),d&&t.jsx(Xa,{filters:u,onChange:r}),t.jsxs("div",{className:"bim-sr-main","aria-busy":$,children:[F.length>0&&t.jsxs("div",{className:"bim-sr-tabs",role:"group","aria-label":c.search.resultTabs,style:{display:"flex",flexWrap:"wrap",gap:"0 4px",borderBottom:`1px solid ${i("rule")}`},children:[t.jsxs(Do,{on:b==="all",onClick:()=>H("all"),children:[c.search.allTab," ",t.jsx("small",{children:O.toLocaleString()})]}),F.map(E=>t.jsxs(Do,{on:b===E,onClick:()=>H(E),children:[l(E)," ",t.jsx("small",{children:Jt(h,E).toLocaleString()})]},E))]}),t.jsxs("div",{className:"bim-sr-tools",children:[d&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":a(p.sortLabel),children:[t.jsx("button",{type:"button","aria-pressed":!u.sort,onClick:()=>r({...u,sort:""}),children:a(p.sortRelevance)}),["era","title"].map(E=>{const W=u.sort.startsWith(`${E}:`)?u.sort.endsWith("desc")?"desc":"asc":null,ce=E==="era"?p.sortEra:p.sortTitle,Y=E==="era"?W==="desc"?p.sortEraDesc:p.sortEraAsc:W==="desc"?p.sortTitleDesc:p.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":W!==null,title:a(Y),onClick:()=>r({...u,sort:`${E}:${W==="asc"?"desc":"asc"}`}),children:[a(ce),W?t.jsxs("span",{"aria-hidden":"true",children:[" ",W==="asc"?"↑":"↓"]}):null]},E)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":a(p.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":m==="table",onClick:()=>g("table"),children:a(p.viewTable)}),t.jsx("button",{type:"button","aria-pressed":m==="card",onClick:()=>g("card"),children:a(p.viewCard)})]})]}),T&&t.jsxs("div",{className:"bim-sr-chips-row",children:[t.jsx("span",{className:"bim-sr-count",role:"status",children:a(it(p.filteredCount,{n:O.toLocaleString()}))}),z.map(E=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":a(it(p.removeFilter,{name:E.name})),onClick:E.remove,children:[a(E.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},E.name))]}),C&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:C}),D&&t.jsx("div",{className:"bim-sr-empty",children:a(T?p.emptyFiltered:it(c.search.noResultsFor,{query:n}))}),!C&&!D&&b==="all"&&h&&(m==="table"?t.jsxs(t.Fragment,{children:[t.jsx(Mo,{entries:oe,...pe}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:a(p.limitedNote)})]}):t.jsx(t.Fragment,{children:F.map(E=>t.jsxs("section",{style:{marginTop:22},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[t.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ht,{type:E,size:8}),l(E),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:i("meta-fg")},children:[Jt(h,E).toLocaleString()," ",c.unit.items]})]}),Jt(h,E)>Jn(h,E).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>H(E),children:c.action.viewAll})]}),t.jsx(Wo,{entries:Jn(h,E),...pe})]},E))})),!C&&b!=="all"&&_&&_.entries.length>0&&t.jsxs(t.Fragment,{children:[A(_.entries),t.jsx(nc,{page:y,pageSize:qn,total:Math.min(_.total,Oo),onPage:j})]}),!C&&b!=="all"&&_&&_.entries.length===0&&!$&&t.jsxs("div",{className:"bim-sr-empty",children:[a(T?p.emptyFiltered:it(c.search.noResultsFor,{query:n})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>H("all"),children:c.search.allTab})})]})]})]})};function Do({on:e,onClick:n,children:o}){return t.jsx("button",{type:"button","aria-pressed":e,onClick:n,style:{border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:14.5,minHeight:44,padding:"8px 12px",letterSpacing:".06em",color:i(e?"ink":"meta-fg"),fontWeight:e?700:400,boxShadow:e?`inset 0 -2px 0 ${i("accent")}`:"none"},children:o})}const Bt="bim-recent-ids",Ho="bim-recent-entries",Go=50,Zn=5,cc=50,dc=200;function Nt(){try{const e=localStorage.getItem(Bt);if(e)return JSON.parse(e);const n=localStorage.getItem(Ho);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Bt,JSON.stringify(o)),localStorage.removeItem(Ho),o}return[]}catch{return[]}}function Vo(e){try{const n=Nt().filter(o=>o!==e);n.unshift(e),n.length>Go&&(n.length=Go),localStorage.setItem(Bt,JSON.stringify(n))}catch{}}function pc(e){try{const n=Nt().filter(o=>o!==e);localStorage.setItem(Bt,JSON.stringify(n))}catch{}}function uc(){try{localStorage.removeItem(Bt)}catch{}}const Uo={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},pi=({transport:e,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a,hideModeIndicator:d,resultVariant:u="compact",renderEntry:m,initialQuery:f,onQueryChange:g,headerRight:b,reserveViewportHeight:w=!1,filtersEnabled:y=!1,filters:j=In,onFiltersChange:h})=>{const v=ge(),_=[{type:"work",name:v.indexType.work,key:"works"},{type:"book",name:v.indexType.book,key:"books"},{type:"collection",name:v.indexType.collection,key:"collections"},{type:"entity",name:v.indexType.entity,key:"entities"}],k=["work","collection","book","entity"],[$,S]=x.useState(f??""),[C,L]=x.useState(null),[I,T]=x.useState(f??""),U=wn(j).toString(),[M,F]=x.useState(j);x.useEffect(()=>{F(j)},[U]);const O=J=>{F(J),h==null||h(J)},[D,H]=x.useState(null),[z,pe]=x.useState("all"),[A,oe]=x.useState(!1),[E,W]=x.useState(null),[ce,Y]=x.useState(""),[ee,Z]=x.useState(!(f!=null&&f.trim())),[le,be]=x.useState(Nt),[Le,Be]=x.useState([]),[he,Ne]=x.useState(!1),[Te,Re]=x.useState(!1),[P,me]=x.useState(null),[te,ke]=x.useState(null),we=x.useRef(void 0),K=x.useRef(!1),N=x.useCallback(async(J,_e)=>{if(!J.trim()){Z(!0),L(null),H(null);return}if(Z(!1),y){T(J);return}oe(!0),Y("");try{if(e.searchAll){const R=await e.searchAll(J,_e??Zn);L(R)}else{const R=["work","book","collection","entity"],se=await Promise.all(R.map(ue=>e.search(J,ue,{page:1,pageSize:_e??Zn})));L({works:se[0].entries,books:se[1].entries,collections:se[2].entries,entities:se[3].entries,totalWorks:se[0].total,totalBooks:se[1].total,totalCollections:se[2].total,totalEntities:se[3].total})}}catch(R){Y(R instanceof Error?R.message:String(R)),L(null)}finally{oe(!1)}},[e,y]);x.useEffect(()=>{let J=!1;const _e=()=>{var ie,Se;const R=["work","book","collection","entity"],se=Promise.all(R.map(Ee=>e.loadEntries(Ee,{page:1,pageSize:1}).catch(()=>({total:0})))),ue=((ie=e.getResourceCounts)==null?void 0:ie.call(e).catch(()=>null))??Promise.resolve(null),ae=((Se=e.getSubtypeStats)==null?void 0:Se.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([se,ue,ae]).then(([Ee,We,qe])=>{J||(me({works:Ee[0].total,books:Ee[1].total,collections:Ee[2].total,entities:Ee[3].total,hasText:We==null?void 0:We.hasText,hasImage:We==null?void 0:We.hasImage}),qe&&ke(qe))})};return e.getCounts?e.getCounts().then(R=>{var se,ue;J||(me({works:R.works,books:R.books,collections:R.collections,entities:R.entities,hasText:(se=R.resourceCounts)==null?void 0:se.hasText,hasImage:(ue=R.resourceCounts)==null?void 0:ue.hasImage}),R.subtypeStats&&ke(R.subtypeStats))}).catch(()=>{J||_e()}):_e(),()=>{J=!0}},[e]),x.useEffect(()=>{K.current||!(f!=null&&f.trim())||(K.current=!0,N(f))},[f,N]);const q=x.useCallback(J=>{if(S(J),!J.trim()){g==null||g(J),Z(!0),L(null),H(null),pe("all");return}we.current&&clearTimeout(we.current),we.current=setTimeout(()=>{H(null),pe("all"),g==null||g(J),N(J)},dc)},[N,g]),xe=x.useCallback(J=>{we.current&&clearTimeout(we.current),pe("all"),g==null||g(J),N(J)},[N,g]),ye=x.useCallback(J=>{H(J),N($,cc)},[$,N]);x.useEffect(()=>{if(!le.length){Be([]);return}let J=!1;return Ne(!0),Promise.all(le.slice(0,10).map(async _e=>{var R,se,ue;try{if(e.getEntry){const ie=await e.getEntry(_e);if(ie)return ie}const ae=await e.getItem(_e);if(ae){const ie=ae.authors;return{id:_e,title:ae.title||_e,type:ae.type||"work",author:(R=ie==null?void 0:ie[0])==null?void 0:R.name,dynasty:(se=ie==null?void 0:ie[0])==null?void 0:se.dynasty,role:(ue=ie==null?void 0:ie[0])==null?void 0:ue.role,edition:ae.edition||void 0}}}catch{}return{id:_e,title:_e,type:"work",notFound:!0}})).then(_e=>{J||(Be(_e),Ne(!1))}),()=>{J=!0}},[le,e]);const B=J=>{W(J.id),Vo(J.id),be(Nt()),r==null||r(J)},re=(J,_e)=>{if(r&&fc(_e)){_e.preventDefault(),B(J);return}Vo(J.id),be(Nt())},Q=J=>{pc(J),be(Nt())},fe=()=>{uc(),be([])},G=J=>_.find(_e=>_e.type===J),ve=!ee&&!C&&!ce,$e=C&&(C.works.length>0||C.books.length>0||C.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",style:w?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:mc}),t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("h1",{style:{margin:0,fontSize:"18px",color:i("fg")},children:v.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&t.jsx(is,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:l,onToggleDraft:c,onConfigurePath:p,onSelectFolder:a})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(os,{transport:e,value:$,onChange:q,onSearch:xe,onEntrySelect:B}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${i("primary")}`,borderRadius:"6px",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"13px"},children:v.action.newEntry})]}),ee&&t.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:P&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:te?t.jsxs(t.Fragment,{children:[(te.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:i("fg")},children:te.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:i("fg")},children:P.books.toLocaleString()})," 本"]}),te.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:i("fg")},children:te.article.toLocaleString()})," 篇"]}):null,te.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:i("fg")},children:te.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:i("fg")},children:P.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[v.indexType.work," ",t.jsx("strong",{style:{color:i("fg")},children:P.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.book," ",t.jsx("strong",{style:{color:i("fg")},children:P.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.collection," ",t.jsx("strong",{style:{color:i("fg")},children:P.collections.toLocaleString()}),P.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.entity," ",t.jsx("strong",{style:{color:i("fg")},children:P.entities.toLocaleString()})]})]})}),P.hasImage!=null&&P.hasText!=null&&t.jsxs("span",{children:[v.resourceType.image," ",t.jsx("strong",{style:{color:i("fg")},children:P.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.resourceType.text," ",t.jsx("strong",{style:{color:i("fg")},children:P.hasText.toLocaleString()})]})]})}),y&&!ee&&t.jsx(us,{transport:e,query:I,filters:M,onFiltersChange:O,onEntryLinkClick:re,typeName:J=>G(J).name}),!(y&&!ee)&&t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:A||ve?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg"),minHeight:xc,boxSizing:"border-box"},children:v.search.searching}):ce?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:i("desc-fg")},children:ce})}):ee?t.jsx("div",{style:{flex:1},children:he?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg")},children:v.search.loading}):Le.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:v.search.recentBrowse}),t.jsx("button",{onClick:fe,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:v.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:Le.slice(0,Te?10:3).map(J=>J.notFound?t.jsx(yc,{id:J.id,onRemove:Q,t:v},J.id):t.jsx(Yo,{entry:J,selected:E===J.id,onClick:re,getConfig:G,onRemove:Q},J.id))}),!Te&&Le.length>3&&t.jsx("button",{onClick:()=>Re(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:v.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:v.search.searchTitle}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:v.search.searchSubtitle})]})}):$e?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:gc}),(()=>{const J=ae=>C[Uo[ae]]??0,_e=k.map(ae=>_.find(ie=>ie.type===ae)).filter(ae=>J(ae.key)>0);if(_e.length<2)return null;const R=_e.reduce((ae,ie)=>ae+J(ie.key),0),se=ae=>{if(pe(ae),ae!=="all"&&D!==ae){const ie=_.find(Ee=>Ee.type===ae),Se=(C[ie.key]??[]).length;J(ie.key)>Se&&ye(ae)}},ue=ae=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:i(ae?"fg":"desc-fg"),fontWeight:ae?700:400,boxShadow:ae?`inset 0 -2px 0 ${i("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":v.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":z==="all",style:ue(z==="all"),onClick:()=>se("all"),children:[v.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:R.toLocaleString()})]}),_e.map(ae=>t.jsxs("button",{type:"button","aria-pressed":z===ae.type,style:ue(z===ae.type),onClick:()=>se(ae.type),children:[ae.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:J(ae.key).toLocaleString()})]},ae.type))]})})(),_.map(({type:J,name:_e,key:R})=>{const se=C[R]??[],ue=Uo[R],ae=C[ue]??0;if(se.length===0||z!=="all"&&z!==J)return null;const Se=z==="all"&&!(D===J)&&ae>Zn;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:[t.jsx(Ht,{type:J})," ",_e,t.jsxs("span",{style:{fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[ae," ",v.unit.items]})]}),Se&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>ye(J),style:{border:"none",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"12px"},children:v.action.viewAll})]}),t.jsx("div",{style:u==="list"?{display:"flex",flexDirection:"column",gap:0}:u==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:se.map(Ee=>{if(m)return t.jsx(x.Fragment,{children:m(Ee)},Ee.id);const We=u==="card"?bc:Yo;return t.jsx(We,{entry:Ee,selected:E===Ee.id,onClick:re,getConfig:G,query:$},Ee.id)})})]},J)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:it(v.search.noResultsFor,{query:$})}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:v.search.tryOther})]})})]})},xc=240;function fc(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const mc=`
|
|
121
121
|
.bim-ib-stats { min-height: 25px; box-sizing: content-box; }
|
|
122
122
|
@media (max-width: 719px) { .bim-ib-stats { min-height: 46px; } }
|
|
123
|
-
`,
|
|
123
|
+
`,gc=`
|
|
124
124
|
@media (max-width: 719px), (pointer: coarse) {
|
|
125
125
|
.bim-ib-viewall { position: relative; }
|
|
126
126
|
.bim-ib-viewall::after {
|
|
127
127
|
content: ""; position: absolute; left: 50%; top: 50%;
|
|
128
128
|
width: max(calc(100% + 8px), 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
|
|
129
129
|
}
|
|
130
|
-
}`,ss={color:"inherit",textDecoration:"none"},ac=({snippet:e})=>{const{convert:n}=V();return t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.6},children:wi(e).map((o,r)=>o.marked?t.jsx("mark",{style:{background:i("highlight-bg"),color:i("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(o.text)},r):t.jsx(f.Fragment,{children:n(o.text)},r))})},cc=({entry:e,selected:n,onClick:o,getConfig:r,query:s})=>{const l=me(),{convert:c}=V(),p=c(e.title||e.primary_name||e.id),a=e.measure_info?c(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",d=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&d.length?d.find(g=>{const b=typeof g=="string"?g:g==null?void 0:g.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,m=i("cover-accent"),x=Fe();return t.jsxs("a",{href:x(e.id),onClick:g=>o(e,g),className:"bim-result-card",style:{...ss,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:i("bg"),border:n?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[t.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${m} 50%, ${i("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${m} 14%, ${i("bg")}), color-mix(in srgb, ${m} 7%, ${i("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[t.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${m} 45%, transparent)`}}),t.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:m},children:Array.from(p).map((g,b)=>t.jsx("span",{children:g},b))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:i("fg")},children:p}),a&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:a})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",c(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:c(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",c(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",c(e.era),"〕"]}),e.edition&&t.jsx("span",{children:c(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[l.search.alias,":",c(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(ac,{snippet:e.descriptionSnippet}),t.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[t.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:[t.jsx(Wt,{type:e.type,size:8})," ",r(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.imageResource})]})]})]})},Oo=({entry:e,selected:n,onClick:o,getConfig:r,query:s,onRemove:l})=>{const c=me(),{convert:p}=V(),a=[...e.additional_titles||[],...e.attached_texts||[]],d=s&&a.length?a.find(m=>{const x=typeof m=="string"?m:m==null?void 0:m.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,u=Fe();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("a",{href:u(e.id),onClick:m=>o(e,m),className:"bim-result-card",style:{...ss,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx(Wt,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:i("desc-fg"),lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg")},children:p(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{children:c.misc.textResource}),e.has_image&&t.jsx("span",{children:c.misc.imageResource})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",p(e.era),"〕"]}),e.edition&&p(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:p(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[e.juan_count,c.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",p(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:p(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",p(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),d&&t.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:[c.search.alias,":",p(d)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:c.search.removeFromRecent,"aria-label":c.search.removeFromRecent,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},dc=({id:e,onRemove:n,t:o})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${i("widget-border")}`,background:i("input-bg"),opacity:.6},children:[t.jsx("span",{style:{fontSize:"16px"},children:"❓"}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:"13px",color:i("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:o.search.itemNotFound})]}),t.jsx("button",{onClick:()=>n(e),title:o.search.removeFromRecent,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function pc(e){var n;return!e.dynasty&&!e.birth_year&&!e.death_year&&(!e.alt_names||e.alt_names.length===0)&&!((n=e.description)!=null&&n.text)}function uc({data:e}){const{convert:n}=V(),{dynasty:o,birth_year:r,death_year:s}=e,l=[];return o&&l.push(`〔${n(o)}〕`),r!==void 0&&s!==void 0?l.push(`${r}—${s}`):r!==void 0?l.push(`${r}—?`):s!==void 0&&l.push(`?—${s}`),l.length===0?null:t.jsx("span",{style:{fontSize:"14px",color:i("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function xc({alt_names:e}){const{convert:n}=V(),o=new Map;for(const l of e){const c=l.type||"別名";o.has(c)||o.set(c,[]),o.get(c).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((l,c)=>{const p=r.indexOf(l),a=r.indexOf(c);return p===-1&&a===-1?0:p===-1?1:a===-1?-1:p-a});return t.jsx("div",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const c=o.get(l);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),t.jsx("span",{children:c.map((p,a)=>t.jsxs("span",{children:[a>0&&t.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},a))})]},l)})})}function fc({data:e}){const n=e.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.push(t.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:i("link-fg"),border:`1px solid ${i("link-fg")}40`,borderRadius:"3px",textDecoration:"none",background:`${i("link-fg")}08`},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),o.length===0?null:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function mc({works:e,transport:n,onNavigate:o,renderLink:r}){const s=me(),{convert:l}=V(),c=Fe(),[p,a]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let x=!1;const g=e.map(w=>w.work_id);return(async()=>{const w=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(g);let $=!0;for(let k=0;k<g.length;k++){const _=v[k];_!=null&&_.title?w.set(g[k],_.title):_!=null&&_.primary_name?w.set(g[k],_.primary_name):$=!1}if($)return w}catch{}const y=[...g],j=8,h=new Array(j).fill(0).map(async()=>{for(;y.length;){const v=y.shift();if(!v)break;if(!w.has(v))try{if(n.getEntry){const _=await n.getEntry(v);if(_!=null&&_.title){w.set(v,_.title);continue}}const $=await n.getItem(v),k=$&&($.title||$.primary_name)||v;w.set(v,k)}catch{w.set(v,v)}}});return await Promise.all(h),w})().then(w=>{x||a(w)}),()=>{x=!0}},[e,n]);const d=new Map;for(const x of e){const g=x.role||"";d.has(g)||d.set(g,[]),d.get(g).push(x)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],m=[...d.keys()].sort((x,g)=>{const b=u.indexOf(x),w=u.indexOf(g);return b===-1&&w===-1?x.localeCompare(g):b===-1?1:w===-1?-1:b-w});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:i("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:i("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),m.map(x=>{const g=d.get(x);return t.jsxs("div",{style:{marginBottom:"8px"},children:[x&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"2px"},children:[l(x)," ",t.jsxs("span",{style:{color:i("desc-fg")},children:["(",g.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:x?"16px":"0",listStyle:x?"disc":"none",fontSize:"14px",lineHeight:1.8},children:g.map((b,w)=>{const y=l(p.get(b.work_id)||b.work_id);return r?t.jsx("li",{children:r(b.work_id,y)},w):o?t.jsx("li",{children:t.jsx("a",{href:c(b.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),o(b.work_id))},style:{color:i("link-fg"),textDecoration:"underline",cursor:"pointer"},children:y})},w):t.jsx("li",{children:y},w)})})]},x)})]})}const ls=({data:e,transport:n,onNavigate:o,renderLink:r,headerExtra:s,hideHeader:l})=>{var m;const c=me(),{convert:p}=V();let a=!1;try{a=$e.extractStatus(e.id)==="draft"}catch{}const d=pc(e),u=e.subtype==="people"?"人物":e.subtype==="place"?"地名":e.subtype==="dynasty"?"朝代":e.subtype==="anonymous"?"佚名":e.subtype==="collective"?"集体":e.subtype;return t.jsxs("div",{children:[!l&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:i("fg")},children:[p(e.primary_name),t.jsx(uc,{data:e})]}),s]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:i("type-entity"),border:`1px solid color-mix(in srgb, ${i("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${i("type-entity")} 3%, transparent)`},children:c.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),a&&t.jsx("span",{style:{padding:"1px 6px",background:i("warn-bg"),border:`1px solid ${i("warn-border")}`,borderRadius:"2px",color:i("warn-fg")},children:c.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),d&&t.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:i("widget-bg"),border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(xc,{alt_names:e.alt_names}),t.jsx(fc,{data:e}),((m=e.description)==null?void 0:m.text)&&t.jsx("p",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(e.description.text)}),e.works&&e.works.length>0&&t.jsx(mc,{works:e.works,transport:n,onNavigate:o,renderLink:r})]})},gc=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function hc(e){const n=e.search(gc);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const as={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>{let o=e,r="",s=n;if(e&&typeof n=="string"&&(n===e||n===bc(e))){const[l,c]=hc(n);c&&(o=encodeURI(l),s=l,r=c)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:o,target:o!=null&&o.startsWith("http")?"_blank":void 0,rel:o!=null&&o.startsWith("http")?"noopener noreferrer":void 0,style:{color:i("link")},children:s}),r]})},code:({children:e})=>t.jsx("code",{style:{background:i("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function bc(e){try{return decodeURI(e)}catch{return e}}const yc={...as,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},dt=({text:e,plainStrong:n,style:o,className:r})=>{const{convert:s}=V(),l=n?yc:as;return t.jsx("div",{className:r,style:o,children:t.jsx(la,{remarkPlugins:[aa],components:l,children:s(e)})})},jc=["〇","一","二","三","四","五","六","七","八","九"],Do=["","十","百","千"];function cs(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),o=n.length;let r="",s=!1;for(let l=0;l<o;l++){const c=parseInt(n[l]),p=o-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=Do[p]:r+=jc[c]+Do[p])}return r}function ds(e){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:e,border:`1px solid color-mix(in srgb, ${e} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${e} 3%, transparent)`}}const vc={book:i("type-book"),work:i("type-work"),collection:i("type-collection"),entity:i("type-entity")};function kc({type:e}){const n=me();return t.jsx("span",{style:ds(vc[e]),children:n.indexType[e]})}function wc({isDraft:e}){const n=me(),o=i(e?"status-draft":"status-official");return t.jsx("span",{style:ds(o),children:e?n.status.draft:n.status.official})}function Sc({id:e}){const n=me(),[o,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:i("desc-fg"),background:i("bg-subtle"),border:`1px solid ${i("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:i("fg")},children:e}),t.jsx("span",{onClick:s,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function qe({children:e,extra:n}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("desc-fg"),letterSpacing:"1px"},children:e}),t.jsx("span",{style:{flex:1}}),n]})}function rt({label:e,children:n}){return t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[t.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:e}),t.jsx("span",{style:{color:i("fg")},children:n})]})}function ps({authors:e,type:n,onNavigate:o,renderLink:r}){const{convert:s}=V();return t.jsx("span",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.6},children:e.map((l,c)=>{const p=s(l.name),a=l.entity_id?t.jsx(et,{id:l.entity_id,label:p,onNavigate:o,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:p});return t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),a,l.role&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},c)})})}function et({id:e,label:n,onNavigate:o,renderLink:r}){const s=Fe();return r?t.jsx(t.Fragment,{children:r(e,n)}):o?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(e))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`,paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{children:n||e})}function $c({id:e,title:n,edition:o,type:r,isDraft:s,authors:l,volumeText:c,meta:p,headerExtra:a,onNavigate:d,renderLink:u}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:i("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,o&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:o}),c&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:c})]}),a&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(kc,{type:r}),t.jsx(wc,{isDraft:s}),t.jsx(Sc,{id:e})]}),((l==null?void 0:l.length)||p.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&t.jsx(ps,{authors:l,type:r,onNavigate:d,renderLink:u}),p]})]})}function us({items:e,label:n,showMeta:o,onNavigate:r,renderLink:s}){const l=me(),{convert:c}=V();if(!e.length)return null;const[p,a]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(qe,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((d,u)=>{const m=p===u;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...m?{boxShadow:i("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>a(m?null:u),style:{padding:"8px 12px",background:i("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.15s",transform:m?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:c(d.source)}),!m&&o&&d.title_info&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c(d.title_info)}),d.source_bid&&t.jsx("span",{onClick:x=>x.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(et,{id:d.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),m&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${i("widget-border")}`},children:[o&&(d.title_info||d.author_info||d.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&t.jsx(rt,{label:l.label.titleInfo,children:c(d.title_info)}),d.author_info&&t.jsx(rt,{label:l.label.authorInfo,children:c(d.author_info)}),d.edition&&t.jsx(rt,{label:l.label.edition,children:c(d.edition)})]}),d.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${i("primary")}`,background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:c(d.summary)})]}),d.comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(d.comment)})]}),d.additional_comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(d.additional_comment)})]})]})]},u)})})]})}function _c({items:e,onNavigate:n,renderLink:o}){const r=me();return t.jsx(us,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function xs({items:e,onNavigate:n,renderLink:o}){const r=me();return t.jsx(us,{items:e,label:r.section.emendated,onNavigate:n,renderLink:o})}function fs({label:e,items:n}){const{convert:o}=V();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(qe,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const l=typeof r=="string"?r:r.book_title;return t.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:i("fg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:o(l)},s)})})]}):null}function zc({items:e}){const n=me();return t.jsx(fs,{label:n.section.aliases,items:e})}function Cc({items:e}){const n=me();return t.jsx(fs,{label:n.section.attachedTexts,items:e})}function Tc({items:e}){const n=me(),{convert:o}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(qe,{children:n.section.appendix}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:e.map((r,s)=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:i("fg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:["《",o(r.book_title),"》",r.n_juan!=null&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function Ic({items:e}){const n=me(),{convert:o}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(qe,{children:n.section.locationHistory}),t.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[t.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:i("widget-border")}}),e.map((r,s)=>t.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[t.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:i("primary"),border:`1.5px solid ${i("input-bg")}`}}),t.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:i("fg")},children:o(r.name)}),r.description&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),marginLeft:"8px"},children:o(r.description)})]},s))]})]}):null}function Ec({items:e}){const n=me(),{convert:o}=V();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(qe,{children:n.section.historyOverview}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map((r,s)=>t.jsxs("div",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[t.jsx("span",{style:{position:"absolute",left:0,top:0,color:i("desc-fg")},children:"·"}),o(r)]},s))})]}):null}function Ho({title:e,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:l}=V(),[c,p]=f.useState([]);return f.useEffect(()=>{if(!n.length){p([]);return}if(!o){p(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>o.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{a||p(d)}),()=>{a=!0}},[n,o]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(qe,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",n.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(c.length?c:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${l(a.title)||a.id}(${l(a.edition)})`:l(a.title)||void 0;return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),transition:"border-color 0.15s"},children:t.jsx(et,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function Un({book:e,onNavigate:n,renderLink:o}){const r=me(),{convert:s}=V(),[l,c]=f.useState(!1),p=e.resources&&e.resources.length>0,a=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:i("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${i("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(et,{id:e.id,label:a,onNavigate:n,renderLink:o})}),p&&t.jsx("span",{onClick:()=>c(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:i("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),p&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(Ci,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Rc({ids:e,workData:n,transport:o,onNavigate:r,renderLink:s,footer:l}){const c=me(),{convert:p}=V(),[a,d]=f.useState([]);if(f.useEffect(()=>{if(!e.length){d([]);return}if(!o){d(e.map(w=>({id:w})));return}let b=!1;return Promise.all(e.map(w=>o.getItem(w).then(y=>({id:w,title:y?y.title:void 0,edition:y?y.edition:void 0,resources:y?y.resources:void 0,resource_groups:y?y.resource_groups:void 0})).catch(()=>({id:w})))).then(w=>{b||d(w)}),()=>{b=!0}},[e,o]),!e.length)return null;const u=a.length?a:e.map(b=>({id:b})),m=new Map(u.map(b=>[b.id,b])),x=n==null?void 0:n.version_graph,g=Nc(e,x);return t.jsxs(t.Fragment,{children:[t.jsxs(qe,{children:[c.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,g.useGrouping?t.jsxs(t.Fragment,{children:[g.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:g.coreIds.map(b=>{const w=m.get(b);return w?t.jsx(Un,{book:w,onNavigate:r,renderLink:s},b):null})}),g.groupedIds.map(b=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${i("widget-border")}`,borderRadius:6,background:i("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:i("fg"),userSelect:"none"},children:[p(b.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:i("desc-fg"),fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:i("desc-fg"),fontWeight:400},children:p(b.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(w=>{const y=m.get(w);return y?t.jsx(Un,{book:y,onNavigate:r,renderLink:s},w):null})})]},b.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(b=>t.jsx(Un,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Nc(e,n){var y,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const o=(y=n.collections)==null?void 0:y[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.book_ids)??[],l=r.length>0||s.length>0,c=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&c.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...c]),d=h=>{if(a.has(h))return!0;const v=n.node_groups[h];return v!=null&&p.has(v)},u=[],m=new Map,x=[];for(const h of e)if(!((j=n.excluded_books)!=null&&j.includes(h)))if(d(h))u.push(h);else{const v=n.node_groups[h];v?(m.has(v)||m.set(v,[]),m.get(v).push(h)):x.push(h)}if(x.length+[...m.values()].reduce((h,v)=>h+v.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(h=>[h.id,h])),w=[...m.entries()].map(([h,v])=>{const $=b.get(h);return{id:h,label:($==null?void 0:$.label)??h,description:$==null?void 0:$.description,ids:v}});return x.length>0&&w.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:w}}function Lc({workData:e,onNavigate:n,renderLink:o}){var c,p,a,d;const r=me(),{convert:s}=V(),l=!!((c=e.description)!=null&&c.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:i("input-bg"),marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?`1px solid ${i("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`},children:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:t.jsx(et,{id:e.id,label:s(e.title),onNavigate:n,renderLink:o})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:s(e.measure_info)}):((p=e.juan_count)==null?void 0:p.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[cs(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(ps,{authors:e.authors,type:"work",onNavigate:n,renderLink:o})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((a=e.description)==null?void 0:a.text)&&t.jsx(dt,{text:e.description.text,style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(d=e.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:t.jsx(rt,{label:r.label.parentWork,children:t.jsx(et,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Bc({items:e,onNavigate:n,renderLink:o}){const r=me(),{convert:s}=V();return e.length?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(l=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid color-mix(in srgb, ${i("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${i("type-collection")} 3%, transparent)`},children:[t.jsx("span",{style:{fontSize:"11px",color:i("type-collection")},children:r.indexType.collection}),t.jsx(et,{id:l.id,label:s(l.title)||l.id,onNavigate:n,renderLink:o}),l.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"2px"},children:Qe(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Ei=({data:e,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:c,className:p,style:a})=>{var H,L,M,F,X,U,T,ce;const d=me(),{convert:u}=V(),[m,x]=f.useState(null),[g,b]=f.useState(!1),[w,y]=f.useState(null),[j,h]=f.useState(null),[v,$]=f.useState([]),k=e||m;if(f.useEffect(()=>{if(e||!n||!o)return;let B=!1;return b(!0),y(null),o.getItem(n).then(D=>{B||(D?x(D):y(d.misc.notFoundEntry))}).catch(D=>{B||y(D instanceof Error?D.message:d.misc.loadFailed)}).finally(()=>{B||b(!1)}),()=>{B=!0}},[e,n,o]),f.useEffect(()=>{if(!k||!o){h(null),$([]);return}let B=!1;const D=k.type==="book"||k.type==="collection"?k.work_id:void 0;if(D?o.getItem(D).then(A=>{!B&&A&&A.type==="work"&&h(A)}).catch(()=>{}):h(null),k.type==="book"){const A=k;A.contained_in&&A.contained_in.length>0?Promise.all(A.contained_in.map(ee=>{const de=typeof ee=="string"?ee:ee.id,G=typeof ee=="string"?void 0:ee.volume_index;return o.getItem(de).then(q=>({id:de,title:q&&q.title||de,volume_index:G})).catch(()=>({id:de,title:de,volume_index:G}))})).then(ee=>{B||$(ee)}):$([])}else $([]);return()=>{B=!0}},[k,o]),g)return t.jsx("div",{className:p,style:{...a,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((B,D)=>t.jsx("div",{style:{height:D===1?"32px":"16px",width:`${B}px`,background:i("widget-border"),borderRadius:"4px",opacity:.4}},D))})});if(w)return t.jsx("div",{className:p,style:{...a,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:w});if(!k)return null;if(k.type==="entity")return t.jsx("div",{className:p,style:a,children:t.jsx(ls,{data:k,transport:o,onNavigate:r,renderLink:s,headerExtra:l})});const _=k.type==="book"?k:null,S=k.type==="collection"?k:null,z=k.type==="work"?k:null;let N=!1;try{N=$e.extractStatus(k.id)==="draft"}catch{}let R="";k.measure_info?R=u(k.measure_info):(H=k.juan_count)!=null&&H.number?R=cs(k.juan_count.number)+d.unit.juan:(L=k.juan_count)!=null&&L.description&&(R=u(k.juan_count.description));const C=[];return(M=k.publication_info)!=null&&M.year&&C.push(t.jsx(rt,{label:d.label.year,children:k.publication_info.year},"year")),(F=k.current_location)!=null&&F.name&&C.push(t.jsx(rt,{label:d.label.currentLocation,children:u(k.current_location.name)},"loc")),(X=k.page_count)!=null&&X.description&&C.push(t.jsx(rt,{label:d.label.pageCount,children:k.page_count.description},"page")),_!=null&&_.edition&&C.push(t.jsx(rt,{label:d.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&C.push(t.jsx(rt,{label:d.label.parentWork,children:t.jsx(et,{id:z.parent_work.id,label:u(z.parent_work.title),onNavigate:r,renderLink:s})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&C.push(t.jsx(rt,{label:d.label.parentWork,children:z.parent_works.map((B,D)=>t.jsxs("span",{children:[D>0&&"、",t.jsx(et,{id:B,onNavigate:r,renderLink:s})]},B))},"pws")),t.jsxs("div",{className:p,style:a,children:[t.jsx($c,{id:k.id,title:u(k.title),edition:k.edition?u(k.edition):void 0,type:k.type,isDraft:N,authors:k.authors,volumeText:R,meta:C,headerExtra:l,onNavigate:r,renderLink:s}),((U=k.description)==null?void 0:U.text)&&t.jsx(dt,{text:k.description.text,style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),k.appendix&&k.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:k.appendix.map((B,D)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:i("bg-subtle"),borderRadius:4,border:`1px solid ${i("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:i("muted")},children:u(B.title)}),t.jsx(dt,{text:B.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:i("fg")}})]},D))}),v.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(qe,{children:d.section.containedIn}),t.jsx(Bc,{items:v,onNavigate:r,renderLink:s})]}),j&&t.jsxs(t.Fragment,{children:[t.jsx(qe,{children:d.section.belongsToWork}),t.jsx(Lc,{workData:j,onNavigate:r,renderLink:s})]}),k.additional_works&&k.additional_works.length>0&&t.jsx(Tc,{items:k.additional_works}),k.additional_titles&&k.additional_titles.length>0&&t.jsx(zc,{items:k.additional_titles}),k.attached_texts&&k.attached_texts.length>0&&t.jsx(Cc,{items:k.attached_texts}),k.indexed_by&&k.indexed_by.length>0&&t.jsx(_c,{items:k.indexed_by,onNavigate:r,renderLink:s}),k.emendated_by&&k.emendated_by.length>0&&t.jsx(xs,{items:k.emendated_by,onNavigate:r,renderLink:s}),k.resources&&k.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(qe,{children:d.section.resources}),t.jsx(Ci,{items:k.resources,resourceGroups:k.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&t.jsx(Ic,{items:_.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&t.jsx(Ec,{items:S.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&t.jsx(Ho,{title:d.section.relatedVersions,ids:_.related_books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&t.jsx(Ho,{title:d.section.containedBooks,ids:S.books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(qe,{children:[d.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",S.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(B=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:t.jsx(et,{id:B.id,label:u(B.title),onNavigate:r,renderLink:s})},B.id))})]}),(((T=z==null?void 0:z.books)==null?void 0:T.length)||0)+(((ce=z==null?void 0:z.collections)==null?void 0:ce.length)||0)>0&&t.jsx(Rc,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z??void 0,transport:o,onNavigate:r,renderLink:s,footer:c}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const B=[],D=z.related_works.filter(ie=>ie.relation==="part_of"),A=z.related_works.filter(ie=>ie.relation==="has_part"),ee=z.related_works.filter(ie=>ie.relation==="has_adaptation"),de=z.related_works.filter(ie=>ie.relation==="text_carried_by"),G=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),q=z.related_works.filter(ie=>!ie.relation||!G.has(ie.relation));return D.length>0&&B.push({label:d.section.belongsToWork,items:D}),A.length>0&&B.push({label:d.section.containedWorks,items:A}),ee.length>0&&B.push({label:d.section.adaptations,items:ee}),de.length>0&&B.push({label:d.section.derivativeWorks,items:de}),q.length>0&&B.push({label:d.section.relatedWorks,items:q}),B.map(ie=>t.jsxs("div",{children:[t.jsxs(qe,{children:[ie.label,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",ie.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:ie.items.map(pe=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:t.jsx(et,{id:pe.id,label:u(pe.title),onNavigate:r,renderLink:s})},pe.id))})]},ie.label))})()]})};function Ac({data:e}){const n=me(),{convert:o}=V(),{stats:r}=e,s=r.processed_volumes??r.total_found_volumes,l=s!=null&&e.total_volumes>0?Math.round(s/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:o(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"6px"},children:o(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:i("desc-fg")},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:i("fg")},children:e.total_volumes})," ",n.unit.volume]}),l!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:i("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:i("fg")},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&t.jsxs("span",{children:[n.catalog.matched," ",t.jsx("strong",{style:{color:i("fg")},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&t.jsxs("span",{children:[n.catalog.unmatched," ",t.jsx("strong",{style:{color:i("missing-fg")},children:r.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:i("desc-fg")},children:[n.catalog.source," ",e.source]})]})}function Wc({sections:e,activeSection:n,onSelect:o}){const r=me();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>o(null),style:Go(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>o(s.name),style:Go(n===s.name),children:[s.name,s.volume_range&&t.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function Go(e){return{padding:"4px 12px",border:e?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${i("primary")} 8%, transparent)`:"transparent",color:i(e?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Mc({id:e,label:n,onNavigate:o,renderLink:r}){const s=Fe();return r?t.jsx(t.Fragment,{children:r(e,n)}):o?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(e))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:n||e})}function Fc(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const o=e[0],r=e[e.length-1];return r-o+1===e.length?`${o}–${r}`:e.length<=3?e.join(", "):`${o}–${r} (${e.length}${n})`}function Uo({book:e,onNavigate:n,renderLink:o,showVolumes:r}){const s=me(),{convert:l}=V(),c=e.book_id||e.work_id,p=r&&e.volumes.length>0?Fc(e.volumes,s.unit.volume):null,a=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${i("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:i("desc-fg"),textAlign:"right"},children:p}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:i("fg")},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(d=>l(d)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:i(a?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),c&&t.jsx(Mc,{id:c,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!c&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const Ri=({data:e,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:l,style:c})=>{const p=me(),[a,d]=f.useState(null),[u,m]=f.useState(!1),[x,g]=f.useState(null),[b,w]=f.useState(null),[y,j]=f.useState(""),h=e||a;f.useEffect(()=>{if(e||!n||!(o!=null&&o.getCollectionCatalog))return;let S=!1;return m(!0),g(null),o.getCollectionCatalog(n).then(z=>{S||(z?d(z):g(p.catalog.notFound))}).catch(z=>{S||g(z instanceof Error?z.message:p.catalog.loadFailed)}).finally(()=>{S||m(!1)}),()=>{S=!0}},[e,n,o,p]);const v=(h==null?void 0:h.sections)&&h.sections.length>0,$=f.useMemo(()=>{if(!h)return!1;if(h.volume_index&&Object.keys(h.volume_index).length>0)return!0;const S=h.books.map(N=>N.volumes[0]).filter(N=>N!=null);return new Set(S).size<S.length},[h]),k=f.useMemo(()=>{if(!h)return[];let S=h.books;if(b&&(S=S.filter(z=>z.section===b)),y.trim()){const z=y.trim().toLowerCase();S=S.filter(N=>N.title.toLowerCase().includes(z)||N.sub_items&&N.sub_items.some(R=>R.toLowerCase().includes(z))||N.edition&&N.edition.toLowerCase().includes(z))}return S},[h,b,y]),_=f.useMemo(()=>{if(!$)return null;const S=[],z=new Map;for(const R of k){if(!R.volumes||R.volumes.length===0)continue;const C=R.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(R)}const N=[...z.keys()].sort((R,C)=>R-C);for(const R of N)S.push({volume:R,books:z.get(R)});return S},[k,$]);return u?t.jsx("div",{className:l,style:{...c,padding:"24px"},children:t.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):x?t.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:x}):h?t.jsxs("div",{className:l,style:c,children:[t.jsx(Ac,{data:h}),v&&t.jsx(Wc,{sections:h.sections,activeSection:b,onSelect:w}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:y,onChange:S=>j(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:i("desc-fg")},children:[k.length," ",p.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[_?_.map((S,z)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:i("bg"),borderBottom:`1px solid ${i("widget-border")}`,fontSize:"12px",fontWeight:600,color:i("desc-fg"),position:"sticky",top:0,zIndex:1},children:Qe(p.catalog.volume,{n:S.volume})}),S.books.map((N,R)=>t.jsx(Uo,{book:N,onNavigate:r,renderLink:s,showVolumes:N.volumes.length>1},`${S.volume}-${R}`))]},`${S.volume}-${z}`)):k.map((S,z)=>t.jsx(Uo,{book:S,onNavigate:r,renderLink:s,showVolumes:!0},z)),k.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},kt=()=>{const[e,n]=f.useState(1);return f.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:i("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(e)})},ms=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Pc={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Oe(e){return Pc[e]??e}const Et=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],Rt={熹平:172,建安:196,黃初:220,正始:240,廣政:938,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,開成:836,會昌:841,咸通:860,建隆:960,太平興國:976,咸平:998,天禧:1017,慶曆:1041,皇祐:1049,嘉祐:1056,治平:1064,熙寧:1068,元豐:1078,元祐:1086,紹聖:1094,崇寧:1102,大觀:1107,政和:1111,宣和:1119,建炎:1127,紹興:1131,隆興:1163,乾道:1165,淳熙:1174,紹熙:1190,慶元:1195,嘉泰:1201,開禧:1205,嘉定:1208,寶慶:1225,紹定:1228,端平:1234,嘉熙:1237,淳祐:1241,寶祐:1253,開慶:1259,景定:1260,咸淳:1265,大定:1161,明昌:1190,至元:1264,大德:1297,皇慶:1312,延祐:1314,泰定:1324,天曆:1328,至順:1330,至正:1341,洪武:1368,永樂:1403,宣德:1426,正統:1436,景泰:1450,天順:1457,成化:1465,弘治:1488,正德:1506,嘉靖:1522,隆慶:1567,萬曆:1573,泰昌:1620,天啟:1621,崇禎:1628,弘光:1645,隆武:1645,紹武:1646,永曆:1647,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,正保:1644,慶安:1648,承應:1652,明曆:1655,萬治:1658,寬文:1661,延寶:1673,天和:1681,貞享:1684,元祿:1688,寶永:1704,享保:1716,元文:1736,寬保:1741,延享:1744,寬延:1748,寶曆:1751,明和:1764,安永:1772,天明:1781,寬政:1789,享和:1801,文化:1804,文政:1818,天保:1830,弘化:1844,嘉永:1848,安政:1854,萬延:1860,文久:1861,元治:1864,慶應:1865,明治:1868,大正:1912,昭和:1926,天正:1573,文祿:1592,永祿:1558,天文:1532},gs={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function In(e){const n=e.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const o=parseInt(n[1],10);if(o<100||o>2100)return;const r=n[2]?parseInt(n[2],10):void 0;return{from:o,to:r!=null&&r>=o&&r<=2100?r:void 0}}function Oc(e){return e>=1950?"":e>=1912?"民國":e>=1645?"清":e>=1368?"明":e>=1279?"元":e>=960?"宋":e>=907?"五代":e>=618?"唐":e>=581?"隋":e>=420?"南北朝":e>=265?"晉":e>=220?"三國":e>=-202?"漢":""}const Dc=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Vo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Ni(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(Vo))if(n.startsWith(s))return Vo[s];const o=Oe(n);if(ht[o]!=null)return o;const r=ct(n);if(r&&n.length<=r.length+1)return Oe(r)}function gt(e,n){if(n){const o=gs[`${n}|${e}`];if(o!=null)return o}return Rt[e]}const Hc=1911;function Gc(e){const n=Rt[e];if(n==null)return;const o=st[e];let r;for(const[s,l]of Object.entries(Rt))st[s]===o&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const Uc={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function jn(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,o=0,r=!1;for(const l of e){const c=Uc[l];if(c===void 0)return;r=!0,l==="十"?o=(o||1)*10:l==="廿"||l==="卅"?(n+=c,o=0):o>=10?(n+=o+c,o=0):o=o*10+c}const s=n+o;return r&&s>0?s:void 0}function ct(e){for(const n of ms)if(e.startsWith(n))return n}const st={};{const e=(n,o)=>{for(const r of o)st[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function bt(e,n){const o=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(Rt))if(e.includes(r)&&!(o&&st[r]&&st[r]!==o&&gs[`${o}|${r}`]==null))return r}function tn(e){var c,p,a;const n={era:"",reign:"",source:"none"},o=e.dating;if(o!=null&&o.era||o!=null&&o.reign)return{era:o.era??"",reign:o.reign??"",source:o.certainty==="attested"?"catalog":"edition"};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const d=ct(r)??"";return{era:Oe(d),reign:bt(r,d)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const d=In(s);if(d)return{era:Oc(d.from),reign:"",source:"publication"};const u=ct(s)??Ni(s)??((a=Et.find(g=>g.pattern.test(s)))==null?void 0:a.era)??"",m=bt(s,u)??"",x=u||(m?st[m]??"":"");if(x||m)return{era:Oe(x),reign:m,source:"publication"}}const l=e.edition||e.title||"";if(l){const d=ct(l);if(d)return{era:Oe(d),reign:bt(l,d)??"",source:"edition"};const u=Et.find(m=>m.pattern.test(l));if(u)return{era:Oe(u.era),reign:bt(l,u.era)??u.reign??"",source:"edition"}}return n}function En(e){var r,s,l,c,p,a,d,u,m;if(((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;if(typeof((s=e.lineage)==null?void 0:s.year)=="number")return e.lineage.year;const n=(l=e.publication_info)==null?void 0:l.year;if(n){const x=In(n);if(x)return x.from}const o=[(c=e.lineage)==null?void 0:c.year_text,(p=e.publication_info)==null?void 0:p.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const x of o){const g=((a=e.publication_info)==null?void 0:a.year)||((d=e.lineage)==null?void 0:d.year_text);if(g&&x!==g&&(ct(g)||Ni(g)))break;const b=x.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??x.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const v=parseInt(b[1],10);if(v>=100&&v<=2100)return v}const w=x.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(w){const v=ct(x);if(!v||Oe(v)==="民國"){const k=jn(w[1]);if(k!=null&&k>=1&&k<=120)return Hc+k}}const y=ct(x)??((u=Et.find(v=>v.pattern.test(x)))==null?void 0:u.era),j=y?Oe(y):void 0,h=bt(x,j)??(ct(x)||(m=Et.find(v=>v.pattern.test(x)))==null?void 0:m.reign);if(h){const v=gt(h,j);if(v==null)continue;const $=x.indexOf(h),k=$>=0?x.slice($+h.length):"",_=k.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??k.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=_?jn(_[1]):void 0;return v+(S?S-1:0)}}}function Li(e){var c,p,a,d,u,m;const n=(c=e.dating)==null?void 0:c.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const o=(p=e.lineage)==null?void 0:p.year_range;if(o&&o.length===2)return{from:o[0],to:o[1]};const r=(a=e.lineage)==null?void 0:a.year_text;if(r){const x=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(x){const g=oi[Oe(x[1])],b=ht[Oe(x[2])];if(g!=null&&b!=null)return{from:Math.min(g,b)-20,to:Math.max(g,b)+40}}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const x=In(s);if((x==null?void 0:x.to)!=null)return{from:x.from,to:x.to};const g=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const b=oi[Oe(g[1])],w=ht[Oe(g[2])];if(b!=null&&w!=null)return{from:Math.min(b,w)-20,to:Math.max(b,w)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const x of l){if(!/[間间]/.test(x))continue;const g=ct(x)??Ni(x)??((m=Et.find(y=>y.pattern.test(x)))==null?void 0:m.era),b=g?Oe(g):void 0,w=[];for(const y of Object.keys(Rt))x.includes(y)&&(b&&st[y]&&st[y]!==b||gt(y,b)!=null&&w.push(y));if(w.length===0){const y=x.match(/([一-鿿])([一-鿿])[間间]/);if(y&&b){for(const j of[y[1],y[2]])for(const h of Object.keys(Rt))if(st[h]===b&&!(h[0]!==j&&h[h.length-1]!==j)&>(h,b)!=null){w.push(h);break}}}if(w.length>0){const y=w.map($=>gt($,b)).filter($=>$!=null),j=Math.min(...y),h=w.reduce(($,k)=>gt($,b)>=gt(k,b)?$:k),v=Gc(h)??Vn(b??"")??Math.max(...y);return{from:j,to:v>j?v:Vn(b??st[h]??"")??j}}if(b&&ht[b]!=null)return{from:ht[b],to:Vn(b)??ht[b]}}}const ht={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Vc=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Yc=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,Yo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Ko(e,n){for(const o of ms){const r=e.indexOf(o);if(r<0)continue;if(o.length===1){const a=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(a)&&!bt(e.slice(r),Oe(o)))continue}const s=Oe(o);if(s===n)continue;const l=e.slice(r),c=bt(l,s)??"";let p;if(c){const a=gt(c,s);if(a!=null){const u=l.slice(l.indexOf(c)+c.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),m=u?jn(u[1]):void 0;p=a+(m?m-1:0)}}return{era:s,reign:c,year:p}}for(const o of Et)if(o.pattern.test(e))return{era:Oe(o.era),reign:o.reign??""}}function Kc(e){var j,h,v,$,k;const n=tn(e),o=((j=e.publication_info)==null?void 0:j.year)??"",r=o?In(o):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),c=((h=e.lineage)==null?void 0:h.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(c),a=n.source==="publication"&&Dc.test(o),d=n.source==="publication"&&/[間间]/.test(o),u=c.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let m;l||p||a||d?m=void 0:u?m=parseInt(u[2],10):m=En(e);const x=m==null?Li(e):void 0;let g;n.source==="publication"&&(a||Yo.test(o))?g="uncertain":n.source==="lineage"||n.source==="publication"?g="attested":Yo.test(s)||!n.reign&&m==null?g="uncertain":g="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((v=e.lineage)==null?void 0:v.year_text)??(($=e.lineage)==null?void 0:$.year)??""}」`:`出版著錄「${((k=e.publication_info)==null?void 0:k.year)??""}」`,w={era:n.era,reign:n.reign,year:m,yearRange:x,certainty:g,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const _=c.match(/[、,,]\s*([宋元明清])/);_&&_[1]!==w.era&&(w.laterRepair={era:_[1]})}if(!w.laterRepair&&Yc.test(s)){const _=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);_&&_[1]!==n.era&&(w.laterRepair={era:_[1]})}const y=Vc.find(_=>_.re.test(s));if(y){const _=s.search(y.re),S=s.slice(_),z=Ko(S,n.era)??Ko(s,n.era);z&&(w.basedOn={era:z.era,reign:z.reign,year:z.year,relation:y.relation})}return w}const oi={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Vn(e){return oi[e]}function vn(e){const n=En(e);if(n!=null)return n;const o=Li(e);if(o)return o.from;const r=tn(e).era;return r?ht[r]:void 0}const qo=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function ri(e){const n=qo.indexOf(e);return n===-1?qo.length:n}function qc(e){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of e){const l=s.relation;l==="part_of"?n.belongsTo.push(s):l==="collected_in"?n.collected.push(s):l==="has_part"||l==="contains_text_of"?n.contains.push(s):l==="text_carried_by"||l==="studied_by"||l==="derived_from"||l==="followed_by"||l==="has_adaptation"?n.derivative.push(s):l==="studies"||l==="preceded_by"?n.studies.push(s):n.related.push(s)}const o=[],r=(s,l)=>{n[s].length&&o.push({key:s,labelKey:l,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),o}function Bi(e,n){const o=$i(e||[]),r=new Map,s=[];for(const d of o)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((u,m)=>{const x=g=>g.group_role==="origin"?0:g.group_role==="mirror"?1:2;return x(u)-x(m)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=vt(d),m=u.includes("text"),x=u.includes("image");m&&x?l.textImage.push(d):m?l.text.push(d):x?l.image.push(d):l.physical.push(d)}const p=["text","image","textImage","physical"].filter(d=>l[d].length>0).map(d=>({key:d,items:l[d]})),a=[...r.entries()].map(([d,u])=>{var m,x;return{key:d,label:((m=n==null?void 0:n[d])==null?void 0:m.label)||d,description:(x=n==null?void 0:n[d])==null?void 0:x.description,items:u}});return{buckets:p,mirrors:a,total:o.length}}function Rn(e){const n=[],o=e.metadata||{};o.edition&&n.push(String(o.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const r=Sn(e);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),o.version&&n.push(String(o.version)),n.join(" · ")}function hs(e,n){if(Rn(e)||n.filter(r=>r.name===e.name).length<2)return"";try{const r=new URL(e.url),s=r.searchParams.get("res")||r.searchParams.get("id");if(s)return s;const l=r.pathname.split("/").filter(Boolean).pop();if(l)return decodeURIComponent(l)}catch{}return""}function bs(e,n){var l,c;const o=e.resources||[],r=[],s=[];for(const p of o){const a=vt(p);a.includes("image")&&r.push(p),a.includes("physical")&&s.push(p)}return{id:e.id,name:e.edition||e.title||e.id,era:tn(e),year:En(e),sortYear:vn(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:Jc(e.id,n),group:(c=n==null?void 0:n.node_groups)==null?void 0:c[e.id],hasImage:r.length>0}}function Jc(e,n){var p,a;if(!n)return!1;const o=n.default_collection;if(!o)return!1;const r=(p=n.collections)==null?void 0:p[o];if(((r==null?void 0:r.book_ids)??(o==="core"?n.core_books??[]:[])).includes(e))return!0;const l=(r==null?void 0:r.groups)??[],c=(a=n.node_groups)==null?void 0:a[e];return!!c&&l.includes(c)}function ys(e,n,o={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(a=>!r.has(a.id)).map(a=>bs(a,n));let l=s;o.era&&(l=l.filter(a=>a.era.era===o.era)),o.scanOnly&&(l=l.filter(a=>a.hasImage)),o.sort==="year"?l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=a.r.sortYear,m=d.r.sortYear;return u!=null&&m!=null?u-m||a.i-d.i:u!=null?-1:m!=null?1:a.i-d.i}).map(a=>a.r):l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=m=>(m.important?0:1)*2+(m.hasImage?0:1);return u(a.r)-u(d.r)||a.i-d.i}).map(a=>a.r);const p=[...new Set(s.map(a=>a.era.era).filter(Boolean))].sort((a,d)=>ri(a)-ri(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(a=>a.era.source==="edition")}}function Zc(e,n){var y,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const o=(y=n.collections)==null?void 0:y[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.book_ids)??[],l=r.length>0||s.length>0,c=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&c.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...c]),d=h=>{if(a.has(h))return!0;const v=n.node_groups[h];return v!=null&&p.has(v)},u=[],m=new Map,x=[];for(const h of e)if(!((j=n.excluded_books)!=null&&j.includes(h)))if(d(h))u.push(h);else{const v=n.node_groups[h];v?(m.has(v)||m.set(v,[]),m.get(v).push(h)):x.push(h)}if(x.length+[...m.values()].reduce((h,v)=>h+v.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(h=>[h.id,h])),w=[...m.entries()].map(([h,v])=>{const $=b.get(h);return{id:h,label:($==null?void 0:$.label)??h,description:$==null?void 0:$.description,ids:v}});return x.length>0&&w.push({id:"__other__",label:"其他版本",description:void 0,ids:x}),{useGrouping:!0,coreIds:u,groupedIds:w}}const js=["撰","編","注","校","譯","繪","其他"],Xc=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function Ai(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:o,re:r}of Xc)if(r.test(n))return o;return"其他"}function Wi(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function vs(e){const n=new Map;for(const r of e){const s=Ai(r);n.set(s,(n.get(s)??0)+1)}const o=[{cls:"全部",label:"全部",count:e.length}];for(const r of js){const s=n.get(r);s&&o.push({cls:r,label:r,count:s})}return o.length>2?o:[]}function ks(e,n,o){if(n&&n.books&&n.books.length>0){const s=n.books.map(c=>({id:c.work_id||c.book_id||void 0,title:c.title,section:c.section,volumes:c.volumes||[],subItems:c.sub_items,edition:c.edition,found:c.found_volumes,expected:c.expected_volumes})),l=[...new Set(s.map(c=>c.section).filter(Boolean))];return{rows:s,source:"catalog",sections:l,totalVolumes:n.total_volumes}}return e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(l=>({id:l.id,title:l.title,volumes:Jt(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,c;return{id:s,title:((l=o==null?void 0:o.get(s))==null?void 0:l.title)||s,edition:(c=o==null?void 0:o.get(s))==null?void 0:c.edition,volumes:[]}}),source:"books",sections:[]}}function Jt(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(n=>typeof n=="number");if(typeof e=="string"){const n=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[o,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-o+1)},(s,l)=>o+l)}return e.split(/[,、]/).map(o=>parseInt(o.trim())).filter(o=>!isNaN(o))}return[]}function Nn(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const o=[...e].sort((l,c)=>l-c),r=o[0],s=o[o.length-1];return s-r+1===o.length?`${r}–${s}`:o.length<=3?o.join(", "):`${r}–${s} (${o.length}${n})`}const Qc=["〇","一","二","三","四","五","六","七","八","九"],Jo=["","十","百","千"];function ws(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),o=n.length;let r="",s=!1;for(let l=0;l<o;l++){const c=parseInt(n[l]),p=o-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=Jo[p]:r+=Qc[c]+Jo[p])}return r}function ed(e){return e==null?"":typeof e=="string"?e:e.title??""}function pt(e,n="卷"){var r,s;const o=e;return o.measure_info?o.measure_info:(r=o.juan_count)!=null&&r.number?ws(o.juan_count.number)+n:(s=o.juan_count)!=null&&s.description?o.juan_count.description:""}function Ss(e){var r;if(e.edition_type)return e.edition_type;if((r=e.lineage)!=null&&r.category)return e.lineage.category;const n=e.edition||e.title||"",o=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,l]of o)if(s.test(n))return l;return""}const td="guji_markdown";function si(e){const n=e==null?void 0:e.guji_markdown;if(typeof n!="string")return!1;const o=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!o)return!1;const r=parseInt(o[1],10),s=parseInt(o[2],10);return r>0||s>=2}const nd=/^□\{guess=([^\s{}]+)\}/;function id(e,n){const o=e[n+1];return o!==void 0&&!/[A-Za-z/!?>\s]/.test(o)}function $s(e,n){let o=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
|
|
131
|
-
`)return-1;if(s==="\\"){r++;continue}if(s==="[")o++;else if(s==="]"&&(o--,o===0))return r}return-1}function
|
|
132
|
-
`)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(o===":"&&e.startsWith(":zi[",n)){const r
|
|
133
|
-
`)return null}const a=
|
|
134
|
-
.bim-d-main.bim-d-main-grid { max-width: ${
|
|
130
|
+
}`,xs={color:"inherit",textDecoration:"none"},hc=({snippet:e})=>{const{convert:n}=X();return t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.6},children:Ii(e).map((o,r)=>o.marked?t.jsx("mark",{style:{background:i("highlight-bg"),color:i("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(o.text)},r):t.jsx(x.Fragment,{children:n(o.text)},r))})},bc=({entry:e,selected:n,onClick:o,getConfig:r,query:s})=>{const l=ge(),{convert:c}=X(),p=c(e.title||e.primary_name||e.id),a=e.measure_info?c(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${l.unit.juan}`:"",d=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&d.length?d.find(g=>{const b=typeof g=="string"?g:g==null?void 0:g.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,m=i("cover-accent"),f=Fe();return t.jsxs("a",{href:f(e.id),onClick:g=>o(e,g),className:"bim-result-card",style:{...xs,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:i("bg"),border:n?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[t.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${m} 50%, ${i("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${m} 14%, ${i("bg")}), color-mix(in srgb, ${m} 7%, ${i("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[t.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${m} 45%, transparent)`}}),t.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:m},children:Array.from(p).map((g,b)=>t.jsx("span",{children:g},b))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:i("fg")},children:p}),a&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:a})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",c(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:c(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",c(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",c(e.era),"〕"]}),e.edition&&t.jsx("span",{children:c(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[l.search.alias,":",c(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(hc,{snippet:e.descriptionSnippet}),t.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[t.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:[t.jsx(Ht,{type:e.type,size:8})," ",r(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.imageResource})]})]})]})},Yo=({entry:e,selected:n,onClick:o,getConfig:r,query:s,onRemove:l})=>{const c=ge(),{convert:p}=X(),a=[...e.additional_titles||[],...e.attached_texts||[]],d=s&&a.length?a.find(m=>{const f=typeof m=="string"?m:m==null?void 0:m.book_title;return f==null?void 0:f.toLowerCase().includes(s.toLowerCase())}):void 0,u=Fe();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("a",{href:u(e.id),onClick:m=>o(e,m),className:"bim-result-card",style:{...xs,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(Ht,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:i("desc-fg"),lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg")},children:p(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{children:c.misc.textResource}),e.has_image&&t.jsx("span",{children:c.misc.imageResource})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",p(e.era),"〕"]}),e.edition&&p(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:p(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[e.juan_count,c.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",p(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:p(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",p(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),d&&t.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:[c.search.alias,":",p(d)]})]}),!l&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&t.jsx("button",{type:"button",onClick:()=>l(e.id),title:c.search.removeFromRecent,"aria-label":c.search.removeFromRecent,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},yc=({id:e,onRemove:n,t:o})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${i("widget-border")}`,background:i("input-bg"),opacity:.6},children:[t.jsx("span",{style:{fontSize:"16px"},children:"❓"}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:"13px",color:i("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:o.search.itemNotFound})]}),t.jsx("button",{onClick:()=>n(e),title:o.search.removeFromRecent,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function jc(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 vc({data:e}){const{convert:n}=X(),{dynasty:o,birth_year:r,death_year:s}=e,l=[];return o&&l.push(`〔${n(o)}〕`),r!==void 0&&s!==void 0?l.push(`${r}—${s}`):r!==void 0?l.push(`${r}—?`):s!==void 0&&l.push(`?—${s}`),l.length===0?null:t.jsx("span",{style:{fontSize:"14px",color:i("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function kc({alt_names:e}){const{convert:n}=X(),o=new Map;for(const l of e){const c=l.type||"別名";o.has(c)||o.set(c,[]),o.get(c).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((l,c)=>{const p=r.indexOf(l),a=r.indexOf(c);return p===-1&&a===-1?0:p===-1?1:a===-1?-1:p-a});return t.jsx("div",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const c=o.get(l);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),t.jsx("span",{children:c.map((p,a)=>t.jsxs("span",{children:[a>0&&t.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},a))})]},l)})})}function wc({data:e}){const n=e.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.push(t.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:i("link-fg"),border:`1px solid ${i("link-fg")}40`,borderRadius:"3px",textDecoration:"none",background:`${i("link-fg")}08`},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),o.length===0?null:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function Sc({works:e,transport:n,onNavigate:o,renderLink:r}){const s=ge(),{convert:l}=X(),c=Fe(),[p,a]=x.useState(new Map);x.useEffect(()=>{if(!n)return;let f=!1;const g=e.map(w=>w.work_id);return(async()=>{const w=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(g);let _=!0;for(let k=0;k<g.length;k++){const $=v[k];$!=null&&$.title?w.set(g[k],$.title):$!=null&&$.primary_name?w.set(g[k],$.primary_name):_=!1}if(_)return w}catch{}const y=[...g],j=8,h=new Array(j).fill(0).map(async()=>{for(;y.length;){const v=y.shift();if(!v)break;if(!w.has(v))try{if(n.getEntry){const $=await n.getEntry(v);if($!=null&&$.title){w.set(v,$.title);continue}}const _=await n.getItem(v),k=_&&(_.title||_.primary_name)||v;w.set(v,k)}catch{w.set(v,v)}}});return await Promise.all(h),w})().then(w=>{f||a(w)}),()=>{f=!0}},[e,n]);const d=new Map;for(const f of e){const g=f.role||"";d.has(g)||d.set(g,[]),d.get(g).push(f)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],m=[...d.keys()].sort((f,g)=>{const b=u.indexOf(f),w=u.indexOf(g);return b===-1&&w===-1?f.localeCompare(g):b===-1?1:w===-1?-1:b-w});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:i("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:i("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),m.map(f=>{const g=d.get(f);return t.jsxs("div",{style:{marginBottom:"8px"},children:[f&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"2px"},children:[l(f)," ",t.jsxs("span",{style:{color:i("desc-fg")},children:["(",g.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:f?"16px":"0",listStyle:f?"disc":"none",fontSize:"14px",lineHeight:1.8},children:g.map((b,w)=>{const y=l(p.get(b.work_id)||b.work_id);return r?t.jsx("li",{children:r(b.work_id,y)},w):o?t.jsx("li",{children:t.jsx("a",{href:c(b.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),o(b.work_id))},style:{color:i("link-fg"),textDecoration:"underline",cursor:"pointer"},children:y})},w):t.jsx("li",{children:y},w)})})]},f)})]})}const fs=({data:e,transport:n,onNavigate:o,renderLink:r,headerExtra:s,hideHeader:l})=>{var m;const c=ge(),{convert:p}=X();let a=!1;try{a=je.extractStatus(e.id)==="draft"}catch{}const d=jc(e),u=e.subtype==="people"?"人物":e.subtype==="place"?"地名":e.subtype==="dynasty"?"朝代":e.subtype==="anonymous"?"佚名":e.subtype==="collective"?"集体":e.subtype;return t.jsxs("div",{children:[!l&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:i("fg")},children:[p(e.primary_name),t.jsx(vc,{data:e})]}),s]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:i("type-entity"),border:`1px solid color-mix(in srgb, ${i("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${i("type-entity")} 3%, transparent)`},children:c.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),a&&t.jsx("span",{style:{padding:"1px 6px",background:i("warn-bg"),border:`1px solid ${i("warn-border")}`,borderRadius:"2px",color:i("warn-fg")},children:c.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),d&&t.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:i("widget-bg"),border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(kc,{alt_names:e.alt_names}),t.jsx(wc,{data:e}),((m=e.description)==null?void 0:m.text)&&t.jsx("p",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(e.description.text)}),e.works&&e.works.length>0&&t.jsx(Sc,{works:e.works,transport:n,onNavigate:o,renderLink:r})]})},$c=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function _c(e){const n=e.search($c);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const ms={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>{let o=e,r="",s=n;if(e&&typeof n=="string"&&(n===e||n===Cc(e))){const[l,c]=_c(n);c&&(o=encodeURI(l),s=l,r=c)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:o,target:o!=null&&o.startsWith("http")?"_blank":void 0,rel:o!=null&&o.startsWith("http")?"noopener noreferrer":void 0,style:{color:i("link")},children:s}),r]})},code:({children:e})=>t.jsx("code",{style:{background:i("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function Cc(e){try{return decodeURI(e)}catch{return e}}const zc={...ms,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},ft=({text:e,plainStrong:n,style:o,className:r})=>{const{convert:s}=X(),l=n?zc:ms;return t.jsx("div",{className:r,style:o,children:t.jsx(ga,{remarkPlugins:[ha],components:l,children:s(e)})})},Tc=["〇","一","二","三","四","五","六","七","八","九"],Ko=["","十","百","千"];function gs(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),o=n.length;let r="",s=!1;for(let l=0;l<o;l++){const c=parseInt(n[l]),p=o-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=Ko[p]:r+=Tc[c]+Ko[p])}return r}function hs(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 Ic={book:i("type-book"),work:i("type-work"),collection:i("type-collection"),entity:i("type-entity")};function Ec({type:e}){const n=ge();return t.jsx("span",{style:hs(Ic[e]),children:n.indexType[e]})}function Rc({isDraft:e}){const n=ge(),o=i(e?"status-draft":"status-official");return t.jsx("span",{style:hs(o),children:e?n.status.draft:n.status.official})}function Nc({id:e}){const n=ge(),[o,r]=x.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:i("desc-fg"),background:i("bg-subtle"),border:`1px solid ${i("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:i("fg")},children:e}),t.jsx("span",{onClick:s,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function et({children:e,extra:n}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("desc-fg"),letterSpacing:"1px"},children:e}),t.jsx("span",{style:{flex:1}}),n]})}function at({label:e,children:n}){return t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[t.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:e}),t.jsx("span",{style:{color:i("fg")},children:n})]})}function bs({authors:e,type:n,onNavigate:o,renderLink:r}){const{convert:s}=X();return t.jsx("span",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.6},children:e.map((l,c)=>{const p=s(l.name),a=l.entity_id?t.jsx(ot,{id:l.entity_id,label:p,onNavigate:o,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:p});return t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),a,l.role&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},c)})})}function ot({id:e,label:n,onNavigate:o,renderLink:r}){const s=Fe();return r?t.jsx(t.Fragment,{children:r(e,n)}):o?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(e))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`,paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{children:n||e})}function Lc({id:e,title:n,edition:o,type:r,isDraft:s,authors:l,volumeText:c,meta:p,headerExtra:a,onNavigate:d,renderLink:u}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:i("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,o&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:o}),c&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:c})]}),a&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(Ec,{type:r}),t.jsx(Rc,{isDraft:s}),t.jsx(Nc,{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(bs,{authors:l,type:r,onNavigate:d,renderLink:u}),p]})]})}function ys({items:e,label:n,showMeta:o,onNavigate:r,renderLink:s}){const l=ge(),{convert:c}=X();if(!e.length)return null;const[p,a]=x.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(et,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((d,u)=>{const m=p===u;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...m?{boxShadow:i("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>a(m?null:u),style:{padding:"8px 12px",background:i("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.15s",transform:m?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:c(d.source)}),!m&&o&&d.title_info&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c(d.title_info)}),d.source_bid&&t.jsx("span",{onClick:f=>f.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(ot,{id:d.source_bid,label:l.action.view,onNavigate:r,renderLink:s})})]}),m&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${i("widget-border")}`},children:[o&&(d.title_info||d.author_info||d.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&t.jsx(at,{label:l.label.titleInfo,children:c(d.title_info)}),d.author_info&&t.jsx(at,{label:l.label.authorInfo,children:c(d.author_info)}),d.edition&&t.jsx(at,{label:l.label.edition,children:c(d.edition)})]}),d.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${i("primary")}`,background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:c(d.summary)})]}),d.comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(d.comment)})]}),d.additional_comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:c(d.additional_comment)})]})]})]},u)})})]})}function Ac({items:e,onNavigate:n,renderLink:o}){const r=ge();return t.jsx(ys,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function js({items:e,onNavigate:n,renderLink:o}){const r=ge();return t.jsx(ys,{items:e,label:r.section.emendated,onNavigate:n,renderLink:o})}function vs({label:e,items:n}){const{convert:o}=X();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(et,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const l=typeof r=="string"?r:r.book_title;return t.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:i("fg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:o(l)},s)})})]}):null}function Bc({items:e}){const n=ge();return t.jsx(vs,{label:n.section.aliases,items:e})}function Mc({items:e}){const n=ge();return t.jsx(vs,{label:n.section.attachedTexts,items:e})}function Wc({items:e}){const n=ge(),{convert:o}=X();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(et,{children:n.section.appendix}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:e.map((r,s)=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:i("fg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:["《",o(r.book_title),"》",r.n_juan!=null&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function Fc({items:e}){const n=ge(),{convert:o}=X();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(et,{children:n.section.locationHistory}),t.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[t.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:i("widget-border")}}),e.map((r,s)=>t.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[t.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:i("primary"),border:`1.5px solid ${i("input-bg")}`}}),t.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:i("fg")},children:o(r.name)}),r.description&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),marginLeft:"8px"},children:o(r.description)})]},s))]})]}):null}function Oc({items:e}){const n=ge(),{convert:o}=X();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(et,{children:n.section.historyOverview}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map((r,s)=>t.jsxs("div",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[t.jsx("span",{style:{position:"absolute",left:0,top:0,color:i("desc-fg")},children:"·"}),o(r)]},s))})]}):null}function qo({title:e,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:l}=X(),[c,p]=x.useState([]);return x.useEffect(()=>{if(!n.length){p([]);return}if(!o){p(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>o.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{a||p(d)}),()=>{a=!0}},[n,o]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(et,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",n.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(c.length?c:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${l(a.title)||a.id}(${l(a.edition)})`:l(a.title)||void 0;return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),transition:"border-color 0.15s"},children:t.jsx(ot,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function Xn({book:e,onNavigate:n,renderLink:o}){const r=ge(),{convert:s}=X(),[l,c]=x.useState(!1),p=e.resources&&e.resources.length>0,a=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:i("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${i("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(ot,{id:e.id,label:a,onNavigate:n,renderLink:o})}),p&&t.jsx("span",{onClick:()=>c(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:i("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),p&&!l&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(Ai,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Pc({ids:e,workData:n,transport:o,onNavigate:r,renderLink:s,footer:l}){const c=ge(),{convert:p}=X(),[a,d]=x.useState([]);if(x.useEffect(()=>{if(!e.length){d([]);return}if(!o){d(e.map(w=>({id:w})));return}let b=!1;return Promise.all(e.map(w=>o.getItem(w).then(y=>({id:w,title:y?y.title:void 0,edition:y?y.edition:void 0,resources:y?y.resources:void 0,resource_groups:y?y.resource_groups:void 0})).catch(()=>({id:w})))).then(w=>{b||d(w)}),()=>{b=!0}},[e,o]),!e.length)return null;const u=a.length?a:e.map(b=>({id:b})),m=new Map(u.map(b=>[b.id,b])),f=n==null?void 0:n.version_graph,g=Dc(e,f);return t.jsxs(t.Fragment,{children:[t.jsxs(et,{children:[c.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),l,g.useGrouping?t.jsxs(t.Fragment,{children:[g.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:g.coreIds.map(b=>{const w=m.get(b);return w?t.jsx(Xn,{book:w,onNavigate:r,renderLink:s},b):null})}),g.groupedIds.map(b=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${i("widget-border")}`,borderRadius:6,background:i("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:i("fg"),userSelect:"none"},children:[p(b.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:i("desc-fg"),fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:i("desc-fg"),fontWeight:400},children:p(b.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(w=>{const y=m.get(w);return y?t.jsx(Xn,{book:y,onNavigate:r,renderLink:s},w):null})})]},b.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(b=>t.jsx(Xn,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Dc(e,n){var y,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const o=(y=n.collections)==null?void 0:y[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.book_ids)??[],l=r.length>0||s.length>0,c=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&c.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...c]),d=h=>{if(a.has(h))return!0;const v=n.node_groups[h];return v!=null&&p.has(v)},u=[],m=new Map,f=[];for(const h of e)if(!((j=n.excluded_books)!=null&&j.includes(h)))if(d(h))u.push(h);else{const v=n.node_groups[h];v?(m.has(v)||m.set(v,[]),m.get(v).push(h)):f.push(h)}if(f.length+[...m.values()].reduce((h,v)=>h+v.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(h=>[h.id,h])),w=[...m.entries()].map(([h,v])=>{const _=b.get(h);return{id:h,label:(_==null?void 0:_.label)??h,description:_==null?void 0:_.description,ids:v}});return f.length>0&&w.push({id:"__other__",label:"其他版本",description:void 0,ids:f}),{useGrouping:!0,coreIds:u,groupedIds:w}}function Hc({workData:e,onNavigate:n,renderLink:o}){var c,p,a,d;const r=ge(),{convert:s}=X(),l=!!((c=e.description)!=null&&c.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:i("input-bg"),marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?`1px solid ${i("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`},children:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:t.jsx(ot,{id:e.id,label:s(e.title),onNavigate:n,renderLink:o})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:s(e.measure_info)}):((p=e.juan_count)==null?void 0:p.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[gs(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(bs,{authors:e.authors,type:"work",onNavigate:n,renderLink:o})})]}),l&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((a=e.description)==null?void 0:a.text)&&t.jsx(ft,{text:e.description.text,style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(d=e.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:t.jsx(at,{label:r.label.parentWork,children:t.jsx(ot,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Gc({items:e,onNavigate:n,renderLink:o}){const r=ge(),{convert:s}=X();return e.length?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(l=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid color-mix(in srgb, ${i("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${i("type-collection")} 3%, transparent)`},children:[t.jsx("span",{style:{fontSize:"11px",color:i("type-collection")},children:r.indexType.collection}),t.jsx(ot,{id:l.id,label:s(l.title)||l.id,onNavigate:n,renderLink:o}),l.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"2px"},children:it(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Wi=({data:e,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:l,relatedBooksFooter:c,className:p,style:a})=>{var U,M,F,O,D,H,z,pe;const d=ge(),{convert:u}=X(),[m,f]=x.useState(null),[g,b]=x.useState(!1),[w,y]=x.useState(null),[j,h]=x.useState(null),[v,_]=x.useState([]),k=e||m;if(x.useEffect(()=>{if(e||!n||!o)return;let A=!1;return b(!0),y(null),o.getItem(n).then(oe=>{A||(oe?f(oe):y(d.misc.notFoundEntry))}).catch(oe=>{A||y(oe instanceof Error?oe.message:d.misc.loadFailed)}).finally(()=>{A||b(!1)}),()=>{A=!0}},[e,n,o]),x.useEffect(()=>{if(!k||!o){h(null),_([]);return}let A=!1;const oe=k.type==="book"||k.type==="collection"?k.work_id:void 0;if(oe?o.getItem(oe).then(E=>{!A&&E&&E.type==="work"&&h(E)}).catch(()=>{}):h(null),k.type==="book"){const E=k;E.contained_in&&E.contained_in.length>0?Promise.all(E.contained_in.map(W=>{const ce=typeof W=="string"?W:W.id,Y=typeof W=="string"?void 0:W.volume_index;return o.getItem(ce).then(ee=>({id:ce,title:ee&&ee.title||ce,volume_index:Y})).catch(()=>({id:ce,title:ce,volume_index:Y}))})).then(W=>{A||_(W)}):_([])}else _([]);return()=>{A=!0}},[k,o]),g)return t.jsx("div",{className:p,style:{...a,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((A,oe)=>t.jsx("div",{style:{height:oe===1?"32px":"16px",width:`${A}px`,background:i("widget-border"),borderRadius:"4px",opacity:.4}},oe))})});if(w)return t.jsx("div",{className:p,style:{...a,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:w});if(!k)return null;if(k.type==="entity")return t.jsx("div",{className:p,style:a,children:t.jsx(fs,{data:k,transport:o,onNavigate:r,renderLink:s,headerExtra:l})});const $=k.type==="book"?k:null,S=k.type==="collection"?k:null,C=k.type==="work"?k:null;let L=!1;try{L=je.extractStatus(k.id)==="draft"}catch{}let I="";k.measure_info?I=u(k.measure_info):(U=k.juan_count)!=null&&U.number?I=gs(k.juan_count.number)+d.unit.juan:(M=k.juan_count)!=null&&M.description&&(I=u(k.juan_count.description));const T=[];return(F=k.publication_info)!=null&&F.year&&T.push(t.jsx(at,{label:d.label.year,children:k.publication_info.year},"year")),(O=k.current_location)!=null&&O.name&&T.push(t.jsx(at,{label:d.label.currentLocation,children:u(k.current_location.name)},"loc")),(D=k.page_count)!=null&&D.description&&T.push(t.jsx(at,{label:d.label.pageCount,children:k.page_count.description},"page")),$!=null&&$.edition&&T.push(t.jsx(at,{label:d.label.edition,children:u($.edition)},"ver")),C!=null&&C.parent_work&&T.push(t.jsx(at,{label:d.label.parentWork,children:t.jsx(ot,{id:C.parent_work.id,label:u(C.parent_work.title),onNavigate:r,renderLink:s})},"pw")),C!=null&&C.parent_works&&C.parent_works.length>0&&!C.parent_work&&T.push(t.jsx(at,{label:d.label.parentWork,children:C.parent_works.map((A,oe)=>t.jsxs("span",{children:[oe>0&&"、",t.jsx(ot,{id:A,onNavigate:r,renderLink:s})]},A))},"pws")),t.jsxs("div",{className:p,style:a,children:[t.jsx(Lc,{id:k.id,title:u(k.title),edition:k.edition?u(k.edition):void 0,type:k.type,isDraft:L,authors:k.authors,volumeText:I,meta:T,headerExtra:l,onNavigate:r,renderLink:s}),((H=k.description)==null?void 0:H.text)&&t.jsx(ft,{text:k.description.text,style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),k.appendix&&k.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:k.appendix.map((A,oe)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:i("bg-subtle"),borderRadius:4,border:`1px solid ${i("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:i("muted")},children:u(A.title)}),t.jsx(ft,{text:A.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:i("fg")}})]},oe))}),v.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(et,{children:d.section.containedIn}),t.jsx(Gc,{items:v,onNavigate:r,renderLink:s})]}),j&&t.jsxs(t.Fragment,{children:[t.jsx(et,{children:d.section.belongsToWork}),t.jsx(Hc,{workData:j,onNavigate:r,renderLink:s})]}),k.additional_works&&k.additional_works.length>0&&t.jsx(Wc,{items:k.additional_works}),k.additional_titles&&k.additional_titles.length>0&&t.jsx(Bc,{items:k.additional_titles}),k.attached_texts&&k.attached_texts.length>0&&t.jsx(Mc,{items:k.attached_texts}),k.indexed_by&&k.indexed_by.length>0&&t.jsx(Ac,{items:k.indexed_by,onNavigate:r,renderLink:s}),k.emendated_by&&k.emendated_by.length>0&&t.jsx(js,{items:k.emendated_by,onNavigate:r,renderLink:s}),k.resources&&k.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(et,{children:d.section.resources}),t.jsx(Ai,{items:k.resources,resourceGroups:k.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),($==null?void 0:$.location_history)&&$.location_history.length>0&&t.jsx(Fc,{items:$.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&t.jsx(Oc,{items:S.history}),($==null?void 0:$.related_books)&&$.related_books.length>0&&t.jsx(qo,{title:d.section.relatedVersions,ids:$.related_books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&t.jsx(qo,{title:d.section.containedBooks,ids:S.books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(et,{children:[d.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",S.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(A=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:t.jsx(ot,{id:A.id,label:u(A.title),onNavigate:r,renderLink:s})},A.id))})]}),(((z=C==null?void 0:C.books)==null?void 0:z.length)||0)+(((pe=C==null?void 0:C.collections)==null?void 0:pe.length)||0)>0&&t.jsx(Pc,{ids:[...(C==null?void 0:C.books)||[],...(C==null?void 0:C.collections)||[]],workData:C??void 0,transport:o,onNavigate:r,renderLink:s,footer:c}),(C==null?void 0:C.related_works)&&C.related_works.length>0&&(()=>{const A=[],oe=C.related_works.filter(Z=>Z.relation==="part_of"),E=C.related_works.filter(Z=>Z.relation==="has_part"),W=C.related_works.filter(Z=>Z.relation==="has_adaptation"),ce=C.related_works.filter(Z=>Z.relation==="text_carried_by"),Y=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ee=C.related_works.filter(Z=>!Z.relation||!Y.has(Z.relation));return oe.length>0&&A.push({label:d.section.belongsToWork,items:oe}),E.length>0&&A.push({label:d.section.containedWorks,items:E}),W.length>0&&A.push({label:d.section.adaptations,items:W}),ce.length>0&&A.push({label:d.section.derivativeWorks,items:ce}),ee.length>0&&A.push({label:d.section.relatedWorks,items:ee}),A.map(Z=>t.jsxs("div",{children:[t.jsxs(et,{children:[Z.label,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",Z.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:Z.items.map(le=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:t.jsx(ot,{id:le.id,label:u(le.title),onNavigate:r,renderLink:s})},le.id))})]},Z.label))})()]})};function Vc({data:e}){const n=ge(),{convert:o}=X(),{stats:r}=e,s=r.processed_volumes??r.total_found_volumes,l=s!=null&&e.total_volumes>0?Math.round(s/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:o(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"6px"},children:o(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:i("desc-fg")},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:i("fg")},children:e.total_volumes})," ",n.unit.volume]}),l!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:i("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:i("fg")},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&t.jsxs("span",{children:[n.catalog.matched," ",t.jsx("strong",{style:{color:i("fg")},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&t.jsxs("span",{children:[n.catalog.unmatched," ",t.jsx("strong",{style:{color:i("missing-fg")},children:r.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:i("desc-fg")},children:[n.catalog.source," ",e.source]})]})}function Uc({sections:e,activeSection:n,onSelect:o}){const r=ge();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>o(null),style:Jo(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>o(s.name),style:Jo(n===s.name),children:[s.name,s.volume_range&&t.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function Jo(e){return{padding:"4px 12px",border:e?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${i("primary")} 8%, transparent)`:"transparent",color:i(e?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Yc({id:e,label:n,onNavigate:o,renderLink:r}){const s=Fe();return r?t.jsx(t.Fragment,{children:r(e,n)}):o?t.jsx("a",{href:s(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(e))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:n||e})}function Kc(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const o=e[0],r=e[e.length-1];return r-o+1===e.length?`${o}–${r}`:e.length<=3?e.join(", "):`${o}–${r} (${e.length}${n})`}function Zo({book:e,onNavigate:n,renderLink:o,showVolumes:r}){const s=ge(),{convert:l}=X(),c=e.book_id||e.work_id,p=r&&e.volumes.length>0?Kc(e.volumes,s.unit.volume):null,a=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${i("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:i("desc-fg"),textAlign:"right"},children:p}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:i("fg")},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(d=>l(d)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:i(a?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),c&&t.jsx(Yc,{id:c,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!c&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const Fi=({data:e,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:l,style:c})=>{const p=ge(),[a,d]=x.useState(null),[u,m]=x.useState(!1),[f,g]=x.useState(null),[b,w]=x.useState(null),[y,j]=x.useState(""),h=e||a;x.useEffect(()=>{if(e||!n||!(o!=null&&o.getCollectionCatalog))return;let S=!1;return m(!0),g(null),o.getCollectionCatalog(n).then(C=>{S||(C?d(C):g(p.catalog.notFound))}).catch(C=>{S||g(C instanceof Error?C.message:p.catalog.loadFailed)}).finally(()=>{S||m(!1)}),()=>{S=!0}},[e,n,o,p]);const v=(h==null?void 0:h.sections)&&h.sections.length>0,_=x.useMemo(()=>{if(!h)return!1;if(h.volume_index&&Object.keys(h.volume_index).length>0)return!0;const S=h.books.map(L=>L.volumes[0]).filter(L=>L!=null);return new Set(S).size<S.length},[h]),k=x.useMemo(()=>{if(!h)return[];let S=h.books;if(b&&(S=S.filter(C=>C.section===b)),y.trim()){const C=y.trim().toLowerCase();S=S.filter(L=>L.title.toLowerCase().includes(C)||L.sub_items&&L.sub_items.some(I=>I.toLowerCase().includes(C))||L.edition&&L.edition.toLowerCase().includes(C))}return S},[h,b,y]),$=x.useMemo(()=>{if(!_)return null;const S=[],C=new Map;for(const I of k){if(!I.volumes||I.volumes.length===0)continue;const T=I.volumes[0];C.has(T)||C.set(T,[]),C.get(T).push(I)}const L=[...C.keys()].sort((I,T)=>I-T);for(const I of L)S.push({volume:I,books:C.get(I)});return S},[k,_]);return u?t.jsx("div",{className:l,style:{...c,padding:"24px"},children:t.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):f?t.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:f}):h?t.jsxs("div",{className:l,style:c,children:[t.jsx(Vc,{data:h}),v&&t.jsx(Uc,{sections:h.sections,activeSection:b,onSelect:w}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:p.search.searchBookName,value:y,onChange:S=>j(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:i("desc-fg")},children:[k.length," ",p.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[$?$.map((S,C)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:i("bg"),borderBottom:`1px solid ${i("widget-border")}`,fontSize:"12px",fontWeight:600,color:i("desc-fg"),position:"sticky",top:0,zIndex:1},children:it(p.catalog.volume,{n:S.volume})}),S.books.map((L,I)=>t.jsx(Zo,{book:L,onNavigate:r,renderLink:s,showVolumes:L.volumes.length>1},`${S.volume}-${I}`))]},`${S.volume}-${C}`)):k.map((S,C)=>t.jsx(Zo,{book:S,onNavigate:r,renderLink:s,showVolumes:!0},C)),k.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},yt=()=>{const[e,n]=x.useState(1);return x.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:i("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(e)})},ks=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],qc={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function De(e){return qc[e]??e}const Mt=[{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},ws={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Ln(e){const n=e.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const o=parseInt(n[1],10);if(o<100||o>2100)return;const r=n[2]?parseInt(n[2],10):void 0;return{from:o,to:r!=null&&r>=o&&r<=2100?r:void 0}}function Jc(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 Zc=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Xo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Oi(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(Xo))if(n.startsWith(s))return Xo[s];const o=De(n);if(kt[o]!=null)return o;const r=xt(n);if(r&&n.length<=r.length+1)return De(r)}function vt(e,n){if(n){const o=ws[`${n}|${e}`];if(o!=null)return o}return Wt[e]}const Xc=1911;function Qc(e){const n=Wt[e];if(n==null)return;const o=ct[e];let r;for(const[s,l]of Object.entries(Wt))ct[s]===o&&l>n&&(r==null||l<r)&&(r=l);return r!=null?r-1:void 0}const ed={零: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,o=0,r=!1;for(const l of e){const c=ed[l];if(c===void 0)return;r=!0,l==="十"?o=(o||1)*10:l==="廿"||l==="卅"?(n+=c,o=0):o>=10?(n+=o+c,o=0):o=o*10+c}const s=n+o;return r&&s>0?s:void 0}function xt(e){for(const n of ks)if(e.startsWith(n))return n}const ct={};{const e=(n,o)=>{for(const r of o)ct[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function wt(e,n){const o=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(Wt))if(e.includes(r)&&!(o&&ct[r]&&ct[r]!==o&&ws[`${o}|${r}`]==null))return r}function cn(e){var c,p,a;const n={era:"",reign:"",source:"none"},o=e.dating;if(o!=null&&o.era||o!=null&&o.reign)return{era:o.era??"",reign:o.reign??"",source:o.certainty==="attested"?"catalog":"edition"};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const d=xt(r)??"";return{era:De(d),reign:wt(r,d)??"",source:"lineage"}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const d=Ln(s);if(d)return{era:Jc(d.from),reign:"",source:"publication"};const u=xt(s)??Oi(s)??((a=Mt.find(g=>g.pattern.test(s)))==null?void 0:a.era)??"",m=wt(s,u)??"",f=u||(m?ct[m]??"":"");if(f||m)return{era:De(f),reign:m,source:"publication"}}const l=e.edition||e.title||"";if(l){const d=xt(l);if(d)return{era:De(d),reign:wt(l,d)??"",source:"edition"};const u=Mt.find(m=>m.pattern.test(l));if(u)return{era:De(u.era),reign:wt(l,u.era)??u.reign??"",source:"edition"}}return n}function An(e){var r,s,l,c,p,a,d,u,m;if(((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;if(typeof((s=e.lineage)==null?void 0:s.year)=="number")return e.lineage.year;const n=(l=e.publication_info)==null?void 0:l.year;if(n){const f=Ln(n);if(f)return f.from}const o=[(c=e.lineage)==null?void 0:c.year_text,(p=e.publication_info)==null?void 0:p.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const f of o){const g=((a=e.publication_info)==null?void 0:a.year)||((d=e.lineage)==null?void 0:d.year_text);if(g&&f!==g&&(xt(g)||Oi(g)))break;const b=f.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??f.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const v=parseInt(b[1],10);if(v>=100&&v<=2100)return v}const w=f.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(w){const v=xt(f);if(!v||De(v)==="民國"){const k=Sn(w[1]);if(k!=null&&k>=1&&k<=120)return Xc+k}}const y=xt(f)??((u=Mt.find(v=>v.pattern.test(f)))==null?void 0:u.era),j=y?De(y):void 0,h=wt(f,j)??(xt(f)||(m=Mt.find(v=>v.pattern.test(f)))==null?void 0:m.reign);if(h){const v=vt(h,j);if(v==null)continue;const _=f.indexOf(h),k=_>=0?f.slice(_+h.length):"",$=k.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??k.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=$?Sn($[1]):void 0;return v+(S?S-1:0)}}}function Pi(e){var c,p,a,d,u,m;const n=(c=e.dating)==null?void 0:c.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const o=(p=e.lineage)==null?void 0:p.year_range;if(o&&o.length===2)return{from:o[0],to:o[1]};const r=(a=e.lineage)==null?void 0:a.year_text;if(r){const f=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(f){const g=ui[De(f[1])],b=kt[De(f[2])];if(g!=null&&b!=null)return{from:Math.min(g,b)-20,to:Math.max(g,b)+40}}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const f=Ln(s);if((f==null?void 0:f.to)!=null)return{from:f.from,to:f.to};const g=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const b=ui[De(g[1])],w=kt[De(g[2])];if(b!=null&&w!=null)return{from:Math.min(b,w)-20,to:Math.max(b,w)+40}}}const l=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const f of l){if(!/[間间]/.test(f))continue;const g=xt(f)??Oi(f)??((m=Mt.find(y=>y.pattern.test(f)))==null?void 0:m.era),b=g?De(g):void 0,w=[];for(const y of Object.keys(Wt))f.includes(y)&&(b&&ct[y]&&ct[y]!==b||vt(y,b)!=null&&w.push(y));if(w.length===0){const y=f.match(/([一-鿿])([一-鿿])[間间]/);if(y&&b){for(const j of[y[1],y[2]])for(const h of Object.keys(Wt))if(ct[h]===b&&!(h[0]!==j&&h[h.length-1]!==j)&&vt(h,b)!=null){w.push(h);break}}}if(w.length>0){const y=w.map(_=>vt(_,b)).filter(_=>_!=null),j=Math.min(...y),h=w.reduce((_,k)=>vt(_,b)>=vt(k,b)?_:k),v=Qc(h)??Qn(b??"")??Math.max(...y);return{from:j,to:v>j?v:Qn(b??ct[h]??"")??j}}if(b&&kt[b]!=null)return{from:kt[b],to:Qn(b)??kt[b]}}}const kt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},td=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],nd=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,Qo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function er(e,n){for(const o of ks){const r=e.indexOf(o);if(r<0)continue;if(o.length===1){const a=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(a)&&!wt(e.slice(r),De(o)))continue}const s=De(o);if(s===n)continue;const l=e.slice(r),c=wt(l,s)??"";let p;if(c){const a=vt(c,s);if(a!=null){const u=l.slice(l.indexOf(c)+c.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),m=u?Sn(u[1]):void 0;p=a+(m?m-1:0)}}return{era:s,reign:c,year:p}}for(const o of Mt)if(o.pattern.test(e))return{era:De(o.era),reign:o.reign??""}}function id(e){var j,h,v,_,k;const n=cn(e),o=((j=e.publication_info)==null?void 0:j.year)??"",r=o?Ln(o):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",l=/[間间]/.test(s),c=((h=e.lineage)==null?void 0:h.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(c),a=n.source==="publication"&&Zc.test(o),d=n.source==="publication"&&/[間间]/.test(o),u=c.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let m;l||p||a||d?m=void 0:u?m=parseInt(u[2],10):m=An(e);const f=m==null?Pi(e):void 0;let g;n.source==="publication"&&(a||Qo.test(o))?g="uncertain":n.source==="lineage"||n.source==="publication"?g="attested":Qo.test(s)||!n.reign&&m==null?g="uncertain":g="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((v=e.lineage)==null?void 0:v.year_text)??((_=e.lineage)==null?void 0:_.year)??""}」`:`出版著錄「${((k=e.publication_info)==null?void 0:k.year)??""}」`,w={era:n.era,reign:n.reign,year:m,yearRange:f,certainty:g,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const $=c.match(/[、,,]\s*([宋元明清])/);$&&$[1]!==w.era&&(w.laterRepair={era:$[1]})}if(!w.laterRepair&&nd.test(s)){const $=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);$&&$[1]!==n.era&&(w.laterRepair={era:$[1]})}const y=td.find($=>$.re.test(s));if(y){const $=s.search(y.re),S=s.slice($),C=er(S,n.era)??er(s,n.era);C&&(w.basedOn={era:C.era,reign:C.reign,year:C.year,relation:y.relation})}return w}const ui={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Qn(e){return ui[e]}function $n(e){const n=An(e);if(n!=null)return n;const o=Pi(e);if(o)return o.from;const r=cn(e).era;return r?kt[r]:void 0}const tr=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function xi(e){const n=tr.indexOf(e);return n===-1?tr.length:n}function od(e){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of e){const l=s.relation;l==="part_of"?n.belongsTo.push(s):l==="collected_in"?n.collected.push(s):l==="has_part"||l==="contains_text_of"?n.contains.push(s):l==="text_carried_by"||l==="studied_by"||l==="derived_from"||l==="followed_by"||l==="has_adaptation"?n.derivative.push(s):l==="studies"||l==="preceded_by"?n.studies.push(s):n.related.push(s)}const o=[],r=(s,l)=>{n[s].length&&o.push({key:s,labelKey:l,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),o}function Di(e,n){const o=Ri(e||[]),r=new Map,s=[];for(const d of o)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((u,m)=>{const f=g=>g.group_role==="origin"?0:g.group_role==="mirror"?1:2;return f(u)-f(m)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=_t(d),m=u.includes("text"),f=u.includes("image");m&&f?l.textImage.push(d):m?l.text.push(d):f?l.image.push(d):l.physical.push(d)}const p=["text","image","textImage","physical"].filter(d=>l[d].length>0).map(d=>({key:d,items:l[d]})),a=[...r.entries()].map(([d,u])=>{var m,f;return{key:d,label:((m=n==null?void 0:n[d])==null?void 0:m.label)||d,description:(f=n==null?void 0:n[d])==null?void 0:f.description,items:u}});return{buckets:p,mirrors:a,total:o.length}}function Bn(e){const n=[],o=e.metadata||{};o.edition&&n.push(String(o.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const r=zn(e);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),o.version&&n.push(String(o.version)),n.join(" · ")}function Ss(e,n){if(Bn(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 $s(e,n){var l,c;const o=e.resources||[],r=[],s=[];for(const p of o){const a=_t(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:cn(e),year:An(e),sortYear:$n(e),images:r,holders:s,locationName:(l=e.current_location)==null?void 0:l.name,important:rd(e.id,n),group:(c=n==null?void 0:n.node_groups)==null?void 0:c[e.id],hasImage:r.length>0}}function rd(e,n){var p,a;if(!n)return!1;const o=n.default_collection;if(!o)return!1;const r=(p=n.collections)==null?void 0:p[o];if(((r==null?void 0:r.book_ids)??(o==="core"?n.core_books??[]:[])).includes(e))return!0;const l=(r==null?void 0:r.groups)??[],c=(a=n.node_groups)==null?void 0:a[e];return!!c&&l.includes(c)}function _s(e,n,o={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(a=>!r.has(a.id)).map(a=>$s(a,n));let l=s;o.era&&(l=l.filter(a=>a.era.era===o.era)),o.scanOnly&&(l=l.filter(a=>a.hasImage)),o.sort==="year"?l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=a.r.sortYear,m=d.r.sortYear;return u!=null&&m!=null?u-m||a.i-d.i:u!=null?-1:m!=null?1:a.i-d.i}).map(a=>a.r):l=l.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const u=m=>(m.important?0:1)*2+(m.hasImage?0:1);return u(a.r)-u(d.r)||a.i-d.i}).map(a=>a.r);const p=[...new Set(s.map(a=>a.era.era).filter(Boolean))].sort((a,d)=>xi(a)-xi(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(a=>a.era.source==="edition")}}function sd(e,n){var y,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const o=(y=n.collections)==null?void 0:y[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.book_ids)??[],l=r.length>0||s.length>0,c=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&c.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const p=new Set(r),a=new Set([...s,...c]),d=h=>{if(a.has(h))return!0;const v=n.node_groups[h];return v!=null&&p.has(v)},u=[],m=new Map,f=[];for(const h of e)if(!((j=n.excluded_books)!=null&&j.includes(h)))if(d(h))u.push(h);else{const v=n.node_groups[h];v?(m.has(v)||m.set(v,[]),m.get(v).push(h)):f.push(h)}if(f.length+[...m.values()].reduce((h,v)=>h+v.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const b=new Map((n.groups??[]).map(h=>[h.id,h])),w=[...m.entries()].map(([h,v])=>{const _=b.get(h);return{id:h,label:(_==null?void 0:_.label)??h,description:_==null?void 0:_.description,ids:v}});return f.length>0&&w.push({id:"__other__",label:"其他版本",description:void 0,ids:f}),{useGrouping:!0,coreIds:u,groupedIds:w}}const Cs=["撰","編","注","校","譯","繪","其他"],ld=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function Hi(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:o,re:r}of ld)if(r.test(n))return o;return"其他"}function Gi(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function zs(e){const n=new Map;for(const r of e){const s=Hi(r);n.set(s,(n.get(s)??0)+1)}const o=[{cls:"全部",label:"全部",count:e.length}];for(const r of Cs){const s=n.get(r);s&&o.push({cls:r,label:r,count:s})}return o.length>2?o:[]}function Ts(e,n,o){if(n&&n.books&&n.books.length>0){const s=n.books.map(c=>({id:c.work_id||c.book_id||void 0,title:c.title,section:c.section,volumes:c.volumes||[],subItems:c.sub_items,edition:c.edition,found:c.found_volumes,expected:c.expected_volumes})),l=[...new Set(s.map(c=>c.section).filter(Boolean))];return{rows:s,source:"catalog",sections:l,totalVolumes:n.total_volumes}}return e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(l=>({id:l.id,title:l.title,volumes:on(l.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var l,c;return{id:s,title:((l=o==null?void 0:o.get(s))==null?void 0:l.title)||s,edition:(c=o==null?void 0:o.get(s))==null?void 0:c.edition,volumes:[]}}),source:"books",sections:[]}}function on(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(n=>typeof n=="number");if(typeof e=="string"){const n=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[o,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-o+1)},(s,l)=>o+l)}return e.split(/[,、]/).map(o=>parseInt(o.trim())).filter(o=>!isNaN(o))}return[]}function Mn(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const o=[...e].sort((l,c)=>l-c),r=o[0],s=o[o.length-1];return s-r+1===o.length?`${r}–${s}`:o.length<=3?o.join(", "):`${r}–${s} (${o.length}${n})`}const ad=["〇","一","二","三","四","五","六","七","八","九"],nr=["","十","百","千"];function Is(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),o=n.length;let r="",s=!1;for(let l=0;l<o;l++){const c=parseInt(n[l]),p=o-1-l;c===0?s=!0:(s&&r&&(r+="〇"),s=!1,c===1&&p===1&&l===0?r+=nr[p]:r+=ad[c]+nr[p])}return r}function cd(e){return e==null?"":typeof e=="string"?e:e.title??""}function mt(e,n="卷"){var r,s;const o=e;return o.measure_info?o.measure_info:(r=o.juan_count)!=null&&r.number?Is(o.juan_count.number)+n:(s=o.juan_count)!=null&&s.description?o.juan_count.description:""}function Es(e){var r;if(e.edition_type)return e.edition_type;if((r=e.lineage)!=null&&r.category)return e.lineage.category;const n=e.edition||e.title||"",o=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,l]of o)if(s.test(n))return l;return""}const dd="guji_markdown";function ln(e){const n=e==null?void 0:e.guji_markdown;if(typeof n!="string")return!1;const o=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!o)return!1;const r=parseInt(o[1],10),s=parseInt(o[2],10);return r>0||s>=2}const pd=/^□\{guess=([^\s{}]+)\}/;function ud(e,n){const o=e[n+1];return o!==void 0&&!/[A-Za-z/!?>\s]/.test(o)}function Rs(e,n){let o=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
|
|
131
|
+
`)return-1;if(s==="\\"){r++;continue}if(s==="[")o++;else if(s==="]"&&(o--,o===0))return r}return-1}function xd(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function fd(e,n){const o=e[n];if(o==="["&&e[n+1]==="["){const r=e.indexOf("]]",n+2);return r>=0&&e.slice(n+2,r).indexOf(`
|
|
132
|
+
`)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(o===":"&&e.startsWith(":zi[",n)){const r=Rs(e,n+3);return r>n+4?{node:{type:"zi",label:xd(e.slice(n+4,r))},end:r+1}:null}if(o==="□"&&e[n+1]==="{"){const r=pd.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function Ns(e,n,o,r){const s=[];let l="";const c=()=>{if(!l)return;const p=r?l.replace(/\\?\|/g,""):l;p&&s.push({type:"text",text:p}),l=""};for(;n<e.length;){const p=e[n];if(o!==null){if(p===o)return c(),{nodes:s,end:n};if(p===`
|
|
133
|
+
`)return null}const a=fd(e,n);if(a){c(),s.push(a.node),n=a.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&ud(e,n)&&(d=">"),d){const u=Ns(e,n+1,d,!0);if(u){c(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return o!==null?null:(c(),{nodes:s,end:n})}function Ls(e){return Ns(e,0,null,!1).nodes}function md(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function As(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${As(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const gd=216,ir="clamp(280px, 23vw, 360px)",hd=1440,fi="(max-width: 719px)",bd=`${fi}, (pointer: coarse)`,yd=`
|
|
134
|
+
.bim-d-main.bim-d-main-grid { max-width: ${hd}px; padding: 16px 32px 0; }
|
|
135
135
|
.bim-d-grid {
|
|
136
136
|
display: grid;
|
|
137
|
-
grid-template-columns: ${
|
|
137
|
+
grid-template-columns: ${gd}px minmax(0, 1fr) ${ir};
|
|
138
138
|
grid-template-rows: auto 1fr;
|
|
139
139
|
grid-template-areas: "rail main card" "rail main side";
|
|
140
140
|
column-gap: 32px; row-gap: 28px; align-items: start;
|
|
@@ -459,7 +459,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
459
459
|
.bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
|
|
460
460
|
|
|
461
461
|
/* 点击目标 ≥44px(Q5):触屏与窄屏 */
|
|
462
|
-
@media ${
|
|
462
|
+
@media ${bd} {
|
|
463
463
|
.bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
|
|
464
464
|
.bim-d-card-foot summary, .bim-d-card-toggle, .bim-d-card details.bim-d-more-names summary,
|
|
465
465
|
.bim-d-tl summary, .bim-d-chap a { min-height: 44px; }
|
|
@@ -497,7 +497,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
497
497
|
/* 中等宽度:左栏折到顶部一行 */
|
|
498
498
|
@media (max-width: 1100px) {
|
|
499
499
|
.bim-d-grid {
|
|
500
|
-
grid-template-columns: minmax(0, 1fr) ${
|
|
500
|
+
grid-template-columns: minmax(0, 1fr) ${ir};
|
|
501
501
|
grid-template-rows: auto auto 1fr;
|
|
502
502
|
grid-template-areas: "rail rail" "main card" "main side";
|
|
503
503
|
}
|
|
@@ -511,7 +511,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
511
511
|
}
|
|
512
512
|
|
|
513
513
|
/* 手机:左栏收起,提要卡 → 正文 → 旁栏 */
|
|
514
|
-
@media ${
|
|
514
|
+
@media ${fi} {
|
|
515
515
|
.bim-d-main.bim-d-main-grid { padding: 8px 16px 0; }
|
|
516
516
|
.bim-d-grid {
|
|
517
517
|
grid-template-columns: minmax(0, 1fr);
|
|
@@ -573,7 +573,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
573
573
|
:root[data-layout="boxed"] .bim-d-g-rail { border: ${i("fr-bd")}; background: ${i("fr-bg")}; padding: 14px 8px; }
|
|
574
574
|
:root[data-layout="boxed"] .bim-d-filters { border-bottom: 1px solid ${i("fr-tab-bd")}; }
|
|
575
575
|
:root[data-layout="boxed"] .bim-d-filters .bim-d-tab { margin-bottom: -1px; }
|
|
576
|
-
@media ${
|
|
576
|
+
@media ${fi} {
|
|
577
577
|
:root[data-layout="boxed"] .bim-d-card { padding: 16px; }
|
|
578
578
|
:root[data-layout="boxed"] .bim-d-g-rail { border: 0; background: transparent; padding: 0; }
|
|
579
579
|
}
|
|
@@ -588,7 +588,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
588
588
|
:root[data-theme="ink"] :is(.bim-d-zt, .bim-d-side li, .bim-d-card-desc, .bim-d-desc, .bim-d-lf-card) a:hover {
|
|
589
589
|
text-decoration-color: currentColor; text-decoration-thickness: 2px;
|
|
590
590
|
}
|
|
591
|
-
`;function
|
|
591
|
+
`;function dn({railTop:e,back:n,up:o,nav:r,railLinks:s,main:l,card:c,side:p}){const{convert:a}=X(),d=(r||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,n&&t.jsx("div",{style:{marginTop:e?12:0},children:n}),o,d.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":a("本頁導航"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:a("本頁")}),t.jsx("ul",{className:"bim-d-rail-nav",children:d.map(u=>t.jsx("li",{children:t.jsxs("a",{href:`#${u.id}`,children:[t.jsx("span",{children:a(u.label)}),u.count!=null&&t.jsx("span",{className:"bim-d-meta",children:u.count})]})},u.id))})]}),s&&s.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":a("更多"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:a("更多")}),t.jsx("ul",{className:"bim-d-rail-nav",children:s.map(u=>t.jsx("li",{children:t.jsxs("a",{href:u.href??"#",onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),u.onClick())},children:[t.jsx("span",{children:a(u.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},u.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:l}),t.jsx("div",{className:"bim-d-g-card",children:c}),t.jsx("div",{className:"bim-d-g-side",children:p})]})}function Bs({caption:e,children:n}){const{convert:o}=X();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:o(e)}),n]})}function Ge({id:e,title:n,meta:o,action:r,children:s}){const{convert:l}=X();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:l(n)}),o!=null&&o!==""&&t.jsx("span",{className:"bim-d-meta",children:o}),r&&t.jsx("span",{className:"bim-d-sec-act",children:r})]}),t.jsx("div",{className:"bim-d-sec-body",children:s})]})}function He({items:e,className:n,style:o}){const r=e.filter(s=>s!=null&&s!==""&&s!==!1);return r.length?t.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:o,children:r.map((s,l)=>t.jsxs(x.Fragment,{children:[l>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},l))}):null}function Wn({items:e,value:n,onChange:o}){const{convert:r}=X();return t.jsx(t.Fragment,{children:e.map(s=>t.jsx("button",{type:"button",className:[...r(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>o(s.key),children:r(s.label)},s.key))})}function Ms({label:e,checked:n,onChange:o}){const{convert:r}=X();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:s=>o(s.target.checked)}),r(e)]})}function Gt({label:e,onClick:n}){const{convert:o}=X();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:o(e)})}function pn({kind:e,title:n,subtitle:o,byline:r,meta:s,description:l,clampDescription:c,facts:p,stats:a,readAction:d,secondaryAction:u,children:m,foot:f}){const{convert:g}=X(),b=(p||[]).filter(v=>v.value!=null&&v.value!==""),w=(a||[]).filter(v=>v.value!=null&&v.value!==""&&v.value!==0),[y,j]=x.useState(!1),h=!!c&&!y;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:g(e)}),t.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),o&&t.jsx("div",{className:"bim-d-card-sub",children:o}),r&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:r}),s&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),l&&t.jsx("div",{className:h?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:h?{"--detail-clamp":c}:void 0,children:l}),l&&!!c&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":y,onClick:()=>j(v=>!v),children:g(y?"收起":"展開")}),w.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:w.map((v,_)=>t.jsxs("div",{children:[t.jsx("b",{children:v.value}),t.jsx("span",{children:g(v.label)})]},_))}),b.length>0&&t.jsx("dl",{className:"bim-d-ui",children:b.map((v,_)=>t.jsxs(x.Fragment,{children:[t.jsx("dt",{children:g(v.label)}),t.jsx("dd",{title:v.title,children:v.value})]},_))}),m,d,u,f&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:f})]})}function Vi(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function mi({href:e,onClick:n,label:o="閱讀全文"}){const{convert:r}=X();return e?t.jsx("a",{className:"bim-d-btn",href:e,onClick:n?s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),n())}:void 0,children:r(o)}):t.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:r(o)})}function St({id:e,title:n,meta:o,items:r,metas:s,currentIndex:l,cap:c=8,moreLabel:p,foot:a,sub:d,timeline:u}){const{convert:m}=X(),[f,g]=x.useState(!1);if(!r.length)return null;const b=f?r:r.slice(0,c),w=r.length-b.length;return t.jsxs("div",{id:e,className:u?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[m(n),o!=null&&o!==""&&t.jsx("span",{className:"bim-d-meta",children:o})]}),d&&t.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:d}),t.jsx("ul",{children:b.map((y,j)=>t.jsxs("li",{className:j===l?"bim-d-side-cur":void 0,"aria-current":j===l?"page":void 0,children:[y,s!=null&&s[j]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[j]}):null]},j))}),w>0&&t.jsx(Gt,{label:p?p(w):`顯示更多(${w})`,onClick:()=>g(!0)}),a&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:a})]})}const jd={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function un({revision:e,revisedAt:n,review:o,todo:r}){const{convert:s}=X(),l=o?jd[o.status]:void 0,c=o&&o.status!=="unreviewed"&&l?[l,o.by,o.date].filter(Boolean).join(" "):"",p=[e!=null&&e!==""?`${s("數據版本")} ${e}`:"",n??"",s(c)].filter(Boolean),a=(r||[]).filter(d=>d&&d.what);return!p.length&&!a.length?null:t.jsxs(t.Fragment,{children:[p.length>0&&t.jsx(He,{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 jn=1e3,or=208,vd=1440,kd="(max-width: 719px)",Ws=`
|
|
592
592
|
.bim-d-page {
|
|
593
593
|
background: ${i("page-bg")};
|
|
594
594
|
color: ${i("ink")};
|
|
@@ -597,7 +597,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
597
597
|
padding-bottom: 64px;
|
|
598
598
|
}
|
|
599
599
|
.bim-d-main {
|
|
600
|
-
max-width: ${
|
|
600
|
+
max-width: ${jn}px;
|
|
601
601
|
margin: 0 auto;
|
|
602
602
|
padding: 24px clamp(16px, 4vw, 28px) 0;
|
|
603
603
|
}
|
|
@@ -608,7 +608,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
608
608
|
* PAGE_MAX_WIDTH,读者的行宽体验不变。
|
|
609
609
|
*/
|
|
610
610
|
.bim-d-main.bim-d-main-wide {
|
|
611
|
-
max-width: ${
|
|
611
|
+
max-width: ${vd}px;
|
|
612
612
|
}
|
|
613
613
|
.bim-d-ui { font-family: var(--bim-font-ui, system-ui, sans-serif); }
|
|
614
614
|
|
|
@@ -640,9 +640,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
640
640
|
*/
|
|
641
641
|
.bim-d-reader {
|
|
642
642
|
display: grid;
|
|
643
|
-
grid-template-columns: ${
|
|
643
|
+
grid-template-columns: ${or}px minmax(0, ${jn}px);
|
|
644
644
|
gap: 32px;
|
|
645
|
-
max-width: ${
|
|
645
|
+
max-width: ${or+jn+32}px;
|
|
646
646
|
margin: 0 auto;
|
|
647
647
|
align-items: start;
|
|
648
648
|
}
|
|
@@ -665,7 +665,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
665
665
|
align-items: start; margin-bottom: 48px; }
|
|
666
666
|
.bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
|
|
667
667
|
|
|
668
|
-
@media ${
|
|
668
|
+
@media ${kd} {
|
|
669
669
|
.bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
|
|
670
670
|
.bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
|
|
671
671
|
/* 表格:meta 列折到第二行,表头隐藏 */
|
|
@@ -683,14 +683,14 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
|
|
|
683
683
|
padding-right: 0; padding-bottom: 12px;
|
|
684
684
|
}
|
|
685
685
|
}
|
|
686
|
-
${
|
|
687
|
-
`)||(n.push({start:o,end:l+1,inner:c}),o=l)}return n}function
|
|
686
|
+
${yd}`;function tn({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Ws}),t.jsx("div",{className:r?"bim-d-main bim-d-main-grid":o?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function gi({breadcrumb:e,actions:n}){return t.jsxs("div",{className:"bim-d-ui bim-d-top",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:i("aux-fg")},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:e}),n&&t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function Ui({char:e,tone:n="accent"}){return t.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,flex:"none",fontSize:11,fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",background:i(n==="accent"?"accent":"ink"),color:i("page-bg")},children:e})}function hi({items:e}){const n=Fe();return t.jsx(t.Fragment,{children:e.map((o,r)=>{const s=r===e.length-1,l=r>0&&t.jsx("span",{style:{color:i("hint-fg")},children:"/"},`s${r}`),c=o.id?n(o.id):o.href,p=s||!o.onClick&&!c?t.jsx("span",{style:{color:i("ink")},children:o.label},r):t.jsx("a",{href:c??"#",onClick:o.onClick?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),o.onClick())}:void 0,style:{color:i("meta-fg")},children:o.label},r);return t.jsxs(x.Fragment,{children:[l,p]},r)})})}function Fs({title:e,subtitle:n,aside:o,secondLine:r}){return t.jsxs("header",{style:{borderBottom:`2px solid ${i("rule-strong")}`,paddingBottom:18},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[t.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:e}),n&&t.jsx("span",{style:{fontSize:15,color:i("meta-fg"),letterSpacing:".06em"},children:n})]}),o&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".06em"},children:o})]}),r&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:i("quiet-fg")},children:r})]})}function wd({children:e,facts:n}){return!e&&n?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${i("rule")}`,marginBottom:40},children:n}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),n]})}function Sd({items:e,horizontal:n}){const{convert:o}=X();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${i("accent")}`,paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:e.map((r,s)=>t.jsxs("div",{title:r.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[t.jsx("span",{className:"bim-d-ui",style:{color:i("label-fg"),letterSpacing:".08em",flex:"none"},children:o(r.label)}),t.jsx("span",{style:{color:i("body-fg"),textAlign:n?"left":"right",minWidth:0},children:r.value})]},s))}):null}function $d({glyph:e,tone:n,title:o,count:r,actions:s,id:l}){const{convert:c}=X();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(Ui,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:c(o)}),r!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg")},children:r})]}),s&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function Os({label:e,active:n,onClick:o,dashed:r}){const{convert:s}=X();return t.jsx("button",{type:"button",onClick:o,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!n?"dashed":"solid"} ${i(n?"accent":"rule")}`,background:n?i("accent"):"transparent",color:i(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(e)})}function _d({label:e,onClick:n}){const{convert:o}=X();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:o(e)})}function Cd({label:e,onClick:n,inline:o}){const{convert:r}=X();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:o?0:12,width:o?void 0:"100%",padding:o?"4px 12px":9,background:"none",border:`1px dashed ${i("rule-dashed")}`,cursor:"pointer",fontSize:12,color:i("meta-fg"),letterSpacing:o?void 0:".08em"},children:r(e)})}function Ps({children:e,href:n,onClick:o,title:r}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${i("rule")}`,fontSize:13,color:i("body-fg"),lineHeight:1.5};return n||o?t.jsx("a",{href:n??"#",title:r,onClick:o?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o())}:void 0,style:s,children:e}):t.jsx("span",{title:r,style:s,children:e})}function zd({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function Td({volumes:e,unit:n="冊",max:o=60}){const[r,s]=x.useState(!1);if(!e.length)return null;const l=r?e:e.slice(0,o);return t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[l.map(c=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${i("rule")}`,color:i("meta-fg")},children:c},c)),!r&&e.length>o&&t.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${i("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:i("meta-fg")},children:["+",e.length-o]}),t.jsx("span",{style:{padding:"2px 6px",color:i("hint-fg")},children:n})]})}function Id({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${i("rule-strong")}`},children:e})}function Ed({spec:e}){const{convert:n}=X();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${i("rule-strong")}`,fontSize:11,color:i("label-fg"),letterSpacing:".1em"},children:[t.jsx("span",{}),t.jsx("span",{children:n(e.mainLabel)}),t.jsx("span",{style:{display:"grid",gridTemplateColumns:e.columns.map(o=>o.width).join(" "),gap:12},children:e.columns.map(o=>t.jsx("span",{children:n(o.label)},o.label))})]})}function Rd({no:e,main:n,meta:o,spec:r}){return t.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${r.leadWidth}px 1fr ${r.metaWidth}px`,gap:12},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:i("hint-fg"),textAlign:"right"},children:e}),t.jsx("span",{style:{minWidth:0},children:n}),t.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:r.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:o})]})}function Nd(e){return String(e+1).padStart(2,"0")}function Ld(){return t.jsx("span",{style:{color:i("hint-fg")},children:"—"})}function Ad({open:e,onToggle:n,main:o,action:r,children:s}){return t.jsxs("div",{style:{borderBottom:`1px solid ${i("rule")}`},children:[t.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[t.jsx("button",{type:"button",onClick:n,"aria-expanded":e,className:"bim-d-ui",style:{width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",fontSize:12,lineHeight:1,border:`1px solid ${i(e?"accent":"rule-dashed")}`,background:e?i("accent"):"transparent",color:i(e?"page-bg":"accent")},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:o}),r]}),e&&s&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${i("rule-accent-soft")}`,marginLeft:12},children:s})]})}function Ds(e){const n=[];for(let o=0;o<e.length;o++){const r=e[o];let s;if(r==="⟨")s="⟩";else if(r==="<"){const p=e[o+1];if(p===void 0||/[A-Za-z/!?>\s]/.test(p))continue;s=">"}else continue;const l=e.indexOf(s,o+1);if(l<0)continue;const c=e.slice(o+1,l);c.includes(`
|
|
687
|
+
`)||(n.push({start:o,end:l+1,inner:c}),o=l)}return n}function Hs(e,n){if(e.length<=n)return e;let o=n;for(const r of Ds(e)){if(r.start>=o)break;if(r.end>o){o=r.start>0?r.start:r.end;break}}return e.slice(0,o)}const Gs={fontSize:".78em",color:i("meta-fg"),lineHeight:1.55},Bd={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 Vs(e,n,o){return e.map((r,s)=>{switch(r.type){case"text":return t.jsx(x.Fragment,{children:n(r.text)},s);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:o===0?Gs:void 0,children:Vs(r.children,n,o+1)},s);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:r.label?`闕文:${r.label}`:"闕文",children:"□"},s);case"qz":return t.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":r.guess,children:"□"},s);case"zi":return t.jsx("span",{className:"bim-zi guji-zi",title:`組字:${r.label}`,style:Bd,children:r.label},s)}})}function Xe(e,n=r=>r,o){if(!e)return"";if(o!=null&&o.gujiMarkdown)return md(e)?Vs(Ls(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 Ds(e))c.start>s&&r.push(t.jsx(x.Fragment,{children:n(e.slice(s,c.start))},l++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:Gs,children:n(c.inner)},l++)),s=c.end;return s<e.length&&r.push(t.jsx(x.Fragment,{children:n(e.slice(s))},l++)),r}function Md({label:e,children:n}){return t.jsxs("div",{style:{marginBottom:10},children:[e&&t.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:i("label-fg"),marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:i("quiet-fg"),textAlign:"justify"},children:n})]})}function Wd({title:e,tag:n,children:o}){const{convert:r}=X();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${i("rule-strong")}`,marginBottom:2},children:[t.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:r(e)}),n&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:i("accent"),letterSpacing:".06em"},children:r(n)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:o})]})}function Us({name:e,note:n,href:o,extra:r}){const s=t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{fontSize:14,minWidth:0},children:e}),t.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:i("hint-fg"),flex:"none"},children:o?"↗":""}),n&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:i("label-fg")},children:n})]}),l={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${i("rule")}`,color:i("body-fg"),alignItems:"baseline"};return t.jsxs(t.Fragment,{children:[o?t.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",style:l,children:s}):t.jsx("div",{style:l,children:s}),r]})}function Fd({item:e,siblings:n,showVolumes:o=!0,fallbackNote:r}){const{convert:s}=X(),[l,c]=x.useState(!1),p=zn(e),a=o&&!!p&&p.expected>0,d=(e.url?Pt(e.url):void 0)||s(e.name),u=n?Ss(e,n):"",m=u?`${d}(${u})`:d;return t.jsx(Us,{name:m,note:Bn(e)||r,href:Dt(e),extra:a?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>c(f=>!f),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:l?"收起分冊":`展開 ${p.expected} 冊`}),l&&t.jsx(Yi,{item:e})]}):void 0})}function Yi({item:e}){return t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(e.volumes||[]).map((n,o)=>{const r=n.status==="missing";return n.url&&!r?t.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{padding:"4px 8px",borderRadius:4,background:i("zebra-bg")},children:n.volume},o):t.jsx("span",{style:{padding:"1px 5px",color:i(r?"missing-fg":"hint-fg"),textDecoration:r?"line-through":void 0},children:n.volume},o)})})}function Ys({label:e,items:n}){const{convert:o}=X();return n.length?t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".08em"},children:e}),n.map((r,s)=>t.jsx(Ps,{children:o(r)},s))]}):null}function Od({rows:e}){const n=e.filter(o=>o.items.length>0);return n.length?t.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(o=>t.jsx(Ys,{label:o.label,items:o.items},o.label))}):null}function bi(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Ks({left:e,right:n}){return t.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:i("aux-fg")},children:[t.jsx("span",{children:e}),n&&t.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function Pd({children:e,action:n}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:i("aux-fg"),borderBottom:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),n]})}function Oe({id:e,label:n,onNavigate:o,renderLink:r,style:s,dense:l}){const c=Fe();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:l})}):t.jsx("a",{href:c(e),onClick:o?p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),o(e))}:void 0,style:s,children:n??e})}function Dd({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 qs="(min-width: 1100px)",Js="(max-width: 719px)",Hd=`${Js}, (pointer: coarse)`,gt=i("reader-top"),Gd="48px",Zs=`
|
|
688
688
|
.bim-rd {
|
|
689
689
|
position: relative;
|
|
690
690
|
background: ${i("page-bg")};
|
|
691
691
|
color: ${i("ink")};
|
|
692
692
|
font-family: ${i("font-ui")};
|
|
693
|
-
--bimrd-bar-h: ${
|
|
693
|
+
--bimrd-bar-h: ${Gd};
|
|
694
694
|
}
|
|
695
695
|
.bim-rd *, .bim-rd *::before, .bim-rd *::after { box-sizing: border-box; }
|
|
696
696
|
|
|
@@ -716,7 +716,7 @@ ${dd}`;function Kt({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
716
716
|
|
|
717
717
|
/* ── 工具条:文字 + 图标,不画按钮外框 ── */
|
|
718
718
|
.bim-rd-bar {
|
|
719
|
-
position: sticky; top: ${
|
|
719
|
+
position: sticky; top: ${gt}; z-index: 30;
|
|
720
720
|
height: var(--bimrd-bar-h);
|
|
721
721
|
display: flex; align-items: center; gap: 16px;
|
|
722
722
|
padding: 0 20px;
|
|
@@ -745,6 +745,7 @@ ${dd}`;function Kt({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
745
745
|
.bim-rd-wl:hover { background: ${i("accent")}; color: ${i("page-bg")} !important; }
|
|
746
746
|
.bim-rd-tools { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; color: ${i("quiet-fg")}; flex: none; }
|
|
747
747
|
.bim-rd-tools .bim-rd-sep { width: 1px; height: 14px; background: ${i("rule")}; }
|
|
748
|
+
.bim-rd-nav { display: inline-flex; align-items: center; gap: 4px; }
|
|
748
749
|
.bim-rd-t {
|
|
749
750
|
background: none; border: 0; margin: 0; padding: 6px 2px;
|
|
750
751
|
font: inherit; color: inherit; cursor: pointer; line-height: 1;
|
|
@@ -770,14 +771,14 @@ ${dd}`;function Kt({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
770
771
|
display: grid;
|
|
771
772
|
grid-template-columns: auto auto minmax(0, 1fr);
|
|
772
773
|
align-items: start;
|
|
773
|
-
min-height: calc(100vh - ${
|
|
774
|
+
min-height: calc(100vh - ${gt} - var(--bimrd-bar-h));
|
|
774
775
|
}
|
|
775
776
|
|
|
776
777
|
/* 目录:宽屏是侧栏 */
|
|
777
778
|
.bim-rd-toc {
|
|
778
779
|
grid-column: 1;
|
|
779
|
-
position: sticky; top: calc(${
|
|
780
|
-
width: 248px; height: calc(100vh - ${
|
|
780
|
+
position: sticky; top: calc(${gt} + var(--bimrd-bar-h));
|
|
781
|
+
width: 248px; height: calc(100vh - ${gt} - var(--bimrd-bar-h));
|
|
781
782
|
overflow-y: auto; overscroll-behavior: contain;
|
|
782
783
|
padding: 0 10px 40px;
|
|
783
784
|
background: ${i("sidebar-bg")};
|
|
@@ -814,8 +815,8 @@ ${dd}`;function Kt({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
814
815
|
/* 书影:正文左侧 */
|
|
815
816
|
.bim-rd-img {
|
|
816
817
|
grid-column: 2;
|
|
817
|
-
position: sticky; top: calc(${
|
|
818
|
-
width: clamp(300px, 32vw, 560px); height: calc(100vh - ${
|
|
818
|
+
position: sticky; top: calc(${gt} + var(--bimrd-bar-h));
|
|
819
|
+
width: clamp(300px, 32vw, 560px); height: calc(100vh - ${gt} - var(--bimrd-bar-h));
|
|
819
820
|
padding: 16px 0 16px 20px;
|
|
820
821
|
display: flex; flex-direction: column; gap: 8px;
|
|
821
822
|
}
|
|
@@ -826,7 +827,7 @@ ${dd}`;function Kt({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
826
827
|
display: flex; align-items: center; justify-content: center; overflow: hidden;
|
|
827
828
|
}
|
|
828
829
|
.bim-rd-img-fig { position: relative; margin: 0; max-width: 100%; max-height: 100%; }
|
|
829
|
-
.bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${
|
|
830
|
+
.bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${gt} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
|
|
830
831
|
.bim-rd-img-fig svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
|
|
831
832
|
.bim-rd-img-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 24px; text-align: center; font-size: 13px; color: ${i("meta-fg")}; }
|
|
832
833
|
.bim-rd-img-empty b { font-size: 15px; font-weight: 500; color: ${i("quiet-fg")}; }
|
|
@@ -839,7 +840,7 @@ ${dd}`;function Kt({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
839
840
|
/* 右栏(v3):正文列右侧 220px,≥860px 才显示,吸顶 */
|
|
840
841
|
.bim-rd-rail { display: none; }
|
|
841
842
|
@media (min-width: 860px) {
|
|
842
|
-
.bim-rd-text[data-rail] { display: grid; grid-template-columns: minmax(0, 50em) 220px; gap: 40px; align-items: start; justify-content:
|
|
843
|
+
.bim-rd-text[data-rail] { display: grid; grid-template-columns: minmax(0, 50em) 220px; gap: 40px; align-items: start; justify-content: center; }
|
|
843
844
|
.bim-rd-text[data-rail] .bim-rd-col { margin: 0; max-width: none; }
|
|
844
845
|
.bim-rd-rail { display: block; position: sticky; top: calc(var(--bimrd-bar-h) + 16px); max-height: calc(100vh - var(--bimrd-bar-h) - 32px); overflow-y: auto; font-family: ${i("font-ui")}; }
|
|
845
846
|
}
|
|
@@ -858,13 +859,16 @@ ${dd}`;function Kt({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
858
859
|
.bim-rd-rail-acts { margin-top: 18px; padding-top: 14px; border-top: 1px solid ${i("rule")}; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; font-size: 12.5px; }
|
|
859
860
|
.bim-rd-rail-report { padding: 0; border: none; background: none; font: inherit; color: ${i("accent")}; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
|
|
860
861
|
.bim-rd-rail-report:hover { color: ${i("ink")}; }
|
|
862
|
+
/* 窄屏(右栏藏起来)时正文末尾的「报告错字」;≥860px 右栏里已有,这里隐去 */
|
|
863
|
+
.bim-rd-report-foot { margin-top: 12px; }
|
|
864
|
+
@media (min-width: 860px) { .bim-rd-report-foot { display: none; } }
|
|
861
865
|
.bim-rd-rail-dot { flex: none; align-self: center; width: 5px; height: 5px; background: ${i("rule")}; }
|
|
862
866
|
.bim-rd-rail-dot.on { background: ${i("accent")}; }
|
|
863
867
|
|
|
864
868
|
/* 正文 */
|
|
865
869
|
.bim-rd-text { grid-column: 3; min-width: 0; padding: 32px 48px 96px 40px; outline: none; }
|
|
866
|
-
/*
|
|
867
|
-
.bim-rd-col { max-width: 50em; margin: 0 auto
|
|
870
|
+
/* 正文列居中(收起目录/书影后不再留右侧大片空白,overview#308),宽 50em */
|
|
871
|
+
.bim-rd-col { max-width: 50em; margin: 0 auto; font-size: var(--bimrd-fs, 18px); }
|
|
868
872
|
.bim-rd-kicker { margin: 0 0 8px; font-size: 12px; letter-spacing: 0.2em; color: ${i("label-fg")}; font-family: ${i("font-ui")}; }
|
|
869
873
|
.bim-rd-kicker .bim-rd-dot::before { content: "·"; margin: 0 0.6em; }
|
|
870
874
|
.bim-rd-h1 { font-family: ${i("font-ui")}; font-size: 28px; font-weight: 700; letter-spacing: 0.12em; margin: 0; color: ${i("ink")}; line-height: 1.4; }
|
|
@@ -919,7 +923,7 @@ ${dd}`;function Kt({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
919
923
|
|
|
920
924
|
/* 竖排(预留):只在宿主打开 allowVertical 时可切换 */
|
|
921
925
|
.bim-rd-vertical .bim-rd-prose {
|
|
922
|
-
writing-mode: vertical-rl; max-height: calc(100vh - ${
|
|
926
|
+
writing-mode: vertical-rl; max-height: calc(100vh - ${gt} - var(--bimrd-bar-h) - 120px);
|
|
923
927
|
overflow-x: auto; text-align: start;
|
|
924
928
|
}
|
|
925
929
|
|
|
@@ -944,7 +948,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
|
|
|
944
948
|
|
|
945
949
|
/* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
|
|
946
950
|
A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
|
|
947
|
-
@media ${
|
|
951
|
+
@media ${Hd} {
|
|
948
952
|
.bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
|
|
949
953
|
.bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
|
|
950
954
|
content: ""; position: absolute; left: 50%; top: 50%;
|
|
@@ -953,10 +957,11 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
|
|
|
953
957
|
.bim-rd-tools .bim-rd-fs + .bim-rd-fs { margin-left: 12px; }
|
|
954
958
|
.bim-rd-ver select { min-height: 44px; }
|
|
955
959
|
.bim-rd-pager .bim-rd-pg { min-height: 44px; }
|
|
960
|
+
.bim-rd-report-foot .bim-rd-rail-report { min-height: 44px; min-width: 44px; padding: 0 8px; }
|
|
956
961
|
}
|
|
957
962
|
|
|
958
963
|
/* ── 中屏以下:目录改抽屉 ── */
|
|
959
|
-
@media not all and ${
|
|
964
|
+
@media not all and ${qs} {
|
|
960
965
|
.bim-rd-toc {
|
|
961
966
|
position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto;
|
|
962
967
|
width: min(86vw, 320px);
|
|
@@ -970,11 +975,13 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
|
|
|
970
975
|
}
|
|
971
976
|
|
|
972
977
|
/* ── 窄屏:书影收起,只留正文 ── */
|
|
973
|
-
@media ${
|
|
978
|
+
@media ${Js} {
|
|
974
979
|
.bim-rd-bar { padding: 0 12px; gap: 10px; }
|
|
975
980
|
.bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
|
|
976
|
-
|
|
977
|
-
.bim-rd-tools { gap: 10px; }
|
|
981
|
+
/* 工具条放不下时(版本、自然段、标出作品链接都在)在条内左右滑,不撑宽页面 */
|
|
982
|
+
.bim-rd-tools { gap: 10px; flex: 0 1 auto; min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
|
|
983
|
+
.bim-rd-tools::-webkit-scrollbar { display: none; }
|
|
984
|
+
.bim-rd-ttl { flex: 1 1 72px; min-width: 72px; }
|
|
978
985
|
.bim-rd-ver { min-width: 44px; min-height: 44px; justify-content: center; }
|
|
979
986
|
.bim-rd-ver-short { display: inline; white-space: nowrap; }
|
|
980
987
|
.bim-rd-ver select { position: absolute; inset: 0; width: 100%; max-width: none; opacity: 0; }
|
|
@@ -1002,19 +1009,21 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
|
|
|
1002
1009
|
:root[data-theme="ink"] .bim-rd-t[aria-pressed="true"], :root[data-theme="ink"] .bim-rd-t[aria-current="true"] {
|
|
1003
1010
|
text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px;
|
|
1004
1011
|
}
|
|
1005
|
-
`;function Oi(e,n){var o;return n?e.key===n?!0:!!((o=e.children)!=null&&o.some(r=>Oi(r,n))):!1}const Ad=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Wd({item:e,activeKey:n,onSelect:o,tabKey:r}){const s=Oi(e,n),[l,c]=f.useState(s||!!e.defaultExpanded);return f.useEffect(()=>{s&&c(!0)},[s]),f.useEffect(()=>{e.defaultExpanded&&c(!0)},[e.defaultExpanded]),t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>c(p=>!p),children:[t.jsx(Ad,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Us,{items:e.children,activeKey:n,onSelect:o,tabKey:r})]})}function Us({items:e,activeKey:n,onSelect:o,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Wd,{item:s,activeKey:n,onSelect:o,tabKey:r},s.key):t.jsx("li",{children:t.jsxs("button",{type:"button",className:"bim-rd-ti","aria-current":s.key===n?"true":void 0,disabled:s.disabled,"data-rd-toc-key":s.key,tabIndex:r===s.key?0:-1,onClick:()=>o(s.key),children:[t.jsx("span",{children:s.label}),s.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:s.hint})]})},s.key))})}function Qo(e,n){var o;for(const r of e)if(r.key===n||Oi(r,n))return r.key;return((o=e[0])==null?void 0:o.key)??null}function Vs({items:e,activeKey:n,onSelect:o,label:r="目录"}){const s=f.useRef(null),[l,c]=f.useState(null);f.useEffect(()=>{c(null)},[n]);const p=f.useMemo(()=>l||(n??Qo(e,n)),[l,n,e]);f.useEffect(()=>{const d=s.current;if(!d)return;const u=Array.from(d.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const m=u.find(x=>x.dataset.rdTocKey===p)??u.find(x=>x.dataset.rdTocKey===Qo(e,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===m?0:-1}),f.useEffect(()=>{const d=s.current,u=d==null?void 0:d.closest(".bim-rd-toc");if(!d||!u||!n)return;const m=Array.from(d.querySelectorAll("[data-rd-toc-key]")).find(g=>g.dataset.rdTocKey===n);if(!m)return;const x=m.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(x<u.scrollTop+80||x>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,x-u.clientHeight/3))},[n]);const a=f.useCallback(d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const m=s.current;if(!m)return;const x=Array.from(m.querySelectorAll("[data-rd-toc-key]")).filter(y=>!y.disabled),g=x.indexOf(document.activeElement);let b=g;if(d.key==="ArrowDown"?b=Math.min(x.length-1,g+1):d.key==="ArrowUp"?b=Math.max(0,g-1):d.key==="Home"?b=0:d.key==="End"&&(b=x.length-1),b<0||b===g)return;d.preventDefault();const w=x[b];for(const y of x)y.tabIndex=-1;w.tabIndex=0,w.focus(),c(w.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:a,children:t.jsx(Us,{items:e,activeKey:n,onSelect:o,tabKey:p})})}function Md({page:e}){var n;return!((n=e.boxes)!=null&&n.length)||!e.width||!e.height||e.boxFormat&&e.boxFormat!=="bim-charbox-v0"?null:t.jsx("svg",{viewBox:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:e.boxes.map((o,r)=>t.jsx("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:"none",stroke:i("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},r))})}function Ys({pages:e,loading:n,page:o,onPageChange:r,renderOverlay:s}){const[l,c]=f.useState(0),p=o??l,a=x=>{r?r(x):c(x)};if(f.useEffect(()=>{o===void 0&&c(0)},[e,o]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:"加载书影…"})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:"暂无书影"}),t.jsx("span",{children:"这一卷还没有配上影像;接入后在此与正文逐页对看"})]})});const d=Math.max(0,Math.min(e.length-1,p)),u=e[d],m=u.label??`${d+1}`;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${m} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(Md,{page:u}),s==null?void 0:s(u,d)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:d===0,onClick:()=>a(d-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${d+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:d===e.length-1,onClick:()=>a(d+1),children:"›"})]})]})}const Di={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal",workLinks:!0},Ct=[15,16,17,18,20,22,24],ui=18,Ks="bim-reader-prefs",Fd="bim-reading-mode";function Pd(){const e={...Di};try{const n=localStorage.getItem(Ks),o=n?JSON.parse(n):{};typeof o.fontSize=="number"&&Ct.includes(o.fontSize)&&(e.fontSize=o.fontSize),(o.readingMode??localStorage.getItem(Fd))==="paragraph"&&(e.readingMode="paragraph"),o.properNames===!0&&(e.properNames=!0),o.writingMode==="vertical"&&(e.writingMode="vertical"),o.workLinks===!1&&(e.workLinks=!1)}catch{}return e}function Od(e){try{localStorage.setItem(Ks,JSON.stringify(e))}catch{}}function er(e,n){const o=e??ui,r=Ct;let s=r.indexOf(o);return s<0&&(s=r.indexOf(ui)),r[Math.max(0,Math.min(r.length-1,s+n))]}function Hi(){const[e,n]=f.useState(Di);f.useEffect(()=>{n(Pd())},[]);const o=f.useCallback(r=>{n(s=>{const l={...s,...r};return Od(l),l})},[]);return[e,o]}function qs(e){return e.map(n=>({key:n.key,label:n.version_label||n.key,sourceName:n.source_name,license:n.license,sourceUrl:n.source_url,primary:n.primary}))}function xi(e){const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function Js(e,n){if(!(!e||e.length===0))return(n!=null?e.find(o=>o.key===n):void 0)??e.find(o=>o.primary)??e[0]}function Zs(e){const n=[],o=r=>{for(const s of r)s.children&&s.children.length>0?o(s.children):n.push(s)};return o(e),n}const Dd=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),Hd=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),t.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function Gd(e,n){if(!n)return;const o=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(c=>c.tabIndex>=0);if(o.length===0)return;const r=o[0],s=o[o.length-1],l=document.activeElement;e.shiftKey&&(l===r||!n.contains(l))?(e.preventDefault(),s.focus()):!e.shiftKey&&(l===s||!n.contains(l))&&(e.preventDefault(),r.focus())}function Ud(e,n){const[o,r]=f.useState(n);return f.useEffect(()=>{var c;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(s.matches);return(c=s.addEventListener)==null||c.call(s,"change",l),()=>{var p;return(p=s.removeEventListener)==null?void 0:p.call(s,"change",l)}},[e]),o}function Vd(){const e=f.useContext(Lt);if(!e)return null;const n=e.locale==="zh-Hant";return t.jsxs("button",{type:"button",className:"bim-rd-t",title:n?"切换为简体":"切換為繁體","aria-label":n?"切换为简体":"切換為繁體",onClick:()=>e.setLocale(n?"zh-Hans":"zh-Hant"),children:[t.jsx("span",{className:n?"bim-rd-on":"bim-rd-off",children:"繁"}),t.jsx("span",{className:"bim-rd-off",children:"|"}),t.jsx("span",{className:n?"bim-rd-off":"bim-rd-on",children:"简"})]})}function Yd(e,n){if(!e)return;let o;for(const r of Array.from(e.querySelectorAll('[id^="rd-e-"]')))if(r.getBoundingClientRect().top<=n+8)o=r.id;else break;return o}function Kd(e){var l;if(typeof window>"u"||!e)return;const n=(l=window.getSelection)==null?void 0:l.call(window);if(!n||n.isCollapsed||n.rangeCount===0)return;const o=e.querySelector(".bim-rd-col"),r=c=>{const p=(c==null?void 0:c.nodeType)===1?c:c==null?void 0:c.parentElement;return!!c&&!!(o!=null&&o.contains(c))&&!(p!=null&&p.closest(".bim-rd-src, .bim-rd-pager"))};if(!r(n.anchorNode)||!r(n.focusNode))return;const s=n.toString().replace(/\s+/g," ").trim();return s?s.slice(0,500):void 0}function Gi({title:e,subtitle:n,toc:o,activeKey:r,onSelect:s,tocHeader:l,tocCaption:c,images:p,imagesLoading:a,renderImageOverlay:d,imagePanel:u="auto",prefs:m,onPrefsChange:x,paragraphToggle:g,properNameToggle:b=!0,allowVertical:w,byline:y,current:j,workLinkToggle:h,rail:v,onReportError:$,revisedAt:k,pager:_=!0,pagerUnit:S="卷",versions:z,currentVersionKey:N,onVersionChange:R,versionSource:C=!0,children:H,className:L,style:M}){const F=f.useId().replace(/:/g,""),X=`bim-rd-toc-${F}`,U=`bim-rd-text-${F}`,T=f.useRef(null),ce=f.useRef(null),B=f.useRef(null),D=f.useRef(null),A=Ud(Ds,!0),[ee,de]=f.useState("auto"),G=ee==="auto"?A:ee==="open",q=!A,ie=!!p&&p.length>0,[pe,ge]=f.useState(u);f.useEffect(()=>{ge(u)},[u]);const Ee=pe==="auto"?ie||!!a:pe==="open",Ne=f.useCallback(O=>{var xe;de("auto"),O&&((xe=D.current)==null||xe.focus())},[]),ze=()=>de(G?"closed":"open");f.useEffect(()=>{if(!q||ee!=="open")return;const O=B.current,xe=O==null?void 0:O.querySelector('input, [data-rd-toc-key][tabindex="0"]');xe==null||xe.focus()},[q,ee]);const Te=f.useCallback(O=>{s(O),q&&Ne(!1);const xe=ce.current,je=T.current;if(xe&&je&&typeof window<"u"){const Se=xe.getBoundingClientRect().top-je.getBoundingClientRect().bottom;Se<0&&window.scrollBy({top:Se})}},[s,q,Ne]),Ce=f.useMemo(()=>Zs(o),[o]),[Ae,P]=f.useState(null),se=Js(z,N!==void 0?N:Ae),re=(se==null?void 0:se.key)??null,ye=f.useMemo(()=>Ce.map(O=>O.key).join(`
|
|
1006
|
-
`),[
|
|
1012
|
+
`;function Ki(e,n){var o;return n?e.key===n?!0:!!((o=e.children)!=null&&o.some(r=>Ki(r,n))):!1}const Vd=()=>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 Ud({item:e,activeKey:n,onSelect:o,tabKey:r}){const s=Ki(e,n),[l,c]=x.useState(s||!!e.defaultExpanded);return x.useEffect(()=>{s&&c(!0)},[s]),x.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(Vd,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Xs,{items:e.children,activeKey:n,onSelect:o,tabKey:r})]})}function Xs({items:e,activeKey:n,onSelect:o,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Ud,{item:s,activeKey:n,onSelect:o,tabKey:r},s.key):t.jsx("li",{children:t.jsxs("button",{type:"button",className:"bim-rd-ti","aria-current":s.key===n?"true":void 0,disabled:s.disabled,"data-rd-toc-key":s.key,tabIndex:r===s.key?0:-1,onClick:()=>o(s.key),children:[t.jsx("span",{children:s.label}),s.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:s.hint})]})},s.key))})}function rr(e,n){var o;for(const r of e)if(r.key===n||Ki(r,n))return r.key;return((o=e[0])==null?void 0:o.key)??null}function Qs({items:e,activeKey:n,onSelect:o,label:r="目录"}){const s=x.useRef(null),[l,c]=x.useState(null);x.useEffect(()=>{c(null)},[n]);const p=x.useMemo(()=>l||(n??rr(e,n)),[l,n,e]);x.useEffect(()=>{const d=s.current;if(!d)return;const u=Array.from(d.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const m=u.find(f=>f.dataset.rdTocKey===p)??u.find(f=>f.dataset.rdTocKey===rr(e,n))??u.find(f=>!f.disabled)??u[0];for(const f of u)f.tabIndex=f===m?0:-1}),x.useEffect(()=>{const d=s.current,u=d==null?void 0:d.closest(".bim-rd-toc");if(!d||!u||!n)return;const m=Array.from(d.querySelectorAll("[data-rd-toc-key]")).find(g=>g.dataset.rdTocKey===n);if(!m)return;const f=m.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(f<u.scrollTop+80||f>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,f-u.clientHeight/3))},[n]);const a=x.useCallback(d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const m=s.current;if(!m)return;const f=Array.from(m.querySelectorAll("[data-rd-toc-key]")).filter(y=>!y.disabled),g=f.indexOf(document.activeElement);let b=g;if(d.key==="ArrowDown"?b=Math.min(f.length-1,g+1):d.key==="ArrowUp"?b=Math.max(0,g-1):d.key==="Home"?b=0:d.key==="End"&&(b=f.length-1),b<0||b===g)return;d.preventDefault();const w=f[b];for(const y of f)y.tabIndex=-1;w.tabIndex=0,w.focus(),c(w.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:s,role:"navigation","aria-label":r,onKeyDown:a,children:t.jsx(Xs,{items:e,activeKey:n,onSelect:o,tabKey:p})})}function Yd({page:e}){var n;return!((n=e.boxes)!=null&&n.length)||!e.width||!e.height||e.boxFormat&&e.boxFormat!=="bim-charbox-v0"?null:t.jsx("svg",{viewBox:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:e.boxes.map((o,r)=>t.jsx("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:"none",stroke:i("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},r))})}function el({pages:e,loading:n,page:o,onPageChange:r,renderOverlay:s}){const[l,c]=x.useState(0),p=o??l,a=f=>{r?r(f):c(f)};if(x.useEffect(()=>{o===void 0&&c(0)},[e,o]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:"加载书影…"})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:"暂无书影"}),t.jsx("span",{children:"这一卷还没有配上影像;接入后在此与正文逐页对看"})]})});const d=Math.max(0,Math.min(e.length-1,p)),u=e[d],m=u.label??`${d+1}`;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${m} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(Yd,{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 qi={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal",workLinks:!0},Lt=[15,16,17,18,20,22,24],yi=18,tl="bim-reader-prefs",Kd="bim-reading-mode";function qd(){const e={...qi};try{const n=localStorage.getItem(tl),o=n?JSON.parse(n):{};typeof o.fontSize=="number"&&Lt.includes(o.fontSize)&&(e.fontSize=o.fontSize),(o.readingMode??localStorage.getItem(Kd))==="paragraph"&&(e.readingMode="paragraph"),o.properNames===!0&&(e.properNames=!0),o.writingMode==="vertical"&&(e.writingMode="vertical"),o.workLinks===!1&&(e.workLinks=!1)}catch{}return e}function Jd(e){try{localStorage.setItem(tl,JSON.stringify(e))}catch{}}function sr(e,n){const o=e??yi,r=Lt;let s=r.indexOf(o);return s<0&&(s=r.indexOf(yi)),r[Math.max(0,Math.min(r.length-1,s+n))]}function Fn(){const[e,n]=x.useState(qi);x.useEffect(()=>{n(qd())},[]);const o=x.useCallback(r=>{n(s=>{const l={...s,...r};return Jd(l),l})},[]);return[e,o]}function nl(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 ji(e){if(e.optionLabel)return e.optionLabel;const n=e.label||e.key;return!e.sourceName||n.includes(e.sourceName)?n:`${n} · ${e.sourceName}`}function il(e,n){if(!(!e||e.length===0))return(n!=null?e.find(o=>o.key===n):void 0)??e.find(o=>o.primary)??e[0]}function ol(e){const n=[],o=r=>{for(const s of r)s.children&&s.children.length>0?o(s.children):n.push(s)};return o(e),n}const Zd=()=>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"})}),Xd=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M15 5l-7 7 7 7"})}),Qd=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M9 5l7 7-7 7"})}),ep=()=>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 tp(e,n){if(!n)return;const o=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(c=>c.tabIndex>=0);if(o.length===0)return;const r=o[0],s=o[o.length-1],l=document.activeElement;e.shiftKey&&(l===r||!n.contains(l))?(e.preventDefault(),s.focus()):!e.shiftKey&&(l===s||!n.contains(l))&&(e.preventDefault(),r.focus())}function np(e,n){const[o,r]=x.useState(n);return x.useEffect(()=>{var c;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const l=()=>r(s.matches);return(c=s.addEventListener)==null||c.call(s,"change",l),()=>{var p;return(p=s.removeEventListener)==null?void 0:p.call(s,"change",l)}},[e]),o}function ip(){const e=x.useContext(Ot);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 op(e,n){if(!e)return;let o;for(const r of Array.from(e.querySelectorAll('[id^="rd-e-"]')))if(r.getBoundingClientRect().top<=n+8)o=r.id;else break;return o}function rp(e){var l;if(typeof window>"u"||!e)return;const n=(l=window.getSelection)==null?void 0:l.call(window);if(!n||n.isCollapsed||n.rangeCount===0)return;const o=e.querySelector(".bim-rd-col"),r=c=>{const p=(c==null?void 0:c.nodeType)===1?c:c==null?void 0:c.parentElement;return!!c&&!!(o!=null&&o.contains(c))&&!(p!=null&&p.closest(".bim-rd-src, .bim-rd-pager"))};if(!r(n.anchorNode)||!r(n.focusNode))return;const s=n.toString().replace(/\s+/g," ").trim();return s?s.slice(0,500):void 0}function On({title:e,subtitle:n,toc:o,activeKey:r,onSelect:s,tocHeader:l,tocCaption:c,images:p,imagesLoading:a,renderImageOverlay:d,imagePanel:u="auto",prefs:m,onPrefsChange:f,paragraphToggle:g,properNameToggle:b=!0,allowVertical:w,byline:y,current:j,workLinkToggle:h,rail:v,onReportError:_,revisedAt:k,pager:$=!0,pagerUnit:S="卷",versions:C,currentVersionKey:L,onVersionChange:I,versionSource:T=!0,keepChapterOnVersionChange:U=!1,children:M,className:F,style:O}){const D=x.useId().replace(/:/g,""),H=`bim-rd-toc-${D}`,z=`bim-rd-text-${D}`,pe=x.useRef(null),A=x.useRef(null),oe=x.useRef(null),E=x.useRef(null),W=np(qs,!0),[ce,Y]=x.useState("auto"),ee=ce==="auto"?W:ce==="open",Z=!W,le=!!p&&p.length>0,[be,Le]=x.useState(u);x.useEffect(()=>{Le(u)},[u]);const Be=be==="auto"?le||!!a:be==="open",he=x.useCallback(G=>{var ve;Y("auto"),G&&((ve=E.current)==null||ve.focus())},[]),Ne=()=>Y(ee?"closed":"open");x.useEffect(()=>{if(!Z||ce!=="open")return;const G=oe.current,ve=G==null?void 0:G.querySelector('input, [data-rd-toc-key][tabindex="0"]');ve==null||ve.focus()},[Z,ce]);const Te=x.useCallback(G=>{s(G),Z&&he(!1);const ve=A.current,$e=pe.current;if(ve&&$e&&typeof window<"u"){const J=ve.getBoundingClientRect().top-$e.getBoundingClientRect().bottom;J<0&&window.scrollBy({top:J})}},[s,Z,he]),Re=x.useMemo(()=>ol(o),[o]),[P,me]=x.useState(null),te=il(C,L!==void 0?L:P),ke=(te==null?void 0:te.key)??null,we=x.useMemo(()=>Re.map(G=>G.key).join(`
|
|
1013
|
+
`),[Re]),K=x.useRef(null),N=G=>{G!==ke&&(U||(K.current={key:G,sig:we,done:!1}),L===void 0&&me(G),I==null||I(G))};x.useEffect(()=>{const G=K.current;if(!G||G.key!==ke)return;const ve=Re.find(J=>!J.disabled);if(!ve)return;const $e=we!==G.sig;!$e&&G.done||($e?K.current=null:G.done=!0,ve.key!==r&&Te(ve.key))},[ke,we,Re,r,Te]);const q=Re.find(G=>G.key===r),xe=()=>{var G;_==null||_({chapterKey:r,chapterLabel:typeof(q==null?void 0:q.label)=="string"?q.label:void 0,anchor:op(A.current,((G=pe.current)==null?void 0:G.getBoundingClientRect().bottom)??0),selectedText:rp(A.current)})},ye=Re.findIndex(G=>G.key===r),B=ye>0?Re.slice(0,ye).reverse().find(G=>!G.disabled):void 0,re=ye>=0?Re.slice(ye+1).find(G=>!G.disabled):void 0,Q=m.fontSize??yi,fe={...O,...m.fontSize?{"--bimrd-fs":`${m.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",m.writingMode==="vertical"&&w?"bim-rd-vertical":"",F].filter(Boolean).join(" "),"data-toc":ce,"data-img":Be?"open":"closed",style:fe,children:[t.jsx("style",{children:Zs}),t.jsx("a",{className:"bim-rd-skip",href:`#${z}`,onClick:G=>{var ve,$e,J;G.preventDefault(),(ve=A.current)==null||ve.focus(),(J=($e=A.current)==null?void 0:$e.scrollIntoView)==null||J.call($e,{block:"start"})},children:"跳到正文"}),t.jsxs("div",{className:"bim-rd-bar",ref:pe,children:[(e||n||y||j)&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),y&&t.jsx("span",{className:"bim-rd-by",children:y}),j&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:j})]}),n&&t.jsx("span",{children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":"阅读设置",children:[C&&C.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:te?ji(te):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:ke??"",onChange:G=>N(G.target.value),children:C.map(G=>t.jsx("option",{value:G.key,children:ji(G)},G.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),$&&(B||re)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":`翻${S}`,children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":`上一${S}`,title:B?`上一${S}:${typeof B.label=="string"?B.label:""}`.replace(/:$/,""):`已是第一${S}`,disabled:!B,onClick:()=>B&&Te(B.key),children:t.jsx(Xd,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":`下一${S}`,title:re?`下一${S}:${typeof re.label=="string"?re.label:""}`.replace(/:$/,""):`已是最后一${S}`,disabled:!re,onClick:()=>re&&Te(re.key),children:t.jsx(Qd,{})})]}),$&&(B||re)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:E,type:"button",className:"bim-rd-t","aria-expanded":ee,"aria-controls":H,onClick:Ne,children:[t.jsx(Zd,{}),t.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":Be,onClick:()=>Le(Be?"closed":"open"),children:[t.jsx(ep,{}),"书影"]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(ip,{}),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:Q<=Lt[0],onClick:()=>f({fontSize:sr(m.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs","aria-label":"放大字号",disabled:Q>=Lt[Lt.length-1],onClick:()=>f({fontSize:sr(m.fontSize,1)}),children:"A+"}),(g||b||w)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),g&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":m.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>f({readingMode:m.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),h&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk",children:[t.jsx("input",{type:"checkbox",checked:m.workLinks,onChange:G=>f({workLinks:G.target.checked})}),t.jsx("span",{children:"标出作品链接"})]}),b&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":m.properNames,title:"书名加波浪线",onClick:()=>f({properNames:!m.properNames}),children:"专名线"}),w&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":m.writingMode==="vertical",onClick:()=>f({writingMode:m.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:H,ref:oe,role:Z&&ee?"dialog":void 0,"aria-modal":Z&&ee?!0:void 0,"aria-label":Z&&ee?"目录":void 0,onKeyDown:G=>{if(!(!Z||!ee)){if(G.key==="Escape"){G.stopPropagation(),he(!0);return}G.key==="Tab"&&tp(G,oe.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??"目录"}),Z&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>he(!0),children:"✕"})]}),l]}),t.jsx(Qs,{items:o,activeKey:r,onSelect:Te})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>he(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:Be&&t.jsx(el,{pages:p??null,loading:a,renderOverlay:d})}),t.jsxs("div",{className:"bim-rd-text",id:z,ref:A,tabIndex:-1,"data-rail":v||_?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[M,T&&te&&(te.sourceName||te.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":te.key,children:[te.sourceName&&t.jsxs(t.Fragment,{children:["出处"," ",te.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:te.sourceUrl,target:"_blank",rel:"noreferrer",children:te.sourceName}):te.sourceName]}),te.sourceName&&te.license&&t.jsx("span",{className:"bim-rd-dot"}),te.license&&t.jsxs(t.Fragment,{children:["授权 ",te.license]})]}),k&&t.jsxs("p",{className:"bim-rd-src bim-rd-rev",children:["最近校订 ",k]}),_&&t.jsx("p",{className:"bim-rd-src bim-rd-report-foot",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:G=>G.preventDefault(),onClick:xe,children:"报告错字"})}),$&&(B||re)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[B?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>Te(B.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),"上一",S]}),t.jsx("span",{className:"bim-rd-pglabel",children:B.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← 已是第一",S]}),re?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>Te(re.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:["下一",S,t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:re.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:["已是最后一",S," →"]})]})]}),(v||_)&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":"本卷",children:[v,_&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:G=>G.preventDefault(),onClick:xe,children:"报告错字"})})]})]})]})]})}const rl="guji-table-v1";function Ji(e){return!!e&&e.table_notation===rl}const sp=/^:::table(?:\{[^}]*\})?[ \t]*$/,lp=/^:::[ \t]*$/;function sl(e){const n=[];let o="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const c=Rs(e,r+3);if(c>r+4){o+=e.slice(r,c+1),r=c;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const c=e[r+1];c!==void 0&&!/[A-Za-z/!?>\s]/.test(c)&&(l=">")}if(l){const c=e.indexOf(l,r+1);if(c>0){o+=e.slice(r,c+1),r=c;continue}}s==="|"?(n.push(o),o=""):o+=s}return n.push(o),n.map(r=>r.trim())}const ap=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function cp(e){if(e==="^")return{cont:!0};const n=ap.exec(e),o=n[1].trim(),r=n[2]?Math.max(1,parseInt(n[2],10)):1,s=n[3]?Math.max(1,parseInt(n[3],10)):1,l=o==="_";return{cont:!1,cell:{text:l?"":o,empty:l,colspan:r,rowspan:s}}}function ll(e,n=1){const o=[],r=[],s=[];let l=[];e.forEach((p,a)=>{const d=a+n+1;let u=p.trim();if(!u)return;let m=!1;u.startsWith("!")&&(m=!0,u=u.slice(1));const f=sl(u).map(cp),g=l.map(j=>j>0),b=l.map(j=>j>0?j-1:0),w=[];let y=0;for(const j of f){if(j.cont){g[y]||o.push(`第 ${d} 行第 ${y+1} 列:续格 ^ 上方没有跨行格`),y+=1;continue}const{cell:h}=j;for(let v=y;v<y+h.colspan;v++)if(g[v]){o.push(`第 ${d} 行第 ${v+1} 列:此处被上方跨行格占住,应写 ^`);break}if(h.rowspan>1)for(let v=y;v<y+h.colspan;v++)b[v]=h.rowspan-1;w.push(h),y+=h.colspan}for(let j=y;j<g.length;j++)g[j]&&o.push(`第 ${d} 行第 ${j+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let j=0;j<b.length;j++)b[j]===void 0&&(b[j]=0);l=b,r.push({header:m,cells:w}),s.push({width:y,line:d})});const c=s.reduce((p,a)=>Math.max(p,a.width),0);for(const p of s)p.width!==c&&o.push(`第 ${p.line} 行:占 ${p.width} 列,与总列数 ${c} 不符`);return l.some(p=>p>0)&&o.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&o.push("空表"),{rows:r,columns:c,warnings:o}}function Zi(e){const n=e.split(`
|
|
1007
1014
|
`),o=[];let r=[];const s=()=>{if(r.length===0)return;const c=r.join(`
|
|
1008
|
-
`);r=[],o.push({type:"text",text:c})};let l=0;for(;l<n.length;){if(
|
|
1009
|
-
`)}),l=c+1;continue}}r.push(n[l]),l++}return s(),o.map((c,p)=>{var d,u;if(c.type!=="text")return c;let a=c.text;return((d=o[p-1])==null?void 0:d.type)==="table"&&(a=a.replace(/^\n+/,"")),((u=o[p+1])==null?void 0:u.type)==="table"&&(a=a.replace(/\n+$/,"")),{type:"text",text:a}}).filter(c=>c.type!=="text"||c.text!=="")}const
|
|
1010
|
-
`).map(n=>n.trim()).filter(n=>n&&!
|
|
1011
|
-
`)){const s=r.trim();if(!s||
|
|
1015
|
+
`);r=[],o.push({type:"text",text:c})};let l=0;for(;l<n.length;){if(sp.test(n[l].trim())){let c=l+1;for(;c<n.length&&!lp.test(n[c].trim());)c++;if(c<n.length){s();const p=n.slice(l+1,c);o.push({type:"table",table:ll(p,l+1),source:n.slice(l,c+1).join(`
|
|
1016
|
+
`)}),l=c+1;continue}}r.push(n[l]),l++}return s(),o.map((c,p)=>{var d,u;if(c.type!=="text")return c;let a=c.text;return((d=o[p-1])==null?void 0:d.type)==="table"&&(a=a.replace(/^\n+/,"")),((u=o[p+1])==null?void 0:u.type)==="table"&&(a=a.replace(/\n+$/,"")),{type:"text",text:a}}).filter(c=>c.type!=="text"||c.text!=="")}const dp={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},pp={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},up=`1px solid ${i("table-border")}`,al={border:up,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},xp={...al,background:i("table-head-bg"),fontWeight:600};function Xi({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:dp,children:t.jsx("table",{className:"bim-guji-table",style:pp,children:t.jsx("tbody",{children:e.rows.map((o,r)=>t.jsx("tr",{children:o.cells.map((s,l)=>{const c=o.header?"th":"td";return t.jsx(c,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:o.header?xp:al,children:s.empty?null:Xe(s.text,void 0,n)},l)})},r))})})})}function fp(e,n){return e.indexOf("**")<0?Xe(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:Xe(r.trim().slice(2,-2),void 0,n)},s):t.jsx(x.Fragment,{children:Xe(r,void 0,n)},s))}function mp(e,n,o=!1){const r=o?{gujiMarkdown:!0}:void 0;return n?Zi(e).map((s,l)=>s.type==="table"?t.jsx(Xi,{table:s.table,opts:r},l):t.jsx(x.Fragment,{children:fp(s.text,r)},l)):Xe(e,void 0,r)}const gp=/^(#{1,6})\s+(.*)$/,hp=/^\*\*([^*\n]+)\*\*\s*$/;function Qi(e){const n=e.match(gp);if(n)return{level:n[1].length,text:n[2].trim()};const o=e.trim().match(hp);return o?{level:3,text:o[1].trim()}:null}const eo=/^<!--.*-->$/;function cl(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function dl(e){return e.split(`
|
|
1017
|
+
`).map(n=>n.trim()).filter(n=>n&&!eo.test(n))}const bp=60;function pl(e){let n=0,o=0;for(const r of e.split(`
|
|
1018
|
+
`)){const s=r.trim();if(!s||eo.test(s)||Qi(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>bp&&(o+=l)}return n>0&&o*2>=n}function yp(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function Pn(e){if(e=yp(e),pl(e))return"unknown";const n=cl(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const o=n.map(s=>dl(s).length).filter(s=>s>0);if(o.length===0)return"unknown";const r=o.reduce((s,l)=>s+l,0)/o.length;return r<=4?"record":r>=8?"catalog":"unknown"}function jp(e){const n=e.split(`
|
|
1012
1019
|
`),o=[];let r=null,s=[];const l=()=>{o.push({heading:r,body:s.join(`
|
|
1013
|
-
`)}),s=[]};for(const c of n){const p=
|
|
1014
|
-
`)){const r=
|
|
1015
|
-
`)?"":n)}function
|
|
1016
|
-
`);let a=0;return t.jsx(t.Fragment,{children:p.map((d,u)=>{const m=d.match(Yn);if(m){const g=a++;if(l(m[1].length,m[2],g))return null;const{Tag:b,className:w}=c(m[1].length);return t.jsx(b,{className:w,children:o(m[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Yn.test(p[u-1])&&!Yn.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(dp.test(d))return null;if(a++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:g,className:b}=c(3);return t.jsx(g,{className:b,children:o(d.trim().slice(2,-2))},u)}return t.jsx("p",{children:nr(d,o,u)},u)})})}function xp(e){const{convert:n}=V();return f.useMemo(()=>e?n(e):"",[e,n])}function Ji({text:e,mode:n,tables:o=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:c}){const p=xp(e),{convert:a}=V(),d=x=>qi(x,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,m=c?a(c):void 0;return!o||p.indexOf(":::")<0?t.jsx(ir,{text:p,mode:n,inline:d,dropTitle:m}):t.jsx(t.Fragment,{children:Ui(p).map((x,g)=>x.type==="table"?t.jsx(Vi,{table:x.table,opts:u},g):t.jsx(ir,{text:x.text,mode:n,inline:d,dropTitle:g===0?m:void 0},g))})}function dl(e,n){const[o,r]=f.useState(null),[s,l]=f.useState(!1),c=f.useRef(0);return f.useEffect(()=>{const p=++c.current;if(!e||!n){r(null),l(!1);return}let a;try{a=e(n)}catch{r(null),l(!1);return}if(!a||typeof a.then!="function"){r(a??null),l(!1);return}l(!0),a.then(d=>{p===c.current&&r(d??null)}).catch(()=>{p===c.current&&r(null)}).finally(()=>{p===c.current&&l(!1)})},[e,n]),{images:o,loading:s}}const or={A:"fine",B:"rough",C:"rough",D:"ocr"};function fp(e){return typeof e!="string"?null:e in ti?e:e in or?or[e]:null}const mp={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},gp={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function Je(e){return typeof e!="string"?"":mp[e]??gp[e]??e}const hp=["〇","一","二","三","四","五","六","七","八","九"],rr=["","十","百","千"],bp=["","萬","億"];function Zi(e){if(e===0)return"〇";if(e<0)return`負${Zi(-e)}`;const n=[];let o=e,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(yp(s,r>0)+bp[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function yp(e,n){const o=[];let r=e;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let s="";for(let l=0;l<o.length;l++){const c=o[l],p=o.length-1-l;c===0?s&&!s.endsWith("〇")&&(s+="〇"):c===1&&p===1&&l===0&&!n?s+=rr[p]:s+=hp[c]+rr[p]}return s.replace(/〇$/,"")}let Zt=null,fn=null;const kn=new Set;function jp(){return Zt?Promise.resolve():fn||(fn=import("opencc-js/t2cn").then(e=>{Zt=e.Converter({from:"tw",to:"cn"}),kn.forEach(n=>n())}).catch(()=>{Zt=e=>e,kn.forEach(e=>e())}),fn)}const vp=e=>e;function wt(){const[,e]=f.useState(0);return f.useEffect(()=>{if(Zt)return;const n=()=>e(o=>o+1);return kn.add(n),jp(),()=>{kn.delete(n)}},[]),Zt??vp}function Nt(e,n){return n(e).toLowerCase()}const kp=i("highlight-bg");function sn(e,n,o){if(!n)return e;const r=Nt(n,o);if(!r)return e;const s=Nt(e,o);if(s.length!==e.length)return e;const l=[];let c=0,p=0;for(;c<e.length;){const a=s.indexOf(r,c);if(a===-1){l.push(e.slice(c));break}a>c&&l.push(e.slice(c,a)),l.push(t.jsx("mark",{style:{background:kp,padding:0,color:"inherit"},children:e.slice(a,a+r.length)},p++)),c=a+r.length}return t.jsx(t.Fragment,{children:l})}function Xi(e,n,o,r){if(!n)return!0;const s=Nt(n,r);return(o?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(c=>typeof c=="string"&&Nt(c,r).includes(s))}function wp(e,n,o){return n?Nt(e,o).includes(Nt(n,o)):!0}const Qi={类:i("section-lei"),书:i("section-shu"),序:i("section-xu"),结语:i("section-jieyu"),注释:i("section-zhushi")},Sp={考证:i("section-kaozhen")};function $p(e){const n=e.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function pl(e){var r;const n=e.files.length,o=((r=e.children)==null?void 0:r.reduce((s,l)=>s+pl(l),0))||0;return n+o}function _p(e,n){const o=[],r=c=>{var p;o.push(...c.files),(p=c.children)==null||p.forEach(r)};if(r(e),o.length===0)return;const s=o.map(c=>n[c]);if(s.every(c=>c===void 0))return;if(s.some(c=>c==="loading"))return"loading";let l=0;for(const c of s)typeof c=="number"&&(l+=c);return l}const zp={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function eo({enabled:e,expanded:n,onClick:o,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:o,style:{...zp,...r},children:s}):t.jsx("span",{style:r,children:s})}function Cp({type:e}){const n=Je(e),o=Qi[n]||i("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:o,border:`1px solid ${o}40`,borderRadius:"2px",background:`${o}08`,flexShrink:0},children:n})}function Tp({section:e,onNavigate:n,highlightQuery:o="",no:r,showUnlinked:s=!1,domId:l}){const{convert:c}=V(),p=Fe(),a=wt(),d=h=>h?Ke(c(h),v=>o?sn(v,o,a):v):"",[u,m]=f.useState(!1),x=!!e.summary,g=!!e.comment,b=!!e.additional_comment,w=!!(e.content&&e.content.length>60),y=x||g||b||w;f.useEffect(()=>{o&&m(!0)},[o]);const j=!u&&w?As(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{className:"bim-rd-row",id:l,style:{borderBottom:`1px solid ${i("rule")}`,overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>y&&m(!u),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:y?"pointer":"default",userSelect:"none"},children:[r!=null&&t.jsx("span",{className:"bim-rd-no",style:{flex:"none",width:28,fontSize:12,color:i("label-fg")},children:r}),t.jsxs(eo,{enabled:y,expanded:u,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[y&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",d(e.book_title),"》"]}):d(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[Zi(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:d(e.author_info||e.author)})]}),!u&&j&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:d(j)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:d(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:i("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:p(e.work_id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),h.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品","aria-label":`查看作品:${e.book_title||e.title}`,children:"作品 →"}),s&&!e.work_id&&t.jsx("span",{style:{fontSize:"11px",color:i("label-fg"),flexShrink:0},children:"未关联"})]}),u&&y&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${i("widget-border")}`,background:i("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"8px"},children:d(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${i("primary")}`,background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:d(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(e.additional_comment)})]}),w&&!x&&!g&&!b&&t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:d(e.content)})]})]})}function Ip({section:e,highlightQuery:n=""}){const{convert:o}=V(),r=wt(),s=a=>a?Ke(o(a),d=>n?sn(d,n,r):d):"",[l,c]=f.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(eo,{enabled:p,expanded:l,onClick:()=>c(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(Cp,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:s(e.title)}),p&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&p&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${Qi[Je(e.type)]||i("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:i("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(e.content)})})]})}const Ep=100;function to(e){return Je(e.type)!=="page_header"?!1:(e.content||"").length>=Ep}function Rp({section:e,highlightQuery:n=""}){const{convert:o}=V(),r=wt();if(Je(e.type)==="page_header"&&!to(e)||!e.content&&!e.title)return null;const s=o((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
1017
|
-
`)),l=Ke(s,d=>n?sn(d,n,r):d),c=Je(e.type),p=Qi[c]||i("desc-fg"),a=c==="序"||c==="结语"||c==="注释";return t.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:i("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${p}40`:void 0,background:a?i("bg"):void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:c}),l]})}function Np(e,n,o){const[r,s]=f.useState({});return f.useEffect(()=>{var d;if(!n||e.length===0)return;let l=!1;const c=e.filter(u=>{var m;return!((m=o==null?void 0:o.current)!=null&&m.has(u))}),p={};for(const u of e)(d=o==null?void 0:o.current)!=null&&d.has(u)&&(p[u]=o.current.get(u));if(Object.keys(p).length>0&&s(p),c.length===0)return;const a=async u=>{var m;try{if(n.getEntry){const y=await n.getEntry(u);if(y)return{title:y.title,author:y.author}}const x=await n.getItem(u);if(!x)return null;const g=x.title||u,b=x.authors,w=(m=b==null?void 0:b[0])==null?void 0:m.name;return{title:g,author:w}}catch{return null}};return Promise.all(c.map(async u=>{var x;const m=await a(u);return(x=o==null?void 0:o.current)==null||x.set(u,m),[u,m]})).then(u=>{l||s(m=>{const x={...m};for(const[g,b]of u)x[g]=b;return x})}),()=>{l=!0}},[e.join(","),n]),r}function Lp({section:e,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=V(),c=Fe(),p=wt(),a=h=>h?Ke(l(h),v=>s?sn(v,s,p):v):"",[d,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const m=Je(e.type),x=Sp[m]||i("desc-fg"),g=!!e.content,b=e.work_ids||[],w=b.length>1,y=Np(w?b:[],o,r),j=g&&!d&&e.content.length>80?As(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${i("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>g&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:g?"pointer":"default",userSelect:"none"},children:[t.jsxs(eo,{enabled:g,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[g&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg"),lineHeight:1.6},children:e.header_line?a(e.header_line):a(e.title)}),!d&&j&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:i("desc-fg"),lineHeight:1.7},children:a(j)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:c(b[0]),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),h.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),w&&t.jsxs("span",{style:{fontSize:"11px",color:i("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:m})]})]}),w&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(h=>{const v=y[h],$=v?`${l(v.title)}${v.author?`(${l(v.author)})`:""}`:h.slice(0,8)+"…";return t.jsxs("a",{href:c(h),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),n(h))},style:{fontSize:"12px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:h,children:["→",$]},h)})}),d&&g&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:i("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${i("widget-border")}`,fontSize:"12px",color:i("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:a(e.comment)})]})]})}function Bp({juan:e,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const l=wt(),c=n.trim(),p=f.useMemo(()=>c?e.sections.filter(a=>Xi(a,c,!0,l)):e.sections,[e.sections,c,l]);return t.jsxs("div",{children:[t.jsx("div",{children:p.map((a,d)=>t.jsx(Lp,{section:a,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:c},d))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Ap(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Wp({sections:e,onNavigate:n,inline:o,workLinks:r=!0}){const s=Fe(),{convert:l}=V(),c=Ap();return t.jsx(t.Fragment,{children:e.map((p,a)=>{const d=Je(p.type);if(d==="page_header"&&!to(p))return null;if(d==="类")return t.jsxs(f.Fragment,{children:[f.createElement(c("类"),null,o(l(p.title))),p.content&&t.jsx("p",{children:o(l(p.content))})]},a);if(d==="书"||d==="诗"||d==="考证"||d==="注释"){const u=p.book_title?`《${p.book_title}》${p.n_juan!=null?Zi(p.n_juan)+"卷":""}`:p.title,m=o(l(u));return t.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${a}`,children:[f.createElement(c("条目"),{className:"bim-rd-entry-h"},p.work_id&&n&&r?t.jsxs(t.Fragment,{children:[t.jsx("a",{href:s(p.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),n(p.work_id))},title:"查看作品",children:m}),t.jsx("a",{className:"bim-rd-wl",href:s(p.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),n(p.work_id))},"aria-label":`查看作品:${u}`,children:"作品 →"})]}):m),p.author_info&&t.jsx("p",{className:"bim-rd-sub",children:o(l(p.author_info))}),p.content&&p.content.split(/\n+/).map((x,g)=>t.jsx("p",{children:o(l(x))},g)),p.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),o(l(p.summary))]}),p.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),o(l(p.comment))]}),p.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),o(l(p.additional_comment))]})]},a)}return p.content?t.jsx("p",{children:o(l(p.content))},a):null})})}function ul(e){return e.some(n=>{const o=Je(n.type);return o==="书"||o==="诗"||o==="考证"||o==="注释"||o==="类"||(o==="序"||o==="结语")&&!!n.content||o==="page_header"&&to(n)})}function Mp({juan:e,rawText:n,positionLabel:o,groupLabel:r,index:s,searchQuery:l,onNavigate:c,transport:p,workLabelCache:a,prefs:d,view:u,onViewChange:m}){var ce;const{convert:x}=V(),g=wt(),[b,w]=f.useState("text"),y=u??b,j=B=>{w(B),m==null||m(B)},h=l.trim(),v=(s==null?void 0:s.type)==="kaozhen",$=f.useCallback(B=>h?sn(B,h,g):B,[h,g]),k=B=>qi(B,{renderText:$,properNames:d.properNames}),_=f.useMemo(()=>h?e.sections.filter(B=>Xi(B,h,v,g)):e.sections,[e.sections,h,v,g]),S=(B,D)=>D.filter(A=>Je(A.type)===B).length,z=S("书",e.sections),N=S("诗",e.sections),R=S("考证",e.sections);let C="";v?C=h?`${S("考证",_)} / ${R} ${x("條")}`:`${R} ${x("條")}`:N>0?C=h?`${S("诗",_)} / ${N} 首`:`${N} 首`:z>0&&(C=h?`${S("书",_)} / ${z} ${x("部書")}`:`${z} ${x("部書")}`);const H=s!=null&&s.text_quality?fp(s.text_quality.grade):null,L=[];C&&L.push(C),v&&(s!=null&&s.target_source)&&L.push(t.jsxs(t.Fragment,{children:[x("考證對象")," ",x(s.target_source)]})),H&&L.push(t.jsx("span",{title:fa[H],children:(ce=s==null?void 0:s.text_quality)!=null&&ce.source_note?t.jsxs(t.Fragment,{children:["底本 ",x(s.text_quality.source_note),t.jsx("span",{className:"bim-rd-grade",children:x(ti[H])})]}):t.jsxs(t.Fragment,{children:[x("文本質量"),t.jsx("span",{className:"bim-rd-grade",children:x(ti[H])})]})})),e.source_url&&L.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:x("原文來源")}));const M=!v&&ul(e.sections),F=!!n&&(!M||d.readingMode==="paragraph"&&Qt(n)),X=!v&&(M||!!n),U=v||!X?"entries":y;let T=0;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[(o||r)&&t.jsxs("p",{className:"bim-rd-kicker",children:[o,o&&r&&t.jsx("span",{className:"bim-rd-dot"}),r&&x(r)]}),t.jsx("h1",{className:"bim-rd-h1",children:x(e.title)}),L.length>0&&t.jsx("p",{className:"bim-rd-meta",children:L.map((B,D)=>t.jsxs(f.Fragment,{children:[D>0&&t.jsx("span",{className:"bim-rd-dot"}),B]},D))}),X&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":"看法",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":U==="text",onClick:()=>j("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":U==="entries",onClick:()=>j("entries"),children:x("條目")})]})]}),U==="text"&&t.jsx("article",{className:"bim-rd-prose",children:F?t.jsx(Ji,{text:n,mode:d.readingMode,properNames:d.properNames,renderText:$,dropTitle:e.title}):t.jsx(Wp,{sections:e.sections,onNavigate:c,inline:k,workLinks:d.workLinks})}),U==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:v?t.jsx(Bp,{juan:e,searchQuery:l,onNavigate:c,transport:p,workLabelCache:a}):t.jsxs(t.Fragment,{children:[_.some(B=>["书","诗","考证"].includes(Je(B.type)))&&t.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[t.jsx("span",{style:{width:28},children:"序"}),t.jsx("span",{style:{flex:1},children:"书名"}),t.jsx("span",{children:"作品"})]}),_.map((B,D)=>{const A=Je(B.type);return A==="书"||A==="诗"||A==="考证"?(T+=1,t.jsx(Tp,{domId:`rd-e-${e.sections.indexOf(B)}`,section:B,onNavigate:d.workLinks?c:void 0,highlightQuery:h,no:T,showUnlinked:d.workLinks&&!!c},D)):A==="类"?t.jsx(Ip,{section:B,highlightQuery:h},D):t.jsx(Rp,{section:B,highlightQuery:h},D)}),_.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function xl(e){return e.juan_files&&e.juan_files.length>0?e.juan_files:e.files&&e.files.length>0?e.files.map(n=>n.filename):[]}function Fp(e){const n=xl(e);return n.length>0?n[0]:null}function Pp(e){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:l,activeRawText:c,query:p,isKaozhen:a}=e,d=wt(),u=f.useRef(new Map),[m,x]=f.useState({}),[g,b]=f.useState({}),w=f.useCallback((j,h)=>{const v=h==null?void 0:h.title;v&&b($=>$[j]===v?$:{...$,[j]:v})},[]);f.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:c}),w(s,l))},[s,l,c,w]),f.useEffect(()=>{u.current.clear(),x({}),b({})},[n]);const y=f.useCallback((j,h)=>{let v=0;if(j.juan)for(const $ of j.juan.sections)Xi($,h,a,d)&&v++;return v===0&&j.rawText&&wp(j.rawText,h,d)&&(v=1),v},[a,d]);return f.useEffect(()=>{const j=p.trim();if(!j){x({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let h=!1;const v={},$=[];for(const N of r){const R=u.current.get(N);R?v[N]=y(R,j):(v[N]="loading",$.push(N))}x(v);const k=8;let _=0;const S=async()=>{var N;for(;_<$.length;){if(h)return;const R=_++,C=$[R];try{const[H,L]=await Promise.all([o.getCollatedJuan(n,C),((N=o.getCollatedJuanText)==null?void 0:N.call(o,n,C))??Promise.resolve(null)]),M={juan:H,rawText:L};if(u.current.set(C,M),w(C,H),h)return;x(F=>({...F,[C]:y(M,j)}))}catch{if(h)return;x(H=>({...H,[C]:0}))}}},z=Array.from({length:Math.min(k,$.length)},()=>S());return Promise.all(z),()=>{h=!0}},[p,n,o,r.join(","),y,d,w]),{matchStates:m,titles:g}}function Op({juan:e,view:n,onView:o,textHasEntries:r}){const{convert:s}=V(),l=e.sections.map((d,u)=>({s:d,i:u,t:Je(d.type)})).filter(d=>d.t==="书"||d.t==="诗");if(l.length===0)return null;const c=l.filter(d=>!!d.s.work_id).length,p=l.every(d=>d.t==="诗")?"首":"部书",a=d=>{const u=()=>{var m,x;return(x=(m=document.getElementById(`rd-e-${d}`))==null?void 0:m.scrollIntoView)==null?void 0:x.call(m,{block:"start",behavior:"smooth"})};n==="text"&&!r&&o("entries"),n==="text"&&!r?setTimeout(u,0):u()};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-rd-rail-card",children:[t.jsx("div",{className:"bim-rd-rail-cap",children:"本卷"}),t.jsxs("div",{className:"bim-rd-rail-n",children:[t.jsx("b",{children:l.length}),t.jsx("span",{children:s(p)}),t.jsxs("span",{className:"bim-rd-rail-linked",children:["已关联 ",c]})]}),t.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":`已关联 ${c} / ${l.length}`,children:t.jsx("span",{style:{width:`${Math.round(c/l.length*100)}%`}})})]}),t.jsxs("nav",{"aria-label":"本卷条目",children:[t.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:s("條目")}),t.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:d,i:u})=>t.jsx("li",{children:t.jsxs("a",{href:`#rd-e-${u}`,onClick:m=>{m.preventDefault(),a(u)},children:[t.jsx("span",{className:`bim-rd-rail-dot${d.work_id?" on":""}`,"aria-hidden":"true"}),t.jsx("span",{children:s(d.book_title||d.title)})]})},u))})]})]})}function Dp(e,n){const[o,r]=f.useState([]);return f.useEffect(()=>{if(r([]),!e||typeof(n==null?void 0:n.getItem)!="function")return;let s=!1;return Promise.resolve(n.getItem(e)).then(l=>{if(s||!l)return;const c=l.authors??[];r(c.filter(p=>p&&p.name))}).catch(()=>{}),()=>{s=!0}},[e,n]),o}const no=({index:e,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:l,className:c,style:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:m,imagePanel:x,allowVertical:g,onReportError:b,revisedAt:w})=>{const[y,j]=f.useState(null),[h,v]=f.useState(!1),[$,k]=f.useState(null),[_,S]=f.useState(null),[z,N]=f.useState(null),[R,C]=f.useState(!1),[H,L]=f.useState(null),[M,F]=f.useState(""),X=f.useRef(new Map),U=f.useRef(0),T=s??_,ce=f.useCallback(q=>{S(q),l==null||l(q)},[l]),B=e||y;f.useEffect(()=>{e&&(v(!1),k(null))},[e]),f.useEffect(()=>{if(e||!n||!(o!=null&&o.getCollatedEditionIndex))return;let q=!1;return v(!0),k(null),o.getCollatedEditionIndex(n).then(ie=>{q||(ie?j(ie):k("未找到整理本数据"))}).catch(ie=>{q||k(ie instanceof Error?ie.message:"加载失败")}).finally(()=>{q||v(!1)}),()=>{q=!0}},[e,n,o]),f.useEffect(()=>{if(B&&!T){const q=Fp(B);q&&ce(q)}},[B,T,ce]);const D=n||(B==null?void 0:B.work_id),A=f.useCallback(async q=>{var pe;if(!D||!(o!=null&&o.getCollatedJuan))return;const ie=++U.current;C(!0),N(null),L(null);try{const[ge,Ee]=await Promise.all([o.getCollatedJuan(D,q),((pe=o.getCollatedJuanText)==null?void 0:pe.call(o,D,q))??Promise.resolve(null)]);if(ie!==U.current)return;N(ge),L(Ee)}catch{if(ie!==U.current)return;N(null),L(null)}finally{ie===U.current&&C(!1)}},[D,o]);f.useEffect(()=>{T&&A(T)},[T,A]);const ee=q=>{ce(q)};if(h)return t.jsx("div",{className:c,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if($)return t.jsx("div",{className:c,style:{...p,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:$});if(!B)return null;const de=B.type==="kaozhen",G=xl(B);return t.jsx(Up,{className:c,style:p,index:B,allFiles:G,isKaozhen:de,effectiveWorkId:D,transport:o,activeFile:T,handleSelectFile:ee,juanData:z,juanRawText:H,juanLoading:R,searchQuery:M,setSearchQuery:F,onNavigate:r,workLabelCacheRef:X,reader:{title:a,subtitle:d,resolveImages:u,renderImageOverlay:m,imagePanel:x,allowVertical:g,onReportError:b,revisedAt:w}})};function fi(e,n,o,r){var d,u,m,x;const s=(u=(d=n.juan_metadata)==null?void 0:d[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:$p(e)),p=((x=(m=n.files)==null?void 0:m.find(g=>g.filename===e))==null?void 0:x.title)??o[e];if(!p)return{position:l,label:l};const a=r(p);return{position:l,label:l===p||l===a?a:`${l} ${a}`}}function Hp(e,n){if(!n)return;const o=r=>{var s;for(const l of r??[]){const c=o(l.children);if(c)return c;if((s=l.files)!=null&&s.includes(n))return l.label}};return o(e==null?void 0:e.juan_groups)}function Gp(e,n,o,r,s){const l=a=>a==="loading"?"…":typeof a=="number"&&a>0?a:void 0,c=(a,d)=>({key:a,label:d??fi(a,e,r,s).label,hint:l(o[a]),disabled:o[a]===0}),p=(a,d)=>{var m;if(a.files.length===1&&!((m=a.children)!=null&&m.length))return c(a.files[0],s(a.label));const u=_p(a,o);return{key:`group:${d}`,label:s(a.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:pl(a),defaultExpanded:typeof u=="number"&&u>0,children:[...a.files.map(x=>c(x)),...(a.children??[]).map((x,g)=>p(x,`${d}.${g}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((a,d)=>p(a,`${d}`)):n.map(a=>c(a))}const Up=({className:e,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:c,activeFile:p,handleSelectFile:a,juanData:d,juanRawText:u,juanLoading:m,searchQuery:x,setSearchQuery:g,onNavigate:b,workLabelCacheRef:w,reader:y})=>{const{convert:j}=V(),[h,v]=Hi(),[$,k]=f.useState("text");f.useEffect(()=>{k("text")},[p]);const{matchStates:_,titles:S}=Pp({workId:l,transport:c,files:r,activeFile:p,activeJuan:d,activeRawText:u,query:x,isKaozhen:s}),z=dl(y.resolveImages,p),N=f.useMemo(()=>Gp(o,r,_,S,j),[o,r,_,S,j]),R=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:D=>g(D.target.value)}),C=s?"章":o.juan_metadata&&Object.values(o.juan_metadata).some(D=>D.vol_label)?"冊":"卷",H=p?fi(p,o,S,j).position:void 0,L=Fe(),M=y.title??(o.title?j(o.title):void 0),F=M&&l&&b?t.jsx("a",{href:L(l),onClick:D=>{D.metaKey||D.ctrlKey||(D.preventDefault(),b(l))},title:"查看作品",children:M}):M,X=!!d&&!s&&ul(d.sections),U=X&&!(u&&h.readingMode==="paragraph"&&Qt(u)),T=d&&!s&&X?t.jsx(Op,{juan:d,view:$,onView:k,textHasEntries:U}):void 0,ce=Dp(l,c),B=ce.length>0?j(ce.slice(0,2).map(D=>`${D.dynasty?`〔${D.dynasty}〕`:""}${D.name}${D.role?` ${D.role}`:" 撰"}`).join("、")):void 0;return t.jsxs(Gi,{className:e,style:n,title:F,subtitle:y.subtitle??j(s?"考證":"整理本"),byline:B,pagerUnit:C,rail:T,revisedAt:y.revisedAt,onReportError:y.onReportError?D=>y.onReportError({...D,bookTitle:o.title??(typeof y.title=="string"?y.title:void 0),entryId:l}):void 0,current:p?fi(p,o,S,j).label:void 0,workLinkToggle:!s&&!!b&&!!(d!=null&&d.sections.some(D=>D.work_id)),toc:N,tocCaption:`目录 · ${r.length} ${j(C)}`,tocHeader:R,activeKey:p,onSelect:a,images:z.images,imagesLoading:z.loading,renderImageOverlay:y.renderImageOverlay,imagePanel:y.imagePanel,prefs:h,onPrefsChange:v,paragraphToggle:!s&&Qt(u),allowVertical:y.allowVertical,children:[m?t.jsx(kt,{}):d?t.jsx(Mp,{juan:d,rawText:u,positionLabel:H,groupLabel:Hp(o,p),index:o,searchQuery:x,onNavigate:b,transport:c,workLabelCache:w,prefs:h,view:$,onViewChange:k},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,o.references&&o.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:j("參考文獻")}),t.jsx("ol",{children:o.references.map((D,A)=>t.jsxs("li",{children:[D.url?t.jsx("a",{className:"bim-rd-link",href:D.url,target:"_blank",rel:"noopener noreferrer",children:D.title}):t.jsx("span",{children:D.title}),D.author&&t.jsxs("span",{children:[",",D.author]}),D.note&&t.jsxs("span",{children:["。",D.note]})]},A))})]})]})},Vp={bug:{label:"错误反馈",color:i("danger")},resource:{label:"资源建议",color:i("primary")},suggestion:{label:"功能建议",color:i("primary")},other:{label:"其他",color:i("desc-fg")}},Yp={label:"其他",color:i("desc-fg")},Kp={pending:{label:"待处理",color:i("warning")},in_progress:{label:"处理中",color:i("primary")},resolved:{label:"已处理",color:i("success")},wontfix:{label:"不采纳",color:i("desc-fg")},duplicate:{label:"重复",color:i("desc-fg")}},qp={label:"待处理",color:i("warning")};function Jp(e){try{const n=new Date(e),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return e}}function Zp(e,n){if(!e)return!1;try{const o=new URL(e,n);if(o.protocol!=="http:"&&o.protocol!=="https:")return!1;const r=new URL(n);return o.hostname===r.hostname}catch{return!1}}const io=({items:e,loading:n})=>{const o=Fe();return n?t.jsx(kt,{}):e.length===0?t.jsx("div",{style:Xp,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Vp[r.type]||Yp,l=Kp[r.status]||qp,c=typeof window<"u"&&Zp(r.pageUrl,window.location.href);return t.jsxs("div",{style:Qp,children:[t.jsxs("div",{style:eu,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...sr,background:s.color},children:s.label}),t.jsx("span",{style:{...sr,background:l.color},children:l.label})]}),t.jsx("span",{style:tu,children:Jp(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:nu,children:[r.resourceId&&t.jsx("a",{href:o(r.resourceId),style:Kn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(c?t.jsx("a",{href:r.pageUrl,style:Kn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Kn,children:r.pageUrl}))]}),t.jsx("div",{style:iu,children:r.content}),r.reply&&t.jsxs("div",{style:ou,children:[t.jsx("div",{style:ru,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Xp={textAlign:"center",padding:"40px 0",color:i("desc-fg"),fontSize:"14px"},Qp={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"16px"},eu={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},sr={fontSize:"12px",color:i("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},tu={fontSize:"12px",color:i("desc-fg")},nu={fontSize:"12px",marginBottom:"6px"},Kn={color:i("primary"),textDecoration:"none",borderBottom:`1px dashed ${i("primary")}`},iu={fontSize:"14px",lineHeight:"1.6",color:i("fg"),whiteSpace:"pre-wrap"},ou={marginTop:"12px",padding:"10px 12px",background:i("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:i("fg")},ru={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:i("primary")},mi=({transport:e,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const c=me(),[p,a]=f.useState(null),[d,u]=f.useState([]),[m,x]=f.useState("recommend"),[g,b]=f.useState([]),[w,y]=f.useState(!1),j=r??m,h=F=>{x(F),s==null||s(F)},[v,$]=f.useState(!0),[k,_]=f.useState(null),[S,z]=f.useState(null),[N,R]=f.useState(null);f.useEffect(()=>{let F=!1;if(e.getCounts)return e.getCounts().then(X=>{F||a({works:X.works,books:X.books,collections:X.collections})}).catch(()=>{}),()=>{F=!0}},[e]),f.useEffect(()=>{let F=!1;return(async()=>{if(o)return o;if(e.getRecommended)try{const U=await e.getRecommended();if(U!=null&&U.groups)return U.groups.flatMap(T=>T.items.map(ce=>({...ce,group:T.name})))}catch{}return[]})().then(async U=>{if(F)return;const T=U.filter(B=>B.id);if(T.length===0){$(!1);return}const ce=await Promise.all(T.map(async B=>{if(B.type)return{id:B.id,title:B.title,type:B.type,author:B.author,dynasty:B.dynasty,role:B.role,edition:B.edition,has_text:B.has_text,has_image:B.has_image,has_collated:B.has_collated,subtype:B.subtype,primary_name:B.primary_name,group:B.group,fallbackDescription:B.description};try{let D=null;if(e.getEntry)D=await e.getEntry(B.id);else{const A=await e.getItem(B.id);A&&(D={id:B.id,title:A.title||B.id,type:A.type||"work"})}if(D)return{...D,group:B.group,fallbackDescription:B.description}}catch{}return{id:B.id,title:B.title,type:$e.extractType(B.id),group:B.group,fallbackDescription:B.description}}));F||(u(ce.filter(B=>B!==null)),$(!1))}),()=>{F=!0}},[e,o]);const C=f.useRef(!1),H=f.useRef(!1),L=f.useRef(!1);f.useEffect(()=>{if(j!=="catalog"||C.current)return;const F=e.getCatalogProgress??e.getResourceProgress;if(!F)return;C.current=!0;let X=!1;return F.call(e).then(U=>{X||_(U)}).catch(()=>{C.current=!1}),()=>{X=!0}},[e,j]),f.useEffect(()=>{if(j!=="collection"||H.current||!e.getCollectionProgress)return;H.current=!0;let F=!1;return e.getCollectionProgress().then(X=>{F||z(X)}).catch(()=>{H.current=!1}),()=>{F=!0}},[e,j]),f.useEffect(()=>{if(j!=="site"||L.current||!e.getSiteProgress)return;L.current=!0;let F=!1;return e.getSiteProgress().then(X=>{F||R(X)}).catch(()=>{L.current=!1}),()=>{F=!0}},[e,j]),f.useEffect(()=>{if(!l||j!=="feedback")return;let F=!1;return y(!0),fetch(l).then(X=>X.json()).then(X=>{!F&&X.success&&b(X.items||[])}).catch(()=>{}).finally(()=>{F||y(!1)}),()=>{F=!0}},[l,j]);const M=F=>t.jsx(Wt,{type:F,size:12});return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:i("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"16px"},children:[t.jsx(Gt,{label:c.home.recommendTab,active:j==="recommend",onClick:()=>h("recommend")}),t.jsx(Gt,{label:c.home.catalogTab,active:j==="catalog",onClick:()=>h("catalog")}),t.jsx(Gt,{label:c.home.collectionTab,active:j==="collection",onClick:()=>h("collection")}),t.jsx(Gt,{label:c.home.siteTab,active:j==="site",onClick:()=>h("site")}),l&&t.jsx(Gt,{label:c.home.feedbackTab,active:j==="feedback",onClick:()=>h("feedback")})]}),j==="recommend"&&t.jsx(su,{recommended:d,loading:v,onNavigate:n,getIcon:M,t:c}),j==="catalog"&&t.jsx(lr,{progress:k,t:c,onNavigate:n}),j==="collection"&&t.jsx(lr,{progress:S,t:c,onNavigate:n}),j==="site"&&t.jsx(au,{progress:N,t:c,totalWorks:(p==null?void 0:p.works)??0}),j==="feedback"&&l&&t.jsx(io,{items:g,loading:w})]})})},Gt=({label:e,active:n,onClick:o})=>t.jsx("button",{onClick:o,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:i(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${i("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),su=({recommended:e,loading:n,onNavigate:o,getIcon:r,t:s})=>{const l=Fe();if(n)return t.jsx(kt,{});if(e.length===0)return null;const c=new Map;for(const p of e){const a=p.group||s.home.recommendedBrowse;c.has(a)||c.set(a,[]),c.get(a).push(p)}return t.jsx(t.Fragment,{children:Array.from(c.entries()).map(([p,a])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:p}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return t.jsxs("a",{href:l(d.id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),o==null||o(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,cursor:"pointer",background:i("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},lr=({progress:e,t:n,onNavigate:o})=>{if(!e)return t.jsx(kt,{});const r=[...e.resources].sort((p,a)=>p.priority-a.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},c={in_progress:i("progress-active"),done:i("progress-done"),todo:i("progress-todo")};return t.jsx("div",{children:s.map(p=>{const a=r.filter(d=>d.status===p);return a.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:c[p]}}),l[p]," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>t.jsx(lu,{item:d,t:n,statusColor:c[p],onNavigate:o},d.id))})]},p)})})},lu=({item:e,t:n,statusColor:o,onNavigate:r})=>{const s=Fe(),l=e.total>0?Math.round(e.imported/e.total*100):0,c=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=e.edition?`${e.name}·${e.edition}`:e.name,a=e.collection_id||e.work_id;return a&&r?t.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:p}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:i("widget-border"),color:i("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:c})]}),t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Qe(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:o,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:e.description})]})},au=({progress:e,t:n,totalWorks:o})=>{if(!e)return t.jsx(kt,{});const r=[...e.resources].sort((a,d)=>a.priority-d.priority),s=r.filter(a=>a.imported>0),l=r.filter(a=>a.imported===0),c=s.reduce((a,d)=>Math.max(a,d.imported),0),p=o>0?Math.round(c/o*100):0;return t.jsxs("div",{children:[o>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${i("primary")} 6%, transparent)`,fontSize:"13px",color:i("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:c.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>t.jsx(ar,{item:a,t:n,totalWorks:o},a.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(a=>t.jsx(ar,{item:a,t:n,totalWorks:o},a.id))})]})]})},ar=({item:e,t:n,totalWorks:o})=>{const r=o>0?Math.round(e.imported/o*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:t.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&o>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:i("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:e.description})]})},cr="(max-width: 768px)";function cu(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(cr).matches);return f.useEffect(()=>{const o=window.matchMedia(cr),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),e}const du=({transport:e,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var X;const l=me(),{convert:c}=V(),p=cu(),[a,d]=f.useState(null),[u,m]=f.useState(null),[x,g]=f.useState(!1),[b,w]=f.useState("detail"),[y,j]=f.useState([]),[h,v]=f.useState(!1),[$,k]=f.useState(null),[_,S]=f.useState(!1),z=f.useCallback(async U=>{if(!e.getCollatedEditionIndex){k(null);return}S(!0);try{const T=await e.getCollatedEditionIndex(U);k(T)}catch{k(null)}finally{S(!1)}},[e]),N=f.useCallback(async U=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){j([]);return}v(!0);try{if(e.getCollectionCatalogs){const T=await e.getCollectionCatalogs(U);j(T||[])}else if(e.getCollectionCatalog){const T=await e.getCollectionCatalog(U);j(T?[{resource_id:"",data:T}]:[])}}catch{j([])}finally{v(!1)}},[e]),R=f.useCallback(async U=>{if(o){o(U);return}d(U),m(null),j([]),k(null),w("detail"),g(!0);try{const T=await e.getItem(U.id);T&&(m(T),T.type==="collection"?N(U.id):T.type==="work"&&T.has_collated&&z(U.id))}catch(T){console.error("加载详情失败:",T)}finally{g(!1)}},[e,o,N,z]),C=f.useCallback(async U=>{m(null),j([]),k(null),w("detail"),g(!0);try{const T=await e.getItem(U);T&&(m(T),d({id:U,title:T.title||U,type:T.type||"book"}),T.type==="collection"?N(U):T.type==="work"&&T.has_collated&&z(U))}catch(T){console.error("导航失败:",T)}finally{g(!1)}},[e,N,z]),H=(u==null?void 0:u.type)==="collection"&&(y.length>0||h)||(u==null?void 0:u.type)==="work"&&($||_),L=p&&(x||u),M=f.useCallback(()=>{d(null),m(null),j([]),k(null),w("detail")},[]),F=t.jsx(t.Fragment,{children:x?t.jsx(kt,{}):u?t.jsxs(t.Fragment,{children:[(H||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${i("widget-border")}`,padding:p?"0 12px":"0 48px",background:i("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[H&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>w("detail"),style:mn(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&h&&y.length===0&&t.jsxs("button",{onClick:()=>{},style:mn(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&y.map(U=>t.jsx("button",{onClick:()=>w(`catalog:${U.resource_id}`),style:mn(b===`catalog:${U.resource_id}`),children:U.short_name?`${c(U.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},U.resource_id)),u.type==="work"&&($||_)&&t.jsxs("button",{onClick:()=>w("collated"),style:mn(b==="collated"),children:[l.detailTab.collatedEdition,_&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?t.jsx(Ei,{data:u,transport:e,onNavigate:C}):b.startsWith("catalog:")?t.jsx(Ri,{data:(X=y.find(U=>`catalog:${U.resource_id}`===b))==null?void 0:X.data,onNavigate:C}):b==="collated"?t.jsx(no,{index:$||void 0,workId:u.id,transport:e,onNavigate:C}):null})]}):t.jsx(mi,{transport:e,onNavigate:C,recommendedIds:r})});return p?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:L?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${i("widget-border")}`,background:i("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:M,style:{padding:"4px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:F})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(ii,{transport:e,onEntryClick:R,hideModeIndicator:n}),!u&&t.jsx(mi,{transport:e,onNavigate:C,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${i("widget-border")}`,display:"flex",flexDirection:"column",background:i("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(ii,{transport:e,onEntryClick:R,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:i("bg"),display:"flex",flexDirection:"column"},children:F})]})};function mn(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function ft(e){return e.replace(/\.md$/,"")}function dr(e){let n="";if(e.source_url)try{const r=new URL(e.source_url).pathname.split("/").filter(Boolean).pop()??"";n=decodeURIComponent(r).replace(/_/g," ")}catch{}return[e.source_name,n||e.version_label].filter(Boolean).join(" · ")||e.key}const pr={padding:24,color:i("desc-fg")},gi=({index:e,bookId:n,transport:o,activeChapter:r,onChapterChange:s,workKey:l,versions:c,onVersionChange:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:m,imagePanel:x,allowVertical:g,onReportError:b,revisedAt:w,className:y,style:j})=>{const[h,v]=f.useState(e??null),[$,k]=f.useState(!1),[_,S]=f.useState(null),z=r!==void 0?r:_,N=f.useCallback(G=>{s?s(G):S(G)},[s]),[R,C]=f.useState(null),[H,L]=f.useState(!1);f.useEffect(()=>{e&&v(e)},[e]),f.useEffect(()=>{if(e)return;v(null),k(!1);const G=l!==void 0?o.getWorkFullTextIndex?()=>o.getWorkFullTextIndex(n,l):null:o.getBookFullTextIndex?()=>o.getBookFullTextIndex(n):null;if(!n||!G){k(!0);return}let q=!1;return Promise.resolve().then(G).then(ie=>{q||(ie?v(ie):k(!0))}).catch(()=>{q||k(!0)}),()=>{q=!0}},[n,o,e,l]),f.useEffect(()=>{if(!h||h.chapters.length===0)return;const G=ft(h.chapters[0].file);if(!z){N(G);return}const q=ft(z);h.chapters.some(pe=>ft(pe.file)===q)||N(G)},[h,z,N]);const M=f.useMemo(()=>{if(!h||!z)return null;const G=ft(z);return h.chapters.find(q=>ft(q.file)===G)??null},[h,z]);f.useEffect(()=>{if(!n||!M)return;const G=l!==void 0?o.getWorkFullTextChapter?ie=>o.getWorkFullTextChapter(n,l,ie):null:o.getBookFullTextChapter?ie=>o.getBookFullTextChapter(n,ie):null;if(!G)return;let q=!1;return L(!0),C(null),Promise.resolve(M.file).then(G).then(ie=>{q||C(ie)}).catch(()=>{q||C(null)}).finally(()=>{q||L(!1)}),()=>{q=!0}},[n,M,o,l]);const F=dl(u,M?ft(M.file):null),[X,U]=Hi(),{convert:T}=V(),ce=!!(c&&c.length>1&&p),B=f.useMemo(()=>ce?qs(c).map((G,q)=>({...G,label:dr(c[q])})):void 0,[ce,c]),D=ce?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:G=>p(G.target.value),children:c.map(G=>t.jsx("option",{value:G.key,children:dr(G)},G.key))})]}):null;if(!h)return t.jsxs("div",{style:pr,children:[D&&t.jsx("div",{style:{marginBottom:12},children:D}),$?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:pr,children:[D&&t.jsx("div",{style:{marginBottom:12},children:D}),"全文目录为空"]});const A=h.chapters.map(G=>({key:ft(G.file),label:T(G.title)})),ee=Qs(h)||si(h),de=R?R.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(Gi,{title:a??T(h.version_label),subtitle:d??"全文",toc:A,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:z?ft(z):null,onSelect:N,images:F.images,imagesLoading:F.loading,renderImageOverlay:m,imagePanel:x,prefs:X,onPrefsChange:U,versions:B,currentVersionKey:B?l??null:void 0,onVersionChange:B?p:void 0,versionSource:!1,paragraphToggle:Qt(de),allowVertical:g,revisedAt:w,onReportError:b?G=>b({...G,bookTitle:a===void 0?T(h.version_label):typeof a=="string"?a:void 0,entryId:n}):void 0,className:y,style:j,children:[M&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:T(M.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:h.source.url,target:"_blank",rel:"noreferrer",children:T(h.source.name)}),h.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),h.source.license]})]})]}),H&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!H&&de!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Ji,{text:de,mode:X.readingMode,tables:ee,gujiMarkdown:si(h),properNames:X.properNames})}),!H&&!R&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},pu=({data:e,onNavigate:n,className:o,style:r})=>{var u;const s=me(),{convert:l}=V(),[c,p]=f.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[a,d]=f.useState(null);return t.jsxs("div",{className:o,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:l(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[s.catalog.totalVolumes," ",t.jsx("strong",{children:e.total_volumes})," ",s.unit.juan]}),e.stats.zhulu!=null&&t.jsxs("span",{children:["著錄 ",t.jsx("strong",{children:e.stats.zhulu})," ",s.unit.bu]}),e.stats.cunmu!=null&&t.jsxs("span",{children:["存目 ",t.jsx("strong",{children:e.stats.cunmu})," ",s.unit.bu]}),e.stats.categories!=null&&t.jsxs("span",{children:[e.stats.categories," 類"]})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(m=>t.jsx(uu,{division:m,expanded:c===m.name,onToggle:()=>p(c===m.name?null:m.name),expandedCat:a,onCatToggle:x=>d(a===x?null:x),onNavigate:n},m.name))})]})},uu=({division:e,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:c}=V(),p=e.categories.reduce((a,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return a+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${i("primary")} 6%, transparent)`:i("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:i("fg"),textAlign:"left"},children:[t.jsx("span",{children:c(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg")},children:[e.categories.length," 類 · ",p," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(a=>{const d=`${e.name}/${a.name}`;return t.jsx(xu,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:l},a.name)})})]})},xu=({category:e,expanded:n,onToggle:o,onNavigate:r})=>{var a,d,u,m;const{convert:s}=V(),l=((a=e.books)==null?void 0:a.zhulu)||[],c=((d=e.books)==null?void 0:d.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((m=e.stats)==null?void 0:m.cunmu)||c.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?i("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:i("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||c.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(ur,{label:"著錄",books:l,onNavigate:r}),c.length>0&&t.jsx(ur,{label:"存目",books:c,onNavigate:r})]})]})},ur=({label:e,books:n,onNavigate:o})=>{const{convert:r}=V(),s=Fe(),[l,c]=f.useState(n.length<=20),p=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((a,d)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:i("fg")},children:a.work_id&&o?t.jsx("a",{href:s(a.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),o(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},children:r(a.title)}):r(a.title)}),a.volumes&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:r(a.volumes)}),a.author&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:r(a.author).slice(0,20)})]},d))}),!l&&t.jsxs("button",{onClick:()=>c(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},Xe=({title:e,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const l=me();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:i("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&t.jsx("button",{onClick:o,style:mu,children:"AI"}),n&&t.jsx("button",{onClick:n,style:fu,children:l.action.save})]})]}),s]})},fu={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},mu={padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Ye=({label:e,value:n,onChange:o,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:l=>o(l.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),jt=({value:e,onChange:n,placeholder:o})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},wn=({children:e,color:n,style:o})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||i("primary-soft"),color:i(n?"on-color-fg":"fg"),...o},children:e});function gu(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const hn=({value:e,onChange:n,label:o})=>{const[r,s]=f.useState(!1),l=f.useRef(null),c=gu(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&c?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:xr,children:o}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${i("input-border")}`,borderRadius:"2px",background:i("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:i("fg")},children:c.name}),t.jsx(wn,{children:c.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:xr,children:o}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},xr={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500};function hu(e){switch(e){case"url":return i("source-url");case"bookID":return i("source-bookid");default:return i("desc-fg")}}function bu(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const fl=({items:e,onChange:n,onOpenEntityPicker:o})=>{const r=me(),[s,l]=f.useState(null),c=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},p=m=>{n(e.filter((x,g)=>g!==m)),s===m&&l(null)},a=(m,x,g)=>{const b=[...e];b[m]={...b[m],[x]:g},n(b)},d=(m,x)=>{const g=[...e];g[m]={...g[m],type:x,id:"",name:""},n(g),x==="bookID"&&o&&o(b=>{const w=[...e];w[m]={...w[m],id:b.id,name:b.title,type:"bookID"},n(w)})},u=m=>{o&&o(x=>{const g=[...e];g[m]={...g[m],id:x.id,name:x.title,type:"bookID"},n(g)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((m,x)=>t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===x?null:x),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===x?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:i("fg")},children:m.name||`${r.editor.sourcePlaceholder} ${x+1}`}),m.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:hu(m.type),color:i("on-color-fg"),borderRadius:"3px",fontWeight:500},children:bu(m.type)}),t.jsx("button",{onClick:g=>{g.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===x&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!m.type&&t.jsxs("div",{children:[t.jsx("label",{style:lt,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>d(x,"bookID"),style:{...fr,borderColor:i("source-bookid"),color:i("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>d(x,"url"),style:{...fr,borderColor:i("source-url"),color:i("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),m.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:lt,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const g=[...e];g[x]={...g[x],type:"",id:"",name:""},n(g)},style:mr,children:r.action.changeType})]}),m.id&&m.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:i("bg"),border:`1px solid ${i("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:i("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:m.name}),t.jsx("code",{style:{fontSize:"11px",background:i("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:m.id})]}),t.jsx("button",{onClick:()=>u(x),style:{background:"transparent",border:`1px solid ${i("widget-border")}`,color:i("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(x),style:{width:"100%",padding:"14px",border:`2px dashed ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),m.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:lt,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const g=[...e];g[x]={...g[x],type:"",id:"",name:""},n(g)},style:mr,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:m.name,onChange:g=>a(x,"name",g.target.value),placeholder:r.editor.sourceNamePlaceholder,style:$t})]}),t.jsxs("div",{children:[t.jsx("label",{style:lt,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:m.id,onChange:g=>a(x,"id",g.target.value),placeholder:"https://...",style:$t})]})]}),m.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${i("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...lt,opacity:.7},children:r.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:lt,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:m.details,onChange:g=>a(x,"details",g.target.value),placeholder:r.editor.detailsPlaceholder,style:$t})]}),t.jsxs("div",{children:[t.jsx("label",{style:lt,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:m.position,onChange:g=>a(x,"position",g.target.value),placeholder:"如: 卷三, p.52",style:$t})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:lt,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:m.version,onChange:g=>a(x,"version",g.target.value),placeholder:"如: v1.0, 2024-01",style:$t})]}),t.jsxs("div",{children:[t.jsx("label",{style:lt,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:m.processor_version,onChange:g=>a(x,"processor_version",g.target.value),placeholder:"如: v0.1",style:$t})]})]})]})]})})]},x)),t.jsxs("button",{onClick:c,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},lt={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},$t={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},fr={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:i("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},mr={background:"transparent",border:"none",color:i("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function ml(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(o=>({id:o.id||"",name:o.name||"",type:o.type||"",details:o.details||"",position:o.position||"",version:o.version||"",processor_version:o.processor_version||""}))}catch{}return[]}function gl(e){return!e||e.length===0?"":JSON.stringify(e)}const hl=({entityType:e,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:c,childWorks:p,childCollections:a,containedBooks:d,siblingBooks:u,onLinkEntity:m,onUnlinkEntity:x,onViewEntity:g,onCreateAndLink:b,onSaveRelations:w})=>{const y=me();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:y.section.relations})]}),w&&t.jsx("button",{onClick:w,style:yu,children:y.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Ut,{direction:"up",title:y.relation.belongsToWork,entity:l,onView:g,onUnlink:()=>x("workId"),onLink:()=>m("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(Ut,{direction:"up",title:y.relation.containedInCollection,entity:c,onView:g,onUnlink:()=>x("collectionId"),onLink:()=>m("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),l&&u&&u.length>0&&t.jsx(_t,{direction:"horizontal",title:`${y.relation.siblingVersions} (${u.length})`,entities:u,onView:g,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:y.relation.addVersionForWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Ut,{direction:"up",title:y.relation.parentWork,entity:r,onView:g,onUnlink:()=>x("parentWorkId"),onLink:()=>m("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),p&&p.length>0&&t.jsx(_t,{direction:"down",title:`${y.relation.childWorks} (${p.length})`,entities:p,onView:g,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:y.action.addSubWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),a&&a.length>0&&t.jsx(_t,{direction:"down",title:`${y.relation.collectionImpl} (${a.length})`,entities:a,onView:g,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:y.action.addCollectionImpl,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(_t,{direction:"down",title:`${y.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:g,onAdd:()=>b("childBook","book",{workId:n}),addLabel:y.action.addVersion,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Ut,{direction:"up",title:y.relation.correspondingWork,entity:l,onView:g,onUnlink:()=>x("workId"),onLink:()=>m("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(Ut,{direction:"up",title:y.relation.parentCollection,entity:s,onView:g,onUnlink:()=>x("parentCollectionId"),onLink:()=>m("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(_t,{direction:"down",title:`${y.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:g,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:y.action.addSubCollection,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(_t,{direction:"down",title:`${y.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:g,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:y.action.addBook,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]})]})]})},Ut=({direction:e,title:n,entity:o,onView:r,onUnlink:s,onLink:l,onCreate:c,linkLabel:p,createLabel:a,notLinkedLabel:d,viewLabel:u,unlinkLabel:m})=>{const x=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),g=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:g}),t.jsx("span",{children:n})]}),o?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:i("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:bl(o.type)}),t.jsx("span",{style:{fontWeight:500},children:o.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(gr,{onClick:()=>r(o),title:u,children:"👁️"}),t.jsx(gr,{onClick:s,title:m,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(hi,{onClick:l,children:p}),t.jsx(hi,{onClick:c,primary:!0,children:a})]})]})},_t=({direction:e,title:n,entities:o,onView:r,onAdd:s,addLabel:l,noneLabel:c,expandMoreLabel:p})=>{const[a,d]=f.useState(!1),u=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=a?o:o.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),o.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[x.map(g=>t.jsxs("div",{onClick:()=>r(g),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:i("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:bl(g.type)}),t.jsx("span",{children:g.title})]},g.id)),o.length>5&&!a&&t.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:i("link-fg"),cursor:"pointer"},children:[p," (",o.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:c}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(hi,{onClick:s,primary:!0,children:["+ ",l]})})]})},gr=({onClick:e,title:n,danger:o,children:r})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:o?i("danger"):"inherit",opacity:.7},children:r}),hi=({onClick:e,primary:n,children:o})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${i("widget-border")}`,borderRadius:"4px",background:n?i("primary"):"transparent",color:n?i("primary-fg"):"inherit",cursor:"pointer"},children:o});function bl(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const yu={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},yl=({isOpen:e,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:l,searchResults:c,onSearch:p,isLoading:a,excludeId:d})=>{const[u,m]=f.useState(""),x=d?c.filter(y=>y.id!==d):c;f.useEffect(()=>{e&&(m(""),p(""))},[e]);const g=y=>{m(y),p(y)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",w=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:ju,children:t.jsxs("div",{style:vu,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),t.jsx("button",{onClick:s,style:ku,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:y=>g(y.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:wu})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?t.jsx("div",{style:qn,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(y=>t.jsxs("div",{onClick:()=>r(y),style:Su,children:[t.jsx("span",{style:{fontSize:"16px"},children:w}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[y.title,y.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:y.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[y.id,y.author&&` · ${y.author}`,y.dynasty&&` · ${y.dynasty}`]})]})]},y.id))}):u?t.jsxs("div",{style:qn,children:["未找到匹配的",b]}):t.jsxs("div",{style:qn,children:["输入关键词搜索",b]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:l,style:$u,children:["创建新",b,"并关联"]})]})]})})},ju={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},vu={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},ku={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},wu={width:"100%",padding:"10px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},Su={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:i("primary-soft")},qn={padding:"20px",textAlign:"center",color:i("desc-fg")},$u={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},hr={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},_u={work:"📜",book:"📖",collection:"📚",entity:"👤"},jl=({isOpen:e,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:l})=>{const[c,p]=f.useState(""),a=f.useRef(null);f.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,g;(x=a.current)==null||x.focus(),(g=a.current)==null||g.select()},100))},[e,r==null?void 0:r.title]);const d=x=>{x.key==="Enter"&&c.trim()?u():x.key==="Escape"&&l()},u=()=>{c.trim()&&s(c.trim(),{...r,title:c.trim()})};if(!e)return null;const m=()=>{switch(o){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${hr[n]}`}};return t.jsx("div",{style:zu,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:Cu,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:_u[n]}),t.jsx("span",{children:m()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:i("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:i("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:a,type:"text",value:c,onChange:x=>p(x.target.value),onKeyDown:d,placeholder:`请输入${hr[n]}名称...`,style:Tu})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),background:i("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&t.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:l,style:Iu,children:"取消"}),t.jsx("button",{onClick:u,disabled:!c.trim(),style:{...Eu,opacity:c.trim()?1:.6,cursor:c.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},zu={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Cu={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:i("shadow-dialog")},Tu={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box"},Iu={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Eu={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg")};function Ru(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function vl(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Nu(e){switch(e){case"work":return i("editor-type-work");case"collection":return i("editor-type-collection");case"book":return i("editor-type-book");default:return i("desc-fg")}}const kl=({isOpen:e,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:c,onSelect:p,onCancel:a,onCreate:d,onSearch:u})=>{const[m,x]=f.useState(""),[g,b]=f.useState([]),[w,y]=f.useState(!1),[j,h]=f.useState("recent");f.useEffect(()=>{e&&(x(""),b([]),h(r.length>0?"recent":"search"))},[e,r.length]),f.useEffect(()=>{if(!m.trim()){b([]);return}const z=setTimeout(async()=>{y(!0);try{b(await u(m,o))}catch{b([])}finally{y(!1)}},300);return()=>clearTimeout(z)},[m,o,u]);const v=f.useCallback(z=>{x(z.target.value),z.target.value.trim()&&h("search")},[]),$=f.useCallback(z=>s?z.filter(N=>N.id!==s):z,[s]);if(!e)return null;const k=n||(o==="all"?"选择实体":`选择${vl(o)}`),_=$(r),S=$(g);return t.jsx("div",{style:Bu,children:t.jsxs("div",{style:Au,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:k}),t.jsx("button",{onClick:a,style:Wu,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:m,onChange:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Mu}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),w&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),_.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsxs(br,{active:j==="recent",onClick:()=>h("recent"),children:["最近使用 (",_.length,")"]}),t.jsxs(br,{active:j==="search",onClick:()=>h("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&_.length>0?t.jsx(yr,{entities:_,onSelect:p}):m.trim()?w?t.jsx(Jn,{message:"搜索中..."}):S.length>0?t.jsx(yr,{entities:S,onSelect:p}):t.jsx(Jn,{message:"未找到匹配的结果"}):t.jsx(Jn,{message:"输入关键词开始搜索"})}),l&&d&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:d,style:Fu,children:c||"创建新实体"})]})]})})},br=({active:e,onClick:n,children:o})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:o}),yr=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(o=>t.jsx(Lu,{entity:o,onClick:()=>n(o)},o.id))}),Lu=({entity:e,onClick:n})=>{const[o,r]=f.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Ru(e.type)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:e.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[t.jsx("code",{style:{fontSize:"10px",background:i("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&t.jsx("span",{children:e.author}),e.dynasty&&t.jsx("span",{children:e.dynasty})]})]}),t.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Nu(e.type),color:i("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:vl(e.type)})]})},Jn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:e}),Bu={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Au={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},Wu={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Mu={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},Fu={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Pu={work:i("editor-type-work"),collection:i("editor-type-collection"),book:i("editor-type-book"),entity:i("editor-type-entity")},Ou={work:"📜",collection:"📚",book:"📖",entity:"👤"},wl=({data:e,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:l,onDelete:c,onAskAI:p,renderSectionActions:a,onDownloadResource:d,downloadStatuses:u,relations:m,onRelationsChange:x})=>{var be;const g=me(),[b,w]=f.useState(!1),[y,j]=f.useState("work"),[h,v]=f.useState(""),[$,k]=f.useState(""),[_,S]=f.useState([]),[z,N]=f.useState(!1),[R,C]=f.useState(!1),[H,L]=f.useState("work"),[M,F]=f.useState(""),[X,U]=f.useState(),[T,ce]=f.useState(!1),[B,D]=f.useState(null),[A,ee]=f.useState([]);f.useRef(null);const de=e.type,G=de==="work",q=de==="collection",ie=de==="book",pe=f.useCallback((K,I)=>{n({...e,[K]:I})},[e,n]),ge=f.useCallback((K,I)=>{v(K),j(I),k(g.editor.selectToLink+g.indexType[I]),S([]),w(!0)},[g]),Ee=f.useCallback(K=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,K)},[r,e.id]),Ne=f.useCallback(K=>{s==null||s(K.id,K.type)},[s]),ze=f.useCallback((K,I,Y)=>{const fe={...Y,author:(Y==null?void 0:Y.author)||e.author,dynasty:Y==null?void 0:Y.dynasty};L(I),F(K),U(fe),C(!0)},[e.author]),Te=f.useCallback((K,I)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,M,{type:H,title:K,inheritData:I}),C(!1)},[r,e.id,M,H]),Ce=f.useCallback(K=>{if(!K.trim()){S([]);return}N(!0),r!=null&&r.searchEntities&&r.searchEntities(K,y).then(I=>{S(I),N(!1)}).catch(()=>{S([]),N(!1)})},[r,y]),Ae=f.useCallback(K=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,h,K.id),w(!1)},[r,e.id,h]),P=f.useCallback(()=>{o()},[o]),se=f.useCallback(K=>{D(()=>K),ce(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(ee).catch(()=>{})},[r]),re=f.useCallback((K,I)=>r!=null&&r.searchEntities?r.searchEntities(K,I==="all"?void 0:I):Promise.resolve([]),[r]),ye=f.useCallback(K=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(K),ee(I=>[K,...I.filter(Y=>Y.id!==K.id)].slice(0,10)),B==null||B(K),ce(!1),D(null)},[r,B]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${i("widget-border")}`,paddingBottom:"16px"},children:t.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Ou[de]}),t.jsx("span",{children:e.title||g.editor.untitled}),t.jsx(wn,{children:e.id}),t.jsx(wn,{color:Pu[de],children:g.indexType[de]})]})}),t.jsx(Xe,{title:g.section.basicInfo,onSave:o,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(hn,{label:G?g.editor.workTitle:q?g.editor.collectionTitle:g.editor.bookTitle,value:e.title,onChange:K=>pe("title",K)}),ie&&t.jsx(hn,{label:g.editor.belongsToWork,value:e.workName||"",onChange:K=>pe("workName",K)}),t.jsx(Ye,{label:g.editor.authorLabel,value:e.author||"",onChange:K=>pe("author",K)}),t.jsx(Ye,{label:g.editor.publicationYearLabel,value:e.publicationYear||"",onChange:K=>pe("publicationYear",K)}),(ie||q)&&t.jsx(hn,{label:g.editor.containedIn,value:e.collection||"",onChange:K=>pe("collection",K)}),(ie||q)&&t.jsx(Ye,{label:g.editor.holderLabel,value:e.holder||"",onChange:K=>pe("holder",K)}),(ie||q)&&t.jsx(Ye,{label:ie?g.editor.pageLabel:g.editor.volumeLabel,value:e.pages||"",onChange:K=>pe("pages",K)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(Ye,{label:g.editor.firstImageLabel,value:e.firstImage||"",onChange:K=>pe("firstImage",K)})})]})}),t.jsx(Xe,{title:g.section.description,onSave:o,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(jt,{value:e.description||"",onChange:K=>pe("description",K),placeholder:g.editor.descriptionPlaceholder})}),(((be=e.additional_works)==null?void 0:be.length)||0)>0&&t.jsx(Xe,{title:g.section.additionalWorks,onSave:o,children:t.jsx(Du,{items:e.additional_works||[],onChange:K=>pe("additional_works",K)})}),t.jsx(Xe,{title:g.section.indexedBy,onSave:o,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Hu,{items:e.indexed_by||[],onChange:K=>pe("indexed_by",K)})}),t.jsx(Xe,{title:g.section.emendatedBy,onSave:o,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Gu,{items:e.emendated_by||[],onChange:K=>pe("emendated_by",K)})}),t.jsx(Xe,{title:g.section.textResources,onSave:o,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(ni,{items:e.resources||[],onChange:K=>pe("resources",K),onDownload:d,downloadStatuses:u,filterType:"text"})}),t.jsx(Xe,{title:g.section.imageResources,onSave:o,children:t.jsx(ni,{items:e.resources||[],onChange:K=>pe("resources",K),onDownload:d,downloadStatuses:u,filterType:"image"})}),t.jsx(Xe,{title:g.section.sources,onSave:o,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(fl,{items:ml(e.sources||""),onChange:K=>pe("sources",gl(K)),onOpenEntityPicker:se})}),(ie||q)&&t.jsx(Xe,{title:g.section.provenance,onSave:o,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(jt,{value:e.provenance||"",onChange:K=>pe("provenance",K),placeholder:g.editor.provenancePlaceholder})}),ie&&t.jsx(Xe,{title:g.section.otherEditions,onSave:o,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(jt,{value:e.otherEditions||"",onChange:K=>pe("otherEditions",K),placeholder:g.editor.otherEditionsPlaceholder})}),t.jsx(hl,{entityType:de,entityId:e.id,entityTitle:e.title,parentWork:m==null?void 0:m.parentWork,parentCollection:m==null?void 0:m.parentCollection,belongsToWork:m==null?void 0:m.belongsToWork,belongsToCollection:m==null?void 0:m.belongsToCollection,childWorks:m==null?void 0:m.childWorks,childCollections:m==null?void 0:m.childCollections,containedBooks:m==null?void 0:m.containedBooks,siblingBooks:m==null?void 0:m.siblingBooks,onLinkEntity:ge,onUnlinkEntity:Ee,onViewEntity:Ne,onCreateAndLink:ze,onSaveRelations:P}),l&&c&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${i("danger-soft-border")}`,background:i("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:i("danger"),fontWeight:600,marginBottom:"8px"},children:g.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"12px"},children:g.editor.dangerZoneDesc}),t.jsx("button",{onClick:c,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("danger")}`,borderRadius:"4px",background:"transparent",color:i("danger"),cursor:"pointer"},children:g.editor.deleteEntity})]}),t.jsx(yl,{isOpen:b,entityType:y,title:$,onSelect:Ae,onCancel:()=>w(!1),onCreate:()=>{w(!1),ze(h,y)},searchResults:_,onSearch:Ce,isLoading:z,excludeId:e.id}),t.jsx(jl,{isOpen:R,entityType:H,relationField:M,inheritData:X,onConfirm:Te,onCancel:()=>C(!1)}),t.jsx(kl,{isOpen:T,title:g.action.selectBookOrWork,filterType:"all",recentEntities:A,excludeId:e.id,onSelect:ye,onCancel:()=>{ce(!1),D(null)},onSearch:re})]})};function Du({items:e,onChange:n}){const o=me(),r=(c,p,a)=>{const d=e.map((u,m)=>m===c?{...u,[p]:a}:u);n(d)},s=c=>n(e.filter((p,a)=>a!==c)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((c,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(Ye,{label:o.editor.bookNameLabel,value:c.book_title,onChange:a=>r(p,"book_title",a)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(Ye,{label:o.label.juanCount,value:c.n_juan!=null?String(c.n_juan):"",onChange:a=>r(p,"n_juan",a&&parseInt(a,10)||void 0)})}),t.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function Sl({items:e,onChange:n,showMeta:o,addLabel:r}){const s=me(),[l,c]=f.useState(null),p=(u,m,x)=>{const g=e.map((b,w)=>w===u?{...b,[m]:x||void 0}:b);n(g)},a=u=>{n(e.filter((m,x)=>x!==u)),l===u&&c(null)},d=()=>{n([...e,{source:""}]),c(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,m)=>{const x=l===m;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:x?`color-mix(in srgb, ${i("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>c(x?null:m),children:[t.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.2s",transform:x?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:g=>{g.stopPropagation(),a(m)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${i("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:i("muted")},children:"✕"})]}),!x&&o&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:i("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),x&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ye,{label:s.label.sourceName,value:u.source,onChange:g=>p(m,"source",g)}),t.jsx(Ye,{label:s.label.sourceBid,value:u.source_bid||"",onChange:g=>p(m,"source_bid",g)})]}),o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ye,{label:s.label.titleInfo,value:u.title_info||"",onChange:g=>p(m,"title_info",g)}),t.jsx(Ye,{label:s.label.authorInfo,value:u.author_info||"",onChange:g=>p(m,"author_info",g)})]}),t.jsx(Ye,{label:s.label.edition,value:u.edition||"",onChange:g=>p(m,"edition",g)})]}),t.jsx(jt,{value:u.summary||"",onChange:g=>p(m,"summary",g),placeholder:s.editor.summaryPlaceholder}),t.jsx(jt,{value:u.comment||"",onChange:g=>p(m,"comment",g),placeholder:s.editor.commentPlaceholder}),t.jsx(jt,{value:u.additional_comment||"",onChange:g=>p(m,"additional_comment",g),placeholder:s.editor.additionalCommentPlaceholder})]})]},m)}),t.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Hu({items:e,onChange:n}){const o=me();return t.jsx(Sl,{items:e,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function Gu({items:e,onChange:n}){const o=me();return t.jsx(Sl,{items:e,onChange:n,addLabel:o.action.addEmendatedBy})}function $l(e){var p,a,d,u,m,x,g;const n=((a=(p=e.authors)==null?void 0:p[0])==null?void 0:a.name)||"",o=((d=e.publication_info)==null?void 0:d.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(m=e.page_count)!=null&&m.number?String(e.page_count.number):((x=e.page_count)==null?void 0:x.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",c={id:e.id,title:e.title,type:e.type,author:n,publicationYear:o,holder:r,pages:s,description:l,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const b=e;if(Array.isArray(b.related_works)){const w=b.related_works.find(y=>y.relation==="part_of");w&&(c.parentWorkId=w.id,c.parentWorkName=w.title)}}if(e.type==="book"){const b=e;c.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(c.collectionId=(g=b.contained_in[0])==null?void 0:g.id)}return c}function Uu(e){const n={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.publicationYear?{year:e.publicationYear}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(n.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(n.work_id=e.workId,e.collectionId&&(n.contained_in=[{id:e.collectionId}])),n}const Vu=e=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:l,onChange:c,onSave:p,onDelete:a,onNavigate:d,renderLink:u,onAskAI:m,renderSectionActions:x,onDownloadResource:g,downloadStatuses:b,relations:w,onRelationsChange:y,headerExtra:j,className:h,style:v}=e;me();const[$,k]=f.useState(s),_=l?s:$;f.useEffect(()=>{s!==$&&k(s)},[s]);const S=f.useCallback(()=>{const M=_==="view"?"edit":"view";l?l(M):k(M)},[_,l]),[z,N]=f.useState(null);f.useEffect(()=>{o&&r&&r.getItem(o).then(M=>{M&&N(M)})},[o,r]);const R=n||z,C=f.useMemo(()=>R?$l(R):null,[R]),H=l||!n?t.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:_==="edit"?i("accent-bg"):"transparent",color:i(_==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?"切换到编辑模式":"切换到查看模式",children:_==="view"?"✏️ 编辑":"👁 查看"}):null,L=t.jsxs(t.Fragment,{children:[H,j]});return!R&&!C?t.jsx(kt,{}):_==="view"?t.jsx(Ei,{data:R,transport:r,onNavigate:d?M=>d(M):void 0,renderLink:u,headerExtra:L,className:h,style:v}):C?t.jsxs("div",{className:h,style:v,children:[L&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:L}),t.jsx(wl,{data:C,onChange:c||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:m,renderSectionActions:x,onDownloadResource:g,downloadStatuses:b,relations:w,onRelationsChange:y})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:i("muted")},children:"无数据"})},jr=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],_l=({isOpen:e,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,l]=f.useState(null),[c,p]=f.useState(""),[a,d]=f.useState(""),[u,m]=f.useState("idle"),[x,g]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{e&&(l(null),p(""),d(""),m("idle"),g(""))},[e]),f.useEffect(()=>{s&&setTimeout(()=>{var h;return(h=b.current)==null?void 0:h.focus()},100)},[s]),f.useEffect(()=>{if(u==="success"){const h=setTimeout(n,2e3);return()=>clearTimeout(h)}},[u,n]),f.useEffect(()=>{if(!e)return;const h=v=>{v.key==="Escape"&&n()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[e,n]);const w=async()=>{if(!(!s||!c.trim())){m("submitting"),g("");try{await o({type:s,content:c.trim(),...a.trim()?{contact:a.trim()}:{}}),m("success")}catch(h){m("error"),g(h instanceof Error?h.message:"提交失败,请稍后重试")}}};if(!e)return null;const y=s&&c.trim()&&u!=="submitting",j=jr.find(h=>h.value===s);return t.jsx("div",{style:Yu,onClick:h=>{h.target===h.currentTarget&&n()},children:t.jsxs("div",{style:Ku,onClick:h=>h.stopPropagation(),children:[t.jsxs("div",{style:qu,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:Ju,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:tx,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:i("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:jr.map(h=>t.jsxs("button",{onClick:()=>l(h.value),style:{...Zu,...s===h.value?Xu:{}},children:[t.jsx("span",{children:h.icon})," ",h.label]},h.value))}),t.jsx("textarea",{ref:b,value:c,onChange:h=>p(h.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...Qu,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:a,onChange:h=>d(h.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:ix}),t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[c.length," / 2000"]}),u==="error"&&t.jsx("div",{style:nx,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:w,disabled:!y,style:{...ex,opacity:y?1:.6,cursor:y?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},Yu={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ku={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:i("shadow-dialog")},qu={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Ju={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:i("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Zu={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Xu={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Qu={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},ex={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},tx={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:i("success")},nx={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginBottom:"12px"},ix={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},bi="--bim-feedback-fab-offset",yi=48,ox=16,rx=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:o,hidden:r=!1,zIndex:s})=>{const[l,c]=f.useState(!1),p=n.bottom??24;return f.useEffect(()=>{if(r||typeof document>"u")return;const a=document.documentElement;return a.style.setProperty(bi,`calc(${p+yi+ox}px + env(safe-area-inset-bottom, 0px))`),()=>{a.style.removeProperty(bi)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>c(!0),style:{...sx,zIndex:s??i("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(_l,{isOpen:l,onClose:()=>c(!1),onSubmit:e,feedbackListUrl:o})]})},sx={position:"fixed",width:`${yi}px`,height:`${yi}px`,borderRadius:"50%",border:"none",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:i("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},vr=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],zl=({onSubmit:e})=>{const[n,o]=f.useState("bug"),[r,s]=f.useState(""),[l,c]=f.useState(""),[p,a]=f.useState("idle"),[d,u]=f.useState(""),m=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var w;return(w=m.current)==null?void 0:w.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){a("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),a("success"),s(""),c(""),o("bug")}catch(w){a("error"),u(w instanceof Error?w.message:"提交失败,请稍后重试")}}},g=n&&r.trim()&&p!=="submitting",b=vr.find(w=>w.value===n);return p==="success"?t.jsx("div",{style:kr,children:t.jsxs("div",{style:px,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>a("idle"),style:ux,children:"继续提交"})]})}):t.jsxs("div",{style:kr,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:vr.map(w=>t.jsxs("button",{onClick:()=>o(w.value),style:{...lx,...n===w.value?ax:{}},children:[t.jsx("span",{children:w.icon})," ",w.label]},w.value))}),t.jsx("textarea",{ref:m,value:r,onChange:w=>s(w.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...cx}}),t.jsx("input",{type:"text",value:l,onChange:w=>c(w.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:fx}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:x,disabled:!g,style:{...dx,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:xx,children:d})]})},kr={padding:"16px",border:`1px solid ${i("widget-border")}`,borderRadius:"8px",background:i("input-bg")},lx={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ax={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},cx={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},dx={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},px={display:"flex",alignItems:"center",gap:"12px",color:i("success"),fontSize:"14px"},ux={background:"none",border:"none",color:i("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},xx={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginTop:"8px"},fx={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function wr(e){return typeof e=="function"?e():e??"/api/feedback"}const Cl=({resourceId:e,apiUrl:n})=>{const[o,r]=f.useState([]),[s,l]=f.useState(!0),c=f.useCallback(async()=>{const a=wr(n);l(!0);try{const u=await(await fetch(`${a}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);f.useEffect(()=>{c()},[c]);const p=async a=>{const d=wr(n),u=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const m=await u.json().catch(()=>null);throw new Error((m==null?void 0:m.error)||"提交失败")}setTimeout(()=>c(),500)};return t.jsxs("div",{children:[t.jsx(io,{items:o,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(zl,{onSubmit:p})})]})},Sr={part_of:"所屬",has_part:"包含",contains_text_of:"收錄",collected_in:"叢編",text_carried_by:"載錄",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"後繼",derived_from:"衍生",has_adaptation:"改編",related:"相關"};function $r(e){return e?Sr[e]??e:Sr.related}const mx={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function gx(e){return mx[e]??e}const hx={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function bx(e){return hx[e]??""}function oo({authors:e,onNavigate:n,renderLink:o}){const{convert:r}=V(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,c)=>{const p=Wi(l.role);return t.jsxs(f.Fragment,{children:[c>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Me,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:o,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},c)})}):null}function Tl(e,n){var p,a;const o=Bi(e,n),r=o.mirrors.map(d=>({key:d.key,label:d.label,description:d.description,rows:d.items.filter(u=>u.group_role!=="mirror"),mirrors:d.items.filter(u=>u.group_role==="mirror")})),s=o.buckets.filter(d=>d.key==="image"||d.key==="textImage").flatMap(d=>d.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=o.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((a=o.buckets.find(d=>d.key==="text"))==null?void 0:a.items)??[],groups:r}}function Il(e,n){const o=(e.url?Bt(e.url):void 0)||e.name,r=hs(e,n);return r?`${o}(${r})`:o}function ro({item:e,siblings:n,listedVolumeCounts:o}){const{convert:r}=V(),[s,l]=f.useState(!1),c=Sn(e),p=!!c&&c.expected>0&&!(o!=null&&o.has(c.expected)),a=r(Il(e,n)),d=At(e),u=Rn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var x,g;const m=(x=e.metadata)!=null&&x.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((g=e.metadata)==null?void 0:g.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("殘片")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:r(e.color_mode==="color"?"彩色":"黑白")})]}):null;return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[a," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),m]}):t.jsxs("span",{className:"bim-d-zt-name",children:[a,m]})})(),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(Pi,{item:e})})]}),t.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(m=>!m),children:r(s?"收起分冊":`展開 ${c.expected} 冊`)})})]})}function El({groups:e,listedVolumeCounts:n}){const{convert:o}=V();return t.jsx(t.Fragment,{children:e.map(r=>t.jsxs("div",{className:"bim-d-rg",children:[r.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:o(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:o(r.description)}),r.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:r.rows.map((s,l)=>t.jsx(ro,{item:s,siblings:r.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),r.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[r.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:o("鏡像")}),r.mirrors.map((s,l)=>{const c=At(s),p=o(Il(s,r.mirrors));return c?t.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",title:s.details?o(s.details):void 0,children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:p},l)})]})]},r.key))})}const Xt=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function ji(e){var o;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(o=Xt.find(r=>n.startsWith(r.key[0])))==null?void 0:o.key}const _r=12,yx=60,Rl=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,railTop:l,back:c,railLinks:p})=>{var Te,Ce,Ae;const a=me(),{convert:d}=V(),u=f.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[m,x]=f.useState(new Map),[g,b]=f.useState(!1),[w,y]=f.useState(""),[j,h]=f.useState(!1),v=u.length<=yx,$=v||g||!!w||j,k=f.useMemo(()=>$?u:u.slice(0,_r),[u,$]);f.useEffect(()=>{if(!n||k.length===0)return;const P=k.filter(re=>!m.has(re));if(P.length===0)return;let se=!1;return Promise.all(P.map(re=>n.getItem(re).then(ye=>{const be=ye??{};return[re,{id:re,title:be.title,edition:be.edition,resources:be.resources,publication_info:be.publication_info,current_location:be.current_location,lineage:be.lineage,measure_info:be.measure_info}]}).catch(()=>[re,{id:re}]))).then(re=>{se||x(ye=>{const be=new Map(ye);for(const[K,I]of re)be.set(K,I);return be})}),()=>{se=!0}},[n,k,m]);const _=f.useMemo(()=>u.map(P=>m.get(P)??{id:P}),[u,m]),S=u.length>0&&u.every(P=>m.has(P)),z=!!n&&k.some(P=>!m.has(P)),N=v||$,R=f.useMemo(()=>ys(_,e.version_graph,{era:w,scanOnly:j,sort:N?"year":"default"}),[_,e.version_graph,w,j,N]),C=g?R.rows:R.rows.slice(0,_r),H=R.allRows.filter(P=>P.hasImage).length,L=e.related_works||[],M=L.filter(P=>P.relation==="collected_in"),F=f.useMemo(()=>{const P=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],se=re=>{const ye=P.indexOf(re??"");return ye<0?P.length:ye};return L.filter(re=>re.relation!=="collected_in").map((re,ye)=>({r:re,i:ye})).sort((re,ye)=>se(re.r.relation)-se(ye.r.relation)||re.i-ye.i).map(re=>re.r)},[L]),X=f.useMemo(()=>{const P=Bi(e.resources,e.resource_groups);return[...P.mirrors.flatMap(se=>se.items.map(re=>({r:re,kind:d(se.label)}))),...P.buckets.flatMap(se=>se.items.map(re=>({r:re,kind:d(bx(se.key))})))]},[e.resources,e.resource_groups,d]),U=e.indexed_by||[],T=e.emendated_by||[],ce=f.useMemo(()=>{var fe,he,W;const P=[],se=(he=(fe=e.authors)==null?void 0:fe[0])==null?void 0:he.dynasty;se&&P.push({label:"成書",value:d(se)});const re=pt(e,a.unit.juan);if(re){const ae=(W=e.juan_count)==null?void 0:W.description;P.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[d(re),ae&&ae!==re?t.jsxs("span",{className:"bim-d-meta",children:["(",d(ae),")"]}):null]})})}e.loss_status&&P.push({label:"存佚",value:d(gx(e.loss_status))});const ye=R.allRows.filter(ae=>ae.sortYear!=null),be=ye.length>0?ye.reduce((ae,J)=>ae.sortYear<=J.sortYear?ae:J):null;be!=null&&be.era.era?P.push({label:"最早存世",value:d([be.era.era,be.era.reign].filter(Boolean).join(" ")),title:be.era.source==="edition"?d("據版本題名推斷"):void 0}):z&&P.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),T.length&&P.push({label:"考證",value:`${T.length} ${d("條")}`});const K=zr(e.additional_titles);K.length&&P.push({label:"又名",value:K.map(d).join("、")});const I=zr(e.attached_texts);I.length&&P.push({label:"附載",value:I.map(d).join("、")});const Y=(e.additional_works||[]).map(ae=>d(ae.book_title)+(ae.n_juan!=null?` ${ae.n_juan}${d(a.unit.juan)}`:""));return Y.length&&P.push({label:"附錄",value:Y.join("、")}),P},[e,d,a,z,R.allRows,T.length]),D=[{value:e._edition_count??u.length,label:"版本"},{value:S?H:0,label:"有影印"},{value:U.length,label:"家著錄"}],A=e.classification,ee=A?[A.l1,A.l2,A.l3,A.l4].filter(Boolean).map(P=>d(P)):[],de=e.subtype?d(a.workSubtype[e.subtype]??e.subtype):"",G=t.jsx(on,{title:d(e.title),byline:t.jsx(oo,{authors:e.authors,onNavigate:o,renderLink:r}),meta:t.jsx(De,{items:[...ee,A!=null&&A.source?d(`據《${A.source.split("/")[0]}》`):"",de]}),description:(Te=e.description)!=null&&Te.text?t.jsxs(t.Fragment,{children:[t.jsx(dt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Ce=e.description.sources)!=null&&Ce.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(P=>d(ed(P))).filter(Boolean).join(" · ")}):null]}):void 0,stats:D,facts:ce,readAction:s,foot:t.jsx(rn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Ae=e.appendix)==null?void 0:Ae.map((P,se)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(P.title)}),t.jsx(dt,{text:P.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},se))}),q=R.eras.length>=2?[{key:"",label:a.catalog.all},...R.eras.map(P=>({key:P,label:`${P} ${R.allRows.filter(se=>se.era.era===P).length}`}))]:[],ie=[];u.length&&ie.push({id:"versions",label:"版本",count:u.length}),U.length&&ie.push({id:"catalogs",label:"著錄",count:U.length}),M.length&&ie.push({id:"collected",label:"收入叢編",count:M.length}),F.length&&ie.push({id:"related",label:"相關書目",count:F.length}),X.length&&ie.push({id:"resources",label:"在線資源",count:X.length});const pe=u.length===0&&U.length===0,ge=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(He,{id:"versions",title:"版本",meta:t.jsx(De,{items:[d(`共 ${u.length} 種`),S&&H?d(`${H} 種有影印`):"",R.rows.length!==R.allRows.length?d(`當前 ${R.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&q.length===0&&u.length>1?"":void 0,children:[q.length>0&&t.jsx(Ln,{items:q,value:w,onChange:P=>{y(P),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Is,{label:"只看有影印",checked:j,onChange:P=>{h(P),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:d(N?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("版本")}),t.jsx("th",{children:d("年代")}),t.jsx("th",{children:d("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:d("影印")})})]})}),t.jsx("tbody",{children:C.map(P=>{var se;return t.jsx(jx,{row:P,measure:(se=m.get(P.id))==null?void 0:se.measure_info,loaded:m.has(P.id),onNavigate:o,renderLink:r},`${P.id}:${m.has(P.id)?"r":"p"}`)})})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(w||j?"當前篩選下沒有版本":"暫無版本著錄")}),R.rows.length>C.length&&t.jsx(Mt,{label:`展開其餘 ${R.rows.length-C.length} 種版本`,onClick:()=>b(!0)}),R.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:d("部分年代據版本題名推斷,非著錄原文")})]}),U.length>0&&t.jsx(vx,{items:U,transport:n,onNavigate:o,renderLink:r}),pe&&t.jsx(He,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),Ee=(P,se)=>t.jsx(Me,{id:P,label:d(se),onNavigate:o,renderLink:r,dense:!0}),Ne=f.useMemo(()=>{const P=new Map;for(const se of F){const re=$r(se.relation);P.set(re,(P.get(re)??0)+1)}return P.size>1?[...P.entries()].sort((se,re)=>re[1]-se[1]).slice(0,4).map(([se,re])=>`${d(se)} ${re}`).join(" · "):void 0},[F,d]),ze=t.jsxs(t.Fragment,{children:[t.jsx(yt,{id:"collected",title:"收入叢編",items:M.map(P=>Ee(P.id,P.title))}),t.jsx(yt,{id:"related",title:"相關書目",meta:d(`${F.length} 部`),sub:Ne,items:F.map(P=>t.jsxs(t.Fragment,{children:[Ee(P.id,P.title),t.jsx("span",{className:"bim-d-meta",title:P.note?d(P.note):void 0,children:d($r(P.relation))})]}))}),t.jsx(yt,{id:"resources",title:"在線資源",cap:6,items:X.map(({r:P,kind:se})=>{const re=d((P.url?Bt(P.url):void 0)||P.name),ye=At(P);return t.jsxs(t.Fragment,{children:[ye?t.jsxs("a",{href:ye,target:"_blank",rel:"noopener noreferrer",children:[re," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:re}),se&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:se})]})})})]});return t.jsx(nn,{railTop:l,back:c,nav:ie,railLinks:p,main:ge,card:G,side:ze})};function zr(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Cr(e,n){return n((e.url?Bt(e.url):void 0)||e.name)}function jx({row:e,measure:n,loaded:o,onNavigate:r,renderLink:s}){const{convert:l}=V(),c=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",a=e.holders[0],d=a?Cr(a,l):e.locationName?l(e.locationName):"",u=e.images[0],m=u?At(u):void 0,x=e.images.map(g=>Cr(g,l)).join("、");return t.jsxs("tr",{"data-loading":o?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Me,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${c?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:c?l(c):o?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${d?"":" bim-d-zt-blank"}`,children:[d||(o?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(m?t.jsx("a",{className:"bim-d-flag",href:m,target:"_blank",rel:"noopener noreferrer",title:x,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:x,children:l("有影印")}))})]})}function vx({items:e,transport:n,onNavigate:o,renderLink:r}){const s=me(),{convert:l}=V(),[c,p]=f.useState(0),a=Math.min(c,e.length-1),d=e[a],[u,m]=f.useState(new Map);return f.useEffect(()=>{if(!n)return;const x=[...new Set(e.map(b=>b.source_bid).filter(b=>!!b))];if(x.length===0)return;let g=!1;return Promise.all(x.map(b=>n.getItem(b).then(w=>{var y,j;return[b,((j=(y=w==null?void 0:w.authors)==null?void 0:y[0])==null?void 0:j.dynasty)??""]}).catch(()=>[b,""]))).then(b=>{g||m(new Map(b.filter(([,w])=>w)))}),()=>{g=!0}},[n,e]),t.jsx(He,{id:"catalogs",title:"著錄",meta:t.jsx(De,{items:[l(`歷代書目 ${e.length} 家`),l("按著錄順序")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":l("著錄書目"),children:e.map((x,g)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":g===a,"aria-label":l(x.source),onClick:()=>p(g),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(x.source_bid??"")?l(u.get(x.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...l(x.source)].slice(0,9).map((b,w)=>t.jsx("span",{children:b},w))})]})},g))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:l(d.title_info)}),t.jsx(De,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?t.jsx(Me,{id:d.source_bid,label:l(d.source),onNavigate:o,renderLink:r,dense:!0}):l(d.source),d.section?l(d.section):"",d.author_info?`${l(s.label.authorInfo)} ${l(d.author_info)}`:"",d.edition?`${l(s.label.edition)} ${l(d.edition)}`:"",d.page??""]}),d.summary&&t.jsx("p",{className:"bim-d-quote",children:Ke(l(d.summary))}),d.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:Ke(l(d.comment))})]}),d.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:Ke(l(d.additional_comment))})]}),!d.summary&&!d.comment&&!d.additional_comment&&!d.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:l("僅著錄書名,無提要。")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[a>0?t.jsx("button",{type:"button","aria-label":l(`上一家:${e[a-1].source}`),onClick:()=>p(a-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",l(e[a-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[a+1," / ",e.length]}),a<e.length-1?t.jsx("button",{type:"button","aria-label":l(`下一家:${e[a+1].source}`),onClick:()=>p(a+1),children:t.jsxs("span",{"aria-hidden":"true",children:[l(e[a+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function kx(e){var n;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((n=e.year_range)==null?void 0:n[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function wx(e,n){if(!e.lineage)return null;const o=e.lineage;return{id:e.id,kind:"book",label:e.title,year:o.year,year_text:o.year_text,year_uncertain:o.year_uncertain,category:o.category,status:o.status,extant_juan:o.extant_juan,group:n[e.id],note:o.note}}function Tr(e,n,o){return{id:`derive:${n.ref}->${e}:${o}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Sx(e,n,o){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${o}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function $x(e,n){var d;if(n==="all")return null;const o=(d=e.collections)==null?void 0:d[n],r=Array.isArray(o==null?void 0:o.groups)&&o.groups.length>0,s=Array.isArray(o==null?void 0:o.book_ids)&&o.book_ids.length>0,l=r||s||!!(o!=null&&o.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!o||!l)return null;const c=r?new Set(o.groups):null,p=new Set(o.book_ids??[]);if(c&&e.node_groups)for(const[u,m]of Object.entries(e.node_groups))c.has(m)&&p.add(u);let a=null;if(o.hypothetical_ids&&(a=new Set(o.hypothetical_ids)),c){a||(a=new Set);for(const u of e.hypothetical_nodes??[])u.group&&c.has(u.group)&&a.add(u.id)}return{books:p,hypos:a}}function bn(e,n,o){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const l=new Set(r.excluded_books??[]),c=r.node_groups??{},p=$x(r,o??r.default_collection??"all"),a=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,m=new Set,x=new Set;if(a){const $=new Map(n.map(R=>[R.id,R])),k=new Map((r.hypothetical_nodes??[]).map(R=>[R.id,R])),_=R=>{const C=$.get(R);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(L=>L.ref);const H=k.get(R);return H?(H.derived_from??[]).map(L=>L.ref):[]},S=R=>k.has(R)?!u||u.has(R):!d||d.has(R),z=new Set,N=R=>{if(!z.has(R)){z.add(R);for(const C of _(R))l.has(C)||(S(C)||(k.has(C)?x.add(C):$.has(C)&&m.add(C)),N(C))}};for(const R of n)d&&d.has(R.id)&&!l.has(R.id)&&N(R.id);for(const R of r.hypothetical_nodes??[])u&&u.has(R.id)&&N(R.id)}const g=n.filter($=>!l.has($.id)).filter($=>!d||d.has($.id)||m.has($.id)).map($=>{const k=wx($,c);return k&&m.has($.id)&&(k.bridge=!0),k}).filter($=>$!==null),b=(r.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||x.has($.id)).map($=>{const k=kx($);return x.has($.id)&&(k.bridge=!0),k}),w=[...g,...b],y=new Set(w.map($=>$.id)),j=new Set,h=[],v=$=>{j.has($.id)||!y.has($.source)||!y.has($.target)||(j.add($.id),h.push($))};for(const $ of n)l.has($.id)||!$.lineage||d&&!d.has($.id)&&!m.has($.id)||(($.lineage.derived_from??[]).forEach((k,_)=>{v(Tr($.id,k,_))}),($.lineage.related_to??[]).forEach((k,_)=>{v(Sx($.id,k,_))}));for(const $ of r.hypothetical_nodes??[])u&&!u.has($.id)&&!x.has($.id)||($.derived_from??[]).forEach((k,_)=>{v(Tr($.id,k,_))});return{nodes:w,edges:h,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function Nl(e,n,o){const r=(e??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function _x(e,n){const o=[],r=e.version_graph;if(!r)return o;const s=new Set(n.map(a=>a.id)),l=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),c=new Set([...s,...l]),p=(a,d)=>{c.has(d.ref)||o.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&o.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&o.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(u=>p(d,u)),(a.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||o.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(u=>p(d,u))}return o}const Ll=({graph:e,renderLink:n,className:o,style:r})=>{const{convert:s}=V();if(!e.nodes.length)return t.jsx("div",{style:{...Px,...r},className:o,children:"暂无版本图数据"});const l=new Map,c=new Map;for(const x of e.edges)if(x.kind==="derive"){const g=l.get(x.target)??[];g.push(x),l.set(x.target,g)}else for(const g of[x.source,x.target]){const b=c.get(g)??[];b.push(x),c.set(g,b)}const p=new Map(e.nodes.map(x=>[x.id,x])),a=new Map,d=[];for(const x of e.nodes)if(x.group){const g=a.get(x.group)??[];g.push(x),a.set(x.group,g)}else d.push(x);const u=(x,g)=>(x.year??9999)-(g.year??9999);a.forEach(x=>x.sort(u)),d.sort(u);const m=e.groups.filter(x=>a.has(x.id));return t.jsxs("div",{className:o,style:{...Cx,...r},children:[e.title&&t.jsx("div",{style:Tx,children:s(e.title)}),e.description&&t.jsx("div",{style:Ix,children:s(e.description)}),m.map(x=>t.jsx(Ir,{label:x.label,color:x.color,nodes:a.get(x.id),incomingMap:l,siblingMap:c,nodeMap:p,renderLink:n},x.id)),d.length>0&&t.jsx(Ir,{label:"其他",nodes:d,incomingMap:l,siblingMap:c,nodeMap:p,renderLink:n})]})},Ir=({label:e,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:c})=>{const{convert:p}=V();return t.jsxs("div",{style:Ex,children:[t.jsx("div",{style:{...Rx,borderLeftColor:n??i("widget-border")},children:p(e)}),o.map(a=>t.jsx(zx,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:l,renderLink:c},a.id))]})},zx=({node:e,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",c=e.bridge,{convert:p}=V();return t.jsxs("div",{style:{...Nx,borderStyle:l||c?"dashed":"solid",opacity:c?.55:e.status==="lost"?.7:1,background:c?i("bg-subtle"):void 0},title:c?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:Lx,children:[t.jsx("span",{style:Bx,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Ax,children:Nl(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Wx,children:[e.category&&t.jsx(Vt,{children:p(e.category)}),e.status==="lost"&&t.jsx(Vt,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(Vt,{tone:"warn",children:"残本"}),l&&t.jsx(Vt,{tone:"info",children:"假想祖本"}),c&&t.jsx(Vt,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Mx,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:Fx,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:Rr,children:[t.jsx("div",{style:Nr,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return t.jsxs("div",{style:Lr(a.confidence),children:[t.jsx("span",{style:Br,children:p(a.relation)}),t.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,p(d.label)):p((d==null?void 0:d.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&t.jsx(Er,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:Ar,children:["· ",p(a.evidence)]})]},a.id)})]}),o.length>0&&t.jsxs("div",{style:Rr,children:[t.jsx("div",{style:Nr,children:"关联:"}),o.map(a=>{const d=a.source===e.id?a.target:a.source,u=r.get(d);return t.jsxs("div",{style:Lr(a.confidence),children:[t.jsx("span",{style:Br,children:p(a.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,p(u.label)):p((u==null?void 0:u.label)??d)}),t.jsx(Er,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:Ar,children:["· ",p(a.evidence)]})]},a.id)})]})]})},Vt=({children:e,tone:n="default"})=>{const r={default:{bg:i("tag-bg"),fg:i("fg")},warn:{bg:i("warn-bg"),fg:i("warn-fg")},info:{bg:i("info-bg"),fg:i("info-fg")}}[n];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},Er=({level:e})=>{const o={certain:{label:"确定",color:i("confidence-certain")},consensus:{label:"共识",color:i("confidence-consensus")},probable:{label:"推测",color:i("confidence-probable")},disputed:{label:"有争议",color:i("confidence-disputed")}}[e];return o?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${o.color}`,color:o.color,borderRadius:"8px",marginLeft:"4px"},children:o.label}):null},Cx={fontSize:"14px",color:i("fg")},Tx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ix={fontSize:"13px",color:i("muted"),marginBottom:"16px",lineHeight:1.6},Ex={marginBottom:"16px"},Rx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:i("fg")},Nx={border:`1px solid ${i("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:i("bg")},Lx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Bx={fontSize:"15px",fontWeight:600},Ax={fontSize:"12px",color:i("muted")},Wx={marginBottom:"6px"},Mx={fontSize:"12px",color:i("muted"),margin:"2px 0"},Fx={fontSize:"12px",color:i("muted"),fontStyle:"italic",margin:"4px 0"},Rr={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${i("widget-border")}`},Nr={fontSize:"11px",color:i("muted"),marginBottom:"2px"},Lr=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Br={display:"inline-block",padding:"0 6px",fontSize:"11px",background:i("tag-bg"),color:i("fg"),borderRadius:"3px",marginRight:"6px"},Ar={fontSize:"11px",color:i("muted")},Px={padding:"20px",textAlign:"center",color:i("muted"),fontSize:"13px"},Bl=({selectedNodeId:e,...n})=>{const[o,r]=f.useState("loading"),[s,l]=f.useState(null);return f.useEffect(()=>{let c=!1;return Ox().then(p=>{c||(p?(l(p),r("ready")):r("missing"))}),()=>{c=!0}},[]),o==="loading"?t.jsx("div",{style:Wr,children:"加载图组件中…"}):o==="missing"||!s?t.jsxs("div",{style:Wr,children:[t.jsxs("div",{children:["图组件未安装。请安装 ",t.jsx("code",{children:"@xyflow/react"})," 与 ",t.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),t.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",t.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):t.jsx(Dx,{modules:s,selectedNodeId:e,...n})};async function Ox(){try{const[e,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let o=!1;try{await import("@xyflow/react/dist/style.css"),o=!0}catch{o=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:n,cssLoaded:o}}catch{return null}}const Dx=({graph:e,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:l,modules:c})=>{const{ReactFlow:p,Background:a,Controls:d,Handle:u,Position:m,BaseEdge:x,EdgeLabelRenderer:g,getSmoothStepPath:b,dagre:w}=c,y=f.useMemo(()=>({lineage:_=>{var X,U,T,ce;const S=((X=_.data)==null?void 0:X.stepPosition)??.85,[z,N,R]=b({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:S,borderRadius:5}),C=!!((U=_.data)!=null&&U.isSibling),H=C?N:_.targetX-18,L=C?R:_.targetY-12,M=(T=_.data)==null?void 0:T.labelStyle,F=(ce=_.data)==null?void 0:ce.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(x,{id:_.id,path:z,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&t.jsx(g,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${H}px,${L}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:i("bg"),border:`0.5px solid ${i("widget-border")}`,...F,...M},children:_.label})})]})}}),[x,g,b]),j=f.useMemo(()=>({version:_=>{const S=_.data,z=S.kind==="hypothetical",N=S.status==="lost",R=S.isSelected,C=S.bridge,H=S.borderColor??i("muted"),L=C||z?"dashed":"solid",M=C?.5:N?.6:1;return t.jsxs("div",{style:{background:i(C?"bg-subtle":"bg"),border:`2px ${L} ${R?i("primary"):H}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:M,boxShadow:R?i("shadow-node-selected"):z||C?"none":i("shadow-node")},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:m.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.2},children:Nl(S.yearText,void 0,S.uncertain)}),N&&t.jsx("div",{style:{fontSize:9,color:i("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:m.Right,style:{visibility:"hidden"}})]})}}),[u,m]),{convert:h}=V(),{rfNodes:v,rfEdges:$}=f.useMemo(()=>Hx(e,w,n,l,h),[e,w,n,l,h]);return t.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:t.jsxs(p,{nodes:v,edges:$,nodeTypes:j,edgeTypes:y,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(a,{gap:16}),t.jsx(d,{showInteractive:!1})]})})};function Hx(e,n,o,r,s=l=>l??""){const p=e.layout==="LR"||!e.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:p?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(e.groups.map(j=>[j.id,j.color??i("muted")]));for(const j of e.nodes)a.setNode(j.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of e.edges)j.kind==="derive"&&(u.has(j.relation)||a.setEdge(j.source,j.target));n.layout(a);const m=e.nodes.map(j=>{const h=a.node(j.id),v=r?j.id===r:void 0,$={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??Ux(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:o,isSelected:v,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:h.x-160/2,y:h.y-90/2},data:$,draggable:!1,selected:v}}),x=.78,g=.06,b=new Map;for(const j of e.edges)j.kind==="derive"&&(b.has(j.source)||b.set(j.source,[]),b.get(j.source).push(j));const w=new Map;for(const[j,h]of b){if(h.length<=1)continue;const v=[...h].sort((k,_)=>{var N,R;const S=((N=a.node(k.target))==null?void 0:N.y)??0,z=((R=a.node(_.target))==null?void 0:R.y)??0;return S-z}),$=v.length;v.forEach((k,_)=>{const S=(_-($-1)/2)*g;w.set(k.id,x+S)})}const y=e.edges.map(j=>Gx(j,w.get(j.id),s));return{rfNodes:m,rfEdges:y}}function Gx(e,n,o=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=Vx(e.confidence),c={type:"arrowclosed",color:l,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:o(e.relation),data:{labelStyle:{color:i("fg")},isSibling:s,stepPosition:n},style:{stroke:l,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:c,markerStart:s?c:void 0,zIndex:1e3}}function Ux(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Vx(e){switch(e){case"certain":return i("confidence-certain");case"consensus":return i("lineage-edge-consensus");case"probable":return i("confidence-probable");case"disputed":return i("confidence-disputed");default:return i("muted")}}const Wr={padding:"40px 20px",textAlign:"center",color:i("muted"),fontSize:"13px",border:`1px dashed ${i("widget-border")}`,borderRadius:8,background:i("bg")},so=({graph:e,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:c,onCollectionChange:p,collectionsAvailable:a,collectionCounts:d,className:u,style:m})=>{var h;const[x,g]=f.useState(n),b=v=>{g(v),l==null||l(v)},w=(()=>{if(!a)return[];const v=Object.entries(a);return v.length===0||a.all?v:[...v,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),y=!!(p&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:i("muted"),textAlign:"center"},children:"暂无版本传承数据"});const j=c?(h=a==null?void 0:a[c])==null?void 0:h.description:void 0;return t.jsxs("div",{className:u,style:m,children:[t.jsxs("div",{style:Yx,children:[t.jsx("button",{onClick:()=>b("list"),style:Zn(x==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:Zn(x==="graph"),children:"关系图"}),y&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:i("muted"),marginRight:4},children:"集合:"}),w.map(([v,$])=>{const k=d==null?void 0:d[v];return t.jsxs("button",{onClick:()=>p==null?void 0:p(v),style:Zn(c===v),title:$.description,children:[$.label,k!=null?` ${k}`:""]},v)})]})]}),y&&j&&t.jsx("div",{style:{fontSize:12,color:i("muted"),marginBottom:8,padding:"4px 8px",background:i("bg-subtle"),borderRadius:4},children:j}),x==="list"?t.jsx(Ll,{graph:e,renderLink:o}):t.jsx(Bl,{graph:e,renderLink:o,height:r,selectedNodeId:s})]})},Yx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Zn=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${i("widget-border")}`,borderRadius:4,background:e?i("primary"):"transparent",color:i(e?"primary-fg":"fg"),cursor:"pointer"}),Mr=40,Fr=2,Kx=9,Pr={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function Xn(e){if(!e)return["",""];const n=e.split(/[ ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Al=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,fullText:l,fullTextPending:c,chapterLink:p,railTop:a,back:d,railLinks:u})=>{var fe,he,W,ae,J,O,xe,je,Se,ne,we;const m=me(),{convert:x}=V(),[g,b]=f.useState(null),[w,y]=f.useState(new Map),[j,h]=f.useState([]),[v,$]=f.useState(new Map),[k,_]=f.useState(!1),[S,z]=f.useState("flow"),[N,R]=f.useState(null);f.useEffect(()=>{if(!n||!e.work_id){b(null);return}let E=!1;return n.getItem(e.work_id).then(Q=>{!E&&Q&&Q.type==="work"&&b(Q)}).catch(()=>{}),()=>{E=!0}},[n,e.work_id]),f.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){R(null);return}let E=!1;return n.getLineageGraph(e.work_id).then(Q=>{E||R(Q&&Q.nodes.length>1?Q:null)}).catch(()=>{E||R(null)}),()=>{E=!0}},[n,e.work_id]),f.useEffect(()=>{const E=e.contained_in||[];if(!n||E.length===0){y(new Map);return}let Q=!1;return Promise.all(E.map(ue=>{const le=typeof ue=="string"?ue:ue.id;return n.getItem(le).then(te=>[le,te]).catch(()=>[le,null])})).then(ue=>{if(Q)return;const le=new Map;for(const[te,ke]of ue)ke&&le.set(te,ke);y(le)}),()=>{Q=!0}},[n,e.contained_in]);const C=f.useMemo(()=>{const E=new Set([...(g==null?void 0:g.books)||[],...e.related_books||[]]);return E.add(e.id),[...E]},[g==null?void 0:g.books,e.related_books,e.id]),H=C.length-1;f.useEffect(()=>{if(!n||H<=0){h([]);return}const E=C.length<=Mr,Q=E?C:C.slice(0,8);let ue=!1;return Promise.all(Q.map(le=>le===e.id?Promise.resolve({id:le,title:e.title,edition:e.edition,year:vn(e)}):n.getItem(le).then(te=>{const ke=te??{};return{id:le,title:ke.title,edition:ke.edition,year:te?vn(ke):void 0}}).catch(()=>({id:le})))).then(le=>{if(ue)return;const te=le.filter(ke=>ke.id===e.id||ke.title||ke.edition);E&&te.sort((ke,Ie)=>(ke.year??1/0)-(Ie.year??1/0)),h(te)}),()=>{ue=!0}},[n,C,H,e]);const L=e.lineage,M=f.useMemo(()=>[...((L==null?void 0:L.derived_from)||[]).filter(E=>E.ref_type==="book").map(E=>E.ref),...((L==null?void 0:L.related_to)||[]).map(E=>E.book_id)].filter(Boolean),[L]);f.useEffect(()=>{if(!n||M.length===0){$(new Map);return}let E=!1;return Promise.all(M.map(Q=>n.getItem(Q).then(ue=>[Q,{id:Q,title:ue==null?void 0:ue.title,edition:ue==null?void 0:ue.edition}]).catch(()=>[Q,{id:Q}]))).then(Q=>{E||$(new Map(Q))}),()=>{E=!0}},[n,M]);const F=f.useMemo(()=>Tl(e.resources,e.resource_groups),[e.resources,e.resource_groups]),X=F.groups.reduce((E,Q)=>E+Q.rows.length+Q.mirrors.length,0),U=F.groups.length>0&&F.groups.every(E=>E.key==="_physical"),T=tn(e),ce=Ss(e),B=pt(e,m.unit.juan),D=new Set((e.contained_in||[]).map(E=>typeof E=="string"?0:Jt(E.volume_index).length).filter(E=>E>0)),A=E=>{var le;const Q=(le=e.base_edition)==null?void 0:le.find(te=>te.book_id===E&&te.name);if(Q!=null&&Q.name)return Q.name;const ue=v.get(E);return(ue==null?void 0:ue.edition)||(ue==null?void 0:ue.title)||""},ee=f.useMemo(()=>{var Ze,an,ut,cn,dn;const E=[];ce&&E.push({label:"版本類型",value:x(ce),title:e.edition_type||(Ze=e.lineage)!=null&&Ze.category?void 0:x("據版本題名推斷")}),(an=e.publication_info)!=null&&an.details?E.push({label:"刊印",value:x(e.publication_info.details)}):(T.era||T.reign)&&E.push({label:"刊寫年代",value:x([T.era,T.reign].filter(Boolean).join(" ")),title:T.source==="edition"?x("據版本題名推斷"):void 0}),B&&E.push({label:"卷帙",value:x(B)});const Q=(e.contained_in||[]).flatMap(_e=>typeof _e=="string"?[]:Jt(_e.volume_index));Q.length&&E.push({label:"冊次",value:x(`第 ${Nn(Q,m.unit.volume)} ${m.unit.volume}(${Q.length} ${m.unit.volume})`)});const ue=(((ut=e.lineage)==null?void 0:ut.derived_from)||[]).find(_e=>_e.relation==="底本"&&_e.ref_type==="book");ue&&A(ue.ref)&&E.push({label:"底本",value:t.jsx(Me,{id:ue.ref,label:x(A(ue.ref)),onNavigate:o,renderLink:r,dense:!0})});const le=(e.base_edition||[]).filter(_e=>_e&&_e.name);for(const _e of["底本","配補","參校"]){if(_e==="底本"&&ue&&A(ue.ref))continue;const tt=le.filter(Be=>Be.role===_e);tt.length&&E.push({label:_e,value:tt.map((Be,St)=>t.jsxs(f.Fragment,{children:[St>0&&"、",Be.book_id?t.jsx(Me,{id:Be.book_id,label:x(Be.name),onNavigate:o,renderLink:r,dense:!0}):x(Be.name)]},St))})}const te=(e.provenance||[]).filter(_e=>_e&&_e.institution),ke=(e.resources||[]).filter(_e=>(_e.types||(_e.type?[_e.type]:[])).includes("physical"));if(te.length){E.push({label:"存藏",value:te.slice(0,2).map(Be=>x(Be.institution)).join("、")+(te.length>2?x(` 等 ${te.length} 處`):"")});const _e=te.filter(Be=>Be.call_number).slice(0,2).map(Be=>`${x(Be.institution)} ${Be.call_number}`);_e.length&&E.push({label:"索書號",value:_e.join(";")+(te.filter(Be=>Be.call_number).length>2?"…":"")});const tt=te.flatMap(Be=>Be.seals||[]).filter(Boolean);tt.length&&E.push({label:"藏印",value:x(tt.join("、"))})}else ke.length?E.push({label:"存藏",value:ke.slice(0,2).map(_e=>x(_e.name)).join("、")+(ke.length>2?x(` 等 ${ke.length} 處`):"")}):(cn=e.current_location)!=null&&cn.name&&E.push({label:"存藏",value:x(e.current_location.name)});const Ie=e.physical_description;if(Ie){const _e=[["行款",Ie.leaf_style],["裝幀",Ie.binding],["尺寸",Ie.dimensions],["品相",Ie.condition]];for(const[tt,Be]of _e)Be&&Be.trim()&&E.push({label:tt,value:x(Be)})}(dn=e.page_count)!=null&&dn.description&&E.push({label:m.label.pageCount,value:x(e.page_count.description)});const We=[...pi(e.additional_titles),...pi(e.attached_texts)];return We.length&&E.push({label:"又名",value:We.map(x).join("、")}),E},[e,x,m,T,ce,B,v,o,r]),de=x(e.title),G=e.edition?x(e.edition):void 0,q=((fe=e.lineage)==null?void 0:fe.year_text)||"",ie=t.jsx(on,{kind:"版本",title:de,subtitle:G,byline:t.jsx(oo,{authors:e.authors??(g==null?void 0:g.authors),onNavigate:o,renderLink:r}),meta:(()=>{const E=[ce?x(ce):"",T.era?x([T.era,T.reign].filter(Boolean).join("")):"",B?x(B):""].filter(Boolean);return E.length?t.jsx("span",{className:"bim-d-tags",children:E.map((Q,ue)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ue,2)}`,children:Q},ue))}):null})(),description:(he=e.description)!=null&&he.text?t.jsx(dt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Mi((W=e.description)==null?void 0:W.text)?6:void 0,facts:ee,readAction:s,secondaryAction:s&&X>0&&!U?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(rn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),pe=e.contained_in||[],ge=(l==null?void 0:l.chapters)||[],Ee=ge[0]&&Xn(ge[0].title)[0].slice(-1)||"章",Ne=!!((ae=L==null?void 0:L.derived_from)!=null&&ae.length||(J=L==null?void 0:L.related_to)!=null&&J.length||(O=e.appendix)!=null&&O.length),ze=[];(ge.length||F.text.length||c)&&ze.push({id:"fulltext",label:"全文",count:ge.length?x(`${ge.length} ${Ee}`):void 0}),F.groups.length&&ze.push({id:"images",label:U?"館藏":"影印",count:X}),Ne&&ze.push({id:"lineage",label:"版本源流"}),pe.length&&ze.push({id:"collections",label:"收入叢編",count:pe.length}),(xe=e.location_history)!=null&&xe.length&&ze.push({id:"provenance",label:"流轉歷史"});const Te=E=>(p==null?void 0:p(E))??null,Ce=ge[0],Ae=Ce?Te(Ce.file):null,P=k?ge:ge.slice(0,Kx),se=(E,Q,ue)=>E?t.jsx("a",{className:ue,href:E.href??"#",onClick:E.onClick?le=>{le.metaKey||le.ctrlKey||(le.preventDefault(),E.onClick())}:void 0,children:Q}):t.jsx("span",{className:ue,children:Q}),re=t.jsxs(t.Fragment,{children:[(ge.length>0||F.text.length>0||c)&&t.jsxs(He,{id:"fulltext",title:"全文",meta:ge.length>0?t.jsx(De,{items:[x(`${ge.length} ${Ee}`),(je=l==null?void 0:l.source)!=null&&je.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[c&&!Ce&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),Ce&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${Xn(Ce.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((Ce.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),se(Ae,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),ge.length>1&&t.jsx("ul",{className:"bim-d-chap",children:P.map(E=>{const[Q,ue]=Xn(E.title);return t.jsx("li",{children:se(Te(E.file),t.jsxs(t.Fragment,{children:[Q&&t.jsx("b",{children:x(Q)}),x(ue||E.file)]}))},E.file)})}),ge.length>P.length&&t.jsx(Mt,{label:`展開其餘 ${ge.length-P.length} ${Ee}`,onClick:()=>_(!0)}),F.text.length>0&&t.jsxs(t.Fragment,{children:[(ge.length>0||c)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:F.text.map((E,Q)=>t.jsx(ro,{item:E,siblings:F.text,listedVolumeCounts:D},`${E.id||E.url||E.name}-${Q}`))})})]})]}),F.groups.length>0&&t.jsx(He,{id:"images",title:U?"館藏":"影印",meta:t.jsx(De,{items:[F.groups.length>1?x(`${F.groups.length} 組`):"",x(`${X} 處`)]}),children:t.jsx(El,{groups:F.groups,listedVolumeCounts:D})}),Ne&&t.jsx(He,{id:"lineage",title:"版本源流",meta:(Se=L==null?void 0:L.derived_from)!=null&&Se.length?x("據版本傳承著錄"):void 0,action:N?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":x("源流視圖"),children:[t.jsx("button",{type:"button","aria-pressed":S==="flow",onClick:()=>z("flow"),children:x("卡片")}),t.jsx("button",{type:"button","aria-pressed":S==="graph",onClick:()=>z("graph"),children:x("關係圖")})]}):void 0,children:S==="graph"&&N?t.jsx(so,{graph:N,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(E,Q)=>t.jsx(Me,{id:E,label:x(Q),onNavigate:o,renderLink:r,dense:!0})}):t.jsx(Jx,{data:e,heading:G||de,yearText:q,refName:A,onNavigate:o,renderLink:r})}),pe.length>0&&t.jsx(He,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:pe.map((E,Q)=>{var Ie,We;const ue=typeof E=="string"?E:E.id,le=typeof E=="string"?[]:Jt(E.volume_index),te=w.get(ue),ke=(te==null?void 0:te._member_count)||((Ie=te==null?void 0:te.books)==null?void 0:Ie.length)||((We=te==null?void 0:te.contained_works)==null?void 0:We.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Me,{id:ue,label:te?x(te.title):ue,onNavigate:o,renderLink:r,dense:!0}),le.length>0&&t.jsx(qx,{volumes:le,unit:m.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ke?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ke>0&&x(`全 ${ke} ${m.unit.bu}`)})]},`${ue}-${Q}`)})})})}),(ne=e.location_history)!=null&&ne.length?t.jsx(He,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((E,Q)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(E.name)}),([E.start_date,E.end_date].filter(Boolean).join("—")||E.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(De,{items:[[E.start_date,E.end_date].filter(Boolean).join("—"),E.description?x(E.description):""]})})]},Q))})}):null,ze.length===0&&t.jsx(He,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),ye=j.findIndex(E=>E.id===e.id),be=C.length<=Mr,K=be&&ye>=0?j.slice(Math.max(0,ye-Fr),ye+Fr+1):j.filter(E=>E.id!==e.id),I=t.jsxs(t.Fragment,{children:[g&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:x(m.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Me,{id:g.id,label:x(g.title),onNavigate:o,renderLink:r})}),t.jsx(De,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(g.authors||[]).slice(0,2).map(E=>`${E.dynasty?`〔${x(E.dynasty)}〕`:""}${x(E.name)}`),x(pt(g,m.unit.juan)),g._edition_count?x(`${g._edition_count} 種版本`):""]}),((we=g.description)==null?void 0:we.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:x(g.description.text.replace(/[#*_>`[\]]/g,""))})]}),H>0&&K.length>0&&t.jsxs("div",{children:[t.jsx(yt,{id:"siblings",timeline:!0,title:be?"同作品版本":m.relation.siblingVersions,meta:x(be?"按年代":`${H} 種`),cap:K.length,items:K.map(E=>E.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(E.edition||E.title||E.id)}):t.jsx(Me,{id:E.id,label:x(E.edition||E.title||E.id),onNavigate:o,renderLink:r,dense:!0})),metas:K.map(E=>[E.year!=null?E.year<0?`前${-E.year}`:String(E.year):"",E.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:K.findIndex(E=>E.id===e.id)}),g&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Me,{id:g.id,label:x(`在作品頁看全部 ${C.length} 種 →`),onNavigate:o,renderLink:r,dense:!0})})]})]}),Y=e.work_id?t.jsx(Ts,{caption:m.section.belongsToWork,children:t.jsx(Me,{id:e.work_id,label:g?x(g.title):" ",onNavigate:o,renderLink:r,dense:!0})}):void 0;return t.jsx(nn,{railTop:a,back:d,up:Y,nav:ze,railLinks:u,main:re,card:ie,side:I})};function qx({volumes:e,unit:n}){const{convert:o}=V();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[o(`第 ${Nn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),o(`${e.length} ${n}`)]})]})}function Jx({data:e,heading:n,yearText:o,refName:r,onNavigate:s,renderLink:l}){var y;const{convert:c}=V(),p=e.lineage,a=(p==null?void 0:p.derived_from)||[],d=a.filter(j=>j.ref_type!=="book"),u=a.filter(j=>j.ref_type==="book"&&j.relation==="底本"),m=a.filter(j=>j.ref_type==="book"&&j.relation!=="底本"),x=(p==null?void 0:p.related_to)||[],g=a.length>0||x.length>0,b=j=>j&&Pr[j]?c(`(${Pr[j]})`):"",w=(j,h)=>t.jsx(Me,{id:j,label:c(h||j),onNavigate:s,renderLink:l,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[g&&t.jsxs("ol",{className:"bim-d-lf-list",children:[d.map((j,h)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:c(j.relation||"祖本")}),t.jsx("span",{className:"bim-d-lf-name",children:c("擬構祖本")}),j.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[c(j.evidence),b(j.confidence)]})]})},`a-${h}`)),u.map((j,h)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:c(j.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:w(j.ref,r(j.ref))}),j.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[c(j.evidence),b(j.confidence)]})]})},`b-${h}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:c("本版")}),t.jsx("span",{className:"bim-d-lf-name",children:n}),o&&t.jsx("span",{className:"bim-d-lf-yr",children:c(o)})]}),m.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:m.map((j,h)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:c(j.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:w(j.ref,r(j.ref))}),j.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[c(j.evidence),b(j.confidence)]})]},h))})]}),x.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:c("翻刻 · 衍生")}),t.jsx("span",{className:"bim-d-lf-chips",children:x.map((j,h)=>t.jsxs("span",{className:"bim-d-lf-chip",title:j.evidence?c(j.evidence):void 0,children:[w(j.book_id,r(j.book_id)),t.jsx("span",{className:"bim-d-meta",children:c(j.relation)})]},h))})]})]}),(y=e.appendix)==null?void 0:y.map((j,h)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:c("附記")})," ",c(j.title)]}),t.jsx(dt,{text:j.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${h}`)),(p==null?void 0:p.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:c(p.note)})]})}const Yt=16,Zx=200,Xx=16,Wl=({data:e,catalog:n,transport:o,onNavigate:r,renderLink:s,catalogAction:l,railTop:c,back:p,railLinks:a})=>{var ye,be,K,I,Y,fe,he;const d=me(),{convert:u}=V(),[m,x]=f.useState(""),[g,b]=f.useState(!1),[w,y]=f.useState(null),[j,h]=f.useState(""),[v,$]=f.useState(!1),k=f.useMemo(()=>ks(e,n),[e,n]),[_,S]=f.useState(new Map),z=!!o&&k.rows.length>0&&k.rows.length<=Zx,N=z&&(k.rows.length<=Yt||v),R=N&&k.rows.every(W=>!W.id||_.has(W.id)),C=W=>{var ae;return ji(W?(ae=_.get(W))==null?void 0:ae.l1:void 0)},H=f.useMemo(()=>{const W=m.trim(),ae=W?u(W):"";return k.rows.filter(J=>{var xe,je;if(j&&ji(J.id?(xe=_.get(J.id))==null?void 0:xe.l1:void 0)!==j)return!1;if(!ae)return!0;const O=J.id&&((je=_.get(J.id))==null?void 0:je.title)||J.title;return u(O).includes(ae)||(J.subItems||[]).some(Se=>u(Se).includes(ae))})},[k.rows,m,j,_,u]),L=g?H:H.slice(0,Yt),M=f.useMemo(()=>(N?k.rows:L).filter(W=>W.id&&!_.has(W.id)).map(W=>W.id),[N,k.rows,L,_]);f.useEffect(()=>{if(!o||M.length===0)return;let W=!1;const ae=M.slice(0,Xx);return Promise.all(ae.map(J=>o.getItem(J).then(O=>{var Se,ne;const xe=O??{},je={title:xe.title,edition:xe.edition,authors:xe.authors,measure:O?pt(O,d.unit.juan):void 0,versionCount:xe._edition_count??((Se=xe.books)==null?void 0:Se.length),l1:((ne=xe.classification)==null?void 0:ne.l1)||void 0};return[J,je]}).catch(()=>[J,{}]))).then(J=>{W||S(O=>{const xe=new Map(O);for(const[je,Se]of J)xe.set(je,Se);return xe})}),()=>{W=!0}},[o,M,d.unit.juan]);const F=(e.contained_in||[])[0];f.useEffect(()=>{if(!F){y(null);return}if(y({id:F}),!o)return;let W=!1;return o.getItem(F).then(ae=>{W||y({id:F,title:ae==null?void 0:ae.title})}).catch(()=>{}),()=>{W=!0}},[o,F]);const X=f.useMemo(()=>Tl(e.resources,e.resource_groups),[e.resources,e.resource_groups]),U=X.text.length+X.groups.reduce((W,ae)=>W+ae.rows.length+ae.mirrors.length,0),T=e.contained_works||[],ce=new Set(k.rows.map(W=>W.id).filter(Boolean)),B=T.length>0&&!T.every(W=>ce.has(W.id)),D=(()=>{const W=k.rows.map(ae=>ae.edition).filter(Boolean);return W.length>1&&new Set(W).size===1})(),A=k.rows.some(W=>W.volumes.length>0||W.expected!=null),ee=e._member_count||((ye=e.books)==null?void 0:ye.length)||T.length,de=pt(e,d.unit.juan),G=e.count,q=W=>typeof W=="number"&&Number.isFinite(W)?W:null,ie=q(G==null?void 0:G.juan)??q((be=e.juan_count)==null?void 0:be.number),pe=q(G==null?void 0:G.ce)??(k.totalVolumes||null),ge=[{value:k.rows.length,label:"子目"},{value:ie??0,label:d.unit.juan},{value:pe??0,label:d.unit.volume}],Ee=f.useMemo(()=>{var J,O;const W=[];if((J=e.publication_info)!=null&&J.details&&W.push({label:"刊印",value:u(e.publication_info.details)}),ee&&ee!==k.rows.length){const xe=e._member_type==="Book"?"所收版本":e._member_type==="Work"?"所收作品":"成員";W.push({label:u(xe),value:`${ee} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")})}const ae=[q(G==null?void 0:G.zhong)!=null?`${G.zhong} 種`:"",q(G==null?void 0:G.han)!=null?`${G.han} 函`:""].filter(Boolean);return ae.length&&W.push({label:"應收",value:u(ae.join(" "))}),ie==null&&de&&W.push({label:"卷帙",value:u(de),title:(O=e.juan_count)!=null&&O.description?u(e.juan_count.description):void 0}),W},[e,ee,k.rows.length,ie,de,G,u,d]),Ne=f.useMemo(()=>{if(!R)return[];const W=new Map;for(const J of k.rows){const O=C(J.id);O&&W.set(O,(W.get(O)??0)+1)}const ae=Xt.filter(J=>(W.get(J.key)??0)>0);return ae.length<2?[]:[{key:"",label:`${d.catalog.all} ${k.rows.length}`},...ae.map(J=>({key:J.key,label:`${J.label} ${W.get(J.key)}`}))]},[R,k.rows,_,d]),ze=f.useMemo(()=>{if(!R||!k.rows.some(O=>O.volumes.length>0))return null;const W=[],ae=k.rows.filter(O=>O.volumes.length>0).map(O=>({k:C(O.id)??"",from:Math.min(...O.volumes),to:Math.max(...O.volumes)})).sort((O,xe)=>O.from-xe.from);for(const O of ae){const xe=O.to-O.from+1,je=W[W.length-1];je&&je.key===O.k?(je.to=Math.max(je.to,O.to),je.n+=xe):W.push({key:O.k,from:O.from,to:O.to,n:xe})}const J=ae.reduce((O,xe)=>Math.max(O,xe.to),0);return W.length>1&&W.some(O=>O.key)?{segs:W,last:J}:null},[R,k.rows,_]),Te=(K=e.description)==null?void 0:K.text,Ce=t.jsx(on,{kind:"叢編",title:u(e.title),byline:t.jsx(oo,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(De,{items:[e.subtype==="work_collection"?u("作品集"):"",(I=e.publication_info)!=null&&I.year?u(e.publication_info.year):""]}),description:Te||(Y=e.history)!=null&&Y.length?t.jsxs(t.Fragment,{children:[Te&&t.jsx(dt,{text:Te,style:{fontSize:15,lineHeight:1.85}}),(fe=e.history)!=null&&fe.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((W,ae)=>t.jsx("li",{children:u(W)},ae))}):null]}):void 0,clampDescription:Mi(Te)||(((he=e.history)==null?void 0:he.length)??0)>2?6:void 0,stats:ge,facts:Ee,foot:t.jsx(rn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ze&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:u("全帙冊次分佈")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":u("全帙冊次分佈"),children:ze.segs.map((W,ae)=>{const J=Xt.find(O=>O.key===W.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!J,title:J?u(`${J.label} 第 ${W.from}–${W.to} 冊`):void 0,"aria-label":u(J?`只看${J.label}`:"未分類"),"aria-pressed":!!J&&j===W.key,style:{flexGrow:W.n,background:i(J?J.token:"rule")},onClick:()=>{J&&(h(j===W.key?"":W.key),b(!1))}},ae)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:u(`第 1 ${d.unit.volume}`)}),t.jsx("span",{children:u("點色段篩選部類")}),t.jsx("span",{children:u(`第 ${ze.last} ${d.unit.volume}`)})]})]})}),Ae=[];k.rows.length&&Ae.push({id:"titles",label:"子目",count:k.rows.length}),U&&Ae.push({id:"resources",label:"影印與全文",count:U}),B&&Ae.push({id:"works",label:d.section.containedWorks,count:T.length});const P=t.jsxs(t.Fragment,{children:[k.rows.length>0&&t.jsxs(He,{id:"titles",title:"子目",meta:t.jsx(De,{items:[u(`${k.rows.length} ${d.unit.items}`),k.totalVolumes?u(`全帙 ${k.totalVolumes} ${d.unit.volume}`):"",H.length!==k.rows.length?u(`當前 ${H.length} ${d.unit.items}`):""]}),action:l,children:[(k.rows.length>Yt||Ne.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[Ne.length>0&&t.jsx(Ln,{items:Ne,value:j,onChange:W=>{h(W),b(!1)}}),z&&k.rows.length>Yt&&!R&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:v,onClick:()=>$(!0),title:u(`將載入全部 ${k.rows.length} ${d.unit.items}`),children:u(v?"正在按部類分組…":"按部類分組")}),t.jsx("span",{className:"bim-d-spacer"}),k.rows.length>Yt&&t.jsx("input",{type:"search",className:"bim-d-find",value:m,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:W=>{x(W.target.value),b(!1)}})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[A&&t.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),t.jsx("th",{children:u("書名")}),t.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),t.jsx("tbody",{children:L.map((W,ae)=>{var we;const J=W.id?_.get(W.id):void 0,O=J!=null&&J.title&&W.title===W.id?J.title:W.title,xe=((J==null?void 0:J.authors)||[]).find(E=>E&&E.name),je=[xe?`${xe.dynasty?`〔${u(xe.dynasty)}〕`:""}${u(xe.name)}${xe.role?` ${u(xe.role)}`:""}`:"",J!=null&&J.measure?u(J.measure):"",(we=W.subItems)!=null&&we.length?W.subItems.map(E=>u(E)).join("、"):"",(J!=null&&J.edition||W.edition)&&!D?u((J==null?void 0:J.edition)||W.edition||""):""].filter(Boolean),Se=Xt.find(E=>E.key===C(W.id)),ne=W.volumes.length>0?u(`第 ${Nn(W.volumes,d.unit.volume)} ${d.unit.volume}`):W.expected!=null?u(`${W.found??0}/${W.expected} ${d.unit.volume}`):"";return t.jsxs("tr",{children:[A&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ne?"":" bim-d-zt-blank"}`,children:[Se&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:i(Se.token)}}),ne||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[W.id?t.jsx(Me,{id:W.id,label:u(O),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(O)}),je.length>0?t.jsx(De,{items:je}):W.id&&!J&&o?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${J!=null&&J.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:J!=null&&J.versionCount?u(`${J.versionCount} 種`):""})]},`${W.id??W.title}-${ae}`)})})]}),L.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),H.length>L.length&&t.jsx(Mt,{label:`展開其餘 ${H.length-L.length} ${d.unit.items}`,onClick:()=>b(!0)})]}),U>0&&t.jsxs(He,{id:"resources",title:"影印與全文",meta:u(`${U} 處`),children:[X.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[X.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:X.text.map((W,ae)=>t.jsx(ro,{item:W,siblings:X.text},`${W.id||W.url||W.name}-${ae}`))})})]}),t.jsx(El,{groups:X.groups})]}),k.rows.length===0&&U===0&&t.jsx(He,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),se=B?t.jsx(yt,{id:"works",title:d.section.containedWorks,meta:u(`${T.length} 種`),cap:12,items:T.map(W=>t.jsx(Me,{id:W.id,label:u(W.title),onNavigate:r,renderLink:s,dense:!0}))}):null,re=w?t.jsx(Ts,{caption:"上級叢編",children:t.jsx(Me,{id:w.id,label:u(w.title||w.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(nn,{railTop:c,back:p,up:re,nav:Ae,railLinks:a,main:P,card:Ce,side:se})},Qx=16,Qn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Or(e){if(!e)return Qn.length;const n=Qn.indexOf(e);return n===-1?Qn.length:n}const ef={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function mt(e){return e==null?"":e<0?`前${-e}`:String(e)}const tf={秦:[-221,-207],西漢:[-202,8],西汉:[-202,8],東漢:[25,220],东汉:[25,220],漢:[-202,220],汉:[-202,220],三國:[220,280],三国:[220,280],西晉:[265,316],西晋:[265,316],東晉:[317,420],东晋:[317,420],隋:[581,618],唐:[618,907],五代:[907,960],北宋:[960,1127],南宋:[1127,1279],宋:[960,1279],遼:[916,1125],辽:[916,1125],金:[1115,1234],元:[1271,1368],明:[1368,1644],清:[1636,1912]},Ml=({data:e,transport:n,onNavigate:o,renderLink:r,railTop:s,back:l,railLinks:c})=>{var se,re,ye,be,K;const p=me(),{convert:a}=V(),[d,u]=f.useState("全部"),[m,x]=f.useState(!1),[g,b]=f.useState("default"),[w,y]=f.useState(new Map),j=f.useMemo(()=>(e.works||[]).map(I=>{const Y=w.get(I.work_id);return{id:I.work_id,title:(Y==null?void 0:Y.title)??I.title??I.work_id,role:I.role||"",cls:Ai(I.role),versionCount:Y==null?void 0:Y.versionCount,section:Y==null?void 0:Y.cls,l1:Y==null?void 0:Y.l1,measure:Y==null?void 0:Y.measure,hasImage:Y==null?void 0:Y.hasImage,loaded:!!(Y!=null&&Y.loaded)}}),[e.works,w]),h=f.useMemo(()=>vs((e.works||[]).map(I=>I.role)),[e.works]),v=f.useMemo(()=>{const I=d==="全部"?j:j.filter(Y=>Y.cls===d);return g==="versions"?[...I].sort((Y,fe)=>(fe.versionCount??-1)-(Y.versionCount??-1)):I},[j,d,g]),$=m?v:v.slice(0,Qx),k=f.useMemo(()=>$.filter(I=>!w.has(I.id)).map(I=>I.id),[$,w]);f.useEffect(()=>{if(!n||k.length===0)return;let I=!1;return Promise.all(k.map(Y=>n.getItem(Y).then(fe=>{var J,O,xe,je,Se;const he=fe??{},W=he._edition_count??(((J=he.books)==null?void 0:J.length)??0)+(((O=he.collections)==null?void 0:O.length)??0),ae=[(xe=he.classification)==null?void 0:xe.l1,(je=he.classification)==null?void 0:je.l2].filter(Boolean).join(" ");return[Y,{id:Y,title:he.title,versionCount:W,loaded:!0,cls:ae||void 0,l1:((Se=he.classification)==null?void 0:Se.l1)||void 0,measure:fe&&pt(fe,p.unit.juan)||void 0,hasImage:!!(he.has_image??he._has_image)}]}).catch(()=>[Y,{id:Y,loaded:!0}]))).then(Y=>{I||y(fe=>{const he=new Map(fe);for(const[W,ae]of Y)he.set(W,ae);return he})}),()=>{I=!0}},[n,k,p.unit.juan]);const _=f.useMemo(()=>{const I=new Map;for(const Y of e.alt_names||[]){const fe=Y.type||p.section.aliases;I.has(fe)||I.set(fe,[]),I.get(fe).push(Y.name)}return[...I.entries()].sort((Y,fe)=>Or(Y[0])-Or(fe[0])).map(([Y,fe])=>({label:Y,names:fe}))},[e.alt_names,p]),S=e.birth_year??((se=e.dates)==null?void 0:se.birth)??void 0,z=e.death_year??((re=e.dates)==null?void 0:re.death)??void 0,N=(ye=e.dates)==null?void 0:ye.floruit,R=S!=null||z!=null?`${mt(S)||"?"}—${mt(z)||"?"}`:Array.isArray(N)&&N.length===2&&N.every(I=>Number.isFinite(I))?`活躍於 ${mt(N[0])}—${mt(N[1])}`:"",C=new Set(["本名","字","號","号"]),H=_.filter(I=>C.has(I.label)),L=_.filter(I=>!C.has(I.label)),M=L.reduce((I,Y)=>I+Y.names.length,0),F=f.useMemo(()=>{const I=[];for(const fe of H)I.push({label:fe.label,value:fe.names.map(he=>a(he)).join("、")});const Y=(e.works||[]).length;return Y&&I.push({label:"著作",value:`${Y} ${a("種")}`}),I},[e.works,H,a]),X=I=>{var Y;return(Y=_.find(fe=>I.includes(fe.label)))==null?void 0:Y.names[0]},U=X(["字"]),T=X(["號","号"]),ce=[U?`字${U}`:"",T?`號${T}`:""].filter(Boolean).join(","),B=e.native_place,D=e.dynasty?tf[e.dynasty]:void 0,A=(()=>{if(!D||S==null||z==null||z<S)return null;const[I,Y]=D,fe=Math.max(S,I),he=Math.min(z,Y);if(he<=fe)return null;const W=Y-I;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":a(`${mt(S)}—${mt(z)},一生 ${z-S+1} 年`),children:t.jsx("i",{style:{left:`${(fe-I)/W*100}%`,width:`${(he-fe)/W*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:a(`${mt(I)} ${e.dynasty}`)}),t.jsx("span",{children:a(`一生 ${z-S+1} 年`)}),t.jsx("span",{children:mt(Y)})]})]})})(),ee=f.useMemo(()=>{if(!n||j.length===0||j.some(fe=>!fe.loaded))return null;const I=new Map;for(const fe of j){const he=ji(fe.l1);he&&I.set(he,(I.get(he)??0)+1)}const Y=Xt.map(fe=>({...fe,n:I.get(fe.key)??0})).filter(fe=>fe.n>0);return Y.length?Y:null},[j,n]),de=t.jsxs(on,{kind:ef[e.subtype]??"人物",title:a(e.primary_name||e.title),subtitle:ce?a(ce):void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(De,{items:[e.dynasty?a(e.dynasty):"",R?a(R):"",B?a(`${B}人`):""]}),A]}),description:(be=e.description)!=null&&be.text?t.jsx(dt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Mi((K=e.description)==null?void 0:K.text)?6:void 0,facts:F,foot:t.jsx(rn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[M>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:a(`更多別名(${M})`)}),t.jsx("dl",{children:L.map(I=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:a(I.label)}),t.jsx("dd",{children:I.names.map(Y=>a(Y)).join("、")})]},I.label))})]}),ee&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:a("著作分佈")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:ee.map(I=>t.jsx("i",{style:{flexGrow:I.n,background:i(I.token)}},I.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ee.map(I=>t.jsxs("span",{children:[t.jsx("i",{style:{background:i(I.token)}}),a(I.label)," ",I.n]},I.key))})]})]}),G=f.useMemo(()=>j.filter(I=>I.loaded&&(I.versionCount??0)>0).sort((I,Y)=>(Y.versionCount??0)-(I.versionCount??0)).slice(0,3),[j]),q=!!n&&j.length>=3&&$.some(I=>!I.loaded),ie=d==="全部"&&(q||G.length>=2),pe=e.external_ids||{},ge=[];pe.cbdb_id!=null&&ge.push({label:"CBDB",id:String(pe.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${pe.cbdb_id}`,note:pe.cbdb_match==="auto"?"自動匹配":void 0});const Ee=pe.wikidata_id;Ee&&ge.push({label:"Wikidata",id:Ee,href:`https://www.wikidata.org/wiki/${Ee}`});const Ne=pe.viaf_id;Ne&&ge.push({label:"VIAF",id:Ne,href:`https://viaf.org/viaf/${Ne}`});const ze=h.map(I=>({key:I.cls,label:`${I.label} ${I.count}`})),Te=[...ie&&!q?[{id:"featured",label:"著作舉要",count:G.length}]:[],...j.length?[{id:"works",label:"全部著作",count:j.length}]:[],...ge.length?[{id:"external",label:"站外資料",count:ge.length}]:[]],Ce=ie?t.jsxs(He,{id:"featured",title:"著作舉要",children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:a("存世版本最多的三部")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":q||void 0,children:[q&&[0,1,2].map(I=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},I)),!q&&G.map(I=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Me,{id:I.id,label:a(I.title),onNavigate:o,renderLink:r,dense:!0})}),t.jsx(De,{items:[I.section?a(I.section):"",I.measure?a(I.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:I.versionCount}),t.jsx("span",{children:a("種版本")}),I.hasImage&&t.jsx("span",{className:"bim-d-flag",children:a("有影印")})]})]},I.id))]})]}):null,Ae=j.length===0?t.jsx(He,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該人物的關聯作品。")})}):t.jsxs(t.Fragment,{children:[Ce,t.jsxs(He,{id:"works",title:"著作",meta:t.jsx(De,{items:[a(`共 ${j.length} 種`),v.length!==j.length?a(`當前 ${v.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ze.length>1&&t.jsx(Ln,{items:ze,value:d,onChange:I=>{u(I),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":g==="versions",onClick:()=>{g==="default"&&x(!0),b(I=>I==="default"?"versions":"default")},children:a(g==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("作品")}),t.jsx("th",{children:a("部類")}),t.jsx("th",{children:a("職任")}),t.jsx("th",{children:a("存世版本")}),t.jsx("th",{"aria-label":a("影印")})]})}),t.jsx("tbody",{children:$.map(I=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Me,{id:I.id,label:a(I.title),onNavigate:o,renderLink:r,dense:!0}),I.measure?t.jsx(De,{items:[a(I.measure)]}):!I.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.section||I.loaded?"":" bim-d-zt-blank"}`,children:I.section?a(I.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.role?"":" bim-d-zt-blank"}`,children:I.role?a(I.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.loaded?"":" bim-d-zt-blank"}`,children:I.loaded?I.versionCount?a(`${I.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:a("未著錄")}):""}),t.jsx("td",{className:I.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:I.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:a("有影印")})})]},I.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a("該職任下的著作尚未著錄。")}),v.length>$.length&&t.jsx(Mt,{label:`展開其餘 ${v.length-$.length} 種著作`,onClick:()=>x(!0)})]})]}),P=ge.length>0?t.jsx(yt,{id:"external",title:"站外資料",items:ge.map(I=>t.jsxs("a",{href:I.href,target:"_blank",rel:"noopener noreferrer",children:[I.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:ge.map(I=>I.id),foot:pe.cbdb_id!=null&&pe.cbdb_match==="auto"?a("CBDB 為自動匹配,未經人工核對"):void 0}):null;return t.jsx(nn,{railTop:s,back:l,nav:Te,railLinks:c,main:Ae,card:de,side:P})},lo="(max-width: 719px)",nf=`${lo}, (pointer: coarse)`,Fl=`
|
|
1020
|
+
`)}),s=[]};for(const c of n){const p=Qi(c);if(p){l(),r={kind:"heading",level:p.level,text:p.text};continue}s.push(c)}return l(),o}function lr(e){const n=[];for(const o of e.split(`
|
|
1021
|
+
`)){const r=Qi(o);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=o.trim();!s||eo.test(s)||n.push({kind:"body",text:o})}return n}function ul(e){if(!e)return[];const n=Pn(e);if(n==="unknown")return lr(e);const o=[];for(const{heading:r,body:s}of jp(e)){r&&o.push(r);const l=cl(s);if(l.length!==0){if(pl(s)){o.push(...lr(s));continue}if(n==="record"){const c=l.join(" ");c&&o.push({kind:"body",text:c})}else for(const c of l){const p=dl(c);p.length&&o.push({kind:"body",text:p.join(" ")})}}}return o}const xl=e=>e;function fl(e,n=xl){if(e.indexOf("《")<0)return n(e);const o=[],r=/《([^《》\n]+)》/g;let s=0,l=0,c;for(;c=r.exec(e);)c.index>s&&o.push(t.jsx(x.Fragment,{children:n(e.slice(s,c.index))},l++)),o.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(c[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=c.index+c[0].length;return s===0?n(e):(s<e.length&&o.push(t.jsx(x.Fragment,{children:n(e.slice(s))},l++)),o)}function to(e,n={}){const o=n.renderText??xl,r=n.properNames?l=>fl(l,o):o,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Xe(e,r,s)}function ar(e,n,o){return e.indexOf("**")<0?n(e):e.split(/(\*\*[^*]+\*\*)/g).map((s,l)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?t.jsx("strong",{children:n(s.slice(2,-2))},`${o}-${l}`):t.jsx(x.Fragment,{children:n(s)},`${o}-${l}`))}const ei=/^(#{1,6})\s+(.*)$/,vp=/^\s*<!--.*-->\s*$/;function ml(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
|
|
1022
|
+
`)?"":n)}function kp(e){return e<=1?2:e===2?3:4}function wp(){let e=1;return n=>{const o=kp(n),r=Math.min(o,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${o}`}}}function Ct(e){return e?Pn(ml(e))!=="unknown":!1}function cr({text:e,mode:n,inline:o,dropTitle:r}){const s=ml(e),l=(d,u,m)=>!!r&&m<=1&&d<=2&&u.trim()===r.trim(),c=wp();if(n==="paragraph"&&Pn(s)!=="unknown"){const d=ul(s);return t.jsx(t.Fragment,{children:d.map((u,m)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,m))return null;const{Tag:f,className:g}=c(u.level??1);return t.jsx(f,{className:g,children:o(u.text)},m)}return t.jsx("p",{children:ar(u.text,o,m)},m)})})}const p=s.split(`
|
|
1023
|
+
`);let a=0;return t.jsx(t.Fragment,{children:p.map((d,u)=>{const m=d.match(ei);if(m){const g=a++;if(l(m[1].length,m[2],g))return null;const{Tag:b,className:w}=c(m[1].length);return t.jsx(b,{className:w,children:o(m[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!ei.test(p[u-1])&&!ei.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(vp.test(d))return null;if(a++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:g,className:b}=c(3);return t.jsx(g,{className:b,children:o(d.trim().slice(2,-2))},u)}return t.jsx("p",{children:ar(d,o,u)},u)})})}function Sp(e){const{convert:n}=X();return x.useMemo(()=>e?n(e):"",[e,n])}function Dn({text:e,mode:n,tables:o=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:c}){const p=Sp(e),{convert:a}=X(),d=f=>to(f,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,m=c?a(c):void 0;return!o||p.indexOf(":::")<0?t.jsx(cr,{text:p,mode:n,inline:d,dropTitle:m}):t.jsx(t.Fragment,{children:Zi(p).map((f,g)=>f.type==="table"?t.jsx(Xi,{table:f.table,opts:u},g):t.jsx(cr,{text:f.text,mode:n,inline:d,dropTitle:g===0?m:void 0},g))})}function no(e,n){const[o,r]=x.useState(null),[s,l]=x.useState(!1),c=x.useRef(0);return x.useEffect(()=>{const p=++c.current;if(!e||!n){r(null),l(!1);return}let a;try{a=e(n)}catch{r(null),l(!1);return}if(!a||typeof a.then!="function"){r(a??null),l(!1);return}l(!0),a.then(d=>{p===c.current&&r(d??null)}).catch(()=>{p===c.current&&r(null)}).finally(()=>{p===c.current&&l(!1)})},[e,n]),{images:o,loading:s}}const dr={A:"fine",B:"rough",C:"rough",D:"ocr"};function $p(e){return typeof e!="string"?null:e in ci?e:e in dr?dr[e]:null}const _p={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Cp={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function tt(e){return typeof e!="string"?"":_p[e]??Cp[e]??e}const zp=["〇","一","二","三","四","五","六","七","八","九"],pr=["","十","百","千"],Tp=["","萬","億"];function io(e){if(e===0)return"〇";if(e<0)return`負${io(-e)}`;const n=[];let o=e,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(Ip(s,r>0)+Tp[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Ip(e,n){const o=[];let r=e;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let s="";for(let l=0;l<o.length;l++){const c=o[l],p=o.length-1-l;c===0?s&&!s.endsWith("〇")&&(s+="〇"):c===1&&p===1&&l===0&&!n?s+=pr[p]:s+=zp[c]+pr[p]}return s.replace(/〇$/,"")}let rn=null,hn=null;const _n=new Set;function Ep(){return rn?Promise.resolve():hn||(hn=import("opencc-js/t2cn").then(e=>{rn=e.Converter({from:"tw",to:"cn"}),_n.forEach(n=>n())}).catch(()=>{rn=e=>e,_n.forEach(e=>e())}),hn)}const Rp=e=>e;function zt(){const[,e]=x.useState(0);return x.useEffect(()=>{if(rn)return;const n=()=>e(o=>o+1);return _n.add(n),Ep(),()=>{_n.delete(n)}},[]),rn??Rp}function Ft(e,n){return n(e).toLowerCase()}const Np=i("highlight-bg");function xn(e,n,o){if(!n)return e;const r=Ft(n,o);if(!r)return e;const s=Ft(e,o);if(s.length!==e.length)return e;const l=[];let c=0,p=0;for(;c<e.length;){const a=s.indexOf(r,c);if(a===-1){l.push(e.slice(c));break}a>c&&l.push(e.slice(c,a)),l.push(t.jsx("mark",{style:{background:Np,padding:0,color:"inherit"},children:e.slice(a,a+r.length)},p++)),c=a+r.length}return t.jsx(t.Fragment,{children:l})}function oo(e,n,o,r){if(!n)return!0;const s=Ft(n,r);return(o?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(c=>typeof c=="string"&&Ft(c,r).includes(s))}function Lp(e,n,o){return n?Ft(e,o).includes(Ft(n,o)):!0}const ro={类:i("section-lei"),书:i("section-shu"),序:i("section-xu"),结语:i("section-jieyu"),注释:i("section-zhushi")},Ap={考证:i("section-kaozhen")};function Bp(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 so(e){var r;const n=e.files.length,o=((r=e.children)==null?void 0:r.reduce((s,l)=>s+so(l),0))||0;return n+o}function gl(e,n){const o=[],r=c=>{var p;o.push(...c.files),(p=c.children)==null||p.forEach(r)};if(r(e),o.length===0)return;const s=o.map(c=>n[c]);if(s.every(c=>c===void 0))return;if(s.some(c=>c==="loading"))return"loading";let l=0;for(const c of s)typeof c=="number"&&(l+=c);return l}const Mp={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function lo({enabled:e,expanded:n,onClick:o,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:o,style:{...Mp,...r},children:s}):t.jsx("span",{style:r,children:s})}function Wp({type:e}){const n=tt(e),o=ro[n]||i("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:o,border:`1px solid ${o}40`,borderRadius:"2px",background:`${o}08`,flexShrink:0},children:n})}function Fp({section:e,onNavigate:n,highlightQuery:o="",no:r,showUnlinked:s=!1,domId:l}){const{convert:c}=X(),p=Fe(),a=zt(),d=h=>h?Xe(c(h),v=>o?xn(v,o,a):v):"",[u,m]=x.useState(!1),f=!!e.summary,g=!!e.comment,b=!!e.additional_comment,w=!!(e.content&&e.content.length>60),y=f||g||b||w;x.useEffect(()=>{o&&m(!0)},[o]);const j=!u&&w?Hs(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{className:"bim-rd-row",id:l,style:{borderBottom:`1px solid ${i("rule")}`,overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>y&&m(!u),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:y?"pointer":"default",userSelect:"none"},children:[r!=null&&t.jsx("span",{className:"bim-rd-no",style:{flex:"none",width:28,fontSize:12,color:i("label-fg")},children:r}),t.jsxs(lo,{enabled:y,expanded:u,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[y&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",d(e.book_title),"》"]}):d(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[io(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:d(e.author_info||e.author)})]}),!u&&j&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:d(j)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:d(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:i("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:p(e.work_id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),h.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品","aria-label":`查看作品:${e.book_title||e.title}`,children:"作品 →"}),s&&!e.work_id&&t.jsx("span",{style:{fontSize:"11px",color:i("label-fg"),flexShrink:0},children:"未关联"})]}),u&&y&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${i("widget-border")}`,background:i("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"8px"},children:d(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${i("primary")}`,background:`color-mix(in srgb, ${i("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:d(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(e.additional_comment)})]}),w&&!f&&!g&&!b&&t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:d(e.content)})]})]})}function Op({section:e,highlightQuery:n=""}){const{convert:o}=X(),r=zt(),s=a=>a?Xe(o(a),d=>n?xn(d,n,r):d):"",[l,c]=x.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(lo,{enabled:p,expanded:l,onClick:()=>c(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(Wp,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:s(e.title)}),p&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&p&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${ro[tt(e.type)]||i("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:i("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(e.content)})})]})}const Pp=100;function ao(e){return tt(e.type)!=="page_header"?!1:(e.content||"").length>=Pp}function Dp({section:e,highlightQuery:n=""}){const{convert:o}=X(),r=zt();if(tt(e.type)==="page_header"&&!ao(e)||!e.content&&!e.title)return null;const s=o((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
1024
|
+
`)),l=Xe(s,d=>n?xn(d,n,r):d),c=tt(e.type),p=ro[c]||i("desc-fg"),a=c==="序"||c==="结语"||c==="注释";return t.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:i("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${p}40`:void 0,background:a?i("bg"):void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:c}),l]})}function Hp(e,n,o){const[r,s]=x.useState({});return x.useEffect(()=>{var d;if(!n||e.length===0)return;let l=!1;const c=e.filter(u=>{var m;return!((m=o==null?void 0:o.current)!=null&&m.has(u))}),p={};for(const u of e)(d=o==null?void 0:o.current)!=null&&d.has(u)&&(p[u]=o.current.get(u));if(Object.keys(p).length>0&&s(p),c.length===0)return;const a=async u=>{var m;try{if(n.getEntry){const y=await n.getEntry(u);if(y)return{title:y.title,author:y.author}}const f=await n.getItem(u);if(!f)return null;const g=f.title||u,b=f.authors,w=(m=b==null?void 0:b[0])==null?void 0:m.name;return{title:g,author:w}}catch{return null}};return Promise.all(c.map(async u=>{var f;const m=await a(u);return(f=o==null?void 0:o.current)==null||f.set(u,m),[u,m]})).then(u=>{l||s(m=>{const f={...m};for(const[g,b]of u)f[g]=b;return f})}),()=>{l=!0}},[e.join(","),n]),r}function Gp({section:e,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=X(),c=Fe(),p=zt(),a=h=>h?Xe(l(h),v=>s?xn(v,s,p):v):"",[d,u]=x.useState(!1);x.useEffect(()=>{s&&u(!0)},[s]);const m=tt(e.type),f=Ap[m]||i("desc-fg"),g=!!e.content,b=e.work_ids||[],w=b.length>1,y=Hp(w?b:[],o,r),j=g&&!d&&e.content.length>80?Hs(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${i("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>g&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:g?"pointer":"default",userSelect:"none"},children:[t.jsxs(lo,{enabled:g,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[g&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg"),lineHeight:1.6},children:e.header_line?a(e.header_line):a(e.title)}),!d&&j&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:i("desc-fg"),lineHeight:1.7},children:a(j)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:c(b[0]),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),h.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),w&&t.jsxs("span",{style:{fontSize:"11px",color:i("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:f,border:`1px solid ${f}40`,borderRadius:"2px",background:`${f}08`},children:m})]})]}),w&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(h=>{const v=y[h],_=v?`${l(v.title)}${v.author?`(${l(v.author)})`:""}`:h.slice(0,8)+"…";return t.jsxs("a",{href:c(h),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),n(h))},style:{fontSize:"12px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:h,children:["→",_]},h)})}),d&&g&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${f}40`,borderRadius:"0 4px 4px 0",background:i("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${i("widget-border")}`,fontSize:"12px",color:i("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:a(e.comment)})]})]})}function Vp({juan:e,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const l=zt(),c=n.trim(),p=x.useMemo(()=>c?e.sections.filter(a=>oo(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(Gp,{section:a,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:c},d))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Up(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Yp({sections:e,onNavigate:n,inline:o,workLinks:r=!0}){const s=Fe(),{convert:l}=X(),c=Up();return t.jsx(t.Fragment,{children:e.map((p,a)=>{const d=tt(p.type);if(d==="page_header"&&!ao(p))return null;if(d==="类")return t.jsxs(x.Fragment,{children:[x.createElement(c("类"),null,o(l(p.title))),p.content&&t.jsx("p",{children:o(l(p.content))})]},a);if(d==="书"||d==="诗"||d==="考证"||d==="注释"){const u=p.book_title?`《${p.book_title}》${p.n_juan!=null?io(p.n_juan)+"卷":""}`:p.title,m=o(l(u));return t.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${a}`,children:[x.createElement(c("条目"),{className:"bim-rd-entry-h"},p.work_id&&n&&r?t.jsxs(t.Fragment,{children:[t.jsx("a",{href:s(p.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(p.work_id))},title:"查看作品",children:m}),t.jsx("a",{className:"bim-rd-wl",href:s(p.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(p.work_id))},"aria-label":`查看作品:${u}`,children:"作品 →"})]}):m),p.author_info&&t.jsx("p",{className:"bim-rd-sub",children:o(l(p.author_info))}),p.content&&p.content.split(/\n+/).map((f,g)=>t.jsx("p",{children:o(l(f))},g)),p.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),o(l(p.summary))]}),p.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),o(l(p.comment))]}),p.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),o(l(p.additional_comment))]})]},a)}return p.content?t.jsx("p",{children:o(l(p.content))},a):null})})}function co(e){return e.some(n=>{const o=tt(n.type);return o==="书"||o==="诗"||o==="考证"||o==="注释"||o==="类"||(o==="序"||o==="结语")&&!!n.content||o==="page_header"&&ao(n)})}function hl({juan:e,rawText:n,positionLabel:o,groupLabel:r,index:s,searchQuery:l,onNavigate:c,transport:p,workLabelCache:a,prefs:d,view:u,onViewChange:m}){var pe;const{convert:f}=X(),g=zt(),[b,w]=x.useState("text"),y=u??b,j=A=>{w(A),m==null||m(A)},h=l.trim(),v=(s==null?void 0:s.type)==="kaozhen",_=x.useCallback(A=>h?xn(A,h,g):A,[h,g]),k=A=>to(A,{renderText:_,properNames:d.properNames}),$=x.useMemo(()=>h?e.sections.filter(A=>oo(A,h,v,g)):e.sections,[e.sections,h,v,g]),S=(A,oe)=>oe.filter(E=>tt(E.type)===A).length,C=S("书",e.sections),L=S("诗",e.sections),I=S("考证",e.sections);let T="";v?T=h?`${S("考证",$)} / ${I} ${f("條")}`:`${I} ${f("條")}`:L>0?T=h?`${S("诗",$)} / ${L} 首`:`${L} 首`:C>0&&(T=h?`${S("书",$)} / ${C} ${f("部書")}`:`${C} ${f("部書")}`);const U=s!=null&&s.text_quality?$p(s.text_quality.grade):null,M=[];T&&M.push(T),v&&(s!=null&&s.target_source)&&M.push(t.jsxs(t.Fragment,{children:[f("考證對象")," ",f(s.target_source)]})),U&&M.push(t.jsx("span",{title:wa[U],children:(pe=s==null?void 0:s.text_quality)!=null&&pe.source_note?t.jsxs(t.Fragment,{children:["底本 ",f(s.text_quality.source_note),t.jsx("span",{className:"bim-rd-grade",children:f(ci[U])})]}):t.jsxs(t.Fragment,{children:[f("文本質量"),t.jsx("span",{className:"bim-rd-grade",children:f(ci[U])})]})})),e.source_url&&M.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:f("原文來源")}));const F=!v&&co(e.sections),O=!!n&&(!F||d.readingMode==="paragraph"&&Ct(n)),D=!v&&(F||!!n),H=v||!D?"entries":y;let z=0;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[(o||r)&&t.jsxs("p",{className:"bim-rd-kicker",children:[o,o&&r&&t.jsx("span",{className:"bim-rd-dot"}),r&&f(r)]}),t.jsx("h1",{className:"bim-rd-h1",children:f(e.title)}),M.length>0&&t.jsx("p",{className:"bim-rd-meta",children:M.map((A,oe)=>t.jsxs(x.Fragment,{children:[oe>0&&t.jsx("span",{className:"bim-rd-dot"}),A]},oe))}),D&&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":H==="text",onClick:()=>j("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":H==="entries",onClick:()=>j("entries"),children:f("條目")})]})]}),H==="text"&&t.jsx("article",{className:"bim-rd-prose",children:O?t.jsx(Dn,{text:n,mode:d.readingMode,properNames:d.properNames,renderText:_,dropTitle:e.title}):t.jsx(Yp,{sections:e.sections,onNavigate:c,inline:k,workLinks:d.workLinks})}),H==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:v?t.jsx(Vp,{juan:e,searchQuery:l,onNavigate:c,transport:p,workLabelCache:a}):t.jsxs(t.Fragment,{children:[$.some(A=>["书","诗","考证"].includes(tt(A.type)))&&t.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[t.jsx("span",{style:{width:28},children:"序"}),t.jsx("span",{style:{flex:1},children:"书名"}),t.jsx("span",{children:"作品"})]}),$.map((A,oe)=>{const E=tt(A.type);return E==="书"||E==="诗"||E==="考证"?(z+=1,t.jsx(Fp,{domId:`rd-e-${e.sections.indexOf(A)}`,section:A,onNavigate:d.workLinks?c:void 0,highlightQuery:h,no:z,showUnlinked:d.workLinks&&!!c},oe)):E==="类"?t.jsx(Op,{section:A,highlightQuery:h},oe):t.jsx(Dp,{section:A,highlightQuery:h},oe)}),$.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function bl(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 Kp(e){const n=bl(e);return n.length>0?n[0]:null}function yl(e){const{resetKey:n,load:o,files:r,activeFile:s,activeJuan:l,activeRawText:c,query:p,isKaozhen:a}=e,d=zt(),u=x.useRef(new Map),[m,f]=x.useState({}),[g,b]=x.useState({}),w=x.useCallback((j,h)=>{const v=h==null?void 0:h.title;v&&b(_=>_[j]===v?_:{..._,[j]:v})},[]);x.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:c}),w(s,l))},[s,l,c,w]),x.useEffect(()=>{u.current.clear(),f({}),b({})},[n]);const y=x.useCallback((j,h)=>{let v=0;if(j.juan)for(const _ of j.juan.sections)oo(_,h,a,d)&&v++;return v===0&&j.rawText&&Lp(j.rawText,h,d)&&(v=1),v},[a,d]);return x.useEffect(()=>{const j=p.trim();if(!j){f({});return}if(!o||r.length===0)return;let h=!1;const v={},_=[];for(const L of r){const I=u.current.get(L);I?v[L]=y(I,j):(v[L]="loading",_.push(L))}f(v);const k=8;let $=0;const S=async()=>{for(;$<_.length;){if(h)return;const L=$++,I=_[L];try{const T=await o(I),U=T.juan;if(u.current.set(I,T),w(I,U),h)return;f(M=>({...M,[I]:y(T,j)}))}catch{if(h)return;f(T=>({...T,[I]:0}))}}},C=Array.from({length:Math.min(k,_.length)},()=>S());return Promise.all(C),()=>{h=!0}},[p,n,o,r.join(","),y,d,w]),{matchStates:m,titles:g}}function jl({juan:e,view:n,onView:o,textHasEntries:r}){const{convert:s}=X(),l=e.sections.map((d,u)=>({s:d,i:u,t:tt(d.type)})).filter(d=>d.t==="书"||d.t==="诗");if(l.length===0)return null;const c=l.filter(d=>!!d.s.work_id).length,p=l.every(d=>d.t==="诗")?"首":"部书",a=d=>{const u=()=>{var m,f;return(f=(m=document.getElementById(`rd-e-${d}`))==null?void 0:m.scrollIntoView)==null?void 0:f.call(m,{block:"start",behavior:"smooth"})};n==="text"&&!r&&o("entries"),n==="text"&&!r?setTimeout(u,0):u()};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-rd-rail-card",children:[t.jsx("div",{className:"bim-rd-rail-cap",children:"本卷"}),t.jsxs("div",{className:"bim-rd-rail-n",children:[t.jsx("b",{children:l.length}),t.jsx("span",{children:s(p)}),t.jsxs("span",{className:"bim-rd-rail-linked",children:["已关联 ",c]})]}),t.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":`已关联 ${c} / ${l.length}`,children:t.jsx("span",{style:{width:`${Math.round(c/l.length*100)}%`}})})]}),t.jsxs("nav",{"aria-label":"本卷条目",children:[t.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:s("條目")}),t.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:d,i:u})=>t.jsx("li",{children:t.jsxs("a",{href:`#rd-e-${u}`,onClick:m=>{m.preventDefault(),a(u)},children:[t.jsx("span",{className:`bim-rd-rail-dot${d.work_id?" on":""}`,"aria-hidden":"true"}),t.jsx("span",{children:s(d.book_title||d.title)})]})},u))})]})]})}function qp(e,n){const[o,r]=x.useState([]);return x.useEffect(()=>{if(r([]),!e||typeof(n==null?void 0:n.getItem)!="function")return;let s=!1;return Promise.resolve(n.getItem(e)).then(l=>{if(s||!l)return;const c=l.authors??[];r(c.filter(p=>p&&p.name))}).catch(()=>{}),()=>{s=!0}},[e,n]),o}const po=({index:e,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:l,className:c,style:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:m,imagePanel:f,allowVertical:g,onReportError:b,revisedAt:w})=>{const[y,j]=x.useState(null),[h,v]=x.useState(!1),[_,k]=x.useState(null),[$,S]=x.useState(null),[C,L]=x.useState(null),[I,T]=x.useState(!1),[U,M]=x.useState(null),[F,O]=x.useState(""),D=x.useRef(new Map),H=x.useRef(0),z=s??$,pe=x.useCallback(ee=>{S(ee),l==null||l(ee)},[l]),A=e||y;x.useEffect(()=>{e&&(v(!1),k(null))},[e]),x.useEffect(()=>{if(e||!n||!(o!=null&&o.getCollatedEditionIndex))return;let ee=!1;return v(!0),k(null),o.getCollatedEditionIndex(n).then(Z=>{ee||(Z?j(Z):k("未找到整理本数据"))}).catch(Z=>{ee||k(Z instanceof Error?Z.message:"加载失败")}).finally(()=>{ee||v(!1)}),()=>{ee=!0}},[e,n,o]),x.useEffect(()=>{if(A&&!z){const ee=Kp(A);ee&&pe(ee)}},[A,z,pe]);const oe=n||(A==null?void 0:A.work_id),E=x.useCallback(async ee=>{var le;if(!oe||!(o!=null&&o.getCollatedJuan))return;const Z=++H.current;T(!0),L(null),M(null);try{const[be,Le]=await Promise.all([o.getCollatedJuan(oe,ee),((le=o.getCollatedJuanText)==null?void 0:le.call(o,oe,ee))??Promise.resolve(null)]);if(Z!==H.current)return;L(be),M(Le)}catch{if(Z!==H.current)return;L(null),M(null)}finally{Z===H.current&&T(!1)}},[oe,o]);x.useEffect(()=>{z&&E(z)},[z,E]);const W=ee=>{pe(ee)};if(h)return t.jsx("div",{className:c,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(_)return t.jsx("div",{className:c,style:{...p,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:_});if(!A)return null;const ce=A.type==="kaozhen",Y=bl(A);return t.jsx(Xp,{className:c,style:p,index:A,allFiles:Y,isKaozhen:ce,effectiveWorkId:oe,transport:o,activeFile:z,handleSelectFile:W,juanData:C,juanRawText:U,juanLoading:I,searchQuery:F,setSearchQuery:O,onNavigate:r,workLabelCacheRef:D,reader:{title:a,subtitle:d,resolveImages:u,renderImageOverlay:m,imagePanel:f,allowVertical:g,onReportError:b,revisedAt:w}})};function vi(e,n,o,r){var d,u,m,f;const s=(u=(d=n.juan_metadata)==null?void 0:d[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:Bp(e)),p=((f=(m=n.files)==null?void 0:m.find(g=>g.filename===e))==null?void 0:f.title)??o[e];if(!p)return{position:l,label:l};const a=r(p);return{position:l,label:l===p||l===a?a:`${l} ${a}`}}function Jp(e,n){if(!n)return;const o=r=>{var s;for(const l of r??[]){const c=o(l.children);if(c)return c;if((s=l.files)!=null&&s.includes(n))return l.label}};return o(e==null?void 0:e.juan_groups)}function Zp(e,n,o,r,s){const l=a=>a==="loading"?"…":typeof a=="number"&&a>0?a:void 0,c=(a,d)=>({key:a,label:d??vi(a,e,r,s).label,hint:l(o[a]),disabled:o[a]===0}),p=(a,d)=>{var m;if(a.files.length===1&&!((m=a.children)!=null&&m.length))return c(a.files[0],s(a.label));const u=gl(a,o);return{key:`group:${d}`,label:s(a.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:so(a),defaultExpanded:typeof u=="number"&&u>0,children:[...a.files.map(f=>c(f)),...(a.children??[]).map((f,g)=>p(f,`${d}.${g}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((a,d)=>p(a,`${d}`)):n.map(a=>c(a))}const Xp=({className:e,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:c,activeFile:p,handleSelectFile:a,juanData:d,juanRawText:u,juanLoading:m,searchQuery:f,setSearchQuery:g,onNavigate:b,workLabelCacheRef:w,reader:y})=>{const{convert:j}=X(),[h,v]=Fn(),[_,k]=x.useState("text");x.useEffect(()=>{k("text")},[p]);const $=x.useMemo(()=>l&&(c!=null&&c.getCollatedJuan)?async E=>{var Y;const[W,ce]=await Promise.all([c.getCollatedJuan(l,E),((Y=c.getCollatedJuanText)==null?void 0:Y.call(c,l,E))??Promise.resolve(null)]);return{juan:W,rawText:ce}}:null,[l,c]),{matchStates:S,titles:C}=yl({resetKey:l,load:$,files:r,activeFile:p,activeJuan:d,activeRawText:u,query:f,isKaozhen:s}),L=no(y.resolveImages,p),I=x.useMemo(()=>Zp(o,r,S,C,j),[o,r,S,C,j]),T=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:f,onChange:E=>g(E.target.value)}),U=s?"章":o.juan_metadata&&Object.values(o.juan_metadata).some(E=>E.vol_label)?"冊":"卷",M=p?vi(p,o,C,j).position:void 0,F=Fe(),O=y.title??(o.title?j(o.title):void 0),D=O&&l&&b?t.jsx("a",{href:F(l),onClick:E=>{E.metaKey||E.ctrlKey||(E.preventDefault(),b(l))},title:"查看作品",children:O}):O,H=!!d&&!s&&co(d.sections),z=H&&!(u&&h.readingMode==="paragraph"&&Ct(u)),pe=d&&!s&&H?t.jsx(jl,{juan:d,view:_,onView:k,textHasEntries:z}):void 0,A=qp(l,c),oe=A.length>0?j(A.slice(0,2).map(E=>`${E.dynasty?`〔${E.dynasty}〕`:""}${E.name}${E.role?` ${E.role}`:" 撰"}`).join("、")):void 0;return t.jsxs(On,{className:e,style:n,title:D,subtitle:y.subtitle??j(s?"考證":"整理本"),byline:oe,pagerUnit:U,rail:pe,revisedAt:y.revisedAt,onReportError:y.onReportError?E=>y.onReportError({...E,bookTitle:o.title??(typeof y.title=="string"?y.title:void 0),entryId:l}):void 0,current:p?vi(p,o,C,j).label:void 0,workLinkToggle:!s&&!!b&&!!(d!=null&&d.sections.some(E=>E.work_id)),toc:I,tocCaption:`目录 · ${r.length} ${j(U)}`,tocHeader:T,activeKey:p,onSelect:a,images:L.images,imagesLoading:L.loading,renderImageOverlay:y.renderImageOverlay,imagePanel:y.imagePanel,prefs:h,onPrefsChange:v,paragraphToggle:!s&&Ct(u),allowVertical:y.allowVertical,children:[m?t.jsx(yt,{}):d?t.jsx(hl,{juan:d,rawText:u,positionLabel:M,groupLabel:Jp(o,p),index:o,searchQuery:f,onNavigate:b,transport:c,workLabelCache:w,prefs:h,view:_,onViewChange:k},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,o.references&&o.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:j("參考文獻")}),t.jsx("ol",{children:o.references.map((E,W)=>t.jsxs("li",{children:[E.url?t.jsx("a",{className:"bim-rd-link",href:E.url,target:"_blank",rel:"noopener noreferrer",children:E.title}):t.jsx("span",{children:E.title}),E.author&&t.jsxs("span",{children:[",",E.author]}),E.note&&t.jsxs("span",{children:["。",E.note]})]},W))})]})]})},Qp={bug:{label:"错误反馈",color:i("danger")},resource:{label:"资源建议",color:i("primary")},suggestion:{label:"功能建议",color:i("primary")},other:{label:"其他",color:i("desc-fg")}},eu={label:"其他",color:i("desc-fg")},tu={pending:{label:"待处理",color:i("warning")},in_progress:{label:"处理中",color:i("primary")},resolved:{label:"已处理",color:i("success")},wontfix:{label:"不采纳",color:i("desc-fg")},duplicate:{label:"重复",color:i("desc-fg")}},nu={label:"待处理",color:i("warning")};function iu(e){try{const n=new Date(e),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return e}}function ou(e,n){if(!e)return!1;try{const o=new URL(e,n);if(o.protocol!=="http:"&&o.protocol!=="https:")return!1;const r=new URL(n);return o.hostname===r.hostname}catch{return!1}}const uo=({items:e,loading:n})=>{const o=Fe();return n?t.jsx(yt,{}):e.length===0?t.jsx("div",{style:ru,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Qp[r.type]||eu,l=tu[r.status]||nu,c=typeof window<"u"&&ou(r.pageUrl,window.location.href);return t.jsxs("div",{style:su,children:[t.jsxs("div",{style:lu,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...ur,background:s.color},children:s.label}),t.jsx("span",{style:{...ur,background:l.color},children:l.label})]}),t.jsx("span",{style:au,children:iu(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:cu,children:[r.resourceId&&t.jsx("a",{href:o(r.resourceId),style:ti,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(c?t.jsx("a",{href:r.pageUrl,style:ti,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:ti,children:r.pageUrl}))]}),t.jsx("div",{style:du,children:r.content}),r.reply&&t.jsxs("div",{style:pu,children:[t.jsx("div",{style:uu,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},ru={textAlign:"center",padding:"40px 0",color:i("desc-fg"),fontSize:"14px"},su={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"16px"},lu={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},ur={fontSize:"12px",color:i("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},au={fontSize:"12px",color:i("desc-fg")},cu={fontSize:"12px",marginBottom:"6px"},ti={color:i("primary"),textDecoration:"none",borderBottom:`1px dashed ${i("primary")}`},du={fontSize:"14px",lineHeight:"1.6",color:i("fg"),whiteSpace:"pre-wrap"},pu={marginTop:"12px",padding:"10px 12px",background:i("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:i("fg")},uu={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:i("primary")},ki=({transport:e,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const c=ge(),[p,a]=x.useState(null),[d,u]=x.useState([]),[m,f]=x.useState("recommend"),[g,b]=x.useState([]),[w,y]=x.useState(!1),j=r??m,h=O=>{f(O),s==null||s(O)},[v,_]=x.useState(!0),[k,$]=x.useState(null),[S,C]=x.useState(null),[L,I]=x.useState(null);x.useEffect(()=>{let O=!1;if(e.getCounts)return e.getCounts().then(D=>{O||a({works:D.works,books:D.books,collections:D.collections})}).catch(()=>{}),()=>{O=!0}},[e]),x.useEffect(()=>{let O=!1;return(async()=>{if(o)return o;if(e.getRecommended)try{const H=await e.getRecommended();if(H!=null&&H.groups)return H.groups.flatMap(z=>z.items.map(pe=>({...pe,group:z.name})))}catch{}return[]})().then(async H=>{if(O)return;const z=H.filter(A=>A.id);if(z.length===0){_(!1);return}const pe=await Promise.all(z.map(async A=>{if(A.type)return{id:A.id,title:A.title,type:A.type,author:A.author,dynasty:A.dynasty,role:A.role,edition:A.edition,has_text:A.has_text,has_image:A.has_image,has_collated:A.has_collated,subtype:A.subtype,primary_name:A.primary_name,group:A.group,fallbackDescription:A.description};try{let oe=null;if(e.getEntry)oe=await e.getEntry(A.id);else{const E=await e.getItem(A.id);E&&(oe={id:A.id,title:E.title||A.id,type:E.type||"work"})}if(oe)return{...oe,group:A.group,fallbackDescription:A.description}}catch{}return{id:A.id,title:A.title,type:je.extractType(A.id),group:A.group,fallbackDescription:A.description}}));O||(u(pe.filter(A=>A!==null)),_(!1))}),()=>{O=!0}},[e,o]);const T=x.useRef(!1),U=x.useRef(!1),M=x.useRef(!1);x.useEffect(()=>{if(j!=="catalog"||T.current)return;const O=e.getCatalogProgress??e.getResourceProgress;if(!O)return;T.current=!0;let D=!1;return O.call(e).then(H=>{D||$(H)}).catch(()=>{T.current=!1}),()=>{D=!0}},[e,j]),x.useEffect(()=>{if(j!=="collection"||U.current||!e.getCollectionProgress)return;U.current=!0;let O=!1;return e.getCollectionProgress().then(D=>{O||C(D)}).catch(()=>{U.current=!1}),()=>{O=!0}},[e,j]),x.useEffect(()=>{if(j!=="site"||M.current||!e.getSiteProgress)return;M.current=!0;let O=!1;return e.getSiteProgress().then(D=>{O||I(D)}).catch(()=>{M.current=!1}),()=>{O=!0}},[e,j]),x.useEffect(()=>{if(!l||j!=="feedback")return;let O=!1;return y(!0),fetch(l).then(D=>D.json()).then(D=>{!O&&D.success&&b(D.items||[])}).catch(()=>{}).finally(()=>{O||y(!1)}),()=>{O=!0}},[l,j]);const F=O=>t.jsx(Ht,{type:O,size:12});return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:i("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"16px"},children:[t.jsx(Zt,{label:c.home.recommendTab,active:j==="recommend",onClick:()=>h("recommend")}),t.jsx(Zt,{label:c.home.catalogTab,active:j==="catalog",onClick:()=>h("catalog")}),t.jsx(Zt,{label:c.home.collectionTab,active:j==="collection",onClick:()=>h("collection")}),t.jsx(Zt,{label:c.home.siteTab,active:j==="site",onClick:()=>h("site")}),l&&t.jsx(Zt,{label:c.home.feedbackTab,active:j==="feedback",onClick:()=>h("feedback")})]}),j==="recommend"&&t.jsx(xu,{recommended:d,loading:v,onNavigate:n,getIcon:F,t:c}),j==="catalog"&&t.jsx(xr,{progress:k,t:c,onNavigate:n}),j==="collection"&&t.jsx(xr,{progress:S,t:c,onNavigate:n}),j==="site"&&t.jsx(mu,{progress:L,t:c,totalWorks:(p==null?void 0:p.works)??0}),j==="feedback"&&l&&t.jsx(uo,{items:g,loading:w})]})})},Zt=({label:e,active:n,onClick:o})=>t.jsx("button",{onClick:o,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:i(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${i("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),xu=({recommended:e,loading:n,onNavigate:o,getIcon:r,t:s})=>{const l=Fe();if(n)return t.jsx(yt,{});if(e.length===0)return null;const c=new Map;for(const p of e){const a=p.group||s.home.recommendedBrowse;c.has(a)||c.set(a,[]),c.get(a).push(p)}return t.jsx(t.Fragment,{children:Array.from(c.entries()).map(([p,a])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:p}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return t.jsxs("a",{href:l(d.id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),o==null||o(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,cursor:"pointer",background:i("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},xr=({progress:e,t:n,onNavigate:o})=>{if(!e)return t.jsx(yt,{});const r=[...e.resources].sort((p,a)=>p.priority-a.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},c={in_progress:i("progress-active"),done:i("progress-done"),todo:i("progress-todo")};return t.jsx("div",{children:s.map(p=>{const a=r.filter(d=>d.status===p);return a.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:c[p]}}),l[p]," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>t.jsx(fu,{item:d,t:n,statusColor:c[p],onNavigate:o},d.id))})]},p)})})},fu=({item:e,t:n,statusColor:o,onNavigate:r})=>{const s=Fe(),l=e.total>0?Math.round(e.imported/e.total*100):0,c=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=e.edition?`${e.name}·${e.edition}`:e.name,a=e.collection_id||e.work_id;return a&&r?t.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:p}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:i("widget-border"),color:i("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:c})]}),t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?it(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:o,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:e.description})]})},mu=({progress:e,t:n,totalWorks:o})=>{if(!e)return t.jsx(yt,{});const r=[...e.resources].sort((a,d)=>a.priority-d.priority),s=r.filter(a=>a.imported>0),l=r.filter(a=>a.imported===0),c=s.reduce((a,d)=>Math.max(a,d.imported),0),p=o>0?Math.round(c/o*100):0;return t.jsxs("div",{children:[o>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${i("primary")} 6%, transparent)`,fontSize:"13px",color:i("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:c.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>t.jsx(fr,{item:a,t:n,totalWorks:o},a.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(a=>t.jsx(fr,{item:a,t:n,totalWorks:o},a.id))})]})]})},fr=({item:e,t:n,totalWorks:o})=>{const r=o>0?Math.round(e.imported/o*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:t.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&o>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:i("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:e.description})]})},mr="(max-width: 768px)";function gu(){const[e,n]=x.useState(()=>typeof window>"u"?!1:window.matchMedia(mr).matches);return x.useEffect(()=>{const o=window.matchMedia(mr),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),e}const hu=({transport:e,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var D;const l=ge(),{convert:c}=X(),p=gu(),[a,d]=x.useState(null),[u,m]=x.useState(null),[f,g]=x.useState(!1),[b,w]=x.useState("detail"),[y,j]=x.useState([]),[h,v]=x.useState(!1),[_,k]=x.useState(null),[$,S]=x.useState(!1),C=x.useCallback(async H=>{if(!e.getCollatedEditionIndex){k(null);return}S(!0);try{const z=await e.getCollatedEditionIndex(H);k(z)}catch{k(null)}finally{S(!1)}},[e]),L=x.useCallback(async H=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){j([]);return}v(!0);try{if(e.getCollectionCatalogs){const z=await e.getCollectionCatalogs(H);j(z||[])}else if(e.getCollectionCatalog){const z=await e.getCollectionCatalog(H);j(z?[{resource_id:"",data:z}]:[])}}catch{j([])}finally{v(!1)}},[e]),I=x.useCallback(async H=>{if(o){o(H);return}d(H),m(null),j([]),k(null),w("detail"),g(!0);try{const z=await e.getItem(H.id);z&&(m(z),z.type==="collection"?L(H.id):z.type==="work"&&z.has_collated&&C(H.id))}catch(z){console.error("加载详情失败:",z)}finally{g(!1)}},[e,o,L,C]),T=x.useCallback(async H=>{m(null),j([]),k(null),w("detail"),g(!0);try{const z=await e.getItem(H);z&&(m(z),d({id:H,title:z.title||H,type:z.type||"book"}),z.type==="collection"?L(H):z.type==="work"&&z.has_collated&&C(H))}catch(z){console.error("导航失败:",z)}finally{g(!1)}},[e,L,C]),U=(u==null?void 0:u.type)==="collection"&&(y.length>0||h)||(u==null?void 0:u.type)==="work"&&(_||$),M=p&&(f||u),F=x.useCallback(()=>{d(null),m(null),j([]),k(null),w("detail")},[]),O=t.jsx(t.Fragment,{children:f?t.jsx(yt,{}):u?t.jsxs(t.Fragment,{children:[(U||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${i("widget-border")}`,padding:p?"0 12px":"0 48px",background:i("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[U&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>w("detail"),style:bn(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&h&&y.length===0&&t.jsxs("button",{onClick:()=>{},style:bn(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&y.map(H=>t.jsx("button",{onClick:()=>w(`catalog:${H.resource_id}`),style:bn(b===`catalog:${H.resource_id}`),children:H.short_name?`${c(H.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},H.resource_id)),u.type==="work"&&(_||$)&&t.jsxs("button",{onClick:()=>w("collated"),style:bn(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(Wi,{data:u,transport:e,onNavigate:T}):b.startsWith("catalog:")?t.jsx(Fi,{data:(D=y.find(H=>`catalog:${H.resource_id}`===b))==null?void 0:D.data,onNavigate:T}):b==="collated"?t.jsx(po,{index:_||void 0,workId:u.id,transport:e,onNavigate:T}):null})]}):t.jsx(ki,{transport:e,onNavigate:T,recommendedIds:r})});return p?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:M?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${i("widget-border")}`,background:i("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:F,style:{padding:"4px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:O})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(pi,{transport:e,onEntryClick:I,hideModeIndicator:n}),!u&&t.jsx(ki,{transport:e,onNavigate:T,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${i("widget-border")}`,display:"flex",flexDirection:"column",background:i("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(pi,{transport:e,onEntryClick:I,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:i("bg"),display:"flex",flexDirection:"column"},children:O})]})};function bn(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function ht(e){return e.replace(/\.md$/,"")}function gr(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 hr={padding:24,color:i("desc-fg")},wi=({index:e,bookId:n,transport:o,activeChapter:r,onChapterChange:s,workKey:l,versions:c,onVersionChange:p,title:a,subtitle:d,resolveImages:u,renderImageOverlay:m,imagePanel:f,allowVertical:g,onReportError:b,revisedAt:w,className:y,style:j})=>{const[h,v]=x.useState(e??null),[_,k]=x.useState(!1),[$,S]=x.useState(null),C=r!==void 0?r:$,L=x.useCallback(Y=>{s?s(Y):S(Y)},[s]),[I,T]=x.useState(null),[U,M]=x.useState(!1);x.useEffect(()=>{e&&v(e)},[e]),x.useEffect(()=>{if(e)return;v(null),k(!1);const Y=l!==void 0?o.getWorkFullTextIndex?()=>o.getWorkFullTextIndex(n,l):null:o.getBookFullTextIndex?()=>o.getBookFullTextIndex(n):null;if(!n||!Y){k(!0);return}let ee=!1;return Promise.resolve().then(Y).then(Z=>{ee||(Z?v(Z):k(!0))}).catch(()=>{ee||k(!0)}),()=>{ee=!0}},[n,o,e,l]),x.useEffect(()=>{if(!h||h.chapters.length===0)return;const Y=ht(h.chapters[0].file);if(!C){L(Y);return}const ee=ht(C);h.chapters.some(le=>ht(le.file)===ee)||L(Y)},[h,C,L]);const F=x.useMemo(()=>{if(!h||!C)return null;const Y=ht(C);return h.chapters.find(ee=>ht(ee.file)===Y)??null},[h,C]);x.useEffect(()=>{if(!n||!F)return;const Y=l!==void 0?o.getWorkFullTextChapter?Z=>o.getWorkFullTextChapter(n,l,Z):null:o.getBookFullTextChapter?Z=>o.getBookFullTextChapter(n,Z):null;if(!Y)return;let ee=!1;return M(!0),T(null),Promise.resolve(F.file).then(Y).then(Z=>{ee||T(Z)}).catch(()=>{ee||T(null)}).finally(()=>{ee||M(!1)}),()=>{ee=!0}},[n,F,o,l]);const O=no(u,F?ht(F.file):null),[D,H]=Fn(),{convert:z}=X(),pe=!!(c&&c.length>1&&p),A=x.useMemo(()=>pe?nl(c).map((Y,ee)=>({...Y,label:gr(c[ee])})):void 0,[pe,c]),oe=pe?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:Y=>p(Y.target.value),children:c.map(Y=>t.jsx("option",{value:Y.key,children:gr(Y)},Y.key))})]}):null;if(!h)return t.jsxs("div",{style:hr,children:[oe&&t.jsx("div",{style:{marginBottom:12},children:oe}),_?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:hr,children:[oe&&t.jsx("div",{style:{marginBottom:12},children:oe}),"全文目录为空"]});const E=h.chapters.map(Y=>({key:ht(Y.file),label:z(Y.title)})),W=Ji(h)||ln(h),ce=I?I.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs(On,{title:a??z(h.version_label),subtitle:d??"全文",toc:E,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:C?ht(C):null,onSelect:L,images:O.images,imagesLoading:O.loading,renderImageOverlay:m,imagePanel:f,prefs:D,onPrefsChange:H,versions:A,currentVersionKey:A?l??null:void 0,onVersionChange:A?p:void 0,versionSource:!1,paragraphToggle:Ct(ce),allowVertical:g,revisedAt:w,onReportError:b?Y=>b({...Y,bookTitle:a===void 0?z(h.version_label):typeof a=="string"?a:void 0,entryId:n}):void 0,className:y,style:j,children:[F&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:z(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:z(h.source.name)}),h.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),h.source.license]})]})]}),U&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!U&&ce!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Dn,{text:ce,mode:D.readingMode,tables:W,gujiMarkdown:ln(h),properNames:D.properNames})}),!U&&!I&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},ni=e=>e?e.catch(()=>null):Promise.resolve(null);function vl(e){const n=new Map;function o(r){var l;let s=n.get(r);return s||(s=ni((l=e.getTextManifest)==null?void 0:l.call(e,r)).then(c=>{const p=c&&Array.isArray(c.versions)&&c.versions.length>0?c:null;return p||n.delete(r),p}),n.set(r,s)),s}return{getManifest(r){return je.isSafeSegment(r)?o(r):Promise.resolve(null)},async getIndex(r,s){return!je.isSafeSegment(r)||!je.isSafeSegment(s)||!e.getTextIndex?null:ni(e.getTextIndex(r,s))},async getChapter(r,s,l,c){return!je.isSafeSegment(r)||!je.isSafeSegment(s)||!je.isSafeSegment(l)||!e.getChapter?null:ni(e.getChapter(r,s,l,c))}}}const yn={padding:24,color:i("desc-fg"),fontSize:14},br=/^https?:\/\//i;function bu(e){if(!e||typeof e!="object")return null;const n=l=>typeof l=="string"&&l.trim()?l.trim():void 0,o=n(e.url),r=n(e.license_url),s={name:n(e.name),url:o&&br.test(o)?o:void 0,license:n(e.license),license_url:r&&br.test(r)?r:void 0,note:n(e.note)};return s.name||s.license||s.note?s:null}function yu(e,n){return{work_id:n.work_id??e,title:n.title,type:n.type,juan_files:n.chapters.map(o=>o.file),juan_metadata:n.juan_metadata,juan_groups:n.juan_groups,references:n.references,target_source:n.target_source,target_source_id:n.target_source_id,text_source:n.text_source,text_quality:n.text_quality}}function ju(e,n){return(n==null?void 0:n.type)==="kaozhen"?"章":n!=null&&n.juan_metadata&&Object.values(n.juan_metadata).some(o=>o.vol_label)?"冊":(e==null?void 0:e.kind)==="collated"?"卷":"章"}function kl(e,n,o,r=!1){const s=o(`${n}${e.n}`);if(!e.title)return s;const l=o(e.title);return r&&!/^[卷冊册章篇回第]/.test(e.title)?`${s} ${l}`:l}function vu(e,n,o,r,s){var d;const l=new Map(e.chapters.map(u=>[u.file,u])),c=u=>u==="loading"?"…":typeof u=="number"&&u>0?u:void 0,p=(u,m)=>{const f=l.get(u);return{key:u,label:m??(f?kl(f,o,r,s):u),hint:c(n[u]),disabled:n[u]===0}},a=(d=e.juan_groups)==null?void 0:d.filter(u=>{var m;return u.files.some(f=>l.has(f))||((m=u.children)==null?void 0:m.length)});if(a&&a.length>0){const u=(m,f)=>{var b;if(m.files.length===1&&!((b=m.children)!=null&&b.length))return p(m.files[0],r(m.label));const g=gl(m,n);return{key:`group:${f}`,label:r(m.label),hint:g==="loading"?"…":typeof g=="number"&&g>0?`${g}`:so(m),defaultExpanded:typeof g=="number"&&g>0,children:[...m.files.filter(w=>l.has(w)).map(w=>p(w)),...(m.children??[]).map((w,y)=>u(w,`${f}.${y}`))]}};return a.map((m,f)=>u(m,`${f}`))}return e.chapters.map(u=>p(u.file))}const ku=({id:e,transport:n,versionKey:o,chapter:r,onLocationChange:s,onNavigate:l,title:c,subtitle:p,resolveImages:a,renderImageOverlay:d,imagePanel:u,allowVertical:m,onReportError:f,revisedAt:g,className:b,style:w})=>{var jt,Ie,Je;const{convert:y}=X(),j=x.useMemo(()=>vl(n),[n]),[h,v]=Fn(),_=Fe(),k=x.useRef(s);k.current=s;const[$,S]=x.useState(null),[C,L]=x.useState("loading");x.useEffect(()=>{let V=!1;return S(null),L("loading"),j.getManifest(e).then(ze=>{V||(ze?(S(ze),L("ready")):L("missing"))}).catch(()=>{V||L("missing")}),()=>{V=!0}},[j,e]);const I=o!==void 0,T=r!==void 0,[U,M]=x.useState(null),[F,O]=x.useState(null);x.useEffect(()=>{M(null),O(null)},[e]);const D=je.pickTextVersion($,I?o:U),H=((jt=$==null?void 0:$.versions.find(V=>V.key==="default"))==null?void 0:jt.key)??((Ie=$==null?void 0:$.versions[0])==null?void 0:Ie.key)??"default",z=(D==null?void 0:D.key)??null,pe=T?r:F,A=x.useCallback((V,ze,Ue)=>{var dt;(dt=k.current)==null||dt.call(k,{key:V,chapter:ze,isDefault:V===H},Ue)},[H]);x.useEffect(()=>{!$||!I||o==null||$.versions.some(V=>V.key===o)||A(H,null,"auto")},[$,I,o,H,A]);const oe=x.useRef(new Map);x.useEffect(()=>{oe.current.clear()},[j,e]);const E=x.useCallback(async V=>{const ze=`${e}
|
|
1025
|
+
${V}`;if(oe.current.has(ze))return oe.current.get(ze)??null;const Ue=await j.getIndex(e,V).catch(()=>null);return Ue&&oe.current.set(ze,Ue),Ue},[j,e]),[W,ce]=x.useState(null),[Y,ee]=x.useState("loading");x.useEffect(()=>{if(!z)return;let V=!1;return ce(null),ee("loading"),E(z).then(ze=>{V||(ze&&ze.chapters.length>0?(ce(ze),ee("ready")):ee("failed"))}),()=>{V=!0}},[z,E]),x.useEffect(()=>{if(!W||!z||pe!=null&&W.chapters.some(Ue=>Ue.file===pe))return;const ze=W.chapters[0].file;T||O(ze),A(z,ze,"auto")},[W,z,pe,T,A]);const Z=W?pe!=null&&W.chapters.some(V=>V.file===pe)?pe:W.chapters[0].file:pe,le=x.useMemo(()=>W&&Z?W.chapters.find(V=>V.file===Z)??null:null,[W,Z]),be=x.useRef(0),Le=x.useCallback(async V=>{if(!$||V===z||!$.versions.some(mn=>mn.key===V))return;const ze=++be.current,Ue=await E(V);if(ze!==be.current)return;const dt=le??(Z?{file:Z}:null),Vt=je.matchChapterAcrossVersions(dt,Ue);I||M(V),T||O(Vt),A(V,Vt,"version")},[$,z,E,le,Z,I,T,A]),Be=x.useCallback(V=>{z&&(T||O(V),A(z,V,"chapter"))},[z,T,A]),[he,Ne]=x.useState(null),[Te,Re]=x.useState(!1),P=x.useRef(0);x.useEffect(()=>{if(!z||!le)return;const V=++P.current;Re(!0),Ne(null),j.getChapter(e,z,le.file,{json:!!le.has_json}).then(ze=>{V===P.current&&Ne(ze)}).catch(()=>{V===P.current&&Ne(null)}).finally(()=>{V===P.current&&Re(!1)})},[j,e,z,le]);const me=(D==null?void 0:D.kind)==="collated",[te,ke]=x.useState("");x.useEffect(()=>{ke("")},[e,z]);const we=x.useMemo(()=>z&&me?async V=>{const ze=await j.getChapter(e,z,V,{json:!0});return{juan:(ze==null?void 0:ze.json)??null,rawText:(ze==null?void 0:ze.md)??null}}:null,[j,e,z,me]),K=(W==null?void 0:W.type)==="kaozhen",N=x.useMemo(()=>(W==null?void 0:W.chapters.map(V=>V.file))??[],[W]),{matchStates:q}=yl({resetKey:`${e}
|
|
1026
|
+
${z??""}`,load:we,files:N,activeFile:Z??null,activeJuan:(he==null?void 0:he.json)??null,activeRawText:(he==null?void 0:he.md)??null,query:te,isKaozhen:K}),xe=x.useRef(new Map);x.useEffect(()=>{xe.current.clear()},[e]);const ye=no(a,Z??null),{entryTitle:B,authors:re}=$u(e,n,c===void 0),[Q,fe]=x.useState("text");if(x.useEffect(()=>{fe("text")},[Z,z]),C==="loading")return t.jsx("div",{className:b,style:{...w,...yn},children:"加载中…"});if(C==="missing"||!$||!D)return t.jsx("div",{className:b,style:{...w,...yn},children:"暂无文本"});if(Y==="failed")return t.jsx("div",{className:b,style:{...w,...yn},children:"无法加载目录"});if(!W)return t.jsx("div",{className:b,style:{...w,...yn},children:"加载目录…"});const G=ju(D,W),ve=vu(W,q,G,y,me),$e=$.versions.map(V=>({key:V.key,label:je.textVersionLabel(V),optionLabel:y(je.textVersionLabel(V)),sourceName:V.source_name?y(V.source_name):void 0,license:V.license??void 0,sourceUrl:V.source_url??void 0,primary:V.key===H})),J=bu((Je=W.source)==null?void 0:Je.upstream),_e=c??(W.title?y(W.title):B?y(B):void 0),R=_e?t.jsx("a",{href:_(e),title:"查看条目",onClick:l?V=>{V.metaKey||V.ctrlKey||(V.preventDefault(),l(e))}:void 0,children:_e}):void 0,se=re.length>0?y(re.slice(0,2).map(V=>`${V.dynasty?`〔${V.dynasty}〕`:""}${V.name}${V.role?` ${V.role}`:" 撰"}`).join("、")):void 0,ue=le?kl(le,G,y,me):void 0,ae=me&&!!(he!=null&&he.json),ie=(he==null?void 0:he.json)??null,Se=(he==null?void 0:he.md)??null,Ee=ae&&!K&&co(ie.sections),We=Ee&&!(Se&&h.readingMode==="paragraph"&&Ct(Se)),qe=ae&&Ee?t.jsx(jl,{juan:ie,view:Q,onView:fe,textHasEntries:We}):void 0,Tt=Ji(W)||ln(W),Qe=Se?Se.replace(/^##\s+[^\n]+\n+/,""):null,It=p??(D.source_name?y(D.source_name):y(je.textVersionLabel(D)));return t.jsxs(On,{className:b,style:w,title:R,subtitle:It,byline:se,current:ue,pagerUnit:G,rail:qe,revisedAt:g,onReportError:f?V=>f({...V,bookTitle:typeof _e=="string"?_e:void 0,entryId:e}):void 0,workLinkToggle:ae&&!K&&!!l&&!!(ie!=null&&ie.sections.some(V=>V.work_id)),toc:ve,tocCaption:`目录 · ${W.chapters.length} ${y(G)}`,tocHeader:me&&W.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:K?"搜索全部章节…":`搜索全部${G}…`,"aria-label":K?"搜索全部章节":`搜索全部${G}`,value:te,onChange:V=>ke(V.target.value)}):void 0,activeKey:Z??null,onSelect:Be,images:ye.images,imagesLoading:ye.loading,renderImageOverlay:d,imagePanel:u,prefs:h,onPrefsChange:v,versions:$e.length>1?$e:void 0,currentVersionKey:$e.length>1?D.key:void 0,onVersionChange:Le,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:Ct(Se),allowVertical:m,children:[Te&&t.jsx(yt,{}),!Te&&ae&&ie&&t.jsx(hl,{juan:ie,rawText:Se,positionLabel:wu(le,W,G,y),groupLabel:Su(W,Z??null),index:yu(e,W),searchQuery:te,onNavigate:l,transport:n,workLabelCache:xe,prefs:h,view:Q,onViewChange:fe},`${z}/${Z}`),!Te&&!ae&&Qe!=null&&le&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:le.title?y(le.title):ue}),(D.source_name||D.license)&&t.jsxs("p",{className:"bim-rd-meta",children:[D.source_name&&t.jsxs(t.Fragment,{children:["来源 ",D.source_url?t.jsx("a",{className:"bim-rd-link",href:D.source_url,target:"_blank",rel:"noreferrer",children:y(D.source_name)}):y(D.source_name)]}),D.source_name&&D.license&&t.jsx("span",{className:"bim-rd-dot"}),D.license]}),J&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:["上游 ",J.url?t.jsx("a",{className:"bim-rd-link",href:J.url,target:"_blank",rel:"noreferrer",children:y(J.name??J.url)}):y(J.name??""),J.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),J.license_url?t.jsx("a",{className:"bim-rd-link",href:J.license_url,target:"_blank",rel:"noreferrer",children:J.license}):J.license]}),J.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),y(J.note)]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Dn,{text:Qe,mode:h.readingMode,tables:Tt,gujiMarkdown:ln(W),properNames:h.properNames})})]}),!Te&&!ae&&Qe==null&&le&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"}),W.references&&W.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:y("參考文獻")}),t.jsx("ol",{children:W.references.map((V,ze)=>t.jsxs("li",{children:[V.url?t.jsx("a",{className:"bim-rd-link",href:V.url,target:"_blank",rel:"noopener noreferrer",children:V.title}):t.jsx("span",{children:V.title}),V.author&&t.jsxs("span",{children:[",",V.author]}),V.note&&t.jsxs("span",{children:["。",V.note]})]},ze))})]})]})};function wu(e,n,o,r){var l,c;if(!e)return;const s=(c=(l=n.juan_metadata)==null?void 0:l[e.file])==null?void 0:c.vol_label;return r(s?`${s}冊`:`${o}${e.n}`)}function Su(e,n){if(!n)return;const o=r=>{var s;for(const l of r??[]){const c=o(l.children);if(c)return c;if((s=l.files)!=null&&s.includes(n))return l.label}};return o(e.juan_groups)}function $u(e,n,o){const[r,s]=x.useState({entryTitle:void 0,authors:[]});return x.useEffect(()=>{if(s({entryTitle:void 0,authors:[]}),typeof n.getItem!="function")return;let l=!1;return Promise.resolve(n.getItem(e)).then(c=>{if(l||!c)return;const p=(c.authors??[]).filter(a=>a&&a.name);s({entryTitle:o&&typeof c.title=="string"?c.title:void 0,authors:p})}).catch(()=>{}),()=>{l=!0}},[e,n,o]),r}const _u=({data:e,onNavigate:n,className:o,style:r})=>{var u;const s=ge(),{convert:l}=X(),[c,p]=x.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[a,d]=x.useState(null);return t.jsxs("div",{className:o,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:l(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[s.catalog.totalVolumes," ",t.jsx("strong",{children:e.total_volumes})," ",s.unit.juan]}),e.stats.zhulu!=null&&t.jsxs("span",{children:["著錄 ",t.jsx("strong",{children:e.stats.zhulu})," ",s.unit.bu]}),e.stats.cunmu!=null&&t.jsxs("span",{children:["存目 ",t.jsx("strong",{children:e.stats.cunmu})," ",s.unit.bu]}),e.stats.categories!=null&&t.jsxs("span",{children:[e.stats.categories," 類"]})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(m=>t.jsx(Cu,{division:m,expanded:c===m.name,onToggle:()=>p(c===m.name?null:m.name),expandedCat:a,onCatToggle:f=>d(a===f?null:f),onNavigate:n},m.name))})]})},Cu=({division:e,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:c}=X(),p=e.categories.reduce((a,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return a+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${i("primary")} 6%, transparent)`:i("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:i("fg"),textAlign:"left"},children:[t.jsx("span",{children:c(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg")},children:[e.categories.length," 類 · ",p," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(a=>{const d=`${e.name}/${a.name}`;return t.jsx(zu,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:l},a.name)})})]})},zu=({category:e,expanded:n,onToggle:o,onNavigate:r})=>{var a,d,u,m;const{convert:s}=X(),l=((a=e.books)==null?void 0:a.zhulu)||[],c=((d=e.books)==null?void 0:d.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((m=e.stats)==null?void 0:m.cunmu)||c.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?i("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:i("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||c.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(yr,{label:"著錄",books:l,onNavigate:r}),c.length>0&&t.jsx(yr,{label:"存目",books:c,onNavigate:r})]})]})},yr=({label:e,books:n,onNavigate:o})=>{const{convert:r}=X(),s=Fe(),[l,c]=x.useState(n.length<=20),p=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((a,d)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:i("fg")},children:a.work_id&&o?t.jsx("a",{href:s(a.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),o(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},children:r(a.title)}):r(a.title)}),a.volumes&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:r(a.volumes)}),a.author&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:r(a.author).slice(0,20)})]},d))}),!l&&t.jsxs("button",{onClick:()=>c(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},nt=({title:e,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const l=ge();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:i("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&t.jsx("button",{onClick:o,style:Iu,children:"AI"}),n&&t.jsx("button",{onClick:n,style:Tu,children:l.action.save})]})]}),s]})},Tu={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Iu={padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Ze=({label:e,value:n,onChange:o,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:l=>o(l.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),$t=({value:e,onChange:n,placeholder:o})=>{const r=x.useRef(null);return x.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Cn=({children:e,color:n,style:o})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||i("primary-soft"),color:i(n?"on-color-fg":"fg"),...o},children:e});function Eu(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const vn=({value:e,onChange:n,label:o})=>{const[r,s]=x.useState(!1),l=x.useRef(null),c=Eu(e||"");return x.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&c?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:jr,children:o}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${i("input-border")}`,borderRadius:"2px",background:i("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:i("fg")},children:c.name}),t.jsx(Cn,{children:c.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:jr,children:o}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},jr={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500};function Ru(e){switch(e){case"url":return i("source-url");case"bookID":return i("source-bookid");default:return i("desc-fg")}}function Nu(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const wl=({items:e,onChange:n,onOpenEntityPicker:o})=>{const r=ge(),[s,l]=x.useState(null),c=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},p=m=>{n(e.filter((f,g)=>g!==m)),s===m&&l(null)},a=(m,f,g)=>{const b=[...e];b[m]={...b[m],[f]:g},n(b)},d=(m,f)=>{const g=[...e];g[m]={...g[m],type:f,id:"",name:""},n(g),f==="bookID"&&o&&o(b=>{const w=[...e];w[m]={...w[m],id:b.id,name:b.title,type:"bookID"},n(w)})},u=m=>{o&&o(f=>{const g=[...e];g[m]={...g[m],id:f.id,name:f.title,type:"bookID"},n(g)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((m,f)=>t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===f?null:f),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===f?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:i("fg")},children:m.name||`${r.editor.sourcePlaceholder} ${f+1}`}),m.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Ru(m.type),color:i("on-color-fg"),borderRadius:"3px",fontWeight:500},children:Nu(m.type)}),t.jsx("button",{onClick:g=>{g.stopPropagation(),p(f)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===f&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!m.type&&t.jsxs("div",{children:[t.jsx("label",{style:pt,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>d(f,"bookID"),style:{...vr,borderColor:i("source-bookid"),color:i("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>d(f,"url"),style:{...vr,borderColor:i("source-url"),color:i("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),m.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:pt,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const g=[...e];g[f]={...g[f],type:"",id:"",name:""},n(g)},style:kr,children:r.action.changeType})]}),m.id&&m.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:i("bg"),border:`1px solid ${i("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:i("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:m.name}),t.jsx("code",{style:{fontSize:"11px",background:i("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:m.id})]}),t.jsx("button",{onClick:()=>u(f),style:{background:"transparent",border:`1px solid ${i("widget-border")}`,color:i("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(f),style:{width:"100%",padding:"14px",border:`2px dashed ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),m.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:pt,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const g=[...e];g[f]={...g[f],type:"",id:"",name:""},n(g)},style:kr,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:m.name,onChange:g=>a(f,"name",g.target.value),placeholder:r.editor.sourceNamePlaceholder,style:Et})]}),t.jsxs("div",{children:[t.jsx("label",{style:pt,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:m.id,onChange:g=>a(f,"id",g.target.value),placeholder:"https://...",style:Et})]})]}),m.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${i("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...pt,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:pt,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:m.details,onChange:g=>a(f,"details",g.target.value),placeholder:r.editor.detailsPlaceholder,style:Et})]}),t.jsxs("div",{children:[t.jsx("label",{style:pt,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:m.position,onChange:g=>a(f,"position",g.target.value),placeholder:"如: 卷三, p.52",style:Et})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:pt,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:m.version,onChange:g=>a(f,"version",g.target.value),placeholder:"如: v1.0, 2024-01",style:Et})]}),t.jsxs("div",{children:[t.jsx("label",{style:pt,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:m.processor_version,onChange:g=>a(f,"processor_version",g.target.value),placeholder:"如: v0.1",style:Et})]})]})]})]})})]},f)),t.jsxs("button",{onClick:c,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},pt={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},Et={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},vr={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:i("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},kr={background:"transparent",border:"none",color:i("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Sl(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(o=>({id:o.id||"",name:o.name||"",type:o.type||"",details:o.details||"",position:o.position||"",version:o.version||"",processor_version:o.processor_version||""}))}catch{}return[]}function $l(e){return!e||e.length===0?"":JSON.stringify(e)}const _l=({entityType:e,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:c,childWorks:p,childCollections:a,containedBooks:d,siblingBooks:u,onLinkEntity:m,onUnlinkEntity:f,onViewEntity:g,onCreateAndLink:b,onSaveRelations:w})=>{const y=ge();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:y.section.relations})]}),w&&t.jsx("button",{onClick:w,style:Lu,children:y.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Xt,{direction:"up",title:y.relation.belongsToWork,entity:l,onView:g,onUnlink:()=>f("workId"),onLink:()=>m("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(Xt,{direction:"up",title:y.relation.containedInCollection,entity:c,onView:g,onUnlink:()=>f("collectionId"),onLink:()=>m("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),l&&u&&u.length>0&&t.jsx(Rt,{direction:"horizontal",title:`${y.relation.siblingVersions} (${u.length})`,entities:u,onView:g,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:y.relation.addVersionForWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Xt,{direction:"up",title:y.relation.parentWork,entity:r,onView:g,onUnlink:()=>f("parentWorkId"),onLink:()=>m("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),p&&p.length>0&&t.jsx(Rt,{direction:"down",title:`${y.relation.childWorks} (${p.length})`,entities:p,onView:g,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:y.action.addSubWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),a&&a.length>0&&t.jsx(Rt,{direction:"down",title:`${y.relation.collectionImpl} (${a.length})`,entities:a,onView:g,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:y.action.addCollectionImpl,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(Rt,{direction:"down",title:`${y.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:g,onAdd:()=>b("childBook","book",{workId:n}),addLabel:y.action.addVersion,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Xt,{direction:"up",title:y.relation.correspondingWork,entity:l,onView:g,onUnlink:()=>f("workId"),onLink:()=>m("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(Xt,{direction:"up",title:y.relation.parentCollection,entity:s,onView:g,onUnlink:()=>f("parentCollectionId"),onLink:()=>m("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(Rt,{direction:"down",title:`${y.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:g,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:y.action.addSubCollection,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(Rt,{direction:"down",title:`${y.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:g,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:y.action.addBook,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]})]})]})},Xt=({direction:e,title:n,entity:o,onView:r,onUnlink:s,onLink:l,onCreate:c,linkLabel:p,createLabel:a,notLinkedLabel:d,viewLabel:u,unlinkLabel:m})=>{const f=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),g=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:f,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:g}),t.jsx("span",{children:n})]}),o?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:i("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Cl(o.type)}),t.jsx("span",{style:{fontWeight:500},children:o.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(wr,{onClick:()=>r(o),title:u,children:"👁️"}),t.jsx(wr,{onClick:s,title:m,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(Si,{onClick:l,children:p}),t.jsx(Si,{onClick:c,primary:!0,children:a})]})]})},Rt=({direction:e,title:n,entities:o,onView:r,onAdd:s,addLabel:l,noneLabel:c,expandMoreLabel:p})=>{const[a,d]=x.useState(!1),u=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",f=a?o:o.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),o.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[f.map(g=>t.jsxs("div",{onClick:()=>r(g),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:i("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:Cl(g.type)}),t.jsx("span",{children:g.title})]},g.id)),o.length>5&&!a&&t.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:i("link-fg"),cursor:"pointer"},children:[p," (",o.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:c}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(Si,{onClick:s,primary:!0,children:["+ ",l]})})]})},wr=({onClick:e,title:n,danger:o,children:r})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:o?i("danger"):"inherit",opacity:.7},children:r}),Si=({onClick:e,primary:n,children:o})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${i("widget-border")}`,borderRadius:"4px",background:n?i("primary"):"transparent",color:n?i("primary-fg"):"inherit",cursor:"pointer"},children:o});function Cl(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const Lu={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},zl=({isOpen:e,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:l,searchResults:c,onSearch:p,isLoading:a,excludeId:d})=>{const[u,m]=x.useState(""),f=d?c.filter(y=>y.id!==d):c;x.useEffect(()=>{e&&(m(""),p(""))},[e]);const g=y=>{m(y),p(y)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",w=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:Au,children:t.jsxs("div",{style:Bu,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),t.jsx("button",{onClick:s,style:Mu,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:y=>g(y.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:Wu})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?t.jsx("div",{style:ii,children:"搜索中..."}):f.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:f.map(y=>t.jsxs("div",{onClick:()=>r(y),style:Fu,children:[t.jsx("span",{style:{fontSize:"16px"},children:w}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[y.title,y.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:y.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[y.id,y.author&&` · ${y.author}`,y.dynasty&&` · ${y.dynasty}`]})]})]},y.id))}):u?t.jsxs("div",{style:ii,children:["未找到匹配的",b]}):t.jsxs("div",{style:ii,children:["输入关键词搜索",b]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:l,style:Ou,children:["创建新",b,"并关联"]})]})]})})},Au={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Bu={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},Mu={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Wu={width:"100%",padding:"10px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},Fu={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:i("primary-soft")},ii={padding:"20px",textAlign:"center",color:i("desc-fg")},Ou={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Sr={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Pu={work:"📜",book:"📖",collection:"📚",entity:"👤"},Tl=({isOpen:e,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:l})=>{const[c,p]=x.useState(""),a=x.useRef(null);x.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var f,g;(f=a.current)==null||f.focus(),(g=a.current)==null||g.select()},100))},[e,r==null?void 0:r.title]);const d=f=>{f.key==="Enter"&&c.trim()?u():f.key==="Escape"&&l()},u=()=>{c.trim()&&s(c.trim(),{...r,title:c.trim()})};if(!e)return null;const m=()=>{switch(o){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Sr[n]}`}};return t.jsx("div",{style:Du,onClick:f=>{f.target===f.currentTarget&&l()},children:t.jsxs("div",{style:Hu,onClick:f=>f.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Pu[n]}),t.jsx("span",{children:m()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:i("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:i("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:a,type:"text",value:c,onChange:f=>p(f.target.value),onKeyDown:d,placeholder:`请输入${Sr[n]}名称...`,style:Gu})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),background:i("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&t.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:l,style:Vu,children:"取消"}),t.jsx("button",{onClick:u,disabled:!c.trim(),style:{...Uu,opacity:c.trim()?1:.6,cursor:c.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Du={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Hu={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:i("shadow-dialog")},Gu={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box"},Vu={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Uu={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg")};function Yu(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Il(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ku(e){switch(e){case"work":return i("editor-type-work");case"collection":return i("editor-type-collection");case"book":return i("editor-type-book");default:return i("desc-fg")}}const El=({isOpen:e,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:c,onSelect:p,onCancel:a,onCreate:d,onSearch:u})=>{const[m,f]=x.useState(""),[g,b]=x.useState([]),[w,y]=x.useState(!1),[j,h]=x.useState("recent");x.useEffect(()=>{e&&(f(""),b([]),h(r.length>0?"recent":"search"))},[e,r.length]),x.useEffect(()=>{if(!m.trim()){b([]);return}const C=setTimeout(async()=>{y(!0);try{b(await u(m,o))}catch{b([])}finally{y(!1)}},300);return()=>clearTimeout(C)},[m,o,u]);const v=x.useCallback(C=>{f(C.target.value),C.target.value.trim()&&h("search")},[]),_=x.useCallback(C=>s?C.filter(L=>L.id!==s):C,[s]);if(!e)return null;const k=n||(o==="all"?"选择实体":`选择${Il(o)}`),$=_(r),S=_(g);return t.jsx("div",{style:Ju,children:t.jsxs("div",{style:Zu,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:k}),t.jsx("button",{onClick:a,style:Xu,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:m,onChange:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Qu}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),w&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),$.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsxs($r,{active:j==="recent",onClick:()=>h("recent"),children:["最近使用 (",$.length,")"]}),t.jsxs($r,{active:j==="search",onClick:()=>h("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&$.length>0?t.jsx(_r,{entities:$,onSelect:p}):m.trim()?w?t.jsx(oi,{message:"搜索中..."}):S.length>0?t.jsx(_r,{entities:S,onSelect:p}):t.jsx(oi,{message:"未找到匹配的结果"}):t.jsx(oi,{message:"输入关键词开始搜索"})}),l&&d&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:d,style:ex,children:c||"创建新实体"})]})]})})},$r=({active:e,onClick:n,children:o})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:o}),_r=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(o=>t.jsx(qu,{entity:o,onClick:()=>n(o)},o.id))}),qu=({entity:e,onClick:n})=>{const[o,r]=x.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Yu(e.type)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:e.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[t.jsx("code",{style:{fontSize:"10px",background:i("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&t.jsx("span",{children:e.author}),e.dynasty&&t.jsx("span",{children:e.dynasty})]})]}),t.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Ku(e.type),color:i("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Il(e.type)})]})},oi=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:e}),Ju={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Zu={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},Xu={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Qu={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},ex={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},tx={work:i("editor-type-work"),collection:i("editor-type-collection"),book:i("editor-type-book"),entity:i("editor-type-entity")},nx={work:"📜",collection:"📚",book:"📖",entity:"👤"},Rl=({data:e,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:l,onDelete:c,onAskAI:p,renderSectionActions:a,onDownloadResource:d,downloadStatuses:u,relations:m,onRelationsChange:f})=>{var we;const g=ge(),[b,w]=x.useState(!1),[y,j]=x.useState("work"),[h,v]=x.useState(""),[_,k]=x.useState(""),[$,S]=x.useState([]),[C,L]=x.useState(!1),[I,T]=x.useState(!1),[U,M]=x.useState("work"),[F,O]=x.useState(""),[D,H]=x.useState(),[z,pe]=x.useState(!1),[A,oe]=x.useState(null),[E,W]=x.useState([]);x.useRef(null);const ce=e.type,Y=ce==="work",ee=ce==="collection",Z=ce==="book",le=x.useCallback((K,N)=>{n({...e,[K]:N})},[e,n]),be=x.useCallback((K,N)=>{v(K),j(N),k(g.editor.selectToLink+g.indexType[N]),S([]),w(!0)},[g]),Le=x.useCallback(K=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,K)},[r,e.id]),Be=x.useCallback(K=>{s==null||s(K.id,K.type)},[s]),he=x.useCallback((K,N,q)=>{const xe={...q,author:(q==null?void 0:q.author)||e.author,dynasty:q==null?void 0:q.dynasty};M(N),O(K),H(xe),T(!0)},[e.author]),Ne=x.useCallback((K,N)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,F,{type:U,title:K,inheritData:N}),T(!1)},[r,e.id,F,U]),Te=x.useCallback(K=>{if(!K.trim()){S([]);return}L(!0),r!=null&&r.searchEntities&&r.searchEntities(K,y).then(N=>{S(N),L(!1)}).catch(()=>{S([]),L(!1)})},[r,y]),Re=x.useCallback(K=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,h,K.id),w(!1)},[r,e.id,h]),P=x.useCallback(()=>{o()},[o]),me=x.useCallback(K=>{oe(()=>K),pe(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(W).catch(()=>{})},[r]),te=x.useCallback((K,N)=>r!=null&&r.searchEntities?r.searchEntities(K,N==="all"?void 0:N):Promise.resolve([]),[r]),ke=x.useCallback(K=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(K),W(N=>[K,...N.filter(q=>q.id!==K.id)].slice(0,10)),A==null||A(K),pe(!1),oe(null)},[r,A]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${i("widget-border")}`,paddingBottom:"16px"},children:t.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:nx[ce]}),t.jsx("span",{children:e.title||g.editor.untitled}),t.jsx(Cn,{children:e.id}),t.jsx(Cn,{color:tx[ce],children:g.indexType[ce]})]})}),t.jsx(nt,{title:g.section.basicInfo,onSave:o,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(vn,{label:Y?g.editor.workTitle:ee?g.editor.collectionTitle:g.editor.bookTitle,value:e.title,onChange:K=>le("title",K)}),Z&&t.jsx(vn,{label:g.editor.belongsToWork,value:e.workName||"",onChange:K=>le("workName",K)}),t.jsx(Ze,{label:g.editor.authorLabel,value:e.author||"",onChange:K=>le("author",K)}),t.jsx(Ze,{label:g.editor.publicationYearLabel,value:e.publicationYear||"",onChange:K=>le("publicationYear",K)}),(Z||ee)&&t.jsx(vn,{label:g.editor.containedIn,value:e.collection||"",onChange:K=>le("collection",K)}),(Z||ee)&&t.jsx(Ze,{label:g.editor.holderLabel,value:e.holder||"",onChange:K=>le("holder",K)}),(Z||ee)&&t.jsx(Ze,{label:Z?g.editor.pageLabel:g.editor.volumeLabel,value:e.pages||"",onChange:K=>le("pages",K)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(Ze,{label:g.editor.firstImageLabel,value:e.firstImage||"",onChange:K=>le("firstImage",K)})})]})}),t.jsx(nt,{title:g.section.description,onSave:o,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx($t,{value:e.description||"",onChange:K=>le("description",K),placeholder:g.editor.descriptionPlaceholder})}),(((we=e.additional_works)==null?void 0:we.length)||0)>0&&t.jsx(nt,{title:g.section.additionalWorks,onSave:o,children:t.jsx(ix,{items:e.additional_works||[],onChange:K=>le("additional_works",K)})}),t.jsx(nt,{title:g.section.indexedBy,onSave:o,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(ox,{items:e.indexed_by||[],onChange:K=>le("indexed_by",K)})}),t.jsx(nt,{title:g.section.emendatedBy,onSave:o,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(rx,{items:e.emendated_by||[],onChange:K=>le("emendated_by",K)})}),t.jsx(nt,{title:g.section.textResources,onSave:o,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(di,{items:e.resources||[],onChange:K=>le("resources",K),onDownload:d,downloadStatuses:u,filterType:"text"})}),t.jsx(nt,{title:g.section.imageResources,onSave:o,children:t.jsx(di,{items:e.resources||[],onChange:K=>le("resources",K),onDownload:d,downloadStatuses:u,filterType:"image"})}),t.jsx(nt,{title:g.section.sources,onSave:o,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(wl,{items:Sl(e.sources||""),onChange:K=>le("sources",$l(K)),onOpenEntityPicker:me})}),(Z||ee)&&t.jsx(nt,{title:g.section.provenance,onSave:o,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx($t,{value:e.provenance||"",onChange:K=>le("provenance",K),placeholder:g.editor.provenancePlaceholder})}),Z&&t.jsx(nt,{title:g.section.otherEditions,onSave:o,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx($t,{value:e.otherEditions||"",onChange:K=>le("otherEditions",K),placeholder:g.editor.otherEditionsPlaceholder})}),t.jsx(_l,{entityType:ce,entityId:e.id,entityTitle:e.title,parentWork:m==null?void 0:m.parentWork,parentCollection:m==null?void 0:m.parentCollection,belongsToWork:m==null?void 0:m.belongsToWork,belongsToCollection:m==null?void 0:m.belongsToCollection,childWorks:m==null?void 0:m.childWorks,childCollections:m==null?void 0:m.childCollections,containedBooks:m==null?void 0:m.containedBooks,siblingBooks:m==null?void 0:m.siblingBooks,onLinkEntity:be,onUnlinkEntity:Le,onViewEntity:Be,onCreateAndLink:he,onSaveRelations:P}),l&&c&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${i("danger-soft-border")}`,background:i("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:i("danger"),fontWeight:600,marginBottom:"8px"},children:g.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"12px"},children:g.editor.dangerZoneDesc}),t.jsx("button",{onClick:c,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("danger")}`,borderRadius:"4px",background:"transparent",color:i("danger"),cursor:"pointer"},children:g.editor.deleteEntity})]}),t.jsx(zl,{isOpen:b,entityType:y,title:_,onSelect:Re,onCancel:()=>w(!1),onCreate:()=>{w(!1),he(h,y)},searchResults:$,onSearch:Te,isLoading:C,excludeId:e.id}),t.jsx(Tl,{isOpen:I,entityType:U,relationField:F,inheritData:D,onConfirm:Ne,onCancel:()=>T(!1)}),t.jsx(El,{isOpen:z,title:g.action.selectBookOrWork,filterType:"all",recentEntities:E,excludeId:e.id,onSelect:ke,onCancel:()=>{pe(!1),oe(null)},onSearch:te})]})};function ix({items:e,onChange:n}){const o=ge(),r=(c,p,a)=>{const d=e.map((u,m)=>m===c?{...u,[p]:a}:u);n(d)},s=c=>n(e.filter((p,a)=>a!==c)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((c,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(Ze,{label:o.editor.bookNameLabel,value:c.book_title,onChange:a=>r(p,"book_title",a)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(Ze,{label:o.label.juanCount,value:c.n_juan!=null?String(c.n_juan):"",onChange:a=>r(p,"n_juan",a&&parseInt(a,10)||void 0)})}),t.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function Nl({items:e,onChange:n,showMeta:o,addLabel:r}){const s=ge(),[l,c]=x.useState(null),p=(u,m,f)=>{const g=e.map((b,w)=>w===u?{...b,[m]:f||void 0}:b);n(g)},a=u=>{n(e.filter((m,f)=>f!==u)),l===u&&c(null)},d=()=>{n([...e,{source:""}]),c(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,m)=>{const f=l===m;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:f?`color-mix(in srgb, ${i("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>c(f?null:m),children:[t.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.2s",transform:f?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:g=>{g.stopPropagation(),a(m)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${i("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:i("muted")},children:"✕"})]}),!f&&o&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:i("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),f&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ze,{label:s.label.sourceName,value:u.source,onChange:g=>p(m,"source",g)}),t.jsx(Ze,{label:s.label.sourceBid,value:u.source_bid||"",onChange:g=>p(m,"source_bid",g)})]}),o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(Ze,{label:s.label.titleInfo,value:u.title_info||"",onChange:g=>p(m,"title_info",g)}),t.jsx(Ze,{label:s.label.authorInfo,value:u.author_info||"",onChange:g=>p(m,"author_info",g)})]}),t.jsx(Ze,{label:s.label.edition,value:u.edition||"",onChange:g=>p(m,"edition",g)})]}),t.jsx($t,{value:u.summary||"",onChange:g=>p(m,"summary",g),placeholder:s.editor.summaryPlaceholder}),t.jsx($t,{value:u.comment||"",onChange:g=>p(m,"comment",g),placeholder:s.editor.commentPlaceholder}),t.jsx($t,{value:u.additional_comment||"",onChange:g=>p(m,"additional_comment",g),placeholder:s.editor.additionalCommentPlaceholder})]})]},m)}),t.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:r})]})}function ox({items:e,onChange:n}){const o=ge();return t.jsx(Nl,{items:e,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function rx({items:e,onChange:n}){const o=ge();return t.jsx(Nl,{items:e,onChange:n,addLabel:o.action.addEmendatedBy})}function Ll(e){var p,a,d,u,m,f,g;const n=((a=(p=e.authors)==null?void 0:p[0])==null?void 0:a.name)||"",o=((d=e.publication_info)==null?void 0:d.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(m=e.page_count)!=null&&m.number?String(e.page_count.number):((f=e.page_count)==null?void 0:f.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",c={id:e.id,title:e.title,type:e.type,author:n,publicationYear:o,holder:r,pages:s,description:l,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const b=e;if(Array.isArray(b.related_works)){const w=b.related_works.find(y=>y.relation==="part_of");w&&(c.parentWorkId=w.id,c.parentWorkName=w.title)}}if(e.type==="book"){const b=e;c.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(c.collectionId=(g=b.contained_in[0])==null?void 0:g.id)}return c}function sx(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 lx=e=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:l,onChange:c,onSave:p,onDelete:a,onNavigate:d,renderLink:u,onAskAI:m,renderSectionActions:f,onDownloadResource:g,downloadStatuses:b,relations:w,onRelationsChange:y,headerExtra:j,className:h,style:v}=e;ge();const[_,k]=x.useState(s),$=l?s:_;x.useEffect(()=>{s!==_&&k(s)},[s]);const S=x.useCallback(()=>{const F=$==="view"?"edit":"view";l?l(F):k(F)},[$,l]),[C,L]=x.useState(null);x.useEffect(()=>{o&&r&&r.getItem(o).then(F=>{F&&L(F)})},[o,r]);const I=n||C,T=x.useMemo(()=>I?Ll(I):null,[I]),U=l||!n?t.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:$==="edit"?i("accent-bg"):"transparent",color:i($==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:$==="view"?"切换到编辑模式":"切换到查看模式",children:$==="view"?"✏️ 编辑":"👁 查看"}):null,M=t.jsxs(t.Fragment,{children:[U,j]});return!I&&!T?t.jsx(yt,{}):$==="view"?t.jsx(Wi,{data:I,transport:r,onNavigate:d?F=>d(F):void 0,renderLink:u,headerExtra:M,className:h,style:v}):T?t.jsxs("div",{className:h,style:v,children:[M&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:M}),t.jsx(Rl,{data:T,onChange:c||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:m,renderSectionActions:f,onDownloadResource:g,downloadStatuses:b,relations:w,onRelationsChange:y})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:i("muted")},children:"无数据"})},Cr=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Al=({isOpen:e,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,l]=x.useState(null),[c,p]=x.useState(""),[a,d]=x.useState(""),[u,m]=x.useState("idle"),[f,g]=x.useState(""),b=x.useRef(null);x.useEffect(()=>{e&&(l(null),p(""),d(""),m("idle"),g(""))},[e]),x.useEffect(()=>{s&&setTimeout(()=>{var h;return(h=b.current)==null?void 0:h.focus()},100)},[s]),x.useEffect(()=>{if(u==="success"){const h=setTimeout(n,2e3);return()=>clearTimeout(h)}},[u,n]),x.useEffect(()=>{if(!e)return;const h=v=>{v.key==="Escape"&&n()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[e,n]);const w=async()=>{if(!(!s||!c.trim())){m("submitting"),g("");try{await o({type:s,content:c.trim(),...a.trim()?{contact:a.trim()}:{}}),m("success")}catch(h){m("error"),g(h instanceof Error?h.message:"提交失败,请稍后重试")}}};if(!e)return null;const y=s&&c.trim()&&u!=="submitting",j=Cr.find(h=>h.value===s);return t.jsx("div",{style:ax,onClick:h=>{h.target===h.currentTarget&&n()},children:t.jsxs("div",{style:cx,onClick:h=>h.stopPropagation(),children:[t.jsxs("div",{style:dx,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:px,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:gx,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:i("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Cr.map(h=>t.jsxs("button",{onClick:()=>l(h.value),style:{...ux,...s===h.value?xx:{}},children:[t.jsx("span",{children:h.icon})," ",h.label]},h.value))}),t.jsx("textarea",{ref:b,value:c,onChange:h=>p(h.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...fx,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:a,onChange:h=>d(h.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:bx}),t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[c.length," / 2000"]}),u==="error"&&t.jsx("div",{style:hx,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:w,disabled:!y,style:{...mx,opacity:y?1:.6,cursor:y?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},ax={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},cx={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:i("shadow-dialog")},dx={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},px={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:i("desc-fg"),padding:"4px 8px",borderRadius:"4px"},ux={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},xx={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},fx={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},mx={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},gx={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:i("success")},hx={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginBottom:"12px"},bx={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},$i="--bim-feedback-fab-offset",_i=48,yx=16,jx=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:o,hidden:r=!1,zIndex:s})=>{const[l,c]=x.useState(!1),p=n.bottom??24;return x.useEffect(()=>{if(r||typeof document>"u")return;const a=document.documentElement;return a.style.setProperty($i,`calc(${p+_i+yx}px + env(safe-area-inset-bottom, 0px))`),()=>{a.style.removeProperty($i)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>c(!0),style:{...vx,zIndex:s??i("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(Al,{isOpen:l,onClose:()=>c(!1),onSubmit:e,feedbackListUrl:o})]})},vx={position:"fixed",width:`${_i}px`,height:`${_i}px`,borderRadius:"50%",border:"none",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:i("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},zr=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Bl=({onSubmit:e})=>{const[n,o]=x.useState("bug"),[r,s]=x.useState(""),[l,c]=x.useState(""),[p,a]=x.useState("idle"),[d,u]=x.useState(""),m=x.useRef(null);x.useEffect(()=>{n&&setTimeout(()=>{var w;return(w=m.current)==null?void 0:w.focus()},100)},[n]);const f=async()=>{if(!(!n||!r.trim())){a("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),a("success"),s(""),c(""),o("bug")}catch(w){a("error"),u(w instanceof Error?w.message:"提交失败,请稍后重试")}}},g=n&&r.trim()&&p!=="submitting",b=zr.find(w=>w.value===n);return p==="success"?t.jsx("div",{style:Tr,children:t.jsxs("div",{style:_x,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>a("idle"),style:Cx,children:"继续提交"})]})}):t.jsxs("div",{style:Tr,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:zr.map(w=>t.jsxs("button",{onClick:()=>o(w.value),style:{...kx,...n===w.value?wx:{}},children:[t.jsx("span",{children:w.icon})," ",w.label]},w.value))}),t.jsx("textarea",{ref:m,value:r,onChange:w=>s(w.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...Sx}}),t.jsx("input",{type:"text",value:l,onChange:w=>c(w.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:Tx}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:f,disabled:!g,style:{...$x,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:zx,children:d})]})},Tr={padding:"16px",border:`1px solid ${i("widget-border")}`,borderRadius:"8px",background:i("input-bg")},kx={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},wx={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Sx={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},$x={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},_x={display:"flex",alignItems:"center",gap:"12px",color:i("success"),fontSize:"14px"},Cx={background:"none",border:"none",color:i("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},zx={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginTop:"8px"},Tx={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function Ir(e){return typeof e=="function"?e():e??"/api/feedback"}const Ml=({resourceId:e,apiUrl:n})=>{const[o,r]=x.useState([]),[s,l]=x.useState(!0),c=x.useCallback(async()=>{const a=Ir(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]);x.useEffect(()=>{c()},[c]);const p=async a=>{const d=Ir(n),u=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const m=await u.json().catch(()=>null);throw new Error((m==null?void 0:m.error)||"提交失败")}setTimeout(()=>c(),500)};return t.jsxs("div",{children:[t.jsx(uo,{items:o,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Bl,{onSubmit:p})})]})},Er={part_of:"所屬",has_part:"包含",contains_text_of:"收錄",collected_in:"叢編",text_carried_by:"載錄",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"後繼",derived_from:"衍生",has_adaptation:"改編",related:"相關"};function Rr(e){return e?Er[e]??e:Er.related}const Ix={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function Ex(e){return Ix[e]??e}const Rx={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function Nx(e){return Rx[e]??""}function xo({authors:e,onNavigate:n,renderLink:o}){const{convert:r}=X(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,c)=>{const p=Gi(l.role);return t.jsxs(x.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(Oe,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:o,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},c)})}):null}function Wl(e,n){var p,a;const o=Di(e,n),r=o.mirrors.map(d=>({key:d.key,label:d.label,description:d.description,rows:d.items.filter(u=>u.group_role!=="mirror"),mirrors:d.items.filter(u=>u.group_role==="mirror")})),s=o.buckets.filter(d=>d.key==="image"||d.key==="textImage").flatMap(d=>d.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=o.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((a=o.buckets.find(d=>d.key==="text"))==null?void 0:a.items)??[],groups:r}}function Fl(e,n){const o=(e.url?Pt(e.url):void 0)||e.name,r=Ss(e,n);return r?`${o}(${r})`:o}function fo({item:e,siblings:n,listedVolumeCounts:o}){const{convert:r}=X(),[s,l]=x.useState(!1),c=zn(e),p=!!c&&c.expected>0&&!(o!=null&&o.has(c.expected)),a=r(Fl(e,n)),d=Dt(e),u=Bn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var f,g;const m=(f=e.metadata)!=null&&f.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((g=e.metadata)==null?void 0:g.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("殘片")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:r(e.color_mode==="color"?"彩色":"黑白")})]}):null;return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[a," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),m]}):t.jsxs("span",{className:"bim-d-zt-name",children:[a,m]})})(),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(Yi,{item:e})})]}),t.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(m=>!m),children:r(s?"收起分冊":`展開 ${c.expected} 冊`)})})]})}function Ol({groups:e,listedVolumeCounts:n}){const{convert:o}=X();return t.jsx(t.Fragment,{children:e.map(r=>t.jsxs("div",{className:"bim-d-rg",children:[r.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:o(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:o(r.description)}),r.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:r.rows.map((s,l)=>t.jsx(fo,{item:s,siblings:r.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),r.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[r.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:o("鏡像")}),r.mirrors.map((s,l)=>{const c=Dt(s),p=o(Fl(s,r.mirrors));return c?t.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",title:s.details?o(s.details):void 0,children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:p},l)})]})]},r.key))})}const sn=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function Ci(e){var o;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(o=sn.find(r=>n.startsWith(r.key[0])))==null?void 0:o.key}const Nr=12,Lx=60,Pl=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,railTop:l,back:c,railLinks:p})=>{var Ne,Te,Re;const a=ge(),{convert:d}=X(),u=x.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[m,f]=x.useState(new Map),[g,b]=x.useState(!1),[w,y]=x.useState(""),[j,h]=x.useState(!1),v=u.length<=Lx,_=v||g||!!w||j,k=x.useMemo(()=>_?u:u.slice(0,Nr),[u,_]);x.useEffect(()=>{if(!n||k.length===0)return;const P=k.filter(te=>!m.has(te));if(P.length===0)return;let me=!1;return Promise.all(P.map(te=>n.getItem(te).then(ke=>{const we=ke??{};return[te,{id:te,title:we.title,edition:we.edition,resources:we.resources,publication_info:we.publication_info,current_location:we.current_location,lineage:we.lineage,measure_info:we.measure_info}]}).catch(()=>[te,{id:te}]))).then(te=>{me||f(ke=>{const we=new Map(ke);for(const[K,N]of te)we.set(K,N);return we})}),()=>{me=!0}},[n,k,m]);const $=x.useMemo(()=>u.map(P=>m.get(P)??{id:P}),[u,m]),S=u.length>0&&u.every(P=>m.has(P)),C=!!n&&k.some(P=>!m.has(P)),L=v||_,I=x.useMemo(()=>_s($,e.version_graph,{era:w,scanOnly:j,sort:L?"year":"default"}),[$,e.version_graph,w,j,L]),T=g?I.rows:I.rows.slice(0,Nr),U=I.allRows.filter(P=>P.hasImage).length,M=e.related_works||[],F=M.filter(P=>P.relation==="collected_in"),O=x.useMemo(()=>{const P=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],me=te=>{const ke=P.indexOf(te??"");return ke<0?P.length:ke};return M.filter(te=>te.relation!=="collected_in").map((te,ke)=>({r:te,i:ke})).sort((te,ke)=>me(te.r.relation)-me(ke.r.relation)||te.i-ke.i).map(te=>te.r)},[M]),D=x.useMemo(()=>{const P=Di(e.resources,e.resource_groups);return[...P.mirrors.flatMap(me=>me.items.map(te=>({r:te,kind:d(me.label)}))),...P.buckets.flatMap(me=>me.items.map(te=>({r:te,kind:d(Nx(me.key))})))]},[e.resources,e.resource_groups,d]),H=e.indexed_by||[],z=e.emendated_by||[],pe=x.useMemo(()=>{var xe,ye,B;const P=[],me=(ye=(xe=e.authors)==null?void 0:xe[0])==null?void 0:ye.dynasty;me&&P.push({label:"成書",value:d(me)});const te=mt(e,a.unit.juan);if(te){const re=(B=e.juan_count)==null?void 0:B.description;P.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[d(te),re&&re!==te?t.jsxs("span",{className:"bim-d-meta",children:["(",d(re),")"]}):null]})})}e.loss_status&&P.push({label:"存佚",value:d(Ex(e.loss_status))});const ke=I.allRows.filter(re=>re.sortYear!=null),we=ke.length>0?ke.reduce((re,Q)=>re.sortYear<=Q.sortYear?re:Q):null;we!=null&&we.era.era?P.push({label:"最早存世",value:d([we.era.era,we.era.reign].filter(Boolean).join(" ")),title:we.era.source==="edition"?d("據版本題名推斷"):void 0}):C&&P.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),z.length&&P.push({label:"考證",value:`${z.length} ${d("條")}`});const K=Lr(e.additional_titles);K.length&&P.push({label:"又名",value:K.map(d).join("、")});const N=Lr(e.attached_texts);N.length&&P.push({label:"附載",value:N.map(d).join("、")});const q=(e.additional_works||[]).map(re=>d(re.book_title)+(re.n_juan!=null?` ${re.n_juan}${d(a.unit.juan)}`:""));return q.length&&P.push({label:"附錄",value:q.join("、")}),P},[e,d,a,C,I.allRows,z.length]),oe=[{value:e._edition_count??u.length,label:"版本"},{value:S?U:0,label:"有影印"},{value:H.length,label:"家著錄"}],E=e.classification,W=E?[E.l1,E.l2,E.l3,E.l4].filter(Boolean).map(P=>d(P)):[],ce=e.subtype?d(a.workSubtype[e.subtype]??e.subtype):"",Y=t.jsx(pn,{title:d(e.title),byline:t.jsx(xo,{authors:e.authors,onNavigate:o,renderLink:r}),meta:t.jsx(He,{items:[...W,E!=null&&E.source?d(`據《${E.source.split("/")[0]}》`):"",ce]}),description:(Ne=e.description)!=null&&Ne.text?t.jsxs(t.Fragment,{children:[t.jsx(ft,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Te=e.description.sources)!=null&&Te.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(P=>d(cd(P))).filter(Boolean).join(" · ")}):null]}):void 0,stats:oe,facts:pe,readAction:s,foot:t.jsx(un,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Re=e.appendix)==null?void 0:Re.map((P,me)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(P.title)}),t.jsx(ft,{text:P.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},me))}),ee=I.eras.length>=2?[{key:"",label:a.catalog.all},...I.eras.map(P=>({key:P,label:`${P} ${I.allRows.filter(me=>me.era.era===P).length}`}))]:[],Z=[];u.length&&Z.push({id:"versions",label:"版本",count:u.length}),H.length&&Z.push({id:"catalogs",label:"著錄",count:H.length}),F.length&&Z.push({id:"collected",label:"收入叢編",count:F.length}),O.length&&Z.push({id:"related",label:"相關書目",count:O.length}),D.length&&Z.push({id:"resources",label:"在線資源",count:D.length});const le=u.length===0&&H.length===0,be=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Ge,{id:"versions",title:"版本",meta:t.jsx(He,{items:[d(`共 ${u.length} 種`),S&&U?d(`${U} 種有影印`):"",I.rows.length!==I.allRows.length?d(`當前 ${I.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":C&&ee.length===0&&u.length>1?"":void 0,children:[ee.length>0&&t.jsx(Wn,{items:ee,value:w,onChange:P=>{y(P),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Ms,{label:"只看有影印",checked:j,onChange:P=>{h(P),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:d(L?"按年代排列":"按著錄順序")})]}),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:T.map(P=>{var me;return t.jsx(Ax,{row:P,measure:(me=m.get(P.id))==null?void 0:me.measure_info,loaded:m.has(P.id),onNavigate:o,renderLink:r},`${P.id}:${m.has(P.id)?"r":"p"}`)})})]}),T.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(w||j?"當前篩選下沒有版本":"暫無版本著錄")}),I.rows.length>T.length&&t.jsx(Gt,{label:`展開其餘 ${I.rows.length-T.length} 種版本`,onClick:()=>b(!0)}),I.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:d("部分年代據版本題名推斷,非著錄原文")})]}),H.length>0&&t.jsx(Bx,{items:H,transport:n,onNavigate:o,renderLink:r}),le&&t.jsx(Ge,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),Le=(P,me)=>t.jsx(Oe,{id:P,label:d(me),onNavigate:o,renderLink:r,dense:!0}),Be=x.useMemo(()=>{const P=new Map;for(const me of O){const te=Rr(me.relation);P.set(te,(P.get(te)??0)+1)}return P.size>1?[...P.entries()].sort((me,te)=>te[1]-me[1]).slice(0,4).map(([me,te])=>`${d(me)} ${te}`).join(" · "):void 0},[O,d]),he=t.jsxs(t.Fragment,{children:[t.jsx(St,{id:"collected",title:"收入叢編",items:F.map(P=>Le(P.id,P.title))}),t.jsx(St,{id:"related",title:"相關書目",meta:d(`${O.length} 部`),sub:Be,items:O.map(P=>t.jsxs(t.Fragment,{children:[Le(P.id,P.title),t.jsx("span",{className:"bim-d-meta",title:P.note?d(P.note):void 0,children:d(Rr(P.relation))})]}))}),t.jsx(St,{id:"resources",title:"在線資源",cap:6,items:D.map(({r:P,kind:me})=>{const te=d((P.url?Pt(P.url):void 0)||P.name),ke=Dt(P);return t.jsxs(t.Fragment,{children:[ke?t.jsxs("a",{href:ke,target:"_blank",rel:"noopener noreferrer",children:[te," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:te}),me&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:me})]})})})]});return t.jsx(dn,{railTop:l,back:c,nav:Z,railLinks:p,main:be,card:Y,side:he})};function Lr(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Ar(e,n){return n((e.url?Pt(e.url):void 0)||e.name)}function Ax({row:e,measure:n,loaded:o,onNavigate:r,renderLink:s}){const{convert:l}=X(),c=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",a=e.holders[0],d=a?Ar(a,l):e.locationName?l(e.locationName):"",u=e.images[0],m=u?Dt(u):void 0,f=e.images.map(g=>Ar(g,l)).join("、");return t.jsxs("tr",{"data-loading":o?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Oe,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${c?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:c?l(c):o?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${d?"":" bim-d-zt-blank"}`,children:[d||(o?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(m?t.jsx("a",{className:"bim-d-flag",href:m,target:"_blank",rel:"noopener noreferrer",title:f,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:f,children:l("有影印")}))})]})}function Bx({items:e,transport:n,onNavigate:o,renderLink:r}){const s=ge(),{convert:l}=X(),[c,p]=x.useState(0),a=Math.min(c,e.length-1),d=e[a],[u,m]=x.useState(new Map);return x.useEffect(()=>{if(!n)return;const f=[...new Set(e.map(b=>b.source_bid).filter(b=>!!b))];if(f.length===0)return;let g=!1;return Promise.all(f.map(b=>n.getItem(b).then(w=>{var y,j;return[b,((j=(y=w==null?void 0:w.authors)==null?void 0:y[0])==null?void 0:j.dynasty)??""]}).catch(()=>[b,""]))).then(b=>{g||m(new Map(b.filter(([,w])=>w)))}),()=>{g=!0}},[n,e]),t.jsx(Ge,{id:"catalogs",title:"著錄",meta:t.jsx(He,{items:[l(`歷代書目 ${e.length} 家`),l("按著錄順序")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":l("著錄書目"),children:e.map((f,g)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":g===a,"aria-label":l(f.source),onClick:()=>p(g),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(f.source_bid??"")?l(u.get(f.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...l(f.source)].slice(0,9).map((b,w)=>t.jsx("span",{children:b},w))})]})},g))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:l(d.title_info)}),t.jsx(He,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?t.jsx(Oe,{id:d.source_bid,label:l(d.source),onNavigate:o,renderLink:r,dense:!0}):l(d.source),d.section?l(d.section):"",d.author_info?`${l(s.label.authorInfo)} ${l(d.author_info)}`:"",d.edition?`${l(s.label.edition)} ${l(d.edition)}`:"",d.page??""]}),d.summary&&t.jsx("p",{className:"bim-d-quote",children:Xe(l(d.summary))}),d.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:Xe(l(d.comment))})]}),d.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:Xe(l(d.additional_comment))})]}),!d.summary&&!d.comment&&!d.additional_comment&&!d.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:l("僅著錄書名,無提要。")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[a>0?t.jsx("button",{type:"button","aria-label":l(`上一家:${e[a-1].source}`),onClick:()=>p(a-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",l(e[a-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[a+1," / ",e.length]}),a<e.length-1?t.jsx("button",{type:"button","aria-label":l(`下一家:${e[a+1].source}`),onClick:()=>p(a+1),children:t.jsxs("span",{"aria-hidden":"true",children:[l(e[a+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function Mx(e){var n;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((n=e.year_range)==null?void 0:n[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function Wx(e,n){if(!e.lineage)return null;const o=e.lineage;return{id:e.id,kind:"book",label:e.title,year:o.year,year_text:o.year_text,year_uncertain:o.year_uncertain,category:o.category,status:o.status,extant_juan:o.extant_juan,group:n[e.id],note:o.note}}function Br(e,n,o){return{id:`derive:${n.ref}->${e}:${o}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Fx(e,n,o){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${o}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Ox(e,n){var d;if(n==="all")return null;const o=(d=e.collections)==null?void 0:d[n],r=Array.isArray(o==null?void 0:o.groups)&&o.groups.length>0,s=Array.isArray(o==null?void 0:o.book_ids)&&o.book_ids.length>0,l=r||s||!!(o!=null&&o.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!o||!l)return null;const c=r?new Set(o.groups):null,p=new Set(o.book_ids??[]);if(c&&e.node_groups)for(const[u,m]of Object.entries(e.node_groups))c.has(m)&&p.add(u);let a=null;if(o.hypothetical_ids&&(a=new Set(o.hypothetical_ids)),c){a||(a=new Set);for(const u of e.hypothetical_nodes??[])u.group&&c.has(u.group)&&a.add(u.id)}return{books:p,hypos:a}}function kn(e,n,o){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const l=new Set(r.excluded_books??[]),c=r.node_groups??{},p=Ox(r,o??r.default_collection??"all"),a=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,m=new Set,f=new Set;if(a){const _=new Map(n.map(I=>[I.id,I])),k=new Map((r.hypothetical_nodes??[]).map(I=>[I.id,I])),$=I=>{const T=_.get(I);if(T&&T.lineage)return(T.lineage.derived_from??[]).map(M=>M.ref);const U=k.get(I);return U?(U.derived_from??[]).map(M=>M.ref):[]},S=I=>k.has(I)?!u||u.has(I):!d||d.has(I),C=new Set,L=I=>{if(!C.has(I)){C.add(I);for(const T of $(I))l.has(T)||(S(T)||(k.has(T)?f.add(T):_.has(T)&&m.add(T)),L(T))}};for(const I of n)d&&d.has(I.id)&&!l.has(I.id)&&L(I.id);for(const I of r.hypothetical_nodes??[])u&&u.has(I.id)&&L(I.id)}const g=n.filter(_=>!l.has(_.id)).filter(_=>!d||d.has(_.id)||m.has(_.id)).map(_=>{const k=Wx(_,c);return k&&m.has(_.id)&&(k.bridge=!0),k}).filter(_=>_!==null),b=(r.hypothetical_nodes??[]).filter(_=>!u||u.has(_.id)||f.has(_.id)).map(_=>{const k=Mx(_);return f.has(_.id)&&(k.bridge=!0),k}),w=[...g,...b],y=new Set(w.map(_=>_.id)),j=new Set,h=[],v=_=>{j.has(_.id)||!y.has(_.source)||!y.has(_.target)||(j.add(_.id),h.push(_))};for(const _ of n)l.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!m.has(_.id)||((_.lineage.derived_from??[]).forEach((k,$)=>{v(Br(_.id,k,$))}),(_.lineage.related_to??[]).forEach((k,$)=>{v(Fx(_.id,k,$))}));for(const _ of r.hypothetical_nodes??[])u&&!u.has(_.id)&&!f.has(_.id)||(_.derived_from??[]).forEach((k,$)=>{v(Br(_.id,k,$))});return{nodes:w,edges:h,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function Dl(e,n,o){const r=(e??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Px(e,n){const o=[],r=e.version_graph;if(!r)return o;const s=new Set(n.map(a=>a.id)),l=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),c=new Set([...s,...l]),p=(a,d)=>{c.has(d.ref)||o.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&o.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&o.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(u=>p(d,u)),(a.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||o.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(u=>p(d,u))}return o}const Hl=({graph:e,renderLink:n,className:o,style:r})=>{const{convert:s}=X();if(!e.nodes.length)return t.jsx("div",{style:{...tf,...r},className:o,children:"暂无版本图数据"});const l=new Map,c=new Map;for(const f of e.edges)if(f.kind==="derive"){const g=l.get(f.target)??[];g.push(f),l.set(f.target,g)}else for(const g of[f.source,f.target]){const b=c.get(g)??[];b.push(f),c.set(g,b)}const p=new Map(e.nodes.map(f=>[f.id,f])),a=new Map,d=[];for(const f of e.nodes)if(f.group){const g=a.get(f.group)??[];g.push(f),a.set(f.group,g)}else d.push(f);const u=(f,g)=>(f.year??9999)-(g.year??9999);a.forEach(f=>f.sort(u)),d.sort(u);const m=e.groups.filter(f=>a.has(f.id));return t.jsxs("div",{className:o,style:{...Hx,...r},children:[e.title&&t.jsx("div",{style:Gx,children:s(e.title)}),e.description&&t.jsx("div",{style:Vx,children:s(e.description)}),m.map(f=>t.jsx(Mr,{label:f.label,color:f.color,nodes:a.get(f.id),incomingMap:l,siblingMap:c,nodeMap:p,renderLink:n},f.id)),d.length>0&&t.jsx(Mr,{label:"其他",nodes:d,incomingMap:l,siblingMap:c,nodeMap:p,renderLink:n})]})},Mr=({label:e,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:l,renderLink:c})=>{const{convert:p}=X();return t.jsxs("div",{style:Ux,children:[t.jsx("div",{style:{...Yx,borderLeftColor:n??i("widget-border")},children:p(e)}),o.map(a=>t.jsx(Dx,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:l,renderLink:c},a.id))]})},Dx=({node:e,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const l=e.kind==="hypothetical",c=e.bridge,{convert:p}=X();return t.jsxs("div",{style:{...Kx,borderStyle:l||c?"dashed":"solid",opacity:c?.55:e.status==="lost"?.7:1,background:c?i("bg-subtle"):void 0},title:c?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:qx,children:[t.jsx("span",{style:Jx,children:l||!s?p(e.label):s(e.id,p(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Zx,children:Dl(p(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Xx,children:[e.category&&t.jsx(Qt,{children:p(e.category)}),e.status==="lost"&&t.jsx(Qt,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(Qt,{tone:"warn",children:"残本"}),l&&t.jsx(Qt,{tone:"info",children:"假想祖本"}),c&&t.jsx(Qt,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Qx,children:["现存:",p(e.extant_juan)]}),e.note&&t.jsx("div",{style:ef,children:p(e.note)}),n.length>0&&t.jsxs("div",{style:Fr,children:[t.jsx("div",{style:Or,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return t.jsxs("div",{style:Pr(a.confidence),children:[t.jsx("span",{style:Dr,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(Wr,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:Hr,children:["· ",p(a.evidence)]})]},a.id)})]}),o.length>0&&t.jsxs("div",{style:Fr,children:[t.jsx("div",{style:Or,children:"关联:"}),o.map(a=>{const d=a.source===e.id?a.target:a.source,u=r.get(d);return t.jsxs("div",{style:Pr(a.confidence),children:[t.jsx("span",{style:Dr,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(Wr,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:Hr,children:["· ",p(a.evidence)]})]},a.id)})]})]})},Qt=({children:e,tone:n="default"})=>{const r={default:{bg:i("tag-bg"),fg:i("fg")},warn:{bg:i("warn-bg"),fg:i("warn-fg")},info:{bg:i("info-bg"),fg:i("info-fg")}}[n];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},Wr=({level:e})=>{const o={certain:{label:"确定",color:i("confidence-certain")},consensus:{label:"共识",color:i("confidence-consensus")},probable:{label:"推测",color:i("confidence-probable")},disputed:{label:"有争议",color:i("confidence-disputed")}}[e];return o?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${o.color}`,color:o.color,borderRadius:"8px",marginLeft:"4px"},children:o.label}):null},Hx={fontSize:"14px",color:i("fg")},Gx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Vx={fontSize:"13px",color:i("muted"),marginBottom:"16px",lineHeight:1.6},Ux={marginBottom:"16px"},Yx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:i("fg")},Kx={border:`1px solid ${i("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:i("bg")},qx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Jx={fontSize:"15px",fontWeight:600},Zx={fontSize:"12px",color:i("muted")},Xx={marginBottom:"6px"},Qx={fontSize:"12px",color:i("muted"),margin:"2px 0"},ef={fontSize:"12px",color:i("muted"),fontStyle:"italic",margin:"4px 0"},Fr={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${i("widget-border")}`},Or={fontSize:"11px",color:i("muted"),marginBottom:"2px"},Pr=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Dr={display:"inline-block",padding:"0 6px",fontSize:"11px",background:i("tag-bg"),color:i("fg"),borderRadius:"3px",marginRight:"6px"},Hr={fontSize:"11px",color:i("muted")},tf={padding:"20px",textAlign:"center",color:i("muted"),fontSize:"13px"},Gl=({selectedNodeId:e,...n})=>{const[o,r]=x.useState("loading"),[s,l]=x.useState(null);return x.useEffect(()=>{let c=!1;return nf().then(p=>{c||(p?(l(p),r("ready")):r("missing"))}),()=>{c=!0}},[]),o==="loading"?t.jsx("div",{style:Gr,children:"加载图组件中…"}):o==="missing"||!s?t.jsxs("div",{style:Gr,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(of,{modules:s,selectedNodeId:e,...n})};async function nf(){try{const[e,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let o=!1;try{await import("@xyflow/react/dist/style.css"),o=!0}catch{o=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:n,cssLoaded:o}}catch{return null}}const of=({graph:e,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:l,modules:c})=>{const{ReactFlow:p,Background:a,Controls:d,Handle:u,Position:m,BaseEdge:f,EdgeLabelRenderer:g,getSmoothStepPath:b,dagre:w}=c,y=x.useMemo(()=>({lineage:$=>{var D,H,z,pe;const S=((D=$.data)==null?void 0:D.stepPosition)??.85,[C,L,I]=b({sourceX:$.sourceX,sourceY:$.sourceY,sourcePosition:$.sourcePosition,targetX:$.targetX,targetY:$.targetY,targetPosition:$.targetPosition,stepPosition:S,borderRadius:5}),T=!!((H=$.data)!=null&&H.isSibling),U=T?L:$.targetX-18,M=T?I:$.targetY-12,F=(z=$.data)==null?void 0:z.labelStyle,O=(pe=$.data)==null?void 0:pe.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(f,{id:$.id,path:C,style:$.style,markerStart:$.markerStart,markerEnd:$.markerEnd}),$.label&&t.jsx(g,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${U}px,${M}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:i("bg"),border:`0.5px solid ${i("widget-border")}`,...O,...F},children:$.label})})]})}}),[f,g,b]),j=x.useMemo(()=>({version:$=>{const S=$.data,C=S.kind==="hypothetical",L=S.status==="lost",I=S.isSelected,T=S.bridge,U=S.borderColor??i("muted"),M=T||C?"dashed":"solid",F=T?.5:L?.6:1;return t.jsxs("div",{style:{background:i(T?"bg-subtle":"bg"),border:`2px ${M} ${I?i("primary"):U}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:F,boxShadow:I?i("shadow-node-selected"):C||T?"none":i("shadow-node")},title:T?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(u,{type:"target",position:m.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:C||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.2},children:Dl(S.yearText,void 0,S.uncertain)}),L&&t.jsx("div",{style:{fontSize:9,color:i("lost-fg"),marginTop:1},children:"已佚"}),t.jsx(u,{type:"source",position:m.Right,style:{visibility:"hidden"}})]})}}),[u,m]),{convert:h}=X(),{rfNodes:v,rfEdges:_}=x.useMemo(()=>rf(e,w,n,l,h),[e,w,n,l,h]);return t.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:t.jsxs(p,{nodes:v,edges:_,nodeTypes:j,edgeTypes:y,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(a,{gap:16}),t.jsx(d,{showInteractive:!1})]})})};function rf(e,n,o,r,s=l=>l??""){const p=e.layout==="LR"||!e.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:p?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(e.groups.map(j=>[j.id,j.color??i("muted")]));for(const j of e.nodes)a.setNode(j.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of e.edges)j.kind==="derive"&&(u.has(j.relation)||a.setEdge(j.source,j.target));n.layout(a);const m=e.nodes.map(j=>{const h=a.node(j.id),v=r?j.id===r:void 0,_={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??lf(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:o,isSelected:v,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:h.x-160/2,y:h.y-90/2},data:_,draggable:!1,selected:v}}),f=.78,g=.06,b=new Map;for(const j of e.edges)j.kind==="derive"&&(b.has(j.source)||b.set(j.source,[]),b.get(j.source).push(j));const w=new Map;for(const[j,h]of b){if(h.length<=1)continue;const v=[...h].sort((k,$)=>{var L,I;const S=((L=a.node(k.target))==null?void 0:L.y)??0,C=((I=a.node($.target))==null?void 0:I.y)??0;return S-C}),_=v.length;v.forEach((k,$)=>{const S=($-(_-1)/2)*g;w.set(k.id,f+S)})}const y=e.edges.map(j=>sf(j,w.get(j.id),s));return{rfNodes:m,rfEdges:y}}function sf(e,n,o=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",l=af(e.confidence),c={type:"arrowclosed",color:l,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:o(e.relation),data:{labelStyle:{color:i("fg")},isSibling:s,stepPosition:n},style:{stroke:l,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:c,markerStart:s?c:void 0,zIndex:1e3}}function lf(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function af(e){switch(e){case"certain":return i("confidence-certain");case"consensus":return i("lineage-edge-consensus");case"probable":return i("confidence-probable");case"disputed":return i("confidence-disputed");default:return i("muted")}}const Gr={padding:"40px 20px",textAlign:"center",color:i("muted"),fontSize:"13px",border:`1px dashed ${i("widget-border")}`,borderRadius:8,background:i("bg")},mo=({graph:e,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:l,collection:c,onCollectionChange:p,collectionsAvailable:a,collectionCounts:d,className:u,style:m})=>{var h;const[f,g]=x.useState(n),b=v=>{g(v),l==null||l(v)},w=(()=>{if(!a)return[];const v=Object.entries(a);return v.length===0||a.all?v:[...v,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),y=!!(p&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:i("muted"),textAlign:"center"},children:"暂无版本传承数据"});const j=c?(h=a==null?void 0:a[c])==null?void 0:h.description:void 0;return t.jsxs("div",{className:u,style:m,children:[t.jsxs("div",{style:cf,children:[t.jsx("button",{onClick:()=>b("list"),style:ri(f==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:ri(f==="graph"),children:"关系图"}),y&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:i("muted"),marginRight:4},children:"集合:"}),w.map(([v,_])=>{const k=d==null?void 0:d[v];return t.jsxs("button",{onClick:()=>p==null?void 0:p(v),style:ri(c===v),title:_.description,children:[_.label,k!=null?` ${k}`:""]},v)})]})]}),y&&j&&t.jsx("div",{style:{fontSize:12,color:i("muted"),marginBottom:8,padding:"4px 8px",background:i("bg-subtle"),borderRadius:4},children:j}),f==="list"?t.jsx(Hl,{graph:e,renderLink:o}):t.jsx(Gl,{graph:e,renderLink:o,height:r,selectedNodeId:s})]})},cf={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},ri=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${i("widget-border")}`,borderRadius:4,background:e?i("primary"):"transparent",color:i(e?"primary-fg":"fg"),cursor:"pointer"}),Vr=40,Ur=2,df=9,Yr={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function si(e){if(!e)return["",""];const n=e.split(/[ ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Vl=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,fullText:l,fullTextPending:c,chapterLink:p,railTop:a,back:d,railLinks:u})=>{var xe,ye,B,re,Q,fe,G,ve,$e,J,_e;const m=ge(),{convert:f}=X(),[g,b]=x.useState(null),[w,y]=x.useState(new Map),[j,h]=x.useState([]),[v,_]=x.useState(new Map),[k,$]=x.useState(!1),[S,C]=x.useState("flow"),[L,I]=x.useState(null);x.useEffect(()=>{if(!n||!e.work_id){b(null);return}let R=!1;return n.getItem(e.work_id).then(se=>{!R&&se&&se.type==="work"&&b(se)}).catch(()=>{}),()=>{R=!0}},[n,e.work_id]),x.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){I(null);return}let R=!1;return n.getLineageGraph(e.work_id).then(se=>{R||I(se&&se.nodes.length>1?se:null)}).catch(()=>{R||I(null)}),()=>{R=!0}},[n,e.work_id]),x.useEffect(()=>{const R=e.contained_in||[];if(!n||R.length===0){y(new Map);return}let se=!1;return Promise.all(R.map(ue=>{const ae=typeof ue=="string"?ue:ue.id;return n.getItem(ae).then(ie=>[ae,ie]).catch(()=>[ae,null])})).then(ue=>{if(se)return;const ae=new Map;for(const[ie,Se]of ue)Se&&ae.set(ie,Se);y(ae)}),()=>{se=!0}},[n,e.contained_in]);const T=x.useMemo(()=>{const R=new Set([...(g==null?void 0:g.books)||[],...e.related_books||[]]);return R.add(e.id),[...R]},[g==null?void 0:g.books,e.related_books,e.id]),U=T.length-1;x.useEffect(()=>{if(!n||U<=0){h([]);return}const R=T.length<=Vr,se=R?T:T.slice(0,8);let ue=!1;return Promise.all(se.map(ae=>ae===e.id?Promise.resolve({id:ae,title:e.title,edition:e.edition,year:$n(e)}):n.getItem(ae).then(ie=>{const Se=ie??{};return{id:ae,title:Se.title,edition:Se.edition,year:ie?$n(Se):void 0}}).catch(()=>({id:ae})))).then(ae=>{if(ue)return;const ie=ae.filter(Se=>Se.id===e.id||Se.title||Se.edition);R&&ie.sort((Se,Ee)=>(Se.year??1/0)-(Ee.year??1/0)),h(ie)}),()=>{ue=!0}},[n,T,U,e]);const M=e.lineage,F=x.useMemo(()=>[...((M==null?void 0:M.derived_from)||[]).filter(R=>R.ref_type==="book").map(R=>R.ref),...((M==null?void 0:M.related_to)||[]).map(R=>R.book_id)].filter(Boolean),[M]);x.useEffect(()=>{if(!n||F.length===0){_(new Map);return}let R=!1;return Promise.all(F.map(se=>n.getItem(se).then(ue=>[se,{id:se,title:ue==null?void 0:ue.title,edition:ue==null?void 0:ue.edition}]).catch(()=>[se,{id:se}]))).then(se=>{R||_(new Map(se))}),()=>{R=!0}},[n,F]);const O=x.useMemo(()=>Wl(e.resources,e.resource_groups),[e.resources,e.resource_groups]),D=O.groups.reduce((R,se)=>R+se.rows.length+se.mirrors.length,0),H=O.groups.length>0&&O.groups.every(R=>R.key==="_physical"),z=cn(e),pe=Es(e),A=mt(e,m.unit.juan),oe=new Set((e.contained_in||[]).map(R=>typeof R=="string"?0:on(R.volume_index).length).filter(R=>R>0)),E=R=>{var ae;const se=(ae=e.base_edition)==null?void 0:ae.find(ie=>ie.book_id===R&&ie.name);if(se!=null&&se.name)return se.name;const ue=v.get(R);return(ue==null?void 0:ue.edition)||(ue==null?void 0:ue.title)||""},W=x.useMemo(()=>{var qe,Tt,Qe,It,jt;const R=[];pe&&R.push({label:"版本類型",value:f(pe),title:e.edition_type||(qe=e.lineage)!=null&&qe.category?void 0:f("據版本題名推斷")}),(Tt=e.publication_info)!=null&&Tt.details?R.push({label:"刊印",value:f(e.publication_info.details)}):(z.era||z.reign)&&R.push({label:"刊寫年代",value:f([z.era,z.reign].filter(Boolean).join(" ")),title:z.source==="edition"?f("據版本題名推斷"):void 0}),A&&R.push({label:"卷帙",value:f(A)});const se=(e.contained_in||[]).flatMap(Ie=>typeof Ie=="string"?[]:on(Ie.volume_index));se.length&&R.push({label:"冊次",value:f(`第 ${Mn(se,m.unit.volume)} ${m.unit.volume}(${se.length} ${m.unit.volume})`)});const ue=(((Qe=e.lineage)==null?void 0:Qe.derived_from)||[]).find(Ie=>Ie.relation==="底本"&&Ie.ref_type==="book");ue&&E(ue.ref)&&R.push({label:"底本",value:t.jsx(Oe,{id:ue.ref,label:f(E(ue.ref)),onNavigate:o,renderLink:r,dense:!0})});const ae=(e.base_edition||[]).filter(Ie=>Ie&&Ie.name);for(const Ie of["底本","配補","參校"]){if(Ie==="底本"&&ue&&E(ue.ref))continue;const Je=ae.filter(V=>V.role===Ie);Je.length&&R.push({label:Ie,value:Je.map((V,ze)=>t.jsxs(x.Fragment,{children:[ze>0&&"、",V.book_id?t.jsx(Oe,{id:V.book_id,label:f(V.name),onNavigate:o,renderLink:r,dense:!0}):f(V.name)]},ze))})}const ie=(e.provenance||[]).filter(Ie=>Ie&&Ie.institution),Se=(e.resources||[]).filter(Ie=>(Ie.types||(Ie.type?[Ie.type]:[])).includes("physical"));if(ie.length){R.push({label:"存藏",value:ie.slice(0,2).map(V=>f(V.institution)).join("、")+(ie.length>2?f(` 等 ${ie.length} 處`):"")});const Ie=ie.filter(V=>V.call_number).slice(0,2).map(V=>`${f(V.institution)} ${V.call_number}`);Ie.length&&R.push({label:"索書號",value:Ie.join(";")+(ie.filter(V=>V.call_number).length>2?"…":"")});const Je=ie.flatMap(V=>V.seals||[]).filter(Boolean);Je.length&&R.push({label:"藏印",value:f(Je.join("、"))})}else Se.length?R.push({label:"存藏",value:Se.slice(0,2).map(Ie=>f(Ie.name)).join("、")+(Se.length>2?f(` 等 ${Se.length} 處`):"")}):(It=e.current_location)!=null&&It.name&&R.push({label:"存藏",value:f(e.current_location.name)});const Ee=e.physical_description;if(Ee){const Ie=[["行款",Ee.leaf_style],["裝幀",Ee.binding],["尺寸",Ee.dimensions],["品相",Ee.condition]];for(const[Je,V]of Ie)V&&V.trim()&&R.push({label:Je,value:f(V)})}(jt=e.page_count)!=null&&jt.description&&R.push({label:m.label.pageCount,value:f(e.page_count.description)});const We=[...bi(e.additional_titles),...bi(e.attached_texts)];return We.length&&R.push({label:"又名",value:We.map(f).join("、")}),R},[e,f,m,z,pe,A,v,o,r]),ce=f(e.title),Y=e.edition?f(e.edition):void 0,ee=((xe=e.lineage)==null?void 0:xe.year_text)||"",Z=t.jsx(pn,{kind:"版本",title:ce,subtitle:Y,byline:t.jsx(xo,{authors:e.authors??(g==null?void 0:g.authors),onNavigate:o,renderLink:r}),meta:(()=>{const R=[pe?f(pe):"",z.era?f([z.era,z.reign].filter(Boolean).join("")):"",A?f(A):""].filter(Boolean);return R.length?t.jsx("span",{className:"bim-d-tags",children:R.map((se,ue)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ue,2)}`,children:se},ue))}):null})(),description:(ye=e.description)!=null&&ye.text?t.jsx(ft,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Vi((B=e.description)==null?void 0:B.text)?6:void 0,facts:W,readAction:s,secondaryAction:s&&D>0&&!H?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:f("看原書影印")}):void 0,foot:t.jsx(un,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),le=e.contained_in||[],be=(l==null?void 0:l.chapters)||[],Le=be[0]&&si(be[0].title)[0].slice(-1)||"章",Be=!!((re=M==null?void 0:M.derived_from)!=null&&re.length||(Q=M==null?void 0:M.related_to)!=null&&Q.length||(fe=e.appendix)!=null&&fe.length),he=[];(be.length||O.text.length||c)&&he.push({id:"fulltext",label:"全文",count:be.length?f(`${be.length} ${Le}`):void 0}),O.groups.length&&he.push({id:"images",label:H?"館藏":"影印",count:D}),Be&&he.push({id:"lineage",label:"版本源流"}),le.length&&he.push({id:"collections",label:"收入叢編",count:le.length}),(G=e.location_history)!=null&&G.length&&he.push({id:"provenance",label:"流轉歷史"});const Ne=R=>(p==null?void 0:p(R))??null,Te=be[0],Re=Te?Ne(Te.file):null,P=k?be:be.slice(0,df),me=(R,se,ue)=>R?t.jsx("a",{className:ue,href:R.href??"#",onClick:R.onClick?ae=>{ae.metaKey||ae.ctrlKey||(ae.preventDefault(),R.onClick())}:void 0,children:se}):t.jsx("span",{className:ue,children:se}),te=t.jsxs(t.Fragment,{children:[(be.length>0||O.text.length>0||c)&&t.jsxs(Ge,{id:"fulltext",title:"全文",meta:be.length>0?t.jsx(He,{items:[f(`${be.length} ${Le}`),(ve=l==null?void 0:l.source)!=null&&ve.name?f(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[c&&!Te&&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"})]}),Te&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:f(`從${si(Te.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:f((Te.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),me(Re,t.jsxs(t.Fragment,{children:[f("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),be.length>1&&t.jsx("ul",{className:"bim-d-chap",children:P.map(R=>{const[se,ue]=si(R.title);return t.jsx("li",{children:me(Ne(R.file),t.jsxs(t.Fragment,{children:[se&&t.jsx("b",{children:f(se)}),f(ue||R.file)]}))},R.file)})}),be.length>P.length&&t.jsx(Gt,{label:`展開其餘 ${be.length-P.length} ${Le}`,onClick:()=>$(!0)}),O.text.length>0&&t.jsxs(t.Fragment,{children:[(be.length>0||c)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:f("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:O.text.map((R,se)=>t.jsx(fo,{item:R,siblings:O.text,listedVolumeCounts:oe},`${R.id||R.url||R.name}-${se}`))})})]})]}),O.groups.length>0&&t.jsx(Ge,{id:"images",title:H?"館藏":"影印",meta:t.jsx(He,{items:[O.groups.length>1?f(`${O.groups.length} 組`):"",f(`${D} 處`)]}),children:t.jsx(Ol,{groups:O.groups,listedVolumeCounts:oe})}),Be&&t.jsx(Ge,{id:"lineage",title:"版本源流",meta:($e=M==null?void 0:M.derived_from)!=null&&$e.length?f("據版本傳承著錄"):void 0,action:L?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":f("源流視圖"),children:[t.jsx("button",{type:"button","aria-pressed":S==="flow",onClick:()=>C("flow"),children:f("卡片")}),t.jsx("button",{type:"button","aria-pressed":S==="graph",onClick:()=>C("graph"),children:f("關係圖")})]}):void 0,children:S==="graph"&&L?t.jsx(mo,{graph:L,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(R,se)=>t.jsx(Oe,{id:R,label:f(se),onNavigate:o,renderLink:r,dense:!0})}):t.jsx(uf,{data:e,heading:Y||ce,yearText:ee,refName:E,onNavigate:o,renderLink:r})}),le.length>0&&t.jsx(Ge,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:le.map((R,se)=>{var Ee,We;const ue=typeof R=="string"?R:R.id,ae=typeof R=="string"?[]:on(R.volume_index),ie=w.get(ue),Se=(ie==null?void 0:ie._member_count)||((Ee=ie==null?void 0:ie.books)==null?void 0:Ee.length)||((We=ie==null?void 0:ie.contained_works)==null?void 0:We.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Oe,{id:ue,label:ie?f(ie.title):ue,onNavigate:o,renderLink:r,dense:!0}),ae.length>0&&t.jsx(pf,{volumes:ae,unit:m.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Se?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Se>0&&f(`全 ${Se} ${m.unit.bu}`)})]},`${ue}-${se}`)})})})}),(J=e.location_history)!=null&&J.length?t.jsx(Ge,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((R,se)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(R.name)}),([R.start_date,R.end_date].filter(Boolean).join("—")||R.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(He,{items:[[R.start_date,R.end_date].filter(Boolean).join("—"),R.description?f(R.description):""]})})]},se))})}):null,he.length===0&&t.jsx(Ge,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:f("尚未著錄該版本的影印、全文與收藏信息。")})})]}),ke=j.findIndex(R=>R.id===e.id),we=T.length<=Vr,K=we&&ke>=0?j.slice(Math.max(0,ke-Ur),ke+Ur+1):j.filter(R=>R.id!==e.id),N=t.jsxs(t.Fragment,{children:[g&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:f(m.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Oe,{id:g.id,label:f(g.title),onNavigate:o,renderLink:r})}),t.jsx(He,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(g.authors||[]).slice(0,2).map(R=>`${R.dynasty?`〔${f(R.dynasty)}〕`:""}${f(R.name)}`),f(mt(g,m.unit.juan)),g._edition_count?f(`${g._edition_count} 種版本`):""]}),((_e=g.description)==null?void 0:_e.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:f(g.description.text.replace(/[#*_>`[\]]/g,""))})]}),U>0&&K.length>0&&t.jsxs("div",{children:[t.jsx(St,{id:"siblings",timeline:!0,title:we?"同作品版本":m.relation.siblingVersions,meta:f(we?"按年代":`${U} 種`),cap:K.length,items:K.map(R=>R.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(R.edition||R.title||R.id)}):t.jsx(Oe,{id:R.id,label:f(R.edition||R.title||R.id),onNavigate:o,renderLink:r,dense:!0})),metas:K.map(R=>[R.year!=null?R.year<0?`前${-R.year}`:String(R.year):"",R.id===e.id?f("本頁"):""].filter(Boolean).join(" ")),currentIndex:K.findIndex(R=>R.id===e.id)}),g&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Oe,{id:g.id,label:f(`在作品頁看全部 ${T.length} 種 →`),onNavigate:o,renderLink:r,dense:!0})})]})]}),q=e.work_id?t.jsx(Bs,{caption:m.section.belongsToWork,children:t.jsx(Oe,{id:e.work_id,label:g?f(g.title):" ",onNavigate:o,renderLink:r,dense:!0})}):void 0;return t.jsx(dn,{railTop:a,back:d,up:q,nav:he,railLinks:u,main:te,card:Z,side:N})};function pf({volumes:e,unit:n}){const{convert:o}=X();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[o(`第 ${Mn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),o(`${e.length} ${n}`)]})]})}function uf({data:e,heading:n,yearText:o,refName:r,onNavigate:s,renderLink:l}){var y;const{convert:c}=X(),p=e.lineage,a=(p==null?void 0:p.derived_from)||[],d=a.filter(j=>j.ref_type!=="book"),u=a.filter(j=>j.ref_type==="book"&&j.relation==="底本"),m=a.filter(j=>j.ref_type==="book"&&j.relation!=="底本"),f=(p==null?void 0:p.related_to)||[],g=a.length>0||f.length>0,b=j=>j&&Yr[j]?c(`(${Yr[j]})`):"",w=(j,h)=>t.jsx(Oe,{id:j,label:c(h||j),onNavigate:s,renderLink:l,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[g&&t.jsxs("ol",{className:"bim-d-lf-list",children:[d.map((j,h)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:c(j.relation||"祖本")}),t.jsx("span",{className:"bim-d-lf-name",children:c("擬構祖本")}),j.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[c(j.evidence),b(j.confidence)]})]})},`a-${h}`)),u.map((j,h)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:c(j.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:w(j.ref,r(j.ref))}),j.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[c(j.evidence),b(j.confidence)]})]})},`b-${h}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:c("本版")}),t.jsx("span",{className:"bim-d-lf-name",children:n}),o&&t.jsx("span",{className:"bim-d-lf-yr",children:c(o)})]}),m.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:m.map((j,h)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:c(j.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:w(j.ref,r(j.ref))}),j.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[c(j.evidence),b(j.confidence)]})]},h))})]}),f.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:c("翻刻 · 衍生")}),t.jsx("span",{className:"bim-d-lf-chips",children:f.map((j,h)=>t.jsxs("span",{className:"bim-d-lf-chip",title:j.evidence?c(j.evidence):void 0,children:[w(j.book_id,r(j.book_id)),t.jsx("span",{className:"bim-d-meta",children:c(j.relation)})]},h))})]})]}),(y=e.appendix)==null?void 0:y.map((j,h)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:c("附記")})," ",c(j.title)]}),t.jsx(ft,{text:j.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${h}`)),(p==null?void 0:p.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:c(p.note)})]})}const en=16,xf=200,ff=16,Ul=({data:e,catalog:n,transport:o,onNavigate:r,renderLink:s,catalogAction:l,railTop:c,back:p,railLinks:a})=>{var ke,we,K,N,q,xe,ye;const d=ge(),{convert:u}=X(),[m,f]=x.useState(""),[g,b]=x.useState(!1),[w,y]=x.useState(null),[j,h]=x.useState(""),[v,_]=x.useState(!1),k=x.useMemo(()=>Ts(e,n),[e,n]),[$,S]=x.useState(new Map),C=!!o&&k.rows.length>0&&k.rows.length<=xf,L=C&&(k.rows.length<=en||v),I=L&&k.rows.every(B=>!B.id||$.has(B.id)),T=B=>{var re;return Ci(B?(re=$.get(B))==null?void 0:re.l1:void 0)},U=x.useMemo(()=>{const B=m.trim(),re=B?u(B):"";return k.rows.filter(Q=>{var G,ve;if(j&&Ci(Q.id?(G=$.get(Q.id))==null?void 0:G.l1:void 0)!==j)return!1;if(!re)return!0;const fe=Q.id&&((ve=$.get(Q.id))==null?void 0:ve.title)||Q.title;return u(fe).includes(re)||(Q.subItems||[]).some($e=>u($e).includes(re))})},[k.rows,m,j,$,u]),M=g?U:U.slice(0,en),F=x.useMemo(()=>(L?k.rows:M).filter(B=>B.id&&!$.has(B.id)).map(B=>B.id),[L,k.rows,M,$]);x.useEffect(()=>{if(!o||F.length===0)return;let B=!1;const re=F.slice(0,ff);return Promise.all(re.map(Q=>o.getItem(Q).then(fe=>{var $e,J;const G=fe??{},ve={title:G.title,edition:G.edition,authors:G.authors,measure:fe?mt(fe,d.unit.juan):void 0,versionCount:G._edition_count??(($e=G.books)==null?void 0:$e.length),l1:((J=G.classification)==null?void 0:J.l1)||void 0};return[Q,ve]}).catch(()=>[Q,{}]))).then(Q=>{B||S(fe=>{const G=new Map(fe);for(const[ve,$e]of Q)G.set(ve,$e);return G})}),()=>{B=!0}},[o,F,d.unit.juan]);const O=(e.contained_in||[])[0];x.useEffect(()=>{if(!O){y(null);return}if(y({id:O}),!o)return;let B=!1;return o.getItem(O).then(re=>{B||y({id:O,title:re==null?void 0:re.title})}).catch(()=>{}),()=>{B=!0}},[o,O]);const D=x.useMemo(()=>Wl(e.resources,e.resource_groups),[e.resources,e.resource_groups]),H=D.text.length+D.groups.reduce((B,re)=>B+re.rows.length+re.mirrors.length,0),z=e.contained_works||[],pe=new Set(k.rows.map(B=>B.id).filter(Boolean)),A=z.length>0&&!z.every(B=>pe.has(B.id)),oe=(()=>{const B=k.rows.map(re=>re.edition).filter(Boolean);return B.length>1&&new Set(B).size===1})(),E=k.rows.some(B=>B.volumes.length>0||B.expected!=null),W=e._member_count||((ke=e.books)==null?void 0:ke.length)||z.length,ce=mt(e,d.unit.juan),Y=e.count,ee=B=>typeof B=="number"&&Number.isFinite(B)?B:null,Z=ee(Y==null?void 0:Y.juan)??ee((we=e.juan_count)==null?void 0:we.number),le=ee(Y==null?void 0:Y.ce)??(k.totalVolumes||null),be=[{value:k.rows.length,label:"子目"},{value:Z??0,label:d.unit.juan},{value:le??0,label:d.unit.volume}],Le=x.useMemo(()=>{var Q,fe;const B=[];if((Q=e.publication_info)!=null&&Q.details&&B.push({label:"刊印",value:u(e.publication_info.details)}),W&&W!==k.rows.length){const G=e._member_type==="Book"?"所收版本":e._member_type==="Work"?"所收作品":"成員";B.push({label:u(G),value:`${W} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")})}const re=[ee(Y==null?void 0:Y.zhong)!=null?`${Y.zhong} 種`:"",ee(Y==null?void 0:Y.han)!=null?`${Y.han} 函`:""].filter(Boolean);return re.length&&B.push({label:"應收",value:u(re.join(" "))}),Z==null&&ce&&B.push({label:"卷帙",value:u(ce),title:(fe=e.juan_count)!=null&&fe.description?u(e.juan_count.description):void 0}),B},[e,W,k.rows.length,Z,ce,Y,u,d]),Be=x.useMemo(()=>{if(!I)return[];const B=new Map;for(const Q of k.rows){const fe=T(Q.id);fe&&B.set(fe,(B.get(fe)??0)+1)}const re=sn.filter(Q=>(B.get(Q.key)??0)>0);return re.length<2?[]:[{key:"",label:`${d.catalog.all} ${k.rows.length}`},...re.map(Q=>({key:Q.key,label:`${Q.label} ${B.get(Q.key)}`}))]},[I,k.rows,$,d]),he=x.useMemo(()=>{if(!I||!k.rows.some(fe=>fe.volumes.length>0))return null;const B=[],re=k.rows.filter(fe=>fe.volumes.length>0).map(fe=>({k:T(fe.id)??"",from:Math.min(...fe.volumes),to:Math.max(...fe.volumes)})).sort((fe,G)=>fe.from-G.from);for(const fe of re){const G=fe.to-fe.from+1,ve=B[B.length-1];ve&&ve.key===fe.k?(ve.to=Math.max(ve.to,fe.to),ve.n+=G):B.push({key:fe.k,from:fe.from,to:fe.to,n:G})}const Q=re.reduce((fe,G)=>Math.max(fe,G.to),0);return B.length>1&&B.some(fe=>fe.key)?{segs:B,last:Q}:null},[I,k.rows,$]),Ne=(K=e.description)==null?void 0:K.text,Te=t.jsx(pn,{kind:"叢編",title:u(e.title),byline:t.jsx(xo,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(He,{items:[e.subtype==="work_collection"?u("作品集"):"",(N=e.publication_info)!=null&&N.year?u(e.publication_info.year):""]}),description:Ne||(q=e.history)!=null&&q.length?t.jsxs(t.Fragment,{children:[Ne&&t.jsx(ft,{text:Ne,style:{fontSize:15,lineHeight:1.85}}),(xe=e.history)!=null&&xe.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((B,re)=>t.jsx("li",{children:u(B)},re))}):null]}):void 0,clampDescription:Vi(Ne)||(((ye=e.history)==null?void 0:ye.length)??0)>2?6:void 0,stats:be,facts:Le,foot:t.jsx(un,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:he&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:u("全帙冊次分佈")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":u("全帙冊次分佈"),children:he.segs.map((B,re)=>{const Q=sn.find(fe=>fe.key===B.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!Q,title:Q?u(`${Q.label} 第 ${B.from}–${B.to} 冊`):void 0,"aria-label":u(Q?`只看${Q.label}`:"未分類"),"aria-pressed":!!Q&&j===B.key,style:{flexGrow:B.n,background:i(Q?Q.token:"rule")},onClick:()=>{Q&&(h(j===B.key?"":B.key),b(!1))}},re)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:u(`第 1 ${d.unit.volume}`)}),t.jsx("span",{children:u("點色段篩選部類")}),t.jsx("span",{children:u(`第 ${he.last} ${d.unit.volume}`)})]})]})}),Re=[];k.rows.length&&Re.push({id:"titles",label:"子目",count:k.rows.length}),H&&Re.push({id:"resources",label:"影印與全文",count:H}),A&&Re.push({id:"works",label:d.section.containedWorks,count:z.length});const P=t.jsxs(t.Fragment,{children:[k.rows.length>0&&t.jsxs(Ge,{id:"titles",title:"子目",meta:t.jsx(He,{items:[u(`${k.rows.length} ${d.unit.items}`),k.totalVolumes?u(`全帙 ${k.totalVolumes} ${d.unit.volume}`):"",U.length!==k.rows.length?u(`當前 ${U.length} ${d.unit.items}`):""]}),action:l,children:[(k.rows.length>en||Be.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[Be.length>0&&t.jsx(Wn,{items:Be,value:j,onChange:B=>{h(B),b(!1)}}),C&&k.rows.length>en&&!I&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:v,onClick:()=>_(!0),title:u(`將載入全部 ${k.rows.length} ${d.unit.items}`),children:u(v?"正在按部類分組…":"按部類分組")}),t.jsx("span",{className:"bim-d-spacer"}),k.rows.length>en&&t.jsx("input",{type:"search",className:"bim-d-find",value:m,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:B=>{f(B.target.value),b(!1)}})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[E&&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:M.map((B,re)=>{var _e;const Q=B.id?$.get(B.id):void 0,fe=Q!=null&&Q.title&&B.title===B.id?Q.title:B.title,G=((Q==null?void 0:Q.authors)||[]).find(R=>R&&R.name),ve=[G?`${G.dynasty?`〔${u(G.dynasty)}〕`:""}${u(G.name)}${G.role?` ${u(G.role)}`:""}`:"",Q!=null&&Q.measure?u(Q.measure):"",(_e=B.subItems)!=null&&_e.length?B.subItems.map(R=>u(R)).join("、"):"",(Q!=null&&Q.edition||B.edition)&&!oe?u((Q==null?void 0:Q.edition)||B.edition||""):""].filter(Boolean),$e=sn.find(R=>R.key===T(B.id)),J=B.volumes.length>0?u(`第 ${Mn(B.volumes,d.unit.volume)} ${d.unit.volume}`):B.expected!=null?u(`${B.found??0}/${B.expected} ${d.unit.volume}`):"";return t.jsxs("tr",{children:[E&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${J?"":" bim-d-zt-blank"}`,children:[$e&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:i($e.token)}}),J||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[B.id?t.jsx(Oe,{id:B.id,label:u(fe),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(fe)}),ve.length>0?t.jsx(He,{items:ve}):B.id&&!Q&&o?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Q!=null&&Q.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Q!=null&&Q.versionCount?u(`${Q.versionCount} 種`):""})]},`${B.id??B.title}-${re}`)})})]}),M.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),U.length>M.length&&t.jsx(Gt,{label:`展開其餘 ${U.length-M.length} ${d.unit.items}`,onClick:()=>b(!0)})]}),H>0&&t.jsxs(Ge,{id:"resources",title:"影印與全文",meta:u(`${H} 處`),children:[D.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[D.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:D.text.map((B,re)=>t.jsx(fo,{item:B,siblings:D.text},`${B.id||B.url||B.name}-${re}`))})})]}),t.jsx(Ol,{groups:D.groups})]}),k.rows.length===0&&H===0&&t.jsx(Ge,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),me=A?t.jsx(St,{id:"works",title:d.section.containedWorks,meta:u(`${z.length} 種`),cap:12,items:z.map(B=>t.jsx(Oe,{id:B.id,label:u(B.title),onNavigate:r,renderLink:s,dense:!0}))}):null,te=w?t.jsx(Bs,{caption:"上級叢編",children:t.jsx(Oe,{id:w.id,label:u(w.title||w.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(dn,{railTop:c,back:p,up:te,nav:Re,railLinks:a,main:P,card:Te,side:me})},mf=16,li=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Kr(e){if(!e)return li.length;const n=li.indexOf(e);return n===-1?li.length:n}const gf={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function bt(e){return e==null?"":e<0?`前${-e}`:String(e)}const hf={秦:[-221,-207],西漢:[-202,8],西汉:[-202,8],東漢:[25,220],东汉:[25,220],漢:[-202,220],汉:[-202,220],三國:[220,280],三国:[220,280],西晉:[265,316],西晋:[265,316],東晉:[317,420],东晋:[317,420],隋:[581,618],唐:[618,907],五代:[907,960],北宋:[960,1127],南宋:[1127,1279],宋:[960,1279],遼:[916,1125],辽:[916,1125],金:[1115,1234],元:[1271,1368],明:[1368,1644],清:[1636,1912]},Yl=({data:e,transport:n,onNavigate:o,renderLink:r,railTop:s,back:l,railLinks:c})=>{var me,te,ke,we,K;const p=ge(),{convert:a}=X(),[d,u]=x.useState("全部"),[m,f]=x.useState(!1),[g,b]=x.useState("default"),[w,y]=x.useState(new Map),j=x.useMemo(()=>(e.works||[]).map(N=>{const q=w.get(N.work_id);return{id:N.work_id,title:(q==null?void 0:q.title)??N.title??N.work_id,role:N.role||"",cls:Hi(N.role),versionCount:q==null?void 0:q.versionCount,section:q==null?void 0:q.cls,l1:q==null?void 0:q.l1,measure:q==null?void 0:q.measure,hasImage:q==null?void 0:q.hasImage,loaded:!!(q!=null&&q.loaded)}}),[e.works,w]),h=x.useMemo(()=>zs((e.works||[]).map(N=>N.role)),[e.works]),v=x.useMemo(()=>{const N=d==="全部"?j:j.filter(q=>q.cls===d);return g==="versions"?[...N].sort((q,xe)=>(xe.versionCount??-1)-(q.versionCount??-1)):N},[j,d,g]),_=m?v:v.slice(0,mf),k=x.useMemo(()=>_.filter(N=>!w.has(N.id)).map(N=>N.id),[_,w]);x.useEffect(()=>{if(!n||k.length===0)return;let N=!1;return Promise.all(k.map(q=>n.getItem(q).then(xe=>{var Q,fe,G,ve,$e;const ye=xe??{},B=ye._edition_count??(((Q=ye.books)==null?void 0:Q.length)??0)+(((fe=ye.collections)==null?void 0:fe.length)??0),re=[(G=ye.classification)==null?void 0:G.l1,(ve=ye.classification)==null?void 0:ve.l2].filter(Boolean).join(" ");return[q,{id:q,title:ye.title,versionCount:B,loaded:!0,cls:re||void 0,l1:(($e=ye.classification)==null?void 0:$e.l1)||void 0,measure:xe&&mt(xe,p.unit.juan)||void 0,hasImage:!!(ye.has_image??ye._has_image)}]}).catch(()=>[q,{id:q,loaded:!0}]))).then(q=>{N||y(xe=>{const ye=new Map(xe);for(const[B,re]of q)ye.set(B,re);return ye})}),()=>{N=!0}},[n,k,p.unit.juan]);const $=x.useMemo(()=>{const N=new Map;for(const q of e.alt_names||[]){const xe=q.type||p.section.aliases;N.has(xe)||N.set(xe,[]),N.get(xe).push(q.name)}return[...N.entries()].sort((q,xe)=>Kr(q[0])-Kr(xe[0])).map(([q,xe])=>({label:q,names:xe}))},[e.alt_names,p]),S=e.birth_year??((me=e.dates)==null?void 0:me.birth)??void 0,C=e.death_year??((te=e.dates)==null?void 0:te.death)??void 0,L=(ke=e.dates)==null?void 0:ke.floruit,I=S!=null||C!=null?`${bt(S)||"?"}—${bt(C)||"?"}`:Array.isArray(L)&&L.length===2&&L.every(N=>Number.isFinite(N))?`活躍於 ${bt(L[0])}—${bt(L[1])}`:"",T=new Set(["本名","字","號","号"]),U=$.filter(N=>T.has(N.label)),M=$.filter(N=>!T.has(N.label)),F=M.reduce((N,q)=>N+q.names.length,0),O=x.useMemo(()=>{const N=[];for(const xe of U)N.push({label:xe.label,value:xe.names.map(ye=>a(ye)).join("、")});const q=(e.works||[]).length;return q&&N.push({label:"著作",value:`${q} ${a("種")}`}),N},[e.works,U,a]),D=N=>{var q;return(q=$.find(xe=>N.includes(xe.label)))==null?void 0:q.names[0]},H=D(["字"]),z=D(["號","号"]),pe=[H?`字${H}`:"",z?`號${z}`:""].filter(Boolean).join(","),A=e.native_place,oe=e.dynasty?hf[e.dynasty]:void 0,E=(()=>{if(!oe||S==null||C==null||C<S)return null;const[N,q]=oe,xe=Math.max(S,N),ye=Math.min(C,q);if(ye<=xe)return null;const B=q-N;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":a(`${bt(S)}—${bt(C)},一生 ${C-S+1} 年`),children:t.jsx("i",{style:{left:`${(xe-N)/B*100}%`,width:`${(ye-xe)/B*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:a(`${bt(N)} ${e.dynasty}`)}),t.jsx("span",{children:a(`一生 ${C-S+1} 年`)}),t.jsx("span",{children:bt(q)})]})]})})(),W=x.useMemo(()=>{if(!n||j.length===0||j.some(xe=>!xe.loaded))return null;const N=new Map;for(const xe of j){const ye=Ci(xe.l1);ye&&N.set(ye,(N.get(ye)??0)+1)}const q=sn.map(xe=>({...xe,n:N.get(xe.key)??0})).filter(xe=>xe.n>0);return q.length?q:null},[j,n]),ce=t.jsxs(pn,{kind:gf[e.subtype]??"人物",title:a(e.primary_name||e.title),subtitle:pe?a(pe):void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(He,{items:[e.dynasty?a(e.dynasty):"",I?a(I):"",A?a(`${A}人`):""]}),E]}),description:(we=e.description)!=null&&we.text?t.jsx(ft,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Vi((K=e.description)==null?void 0:K.text)?6:void 0,facts:O,foot:t.jsx(un,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[F>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:a(`更多別名(${F})`)}),t.jsx("dl",{children:M.map(N=>t.jsxs(x.Fragment,{children:[t.jsx("dt",{children:a(N.label)}),t.jsx("dd",{children:N.names.map(q=>a(q)).join("、")})]},N.label))})]}),W&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:a("著作分佈")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:W.map(N=>t.jsx("i",{style:{flexGrow:N.n,background:i(N.token)}},N.key))}),t.jsx("div",{className:"bim-d-dist-key",children:W.map(N=>t.jsxs("span",{children:[t.jsx("i",{style:{background:i(N.token)}}),a(N.label)," ",N.n]},N.key))})]})]}),Y=x.useMemo(()=>j.filter(N=>N.loaded&&(N.versionCount??0)>0).sort((N,q)=>(q.versionCount??0)-(N.versionCount??0)).slice(0,3),[j]),ee=!!n&&j.length>=3&&_.some(N=>!N.loaded),Z=d==="全部"&&(ee||Y.length>=2),le=e.external_ids||{},be=[];le.cbdb_id!=null&&be.push({label:"CBDB",id:String(le.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${le.cbdb_id}`,note:le.cbdb_match==="auto"?"自動匹配":void 0});const Le=le.wikidata_id;Le&&be.push({label:"Wikidata",id:Le,href:`https://www.wikidata.org/wiki/${Le}`});const Be=le.viaf_id;Be&&be.push({label:"VIAF",id:Be,href:`https://viaf.org/viaf/${Be}`});const he=h.map(N=>({key:N.cls,label:`${N.label} ${N.count}`})),Ne=[...Z&&!ee?[{id:"featured",label:"著作舉要",count:Y.length}]:[],...j.length?[{id:"works",label:"全部著作",count:j.length}]:[],...be.length?[{id:"external",label:"站外資料",count:be.length}]:[]],Te=Z?t.jsxs(Ge,{id:"featured",title:"著作舉要",children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:a("存世版本最多的三部")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":ee||void 0,children:[ee&&[0,1,2].map(N=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},N)),!ee&&Y.map(N=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Oe,{id:N.id,label:a(N.title),onNavigate:o,renderLink:r,dense:!0})}),t.jsx(He,{items:[N.section?a(N.section):"",N.measure?a(N.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:N.versionCount}),t.jsx("span",{children:a("種版本")}),N.hasImage&&t.jsx("span",{className:"bim-d-flag",children:a("有影印")})]})]},N.id))]})]}):null,Re=j.length===0?t.jsx(Ge,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該人物的關聯作品。")})}):t.jsxs(t.Fragment,{children:[Te,t.jsxs(Ge,{id:"works",title:"著作",meta:t.jsx(He,{items:[a(`共 ${j.length} 種`),v.length!==j.length?a(`當前 ${v.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[he.length>1&&t.jsx(Wn,{items:he,value:d,onChange:N=>{u(N),f(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":g==="versions",onClick:()=>{g==="default"&&f(!0),b(N=>N==="default"?"versions":"default")},children:a(g==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("作品")}),t.jsx("th",{children:a("部類")}),t.jsx("th",{children:a("職任")}),t.jsx("th",{children:a("存世版本")}),t.jsx("th",{"aria-label":a("影印")})]})}),t.jsx("tbody",{children:_.map(N=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Oe,{id:N.id,label:a(N.title),onNavigate:o,renderLink:r,dense:!0}),N.measure?t.jsx(He,{items:[a(N.measure)]}):!N.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${N.section||N.loaded?"":" bim-d-zt-blank"}`,children:N.section?a(N.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${N.role?"":" bim-d-zt-blank"}`,children:N.role?a(N.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${N.loaded?"":" bim-d-zt-blank"}`,children:N.loaded?N.versionCount?a(`${N.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:a("未著錄")}):""}),t.jsx("td",{className:N.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:N.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:a("有影印")})})]},N.id))})]}),_.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a("該職任下的著作尚未著錄。")}),v.length>_.length&&t.jsx(Gt,{label:`展開其餘 ${v.length-_.length} 種著作`,onClick:()=>f(!0)})]})]}),P=be.length>0?t.jsx(St,{id:"external",title:"站外資料",items:be.map(N=>t.jsxs("a",{href:N.href,target:"_blank",rel:"noopener noreferrer",children:[N.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:be.map(N=>N.id),foot:le.cbdb_id!=null&&le.cbdb_match==="auto"?a("CBDB 為自動匹配,未經人工核對"):void 0}):null;return t.jsx(dn,{railTop:s,back:l,nav:Ne,railLinks:c,main:Re,card:ce,side:P})},go="(max-width: 719px)",bf=`${go}, (pointer: coarse)`,Kl=`
|
|
1018
1027
|
.bim-ct {
|
|
1019
1028
|
display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
|
|
1020
1029
|
max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
|
|
@@ -1122,7 +1131,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
|
|
|
1122
1131
|
.bim-ct-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
1123
1132
|
}
|
|
1124
1133
|
|
|
1125
|
-
@media ${
|
|
1134
|
+
@media ${go} {
|
|
1126
1135
|
.bim-ct { display: block; padding: 12px 16px 40px; }
|
|
1127
1136
|
.bim-ct-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
|
|
1128
1137
|
.bim-ct-lrow > a { grid-template-columns: minmax(0, 1fr); }
|
|
@@ -1147,7 +1156,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
|
|
|
1147
1156
|
}
|
|
1148
1157
|
|
|
1149
1158
|
/* 点击目标 ≥44px(Q5):触屏与窄屏 */
|
|
1150
|
-
@media ${
|
|
1159
|
+
@media ${bf} {
|
|
1151
1160
|
.bim-ct-row { min-height: 44px; }
|
|
1152
1161
|
.bim-ct-tw { width: 44px; }
|
|
1153
1162
|
.bim-ct-pg { min-width: 44px; height: 44px; }
|
|
@@ -1157,4 +1166,4 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
|
|
|
1157
1166
|
:root[data-layout="boxed"] .bim-ct-side { border: ${i("fr-bd")}; background: ${i("fr-bg")}; padding: 14px 8px; }
|
|
1158
1167
|
:root[data-layout="boxed"] .bim-ct-head { padding: ${i("fr-hd-pad")}; border: ${i("fr-bd")}; border-bottom: ${i("fr-hd-bd")}; background: ${i("fr-bg")}; margin: 0; }
|
|
1159
1168
|
:root[data-layout="boxed"] .bim-ct-main > .bim-ct-search { margin-top: 14px; }
|
|
1160
|
-
`,en="未分類",at="all",ao=20;function ln(e){if(!e)return[];const n=[];for(const o of[e.l1,e.l2,e.l3,e.l4]){const r=(o??"").trim();if(!r)break;n.push(r)}return n}function of(e){const n=ln(e);return n.length?n.join("/"):en}function rf(e){const n=ln(e);return n.length?n.map((o,r)=>n.slice(0,r+1).join("/")):[en]}function sf(e,n=[]){const o=new Map;n.forEach((p,a)=>{const d=[p.cata_l1,p.cata_l2,p.cata_l3,p.cata_l4].filter(u=>!!u);d.forEach((u,m)=>{const x=d.slice(0,m+1).join("/");o.has(x)||o.set(x,a)})});const r=new Map;let s=0;for(const p of e){const a=ln(p.classification);if(!a.length){s++;continue}let d=r;a.forEach((u,m)=>{const x=a.slice(0,m+1).join("/");let g=d.get(u);g||(g={id:x,label:u,count:0,children:new Map},d.set(u,g)),g.count++,d=g.children})}const l=p=>[...p.values()].sort((a,d)=>{const u=o.get(a.id)??1/0,m=o.get(d.id)??1/0;return u!==m?u-m:a.label.localeCompare(d.label,"zh")}).map(a=>{const d={id:a.id,label:a.label,count:a.count};return a.children.size&&(d.children=l(a.children)),d}),c=l(r);return s>0&&c.push({id:en,label:en,count:s}),c}function Tt(e,n){if(!n)return[];for(const o of e){if(o.id===n)return[o];if(o.children){const r=Tt(o.children,n);if(r.length)return[o,...r]}}return[]}function co(e){return e.reduce((n,o)=>n+o.count,0)}function lf(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function af(e){var p;const n={id:e.id,title:e.title||e.id},o=e.juan_count,r=typeof o=="number"?o:o==null?void 0:o.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(a=>a==null?void 0:a.name).map(a=>{const d=a.dynasty||(e.authors.length===1?e.dynasty:void 0);return d?{name:a.name,dynasty:d}:{name:a.name}});s.length&&(n.authors=s);const l=lf(typeof e.description=="string"?e.description:(p=e.description)==null?void 0:p.text);l&&(n.summary=l);const c=ln(e.classification);return c.length&&(n.classification=c),n}function cf(e,n){const o=e.summary?0:1,r=n.summary?0:1;return o!==r?o-r:e.title.localeCompare(n.title,"zh")}function df(e,n=ao){return Math.max(1,Math.ceil(e/n))}function Pl(e,n,o=2){if(n<=1)return[1];const r=new Set([1,n]);for(let c=e-o;c<=e+o;c++)c>=1&&c<=n&&r.add(c);const s=[...r].sort((c,p)=>c-p),l=[];return s.forEach((c,p)=>{if(p>0){const a=c-s[p-1];a===2?l.push(c-1):a>2&&l.push(null)}l.push(c)}),l}const pf=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function uf(e,n,o){const r=[];o&&r.push({id:at,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,c)=>{var p;for(const a of l){const d=(p=a.children)!=null&&p.length?a.children:null;r.push({id:a.id,parentId:c,hasChildren:!!d,firstChildId:d?d[0].id:null}),d&&n.has(a.id)&&s(d,a.id)}};return s(e,null),r}function Ol({tree:e,selectedId:n,onSelect:o,allLabel:r="全部",label:s="分類"}){const{convert:l}=V(),c=f.useRef(null),p=n&&n!==at?n:null,a=r!==null,[d,u]=f.useState(()=>{const k=new Set;for(const _ of Tt(e,p))k.add(_.id);return k});f.useEffect(()=>{const k=Tt(e,p);k.length&&u(_=>{if(k.every(z=>_.has(z.id)))return _;const S=new Set(_);for(const z of k)S.add(z.id);return S})},[e,p]);const m=f.useMemo(()=>uf(e,d,a),[e,d,a]),[x,g]=f.useState(null);f.useEffect(()=>{g(null)},[n]);const b=p??(a?at:null),w=f.useMemo(()=>{var S;const k=new Set(m.map(z=>z.id));if(x&&k.has(x))return x;if(b&&k.has(b))return b;const _=Tt(e,p).map(z=>z.id).filter(z=>k.has(z));return _.length?_[_.length-1]:((S=m[0])==null?void 0:S.id)??null},[m,x,b,e,p]),y=f.useCallback((k,_)=>{u(S=>{const z=S.has(k),N=_??!z;if(N===z)return S;const R=new Set(S);return N?R.add(k):R.delete(k),R})},[]),j=f.useCallback(k=>{g(k),requestAnimationFrame(()=>{var S;const _=Array.from(((S=c.current)==null?void 0:S.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===k);_==null||_.focus()})},[]),h=f.useCallback((k,_)=>{_&&y(k,!0),o(k)},[o,y]),v=f.useCallback(k=>{const _=k.target.closest("[data-ct-id]");if(!_)return;const S=_.dataset.ctId,z=m.findIndex(C=>C.id===S);if(z<0)return;const N=m[z];let R=null;switch(k.key){case"ArrowDown":R=m[Math.min(m.length-1,z+1)].id;break;case"ArrowUp":R=m[Math.max(0,z-1)].id;break;case"Home":R=m[0].id;break;case"End":R=m[m.length-1].id;break;case"ArrowRight":if(!N.hasChildren)break;d.has(S)?R=N.firstChildId:y(S,!0);break;case"ArrowLeft":N.hasChildren&&d.has(S)?y(S,!1):R=N.parentId;break;case"Enter":case" ":k.preventDefault(),h(S,N.hasChildren);return;default:return}k.preventDefault(),R&&R!==S&&j(R)},[m,d,y,j,h]),$=(k,_)=>k.map((S,z)=>{var L;const N=(L=S.children)!=null&&L.length?S.children:null,R=!!N&&d.has(S.id),C=S.id===p,H=_===1&&k.length>1&&z===k.length-1;return t.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":N?R:void 0,"aria-selected":C,tabIndex:w===S.id?0:-1,"data-ct-id":S.id,className:H?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{g(S.id),h(S.id,!!N)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:N?M=>{M.stopPropagation(),g(S.id),y(S.id)}:void 0,children:N?t.jsx(pf,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(S.label)}),t.jsx("span",{className:"bim-ct-n",children:S.count.toLocaleString("en-US")})]}),R&&t.jsx("ul",{role:"group",children:$(N,_+1)})]},S.id)});return t.jsxs("ul",{ref:c,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:v,children:[a&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:w===at?0:-1,"data-ct-id":at,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{g(at),o(at)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),t.jsx("span",{className:"bim-ct-lb",children:l(r)}),t.jsx("span",{className:"bim-ct-n",children:co(e).toLocaleString("en-US")})]})}),$(e,1)]})}const Dl=e=>`/item/${encodeURIComponent(e)}`;function xf(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Hl(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function Gl({work:e,href:n}){var c,p;const{convert:o}=V(),r=Hl(e.juan),s=((c=e.authors)==null?void 0:c.filter(a=>a.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:n,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:o(e.title)}),r&&t.jsx("span",{className:"bim-ct-juan",children:o(r)})]}),s.length>0&&t.jsx("span",{className:"bim-ct-by",children:s.map((a,d)=>t.jsxs(f.Fragment,{children:[d>0&&"、",a.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(a.dynasty),"〕"]}),o(a.name)]},d))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:o(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(a=>o(a)).join(" · ")})]})})}function Ul({work:e,href:n}){var c,p;const{convert:o}=V(),r=Hl(e.juan),s=((c=e.authors)==null?void 0:c.filter(a=>a.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-lrow",children:t.jsxs("a",{href:n,children:[t.jsxs("span",{className:"bim-ct-lt",children:[o(e.title),r&&t.jsx("span",{className:"bim-ct-juan",children:o(r)})]}),t.jsx("span",{className:"bim-ct-by",children:s.map((a,d)=>t.jsxs(f.Fragment,{children:[d>0&&"、",a.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(a.dynasty),"〕"]}),o(a.name)]},d))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(a=>o(a)).join(" · ")})]})})}function Vl({page:e,pageCount:n,onPage:o,pageHref:r,label:s="分頁"}){const{convert:l}=V();if(n<=1)return null;const c=a=>d=>{o&&(r&&!xf(d)||(d.preventDefault(),o(a)))},p=(a,d,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const m={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...m,href:r(a),onClick:c(a),children:d}):t.jsx("button",{type:"button",...m,onClick:u.current?void 0:c(a),children:d})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:Pl(e,n).map((a,d)=>t.jsx("li",{style:{display:"contents"},children:a===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(a,a,{current:a===e,aria:l(`第 ${a} 頁`)})},a??`gap${d}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),p(e+1,l("下一頁"),{disabled:e>=n})]})}function Yl({works:e,workLink:n=Dl,emptyText:o="此類暫無作品",view:r="card",...s}){const{convert:l}=V();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:typeof o=="string"?l(o):o}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(c=>t.jsx(Ul,{work:c,href:n(c.id)},c.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(c=>t.jsx(Gl,{work:c,href:n(c.id)},c.id))}),t.jsx(Vl,{...s})]})}const ff=()=>t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:t.jsx("path",{d:"M2.5 4.5 6 8l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function mf({tree:e,selectedId:n,page:o,pageCount:r,works:s,onSelect:l,onPage:c,searchSlot:p,workLink:a,pageHref:d,allLabel:u="全部",allTitle:m="全部典籍",pageSize:x=ao,className:g,view:b,onViewChange:w}){const{convert:y}=V(),h=`bim-ct-drawer-${f.useId().replace(/:/g,"")}`,[v,$]=f.useState(!1),[k,_]=f.useState("card"),S=b??k,z=M=>{_(M),w==null||w(M)},N=Tt(e,n&&n!==at?n:null),R=N.length?N[N.length-1]:null,C=R?R.label:m,H=R?R.count:co(e),L=f.useCallback(M=>{$(!1),l(M)},[l]);return t.jsxs("div",{className:g?`bim-ct ${g}`:"bim-ct","data-drawer":v?"open":"closed",children:[t.jsx("style",{children:Fl}),t.jsxs("aside",{className:"bim-ct-side","aria-label":y("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":v,"aria-controls":h,onClick:()=>$(M=>!M),children:[t.jsxs("span",{children:[y("分類"),":",y(N.length?N.map(M=>M.label).join(" › "):u??m)]}),t.jsx(ff,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:h,children:[t.jsx("h2",{className:"bim-ct-side-h",children:y("分類")}),t.jsx(Ol,{tree:e,selectedId:n,onSelect:L,allLabel:u})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:y(C)}),N.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:y(N.slice(0,-1).map(M=>M.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[y(`共 ${H.toLocaleString("en-US")} 種 · 每頁 ${x} 條`),r>1&&y(` · 第 ${o} / ${r} 頁`)]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":y("呈現方式"),children:[t.jsx("button",{type:"button","aria-pressed":S==="card",onClick:()=>z("card"),children:y("卡片")}),t.jsx("button",{type:"button","aria-pressed":S==="list",onClick:()=>z("list"),children:y("列表")})]})]}),p&&t.jsx("div",{className:"bim-ct-search",children:p}),t.jsx(Yl,{works:s,view:S,workLink:a,page:o,pageCount:r,onPage:c,pageHref:d})]})]})}const vi=({style:e})=>{const n=f.useContext(Lt);if(!n)return null;const{locale:o,setLocale:r}=n,s=o==="zh-Hant",l=()=>r(s?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:`1px solid ${i("border")}`,borderRadius:"4px",background:i("bg"),color:i("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:s?i("primary"):void 0,fontWeight:s?700:400},children:"繁"}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:s?void 0:i("primary"),fontWeight:s?400:700},children:"简"})]})},ki=({href:e,label:n="在 GitHub 查看本条目源文件",size:o=16,className:r,style:s})=>t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:o+8,height:o+8,borderRadius:4,color:i("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:l=>{l.currentTarget.style.color=i("fg")},onMouseLeave:l=>{l.currentTarget.style.color=i("desc-fg")},children:t.jsx("svg",{width:o,height:o,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:t.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})});function ei(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function gf(e,n){if(!n)return!1;const o=n.id;return o===void 0||o===e}const hf=({id:e,transport:n,initialDetail:o,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:c,onJuanChange:p,lineageMode:a="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:m,initialPage:x=1,selectedLineageNodeId:g,onNavigate:b,onBack:w,backLabel:y,renderLink:j,enrichDetail:h,getSourceLink:v,readLink:$,railTop:k,extraTabs:_=[],showFeedbackTab:S=!0,feedbackApiUrl:z,height:N,footerExtra:R,className:C,style:H})=>{var fo;const L=me(),{convert:M}=V(),[F]=f.useState(()=>{if(!gf(e,o))return null;const Z={...o},ve=r??ei(e,Z);return h&&h(ve,Z),{id:e,entry:ve,detail:Z}}),[X,U]=f.useState((F==null?void 0:F.entry)??null),[T,ce]=f.useState((F==null?void 0:F.detail)??null),[B,D]=f.useState(!F),[A,ee]=f.useState(!1),[de,G]=f.useState([]),[q,ie]=f.useState(!1),[pe,ge]=f.useState(null),[Ee,Ne]=f.useState(!1),[ze,Te]=f.useState(null),[Ce,Ae]=f.useState(!1),[P,se]=f.useState(null),[re,ye]=f.useState([]),[be,K]=f.useState(!1),[I,Y]=f.useState(null),[fe,he]=f.useState(null),[W,ae]=f.useState(!1),J=f.useRef(null),[O,xe]=f.useState(null),je=c!==void 0?c:O,Se=f.useCallback(Z=>{p?p(Z):xe(Z)},[p]),ne=f.useCallback(async Z=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){G([]);return}ie(!0);try{if(n.getCollectionCatalogs)G(await n.getCollectionCatalogs(Z)||[]);else if(n.getCollectionCatalog){const ve=await n.getCollectionCatalog(Z);G(ve?[{resource_id:"",data:ve}]:[])}}catch{G([])}finally{ie(!1)}},[n]),we=f.useCallback(async Z=>{if(!n.getCollatedEditionIndex){ge(null);return}Ne(!0);try{ge(await n.getCollatedEditionIndex(Z))}catch{ge(null)}finally{Ne(!1)}},[n]),E=f.useCallback(async Z=>{if(!n.getBookFullTextIndex){Te(null);return}Ae(!0);try{Te(await n.getBookFullTextIndex(Z))}catch{Te(null)}finally{Ae(!1),se(Z)}},[n]),Q=f.useCallback(async Z=>{var ve;if(!n.getWorkFullTextList){ye([]);return}K(!0);try{const Re=(await n.getWorkFullTextList(Z)??[]).filter(Pe=>Pe.owner_type!=="Book");ye(Re),Y(((ve=Re.find(Pe=>Pe.primary)??Re[0])==null?void 0:ve.key)??null)}catch{ye([])}finally{K(!1)}},[n]),ue=f.useCallback(async(Z,ve)=>{ae(!0);try{if(n.getLineageGraph){const Ue=await n.getLineageGraph(Z);Ue&&he(Ue)}const Re=ve.version_graph;if(!Re||!Re.enabled){fe||he(null),J.current=null;return}const Pe=ve.books??[],nt=[];for(const Ue of Pe)try{const it=await n.getItem(Ue);it&&nt.push(it)}catch{}J.current={work:ve,books:nt};const oe=u??Re.default_collection??(Re.core_books&&Re.core_books.length>0?"core":"all"),Le=oe==="core"&&Array.isArray(Re.core_books)&&Re.core_books.length>0?"core":oe??"all";he(bn(ve,nt,Le))}catch{he(null),J.current=null}finally{ae(!1)}},[n]),le=f.useRef({initialDetail:o,initialEntry:r});le.current={initialDetail:o,initialEntry:r},f.useEffect(()=>{let Z=!1;const ve=oe=>{oe.type==="collection"?ne(e):oe.type==="work"?(oe.has_collated&&we(e),(oe.version_graph||n.getLineageGraph)&&ue(e,oe),n.getWorkFullTextList&&Q(e)):oe.type==="book"&&oe.has_full_text&&n.getBookFullTextIndex&&E(e)},Re=le.current;let Pe=null;if(F&&F.id===e)Pe=F;else if(Re.initialDetail&&Re.initialDetail.id===e){const oe={...Re.initialDetail},Le=Re.initialEntry??ei(e,oe);h&&h(Le,oe),Pe={entry:Le,detail:oe}}return Pe?(ee(!1),G(oe=>oe.length?[]:oe),ge(null),Te(null),ye(oe=>oe.length?[]:oe),Y(null),he(null),J.current=null,U(Pe.entry),ce(Pe.detail),D(!1),ve(Pe.detail),()=>{Z=!0}):((async()=>{D(!0),ee(!1),U(null),ce(null),G([]),ge(null),Te(null),ye([]),Y(null),he(null),J.current=null;try{const oe=await n.getItem(e);if(Z)return;if(!oe){ee(!0);return}const Le=oe;let Ue=null;if(n.getEntry&&(Ue=await n.getEntry(e),Z))return;Ue||(Ue=ei(e,Le)),h&&h(Ue,Le),U(Ue),ce(Le),ve(Le)}catch{Z||ee(!0)}finally{Z||D(!1)}})(),()=>{Z=!0})},[e,n,F,h,ne,we,ue,E,Q]),f.useEffect(()=>{const Z=J.current;!Z||!u||he(bn(Z.work,Z.books,u))},[u]);const te=[];if(T){if(te.push({key:"basic",label:L.detailTab.basicInfo}),T.type==="collection"){q&&de.length===0&&te.push({key:"catalog:loading",label:`${L.detailTab.catalog}…`});for(const Z of de)te.push({key:`catalog:${Z.resource_id}`,label:Z.short_name?`${M(Z.short_name)}${L.detailTab.catalogSuffix}`:L.detailTab.collectionCatalog})}T.type==="work"&&(pe||Ee)&&s==="collated"&&te.push({key:"collated",label:Ee?`${L.detailTab.collatedEdition}…`:L.detailTab.collatedEdition}),T.type==="book"&&(ze||Ce)&&s==="fulltext"&&te.push({key:"fulltext",label:Ce?`${L.detailTab.fullText}…`:L.detailTab.fullText}),T.type==="work"&&(re.length>0||be)&&s==="fulltext"&&te.push({key:"fulltext",label:be?`${L.detailTab.fullText}…`:L.detailTab.fullText}),T.type==="work"&&(fe||W)&&te.push({key:"lineage",label:W?`${L.detailTab.lineage}…`:L.detailTab.lineage});for(const Z of _)(Z.position??"before-feedback")==="before-feedback"&&Z.shouldShow(T)&&te.push({key:Z.key,label:Z.label});S&&s==="feedback"&&te.push({key:"feedback",label:L.detailTab.feedback});for(const Z of _)Z.position==="after-feedback"&&Z.shouldShow(T)&&te.push({key:Z.key,label:Z.label})}f.useEffect(()=>{if(s!=="emendated"||!T)return;l("basic");const Z=setTimeout(()=>{var ve;(ve=document.getElementById("studies"))==null||ve.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(Z)},[s,T,l]);const ke=X&&T&&v?v({activeTab:s,activeJuan:je,entry:X,detail:T}):null,Ie=f.useMemo(()=>{var nt;if(!T)return null;const ve=(T.authors??[]).map(oe=>{const Le=Wi(oe.role);return`${oe.dynasty?`〔${M(oe.dynasty)}〕`:""}${M(oe.name)}${Le?` ${M(Le)}`:""}`}).join(" · ");let Re=!1;try{Re=$e.extractStatus(T.id)==="draft"}catch{}if(T.type==="book"){const oe=T;return{title:M(oe.title),subtitle:oe.edition?M(oe.edition):ve||void 0,aside:[Re?L.status.draft:"",ve&&oe.edition?ve:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(T.type==="collection"){const oe=T;return{title:M(oe.title),subtitle:M(pt(oe,L.unit.juan))||void 0,aside:[(nt=oe.publication_info)==null?void 0:nt.year,Re?L.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:ve||void 0}}if(T.type==="entity"){const oe=T,Le=it=>it==null?"":it<0?`前${-it}`:String(it),Ue=oe.birth_year!=null||oe.death_year!=null?`${Le(oe.birth_year)||"?"}—${Le(oe.death_year)||"?"}`:"";return{title:M(oe.primary_name||oe.title),subtitle:[oe.dynasty?`〔${M(oe.dynasty)}〕`:"",Ue].filter(Boolean).join(" ")||void 0,aside:Re?L.status.draft:void 0,secondLine:void 0}}const Pe=M(pt(T,L.unit.juan));return{title:M(T.title),subtitle:[Pe,ve].filter(Boolean).join(" · ")||void 0,aside:[yf(L,T.subtype),Re?L.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[T,M,L]),We=T?T.type==="work"?(((fo=pe==null?void 0:pe.juan_files)==null?void 0:fo.length)??0)>0?"collated":re.length>0?"fulltext":null:T.type==="book"&&(((ze==null?void 0:ze.chapters.length)??0)>0||T.has_full_text&&n.getBookFullTextIndex&&P!==T.id)?"fulltext":null:null,Ze=re.find(Z=>Z.primary)??re[0],an=()=>{var Z;We==="collated"&&((Z=pe==null?void 0:pe.juan_files)!=null&&Z.length)?(Se(pe.juan_files[0]),l("collated")):We==="fulltext"&&((T==null?void 0:T.type)==="work"&&Ze&&Y(Ze.key),Se(null),l("fulltext"))};let ut=null;if(T&&$){const Z=$({detail:T,kind:We,fullTextKey:T.type==="work"?Ze==null?void 0:Ze.key:void 0});Z&&(ut=t.jsx(ai,{href:Z}))}else We&&(ut=t.jsx(ai,{onClick:an}));const cn=Z=>{if(!T)return null;const ve=Z.replace(/\.[^.]+$/,"");if($){const Re=$({detail:T,kind:"fulltext",juan:ve});return Re?{href:Re}:null}return{onClick:()=>{Se(ve),l("fulltext")}}},dn=new Set(_.map(Z=>Z.key)),_e=te.filter(Z=>Z.key.startsWith("catalog:")&&Z.key!=="catalog:loading"||dn.has(Z.key)).map(Z=>({key:Z.key,label:Z.label,onClick:()=>l(Z.key)})),tt=()=>{var Z;return T?T.type==="work"?t.jsx(Rl,{data:T,transport:n,onNavigate:b,renderLink:j,readAction:ut,railTop:k,railLinks:_e}):T.type==="book"?t.jsx(Al,{data:T,transport:n,onNavigate:b,renderLink:j,readAction:ut,fullText:ze,fullTextPending:!!T.has_full_text&&!!n.getBookFullTextIndex&&P!==T.id,chapterLink:cn,railTop:k,railLinks:_e}):T.type==="collection"?t.jsx(Wl,{data:T,catalog:(Z=de[0])==null?void 0:Z.data,transport:n,onNavigate:b,renderLink:j,readAction:ut,railTop:k,railLinks:_e,catalogAction:de.length>0?t.jsxs("a",{href:"#catalog",onClick:ve=>{ve.preventDefault(),l(`catalog:${de[0].resource_id}`)},children:[M(L.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Ml,{data:T,transport:n,onNavigate:b,renderLink:j,railTop:k,railLinks:_e}):null},Be=()=>{var ve,Re,Pe,nt;if(!X||!T)return null;if(s==="basic"||s==="emendated")return tt();if(typeof s=="string"&&s.startsWith("catalog:")){const oe=(ve=de.find(Le=>`catalog:${Le.resource_id}`===s))==null?void 0:ve.data;return t.jsx(Ri,{data:oe,onNavigate:b,renderLink:j})}if(s==="collated")return t.jsx(no,{index:pe||void 0,workId:e,transport:n,onNavigate:b,activeJuan:je,onJuanChange:Se});if(s==="fulltext"&&T.type==="work"){const oe=I??((Re=re[0])==null?void 0:Re.key);return oe?t.jsx(gi,{bookId:e,workKey:oe,versions:re,onVersionChange:Le=>{Y(Le),Se(null)},transport:n,activeChapter:je,onChapterChange:Se},oe):t.jsx("div",{style:{padding:24,color:i("desc-fg")},children:be?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(gi,{index:ze||void 0,bookId:e,transport:n,activeChapter:je,onChapterChange:Se});if(s==="lineage"){if(!fe)return t.jsx("div",{style:{color:i("label-fg"),padding:"24px 0"},children:W?"加載中…":"暫無版本圖數據"});const oe=T.type==="work"?T:null;return t.jsx(so,{graph:fe,renderLink:j,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:a,onModeChange:d,selectedNodeId:g,collection:u??((Pe=oe==null?void 0:oe.version_graph)==null?void 0:Pe.default_collection),onCollectionChange:m,collectionsAvailable:(nt=oe==null?void 0:oe.version_graph)==null?void 0:nt.collections,collectionCounts:(()=>{var mo,go,ho,bo,yo,jo,vo;if(!oe)return;const Le={},Ue=((mo=J.current)==null?void 0:mo.books)??[];Le.all=(((go=oe.books)==null?void 0:go.length)??0)-(((bo=(ho=oe.version_graph)==null?void 0:ho.excluded_books)==null?void 0:bo.length)??0);const it=(yo=oe.version_graph)==null?void 0:yo.collections;if(it)for(const ko of Object.keys(it))Le[ko]=bn(oe,Ue,ko).nodes.filter(wo=>wo.kind==="book"&&!wo.bridge).length;return Le.core==null&&((vo=(jo=oe.version_graph)==null?void 0:jo.core_books)!=null&&vo.length)&&(Le.core=oe.version_graph.core_books.length),Le})()})}if(s==="feedback"&&S)return t.jsx(Cl,{resourceId:e,apiUrl:z});const Z=_.find(oe=>oe.key===s);return Z?Z.render({detail:T,entry:X,transport:n,onNavigate:b}):null};if(B)return t.jsx(Kt,{style:{minHeight:N,...H},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((Z,ve)=>t.jsx("div",{style:{height:ve===1?40:16,width:Z,opacity:.35,background:i("rule")}},ve))})});if(A||!T||!X||!Ie)return t.jsx(Kt,{style:{minHeight:N,...H},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:i("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const St=s==="basic"||s==="emendated",pn=[{label:y??L.detailTab.backToIndex,onClick:w}];if(T.type==="book"&&T.work_id){const Z=T.work_id;pn.push({label:L.indexType.work,id:Z,onClick:()=>b==null?void 0:b(Z)})}pn.push({label:L.indexType[T.type]});const un=s==="collated"||s==="fulltext",uo=typeof R=="string"?L.status[R.trim()]??R:R,xo=t.jsx(Os,{left:t.jsxs(t.Fragment,{children:[uo,uo?" · ":"",t.jsx(bf,{id:T.id,label:L.label.id,copied:L.action.copied,copyLabel:L.action.copy})]}),right:t.jsxs(t.Fragment,{children:[S&&!St&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:L.detailTab.submitVersion}),ke&&t.jsx("a",{href:ke.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:i("meta-fg")},children:L.detailTab.dataLicense})]})});return St?t.jsx("div",{className:C,children:t.jsxs(Kt,{grid:!0,style:{minHeight:N,...H},children:[t.jsx(ci,{breadcrumb:t.jsx(di,{items:pn}),actions:t.jsxs(t.Fragment,{children:[t.jsx(vi,{style:{border:"none",background:"transparent"}}),ke&&t.jsx(ki,{...ke})]})}),tt(),xo]})}):t.jsx("div",{className:C,children:t.jsxs(Kt,{wide:un,style:{minHeight:N,...H},children:[t.jsx(ci,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Fi,{char:"籍"}),t.jsx(di,{items:pn})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(vi,{}),S&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:L.detailTab.feedback}),ke&&t.jsx(ki,{...ke})]})}),t.jsx(Rs,{...Ie,aside:un?t.jsxs("button",{type:"button",onClick:()=>l("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("accent"),borderBottom:`1px solid ${i("rule")}`},children:[M("作品信息")," →"]}):Ie.aside}),!un&&te.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:te.map(Z=>t.jsx(Ns,{label:Z.label,active:Z.key===s||St&&Z.key==="basic",onClick:()=>l(Z.key)},Z.key))}),t.jsx("div",{style:{marginTop:!un&&te.length>1?8:0},children:Be()}),xo]})})};function bf({id:e,label:n,copied:o,copyLabel:r}){const[s,l]=f.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var c;(c=navigator.clipboard)==null||c.writeText(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?o:r,"aria-label":s?o:r,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:i("aux-fg")},children:s?"✓":"⧉"})]})}function yf(e,n){return n?e.workSubtype[n]??n:""}const Kl=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],An="zhusha",Wn="bim-theme";function ql(e){return e==="zhusha"||e==="indigo"||e==="ink"}function Mn(e){return ql(e)?e:An}function jf(){try{return Mn(window.localStorage.getItem(Wn))}catch{return An}}function Jl(e){try{window.localStorage.setItem(Wn,e)}catch{}}function Zl(e){const n=Mn(e);return document.documentElement.setAttribute("data-theme",n),n}function Xl(){return Mn(document.documentElement.getAttribute("data-theme"))}const vf=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],po="airy",Fn="bim-layout";function Ql(e){return e==="airy"||e==="boxed"}function Pn(e){return Ql(e)?e:po}function kf(){try{return Pn(window.localStorage.getItem(Fn))}catch{return po}}function wf(e){try{window.localStorage.setItem(Fn,e)}catch{}}function Sf(e){const n=Pn(e);return document.documentElement.setAttribute("data-layout",n),n}function $f(){return Pn(document.documentElement.getAttribute("data-layout"))}const _f=`try{var t=localStorage.getItem(${JSON.stringify(Wn)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(Fn)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,zf={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},Cf=({onChange:e,style:n})=>{const{convert:o}=V(),[r,s]=f.useState(An);f.useEffect(()=>{s(Xl())},[]);const l=c=>{s(Zl(c)),Jl(c),e==null||e(c)};return t.jsx("div",{role:"radiogroup","aria-label":o("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:Kl.map(c=>{const p=r===c.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":p,"aria-label":o(c.label),title:o(c.label),onClick:()=>l(c.name),style:{width:28,height:44,padding:0,border:0,background:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:t.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:"50%",boxSizing:"border-box",background:i(zf[c.name]),boxShadow:p?`0 0 0 2px ${i("page-bg")}, 0 0 0 3.5px ${i("aux-fg")}`:"none"}})},c.name)})})};exports.BidLink=$e.BidLink;exports.BookIndexError=$e.BookIndexError;exports.BookIndexManager=$e.BookIndexManager;exports.BookIndexStorage=$e.BookIndexStorage;exports.BundleStorage=$e.BundleStorage;exports.ConfigError=$e.ConfigError;exports.GithubStorage=$e.GithubStorage;exports.IdGenerationError=$e.IdGenerationError;exports.IdGenerator=$e.IdGenerator;exports.LocalStorage=$e.LocalStorage;exports.MigrationError=$e.MigrationError;exports.StorageError=$e.StorageError;exports.base36Decode=$e.base36Decode;exports.base36Encode=$e.base36Encode;exports.base58Decode=$e.base58Decode;exports.buildId=$e.buildId;exports.buildPromotionMap=$e.buildPromotionMap;exports.cleanName=$e.cleanName;exports.decodeId=$e.decodeId;exports.decodeIdString=$e.decodeIdString;exports.encodeId=$e.encodeId;exports.extractIdFromUrl=$e.extractIdFromUrl;exports.extractStatus=$e.extractStatus;exports.extractType=$e.extractType;exports.normalizeCatalog=$e.normalizeCatalog;exports.parseId=$e.parseId;exports.shardOf=$e.shardOf;exports.smartDecode=$e.smartDecode;exports.validateResource=$e.validateResource;exports.Badge=wn;exports.BidUrlProvider=da;exports.BookDetailLayout=hf;exports.BookFullText=gi;exports.BookPage=Al;exports.Breadcrumb=di;exports.CATALOG_ALL_ID=at;exports.CATALOG_CSS=Fl;exports.CATALOG_NARROW_QUERY=lo;exports.CATALOG_PAGE_SIZE=ao;exports.CATALOG_UNCLASSIFIED_ID=en;exports.CLASSIFICATIONS=Cn;exports.CardFoot=rn;exports.CatalogPage=mf;exports.CatalogPager=Vl;exports.CatalogTree=Ol;exports.CheckFilter=Is;exports.Chip=Ls;exports.ChipWall=yd;exports.CollatedEdition=no;exports.CollectionCatalog=Ri;exports.CollectionPage=Wl;exports.CreateEntityDialog=jl;exports.DEFAULT_LAYOUT=po;exports.DEFAULT_READER_PREFS=Di;exports.DEFAULT_THEME=An;exports.DETAIL_CSS=Es;exports.DYNASTY_GROUPS=zn;exports.Dash=$d;exports.DataTable=vd;exports.DetailFooter=Os;exports.DetailGrid=nn;exports.DetailHeader=Rs;exports.EMPTY_FILTERS=_n;exports.EmendatedBySection=xs;exports.EmptyNote=Rd;exports.EntityDetail=ls;exports.EntityPage=Ml;exports.EntityPickerDialog=kl;exports.EntitySelector=yl;exports.ExpandRow=_d;exports.ExtLink=Nd;exports.FEEDBACK_FAB_OFFSET_VAR=bi;exports.FILTER_SUPPORT=Qr;exports.FONT_SIZE_STEPS=Ct;exports.FactList=md;exports.FeedbackButton=rx;exports.FeedbackDialog=_l;exports.FeedbackForm=zl;exports.FeedbackList=io;exports.FeedbackTab=Cl;exports.FilterChip=Ns;exports.FormInput=Ye;exports.FormTextArea=jt;exports.GUJI_MARKDOWN_FIELD=td;exports.GUJI_TABLE_NOTATION=Xs;exports.GlyphBadge=Fi;exports.GujiTable=Vi;exports.HomePage=mi;exports.ImagePanel=Ys;exports.IndexApp=du;exports.IndexBrowser=ii;exports.IndexDetail=Ei;exports.IndexEditor=wl;exports.IndexView=Vu;exports.IntroGrid=fd;exports.LAYOUTS=vf;exports.LAYOUT_STORAGE_KEY=Fn;exports.LOSS_OPTIONS=Ti;exports.LocaleContext=Lt;exports.LocaleProvider=Sa;exports.LocaleToggle=vi;exports.MetaLine=De;exports.ModeIndicator=Jr;exports.MoreButton=bd;exports.MoreLink=Mt;exports.PAGE_MAX_WIDTH=gn;exports.PageFrame=Kt;exports.Quote=Cd;exports.READER_CSS=Gs;exports.RECENT_IDS_STORAGE_KEY=It;exports.ROLE_CLASS_ORDER=js;exports.ReadButton=ai;exports.ReaderMdText=Ji;exports.ReaderShell=Gi;exports.ReaderToc=Vs;exports.RelationPanel=hl;exports.RepoSourceLink=ki;exports.ResourceEditor=ni;exports.ResourceGroup=Td;exports.ResourceLine=Id;exports.ResourceList=Ci;exports.ResourceRow=Fs;exports.SEARCH_VIEW_STORAGE_KEY=Ii;exports.SNIPPET_MARK_END=Gr;exports.SNIPPET_MARK_START=Hr;exports.SORTABLE_TYPES=Xr;exports.SearchInput=Zr;exports.SearchResults=rs;exports.Sec=He;exports.Section=Xe;exports.SectionHead=gd;exports.SideList=yt;exports.SmartBidInput=hn;exports.SourceEditor=fl;exports.SummaryCard=on;exports.THEMES=Kl;exports.THEME_INIT_SCRIPT=_f;exports.THEME_STORAGE_KEY=Wn;exports.TabFilter=Ln;exports.TableHead=kd;exports.TableRow=wd;exports.TagRow=Ps;exports.TagRows=Ed;exports.TextButton=hd;exports.ThemeToggle=Cf;exports.TopStrip=ci;exports.VersionLineageGraph=Bl;exports.VersionLineageList=Ll;exports.VersionLineageView=so;exports.VolumeChips=jd;exports.VolumeLinks=Pi;exports.WorkCard=Gl;exports.WorkCardGrid=Yl;exports.WorkCatalog=pu;exports.WorkPage=Rl;exports.WorkRow=Ul;exports.applyLayout=Sf;exports.applyTheme=Zl;exports.bucketResources=Bi;exports.buildCatalogTree=sf;exports.buildCollectionTable=ks;exports.buildLineageGraph=bn;exports.buildMeiliFilter=Pa;exports.buildPageUrl=zi;exports.buildParagraphBlocks=sl;exports.buildVersionRow=bs;exports.buildVersionTable=ys;exports.canParagraphize=Qt;exports.catalogNodeIdOf=of;exports.catalogNodeIdsOf=rf;exports.catalogPageCount=df;exports.catalogTotal=co;exports.classificationPath=ln;exports.compareCatalogCards=cf;exports.computeVersionPartition=Zc;exports.countActiveFilters=Tn;exports.currentLayout=$f;exports.currentTheme=Xl;exports.defaultWorkLink=Dl;exports.deriveDating=Kc;exports.deriveEditionType=Ss;exports.deriveEra=tn;exports.deriveYear=En;exports.deriveYearRange=Li;exports.detailToEditor=$l;exports.detectGenre=Bn;exports.displayAuthorRole=Wi;exports.editorToDetail=Uu;exports.eraRank=ri;exports.filtersFromParams=Oa;exports.filtersToParams=yn;exports.findCatalogPath=Tt;exports.flattenTitles=pi;exports.flattenToc=Zs;exports.formatTemplate=Qe;exports.formatVolumeRange=Nn;exports.getDisplayNameFromUrl=Bt;exports.getStartPage=_i;exports.getTypeGroupKey=Si;exports.groupRelatedWorks=qc;exports.gujiInlineToPlain=Cs;exports.hasActiveFilters=es;exports.hasGujiMarkdownV02=si;exports.hasGujiTableNotation=Qs;exports.hasSearchOptions=Wa;exports.isLayoutName=Ql;exports.isThemeName=ql;exports.measureText=pt;exports.mergeVolumeResources=$i;exports.normalizeEra=Oe;exports.normalizeLayout=Pn;exports.normalizeRole=Ai;exports.normalizeTheme=Mn;exports.normalizeVolumeIndex=Jt;exports.normalizeVolumes=qr;exports.numberToChinese=ws;exports.paginationItems=Pl;exports.parseChineseNumber=jn;exports.parseGujiInline=zs;exports.parseGujiTable=tl;exports.parseSourceString=ml;exports.pickReaderVersion=Js;exports.readStoredLayout=kf;exports.readStoredTheme=jf;exports.readerVersionOptionLabel=xi;exports.readerVersionsFromFullText=qs;exports.renderFullTextBody=op;exports.renderProperNames=al;exports.renderReaderInline=qi;exports.resourceHref=At;exports.resourceNote=Rn;exports.roleFacets=vs;exports.rowNo=Sd;exports.sameFilters=Da;exports.sortFor=Ma;exports.sortYear=vn;exports.splitFullTextTables=Ui;exports.splitHighlightSnippet=wi;exports.splitTableRow=el;exports.storeLayout=wf;exports.storeTheme=Jl;exports.stringifySources=gl;exports.toCatalogWorkCard=af;exports.typeSupportsFilters=ts;exports.useBidUrl=Fe;exports.useConvert=V;exports.useReaderPrefs=Hi;exports.useT=me;exports.validateLineageGraph=_x;exports.volumeStats=Sn;
|
|
1169
|
+
`,an="未分類",ut="all",ho=20;function fn(e){if(!e)return[];const n=[];for(const o of[e.l1,e.l2,e.l3,e.l4]){const r=(o??"").trim();if(!r)break;n.push(r)}return n}function yf(e){const n=fn(e);return n.length?n.join("/"):an}function jf(e){const n=fn(e);return n.length?n.map((o,r)=>n.slice(0,r+1).join("/")):[an]}function vf(e,n=[]){const o=new Map;n.forEach((p,a)=>{const d=[p.cata_l1,p.cata_l2,p.cata_l3,p.cata_l4].filter(u=>!!u);d.forEach((u,m)=>{const f=d.slice(0,m+1).join("/");o.has(f)||o.set(f,a)})});const r=new Map;let s=0;for(const p of e){const a=fn(p.classification);if(!a.length){s++;continue}let d=r;a.forEach((u,m)=>{const f=a.slice(0,m+1).join("/");let g=d.get(u);g||(g={id:f,label:u,count:0,children:new Map},d.set(u,g)),g.count++,d=g.children})}const l=p=>[...p.values()].sort((a,d)=>{const u=o.get(a.id)??1/0,m=o.get(d.id)??1/0;return u!==m?u-m:a.label.localeCompare(d.label,"zh")}).map(a=>{const d={id:a.id,label:a.label,count:a.count};return a.children.size&&(d.children=l(a.children)),d}),c=l(r);return s>0&&c.push({id:an,label:an,count:s}),c}function At(e,n){if(!n)return[];for(const o of e){if(o.id===n)return[o];if(o.children){const r=At(o.children,n);if(r.length)return[o,...r]}}return[]}function bo(e){return e.reduce((n,o)=>n+o.count,0)}function kf(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function wf(e){var p;const n={id:e.id,title:e.title||e.id},o=e.juan_count,r=typeof o=="number"?o:o==null?void 0:o.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(a=>a==null?void 0:a.name).map(a=>{const d=a.dynasty||(e.authors.length===1?e.dynasty:void 0);return d?{name:a.name,dynasty:d}:{name:a.name}});s.length&&(n.authors=s);const l=kf(typeof e.description=="string"?e.description:(p=e.description)==null?void 0:p.text);l&&(n.summary=l);const c=fn(e.classification);return c.length&&(n.classification=c),n}function Sf(e,n){const o=e.summary?0:1,r=n.summary?0:1;return o!==r?o-r:e.title.localeCompare(n.title,"zh")}function $f(e,n=ho){return Math.max(1,Math.ceil(e/n))}function ql(e,n,o=2){if(n<=1)return[1];const r=new Set([1,n]);for(let c=e-o;c<=e+o;c++)c>=1&&c<=n&&r.add(c);const s=[...r].sort((c,p)=>c-p),l=[];return s.forEach((c,p)=>{if(p>0){const a=c-s[p-1];a===2?l.push(c-1):a>2&&l.push(null)}l.push(c)}),l}const _f=()=>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 Cf(e,n,o){const r=[];o&&r.push({id:ut,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 Jl({tree:e,selectedId:n,onSelect:o,allLabel:r="全部",label:s="分類"}){const{convert:l}=X(),c=x.useRef(null),p=n&&n!==ut?n:null,a=r!==null,[d,u]=x.useState(()=>{const k=new Set;for(const $ of At(e,p))k.add($.id);return k});x.useEffect(()=>{const k=At(e,p);k.length&&u($=>{if(k.every(C=>$.has(C.id)))return $;const S=new Set($);for(const C of k)S.add(C.id);return S})},[e,p]);const m=x.useMemo(()=>Cf(e,d,a),[e,d,a]),[f,g]=x.useState(null);x.useEffect(()=>{g(null)},[n]);const b=p??(a?ut:null),w=x.useMemo(()=>{var S;const k=new Set(m.map(C=>C.id));if(f&&k.has(f))return f;if(b&&k.has(b))return b;const $=At(e,p).map(C=>C.id).filter(C=>k.has(C));return $.length?$[$.length-1]:((S=m[0])==null?void 0:S.id)??null},[m,f,b,e,p]),y=x.useCallback((k,$)=>{u(S=>{const C=S.has(k),L=$??!C;if(L===C)return S;const I=new Set(S);return L?I.add(k):I.delete(k),I})},[]),j=x.useCallback(k=>{g(k),requestAnimationFrame(()=>{var S;const $=Array.from(((S=c.current)==null?void 0:S.querySelectorAll("[data-ct-id]"))??[]).find(C=>C.dataset.ctId===k);$==null||$.focus()})},[]),h=x.useCallback((k,$)=>{$&&y(k,!0),o(k)},[o,y]),v=x.useCallback(k=>{const $=k.target.closest("[data-ct-id]");if(!$)return;const S=$.dataset.ctId,C=m.findIndex(T=>T.id===S);if(C<0)return;const L=m[C];let I=null;switch(k.key){case"ArrowDown":I=m[Math.min(m.length-1,C+1)].id;break;case"ArrowUp":I=m[Math.max(0,C-1)].id;break;case"Home":I=m[0].id;break;case"End":I=m[m.length-1].id;break;case"ArrowRight":if(!L.hasChildren)break;d.has(S)?I=L.firstChildId:y(S,!0);break;case"ArrowLeft":L.hasChildren&&d.has(S)?y(S,!1):I=L.parentId;break;case"Enter":case" ":k.preventDefault(),h(S,L.hasChildren);return;default:return}k.preventDefault(),I&&I!==S&&j(I)},[m,d,y,j,h]),_=(k,$)=>k.map((S,C)=>{var M;const L=(M=S.children)!=null&&M.length?S.children:null,I=!!L&&d.has(S.id),T=S.id===p,U=$===1&&k.length>1&&C===k.length-1;return t.jsxs("li",{role:"treeitem","aria-level":$,"aria-expanded":L?I:void 0,"aria-selected":T,tabIndex:w===S.id?0:-1,"data-ct-id":S.id,className:U?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":$-1},onClick:()=>{g(S.id),h(S.id,!!L)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:L?F=>{F.stopPropagation(),g(S.id),y(S.id)}:void 0,children:L?t.jsx(_f,{}):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")})]}),I&&t.jsx("ul",{role:"group",children:_(L,$+1)})]},S.id)});return t.jsxs("ul",{ref:c,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:v,children:[a&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:w===ut?0:-1,"data-ct-id":ut,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{g(ut),o(ut)},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:bo(e).toLocaleString("en-US")})]})}),_(e,1)]})}const Zl=e=>`/item/${encodeURIComponent(e)}`;function zf(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Xl(e){return e==null||e===""?null:typeof e=="number"?`${e}卷`:e}function Ql({work:e,href:n}){var c,p;const{convert:o}=X(),r=Xl(e.juan),s=((c=e.authors)==null?void 0:c.filter(a=>a.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:n,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:o(e.title)}),r&&t.jsx("span",{className:"bim-ct-juan",children:o(r)})]}),s.length>0&&t.jsx("span",{className:"bim-ct-by",children:s.map((a,d)=>t.jsxs(x.Fragment,{children:[d>0&&"、",a.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(a.dynasty),"〕"]}),o(a.name)]},d))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:o(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(a=>o(a)).join(" · ")})]})})}function ea({work:e,href:n}){var c,p;const{convert:o}=X(),r=Xl(e.juan),s=((c=e.authors)==null?void 0:c.filter(a=>a.name))??[],l=((p=e.classification)==null?void 0:p.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-lrow",children:t.jsxs("a",{href:n,children:[t.jsxs("span",{className:"bim-ct-lt",children:[o(e.title),r&&t.jsx("span",{className:"bim-ct-juan",children:o(r)})]}),t.jsx("span",{className:"bim-ct-by",children:s.map((a,d)=>t.jsxs(x.Fragment,{children:[d>0&&"、",a.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(a.dynasty),"〕"]}),o(a.name)]},d))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(a=>o(a)).join(" · ")})]})})}function ta({page:e,pageCount:n,onPage:o,pageHref:r,label:s="分頁"}){const{convert:l}=X();if(n<=1)return null;const c=a=>d=>{o&&(r&&!zf(d)||(d.preventDefault(),o(a)))},p=(a,d,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const m={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return r?t.jsx("a",{...m,href:r(a),onClick:c(a),children:d}):t.jsx("button",{type:"button",...m,onClick:u.current?void 0:c(a),children:d})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(e-1,l("上一頁"),{disabled:e<=1}),t.jsx("ol",{children:ql(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 na({works:e,workLink:n=Zl,emptyText:o="此類暫無作品",view:r="card",...s}){const{convert:l}=X();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:typeof o=="string"?l(o):o}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(c=>t.jsx(ea,{work:c,href:n(c.id)},c.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(c=>t.jsx(Ql,{work:c,href:n(c.id)},c.id))}),t.jsx(ta,{...s})]})}const Tf=()=>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 If({tree:e,selectedId:n,page:o,pageCount:r,works:s,onSelect:l,onPage:c,searchSlot:p,workLink:a,pageHref:d,allLabel:u="全部",allTitle:m="全部典籍",pageSize:f=ho,className:g,view:b,onViewChange:w}){const{convert:y}=X(),h=`bim-ct-drawer-${x.useId().replace(/:/g,"")}`,[v,_]=x.useState(!1),[k,$]=x.useState("card"),S=b??k,C=F=>{$(F),w==null||w(F)},L=At(e,n&&n!==ut?n:null),I=L.length?L[L.length-1]:null,T=I?I.label:m,U=I?I.count:bo(e),M=x.useCallback(F=>{_(!1),l(F)},[l]);return t.jsxs("div",{className:g?`bim-ct ${g}`:"bim-ct","data-drawer":v?"open":"closed",children:[t.jsx("style",{children:Kl}),t.jsxs("aside",{className:"bim-ct-side","aria-label":y("分類導航"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":v,"aria-controls":h,onClick:()=>_(F=>!F),children:[t.jsxs("span",{children:[y("分類"),":",y(L.length?L.map(F=>F.label).join(" › "):u??m)]}),t.jsx(Tf,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:h,children:[t.jsx("h2",{className:"bim-ct-side-h",children:y("分類")}),t.jsx(Jl,{tree:e,selectedId:n,onSelect:M,allLabel:u})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:y(T)}),L.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:y(L.slice(0,-1).map(F=>F.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[y(`共 ${U.toLocaleString("en-US")} 種 · 每頁 ${f} 條`),r>1&&y(` · 第 ${o} / ${r} 頁`)]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":y("呈現方式"),children:[t.jsx("button",{type:"button","aria-pressed":S==="card",onClick:()=>C("card"),children:y("卡片")}),t.jsx("button",{type:"button","aria-pressed":S==="list",onClick:()=>C("list"),children:y("列表")})]})]}),p&&t.jsx("div",{className:"bim-ct-search",children:p}),t.jsx(na,{works:s,view:S,workLink:a,page:o,pageCount:r,onPage:c,pageHref:d})]})]})}const zi=({style:e})=>{const n=x.useContext(Ot);if(!n)return null;const{locale:o,setLocale:r}=n,s=o==="zh-Hant",l=()=>r(s?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:`1px solid ${i("border")}`,borderRadius:"4px",background:i("bg"),color:i("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:s?i("primary"):void 0,fontWeight:s?700:400},children:"繁"}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:s?void 0:i("primary"),fontWeight:s?400:700},children:"简"})]})},Ti=({href:e,label:n="在 GitHub 查看本条目源文件",size:o=16,className:r,style:s})=>t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:o+8,height:o+8,borderRadius:4,color:i("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:l=>{l.currentTarget.style.color=i("fg")},onMouseLeave:l=>{l.currentTarget.style.color=i("desc-fg")},children:t.jsx("svg",{width:o,height:o,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:t.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})});function ai(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function Ef(e,n){if(!n)return!1;const o=n.id;return o===void 0||o===e}const Rf=({id:e,transport:n,initialDetail:o,initialEntry:r,activeTab:s,onTabChange:l,activeJuan:c,onJuanChange:p,lineageMode:a="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:m,initialPage:f=1,selectedLineageNodeId:g,onNavigate:b,onBack:w,backLabel:y,renderLink:j,enrichDetail:h,getSourceLink:v,readLink:_,railTop:k,extraTabs:$=[],showFeedbackTab:S=!0,feedbackApiUrl:C,height:L,footerExtra:I,className:T,style:U})=>{var jo;const M=ge(),{convert:F}=X(),[O]=x.useState(()=>{if(!Ef(e,o))return null;const ne={...o},Ce=r??ai(e,ne);return h&&h(Ce,ne),{id:e,entry:Ce,detail:ne}}),[D,H]=x.useState((O==null?void 0:O.entry)??null),[z,pe]=x.useState((O==null?void 0:O.detail)??null),[A,oe]=x.useState(!O),[E,W]=x.useState(!1),[ce,Y]=x.useState([]),[ee,Z]=x.useState(!1),[le,be]=x.useState(null),[Le,Be]=x.useState(!1),[he,Ne]=x.useState(null),[Te,Re]=x.useState(!1),[P,me]=x.useState(null),[te,ke]=x.useState([]),[we,K]=x.useState(!1),[N,q]=x.useState(null),[xe,ye]=x.useState(null),[B,re]=x.useState(!1),Q=x.useRef(null),[fe,G]=x.useState(null),ve=c!==void 0?c:fe,$e=x.useCallback(ne=>{p?p(ne):G(ne)},[p]),J=x.useCallback(async ne=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){Y([]);return}Z(!0);try{if(n.getCollectionCatalogs)Y(await n.getCollectionCatalogs(ne)||[]);else if(n.getCollectionCatalog){const Ce=await n.getCollectionCatalog(ne);Y(Ce?[{resource_id:"",data:Ce}]:[])}}catch{Y([])}finally{Z(!1)}},[n]),_e=x.useCallback(async ne=>{if(!n.getCollatedEditionIndex){be(null);return}Be(!0);try{be(await n.getCollatedEditionIndex(ne))}catch{be(null)}finally{Be(!1)}},[n]),R=x.useCallback(async ne=>{if(!n.getBookFullTextIndex){Ne(null);return}Re(!0);try{Ne(await n.getBookFullTextIndex(ne))}catch{Ne(null)}finally{Re(!1),me(ne)}},[n]),se=x.useCallback(async ne=>{var Ce;if(!n.getWorkFullTextList){ke([]);return}K(!0);try{const Ae=(await n.getWorkFullTextList(ne)??[]).filter(Pe=>Pe.owner_type!=="Book");ke(Ae),q(((Ce=Ae.find(Pe=>Pe.primary)??Ae[0])==null?void 0:Ce.key)??null)}catch{ke([])}finally{K(!1)}},[n]),ue=x.useCallback(async(ne,Ce)=>{re(!0);try{if(n.getLineageGraph){const Ye=await n.getLineageGraph(ne);Ye&&ye(Ye)}const Ae=Ce.version_graph;if(!Ae||!Ae.enabled){xe||ye(null),Q.current=null;return}const Pe=Ce.books??[],rt=[];for(const Ye of Pe)try{const st=await n.getItem(Ye);st&&rt.push(st)}catch{}Q.current={work:Ce,books:rt};const de=u??Ae.default_collection??(Ae.core_books&&Ae.core_books.length>0?"core":"all"),Me=de==="core"&&Array.isArray(Ae.core_books)&&Ae.core_books.length>0?"core":de??"all";ye(kn(Ce,rt,Me))}catch{ye(null),Q.current=null}finally{re(!1)}},[n]),ae=x.useRef({initialDetail:o,initialEntry:r});ae.current={initialDetail:o,initialEntry:r},x.useEffect(()=>{let ne=!1;const Ce=de=>{de.type==="collection"?J(e):de.type==="work"?(de.has_collated&&_e(e),(de.version_graph||n.getLineageGraph)&&ue(e,de),n.getWorkFullTextList&&se(e)):de.type==="book"&&de.has_full_text&&n.getBookFullTextIndex&&R(e)},Ae=ae.current;let Pe=null;if(O&&O.id===e)Pe=O;else if(Ae.initialDetail&&Ae.initialDetail.id===e){const de={...Ae.initialDetail},Me=Ae.initialEntry??ai(e,de);h&&h(Me,de),Pe={entry:Me,detail:de}}return Pe?(W(!1),Y(de=>de.length?[]:de),be(null),Ne(null),ke(de=>de.length?[]:de),q(null),ye(null),Q.current=null,H(Pe.entry),pe(Pe.detail),oe(!1),Ce(Pe.detail),()=>{ne=!0}):((async()=>{oe(!0),W(!1),H(null),pe(null),Y([]),be(null),Ne(null),ke([]),q(null),ye(null),Q.current=null;try{const de=await n.getItem(e);if(ne)return;if(!de){W(!0);return}const Me=de;let Ye=null;if(n.getEntry&&(Ye=await n.getEntry(e),ne))return;Ye||(Ye=ai(e,Me)),h&&h(Ye,Me),H(Ye),pe(Me),Ce(Me)}catch{ne||W(!0)}finally{ne||oe(!1)}})(),()=>{ne=!0})},[e,n,O,h,J,_e,ue,R,se]),x.useEffect(()=>{const ne=Q.current;!ne||!u||ye(kn(ne.work,ne.books,u))},[u]);const ie=[];if(z){if(ie.push({key:"basic",label:M.detailTab.basicInfo}),z.type==="collection"){ee&&ce.length===0&&ie.push({key:"catalog:loading",label:`${M.detailTab.catalog}…`});for(const ne of ce)ie.push({key:`catalog:${ne.resource_id}`,label:ne.short_name?`${F(ne.short_name)}${M.detailTab.catalogSuffix}`:M.detailTab.collectionCatalog})}z.type==="work"&&(le||Le)&&s==="collated"&&ie.push({key:"collated",label:Le?`${M.detailTab.collatedEdition}…`:M.detailTab.collatedEdition}),z.type==="book"&&(he||Te)&&s==="fulltext"&&ie.push({key:"fulltext",label:Te?`${M.detailTab.fullText}…`:M.detailTab.fullText}),z.type==="work"&&(te.length>0||we)&&s==="fulltext"&&ie.push({key:"fulltext",label:we?`${M.detailTab.fullText}…`:M.detailTab.fullText}),z.type==="work"&&(xe||B)&&ie.push({key:"lineage",label:B?`${M.detailTab.lineage}…`:M.detailTab.lineage});for(const ne of $)(ne.position??"before-feedback")==="before-feedback"&&ne.shouldShow(z)&&ie.push({key:ne.key,label:ne.label});S&&s==="feedback"&&ie.push({key:"feedback",label:M.detailTab.feedback});for(const ne of $)ne.position==="after-feedback"&&ne.shouldShow(z)&&ie.push({key:ne.key,label:ne.label})}x.useEffect(()=>{if(s!=="emendated"||!z)return;l("basic");const ne=setTimeout(()=>{var Ce;(Ce=document.getElementById("studies"))==null||Ce.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(ne)},[s,z,l]);const Se=D&&z&&v?v({activeTab:s,activeJuan:ve,entry:D,detail:z}):null,Ee=x.useMemo(()=>{var rt;if(!z)return null;const Ce=(z.authors??[]).map(de=>{const Me=Gi(de.role);return`${de.dynasty?`〔${F(de.dynasty)}〕`:""}${F(de.name)}${Me?` ${F(Me)}`:""}`}).join(" · ");let Ae=!1;try{Ae=je.extractStatus(z.id)==="draft"}catch{}if(z.type==="book"){const de=z;return{title:F(de.title),subtitle:de.edition?F(de.edition):Ce||void 0,aside:[Ae?M.status.draft:"",Ce&&de.edition?Ce:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(z.type==="collection"){const de=z;return{title:F(de.title),subtitle:F(mt(de,M.unit.juan))||void 0,aside:[(rt=de.publication_info)==null?void 0:rt.year,Ae?M.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:Ce||void 0}}if(z.type==="entity"){const de=z,Me=st=>st==null?"":st<0?`前${-st}`:String(st),Ye=de.birth_year!=null||de.death_year!=null?`${Me(de.birth_year)||"?"}—${Me(de.death_year)||"?"}`:"";return{title:F(de.primary_name||de.title),subtitle:[de.dynasty?`〔${F(de.dynasty)}〕`:"",Ye].filter(Boolean).join(" ")||void 0,aside:Ae?M.status.draft:void 0,secondLine:void 0}}const Pe=F(mt(z,M.unit.juan));return{title:F(z.title),subtitle:[Pe,Ce].filter(Boolean).join(" · ")||void 0,aside:[Lf(M,z.subtype),Ae?M.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[z,F,M]),We=z?z.type==="work"?(((jo=le==null?void 0:le.juan_files)==null?void 0:jo.length)??0)>0?"collated":te.length>0?"fulltext":null:z.type==="book"&&(((he==null?void 0:he.chapters.length)??0)>0||z.has_full_text&&n.getBookFullTextIndex&&P!==z.id)?"fulltext":null:null,qe=te.find(ne=>ne.primary)??te[0],Tt=()=>{var ne;We==="collated"&&((ne=le==null?void 0:le.juan_files)!=null&&ne.length)?($e(le.juan_files[0]),l("collated")):We==="fulltext"&&((z==null?void 0:z.type)==="work"&&qe&&q(qe.key),$e(null),l("fulltext"))};let Qe=null;if(z&&_){const ne=_({detail:z,kind:We,fullTextKey:z.type==="work"?qe==null?void 0:qe.key:void 0});ne&&(Qe=t.jsx(mi,{href:ne}))}else We&&(Qe=t.jsx(mi,{onClick:Tt}));const It=ne=>{if(!z)return null;const Ce=ne.replace(/\.[^.]+$/,"");if(_){const Ae=_({detail:z,kind:"fulltext",juan:Ce});return Ae?{href:Ae}:null}return{onClick:()=>{$e(Ce),l("fulltext")}}},jt=new Set($.map(ne=>ne.key)),Ie=ie.filter(ne=>ne.key.startsWith("catalog:")&&ne.key!=="catalog:loading"||jt.has(ne.key)).map(ne=>({key:ne.key,label:ne.label,onClick:()=>l(ne.key)})),Je=()=>{var ne;return z?z.type==="work"?t.jsx(Pl,{data:z,transport:n,onNavigate:b,renderLink:j,readAction:Qe,railTop:k,railLinks:Ie}):z.type==="book"?t.jsx(Vl,{data:z,transport:n,onNavigate:b,renderLink:j,readAction:Qe,fullText:he,fullTextPending:!!z.has_full_text&&!!n.getBookFullTextIndex&&P!==z.id,chapterLink:It,railTop:k,railLinks:Ie}):z.type==="collection"?t.jsx(Ul,{data:z,catalog:(ne=ce[0])==null?void 0:ne.data,transport:n,onNavigate:b,renderLink:j,readAction:Qe,railTop:k,railLinks:Ie,catalogAction:ce.length>0?t.jsxs("a",{href:"#catalog",onClick:Ce=>{Ce.preventDefault(),l(`catalog:${ce[0].resource_id}`)},children:[F(M.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Yl,{data:z,transport:n,onNavigate:b,renderLink:j,railTop:k,railLinks:Ie}):null},V=()=>{var Ce,Ae,Pe,rt;if(!D||!z)return null;if(s==="basic"||s==="emendated")return Je();if(typeof s=="string"&&s.startsWith("catalog:")){const de=(Ce=ce.find(Me=>`catalog:${Me.resource_id}`===s))==null?void 0:Ce.data;return t.jsx(Fi,{data:de,onNavigate:b,renderLink:j})}if(s==="collated")return t.jsx(po,{index:le||void 0,workId:e,transport:n,onNavigate:b,activeJuan:ve,onJuanChange:$e});if(s==="fulltext"&&z.type==="work"){const de=N??((Ae=te[0])==null?void 0:Ae.key);return de?t.jsx(wi,{bookId:e,workKey:de,versions:te,onVersionChange:Me=>{q(Me),$e(null)},transport:n,activeChapter:ve,onChapterChange:$e},de):t.jsx("div",{style:{padding:24,color:i("desc-fg")},children:we?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return t.jsx(wi,{index:he||void 0,bookId:e,transport:n,activeChapter:ve,onChapterChange:$e});if(s==="lineage"){if(!xe)return t.jsx("div",{style:{color:i("label-fg"),padding:"24px 0"},children:B?"加載中…":"暫無版本圖數據"});const de=z.type==="work"?z:null;return t.jsx(mo,{graph:xe,renderLink:j,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:a,onModeChange:d,selectedNodeId:g,collection:u??((Pe=de==null?void 0:de.version_graph)==null?void 0:Pe.default_collection),onCollectionChange:m,collectionsAvailable:(rt=de==null?void 0:de.version_graph)==null?void 0:rt.collections,collectionCounts:(()=>{var vo,ko,wo,So,$o,_o,Co;if(!de)return;const Me={},Ye=((vo=Q.current)==null?void 0:vo.books)??[];Me.all=(((ko=de.books)==null?void 0:ko.length)??0)-(((So=(wo=de.version_graph)==null?void 0:wo.excluded_books)==null?void 0:So.length)??0);const st=($o=de.version_graph)==null?void 0:$o.collections;if(st)for(const zo of Object.keys(st))Me[zo]=kn(de,Ye,zo).nodes.filter(To=>To.kind==="book"&&!To.bridge).length;return Me.core==null&&((Co=(_o=de.version_graph)==null?void 0:_o.core_books)!=null&&Co.length)&&(Me.core=de.version_graph.core_books.length),Me})()})}if(s==="feedback"&&S)return t.jsx(Ml,{resourceId:e,apiUrl:C});const ne=$.find(de=>de.key===s);return ne?ne.render({detail:z,entry:D,transport:n,onNavigate:b}):null};if(A)return t.jsx(tn,{style:{minHeight:L,...U},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((ne,Ce)=>t.jsx("div",{style:{height:Ce===1?40:16,width:ne,opacity:.35,background:i("rule")}},Ce))})});if(E||!z||!D||!Ee)return t.jsx(tn,{style:{minHeight:L,...U},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:i("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const ze=s==="basic"||s==="emendated",Ue=[{label:y??M.detailTab.backToIndex,onClick:w}];if(z.type==="book"&&z.work_id){const ne=z.work_id;Ue.push({label:M.indexType.work,id:ne,onClick:()=>b==null?void 0:b(ne)})}Ue.push({label:M.indexType[z.type]});const dt=s==="collated"||s==="fulltext",Vt=typeof I=="string"?M.status[I.trim()]??I:I,mn=t.jsx(Ks,{left:t.jsxs(t.Fragment,{children:[Vt,Vt?" · ":"",t.jsx(Nf,{id:z.id,label:M.label.id,copied:M.action.copied,copyLabel:M.action.copy})]}),right:t.jsxs(t.Fragment,{children:[S&&!ze&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:M.detailTab.submitVersion}),Se&&t.jsx("a",{href:Se.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:i("meta-fg")},children:M.detailTab.dataLicense})]})});return ze?t.jsx("div",{className:T,children:t.jsxs(tn,{grid:!0,style:{minHeight:L,...U},children:[t.jsx(gi,{breadcrumb:t.jsx(hi,{items:Ue}),actions:t.jsxs(t.Fragment,{children:[t.jsx(zi,{style:{border:"none",background:"transparent"}}),Se&&t.jsx(Ti,{...Se})]})}),Je(),mn]})}):t.jsx("div",{className:T,children:t.jsxs(tn,{wide:dt,style:{minHeight:L,...U},children:[t.jsx(gi,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Ui,{char:"籍"}),t.jsx(hi,{items:Ue})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(zi,{}),S&&t.jsx("button",{type:"button",onClick:()=>l("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:M.detailTab.feedback}),Se&&t.jsx(Ti,{...Se})]})}),t.jsx(Fs,{...Ee,aside:dt?t.jsxs("button",{type:"button",onClick:()=>l("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("accent"),borderBottom:`1px solid ${i("rule")}`},children:[F("作品信息")," →"]}):Ee.aside}),!dt&&ie.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:ie.map(ne=>t.jsx(Os,{label:ne.label,active:ne.key===s||ze&&ne.key==="basic",onClick:()=>l(ne.key)},ne.key))}),t.jsx("div",{style:{marginTop:!dt&&ie.length>1?8:0},children:V()}),mn]})})};function Nf({id:e,label:n,copied:o,copyLabel:r}){const[s,l]=x.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var c;(c=navigator.clipboard)==null||c.writeText(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?o:r,"aria-label":s?o:r,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:i("aux-fg")},children:s?"✓":"⧉"})]})}function Lf(e,n){return n?e.workSubtype[n]??n:""}const ia=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],Hn="zhusha",Gn="bim-theme";function oa(e){return e==="zhusha"||e==="indigo"||e==="ink"}function Vn(e){return oa(e)?e:Hn}function Af(){try{return Vn(window.localStorage.getItem(Gn))}catch{return Hn}}function ra(e){try{window.localStorage.setItem(Gn,e)}catch{}}function sa(e){const n=Vn(e);return document.documentElement.setAttribute("data-theme",n),n}function la(){return Vn(document.documentElement.getAttribute("data-theme"))}const Bf=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],yo="airy",Un="bim-layout";function aa(e){return e==="airy"||e==="boxed"}function Yn(e){return aa(e)?e:yo}function Mf(){try{return Yn(window.localStorage.getItem(Un))}catch{return yo}}function Wf(e){try{window.localStorage.setItem(Un,e)}catch{}}function Ff(e){const n=Yn(e);return document.documentElement.setAttribute("data-layout",n),n}function Of(){return Yn(document.documentElement.getAttribute("data-layout"))}const Pf=`try{var t=localStorage.getItem(${JSON.stringify(Gn)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(Un)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,Df={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},Hf=({onChange:e,style:n})=>{const{convert:o}=X(),[r,s]=x.useState(Hn);x.useEffect(()=>{s(la())},[]);const l=c=>{s(sa(c)),ra(c),e==null||e(c)};return t.jsx("div",{role:"radiogroup","aria-label":o("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:ia.map(c=>{const p=r===c.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":p,"aria-label":o(c.label),title:o(c.label),onClick:()=>l(c.name),style:{width:28,height:44,padding:0,border:0,background:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:t.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:"50%",boxSizing:"border-box",background:i(Df[c.name]),boxShadow:p?`0 0 0 2px ${i("page-bg")}, 0 0 0 3.5px ${i("aux-fg")}`:"none"}})},c.name)})})};exports.BidLink=je.BidLink;exports.BookIndexError=je.BookIndexError;exports.BookIndexManager=je.BookIndexManager;exports.BookIndexStorage=je.BookIndexStorage;exports.BundleStorage=je.BundleStorage;exports.ConfigError=je.ConfigError;exports.GithubStorage=je.GithubStorage;exports.IdGenerationError=je.IdGenerationError;exports.IdGenerator=je.IdGenerator;exports.LocalStorage=je.LocalStorage;exports.MigrationError=je.MigrationError;exports.StorageError=je.StorageError;exports.base36Decode=je.base36Decode;exports.base36Encode=je.base36Encode;exports.base58Decode=je.base58Decode;exports.buildId=je.buildId;exports.buildPromotionMap=je.buildPromotionMap;exports.cleanName=je.cleanName;exports.decodeId=je.decodeId;exports.decodeIdString=je.decodeIdString;exports.encodeId=je.encodeId;exports.extractIdFromUrl=je.extractIdFromUrl;exports.extractStatus=je.extractStatus;exports.extractType=je.extractType;exports.isChapterSegment=je.isChapterSegment;exports.isTextKey=je.isTextKey;exports.matchChapterAcrossVersions=je.matchChapterAcrossVersions;exports.normalizeCatalog=je.normalizeCatalog;exports.parseId=je.parseId;exports.pickTextVersion=je.pickTextVersion;exports.shardOf=je.shardOf;exports.smartDecode=je.smartDecode;exports.textVersionLabel=je.textVersionLabel;exports.validateResource=je.validateResource;exports.Badge=Cn;exports.BidUrlProvider=ya;exports.BookDetailLayout=Rf;exports.BookFullText=wi;exports.BookPage=Vl;exports.Breadcrumb=hi;exports.CATALOG_ALL_ID=ut;exports.CATALOG_CSS=Kl;exports.CATALOG_NARROW_QUERY=go;exports.CATALOG_PAGE_SIZE=ho;exports.CATALOG_UNCLASSIFIED_ID=an;exports.CLASSIFICATIONS=Rn;exports.CardFoot=un;exports.CatalogPage=If;exports.CatalogPager=ta;exports.CatalogTree=Jl;exports.CheckFilter=Ms;exports.Chip=Ps;exports.ChipWall=zd;exports.CollatedEdition=po;exports.CollectionCatalog=Fi;exports.CollectionPage=Ul;exports.CreateEntityDialog=Tl;exports.DEFAULT_LAYOUT=yo;exports.DEFAULT_READER_PREFS=qi;exports.DEFAULT_THEME=Hn;exports.DETAIL_CSS=Ws;exports.DYNASTY_GROUPS=En;exports.Dash=Ld;exports.DataTable=Id;exports.DetailFooter=Ks;exports.DetailGrid=dn;exports.DetailHeader=Fs;exports.EMPTY_FILTERS=In;exports.EmendatedBySection=js;exports.EmptyNote=Pd;exports.EntityDetail=fs;exports.EntityPage=Yl;exports.EntityPickerDialog=El;exports.EntitySelector=zl;exports.ExpandRow=Ad;exports.ExtLink=Dd;exports.FEEDBACK_FAB_OFFSET_VAR=$i;exports.FILTER_SUPPORT=ss;exports.FONT_SIZE_STEPS=Lt;exports.FactList=Sd;exports.FeedbackButton=jx;exports.FeedbackDialog=Al;exports.FeedbackForm=Bl;exports.FeedbackList=uo;exports.FeedbackTab=Ml;exports.FilterChip=Os;exports.FormInput=Ze;exports.FormTextArea=$t;exports.GUJI_MARKDOWN_FIELD=dd;exports.GUJI_TABLE_NOTATION=rl;exports.GlyphBadge=Ui;exports.GujiTable=Xi;exports.HomePage=ki;exports.ImagePanel=el;exports.IndexApp=hu;exports.IndexBrowser=pi;exports.IndexDetail=Wi;exports.IndexEditor=Rl;exports.IndexView=lx;exports.IntroGrid=wd;exports.LAYOUTS=Bf;exports.LAYOUT_STORAGE_KEY=Un;exports.LOSS_OPTIONS=Bi;exports.LocaleContext=Ot;exports.LocaleProvider=Na;exports.LocaleToggle=zi;exports.MetaLine=He;exports.ModeIndicator=is;exports.MoreButton=Cd;exports.MoreLink=Gt;exports.PAGE_MAX_WIDTH=jn;exports.PageFrame=tn;exports.Quote=Md;exports.READER_CSS=Zs;exports.RECENT_IDS_STORAGE_KEY=Bt;exports.ROLE_CLASS_ORDER=Cs;exports.ReadButton=mi;exports.ReaderMdText=Dn;exports.ReaderShell=On;exports.ReaderToc=Qs;exports.RelationPanel=_l;exports.RepoSourceLink=Ti;exports.ResourceEditor=di;exports.ResourceGroup=Wd;exports.ResourceLine=Fd;exports.ResourceList=Ai;exports.ResourceRow=Us;exports.SEARCH_VIEW_STORAGE_KEY=Mi;exports.SNIPPET_MARK_END=Zr;exports.SNIPPET_MARK_START=Jr;exports.SORTABLE_TYPES=rs;exports.SearchInput=os;exports.SearchResults=us;exports.Sec=Ge;exports.Section=nt;exports.SectionHead=$d;exports.SideList=St;exports.SmartBidInput=vn;exports.SourceEditor=wl;exports.SummaryCard=pn;exports.THEMES=ia;exports.THEME_INIT_SCRIPT=Pf;exports.THEME_STORAGE_KEY=Gn;exports.TabFilter=Wn;exports.TableHead=Ed;exports.TableRow=Rd;exports.TagRow=Ys;exports.TagRows=Od;exports.TextButton=_d;exports.TextReader=ku;exports.ThemeToggle=Hf;exports.TopStrip=gi;exports.VersionLineageGraph=Gl;exports.VersionLineageList=Hl;exports.VersionLineageView=mo;exports.VolumeChips=Td;exports.VolumeLinks=Yi;exports.WorkCard=Ql;exports.WorkCardGrid=na;exports.WorkCatalog=_u;exports.WorkPage=Pl;exports.WorkRow=ea;exports.applyLayout=Ff;exports.applyTheme=sa;exports.bucketResources=Di;exports.buildCatalogTree=vf;exports.buildCollectionTable=Ts;exports.buildLineageGraph=kn;exports.buildMeiliFilter=qa;exports.buildPageUrl=Li;exports.buildParagraphBlocks=ul;exports.buildVersionRow=$s;exports.buildVersionTable=_s;exports.canParagraphize=Ct;exports.catalogNodeIdOf=yf;exports.catalogNodeIdsOf=jf;exports.catalogPageCount=$f;exports.catalogTotal=bo;exports.classificationPath=fn;exports.compareCatalogCards=Sf;exports.computeVersionPartition=sd;exports.countActiveFilters=Nn;exports.createTextApi=vl;exports.currentLayout=Of;exports.currentTheme=la;exports.defaultWorkLink=Zl;exports.deriveDating=id;exports.deriveEditionType=Es;exports.deriveEra=cn;exports.deriveYear=An;exports.deriveYearRange=Pi;exports.detailToEditor=Ll;exports.detectGenre=Pn;exports.displayAuthorRole=Gi;exports.editorToDetail=sx;exports.eraRank=xi;exports.filtersFromParams=Ja;exports.filtersToParams=wn;exports.findCatalogPath=At;exports.flattenTitles=bi;exports.flattenToc=ol;exports.formatTemplate=it;exports.formatVolumeRange=Mn;exports.getDisplayNameFromUrl=Pt;exports.getStartPage=Ni;exports.getTypeGroupKey=Ei;exports.groupRelatedWorks=od;exports.gujiInlineToPlain=As;exports.hasActiveFilters=ls;exports.hasGujiMarkdownV02=ln;exports.hasGujiTableNotation=Ji;exports.hasSearchOptions=Ua;exports.isLayoutName=aa;exports.isThemeName=oa;exports.measureText=mt;exports.mergeVolumeResources=Ri;exports.normalizeEra=De;exports.normalizeLayout=Yn;exports.normalizeRole=Hi;exports.normalizeTheme=Vn;exports.normalizeVolumeIndex=on;exports.normalizeVolumes=ns;exports.numberToChinese=Is;exports.paginationItems=ql;exports.parseChineseNumber=Sn;exports.parseGujiInline=Ls;exports.parseGujiTable=ll;exports.parseSourceString=Sl;exports.pickReaderVersion=il;exports.readStoredLayout=Mf;exports.readStoredTheme=Af;exports.readerVersionOptionLabel=ji;exports.readerVersionsFromFullText=nl;exports.renderFullTextBody=mp;exports.renderProperNames=fl;exports.renderReaderInline=to;exports.resourceHref=Dt;exports.resourceNote=Bn;exports.roleFacets=zs;exports.rowNo=Nd;exports.sameFilters=Za;exports.sortFor=Ya;exports.sortYear=$n;exports.splitFullTextTables=Zi;exports.splitHighlightSnippet=Ii;exports.splitTableRow=sl;exports.storeLayout=Wf;exports.storeTheme=ra;exports.stringifySources=$l;exports.toCatalogWorkCard=wf;exports.typeSupportsFilters=as;exports.useBidUrl=Fe;exports.useConvert=X;exports.useReaderPrefs=Fn;exports.useT=ge;exports.validateLineageGraph=Px;exports.volumeStats=zn;
|