book-index-ui 0.28.2 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +315 -56
- package/dist/index.d.ts +277 -1
- package/dist/index.js +6899 -6182
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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=`
|
|
1
|
+
"use strict";var Fa=Object.create;var Br=Object.defineProperty;var Oa=Object.getOwnPropertyDescriptor;var Pa=Object.getOwnPropertyNames;var Da=Object.getPrototypeOf,Ha=Object.prototype.hasOwnProperty;var Ga=(t,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Pa(n))!Ha.call(t,s)&&s!==r&&Br(t,s,{get:()=>n[s],enumerable:!(o=Oa(n,s))||o.enumerable});return t};var jn=(t,n,r)=>(r=t!=null?Fa(Da(t)):{},Ga(n||!t||!t.__esModule?Br(r,"default",{value:t,enumerable:!0}):r,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ye=require("./storage-entry-DGtRxALe.cjs"),e=require("react/jsx-runtime"),m=require("react"),Va=require("opencc-js/t2cn"),Ua=require("react-markdown"),Ya=require("remark-gfm"),Ka=t=>`/book-index?id=${t}`,os=m.createContext(Ka);function qa({buildUrl:t,children:n}){const r=m.useMemo(()=>t,[t]);return e.jsx(os.Provider,{value:r,children:n})}function Pe(){return m.useContext(os)}const ss="",ls="";function Bi(t){const n=[];let r=!1,o=t;for(;o.length;){const s=r?ls:ss,l=o.indexOf(s);if(l===-1){n.push({text:o,marked:r});break}l>0&&n.push({text:o.slice(0,l),marked:r}),o=o.slice(l+1),r=!r}return n}function Je(t,n){return{title:t,tokens:n}}const Mr='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Ja=[Je("基础(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"}}),Je("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),Je("提示与警告",{"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)"}}),Je("遮罩与阴影",{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)"}}),Je("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),Je("资源",{"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"}}),Je("整理本(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"}}),Je("版本传承(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"}}),Je("编辑器视图(主要在 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")'}}),Je("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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}}),Je('版式(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:"页签行下沿线颜色(疏朗不画,界栏画)"}}),Je("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"}}),Je("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),Je("字体(全站无衬线,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:Mr,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:Mr,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Za=Object.assign({},...Ja.map(t=>t.tokens)),as={};for(const[t,n]of Object.entries(Za))as[t]=`var(--bim-${t}, ${n.value})`;function i(t){const n=as[t];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${t}`);return n}function Rt(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Xa(t,n){return Rt(t).includes(n)}const xi={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Qa={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"};i("quality-published"),i("quality-fine"),i("quality-rough"),i("quality-ocr");const Vt=m.createContext(null),cs={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:"圖片資源"}},ec={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:"图片资源"}},tc=["曹霑"];function nc(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ic(t,n=tc){const r=[...new Set(n.filter(Boolean))].sort((l,a)=>a.length-l.length);if(!r.length)return t;const o=new RegExp(`(${r.map(nc).join("|")})`,"g"),s=new Set(r);return l=>{if(!l)return t(l);const a=l.split(o);return a.length===1?t(l):a.map((p,c)=>c%2===1&&s.has(p)?p:p&&t(p)).join("")}}let Zt=null;function rc(){if(Zt)return Zt;try{Zt=ic(Va.Converter({from:"tw",to:"cn"}))}catch{Zt=t=>t}return Zt}const oc={"zh-Hant":cs,"zh-Hans":ec},ds="bim-locale";function sc(){try{const t=localStorage.getItem(ds);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function lc(t){try{localStorage.setItem(ds,t)}catch{}}const ac="zh-Hans",cc=({locale:t,onLocaleChange:n,converter:r,children:o})=>{const[s,l]=m.useState(t??ac),a=t??s;m.useEffect(()=>{if(t)return;const u=sc();u&&u!==s&&l(u)},[]);const p=m.useMemo(()=>a==="zh-Hans"?r??rc():null,[a,r]),c=m.useCallback(u=>{l(u),lc(u),n==null||n(u)},[n]),d=m.useMemo(()=>({locale:a,setLocale:c,messages:oc[a],converter:p}),[a,c,p]);return e.jsx(Vt.Provider,{value:d,children:o})};function ge(){const t=m.useContext(Vt);return(t==null?void 0:t.messages)??cs}const dc=2e3;function G(){const t=m.useContext(Vt),n=(t==null?void 0:t.locale)??"zh-Hant",r=(t==null?void 0:t.converter)??null,o=m.useRef(new Map),s=m.useRef(n);s.current!==n&&(o.current.clear(),s.current=n);const l=m.useCallback(a=>{if(!a)return"";if(!r)return a;const p=o.current.get(a);if(p!==void 0)return p;const c=r(a);if(o.current.size>=dc){const d=o.current.keys().next().value;d!==void 0&&o.current.delete(d)}return o.current.set(a,c),c},[r]);return m.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function rt(t,n){return t.replace(/\{(\w+)\}/g,(r,o)=>String(n[o]??""))}function pc(t){if(!t)return"";try{const n=new URL(t).hostname,r={"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(r[n])return r[n];const o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function uc(){return{id:"",name:"",url:"",type:"text",details:""}}const hi=({items:t,onChange:n,onDownload:r,downloadStatuses:o,filterType:s})=>{const l=ge(),[a,p]=m.useState(null),c=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],d=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],u=g=>{if(!s)return!0;const v=Rt(g);return s==="text"?v.includes("text"):s==="image"?v.includes("image")||v.includes("physical"):s==="physical"?v.includes("physical"):v.includes(s)},h=t.map((g,v)=>({item:g,originalIndex:v})).filter(({item:g})=>u(g)),x=()=>{const g=uc();s&&(g.type=s),n([...t,g]),p(t.length)},f=g=>{n(t.filter((v,$)=>$!==g)),p(null)},b=(g,v,$)=>{const k=[...t];if(k[g]={...k[g],[v]:$},v==="url"&&!k[g].id){const _=pc($);_&&(k[g].id=_)}n(k)},w=(g,v,$)=>{const _={...t[g].metadata||{}};$?_[v]=$:delete _[v],b(g,"metadata",Object.keys(_).length>0?_:void 0)},y=(g,v)=>{const $=v.trim()?v.split(/[,,、]/).map(k=>k.trim()).filter(Boolean):void 0;b(g,"structure",$)},j=(g,v,$)=>{const _=t[g].coverage||{level:1,ranges:""};v==="level"?_.level=parseInt($)||1:_.ranges=$,b(g,"coverage",_.ranges?_:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[h.map(({item:g,originalIndex:v})=>{var $,k,_;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>p(a===v?null:v),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===v?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:mc(g.type??"text"),color:i("on-color-fg")},children:(()=>{var z,A;const S=Rt(g);return S.length===0?g.type??"text":S.length===1?((z=c.find(E=>E.value===S[0]))==null?void 0:z.label)??S[0]:S.includes("text")&&S.includes("image")?((A=c.find(E=>E.value==="text+image"))==null?void 0:A.label)??"text+image":S.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:g.name||`${l.editor.resourcePlaceholder} ${v+1}`}),g.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:g.id}),g.url&&e.jsx("a",{href:g.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),r&&g.url&&xc(v,o==null?void 0:o[v],r,l),e.jsx("button",{onClick:S=>{S.stopPropagation(),f(v)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),a===v&&e.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:[Xa(g,"image")&&g.url&&hc(g,l),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Xt,children:[e.jsx("span",{style:Qt,children:l.label.type}),e.jsx("select",{value:g.type,onChange:S=>b(v,"type",S.target.value),style:{...dt,flex:1},children:c.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]}),e.jsxs("label",{style:Xt,children:[e.jsx("span",{style:Qt,children:l.label.rootType}),e.jsx("select",{value:g.root_type||"catalog",onChange:S=>b(v,"root_type",S.target.value),style:{...dt,flex:1},children:d.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:g.id,onChange:S=>b(v,"id",S.target.value),placeholder:l.editor.idAutoExtract,style:{...dt,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:g.name,onChange:S=>b(v,"name",S.target.value),placeholder:l.editor.resourceName,style:{...dt,flex:1}})]}),e.jsx("input",{type:"text",value:g.url,onChange:S=>b(v,"url",S.target.value),placeholder:l.editor.resourceUrl,style:dt}),e.jsx("input",{type:"text",value:(($=g.structure)==null?void 0:$.join("、"))||"",onChange:S=>y(v,S.target.value),placeholder:l.editor.structurePlaceholder,style:dt}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Xt,children:[e.jsx("span",{style:Qt,children:l.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((k=g.coverage)==null?void 0:k.level)??"",onChange:S=>j(v,"level",S.target.value),placeholder:"1",style:{...dt,width:"60px"}})]}),e.jsxs("label",{style:{...Xt,flex:1},children:[e.jsx("span",{style:Qt,children:l.label.coverageRange}),e.jsx("input",{type:"text",value:((_=g.coverage)==null?void 0:_.ranges)||"",onChange:S=>j(v,"ranges",S.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...dt,flex:1}})]})]}),e.jsx("textarea",{value:g.details||"",onChange:S=>b(v,"details",S.target.value),placeholder:l.editor.detailsPlaceholder,style:{...dt,minHeight:"60px",resize:"vertical"}}),e.jsxs("div",{style:{borderTop:`1px solid ${i("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"6px"},children:l.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([S,z])=>{var A;return e.jsxs("label",{style:{...Xt,gap:"4px"},children:[e.jsx("span",{style:{...Qt,minWidth:"56px"},children:z}),e.jsx("input",{type:"text",value:((A=g.metadata)==null?void 0:A[S])||"",onChange:E=>w(v,S,E.target.value),placeholder:z,style:{...dt,flex:1}})]},S)})})]})]})]})]},v)}),e.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:[e.jsx("span",{children:"+"}),e.jsx("span",{children:l.action.addResource})]})]})};function mc(t){switch(t){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 xc(t,n,r,o){const s=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:a=>{a.stopPropagation(),s||r(t,"")},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?o.download.completed:s?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:l?"✓":s?"⏳":"⬇"})}function hc(t,n){const r=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:r?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:i("overlay-bg")},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:o=>{o.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:i("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:i("desc-fg")},children:n.editor.imageResourceLink})})}const dt={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"},Xt={display:"flex",alignItems:"center",gap:"6px"},Qt={fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap"},fc={"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 Ut(t){try{return fc[new URL(t).hostname]}catch{return}}const Wr={text:0,image:1,physical:2};function Mi(t){return t.length===0?"physical":[...t].sort((n,r)=>(Wr[n]??99)-(Wr[r]??99)).join("+")}function Wi(t){var a;const n=p=>{const c=p.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const d=p.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},r=new Map;for(let p=0;p<t.length;p++){const c=t[p];if(c.volumes&&c.volumes.length>0)continue;const d=n(c.name);if(!d)continue;const[u,h]=d,x=`${u}|${Mi(Rt(c))}`;r.has(x)||r.set(x,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const f=r.get(x);f.volumes.push({volume:h,url:c.url||void 0,status:"found"}),f.indices.push(p)}const o=[],s=new Set;for(const p of r.values())if(!(p.volumes.length<2)){p.volumes.sort((c,d)=>c.volume-d.volume),p.base.volumes=p.volumes,p.base.expected_volumes=p.volumes.length,p.base.url||(p.base.url=((a=p.volumes.find(c=>c.url))==null?void 0:a.url)??""),o.push(p.base);for(const c of p.indices)s.add(c)}const l=[...o];for(let p=0;p<t.length;p++)s.has(p)||l.push(t[p]);return l}function ps(t){if(t.url)return t.url;for(const[n,r]of Object.entries(t))if(n.endsWith("_url")&&typeof r=="string")return r}function us(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||ps(n)}))}function Rn(t){const n=us(t);if(!n)return null;const r=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,o=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:r,missing:o,expected:t.expected_volumes??r+o}}function Fi(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const r=n.match(/^(\d+)/);return r?parseInt(r[1],10):void 0}function Oi(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const o=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(o)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(o[1]))}&page=${n}`;const s=new URL(t);return s.searchParams.set("page",String(n)),s.toString()}return t}catch{return t}}function Yt(t){if(!t.url)return;const n=Fi(t.metadata);return n?Oi(t.url,n):t.url}const Fr={text:i("restype-text"),image:i("restype-image"),"text+image":i("restype-text-image"),physical:i("restype-physical")};function gc(t){return t.includes("text")&&t.includes("image")?Fr["text+image"]:Fr[t[0]||"physical"]}const Pi=({items:t,groupByType:n=!0,resourceGroups:r,onNavigate:o,renderLink:s})=>{const l=ge(),{convert:a}=G(),p=m.useMemo(()=>Wi(t||[]),[t]),{mirrorGroups:c,ungroupedItems:d}=m.useMemo(()=>{const y=new Map,j=[];for(const g of p){const v=g.group;v?(y.has(v)||y.set(v,[]),y.get(v).push(g)):j.push(g)}for(const g of y.values())g.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},h=y=>u[y]?u[y]:y.split("+").map(j=>u[j]||j).join("+");if(!p||p.length===0)return e.jsx("div",{style:{padding:"16px",color:i("desc-fg"),fontSize:"13px",textAlign:"center"},children:l.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:p.map((y,j)=>e.jsx(Qn,{item:y},y.id||j))});const x=(y,j)=>{const g=r==null?void 0:r[y],v=(g==null?void 0:g.label)||y,$=g==null?void 0:g.description;return e.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:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:a(v)}),$&&e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.5},children:a($)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((k,_)=>e.jsx(Qn,{item:k,onNavigate:o,renderLink:s},k.id||_))})]},`group-${y}`)},f=new Map;for(const y of d){const j=Mi(Rt(y));f.has(j)||f.set(j,[]),f.get(j).push(y)}const b=["text","image","text+image","physical"],w=[...b.filter(y=>f.has(y)),...[...f.keys()].filter(y=>!b.includes(y)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([y,j])=>x(y,j)),w.map(y=>{const j=f.get(y),g=gc(y.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:g,whiteSpace:"nowrap",flexShrink:0},children:h(y)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((v,$)=>e.jsx(Qn,{item:v,onNavigate:o,renderLink:s},v.id||$))})]},y)})]})},bc={bw:{label:"",bg:i("colormode-bw-bg"),fg:i("colormode-bw-fg")},color:{label:"",bg:i("colormode-color-bg"),fg:i("colormode-color-fg")}},Qn=({item:t})=>{const n=ge(),{convert:r}=G(),[o,s]=m.useState(!1),l=m.useMemo(()=>(t.url?Ut(t.url):void 0)||r(t.name),[t.url,t.name,r]),a=m.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(b=>({...b,url:b.url||ps(b)})),[t.volumes]),p=a&&a.length>0,c=p?new Set(a.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=p?new Set(a.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=t.expected_volumes??(p?c+d:0),h=t.color_mode?{...bc[t.color_mode],label:n.colorMode[t.color_mode]}:null,x=t.details&&!p?r(t.details):null,f={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 e.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[e.jsxs("div",{style:f,children:[e.jsx("span",{style:{fontWeight:500},children:l}),h&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:h.bg,color:h.fg},children:h.label}),x&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:x}),p&&e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[c,"/",u,n.unit.volume,d>0&&e.jsxs("span",{style:{color:i("missing-fg"),marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const b=Fi(t.metadata);return b?Oi(t.url,b):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:i("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),p&&e.jsx("button",{onClick:()=>s(!o),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",lineHeight:1.4},children:o?"▲":"▼"})]}),p&&o&&e.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:a.map(b=>{const w=b.status==="missing";return b.url&&!w?e.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):e.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)})})]})},ms=({indexSource:t,syncConfig:n,variant:r="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:l,onSelectFolder:a})=>{const p=ge(),c=t==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",h=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")},f={onMouseOver:w=>w.currentTarget.style.opacity="0.8",onMouseOut:w=>w.currentTarget.style.opacity="1"},b=e.jsxs("div",{onClick:s,title:d?p.mode.switchToOfficial:p.mode.switchToDraft,style:{...x,background:i(d?"warning":"success"),color:i("on-color-fg")},...f,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return r==="index-browser"?c?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:o,title:p.mode.switchToSync,style:x,...f,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:p.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px"},...f,children:[e.jsx("span",{children:"📂"}),h&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:h})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:o,title:p.mode.switchToLocal,style:x,...f,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:p.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:l,title:h||p.mode.configurePath,style:{...x,background:"transparent",padding:"6px",fontSize:"12px"},...f,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:c?p.mode.switchToGithub:p.mode.switchToLocal,style:x,...f,children:[e.jsx("span",{children:c?"📁":"🌐"}),e.jsx("span",{children:c?p.mode.localMode:p.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&e.jsxs("div",{onClick:a,title:u||p.mode.selectFolder,style:{...x,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...f,children:[e.jsx("span",{children:"📂"}),h&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:h})]}),!c&&h&&e.jsxs("div",{style:{...x,background:i("mode-active-bg"),color:i("on-color-fg"),cursor:"default"},title:u,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:h})]})]})},Ln="bim-search-history",Or=10,Pr=8;function an(){try{const t=localStorage.getItem(Ln);return t?JSON.parse(t):[]}catch{return[]}}function yc(t){try{const n=an().filter(r=>r!==t);n.unshift(t),n.length>Or&&(n.length=Or),localStorage.setItem(Ln,JSON.stringify(n))}catch{}}function jc(t){try{const n=an().filter(r=>r!==t);localStorage.setItem(Ln,JSON.stringify(n))}catch{}}function vc(){try{localStorage.removeItem(Ln)}catch{}}const xs=({transport:t,value:n,onChange:r,onSearch:o,onEntrySelect:s,placeholder:l})=>{const a=ge(),p=l??a.search.placeholder,c={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,u]=m.useState(!1),[h,x]=m.useState([]),[f,b]=m.useState(-1),[w,y]=m.useState(an),j=m.useRef(null),g=m.useRef(null),v=m.useRef(null),$=m.useRef(!1);m.useEffect(()=>{b(-1);const T=n.trim();if(!T){x(w.map(O=>({type:"history",text:O})));return}if(!t.searchAll){x([]);return}let H=!1;const B=setTimeout(()=>{t.searchAll(T,Pr).then(O=>{if(H)return;const D=[...O.works,...O.books,...O.collections,...O.entities??[]];x(D.slice(0,Pr).map(ne=>({type:"entry",text:ne.title||ne.id,entry:ne})))}).catch(()=>{H||x([])})},80);return()=>{H=!0,clearTimeout(B)}},[n,w,t]),m.useEffect(()=>{const T=H=>{v.current&&!v.current.contains(H.target)&&u(!1)};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[]),m.useEffect(()=>{const T=H=>{var B,O;if(H.key==="/"&&document.activeElement!==j.current){const D=(B=document.activeElement)==null?void 0:B.tagName;if(D==="INPUT"||D==="TEXTAREA"||D==="SELECT")return;H.preventDefault(),(O=j.current)==null||O.focus()}};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[]);const k=m.useCallback(T=>{T.trim()&&(yc(T.trim()),y(an())),o(T),u(!1)},[o]),_=m.useCallback(T=>{T.type==="history"?(r(T.text),k(T.text)):T.entry&&(s?(s(T.entry),u(!1)):(r(T.text),k(T.text)))},[r,k,s]),S=m.useCallback(T=>{if(!d||h.length===0){T.key==="Enter"&&k(n);return}switch(T.key){case"ArrowDown":T.preventDefault(),b(H=>(H+1)%h.length);break;case"ArrowUp":T.preventDefault(),b(H=>(H-1+h.length)%h.length);break;case"Enter":T.preventDefault(),f>=0&&f<h.length?_(h[f]):k(n);break;case"Escape":T.preventDefault(),u(!1);break}},[d,h,f,n,k,_]),z=m.useCallback((T,H)=>{H.stopPropagation(),jc(T),y(an()),x(B=>B.filter(O=>!(O.type==="history"&&O.text===T)))},[]),A=m.useCallback(T=>{T.stopPropagation(),vc(),y([]),x([])},[]);m.useEffect(()=>{if(f>=0&&g.current){const T=g.current.children;T[f]&&T[f].scrollIntoView({block:"nearest"})}},[f]);const E=!n.trim()&&w.length>0;return e.jsxs("div",{ref:v,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:j,type:"text",placeholder:p,value:n,onChange:T=>{r(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&&h.length>0&&e.jsxs("div",{ref:g,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:[E&&e.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:[e.jsx("span",{children:a.search.history}),e.jsx("button",{onClick:A,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),h.map((T,H)=>e.jsxs("div",{onClick:()=>_(T),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:i("fg"),background:H===f?i("list-active-bg"):"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:T.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:T.text}),T.entry&&e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:[c[T.entry.type],T.entry.edition&&` · ${T.entry.edition}`,T.entry.author&&` · ${T.entry.author}`]}),T.type==="history"&&e.jsx("button",{onClick:B=>z(T.text,B),style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${T.type}-${T.text}-${H}`))]})]})},Kt=({type:t,size:n=9})=>e.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:n,borderRadius:1,flex:"none",background:i(`type-${t}`),verticalAlign:"middle"}}),An={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},hs=new Set(["work","book","entity"]);function kc(t){return gs(t)||!!t.sort}function wc(t,n){return n.sort&&hs.has(t)?n.sort:void 0}const Bn=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Mn=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Di=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],fs={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function Wn(t){return t.dynasty.length+t.classification.length+(t.hasImage?1:0)+(t.hasText?1:0)+(t.hasCollated?1:0)+(t.loss?1:0)}function gs(t){return Wn(t)>0}function Sc(t){const n=[];return t.dynasty.length&&n.push("dynasty"),t.classification.length&&n.push("classification"),t.hasImage&&n.push("hasImage"),t.hasText&&n.push("hasText"),t.hasCollated&&n.push("hasCollated"),t.loss&&n.push("loss"),n}function bs(t,n){const r=fs[t];return Sc(n).every(o=>r.has(o))}const en=t=>JSON.stringify(t);function $c(t,n){if(!bs(n,t))return null;const r=[];if(t.dynasty.length){const o=Array.from(new Set(t.dynasty.flatMap(s=>{var l;return((l=Bn.find(a=>a.key===s))==null?void 0:l.values)??[]})));o.length===1?r.push(`dynasty = ${en(o[0])}`):o.length>1&&r.push(`dynasty IN [${o.map(en).join(", ")}]`)}return t.classification.length&&r.push(t.classification.length===1?`classification = ${en(t.classification[0])}`:`classification IN [${t.classification.map(en).join(", ")}]`),t.hasImage&&r.push("has_image = true"),t.hasText&&r.push("has_text = true"),t.hasCollated&&r.push("has_collated = true"),t.loss&&r.push(`loss_status = ${en(t.loss)}`),r.join(" AND ")}const Ye={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},ys="_";function Cn(t,n=new URLSearchParams){for(const r of Object.values(Ye))n.delete(r);return t.dynasty.length&&n.set(Ye.dynasty,t.dynasty.join(",")),t.classification.length&&n.set(Ye.classification,t.classification.map(r=>r||ys).join(",")),t.hasImage&&n.set(Ye.hasImage,"1"),t.hasText&&n.set(Ye.hasText,"1"),t.hasCollated&&n.set(Ye.hasCollated,"1"),t.loss&&n.set(Ye.loss,t.loss),t.sort&&n.set(Ye.sort,t.sort),n}function _c(t){const n=l=>(t.get(l)??"").split(",").map(a=>a.trim()).filter(Boolean),r=new Set(Bn.map(l=>l.key)),o=new Set(Mn.map(l=>l.value)),s=t.get(Ye.loss);return{dynasty:Array.from(new Set(n(Ye.dynasty).filter(l=>r.has(l)))),classification:Array.from(new Set(n(Ye.classification).map(l=>l===ys?"":l).filter(l=>o.has(l)))),hasImage:t.get(Ye.hasImage)==="1",hasText:t.get(Ye.hasText)==="1",hasCollated:t.get(Ye.hasCollated)==="1",loss:s==="extant"||s==="partially_extant"||s==="lost"?s:"",sort:["era:asc","era:desc","title:asc","title:desc"].find(l=>l===t.get(Ye.sort))??""}}function zc(t,n){return JSON.stringify([t.dynasty.slice().sort(),t.classification.slice().sort(),t.hasImage,t.hasText,t.hasCollated,t.loss,t.sort])===JSON.stringify([n.dynasty.slice().sort(),n.classification.slice().sort(),n.hasImage,n.hasText,n.hasCollated,n.loss,n.sort])}function Dr(t,n){return t.includes(n)?t.filter(r=>r!==n):[...t,n]}const Cc=({filters:t,onChange:n})=>{const r=ge().searchV4,{convert:o}=G(),[s,l]=m.useState(!1),a=m.useId(),p=Wn(t),c=d=>n({...t,...d});return e.jsxs("aside",{className:"bim-sr-aside","aria-label":o(r.filterTitle),children:[e.jsxs("button",{type:"button",className:"bim-sr-fbtn","aria-expanded":s,"aria-controls":a,onClick:()=>l(d=>!d),children:[e.jsxs("span",{children:[o(r.filterButton),p>0&&e.jsx("span",{className:"bim-sr-fn",children:o(rt(r.filterSelected,{n:p}))})]}),e.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[o(s?r.collapse:r.expand)," ",s?"▴":"▾"]})]}),e.jsxs("div",{className:"bim-sr-filters",id:a,"data-open":s?"true":"false",...s?{}:{"data-collapsed":"true"},children:[e.jsxs("section",{className:"bim-sr-fg",children:[e.jsx("h3",{children:o(r.dynasty)}),e.jsx("div",{className:"bim-sr-chips",children:Bn.map(d=>e.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":t.dynasty.includes(d.key),onClick:()=>c({dynasty:Dr(t.dynasty,d.key)}),children:o(d.key)},d.key))})]}),e.jsxs("section",{className:"bim-sr-fg",children:[e.jsx("h3",{children:o(r.classification)}),Mn.map(d=>e.jsxs("label",{className:"bim-sr-opt",children:[e.jsx("input",{type:"checkbox",checked:t.classification.includes(d.value),onChange:()=>c({classification:Dr(t.classification,d.value)})}),o(d.label)]},d.value||"_"))]}),e.jsxs("section",{className:"bim-sr-fg",children:[e.jsx("h3",{children:o(r.resources)}),e.jsxs("label",{className:"bim-sr-opt",children:[e.jsx("input",{type:"checkbox",checked:t.hasImage,onChange:d=>c({hasImage:d.target.checked})}),o(r.hasImage)]}),e.jsxs("label",{className:"bim-sr-opt",children:[e.jsx("input",{type:"checkbox",checked:t.hasText,onChange:d=>c({hasText:d.target.checked})}),o(r.hasText)]}),e.jsxs("label",{className:"bim-sr-opt",children:[e.jsx("input",{type:"checkbox",checked:t.hasCollated,onChange:d=>c({hasCollated:d.target.checked})}),o(r.hasCollated)]})]}),e.jsxs("section",{className:"bim-sr-fg",children:[e.jsx("h3",{id:`${a}-loss`,children:o(r.extant)}),e.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${a}-loss`,children:Di.map(d=>e.jsx("button",{type:"button","aria-pressed":t.loss===d.value,onClick:()=>c({loss:d.value}),children:o(d.label)},d.value||"all"))})]}),e.jsx("p",{className:"bim-sr-note",children:o(r.onlyWorksNote)}),p>0&&e.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>n({...An,sort:t.sort}),children:o(r.clearAllFilters)})]})]})};function js({text:t,query:n}){const r=(n??"").trim();if(!r||!t)return e.jsx(e.Fragment,{children:t});const o=t.toLowerCase(),s=r.toLowerCase(),l=[];let a=0,p=0;for(;a<t.length;){const c=o.indexOf(s,a);if(c<0){l.push(t.slice(a));break}c>a&&l.push(t.slice(a,c)),l.push(e.jsx("mark",{className:"bim-sr-hl",children:t.slice(c,c+s.length)},p++)),a=c+s.length}return e.jsx(e.Fragment,{children:l})}const Hr=({entries:t,query:n,onEntryLinkClick:r,typeName:o})=>{const s=ge(),l=s.searchV4,{convert:a}=G(),p=Pe();return e.jsx("div",{className:"bim-sr-tablewrap",children:e.jsxs("table",{className:"bim-sr-table",children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"34%"}}),e.jsx("col",{style:{width:"8%"}}),e.jsx("col",{style:{width:"19%"}}),e.jsx("col",{style:{width:"13%"}}),e.jsx("col",{style:{width:"12%"}}),e.jsx("col",{style:{width:"14%"}})]}),e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:a(l.colTitle)}),e.jsx("th",{scope:"col",children:a(l.colType)}),e.jsx("th",{scope:"col",children:a(l.colAuthor)}),e.jsx("th",{scope:"col",children:a(l.colEra)}),e.jsx("th",{scope:"col",children:a(l.colClass)}),e.jsx("th",{scope:"col",style:{textAlign:"right"},children:a(l.colResource)})]})}),e.jsx("tbody",{children:t.map(c=>{const d=a(c.title||c.primary_name||c.id),u=c.measure_info?a(c.measure_info):c.juan_count?`${c.juan_count}${s.unit.juan}`:"",h=c.type==="entity"?[c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:""].filter(Boolean).join(""):c.author?`${a(c.author)}${c.role&&c.role!=="author"?` ${a(c.role)}`:""}`:"",x=c.type==="book"?c.era??c.dynasty:c.dynasty,f=x?a(x):"",b=c.classification?a(c.classification):"",w=[];c.has_image&&w.push({label:l.tagImage,cls:"bim-sr-tag--img"}),c.has_text&&w.push({label:l.tagText,cls:""}),c.has_collated&&w.push({label:l.tagCollated,cls:""}),c.loss_status==="lost"&&w.push({label:l.tagLost,cls:"bim-sr-tag--lost"});const y=[h,f,b].filter(Boolean).join(" · ");return e.jsxs("tr",{children:[e.jsxs("td",{className:"bim-sr-c-title",children:[e.jsxs("div",{className:"bim-sr-tl",children:[e.jsx("a",{href:p(c.id),onClick:j=>r(c,j),children:e.jsx(js,{text:d,query:n?a(n):void 0})}),u&&e.jsx("span",{className:"bim-sr-measure",children:u})]}),y&&e.jsx("span",{className:"bim-sr-sub",children:y})]}),e.jsxs("td",{className:"bim-sr-c-type",children:[e.jsx(Kt,{type:c.type,size:6})," ",o(c.type)]}),e.jsx("td",{className:"bim-sr-c-who",children:h||"—"}),e.jsx("td",{className:"bim-sr-c-era",children:f||"—"}),e.jsx("td",{className:"bim-sr-c-cls",children:b||"—"}),e.jsx("td",{className:"bim-sr-c-res",children:w.map(j=>e.jsx("span",{className:`bim-sr-tag ${j.cls}`,children:a(j.label)},j.label))})]},c.id)})})]})})},Tc=`
|
|
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
|
+
`,Gr=({entries:t,query:n,onEntryLinkClick:r,typeName:o})=>{const s=ge(),l=s.searchV4,{convert:a}=G(),p=Pe();return e.jsxs("div",{className:"bim-sc-grid",children:[e.jsx("style",{children:Tc}),t.map(c=>{const d=a(c.title||c.primary_name||c.id),u=c.measure_info?a(c.measure_info):c.juan_count?`${c.juan_count}${s.unit.juan}`:"",x=[c.type==="entity"?c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:"":`${c.dynasty?`〔${a(c.dynasty)}〕`:""}${c.author?a(c.author):""}`,c.type==="book"&&c.edition?a(c.edition):"",u].filter(Boolean).join(" · "),f=[o(c.type),c.classification?a(c.classification):""].filter(Boolean).join(" · "),b=[];return c.has_image&&b.push({label:l.tagImage,cls:"bim-sr-tag--img"}),c.has_text&&b.push({label:l.tagText,cls:""}),c.has_collated&&b.push({label:l.tagCollated,cls:""}),c.loss_status==="lost"&&b.push({label:l.tagLost,cls:"bim-sr-tag--lost"}),e.jsxs("a",{className:"bim-sc",href:p(c.id),onClick:w=>r(c,w),children:[e.jsx("span",{className:"bim-sc-t",children:e.jsx(js,{text:d,query:n?a(n):void 0})}),x&&e.jsx("span",{className:"bim-sc-m",children:x}),c.descriptionSnippet&&e.jsx("p",{className:"bim-sc-s",children:Bi(c.descriptionSnippet).map((w,y)=>w.marked?e.jsx("mark",{children:a(w.text)},y):e.jsx(m.Fragment,{children:a(w.text)},y))}),e.jsx("span",{className:"bim-sc-sp"}),e.jsxs("div",{className:"bim-sc-f",children:[e.jsx("span",{className:"bim-sc-fl",children:f}),e.jsx("span",{className:"bim-sc-tags",children:b.map(w=>e.jsx("span",{className:`bim-sr-tag ${w.cls}`,children:a(w.label)},w.label))})]})]},c.id)})]})};function Ic(t,n){const r=new Set([1,n,t-1,t,t+1].filter(l=>l>=1&&l<=n)),o=Array.from(r).sort((l,a)=>l-a),s=[];return o.forEach((l,a)=>{a>0&&l-o[a-1]>1&&s.push("gap"),s.push(l)}),s}function Ec(t,n,r){const o=Math.max(1,Math.ceil(n/r));return Math.min(Math.max(1,t),o)}const Nc=({page:t,pageSize:n,total:r,onPage:o})=>{const s=ge().searchV4,{convert:l}=G(),a=Math.max(1,Math.ceil(r/n));return r<=0?null:e.jsxs("nav",{className:"bim-sr-pager","aria-label":l(s.pagerLabel),children:[e.jsx("span",{className:"bim-sr-info",children:l(rt(s.pageInfo,{total:r.toLocaleString(),size:n,page:t,pages:a}))}),a>1&&e.jsxs("ul",{children:[e.jsx("li",{children:e.jsx("button",{type:"button",disabled:t<=1,onClick:()=>o(t-1),children:l(s.prevPage)})}),Ic(t,a).map((p,c)=>p==="gap"?e.jsx("li",{className:"bim-sr-gap","aria-hidden":"true",children:"…"},`g${c}`):e.jsx("li",{children:e.jsx("button",{type:"button","aria-current":p===t?"page":void 0,"aria-label":`${p}`,onClick:()=>o(p),children:p})},p)),e.jsx("li",{children:e.jsx("button",{type:"button",disabled:t>=a,onClick:()=>o(t+1),children:l(s.nextPage)})})]})]})},vs="(max-width: 719px)",Rc=`${vs}, (pointer: coarse)`,Lc=`
|
|
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 ${vs} {
|
|
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 ${Rc} {
|
|
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
|
-
`,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=`
|
|
120
|
+
`,Hi="bim-search-view",ei=50,Vr=5,Ur=1e3,Yr=["work","collection","book","entity"],Ac={work:"works",collection:"collections",book:"books",entity:"entities"},Bc={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function Mc(){try{return window.localStorage.getItem(Hi)==="card"?"card":"table"}catch{return"table"}}function Wc(t){try{window.localStorage.setItem(Hi,t)}catch{}}const tn=(t,n)=>(t==null?void 0:t[Bc[n]])??0,ti=(t,n)=>(t==null?void 0:t[Ac[n]])??[],ks=({transport:t,query:n,filters:r,onFiltersChange:o,onEntryLinkClick:s,typeName:l})=>{const a=ge(),p=a.searchV4,{convert:c}=G(),d=!!t.supportsSearchFilters,u=m.useMemo(()=>d?r:An,[d,r]),[h,x]=m.useState("table");m.useEffect(()=>{x(Mc())},[]);const f=N=>{x(N),Wc(N)},[b,w]=m.useState("all"),[y,j]=m.useState(1),[g,v]=m.useState(null),[$,k]=m.useState(null),[_,S]=m.useState(!1),[z,A]=m.useState(""),E=Cn(u).toString(),T=Wn(u)>0,H=Cn({...u,sort:""}).toString(),B=m.useRef({query:n,filterOnlyKey:H,sort:u.sort});m.useEffect(()=>{const N=B.current;N.query!==n||N.filterOnlyKey!==H?(w("all"),j(1)):N.sort!==u.sort&&j(1),B.current={query:n,filterOnlyKey:H,sort:u.sort}},[n,H,u.sort]),m.useEffect(()=>{let N=!1;return S(!0),A(""),(async()=>{try{let Z;if(t.searchAll)Z=await t.searchAll(n,Vr,u);else{const ce=["work","book","collection","entity"],W=await Promise.all(ce.map(X=>t.search(n,X,{page:1,pageSize:Vr,filters:u})));Z={works:W[0].entries,books:W[1].entries,collections:W[2].entries,entities:W[3].entries,totalWorks:W[0].total,totalBooks:W[1].total,totalCollections:W[2].total,totalEntities:W[3].total}}N||v(Z)}catch(Z){N||(A(Z instanceof Error?Z.message:String(Z)),v(null))}finally{N||S(!1)}})(),()=>{N=!0}},[t,n,E]),m.useEffect(()=>{if(b==="all"){k(null);return}let N=!1;return S(!0),(async()=>{try{const Z=await t.search(n,b,{page:y,pageSize:ei,filters:u});N||k({entries:Z.entries,total:Z.total})}catch(Z){N||(A(Z instanceof Error?Z.message:String(Z)),k(null))}finally{N||S(!1)}})(),()=>{N=!0}},[t,n,E,b,y]),m.useEffect(()=>{if(b==="all"||!$||_)return;const N=Math.min($.total,Ur),Z=Ec(y,N,ei);$.entries.length===0&&N>0&&Z!==y&&j(Z)},[b,$,_,y]);const O=m.useMemo(()=>Yr.filter(N=>tn(g,N)>0),[g]),D=O.reduce((N,Z)=>N+tn(g,Z),0),ne=!_&&!z&&g!==null&&D===0,V=m.useCallback(N=>{w(N),j(1)},[]),C=m.useMemo(()=>{var Z;const N=[];return u.dynasty.forEach(ce=>N.push({name:ce,remove:()=>o({...u,dynasty:u.dynasty.filter(W=>W!==ce)})})),u.classification.forEach(ce=>{var W;return N.push({name:((W=Mn.find(X=>X.value===ce))==null?void 0:W.label)??ce,remove:()=>o({...u,classification:u.classification.filter(X=>X!==ce)})})}),u.hasImage&&N.push({name:p.hasImage,remove:()=>o({...u,hasImage:!1})}),u.hasText&&N.push({name:p.hasText,remove:()=>o({...u,hasText:!1})}),u.hasCollated&&N.push({name:p.hasCollated,remove:()=>o({...u,hasCollated:!1})}),u.loss&&N.push({name:`${p.extant}:${((Z=Di.find(ce=>ce.value===u.loss))==null?void 0:Z.label)??""}`,remove:()=>o({...u,loss:""})}),N},[u,o,p]),xe={query:n,onEntryLinkClick:s,typeName:l},L=N=>h==="table"?e.jsx(Hr,{entries:N,...xe}):e.jsx(Gr,{entries:N,...xe}),te=Yr.flatMap(N=>ti(g,N));return e.jsxs("div",{className:"bim-sr-layout","data-nofilters":d?void 0:"true",children:[e.jsx("style",{children:Lc}),d&&e.jsx(Cc,{filters:u,onChange:o}),e.jsxs("div",{className:"bim-sr-main","aria-busy":_,children:[O.length>0&&e.jsxs("div",{className:"bim-sr-tabs",role:"group","aria-label":a.search.resultTabs,style:{display:"flex",flexWrap:"wrap",gap:"0 4px",borderBottom:`1px solid ${i("rule")}`},children:[e.jsxs(Kr,{on:b==="all",onClick:()=>V("all"),children:[a.search.allTab," ",e.jsx("small",{children:D.toLocaleString()})]}),O.map(N=>e.jsxs(Kr,{on:b===N,onClick:()=>V(N),children:[l(N)," ",e.jsx("small",{children:tn(g,N).toLocaleString()})]},N))]}),e.jsxs("div",{className:"bim-sr-tools",children:[d&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":c(p.sortLabel),children:[e.jsx("button",{type:"button","aria-pressed":!u.sort,onClick:()=>o({...u,sort:""}),children:c(p.sortRelevance)}),["era","title"].map(N=>{const Z=u.sort.startsWith(`${N}:`)?u.sort.endsWith("desc")?"desc":"asc":null,ce=N==="era"?p.sortEra:p.sortTitle,W=N==="era"?Z==="desc"?p.sortEraDesc:p.sortEraAsc:Z==="desc"?p.sortTitleDesc:p.sortTitleAsc;return e.jsxs("button",{type:"button","aria-pressed":Z!==null,title:c(W),onClick:()=>o({...u,sort:`${N}:${Z==="asc"?"desc":"asc"}`}),children:[c(ce),Z?e.jsxs("span",{"aria-hidden":"true",children:[" ",Z==="asc"?"↑":"↓"]}):null]},N)})]}),e.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),e.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":c(p.viewLabel),children:[e.jsx("button",{type:"button","aria-pressed":h==="table",onClick:()=>f("table"),children:c(p.viewTable)}),e.jsx("button",{type:"button","aria-pressed":h==="card",onClick:()=>f("card"),children:c(p.viewCard)})]})]}),T&&e.jsxs("div",{className:"bim-sr-chips-row",children:[e.jsx("span",{className:"bim-sr-count",role:"status",children:c(rt(p.filteredCount,{n:D.toLocaleString()}))}),C.map(N=>e.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":c(rt(p.removeFilter,{name:N.name})),onClick:N.remove,children:[c(N.name),e.jsx("span",{"aria-hidden":"true",children:"×"})]},N.name))]}),z&&e.jsx("div",{className:"bim-sr-empty",role:"alert",children:z}),ne&&e.jsx("div",{className:"bim-sr-empty",children:c(T?p.emptyFiltered:rt(a.search.noResultsFor,{query:n}))}),!z&&!ne&&b==="all"&&g&&(h==="table"?e.jsxs(e.Fragment,{children:[e.jsx(Hr,{entries:te,...xe}),e.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:c(p.limitedNote)})]}):e.jsx(e.Fragment,{children:O.map(N=>e.jsxs("section",{style:{marginTop:22},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[e.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[e.jsx(Kt,{type:N,size:8}),l(N),e.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:i("meta-fg")},children:[tn(g,N).toLocaleString()," ",a.unit.items]})]}),tn(g,N)>ti(g,N).length&&e.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>V(N),children:a.action.viewAll})]}),e.jsx(Gr,{entries:ti(g,N),...xe})]},N))})),!z&&b!=="all"&&$&&$.entries.length>0&&e.jsxs(e.Fragment,{children:[L($.entries),e.jsx(Nc,{page:y,pageSize:ei,total:Math.min($.total,Ur),onPage:j})]}),!z&&b!=="all"&&$&&$.entries.length===0&&!_&&e.jsxs("div",{className:"bim-sr-empty",children:[c(T?p.emptyFiltered:rt(a.search.noResultsFor,{query:n})),e.jsx("div",{children:e.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>V("all"),children:a.search.allTab})})]})]})]})};function Kr({on:t,onClick:n,children:r}){return e.jsx("button",{type:"button","aria-pressed":t,onClick:n,style:{border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:14.5,minHeight:44,padding:"8px 12px",letterSpacing:".06em",color:i(t?"ink":"meta-fg"),fontWeight:t?700:400,boxShadow:t?`inset 0 -2px 0 ${i("accent")}`:"none"},children:r})}const Pt="bim-recent-ids",qr="bim-recent-entries",Jr=50,ni=5,Fc=50,Oc=200;function Ft(){try{const t=localStorage.getItem(Pt);if(t)return JSON.parse(t);const n=localStorage.getItem(qr);if(n){const r=JSON.parse(n).map(o=>o.id);return localStorage.setItem(Pt,JSON.stringify(r)),localStorage.removeItem(qr),r}return[]}catch{return[]}}function Zr(t){try{const n=Ft().filter(r=>r!==t);n.unshift(t),n.length>Jr&&(n.length=Jr),localStorage.setItem(Pt,JSON.stringify(n))}catch{}}function Pc(t){try{const n=Ft().filter(r=>r!==t);localStorage.setItem(Pt,JSON.stringify(n))}catch{}}function Dc(){try{localStorage.removeItem(Pt)}catch{}}const Xr={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},fi=({transport:t,indexSource:n="local",syncConfig:r,onEntryClick:o,onNewEntry:s,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c,hideModeIndicator:d,resultVariant:u="compact",renderEntry:h,initialQuery:x,onQueryChange:f,headerRight:b,reserveViewportHeight:w=!1,filtersEnabled:y=!1,filters:j=An,onFiltersChange:g})=>{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]=m.useState(x??""),[z,A]=m.useState(null),[E,T]=m.useState(x??""),H=Cn(j).toString(),[B,O]=m.useState(j);m.useEffect(()=>{O(j)},[H]);const D=le=>{O(le),g==null||g(le)},[ne,V]=m.useState(null),[C,xe]=m.useState("all"),[L,te]=m.useState(!1),[N,Z]=m.useState(null),[ce,W]=m.useState(""),[X,ae]=m.useState(!(x!=null&&x.trim())),[de,me]=m.useState(Ft),[$e,Me]=m.useState([]),[Ee,Le]=m.useState(!1),[ze,Ae]=m.useState(!1),[P,he]=m.useState(null),[ie,ke]=m.useState(null),we=m.useRef(void 0),Y=m.useRef(!1),R=m.useCallback(async(le,_e)=>{if(!le.trim()){ae(!0),A(null),V(null);return}if(ae(!1),y){T(le);return}te(!0),W("");try{if(t.searchAll){const I=await t.searchAll(le,_e??ni);A(I)}else{const I=["work","book","collection","entity"],J=await Promise.all(I.map(oe=>t.search(le,oe,{page:1,pageSize:_e??ni})));A({works:J[0].entries,books:J[1].entries,collections:J[2].entries,entities:J[3].entries,totalWorks:J[0].total,totalBooks:J[1].total,totalCollections:J[2].total,totalEntities:J[3].total})}}catch(I){W(I instanceof Error?I.message:String(I)),A(null)}finally{te(!1)}},[t,y]);m.useEffect(()=>{let le=!1;const _e=()=>{var ee,Se;const I=["work","book","collection","entity"],J=Promise.all(I.map(F=>t.loadEntries(F,{page:1,pageSize:1}).catch(()=>({total:0})))),oe=((ee=t.getResourceCounts)==null?void 0:ee.call(t).catch(()=>null))??Promise.resolve(null),Q=((Se=t.getSubtypeStats)==null?void 0:Se.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([J,oe,Q]).then(([F,ve,We])=>{le||(he({works:F[0].total,books:F[1].total,collections:F[2].total,entities:F[3].total,hasText:ve==null?void 0:ve.hasText,hasImage:ve==null?void 0:ve.hasImage}),We&&ke(We))})};return t.getCounts?t.getCounts().then(I=>{var J,oe;le||(he({works:I.works,books:I.books,collections:I.collections,entities:I.entities,hasText:(J=I.resourceCounts)==null?void 0:J.hasText,hasImage:(oe=I.resourceCounts)==null?void 0:oe.hasImage}),I.subtypeStats&&ke(I.subtypeStats))}).catch(()=>{le||_e()}):_e(),()=>{le=!0}},[t]),m.useEffect(()=>{Y.current||!(x!=null&&x.trim())||(Y.current=!0,R(x))},[x,R]);const U=m.useCallback(le=>{if(S(le),!le.trim()){f==null||f(le),ae(!0),A(null),V(null),xe("all");return}we.current&&clearTimeout(we.current),we.current=setTimeout(()=>{V(null),xe("all"),f==null||f(le),R(le)},Oc)},[R,f]),fe=m.useCallback(le=>{we.current&&clearTimeout(we.current),xe("all"),f==null||f(le),R(le)},[R,f]),be=m.useCallback(le=>{V(le),R(_,Fc)},[_,R]);m.useEffect(()=>{if(!de.length){Me([]);return}let le=!1;return Le(!0),Promise.all(de.slice(0,10).map(async _e=>{var I,J,oe;try{if(t.getEntry){const ee=await t.getEntry(_e);if(ee)return ee}const Q=await t.getItem(_e);if(Q){const ee=Q.authors;return{id:_e,title:Q.title||_e,type:Q.type||"work",author:(I=ee==null?void 0:ee[0])==null?void 0:I.name,dynasty:(J=ee==null?void 0:ee[0])==null?void 0:J.dynasty,role:(oe=ee==null?void 0:ee[0])==null?void 0:oe.role,edition:Q.edition||void 0}}}catch{}return{id:_e,title:_e,type:"work",notFound:!0}})).then(_e=>{le||(Me(_e),Le(!1))}),()=>{le=!0}},[de,t]);const M=le=>{Z(le.id),Zr(le.id),me(Ft()),o==null||o(le)},ue=(le,_e)=>{if(o&&Gc(_e)){_e.preventDefault(),M(le);return}Zr(le.id),me(Ft())},K=le=>{Pc(le),me(Ft())},se=()=>{Dc(),me([])},je=le=>$.find(_e=>_e.type===le),Te=!X&&!z&&!ce,Ce=z&&(z.works.length>0||z.books.length>0||z.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",style:w?{minHeight:"100svh"}:void 0,children:[e.jsx("style",{children:Vc}),e.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:i("fg")},children:v.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&e.jsx(ms,{variant:"index-browser",indexSource:n,syncConfig:r,onSwitchMode:l,onToggleDraft:a,onConfigurePath:p,onSelectFolder:c})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(xs,{transport:t,value:_,onChange:U,onSearch:fe,onEntrySelect:M}),s&&e.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})]}),X&&e.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&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:ie?e.jsxs(e.Fragment,{children:[(ie.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:i("fg")},children:ie.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:i("fg")},children:P.books.toLocaleString()})," 本"]}),ie.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:i("fg")},children:ie.article.toLocaleString()})," 篇"]}):null,ie.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:i("fg")},children:ie.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:i("fg")},children:P.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[v.indexType.work," ",e.jsx("strong",{style:{color:i("fg")},children:P.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.book," ",e.jsx("strong",{style:{color:i("fg")},children:P.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.collection," ",e.jsx("strong",{style:{color:i("fg")},children:P.collections.toLocaleString()}),P.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.entity," ",e.jsx("strong",{style:{color:i("fg")},children:P.entities.toLocaleString()})]})]})}),P.hasImage!=null&&P.hasText!=null&&e.jsxs("span",{children:[v.resourceType.image," ",e.jsx("strong",{style:{color:i("fg")},children:P.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.resourceType.text," ",e.jsx("strong",{style:{color:i("fg")},children:P.hasText.toLocaleString()})]})]})}),y&&!X&&e.jsx(ks,{transport:t,query:E,filters:B,onFiltersChange:D,onEntryLinkClick:ue,typeName:le=>je(le).name}),!(y&&!X)&&e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:L||Te?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg"),minHeight:Hc,boxSizing:"border-box"},children:v.search.searching}):ce?e.jsx("div",{style:{textAlign:"center",padding:"40px"},children:e.jsx("p",{style:{color:i("desc-fg")},children:ce})}):X?e.jsx("div",{style:{flex:1},children:Ee?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg")},children:v.search.loading}):$e.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:i("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:v.search.recentBrowse}),e.jsx("button",{onClick:se,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:v.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:$e.slice(0,ze?10:3).map(le=>le.notFound?e.jsx(qc,{id:le.id,onRemove:K,t:v},le.id):e.jsx(Qr,{entry:le,selected:N===le.id,onClick:ue,getConfig:je,onRemove:K},le.id))}),!ze&&$e.length>3&&e.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})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:v.search.searchTitle}),e.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:v.search.searchSubtitle})]})}):Ce?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[e.jsx("style",{children:Uc}),(()=>{const le=Q=>z[Xr[Q]]??0,_e=k.map(Q=>$.find(ee=>ee.type===Q)).filter(Q=>le(Q.key)>0);if(_e.length<2)return null;const I=_e.reduce((Q,ee)=>Q+le(ee.key),0),J=Q=>{if(xe(Q),Q!=="all"&&ne!==Q){const ee=$.find(F=>F.type===Q),Se=(z[ee.key]??[]).length;le(ee.key)>Se&&be(Q)}},oe=Q=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:i(Q?"fg":"desc-fg"),fontWeight:Q?700:400,boxShadow:Q?`inset 0 -2px 0 ${i("primary")}`:"none"});return e.jsxs("div",{role:"group","aria-label":v.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsxs("button",{type:"button","aria-pressed":C==="all",style:oe(C==="all"),onClick:()=>J("all"),children:[v.search.allTab," ",e.jsx("span",{style:{fontSize:12,fontWeight:400},children:I.toLocaleString()})]}),_e.map(Q=>e.jsxs("button",{type:"button","aria-pressed":C===Q.type,style:oe(C===Q.type),onClick:()=>J(Q.type),children:[Q.name," ",e.jsx("span",{style:{fontSize:12,fontWeight:400},children:le(Q.key).toLocaleString()})]},Q.type))]})})(),$.map(({type:le,name:_e,key:I})=>{const J=z[I]??[],oe=Xr[I],Q=z[oe]??0;if(J.length===0||C!=="all"&&C!==le)return null;const Se=C==="all"&&!(ne===le)&&Q>ni;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:[e.jsx(Kt,{type:le})," ",_e,e.jsxs("span",{style:{fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[Q," ",v.unit.items]})]}),Se&&e.jsx("button",{className:"bim-ib-viewall",onClick:()=>be(le),style:{border:"none",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"12px"},children:v.action.viewAll})]}),e.jsx("div",{style:u==="list"?{display:"flex",flexDirection:"column",gap:0}:u==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:J.map(F=>{if(h)return e.jsx(m.Fragment,{children:h(F)},F.id);const ve=u==="card"?Kc:Qr;return e.jsx(ve,{entry:F,selected:N===F.id,onClick:ue,getConfig:je,query:_},F.id)})})]},le)})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:rt(v.search.noResultsFor,{query:_})}),e.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:v.search.tryOther})]})})]})},Hc=240;function Gc(t){return t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&!t.altKey}const Vc=`
|
|
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
|
+
`,Uc=`
|
|
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
|
-
}`,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==="\\"){
|
|
132
|
-
`)<0?{node:{type:"qw",label:
|
|
133
|
-
`)return null}const
|
|
134
|
-
.bim-d-main.bim-d-main-grid { max-width: ${
|
|
130
|
+
}`,ws={color:"inherit",textDecoration:"none"},Yc=({snippet:t})=>{const{convert:n}=G();return e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.6},children:Bi(t).map((r,o)=>r.marked?e.jsx("mark",{style:{background:i("highlight-bg"),color:i("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(r.text)},o):e.jsx(m.Fragment,{children:n(r.text)},o))})},Kc=({entry:t,selected:n,onClick:r,getConfig:o,query:s})=>{const l=ge(),{convert:a}=G(),p=a(t.title||t.primary_name||t.id),c=t.measure_info?a(t.measure_info):t.juan_count!=null&&t.juan_count>0?`${t.juan_count}${l.unit.juan}`:"",d=[...t.additional_titles||[],...t.attached_texts||[]],u=s&&d.length?d.find(f=>{const b=typeof f=="string"?f:f==null?void 0:f.book_title;return b==null?void 0:b.toLowerCase().includes(s.toLowerCase())}):void 0,h=i("cover-accent"),x=Pe();return e.jsxs("a",{href:x(t.id),onClick:f=>r(t,f),className:"bim-result-card",style:{...ws,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:[e.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${h} 50%, ${i("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${h} 14%, ${i("bg")}), color-mix(in srgb, ${h} 7%, ${i("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[e.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${h} 45%, transparent)`}}),e.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:h},children:Array.from(p).map((f,b)=>e.jsx("span",{children:f},b))})]}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:i("fg")},children:p}),c&&e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:c})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg")},children:[t.dynasty&&e.jsxs("span",{children:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]})]}),(t.era||t.edition)&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[t.era&&e.jsxs("span",{children:["〔",a(t.era),"〕"]}),t.edition&&e.jsx("span",{children:a(t.edition)})]}),u&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[l.search.alias,":",a(typeof u=="string"?u:u.book_title||"")]}),t.descriptionSnippet&&e.jsx(Yc,{snippet:t.descriptionSnippet}),e.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:[e.jsx(Kt,{type:t.type,size:8})," ",o(t.type).name]}),t.has_text&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.textResource}),t.has_image&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:i("desc-fg"),border:`1px solid ${i("widget-border")}`},children:l.misc.imageResource})]})]})]})},Qr=({entry:t,selected:n,onClick:r,getConfig:o,query:s,onRemove:l})=>{const a=ge(),{convert:p}=G(),c=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&c.length?c.find(h=>{const x=typeof h=="string"?h:h==null?void 0:h.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,u=Pe();return e.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:[e.jsxs("a",{href:u(t.id),onClick:h=>r(t,h),className:"bim-result-card",style:{...ws,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:l?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx(Kt,{type:t.type,size:12}),e.jsx("span",{style:{fontSize:"9px",color:i("desc-fg"),lineHeight:1},children:o(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg")},children:p(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{children:a.misc.textResource}),t.has_image&&e.jsx("span",{children:a.misc.imageResource})]}),(t.era||t.edition)&&e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[t.era&&e.jsxs(e.Fragment,{children:["〔",p(t.era),"〕"]}),t.edition&&p(t.edition)]}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:p(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[t.juan_count,a.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",p(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:p(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",p(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:[a.search.alias,":",p(d)]})]}),!l&&e.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),l&&e.jsx("button",{type:"button",onClick:()=>l(t.id),title:a.search.removeFromRecent,"aria-label":a.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:"×"})]})},qc=({id:t,onRemove:n,t:r})=>e.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:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:i("fg"),fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:r.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:r.search.removeFromRecent,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Jc(t){var n;return!t.dynasty&&!t.birth_year&&!t.death_year&&(!t.alt_names||t.alt_names.length===0)&&!((n=t.description)!=null&&n.text)}function Zc({data:t}){const{convert:n}=G(),{dynasty:r,birth_year:o,death_year:s}=t,l=[];return r&&l.push(`〔${n(r)}〕`),o!==void 0&&s!==void 0?l.push(`${o}—${s}`):o!==void 0?l.push(`${o}—?`):s!==void 0&&l.push(`?—${s}`),l.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:i("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function Xc({alt_names:t}){const{convert:n}=G(),r=new Map;for(const l of t){const a=l.type||"別名";r.has(a)||r.set(a,[]),r.get(a).push(l.name)}const o=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...r.keys()].sort((l,a)=>{const p=o.indexOf(l),c=o.indexOf(a);return p===-1&&c===-1?0:p===-1?1:c===-1?-1:p-c});return e.jsx("div",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(l=>{const a=r.get(l);return e.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[e.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),e.jsx("span",{children:a.map((p,c)=>e.jsxs("span",{children:[c>0&&e.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),n(p)]},c))})]},l)})})}function Qc({data:t}){const n=t.external_ids;if(!n)return null;const r=[];return n.cbdb_id&&r.push(e.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")),r.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:r})}function ed({works:t,transport:n,onNavigate:r,renderLink:o}){const s=ge(),{convert:l}=G(),a=Pe(),[p,c]=m.useState(new Map);m.useEffect(()=>{if(!n)return;let x=!1;const f=t.map(w=>w.work_id);return(async()=>{const w=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(f);let $=!0;for(let k=0;k<f.length;k++){const _=v[k];_!=null&&_.title?w.set(f[k],_.title):_!=null&&_.primary_name?w.set(f[k],_.primary_name):$=!1}if($)return w}catch{}const y=[...f],j=8,g=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(g),w})().then(w=>{x||c(w)}),()=>{x=!0}},[t,n]);const d=new Map;for(const x of t){const f=x.role||"";d.has(f)||d.set(f,[]),d.get(f).push(x)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],h=[...d.keys()].sort((x,f)=>{const b=u.indexOf(x),w=u.indexOf(f);return b===-1&&w===-1?x.localeCompare(f):b===-1?1:w===-1?-1:b-w});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.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," ",e.jsxs("span",{style:{color:i("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),h.map(x=>{const f=d.get(x);return e.jsxs("div",{style:{marginBottom:"8px"},children:[x&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"2px"},children:[l(x)," ",e.jsxs("span",{style:{color:i("desc-fg")},children:["(",f.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:x?"16px":"0",listStyle:x?"disc":"none",fontSize:"14px",lineHeight:1.8},children:f.map((b,w)=>{const y=l(p.get(b.work_id)||b.work_id);return o?e.jsx("li",{children:o(b.work_id,y)},w):r?e.jsx("li",{children:e.jsx("a",{href:a(b.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),r(b.work_id))},style:{color:i("link-fg"),textDecoration:"underline",cursor:"pointer"},children:y})},w):e.jsx("li",{children:y},w)})})]},x)})]})}const Ss=({data:t,transport:n,onNavigate:r,renderLink:o,headerExtra:s,hideHeader:l})=>{var h;const a=ge(),{convert:p}=G();let c=!1;try{c=ye.extractStatus(t.id)==="draft"}catch{}const d=Jc(t),u=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[!l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:i("fg")},children:[p(t.primary_name),e.jsx(Zc,{data:t})]}),s]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:i("desc-fg"),marginBottom:"8px"},children:[e.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:a.indexType.entity}),u&&t.subtype!=="people"&&e.jsx("span",{children:u}),c&&e.jsx("span",{style:{padding:"1px 6px",background:i("warn-bg"),border:`1px solid ${i("warn-border")}`,borderRadius:"2px",color:i("warn-fg")},children:a.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]})]}),d&&e.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 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(Xc,{alt_names:t.alt_names}),e.jsx(Qc,{data:t}),((h=t.description)==null?void 0:h.text)&&e.jsx("p",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:p(t.description.text)}),t.works&&t.works.length>0&&e.jsx(ed,{works:t.works,transport:n,onNavigate:r,renderLink:o})]})},td=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function nd(t){const n=t.search(td);return n<0?[t,""]:[t.slice(0,n),t.slice(n)]}const $s={p:({children:t})=>e.jsx("p",{style:{margin:"0 0 0.5em"},children:t}),ul:({children:t})=>e.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:t}),ol:({children:t})=>e.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:t}),li:({children:t})=>e.jsx("li",{style:{marginBottom:"2px"},children:t}),a:({href:t,children:n})=>{let r=t,o="",s=n;if(t&&typeof n=="string"&&(n===t||n===id(t))){const[l,a]=nd(n);a&&(r=encodeURI(l),s=l,o=a)}return e.jsxs(e.Fragment,{children:[e.jsx("a",{href:r,target:r!=null&&r.startsWith("http")?"_blank":void 0,rel:r!=null&&r.startsWith("http")?"noopener noreferrer":void 0,style:{color:i("link")},children:s}),o]})},code:({children:t})=>e.jsx("code",{style:{background:i("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:t})};function id(t){try{return decodeURI(t)}catch{return t}}const rd={...$s,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},bt=({text:t,plainStrong:n,style:r,className:o})=>{const{convert:s}=G(),l=n?rd:$s;return e.jsx("div",{className:o,style:r,children:e.jsx(Ua,{remarkPlugins:[Ya],components:l,children:s(t)})})},od=["〇","一","二","三","四","五","六","七","八","九"],eo=["","十","百","千"];function _s(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),r=n.length;let o="",s=!1;for(let l=0;l<r;l++){const a=parseInt(n[l]),p=r-1-l;a===0?s=!0:(s&&o&&(o+="〇"),s=!1,a===1&&p===1&&l===0?o+=eo[p]:o+=od[a]+eo[p])}return o}function zs(t){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t,border:`1px solid color-mix(in srgb, ${t} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${t} 3%, transparent)`}}const sd={book:i("type-book"),work:i("type-work"),collection:i("type-collection"),entity:i("type-entity")};function ld({type:t}){const n=ge();return e.jsx("span",{style:zs(sd[t]),children:n.indexType[t]})}function ad({isDraft:t}){const n=ge(),r=i(t?"status-draft":"status-official");return e.jsx("span",{style:zs(r),children:t?n.status.draft:n.status.official})}function cd({id:t}){const n=ge(),[r,o]=m.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})};return e.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:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:i("fg")},children:t}),e.jsx("span",{onClick:s,title:r?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:r?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=r?"1":"0.5",children:r?"✓":"⧉"})]})}function tt({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("desc-fg"),letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function pt({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:t}),e.jsx("span",{style:{color:i("fg")},children:n})]})}function Cs({authors:t,type:n,onNavigate:r,renderLink:o}){const{convert:s}=G();return e.jsx("span",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.6},children:t.map((l,a)=>{const p=s(l.name),c=l.entity_id?e.jsx(ot,{id:l.entity_id,label:p,onNavigate:r,renderLink:o}):e.jsx("span",{style:{fontWeight:500},children:p});return e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),l.dynasty&&e.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:["〔",s(l.dynasty),"〕"]}),c,l.role&&e.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(l.role)]})]},a)})})}function ot({id:t,label:n,onNavigate:r,renderLink:o}){const s=Pe();return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:s(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),r(t))},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||t}):e.jsx("span",{children:n||t})}function dd({id:t,title:n,edition:r,type:o,isDraft:s,authors:l,volumeText:a,meta:p,headerExtra:c,onNavigate:d,renderLink:u}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.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,r&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:r}),a&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:a})]}),c&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(ld,{type:o}),e.jsx(ad,{isDraft:s}),e.jsx(cd,{id:t})]}),((l==null?void 0:l.length)||p.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&e.jsx(Cs,{authors:l,type:o,onNavigate:d,renderLink:u}),p]})]})}function Ts({items:t,label:n,showMeta:r,onNavigate:o,renderLink:s}){const l=ge(),{convert:a}=G();if(!t.length)return null;const[p,c]=m.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(tt,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,u)=>{const h=p===u;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...h?{boxShadow:i("shadow-card")}:{}},children:[e.jsxs("div",{onClick:()=>c(h?null:u),style:{padding:"8px 12px",background:i("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.15s",transform:h?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:a(d.source)}),!h&&r&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:x=>x.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ot,{id:d.source_bid,label:l.action.view,onNavigate:o,renderLink:s})})]}),h&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${i("widget-border")}`},children:[r&&(d.title_info||d.author_info||d.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&e.jsx(pt,{label:l.label.titleInfo,children:a(d.title_info)}),d.author_info&&e.jsx(pt,{label:l.label.authorInfo,children:a(d.author_info)}),d.edition&&e.jsx(pt,{label:l.label.edition,children:a(d.edition)})]}),d.summary&&e.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:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:a(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.additional_comment)})]})]})]},u)})})]})}function pd({items:t,onNavigate:n,renderLink:r}){const o=ge();return e.jsx(Ts,{items:t,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:r})}function Is({items:t,onNavigate:n,renderLink:r}){const o=ge();return e.jsx(Ts,{items:t,label:o.section.emendated,onNavigate:n,renderLink:r})}function Es({label:t,items:n}){const{convert:r}=G();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(tt,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((o,s)=>{const l=typeof o=="string"?o:o.book_title;return e.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:r(l)},s)})})]}):null}function ud({items:t}){const n=ge();return e.jsx(Es,{label:n.section.aliases,items:t})}function md({items:t}){const n=ge();return e.jsx(Es,{label:n.section.attachedTexts,items:t})}function xd({items:t}){const n=ge(),{convert:r}=G();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(tt,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,s)=>e.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:["《",r(o.book_title),"》",o.n_juan!=null&&e.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},s))})]}):null}function hd({items:t}){const n=ge(),{convert:r}=G();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(tt,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:i("widget-border")}}),t.map((o,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.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")}`}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:i("fg")},children:r(o.name)}),o.description&&e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),marginLeft:"8px"},children:r(o.description)})]},s))]})]}):null}function fd({items:t}){const n=ge(),{convert:r}=G();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(tt,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((o,s)=>e.jsxs("div",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:i("desc-fg")},children:"·"}),r(o)]},s))})]}):null}function to({title:t,ids:n,transport:r,onNavigate:o,renderLink:s}){const{convert:l}=G(),[a,p]=m.useState([]);return m.useEffect(()=>{if(!n.length){p([]);return}if(!r){p(n.map(d=>({id:d})));return}let c=!1;return Promise.all(n.map(d=>r.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{c||p(d)}),()=>{c=!0}},[n,r]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(tt,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(a.length?a:n.map(c=>({id:c}))).map(c=>{const d=c.edition?`${l(c.title)||c.id}(${l(c.edition)})`:l(c.title)||void 0;return e.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:e.jsx(ot,{id:c.id,label:d,onNavigate:o,renderLink:s})},c.id)})})]}):null}function ii({book:t,onNavigate:n,renderLink:r}){const o=ge(),{convert:s}=G(),[l,a]=m.useState(!1),p=t.resources&&t.resources.length>0,c=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:i("input-bg")},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:p&&!l?`1px solid ${i("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:e.jsx(ot,{id:t.id,label:c,onNavigate:n,renderLink:r})}),p&&e.jsx("span",{onClick:()=>a(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?o.action.expand:o.action.collapse,children:"▼"})]}),p&&!l&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(Pi,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:r})})]})}function gd({ids:t,workData:n,transport:r,onNavigate:o,renderLink:s,footer:l}){const a=ge(),{convert:p}=G(),[c,d]=m.useState([]);if(m.useEffect(()=>{if(!t.length){d([]);return}if(!r){d(t.map(w=>({id:w})));return}let b=!1;return Promise.all(t.map(w=>r.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}},[t,r]),!t.length)return null;const u=c.length?c:t.map(b=>({id:b})),h=new Map(u.map(b=>[b.id,b])),x=n==null?void 0:n.version_graph,f=bd(t,x);return e.jsxs(e.Fragment,{children:[e.jsxs(tt,{children:[a.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",t.length,")"]})]}),l,f.useGrouping?e.jsxs(e.Fragment,{children:[f.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:f.coreIds.map(b=>{const w=h.get(b);return w?e.jsx(ii,{book:w,onNavigate:o,renderLink:s},b):null})}),f.groupedIds.map(b=>e.jsxs("details",{style:{marginTop:12,border:`1px solid ${i("widget-border")}`,borderRadius:6,background:i("bg-subtle")},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:i("fg"),userSelect:"none"},children:[p(b.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:i("desc-fg"),fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:i("desc-fg"),fontWeight:400},children:p(b.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(w=>{const y=h.get(w);return y?e.jsx(ii,{book:y,onNavigate:o,renderLink:s},w):null})})]},b.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(b=>e.jsx(ii,{book:b,onNavigate:o,renderLink:s},b.id))})]})}function bd(t,n){var y,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const r=(y=n.collections)==null?void 0:y[n.default_collection],o=(r==null?void 0:r.groups)??[],s=(r==null?void 0:r.book_ids)??[],l=o.length>0||s.length>0,a=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const p=new Set(o),c=new Set([...s,...a]),d=g=>{if(c.has(g))return!0;const v=n.node_groups[g];return v!=null&&p.has(v)},u=[],h=new Map,x=[];for(const g of t)if(!((j=n.excluded_books)!=null&&j.includes(g)))if(d(g))u.push(g);else{const v=n.node_groups[g];v?(h.has(v)||h.set(v,[]),h.get(v).push(g)):x.push(g)}if(x.length+[...h.values()].reduce((g,v)=>g+v.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(g=>[g.id,g])),w=[...h.entries()].map(([g,v])=>{const $=b.get(g);return{id:g,label:($==null?void 0:$.label)??g,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 yd({workData:t,onNavigate:n,renderLink:r}){var a,p,c,d;const o=ge(),{convert:s}=G(),l=!!((a=t.description)!=null&&a.text)||!!t.parent_work;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:i("input-bg"),marginTop:"4px"},children:[e.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:[e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:e.jsx(ot,{id:t.id,label:s(t.title),onNavigate:n,renderLink:r})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:s(t.measure_info)}):((p=t.juan_count)==null?void 0:p.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[_s(t.juan_count.number),o.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(Cs,{authors:t.authors,type:"work",onNavigate:n,renderLink:r})})]}),l&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((c=t.description)==null?void 0:c.text)&&e.jsx(bt,{text:t.description.text,style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,textAlign:"justify"}}),t.parent_work&&e.jsx("div",{style:{marginTop:(d=t.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:e.jsx(pt,{label:o.label.parentWork,children:e.jsx(ot,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:r})})})]})]})}function jd({items:t,onNavigate:n,renderLink:r}){const o=ge(),{convert:s}=G();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(l=>e.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:[e.jsx("span",{style:{fontSize:"11px",color:i("type-collection")},children:o.indexType.collection}),e.jsx(ot,{id:l.id,label:s(l.title)||l.id,onNavigate:n,renderLink:r}),l.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"2px"},children:rt(o.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Gi=({data:t,id:n,transport:r,onNavigate:o,renderLink:s,headerExtra:l,relatedBooksFooter:a,className:p,style:c})=>{var H,B,O,D,ne,V,C,xe;const d=ge(),{convert:u}=G(),[h,x]=m.useState(null),[f,b]=m.useState(!1),[w,y]=m.useState(null),[j,g]=m.useState(null),[v,$]=m.useState([]),k=t||h;if(m.useEffect(()=>{if(t||!n||!r)return;let L=!1;return b(!0),y(null),r.getItem(n).then(te=>{L||(te?x(te):y(d.misc.notFoundEntry))}).catch(te=>{L||y(te instanceof Error?te.message:d.misc.loadFailed)}).finally(()=>{L||b(!1)}),()=>{L=!0}},[t,n,r]),m.useEffect(()=>{if(!k||!r){g(null),$([]);return}let L=!1;const te=k.type==="book"||k.type==="collection"?k.work_id:void 0;if(te?r.getItem(te).then(N=>{!L&&N&&N.type==="work"&&g(N)}).catch(()=>{}):g(null),k.type==="book"){const N=k;N.contained_in&&N.contained_in.length>0?Promise.all(N.contained_in.map(Z=>{const ce=typeof Z=="string"?Z:Z.id,W=typeof Z=="string"?void 0:Z.volume_index;return r.getItem(ce).then(X=>({id:ce,title:X&&X.title||ce,volume_index:W})).catch(()=>({id:ce,title:ce,volume_index:W}))})).then(Z=>{L||$(Z)}):$([])}else $([]);return()=>{L=!0}},[k,r]),f)return e.jsx("div",{className:p,style:{...c,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((L,te)=>e.jsx("div",{style:{height:te===1?"32px":"16px",width:`${L}px`,background:i("widget-border"),borderRadius:"4px",opacity:.4}},te))})});if(w)return e.jsx("div",{className:p,style:{...c,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:w});if(!k)return null;if(k.type==="entity")return e.jsx("div",{className:p,style:c,children:e.jsx(Ss,{data:k,transport:r,onNavigate:o,renderLink:s,headerExtra:l})});const _=k.type==="book"?k:null,S=k.type==="collection"?k:null,z=k.type==="work"?k:null;let A=!1;try{A=ye.extractStatus(k.id)==="draft"}catch{}let E="";k.measure_info?E=u(k.measure_info):(H=k.juan_count)!=null&&H.number?E=_s(k.juan_count.number)+d.unit.juan:(B=k.juan_count)!=null&&B.description&&(E=u(k.juan_count.description));const T=[];return(O=k.publication_info)!=null&&O.year&&T.push(e.jsx(pt,{label:d.label.year,children:k.publication_info.year},"year")),(D=k.current_location)!=null&&D.name&&T.push(e.jsx(pt,{label:d.label.currentLocation,children:u(k.current_location.name)},"loc")),(ne=k.page_count)!=null&&ne.description&&T.push(e.jsx(pt,{label:d.label.pageCount,children:k.page_count.description},"page")),_!=null&&_.edition&&T.push(e.jsx(pt,{label:d.label.edition,children:u(_.edition)},"ver")),z!=null&&z.parent_work&&T.push(e.jsx(pt,{label:d.label.parentWork,children:e.jsx(ot,{id:z.parent_work.id,label:u(z.parent_work.title),onNavigate:o,renderLink:s})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&T.push(e.jsx(pt,{label:d.label.parentWork,children:z.parent_works.map((L,te)=>e.jsxs("span",{children:[te>0&&"、",e.jsx(ot,{id:L,onNavigate:o,renderLink:s})]},L))},"pws")),e.jsxs("div",{className:p,style:c,children:[e.jsx(dd,{id:k.id,title:u(k.title),edition:k.edition?u(k.edition):void 0,type:k.type,isDraft:A,authors:k.authors,volumeText:E,meta:T,headerExtra:l,onNavigate:o,renderLink:s}),((V=k.description)==null?void 0:V.text)&&e.jsx(bt,{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&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:k.appendix.map((L,te)=>e.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:i("bg-subtle"),borderRadius:4,border:`1px solid ${i("widget-border")}`},children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:i("muted")},children:u(L.title)}),e.jsx(bt,{text:L.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:i("fg")}})]},te))}),v.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(tt,{children:d.section.containedIn}),e.jsx(jd,{items:v,onNavigate:o,renderLink:s})]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(tt,{children:d.section.belongsToWork}),e.jsx(yd,{workData:j,onNavigate:o,renderLink:s})]}),k.additional_works&&k.additional_works.length>0&&e.jsx(xd,{items:k.additional_works}),k.additional_titles&&k.additional_titles.length>0&&e.jsx(ud,{items:k.additional_titles}),k.attached_texts&&k.attached_texts.length>0&&e.jsx(md,{items:k.attached_texts}),k.indexed_by&&k.indexed_by.length>0&&e.jsx(pd,{items:k.indexed_by,onNavigate:o,renderLink:s}),k.emendated_by&&k.emendated_by.length>0&&e.jsx(Is,{items:k.emendated_by,onNavigate:o,renderLink:s}),k.resources&&k.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(tt,{children:d.section.resources}),e.jsx(Pi,{items:k.resources,resourceGroups:k.resource_groups,groupByType:!0,onNavigate:o,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&e.jsx(hd,{items:_.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(fd,{items:S.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&e.jsx(to,{title:d.section.relatedVersions,ids:_.related_books,transport:r,onNavigate:o,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(to,{title:d.section.containedBooks,ids:S.books,transport:r,onNavigate:o,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(tt,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",S.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(L=>e.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:e.jsx(ot,{id:L.id,label:u(L.title),onNavigate:o,renderLink:s})},L.id))})]}),(((C=z==null?void 0:z.books)==null?void 0:C.length)||0)+(((xe=z==null?void 0:z.collections)==null?void 0:xe.length)||0)>0&&e.jsx(gd,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z??void 0,transport:r,onNavigate:o,renderLink:s,footer:a}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const L=[],te=z.related_works.filter(ae=>ae.relation==="part_of"),N=z.related_works.filter(ae=>ae.relation==="has_part"),Z=z.related_works.filter(ae=>ae.relation==="has_adaptation"),ce=z.related_works.filter(ae=>ae.relation==="text_carried_by"),W=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),X=z.related_works.filter(ae=>!ae.relation||!W.has(ae.relation));return te.length>0&&L.push({label:d.section.belongsToWork,items:te}),N.length>0&&L.push({label:d.section.containedWorks,items:N}),Z.length>0&&L.push({label:d.section.adaptations,items:Z}),ce.length>0&&L.push({label:d.section.derivativeWorks,items:ce}),X.length>0&&L.push({label:d.section.relatedWorks,items:X}),L.map(ae=>e.jsxs("div",{children:[e.jsxs(tt,{children:[ae.label,e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",ae.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:ae.items.map(de=>e.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:e.jsx(ot,{id:de.id,label:u(de.title),onNavigate:o,renderLink:s})},de.id))})]},ae.label))})()]})};function vd({data:t}){const n=ge(),{convert:r}=G(),{stats:o}=t,s=o.processed_volumes??o.total_found_volumes,l=s!=null&&t.total_volumes>0?Math.round(s/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:r(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"6px"},children:r(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:i("desc-fg")},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:i("fg")},children:t.total_volumes})," ",n.unit.volume]}),l!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:i("fg")},children:s})," ",n.unit.volume," (",l,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:i("fg")},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:i("fg")},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:i("missing-fg")},children:o.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:i("desc-fg")},children:[n.catalog.source," ",t.source]})]})}function kd({sections:t,activeSection:n,onSelect:r}){const o=ge();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>r(null),style:no(n===null),children:o.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>r(s.name),style:no(n===s.name),children:[s.name,s.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function no(t){return{padding:"4px 12px",border:t?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:t?`color-mix(in srgb, ${i("primary")} 8%, transparent)`:"transparent",color:i(t?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function wd({id:t,label:n,onNavigate:r,renderLink:o}){const s=Pe();return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:s(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),r(t))},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||t}):e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:n||t})}function Sd(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const r=t[0],o=t[t.length-1];return o-r+1===t.length?`${r}–${o}`:t.length<=3?t.join(", "):`${r}–${o} (${t.length}${n})`}function io({book:t,onNavigate:n,renderLink:r,showVolumes:o}){const s=ge(),{convert:l}=G(),a=t.book_id||t.work_id,p=o&&t.volumes.length>0?Sd(t.volumes,s.unit.volume):null,c=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${i("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[o&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:i("desc-fg"),textAlign:"right"},children:p}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:i("fg")},children:[l(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(d=>l(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),fontWeight:400,marginLeft:"8px"},children:l(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:i(c?"missing-fg":"desc-fg"),flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),a&&e.jsx(wd,{id:a,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:r}),!a&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const Vi=({data:t,collectionId:n,transport:r,onNavigate:o,renderLink:s,className:l,style:a})=>{const p=ge(),[c,d]=m.useState(null),[u,h]=m.useState(!1),[x,f]=m.useState(null),[b,w]=m.useState(null),[y,j]=m.useState(""),g=t||c;m.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollectionCatalog))return;let S=!1;return h(!0),f(null),r.getCollectionCatalog(n).then(z=>{S||(z?d(z):f(p.catalog.notFound))}).catch(z=>{S||f(z instanceof Error?z.message:p.catalog.loadFailed)}).finally(()=>{S||h(!1)}),()=>{S=!0}},[t,n,r,p]);const v=(g==null?void 0:g.sections)&&g.sections.length>0,$=m.useMemo(()=>{if(!g)return!1;if(g.volume_index&&Object.keys(g.volume_index).length>0)return!0;const S=g.books.map(A=>A.volumes[0]).filter(A=>A!=null);return new Set(S).size<S.length},[g]),k=m.useMemo(()=>{if(!g)return[];let S=g.books;if(b&&(S=S.filter(z=>z.section===b)),y.trim()){const z=y.trim().toLowerCase();S=S.filter(A=>A.title.toLowerCase().includes(z)||A.sub_items&&A.sub_items.some(E=>E.toLowerCase().includes(z))||A.edition&&A.edition.toLowerCase().includes(z))}return S},[g,b,y]),_=m.useMemo(()=>{if(!$)return null;const S=[],z=new Map;for(const E of k){if(!E.volumes||E.volumes.length===0)continue;const T=E.volumes[0];z.has(T)||z.set(T,[]),z.get(T).push(E)}const A=[...z.keys()].sort((E,T)=>E-T);for(const E of A)S.push({volume:E,books:z.get(E)});return S},[k,$]);return u?e.jsx("div",{className:l,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:p.catalog.loading})}):x?e.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:x}):g?e.jsxs("div",{className:l,style:a,children:[e.jsx(vd,{data:g}),v&&e.jsx(kd,{sections:g.sections,activeSection:b,onSelect:w}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.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"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:i("desc-fg")},children:[k.length," ",p.unit.bu]})]}),e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[_?_.map((S,z)=>e.jsxs("div",{children:[e.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:rt(p.catalog.volume,{n:S.volume})}),S.books.map((A,E)=>e.jsx(io,{book:A,onNavigate:o,renderLink:s,showVolumes:A.volumes.length>1},`${S.volume}-${E}`))]},`${S.volume}-${z}`)):k.map((S,z)=>e.jsx(io,{book:S,onNavigate:o,renderLink:s,showVolumes:!0},z)),k.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:p.catalog.noMatch})]})]}):null},St=()=>{const[t,n]=m.useState(1);return m.useEffect(()=>{const r=setInterval(()=>n(o=>o>=3?1:o+1),500);return()=>clearInterval(r)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:i("desc-fg"),fontSize:"14px"},children:"加载中"+".".repeat(t)})},Ns=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],$d={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Ge(t){return $d[t]??t}const Dt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],Ht={熹平: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},Rs={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Fn(t){const n=t.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const r=parseInt(n[1],10);if(r<100||r>2100)return;const o=n[2]?parseInt(n[2],10):void 0;return{from:r,to:o!=null&&o>=r&&o<=2100?o:void 0}}function _d(t){return t>=1950?"":t>=1912?"民國":t>=1645?"清":t>=1368?"明":t>=1279?"元":t>=960?"宋":t>=907?"五代":t>=618?"唐":t>=581?"隋":t>=420?"南北朝":t>=265?"晉":t>=220?"三國":t>=-202?"漢":""}const zd=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,ro={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Ui(t){const n=t.trim().replace(/[代朝]$/,"");for(const s of Object.keys(ro))if(n.startsWith(s))return ro[s];const r=Ge(n);if(Tt[r]!=null)return r;const o=gt(n);if(o&&n.length<=o.length+1)return Ge(o)}function Ct(t,n){if(n){const r=Rs[`${n}|${t}`];if(r!=null)return r}return Ht[t]}const Cd=1911;function Td(t){const n=Ht[t];if(n==null)return;const r=ut[t];let o;for(const[s,l]of Object.entries(Ht))ut[s]===r&&l>n&&(o==null||l<o)&&(o=l);return o!=null?o-1:void 0}const Id={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Tn(t){if(!t)return;if(/^\d+$/.test(t))return parseInt(t,10);let n=0,r=0,o=!1;for(const l of t){const a=Id[l];if(a===void 0)return;o=!0,l==="十"?r=(r||1)*10:l==="廿"||l==="卅"?(n+=a,r=0):r>=10?(n+=r+a,r=0):r=r*10+a}const s=n+r;return o&&s>0?s:void 0}function gt(t){for(const n of Ns)if(t.startsWith(n))return n}const ut={};{const t=(n,r)=>{for(const o of r)ut[o]=n};t("東漢",["熹平","建安"]),t("三國",["黃初","正始"]),t("五代",["廣政"]),t("西晉",["太康"]),t("東晉",["永和"]),t("隋",["開皇"]),t("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),t("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),t("金",["大定","明昌"]),t("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),t("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),t("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),t("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function It(t,n){const r=n==="北宋"||n==="南宋"?"宋":n;for(const o of Object.keys(Ht))if(t.includes(o)&&!(r&&ut[o]&&ut[o]!==r&&Rs[`${r}|${o}`]==null))return o}function xn(t){var a,p,c;const n={era:"",reign:"",source:"none"},r=t.dating;if(r!=null&&r.era||r!=null&&r.reign)return{era:r.era??"",reign:r.reign??"",source:r.certainty==="attested"?"catalog":"edition"};const o=(a=t.lineage)==null?void 0:a.year_text;if(o){const d=gt(o)??"";return{era:Ge(d),reign:It(o,d)??"",source:"lineage"}}const s=(p=t.publication_info)==null?void 0:p.year;if(s){const d=Fn(s);if(d)return{era:_d(d.from),reign:"",source:"publication"};const u=gt(s)??Ui(s)??((c=Dt.find(f=>f.pattern.test(s)))==null?void 0:c.era)??"",h=It(s,u)??"",x=u||(h?ut[h]??"":"");if(x||h)return{era:Ge(x),reign:h,source:"publication"}}const l=t.edition||t.title||"";if(l){const d=gt(l);if(d)return{era:Ge(d),reign:It(l,d)??"",source:"edition"};const u=Dt.find(h=>h.pattern.test(l));if(u)return{era:Ge(u.era),reign:It(l,u.era)??u.reign??"",source:"edition"}}return n}function On(t){var o,s,l,a,p,c,d,u,h;if(((o=t.dating)==null?void 0:o.year)!=null)return t.dating.year;if(typeof((s=t.lineage)==null?void 0:s.year)=="number")return t.lineage.year;const n=(l=t.publication_info)==null?void 0:l.year;if(n){const x=Fn(n);if(x)return x.from}const r=[(a=t.lineage)==null?void 0:a.year_text,(p=t.publication_info)==null?void 0:p.year,t.edition,t.edition?void 0:t.title].filter(Boolean);for(const x of r){const f=((c=t.publication_info)==null?void 0:c.year)||((d=t.lineage)==null?void 0:d.year_text);if(f&&x!==f&&(gt(f)||Ui(f)))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=gt(x);if(!v||Ge(v)==="民國"){const k=Tn(w[1]);if(k!=null&&k>=1&&k<=120)return Cd+k}}const y=gt(x)??((u=Dt.find(v=>v.pattern.test(x)))==null?void 0:u.era),j=y?Ge(y):void 0,g=It(x,j)??(gt(x)||(h=Dt.find(v=>v.pattern.test(x)))==null?void 0:h.reign);if(g){const v=Ct(g,j);if(v==null)continue;const $=x.indexOf(g),k=$>=0?x.slice($+g.length):"",_=k.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??k.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=_?Tn(_[1]):void 0;return v+(S?S-1:0)}}}function Yi(t){var a,p,c,d,u,h;const n=(a=t.dating)==null?void 0:a.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const r=(p=t.lineage)==null?void 0:p.year_range;if(r&&r.length===2)return{from:r[0],to:r[1]};const o=(c=t.lineage)==null?void 0:c.year_text;if(o){const x=o.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(x){const f=gi[Ge(x[1])],b=Tt[Ge(x[2])];if(f!=null&&b!=null)return{from:Math.min(f,b)-20,to:Math.max(f,b)+40}}}const s=(d=t.publication_info)==null?void 0:d.year;if(s){const x=Fn(s);if((x==null?void 0:x.to)!=null)return{from:x.from,to:x.to};const f=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(f){const b=gi[Ge(f[1])],w=Tt[Ge(f[2])];if(b!=null&&w!=null)return{from:Math.min(b,w)-20,to:Math.max(b,w)+40}}}const l=[(u=t.publication_info)==null?void 0:u.year,t.edition,t.title].filter(Boolean);for(const x of l){if(!/[間间]/.test(x))continue;const f=gt(x)??Ui(x)??((h=Dt.find(y=>y.pattern.test(x)))==null?void 0:h.era),b=f?Ge(f):void 0,w=[];for(const y of Object.keys(Ht))x.includes(y)&&(b&&ut[y]&&ut[y]!==b||Ct(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 g of Object.keys(Ht))if(ut[g]===b&&!(g[0]!==j&&g[g.length-1]!==j)&&Ct(g,b)!=null){w.push(g);break}}}if(w.length>0){const y=w.map($=>Ct($,b)).filter($=>$!=null),j=Math.min(...y),g=w.reduce(($,k)=>Ct($,b)>=Ct(k,b)?$:k),v=Td(g)??ri(b??"")??Math.max(...y);return{from:j,to:v>j?v:ri(b??ut[g]??"")??j}}if(b&&Tt[b]!=null)return{from:Tt[b],to:ri(b)??Tt[b]}}}const Tt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Ed=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Nd=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,oo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function so(t,n){for(const r of Ns){const o=t.indexOf(r);if(o<0)continue;if(r.length===1){const c=t[o+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!It(t.slice(o),Ge(r)))continue}const s=Ge(r);if(s===n)continue;const l=t.slice(o),a=It(l,s)??"";let p;if(a){const c=Ct(a,s);if(c!=null){const u=l.slice(l.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),h=u?Tn(u[1]):void 0;p=c+(h?h-1:0)}}return{era:s,reign:a,year:p}}for(const r of Dt)if(r.pattern.test(t))return{era:Ge(r.era),reign:r.reign??""}}function Rd(t){var j,g,v,$,k;const n=xn(t),r=((j=t.publication_info)==null?void 0:j.year)??"",o=r?Fn(r):void 0;if(!n.era&&!n.reign&&!o)return;const s=t.edition||t.title||"",l=/[間间]/.test(s),a=((g=t.lineage)==null?void 0:g.year_text)??"",p=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(a),c=n.source==="publication"&&zd.test(r),d=n.source==="publication"&&/[間间]/.test(r),u=a.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let h;l||p||c||d?h=void 0:u?h=parseInt(u[2],10):h=On(t);const x=h==null?Yi(t):void 0;let f;n.source==="publication"&&(c||oo.test(r))?f="uncertain":n.source==="lineage"||n.source==="publication"?f="attested":oo.test(s)||!n.reign&&h==null?f="uncertain":f="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((v=t.lineage)==null?void 0:v.year_text)??(($=t.lineage)==null?void 0:$.year)??""}」`:`出版著錄「${((k=t.publication_info)==null?void 0:k.year)??""}」`,w={era:n.era,reign:n.reign,year:h,yearRange:x,certainty:f,source:n.source==="edition"?"edition":"catalog",basis:b};if(u){const _=a.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=Ed.find(_=>_.re.test(s));if(y){const _=s.search(y.re),S=s.slice(_),z=so(S,n.era)??so(s,n.era);z&&(w.basedOn={era:z.era,reign:z.reign,year:z.year,relation:y.relation})}return w}const gi={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function ri(t){return gi[t]}function In(t){const n=On(t);if(n!=null)return n;const r=Yi(t);if(r)return r.from;const o=xn(t).era;return o?Tt[o]:void 0}const lo=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function bi(t){const n=lo.indexOf(t);return n===-1?lo.length:n}function Ld(t){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of t){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 r=[],o=(s,l)=>{n[s].length&&r.push({key:s,labelKey:l,items:n[s]})};return o("belongsTo","belongsToWork"),o("collected","collectedIn"),o("contains","containedWorks"),o("derivative","derivativeWorks"),o("studies","studies"),o("related","relatedWorks"),r}function Ki(t,n){const r=Wi(t||[]),o=new Map,s=[];for(const d of r)d.group?(o.has(d.group)||o.set(d.group,[]),o.get(d.group).push(d)):s.push(d);for(const d of o.values())d.sort((u,h)=>{const x=f=>f.group_role==="origin"?0:f.group_role==="mirror"?1:2;return x(u)-x(h)});const l={text:[],image:[],textImage:[],physical:[]};for(const d of s){const u=Rt(d),h=u.includes("text"),x=u.includes("image");h&&x?l.textImage.push(d):h?l.text.push(d):x?l.image.push(d):l.physical.push(d)}const p=["text","image","textImage","physical"].filter(d=>l[d].length>0).map(d=>({key:d,items:l[d]})),c=[...o.entries()].map(([d,u])=>{var h,x;return{key:d,label:((h=n==null?void 0:n[d])==null?void 0:h.label)||d,description:(x=n==null?void 0:n[d])==null?void 0:x.description,items:u}});return{buckets:p,mirrors:c,total:r.length}}function Pn(t){const n=[],r=t.metadata||{};r.edition&&n.push(String(r.edition)),t.source_label&&n.push(t.source_label),t.details&&n.push(t.details);const o=Rn(t);return o&&o.expected>0&&n.push(o.missing>0?`${o.found} / ${o.expected} 冊 缺 ${o.missing}`:`${o.found} / ${o.expected} 冊`),r.version&&n.push(String(r.version)),n.join(" · ")}function Ls(t,n){if(Pn(t)||n.filter(o=>o.name===t.name).length<2)return"";try{const o=new URL(t.url),s=o.searchParams.get("res")||o.searchParams.get("id");if(s)return s;const l=o.pathname.split("/").filter(Boolean).pop();if(l)return decodeURIComponent(l)}catch{}return""}function As(t,n){var l,a;const r=t.resources||[],o=[],s=[];for(const p of r){const c=Rt(p);c.includes("image")&&o.push(p),c.includes("physical")&&s.push(p)}return{id:t.id,name:t.edition||t.title||t.id,era:xn(t),year:On(t),sortYear:In(t),images:o,holders:s,locationName:(l=t.current_location)==null?void 0:l.name,important:Ad(t.id,n),group:(a=n==null?void 0:n.node_groups)==null?void 0:a[t.id],hasImage:o.length>0}}function Ad(t,n){var p,c;if(!n)return!1;const r=n.default_collection;if(!r)return!1;const o=(p=n.collections)==null?void 0:p[r];if(((o==null?void 0:o.book_ids)??(r==="core"?n.core_books??[]:[])).includes(t))return!0;const l=(o==null?void 0:o.groups)??[],a=(c=n.node_groups)==null?void 0:c[t];return!!a&&l.includes(a)}function Bs(t,n,r={}){const o=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(c=>!o.has(c.id)).map(c=>As(c,n));let l=s;r.era&&(l=l.filter(c=>c.era.era===r.era)),r.scanOnly&&(l=l.filter(c=>c.hasImage)),r.sort==="year"?l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=c.r.sortYear,h=d.r.sortYear;return u!=null&&h!=null?u-h||c.i-d.i:u!=null?-1:h!=null?1:c.i-d.i}).map(c=>c.r):l=l.map((c,d)=>({r:c,i:d})).sort((c,d)=>{const u=h=>(h.important?0:1)*2+(h.hasImage?0:1);return u(c.r)-u(d.r)||c.i-d.i}).map(c=>c.r);const p=[...new Set(s.map(c=>c.era.era).filter(Boolean))].sort((c,d)=>bi(c)-bi(d));return{rows:l,allRows:s,eras:p,hasInferredEra:s.some(c=>c.era.source==="edition")}}function Bd(t,n){var y,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const r=(y=n.collections)==null?void 0:y[n.default_collection],o=(r==null?void 0:r.groups)??[],s=(r==null?void 0:r.book_ids)??[],l=o.length>0||s.length>0,a=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const p=new Set(o),c=new Set([...s,...a]),d=g=>{if(c.has(g))return!0;const v=n.node_groups[g];return v!=null&&p.has(v)},u=[],h=new Map,x=[];for(const g of t)if(!((j=n.excluded_books)!=null&&j.includes(g)))if(d(g))u.push(g);else{const v=n.node_groups[g];v?(h.has(v)||h.set(v,[]),h.get(v).push(g)):x.push(g)}if(x.length+[...h.values()].reduce((g,v)=>g+v.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(g=>[g.id,g])),w=[...h.entries()].map(([g,v])=>{const $=b.get(g);return{id:g,label:($==null?void 0:$.label)??g,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 Ms=["撰","編","注","校","譯","繪","其他"],Md=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function qi(t){if(!t||!t.trim())return"撰";const n=t.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:r,re:o}of Md)if(o.test(n))return r;return"其他"}function Ji(t){if(!t)return"";const n=t.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Ws(t){const n=new Map;for(const o of t){const s=qi(o);n.set(s,(n.get(s)??0)+1)}const r=[{cls:"全部",label:"全部",count:t.length}];for(const o of Ms){const s=n.get(o);s&&r.push({cls:o,label:o,count:s})}return r.length>2?r:[]}function Fs(t,n,r){if(n&&n.books&&n.books.length>0){const s=n.books.map(a=>({id:a.work_id||a.book_id||void 0,title:a.title,section:a.section,volumes:a.volumes||[],subItems:a.sub_items,edition:a.edition,found:a.found_volumes,expected:a.expected_volumes})),l=[...new Set(s.map(a=>a.section).filter(Boolean))];return{rows:s,source:"catalog",sections:l,totalVolumes:n.total_volumes}}return t.contained_works&&t.contained_works.length>0?{rows:t.contained_works.map(l=>({id:l.id,title:l.title,volumes:cn(l.volume_index)})),source:"works",sections:[]}:{rows:(t.books||[]).map(s=>{var l,a;return{id:s,title:((l=r==null?void 0:r.get(s))==null?void 0:l.title)||s,edition:(a=r==null?void 0:r.get(s))==null?void 0:a.edition,volumes:[]}}),source:"books",sections:[]}}function cn(t){if(t==null)return[];if(typeof t=="number")return[t];if(Array.isArray(t))return t.filter(n=>typeof n=="number");if(typeof t=="string"){const n=t.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[r,o]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,o-r+1)},(s,l)=>r+l)}return t.split(/[,、]/).map(r=>parseInt(r.trim())).filter(r=>!isNaN(r))}return[]}function Dn(t,n="冊"){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const r=[...t].sort((l,a)=>l-a),o=r[0],s=r[r.length-1];return s-o+1===r.length?`${o}–${s}`:r.length<=3?r.join(", "):`${o}–${s} (${r.length}${n})`}const Wd=["〇","一","二","三","四","五","六","七","八","九"],ao=["","十","百","千"];function Os(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),r=n.length;let o="",s=!1;for(let l=0;l<r;l++){const a=parseInt(n[l]),p=r-1-l;a===0?s=!0:(s&&o&&(o+="〇"),s=!1,a===1&&p===1&&l===0?o+=ao[p]:o+=Wd[a]+ao[p])}return o}function Fd(t){return t==null?"":typeof t=="string"?t:t.title??""}function yt(t,n="卷"){var o,s;const r=t;return r.measure_info?r.measure_info:(o=r.juan_count)!=null&&o.number?Os(r.juan_count.number)+n:(s=r.juan_count)!=null&&s.description?r.juan_count.description:""}function Ps(t){var o;if(t.edition_type)return t.edition_type;if((o=t.lineage)!=null&&o.category)return t.lineage.category;const n=t.edition||t.title||"",r=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,l]of r)if(s.test(n))return l;return""}const Od="guji_markdown";function un(t){const n=t==null?void 0:t.guji_markdown;if(typeof n!="string")return!1;const r=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!r)return!1;const o=parseInt(r[1],10),s=parseInt(r[2],10);return o>0||s>=2}const Pd=/^□\{guess=([^\s{}]+)\}/;function Dd(t,n){const r=t[n+1];return r!==void 0&&!/[A-Za-z/!?>\s]/.test(r)}function Ds(t,n){let r=0;for(let o=n;o<t.length;o++){const s=t[o];if(s===`
|
|
131
|
+
`)return-1;if(s==="\\"){o++;continue}if(s==="[")r++;else if(s==="]"&&(r--,r===0))return o}return-1}function Hd(t){return t.replace(/\\([\\[\]<>|{}])/g,"$1")}function Gd(t,n){const r=t[n];if(r==="["&&t[n+1]==="["){const o=t.indexOf("]]",n+2);return o>=0&&t.slice(n+2,o).indexOf(`
|
|
132
|
+
`)<0?{node:{type:"qw",label:t.slice(n+2,o)},end:o+2}:null}if(r===":"&&t.startsWith(":zi[",n)){const o=Ds(t,n+3);return o>n+4?{node:{type:"zi",label:Hd(t.slice(n+4,o))},end:o+1}:null}if(r==="□"&&t[n+1]==="{"){const o=Pd.exec(t.slice(n,n+64));if(o)return{node:{type:"qz",guess:o[1]},end:n+o[0].length}}return null}function Hs(t,n,r,o){const s=[];let l="";const a=()=>{if(!l)return;const p=o?l.replace(/\\?\|/g,""):l;p&&s.push({type:"text",text:p}),l=""};for(;n<t.length;){const p=t[n];if(r!==null){if(p===r)return a(),{nodes:s,end:n};if(p===`
|
|
133
|
+
`)return null}const c=Gd(t,n);if(c){a(),s.push(c.node),n=c.end;continue}let d=null;if(p==="⟨"?d="⟩":p==="<"&&Dd(t,n)&&(d=">"),d){const u=Hs(t,n+1,d,!0);if(u){a(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return r!==null?null:(a(),{nodes:s,end:n})}function Gs(t){return Hs(t,0,null,!1).nodes}function Vd(t){return/[<⟨□]|\[\[|:zi\[/.test(t)}function Vs(t){return t.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Vs(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const Ud=216,co="clamp(280px, 23vw, 360px)",Yd=1440,yi="(max-width: 719px)",Kd=`${yi}, (pointer: coarse)`,qd=`
|
|
134
|
+
.bim-d-main.bim-d-main-grid { max-width: ${Yd}px; padding: 16px 32px 0; }
|
|
135
135
|
.bim-d-grid {
|
|
136
136
|
display: grid;
|
|
137
|
-
grid-template-columns: ${
|
|
137
|
+
grid-template-columns: ${Ud}px minmax(0, 1fr) ${co};
|
|
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 ${Kd} {
|
|
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) ${co};
|
|
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 ${yi} {
|
|
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 ${yi} {
|
|
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 hn({railTop:t,back:n,up:r,nav:o,railLinks:s,main:l,card:a,side:p}){const{convert:c}=G(),d=(o||[]).filter(Boolean);return e.jsxs("div",{className:"bim-d-grid",children:[e.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[t,n&&e.jsx("div",{style:{marginTop:t?12:0},children:n}),r,d.length>1&&e.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":c("本頁導航"),style:{marginTop:20},children:[e.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:c("本頁")}),e.jsx("ul",{className:"bim-d-rail-nav",children:d.map(u=>e.jsx("li",{children:e.jsxs("a",{href:`#${u.id}`,children:[e.jsx("span",{children:c(u.label)}),u.count!=null&&e.jsx("span",{className:"bim-d-meta",children:u.count})]})},u.id))})]}),s&&s.length>0&&e.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("更多"),children:[e.jsx("p",{className:"bim-d-rail-cap",children:c("更多")}),e.jsx("ul",{className:"bim-d-rail-nav",children:s.map(u=>e.jsx("li",{children:e.jsxs("a",{href:u.href??"#",onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),u.onClick())},children:[e.jsx("span",{children:c(u.label)}),e.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},u.key))})]})]}),e.jsx("div",{className:"bim-d-g-main",children:l}),e.jsx("div",{className:"bim-d-g-card",children:a}),e.jsx("div",{className:"bim-d-g-side",children:p})]})}function Us({caption:t,children:n}){const{convert:r}=G();return e.jsxs("div",{className:"bim-d-up bim-d-ui",children:[e.jsx("span",{className:"bim-d-up-cap",children:r(t)}),n]})}function Ue({id:t,title:n,meta:r,action:o,children:s}){const{convert:l}=G();return e.jsxs("section",{id:t,className:"bim-d-sec",children:[e.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[e.jsx("h2",{children:l(n)}),r!=null&&r!==""&&e.jsx("span",{className:"bim-d-meta",children:r}),o&&e.jsx("span",{className:"bim-d-sec-act",children:o})]}),e.jsx("div",{className:"bim-d-sec-body",children:s})]})}function Ve({items:t,className:n,style:r}){const o=t.filter(s=>s!=null&&s!==""&&s!==!1);return o.length?e.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:r,children:o.map((s,l)=>e.jsxs(m.Fragment,{children:[l>0&&e.jsx("span",{className:"bim-d-dot"}),e.jsx("span",{children:s})]},l))}):null}function Hn({items:t,value:n,onChange:r}){const{convert:o}=G();return e.jsx(e.Fragment,{children:t.map(s=>e.jsx("button",{type:"button",className:[...o(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>r(s.key),children:o(s.label)},s.key))})}function Ys({label:t,checked:n,onChange:r}){const{convert:o}=G();return e.jsxs("label",{className:"bim-d-check",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:s=>r(s.target.checked)}),o(t)]})}function qt({label:t,onClick:n}){const{convert:r}=G();return e.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:r(t)})}function fn({kind:t,title:n,subtitle:r,byline:o,meta:s,description:l,clampDescription:a,facts:p,stats:c,readAction:d,secondaryAction:u,children:h,foot:x}){const{convert:f}=G(),b=(p||[]).filter(v=>v.value!=null&&v.value!==""),w=(c||[]).filter(v=>v.value!=null&&v.value!==""&&v.value!==0),[y,j]=m.useState(!1),g=!!a&&!y;return e.jsxs("div",{className:"bim-d-card",children:[t&&e.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:f(t)}),e.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),r&&e.jsx("div",{className:"bim-d-card-sub",children:r}),o&&e.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:o}),s&&e.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),l&&e.jsx("div",{className:g?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:g?{"--detail-clamp":a}:void 0,children:l}),l&&!!a&&e.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":y,onClick:()=>j(v=>!v),children:f(y?"收起":"展開")}),w.length>0&&e.jsx("div",{className:"bim-d-stats bim-d-ui",children:w.map((v,$)=>e.jsxs("div",{children:[e.jsx("b",{children:v.value}),e.jsx("span",{children:f(v.label)})]},$))}),b.length>0&&e.jsx("dl",{className:"bim-d-ui",children:b.map((v,$)=>e.jsxs(m.Fragment,{children:[e.jsx("dt",{children:f(v.label)}),e.jsx("dd",{title:v.title,children:v.value})]},$))}),h,d,u,x&&e.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:x})]})}function Zi(t){return!!t&&[...t.replace(/\s+/g,"")].length>110}function ji({href:t,onClick:n,label:r="閱讀全文"}){const{convert:o}=G();return t?e.jsx("a",{className:"bim-d-btn",href:t,onClick:n?s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),n())}:void 0,children:o(r)}):e.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:o(r)})}function Et({id:t,title:n,meta:r,items:o,metas:s,currentIndex:l,cap:a=8,moreLabel:p,foot:c,sub:d,timeline:u}){const{convert:h}=G(),[x,f]=m.useState(!1);if(!o.length)return null;const b=x?o:o.slice(0,a),w=o.length-b.length;return e.jsxs("div",{id:t,className:u?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[e.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[h(n),r!=null&&r!==""&&e.jsx("span",{className:"bim-d-meta",children:r})]}),d&&e.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:d}),e.jsx("ul",{children:b.map((y,j)=>e.jsxs("li",{className:j===l?"bim-d-side-cur":void 0,"aria-current":j===l?"page":void 0,children:[y,s!=null&&s[j]?e.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[j]}):null]},j))}),w>0&&e.jsx(qt,{label:p?p(w):`顯示更多(${w})`,onClick:()=>f(!0)}),c&&e.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const Jd={reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"};function gn({revision:t,revisedAt:n,review:r,todo:o}){const{convert:s}=G(),l=r?Jd[r.status]:void 0,a=r&&r.status!=="unreviewed"&&l?[l,r.by,r.date].filter(Boolean).join(" "):"",p=[t!=null&&t!==""?`${s("數據版本")} ${t}`:"",n??"",s(a)].filter(Boolean),c=(o||[]).filter(d=>d&&d.what);return!p.length&&!c.length?null:e.jsxs(e.Fragment,{children:[p.length>0&&e.jsx(Ve,{items:p,style:{fontSize:12}}),c.length>0&&e.jsxs("details",{children:[e.jsx("summary",{children:s(`待核 ${c.length} 項`)}),e.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:c.map((d,u)=>e.jsxs("li",{children:[s(d.what),(d.by||d.date)&&e.jsxs("span",{style:{marginLeft:6},children:["(",[d.by&&s(d.by),d.date].filter(Boolean).join(" · "),")"]})]},u))})]})]})}const $n=1e3,po=208,Zd=1440,Xd="(max-width: 719px)",Ks=`
|
|
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: ${$n}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: ${Zd}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: ${po}px minmax(0, ${$n}px);
|
|
644
644
|
gap: 32px;
|
|
645
|
-
max-width: ${
|
|
645
|
+
max-width: ${po+$n+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 ${Xd} {
|
|
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:
|
|
686
|
+
${qd}`;function ln({children:t,style:n,wide:r,grid:o}){return e.jsxs("div",{className:"bim-d-page",style:n,children:[e.jsx("style",{children:Ks}),e.jsx("div",{className:o?"bim-d-main bim-d-main-grid":r?"bim-d-main bim-d-main-wide":"bim-d-main",children:t})]})}function vi({breadcrumb:t,actions:n}){return e.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:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:t}),n&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function Xi({char:t,tone:n="accent"}){return e.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:t})}function ki({items:t}){const n=Pe();return e.jsx(e.Fragment,{children:t.map((r,o)=>{const s=o===t.length-1,l=o>0&&e.jsx("span",{style:{color:i("hint-fg")},children:"/"},`s${o}`),a=r.id?n(r.id):r.href,p=s||!r.onClick&&!a?e.jsx("span",{style:{color:i("ink")},children:r.label},o):e.jsx("a",{href:a??"#",onClick:r.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),r.onClick())}:void 0,style:{color:i("meta-fg")},children:r.label},o);return e.jsxs(m.Fragment,{children:[l,p]},o)})})}function qs({title:t,subtitle:n,aside:r,secondLine:o}){return e.jsxs("header",{style:{borderBottom:`2px solid ${i("rule-strong")}`,paddingBottom:18},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[e.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:t}),n&&e.jsx("span",{style:{fontSize:15,color:i("meta-fg"),letterSpacing:".06em"},children:n})]}),r&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".06em"},children:r})]}),o&&e.jsx("div",{style:{marginTop:12,fontSize:13.5,color:i("quiet-fg")},children:o})]})}function Qd({children:t,facts:n}){return!t&&n?e.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${i("rule")}`,marginBottom:40},children:n}):e.jsxs("div",{className:"bim-d-intro",children:[e.jsx("div",{style:{minWidth:0},children:t}),n]})}function ep({items:t,horizontal:n}){const{convert:r}=G();return t.length?e.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:t.map((o,s)=>e.jsxs("div",{title:o.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[e.jsx("span",{className:"bim-d-ui",style:{color:i("label-fg"),letterSpacing:".08em",flex:"none"},children:r(o.label)}),e.jsx("span",{style:{color:i("body-fg"),textAlign:n?"left":"right",minWidth:0},children:o.value})]},s))}):null}function tp({glyph:t,tone:n,title:r,count:o,actions:s,id:l}){const{convert:a}=G();return e.jsxs("div",{id:l,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(Xi,{char:t,tone:n}),e.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:a(r)}),o!=null&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg")},children:o})]}),s&&e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function Js({label:t,active:n,onClick:r,dashed:o}){const{convert:s}=G();return e.jsx("button",{type:"button",onClick:r,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${o&&!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(t)})}function np({label:t,onClick:n}){const{convert:r}=G();return e.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:r(t)})}function ip({label:t,onClick:n,inline:r}){const{convert:o}=G();return e.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:r?0:12,width:r?void 0:"100%",padding:r?"4px 12px":9,background:"none",border:`1px dashed ${i("rule-dashed")}`,cursor:"pointer",fontSize:12,color:i("meta-fg"),letterSpacing:r?void 0:".08em"},children:o(t)})}function Zs({children:t,href:n,onClick:r,title:o}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${i("rule")}`,fontSize:13,color:i("body-fg"),lineHeight:1.5};return n||r?e.jsx("a",{href:n??"#",title:o,onClick:r?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),r())}:void 0,style:s,children:t}):e.jsx("span",{title:o,style:s,children:t})}function rp({children:t}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t})}function op({volumes:t,unit:n="冊",max:r=60}){const[o,s]=m.useState(!1);if(!t.length)return null;const l=o?t:t.slice(0,r);return e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[l.map(a=>e.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${i("rule")}`,color:i("meta-fg")},children:a},a)),!o&&t.length>r&&e.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:["+",t.length-r]}),e.jsx("span",{style:{padding:"2px 6px",color:i("hint-fg")},children:n})]})}function sp({children:t}){return e.jsx("div",{style:{borderTop:`1px solid ${i("rule-strong")}`},children:t})}function lp({spec:t}){const{convert:n}=G();return e.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${t.leadWidth}px 1fr ${t.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${i("rule-strong")}`,fontSize:11,color:i("label-fg"),letterSpacing:".1em"},children:[e.jsx("span",{}),e.jsx("span",{children:n(t.mainLabel)}),e.jsx("span",{style:{display:"grid",gridTemplateColumns:t.columns.map(r=>r.width).join(" "),gap:12},children:t.columns.map(r=>e.jsx("span",{children:n(r.label)},r.label))})]})}function ap({no:t,main:n,meta:r,spec:o}){return e.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${o.leadWidth}px 1fr ${o.metaWidth}px`,gap:12},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:i("hint-fg"),textAlign:"right"},children:t}),e.jsx("span",{style:{minWidth:0},children:n}),e.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:o.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:r})]})}function cp(t){return String(t+1).padStart(2,"0")}function dp(){return e.jsx("span",{style:{color:i("hint-fg")},children:"—"})}function pp({open:t,onToggle:n,main:r,action:o,children:s}){return e.jsxs("div",{style:{borderBottom:`1px solid ${i("rule")}`},children:[e.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[e.jsx("button",{type:"button",onClick:n,"aria-expanded":t,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(t?"accent":"rule-dashed")}`,background:t?i("accent"):"transparent",color:i(t?"page-bg":"accent")},children:t?"-":"+"}),e.jsx("span",{style:{fontSize:14,minWidth:0},children:r}),o]}),t&&s&&e.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${i("rule-accent-soft")}`,marginLeft:12},children:s})]})}function Xs(t){const n=[];for(let r=0;r<t.length;r++){const o=t[r];let s;if(o==="⟨")s="⟩";else if(o==="<"){const p=t[r+1];if(p===void 0||/[A-Za-z/!?>\s]/.test(p))continue;s=">"}else continue;const l=t.indexOf(s,r+1);if(l<0)continue;const a=t.slice(r+1,l);a.includes(`
|
|
687
|
+
`)||(n.push({start:r,end:l+1,inner:a}),r=l)}return n}function Qs(t,n){if(t.length<=n)return t;let r=n;for(const o of Xs(t)){if(o.start>=r)break;if(o.end>r){r=o.start>0?o.start:o.end;break}}return t.slice(0,r)}const el={fontSize:".78em",color:i("meta-fg"),lineHeight:1.55},up={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 tl(t,n,r){return t.map((o,s)=>{switch(o.type){case"text":return e.jsx(m.Fragment,{children:n(o.text)},s);case"jz":return e.jsx("span",{className:"bim-jiazhu",style:r===0?el:void 0,children:tl(o.children,n,r+1)},s);case"qw":return e.jsx("span",{className:"bim-qw guji-qw",title:o.label?`闕文:${o.label}`:"闕文",children:"□"},s);case"qz":return e.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":o.guess,children:"□"},s);case"zi":return e.jsx("span",{className:"bim-zi guji-zi",title:`組字:${o.label}`,style:up,children:o.label},s)}})}function Qe(t,n=o=>o,r){if(!t)return"";if(r!=null&&r.gujiMarkdown)return Vd(t)?tl(Gs(t),n,0):n(t);if(t.indexOf("⟨")<0&&t.indexOf("<")<0)return n(t);const o=[];let s=0,l=0;for(const a of Xs(t))a.start>s&&o.push(e.jsx(m.Fragment,{children:n(t.slice(s,a.start))},l++)),o.push(e.jsx("span",{className:"bim-jiazhu",style:el,children:n(a.inner)},l++)),s=a.end;return s<t.length&&o.push(e.jsx(m.Fragment,{children:n(t.slice(s))},l++)),o}function mp({label:t,children:n}){return e.jsxs("div",{style:{marginBottom:10},children:[t&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:i("label-fg"),marginBottom:4},children:t}),e.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:i("quiet-fg"),textAlign:"justify"},children:n})]})}function xp({title:t,tag:n,children:r}){const{convert:o}=G();return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${i("rule-strong")}`,marginBottom:2},children:[e.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:o(t)}),n&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:i("accent"),letterSpacing:".06em"},children:o(n)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:r})]})}function nl({name:t,note:n,href:r,extra:o}){const s=e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{fontSize:14,minWidth:0},children:t}),e.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:i("hint-fg"),flex:"none"},children:r?"↗":""}),n&&e.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 e.jsxs(e.Fragment,{children:[r?e.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:l,children:s}):e.jsx("div",{style:l,children:s}),o]})}function hp({item:t,siblings:n,showVolumes:r=!0,fallbackNote:o}){const{convert:s}=G(),[l,a]=m.useState(!1),p=Rn(t),c=r&&!!p&&p.expected>0,d=(t.url?Ut(t.url):void 0)||s(t.name),u=n?Ls(t,n):"",h=u?`${d}(${u})`:d;return e.jsx(nl,{name:h,note:Pn(t)||o,href:Yt(t),extra:c?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>a(x=>!x),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:l?"收起分冊":`展開 ${p.expected} 冊`}),l&&e.jsx(Qi,{item:t})]}):void 0})}function Qi({item:t}){return e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(t.volumes||[]).map((n,r)=>{const o=n.status==="missing";return n.url&&!o?e.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},r):e.jsx("span",{style:{padding:"1px 5px",color:i(o?"missing-fg":"hint-fg"),textDecoration:o?"line-through":void 0},children:n.volume},r)})})}function il({label:t,items:n}){const{convert:r}=G();return n.length?e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".08em"},children:t}),n.map((o,s)=>e.jsx(Zs,{children:r(o)},s))]}):null}function fp({rows:t}){const n=t.filter(r=>r.items.length>0);return n.length?e.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(r=>e.jsx(il,{label:r.label,items:r.items},r.label))}):null}function wi(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function rl({left:t,right:n}){return e.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:[e.jsx("span",{children:t}),n&&e.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function gp({children:t,action:n}){return e.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:[e.jsx("span",{children:t}),n]})}function De({id:t,label:n,onNavigate:r,renderLink:o,style:s,dense:l}){const a=Pe();return o?e.jsx(e.Fragment,{children:o(t,typeof n=="string"?n:void 0,{dense:l})}):e.jsx("a",{href:a(t),onClick:r?p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),r(t))}:void 0,style:s,children:n??t})}function bp({href:t,children:n}){return e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:[n," ",e.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const ol="(min-width: 1100px)",sl="(max-width: 719px)",ll="(max-width: 859px)",yp=`${sl}, (pointer: coarse)`,vt=i("reader-top"),jp="48px",al=`
|
|
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: ${jp};
|
|
694
694
|
}
|
|
695
695
|
.bim-rd *, .bim-rd *::before, .bim-rd *::after { box-sizing: border-box; }
|
|
696
696
|
|
|
@@ -716,7 +716,7 @@ ${yd}`;function tn({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: ${vt}; z-index: 30;
|
|
720
720
|
height: var(--bimrd-bar-h);
|
|
721
721
|
display: flex; align-items: center; gap: 16px;
|
|
722
722
|
padding: 0 20px;
|
|
@@ -771,14 +771,14 @@ ${yd}`;function tn({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
771
771
|
display: grid;
|
|
772
772
|
grid-template-columns: auto auto minmax(0, 1fr);
|
|
773
773
|
align-items: start;
|
|
774
|
-
min-height: calc(100vh - ${
|
|
774
|
+
min-height: calc(100vh - ${vt} - var(--bimrd-bar-h));
|
|
775
775
|
}
|
|
776
776
|
|
|
777
777
|
/* 目录:宽屏是侧栏 */
|
|
778
778
|
.bim-rd-toc {
|
|
779
779
|
grid-column: 1;
|
|
780
|
-
position: sticky; top: calc(${
|
|
781
|
-
width: 248px; height: calc(100vh - ${
|
|
780
|
+
position: sticky; top: calc(${vt} + var(--bimrd-bar-h));
|
|
781
|
+
width: 248px; height: calc(100vh - ${vt} - var(--bimrd-bar-h));
|
|
782
782
|
overflow-y: auto; overscroll-behavior: contain;
|
|
783
783
|
padding: 0 10px 40px;
|
|
784
784
|
background: ${i("sidebar-bg")};
|
|
@@ -815,8 +815,8 @@ ${yd}`;function tn({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
815
815
|
/* 书影:正文左侧 */
|
|
816
816
|
.bim-rd-img {
|
|
817
817
|
grid-column: 2;
|
|
818
|
-
position: sticky; top: calc(${
|
|
819
|
-
width: clamp(300px, 32vw, 560px); height: calc(100vh - ${
|
|
818
|
+
position: sticky; top: calc(${vt} + var(--bimrd-bar-h));
|
|
819
|
+
width: clamp(300px, 32vw, 560px); height: calc(100vh - ${vt} - var(--bimrd-bar-h));
|
|
820
820
|
padding: 16px 0 16px 20px;
|
|
821
821
|
display: flex; flex-direction: column; gap: 8px;
|
|
822
822
|
}
|
|
@@ -827,7 +827,7 @@ ${yd}`;function tn({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
827
827
|
display: flex; align-items: center; justify-content: center; overflow: hidden;
|
|
828
828
|
}
|
|
829
829
|
.bim-rd-img-fig { position: relative; margin: 0; max-width: 100%; max-height: 100%; }
|
|
830
|
-
.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 - ${vt} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
|
|
831
831
|
.bim-rd-img-fig svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
|
|
832
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")}; }
|
|
833
833
|
.bim-rd-img-empty b { font-size: 15px; font-weight: 500; color: ${i("quiet-fg")}; }
|
|
@@ -923,7 +923,7 @@ ${yd}`;function tn({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
|
|
|
923
923
|
|
|
924
924
|
/* 竖排(预留):只在宿主打开 allowVertical 时可切换 */
|
|
925
925
|
.bim-rd-vertical .bim-rd-prose {
|
|
926
|
-
writing-mode: vertical-rl; max-height: calc(100vh - ${
|
|
926
|
+
writing-mode: vertical-rl; max-height: calc(100vh - ${vt} - var(--bimrd-bar-h) - 120px);
|
|
927
927
|
overflow-x: auto; text-align: start;
|
|
928
928
|
}
|
|
929
929
|
|
|
@@ -946,9 +946,51 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
|
|
|
946
946
|
.bim-rd-refs h2 { font-size: 12px; font-weight: 600; letter-spacing: 0.2em; margin: 0 0 6px; color: ${i("meta-fg")}; }
|
|
947
947
|
.bim-rd-refs ol { margin: 0; padding-left: 1.6em; }
|
|
948
948
|
|
|
949
|
+
/* ── 返回阅读首页(overview#308) ── */
|
|
950
|
+
.bim-rd-back {
|
|
951
|
+
flex: none; display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 2px;
|
|
952
|
+
font-size: 13px; color: ${i("quiet-fg")}; text-decoration: none; white-space: nowrap;
|
|
953
|
+
}
|
|
954
|
+
.bim-rd-back > span:first-child { font-size: 18px; line-height: 1; }
|
|
955
|
+
.bim-rd-back:hover { color: ${i("accent")}; }
|
|
956
|
+
|
|
957
|
+
/* ── 手机底栏与底部抽屉(<860px,overview#308):卷目/书影/字号/报告错字 ── */
|
|
958
|
+
.bim-rd-bb {
|
|
959
|
+
position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
|
|
960
|
+
display: flex; padding-bottom: env(safe-area-inset-bottom, 0px);
|
|
961
|
+
background: color-mix(in srgb, ${i("page-bg")} 96%, transparent); backdrop-filter: blur(8px);
|
|
962
|
+
border-top: 1px solid ${i("rule")};
|
|
963
|
+
}
|
|
964
|
+
.bim-rd-bb button {
|
|
965
|
+
flex: 1; min-height: 56px; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
|
|
966
|
+
margin: 0; padding: 6px 4px; border: 0; background: none; cursor: pointer;
|
|
967
|
+
font: inherit; font-size: 12px; color: ${i("quiet-fg")};
|
|
968
|
+
}
|
|
969
|
+
.bim-rd-bb button:hover, .bim-rd-bb button[aria-expanded="true"] { color: ${i("accent")}; }
|
|
970
|
+
.bim-rd-bb-ic { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; font-size: 14px; font-weight: 700; line-height: 1; }
|
|
971
|
+
.bim-rd-sheet-scrim { position: fixed; inset: 0; z-index: 54; background: ${i("backdrop")}; }
|
|
972
|
+
.bim-rd-sheet {
|
|
973
|
+
position: fixed; left: 0; right: 0; bottom: 0; z-index: 55; max-height: 80vh; overflow-y: auto;
|
|
974
|
+
padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px));
|
|
975
|
+
background: ${i("card-bg")}; border-top: 1px solid ${i("rule")}; box-shadow: ${i("shadow-dialog")};
|
|
976
|
+
}
|
|
977
|
+
.bim-rd-sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; letter-spacing: 0.15em; color: ${i("meta-fg")}; }
|
|
978
|
+
.bim-rd-sheet-head .bim-rd-t { margin-left: auto; min-width: 44px; min-height: 44px; justify-content: center; letter-spacing: 0; }
|
|
979
|
+
.bim-rd-sheet-img { display: flex; flex-direction: column; gap: 8px; min-height: 40vh; }
|
|
980
|
+
.bim-rd-sheet-img .bim-rd-img-fig img { max-height: 60vh; }
|
|
981
|
+
.bim-rd-sheet-fs { display: flex; align-items: center; justify-content: center; gap: 24px; padding: 8px 0 12px; font-size: 15px; color: ${i("ink")}; }
|
|
982
|
+
.bim-rd-sheet-fs .bim-rd-t { min-width: 56px; min-height: 44px; justify-content: center; font-size: 17px; border: 1px solid ${i("rule")}; }
|
|
983
|
+
@media ${ll} {
|
|
984
|
+
.bim-rd[data-bb] .bim-rd-text { padding-bottom: calc(56px + 64px + env(safe-area-inset-bottom, 0px)); }
|
|
985
|
+
/* 底栏上已有的,工具条上不再重复(目录、字号) */
|
|
986
|
+
.bim-rd[data-bb] .bim-rd-bb-dup { display: none !important; }
|
|
987
|
+
.bim-rd[data-bb] .bim-rd-tools .bim-rd-sep { display: none; }
|
|
988
|
+
}
|
|
989
|
+
@media (min-width: 860px) { .bim-rd-bb, .bim-rd-sheet, .bim-rd-sheet-scrim { display: none; } }
|
|
990
|
+
|
|
949
991
|
/* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
|
|
950
992
|
A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
|
|
951
|
-
@media ${
|
|
993
|
+
@media ${yp} {
|
|
952
994
|
.bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
|
|
953
995
|
.bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
|
|
954
996
|
content: ""; position: absolute; left: 50%; top: 50%;
|
|
@@ -961,7 +1003,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
|
|
|
961
1003
|
}
|
|
962
1004
|
|
|
963
1005
|
/* ── 中屏以下:目录改抽屉 ── */
|
|
964
|
-
@media not all and ${
|
|
1006
|
+
@media not all and ${ol} {
|
|
965
1007
|
.bim-rd-toc {
|
|
966
1008
|
position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto;
|
|
967
1009
|
width: min(86vw, 320px);
|
|
@@ -975,7 +1017,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
|
|
|
975
1017
|
}
|
|
976
1018
|
|
|
977
1019
|
/* ── 窄屏:书影收起,只留正文 ── */
|
|
978
|
-
@media ${
|
|
1020
|
+
@media ${sl} {
|
|
979
1021
|
.bim-rd-bar { padding: 0 12px; gap: 10px; }
|
|
980
1022
|
.bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
|
|
981
1023
|
/* 工具条放不下时(版本、自然段、标出作品链接都在)在条内左右滑,不撑宽页面 */
|
|
@@ -1009,21 +1051,21 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
|
|
|
1009
1051
|
:root[data-theme="ink"] .bim-rd-t[aria-pressed="true"], :root[data-theme="ink"] .bim-rd-t[aria-current="true"] {
|
|
1010
1052
|
text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px;
|
|
1011
1053
|
}
|
|
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(`
|
|
1014
|
-
`),
|
|
1015
|
-
`);
|
|
1016
|
-
`)}),l=
|
|
1017
|
-
`).map(n=>n.trim()).filter(n=>n&&!
|
|
1018
|
-
`)){const s=
|
|
1019
|
-
`),
|
|
1020
|
-
`)}),s=[]};for(const
|
|
1021
|
-
`)){const
|
|
1022
|
-
`)?"":n)}function
|
|
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
|
-
${
|
|
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=`
|
|
1054
|
+
`;function er(t,n){var r;return n?t.key===n?!0:!!((r=t.children)!=null&&r.some(o=>er(o,n))):!1}const vp=()=>e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:e.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function kp({item:t,activeKey:n,onSelect:r,tabKey:o}){const s=er(t,n),[l,a]=m.useState(s||!!t.defaultExpanded);return m.useEffect(()=>{s&&a(!0)},[s]),m.useEffect(()=>{t.defaultExpanded&&a(!0)},[t.defaultExpanded]),e.jsxs("li",{children:[e.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":t.key,tabIndex:o===t.key?0:-1,onClick:()=>a(p=>!p),children:[e.jsx(vp,{}),e.jsx("span",{children:t.label}),t.hint!=null&&e.jsx("span",{className:"bim-rd-hint",children:t.hint})]}),l&&e.jsx(cl,{items:t.children,activeKey:n,onSelect:r,tabKey:o})]})}function cl({items:t,activeKey:n,onSelect:r,tabKey:o}){return e.jsx("ul",{children:t.map(s=>s.children&&s.children.length>0?e.jsx(kp,{item:s,activeKey:n,onSelect:r,tabKey:o},s.key):e.jsx("li",{children:e.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:o===s.key?0:-1,onClick:()=>r(s.key),children:[e.jsx("span",{children:s.label}),s.hint!=null&&e.jsx("span",{className:"bim-rd-hint",children:s.hint})]})},s.key))})}function uo(t,n){var r;for(const o of t)if(o.key===n||er(o,n))return o.key;return((r=t[0])==null?void 0:r.key)??null}function dl({items:t,activeKey:n,onSelect:r,label:o="目录"}){const s=m.useRef(null),[l,a]=m.useState(null);m.useEffect(()=>{a(null)},[n]);const p=m.useMemo(()=>l||(n??uo(t,n)),[l,n,t]);m.useEffect(()=>{const d=s.current;if(!d)return;const u=Array.from(d.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const h=u.find(x=>x.dataset.rdTocKey===p)??u.find(x=>x.dataset.rdTocKey===uo(t,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===h?0:-1}),m.useEffect(()=>{const d=s.current,u=d==null?void 0:d.closest(".bim-rd-toc");if(!d||!u||!n)return;const h=Array.from(d.querySelectorAll("[data-rd-toc-key]")).find(f=>f.dataset.rdTocKey===n);if(!h)return;const x=h.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(x<u.scrollTop+80||x>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,x-u.clientHeight/3))},[n]);const c=m.useCallback(d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const h=s.current;if(!h)return;const x=Array.from(h.querySelectorAll("[data-rd-toc-key]")).filter(y=>!y.disabled),f=x.indexOf(document.activeElement);let b=f;if(d.key==="ArrowDown"?b=Math.min(x.length-1,f+1):d.key==="ArrowUp"?b=Math.max(0,f-1):d.key==="Home"?b=0:d.key==="End"&&(b=x.length-1),b<0||b===f)return;d.preventDefault();const w=x[b];for(const y of x)y.tabIndex=-1;w.tabIndex=0,w.focus(),a(w.dataset.rdTocKey??null)},[]);return e.jsx("div",{ref:s,role:"navigation","aria-label":o,onKeyDown:c,children:e.jsx(cl,{items:t,activeKey:n,onSelect:r,tabKey:p})})}function wp({page:t}){var n;return!((n=t.boxes)!=null&&n.length)||!t.width||!t.height||t.boxFormat&&t.boxFormat!=="bim-charbox-v0"?null:e.jsx("svg",{viewBox:`0 0 ${t.width} ${t.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:t.boxes.map((r,o)=>e.jsx("rect",{x:r.x,y:r.y,width:r.w,height:r.h,fill:"none",stroke:i("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},o))})}function Si({pages:t,loading:n,page:r,onPageChange:o,renderOverlay:s}){const[l,a]=m.useState(0),p=r??l,c=x=>{o?o(x):a(x)};if(m.useEffect(()=>{r===void 0&&a(0)},[t,r]),n)return e.jsx("div",{className:"bim-rd-img-box",children:e.jsx("div",{className:"bim-rd-img-empty",children:"加载书影…"})});if(!t||t.length===0)return e.jsx("div",{className:"bim-rd-img-box",children:e.jsxs("div",{className:"bim-rd-img-empty",children:[e.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),e.jsx("b",{children:"暂无书影"}),e.jsx("span",{children:"这一卷还没有配上影像;接入后在此与正文逐页对看"})]})});const d=Math.max(0,Math.min(t.length-1,p)),u=t[d],h=u.label??`${d+1}`;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bim-rd-img-box",children:e.jsxs("figure",{className:"bim-rd-img-fig",children:[e.jsx("img",{src:u.url,alt:u.alt??`书影 第 ${h} 页`,width:u.width,height:u.height,loading:"lazy",decoding:"async"}),e.jsx(wp,{page:u}),s==null?void 0:s(u,d)]})}),t.length>1&&e.jsxs("div",{className:"bim-rd-img-pager",children:[e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"上一页书影",disabled:d===0,onClick:()=>c(d-1),children:"‹"}),e.jsx("span",{"aria-live":"polite",children:u.label??`${d+1} / ${t.length}`}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"下一页书影",disabled:d===t.length-1,onClick:()=>c(d+1),children:"›"})]})]})}const tr={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal",workLinks:!0},ht=[15,16,17,18,20,22,24],$i=18,pl="bim-reader-prefs",Sp="bim-reading-mode";function $p(){const t={...tr};try{const n=localStorage.getItem(pl),r=n?JSON.parse(n):{};typeof r.fontSize=="number"&&ht.includes(r.fontSize)&&(t.fontSize=r.fontSize),(r.readingMode??localStorage.getItem(Sp))==="paragraph"&&(t.readingMode="paragraph"),r.properNames===!0&&(t.properNames=!0),r.writingMode==="vertical"&&(t.writingMode="vertical"),r.workLinks===!1&&(t.workLinks=!1)}catch{}return t}function _p(t){try{localStorage.setItem(pl,JSON.stringify(t))}catch{}}function vn(t,n){const r=t??$i,o=ht;let s=o.indexOf(r);return s<0&&(s=o.indexOf($i)),o[Math.max(0,Math.min(o.length-1,s+n))]}function Gn(){const[t,n]=m.useState(tr);m.useEffect(()=>{n($p())},[]);const r=m.useCallback(o=>{n(s=>{const l={...s,...o};return _p(l),l})},[]);return[t,r]}function ul(t){return t.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 _i(t){if(t.optionLabel)return t.optionLabel;const n=t.label||t.key;return!t.sourceName||n.includes(t.sourceName)?n:`${n} · ${t.sourceName}`}function ml(t,n){if(!(!t||t.length===0))return(n!=null?t.find(r=>r.key===n):void 0)??t.find(r=>r.primary)??t[0]}function xl(t){const n=[],r=o=>{for(const s of o)s.children&&s.children.length>0?r(s.children):n.push(s)};return r(t),n}const mo=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),zp=()=>e.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:e.jsx("path",{d:"M15 5l-7 7 7 7"})}),Cp=()=>e.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:e.jsx("path",{d:"M9 5l7 7-7 7"})}),xo=()=>e.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:[e.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),e.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function ho(t,n){if(!n)return;const r=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(a=>a.tabIndex>=0);if(r.length===0)return;const o=r[0],s=r[r.length-1],l=document.activeElement;t.shiftKey&&(l===o||!n.contains(l))?(t.preventDefault(),s.focus()):!t.shiftKey&&(l===s||!n.contains(l))&&(t.preventDefault(),o.focus())}function fo(t,n){const[r,o]=m.useState(n);return m.useEffect(()=>{var a;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(t);o(s.matches);const l=()=>o(s.matches);return(a=s.addEventListener)==null||a.call(s,"change",l),()=>{var p;return(p=s.removeEventListener)==null?void 0:p.call(s,"change",l)}},[t]),r}function Tp(){const t=m.useContext(Vt);if(!t)return null;const n=t.locale==="zh-Hant";return e.jsxs("button",{type:"button",className:"bim-rd-t",title:n?"切换为简体":"切換為繁體","aria-label":n?"切换为简体":"切換為繁體",onClick:()=>t.setLocale(n?"zh-Hans":"zh-Hant"),children:[e.jsx("span",{className:n?"bim-rd-on":"bim-rd-off",children:"繁"}),e.jsx("span",{className:"bim-rd-off",children:"|"}),e.jsx("span",{className:n?"bim-rd-off":"bim-rd-on",children:"简"})]})}function Ip(t,n){if(!t)return;let r;for(const o of Array.from(t.querySelectorAll('[id^="rd-e-"]')))if(o.getBoundingClientRect().top<=n+8)r=o.id;else break;return r}function Ep(t){var l;if(typeof window>"u"||!t)return;const n=(l=window.getSelection)==null?void 0:l.call(window);if(!n||n.isCollapsed||n.rangeCount===0)return;const r=t.querySelector(".bim-rd-col"),o=a=>{const p=(a==null?void 0:a.nodeType)===1?a:a==null?void 0:a.parentElement;return!!a&&!!(r!=null&&r.contains(a))&&!(p!=null&&p.closest(".bim-rd-src, .bim-rd-pager"))};if(!o(n.anchorNode)||!o(n.focusNode))return;const s=n.toString().replace(/\s+/g," ").trim();return s?s.slice(0,500):void 0}function Vn({title:t,subtitle:n,toc:r,activeKey:o,onSelect:s,tocHeader:l,tocCaption:a,images:p,imagesLoading:c,renderImageOverlay:d,imagePanel:u="auto",prefs:h,onPrefsChange:x,paragraphToggle:f,properNameToggle:b=!0,allowVertical:w,byline:y,current:j,workLinkToggle:g,rail:v,onReportError:$,revisedAt:k,backHref:_,backLabel:S="阅读",bottomBar:z=!0,pager:A=!0,pagerUnit:E="卷",versions:T,currentVersionKey:H,onVersionChange:B,versionSource:O=!0,keepChapterOnVersionChange:D=!1,children:ne,className:V,style:C}){const xe=m.useId().replace(/:/g,""),L=`bim-rd-toc-${xe}`,te=`bim-rd-text-${xe}`,N=m.useRef(null),Z=m.useRef(null),ce=m.useRef(null),W=m.useRef(null),X=fo(ol,!0),ae=fo(ll,!1),de=z&&ae,[me,$e]=m.useState(null),Me=m.useRef(null),Ee=m.useRef(null),Le=(F,ve)=>{Ee.current=ve,$e(We=>We===F?null:F)},ze=m.useCallback(()=>{var F;$e(null),(F=Ee.current)==null||F.focus()},[]);m.useEffect(()=>{de||$e(null)},[de]),m.useEffect(()=>{var F,ve;me&&((ve=(F=Me.current)==null?void 0:F.querySelector("button:not([disabled])"))==null||ve.focus())},[me]);const[Ae,P]=m.useState("auto"),he=Ae==="auto"?X:Ae==="open",ie=!X,ke=!!p&&p.length>0,[we,Y]=m.useState(u);m.useEffect(()=>{Y(u)},[u]);const R=we==="auto"?ke||!!c:we==="open",U=m.useCallback(F=>{var ve;P("auto"),F&&((ve=W.current)==null||ve.focus())},[]),fe=()=>P(he?"closed":"open");m.useEffect(()=>{if(!ie||Ae!=="open")return;const F=ce.current,ve=F==null?void 0:F.querySelector('input, [data-rd-toc-key][tabindex="0"]');ve==null||ve.focus()},[ie,Ae]);const be=m.useCallback(F=>{s(F),ie&&U(!1);const ve=Z.current,We=N.current;if(ve&&We&&typeof window<"u"){const Ke=ve.getBoundingClientRect().top-We.getBoundingClientRect().bottom;Ke<0&&window.scrollBy({top:Ke})}},[s,ie,U]),M=m.useMemo(()=>xl(r),[r]),[ue,K]=m.useState(null),se=ml(T,H!==void 0?H:ue),je=(se==null?void 0:se.key)??null,Te=m.useMemo(()=>M.map(F=>F.key).join(`
|
|
1055
|
+
`),[M]),Ce=m.useRef(null),le=F=>{F!==je&&(D||(Ce.current={key:F,sig:Te,done:!1}),H===void 0&&K(F),B==null||B(F))};m.useEffect(()=>{const F=Ce.current;if(!F||F.key!==je)return;const ve=M.find(Ke=>!Ke.disabled);if(!ve)return;const We=Te!==F.sig;!We&&F.done||(We?Ce.current=null:F.done=!0,ve.key!==o&&be(ve.key))},[je,Te,M,o,be]);const _e=M.find(F=>F.key===o),I=()=>{var F;$==null||$({chapterKey:o,chapterLabel:typeof(_e==null?void 0:_e.label)=="string"?_e.label:void 0,anchor:Ip(Z.current,((F=N.current)==null?void 0:F.getBoundingClientRect().bottom)??0),selectedText:Ep(Z.current)})},J=M.findIndex(F=>F.key===o),oe=J>0?M.slice(0,J).reverse().find(F=>!F.disabled):void 0,Q=J>=0?M.slice(J+1).find(F=>!F.disabled):void 0,ee=h.fontSize??$i,Se={...C,...h.fontSize?{"--bimrd-fs":`${h.fontSize}px`}:null};return e.jsxs("div",{className:["bim-rd",h.writingMode==="vertical"&&w?"bim-rd-vertical":"",V].filter(Boolean).join(" "),"data-toc":Ae,"data-img":R?"open":"closed","data-bb":de?"":void 0,style:Se,children:[e.jsx("style",{children:al}),e.jsx("a",{className:"bim-rd-skip",href:`#${te}`,onClick:F=>{var ve,We,Ke;F.preventDefault(),(ve=Z.current)==null||ve.focus(),(Ke=(We=Z.current)==null?void 0:We.scrollIntoView)==null||Ke.call(We,{block:"start"})},children:"跳到正文"}),e.jsxs("div",{className:"bim-rd-bar",ref:N,children:[_&&e.jsxs("a",{className:"bim-rd-back",href:_,"aria-label":`返回${S}首页`,children:[e.jsx("span",{"aria-hidden":"true",children:"‹"}),e.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:S})]}),(t||n||y||j)&&e.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[t&&e.jsx("b",{children:t}),y&&e.jsx("span",{className:"bim-rd-by",children:y}),j&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),e.jsx("span",{className:"bim-rd-cur",children:j})]}),n&&e.jsx("span",{children:n})]}),e.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":"阅读设置",children:[T&&T.length>1&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"bim-rd-ver",title:se?_i(se):void 0,children:[e.jsx("span",{className:"bim-rd-tlabel",children:"版本"}),e.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:"版本▾"}),e.jsx("select",{"aria-label":"版本",value:je??"",onChange:F=>le(F.target.value),children:T.map(F=>e.jsx("option",{value:F.key,children:_i(F)},F.key))})]}),e.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),A&&(oe||Q)&&e.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":`翻${E}`,children:[e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":`上一${E}`,title:oe?`上一${E}:${typeof oe.label=="string"?oe.label:""}`.replace(/:$/,""):`已是第一${E}`,disabled:!oe,onClick:()=>oe&&be(oe.key),children:e.jsx(zp,{})}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":`下一${E}`,title:Q?`下一${E}:${typeof Q.label=="string"?Q.label:""}`.replace(/:$/,""):`已是最后一${E}`,disabled:!Q,onClick:()=>Q&&be(Q.key),children:e.jsx(Cp,{})})]}),A&&(oe||Q)&&e.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),e.jsxs("button",{ref:W,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":he,"aria-controls":L,onClick:fe,children:[e.jsx(mo,{}),e.jsx("span",{className:"bim-rd-tlabel",children:"目录"})]}),e.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":R,onClick:()=>Y(R?"closed":"open"),children:[e.jsx(xo,{}),"书影"]}),e.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),e.jsx(Tp,{}),e.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),e.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":"缩小字号",disabled:ee<=ht[0],onClick:()=>x({fontSize:vn(h.fontSize,-1)}),children:"A−"}),e.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":"放大字号",disabled:ee>=ht[ht.length-1],onClick:()=>x({fontSize:vn(h.fontSize,1)}),children:"A+"}),(f||b||w)&&e.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),f&&e.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":h.readingMode==="paragraph",title:"条目分行 ↔ 自然段",onClick:()=>x({readingMode:h.readingMode==="paragraph"?"line":"paragraph"}),children:"自然段"}),g&&e.jsxs("label",{className:"bim-rd-t bim-rd-chk",children:[e.jsx("input",{type:"checkbox",checked:h.workLinks,onChange:F=>x({workLinks:F.target.checked})}),e.jsx("span",{children:"标出作品链接"})]}),b&&e.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":h.properNames,title:"书名加波浪线",onClick:()=>x({properNames:!h.properNames}),children:"专名线"}),w&&e.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":h.writingMode==="vertical",onClick:()=>x({writingMode:h.writingMode==="vertical"?"horizontal":"vertical"}),children:"竖排"})]})]}),e.jsxs("div",{className:"bim-rd-body",children:[e.jsxs("div",{className:"bim-rd-toc",id:L,ref:ce,role:ie&&he?"dialog":void 0,"aria-modal":ie&&he?!0:void 0,"aria-label":ie&&he?"目录":void 0,onKeyDown:F=>{if(!(!ie||!he)){if(F.key==="Escape"){F.stopPropagation(),U(!0);return}F.key==="Tab"&&ho(F,ce.current)}},children:[e.jsxs("div",{className:"bim-rd-toc-top",children:[e.jsxs("div",{className:"bim-rd-toc-head",children:[e.jsx("span",{children:a??"目录"}),ie&&e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"收起目录",onClick:()=>U(!0),children:"✕"})]}),l]}),e.jsx(dl,{items:r,activeKey:o,onSelect:be})]}),e.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>U(!0)}),e.jsx("aside",{className:"bim-rd-img","aria-label":"书影",children:R&&e.jsx(Si,{pages:p??null,loading:c,renderOverlay:d})}),e.jsxs("div",{className:"bim-rd-text",id:te,ref:Z,tabIndex:-1,"data-rail":v||$?"true":void 0,children:[e.jsxs("div",{className:"bim-rd-col",children:[ne,O&&se&&(se.sourceName||se.license)&&e.jsxs("p",{className:"bim-rd-src","data-version":se.key,children:[se.sourceName&&e.jsxs(e.Fragment,{children:["出处"," ",se.sourceUrl?e.jsx("a",{className:"bim-rd-link",href:se.sourceUrl,target:"_blank",rel:"noreferrer",children:se.sourceName}):se.sourceName]}),se.sourceName&&se.license&&e.jsx("span",{className:"bim-rd-dot"}),se.license&&e.jsxs(e.Fragment,{children:["授权 ",se.license]})]}),k&&e.jsxs("p",{className:"bim-rd-src bim-rd-rev",children:["最近校订 ",k]}),$&&e.jsx("p",{className:"bim-rd-src bim-rd-report-foot",children:e.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:F=>F.preventDefault(),onClick:I,children:"报告错字"})}),A&&(oe||Q)&&e.jsxs("nav",{className:"bim-rd-pager","aria-label":"翻卷",children:[oe?e.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>be(oe.key),children:[e.jsxs("span",{className:"bim-rd-pgcap",children:[e.jsx("span",{"aria-hidden":"true",children:"← "}),"上一",E]}),e.jsx("span",{className:"bim-rd-pglabel",children:oe.label})]}):e.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← 已是第一",E]}),Q?e.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>be(Q.key),children:[e.jsxs("span",{className:"bim-rd-pgcap",children:["下一",E,e.jsx("span",{"aria-hidden":"true",children:" →"})]}),e.jsx("span",{className:"bim-rd-pglabel",children:Q.label})]}):e.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:["已是最后一",E," →"]})]})]}),(v||$)&&e.jsxs("aside",{className:"bim-rd-rail","aria-label":"本卷",children:[v,$&&e.jsx("div",{className:"bim-rd-rail-acts",children:e.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:F=>F.preventDefault(),onClick:I,children:"报告错字"})})]})]})]}),de&&e.jsxs("nav",{className:"bim-rd-bb","aria-label":"阅读工具",children:[e.jsxs("button",{type:"button","aria-expanded":he,"aria-controls":L,onClick:()=>{$e(null),fe()},children:[e.jsx(mo,{}),e.jsx("span",{children:"卷目"})]}),e.jsxs("button",{type:"button","aria-expanded":me==="img","aria-haspopup":"dialog",onClick:F=>Le("img",F.currentTarget),children:[e.jsx(xo,{}),e.jsx("span",{children:"书影"})]}),e.jsxs("button",{type:"button","aria-expanded":me==="fs","aria-haspopup":"dialog",onClick:F=>Le("fs",F.currentTarget),children:[e.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"A"}),e.jsx("span",{children:"字号"})]}),$&&e.jsxs("button",{type:"button",onMouseDown:F=>F.preventDefault(),onClick:()=>{$e(null),I()},children:[e.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),e.jsx("span",{children:"报告错字"})]})]}),de&&me&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:ze}),e.jsxs("div",{className:"bim-rd-sheet",ref:Me,role:"dialog","aria-modal":"true","aria-label":me==="img"?"书影":"字号",onKeyDown:F=>{if(F.key==="Escape"){F.stopPropagation(),ze();return}F.key==="Tab"&&ho(F,Me.current)},children:[e.jsxs("div",{className:"bim-rd-sheet-head",children:[e.jsx("span",{children:me==="img"?"书影":"字号"}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"关闭",onClick:ze,children:"✕"})]}),me==="img"?e.jsx("div",{className:"bim-rd-sheet-img",children:e.jsx(Si,{pages:p??null,loading:c,renderOverlay:d})}):e.jsxs("div",{className:"bim-rd-sheet-fs",children:[e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"缩小字号",disabled:ee<=ht[0],onClick:()=>x({fontSize:vn(h.fontSize,-1)}),children:"A−"}),e.jsxs("output",{"aria-live":"polite",children:[ee,"px"]}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大字号",disabled:ee>=ht[ht.length-1],onClick:()=>x({fontSize:vn(h.fontSize,1)}),children:"A+"})]})]})]})]})}const hl="guji-table-v1";function nr(t){return!!t&&t.table_notation===hl}const Np=/^:::table(?:\{[^}]*\})?[ \t]*$/,Rp=/^:::[ \t]*$/;function fl(t){const n=[];let r="";for(let o=0;o<t.length;o++){const s=t[o];if(s===":"&&t.startsWith(":zi[",o)){const a=Ds(t,o+3);if(a>o+4){r+=t.slice(o,a+1),o=a;continue}}let l=null;if(s==="⟨")l="⟩";else if(s==="<"){const a=t[o+1];a!==void 0&&!/[A-Za-z/!?>\s]/.test(a)&&(l=">")}if(l){const a=t.indexOf(l,o+1);if(a>0){r+=t.slice(o,a+1),o=a;continue}}s==="|"?(n.push(r),r=""):r+=s}return n.push(r),n.map(o=>o.trim())}const Lp=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function Ap(t){if(t==="^")return{cont:!0};const n=Lp.exec(t),r=n[1].trim(),o=n[2]?Math.max(1,parseInt(n[2],10)):1,s=n[3]?Math.max(1,parseInt(n[3],10)):1,l=r==="_";return{cont:!1,cell:{text:l?"":r,empty:l,colspan:o,rowspan:s}}}function gl(t,n=1){const r=[],o=[],s=[];let l=[];t.forEach((p,c)=>{const d=c+n+1;let u=p.trim();if(!u)return;let h=!1;u.startsWith("!")&&(h=!0,u=u.slice(1));const x=fl(u).map(Ap),f=l.map(j=>j>0),b=l.map(j=>j>0?j-1:0),w=[];let y=0;for(const j of x){if(j.cont){f[y]||r.push(`第 ${d} 行第 ${y+1} 列:续格 ^ 上方没有跨行格`),y+=1;continue}const{cell:g}=j;for(let v=y;v<y+g.colspan;v++)if(f[v]){r.push(`第 ${d} 行第 ${v+1} 列:此处被上方跨行格占住,应写 ^`);break}if(g.rowspan>1)for(let v=y;v<y+g.colspan;v++)b[v]=g.rowspan-1;w.push(g),y+=g.colspan}for(let j=y;j<f.length;j++)f[j]&&r.push(`第 ${d} 行第 ${j+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let j=0;j<b.length;j++)b[j]===void 0&&(b[j]=0);l=b,o.push({header:h,cells:w}),s.push({width:y,line:d})});const a=s.reduce((p,c)=>Math.max(p,c.width),0);for(const p of s)p.width!==a&&r.push(`第 ${p.line} 行:占 ${p.width} 列,与总列数 ${a} 不符`);return l.some(p=>p>0)&&r.push("表尾:有跨行格超出了表的最后一行"),o.length===0&&r.push("空表"),{rows:o,columns:a,warnings:r}}function ir(t){const n=t.split(`
|
|
1056
|
+
`),r=[];let o=[];const s=()=>{if(o.length===0)return;const a=o.join(`
|
|
1057
|
+
`);o=[],r.push({type:"text",text:a})};let l=0;for(;l<n.length;){if(Np.test(n[l].trim())){let a=l+1;for(;a<n.length&&!Rp.test(n[a].trim());)a++;if(a<n.length){s();const p=n.slice(l+1,a);r.push({type:"table",table:gl(p,l+1),source:n.slice(l,a+1).join(`
|
|
1058
|
+
`)}),l=a+1;continue}}o.push(n[l]),l++}return s(),r.map((a,p)=>{var d,u;if(a.type!=="text")return a;let c=a.text;return((d=r[p-1])==null?void 0:d.type)==="table"&&(c=c.replace(/^\n+/,"")),((u=r[p+1])==null?void 0:u.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(a=>a.type!=="text"||a.text!=="")}const Bp={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},Mp={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},Wp=`1px solid ${i("table-border")}`,bl={border:Wp,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},Fp={...bl,background:i("table-head-bg"),fontWeight:600};function rr({table:t,opts:n}){return e.jsx("div",{className:"bim-guji-table-wrap",style:Bp,children:e.jsx("table",{className:"bim-guji-table",style:Mp,children:e.jsx("tbody",{children:t.rows.map((r,o)=>e.jsx("tr",{children:r.cells.map((s,l)=>{const a=r.header?"th":"td";return e.jsx(a,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:r.header?Fp:bl,children:s.empty?null:Qe(s.text,void 0,n)},l)})},o))})})})}function Op(t,n){return t.indexOf("**")<0?Qe(t,void 0,n):t.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((o,s)=>s%2===1?e.jsx("strong",{children:Qe(o.trim().slice(2,-2),void 0,n)},s):e.jsx(m.Fragment,{children:Qe(o,void 0,n)},s))}function Pp(t,n,r=!1){const o=r?{gujiMarkdown:!0}:void 0;return n?ir(t).map((s,l)=>s.type==="table"?e.jsx(rr,{table:s.table,opts:o},l):e.jsx(m.Fragment,{children:Op(s.text,o)},l)):Qe(t,void 0,o)}const Dp=/^(#{1,6})\s+(.*)$/,Hp=/^\*\*([^*\n]+)\*\*\s*$/;function or(t){const n=t.match(Dp);if(n)return{level:n[1].length,text:n[2].trim()};const r=t.trim().match(Hp);return r?{level:3,text:r[1].trim()}:null}const sr=/^<!--.*-->$/;function yl(t){return t.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function jl(t){return t.split(`
|
|
1059
|
+
`).map(n=>n.trim()).filter(n=>n&&!sr.test(n))}const Gp=60;function vl(t){let n=0,r=0;for(const o of t.split(`
|
|
1060
|
+
`)){const s=o.trim();if(!s||sr.test(s)||or(s))continue;const l=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=l,l>Gp&&(r+=l)}return n>0&&r*2>=n}function Vp(t){return t.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function Un(t){if(t=Vp(t),vl(t))return"unknown";const n=yl(t);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const r=n.map(s=>jl(s).length).filter(s=>s>0);if(r.length===0)return"unknown";const o=r.reduce((s,l)=>s+l,0)/r.length;return o<=4?"record":o>=8?"catalog":"unknown"}function Up(t){const n=t.split(`
|
|
1061
|
+
`),r=[];let o=null,s=[];const l=()=>{r.push({heading:o,body:s.join(`
|
|
1062
|
+
`)}),s=[]};for(const a of n){const p=or(a);if(p){l(),o={kind:"heading",level:p.level,text:p.text};continue}s.push(a)}return l(),r}function go(t){const n=[];for(const r of t.split(`
|
|
1063
|
+
`)){const o=or(r);if(o){n.push({kind:"heading",level:o.level,text:o.text});continue}const s=r.trim();!s||sr.test(s)||n.push({kind:"body",text:r})}return n}function kl(t){if(!t)return[];const n=Un(t);if(n==="unknown")return go(t);const r=[];for(const{heading:o,body:s}of Up(t)){o&&r.push(o);const l=yl(s);if(l.length!==0){if(vl(s)){r.push(...go(s));continue}if(n==="record"){const a=l.join(" ");a&&r.push({kind:"body",text:a})}else for(const a of l){const p=jl(a);p.length&&r.push({kind:"body",text:p.join(" ")})}}}return r}const wl=t=>t;function Sl(t,n=wl){if(t.indexOf("《")<0)return n(t);const r=[],o=/《([^《》\n]+)》/g;let s=0,l=0,a;for(;a=o.exec(t);)a.index>s&&r.push(e.jsx(m.Fragment,{children:n(t.slice(s,a.index))},l++)),r.push(e.jsxs("span",{className:"bim-rd-pn",children:[e.jsx("span",{className:"bim-rd-sr",children:"《"}),n(a[1]),e.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=a.index+a[0].length;return s===0?n(t):(s<t.length&&r.push(e.jsx(m.Fragment,{children:n(t.slice(s))},l++)),r)}function lr(t,n={}){const r=n.renderText??wl,o=n.properNames?l=>Sl(l,r):r,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Qe(t,o,s)}function bo(t,n,r){return t.indexOf("**")<0?n(t):t.split(/(\*\*[^*]+\*\*)/g).map((s,l)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?e.jsx("strong",{children:n(s.slice(2,-2))},`${r}-${l}`):e.jsx(m.Fragment,{children:n(s)},`${r}-${l}`))}const oi=/^(#{1,6})\s+(.*)$/,Yp=/^\s*<!--.*-->\s*$/;function $l(t){return t.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
|
|
1064
|
+
`)?"":n)}function Kp(t){return t<=1?2:t===2?3:4}function qp(){let t=1;return n=>{const r=Kp(n),o=Math.min(r,t+1);return t=o,{Tag:`h${o}`,className:`bim-rd-hl${r}`}}}function Lt(t){return t?Un($l(t))!=="unknown":!1}function yo({text:t,mode:n,inline:r,dropTitle:o}){const s=$l(t),l=(d,u,h)=>!!o&&h<=1&&d<=2&&u.trim()===o.trim(),a=qp();if(n==="paragraph"&&Un(s)!=="unknown"){const d=kl(s);return e.jsx(e.Fragment,{children:d.map((u,h)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,h))return null;const{Tag:x,className:f}=a(u.level??1);return e.jsx(x,{className:f,children:r(u.text)},h)}return e.jsx("p",{children:bo(u.text,r,h)},h)})})}const p=s.split(`
|
|
1065
|
+
`);let c=0;return e.jsx(e.Fragment,{children:p.map((d,u)=>{const h=d.match(oi);if(h){const f=c++;if(l(h[1].length,h[2],f))return null;const{Tag:b,className:w}=a(h[1].length);return e.jsx(b,{className:w,children:r(h[2])},u)}if(!d.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!oi.test(p[u-1])&&!oi.test(p[u-2])?e.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(Yp.test(d))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(d.trim())){const{Tag:f,className:b}=a(3);return e.jsx(f,{className:b,children:r(d.trim().slice(2,-2))},u)}return e.jsx("p",{children:bo(d,r,u)},u)})})}function Jp(t){const{convert:n}=G();return m.useMemo(()=>t?n(t):"",[t,n])}function Yn({text:t,mode:n,tables:r=!1,gujiMarkdown:o=!1,properNames:s=!1,renderText:l,dropTitle:a}){const p=Jp(t),{convert:c}=G(),d=x=>lr(x,{renderText:l,properNames:s,gujiMarkdown:o}),u=o?{gujiMarkdown:!0}:void 0,h=a?c(a):void 0;return!r||p.indexOf(":::")<0?e.jsx(yo,{text:p,mode:n,inline:d,dropTitle:h}):e.jsx(e.Fragment,{children:ir(p).map((x,f)=>x.type==="table"?e.jsx(rr,{table:x.table,opts:u},f):e.jsx(yo,{text:x.text,mode:n,inline:d,dropTitle:f===0?h:void 0},f))})}function ar(t,n){const[r,o]=m.useState(null),[s,l]=m.useState(!1),a=m.useRef(0);return m.useEffect(()=>{const p=++a.current;if(!t||!n){o(null),l(!1);return}let c;try{c=t(n)}catch{o(null),l(!1);return}if(!c||typeof c.then!="function"){o(c??null),l(!1);return}l(!0),c.then(d=>{p===a.current&&o(d??null)}).catch(()=>{p===a.current&&o(null)}).finally(()=>{p===a.current&&l(!1)})},[t,n]),{images:r,loading:s}}const jo={A:"fine",B:"rough",C:"rough",D:"ocr"};function Zp(t){return typeof t!="string"?null:t in xi?t:t in jo?jo[t]:null}const Xp={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Qp={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function nt(t){return typeof t!="string"?"":Xp[t]??Qp[t]??t}const eu=["〇","一","二","三","四","五","六","七","八","九"],vo=["","十","百","千"],tu=["","萬","億"];function cr(t){if(t===0)return"〇";if(t<0)return`負${cr(-t)}`;const n=[];let r=t,o=0;for(;r>0;){const s=r%1e4;s>0?n.unshift(nu(s,o>0)+tu[o]):n.length>0&&n.unshift("〇"),r=Math.floor(r/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function nu(t,n){const r=[];let o=t;for(;o>0;)r.unshift(o%10),o=Math.floor(o/10);let s="";for(let l=0;l<r.length;l++){const a=r[l],p=r.length-1-l;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&p===1&&l===0&&!n?s+=vo[p]:s+=eu[a]+vo[p]}return s.replace(/〇$/,"")}let dn=null,kn=null;const En=new Set;function iu(){return dn?Promise.resolve():kn||(kn=import("opencc-js/t2cn").then(t=>{dn=t.Converter({from:"tw",to:"cn"}),En.forEach(n=>n())}).catch(()=>{dn=t=>t,En.forEach(t=>t())}),kn)}const ru=t=>t;function At(){const[,t]=m.useState(0);return m.useEffect(()=>{if(dn)return;const n=()=>t(r=>r+1);return En.add(n),iu(),()=>{En.delete(n)}},[]),dn??ru}function Gt(t,n){return n(t).toLowerCase()}const ou=i("highlight-bg");function bn(t,n,r){if(!n)return t;const o=Gt(n,r);if(!o)return t;const s=Gt(t,r);if(s.length!==t.length)return t;const l=[];let a=0,p=0;for(;a<t.length;){const c=s.indexOf(o,a);if(c===-1){l.push(t.slice(a));break}c>a&&l.push(t.slice(a,c)),l.push(e.jsx("mark",{style:{background:ou,padding:0,color:"inherit"},children:t.slice(c,c+o.length)},p++)),a=c+o.length}return e.jsx(e.Fragment,{children:l})}function dr(t,n,r,o){if(!n)return!0;const s=Gt(n,o);return(r?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(a=>typeof a=="string"&&Gt(a,o).includes(s))}function su(t,n,r){return n?Gt(t,r).includes(Gt(n,r)):!0}const pr={类:i("section-lei"),书:i("section-shu"),序:i("section-xu"),结语:i("section-jieyu"),注释:i("section-zhushi")},lu={考证:i("section-kaozhen")};function au(t){const n=t.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function ur(t){var o;const n=t.files.length,r=((o=t.children)==null?void 0:o.reduce((s,l)=>s+ur(l),0))||0;return n+r}function _l(t,n){const r=[],o=a=>{var p;r.push(...a.files),(p=a.children)==null||p.forEach(o)};if(o(t),r.length===0)return;const s=r.map(a=>n[a]);if(s.every(a=>a===void 0))return;if(s.some(a=>a==="loading"))return"loading";let l=0;for(const a of s)typeof a=="number"&&(l+=a);return l}const cu={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function mr({enabled:t,expanded:n,onClick:r,style:o,children:s}){return t?e.jsx("button",{type:"button","aria-expanded":n,onClick:r,style:{...cu,...o},children:s}):e.jsx("span",{style:o,children:s})}function du({type:t}){const n=nt(t),r=pr[n]||i("desc-fg");return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:r,border:`1px solid ${r}40`,borderRadius:"2px",background:`${r}08`,flexShrink:0},children:n})}function pu({section:t,onNavigate:n,highlightQuery:r="",no:o,showUnlinked:s=!1,domId:l}){const{convert:a}=G(),p=Pe(),c=At(),d=g=>g?Qe(a(g),v=>r?bn(v,r,c):v):"",[u,h]=m.useState(!1),x=!!t.summary,f=!!t.comment,b=!!t.additional_comment,w=!!(t.content&&t.content.length>60),y=x||f||b||w;m.useEffect(()=>{r&&h(!0)},[r]);const j=!u&&w?Qs(t.content.replace(/\n/g," "),80)+"…":null;return e.jsxs("div",{className:"bim-rd-row",id:l,style:{borderBottom:`1px solid ${i("rule")}`,overflow:"hidden"},children:[e.jsxs("div",{onClick:()=>y&&h(!u),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:y?"pointer":"default",userSelect:"none"},children:[o!=null&&e.jsx("span",{className:"bim-rd-no",style:{flex:"none",width:28,fontSize:12,color:i("label-fg")},children:o}),e.jsxs(mr,{enabled:y,expanded:u,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[y&&e.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:"▶"}),e.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg")},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",d(t.book_title),"》"]}):d(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[cr(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:d(t.author_info||t.author)})]}),!u&&j&&e.jsx("span",{style:{display:"block",fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:d(j)})]})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:d(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:i("section-tag-fg")},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:p(t.work_id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),g.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品","aria-label":`查看作品:${t.book_title||t.title}`,children:"作品 →"}),s&&!t.work_id&&e.jsx("span",{style:{fontSize:"11px",color:i("label-fg"),flexShrink:0},children:"未关联"})]}),u&&y&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${i("widget-border")}`,background:i("bg")},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:i("desc-fg"),marginBottom:"8px"},children:d(t.author_info)}),t.summary&&e.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:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:d(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${i("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:i("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(t.additional_comment)})]}),w&&!x&&!f&&!b&&e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:d(t.content)})]})]})}function uu({section:t,highlightQuery:n=""}){const{convert:r}=G(),o=At(),s=c=>c?Qe(r(c),d=>n?bn(d,n,o):d):"",[l,a]=m.useState(!1),p=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs(mr,{enabled:p,expanded:l,onClick:()=>a(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[e.jsx(du,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:s(t.title)}),p&&e.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&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${pr[nt(t.type)]||i("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:i("bg")},children:e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(t.content)})})]})}const mu=100;function xr(t){return nt(t.type)!=="page_header"?!1:(t.content||"").length>=mu}function xu({section:t,highlightQuery:n=""}){const{convert:r}=G(),o=At();if(nt(t.type)==="page_header"&&!xr(t)||!t.content&&!t.title)return null;const s=r((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
1066
|
+
`)),l=Qe(s,d=>n?bn(d,n,o):d),a=nt(t.type),p=pr[a]||i("desc-fg"),c=a==="序"||a==="结语"||a==="注释";return e.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:i("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${p}40`:void 0,background:c?i("bg"):void 0,borderRadius:c?"0 4px 4px 0":void 0,position:"relative"},children:[c&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:a}),l]})}function hu(t,n,r){const[o,s]=m.useState({});return m.useEffect(()=>{var d;if(!n||t.length===0)return;let l=!1;const a=t.filter(u=>{var h;return!((h=r==null?void 0:r.current)!=null&&h.has(u))}),p={};for(const u of t)(d=r==null?void 0:r.current)!=null&&d.has(u)&&(p[u]=r.current.get(u));if(Object.keys(p).length>0&&s(p),a.length===0)return;const c=async u=>{var h;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 f=x.title||u,b=x.authors,w=(h=b==null?void 0:b[0])==null?void 0:h.name;return{title:f,author:w}}catch{return null}};return Promise.all(a.map(async u=>{var x;const h=await c(u);return(x=r==null?void 0:r.current)==null||x.set(u,h),[u,h]})).then(u=>{l||s(h=>{const x={...h};for(const[f,b]of u)x[f]=b;return x})}),()=>{l=!0}},[t.join(","),n]),o}function fu({section:t,onNavigate:n,transport:r,workLabelCache:o,highlightQuery:s=""}){const{convert:l}=G(),a=Pe(),p=At(),c=g=>g?Qe(l(g),v=>s?bn(v,s,p):v):"",[d,u]=m.useState(!1);m.useEffect(()=>{s&&u(!0)},[s]);const h=nt(t.type),x=lu[h]||i("desc-fg"),f=!!t.content,b=t.work_ids||[],w=b.length>1,y=hu(w?b:[],r,o),j=f&&!d&&t.content.length>80?Qs(t.content,80)+"……":null;return e.jsxs("div",{style:{borderBottom:`1px solid ${i("widget-border")}`,padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>f&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:f?"pointer":"default",userSelect:"none"},children:[e.jsxs(mr,{enabled:f,expanded:d,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[f&&e.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:"▶"}),e.jsxs("span",{style:{display:"block",flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:i("fg"),lineHeight:1.6},children:t.header_line?c(t.header_line):c(t.title)}),!d&&j&&e.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:i("desc-fg"),lineHeight:1.7},children:c(j)})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&e.jsx("a",{href:a(b[0]),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),g.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),w&&e.jsxs("span",{style:{fontSize:"11px",color:i("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),e.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:h})]})]}),w&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(g=>{const v=y[g],$=v?`${l(v.title)}${v.author?`(${l(v.author)})`:""}`:g.slice(0,8)+"…";return e.jsxs("a",{href:a(g),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),n(g))},style:{fontSize:"12px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:g,children:["→",$]},g)})}),d&&f&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:i("bg")},children:[e.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${i("widget-border")}`,fontSize:"12px",color:i("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:c(t.comment)})]})]})}function gu({juan:t,searchQuery:n,onNavigate:r,transport:o,workLabelCache:s}){const l=At(),a=n.trim(),p=m.useMemo(()=>a?t.sections.filter(c=>dr(c,a,!0,l)):t.sections,[t.sections,a,l]);return e.jsxs("div",{children:[e.jsx("div",{children:p.map((c,d)=>e.jsx(fu,{section:c,onNavigate:r,transport:o,workLabelCache:s,highlightQuery:a},d))}),p.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function bu(){let t=!1;return n=>n==="类"?(t=!0,"h2"):t?"h3":"h2"}function yu({sections:t,onNavigate:n,inline:r,workLinks:o=!0}){const s=Pe(),{convert:l}=G(),a=bu();return e.jsx(e.Fragment,{children:t.map((p,c)=>{const d=nt(p.type);if(d==="page_header"&&!xr(p))return null;if(d==="类")return e.jsxs(m.Fragment,{children:[m.createElement(a("类"),null,r(l(p.title))),p.content&&e.jsx("p",{children:r(l(p.content))})]},c);if(d==="书"||d==="诗"||d==="考证"||d==="注释"){const u=p.book_title?`《${p.book_title}》${p.n_juan!=null?cr(p.n_juan)+"卷":""}`:p.title,h=r(l(u));return e.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${c}`,children:[m.createElement(a("条目"),{className:"bim-rd-entry-h"},p.work_id&&n&&o?e.jsxs(e.Fragment,{children:[e.jsx("a",{href:s(p.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),n(p.work_id))},title:"查看作品",children:h}),e.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:"作品 →"})]}):h),p.author_info&&e.jsx("p",{className:"bim-rd-sub",children:r(l(p.author_info))}),p.content&&p.content.split(/\n+/).map((x,f)=>e.jsx("p",{children:r(l(x))},f)),p.summary&&e.jsxs("p",{children:[e.jsx("span",{className:"bim-rd-lbl",children:"提要"}),r(l(p.summary))]}),p.comment&&e.jsxs("p",{children:[e.jsx("span",{className:"bim-rd-lbl",children:"按語"}),r(l(p.comment))]}),p.additional_comment&&e.jsxs("p",{children:[e.jsx("span",{className:"bim-rd-lbl",children:"附按"}),r(l(p.additional_comment))]})]},c)}return p.content?e.jsx("p",{children:r(l(p.content))},c):null})})}function hr(t){return t.some(n=>{const r=nt(n.type);return r==="书"||r==="诗"||r==="考证"||r==="注释"||r==="类"||(r==="序"||r==="结语")&&!!n.content||r==="page_header"&&xr(n)})}function zl({juan:t,rawText:n,positionLabel:r,groupLabel:o,index:s,searchQuery:l,onNavigate:a,transport:p,workLabelCache:c,prefs:d,view:u,onViewChange:h}){var xe;const{convert:x}=G(),f=At(),[b,w]=m.useState("text"),y=u??b,j=L=>{w(L),h==null||h(L)},g=l.trim(),v=(s==null?void 0:s.type)==="kaozhen",$=m.useCallback(L=>g?bn(L,g,f):L,[g,f]),k=L=>lr(L,{renderText:$,properNames:d.properNames}),_=m.useMemo(()=>g?t.sections.filter(L=>dr(L,g,v,f)):t.sections,[t.sections,g,v,f]),S=(L,te)=>te.filter(N=>nt(N.type)===L).length,z=S("书",t.sections),A=S("诗",t.sections),E=S("考证",t.sections);let T="";v?T=g?`${S("考证",_)} / ${E} ${x("條")}`:`${E} ${x("條")}`:A>0?T=g?`${S("诗",_)} / ${A} 首`:`${A} 首`:z>0&&(T=g?`${S("书",_)} / ${z} ${x("部書")}`:`${z} ${x("部書")}`);const H=s!=null&&s.text_quality?Zp(s.text_quality.grade):null,B=[];T&&B.push(T),v&&(s!=null&&s.target_source)&&B.push(e.jsxs(e.Fragment,{children:[x("考證對象")," ",x(s.target_source)]})),H&&B.push(e.jsx("span",{title:Qa[H],children:(xe=s==null?void 0:s.text_quality)!=null&&xe.source_note?e.jsxs(e.Fragment,{children:["底本 ",x(s.text_quality.source_note),e.jsx("span",{className:"bim-rd-grade",children:x(xi[H])})]}):e.jsxs(e.Fragment,{children:[x("文本質量"),e.jsx("span",{className:"bim-rd-grade",children:x(xi[H])})]})})),t.source_url&&B.push(e.jsx("a",{className:"bim-rd-link",href:t.source_url,target:"_blank",rel:"noopener noreferrer",children:x("原文來源")}));const O=!v&&hr(t.sections),D=!!n&&(!O||d.readingMode==="paragraph"&&Lt(n)),ne=!v&&(O||!!n),V=v||!ne?"entries":y;let C=0;return e.jsxs(e.Fragment,{children:[e.jsxs("header",{children:[(r||o)&&e.jsxs("p",{className:"bim-rd-kicker",children:[r,r&&o&&e.jsx("span",{className:"bim-rd-dot"}),o&&x(o)]}),e.jsx("h1",{className:"bim-rd-h1",children:x(t.title)}),B.length>0&&e.jsx("p",{className:"bim-rd-meta",children:B.map((L,te)=>e.jsxs(m.Fragment,{children:[te>0&&e.jsx("span",{className:"bim-rd-dot"}),L]},te))}),ne&&t.sections.length>0&&e.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":"看法",children:[e.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":V==="text",onClick:()=>j("text"),children:"正文"}),e.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":V==="entries",onClick:()=>j("entries"),children:x("條目")})]})]}),V==="text"&&e.jsx("article",{className:"bim-rd-prose",children:D?e.jsx(Yn,{text:n,mode:d.readingMode,properNames:d.properNames,renderText:$,dropTitle:t.title}):e.jsx(yu,{sections:t.sections,onNavigate:a,inline:k,workLinks:d.workLinks})}),V==="entries"&&e.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:v?e.jsx(gu,{juan:t,searchQuery:l,onNavigate:a,transport:p,workLabelCache:c}):e.jsxs(e.Fragment,{children:[_.some(L=>["书","诗","考证"].includes(nt(L.type)))&&e.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[e.jsx("span",{style:{width:28},children:"序"}),e.jsx("span",{style:{flex:1},children:"书名"}),e.jsx("span",{children:"作品"})]}),_.map((L,te)=>{const N=nt(L.type);return N==="书"||N==="诗"||N==="考证"?(C+=1,e.jsx(pu,{domId:`rd-e-${t.sections.indexOf(L)}`,section:L,onNavigate:d.workLinks?a:void 0,highlightQuery:g,no:C,showUnlinked:d.workLinks&&!!a},te)):N==="类"?e.jsx(uu,{section:L,highlightQuery:g},te):e.jsx(xu,{section:L,highlightQuery:g},te)}),_.length===0&&e.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function Cl(t){return t.juan_files&&t.juan_files.length>0?t.juan_files:t.files&&t.files.length>0?t.files.map(n=>n.filename):[]}function ju(t){const n=Cl(t);return n.length>0?n[0]:null}function Tl(t){const{resetKey:n,load:r,files:o,activeFile:s,activeJuan:l,activeRawText:a,query:p,isKaozhen:c}=t,d=At(),u=m.useRef(new Map),[h,x]=m.useState({}),[f,b]=m.useState({}),w=m.useCallback((j,g)=>{const v=g==null?void 0:g.title;v&&b($=>$[j]===v?$:{...$,[j]:v})},[]);m.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:a}),w(s,l))},[s,l,a,w]),m.useEffect(()=>{u.current.clear(),x({}),b({})},[n]);const y=m.useCallback((j,g)=>{let v=0;if(j.juan)for(const $ of j.juan.sections)dr($,g,c,d)&&v++;return v===0&&j.rawText&&su(j.rawText,g,d)&&(v=1),v},[c,d]);return m.useEffect(()=>{const j=p.trim();if(!j){x({});return}if(!r||o.length===0)return;let g=!1;const v={},$=[];for(const A of o){const E=u.current.get(A);E?v[A]=y(E,j):(v[A]="loading",$.push(A))}x(v);const k=8;let _=0;const S=async()=>{for(;_<$.length;){if(g)return;const A=_++,E=$[A];try{const T=await r(E),H=T.juan;if(u.current.set(E,T),w(E,H),g)return;x(B=>({...B,[E]:y(T,j)}))}catch{if(g)return;x(T=>({...T,[E]:0}))}}},z=Array.from({length:Math.min(k,$.length)},()=>S());return Promise.all(z),()=>{g=!0}},[p,n,r,o.join(","),y,d,w]),{matchStates:h,titles:f}}function Il({juan:t,view:n,onView:r,textHasEntries:o}){const{convert:s}=G(),l=t.sections.map((d,u)=>({s:d,i:u,t:nt(d.type)})).filter(d=>d.t==="书"||d.t==="诗");if(l.length===0)return null;const a=l.filter(d=>!!d.s.work_id).length,p=l.every(d=>d.t==="诗")?"首":"部书",c=d=>{const u=()=>{var h,x;return(x=(h=document.getElementById(`rd-e-${d}`))==null?void 0:h.scrollIntoView)==null?void 0:x.call(h,{block:"start",behavior:"smooth"})};n==="text"&&!o&&r("entries"),n==="text"&&!o?setTimeout(u,0):u()};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bim-rd-rail-card",children:[e.jsx("div",{className:"bim-rd-rail-cap",children:"本卷"}),e.jsxs("div",{className:"bim-rd-rail-n",children:[e.jsx("b",{children:l.length}),e.jsx("span",{children:s(p)}),e.jsxs("span",{className:"bim-rd-rail-linked",children:["已关联 ",a]})]}),e.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":`已关联 ${a} / ${l.length}`,children:e.jsx("span",{style:{width:`${Math.round(a/l.length*100)}%`}})})]}),e.jsxs("nav",{"aria-label":"本卷条目",children:[e.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:s("條目")}),e.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:d,i:u})=>e.jsx("li",{children:e.jsxs("a",{href:`#rd-e-${u}`,onClick:h=>{h.preventDefault(),c(u)},children:[e.jsx("span",{className:`bim-rd-rail-dot${d.work_id?" on":""}`,"aria-hidden":"true"}),e.jsx("span",{children:s(d.book_title||d.title)})]})},u))})]})]})}function vu(t,n){const[r,o]=m.useState([]);return m.useEffect(()=>{if(o([]),!t||typeof(n==null?void 0:n.getItem)!="function")return;let s=!1;return Promise.resolve(n.getItem(t)).then(l=>{if(s||!l)return;const a=l.authors??[];o(a.filter(p=>p&&p.name))}).catch(()=>{}),()=>{s=!0}},[t,n]),r}const fr=({index:t,workId:n,transport:r,onNavigate:o,activeJuan:s,onJuanChange:l,className:a,style:p,title:c,subtitle:d,resolveImages:u,renderImageOverlay:h,imagePanel:x,allowVertical:f,onReportError:b,revisedAt:w})=>{const[y,j]=m.useState(null),[g,v]=m.useState(!1),[$,k]=m.useState(null),[_,S]=m.useState(null),[z,A]=m.useState(null),[E,T]=m.useState(!1),[H,B]=m.useState(null),[O,D]=m.useState(""),ne=m.useRef(new Map),V=m.useRef(0),C=s??_,xe=m.useCallback(X=>{S(X),l==null||l(X)},[l]),L=t||y;m.useEffect(()=>{t&&(v(!1),k(null))},[t]),m.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollatedEditionIndex))return;let X=!1;return v(!0),k(null),r.getCollatedEditionIndex(n).then(ae=>{X||(ae?j(ae):k("未找到整理本数据"))}).catch(ae=>{X||k(ae instanceof Error?ae.message:"加载失败")}).finally(()=>{X||v(!1)}),()=>{X=!0}},[t,n,r]),m.useEffect(()=>{if(L&&!C){const X=ju(L);X&&xe(X)}},[L,C,xe]);const te=n||(L==null?void 0:L.work_id),N=m.useCallback(async X=>{var de;if(!te||!(r!=null&&r.getCollatedJuan))return;const ae=++V.current;T(!0),A(null),B(null);try{const[me,$e]=await Promise.all([r.getCollatedJuan(te,X),((de=r.getCollatedJuanText)==null?void 0:de.call(r,te,X))??Promise.resolve(null)]);if(ae!==V.current)return;A(me),B($e)}catch{if(ae!==V.current)return;A(null),B(null)}finally{ae===V.current&&T(!1)}},[te,r]);m.useEffect(()=>{C&&N(C)},[C,N]);const Z=X=>{xe(X)};if(g)return e.jsx("div",{className:a,style:{...p,padding:"24px"},children:e.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if($)return e.jsx("div",{className:a,style:{...p,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:$});if(!L)return null;const ce=L.type==="kaozhen",W=Cl(L);return e.jsx(Su,{className:a,style:p,index:L,allFiles:W,isKaozhen:ce,effectiveWorkId:te,transport:r,activeFile:C,handleSelectFile:Z,juanData:z,juanRawText:H,juanLoading:E,searchQuery:O,setSearchQuery:D,onNavigate:o,workLabelCacheRef:ne,reader:{title:c,subtitle:d,resolveImages:u,renderImageOverlay:h,imagePanel:x,allowVertical:f,onReportError:b,revisedAt:w}})};function zi(t,n,r,o){var d,u,h,x;const s=(u=(d=n.juan_metadata)==null?void 0:d[t])==null?void 0:u.vol_label,l=o(s?`${s}冊`:au(t)),p=((x=(h=n.files)==null?void 0:h.find(f=>f.filename===t))==null?void 0:x.title)??r[t];if(!p)return{position:l,label:l};const c=o(p);return{position:l,label:l===p||l===c?c:`${l} ${c}`}}function ku(t,n){if(!n)return;const r=o=>{var s;for(const l of o??[]){const a=r(l.children);if(a)return a;if((s=l.files)!=null&&s.includes(n))return l.label}};return r(t==null?void 0:t.juan_groups)}function wu(t,n,r,o,s){const l=c=>c==="loading"?"…":typeof c=="number"&&c>0?c:void 0,a=(c,d)=>({key:c,label:d??zi(c,t,o,s).label,hint:l(r[c]),disabled:r[c]===0}),p=(c,d)=>{var h;if(c.files.length===1&&!((h=c.children)!=null&&h.length))return a(c.files[0],s(c.label));const u=_l(c,r);return{key:`group:${d}`,label:s(c.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:ur(c),defaultExpanded:typeof u=="number"&&u>0,children:[...c.files.map(x=>a(x)),...(c.children??[]).map((x,f)=>p(x,`${d}.${f}`))]}};return t.juan_groups&&t.juan_groups.length>0?t.juan_groups.map((c,d)=>p(c,`${d}`)):n.map(c=>a(c))}const Su=({className:t,style:n,index:r,allFiles:o,isKaozhen:s,effectiveWorkId:l,transport:a,activeFile:p,handleSelectFile:c,juanData:d,juanRawText:u,juanLoading:h,searchQuery:x,setSearchQuery:f,onNavigate:b,workLabelCacheRef:w,reader:y})=>{const{convert:j}=G(),[g,v]=Gn(),[$,k]=m.useState("text");m.useEffect(()=>{k("text")},[p]);const _=m.useMemo(()=>l&&(a!=null&&a.getCollatedJuan)?async N=>{var W;const[Z,ce]=await Promise.all([a.getCollatedJuan(l,N),((W=a.getCollatedJuanText)==null?void 0:W.call(a,l,N))??Promise.resolve(null)]);return{juan:Z,rawText:ce}}:null,[l,a]),{matchStates:S,titles:z}=Tl({resetKey:l,load:_,files:o,activeFile:p,activeJuan:d,activeRawText:u,query:x,isKaozhen:s}),A=ar(y.resolveImages,p),E=m.useMemo(()=>wu(r,o,S,z,j),[r,o,S,z,j]),T=e.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:N=>f(N.target.value)}),H=s?"章":r.juan_metadata&&Object.values(r.juan_metadata).some(N=>N.vol_label)?"冊":"卷",B=p?zi(p,r,z,j).position:void 0,O=Pe(),D=y.title??(r.title?j(r.title):void 0),ne=D&&l&&b?e.jsx("a",{href:O(l),onClick:N=>{N.metaKey||N.ctrlKey||(N.preventDefault(),b(l))},title:"查看作品",children:D}):D,V=!!d&&!s&&hr(d.sections),C=V&&!(u&&g.readingMode==="paragraph"&&Lt(u)),xe=d&&!s&&V?e.jsx(Il,{juan:d,view:$,onView:k,textHasEntries:C}):void 0,L=vu(l,a),te=L.length>0?j(L.slice(0,2).map(N=>`${N.dynasty?`〔${N.dynasty}〕`:""}${N.name}${N.role?` ${N.role}`:" 撰"}`).join("、")):void 0;return e.jsxs(Vn,{className:t,style:n,title:ne,subtitle:y.subtitle??j(s?"考證":"整理本"),byline:te,pagerUnit:H,rail:xe,revisedAt:y.revisedAt,onReportError:y.onReportError?N=>y.onReportError({...N,bookTitle:r.title??(typeof y.title=="string"?y.title:void 0),entryId:l}):void 0,current:p?zi(p,r,z,j).label:void 0,workLinkToggle:!s&&!!b&&!!(d!=null&&d.sections.some(N=>N.work_id)),toc:E,tocCaption:`目录 · ${o.length} ${j(H)}`,tocHeader:T,activeKey:p,onSelect:c,images:A.images,imagesLoading:A.loading,renderImageOverlay:y.renderImageOverlay,imagePanel:y.imagePanel,prefs:g,onPrefsChange:v,paragraphToggle:!s&&Lt(u),allowVertical:y.allowVertical,children:[h?e.jsx(St,{}):d?e.jsx(zl,{juan:d,rawText:u,positionLabel:B,groupLabel:ku(r,p),index:r,searchQuery:x,onNavigate:b,transport:a,workLabelCache:w,prefs:g,view:$,onViewChange:k},p??""):p?e.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,r.references&&r.references.length>0&&e.jsxs("section",{className:"bim-rd-refs",children:[e.jsx("h2",{children:j("參考文獻")}),e.jsx("ol",{children:r.references.map((N,Z)=>e.jsxs("li",{children:[N.url?e.jsx("a",{className:"bim-rd-link",href:N.url,target:"_blank",rel:"noopener noreferrer",children:N.title}):e.jsx("span",{children:N.title}),N.author&&e.jsxs("span",{children:[",",N.author]}),N.note&&e.jsxs("span",{children:["。",N.note]})]},Z))})]})]})},$u={bug:{label:"错误反馈",color:i("danger")},resource:{label:"资源建议",color:i("primary")},suggestion:{label:"功能建议",color:i("primary")},other:{label:"其他",color:i("desc-fg")}},_u={label:"其他",color:i("desc-fg")},zu={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")}},Cu={label:"待处理",color:i("warning")};function Tu(t){try{const n=new Date(t),r=o=>String(o).padStart(2,"0");return`${n.getFullYear()}-${r(n.getMonth()+1)}-${r(n.getDate())} ${r(n.getHours())}:${r(n.getMinutes())}`}catch{return t}}function Iu(t,n){if(!t)return!1;try{const r=new URL(t,n);if(r.protocol!=="http:"&&r.protocol!=="https:")return!1;const o=new URL(n);return r.hostname===o.hostname}catch{return!1}}const gr=({items:t,loading:n})=>{const r=Pe();return n?e.jsx(St,{}):t.length===0?e.jsx("div",{style:Eu,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const s=$u[o.type]||_u,l=zu[o.status]||Cu,a=typeof window<"u"&&Iu(o.pageUrl,window.location.href);return e.jsxs("div",{style:Nu,children:[e.jsxs("div",{style:Ru,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...ko,background:s.color},children:s.label}),e.jsx("span",{style:{...ko,background:l.color},children:l.label})]}),e.jsx("span",{style:Lu,children:Tu(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:Au,children:[o.resourceId&&e.jsx("a",{href:r(o.resourceId),style:si,children:o.resourceId}),o.pageUrl&&!o.resourceId&&(a?e.jsx("a",{href:o.pageUrl,style:si,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):e.jsx("span",{style:si,children:o.pageUrl}))]}),e.jsx("div",{style:Bu,children:o.content}),o.reply&&e.jsxs("div",{style:Mu,children:[e.jsx("div",{style:Wu,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})})},Eu={textAlign:"center",padding:"40px 0",color:i("desc-fg"),fontSize:"14px"},Nu={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"16px"},Ru={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},ko={fontSize:"12px",color:i("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Lu={fontSize:"12px",color:i("desc-fg")},Au={fontSize:"12px",marginBottom:"6px"},si={color:i("primary"),textDecoration:"none",borderBottom:`1px dashed ${i("primary")}`},Bu={fontSize:"14px",lineHeight:"1.6",color:i("fg"),whiteSpace:"pre-wrap"},Mu={marginTop:"12px",padding:"10px 12px",background:i("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:i("fg")},Wu={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:i("primary")},Ci=({transport:t,onNavigate:n,recommendedIds:r,activeTab:o,onTabChange:s,feedbackApiUrl:l})=>{const a=ge(),[p,c]=m.useState(null),[d,u]=m.useState([]),[h,x]=m.useState("recommend"),[f,b]=m.useState([]),[w,y]=m.useState(!1),j=o??h,g=D=>{x(D),s==null||s(D)},[v,$]=m.useState(!0),[k,_]=m.useState(null),[S,z]=m.useState(null),[A,E]=m.useState(null);m.useEffect(()=>{let D=!1;if(t.getCounts)return t.getCounts().then(ne=>{D||c({works:ne.works,books:ne.books,collections:ne.collections})}).catch(()=>{}),()=>{D=!0}},[t]),m.useEffect(()=>{let D=!1;return(async()=>{if(r)return r;if(t.getRecommended)try{const V=await t.getRecommended();if(V!=null&&V.groups)return V.groups.flatMap(C=>C.items.map(xe=>({...xe,group:C.name})))}catch{}return[]})().then(async V=>{if(D)return;const C=V.filter(L=>L.id);if(C.length===0){$(!1);return}const xe=await Promise.all(C.map(async L=>{if(L.type)return{id:L.id,title:L.title,type:L.type,author:L.author,dynasty:L.dynasty,role:L.role,edition:L.edition,has_text:L.has_text,has_image:L.has_image,has_collated:L.has_collated,subtype:L.subtype,primary_name:L.primary_name,group:L.group,fallbackDescription:L.description};try{let te=null;if(t.getEntry)te=await t.getEntry(L.id);else{const N=await t.getItem(L.id);N&&(te={id:L.id,title:N.title||L.id,type:N.type||"work"})}if(te)return{...te,group:L.group,fallbackDescription:L.description}}catch{}return{id:L.id,title:L.title,type:ye.extractType(L.id),group:L.group,fallbackDescription:L.description}}));D||(u(xe.filter(L=>L!==null)),$(!1))}),()=>{D=!0}},[t,r]);const T=m.useRef(!1),H=m.useRef(!1),B=m.useRef(!1);m.useEffect(()=>{if(j!=="catalog"||T.current)return;const D=t.getCatalogProgress??t.getResourceProgress;if(!D)return;T.current=!0;let ne=!1;return D.call(t).then(V=>{ne||_(V)}).catch(()=>{T.current=!1}),()=>{ne=!0}},[t,j]),m.useEffect(()=>{if(j!=="collection"||H.current||!t.getCollectionProgress)return;H.current=!0;let D=!1;return t.getCollectionProgress().then(ne=>{D||z(ne)}).catch(()=>{H.current=!1}),()=>{D=!0}},[t,j]),m.useEffect(()=>{if(j!=="site"||B.current||!t.getSiteProgress)return;B.current=!0;let D=!1;return t.getSiteProgress().then(ne=>{D||E(ne)}).catch(()=>{B.current=!1}),()=>{D=!0}},[t,j]),m.useEffect(()=>{if(!l||j!=="feedback")return;let D=!1;return y(!0),fetch(l).then(ne=>ne.json()).then(ne=>{!D&&ne.success&&b(ne.items||[])}).catch(()=>{}).finally(()=>{D||y(!1)}),()=>{D=!0}},[l,j]);const O=D=>e.jsx(Kt,{type:D,size:12});return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:i("fg")},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"16px"},children:[e.jsx(nn,{label:a.home.recommendTab,active:j==="recommend",onClick:()=>g("recommend")}),e.jsx(nn,{label:a.home.catalogTab,active:j==="catalog",onClick:()=>g("catalog")}),e.jsx(nn,{label:a.home.collectionTab,active:j==="collection",onClick:()=>g("collection")}),e.jsx(nn,{label:a.home.siteTab,active:j==="site",onClick:()=>g("site")}),l&&e.jsx(nn,{label:a.home.feedbackTab,active:j==="feedback",onClick:()=>g("feedback")})]}),j==="recommend"&&e.jsx(Fu,{recommended:d,loading:v,onNavigate:n,getIcon:O,t:a}),j==="catalog"&&e.jsx(wo,{progress:k,t:a,onNavigate:n}),j==="collection"&&e.jsx(wo,{progress:S,t:a,onNavigate:n}),j==="site"&&e.jsx(Pu,{progress:A,t:a,totalWorks:(p==null?void 0:p.works)??0}),j==="feedback"&&l&&e.jsx(gr,{items:f,loading:w})]})})},nn=({label:t,active:n,onClick:r})=>e.jsx("button",{onClick:r,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:t}),Fu=({recommended:t,loading:n,onNavigate:r,getIcon:o,t:s})=>{const l=Pe();if(n)return e.jsx(St,{});if(t.length===0)return null;const a=new Map;for(const p of t){const c=p.group||s.home.recommendedBrowse;a.has(c)||a.set(c,[]),a.get(c).push(p)}return e.jsx(e.Fragment,{children:Array.from(a.entries()).map(([p,c])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:p}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:l(d.id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),r==null||r(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:[e.jsx("span",{style:{fontSize:"20px"},children:o(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:d.edition})]}),u&&e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},p))})},wo=({progress:t,t:n,onNavigate:r})=>{if(!t)return e.jsx(St,{});const o=[...t.resources].sort((p,c)=>p.priority-c.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},a={in_progress:i("progress-active"),done:i("progress-done"),todo:i("progress-todo")};return e.jsx("div",{children:s.map(p=>{const c=o.filter(d=>d.status===p);return c.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:a[p]}}),l[p]," (",c.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(d=>e.jsx(Ou,{item:d,t:n,statusColor:a[p],onNavigate:r},d.id))})]},p)})})},Ou=({item:t,t:n,statusColor:r,onNavigate:o})=>{const s=Pe(),l=t.total>0?Math.round(t.imported/t.total*100):0,a=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=t.edition?`${t.name}·${t.edition}`:t.name,c=t.collection_id||t.work_id;return c&&o?e.jsx("a",{href:s(c),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),o(c))},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}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:i("widget-border"),color:i("desc-fg"),whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:a})]}),e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?rt(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:r,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:t.description})]})},Pu=({progress:t,t:n,totalWorks:r})=>{if(!t)return e.jsx(St,{});const o=[...t.resources].sort((c,d)=>c.priority-d.priority),s=o.filter(c=>c.imported>0),l=o.filter(c=>c.imported===0),a=s.reduce((c,d)=>Math.max(c,d.imported),0),p=r>0?Math.round(a/r*100):0;return e.jsxs("div",{children:[r>0&&e.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,": ",e.jsx("strong",{children:a.toLocaleString()})," / ",r.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>e.jsx(So,{item:c,t:n,totalWorks:r},c.id))})]}),l.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(c=>e.jsx(So,{item:c,t:n,totalWorks:r},c.id))})]})]})},So=({item:t,t:n,totalWorks:r})=>{const o=r>0?Math.round(t.imported/r*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${o}%)`:n.home.statusTodo})]}),t.imported>0&&r>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:i("progress-done"),transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:t.description})]})},$o="(max-width: 768px)";function Du(){const[t,n]=m.useState(()=>typeof window>"u"?!1:window.matchMedia($o).matches);return m.useEffect(()=>{const r=window.matchMedia($o),o=s=>n(s.matches);return r.addEventListener("change",o),()=>r.removeEventListener("change",o)},[]),t}const Hu=({transport:t,hideModeIndicator:n=!0,onEntryClick:r,recommendedIds:o,headerRight:s})=>{var ne;const l=ge(),{convert:a}=G(),p=Du(),[c,d]=m.useState(null),[u,h]=m.useState(null),[x,f]=m.useState(!1),[b,w]=m.useState("detail"),[y,j]=m.useState([]),[g,v]=m.useState(!1),[$,k]=m.useState(null),[_,S]=m.useState(!1),z=m.useCallback(async V=>{if(!t.getCollatedEditionIndex){k(null);return}S(!0);try{const C=await t.getCollatedEditionIndex(V);k(C)}catch{k(null)}finally{S(!1)}},[t]),A=m.useCallback(async V=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){j([]);return}v(!0);try{if(t.getCollectionCatalogs){const C=await t.getCollectionCatalogs(V);j(C||[])}else if(t.getCollectionCatalog){const C=await t.getCollectionCatalog(V);j(C?[{resource_id:"",data:C}]:[])}}catch{j([])}finally{v(!1)}},[t]),E=m.useCallback(async V=>{if(r){r(V);return}d(V),h(null),j([]),k(null),w("detail"),f(!0);try{const C=await t.getItem(V.id);C&&(h(C),C.type==="collection"?A(V.id):C.type==="work"&&C.has_collated&&z(V.id))}catch(C){console.error("加载详情失败:",C)}finally{f(!1)}},[t,r,A,z]),T=m.useCallback(async V=>{h(null),j([]),k(null),w("detail"),f(!0);try{const C=await t.getItem(V);C&&(h(C),d({id:V,title:C.title||V,type:C.type||"book"}),C.type==="collection"?A(V):C.type==="work"&&C.has_collated&&z(V))}catch(C){console.error("导航失败:",C)}finally{f(!1)}},[t,A,z]),H=(u==null?void 0:u.type)==="collection"&&(y.length>0||g)||(u==null?void 0:u.type)==="work"&&($||_),B=p&&(x||u),O=m.useCallback(()=>{d(null),h(null),j([]),k(null),w("detail")},[]),D=e.jsx(e.Fragment,{children:x?e.jsx(St,{}):u?e.jsxs(e.Fragment,{children:[(H||s)&&e.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&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>w("detail"),style:wn(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&g&&y.length===0&&e.jsxs("button",{onClick:()=>{},style:wn(!1),children:[l.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&y.map(V=>e.jsx("button",{onClick:()=>w(`catalog:${V.resource_id}`),style:wn(b===`catalog:${V.resource_id}`),children:V.short_name?`${a(V.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},V.resource_id)),u.type==="work"&&($||_)&&e.jsxs("button",{onClick:()=>w("collated"),style:wn(b==="collated"),children:[l.detailTab.collatedEdition,_&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(Gi,{data:u,transport:t,onNavigate:T}):b.startsWith("catalog:")?e.jsx(Vi,{data:(ne=y.find(V=>`catalog:${V.resource_id}`===b))==null?void 0:ne.data,onNavigate:T}):b==="collated"?e.jsx(fr,{index:$||void 0,workId:u.id,transport:t,onNavigate:T}):null})]}):e.jsx(Ci,{transport:t,onNavigate:T,recommendedIds:o})});return p?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:B?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${i("widget-border")}`,background:i("input-bg"),flexShrink:0},children:e.jsxs("button",{onClick:O,style:{padding:"4px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:D})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(fi,{transport:t,onEntryClick:E,hideModeIndicator:n}),!u&&e.jsx(Ci,{transport:t,onNavigate:T,recommendedIds:o})]})}):e.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:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${i("widget-border")}`,display:"flex",flexDirection:"column",background:i("input-bg"),overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(fi,{transport:t,onEntryClick:E,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:i("bg"),display:"flex",flexDirection:"column"},children:D})]})};function wn(t){return{padding:"10px 16px",border:"none",borderBottom:t?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(t?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function kt(t){return t.replace(/\.md$/,"")}function _o(t){let n="";if(t.source_url)try{const o=new URL(t.source_url).pathname.split("/").filter(Boolean).pop()??"";n=decodeURIComponent(o).replace(/_/g," ")}catch{}return[t.source_name,n||t.version_label].filter(Boolean).join(" · ")||t.key}const zo={padding:24,color:i("desc-fg")},Ti=({index:t,bookId:n,transport:r,activeChapter:o,onChapterChange:s,workKey:l,versions:a,onVersionChange:p,title:c,subtitle:d,resolveImages:u,renderImageOverlay:h,imagePanel:x,allowVertical:f,onReportError:b,revisedAt:w,className:y,style:j})=>{const[g,v]=m.useState(t??null),[$,k]=m.useState(!1),[_,S]=m.useState(null),z=o!==void 0?o:_,A=m.useCallback(W=>{s?s(W):S(W)},[s]),[E,T]=m.useState(null),[H,B]=m.useState(!1);m.useEffect(()=>{t&&v(t)},[t]),m.useEffect(()=>{if(t)return;v(null),k(!1);const W=l!==void 0?r.getWorkFullTextIndex?()=>r.getWorkFullTextIndex(n,l):null:r.getBookFullTextIndex?()=>r.getBookFullTextIndex(n):null;if(!n||!W){k(!0);return}let X=!1;return Promise.resolve().then(W).then(ae=>{X||(ae?v(ae):k(!0))}).catch(()=>{X||k(!0)}),()=>{X=!0}},[n,r,t,l]),m.useEffect(()=>{if(!g||g.chapters.length===0)return;const W=kt(g.chapters[0].file);if(!z){A(W);return}const X=kt(z);g.chapters.some(de=>kt(de.file)===X)||A(W)},[g,z,A]);const O=m.useMemo(()=>{if(!g||!z)return null;const W=kt(z);return g.chapters.find(X=>kt(X.file)===W)??null},[g,z]);m.useEffect(()=>{if(!n||!O)return;const W=l!==void 0?r.getWorkFullTextChapter?ae=>r.getWorkFullTextChapter(n,l,ae):null:r.getBookFullTextChapter?ae=>r.getBookFullTextChapter(n,ae):null;if(!W)return;let X=!1;return B(!0),T(null),Promise.resolve(O.file).then(W).then(ae=>{X||T(ae)}).catch(()=>{X||T(null)}).finally(()=>{X||B(!1)}),()=>{X=!0}},[n,O,r,l]);const D=ar(u,O?kt(O.file):null),[ne,V]=Gn(),{convert:C}=G(),xe=!!(a&&a.length>1&&p),L=m.useMemo(()=>xe?ul(a).map((W,X)=>({...W,label:_o(a[X])})):void 0,[xe,a]),te=xe?e.jsxs("label",{children:["版本:",e.jsx("select",{value:l,onChange:W=>p(W.target.value),children:a.map(W=>e.jsx("option",{value:W.key,children:_o(W)},W.key))})]}):null;if(!g)return e.jsxs("div",{style:zo,children:[te&&e.jsx("div",{style:{marginBottom:12},children:te}),$?"无法加载全文目录":"加载全文目录…"]});if(g.chapters.length===0)return e.jsxs("div",{style:zo,children:[te&&e.jsx("div",{style:{marginBottom:12},children:te}),"全文目录为空"]});const N=g.chapters.map(W=>({key:kt(W.file),label:C(W.title)})),Z=nr(g)||un(g),ce=E?E.replace(/^##\s+[^\n]+\n+/,""):null;return e.jsxs(Vn,{title:c??C(g.version_label),subtitle:d??"全文",toc:N,tocCaption:`目录 · ${g.chapters.length} ${g.chapters.length>1?"卷":"篇"}`,activeKey:z?kt(z):null,onSelect:A,images:D.images,imagesLoading:D.loading,renderImageOverlay:h,imagePanel:x,prefs:ne,onPrefsChange:V,versions:L,currentVersionKey:L?l??null:void 0,onVersionChange:L?p:void 0,versionSource:!1,paragraphToggle:Lt(ce),allowVertical:f,revisedAt:w,onReportError:b?W=>b({...W,bookTitle:c===void 0?C(g.version_label):typeof c=="string"?c:void 0,entryId:n}):void 0,className:y,style:j,children:[O&&e.jsxs("header",{children:[e.jsx("h1",{className:"bim-rd-h1",children:C(O.title)}),e.jsxs("p",{className:"bim-rd-meta",children:["来源 ",e.jsx("a",{className:"bim-rd-link",href:g.source.url,target:"_blank",rel:"noreferrer",children:C(g.source.name)}),g.source.license&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bim-rd-dot"}),g.source.license]})]})]}),H&&e.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!H&&ce!=null&&e.jsx("article",{className:"bim-rd-prose",children:e.jsx(Yn,{text:ce,mode:ne.readingMode,tables:Z,gujiMarkdown:un(g),properNames:ne.properNames})}),!H&&!E&&e.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},li=t=>t?t.catch(()=>null):Promise.resolve(null);function El(t){const n=new Map;function r(o){var l;let s=n.get(o);return s||(s=li((l=t.getTextManifest)==null?void 0:l.call(t,o)).then(a=>{const p=a&&Array.isArray(a.versions)&&a.versions.length>0?a:null;return p||n.delete(o),p}),n.set(o,s)),s}return{getManifest(o){return ye.isSafeSegment(o)?r(o):Promise.resolve(null)},async getIndex(o,s){return!ye.isSafeSegment(o)||!ye.isSafeSegment(s)||!t.getTextIndex?null:li(t.getTextIndex(o,s))},async getChapter(o,s,l,a){return!ye.isSafeSegment(o)||!ye.isSafeSegment(s)||!ye.isSafeSegment(l)||!t.getChapter?null:li(t.getChapter(o,s,l,a))}}}const Sn={padding:24,color:i("desc-fg"),fontSize:14},Co=/^https?:\/\//i;function Gu(t){if(!t||typeof t!="object")return null;const n=l=>typeof l=="string"&&l.trim()?l.trim():void 0,r=n(t.url),o=n(t.license_url),s={name:n(t.name),url:r&&Co.test(r)?r:void 0,license:n(t.license),license_url:o&&Co.test(o)?o:void 0,note:n(t.note)};return s.name||s.license||s.note?s:null}function Vu(t,n){return{work_id:n.work_id??t,title:n.title,type:n.type,juan_files:n.chapters.map(r=>r.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 Uu(t,n){return(n==null?void 0:n.type)==="kaozhen"?"章":n!=null&&n.juan_metadata&&Object.values(n.juan_metadata).some(r=>r.vol_label)?"冊":(t==null?void 0:t.kind)==="collated"?"卷":"章"}function Nl(t,n,r,o=!1){const s=r(`${n}${t.n}`);if(!t.title)return s;const l=r(t.title);return o&&!/^[卷冊册章篇回第]/.test(t.title)?`${s} ${l}`:l}function Yu(t,n,r,o,s){var d;const l=new Map(t.chapters.map(u=>[u.file,u])),a=u=>u==="loading"?"…":typeof u=="number"&&u>0?u:void 0,p=(u,h)=>{const x=l.get(u);return{key:u,label:h??(x?Nl(x,r,o,s):u),hint:a(n[u]),disabled:n[u]===0}},c=(d=t.juan_groups)==null?void 0:d.filter(u=>{var h;return u.files.some(x=>l.has(x))||((h=u.children)==null?void 0:h.length)});if(c&&c.length>0){const u=(h,x)=>{var b;if(h.files.length===1&&!((b=h.children)!=null&&b.length))return p(h.files[0],o(h.label));const f=_l(h,n);return{key:`group:${x}`,label:o(h.label),hint:f==="loading"?"…":typeof f=="number"&&f>0?`${f}`:ur(h),defaultExpanded:typeof f=="number"&&f>0,children:[...h.files.filter(w=>l.has(w)).map(w=>p(w)),...(h.children??[]).map((w,y)=>u(w,`${x}.${y}`))]}};return c.map((h,x)=>u(h,`${x}`))}return t.chapters.map(u=>p(u.file))}const Ku=({id:t,transport:n,versionKey:r,chapter:o,onLocationChange:s,onNavigate:l,title:a,subtitle:p,resolveImages:c,renderImageOverlay:d,imagePanel:u,allowVertical:h,onReportError:x,revisedAt:f,backHref:b,backLabel:w,className:y,style:j})=>{var Ze,Fe,mt;const{convert:g}=G(),v=m.useMemo(()=>El(n),[n]),[$,k]=Gn(),_=Pe(),S=m.useRef(s);S.current=s;const[z,A]=m.useState(null),[E,T]=m.useState("loading");m.useEffect(()=>{let re=!1;return A(null),T("loading"),v.getManifest(t).then(Re=>{re||(Re?(A(Re),T("ready")):T("missing"))}).catch(()=>{re||T("missing")}),()=>{re=!0}},[v,t]);const H=r!==void 0,B=o!==void 0,[O,D]=m.useState(null),[ne,V]=m.useState(null);m.useEffect(()=>{D(null),V(null)},[t]);const C=ye.pickTextVersion(z,H?r:O),xe=((Ze=z==null?void 0:z.versions.find(re=>re.key==="default"))==null?void 0:Ze.key)??((Fe=z==null?void 0:z.versions[0])==null?void 0:Fe.key)??"default",L=(C==null?void 0:C.key)??null,te=B?o:ne,N=m.useCallback((re,Re,et)=>{var _t;(_t=S.current)==null||_t.call(S,{key:re,chapter:Re,isDefault:re===xe},et)},[xe]);m.useEffect(()=>{!z||!H||r==null||z.versions.some(re=>re.key===r)||N(xe,null,"auto")},[z,H,r,xe,N]);const Z=m.useRef(new Map);m.useEffect(()=>{Z.current.clear()},[v,t]);const ce=m.useCallback(async re=>{const Re=`${t}
|
|
1067
|
+
${re}`;if(Z.current.has(Re))return Z.current.get(Re)??null;const et=await v.getIndex(t,re).catch(()=>null);return et&&Z.current.set(Re,et),et},[v,t]),[W,X]=m.useState(null),[ae,de]=m.useState("loading");m.useEffect(()=>{if(!L)return;let re=!1;return X(null),de("loading"),ce(L).then(Re=>{re||(Re&&Re.chapters.length>0?(X(Re),de("ready")):de("failed"))}),()=>{re=!0}},[L,ce]),m.useEffect(()=>{if(!W||!L||te!=null&&W.chapters.some(et=>et.file===te))return;const Re=W.chapters[0].file;B||V(Re),N(L,Re,"auto")},[W,L,te,B,N]);const me=W?te!=null&&W.chapters.some(re=>re.file===te)?te:W.chapters[0].file:te,$e=m.useMemo(()=>W&&me?W.chapters.find(re=>re.file===me)??null:null,[W,me]),Me=m.useRef(0),Ee=m.useCallback(async re=>{if(!z||re===L||!z.versions.some(q=>q.key===re))return;const Re=++Me.current,et=await ce(re);if(Re!==Me.current)return;const _t=$e??(me?{file:me}:null),Jt=ye.matchChapterAcrossVersions(_t,et);H||D(re),B||V(Jt),N(re,Jt,"version")},[z,L,ce,$e,me,H,B,N]),Le=m.useCallback(re=>{L&&(B||V(re),N(L,re,"chapter"))},[L,B,N]),[ze,Ae]=m.useState(null),[P,he]=m.useState(!1),ie=m.useRef(0);m.useEffect(()=>{if(!L||!$e)return;const re=++ie.current;he(!0),Ae(null),v.getChapter(t,L,$e.file,{json:!!$e.has_json}).then(Re=>{re===ie.current&&Ae(Re)}).catch(()=>{re===ie.current&&Ae(null)}).finally(()=>{re===ie.current&&he(!1)})},[v,t,L,$e]);const ke=(C==null?void 0:C.kind)==="collated",[we,Y]=m.useState("");m.useEffect(()=>{Y("")},[t,L]);const R=m.useMemo(()=>L&&ke?async re=>{const Re=await v.getChapter(t,L,re,{json:!0});return{juan:(Re==null?void 0:Re.json)??null,rawText:(Re==null?void 0:Re.md)??null}}:null,[v,t,L,ke]),U=(W==null?void 0:W.type)==="kaozhen",fe=m.useMemo(()=>(W==null?void 0:W.chapters.map(re=>re.file))??[],[W]),{matchStates:be}=Tl({resetKey:`${t}
|
|
1068
|
+
${L??""}`,load:R,files:fe,activeFile:me??null,activeJuan:(ze==null?void 0:ze.json)??null,activeRawText:(ze==null?void 0:ze.md)??null,query:we,isKaozhen:U}),M=m.useRef(new Map);m.useEffect(()=>{M.current.clear()},[t]);const ue=ar(c,me??null),{entryTitle:K,authors:se}=Zu(t,n,a===void 0),[je,Te]=m.useState("text");if(m.useEffect(()=>{Te("text")},[me,L]),E==="loading")return e.jsx("div",{className:y,style:{...j,...Sn},children:"加载中…"});if(E==="missing"||!z||!C)return e.jsx("div",{className:y,style:{...j,...Sn},children:"暂无文本"});if(ae==="failed")return e.jsx("div",{className:y,style:{...j,...Sn},children:"无法加载目录"});if(!W)return e.jsx("div",{className:y,style:{...j,...Sn},children:"加载目录…"});const Ce=Uu(C,W),le=Yu(W,be,Ce,g,ke),_e=z.versions.map(re=>({key:re.key,label:ye.textVersionLabel(re),optionLabel:g(ye.textVersionLabel(re)),sourceName:re.source_name?g(re.source_name):void 0,license:re.license??void 0,sourceUrl:re.source_url??void 0,primary:re.key===xe})),I=Gu((mt=W.source)==null?void 0:mt.upstream),J=a??(W.title?g(W.title):K?g(K):void 0),oe=J?e.jsx("a",{href:_(t),title:"查看条目",onClick:l?re=>{re.metaKey||re.ctrlKey||(re.preventDefault(),l(t))}:void 0,children:J}):void 0,Q=se.length>0?g(se.slice(0,2).map(re=>`${re.dynasty?`〔${re.dynasty}〕`:""}${re.name}${re.role?` ${re.role}`:" 撰"}`).join("、")):void 0,ee=$e?Nl($e,Ce,g,ke):void 0,Se=ke&&!!(ze!=null&&ze.json),F=(ze==null?void 0:ze.json)??null,ve=(ze==null?void 0:ze.md)??null,We=Se&&!U&&hr(F.sections),Ke=We&&!(ve&&$.readingMode==="paragraph"&&Lt(ve)),lt=Se&&We?e.jsx(Il,{juan:F,view:je,onView:Te,textHasEntries:Ke}):void 0,Bt=nr(W)||un(W),jt=ve?ve.replace(/^##\s+[^\n]+\n+/,""):null,Ne=p??(C.source_name?g(C.source_name):g(ye.textVersionLabel(C)));return e.jsxs(Vn,{className:y,style:j,title:oe,subtitle:Ne,byline:Q,current:ee,pagerUnit:Ce,rail:lt,revisedAt:f,backHref:b,backLabel:w,onReportError:x?re=>x({...re,bookTitle:typeof J=="string"?J:void 0,entryId:t}):void 0,workLinkToggle:Se&&!U&&!!l&&!!(F!=null&&F.sections.some(re=>re.work_id)),toc:le,tocCaption:`目录 · ${W.chapters.length} ${g(Ce)}`,tocHeader:ke&&W.chapters.length>1?e.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:U?"搜索全部章节…":`搜索全部${Ce}…`,"aria-label":U?"搜索全部章节":`搜索全部${Ce}`,value:we,onChange:re=>Y(re.target.value)}):void 0,activeKey:me??null,onSelect:Le,images:ue.images,imagesLoading:ue.loading,renderImageOverlay:d,imagePanel:u,prefs:$,onPrefsChange:k,versions:_e.length>1?_e:void 0,currentVersionKey:_e.length>1?C.key:void 0,onVersionChange:Ee,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:Lt(ve),allowVertical:h,children:[P&&e.jsx(St,{}),!P&&Se&&F&&e.jsx(zl,{juan:F,rawText:ve,positionLabel:qu($e,W,Ce,g),groupLabel:Ju(W,me??null),index:Vu(t,W),searchQuery:we,onNavigate:l,transport:n,workLabelCache:M,prefs:$,view:je,onViewChange:Te},`${L}/${me}`),!P&&!Se&&jt!=null&&$e&&e.jsxs(e.Fragment,{children:[e.jsxs("header",{children:[e.jsx("h1",{className:"bim-rd-h1",children:$e.title?g($e.title):ee}),(C.source_name||C.license)&&e.jsxs("p",{className:"bim-rd-meta",children:[C.source_name&&e.jsxs(e.Fragment,{children:["来源 ",C.source_url?e.jsx("a",{className:"bim-rd-link",href:C.source_url,target:"_blank",rel:"noreferrer",children:g(C.source_name)}):g(C.source_name)]}),C.source_name&&C.license&&e.jsx("span",{className:"bim-rd-dot"}),C.license]}),I&&e.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:["上游 ",I.url?e.jsx("a",{className:"bim-rd-link",href:I.url,target:"_blank",rel:"noreferrer",children:g(I.name??I.url)}):g(I.name??""),I.license&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bim-rd-dot"}),I.license_url?e.jsx("a",{className:"bim-rd-link",href:I.license_url,target:"_blank",rel:"noreferrer",children:I.license}):I.license]}),I.note&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bim-rd-dot"}),g(I.note)]})]})]}),e.jsx("article",{className:"bim-rd-prose",children:e.jsx(Yn,{text:jt,mode:$.readingMode,tables:Bt,gujiMarkdown:un(W),properNames:$.properNames})})]}),!P&&!Se&&jt==null&&$e&&e.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"}),W.references&&W.references.length>0&&e.jsxs("section",{className:"bim-rd-refs",children:[e.jsx("h2",{children:g("參考文獻")}),e.jsx("ol",{children:W.references.map((re,Re)=>e.jsxs("li",{children:[re.url?e.jsx("a",{className:"bim-rd-link",href:re.url,target:"_blank",rel:"noopener noreferrer",children:re.title}):e.jsx("span",{children:re.title}),re.author&&e.jsxs("span",{children:[",",re.author]}),re.note&&e.jsxs("span",{children:["。",re.note]})]},Re))})]})]})};function qu(t,n,r,o){var l,a;if(!t)return;const s=(a=(l=n.juan_metadata)==null?void 0:l[t.file])==null?void 0:a.vol_label;return o(s?`${s}冊`:`${r}${t.n}`)}function Ju(t,n){if(!n)return;const r=o=>{var s;for(const l of o??[]){const a=r(l.children);if(a)return a;if((s=l.files)!=null&&s.includes(n))return l.label}};return r(t.juan_groups)}function Zu(t,n,r){const[o,s]=m.useState({entryTitle:void 0,authors:[]});return m.useEffect(()=>{if(s({entryTitle:void 0,authors:[]}),typeof n.getItem!="function")return;let l=!1;return Promise.resolve(n.getItem(t)).then(a=>{if(l||!a)return;const p=(a.authors??[]).filter(c=>c&&c.name);s({entryTitle:r&&typeof a.title=="string"?a.title:void 0,authors:p})}).catch(()=>{}),()=>{l=!0}},[t,n,r]),o}const Xu=({data:t,onNavigate:n,className:r,style:o})=>{var u;const s=ge(),{convert:l}=G(),[a,p]=m.useState(((u=t.divisions[0])==null?void 0:u.name)??null),[c,d]=m.useState(null);return e.jsxs("div",{className:r,style:o,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:l(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg"),display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(h=>e.jsx(Qu,{division:h,expanded:a===h.name,onToggle:()=>p(a===h.name?null:h.name),expandedCat:c,onCatToggle:x=>d(c===x?null:x),onNavigate:n},h.name))})]})},Qu=({division:t,expanded:n,onToggle:r,expandedCat:o,onCatToggle:s,onNavigate:l})=>{const{convert:a}=G(),p=t.categories.reduce((c,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return c+(u.zhulu||0)+(u.cunmu||0)},0);return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:r,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:[e.jsx("span",{children:a(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg")},children:[t.categories.length," 類 · ",p," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(c=>{const d=`${t.name}/${c.name}`;return e.jsx(em,{category:c,expanded:o===d,onToggle:()=>s(d),onNavigate:l},c.name)})})]})},em=({category:t,expanded:n,onToggle:r,onNavigate:o})=>{var c,d,u,h;const{convert:s}=G(),l=((c=t.books)==null?void 0:c.zhulu)||[],a=((d=t.books)==null?void 0:d.cunmu)||[],p=(((u=t.stats)==null?void 0:u.zhulu)||l.length)+(((h=t.stats)==null?void 0:h.cunmu)||a.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:r,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:[e.jsxs("span",{style:{fontWeight:500},children:[s(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||a.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&e.jsx(To,{label:"著錄",books:l,onNavigate:o}),a.length>0&&e.jsx(To,{label:"存目",books:a,onNavigate:o})]})]})},To=({label:t,books:n,onNavigate:r})=>{const{convert:o}=G(),s=Pe(),[l,a]=m.useState(n.length<=20),p=l?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((c,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:i("fg")},children:c.work_id&&r?e.jsx("a",{href:s(c.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),r(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},children:o(c.title)}):o(c.title)}),c.volumes&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:o(c.volumes)}),c.author&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:o(c.author).slice(0,20)})]},d))}),!l&&e.jsxs("button",{onClick:()=>a(!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," 條"]})]})},it=({title:t,onSave:n,onAskAI:r,extraButtons:o,children:s})=>{const l=ge();return e.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:i("fg")},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[o,r&&e.jsx("button",{onClick:r,style:nm,children:"AI"}),n&&e.jsx("button",{onClick:n,style:tm,children:l.action.save})]})]}),s]})},tm={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},nm={padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Xe=({label:t,value:n,onChange:r,placeholder:o,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:l=>r(l.target.value),placeholder:o,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"}})]}),Nt=({value:t,onChange:n,placeholder:r})=>{const o=m.useRef(null);return m.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:o,value:t||"",onChange:s=>n(s.target.value),placeholder:r,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"}})},Nn=({children:t,color:n,style:r})=>e.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"),...r},children:t});function im(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const _n=({value:t,onChange:n,label:r})=>{const[o,s]=m.useState(!1),l=m.useRef(null),a=im(t||"");return m.useEffect(()=>{o&&l.current&&l.current.focus()},[o]),!o&&a?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Io,children:r}),e.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:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:i("fg")},children:a.name}),e.jsx(Nn,{children:a.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Io,children:r}),e.jsx("input",{ref:l,type:"text",value:t||"",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"}})]})},Io={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500};function rm(t){switch(t){case"url":return i("source-url");case"bookID":return i("source-bookid");default:return i("desc-fg")}}function om(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Rl=({items:t,onChange:n,onOpenEntityPicker:r})=>{const o=ge(),[s,l]=m.useState(null),a=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(t.length)},p=h=>{n(t.filter((x,f)=>f!==h)),s===h&&l(null)},c=(h,x,f)=>{const b=[...t];b[h]={...b[h],[x]:f},n(b)},d=(h,x)=>{const f=[...t];f[h]={...f[h],type:x,id:"",name:""},n(f),x==="bookID"&&r&&r(b=>{const w=[...t];w[h]={...w[h],id:b.id,name:b.title,type:"bookID"},n(w)})},u=h=>{r&&r(x=>{const f=[...t];f[h]={...f[h],id:x.id,name:x.title,type:"bookID"},n(f)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((h,x)=>e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===x?null:x),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===x?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:i("fg")},children:h.name||`${o.editor.sourcePlaceholder} ${x+1}`}),h.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:rm(h.type),color:i("on-color-fg"),borderRadius:"3px",fontWeight:500},children:om(h.type)}),e.jsx("button",{onClick:f=>{f.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),s===x&&e.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!h.type&&e.jsxs("div",{children:[e.jsx("label",{style:xt,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(x,"bookID"),style:{...Eo,borderColor:i("source-bookid"),color:i("source-bookid")},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(x,"url"),style:{...Eo,borderColor:i("source-url"),color:i("source-url")},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.enterUrl})]})]})]}),h.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:xt,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const f=[...t];f[x]={...f[x],type:"",id:"",name:""},n(f)},style:No,children:o.action.changeType})]}),h.id&&h.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:i("bg"),border:`1px solid ${i("source-bookid")}`,borderRadius:"6px"},children:[e.jsx("span",{style:{color:i("source-bookid"),fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:h.name}),e.jsx("code",{style:{fontSize:"11px",background:i("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:h.id})]}),e.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:o.action.reselect})]}):e.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:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:o.action.clickToSelectBookOrWork})]})]})}),h.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:xt,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const f=[...t];f[x]={...f[x],type:"",id:"",name:""},n(f)},style:No,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:h.name,onChange:f=>c(x,"name",f.target.value),placeholder:o.editor.sourceNamePlaceholder,style:Mt})]}),e.jsxs("div",{children:[e.jsx("label",{style:xt,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:h.id,onChange:f=>c(x,"id",f.target.value),placeholder:"https://...",style:Mt})]})]}),h.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:`1px dashed ${i("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...xt,opacity:.7},children:o.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:xt,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:h.details,onChange:f=>c(x,"details",f.target.value),placeholder:o.editor.detailsPlaceholder,style:Mt})]}),e.jsxs("div",{children:[e.jsx("label",{style:xt,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:h.position,onChange:f=>c(x,"position",f.target.value),placeholder:"如: 卷三, p.52",style:Mt})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:xt,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:h.version,onChange:f=>c(x,"version",f.target.value),placeholder:"如: v1.0, 2024-01",style:Mt})]}),e.jsxs("div",{children:[e.jsx("label",{style:xt,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:h.processor_version,onChange:f=>c(x,"processor_version",f.target.value),placeholder:"如: v0.1",style:Mt})]})]})]})]})})]},x)),e.jsxs("button",{onClick:a,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:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addSource})]})]})},xt={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},Mt={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"},Eo={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"},No={background:"transparent",border:"none",color:i("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Ll(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(r=>({id:r.id||"",name:r.name||"",type:r.type||"",details:r.details||"",position:r.position||"",version:r.version||"",processor_version:r.processor_version||""}))}catch{}return[]}function Al(t){return!t||t.length===0?"":JSON.stringify(t)}const Bl=({entityType:t,entityId:n,entityTitle:r,parentWork:o,parentCollection:s,belongsToWork:l,belongsToCollection:a,childWorks:p,childCollections:c,containedBooks:d,siblingBooks:u,onLinkEntity:h,onUnlinkEntity:x,onViewEntity:f,onCreateAndLink:b,onSaveRelations:w})=>{const y=ge();return e.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.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:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:y.section.relations})]}),w&&e.jsx("button",{onClick:w,style:sm,children:y.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(rn,{direction:"up",title:y.relation.belongsToWork,entity:l,onView:f,onUnlink:()=>x("workId"),onLink:()=>h("workId","work"),onCreate:()=>b("workId","work",{title:r}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),e.jsx(rn,{direction:"up",title:y.relation.containedInCollection,entity:a,onView:f,onUnlink:()=>x("collectionId"),onLink:()=>h("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:r}),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&&e.jsx(Wt,{direction:"horizontal",title:`${y.relation.siblingVersions} (${u.length})`,entities:u,onView:f,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:y.relation.addVersionForWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(rn,{direction:"up",title:y.relation.parentWork,entity:o,onView:f,onUnlink:()=>x("parentWorkId"),onLink:()=>h("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&&e.jsx(Wt,{direction:"down",title:`${y.relation.childWorks} (${p.length})`,entities:p,onView:f,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:y.action.addSubWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),c&&c.length>0&&e.jsx(Wt,{direction:"down",title:`${y.relation.collectionImpl} (${c.length})`,entities:c,onView:f,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:y.action.addCollectionImpl,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),e.jsx(Wt,{direction:"down",title:`${y.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:f,onAdd:()=>b("childBook","book",{workId:n}),addLabel:y.action.addVersion,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(rn,{direction:"up",title:y.relation.correspondingWork,entity:l,onView:f,onUnlink:()=>x("workId"),onLink:()=>h("workId","work"),onCreate:()=>b("workId","work",{title:r}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),e.jsx(rn,{direction:"up",title:y.relation.parentCollection,entity:s,onView:f,onUnlink:()=>x("parentCollectionId"),onLink:()=>h("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}),e.jsx(Wt,{direction:"down",title:`${y.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:f,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:y.action.addSubCollection,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),e.jsx(Wt,{direction:"down",title:`${y.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:f,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:y.action.addBook,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]})]})]})},rn=({direction:t,title:n,entity:r,onView:o,onUnlink:s,onLink:l,onCreate:a,linkLabel:p,createLabel:c,notLinkedLabel:d,viewLabel:u,unlinkLabel:h})=>{const x=i(t==="up"?"relation-up":t==="down"?"relation-down":"relation-flat"),f=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[e.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:f}),e.jsx("span",{children:n})]}),r?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:i("bg"),borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Ml(r.type)}),e.jsx("span",{style:{fontWeight:500},children:r.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:r.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(Ro,{onClick:()=>o(r),title:u,children:"👁️"}),e.jsx(Ro,{onClick:s,title:h,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(Ii,{onClick:l,children:p}),e.jsx(Ii,{onClick:a,primary:!0,children:c})]})]})},Wt=({direction:t,title:n,entities:r,onView:o,onAdd:s,addLabel:l,noneLabel:a,expandMoreLabel:p})=>{const[c,d]=m.useState(!1),u=i(t==="up"?"relation-up":t==="down"?"relation-down":"relation-flat"),h=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",x=c?r:r.slice(0,5);return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[e.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:h}),e.jsx("span",{children:n})]}),r.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[x.map(f=>e.jsxs("div",{onClick:()=>o(f),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:i("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:Ml(f.type)}),e.jsx("span",{children:f.title})]},f.id)),r.length>5&&!c&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:i("link-fg"),cursor:"pointer"},children:[p," (",r.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:a}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(Ii,{onClick:s,primary:!0,children:["+ ",l]})})]})},Ro=({onClick:t,title:n,danger:r,children:o})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:r?i("danger"):"inherit",opacity:.7},children:o}),Ii=({onClick:t,primary:n,children:r})=>e.jsx("button",{onClick:t,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:r});function Ml(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const sm={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Wl=({isOpen:t,entityType:n,title:r,onSelect:o,onCancel:s,onCreate:l,searchResults:a,onSearch:p,isLoading:c,excludeId:d})=>{const[u,h]=m.useState(""),x=d?a.filter(y=>y.id!==d):a;m.useEffect(()=>{t&&(h(""),p(""))},[t]);const f=y=>{h(y),p(y)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",w=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:lm,children:e.jsxs("div",{style:am,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:r}),e.jsx("button",{onClick:s,style:cm,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:u,onChange:y=>f(y.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:dm})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?e.jsx("div",{style:ai,children:"搜索中..."}):x.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(y=>e.jsxs("div",{onClick:()=>o(y),style:pm,children:[e.jsx("span",{style:{fontSize:"16px"},children:w}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[y.title,y.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:y.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[y.id,y.author&&` · ${y.author}`,y.dynasty&&` · ${y.dynasty}`]})]})]},y.id))}):u?e.jsxs("div",{style:ai,children:["未找到匹配的",b]}):e.jsxs("div",{style:ai,children:["输入关键词搜索",b]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:l,style:um,children:["创建新",b,"并关联"]})]})]})})},lm={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},am={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")},cm={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},dm={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"},pm={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:i("primary-soft")},ai={padding:"20px",textAlign:"center",color:i("desc-fg")},um={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Lo={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},mm={work:"📜",book:"📖",collection:"📚",entity:"👤"},Fl=({isOpen:t,entityType:n,relationField:r,inheritData:o,onConfirm:s,onCancel:l})=>{const[a,p]=m.useState(""),c=m.useRef(null);m.useEffect(()=>{t&&(p((o==null?void 0:o.title)||""),setTimeout(()=>{var x,f;(x=c.current)==null||x.focus(),(f=c.current)==null||f.select()},100))},[t,o==null?void 0:o.title]);const d=x=>{x.key==="Enter"&&a.trim()?u():x.key==="Escape"&&l()},u=()=>{a.trim()&&s(a.trim(),{...o,title:a.trim()})};if(!t)return null;const h=()=>{switch(r){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`创建新${Lo[n]}`}};return e.jsx("div",{style:xm,onClick:x=>{x.target===x.currentTarget&&l()},children:e.jsxs("div",{style:hm,onClick:x=>x.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:mm[n]}),e.jsx("span",{children:h()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:i("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:i("danger"),marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:c,type:"text",value:a,onChange:x=>p(x.target.value),onKeyDown:d,placeholder:`请输入${Lo[n]}名称...`,style:fm})]}),((o==null?void 0:o.author)||(o==null?void 0:o.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),background:i("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(o==null?void 0:o.author)&&e.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:l,style:gm,children:"取消"}),e.jsx("button",{onClick:u,disabled:!a.trim(),style:{...bm,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},xm={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},hm={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")},fm={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"},gm={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},bm={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg")};function ym(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Ol(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function jm(t){switch(t){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 Pl=({isOpen:t,title:n,filterType:r="all",recentEntities:o=[],excludeId:s,showCreateButton:l=!1,createButtonText:a,onSelect:p,onCancel:c,onCreate:d,onSearch:u})=>{const[h,x]=m.useState(""),[f,b]=m.useState([]),[w,y]=m.useState(!1),[j,g]=m.useState("recent");m.useEffect(()=>{t&&(x(""),b([]),g(o.length>0?"recent":"search"))},[t,o.length]),m.useEffect(()=>{if(!h.trim()){b([]);return}const z=setTimeout(async()=>{y(!0);try{b(await u(h,r))}catch{b([])}finally{y(!1)}},300);return()=>clearTimeout(z)},[h,r,u]);const v=m.useCallback(z=>{x(z.target.value),z.target.value.trim()&&g("search")},[]),$=m.useCallback(z=>s?z.filter(A=>A.id!==s):z,[s]);if(!t)return null;const k=n||(r==="all"?"选择实体":`选择${Ol(r)}`),_=$(o),S=$(f);return e.jsx("div",{style:km,children:e.jsxs("div",{style:wm,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:k}),e.jsx("button",{onClick:c,style:Sm,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:h,onChange:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:$m}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),w&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),_.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[e.jsxs(Ao,{active:j==="recent",onClick:()=>g("recent"),children:["最近使用 (",_.length,")"]}),e.jsxs(Ao,{active:j==="search",onClick:()=>g("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&_.length>0?e.jsx(Bo,{entities:_,onSelect:p}):h.trim()?w?e.jsx(ci,{message:"搜索中..."}):S.length>0?e.jsx(Bo,{entities:S,onSelect:p}):e.jsx(ci,{message:"未找到匹配的结果"}):e.jsx(ci,{message:"输入关键词开始搜索"})}),l&&d&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:d,style:_m,children:a||"创建新实体"})]})]})})},Ao=({active:t,onClick:n,children:r})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(t?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:r}),Bo=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(r=>e.jsx(vm,{entity:r,onClick:()=>n(r)},r.id))}),vm=({entity:t,onClick:n})=>{const[r,o]=m.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i("primary-soft"),transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:ym(t.type)}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[t.title,t.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:t.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[e.jsx("code",{style:{fontSize:"10px",background:i("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:t.id}),t.author&&e.jsx("span",{children:t.author}),t.dynasty&&e.jsx("span",{children:t.dynasty})]})]}),e.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:jm(t.type),color:i("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Ol(t.type)})]})},ci=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:t}),km={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},wm={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")},Sm={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},$m={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"},_m={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},zm={work:i("editor-type-work"),collection:i("editor-type-collection"),book:i("editor-type-book"),entity:i("editor-type-entity")},Cm={work:"📜",collection:"📚",book:"📖",entity:"👤"},Dl=({data:t,onChange:n,onSave:r,transport:o,onNavigate:s,showDelete:l,onDelete:a,onAskAI:p,renderSectionActions:c,onDownloadResource:d,downloadStatuses:u,relations:h,onRelationsChange:x})=>{var we;const f=ge(),[b,w]=m.useState(!1),[y,j]=m.useState("work"),[g,v]=m.useState(""),[$,k]=m.useState(""),[_,S]=m.useState([]),[z,A]=m.useState(!1),[E,T]=m.useState(!1),[H,B]=m.useState("work"),[O,D]=m.useState(""),[ne,V]=m.useState(),[C,xe]=m.useState(!1),[L,te]=m.useState(null),[N,Z]=m.useState([]);m.useRef(null);const ce=t.type,W=ce==="work",X=ce==="collection",ae=ce==="book",de=m.useCallback((Y,R)=>{n({...t,[Y]:R})},[t,n]),me=m.useCallback((Y,R)=>{v(Y),j(R),k(f.editor.selectToLink+f.indexType[R]),S([]),w(!0)},[f]),$e=m.useCallback(Y=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,Y)},[o,t.id]),Me=m.useCallback(Y=>{s==null||s(Y.id,Y.type)},[s]),Ee=m.useCallback((Y,R,U)=>{const fe={...U,author:(U==null?void 0:U.author)||t.author,dynasty:U==null?void 0:U.dynasty};B(R),D(Y),V(fe),T(!0)},[t.author]),Le=m.useCallback((Y,R)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,O,{type:H,title:Y,inheritData:R}),T(!1)},[o,t.id,O,H]),ze=m.useCallback(Y=>{if(!Y.trim()){S([]);return}A(!0),o!=null&&o.searchEntities&&o.searchEntities(Y,y).then(R=>{S(R),A(!1)}).catch(()=>{S([]),A(!1)})},[o,y]),Ae=m.useCallback(Y=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,g,Y.id),w(!1)},[o,t.id,g]),P=m.useCallback(()=>{r()},[r]),he=m.useCallback(Y=>{te(()=>Y),xe(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(Z).catch(()=>{})},[o]),ie=m.useCallback((Y,R)=>o!=null&&o.searchEntities?o.searchEntities(Y,R==="all"?void 0:R):Promise.resolve([]),[o]),ke=m.useCallback(Y=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(Y),Z(R=>[Y,...R.filter(U=>U.id!==Y.id)].slice(0,10)),L==null||L(Y),xe(!1),te(null)},[o,L]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${i("widget-border")}`,paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Cm[ce]}),e.jsx("span",{children:t.title||f.editor.untitled}),e.jsx(Nn,{children:t.id}),e.jsx(Nn,{color:zm[ce],children:f.indexType[ce]})]})}),e.jsx(it,{title:f.section.basicInfo,onSave:r,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(_n,{label:W?f.editor.workTitle:X?f.editor.collectionTitle:f.editor.bookTitle,value:t.title,onChange:Y=>de("title",Y)}),ae&&e.jsx(_n,{label:f.editor.belongsToWork,value:t.workName||"",onChange:Y=>de("workName",Y)}),e.jsx(Xe,{label:f.editor.authorLabel,value:t.author||"",onChange:Y=>de("author",Y)}),e.jsx(Xe,{label:f.editor.publicationYearLabel,value:t.publicationYear||"",onChange:Y=>de("publicationYear",Y)}),(ae||X)&&e.jsx(_n,{label:f.editor.containedIn,value:t.collection||"",onChange:Y=>de("collection",Y)}),(ae||X)&&e.jsx(Xe,{label:f.editor.holderLabel,value:t.holder||"",onChange:Y=>de("holder",Y)}),(ae||X)&&e.jsx(Xe,{label:ae?f.editor.pageLabel:f.editor.volumeLabel,value:t.pages||"",onChange:Y=>de("pages",Y)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(Xe,{label:f.editor.firstImageLabel,value:t.firstImage||"",onChange:Y=>de("firstImage",Y)})})]})}),e.jsx(it,{title:f.section.description,onSave:r,onAskAI:p?()=>p("介绍"):void 0,children:e.jsx(Nt,{value:t.description||"",onChange:Y=>de("description",Y),placeholder:f.editor.descriptionPlaceholder})}),(((we=t.additional_works)==null?void 0:we.length)||0)>0&&e.jsx(it,{title:f.section.additionalWorks,onSave:r,children:e.jsx(Tm,{items:t.additional_works||[],onChange:Y=>de("additional_works",Y)})}),e.jsx(it,{title:f.section.indexedBy,onSave:r,onAskAI:p?()=>p("收录于"):void 0,children:e.jsx(Im,{items:t.indexed_by||[],onChange:Y=>de("indexed_by",Y)})}),e.jsx(it,{title:f.section.emendatedBy,onSave:r,onAskAI:p?()=>p("考证"):void 0,children:e.jsx(Em,{items:t.emendated_by||[],onChange:Y=>de("emendated_by",Y)})}),e.jsx(it,{title:f.section.textResources,onSave:r,onAskAI:p?()=>p("资源"):void 0,children:e.jsx(hi,{items:t.resources||[],onChange:Y=>de("resources",Y),onDownload:d,downloadStatuses:u,filterType:"text"})}),e.jsx(it,{title:f.section.imageResources,onSave:r,children:e.jsx(hi,{items:t.resources||[],onChange:Y=>de("resources",Y),onDownload:d,downloadStatuses:u,filterType:"image"})}),e.jsx(it,{title:f.section.sources,onSave:r,onAskAI:p?()=>p("资料来源"):void 0,children:e.jsx(Rl,{items:Ll(t.sources||""),onChange:Y=>de("sources",Al(Y)),onOpenEntityPicker:he})}),(ae||X)&&e.jsx(it,{title:f.section.provenance,onSave:r,onAskAI:p?()=>p("收藏历史"):void 0,children:e.jsx(Nt,{value:t.provenance||"",onChange:Y=>de("provenance",Y),placeholder:f.editor.provenancePlaceholder})}),ae&&e.jsx(it,{title:f.section.otherEditions,onSave:r,onAskAI:p?()=>p("其他版本"):void 0,children:e.jsx(Nt,{value:t.otherEditions||"",onChange:Y=>de("otherEditions",Y),placeholder:f.editor.otherEditionsPlaceholder})}),e.jsx(Bl,{entityType:ce,entityId:t.id,entityTitle:t.title,parentWork:h==null?void 0:h.parentWork,parentCollection:h==null?void 0:h.parentCollection,belongsToWork:h==null?void 0:h.belongsToWork,belongsToCollection:h==null?void 0:h.belongsToCollection,childWorks:h==null?void 0:h.childWorks,childCollections:h==null?void 0:h.childCollections,containedBooks:h==null?void 0:h.containedBooks,siblingBooks:h==null?void 0:h.siblingBooks,onLinkEntity:me,onUnlinkEntity:$e,onViewEntity:Me,onCreateAndLink:Ee,onSaveRelations:P}),l&&a&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${i("danger-soft-border")}`,background:i("danger-soft-bg"),borderRadius:"4px"},children:[e.jsx("div",{style:{color:i("danger"),fontWeight:600,marginBottom:"8px"},children:f.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"12px"},children:f.editor.dangerZoneDesc}),e.jsx("button",{onClick:a,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("danger")}`,borderRadius:"4px",background:"transparent",color:i("danger"),cursor:"pointer"},children:f.editor.deleteEntity})]}),e.jsx(Wl,{isOpen:b,entityType:y,title:$,onSelect:Ae,onCancel:()=>w(!1),onCreate:()=>{w(!1),Ee(g,y)},searchResults:_,onSearch:ze,isLoading:z,excludeId:t.id}),e.jsx(Fl,{isOpen:E,entityType:H,relationField:O,inheritData:ne,onConfirm:Le,onCancel:()=>T(!1)}),e.jsx(Pl,{isOpen:C,title:f.action.selectBookOrWork,filterType:"all",recentEntities:N,excludeId:t.id,onSelect:ke,onCancel:()=>{xe(!1),te(null)},onSearch:ie})]})};function Tm({items:t,onChange:n}){const r=ge(),o=(a,p,c)=>{const d=t.map((u,h)=>h===a?{...u,[p]:c}:u);n(d)},s=a=>n(t.filter((p,c)=>c!==a)),l=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((a,p)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(Xe,{label:r.editor.bookNameLabel,value:a.book_title,onChange:c=>o(p,"book_title",c)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(Xe,{label:r.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:c=>o(p,"n_juan",c&&parseInt(c,10)||void 0)})}),e.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)),e.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:r.action.addAdditionalWork})]})}function Hl({items:t,onChange:n,showMeta:r,addLabel:o}){const s=ge(),[l,a]=m.useState(null),p=(u,h,x)=>{const f=t.map((b,w)=>w===u?{...b,[h]:x||void 0}:b);n(f)},c=u=>{n(t.filter((h,x)=>x!==u)),l===u&&a(null)},d=()=>{n([...t,{source:""}]),a(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((u,h)=>{const x=l===h;return e.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[e.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:()=>a(x?null:h),children:[e.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.2s",transform:x?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:u.source_bid}),e.jsx("button",{onClick:f=>{f.stopPropagation(),c(h)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${i("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:i("muted")},children:"✕"})]}),!x&&r&&(u.title_info||u.author_info)&&e.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&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(Xe,{label:s.label.sourceName,value:u.source,onChange:f=>p(h,"source",f)}),e.jsx(Xe,{label:s.label.sourceBid,value:u.source_bid||"",onChange:f=>p(h,"source_bid",f)})]}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(Xe,{label:s.label.titleInfo,value:u.title_info||"",onChange:f=>p(h,"title_info",f)}),e.jsx(Xe,{label:s.label.authorInfo,value:u.author_info||"",onChange:f=>p(h,"author_info",f)})]}),e.jsx(Xe,{label:s.label.edition,value:u.edition||"",onChange:f=>p(h,"edition",f)})]}),e.jsx(Nt,{value:u.summary||"",onChange:f=>p(h,"summary",f),placeholder:s.editor.summaryPlaceholder}),e.jsx(Nt,{value:u.comment||"",onChange:f=>p(h,"comment",f),placeholder:s.editor.commentPlaceholder}),e.jsx(Nt,{value:u.additional_comment||"",onChange:f=>p(h,"additional_comment",f),placeholder:s.editor.additionalCommentPlaceholder})]})]},h)}),e.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:o})]})}function Im({items:t,onChange:n}){const r=ge();return e.jsx(Hl,{items:t,onChange:n,showMeta:!0,addLabel:r.action.addIndexedBy})}function Em({items:t,onChange:n}){const r=ge();return e.jsx(Hl,{items:t,onChange:n,addLabel:r.action.addEmendatedBy})}function Gl(t){var p,c,d,u,h,x,f;const n=((c=(p=t.authors)==null?void 0:p[0])==null?void 0:c.name)||"",r=((d=t.publication_info)==null?void 0:d.year)||"",o=((u=t.current_location)==null?void 0:u.name)||"",s=(h=t.page_count)!=null&&h.number?String(t.page_count.number):((x=t.page_count)==null?void 0:x.description)||"",l=typeof t.description=="object"&&t.description!==null&&t.description.text||"",a={id:t.id,title:t.title,type:t.type,author:n,publicationYear:r,holder:o,pages:s,description:l,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const b=t;if(Array.isArray(b.related_works)){const w=b.related_works.find(y=>y.relation==="part_of");w&&(a.parentWorkId=w.id,a.parentWorkName=w.title)}}if(t.type==="book"){const b=t;a.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(a.collectionId=(f=b.contained_in[0])==null?void 0:f.id)}return a}function Nm(t){const n={id:t.id,title:t.title,type:t.type,description:t.description?{text:t.description}:void 0,authors:t.author?[{name:t.author}]:void 0,publication_info:t.publicationYear?{year:t.publicationYear}:void 0,current_location:t.holder?{name:t.holder}:void 0,page_count:t.pages?{number:parseInt(t.pages)||0,description:t.pages}:void 0,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};return t.type==="work"&&t.parentWorkId&&(n.related_works=[{id:t.parentWorkId,title:t.parentWorkName||"",relation:"part_of"}]),t.type==="book"&&(n.work_id=t.workId,t.collectionId&&(n.contained_in=[{id:t.collectionId}])),n}const Rm=t=>{const{data:n,id:r,transport:o,mode:s="view",onModeChange:l,onChange:a,onSave:p,onDelete:c,onNavigate:d,renderLink:u,onAskAI:h,renderSectionActions:x,onDownloadResource:f,downloadStatuses:b,relations:w,onRelationsChange:y,headerExtra:j,className:g,style:v}=t;ge();const[$,k]=m.useState(s),_=l?s:$;m.useEffect(()=>{s!==$&&k(s)},[s]);const S=m.useCallback(()=>{const O=_==="view"?"edit":"view";l?l(O):k(O)},[_,l]),[z,A]=m.useState(null);m.useEffect(()=>{r&&o&&o.getItem(r).then(O=>{O&&A(O)})},[r,o]);const E=n||z,T=m.useMemo(()=>E?Gl(E):null,[E]),H=l||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:_==="edit"?i("accent-bg"):"transparent",color:i(_==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?"切换到编辑模式":"切换到查看模式",children:_==="view"?"✏️ 编辑":"👁 查看"}):null,B=e.jsxs(e.Fragment,{children:[H,j]});return!E&&!T?e.jsx(St,{}):_==="view"?e.jsx(Gi,{data:E,transport:o,onNavigate:d?O=>d(O):void 0,renderLink:u,headerExtra:B,className:g,style:v}):T?e.jsxs("div",{className:g,style:v,children:[B&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:B}),e.jsx(Dl,{data:T,onChange:a||(()=>{}),onSave:p||(()=>{}),transport:o,onNavigate:d,showDelete:!!c,onDelete:c,onAskAI:h,renderSectionActions:x,onDownloadResource:f,downloadStatuses:b,relations:w,onRelationsChange:y})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:i("muted")},children:"无数据"})},Mo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Vl=({isOpen:t,onClose:n,onSubmit:r,feedbackListUrl:o})=>{const[s,l]=m.useState(null),[a,p]=m.useState(""),[c,d]=m.useState(""),[u,h]=m.useState("idle"),[x,f]=m.useState(""),b=m.useRef(null);m.useEffect(()=>{t&&(l(null),p(""),d(""),h("idle"),f(""))},[t]),m.useEffect(()=>{s&&setTimeout(()=>{var g;return(g=b.current)==null?void 0:g.focus()},100)},[s]),m.useEffect(()=>{if(u==="success"){const g=setTimeout(n,2e3);return()=>clearTimeout(g)}},[u,n]),m.useEffect(()=>{if(!t)return;const g=v=>{v.key==="Escape"&&n()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t,n]);const w=async()=>{if(!(!s||!a.trim())){h("submitting"),f("");try{await r({type:s,content:a.trim(),...c.trim()?{contact:c.trim()}:{}}),h("success")}catch(g){h("error"),f(g instanceof Error?g.message:"提交失败,请稍后重试")}}};if(!t)return null;const y=s&&a.trim()&&u!=="submitting",j=Mo.find(g=>g.value===s);return e.jsx("div",{style:Lm,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:Am,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:Bm,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Mm,"aria-label":"关闭",children:"✕"})]}),u==="success"?e.jsxs("div",{style:Dm,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),o&&e.jsx("a",{href:o,style:{fontSize:"13px",color:i("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Mo.map(g=>e.jsxs("button",{onClick:()=>l(g.value),style:{...Wm,...s===g.value?Fm:{}},children:[e.jsx("span",{children:g.icon})," ",g.label]},g.value))}),e.jsx("textarea",{ref:b,value:a,onChange:g=>p(g.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...Om,opacity:s?1:.6}}),e.jsx("input",{type:"text",value:c,onChange:g=>d(g.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:Gm}),e.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[a.length," / 2000"]}),u==="error"&&e.jsx("div",{style:Hm,children:x}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:w,disabled:!y,style:{...Pm,opacity:y?1:.6,cursor:y?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},Lm={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Am={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:i("shadow-dialog")},Bm={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Mm={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:i("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Wm={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"},Fm={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Om={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"},Pm={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},Dm={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:i("success")},Hm={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Gm={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"},Ei="--bim-feedback-fab-offset",Ni=48,Vm=16,Um=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:r,hidden:o=!1,zIndex:s})=>{const[l,a]=m.useState(!1),p=n.bottom??24;return m.useEffect(()=>{if(o||typeof document>"u")return;const c=document.documentElement;return c.style.setProperty(Ei,`calc(${p+Ni+Vm}px + env(safe-area-inset-bottom, 0px))`),()=>{c.style.removeProperty(Ei)}},[o,p]),e.jsxs(e.Fragment,{children:[!o&&e.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>a(!0),style:{...Ym,zIndex:s??i("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:e.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:e.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"})})}),e.jsx(Vl,{isOpen:l,onClose:()=>a(!1),onSubmit:t,feedbackListUrl:r})]})},Ym={position:"fixed",width:`${Ni}px`,height:`${Ni}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"},Wo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ul=({onSubmit:t})=>{const[n,r]=m.useState("bug"),[o,s]=m.useState(""),[l,a]=m.useState(""),[p,c]=m.useState("idle"),[d,u]=m.useState(""),h=m.useRef(null);m.useEffect(()=>{n&&setTimeout(()=>{var w;return(w=h.current)==null?void 0:w.focus()},100)},[n]);const x=async()=>{if(!(!n||!o.trim())){c("submitting"),u("");try{await t({type:n,content:o.trim(),...l.trim()?{contact:l.trim()}:{}}),c("success"),s(""),a(""),r("bug")}catch(w){c("error"),u(w instanceof Error?w.message:"提交失败,请稍后重试")}}},f=n&&o.trim()&&p!=="submitting",b=Wo.find(w=>w.value===n);return p==="success"?e.jsx("div",{style:Fo,children:e.jsxs("div",{style:Xm,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>c("idle"),style:Qm,children:"继续提交"})]})}):e.jsxs("div",{style:Fo,children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Wo.map(w=>e.jsxs("button",{onClick:()=>r(w.value),style:{...Km,...n===w.value?qm:{}},children:[e.jsx("span",{children:w.icon})," ",w.label]},w.value))}),e.jsx("textarea",{ref:h,value:o,onChange:w=>s(w.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...Jm}}),e.jsx("input",{type:"text",value:l,onChange:w=>a(w.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:tx}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[o.length," / 2000"]}),e.jsx("button",{onClick:x,disabled:!f,style:{...Zm,opacity:f?1:.6,cursor:f?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&e.jsx("div",{style:ex,children:d})]})},Fo={padding:"16px",border:`1px solid ${i("widget-border")}`,borderRadius:"8px",background:i("input-bg")},Km={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"},qm={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Jm={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"},Zm={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},Xm={display:"flex",alignItems:"center",gap:"12px",color:i("success"),fontSize:"14px"},Qm={background:"none",border:"none",color:i("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ex={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 Oo(t){return typeof t=="function"?t():t??"/api/feedback"}const Yl=({resourceId:t,apiUrl:n})=>{const[r,o]=m.useState([]),[s,l]=m.useState(!0),a=m.useCallback(async()=>{const c=Oo(n);l(!0);try{const u=await(await fetch(`${c}?resourceId=${encodeURIComponent(t)}`)).json();u.success&&o(u.items)}catch{}finally{l(!1)}},[t,n]);m.useEffect(()=>{a()},[a]);const p=async c=>{const d=Oo(n),u=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...c,pageUrl:typeof window<"u"?window.location.href:"",resourceId:t})});if(!u.ok){const h=await u.json().catch(()=>null);throw new Error((h==null?void 0:h.error)||"提交失败")}setTimeout(()=>a(),500)};return e.jsxs("div",{children:[e.jsx(gr,{items:r,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(Ul,{onSubmit:p})})]})},Po={part_of:"所屬",has_part:"包含",contains_text_of:"收錄",collected_in:"叢編",text_carried_by:"載錄",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"後繼",derived_from:"衍生",has_adaptation:"改編",related:"相關"};function Do(t){return t?Po[t]??t:Po.related}const nx={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function ix(t){return nx[t]??t}const rx={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function ox(t){return rx[t]??""}function br({authors:t,onNavigate:n,renderLink:r}){const{convert:o}=G(),s=(t||[]).filter(l=>l&&l.name);return s.length?e.jsx(e.Fragment,{children:s.map((l,a)=>{const p=Ji(l.role);return e.jsxs(m.Fragment,{children:[a>0&&" ",l.dynasty&&e.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",o(l.dynasty),"〕"]}),l.entity_id?e.jsx(De,{id:l.entity_id,label:o(l.name),onNavigate:n,renderLink:r,dense:!0}):o(l.name),p&&e.jsx("span",{style:{marginLeft:4},children:o(p)})]},a)})}):null}function Kl(t,n){var p,c;const r=Ki(t,n),o=r.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=r.buckets.filter(d=>d.key==="image"||d.key==="textImage").flatMap(d=>d.items);s.length&&o.push({key:"_images",label:o.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=r.buckets.find(d=>d.key==="physical"))==null?void 0:p.items)??[];return l.length&&o.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((c=r.buckets.find(d=>d.key==="text"))==null?void 0:c.items)??[],groups:o}}function ql(t,n){const r=(t.url?Ut(t.url):void 0)||t.name,o=Ls(t,n);return o?`${r}(${o})`:r}function yr({item:t,siblings:n,listedVolumeCounts:r}){const{convert:o}=G(),[s,l]=m.useState(!1),a=Rn(t),p=!!a&&a.expected>0&&!(r!=null&&r.has(a.expected)),c=o(ql(t,n)),d=Yt(t),u=Pn(t)||t.details;return e.jsxs("tr",{children:[e.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var x,f;const h=(x=t.metadata)!=null&&x.fragment||t.color_mode?e.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((f=t.metadata)==null?void 0:f.fragment)&&e.jsx("span",{className:"bim-d-tag",children:o("殘片")}),t.color_mode&&e.jsx("span",{className:"bim-d-tag",children:o(t.color_mode==="color"?"彩色":"黑白")})]}):null;return d?e.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:[c," ",e.jsx("span",{"aria-hidden":"true",children:"↗"}),h]}):e.jsxs("span",{className:"bim-d-zt-name",children:[c,h]})})(),u&&e.jsx("span",{className:"bim-d-meta",children:o(u)}),p&&s&&e.jsx("div",{style:{padding:"0 12px 10px"},children:e.jsx(Qi,{item:t})})]}),e.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&e.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(h=>!h),children:o(s?"收起分冊":`展開 ${a.expected} 冊`)})})]})}function Jl({groups:t,listedVolumeCounts:n}){const{convert:r}=G();return e.jsx(e.Fragment,{children:t.map(o=>e.jsxs("div",{className:"bim-d-rg",children:[o.label&&e.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:r(o.label)}),o.description&&e.jsx("p",{className:"bim-d-rg-d",children:r(o.description)}),o.rows.length>0&&e.jsx("table",{className:"bim-d-zt",children:e.jsx("tbody",{children:o.rows.map((s,l)=>e.jsx(yr,{item:s,siblings:o.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),o.mirrors.length>0&&e.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[o.rows.length>0&&e.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:r("鏡像")}),o.mirrors.map((s,l)=>{const a=Yt(s),p=r(ql(s,o.mirrors));return a?e.jsxs("a",{href:a,target:"_blank",rel:"noopener noreferrer",title:s.details?r(s.details):void 0,children:[p," ",e.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):e.jsx("span",{style:{marginRight:14},children:p},l)})]})]},o.key))})}const pn=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function Ri(t){var r;if(!t)return;const n=t.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(r=pn.find(o=>n.startsWith(o.key[0])))==null?void 0:r.key}const Ho=12,sx=60,Zl=({data:t,transport:n,onNavigate:r,renderLink:o,readAction:s,railTop:l,back:a,railLinks:p})=>{var Le,ze,Ae;const c=ge(),{convert:d}=G(),u=m.useMemo(()=>[...t.books||[],...t.collections||[]],[t.books,t.collections]),[h,x]=m.useState(new Map),[f,b]=m.useState(!1),[w,y]=m.useState(""),[j,g]=m.useState(!1),v=u.length<=sx,$=v||f||!!w||j,k=m.useMemo(()=>$?u:u.slice(0,Ho),[u,$]);m.useEffect(()=>{if(!n||k.length===0)return;const P=k.filter(ie=>!h.has(ie));if(P.length===0)return;let he=!1;return Promise.all(P.map(ie=>n.getItem(ie).then(ke=>{const we=ke??{};return[ie,{id:ie,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(()=>[ie,{id:ie}]))).then(ie=>{he||x(ke=>{const we=new Map(ke);for(const[Y,R]of ie)we.set(Y,R);return we})}),()=>{he=!0}},[n,k,h]);const _=m.useMemo(()=>u.map(P=>h.get(P)??{id:P}),[u,h]),S=u.length>0&&u.every(P=>h.has(P)),z=!!n&&k.some(P=>!h.has(P)),A=v||$,E=m.useMemo(()=>Bs(_,t.version_graph,{era:w,scanOnly:j,sort:A?"year":"default"}),[_,t.version_graph,w,j,A]),T=f?E.rows:E.rows.slice(0,Ho),H=E.allRows.filter(P=>P.hasImage).length,B=t.related_works||[],O=B.filter(P=>P.relation==="collected_in"),D=m.useMemo(()=>{const P=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],he=ie=>{const ke=P.indexOf(ie??"");return ke<0?P.length:ke};return B.filter(ie=>ie.relation!=="collected_in").map((ie,ke)=>({r:ie,i:ke})).sort((ie,ke)=>he(ie.r.relation)-he(ke.r.relation)||ie.i-ke.i).map(ie=>ie.r)},[B]),ne=m.useMemo(()=>{const P=Ki(t.resources,t.resource_groups);return[...P.mirrors.flatMap(he=>he.items.map(ie=>({r:ie,kind:d(he.label)}))),...P.buckets.flatMap(he=>he.items.map(ie=>({r:ie,kind:d(ox(he.key))})))]},[t.resources,t.resource_groups,d]),V=t.indexed_by||[],C=t.emendated_by||[],xe=m.useMemo(()=>{var fe,be,M;const P=[],he=(be=(fe=t.authors)==null?void 0:fe[0])==null?void 0:be.dynasty;he&&P.push({label:"成書",value:d(he)});const ie=yt(t,c.unit.juan);if(ie){const ue=(M=t.juan_count)==null?void 0:M.description;P.push({label:"卷帙",value:e.jsxs(e.Fragment,{children:[d(ie),ue&&ue!==ie?e.jsxs("span",{className:"bim-d-meta",children:["(",d(ue),")"]}):null]})})}t.loss_status&&P.push({label:"存佚",value:d(ix(t.loss_status))});const ke=E.allRows.filter(ue=>ue.sortYear!=null),we=ke.length>0?ke.reduce((ue,K)=>ue.sortYear<=K.sortYear?ue:K):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}):z&&P.push({label:"最早存世",value:e.jsx("span",{className:"bim-d-meta","aria-label":d("載入中"),children:"…"})}),C.length&&P.push({label:"考證",value:`${C.length} ${d("條")}`});const Y=Go(t.additional_titles);Y.length&&P.push({label:"又名",value:Y.map(d).join("、")});const R=Go(t.attached_texts);R.length&&P.push({label:"附載",value:R.map(d).join("、")});const U=(t.additional_works||[]).map(ue=>d(ue.book_title)+(ue.n_juan!=null?` ${ue.n_juan}${d(c.unit.juan)}`:""));return U.length&&P.push({label:"附錄",value:U.join("、")}),P},[t,d,c,z,E.allRows,C.length]),te=[{value:t._edition_count??u.length,label:"版本"},{value:S?H:0,label:"有影印"},{value:V.length,label:"家著錄"}],N=t.classification,Z=N?[N.l1,N.l2,N.l3,N.l4].filter(Boolean).map(P=>d(P)):[],ce=t.subtype?d(c.workSubtype[t.subtype]??t.subtype):"",W=e.jsx(fn,{title:d(t.title),byline:e.jsx(br,{authors:t.authors,onNavigate:r,renderLink:o}),meta:e.jsx(Ve,{items:[...Z,N!=null&&N.source?d(`據《${N.source.split("/")[0]}》`):"",ce]}),description:(Le=t.description)!=null&&Le.text?e.jsxs(e.Fragment,{children:[e.jsx(bt,{text:t.description.text,style:{fontSize:15,lineHeight:1.85}}),(ze=t.description.sources)!=null&&ze.length?e.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:t.description.sources.map(P=>d(Fd(P))).filter(Boolean).join(" · ")}):null]}):void 0,stats:te,facts:xe,readAction:s,foot:e.jsx(gn,{revision:t.revision,revisedAt:t.revised_at,review:t.review,todo:t.todo}),children:(Ae=t.appendix)==null?void 0:Ae.map((P,he)=>e.jsxs("details",{style:{marginTop:12},children:[e.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:d(P.title)}),e.jsx(bt,{text:P.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},he))}),X=E.eras.length>=2?[{key:"",label:c.catalog.all},...E.eras.map(P=>({key:P,label:`${P} ${E.allRows.filter(he=>he.era.era===P).length}`}))]:[],ae=[];u.length&&ae.push({id:"versions",label:"版本",count:u.length}),V.length&&ae.push({id:"catalogs",label:"著錄",count:V.length}),O.length&&ae.push({id:"collected",label:"收入叢編",count:O.length}),D.length&&ae.push({id:"related",label:"相關書目",count:D.length}),ne.length&&ae.push({id:"resources",label:"在線資源",count:ne.length});const de=u.length===0&&V.length===0,me=e.jsxs(e.Fragment,{children:[u.length>0&&e.jsxs(Ue,{id:"versions",title:"版本",meta:e.jsx(Ve,{items:[d(`共 ${u.length} 種`),S&&H?d(`${H} 種有影印`):"",E.rows.length!==E.allRows.length?d(`當前 ${E.rows.length} 種`):""]}),children:[e.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":z&&X.length===0&&u.length>1?"":void 0,children:[X.length>0&&e.jsx(Hn,{items:X,value:w,onChange:P=>{y(P),b(!1)}}),e.jsx("span",{className:"bim-d-spacer"}),e.jsx(Ys,{label:"只看有影印",checked:j,onChange:P=>{g(P),b(!1)}}),e.jsx("span",{className:"bim-d-meta",children:d(A?"按年代排列":"按著錄順序")})]}),e.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[e.jsx("thead",{className:"bim-d-ui",children:e.jsxs("tr",{children:[e.jsx("th",{children:d("版本")}),e.jsx("th",{children:d("年代")}),e.jsx("th",{children:d("館藏")}),e.jsx("th",{children:e.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:d("影印")})})]})}),e.jsx("tbody",{children:T.map(P=>{var he;return e.jsx(lx,{row:P,measure:(he=h.get(P.id))==null?void 0:he.measure_info,loaded:h.has(P.id),onNavigate:r,renderLink:o},`${P.id}:${h.has(P.id)?"r":"p"}`)})})]}),T.length===0&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d(w||j?"當前篩選下沒有版本":"暫無版本著錄")}),E.rows.length>T.length&&e.jsx(qt,{label:`展開其餘 ${E.rows.length-T.length} 種版本`,onClick:()=>b(!0)}),E.hasInferredEra&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:d("部分年代據版本題名推斷,非著錄原文")})]}),V.length>0&&e.jsx(ax,{items:V,transport:n,onNavigate:r,renderLink:o}),de&&e.jsx(Ue,{title:"版本",children:e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("尚未著錄該作品的版本與書目收錄。")})})]}),$e=(P,he)=>e.jsx(De,{id:P,label:d(he),onNavigate:r,renderLink:o,dense:!0}),Me=m.useMemo(()=>{const P=new Map;for(const he of D){const ie=Do(he.relation);P.set(ie,(P.get(ie)??0)+1)}return P.size>1?[...P.entries()].sort((he,ie)=>ie[1]-he[1]).slice(0,4).map(([he,ie])=>`${d(he)} ${ie}`).join(" · "):void 0},[D,d]),Ee=e.jsxs(e.Fragment,{children:[e.jsx(Et,{id:"collected",title:"收入叢編",items:O.map(P=>$e(P.id,P.title))}),e.jsx(Et,{id:"related",title:"相關書目",meta:d(`${D.length} 部`),sub:Me,items:D.map(P=>e.jsxs(e.Fragment,{children:[$e(P.id,P.title),e.jsx("span",{className:"bim-d-meta",title:P.note?d(P.note):void 0,children:d(Do(P.relation))})]}))}),e.jsx(Et,{id:"resources",title:"在線資源",cap:6,items:ne.map(({r:P,kind:he})=>{const ie=d((P.url?Ut(P.url):void 0)||P.name),ke=Yt(P);return e.jsxs(e.Fragment,{children:[ke?e.jsxs("a",{href:ke,target:"_blank",rel:"noopener noreferrer",children:[ie," ",e.jsx("span",{"aria-hidden":"true",children:"↗"})]}):e.jsx("span",{children:ie}),he&&e.jsx("span",{className:"bim-d-meta bim-d-kind",children:he})]})})})]});return e.jsx(hn,{railTop:l,back:a,nav:ae,railLinks:p,main:me,card:W,side:Ee})};function Go(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Vo(t,n){return n((t.url?Ut(t.url):void 0)||t.name)}function lx({row:t,measure:n,loaded:r,onNavigate:o,renderLink:s}){const{convert:l}=G(),a=[t.era.era,t.era.reign].filter(Boolean).join(" "),p=t.era.source==="edition",c=t.holders[0],d=c?Vo(c,l):t.locationName?l(t.locationName):"",u=t.images[0],h=u?Yt(u):void 0,x=t.images.map(f=>Vo(f,l)).join("、");return e.jsxs("tr",{"data-loading":r?void 0:"",children:[e.jsxs("td",{className:"bim-d-zt-main",children:[e.jsx(De,{id:t.id,label:l(t.name),onNavigate:o,renderLink:s,dense:!0}),n?e.jsx("span",{className:"bim-d-meta",children:l(n)}):e.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${a?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:a?l(a):r?e.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),e.jsxs("td",{className:`bim-d-zt-sub${d?"":" bim-d-zt-blank"}`,children:[d||(r?e.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),t.holders.length>1&&e.jsxs("span",{className:"bim-d-meta",children:[" +",t.holders.length-1]})]}),e.jsx("td",{className:t.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:t.hasImage&&(h?e.jsx("a",{className:"bim-d-flag",href:h,target:"_blank",rel:"noopener noreferrer",title:x,children:l("有影印")}):e.jsx("span",{className:"bim-d-flag",title:x,children:l("有影印")}))})]})}function ax({items:t,transport:n,onNavigate:r,renderLink:o}){const s=ge(),{convert:l}=G(),[a,p]=m.useState(0),c=Math.min(a,t.length-1),d=t[c],[u,h]=m.useState(new Map);return m.useEffect(()=>{if(!n)return;const x=[...new Set(t.map(b=>b.source_bid).filter(b=>!!b))];if(x.length===0)return;let f=!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=>{f||h(new Map(b.filter(([,w])=>w)))}),()=>{f=!0}},[n,t]),e.jsx(Ue,{id:"catalogs",title:"著錄",meta:e.jsx(Ve,{items:[l(`歷代書目 ${t.length} 家`),l("按著錄順序")]}),children:e.jsxs("div",{className:"bim-d-lu",children:[e.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":l("著錄書目"),children:t.map((x,f)=>e.jsx("li",{role:"presentation",children:e.jsxs("button",{type:"button",role:"tab","aria-selected":f===c,"aria-label":l(x.source),onClick:()=>p(f),children:[e.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(x.source_bid??"")?l(u.get(x.source_bid??"")):" "}),e.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),e.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...l(x.source)].slice(0,9).map((b,w)=>e.jsx("span",{children:b},w))})]})},f))}),e.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d.title_info&&e.jsx("div",{className:"bim-d-lu-title",children:l(d.title_info)}),e.jsx(Ve,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[d.source_bid?e.jsx(De,{id:d.source_bid,label:l(d.source),onNavigate:r,renderLink:o,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&&e.jsx("p",{className:"bim-d-quote",children:Qe(l(d.summary))}),d.comment&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.comment)}),e.jsx("p",{className:"bim-d-quote",children:Qe(l(d.comment))})]}),d.additional_comment&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.additionalComment)}),e.jsx("p",{className:"bim-d-quote",children:Qe(l(d.additional_comment))})]}),!d.summary&&!d.comment&&!d.additional_comment&&!d.title_info&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:l("僅著錄書名,無提要。")}),t.length>1&&e.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?e.jsx("button",{type:"button","aria-label":l(`上一家:${t[c-1].source}`),onClick:()=>p(c-1),children:e.jsxs("span",{"aria-hidden":"true",children:["← ",l(t[c-1].source)]})}):e.jsx("span",{"aria-hidden":"true"}),e.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",t.length]}),c<t.length-1?e.jsx("button",{type:"button","aria-label":l(`下一家:${t[c+1].source}`),onClick:()=>p(c+1),children:e.jsxs("span",{"aria-hidden":"true",children:[l(t[c+1].source)," →"]})}):e.jsx("span",{"aria-hidden":"true"})]})]})]})})}function cx(t){var n;return{id:t.id,kind:"hypothetical",label:t.label,year:t.year??((n=t.year_range)==null?void 0:n[0]),year_range:t.year_range,year_uncertain:t.year_uncertain,group:t.group,note:t.note,description:t.description}}function dx(t,n){if(!t.lineage)return null;const r=t.lineage;return{id:t.id,kind:"book",label:t.title,year:r.year,year_text:r.year_text,year_uncertain:r.year_uncertain,category:r.category,status:r.status,extant_juan:r.extant_juan,group:n[t.id],note:r.note}}function Uo(t,n,r){return{id:`derive:${n.ref}->${t}:${r}`,source:n.ref,target:t,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function px(t,n,r){const[o,s]=[t,n.book_id].sort();return{id:`sibling:${o}-${s}:${r}`,source:o,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function ux(t,n){var d;if(n==="all")return null;const r=(d=t.collections)==null?void 0:d[n],o=Array.isArray(r==null?void 0:r.groups)&&r.groups.length>0,s=Array.isArray(r==null?void 0:r.book_ids)&&r.book_ids.length>0,l=o||s||!!(r!=null&&r.hypothetical_ids);if(!l&&n==="core"&&Array.isArray(t.core_books)&&t.core_books.length>0)return{books:new Set(t.core_books),hypos:t.core_hypotheticals?new Set(t.core_hypotheticals):null};if(!r||!l)return null;const a=o?new Set(r.groups):null,p=new Set(r.book_ids??[]);if(a&&t.node_groups)for(const[u,h]of Object.entries(t.node_groups))a.has(h)&&p.add(u);let c=null;if(r.hypothetical_ids&&(c=new Set(r.hypothetical_ids)),a){c||(c=new Set);for(const u of t.hypothetical_nodes??[])u.group&&a.has(u.group)&&c.add(u.id)}return{books:p,hypos:c}}function zn(t,n,r){const o=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!o||!o.enabled)return s;const l=new Set(o.excluded_books??[]),a=o.node_groups??{},p=ux(o,r??o.default_collection??"all"),c=p!==null,d=(p==null?void 0:p.books)??null,u=(p==null?void 0:p.hypos)??null,h=new Set,x=new Set;if(c){const $=new Map(n.map(E=>[E.id,E])),k=new Map((o.hypothetical_nodes??[]).map(E=>[E.id,E])),_=E=>{const T=$.get(E);if(T&&T.lineage)return(T.lineage.derived_from??[]).map(B=>B.ref);const H=k.get(E);return H?(H.derived_from??[]).map(B=>B.ref):[]},S=E=>k.has(E)?!u||u.has(E):!d||d.has(E),z=new Set,A=E=>{if(!z.has(E)){z.add(E);for(const T of _(E))l.has(T)||(S(T)||(k.has(T)?x.add(T):$.has(T)&&h.add(T)),A(T))}};for(const E of n)d&&d.has(E.id)&&!l.has(E.id)&&A(E.id);for(const E of o.hypothetical_nodes??[])u&&u.has(E.id)&&A(E.id)}const f=n.filter($=>!l.has($.id)).filter($=>!d||d.has($.id)||h.has($.id)).map($=>{const k=dx($,a);return k&&h.has($.id)&&(k.bridge=!0),k}).filter($=>$!==null),b=(o.hypothetical_nodes??[]).filter($=>!u||u.has($.id)||x.has($.id)).map($=>{const k=cx($);return x.has($.id)&&(k.bridge=!0),k}),w=[...f,...b],y=new Set(w.map($=>$.id)),j=new Set,g=[],v=$=>{j.has($.id)||!y.has($.source)||!y.has($.target)||(j.add($.id),g.push($))};for(const $ of n)l.has($.id)||!$.lineage||d&&!d.has($.id)&&!h.has($.id)||(($.lineage.derived_from??[]).forEach((k,_)=>{v(Uo($.id,k,_))}),($.lineage.related_to??[]).forEach((k,_)=>{v(px($.id,k,_))}));for(const $ of o.hypothetical_nodes??[])u&&!u.has($.id)&&!x.has($.id)||($.derived_from??[]).forEach((k,_)=>{v(Uo($.id,k,_))});return{nodes:w,edges:g,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(l)}}function Xl(t,n,r){const o=(t??(n!=null?String(n):"")).trim();return o?!r||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(o)?o:`约 ${o}`:""}function mx(t,n){const r=[],o=t.version_graph;if(!o)return r;const s=new Set(n.map(c=>c.id)),l=new Set((o.hypothetical_nodes??[]).map(c=>c.id)),a=new Set([...s,...l]),p=(c,d)=>{a.has(d.ref)||r.push(`${c}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&r.push(`${c}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!l.has(d.ref)&&r.push(`${c}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const d=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>p(d,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||r.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of o.hypothetical_nodes??[]){const d=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>p(d,u))}return r}const Ql=({graph:t,renderLink:n,className:r,style:o})=>{const{convert:s}=G();if(!t.nodes.length)return e.jsx("div",{style:{...zx,...o},className:r,children:"暂无版本图数据"});const l=new Map,a=new Map;for(const x of t.edges)if(x.kind==="derive"){const f=l.get(x.target)??[];f.push(x),l.set(x.target,f)}else for(const f of[x.source,x.target]){const b=a.get(f)??[];b.push(x),a.set(f,b)}const p=new Map(t.nodes.map(x=>[x.id,x])),c=new Map,d=[];for(const x of t.nodes)if(x.group){const f=c.get(x.group)??[];f.push(x),c.set(x.group,f)}else d.push(x);const u=(x,f)=>(x.year??9999)-(f.year??9999);c.forEach(x=>x.sort(u)),d.sort(u);const h=t.groups.filter(x=>c.has(x.id));return e.jsxs("div",{className:r,style:{...hx,...o},children:[t.title&&e.jsx("div",{style:fx,children:s(t.title)}),t.description&&e.jsx("div",{style:gx,children:s(t.description)}),h.map(x=>e.jsx(Yo,{label:x.label,color:x.color,nodes:c.get(x.id),incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n},x.id)),d.length>0&&e.jsx(Yo,{label:"其他",nodes:d,incomingMap:l,siblingMap:a,nodeMap:p,renderLink:n})]})},Yo=({label:t,color:n,nodes:r,incomingMap:o,siblingMap:s,nodeMap:l,renderLink:a})=>{const{convert:p}=G();return e.jsxs("div",{style:bx,children:[e.jsx("div",{style:{...yx,borderLeftColor:n??i("widget-border")},children:p(t)}),r.map(c=>e.jsx(xx,{node:c,incoming:o.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:l,renderLink:a},c.id))]})},xx=({node:t,incoming:n,siblings:r,nodeMap:o,renderLink:s})=>{const l=t.kind==="hypothetical",a=t.bridge,{convert:p}=G();return e.jsxs("div",{style:{...jx,borderStyle:l||a?"dashed":"solid",opacity:a?.55:t.status==="lost"?.7:1,background:a?i("bg-subtle"):void 0},title:a?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:vx,children:[e.jsx("span",{style:kx,children:l||!s?p(t.label):s(t.id,p(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:wx,children:Xl(p(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:Sx,children:[t.category&&e.jsx(on,{children:p(t.category)}),t.status==="lost"&&e.jsx(on,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(on,{tone:"warn",children:"残本"}),l&&e.jsx(on,{tone:"info",children:"假想祖本"}),a&&e.jsx(on,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:$x,children:["现存:",p(t.extant_juan)]}),t.note&&e.jsx("div",{style:_x,children:p(t.note)}),n.length>0&&e.jsxs("div",{style:qo,children:[e.jsx("div",{style:Jo,children:"来源:"}),n.map(c=>{const d=o.get(c.source);return e.jsxs("div",{style:Zo(c.confidence),children:[e.jsx("span",{style:Xo,children:p(c.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,p(d.label)):p((d==null?void 0:d.label)??c.source)}),c.confidence!=="consensus"&&c.confidence!=="certain"&&e.jsx(Ko,{level:c.confidence}),c.evidence&&e.jsxs("span",{style:Qo,children:["· ",p(c.evidence)]})]},c.id)})]}),r.length>0&&e.jsxs("div",{style:qo,children:[e.jsx("div",{style:Jo,children:"关联:"}),r.map(c=>{const d=c.source===t.id?c.target:c.source,u=o.get(d);return e.jsxs("div",{style:Zo(c.confidence),children:[e.jsx("span",{style:Xo,children:p(c.relation)}),e.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)}),e.jsx(Ko,{level:c.confidence}),c.evidence&&e.jsxs("span",{style:Qo,children:["· ",p(c.evidence)]})]},c.id)})]})]})},on=({children:t,tone:n="default"})=>{const o={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 e.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:o.bg,color:o.fg,marginRight:"4px"},children:t})},Ko=({level:t})=>{const r={certain:{label:"确定",color:i("confidence-certain")},consensus:{label:"共识",color:i("confidence-consensus")},probable:{label:"推测",color:i("confidence-probable")},disputed:{label:"有争议",color:i("confidence-disputed")}}[t];return r?e.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${r.color}`,color:r.color,borderRadius:"8px",marginLeft:"4px"},children:r.label}):null},hx={fontSize:"14px",color:i("fg")},fx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},gx={fontSize:"13px",color:i("muted"),marginBottom:"16px",lineHeight:1.6},bx={marginBottom:"16px"},yx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:i("fg")},jx={border:`1px solid ${i("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:i("bg")},vx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},kx={fontSize:"15px",fontWeight:600},wx={fontSize:"12px",color:i("muted")},Sx={marginBottom:"6px"},$x={fontSize:"12px",color:i("muted"),margin:"2px 0"},_x={fontSize:"12px",color:i("muted"),fontStyle:"italic",margin:"4px 0"},qo={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${i("widget-border")}`},Jo={fontSize:"11px",color:i("muted"),marginBottom:"2px"},Zo=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Xo={display:"inline-block",padding:"0 6px",fontSize:"11px",background:i("tag-bg"),color:i("fg"),borderRadius:"3px",marginRight:"6px"},Qo={fontSize:"11px",color:i("muted")},zx={padding:"20px",textAlign:"center",color:i("muted"),fontSize:"13px"},ea=({selectedNodeId:t,...n})=>{const[r,o]=m.useState("loading"),[s,l]=m.useState(null);return m.useEffect(()=>{let a=!1;return Cx().then(p=>{a||(p?(l(p),o("ready")):o("missing"))}),()=>{a=!0}},[]),r==="loading"?e.jsx("div",{style:es,children:"加载图组件中…"}):r==="missing"||!s?e.jsxs("div",{style:es,children:[e.jsxs("div",{children:["图组件未安装。请安装 ",e.jsx("code",{children:"@xyflow/react"})," 与 ",e.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),e.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",e.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):e.jsx(Tx,{modules:s,selectedNodeId:t,...n})};async function Cx(){try{const[t,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let r=!1;try{await import("@xyflow/react/dist/style.css"),r=!0}catch{r=!1}return{ReactFlow:t.ReactFlow,Background:t.Background,Controls:t.Controls,Handle:t.Handle,Position:t.Position,BaseEdge:t.BaseEdge,EdgeLabelRenderer:t.EdgeLabelRenderer,getSmoothStepPath:t.getSmoothStepPath,dagre:n,cssLoaded:r}}catch{return null}}const Tx=({graph:t,renderLink:n,height:r=600,className:o,style:s,selectedNodeId:l,modules:a})=>{const{ReactFlow:p,Background:c,Controls:d,Handle:u,Position:h,BaseEdge:x,EdgeLabelRenderer:f,getSmoothStepPath:b,dagre:w}=a,y=m.useMemo(()=>({lineage:_=>{var ne,V,C,xe;const S=((ne=_.data)==null?void 0:ne.stepPosition)??.85,[z,A,E]=b({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:S,borderRadius:5}),T=!!((V=_.data)!=null&&V.isSibling),H=T?A:_.targetX-18,B=T?E:_.targetY-12,O=(C=_.data)==null?void 0:C.labelStyle,D=(xe=_.data)==null?void 0:xe.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(x,{id:_.id,path:z,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&e.jsx(f,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${H}px,${B}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:i("bg"),border:`0.5px solid ${i("widget-border")}`,...D,...O},children:_.label})})]})}}),[x,f,b]),j=m.useMemo(()=>({version:_=>{const S=_.data,z=S.kind==="hypothetical",A=S.status==="lost",E=S.isSelected,T=S.bridge,H=S.borderColor??i("muted"),B=T||z?"dashed":"solid",O=T?.5:A?.6:1;return e.jsxs("div",{style:{background:i(T?"bg-subtle":"bg"),border:`2px ${B} ${E?i("primary"):H}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:O,boxShadow:E?i("shadow-node-selected"):z||T?"none":i("shadow-node")},title:T?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(u,{type:"target",position:h.Left,style:{visibility:"hidden"}}),e.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&&e.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&e.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.2},children:Xl(S.yearText,void 0,S.uncertain)}),A&&e.jsx("div",{style:{fontSize:9,color:i("lost-fg"),marginTop:1},children:"已佚"}),e.jsx(u,{type:"source",position:h.Right,style:{visibility:"hidden"}})]})}}),[u,h]),{convert:g}=G(),{rfNodes:v,rfEdges:$}=m.useMemo(()=>Ix(t,w,n,l,g),[t,w,n,l,g]);return e.jsx("div",{style:{width:"100%",height:r,...s},className:o,children:e.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:[e.jsx(c,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function Ix(t,n,r,o,s=l=>l??""){const p=t.layout==="LR"||!t.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:p?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(j=>[j.id,j.color??i("muted")]));for(const j of t.nodes)c.setNode(j.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of t.edges)j.kind==="derive"&&(u.has(j.relation)||c.setEdge(j.source,j.target));n.layout(c);const h=t.nodes.map(j=>{const g=c.node(j.id),v=o?j.id===o:void 0,$={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??Nx(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:r,isSelected:v,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:g.x-160/2,y:g.y-90/2},data:$,draggable:!1,selected:v}}),x=.78,f=.06,b=new Map;for(const j of t.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,g]of b){if(g.length<=1)continue;const v=[...g].sort((k,_)=>{var A,E;const S=((A=c.node(k.target))==null?void 0:A.y)??0,z=((E=c.node(_.target))==null?void 0:E.y)??0;return S-z}),$=v.length;v.forEach((k,_)=>{const S=(_-($-1)/2)*f;w.set(k.id,x+S)})}const y=t.edges.map(j=>Ex(j,w.get(j.id),s));return{rfNodes:h,rfEdges:y}}function Ex(t,n,r=o=>o??""){const o=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",l=Rx(t.confidence),a={type:"arrowclosed",color:l,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:r(t.relation),data:{labelStyle:{color:i("fg")},isSibling:s,stepPosition:n},style:{stroke:l,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":o?"6 4":void 0,opacity:o?.75:1},animated:!1,markerEnd:a,markerStart:s?a:void 0,zIndex:1e3}}function Nx(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function Rx(t){switch(t){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 es={padding:"40px 20px",textAlign:"center",color:i("muted"),fontSize:"13px",border:`1px dashed ${i("widget-border")}`,borderRadius:8,background:i("bg")},jr=({graph:t,defaultMode:n="list",renderLink:r,graphHeight:o=600,selectedNodeId:s,onModeChange:l,collection:a,onCollectionChange:p,collectionsAvailable:c,collectionCounts:d,className:u,style:h})=>{var g;const[x,f]=m.useState(n),b=v=>{f(v),l==null||l(v)},w=(()=>{if(!c)return[];const v=Object.entries(c);return v.length===0||c.all?v:[...v,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),y=!!(p&&w.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:i("muted"),textAlign:"center"},children:"暂无版本传承数据"});const j=a?(g=c==null?void 0:c[a])==null?void 0:g.description:void 0;return e.jsxs("div",{className:u,style:h,children:[e.jsxs("div",{style:Lx,children:[e.jsx("button",{onClick:()=>b("list"),style:di(x==="list"),children:"列表"}),e.jsx("button",{onClick:()=>b("graph"),style:di(x==="graph"),children:"关系图"}),y&&e.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:i("muted"),marginRight:4},children:"集合:"}),w.map(([v,$])=>{const k=d==null?void 0:d[v];return e.jsxs("button",{onClick:()=>p==null?void 0:p(v),style:di(a===v),title:$.description,children:[$.label,k!=null?` ${k}`:""]},v)})]})]}),y&&j&&e.jsx("div",{style:{fontSize:12,color:i("muted"),marginBottom:8,padding:"4px 8px",background:i("bg-subtle"),borderRadius:4},children:j}),x==="list"?e.jsx(Ql,{graph:t,renderLink:r}):e.jsx(ea,{graph:t,renderLink:r,height:o,selectedNodeId:s})]})},Lx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},di=t=>({padding:"4px 12px",fontSize:12,border:`1px solid ${i("widget-border")}`,borderRadius:4,background:t?i("primary"):"transparent",color:i(t?"primary-fg":"fg"),cursor:"pointer"}),ts=40,ns=2,Ax=9,is={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function pi(t){if(!t)return["",""];const n=t.split(/[ ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",t]}const ta=({data:t,transport:n,onNavigate:r,renderLink:o,readAction:s,fullText:l,fullTextPending:a,chapterLink:p,railTop:c,back:d,railLinks:u})=>{var fe,be,M,ue,K,se,je,Te,Ce,le,_e;const h=ge(),{convert:x}=G(),[f,b]=m.useState(null),[w,y]=m.useState(new Map),[j,g]=m.useState([]),[v,$]=m.useState(new Map),[k,_]=m.useState(!1),[S,z]=m.useState("flow"),[A,E]=m.useState(null);m.useEffect(()=>{if(!n||!t.work_id){b(null);return}let I=!1;return n.getItem(t.work_id).then(J=>{!I&&J&&J.type==="work"&&b(J)}).catch(()=>{}),()=>{I=!0}},[n,t.work_id]),m.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!t.work_id){E(null);return}let I=!1;return n.getLineageGraph(t.work_id).then(J=>{I||E(J&&J.nodes.length>1?J:null)}).catch(()=>{I||E(null)}),()=>{I=!0}},[n,t.work_id]),m.useEffect(()=>{const I=t.contained_in||[];if(!n||I.length===0){y(new Map);return}let J=!1;return Promise.all(I.map(oe=>{const Q=typeof oe=="string"?oe:oe.id;return n.getItem(Q).then(ee=>[Q,ee]).catch(()=>[Q,null])})).then(oe=>{if(J)return;const Q=new Map;for(const[ee,Se]of oe)Se&&Q.set(ee,Se);y(Q)}),()=>{J=!0}},[n,t.contained_in]);const T=m.useMemo(()=>{const I=new Set([...(f==null?void 0:f.books)||[],...t.related_books||[]]);return I.add(t.id),[...I]},[f==null?void 0:f.books,t.related_books,t.id]),H=T.length-1;m.useEffect(()=>{if(!n||H<=0){g([]);return}const I=T.length<=ts,J=I?T:T.slice(0,8);let oe=!1;return Promise.all(J.map(Q=>Q===t.id?Promise.resolve({id:Q,title:t.title,edition:t.edition,year:In(t)}):n.getItem(Q).then(ee=>{const Se=ee??{};return{id:Q,title:Se.title,edition:Se.edition,year:ee?In(Se):void 0}}).catch(()=>({id:Q})))).then(Q=>{if(oe)return;const ee=Q.filter(Se=>Se.id===t.id||Se.title||Se.edition);I&&ee.sort((Se,F)=>(Se.year??1/0)-(F.year??1/0)),g(ee)}),()=>{oe=!0}},[n,T,H,t]);const B=t.lineage,O=m.useMemo(()=>[...((B==null?void 0:B.derived_from)||[]).filter(I=>I.ref_type==="book").map(I=>I.ref),...((B==null?void 0:B.related_to)||[]).map(I=>I.book_id)].filter(Boolean),[B]);m.useEffect(()=>{if(!n||O.length===0){$(new Map);return}let I=!1;return Promise.all(O.map(J=>n.getItem(J).then(oe=>[J,{id:J,title:oe==null?void 0:oe.title,edition:oe==null?void 0:oe.edition}]).catch(()=>[J,{id:J}]))).then(J=>{I||$(new Map(J))}),()=>{I=!0}},[n,O]);const D=m.useMemo(()=>Kl(t.resources,t.resource_groups),[t.resources,t.resource_groups]),ne=D.groups.reduce((I,J)=>I+J.rows.length+J.mirrors.length,0),V=D.groups.length>0&&D.groups.every(I=>I.key==="_physical"),C=xn(t),xe=Ps(t),L=yt(t,h.unit.juan),te=new Set((t.contained_in||[]).map(I=>typeof I=="string"?0:cn(I.volume_index).length).filter(I=>I>0)),N=I=>{var Q;const J=(Q=t.base_edition)==null?void 0:Q.find(ee=>ee.book_id===I&&ee.name);if(J!=null&&J.name)return J.name;const oe=v.get(I);return(oe==null?void 0:oe.edition)||(oe==null?void 0:oe.title)||""},Z=m.useMemo(()=>{var We,Ke,lt,Bt,jt;const I=[];xe&&I.push({label:"版本類型",value:x(xe),title:t.edition_type||(We=t.lineage)!=null&&We.category?void 0:x("據版本題名推斷")}),(Ke=t.publication_info)!=null&&Ke.details?I.push({label:"刊印",value:x(t.publication_info.details)}):(C.era||C.reign)&&I.push({label:"刊寫年代",value:x([C.era,C.reign].filter(Boolean).join(" ")),title:C.source==="edition"?x("據版本題名推斷"):void 0}),L&&I.push({label:"卷帙",value:x(L)});const J=(t.contained_in||[]).flatMap(Ne=>typeof Ne=="string"?[]:cn(Ne.volume_index));J.length&&I.push({label:"冊次",value:x(`第 ${Dn(J,h.unit.volume)} ${h.unit.volume}(${J.length} ${h.unit.volume})`)});const oe=(((lt=t.lineage)==null?void 0:lt.derived_from)||[]).find(Ne=>Ne.relation==="底本"&&Ne.ref_type==="book");oe&&N(oe.ref)&&I.push({label:"底本",value:e.jsx(De,{id:oe.ref,label:x(N(oe.ref)),onNavigate:r,renderLink:o,dense:!0})});const Q=(t.base_edition||[]).filter(Ne=>Ne&&Ne.name);for(const Ne of["底本","配補","參校"]){if(Ne==="底本"&&oe&&N(oe.ref))continue;const Ze=Q.filter(Fe=>Fe.role===Ne);Ze.length&&I.push({label:Ne,value:Ze.map((Fe,mt)=>e.jsxs(m.Fragment,{children:[mt>0&&"、",Fe.book_id?e.jsx(De,{id:Fe.book_id,label:x(Fe.name),onNavigate:r,renderLink:o,dense:!0}):x(Fe.name)]},mt))})}const ee=(t.provenance||[]).filter(Ne=>Ne&&Ne.institution),Se=(t.resources||[]).filter(Ne=>(Ne.types||(Ne.type?[Ne.type]:[])).includes("physical"));if(ee.length){I.push({label:"存藏",value:ee.slice(0,2).map(Fe=>x(Fe.institution)).join("、")+(ee.length>2?x(` 等 ${ee.length} 處`):"")});const Ne=ee.filter(Fe=>Fe.call_number).slice(0,2).map(Fe=>`${x(Fe.institution)} ${Fe.call_number}`);Ne.length&&I.push({label:"索書號",value:Ne.join(";")+(ee.filter(Fe=>Fe.call_number).length>2?"…":"")});const Ze=ee.flatMap(Fe=>Fe.seals||[]).filter(Boolean);Ze.length&&I.push({label:"藏印",value:x(Ze.join("、"))})}else Se.length?I.push({label:"存藏",value:Se.slice(0,2).map(Ne=>x(Ne.name)).join("、")+(Se.length>2?x(` 等 ${Se.length} 處`):"")}):(Bt=t.current_location)!=null&&Bt.name&&I.push({label:"存藏",value:x(t.current_location.name)});const F=t.physical_description;if(F){const Ne=[["行款",F.leaf_style],["裝幀",F.binding],["尺寸",F.dimensions],["品相",F.condition]];for(const[Ze,Fe]of Ne)Fe&&Fe.trim()&&I.push({label:Ze,value:x(Fe)})}(jt=t.page_count)!=null&&jt.description&&I.push({label:h.label.pageCount,value:x(t.page_count.description)});const ve=[...wi(t.additional_titles),...wi(t.attached_texts)];return ve.length&&I.push({label:"又名",value:ve.map(x).join("、")}),I},[t,x,h,C,xe,L,v,r,o]),ce=x(t.title),W=t.edition?x(t.edition):void 0,X=((fe=t.lineage)==null?void 0:fe.year_text)||"",ae=e.jsx(fn,{kind:"版本",title:ce,subtitle:W,byline:e.jsx(br,{authors:t.authors??(f==null?void 0:f.authors),onNavigate:r,renderLink:o}),meta:(()=>{const I=[xe?x(xe):"",C.era?x([C.era,C.reign].filter(Boolean).join("")):"",L?x(L):""].filter(Boolean);return I.length?e.jsx("span",{className:"bim-d-tags",children:I.map((J,oe)=>e.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(oe,2)}`,children:J},oe))}):null})(),description:(be=t.description)!=null&&be.text?e.jsx(bt,{text:t.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Zi((M=t.description)==null?void 0:M.text)?6:void 0,facts:Z,readAction:s,secondaryAction:s&&ne>0&&!V?e.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:e.jsx(gn,{revision:t.revision,revisedAt:t.revised_at,review:t.review,todo:t.todo})}),de=t.contained_in||[],me=(l==null?void 0:l.chapters)||[],$e=me[0]&&pi(me[0].title)[0].slice(-1)||"章",Me=!!((ue=B==null?void 0:B.derived_from)!=null&&ue.length||(K=B==null?void 0:B.related_to)!=null&&K.length||(se=t.appendix)!=null&&se.length),Ee=[];(me.length||D.text.length||a)&&Ee.push({id:"fulltext",label:"全文",count:me.length?x(`${me.length} ${$e}`):void 0}),D.groups.length&&Ee.push({id:"images",label:V?"館藏":"影印",count:ne}),Me&&Ee.push({id:"lineage",label:"版本源流"}),de.length&&Ee.push({id:"collections",label:"收入叢編",count:de.length}),(je=t.location_history)!=null&&je.length&&Ee.push({id:"provenance",label:"流轉歷史"});const Le=I=>(p==null?void 0:p(I))??null,ze=me[0],Ae=ze?Le(ze.file):null,P=k?me:me.slice(0,Ax),he=(I,J,oe)=>I?e.jsx("a",{className:oe,href:I.href??"#",onClick:I.onClick?Q=>{Q.metaKey||Q.ctrlKey||(Q.preventDefault(),I.onClick())}:void 0,children:J}):e.jsx("span",{className:oe,children:J}),ie=e.jsxs(e.Fragment,{children:[(me.length>0||D.text.length>0||a)&&e.jsxs(Ue,{id:"fulltext",title:"全文",meta:me.length>0?e.jsx(Ve,{items:[x(`${me.length} ${$e}`),(Te=l==null?void 0:l.source)!=null&&Te.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[a&&!ze&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[e.jsx("span",{className:"bim-d-ft-h",children:" "}),e.jsx("span",{className:"bim-d-meta",children:" "})]}),e.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),ze&&e.jsxs("div",{className:"bim-d-ft",children:[e.jsx("h3",{className:"bim-d-ft-h",children:x(`從${pi(ze.title)[0]||"第一章"}讀起`)}),e.jsx("span",{className:"bim-d-meta",children:x((ze.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),he(Ae,e.jsxs(e.Fragment,{children:[x("進入閱讀頁")," ",e.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),me.length>1&&e.jsx("ul",{className:"bim-d-chap",children:P.map(I=>{const[J,oe]=pi(I.title);return e.jsx("li",{children:he(Le(I.file),e.jsxs(e.Fragment,{children:[J&&e.jsx("b",{children:x(J)}),x(oe||I.file)]}))},I.file)})}),me.length>P.length&&e.jsx(qt,{label:`展開其餘 ${me.length-P.length} ${$e}`,onClick:()=>_(!0)}),D.text.length>0&&e.jsxs(e.Fragment,{children:[(me.length>0||a)&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),e.jsx("table",{className:"bim-d-zt",children:e.jsx("tbody",{children:D.text.map((I,J)=>e.jsx(yr,{item:I,siblings:D.text,listedVolumeCounts:te},`${I.id||I.url||I.name}-${J}`))})})]})]}),D.groups.length>0&&e.jsx(Ue,{id:"images",title:V?"館藏":"影印",meta:e.jsx(Ve,{items:[D.groups.length>1?x(`${D.groups.length} 組`):"",x(`${ne} 處`)]}),children:e.jsx(Jl,{groups:D.groups,listedVolumeCounts:te})}),Me&&e.jsx(Ue,{id:"lineage",title:"版本源流",meta:(Ce=B==null?void 0:B.derived_from)!=null&&Ce.length?x("據版本傳承著錄"):void 0,action:A?e.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":x("源流視圖"),children:[e.jsx("button",{type:"button","aria-pressed":S==="flow",onClick:()=>z("flow"),children:x("卡片")}),e.jsx("button",{type:"button","aria-pressed":S==="graph",onClick:()=>z("graph"),children:x("關係圖")})]}):void 0,children:S==="graph"&&A?e.jsx(jr,{graph:A,defaultMode:"graph",selectedNodeId:t.id,graphHeight:480,renderLink:(I,J)=>e.jsx(De,{id:I,label:x(J),onNavigate:r,renderLink:o,dense:!0})}):e.jsx(Mx,{data:t,heading:W||ce,yearText:X,refName:N,onNavigate:r,renderLink:o})}),de.length>0&&e.jsx(Ue,{id:"collections",title:"收入叢編",children:e.jsx("table",{className:"bim-d-zt",children:e.jsx("tbody",{children:de.map((I,J)=>{var F,ve;const oe=typeof I=="string"?I:I.id,Q=typeof I=="string"?[]:cn(I.volume_index),ee=w.get(oe),Se=(ee==null?void 0:ee._member_count)||((F=ee==null?void 0:ee.books)==null?void 0:F.length)||((ve=ee==null?void 0:ee.contained_works)==null?void 0:ve.length)||0;return e.jsxs("tr",{children:[e.jsxs("td",{className:"bim-d-zt-main",children:[e.jsx(De,{id:oe,label:ee?x(ee.title):oe,onNavigate:r,renderLink:o,dense:!0}),Q.length>0&&e.jsx(Bx,{volumes:Q,unit:h.unit.volume})]}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Se?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Se>0&&x(`全 ${Se} ${h.unit.bu}`)})]},`${oe}-${J}`)})})})}),(le=t.location_history)!=null&&le.length?e.jsx(Ue,{id:"provenance",title:"流轉歷史",children:e.jsx("ul",{className:"bim-d-tl",children:t.location_history.map((I,J)=>e.jsxs("li",{children:[e.jsx("span",{className:"bim-d-tl-t",children:x(I.name)}),([I.start_date,I.end_date].filter(Boolean).join("—")||I.description)&&e.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:e.jsx(Ve,{items:[[I.start_date,I.end_date].filter(Boolean).join("—"),I.description?x(I.description):""]})})]},J))})}):null,Ee.length===0&&e.jsx(Ue,{title:"影印與全文",children:e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),ke=j.findIndex(I=>I.id===t.id),we=T.length<=ts,Y=we&&ke>=0?j.slice(Math.max(0,ke-ns),ke+ns+1):j.filter(I=>I.id!==t.id),R=e.jsxs(e.Fragment,{children:[f&&e.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[e.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:x(h.section.belongsToWork)}),e.jsx("div",{style:{fontSize:17,fontWeight:500},children:e.jsx(De,{id:f.id,label:x(f.title),onNavigate:r,renderLink:o})}),e.jsx(Ve,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(f.authors||[]).slice(0,2).map(I=>`${I.dynasty?`〔${x(I.dynasty)}〕`:""}${x(I.name)}`),x(yt(f,h.unit.juan)),f._edition_count?x(`${f._edition_count} 種版本`):""]}),((_e=f.description)==null?void 0:_e.text)&&e.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(f.description.text.replace(/[#*_>`[\]]/g,""))})]}),H>0&&Y.length>0&&e.jsxs("div",{children:[e.jsx(Et,{id:"siblings",timeline:!0,title:we?"同作品版本":h.relation.siblingVersions,meta:x(we?"按年代":`${H} 種`),cap:Y.length,items:Y.map(I=>I.id===t.id?e.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(I.edition||I.title||I.id)}):e.jsx(De,{id:I.id,label:x(I.edition||I.title||I.id),onNavigate:r,renderLink:o,dense:!0})),metas:Y.map(I=>[I.year!=null?I.year<0?`前${-I.year}`:String(I.year):"",I.id===t.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:Y.findIndex(I=>I.id===t.id)}),f&&e.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:e.jsx(De,{id:f.id,label:x(`在作品頁看全部 ${T.length} 種 →`),onNavigate:r,renderLink:o,dense:!0})})]})]}),U=t.work_id?e.jsx(Us,{caption:h.section.belongsToWork,children:e.jsx(De,{id:t.work_id,label:f?x(f.title):" ",onNavigate:r,renderLink:o,dense:!0})}):void 0;return e.jsx(hn,{railTop:c,back:d,up:U,nav:Ee,railLinks:u,main:ie,card:ae,side:R})};function Bx({volumes:t,unit:n}){const{convert:r}=G();return e.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[r(`第 ${Dn(t,n)} ${n}`),t.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bim-d-dot"}),r(`${t.length} ${n}`)]})]})}function Mx({data:t,heading:n,yearText:r,refName:o,onNavigate:s,renderLink:l}){var y;const{convert:a}=G(),p=t.lineage,c=(p==null?void 0:p.derived_from)||[],d=c.filter(j=>j.ref_type!=="book"),u=c.filter(j=>j.ref_type==="book"&&j.relation==="底本"),h=c.filter(j=>j.ref_type==="book"&&j.relation!=="底本"),x=(p==null?void 0:p.related_to)||[],f=c.length>0||x.length>0,b=j=>j&&is[j]?a(`(${is[j]})`):"",w=(j,g)=>e.jsx(De,{id:j,label:a(g||j),onNavigate:s,renderLink:l,dense:!0});return e.jsxs("div",{className:"bim-d-lf",children:[f&&e.jsxs("ol",{className:"bim-d-lf-list",children:[d.map((j,g)=>e.jsx("li",{className:"bim-d-lf-node",children:e.jsxs("div",{className:"bim-d-lf-dash",children:[e.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(j.relation||"祖本")}),e.jsx("span",{className:"bim-d-lf-name",children:a("擬構祖本")}),j.evidence&&e.jsxs("span",{className:"bim-d-meta",children:[a(j.evidence),b(j.confidence)]})]})},`a-${g}`)),u.map((j,g)=>e.jsx("li",{className:"bim-d-lf-node",children:e.jsxs("div",{className:"bim-d-lf-card",children:[e.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(j.relation)}),e.jsx("span",{className:"bim-d-lf-name",children:w(j.ref,o(j.ref))}),j.evidence&&e.jsxs("p",{className:"bim-d-lf-ev",children:[a(j.evidence),b(j.confidence)]})]})},`b-${g}`)),e.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[e.jsxs("div",{className:"bim-d-lf-here",children:[e.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a("本版")}),e.jsx("span",{className:"bim-d-lf-name",children:n}),r&&e.jsx("span",{className:"bim-d-lf-yr",children:a(r)})]}),h.length>0&&e.jsx("div",{className:"bim-d-lf-side",children:h.map((j,g)=>e.jsxs("div",{className:"bim-d-lf-dash",children:[e.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:a(j.relation)}),e.jsx("span",{className:"bim-d-lf-name",children:w(j.ref,o(j.ref))}),j.evidence&&e.jsxs("p",{className:"bim-d-lf-ev",children:[a(j.evidence),b(j.confidence)]})]},g))})]}),x.length>0&&e.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[e.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:a("翻刻 · 衍生")}),e.jsx("span",{className:"bim-d-lf-chips",children:x.map((j,g)=>e.jsxs("span",{className:"bim-d-lf-chip",title:j.evidence?a(j.evidence):void 0,children:[w(j.book_id,o(j.book_id)),e.jsx("span",{className:"bim-d-meta",children:a(j.relation)})]},g))})]})]}),(y=t.appendix)==null?void 0:y.map((j,g)=>e.jsxs("details",{className:"bim-d-lf-app",children:[e.jsxs("summary",{className:"bim-d-ui",children:[e.jsx("span",{className:"bim-d-meta",children:a("附記")})," ",a(j.title)]}),e.jsx(bt,{text:j.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${g}`)),(p==null?void 0:p.note)&&e.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:a(p.note)})]})}const sn=16,Wx=200,Fx=16,na=({data:t,catalog:n,transport:r,onNavigate:o,renderLink:s,catalogAction:l,railTop:a,back:p,railLinks:c})=>{var ke,we,Y,R,U,fe,be;const d=ge(),{convert:u}=G(),[h,x]=m.useState(""),[f,b]=m.useState(!1),[w,y]=m.useState(null),[j,g]=m.useState(""),[v,$]=m.useState(!1),k=m.useMemo(()=>Fs(t,n),[t,n]),[_,S]=m.useState(new Map),z=!!r&&k.rows.length>0&&k.rows.length<=Wx,A=z&&(k.rows.length<=sn||v),E=A&&k.rows.every(M=>!M.id||_.has(M.id)),T=M=>{var ue;return Ri(M?(ue=_.get(M))==null?void 0:ue.l1:void 0)},H=m.useMemo(()=>{const M=h.trim(),ue=M?u(M):"";return k.rows.filter(K=>{var je,Te;if(j&&Ri(K.id?(je=_.get(K.id))==null?void 0:je.l1:void 0)!==j)return!1;if(!ue)return!0;const se=K.id&&((Te=_.get(K.id))==null?void 0:Te.title)||K.title;return u(se).includes(ue)||(K.subItems||[]).some(Ce=>u(Ce).includes(ue))})},[k.rows,h,j,_,u]),B=f?H:H.slice(0,sn),O=m.useMemo(()=>(A?k.rows:B).filter(M=>M.id&&!_.has(M.id)).map(M=>M.id),[A,k.rows,B,_]);m.useEffect(()=>{if(!r||O.length===0)return;let M=!1;const ue=O.slice(0,Fx);return Promise.all(ue.map(K=>r.getItem(K).then(se=>{var Ce,le;const je=se??{},Te={title:je.title,edition:je.edition,authors:je.authors,measure:se?yt(se,d.unit.juan):void 0,versionCount:je._edition_count??((Ce=je.books)==null?void 0:Ce.length),l1:((le=je.classification)==null?void 0:le.l1)||void 0};return[K,Te]}).catch(()=>[K,{}]))).then(K=>{M||S(se=>{const je=new Map(se);for(const[Te,Ce]of K)je.set(Te,Ce);return je})}),()=>{M=!0}},[r,O,d.unit.juan]);const D=(t.contained_in||[])[0];m.useEffect(()=>{if(!D){y(null);return}if(y({id:D}),!r)return;let M=!1;return r.getItem(D).then(ue=>{M||y({id:D,title:ue==null?void 0:ue.title})}).catch(()=>{}),()=>{M=!0}},[r,D]);const ne=m.useMemo(()=>Kl(t.resources,t.resource_groups),[t.resources,t.resource_groups]),V=ne.text.length+ne.groups.reduce((M,ue)=>M+ue.rows.length+ue.mirrors.length,0),C=t.contained_works||[],xe=new Set(k.rows.map(M=>M.id).filter(Boolean)),L=C.length>0&&!C.every(M=>xe.has(M.id)),te=(()=>{const M=k.rows.map(ue=>ue.edition).filter(Boolean);return M.length>1&&new Set(M).size===1})(),N=k.rows.some(M=>M.volumes.length>0||M.expected!=null),Z=t._member_count||((ke=t.books)==null?void 0:ke.length)||C.length,ce=yt(t,d.unit.juan),W=t.count,X=M=>typeof M=="number"&&Number.isFinite(M)?M:null,ae=X(W==null?void 0:W.juan)??X((we=t.juan_count)==null?void 0:we.number),de=X(W==null?void 0:W.ce)??(k.totalVolumes||null),me=[{value:k.rows.length,label:"子目"},{value:ae??0,label:d.unit.juan},{value:de??0,label:d.unit.volume}],$e=m.useMemo(()=>{var K,se;const M=[];if((K=t.publication_info)!=null&&K.details&&M.push({label:"刊印",value:u(t.publication_info.details)}),Z&&Z!==k.rows.length){const je=t._member_type==="Book"?"所收版本":t._member_type==="Work"?"所收作品":"成員";M.push({label:u(je),value:`${Z} ${u(d.unit.bu)}`,title:u("子目與其各版本合計")})}const ue=[X(W==null?void 0:W.zhong)!=null?`${W.zhong} 種`:"",X(W==null?void 0:W.han)!=null?`${W.han} 函`:""].filter(Boolean);return ue.length&&M.push({label:"應收",value:u(ue.join(" "))}),ae==null&&ce&&M.push({label:"卷帙",value:u(ce),title:(se=t.juan_count)!=null&&se.description?u(t.juan_count.description):void 0}),M},[t,Z,k.rows.length,ae,ce,W,u,d]),Me=m.useMemo(()=>{if(!E)return[];const M=new Map;for(const K of k.rows){const se=T(K.id);se&&M.set(se,(M.get(se)??0)+1)}const ue=pn.filter(K=>(M.get(K.key)??0)>0);return ue.length<2?[]:[{key:"",label:`${d.catalog.all} ${k.rows.length}`},...ue.map(K=>({key:K.key,label:`${K.label} ${M.get(K.key)}`}))]},[E,k.rows,_,d]),Ee=m.useMemo(()=>{if(!E||!k.rows.some(se=>se.volumes.length>0))return null;const M=[],ue=k.rows.filter(se=>se.volumes.length>0).map(se=>({k:T(se.id)??"",from:Math.min(...se.volumes),to:Math.max(...se.volumes)})).sort((se,je)=>se.from-je.from);for(const se of ue){const je=se.to-se.from+1,Te=M[M.length-1];Te&&Te.key===se.k?(Te.to=Math.max(Te.to,se.to),Te.n+=je):M.push({key:se.k,from:se.from,to:se.to,n:je})}const K=ue.reduce((se,je)=>Math.max(se,je.to),0);return M.length>1&&M.some(se=>se.key)?{segs:M,last:K}:null},[E,k.rows,_]),Le=(Y=t.description)==null?void 0:Y.text,ze=e.jsx(fn,{kind:"叢編",title:u(t.title),byline:e.jsx(br,{authors:t.authors,onNavigate:o,renderLink:s}),meta:e.jsx(Ve,{items:[t.subtype==="work_collection"?u("作品集"):"",(R=t.publication_info)!=null&&R.year?u(t.publication_info.year):""]}),description:Le||(U=t.history)!=null&&U.length?e.jsxs(e.Fragment,{children:[Le&&e.jsx(bt,{text:Le,style:{fontSize:15,lineHeight:1.85}}),(fe=t.history)!=null&&fe.length?e.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:t.history.map((M,ue)=>e.jsx("li",{children:u(M)},ue))}):null]}):void 0,clampDescription:Zi(Le)||(((be=t.history)==null?void 0:be.length)??0)>2?6:void 0,stats:me,facts:$e,foot:e.jsx(gn,{revision:t.revision,revisedAt:t.revised_at,review:t.review,todo:t.todo}),children:Ee&&e.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[e.jsx("div",{className:"bim-d-dist-head",children:e.jsx("span",{children:u("全帙冊次分佈")})}),e.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":u("全帙冊次分佈"),children:Ee.segs.map((M,ue)=>{const K=pn.find(se=>se.key===M.key);return e.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!K,title:K?u(`${K.label} 第 ${M.from}–${M.to} 冊`):void 0,"aria-label":u(K?`只看${K.label}`:"未分類"),"aria-pressed":!!K&&j===M.key,style:{flexGrow:M.n,background:i(K?K.token:"rule")},onClick:()=>{K&&(g(j===M.key?"":M.key),b(!1))}},ue)})}),e.jsxs("div",{className:"bim-d-life-lab",children:[e.jsx("span",{children:u(`第 1 ${d.unit.volume}`)}),e.jsx("span",{children:u("點色段篩選部類")}),e.jsx("span",{children:u(`第 ${Ee.last} ${d.unit.volume}`)})]})]})}),Ae=[];k.rows.length&&Ae.push({id:"titles",label:"子目",count:k.rows.length}),V&&Ae.push({id:"resources",label:"影印與全文",count:V}),L&&Ae.push({id:"works",label:d.section.containedWorks,count:C.length});const P=e.jsxs(e.Fragment,{children:[k.rows.length>0&&e.jsxs(Ue,{id:"titles",title:"子目",meta:e.jsx(Ve,{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>sn||Me.length>0)&&e.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[Me.length>0&&e.jsx(Hn,{items:Me,value:j,onChange:M=>{g(M),b(!1)}}),z&&k.rows.length>sn&&!E&&e.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:v,onClick:()=>$(!0),title:u(`將載入全部 ${k.rows.length} ${d.unit.items}`),children:u(v?"正在按部類分組…":"按部類分組")}),e.jsx("span",{className:"bim-d-spacer"}),k.rows.length>sn&&e.jsx("input",{type:"search",className:"bim-d-find",value:h,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:M=>{x(M.target.value),b(!1)}})]}),e.jsxs("table",{className:"bim-d-zt",children:[e.jsx("thead",{className:"bim-d-ui",children:e.jsxs("tr",{children:[N&&e.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),e.jsx("th",{children:u("書名")}),e.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),e.jsx("tbody",{children:B.map((M,ue)=>{var _e;const K=M.id?_.get(M.id):void 0,se=K!=null&&K.title&&M.title===M.id?K.title:M.title,je=((K==null?void 0:K.authors)||[]).find(I=>I&&I.name),Te=[je?`${je.dynasty?`〔${u(je.dynasty)}〕`:""}${u(je.name)}${je.role?` ${u(je.role)}`:""}`:"",K!=null&&K.measure?u(K.measure):"",(_e=M.subItems)!=null&&_e.length?M.subItems.map(I=>u(I)).join("、"):"",(K!=null&&K.edition||M.edition)&&!te?u((K==null?void 0:K.edition)||M.edition||""):""].filter(Boolean),Ce=pn.find(I=>I.key===T(M.id)),le=M.volumes.length>0?u(`第 ${Dn(M.volumes,d.unit.volume)} ${d.unit.volume}`):M.expected!=null?u(`${M.found??0}/${M.expected} ${d.unit.volume}`):"";return e.jsxs("tr",{children:[N&&e.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${le?"":" bim-d-zt-blank"}`,children:[Ce&&e.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:i(Ce.token)}}),le||e.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),e.jsxs("td",{className:"bim-d-zt-main",children:[M.id?e.jsx(De,{id:M.id,label:u(se),onNavigate:o,renderLink:s,dense:!0}):e.jsx("span",{className:"bim-d-zt-name",children:u(se)}),Te.length>0?e.jsx(Ve,{items:Te}):M.id&&!K&&r?e.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${K!=null&&K.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:K!=null&&K.versionCount?u(`${K.versionCount} 種`):""})]},`${M.id??M.title}-${ue}`)})})]}),B.length===0&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(d.catalog.noMatch)}),H.length>B.length&&e.jsx(qt,{label:`展開其餘 ${H.length-B.length} ${d.unit.items}`,onClick:()=>b(!0)})]}),V>0&&e.jsxs(Ue,{id:"resources",title:"影印與全文",meta:u(`${V} 處`),children:[ne.text.length>0&&e.jsxs("div",{className:"bim-d-rg",children:[ne.groups.length>0&&e.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("全文")}),e.jsx("table",{className:"bim-d-zt",children:e.jsx("tbody",{children:ne.text.map((M,ue)=>e.jsx(yr,{item:M,siblings:ne.text},`${M.id||M.url||M.name}-${ue}`))})})]}),e.jsx(Jl,{groups:ne.groups})]}),k.rows.length===0&&V===0&&e.jsx(Ue,{title:"子目",children:e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),he=L?e.jsx(Et,{id:"works",title:d.section.containedWorks,meta:u(`${C.length} 種`),cap:12,items:C.map(M=>e.jsx(De,{id:M.id,label:u(M.title),onNavigate:o,renderLink:s,dense:!0}))}):null,ie=w?e.jsx(Us,{caption:"上級叢編",children:e.jsx(De,{id:w.id,label:u(w.title||w.id),onNavigate:o,renderLink:s,dense:!0})}):void 0;return e.jsx(hn,{railTop:a,back:p,up:ie,nav:Ae,railLinks:c,main:P,card:ze,side:he})},Ox=16,ui=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function rs(t){if(!t)return ui.length;const n=ui.indexOf(t);return n===-1?ui.length:n}const Px={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function wt(t){return t==null?"":t<0?`前${-t}`:String(t)}const Dx={秦:[-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]},ia=({data:t,transport:n,onNavigate:r,renderLink:o,railTop:s,back:l,railLinks:a})=>{var he,ie,ke,we,Y;const p=ge(),{convert:c}=G(),[d,u]=m.useState("全部"),[h,x]=m.useState(!1),[f,b]=m.useState("default"),[w,y]=m.useState(new Map),j=m.useMemo(()=>(t.works||[]).map(R=>{const U=w.get(R.work_id);return{id:R.work_id,title:(U==null?void 0:U.title)??R.title??R.work_id,role:R.role||"",cls:qi(R.role),versionCount:U==null?void 0:U.versionCount,section:U==null?void 0:U.cls,l1:U==null?void 0:U.l1,measure:U==null?void 0:U.measure,hasImage:U==null?void 0:U.hasImage,loaded:!!(U!=null&&U.loaded)}}),[t.works,w]),g=m.useMemo(()=>Ws((t.works||[]).map(R=>R.role)),[t.works]),v=m.useMemo(()=>{const R=d==="全部"?j:j.filter(U=>U.cls===d);return f==="versions"?[...R].sort((U,fe)=>(fe.versionCount??-1)-(U.versionCount??-1)):R},[j,d,f]),$=h?v:v.slice(0,Ox),k=m.useMemo(()=>$.filter(R=>!w.has(R.id)).map(R=>R.id),[$,w]);m.useEffect(()=>{if(!n||k.length===0)return;let R=!1;return Promise.all(k.map(U=>n.getItem(U).then(fe=>{var K,se,je,Te,Ce;const be=fe??{},M=be._edition_count??(((K=be.books)==null?void 0:K.length)??0)+(((se=be.collections)==null?void 0:se.length)??0),ue=[(je=be.classification)==null?void 0:je.l1,(Te=be.classification)==null?void 0:Te.l2].filter(Boolean).join(" ");return[U,{id:U,title:be.title,versionCount:M,loaded:!0,cls:ue||void 0,l1:((Ce=be.classification)==null?void 0:Ce.l1)||void 0,measure:fe&&yt(fe,p.unit.juan)||void 0,hasImage:!!(be.has_image??be._has_image)}]}).catch(()=>[U,{id:U,loaded:!0}]))).then(U=>{R||y(fe=>{const be=new Map(fe);for(const[M,ue]of U)be.set(M,ue);return be})}),()=>{R=!0}},[n,k,p.unit.juan]);const _=m.useMemo(()=>{const R=new Map;for(const U of t.alt_names||[]){const fe=U.type||p.section.aliases;R.has(fe)||R.set(fe,[]),R.get(fe).push(U.name)}return[...R.entries()].sort((U,fe)=>rs(U[0])-rs(fe[0])).map(([U,fe])=>({label:U,names:fe}))},[t.alt_names,p]),S=t.birth_year??((he=t.dates)==null?void 0:he.birth)??void 0,z=t.death_year??((ie=t.dates)==null?void 0:ie.death)??void 0,A=(ke=t.dates)==null?void 0:ke.floruit,E=S!=null||z!=null?`${wt(S)||"?"}—${wt(z)||"?"}`:Array.isArray(A)&&A.length===2&&A.every(R=>Number.isFinite(R))?`活躍於 ${wt(A[0])}—${wt(A[1])}`:"",T=new Set(["本名","字","號","号"]),H=_.filter(R=>T.has(R.label)),B=_.filter(R=>!T.has(R.label)),O=B.reduce((R,U)=>R+U.names.length,0),D=m.useMemo(()=>{const R=[];for(const fe of H)R.push({label:fe.label,value:fe.names.map(be=>c(be)).join("、")});const U=(t.works||[]).length;return U&&R.push({label:"著作",value:`${U} ${c("種")}`}),R},[t.works,H,c]),ne=R=>{var U;return(U=_.find(fe=>R.includes(fe.label)))==null?void 0:U.names[0]},V=ne(["字"]),C=ne(["號","号"]),xe=[V?`字${V}`:"",C?`號${C}`:""].filter(Boolean).join(","),L=t.native_place,te=t.dynasty?Dx[t.dynasty]:void 0,N=(()=>{if(!te||S==null||z==null||z<S)return null;const[R,U]=te,fe=Math.max(S,R),be=Math.min(z,U);if(be<=fe)return null;const M=U-R;return e.jsxs("div",{className:"bim-d-life bim-d-ui",children:[e.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":c(`${wt(S)}—${wt(z)},一生 ${z-S+1} 年`),children:e.jsx("i",{style:{left:`${(fe-R)/M*100}%`,width:`${(be-fe)/M*100}%`}})}),e.jsxs("div",{className:"bim-d-life-lab",children:[e.jsx("span",{children:c(`${wt(R)} ${t.dynasty}`)}),e.jsx("span",{children:c(`一生 ${z-S+1} 年`)}),e.jsx("span",{children:wt(U)})]})]})})(),Z=m.useMemo(()=>{if(!n||j.length===0||j.some(fe=>!fe.loaded))return null;const R=new Map;for(const fe of j){const be=Ri(fe.l1);be&&R.set(be,(R.get(be)??0)+1)}const U=pn.map(fe=>({...fe,n:R.get(fe.key)??0})).filter(fe=>fe.n>0);return U.length?U:null},[j,n]),ce=e.jsxs(fn,{kind:Px[t.subtype]??"人物",title:c(t.primary_name||t.title),subtitle:xe?c(xe):void 0,meta:e.jsxs(e.Fragment,{children:[e.jsx(Ve,{items:[t.dynasty?c(t.dynasty):"",E?c(E):"",L?c(`${L}人`):""]}),N]}),description:(we=t.description)!=null&&we.text?e.jsx(bt,{text:t.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Zi((Y=t.description)==null?void 0:Y.text)?6:void 0,facts:D,foot:e.jsx(gn,{revision:t.revision,revisedAt:t.revised_at,review:t.review,todo:t.todo}),children:[O>0&&e.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[e.jsx("summary",{children:c(`更多別名(${O})`)}),e.jsx("dl",{children:B.map(R=>e.jsxs(m.Fragment,{children:[e.jsx("dt",{children:c(R.label)}),e.jsx("dd",{children:R.names.map(U=>c(U)).join("、")})]},R.label))})]}),Z&&e.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[e.jsx("div",{className:"bim-d-dist-head",children:e.jsx("span",{children:c("著作分佈")})}),e.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:Z.map(R=>e.jsx("i",{style:{flexGrow:R.n,background:i(R.token)}},R.key))}),e.jsx("div",{className:"bim-d-dist-key",children:Z.map(R=>e.jsxs("span",{children:[e.jsx("i",{style:{background:i(R.token)}}),c(R.label)," ",R.n]},R.key))})]})]}),W=m.useMemo(()=>j.filter(R=>R.loaded&&(R.versionCount??0)>0).sort((R,U)=>(U.versionCount??0)-(R.versionCount??0)).slice(0,3),[j]),X=!!n&&j.length>=3&&$.some(R=>!R.loaded),ae=d==="全部"&&(X||W.length>=2),de=t.external_ids||{},me=[];de.cbdb_id!=null&&me.push({label:"CBDB",id:String(de.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${de.cbdb_id}`,note:de.cbdb_match==="auto"?"自動匹配":void 0});const $e=de.wikidata_id;$e&&me.push({label:"Wikidata",id:$e,href:`https://www.wikidata.org/wiki/${$e}`});const Me=de.viaf_id;Me&&me.push({label:"VIAF",id:Me,href:`https://viaf.org/viaf/${Me}`});const Ee=g.map(R=>({key:R.cls,label:`${R.label} ${R.count}`})),Le=[...ae&&!X?[{id:"featured",label:"著作舉要",count:W.length}]:[],...j.length?[{id:"works",label:"全部著作",count:j.length}]:[],...me.length?[{id:"external",label:"站外資料",count:me.length}]:[]],ze=ae?e.jsxs(Ue,{id:"featured",title:"著作舉要",children:[e.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:c("存世版本最多的三部")}),e.jsxs("div",{className:"bim-d-picks","aria-busy":X||void 0,children:[X&&[0,1,2].map(R=>e.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[e.jsx("span",{className:"bim-d-pick-t",children:" "}),e.jsx("span",{className:"bim-d-meta",children:" "}),e.jsx("div",{className:"bim-d-pick-n",children:" "})]},R)),!X&&W.map(R=>e.jsxs("div",{className:"bim-d-pick",children:[e.jsx("span",{className:"bim-d-pick-t",children:e.jsx(De,{id:R.id,label:c(R.title),onNavigate:r,renderLink:o,dense:!0})}),e.jsx(Ve,{items:[R.section?c(R.section):"",R.measure?c(R.measure):""]}),e.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[e.jsx("span",{className:"bim-d-pick-num",children:R.versionCount}),e.jsx("span",{children:c("種版本")}),R.hasImage&&e.jsx("span",{className:"bim-d-flag",children:c("有影印")})]})]},R.id))]})]}):null,Ae=j.length===0?e.jsx(Ue,{title:"著作",children:e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該人物的關聯作品。")})}):e.jsxs(e.Fragment,{children:[ze,e.jsxs(Ue,{id:"works",title:"著作",meta:e.jsx(Ve,{items:[c(`共 ${j.length} 種`),v.length!==j.length?c(`當前 ${v.length} 種`):""]}),children:[e.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[Ee.length>1&&e.jsx(Hn,{items:Ee,value:d,onChange:R=>{u(R),x(!1)}}),e.jsx("span",{className:"bim-d-spacer"}),e.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":f==="versions",onClick:()=>{f==="default"&&x(!0),b(R=>R==="default"?"versions":"default")},children:c(f==="default"?"按版本數排列":"按著錄順序")})]}),e.jsxs("table",{className:"bim-d-zt",children:[e.jsx("thead",{className:"bim-d-ui",children:e.jsxs("tr",{children:[e.jsx("th",{children:c("作品")}),e.jsx("th",{children:c("部類")}),e.jsx("th",{children:c("職任")}),e.jsx("th",{children:c("存世版本")}),e.jsx("th",{"aria-label":c("影印")})]})}),e.jsx("tbody",{children:$.map(R=>e.jsxs("tr",{children:[e.jsxs("td",{className:"bim-d-zt-main",children:[e.jsx(De,{id:R.id,label:c(R.title),onNavigate:r,renderLink:o,dense:!0}),R.measure?e.jsx(Ve,{items:[c(R.measure)]}):!R.loaded&&n?e.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${R.section||R.loaded?"":" bim-d-zt-blank"}`,children:R.section?c(R.section):null}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${R.role?"":" bim-d-zt-blank"}`,children:R.role?c(R.role):e.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),e.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${R.loaded?"":" bim-d-zt-blank"}`,children:R.loaded?R.versionCount?c(`${R.versionCount} 種`):e.jsx("span",{className:"bim-d-zt-empty",children:c("未著錄")}):""}),e.jsx("td",{className:R.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:R.hasImage&&e.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("有影印")})})]},R.id))})]}),$.length===0&&e.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("該職任下的著作尚未著錄。")}),v.length>$.length&&e.jsx(qt,{label:`展開其餘 ${v.length-$.length} 種著作`,onClick:()=>x(!0)})]})]}),P=me.length>0?e.jsx(Et,{id:"external",title:"站外資料",items:me.map(R=>e.jsxs("a",{href:R.href,target:"_blank",rel:"noopener noreferrer",children:[R.label," ",e.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:me.map(R=>R.id),foot:de.cbdb_id!=null&&de.cbdb_match==="auto"?c("CBDB 為自動匹配,未經人工核對"):void 0}):null;return e.jsx(hn,{railTop:s,back:l,nav:Le,railLinks:a,main:Ae,card:ce,side:P})},vr="(max-width: 719px)",Hx=`${vr}, (pointer: coarse)`,ra=`
|
|
1027
1069
|
.bim-ct {
|
|
1028
1070
|
display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
|
|
1029
1071
|
max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
|
|
@@ -1131,7 +1173,7 @@ ${z??""}`,load:we,files:N,activeFile:Z??null,activeJuan:(he==null?void 0:he.json
|
|
|
1131
1173
|
.bim-ct-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
1132
1174
|
}
|
|
1133
1175
|
|
|
1134
|
-
@media ${
|
|
1176
|
+
@media ${vr} {
|
|
1135
1177
|
.bim-ct { display: block; padding: 12px 16px 40px; }
|
|
1136
1178
|
.bim-ct-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
|
|
1137
1179
|
.bim-ct-lrow > a { grid-template-columns: minmax(0, 1fr); }
|
|
@@ -1156,7 +1198,7 @@ ${z??""}`,load:we,files:N,activeFile:Z??null,activeJuan:(he==null?void 0:he.json
|
|
|
1156
1198
|
}
|
|
1157
1199
|
|
|
1158
1200
|
/* 点击目标 ≥44px(Q5):触屏与窄屏 */
|
|
1159
|
-
@media ${
|
|
1201
|
+
@media ${Hx} {
|
|
1160
1202
|
.bim-ct-row { min-height: 44px; }
|
|
1161
1203
|
.bim-ct-tw { width: 44px; }
|
|
1162
1204
|
.bim-ct-pg { min-width: 44px; height: 44px; }
|
|
@@ -1164,6 +1206,223 @@ ${z??""}`,load:we,files:N,activeFile:Z??null,activeJuan:(he==null?void 0:he.json
|
|
|
1164
1206
|
|
|
1165
1207
|
/* ── 版式「界栏」(v4):<html data-layout="boxed"> 才生效;值走 --bim-fr-* 令牌 ── */
|
|
1166
1208
|
:root[data-layout="boxed"] .bim-ct-side { border: ${i("fr-bd")}; background: ${i("fr-bg")}; padding: 14px 8px; }
|
|
1167
|
-
|
|
1168
|
-
:root[data-layout="boxed"] .bim-ct-
|
|
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;
|
|
1209
|
+
/* 标题栏自成一框,与下方(检索框或卡片/列表)留出间距 */
|
|
1210
|
+
: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 0 14px; }
|
|
1211
|
+
/* 卡片:每张一框 */
|
|
1212
|
+
:root[data-layout="boxed"] .bim-ct-card > a { border: ${i("fr-bd")}; border-radius: 0; }
|
|
1213
|
+
/* 列表:整表一框,行间细线,不用斑马底 */
|
|
1214
|
+
:root[data-layout="boxed"] .bim-ct-list { border: ${i("fr-bd")}; background: ${i("fr-bg")}; }
|
|
1215
|
+
:root[data-layout="boxed"] .bim-ct-lrow:nth-child(odd) { background: none; border-radius: 0; }
|
|
1216
|
+
:root[data-layout="boxed"] .bim-ct-lrow + .bim-ct-lrow { border-top: ${i("fr-hd-bd")}; }
|
|
1217
|
+
:root[data-layout="boxed"] .bim-ct-lrow > a { border-radius: 0; }
|
|
1218
|
+
`,mn="未分類",ft="all",kr=20;function yn(t){if(!t)return[];const n=[];for(const r of[t.l1,t.l2,t.l3,t.l4]){const o=(r??"").trim();if(!o)break;n.push(o)}return n}function Gx(t){const n=yn(t);return n.length?n.join("/"):mn}function Vx(t){const n=yn(t);return n.length?n.map((r,o)=>n.slice(0,o+1).join("/")):[mn]}function Ux(t,n=[]){const r=new Map;n.forEach((p,c)=>{const d=[p.cata_l1,p.cata_l2,p.cata_l3,p.cata_l4].filter(u=>!!u);d.forEach((u,h)=>{const x=d.slice(0,h+1).join("/");r.has(x)||r.set(x,c)})});const o=new Map;let s=0;for(const p of t){const c=yn(p.classification);if(!c.length){s++;continue}let d=o;c.forEach((u,h)=>{const x=c.slice(0,h+1).join("/");let f=d.get(u);f||(f={id:x,label:u,count:0,children:new Map},d.set(u,f)),f.count++,d=f.children})}const l=p=>[...p.values()].sort((c,d)=>{const u=r.get(c.id)??1/0,h=r.get(d.id)??1/0;return u!==h?u-h:c.label.localeCompare(d.label,"zh")}).map(c=>{const d={id:c.id,label:c.label,count:c.count};return c.children.size&&(d.children=l(c.children)),d}),a=l(o);return s>0&&a.push({id:mn,label:mn,count:s}),a}function Ot(t,n){if(!n)return[];for(const r of t){if(r.id===n)return[r];if(r.children){const o=Ot(r.children,n);if(o.length)return[r,...o]}}return[]}function wr(t){return t.reduce((n,r)=>n+r.count,0)}function Yx(t){return(t??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function Kx(t){var p;const n={id:t.id,title:t.title||t.id},r=t.juan_count,o=typeof r=="number"?r:r==null?void 0:r.number;typeof o=="number"&&o>0?n.juan=o:t.measure_info&&(n.juan=t.measure_info);const s=(t.authors??[]).filter(c=>c==null?void 0:c.name).map(c=>{const d=c.dynasty||(t.authors.length===1?t.dynasty:void 0);return d?{name:c.name,dynasty:d}:{name:c.name}});s.length&&(n.authors=s);const l=Yx(typeof t.description=="string"?t.description:(p=t.description)==null?void 0:p.text);l&&(n.summary=l);const a=yn(t.classification);return a.length&&(n.classification=a),n}function qx(t,n){const r=t.summary?0:1,o=n.summary?0:1;return r!==o?r-o:t.title.localeCompare(n.title,"zh")}function Jx(t,n=kr){return Math.max(1,Math.ceil(t/n))}function oa(t,n,r=2){if(n<=1)return[1];const o=new Set([1,n]);for(let a=t-r;a<=t+r;a++)a>=1&&a<=n&&o.add(a);const s=[...o].sort((a,p)=>a-p),l=[];return s.forEach((a,p)=>{if(p>0){const c=a-s[p-1];c===2?l.push(a-1):c>2&&l.push(null)}l.push(a)}),l}const Zx=()=>e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:e.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Xx(t,n,r){const o=[];r&&o.push({id:ft,parentId:null,hasChildren:!1,firstChildId:null});const s=(l,a)=>{var p;for(const c of l){const d=(p=c.children)!=null&&p.length?c.children:null;o.push({id:c.id,parentId:a,hasChildren:!!d,firstChildId:d?d[0].id:null}),d&&n.has(c.id)&&s(d,c.id)}};return s(t,null),o}function sa({tree:t,selectedId:n,onSelect:r,allLabel:o="全部",label:s="分類"}){const{convert:l}=G(),a=m.useRef(null),p=n&&n!==ft?n:null,c=o!==null,[d,u]=m.useState(()=>{const k=new Set;for(const _ of Ot(t,p))k.add(_.id);return k});m.useEffect(()=>{const k=Ot(t,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})},[t,p]);const h=m.useMemo(()=>Xx(t,d,c),[t,d,c]),[x,f]=m.useState(null);m.useEffect(()=>{f(null)},[n]);const b=p??(c?ft:null),w=m.useMemo(()=>{var S;const k=new Set(h.map(z=>z.id));if(x&&k.has(x))return x;if(b&&k.has(b))return b;const _=Ot(t,p).map(z=>z.id).filter(z=>k.has(z));return _.length?_[_.length-1]:((S=h[0])==null?void 0:S.id)??null},[h,x,b,t,p]),y=m.useCallback((k,_)=>{u(S=>{const z=S.has(k),A=_??!z;if(A===z)return S;const E=new Set(S);return A?E.add(k):E.delete(k),E})},[]),j=m.useCallback(k=>{f(k),requestAnimationFrame(()=>{var S;const _=Array.from(((S=a.current)==null?void 0:S.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===k);_==null||_.focus()})},[]),g=m.useCallback((k,_)=>{_&&y(k,!0),r(k)},[r,y]),v=m.useCallback(k=>{const _=k.target.closest("[data-ct-id]");if(!_)return;const S=_.dataset.ctId,z=h.findIndex(T=>T.id===S);if(z<0)return;const A=h[z];let E=null;switch(k.key){case"ArrowDown":E=h[Math.min(h.length-1,z+1)].id;break;case"ArrowUp":E=h[Math.max(0,z-1)].id;break;case"Home":E=h[0].id;break;case"End":E=h[h.length-1].id;break;case"ArrowRight":if(!A.hasChildren)break;d.has(S)?E=A.firstChildId:y(S,!0);break;case"ArrowLeft":A.hasChildren&&d.has(S)?y(S,!1):E=A.parentId;break;case"Enter":case" ":k.preventDefault(),g(S,A.hasChildren);return;default:return}k.preventDefault(),E&&E!==S&&j(E)},[h,d,y,j,g]),$=(k,_)=>k.map((S,z)=>{var B;const A=(B=S.children)!=null&&B.length?S.children:null,E=!!A&&d.has(S.id),T=S.id===p,H=_===1&&k.length>1&&z===k.length-1;return e.jsxs("li",{role:"treeitem","aria-level":_,"aria-expanded":A?E:void 0,"aria-selected":T,tabIndex:w===S.id?0:-1,"data-ct-id":S.id,className:H?"bim-ct-last":void 0,children:[e.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":_-1},onClick:()=>{f(S.id),g(S.id,!!A)},children:[e.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:A?O=>{O.stopPropagation(),f(S.id),y(S.id)}:void 0,children:A?e.jsx(Zx,{}):null}),e.jsx("span",{className:"bim-ct-lb",children:l(S.label)}),e.jsx("span",{className:"bim-ct-n",children:S.count.toLocaleString("en-US")})]}),E&&e.jsx("ul",{role:"group",children:$(A,_+1)})]},S.id)});return e.jsxs("ul",{ref:a,role:"tree","aria-label":l(s),className:"bim-ct-tree",onKeyDown:v,children:[c&&e.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:w===ft?0:-1,"data-ct-id":ft,children:e.jsxs("div",{className:"bim-ct-row",onClick:()=>{f(ft),r(ft)},children:[e.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),e.jsx("span",{className:"bim-ct-lb",children:l(o)}),e.jsx("span",{className:"bim-ct-n",children:wr(t).toLocaleString("en-US")})]})}),$(t,1)]})}const la=t=>`/item/${encodeURIComponent(t)}`;function Qx(t){return t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&!t.altKey}function aa(t){return t==null||t===""?null:typeof t=="number"?`${t}卷`:t}function ca({work:t,href:n}){var a,p;const{convert:r}=G(),o=aa(t.juan),s=((a=t.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=t.classification)==null?void 0:p.filter(Boolean))??[];return e.jsx("li",{className:"bim-ct-card",children:e.jsxs("a",{href:n,children:[e.jsxs("div",{className:"bim-ct-ch",children:[e.jsx("h2",{className:"bim-ct-ct",children:r(t.title)}),o&&e.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),s.length>0&&e.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>e.jsxs(m.Fragment,{children:[d>0&&"、",c.dynasty&&e.jsxs("span",{className:"bim-ct-dy",children:["〔",r(c.dynasty),"〕"]}),r(c.name)]},d))}),t.summary&&e.jsx("p",{className:"bim-ct-sum",children:r(t.summary)}),l.length>0&&e.jsx("span",{className:"bim-ct-cls",children:l.map(c=>r(c)).join(" · ")})]})})}function da({work:t,href:n}){var a,p;const{convert:r}=G(),o=aa(t.juan),s=((a=t.authors)==null?void 0:a.filter(c=>c.name))??[],l=((p=t.classification)==null?void 0:p.filter(Boolean))??[];return e.jsx("li",{className:"bim-ct-lrow",children:e.jsxs("a",{href:n,children:[e.jsxs("span",{className:"bim-ct-lt",children:[r(t.title),o&&e.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),e.jsx("span",{className:"bim-ct-by",children:s.map((c,d)=>e.jsxs(m.Fragment,{children:[d>0&&"、",c.dynasty&&e.jsxs("span",{className:"bim-ct-dy",children:["〔",r(c.dynasty),"〕"]}),r(c.name)]},d))}),e.jsx("span",{className:"bim-ct-cls",children:l.map(c=>r(c)).join(" · ")})]})})}function pa({page:t,pageCount:n,onPage:r,pageHref:o,label:s="分頁"}){const{convert:l}=G();if(n<=1)return null;const a=c=>d=>{r&&(o&&!Qx(d)||(d.preventDefault(),r(c)))},p=(c,d,u)=>{if(u.disabled)return e.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:d});const h={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return o?e.jsx("a",{...h,href:o(c),onClick:a(c),children:d}):e.jsx("button",{type:"button",...h,onClick:u.current?void 0:a(c),children:d})};return e.jsxs("nav",{className:"bim-ct-pager","aria-label":l(s),children:[p(t-1,l("上一頁"),{disabled:t<=1}),e.jsx("ol",{children:oa(t,n).map((c,d)=>e.jsx("li",{style:{display:"contents"},children:c===null?e.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):p(c,c,{current:c===t,aria:l(`第 ${c} 頁`)})},c??`gap${d}`))}),e.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[t," / ",n]}),p(t+1,l("下一頁"),{disabled:t>=n})]})}function ua({works:t,workLink:n=la,emptyText:r="此類暫無作品",view:o="card",...s}){const{convert:l}=G();return e.jsxs("div",{className:"bim-ct-works",children:[t.length===0?e.jsx("p",{className:"bim-ct-empty",children:typeof r=="string"?l(r):r}):o==="list"?e.jsx("ul",{className:"bim-ct-list",children:t.map(a=>e.jsx(da,{work:a,href:n(a.id)},a.id))}):e.jsx("ul",{className:"bim-ct-grid",children:t.map(a=>e.jsx(ca,{work:a,href:n(a.id)},a.id))}),e.jsx(pa,{...s})]})}const eh=()=>e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:e.jsx("path",{d:"M2.5 4.5 6 8l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function th({tree:t,selectedId:n,page:r,pageCount:o,works:s,onSelect:l,onPage:a,searchSlot:p,workLink:c,pageHref:d,allLabel:u="全部",allTitle:h="全部典籍",pageSize:x=kr,className:f,view:b,onViewChange:w}){const{convert:y}=G(),g=`bim-ct-drawer-${m.useId().replace(/:/g,"")}`,[v,$]=m.useState(!1),[k,_]=m.useState("card"),S=b??k,z=O=>{_(O),w==null||w(O)},A=Ot(t,n&&n!==ft?n:null),E=A.length?A[A.length-1]:null,T=E?E.label:h,H=E?E.count:wr(t),B=m.useCallback(O=>{$(!1),l(O)},[l]);return e.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":v?"open":"closed",children:[e.jsx("style",{children:ra}),e.jsxs("aside",{className:"bim-ct-side","aria-label":y("分類導航"),children:[e.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":v,"aria-controls":g,onClick:()=>$(O=>!O),children:[e.jsxs("span",{children:[y("分類"),":",y(A.length?A.map(O=>O.label).join(" › "):u??h)]}),e.jsx(eh,{})]}),e.jsxs("div",{className:"bim-ct-drawer",id:g,children:[e.jsx("h2",{className:"bim-ct-side-h",children:y("分類")}),e.jsx(sa,{tree:t,selectedId:n,onSelect:B,allLabel:u})]})]}),e.jsxs("div",{className:"bim-ct-main",children:[e.jsxs("header",{className:"bim-ct-head",children:[e.jsx("h1",{className:"bim-ct-title",children:y(T)}),A.length>1&&e.jsx("span",{className:"bim-ct-crumb",children:y(A.slice(0,-1).map(O=>O.label).join(" › "))}),e.jsxs("span",{className:"bim-ct-stat",children:[y(`共 ${H.toLocaleString("en-US")} 種 · 每頁 ${x} 條`),o>1&&y(` · 第 ${r} / ${o} 頁`)]}),e.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":y("呈現方式"),children:[e.jsx("button",{type:"button","aria-pressed":S==="card",onClick:()=>z("card"),children:y("卡片")}),e.jsx("button",{type:"button","aria-pressed":S==="list",onClick:()=>z("list"),children:y("列表")})]})]}),p&&e.jsx("div",{className:"bim-ct-search",children:p}),e.jsx(ua,{works:s,view:S,workLink:c,page:r,pageCount:o,onPage:a,pageHref:d})]})]})}const Sr="(max-width: 719px)",nh="(max-width: 1079px)",ih=`${Sr}, (pointer: coarse)`,rh=[8,18,30,42,88],ma=`
|
|
1219
|
+
.bim-rh { color: ${i("ink")}; font-family: ${i("font-ui")}; font-size: 14px; line-height: 1.6; }
|
|
1220
|
+
.bim-rh *, .bim-rh *::before, .bim-rh *::after { box-sizing: border-box; }
|
|
1221
|
+
.bim-rh a { color: ${i("accent")}; text-decoration: none; }
|
|
1222
|
+
.bim-rh a:hover { color: ${i("accent-deep")}; }
|
|
1223
|
+
.bim-rh :focus-visible { outline: 2px solid ${i("accent")}; outline-offset: 2px; }
|
|
1224
|
+
.bim-rh-num { font-variant-numeric: tabular-nums; }
|
|
1225
|
+
.bim-rh-sr {
|
|
1226
|
+
position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
|
|
1227
|
+
overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/* ── 统计 ── */
|
|
1231
|
+
.bim-rh-stats { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 26px; font-size: 12.5px; color: ${i("meta-fg")}; }
|
|
1232
|
+
.bim-rh-stats b { color: ${i("ink")}; font-weight: 600; font-size: 20px; margin-right: 4px; }
|
|
1233
|
+
|
|
1234
|
+
/* ── 分区导航(手机吸顶) ── */
|
|
1235
|
+
.bim-rh-secnav {
|
|
1236
|
+
position: sticky; top: ${i("reader-top")}; z-index: 10;
|
|
1237
|
+
background: color-mix(in srgb, ${i("page-bg")} 94%, transparent); backdrop-filter: blur(6px);
|
|
1238
|
+
border-block: 1px solid ${i("rule")};
|
|
1239
|
+
}
|
|
1240
|
+
.bim-rh-secnav ul { display: flex; gap: 4px 22px; margin: 0; padding: 10px 0; list-style: none; overflow-x: auto; scrollbar-width: none; }
|
|
1241
|
+
.bim-rh-secnav a { display: inline-block; font-size: 13px; color: ${i("quiet-fg")}; white-space: nowrap; }
|
|
1242
|
+
.bim-rh-secnav a:hover { color: ${i("accent")}; }
|
|
1243
|
+
|
|
1244
|
+
/* ── 分区通用:疏朗靠留白,界栏加外框(--bim-fr-*) ── */
|
|
1245
|
+
.bim-rh-main { display: flex; flex-direction: column; gap: ${i("fr-gap")}; padding: 40px 0 72px; }
|
|
1246
|
+
.bim-rh-sec { min-width: 0; border: ${i("fr-bd")}; background: ${i("fr-bg")}; scroll-margin-top: calc(${i("reader-top")} + 56px); }
|
|
1247
|
+
.bim-rh-hd {
|
|
1248
|
+
display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px;
|
|
1249
|
+
padding: ${i("fr-hd-pad")}; border-bottom: ${i("fr-hd-bd")}; margin-bottom: 18px;
|
|
1250
|
+
}
|
|
1251
|
+
:root[data-layout="boxed"] .bim-rh-hd { margin-bottom: 0; }
|
|
1252
|
+
.bim-rh-hd h2 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: 0.1em; color: ${i("ink")}; }
|
|
1253
|
+
.bim-rh-hd .bim-rh-sub { font-size: 13px; color: ${i("meta-fg")}; }
|
|
1254
|
+
.bim-rh-hd .bim-rh-more { margin-left: auto; font-size: 13px; white-space: nowrap; }
|
|
1255
|
+
.bim-rh-bd { min-width: 0; padding: ${i("fr-bd-pad")}; }
|
|
1256
|
+
.bim-rh-gt { display: flex; align-items: baseline; gap: 10px; margin: 0 0 10px; font-size: 14px; font-weight: 600; letter-spacing: 0.12em; color: ${i("ink")}; }
|
|
1257
|
+
.bim-rh-gt small { font-weight: 400; font-size: 12px; color: ${i("aux-fg")}; letter-spacing: 0; }
|
|
1258
|
+
|
|
1259
|
+
/* ── 推荐阅读:题签卡 ── */
|
|
1260
|
+
.bim-rh-picks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 0; padding: 0; list-style: none; }
|
|
1261
|
+
.bim-rh-picks > li { min-width: 0; display: flex; }
|
|
1262
|
+
.bim-rh-pk {
|
|
1263
|
+
flex: 1; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 18px; padding: 20px 20px 18px;
|
|
1264
|
+
background: ${i("card-bg")}; border: 1px solid ${i("rule")}; box-shadow: ${i("fr-shadow")};
|
|
1265
|
+
color: ${i("ink")} !important;
|
|
1266
|
+
}
|
|
1267
|
+
.bim-rh-pk:hover { border-color: ${i("accent")}; }
|
|
1268
|
+
.bim-rh-slip {
|
|
1269
|
+
display: flex; flex-direction: column; align-items: center; gap: 2px; width: 34px; align-self: start;
|
|
1270
|
+
min-height: 132px; max-height: 190px; overflow: hidden; padding: 12px 0;
|
|
1271
|
+
border: 1px solid ${i("rule-accent-soft")}; background: ${i("flag-bg")}; color: ${i("accent-deep")};
|
|
1272
|
+
font-size: 15px; font-weight: 600; line-height: 1.2;
|
|
1273
|
+
}
|
|
1274
|
+
.bim-rh-pk-body { min-width: 0; display: flex; flex-direction: column; }
|
|
1275
|
+
.bim-rh-badge { align-self: flex-start; padding: 1px 7px; border: 1px solid ${i("rule-dashed")}; font-size: 11.5px; letter-spacing: 0.06em; color: ${i("quiet-fg")}; white-space: nowrap; }
|
|
1276
|
+
.bim-rh-pk h3 { margin: 8px 0 0; font-size: 18px; font-weight: 600; letter-spacing: 0.06em; line-height: 1.45; color: ${i("ink")}; }
|
|
1277
|
+
.bim-rh-pk .bim-rh-by { margin-top: 3px; font-size: 12.5px; color: ${i("meta-fg")}; }
|
|
1278
|
+
.bim-rh-pk p { margin: 10px 0 0; font-size: 13.5px; line-height: 1.9; color: ${i("body-fg")}; }
|
|
1279
|
+
.bim-rh-go { margin-top: auto; padding-top: 12px; font-size: 13px; color: ${i("accent")}; }
|
|
1280
|
+
|
|
1281
|
+
/* ── 专题:史志书架 ── */
|
|
1282
|
+
.bim-rh-shelf-wrap { overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
|
|
1283
|
+
.bim-rh-shelf { display: flex; align-items: flex-end; gap: 14px; min-width: max-content; margin: 0; padding: 4px 2px 0; list-style: none; border-bottom: 3px solid ${i("quiet-fg")}; }
|
|
1284
|
+
.bim-rh-era { display: flex; flex-direction: column; align-items: center; gap: 6px; }
|
|
1285
|
+
.bim-rh-era > span { font-size: 12px; color: ${i("meta-fg")}; letter-spacing: 0.1em; white-space: nowrap; padding: 0 2px; border-bottom: 1px solid ${i("rule-dashed")}; }
|
|
1286
|
+
.bim-rh-spines { display: flex; align-items: flex-end; gap: 3px; margin: 0; padding: 0; list-style: none; }
|
|
1287
|
+
.bim-rh-spine {
|
|
1288
|
+
width: 30px; padding: 10px 0; display: flex; flex-direction: column; align-items: center; gap: 1px;
|
|
1289
|
+
font-size: 13px; line-height: 1.15; border: 1px solid ${i("rule-accent-soft")}; background: ${i("card-bg")};
|
|
1290
|
+
color: ${i("body-fg")} !important;
|
|
1291
|
+
}
|
|
1292
|
+
.bim-rh-spine:hover { border-color: ${i("accent")}; color: ${i("accent")} !important; }
|
|
1293
|
+
.bim-rh-spine[data-orig] { background: ${i("accent")}; border-color: ${i("accent")}; color: ${i("page-bg")} !important; }
|
|
1294
|
+
.bim-rh-spine[data-orig]:hover { background: ${i("accent-deep")}; color: ${i("page-bg")} !important; }
|
|
1295
|
+
.bim-rh-spine .bim-rh-n { margin-top: auto; padding-top: 6px; font-size: 11px; letter-spacing: 0; }
|
|
1296
|
+
.bim-rh-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 12px; font-size: 12px; color: ${i("meta-fg")}; }
|
|
1297
|
+
.bim-rh-legend i { display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px; border: 1px solid ${i("rule-accent-soft")}; background: ${i("card-bg")}; }
|
|
1298
|
+
.bim-rh-legend i[data-orig] { background: ${i("accent")}; border-color: ${i("accent")}; }
|
|
1299
|
+
|
|
1300
|
+
/* ── 专题:分组列表 ── */
|
|
1301
|
+
.bim-rh-groups { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px 40px; }
|
|
1302
|
+
.bim-rh-shelf-box + .bim-rh-groups { margin-top: 32px; }
|
|
1303
|
+
.bim-rh-grp { min-width: 0; }
|
|
1304
|
+
.bim-rh-rows { margin: 0; padding: 0; list-style: none; }
|
|
1305
|
+
.bim-rh-rows a {
|
|
1306
|
+
display: flex; align-items: baseline; gap: 10px; min-width: 0; min-height: 36px; padding: 8px 2px;
|
|
1307
|
+
border-top: 1px solid ${i("rule")}; color: ${i("ink")}; font-size: 14px;
|
|
1308
|
+
}
|
|
1309
|
+
.bim-rh-rows li:last-child a { border-bottom: 1px solid ${i("rule")}; }
|
|
1310
|
+
.bim-rh-rows a:hover { color: ${i("accent")}; }
|
|
1311
|
+
.bim-rh-rows .bim-rh-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1312
|
+
.bim-rh-rows small { margin-left: auto; flex: none; font-size: 12px; color: ${i("aux-fg")}; white-space: nowrap; }
|
|
1313
|
+
.bim-rh-cnt { flex: none; padding: 0 4px; border: 1px solid ${i("rule-dashed")}; font-size: 11px; font-style: normal; color: ${i("meta-fg")}; }
|
|
1314
|
+
.bim-rh-expand { display: none; margin-top: 8px; padding: 0; border: 0; background: none; font: inherit; font-size: 12.5px; color: ${i("accent")}; cursor: pointer; }
|
|
1315
|
+
|
|
1316
|
+
/* ── 名著与版本 ── */
|
|
1317
|
+
.bim-rh-works { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 0; padding: 0; list-style: none; }
|
|
1318
|
+
.bim-rh-wk { min-width: 0; height: 100%; display: flex; flex-direction: column; gap: 10px; padding: 18px 20px 16px; border: 1px solid ${i("rule")}; background: ${i("card-bg")}; }
|
|
1319
|
+
.bim-rh-wk-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
|
|
1320
|
+
.bim-rh-wk-h h3 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: 0.08em; color: ${i("ink")}; }
|
|
1321
|
+
.bim-rh-wk-h .bim-rh-by { font-size: 12.5px; color: ${i("meta-fg")}; }
|
|
1322
|
+
.bim-rh-wk-h .bim-rh-c { margin-left: auto; font-size: 12px; color: ${i("aux-fg")}; white-space: nowrap; }
|
|
1323
|
+
.bim-rh-lin { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; }
|
|
1324
|
+
.bim-rh-lin > small { flex: none; width: 4.5em; font-size: 12px; color: ${i("aux-fg")}; letter-spacing: 0.05em; }
|
|
1325
|
+
.bim-rh-chip {
|
|
1326
|
+
display: inline-flex; align-items: center; min-height: 30px; padding: 3px 10px; white-space: nowrap;
|
|
1327
|
+
border: 1px solid ${i("rule-dashed")}; background: ${i("page-bg")}; color: ${i("body-fg")} !important; font-size: 13px;
|
|
1328
|
+
}
|
|
1329
|
+
.bim-rh-chip:hover { border-color: ${i("accent")}; color: ${i("accent")} !important; }
|
|
1330
|
+
.bim-rh-wk-f { margin-top: auto; padding-top: 8px; border-top: 1px dashed ${i("rule")}; font-size: 12.5px; }
|
|
1331
|
+
|
|
1332
|
+
/* ── 四部 ── */
|
|
1333
|
+
.bim-rh-bu { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin: 0; padding: 0; list-style: none; }
|
|
1334
|
+
.bim-rh-bu-c { min-width: 0; border-top: 3px solid ${i("ink")}; padding-top: 12px; }
|
|
1335
|
+
:root[data-layout="boxed"] .bim-rh-bu-c { border: ${i("fr-bd")}; border-top: 3px solid ${i("ink")}; padding: 12px 14px 14px; background: ${i("page-bg")}; }
|
|
1336
|
+
.bim-rh-bu-h { display: flex; align-items: baseline; gap: 10px; color: ${i("ink")} !important; }
|
|
1337
|
+
.bim-rh-bu-h b { font-size: 26px; font-weight: 600; letter-spacing: 0.2em; }
|
|
1338
|
+
.bim-rh-bu-h span { margin-left: auto; font-size: 13px; color: ${i("meta-fg")}; }
|
|
1339
|
+
.bim-rh-bu-l { margin: 10px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
|
|
1340
|
+
.bim-rh-bu-l a { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 5px 0; color: ${i("body-fg")}; font-size: 13.5px; }
|
|
1341
|
+
.bim-rh-bu-l a:hover { color: ${i("accent")}; }
|
|
1342
|
+
.bim-rh-bu-l small { font-size: 12px; color: ${i("aux-fg")}; }
|
|
1343
|
+
.bim-rh-bar { grid-column: 1 / -1; position: relative; height: 3px; background: ${i("rule")}; }
|
|
1344
|
+
.bim-rh-bar::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--bimrh-w, 0%); background: ${i("rule-accent-soft")}; }
|
|
1345
|
+
.bim-rh-bu-more { display: inline-block; margin-top: 8px; font-size: 12.5px; }
|
|
1346
|
+
.bim-rh-uncl { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-top: 18px; padding: 12px 14px; border: 1px dashed ${i("rule-dashed")}; font-size: 13px; color: ${i("meta-fg")}; }
|
|
1347
|
+
.bim-rh-uncl b { color: ${i("body-fg")}; font-weight: 500; }
|
|
1348
|
+
.bim-rh-uncl a { margin-left: auto; }
|
|
1349
|
+
|
|
1350
|
+
/* ── 按年代:比例横带(手机改格子) ── */
|
|
1351
|
+
.bim-rh-band { display: flex; height: 64px; margin: 0; padding: 0; list-style: none; border: 1px solid ${i("rule-dashed")}; overflow: hidden; }
|
|
1352
|
+
.bim-rh-band > li { min-width: 0; display: flex; }
|
|
1353
|
+
.bim-rh-band > li + li { border-left: 1px solid ${i("page-bg")}; }
|
|
1354
|
+
.bim-rh-band a {
|
|
1355
|
+
flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; padding: 0 8px; overflow: hidden;
|
|
1356
|
+
color: ${i("ink")} !important; font-size: 13px;
|
|
1357
|
+
}
|
|
1358
|
+
${rh.map((t,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb, ${i("accent")} ${t}%, ${i("card-bg")}); }`).join(`
|
|
1359
|
+
`)}
|
|
1360
|
+
.bim-rh-band a[data-k="4"] { color: ${i("page-bg")} !important; }
|
|
1361
|
+
.bim-rh-band a:hover { outline: 2px solid ${i("ink")}; outline-offset: -2px; }
|
|
1362
|
+
.bim-rh-band .bim-rh-pl { white-space: nowrap; font-weight: 500; letter-spacing: 0.06em; overflow: hidden; text-overflow: ellipsis; }
|
|
1363
|
+
.bim-rh-band small { white-space: nowrap; font-size: 11.5px; }
|
|
1364
|
+
.bim-rh-band .bim-rh-pl-s { display: none; }
|
|
1365
|
+
.bim-rh-band a[data-narrow] .bim-rh-pl, .bim-rh-band a[data-narrow] small { display: none; }
|
|
1366
|
+
.bim-rh-band a[data-narrow] .bim-rh-pl-s { display: block; font-weight: 500; }
|
|
1367
|
+
.bim-rh-pfoot { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 12px; color: ${i("aux-fg")}; }
|
|
1368
|
+
|
|
1369
|
+
/* ── 单篇诗文 ── */
|
|
1370
|
+
.bim-rh-authors { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 26px 32px; margin: 0; padding: 0; list-style: none; }
|
|
1371
|
+
.bim-rh-au { min-width: 0; }
|
|
1372
|
+
.bim-rh-au-h { display: flex; align-items: baseline; gap: 8px; margin: 0; padding-bottom: 6px; border-bottom: 1px solid ${i("quiet-fg")}; font-size: 16px; font-weight: 600; letter-spacing: 0.1em; color: ${i("ink")}; }
|
|
1373
|
+
.bim-rh-au-h span { font-size: 12px; font-weight: 400; letter-spacing: 0; color: ${i("meta-fg")}; }
|
|
1374
|
+
.bim-rh-au-h small { margin-left: auto; font-size: 12px; font-weight: 400; letter-spacing: 0; color: ${i("aux-fg")}; }
|
|
1375
|
+
.bim-rh-au ul { list-style: none; margin: 6px 0 0; padding: 0; }
|
|
1376
|
+
.bim-rh-au li a { display: block; padding: 4px 0; font-size: 14px; color: ${i("body-fg")}; }
|
|
1377
|
+
.bim-rh-au li a:hover { color: ${i("accent")}; }
|
|
1378
|
+
.bim-rh-au .bim-rh-more { display: inline-block; margin-top: 4px; font-size: 12.5px; }
|
|
1379
|
+
|
|
1380
|
+
/* ── 配色「墨」:强调色≈正文色,行内文字链接加下划线 ── */
|
|
1381
|
+
:root[data-theme="ink"] :is(.bim-rh-go, .bim-rh-more, .bim-rh-bu-more, .bim-rh-wk-f a, .bim-rh-uncl a, .bim-rh-expand) {
|
|
1382
|
+
text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); text-underline-offset: 3px;
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
/* ── 中屏 ── */
|
|
1386
|
+
@media ${nh} {
|
|
1387
|
+
.bim-rh-picks, .bim-rh-works, .bim-rh-groups, .bim-rh-bu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
1388
|
+
.bim-rh-authors { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
/* ── 手机 ── */
|
|
1392
|
+
@media ${Sr} {
|
|
1393
|
+
.bim-rh-main { padding-top: 24px; }
|
|
1394
|
+
.bim-rh-stats { gap: 4px 18px; }
|
|
1395
|
+
.bim-rh-stats b { font-size: 16px; }
|
|
1396
|
+
.bim-rh-hd h2 { font-size: 19px; }
|
|
1397
|
+
.bim-rh-hd .bim-rh-more { margin-left: 0; }
|
|
1398
|
+
/* 推荐:横向滑动 */
|
|
1399
|
+
.bim-rh-picks { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 12px; padding-bottom: 6px; scrollbar-width: none; }
|
|
1400
|
+
.bim-rh-picks > li { flex: 0 0 82%; scroll-snap-align: start; }
|
|
1401
|
+
.bim-rh-pk { padding: 16px; gap: 14px; }
|
|
1402
|
+
.bim-rh-slip { min-height: 112px; font-size: 14px; }
|
|
1403
|
+
.bim-rh-works, .bim-rh-groups { grid-template-columns: minmax(0, 1fr); }
|
|
1404
|
+
.bim-rh-groups { gap: 24px; }
|
|
1405
|
+
.bim-rh-shelf-box + .bim-rh-groups { margin-top: 24px; }
|
|
1406
|
+
/* 长分组只露前 6 条,「全部」按钮展开 */
|
|
1407
|
+
.bim-rh-grp:not([data-open]) .bim-rh-rows li:nth-child(n+7) { display: none; }
|
|
1408
|
+
.bim-rh-expand { display: inline-flex; }
|
|
1409
|
+
.bim-rh-bu { gap: 22px 16px; }
|
|
1410
|
+
.bim-rh-bu-h b { font-size: 21px; }
|
|
1411
|
+
.bim-rh-authors { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 18px; }
|
|
1412
|
+
/* 年代:横带改 3 列格子,每格都写全名与部数 */
|
|
1413
|
+
.bim-rh-band { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; height: auto; border: 0; overflow: visible; }
|
|
1414
|
+
.bim-rh-band > li { flex: none !important; }
|
|
1415
|
+
.bim-rh-band > li + li { border-left: 0; }
|
|
1416
|
+
.bim-rh-band a { padding: 8px 10px; border: 1px solid ${i("rule")}; font-size: 13.5px; }
|
|
1417
|
+
.bim-rh-band a[data-narrow] .bim-rh-pl, .bim-rh-band a[data-narrow] small { display: block; }
|
|
1418
|
+
.bim-rh-band a[data-narrow] .bim-rh-pl-s { display: none; }
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
/* 触屏或窄屏:点击目标放大到 44px */
|
|
1422
|
+
@media ${ih} {
|
|
1423
|
+
.bim-rh-rows a, .bim-rh-bu-l a, .bim-rh-au li a, .bim-rh-chip, .bim-rh-secnav a, .bim-rh-expand { min-height: 44px; display: flex; align-items: center; }
|
|
1424
|
+
.bim-rh-chip { display: inline-flex; }
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
@media (prefers-reduced-motion: reduce) { .bim-rh * { scroll-behavior: auto !important; transition: none !important; } }
|
|
1428
|
+
`,xa={xianqin:"先秦",qinhan:"秦漢",weijin:"魏晉南北朝",suitang:"隋唐五代",song:"宋",liaojinyuan:"遼金元",ming:"明",qing:"清",modern:"近現代"},ha={read:t=>`/read/${encodeURIComponent(t)}`,node:t=>`/read?node=${encodeURIComponent(t)}`,period:t=>`/read?period=${encodeURIComponent(t)}`,work:t=>`/item/${encodeURIComponent(t)}`};function $t(t){return{...ha,...t??{}}}function $r(t){var r;const n=(r=t.authors)==null?void 0:r.find(o=>o==null?void 0:o.name);return n?n.dynasty?`${n.dynasty} ${n.name}`:n.name:""}function fa(t){return(t.authors??[]).filter(r=>r==null?void 0:r.name).map(r=>r.dynasty?`〔${r.dynasty}〕${r.name}`:r.name).join(" ")}function ga(t){var o;const n=[],r=new Map;for(const s of t){const l=((o=s.period_of)==null?void 0:o.trim())||"其他";let a=r.get(l);a||(a={label:l,items:[]},r.set(l,a),n.push(a)),a.items.push(s)}return n}function ba(t){return Math.max(150,Array.from(t).length*18+44)}function ya(t,n){if(n<=0||t<=0)return 0;const r=t/n;return r<.15?0:r<.35?1:r<.6?2:r<.85?3:4}const ja=.04;function st(t){return t.toLocaleString("en-US")}function va({text:t}){return e.jsx(e.Fragment,{children:Array.from(t).map((n,r)=>e.jsx("span",{children:n},r))})}function zt({id:t,title:n,sub:r,more:o,children:s}){const{convert:l}=G(),a=`${t}-h`;return e.jsxs("section",{className:"bim-rh-sec",id:t,"aria-labelledby":a,children:[e.jsxs("div",{className:"bim-rh-hd",children:[e.jsx("h2",{id:a,children:l(n)}),r&&e.jsx("span",{className:"bim-rh-sub",children:r}),o]}),e.jsx("div",{className:"bim-rh-bd",children:s})]})}function ka({counts:t}){const{convert:n}=G();return e.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[e.jsxs("span",{children:[e.jsx("b",{children:st(t.readable)}),n("部可讀")]}),t.pieces>0&&e.jsxs("span",{children:[e.jsx("b",{children:st(t.pieces)}),n("篇單篇詩文")]})]})}function wa({picks:t,links:n}){const{convert:r}=G(),o=$t(n);return t.length?e.jsx("ul",{className:"bim-rh-picks",children:t.map(s=>{const l=fa(s),a=[s.type_label,s.edition].filter(Boolean).join(" · ");return e.jsx("li",{children:e.jsxs("a",{className:"bim-rh-pk",href:o.read(s.id),children:[e.jsx("span",{className:"bim-rh-slip","aria-hidden":"true",children:e.jsx(va,{text:r(s.slip||s.title)})}),e.jsxs("span",{className:"bim-rh-pk-body",children:[a&&e.jsx("span",{className:"bim-rh-badge",children:r(a)}),e.jsx("h3",{children:r(s.title)}),l&&e.jsx("span",{className:"bim-rh-by",children:r(l)}),s.blurb&&e.jsx("p",{children:r(s.blurb)}),e.jsx("span",{className:"bim-rh-go","aria-hidden":"true",children:r("開始閱讀 →")})]})]})},s.id)})}):null}function Sa(t){return t&&t>1?`${t}本`:null}function $a({topic:t,links:n}){const{convert:r}=G(),o=$t(n);if(!t.items.length)return null;const s=ga(t.items),l=a=>{const p=Sa(a.text_count),c=$r(a),d=[a.title,a.orig?"正史原志":"",c?`${c} 撰`:"",p?`站內 ${p}`:""].filter(Boolean).join(",");return e.jsx("li",{children:e.jsxs("a",{className:"bim-rh-spine",href:o.read(a.id),"data-orig":a.orig?"":void 0,"aria-label":r(d),title:r(d),style:{height:ba(a.title)},children:[e.jsx(va,{text:r(a.title)}),p&&e.jsx("span",{className:"bim-rh-n bim-rh-num",children:r(p)})]})},a.id)};return e.jsxs("div",{className:"bim-rh-shelf-box",children:[e.jsxs("h3",{className:"bim-rh-gt",children:[r(t.label),e.jsx("small",{children:r("按所志朝代排列,一脊一部")})]}),e.jsx("div",{className:"bim-rh-shelf-wrap",tabIndex:0,role:"region","aria-label":r(`${t.label}書架,可橫向滾動`),children:e.jsx("ul",{className:"bim-rh-shelf",children:s.map(a=>e.jsxs("li",{className:"bim-rh-era",children:[e.jsx("ul",{className:"bim-rh-spines","aria-label":r(a.label),children:a.items.map(l)}),e.jsx("span",{"aria-hidden":"true",children:r(a.label)})]},a.label))})}),e.jsxs("p",{className:"bim-rh-legend",children:[e.jsxs("span",{children:[e.jsx("i",{"data-orig":"","aria-hidden":"true"}),r("正史原志")]}),e.jsxs("span",{children:[e.jsx("i",{"aria-hidden":"true"}),r("後人補撰、續補")]}),e.jsx("span",{children:r("脊下「2本」=站內有幾個本子")})]})]})}function _a({topic:t,links:n}){const{convert:r}=G(),o=$t(n),[s,l]=m.useState(!1);if(!t.items.length)return null;const a=`bim-rh-g-${t.key}`;return e.jsxs("div",{className:"bim-rh-grp","data-open":s?"":void 0,children:[e.jsxs("h3",{className:"bim-rh-gt",id:a,children:[r(t.label),e.jsx("small",{className:"bim-rh-num",children:r(`${st(t.items.length)} 部`)})]}),e.jsx("ul",{className:"bim-rh-rows","aria-labelledby":a,children:t.items.map(p=>{const c=Sa(p.text_count),d=$r(p);return e.jsx("li",{children:e.jsxs("a",{href:o.read(p.id),children:[e.jsx("span",{className:"bim-rh-t",children:r(p.title)}),c&&e.jsx("em",{className:"bim-rh-cnt bim-rh-num",children:r(c)}),d&&e.jsx("small",{children:r(d)})]})},p.id)})}),t.items.length>6&&e.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":s,onClick:()=>l(p=>!p),children:r(s?"收起":`全部 ${t.items.length} 部`)})]})}function za({topics:t,links:n}){const r=t.filter(s=>s.shelf&&s.items.length),o=t.filter(s=>!s.shelf&&s.items.length);return!r.length&&!o.length?null:e.jsxs(e.Fragment,{children:[r.map(s=>e.jsx($a,{topic:s,links:n},s.key)),o.length>0&&e.jsx("div",{className:"bim-rh-groups",children:o.map(s=>e.jsx(_a,{topic:s,links:n},s.key))})]})}function Ca({famous:t,links:n}){const{convert:r}=G(),o=$t(n);return t.length?e.jsx("ul",{className:"bim-rh-works",children:t.map(s=>e.jsx("li",{children:e.jsxs("article",{className:"bim-rh-wk",children:[e.jsxs("div",{className:"bim-rh-wk-h",children:[e.jsx("h3",{children:r(s.title)}),s.authors&&e.jsx("span",{className:"bim-rh-by",children:r(s.authors)}),e.jsx("span",{className:"bim-rh-c bim-rh-num",children:r(`${s.text_count} 個本子`)})]}),s.systems.map((l,a)=>e.jsxs("div",{className:"bim-rh-lin",role:"group","aria-label":l.label?r(l.label):void 0,children:[l.label&&e.jsx("small",{"aria-hidden":"true",children:r(l.label)}),l.items.map(p=>e.jsx("a",{className:"bim-rh-chip",href:o.read(p.id),title:r([p.title,p.edition].filter(Boolean).join(" · ")),children:r(p.short)},p.id))]},a)),s.work_id&&e.jsx("div",{className:"bim-rh-wk-f",children:e.jsx("a",{href:o.work(s.work_id),children:r(`作品頁:${s.title}的源流與全部版本 →`)})})]})},s.work_id??s.title))}):null}function Ta({bu:t,unclassified:n,links:r}){const{convert:o}=G(),s=$t(r);return!t.length&&!n?null:e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"bim-rh-bu",children:t.map(l=>{var p;const a=((p=l.top[0])==null?void 0:p.count)||1;return e.jsxs("li",{className:"bim-rh-bu-c",children:[e.jsxs("a",{className:"bim-rh-bu-h",href:s.node(l.id),children:[e.jsx("b",{children:o(l.label)}),e.jsx("span",{className:"bim-rh-num",children:o(`${st(l.count)} 部`)})]}),l.top.length>0&&e.jsx("ul",{className:"bim-rh-bu-l","aria-label":o(`${l.label}子類`),children:l.top.map(c=>e.jsx("li",{children:e.jsxs("a",{href:s.node(c.id),children:[e.jsx("span",{children:o(c.label)}),e.jsx("small",{className:"bim-rh-num",children:st(c.count)}),e.jsx("span",{className:"bim-rh-bar","aria-hidden":"true",style:{"--bimrh-w":`${Math.round(c.count/a*100)}%`}})]})},c.id))}),l.children_total>l.top.length&&e.jsx("a",{className:"bim-rh-bu-more",href:s.node(l.id),children:o(`${l.label}全部 ${l.children_total} 類 →`)})]},l.id)})}),!!n&&e.jsxs("p",{className:"bim-rh-uncl bim-rh-num",children:[e.jsx("b",{children:o("未分類")}),e.jsx("span",{children:o(`${st(n)} 部`)}),e.jsx("span",{children:o("書目分類還沒補齊,其中多數是單篇詩文,已單列在下方。")}),e.jsx("a",{href:s.node("unclassified"),children:o("查看未分類 →")})]})]})}function Ia({periods:t,unknown:n,links:r}){const{convert:o}=G(),s=$t(r),l=t.filter(c=>c.count>0);if(!l.length)return null;const a=l.reduce((c,d)=>c+d.count,0),p=Math.max(...l.map(c=>c.count));return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"bim-rh-band",children:l.map(c=>{const d=o(c.label||xa[c.key]||c.key),u=c.count/a,h=`${d},${st(c.count)} ${o("部")}`;return e.jsx("li",{style:{flex:`0 0 ${(u*100).toFixed(3)}%`},children:e.jsxs("a",{href:s.period(c.key),"data-k":ya(c.count,p),"data-narrow":u<ja?"":void 0,"aria-label":h,title:h,children:[e.jsx("span",{className:"bim-rh-pl",children:d}),e.jsx("span",{className:"bim-rh-pl-s","aria-hidden":"true",children:Array.from(d)[0]}),e.jsx("small",{className:"bim-rh-num",children:st(c.count)})]})},c.key)})}),e.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!n&&e.jsx("span",{children:o(`另有 ${st(n)} 部作者無朝代,在「四部」和搜索裏能找到`)}),e.jsx("span",{children:o("窄段懸停看全名")})]})]})}function Ea({authors:t,links:n}){const{convert:r}=G(),o=$t(n);return t.length?e.jsx("ul",{className:"bim-rh-authors",children:t.map(s=>e.jsxs("li",{className:"bim-rh-au",children:[e.jsxs("h3",{className:"bim-rh-au-h",children:[r(s.name),s.dynasty&&e.jsx("span",{children:r(s.dynasty)}),e.jsx("small",{className:"bim-rh-num",children:r(`${st(s.count)} 篇`)})]}),e.jsx("ul",{children:s.items.map(l=>e.jsx("li",{children:e.jsx("a",{href:o.read(l.id),children:r(l.title)})},l.id))}),o.author&&e.jsx("a",{className:"bim-rh-more",href:o.author(s.name),children:r(`${s.name}全部 ${s.count} 篇 →`)})]},s.name))}):null}const Na={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function oh({sections:t,links:n,head:r,piecesMoreHref:o,className:s}){const{convert:l}=G(),a=t,p=Na,c=a.topics.filter(h=>!h.shelf),d={picks:a.picks.length>0,topics:c.some(h=>h.items.length>0),famous:a.famous.length>0,sibu:a.bu.length>0||a.unclassified>0,period:a.periods.some(h=>h.count>0),pieces:a.pieces.authors.length>0},u=[["picks","推薦閱讀"],["topics","專題"],["famous","名著與版本"],["sibu","四部"],["period","按年代"],["pieces","單篇詩文"]].filter(([h])=>d[h]);return e.jsxs("div",{className:s?`bim-rh ${s}`:"bim-rh",children:[e.jsx("style",{children:ma}),e.jsxs("div",{className:"bim-rh-head",children:[r,e.jsx(ka,{counts:a.counts})]}),u.length>1&&e.jsx("nav",{className:"bim-rh-secnav","aria-label":l("閱讀首頁分區"),children:e.jsx("ul",{children:u.map(([h,x])=>e.jsx("li",{children:e.jsx("a",{href:`#${p[h]}`,children:l(x)})},h))})}),e.jsxs("div",{className:"bim-rh-main",children:[d.picks&&e.jsx(zt,{id:p.picks,title:"推薦閱讀",sub:l("編輯挑選,定期輪換"),children:e.jsx(wa,{picks:a.picks,links:n})}),d.topics&&e.jsx(zt,{id:p.topics,title:"專題",sub:l("按作品類型歸組;小說見下方「名著與版本」"),children:e.jsx(za,{topics:c,links:n})}),d.famous&&e.jsx(zt,{id:p.famous,title:"名著與版本",sub:l("一部作品一張卡,卡上列出站內能讀的各個本子"),children:e.jsx(Ca,{famous:a.famous,links:n})}),d.sibu&&e.jsx(zt,{id:p.sibu,title:"四部",sub:l("按古籍總目的分類樹,只計站內可讀的作品"),children:e.jsx(Ta,{bu:a.bu,unclassified:a.unclassified,links:n})}),d.period&&e.jsx(zt,{id:p.period,title:"按年代",sub:l("按作者朝代歸段,寬度與部數成比例"),children:e.jsx(Ia,{periods:a.periods,unknown:a.period_unknown,links:n})}),d.pieces&&e.jsx(zt,{id:p.pieces,title:"單篇詩文",sub:l("單篇的詩、文、賦、表,按作者歸組"),more:o?e.jsx("a",{className:"bim-rh-more",href:o,children:l("按作者瀏覽全部 →")}):void 0,children:e.jsx(Ea,{authors:a.pieces.authors,links:n})})]})]})}const Li=({style:t})=>{const n=m.useContext(Vt);if(!n)return null;const{locale:r,setLocale:o}=n,s=r==="zh-Hant",l=()=>o(s?"zh-Hans":"zh-Hant");return e.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",...t},children:[e.jsx("span",{style:{color:s?i("primary"):void 0,fontWeight:s?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:s?void 0:i("primary"),fontWeight:s?400:700},children:"简"})]})},Ai=({href:t,label:n="在 GitHub 查看本条目源文件",size:r=16,className:o,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:o,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:r+8,height:r+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:e.jsx("svg",{width:r,height:r,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.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 mi(t,n){return{id:t,title:n.title??n.primary_name??t,type:n.type??"book"}}function sh(t,n){if(!n)return!1;const r=n.id;return r===void 0||r===t}const lh=({id:t,transport:n,initialDetail:r,initialEntry:o,activeTab:s,onTabChange:l,activeJuan:a,onJuanChange:p,lineageMode:c="list",onLineageModeChange:d,lineageCollection:u,onLineageCollectionChange:h,initialPage:x=1,selectedLineageNodeId:f,onNavigate:b,onBack:w,backLabel:y,renderLink:j,enrichDetail:g,getSourceLink:v,readLink:$,railTop:k,extraTabs:_=[],showFeedbackTab:S=!0,feedbackApiUrl:z,height:A,footerExtra:E,className:T,style:H})=>{var Jt;const B=ge(),{convert:O}=G(),[D]=m.useState(()=>{if(!sh(t,r))return null;const q={...r},Ie=o??mi(t,q);return g&&g(Ie,q),{id:t,entry:Ie,detail:q}}),[ne,V]=m.useState((D==null?void 0:D.entry)??null),[C,xe]=m.useState((D==null?void 0:D.detail)??null),[L,te]=m.useState(!D),[N,Z]=m.useState(!1),[ce,W]=m.useState([]),[X,ae]=m.useState(!1),[de,me]=m.useState(null),[$e,Me]=m.useState(!1),[Ee,Le]=m.useState(null),[ze,Ae]=m.useState(!1),[P,he]=m.useState(null),[ie,ke]=m.useState([]),[we,Y]=m.useState(!1),[R,U]=m.useState(null),[fe,be]=m.useState(null),[M,ue]=m.useState(!1),K=m.useRef(null),[se,je]=m.useState(null),Te=a!==void 0?a:se,Ce=m.useCallback(q=>{p?p(q):je(q)},[p]),le=m.useCallback(async q=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){W([]);return}ae(!0);try{if(n.getCollectionCatalogs)W(await n.getCollectionCatalogs(q)||[]);else if(n.getCollectionCatalog){const Ie=await n.getCollectionCatalog(q);W(Ie?[{resource_id:"",data:Ie}]:[])}}catch{W([])}finally{ae(!1)}},[n]),_e=m.useCallback(async q=>{if(!n.getCollatedEditionIndex){me(null);return}Me(!0);try{me(await n.getCollatedEditionIndex(q))}catch{me(null)}finally{Me(!1)}},[n]),I=m.useCallback(async q=>{if(!n.getBookFullTextIndex){Le(null);return}Ae(!0);try{Le(await n.getBookFullTextIndex(q))}catch{Le(null)}finally{Ae(!1),he(q)}},[n]),J=m.useCallback(async q=>{var Ie;if(!n.getWorkFullTextList){ke([]);return}Y(!0);try{const Be=(await n.getWorkFullTextList(q)??[]).filter(He=>He.owner_type!=="Book");ke(Be),U(((Ie=Be.find(He=>He.primary)??Be[0])==null?void 0:Ie.key)??null)}catch{ke([])}finally{Y(!1)}},[n]),oe=m.useCallback(async(q,Ie)=>{ue(!0);try{if(n.getLineageGraph){const qe=await n.getLineageGraph(q);qe&&be(qe)}const Be=Ie.version_graph;if(!Be||!Be.enabled){fe||be(null),K.current=null;return}const He=Ie.books??[],at=[];for(const qe of He)try{const ct=await n.getItem(qe);ct&&at.push(ct)}catch{}K.current={work:Ie,books:at};const pe=u??Be.default_collection??(Be.core_books&&Be.core_books.length>0?"core":"all"),Oe=pe==="core"&&Array.isArray(Be.core_books)&&Be.core_books.length>0?"core":pe??"all";be(zn(Ie,at,Oe))}catch{be(null),K.current=null}finally{ue(!1)}},[n]),Q=m.useRef({initialDetail:r,initialEntry:o});Q.current={initialDetail:r,initialEntry:o},m.useEffect(()=>{let q=!1;const Ie=pe=>{pe.type==="collection"?le(t):pe.type==="work"?(pe.has_collated&&_e(t),(pe.version_graph||n.getLineageGraph)&&oe(t,pe),n.getWorkFullTextList&&J(t)):pe.type==="book"&&pe.has_full_text&&n.getBookFullTextIndex&&I(t)},Be=Q.current;let He=null;if(D&&D.id===t)He=D;else if(Be.initialDetail&&Be.initialDetail.id===t){const pe={...Be.initialDetail},Oe=Be.initialEntry??mi(t,pe);g&&g(Oe,pe),He={entry:Oe,detail:pe}}return He?(Z(!1),W(pe=>pe.length?[]:pe),me(null),Le(null),ke(pe=>pe.length?[]:pe),U(null),be(null),K.current=null,V(He.entry),xe(He.detail),te(!1),Ie(He.detail),()=>{q=!0}):((async()=>{te(!0),Z(!1),V(null),xe(null),W([]),me(null),Le(null),ke([]),U(null),be(null),K.current=null;try{const pe=await n.getItem(t);if(q)return;if(!pe){Z(!0);return}const Oe=pe;let qe=null;if(n.getEntry&&(qe=await n.getEntry(t),q))return;qe||(qe=mi(t,Oe)),g&&g(qe,Oe),V(qe),xe(Oe),Ie(Oe)}catch{q||Z(!0)}finally{q||te(!1)}})(),()=>{q=!0})},[t,n,D,g,le,_e,oe,I,J]),m.useEffect(()=>{const q=K.current;!q||!u||be(zn(q.work,q.books,u))},[u]);const ee=[];if(C){if(ee.push({key:"basic",label:B.detailTab.basicInfo}),C.type==="collection"){X&&ce.length===0&&ee.push({key:"catalog:loading",label:`${B.detailTab.catalog}…`});for(const q of ce)ee.push({key:`catalog:${q.resource_id}`,label:q.short_name?`${O(q.short_name)}${B.detailTab.catalogSuffix}`:B.detailTab.collectionCatalog})}C.type==="work"&&(de||$e)&&s==="collated"&&ee.push({key:"collated",label:$e?`${B.detailTab.collatedEdition}…`:B.detailTab.collatedEdition}),C.type==="book"&&(Ee||ze)&&s==="fulltext"&&ee.push({key:"fulltext",label:ze?`${B.detailTab.fullText}…`:B.detailTab.fullText}),C.type==="work"&&(ie.length>0||we)&&s==="fulltext"&&ee.push({key:"fulltext",label:we?`${B.detailTab.fullText}…`:B.detailTab.fullText}),C.type==="work"&&(fe||M)&&ee.push({key:"lineage",label:M?`${B.detailTab.lineage}…`:B.detailTab.lineage});for(const q of _)(q.position??"before-feedback")==="before-feedback"&&q.shouldShow(C)&&ee.push({key:q.key,label:q.label});S&&s==="feedback"&&ee.push({key:"feedback",label:B.detailTab.feedback});for(const q of _)q.position==="after-feedback"&&q.shouldShow(C)&&ee.push({key:q.key,label:q.label})}m.useEffect(()=>{if(s!=="emendated"||!C)return;l("basic");const q=setTimeout(()=>{var Ie;(Ie=document.getElementById("studies"))==null||Ie.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(q)},[s,C,l]);const Se=ne&&C&&v?v({activeTab:s,activeJuan:Te,entry:ne,detail:C}):null,F=m.useMemo(()=>{var at;if(!C)return null;const Ie=(C.authors??[]).map(pe=>{const Oe=Ji(pe.role);return`${pe.dynasty?`〔${O(pe.dynasty)}〕`:""}${O(pe.name)}${Oe?` ${O(Oe)}`:""}`}).join(" · ");let Be=!1;try{Be=ye.extractStatus(C.id)==="draft"}catch{}if(C.type==="book"){const pe=C;return{title:O(pe.title),subtitle:pe.edition?O(pe.edition):Ie||void 0,aside:[Be?B.status.draft:"",Ie&&pe.edition?Ie:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(C.type==="collection"){const pe=C;return{title:O(pe.title),subtitle:O(yt(pe,B.unit.juan))||void 0,aside:[(at=pe.publication_info)==null?void 0:at.year,Be?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:Ie||void 0}}if(C.type==="entity"){const pe=C,Oe=ct=>ct==null?"":ct<0?`前${-ct}`:String(ct),qe=pe.birth_year!=null||pe.death_year!=null?`${Oe(pe.birth_year)||"?"}—${Oe(pe.death_year)||"?"}`:"";return{title:O(pe.primary_name||pe.title),subtitle:[pe.dynasty?`〔${O(pe.dynasty)}〕`:"",qe].filter(Boolean).join(" ")||void 0,aside:Be?B.status.draft:void 0,secondLine:void 0}}const He=O(yt(C,B.unit.juan));return{title:O(C.title),subtitle:[He,Ie].filter(Boolean).join(" · ")||void 0,aside:[ch(B,C.subtype),Be?B.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[C,O,B]),ve=C?C.type==="work"?(((Jt=de==null?void 0:de.juan_files)==null?void 0:Jt.length)??0)>0?"collated":ie.length>0?"fulltext":null:C.type==="book"&&(((Ee==null?void 0:Ee.chapters.length)??0)>0||C.has_full_text&&n.getBookFullTextIndex&&P!==C.id)?"fulltext":null:null,We=ie.find(q=>q.primary)??ie[0],Ke=()=>{var q;ve==="collated"&&((q=de==null?void 0:de.juan_files)!=null&&q.length)?(Ce(de.juan_files[0]),l("collated")):ve==="fulltext"&&((C==null?void 0:C.type)==="work"&&We&&U(We.key),Ce(null),l("fulltext"))};let lt=null;if(C&&$){const q=$({detail:C,kind:ve,fullTextKey:C.type==="work"?We==null?void 0:We.key:void 0});q&&(lt=e.jsx(ji,{href:q}))}else ve&&(lt=e.jsx(ji,{onClick:Ke}));const Bt=q=>{if(!C)return null;const Ie=q.replace(/\.[^.]+$/,"");if($){const Be=$({detail:C,kind:"fulltext",juan:Ie});return Be?{href:Be}:null}return{onClick:()=>{Ce(Ie),l("fulltext")}}},jt=new Set(_.map(q=>q.key)),Ne=ee.filter(q=>q.key.startsWith("catalog:")&&q.key!=="catalog:loading"||jt.has(q.key)).map(q=>({key:q.key,label:q.label,onClick:()=>l(q.key)})),Ze=()=>{var q;return C?C.type==="work"?e.jsx(Zl,{data:C,transport:n,onNavigate:b,renderLink:j,readAction:lt,railTop:k,railLinks:Ne}):C.type==="book"?e.jsx(ta,{data:C,transport:n,onNavigate:b,renderLink:j,readAction:lt,fullText:Ee,fullTextPending:!!C.has_full_text&&!!n.getBookFullTextIndex&&P!==C.id,chapterLink:Bt,railTop:k,railLinks:Ne}):C.type==="collection"?e.jsx(na,{data:C,catalog:(q=ce[0])==null?void 0:q.data,transport:n,onNavigate:b,renderLink:j,readAction:lt,railTop:k,railLinks:Ne,catalogAction:ce.length>0?e.jsxs("a",{href:"#catalog",onClick:Ie=>{Ie.preventDefault(),l(`catalog:${ce[0].resource_id}`)},children:[O(B.detailTab.collectionCatalog)," →"]}):null}):e.jsx(ia,{data:C,transport:n,onNavigate:b,renderLink:j,railTop:k,railLinks:Ne}):null},Fe=()=>{var Ie,Be,He,at;if(!ne||!C)return null;if(s==="basic"||s==="emendated")return Ze();if(typeof s=="string"&&s.startsWith("catalog:")){const pe=(Ie=ce.find(Oe=>`catalog:${Oe.resource_id}`===s))==null?void 0:Ie.data;return e.jsx(Vi,{data:pe,onNavigate:b,renderLink:j})}if(s==="collated")return e.jsx(fr,{index:de||void 0,workId:t,transport:n,onNavigate:b,activeJuan:Te,onJuanChange:Ce});if(s==="fulltext"&&C.type==="work"){const pe=R??((Be=ie[0])==null?void 0:Be.key);return pe?e.jsx(Ti,{bookId:t,workKey:pe,versions:ie,onVersionChange:Oe=>{U(Oe),Ce(null)},transport:n,activeChapter:Te,onChapterChange:Ce},pe):e.jsx("div",{style:{padding:24,color:i("desc-fg")},children:we?"加载全文目录…":"暂无全文"})}if(s==="fulltext")return e.jsx(Ti,{index:Ee||void 0,bookId:t,transport:n,activeChapter:Te,onChapterChange:Ce});if(s==="lineage"){if(!fe)return e.jsx("div",{style:{color:i("label-fg"),padding:"24px 0"},children:M?"加載中…":"暫無版本圖數據"});const pe=C.type==="work"?C:null;return e.jsx(jr,{graph:fe,renderLink:j,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:d,selectedNodeId:f,collection:u??((He=pe==null?void 0:pe.version_graph)==null?void 0:He.default_collection),onCollectionChange:h,collectionsAvailable:(at=pe==null?void 0:pe.version_graph)==null?void 0:at.collections,collectionCounts:(()=>{var zr,Cr,Tr,Ir,Er,Nr,Rr;if(!pe)return;const Oe={},qe=((zr=K.current)==null?void 0:zr.books)??[];Oe.all=(((Cr=pe.books)==null?void 0:Cr.length)??0)-(((Ir=(Tr=pe.version_graph)==null?void 0:Tr.excluded_books)==null?void 0:Ir.length)??0);const ct=(Er=pe.version_graph)==null?void 0:Er.collections;if(ct)for(const Lr of Object.keys(ct))Oe[Lr]=zn(pe,qe,Lr).nodes.filter(Ar=>Ar.kind==="book"&&!Ar.bridge).length;return Oe.core==null&&((Rr=(Nr=pe.version_graph)==null?void 0:Nr.core_books)!=null&&Rr.length)&&(Oe.core=pe.version_graph.core_books.length),Oe})()})}if(s==="feedback"&&S)return e.jsx(Yl,{resourceId:t,apiUrl:z});const q=_.find(pe=>pe.key===s);return q?q.render({detail:C,entry:ne,transport:n,onNavigate:b}):null};if(L)return e.jsx(ln,{style:{minHeight:A,...H},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((q,Ie)=>e.jsx("div",{style:{height:Ie===1?40:16,width:q,opacity:.35,background:i("rule")}},Ie))})});if(N||!C||!ne||!F)return e.jsx(ln,{style:{minHeight:A,...H},children:e.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:i("label-fg"),fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const mt=s==="basic"||s==="emendated",re=[{label:y??B.detailTab.backToIndex,onClick:w}];if(C.type==="book"&&C.work_id){const q=C.work_id;re.push({label:B.indexType.work,id:q,onClick:()=>b==null?void 0:b(q)})}re.push({label:B.indexType[C.type]});const Re=s==="collated"||s==="fulltext",et=typeof E=="string"?B.status[E.trim()]??E:E,_t=e.jsx(rl,{left:e.jsxs(e.Fragment,{children:[et,et?" · ":"",e.jsx(ah,{id:C.id,label:B.label.id,copied:B.action.copied,copyLabel:B.action.copy})]}),right:e.jsxs(e.Fragment,{children:[S&&!mt&&e.jsx("button",{type:"button",onClick:()=>l("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:B.detailTab.submitVersion}),Se&&e.jsx("a",{href:Se.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:i("meta-fg")},children:B.detailTab.dataLicense})]})});return mt?e.jsx("div",{className:T,children:e.jsxs(ln,{grid:!0,style:{minHeight:A,...H},children:[e.jsx(vi,{breadcrumb:e.jsx(ki,{items:re}),actions:e.jsxs(e.Fragment,{children:[e.jsx(Li,{style:{border:"none",background:"transparent"}}),Se&&e.jsx(Ai,{...Se})]})}),Ze(),_t]})}):e.jsx("div",{className:T,children:e.jsxs(ln,{wide:Re,style:{minHeight:A,...H},children:[e.jsx(vi,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(Xi,{char:"籍"}),e.jsx(ki,{items:re})]}),actions:e.jsxs(e.Fragment,{children:[e.jsx(Li,{}),S&&e.jsx("button",{type:"button",onClick:()=>l("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:B.detailTab.feedback}),Se&&e.jsx(Ai,{...Se})]})}),e.jsx(qs,{...F,aside:Re?e.jsxs("button",{type:"button",onClick:()=>l("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("accent"),borderBottom:`1px solid ${i("rule")}`},children:[O("作品信息")," →"]}):F.aside}),!Re&&ee.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:ee.map(q=>e.jsx(Js,{label:q.label,active:q.key===s||mt&&q.key==="basic",onClick:()=>l(q.key)},q.key))}),e.jsx("div",{style:{marginTop:!Re&&ee.length>1?8:0},children:Fe()}),_t]})})};function ah({id:t,label:n,copied:r,copyLabel:o}){const[s,l]=m.useState(!1);return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[e.jsxs("span",{children:[n," ",t]}),e.jsx("button",{type:"button",onClick:()=>{var a;(a=navigator.clipboard)==null||a.writeText(t).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},title:s?r:o,"aria-label":s?r:o,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 ch(t,n){return n?t.workSubtype[n]??n:""}const Ra=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],Kn="zhusha",qn="bim-theme";function La(t){return t==="zhusha"||t==="indigo"||t==="ink"}function Jn(t){return La(t)?t:Kn}function dh(){try{return Jn(window.localStorage.getItem(qn))}catch{return Kn}}function Aa(t){try{window.localStorage.setItem(qn,t)}catch{}}function Ba(t){const n=Jn(t);return document.documentElement.setAttribute("data-theme",n),n}function Ma(){return Jn(document.documentElement.getAttribute("data-theme"))}const ph=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],_r="airy",Zn="bim-layout";function Wa(t){return t==="airy"||t==="boxed"}function Xn(t){return Wa(t)?t:_r}function uh(){try{return Xn(window.localStorage.getItem(Zn))}catch{return _r}}function mh(t){try{window.localStorage.setItem(Zn,t)}catch{}}function xh(t){const n=Xn(t);return document.documentElement.setAttribute("data-layout",n),n}function hh(){return Xn(document.documentElement.getAttribute("data-layout"))}const fh=`try{var t=localStorage.getItem(${JSON.stringify(qn)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(Zn)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,gh={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},bh=({onChange:t,style:n})=>{const{convert:r}=G(),[o,s]=m.useState(Kn);m.useEffect(()=>{s(Ma())},[]);const l=a=>{s(Ba(a)),Aa(a),t==null||t(a)};return e.jsx("div",{role:"radiogroup","aria-label":r("主題"),style:{display:"inline-flex",alignItems:"center",...n},children:Ra.map(a=>{const p=o===a.name;return e.jsx("button",{type:"button",role:"radio","aria-checked":p,"aria-label":r(a.label),title:r(a.label),onClick:()=>l(a.name),style:{width:28,height:44,padding:0,border:0,background:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:"50%",boxSizing:"border-box",background:i(gh[a.name]),boxShadow:p?`0 0 0 2px ${i("page-bg")}, 0 0 0 3.5px ${i("aux-fg")}`:"none"}})},a.name)})})};exports.BidLink=ye.BidLink;exports.BookIndexError=ye.BookIndexError;exports.BookIndexManager=ye.BookIndexManager;exports.BookIndexStorage=ye.BookIndexStorage;exports.BundleStorage=ye.BundleStorage;exports.ConfigError=ye.ConfigError;exports.GithubStorage=ye.GithubStorage;exports.IdGenerationError=ye.IdGenerationError;exports.IdGenerator=ye.IdGenerator;exports.LocalStorage=ye.LocalStorage;exports.MigrationError=ye.MigrationError;exports.StorageError=ye.StorageError;exports.base36Decode=ye.base36Decode;exports.base36Encode=ye.base36Encode;exports.base58Decode=ye.base58Decode;exports.buildId=ye.buildId;exports.buildPromotionMap=ye.buildPromotionMap;exports.cleanName=ye.cleanName;exports.decodeId=ye.decodeId;exports.decodeIdString=ye.decodeIdString;exports.encodeId=ye.encodeId;exports.extractIdFromUrl=ye.extractIdFromUrl;exports.extractStatus=ye.extractStatus;exports.extractType=ye.extractType;exports.isChapterSegment=ye.isChapterSegment;exports.isTextKey=ye.isTextKey;exports.matchChapterAcrossVersions=ye.matchChapterAcrossVersions;exports.normalizeCatalog=ye.normalizeCatalog;exports.parseId=ye.parseId;exports.pickTextVersion=ye.pickTextVersion;exports.shardOf=ye.shardOf;exports.smartDecode=ye.smartDecode;exports.textVersionLabel=ye.textVersionLabel;exports.validateResource=ye.validateResource;exports.Badge=Nn;exports.BidUrlProvider=qa;exports.BookDetailLayout=lh;exports.BookFullText=Ti;exports.BookPage=ta;exports.Breadcrumb=ki;exports.CATALOG_ALL_ID=ft;exports.CATALOG_CSS=ra;exports.CATALOG_NARROW_QUERY=vr;exports.CATALOG_PAGE_SIZE=kr;exports.CATALOG_UNCLASSIFIED_ID=mn;exports.CLASSIFICATIONS=Mn;exports.CardFoot=gn;exports.CatalogPage=th;exports.CatalogPager=pa;exports.CatalogTree=sa;exports.CheckFilter=Ys;exports.Chip=Zs;exports.ChipWall=rp;exports.CollatedEdition=fr;exports.CollectionCatalog=Vi;exports.CollectionPage=na;exports.CreateEntityDialog=Fl;exports.DEFAULT_LAYOUT=_r;exports.DEFAULT_READER_PREFS=tr;exports.DEFAULT_READ_HOME_LINKS=ha;exports.DEFAULT_THEME=Kn;exports.DETAIL_CSS=Ks;exports.DYNASTY_GROUPS=Bn;exports.Dash=dp;exports.DataTable=sp;exports.DetailFooter=rl;exports.DetailGrid=hn;exports.DetailHeader=qs;exports.EMPTY_FILTERS=An;exports.EmendatedBySection=Is;exports.EmptyNote=gp;exports.EntityDetail=Ss;exports.EntityPage=ia;exports.EntityPickerDialog=Pl;exports.EntitySelector=Wl;exports.ExpandRow=pp;exports.ExtLink=bp;exports.FEEDBACK_FAB_OFFSET_VAR=Ei;exports.FILTER_SUPPORT=fs;exports.FONT_SIZE_STEPS=ht;exports.FactList=ep;exports.FeedbackButton=Um;exports.FeedbackDialog=Vl;exports.FeedbackForm=Ul;exports.FeedbackList=gr;exports.FeedbackTab=Yl;exports.FilterChip=Js;exports.FormInput=Xe;exports.FormTextArea=Nt;exports.GUJI_MARKDOWN_FIELD=Od;exports.GUJI_TABLE_NOTATION=hl;exports.GlyphBadge=Xi;exports.GujiTable=rr;exports.HomePage=Ci;exports.ImagePanel=Si;exports.IndexApp=Hu;exports.IndexBrowser=fi;exports.IndexDetail=Gi;exports.IndexEditor=Dl;exports.IndexView=Rm;exports.IntroGrid=Qd;exports.LAYOUTS=ph;exports.LAYOUT_STORAGE_KEY=Zn;exports.LOSS_OPTIONS=Di;exports.LocaleContext=Vt;exports.LocaleProvider=cc;exports.LocaleToggle=Li;exports.MetaLine=Ve;exports.ModeIndicator=ms;exports.MoreButton=ip;exports.MoreLink=qt;exports.PAGE_MAX_WIDTH=$n;exports.PERIOD_NARROW_SHARE=ja;exports.PageFrame=ln;exports.Quote=mp;exports.READER_CSS=al;exports.READ_HOME_CSS=ma;exports.READ_HOME_NARROW_QUERY=Sr;exports.READ_HOME_SECTION_IDS=Na;exports.READ_PERIOD_LABELS=xa;exports.RECENT_IDS_STORAGE_KEY=Pt;exports.ROLE_CLASS_ORDER=Ms;exports.ReadButton=ji;exports.ReadFamousWorks=Ca;exports.ReadHomeView=oh;exports.ReadPeriodBand=Ia;exports.ReadPicks=wa;exports.ReadPieces=Ea;exports.ReadSection=zt;exports.ReadShelf=$a;exports.ReadSibu=Ta;exports.ReadStats=ka;exports.ReadTopicGroup=_a;exports.ReadTopics=za;exports.ReaderMdText=Yn;exports.ReaderShell=Vn;exports.ReaderToc=dl;exports.RelationPanel=Bl;exports.RepoSourceLink=Ai;exports.ResourceEditor=hi;exports.ResourceGroup=xp;exports.ResourceLine=hp;exports.ResourceList=Pi;exports.ResourceRow=nl;exports.SEARCH_VIEW_STORAGE_KEY=Hi;exports.SNIPPET_MARK_END=ls;exports.SNIPPET_MARK_START=ss;exports.SORTABLE_TYPES=hs;exports.SearchInput=xs;exports.SearchResults=ks;exports.Sec=Ue;exports.Section=it;exports.SectionHead=tp;exports.SideList=Et;exports.SmartBidInput=_n;exports.SourceEditor=Rl;exports.SummaryCard=fn;exports.THEMES=Ra;exports.THEME_INIT_SCRIPT=fh;exports.THEME_STORAGE_KEY=qn;exports.TabFilter=Hn;exports.TableHead=lp;exports.TableRow=ap;exports.TagRow=il;exports.TagRows=fp;exports.TextButton=np;exports.TextReader=Ku;exports.ThemeToggle=bh;exports.TopStrip=vi;exports.VersionLineageGraph=ea;exports.VersionLineageList=Ql;exports.VersionLineageView=jr;exports.VolumeChips=op;exports.VolumeLinks=Qi;exports.WorkCard=ca;exports.WorkCardGrid=ua;exports.WorkCatalog=Xu;exports.WorkPage=Zl;exports.WorkRow=da;exports.applyLayout=xh;exports.applyTheme=Ba;exports.authorsLine=fa;exports.bucketResources=Ki;exports.buildCatalogTree=Ux;exports.buildCollectionTable=Fs;exports.buildLineageGraph=zn;exports.buildMeiliFilter=$c;exports.buildPageUrl=Oi;exports.buildParagraphBlocks=kl;exports.buildVersionRow=As;exports.buildVersionTable=Bs;exports.canParagraphize=Lt;exports.catalogNodeIdOf=Gx;exports.catalogNodeIdsOf=Vx;exports.catalogPageCount=Jx;exports.catalogTotal=wr;exports.classificationPath=yn;exports.compareCatalogCards=qx;exports.computeVersionPartition=Bd;exports.countActiveFilters=Wn;exports.createTextApi=El;exports.currentLayout=hh;exports.currentTheme=Ma;exports.defaultWorkLink=la;exports.deriveDating=Rd;exports.deriveEditionType=Ps;exports.deriveEra=xn;exports.deriveYear=On;exports.deriveYearRange=Yi;exports.detailToEditor=Gl;exports.detectGenre=Un;exports.displayAuthorRole=Ji;exports.editorToDetail=Nm;exports.eraRank=bi;exports.filtersFromParams=_c;exports.filtersToParams=Cn;exports.findCatalogPath=Ot;exports.firstAuthorText=$r;exports.flattenTitles=wi;exports.flattenToc=xl;exports.fmtCount=st;exports.formatTemplate=rt;exports.formatVolumeRange=Dn;exports.getDisplayNameFromUrl=Ut;exports.getStartPage=Fi;exports.getTypeGroupKey=Mi;exports.groupRelatedWorks=Ld;exports.gujiInlineToPlain=Vs;exports.hasActiveFilters=gs;exports.hasGujiMarkdownV02=un;exports.hasGujiTableNotation=nr;exports.hasSearchOptions=kc;exports.isLayoutName=Wa;exports.isThemeName=La;exports.measureText=yt;exports.mergeVolumeResources=Wi;exports.normalizeEra=Ge;exports.normalizeLayout=Xn;exports.normalizeRole=qi;exports.normalizeTheme=Jn;exports.normalizeVolumeIndex=cn;exports.normalizeVolumes=us;exports.numberToChinese=Os;exports.paginationItems=oa;exports.parseChineseNumber=Tn;exports.parseGujiInline=Gs;exports.parseGujiTable=gl;exports.parseSourceString=Ll;exports.periodLevel=ya;exports.pickReaderVersion=ml;exports.readStoredLayout=uh;exports.readStoredTheme=dh;exports.readerVersionOptionLabel=_i;exports.readerVersionsFromFullText=ul;exports.renderFullTextBody=Pp;exports.renderProperNames=Sl;exports.renderReaderInline=lr;exports.resourceHref=Yt;exports.resourceNote=Pn;exports.roleFacets=Ws;exports.rowNo=cp;exports.sameFilters=zc;exports.shelfColumns=ga;exports.sortFor=wc;exports.sortYear=In;exports.spineHeight=ba;exports.splitFullTextTables=ir;exports.splitHighlightSnippet=Bi;exports.splitTableRow=fl;exports.storeLayout=mh;exports.storeTheme=Aa;exports.stringifySources=Al;exports.toCatalogWorkCard=Kx;exports.typeSupportsFilters=bs;exports.useBidUrl=Pe;exports.useConvert=G;exports.useReaderPrefs=Gn;exports.useT=ge;exports.validateLineageGraph=mx;exports.volumeStats=Rn;exports.withDefaultLinks=$t;
|